mod = M('home_subscription'); } /** * 新增数据 * @author: linch * @param $data * @return array */ public function data_add($data) { $time = date('Y-m-d H:i:s'); $save_data = array( 'email' => $data['email'], 'status' => self::status_wait, 'flag' => self::flag_on, 'c_time' => $time, ); $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['email'])) { return array('code' => false, 'msg' => '邮箱不能为空'); } $one = $this->where(array('email' => $data['email'], 'flag' => self::flag_on))->find(); if (!empty($one)) { return array('code' => false, 'msg' => '已经订阅'); } return array('code' => true, 'msg' => '数据符合'); } }