HomeStoresModel.class.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace Common\Model;
  3. use Common\Model\BaseModel;
  4. /**
  5. * 官网门店
  6. * @author: linch
  7. * Class HomeStoresModel
  8. * @package Common\Model
  9. */
  10. class HomeStoresModel extends BaseModel
  11. {
  12. //软删状态
  13. const status_del = 0; //删除
  14. const status_on = 1; //正常
  15. const status_off = 2; //下架
  16. //新旧状态
  17. const new_off = 0; // 旧店
  18. const new_on = 1; // 新店
  19. protected $mod;
  20. public function __construct() {
  21. parent::__construct();
  22. $this->mod = M('home_stores');
  23. }
  24. /**
  25. * 获取数据
  26. * @author: linch
  27. */
  28. public function get_data($search, $page_num, $page_size, $type = 0) {
  29. $where = array(
  30. 'status' => self::status_on,
  31. );
  32. if ($search['city_id'] > 0) {
  33. $where['city_id'] = $search['city_id'];
  34. }
  35. if (isset($search['is_new'])) {
  36. $where['is_new'] = $search['is_new'];
  37. }
  38. $order = 'id asc';
  39. $limit = ($page_num - 1) * $page_size . ' ,' . $page_size;
  40. $field = '*';
  41. $list = $this->where($where)->order($order)->field($field)->limit($limit)->select();
  42. $count = $this->where($where)->count();
  43. $Page = new \Common\Common\util\PageO($count, $page_size);
  44. // $Page = new \Think\Page($count, $page_size);
  45. $pager = $Page->show();
  46. if (($type == 1) && count($list) < $page_size) {
  47. $list[] = $this->get_default_store();
  48. }
  49. $store_id_arr = array();
  50. foreach ($list as $k => $v) {
  51. $store_id_arr[] = $v['id'];
  52. $list[$k]['have_news'] = 0;
  53. }
  54. //查看文章是否有分店的
  55. if (!empty($store_id_arr)) {
  56. $news_model = new \Common\Model\HomeNewModel();
  57. $news_temp = $news_model->field('distinct(store_id) as store_id')->where(array('store_id' => array('in', $store_id_arr), 'status' => $news_model::status_on))->select();
  58. $news_data = array();
  59. foreach ($news_temp as $k => $v) {
  60. $news_data[$v['store_id']] = $v;
  61. }
  62. }
  63. //整合数据
  64. foreach ($list as $k => $v) {
  65. if (!empty($news_data[$v['id']])) {
  66. $list[$k]['have_news'] = 1;
  67. }
  68. }
  69. $data = array(
  70. 'list' => $list,
  71. 'count' => $count,
  72. 'pager' => $pager,
  73. );
  74. return $data;
  75. }
  76. /**
  77. * 获取填充数据
  78. * @author: linch
  79. */
  80. public function get_default_store() {
  81. return array(
  82. 'name' => '',
  83. 'address' => '',
  84. 'img' => 'https://img.x-motion.cn/home/image/store_join.jpg',
  85. 'date' => '',
  86. 'time' => '',
  87. 'tel' => '',
  88. );
  89. }
  90. }