['name', 'code', 'first_category_id', 'second_category_id', 'third_category_id', 'brand_id', 'supplier_id', 'status', 'image', 'video', 'poster', 'remark', 'content', 'sort', 'sales_sum', 'virtual_sales_sum', 'click_count', 'virtual_click', 'spec_type', 'max_price', 'min_price', 'market_price', 'stock', 'stock_warn', 'is_show_stock', 'free_shipping_type', 'free_shipping', 'free_shipping_template_id', 'is_commission', 'first_ratio', 'second_ratio', 'three_ratio', 'is_share_bouns', 'region_ratio', 'shareholder_ratio', 'is_new', 'is_best', 'is_like', 'is_team', 'is_integral', 'is_member', 'give_integral_type', 'give_integral', 'del', 'is_express', 'is_selffetch'], ]; } /** * @notes 获取列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author likeadmin * @date 2025/05/08 15:34 */ public function lists(): array { $data = Goods::where($this->searchWhere) ->field(['id', 'name', 'code', 'first_category_id', 'second_category_id', 'third_category_id', 'brand_id', 'supplier_id', 'status', 'image', 'video', 'poster', 'remark', 'content', 'sort', 'sales_sum', 'virtual_sales_sum', 'click_count', 'virtual_click', 'spec_type', 'max_price', 'min_price', 'market_price', 'stock', 'stock_warn', 'is_show_stock', 'free_shipping_type', 'free_shipping', 'free_shipping_template_id', 'is_commission', 'first_ratio', 'second_ratio', 'three_ratio', 'is_share_bouns', 'region_ratio', 'shareholder_ratio', 'is_new', 'is_best', 'is_like', 'is_team', 'is_integral', 'is_member', 'give_integral_type', 'give_integral', 'del', 'is_express', 'is_selffetch','cat_name','price','total_sales_sum']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() ->toArray(); $goods_category_list = Db::name('goods_category')->where(['del'=>0])->column('name','id'); foreach($data as &$item){ $item['cat_name'] = self::getCateName($goods_category_list, $item); $item['price'] = '¥'.$item['min_price']; if($item['spec_type'] == 2 && $item['max_price'] !== $item['min_price']){ $item['price'] = '¥'.$item['min_price'].'~'.'¥'.$item['max_price']; } $item['goods_image'] = Db::name('goods_image') ->where(['goods_id'=>$item['id']]) ->select() ->toArray(); } return $data; } public static function getCateName($cates, $item) { if(isset($cates[$item['third_category_id']])) { return $cates[$item['third_category_id']]; } if(isset($cates[$item['second_category_id']])) { return $cates[$item['second_category_id']]; } if(isset($cates[$item['first_category_id']])) { return $cates[$item['first_category_id']]; } return ''; } /** * @notes 获取数量 * @return int * @author likeadmin * @date 2025/05/08 15:34 */ public function count(): int { return Goods::where($this->searchWhere)->count(); } }