HomeStoresModel.class.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace Admin\Model;
  3. use Common\Model\HomeStoresModel as HomeStores;
  4. /**
  5. * 官网门店
  6. * @author: linch
  7. * Class HomeStoresModel
  8. * @package Common\Model
  9. */
  10. class HomeStoresModel extends HomeStores
  11. {
  12. /**
  13. * 获取发布状态列表
  14. * @author: linch
  15. * @return array
  16. */
  17. public function get_status_list() {
  18. return array(
  19. self::status_on => '上架',
  20. self::status_off => '下架',
  21. );
  22. }
  23. /**
  24. * 获取是否最新门店选项
  25. * @author: linch
  26. * @return array
  27. */
  28. public function get_is_new_list() {
  29. return array(
  30. self::new_off => '否',
  31. self::new_on => '是',
  32. );
  33. }
  34. /**
  35. * 获取列表
  36. * @author: linch
  37. * @param array $search 筛选条件
  38. * @param int $page_num 页码
  39. * @param int $page_size 页行数
  40. * @return array
  41. */
  42. public function get_list($search, $page_num, $page_size) {
  43. $where = array(
  44. 'status' => array('neq', self::status_del),
  45. );
  46. if (!empty($search['name'])) {
  47. $where['name'] = array('like', '%' . trim($search['name']) . '%');
  48. }
  49. $order = 'id desc';
  50. $limit = ($page_num - 1) * $page_size . ' ,' . $page_size;
  51. $field = '*';
  52. $list = $this->where($where)->order($order)->field($field)->limit($limit)->select();
  53. $count = $this->mod->where($where)->count();
  54. $page = $this->x_show($count, $page_size, array());
  55. $data = array(
  56. 'list' => $list,
  57. 'pager' => $page,
  58. );
  59. return $data;
  60. }
  61. /**
  62. * 验证保存数据
  63. * @author: linch
  64. * @param $data
  65. * @return array
  66. */
  67. protected function check_edit_data($data) {
  68. if (empty($data['name'])) {
  69. return array('code' => false, 'msg' => '店名不能为空');
  70. }
  71. if (empty($data['img'])) {
  72. return array('code' => false, 'msg' => '图片不能为空');
  73. }
  74. if (empty($data['city_id'])) {
  75. return array('code' => false, 'msg' => '城市不能为空');
  76. }
  77. return array('code' => true, 'msg' => '数据符合');
  78. }
  79. /**
  80. * 新增数据
  81. * @author: linch
  82. * @param $data
  83. * @return mixed
  84. */
  85. public function data_add($data) {
  86. $save_data = array(
  87. 'name' => trim($data['name']),
  88. 'img' => trim($data['img']),
  89. 'city_id' => intval($data['city_id']),
  90. 'address' => trim($data['address']),
  91. 'date' => trim($data['date']),
  92. 'is_new' => intval($data['is_new']),
  93. 's_time' => trim($data['s_time']),
  94. 'e_time' => trim($data['e_time']),
  95. 'tel' => trim($data['tel']),
  96. 'status' => self::status_off,
  97. );
  98. $result = $this->check_edit_data($save_data);
  99. if ($result['code'] == false) { //验证的数据不合格
  100. return array('code' => false, 'msg' => $result['msg']);
  101. }
  102. //处理图片
  103. $Common = new \Common\Common\Common();
  104. if ('data:image' == substr($save_data['img'], 0, 10)) {
  105. $save_data['img'] = $Common->base64_upyun($save_data['img']);
  106. }
  107. $id = $this->data($save_data)->add();
  108. if ($result == false) { //录入数据库失败
  109. return array('code' => false, 'msg' => '系统出错,请重试');
  110. }
  111. return array('code' => true, 'msg' => '操作成功', 'id' => $id);
  112. }
  113. /**
  114. * 编辑数据
  115. * @author: linch
  116. * @param $data
  117. * @return bool
  118. */
  119. public function data_edit($data) {
  120. $id = intval($data['id']);
  121. $save_data = array(
  122. 'name' => trim($data['name']),
  123. 'img' => trim($data['img']),
  124. 'city_id' => intval($data['city_id']),
  125. 'date' => trim($data['date']),
  126. 'is_new' => intval($data['is_new']),
  127. 'address' => trim($data['address']),
  128. 's_time' => trim($data['s_time']),
  129. 'e_time' => trim($data['e_time']),
  130. 'tel' => trim($data['tel']),
  131. );
  132. $result = $this->check_edit_data($save_data);
  133. if ($result['code'] == false) { //验证的数据不合格
  134. return array('code' => false, 'msg' => $result['msg']);
  135. }
  136. //处理图片
  137. $Common = new \Common\Common\Common();
  138. if ('data:image' == substr($save_data['img'], 0, 10)) {
  139. $save_data['img'] = $Common->base64_upyun($save_data['img']);
  140. }
  141. $result = $this->where(array('id' => $id))->data($save_data)->save();
  142. if ($result === false) { //录入数据库失败
  143. return array('code' => false, 'msg' => '系统出错,请重试');
  144. }
  145. return array('code' => true, 'msg' => '操作成功');
  146. }
  147. /**
  148. * 设置删除状态
  149. * @author: linch
  150. * @param $id
  151. * @return bool
  152. */
  153. public function data_del($id) {
  154. $result = $this->where(array('id' => $id))->setField(array('status' => self::status_del));
  155. return $result;
  156. }
  157. /**
  158. * 设置上线
  159. * @author: linch
  160. * @param $id
  161. * @return bool
  162. */
  163. public function data_set_on($id) {
  164. $result = $this->where(array('id' => $id))->setField(array('status' => self::status_on));
  165. return $result;
  166. }
  167. /**
  168. * 设置下线
  169. * @author: linch
  170. * @param $id
  171. * @return bool
  172. */
  173. public function data_set_off($id) {
  174. $result = $this->where(array('id' => $id))->setField(array('status' => self::status_off));
  175. return $result;
  176. }
  177. }