| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- // +----------------------------------------------------------------------
- // | likeadmin快速开发前后端分离管理后台(PHP版)
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
- // | github下载:https://github.com/likeshop-github/likeadmin
- // | 访问官网:https://www.likeadmin.cn
- // | likeadmin团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeadminTeam
- // +----------------------------------------------------------------------
- namespace app\adminapi\lists\agricultural_machinery;
- use app\adminapi\lists\BaseAdminDataLists;
- use app\common\lists\ListsSearchInterface;
- use app\common\lists\ListsSortInterface;
- use app\common\model\asset\AssetArea;
- use app\common\model\supply_demand\SupplyDemandInfo;
- use app\common\model\supply_demand\SupplyDemandCate;
- /**
- * 供需列表
- * Class ArticleCateLists
- * @package app\adminapi\lists\article
- */
- class SupplyDemandLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface
- {
- /**
- * @notes 设置搜索条件
- * @return array
- * @author heshihu
- * @date 2022/2/8 18:39
- */
- public function setSearch(): array
- {
- return [
- '%like%' => ['title','mobile'],
- '=' => ['type']
- ];
- }
- /**
- * @notes 自定查询条件
- * @return array
- * @author 段誉
- * @date 2022/10/25 16:53
- */
- public function queryWhere()
- {
- $where = [];
- if (isset($this->params['status']) && $this->params['status']) {
- $status = $this->params['status'];
- $where[] = ['status', '=',$status];
- }
- if (isset($this->params['type']) && $this->params['type']) {
- $type = $this->params['type'];
- $where[] = ['type', '=',$type];
- }
- if (isset($this->params['cate_id']) && $this->params['cate_id']) {
- $cate_id_arr = [];
- $cate_id = $this->params['cate_id'];
- $cate_info = SupplyDemandCate::find($cate_id);
- if($cate_info){
- array_push($cate_id_arr,$cate_id);
- if($cate_info['level'] == 1){
- $children_cate_info = SupplyDemandCate::where(['pid'=>$cate_id])->field('id,pid')->select()->toArray();
- if($children_cate_info){
- $children_cate = array_column($children_cate_info,'id');
- $cate_id_arr = array_merge($cate_id_arr,$children_cate);
- }
- }
- $where[] = ['cate_id', 'in',$cate_id_arr];
- }
- }
- if (isset($this->params['area_id']) && $this->params['area_id']) {
- // $area_id = $this->params['area_id'];
- // $where[] = ['area_id', '=',$area_id];
- $area_id_arr = [];
- $area_id = $this->params['area_id'];
- $area_info = AssetArea::find($area_id);
- if($area_info){
- array_push($area_id_arr,$area_id);
- if($area_info['level'] == 1){
- $children_area_info = AssetArea::where(['pid'=>$area_id])->field('id,pid')->select()->toArray();
- if($children_area_info){
- $children_area = array_column($children_area_info,'id');
- $area_id_arr=array_merge($area_id_arr,$children_area);
- }
- }
- }
- $where[] = ['area_id', 'in',$area_id_arr];
- }
- return $where;
- }
- /**
- * @notes 设置支持排序字段
- * @return array
- * @author heshihu
- * @date 2022/2/9 15:11
- */
- public function setSortFields(): array
- {
- return [ 'id' => 'id'];
- }
- /**
- * @notes 设置默认排序
- * @return array
- * @author heshihu
- * @date 2022/2/9 15:08
- */
- public function setDefaultOrder(): array
- {
- return ['id' => 'desc'];
- }
- /**
- * @notes 获取管理列表
- * @return array
- * @author heshihu
- * @date 2022/2/21 17:11
- */
- public function lists(): array
- {
- $supplyDemandLists = SupplyDemandInfo::where($this->searchWhere)
- ->where($this->queryWhere())
- ->limit($this->limitOffset, $this->limitLength)
- ->order($this->sortOrder)
- ->append(['status_desc','type_desc','user','area'])
- ->select()
- ->toArray();
- return $supplyDemandLists;
- }
- /**
- * @notes 获取数量
- * @return int
- * @author heshihu
- * @date 2022/2/9 15:12
- */
- public function count(): int
- {
- return SupplyDemandInfo::where($this->searchWhere)->where($this->queryWhere())->count();
- }
- public function extend()
- {
- return [];
- }
- }
|