mod = M('message_board'); } /** * 添加留言信息 * @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'], 'address' => $data['address'], 'message' => $data['message'], 'source' => $source, 'status' => self::status_wait, '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'] == false) { $msg = array('code' => $result['code'], 'msg' => $result['msg']); } else { $id = $this->data($save_data)->add(); if ($id == false) { $msg = array('code' => false, 'msg' => '内部错误,稍后重试'); } else { $msg = array('code' => true, 'msg' => '提交成功'); } } return $msg; } /** * 验证数据 * @author: linch * @param $data * @return array */ public function check_edit_data($data) { if (empty($data['name'])) { return array('code' => false, 'msg' => '姓名不能为空'); } if (empty($data['tel'])) { return array('code' => false, 'msg' => '手机不能为空'); } if (empty($data['address'])) { return array('code' => false, 'msg' => '地址不能为空'); } if (empty($data['message'])) { return array('code' => false, 'msg' => '留言不能为空'); } if (!preg_match('/^[1][3,4,5,7,8][0-9]{9}$/', $data['tel'])) { return array('code' => false, 'msg' => '手机号错误'); } return array('code' => true, 'msg' => '数据符合'); } }