params['coach_id'] ?? 0; if($coachId){ $shopId = Coach::where(['id'=>$coachId])->value('shop_id'); } if($shopId){ $where[] = ['shop_id','in',[0,$shopId]]; }else{ $where[] = ['shop_id','=',0]; } if (isset($this->params['name']) && $this->params['name'] != '') { $where[] = ['name','like','%'.$this->params['name'].'%']; } if (isset($this->params['status']) && $this->params['status'] != '') { switch ($this->params['status']) { case 1://销售中 $where[] = ['status','=',1]; break; case 2://仓库中 $where[] = ['status','=',0]; break; } } $auditStatus = $this->params['audit_status'] ?? 1; if('' != $auditStatus){ $where[] = ['audit_status','=',$auditStatus]; } if (isset($this->params['category_id']) && $this->params['category_id']) { $categoryIds = []; foreach ($this->params['category_id'] as $categoryId){ $categoryIds[] = $categoryId; $category = GoodsCategory::where(['id'=>$categoryId])->findOrEmpty(); if(1 == $category['level']){ $categoryId = GoodsCategory::where(['pid'=>$category['id']])->column('id'); $categoryIds = array_merge($categoryId,$categoryIds); } } $where[] = ['category_id','in',implode(',',$categoryIds)]; } if (isset($this->params['second_id']) && $this->params['second_id']) { $where[] = ['category_id','=',$this->params['second_id']]; }elseif (isset($this->params['first_id']) && $this->params['first_id']) { $category_lists = GoodsCategory::select()->toArray(); $category_arr = []; foreach ($category_lists as $item) { $category_arr[$item['pid']][] = $item['id']; } $ids_arr = $category_arr[$this->params['first_id']] ?? ''; $ids = $this->params['first_id']; if ($ids_arr) { $ids = implode(',',$ids_arr).','.$this->params['first_id']; } $where[] = ['category_id','in',$ids]; } if(isset($this->params['skill_id']) && $this->params['skill_id']){ $goodsIds = GoodsSkillIndex::where(['skill_id'=>$this->params['skill_id']])->column('goods_id'); $where[] = ['id','in',$goodsIds]; } return $where; } /** * @notes 服务列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author ljj * @date 2022/2/9 11:23 上午 */ public function lists(): array { $where = self::where(); $lists = (new Goods()) ->field('id,name,category_id,image,price,status,sort,order_num,create_time') ->order(['sort'=>'desc','id'=>'desc']) ->where($where) ->append(['category_desc','status_desc','skill_desc']) ->limit($this->limitOffset, $this->limitLength) ->select() ->toArray(); return $lists; } /** * @notes 服务数量 * @return int * @author ljj * @date 2022/2/9 11:24 上午 */ public function count(): int { $where = self::where(); return (new Goods())->where($where)->count(); } /** * @notes 服务数据统计 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author ljj * @date 2022/2/21 5:16 下午 */ public function extend(): array { $where = []; $where[] = ['shop_id','=',0]; if (isset($this->params['name']) && $this->params['name'] != '') { $where[] = ['name','like','%'.$this->params['name'].'%']; } if(isset($this->params['audit_status']) && '' != $this->params['audit_status']){ $where[] = ['audit_status','=',$this->params['audit_status']]; } if (isset($this->params['second_id']) && $this->params['second_id']) { $where[] = ['category_id','=',$this->params['second_id']]; }elseif (isset($this->params['first_id']) && $this->params['first_id']) { $category_lists = GoodsCategory::select()->toArray(); $category_arr = []; foreach ($category_lists as $item) { $category_arr[$item['pid']][] = $item['id']; } $ids_arr = $category_arr[$this->params['first_id']] ?? ''; $ids = $this->params['first_id']; if ($ids_arr) { $ids = implode(',',$ids_arr).','.$this->params['first_id']; } $where[] = ['category_id','in',$ids]; } if(isset($this->params['skill_id']) && $this->params['skill_id']){ $goodsIds = GoodsSkillIndex::where(['skill_id'=>$this->params['skill_id']])->column('goods_id'); $where[] = ['id','in',$goodsIds]; } $lists = (new Goods())->where($where) ->select() ->toArray(); $data['all_count'] = 0; $data['SHELVE'] = 0; $data['UNSHELVE'] = 0; foreach ($lists as $val) { $data['all_count'] += 1; if ($val['status'] == 1) { $data['SHELVE'] += 1; } if ($val['status'] == 0) { $data['UNSHELVE'] += 1; } } return $data; } }