['status'], ]; } /** * @notes 获取列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author admin * @date 2025/04/03 15:19 */ public function lists(): array { $store_name = $this->request->get('store_name'); if ($store_name) { $store_id = StoreProduct::where('store_name', 'like', '%' . $store_name . '%')->column('id'); $this->searchWhere[] = ['product_id', 'in', $store_id]; } if (!empty($this->params['start_time'])) { $this->searchWhere[] = ['create_time', '>=', strtotime($this->params['start_time'])]; } if (!empty($this->params['end_time'])) { $this->searchWhere[] = ['create_time', '<=', strtotime($this->params['end_time'])]; } $list = StoreProductPrice::where($this->searchWhere) ->field(['id', 'bhoid', 'offer_id', 'product_id', 'purchase_price', 'purchase_lv', 'purchase', 'cost_lv', 'cost', 'price_lv', 'price', 'vip_lv', 'vip_price', 'price_config', 'status', 'create_time', 'mark', 'warehouse_id']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($item) { $find = StoreProduct::with('unitName')->where('id', $item['product_id'])->field('image,purchase,cost,price,store_name,store_info,unit')->withTrashed()->find(); $item['warehouse'] = Warehouse::where('id', $item['warehouse_id'])->value('name'); $item['unit_name'] = $find['unitName']['name'] ?? ''; $item['store_name'] = $find['store_name']; $item['store_info'] = $find['store_info']; $item['image'] = $find['image']; $item['current_purchase'] = $find['purchase']; $item['current_cost'] = $find['cost']; $item['current_price'] = $find['price']; $item['status_name'] = $item['status'] == 0 ? "未设置" : "已设置"; }) ->toArray(); $productIds = array_unique(array_column($list, 'product_id')); $priceList = StoreProductPriceList::whereIn('product_id', $productIds)->select()->toArray(); $priceList = reset_index($priceList, 'product_id'); foreach ($list as &$item) { $productPrice = $priceList[$item['product_id']] ?? []; if (empty($productPrice) || $item['status'] == 1) { continue; } $priceArray = StoreProductPriceLogic::setProductPrice($item['purchase_price'], $productPrice); $item = array_merge($item, $priceArray); } return $list; } /** * @notes 获取数量 * @return int * @author admin * @date 2025/04/03 15:19 */ public function count(): int { return StoreProductPrice::where($this->searchWhere)->count(); } }