123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace Common\Model;
- use Common\Model\BaseModel;
- /**
- * 官网门店
- * @author: linch
- * Class HomeStoresModel
- * @package Common\Model
- */
- class HomeStoresModel extends BaseModel
- {
- //软删状态
- const status_del = 0; //删除
- const status_on = 1; //正常
- const status_off = 2; //下架
- //新旧状态
- const new_off = 0; // 旧店
- const new_on = 1; // 新店
- protected $mod;
- public function __construct() {
- parent::__construct();
- $this->mod = M('home_stores');
- }
- /**
- * 获取数据
- * @author: linch
- */
- public function get_data($search, $page_num, $page_size, $type = 0) {
- $where = array(
- 'status' => self::status_on,
- );
- if ($search['city_id'] > 0) {
- $where['city_id'] = $search['city_id'];
- }
- if (isset($search['is_new'])) {
- $where['is_new'] = $search['is_new'];
- }
- $order = 'id asc';
- $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 = new \Common\Common\util\PageO($count, $page_size);
- // $Page = new \Think\Page($count, $page_size);
- $pager = $Page->show();
- if (($type == 1) && count($list) < $page_size) {
- $list[] = $this->get_default_store();
- }
- $store_id_arr = array();
- foreach ($list as $k => $v) {
- $store_id_arr[] = $v['id'];
- $list[$k]['have_news'] = 0;
- }
- //查看文章是否有分店的
- if (!empty($store_id_arr)) {
- $news_model = new \Common\Model\HomeNewModel();
- $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();
- $news_data = array();
- foreach ($news_temp as $k => $v) {
- $news_data[$v['store_id']] = $v;
- }
- }
- //整合数据
- foreach ($list as $k => $v) {
- if (!empty($news_data[$v['id']])) {
- $list[$k]['have_news'] = 1;
- }
- }
- $data = array(
- 'list' => $list,
- 'count' => $count,
- 'pager' => $pager,
- );
- return $data;
- }
- /**
- * 获取填充数据
- * @author: linch
- */
- public function get_default_store() {
- return array(
- 'name' => '',
- 'address' => '',
- 'img' => 'https://img.x-motion.cn/home/image/store_join.jpg',
- 'date' => '',
- 'time' => '',
- 'tel' => '',
- );
- }
- }
|