['gps_imei'], '=' => ['license','status','type'], ]; } /** * @notes 获取列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author likeadmin * @date 2023/08/17 09:23 */ public function lists(): array { return Vehicle::where($this->searchWhere) ->field(['id','license', 'gps_imei', 'status','type']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() ->each(function($item){ $item['status_name'] = $item->status_name; $item['type_name'] = $item->type_name; $item['mileage'] = 0; if($item['status'] == 2){ $item['rent_info'] = VehicleRent::where('car_id',$item['id'])->find(); $goodsTotal = 0; Logistics::field('order_id')->where('courier_id',$item['rent_info']['use_user_id'])->where('status',1)->select()->each(function($case)use(&$goodsTotal){ $count = 0; Product::field('product_num,cart_info')->where('order_id', $case['order_id'])->select()->each(function($pro_item)use(&$count){ $pro_item['cart_info'] = json_decode($pro_item['cart_info'], true); $count += $pro_item['product_num']; unset($pro_item['cart_info']); })->toArray(); $case['count'] = $count; $goodsTotal += $case['count']; })->toArray(); $item['goodsTotal'] = $goodsTotal; } return $item; }) ->toArray(); } /** * @notes 获取数量 * @return int * @author likeadmin * @date 2023/08/17 09:23 */ public function count(): int { return Vehicle::where($this->searchWhere)->count(); } }