123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace Common\Model;
- use Common\Model\BaseModel;
- /**
- * 加盟申请
- * @author: linch
- * Class StoreApplicationModel
- * @package Common\Model
- */
- class StoreApplicationModel extends BaseModel
- {
- protected $mod;
- //状态
- const status_wait = 0; //待处理
- const status_processed = 1; //已联系
- //软删状态
- const flag_off = 0; //删除
- const flag_on = 1; //正常
- //来源
- const source_mini_app = 0; //小程序
- const source_official_web = 1; //官网
- const source_official_wap = 2; //wap端
- public function __construct() {
- parent::__construct();
- $this->mod = M('store_application');
- }
- /**
- * 添加加盟信息
- * @author: linch
- * @param $data
- * @param $source
- * @param $ad_message_id
- * @return array
- */
- public function data_add($data, $source, $ad_message_id = 0) {
- $time = date('Y-m-d H:i:s');
- $save_data = array(
- 'name' => $data['name'],
- 'tel' => $data['tel'],
- 'mail' => trim($data['mail']),
- 'intention' => trim($data['intention']),
- 'city' => trim($data['city']),
- 'content' => trim($data['content']),
- 'source' => $source,
- 'status' => self::status_wait,
- 'flag' => self::flag_on,
- 'u_time' => $time,
- 'c_time' => $time,
- );
- if (!empty($ad_message_id)) {
- $save_data['ad_message_id'] = (int)$ad_message_id;
- }
- $result = $this->check_edit_data($save_data);
- if ($result['code'] != 1000) {
- $msg = array('code' => $result['code'], 'msg' => $result['msg']);
- } else {
- $id = $this->data($save_data)->add();
- if ($id == false) {
- $msg = array('code' => 1005, 'msg' => '内部错误,稍后重试');
- } else {
- $msg = array('code' => 1000, 'msg' => '提交成功');
- }
- }
- return $msg;
- }
- /**
- * 验证数据
- * @author: linch
- * @param $data
- * @return array
- */
- public function check_edit_data($data) {
- if (empty($data['name'])) {
- return array('code' => 1001, 'msg' => '姓名不能为空');
- }
- if (empty($data['tel'])) {
- return array('code' => 1001, 'msg' => '手机不能为空');
- }
- //官网web和wap端单独验证规则
- if ($data['source'] == self::source_official_web || $data['source'] == self::source_official_wap) {
- if (empty($data['content'])) {
- return array('code' => 1001, 'msg' => '留言不能为空');
- }
- }
- //小程序单独验证规则
- if ($data['source'] == self::source_mini_app) {
- if (empty($data['mail'])) {
- return array('code' => 1001, 'msg' => '邮箱不能为空');
- }
- }
- if (!preg_match('/^[1][3,4,5,7,8][0-9]{9}$/', $data['tel'])) {
- return array('code' => 1006, 'msg' => '手机号错误');
- }
- return array('code' => 1000, 'msg' => '数据符合');
- }
- }
|