logistics/app/adminapi/lists/vehicle/VehicleLists.php
2023-09-21 18:50:43 +08:00

88 lines
2.8 KiB
PHP

<?php
namespace app\adminapi\lists\vehicle;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\logistics\Logistics;
use app\common\model\logistics\Product;
use app\common\model\platform\Platform;
use app\common\model\vehicle\Vehicle;
use app\common\lists\ListsSearchInterface;
use app\common\model\vehicle\VehicleRent;
/**
* Vehicle列表
* Class VehicleLists
* @package app\adminapi\lists
*/
class VehicleLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/08/17 09:23
*/
public function setSearch(): array
{
return [
'%like%' => ['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)->where('status','<>',3)
->field(['id','license', 'gps_imei','pic', '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'])->findOrEmpty();
$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();
}
}