123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <?php
- namespace Admin\Model;
- use Common\Model\HomeStoresModel as HomeStores;
- /**
- * 官网门店
- * @author: linch
- * Class HomeStoresModel
- * @package Common\Model
- */
- class HomeStoresModel extends HomeStores
- {
- /**
- * 获取发布状态列表
- * @author: linch
- * @return array
- */
- public function get_status_list() {
- return array(
- self::status_on => '上架',
- self::status_off => '下架',
- );
- }
- /**
- * 获取是否最新门店选项
- * @author: linch
- * @return array
- */
- public function get_is_new_list() {
- return array(
- self::new_off => '否',
- self::new_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['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' => '店名不能为空');
- }
- if (empty($data['img'])) {
- return array('code' => false, 'msg' => '图片不能为空');
- }
- if (empty($data['city_id'])) {
- return array('code' => false, 'msg' => '城市不能为空');
- }
- return array('code' => true, 'msg' => '数据符合');
- }
- /**
- * 新增数据
- * @author: linch
- * @param $data
- * @return mixed
- */
- public function data_add($data) {
- $save_data = array(
- 'name' => trim($data['name']),
- 'img' => trim($data['img']),
- 'city_id' => intval($data['city_id']),
- 'address' => trim($data['address']),
- 'date' => trim($data['date']),
- 'is_new' => intval($data['is_new']),
- 's_time' => trim($data['s_time']),
- 'e_time' => trim($data['e_time']),
- 'tel' => trim($data['tel']),
- 'status' => self::status_off,
- );
- $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']);
- }
- $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']),
- 'img' => trim($data['img']),
- 'city_id' => intval($data['city_id']),
- 'date' => trim($data['date']),
- 'is_new' => intval($data['is_new']),
- 'address' => trim($data['address']),
- 's_time' => trim($data['s_time']),
- 'e_time' => trim($data['e_time']),
- 'tel' => trim($data['tel']),
- );
- $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']);
- }
- $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;
- }
- }
|