'上架', self::status_off => '下架', ); } /** * 获取类型列表 * @author: linch * @return array */ public function get_type_list() { return array( self::type_industry => '行业动态', self::type_company => '公司动态', self::type_join => '加盟动态', ); } /** * 获取推荐状态列表 * @author: linch * @return array */ public function get_recommend_list() { return array( self::recommend_off => '否', self::recommend_on => '是', ); } /** * 获取banner状态 * @author: linch * @return array */ public function get_banner_list() { return array( self::banner_off => '否', self::banner_on => '是', ); } /** * 获取列表 * @author: linch * @param array $search 筛选条件 * @param int $page_num 页码 * @param int $page_size 页行数 * @return array */ public function get_list($search, $page_num, $page_size) { $where = array( 'status' => array('neq', self::status_del), ); if (!empty($search['title'])) { $where['title'] = array('like', '%' . trim($search['title']) . '%'); } $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->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['title'])) { return array('code' => false, 'msg' => '标题不能为空'); } if (empty($data['img'])) { return array('code' => false, 'msg' => '图片不能为空'); } if (empty($data['content'])) { return array('code' => false, 'msg' => '内容不能为空'); } if (empty($data['desc'])) { 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( 'title' => trim($data['title']), 'img' => trim($data['img']), 'home_img' => trim($data['home_img']), 'desc' => trim($data['desc']), 'content' => trim($data['content']), 'is_recommend' => intval($data['is_recommend']), 'type' => intval($data['type']), 'store_id' => intval($data['store_id']), 'source' => trim($data['source']), 'author' => trim($data['author']), 'status' => self::status_off, 'c_time' => $time, ); $result = $this->check_edit_data($save_data); if ($result['code'] == false) { //验证的数据不合格 return array('code' => false, 'msg' => $result['msg']); } //处理图片 $Common = new \Common\Common\Common(); if ('data:image' == substr($save_data['img'], 0, 10)) { $save_data['img'] = $Common->base64_upyun($save_data['img']); } if ('data:image' == substr($save_data['home_img'], 0, 10)) { $save_data['home_img'] = $Common->base64_upyun($save_data['home_img']); } $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( 'title' => trim($data['title']), 'img' => trim($data['img']), 'home_img' => trim($data['home_img']), 'desc' => trim($data['desc']), 'content' => trim($data['content']), 'is_recommend' => intval($data['is_recommend']), 'type' => intval($data['type']), 'store_id' => intval($data['store_id']), 'source' => trim($data['source']), 'author' => trim($data['author']), ); $result = $this->check_edit_data($save_data); if ($result['code'] == false) { //验证的数据不合格 return array('code' => false, 'msg' => $result['msg']); } //处理图片 $Common = new \Common\Common\Common(); if ('data:image' == substr($save_data['img'], 0, 10)) { $save_data['img'] = $Common->base64_upyun($save_data['img']); } if ('data:image' == substr($save_data['home_img'], 0, 10)) { $save_data['home_img'] = $Common->base64_upyun($save_data['home_img']); } $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; } /** * 设置上线 * @author: linch * @param $id * @return bool */ public function data_set_on($id) { $result = $this->where(array('id' => $id))->setField(array('status' => self::status_on)); return $result; } /** * 设置下线 * @author: linch * @param $id * @return bool */ public function data_set_off($id) { $result = $this->where(array('id' => $id))->setField(array('status' => self::status_off)); return $result; } /** * 设置成banner状态 * @author: linch * @param $id * @return bool */ public function data_set_banner_on($id) { $result = $this->where(array('id' => $id))->setField(array('is_banner' => self::banner_on)); return $result; } /** * 设置成非banner状态 * @author: linch * @param $id * @return bool */ public function data_set_banner_off($id) { $result = $this->where(array('id' => $id))->setField(array('is_banner' => self::banner_off)); return $result; } }