array('neq', self::status_del), ); if (!empty($search['name'])) { $where['name'] = array('like', '%' . trim($search['name']) . '%'); } $order = 'id desc'; $limit = ($page_num - 1) * $page_size . ' ,' . $page_size; $field = '*'; $list = $this->where($where)->order($order)->field($field)->limit($limit)->select(); $count = $this->mod->where($where)->count(); $page = $this->x_show($count, $page_size, array()); $data = array( 'list' => $list, 'pager' => $page, ); return $data; } /** * 验证保存数据 * @author: linch * @param $data * @return array */ protected function check_edit_data($data) { if (empty($data['name'])) { return array('code' => false, 'msg' => '城市不能为空'); } return array('code' => true, 'msg' => '数据符合'); } /** * 新增数据 * @author: linch * @param $data * @return mixed */ public function data_add($data) { $time = date('Y-m-d H:i:s'); $save_data = array( 'name' => trim($data['name']), 'c_time' => $time, ); $result = $this->check_edit_data($save_data); $id = $this->data($save_data)->add(); if ($result == false) { //录入数据库失败 return array('code' => false, 'msg' => '系统出错,请重试'); } return array('code' => true, 'msg' => '操作成功', 'id' => $id); } /** * 编辑数据 * @author: linch * @param $data * @return bool */ public function data_edit($data) { $id = intval($data['id']); $save_data = array( 'name' => trim($data['name']), ); $result = $this->check_edit_data($save_data); if ($result['code'] == false) { //验证的数据不合格 return array('code' => false, 'msg' => $result['msg']); } $result = $this->where(array('id' => $id))->data($save_data)->save(); if ($result === false) { //录入数据库失败 return array('code' => false, 'msg' => '系统出错,请重试'); } return array('code' => true, 'msg' => '操作成功'); } /** * 设置删除状态 * @author: linch * @param $id * @return bool */ public function data_del($id) { $result = $this->where(array('id' => $id))->setField(array('status' => self::status_del)); return $result; } }