diff --git a/api/controllers/wxapp/material/Home.php b/api/controllers/wxapp/material/Home.php index c1077388..0c0b0270 100644 --- a/api/controllers/wxapp/material/Home.php +++ b/api/controllers/wxapp/material/Home.php @@ -48,10 +48,22 @@ class Home extends Wxapp $jsondata['auto_brands'] && $brand_ids = implode($jsondata['auto_brands'], ','); } } - $brand_ids && $list = $this->mdAutoBrand->select(array("id in ({$brand_ids})" => null, 'status' => 1), "id desc", 0, 0, 'id,name'); -// foreach ($this->mdTemplate->typeAry() as $key => $value) { -//// $list[] = array('id' => $key, 'name' => $value); -//// } + if ($brand_ids) { + $res = $this->mdAutoBrand->select(array("id in ({$brand_ids})" => null, 'status' => 1), "id desc", 0, 0, 'id,name'); + foreach ($res as $key => $value) { + $brand_id = $value['id'] . ','; + $where = array('app_id' => $this->app_id, 'type in(4,1)' => null, "brand_ids like '%{$brand_id}%'" => null, 'status' => 1); + $total = $this->mdTemplate->count($where); + if ($total > 0) { + $value['total'] = $total; + $list[] = $value; + } + } + if ($list) { + $timeKey = array_column($list, 'total'); //取出数组中total的一列,返回一维数组 + array_multisort($timeKey, SORT_DESC, $list);//排序,根据$total 排序 + } + } $this->data['title'] = '推广素材'; $this->data['list'] = $list; return $list; @@ -69,31 +81,31 @@ class Home extends Wxapp $page = $this->input_param('page'); $size = $this->input_param('size'); $brand_id = intval($this->input_param('type')); - if (!$brand_id) { - throw new Hd_exception('参数错误', API_CODE_FAIL); - } - !$page && $page = 1; - !$size && $size = 10; - $brand_id = $brand_id . ','; $lists = array(); - $where = array('app_id' => $this->app_id, 'type in(4,1)' => null, "brand_ids like '%{$brand_id}%'" => null, 'status' => 1); - $total = $this->mdTemplate->count($where); - $fileds = 'id,title,cover,json_data'; - $res = $this->mdTemplate->select($where, "id desc", $page, $size, $fileds); - foreach ($res as $key2 => $value2) { - $setValue = array(); - $moments = ''; - $re_biz = $this->mdMaterialBiz->get(array('app_id' => $this->app_id, 't_id' => $value2['id'], 'biz_id' => $this->biz_id)); - $setValue['id'] = intval($value2['id']); - $setValue['title'] = $value2['title']; - $setValue['cover'] = $value2['cover'] ? build_qiniu_image_url($value2['cover']) : ''; - $setValue['if_add'] = $re_biz ? 1 : 0; - if ($value2['json_data']) { - $json_data = json_decode($value2['json_data'], true); - $json_data['moments'] && $moments = $json_data['moments']; + $total = 0; + if ($brand_id) { + !$page && $page = 1; + !$size && $size = 8; + $brand_id = $brand_id . ','; + $where = array('app_id' => $this->app_id, 'type in(4,1)' => null, "brand_ids like '%{$brand_id}%'" => null, 'status' => 1); + $total = $this->mdTemplate->count($where); + $fileds = 'id,title,cover,json_data'; + $res = $this->mdTemplate->select($where, "id desc", $page, $size, $fileds); + foreach ($res as $key2 => $value2) { + $setValue = array(); + $moments = ''; + $re_biz = $this->mdMaterialBiz->get(array('app_id' => $this->app_id, 't_id' => $value2['id'], 'biz_id' => $this->biz_id)); + $setValue['id'] = intval($value2['id']); + $setValue['title'] = $value2['title']; + $setValue['cover'] = $value2['cover'] ? build_qiniu_image_url($value2['cover']) : ''; + $setValue['if_add'] = $re_biz ? 1 : 0; + if ($value2['json_data']) { + $json_data = json_decode($value2['json_data'], true); + $json_data['moments'] && $moments = $json_data['moments']; + } + $setValue['moments'] = $moments; + $lists[] = $setValue; } - $setValue['moments'] = $moments; - $lists[] = $setValue; } $this->data['show'] = 'image'; $this->data['list'] = $lists;