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' => '数据符合'); } }