logistics/app/adminapi/lists/vehicle/VehicleLists.php

96 lines
3.3 KiB
PHP
Raw Normal View History

2023-08-17 11:30:23 +08:00
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists\vehicle;
use app\adminapi\lists\BaseAdminDataLists;
2023-08-21 16:16:22 +08:00
use app\common\model\logistics\Logistics;
use app\common\model\logistics\Product;
2023-08-17 11:30:23 +08:00
use app\common\model\vehicle\Vehicle;
use app\common\lists\ListsSearchInterface;
2023-08-21 16:16:22 +08:00
use app\common\model\vehicle\VehicleRent;
2023-08-17 11:30:23 +08:00
/**
* 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 [
2023-08-17 14:08:50 +08:00
'%like%' => ['gps_imei'],
'=' => ['license','status'],
2023-08-17 11:30:23 +08:00
];
}
/**
* @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
{
2023-08-17 14:08:50 +08:00
return Vehicle::where($this->searchWhere)->where('is_del',0)
2023-08-17 11:30:23 +08:00
->field(['id', 'license', 'gps_imei', 'gps_carid', 'status'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
2023-08-17 14:08:50 +08:00
->each(function($item){
$item['status_name'] = $item->status_name;
2023-08-21 16:16:22 +08:00
$item['rent'] = VehicleRent::where('car_id',$item['id'])->find();
$product_count = 0;
if($item['rent'] && $item['rent']['lessee_two_flag'] == 1){
//获取物流信息
$logistics = Logistics::field('order_id')->where('courier_id',$item['rent']['lessee_two_user_id'])->where('status',1)->select()->toArray();
foreach($logistics as $v){
//获取订单信息
Product::field('product_num')->where('order_id', $v['order_id'])->select()->each(function($pro_item) use(&$product_count){
$product_count += $pro_item['product_num'];
})->toArray();
}
}
$item['goods_total'] = $product_count;
return $item;
2023-08-17 14:08:50 +08:00
})
2023-08-17 11:30:23 +08:00
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2023/08/17 09:23
*/
public function count(): int
{
return Vehicle::where($this->searchWhere)->count();
}
}