From 8f44220de937b30fa3ffff0dc89ce69ea792f54b Mon Sep 17 00:00:00 2001 From: unknown <736250432@qq.com> Date: Mon, 21 Aug 2023 16:16:22 +0800 Subject: [PATCH] add isCourier api --- app/adminapi/lists/vehicle/VehicleLists.php | 18 ++++- app/api/controller/LogisticsController.php | 18 ++++- app/api/controller/VehicleController.php | 31 +++++++- app/api/logic/LogisticsLogic.php | 12 ++- app/api/logic/VehicleLogic.php | 86 +++++++++++++++++++-- app/api/route/app.php | 5 +- app/common/model/vehicle/VehicleRent.php | 30 +++++++ 7 files changed, 184 insertions(+), 16 deletions(-) diff --git a/app/adminapi/lists/vehicle/VehicleLists.php b/app/adminapi/lists/vehicle/VehicleLists.php index 0f6f840b..f2fd493f 100644 --- a/app/adminapi/lists/vehicle/VehicleLists.php +++ b/app/adminapi/lists/vehicle/VehicleLists.php @@ -16,9 +16,11 @@ 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\vehicle\Vehicle; use app\common\lists\ListsSearchInterface; - +use app\common\model\vehicle\VehicleRent; /** @@ -61,6 +63,20 @@ class VehicleLists extends BaseAdminDataLists implements ListsSearchInterface ->select() ->each(function($item){ $item['status_name'] = $item->status_name; + $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; }) ->toArray(); } diff --git a/app/api/controller/LogisticsController.php b/app/api/controller/LogisticsController.php index 311f7071..33e1f06e 100755 --- a/app/api/controller/LogisticsController.php +++ b/app/api/controller/LogisticsController.php @@ -24,7 +24,7 @@ use app\api\logic\LogisticsLogic; class LogisticsController extends BaseApiController { - public array $notNeedLogin = ['courierLogisticsList','captainLogisticsList','courierLogisticsDetail','userLogisticsDetail','logisticsCreate','courierTakeGoods','courierCompleteDelivery','userConfirmReceipt','userCancelOrder','courierData','sendMessageToApp']; + public array $notNeedLogin = ['courierLogisticsList','captainLogisticsList','courierLogisticsDetail','userLogisticsDetail','logisticsCreate','courierTakeGoods','courierCompleteDelivery','userConfirmReceipt','userCancelOrder','courierData','sendMessageToApp','hasCourier']; /* * 获取配送员物流信息列表 @@ -153,4 +153,20 @@ class LogisticsController extends BaseApiController return $this->data(LogisticsLogic::uDetail($params)); } + //获取配送员 + public function hasCourier(): \think\response\Json { + //获取参数 + $param = $this->request->get('user_address_code'); + if(empty($param)) { + return $this->fail('参数错误'); + } + $result = LogisticsLogic::getCoutier($param); + //返回数据 + if($result){ + return $this->success('有配送员'); + }else{ + return $this->fail('无配送员'); + } + } + } \ No newline at end of file diff --git a/app/api/controller/VehicleController.php b/app/api/controller/VehicleController.php index 6fb52a1c..7e738526 100644 --- a/app/api/controller/VehicleController.php +++ b/app/api/controller/VehicleController.php @@ -23,7 +23,7 @@ use app\api\logic\VehicleLogic; */ class VehicleController extends BaseApiController { - public array $notNeedLogin = ['tricycle','multipleRent']; + public array $notNeedLogin = ['tricycle','multipleRent','singleRent']; /* * 获取去未出租的三轮车列表 @@ -42,9 +42,9 @@ class VehicleController extends BaseApiController */ public function multipleRent() { //获取参数 - $params = $this->request->post(['company_id','tricycle_ids','start_time','end_time']); + $params = $this->request->post(['company_id','car_ids','start_time','end_time']); //验证参数 - if(empty($params['company_id']) || empty($params['tricycle_ids']) || empty($params['start_time']) || empty($params['end_time'])) { + if(empty($params['company_id']) || empty($params['car_ids']) || empty($params['start_time']) || empty($params['end_time'])) { return $this->fail('缺少必要参数'); } if(!checkDateIsValid($params['start_time']) || !checkDateIsValid($params['end_time'])){ @@ -54,7 +54,30 @@ class VehicleController extends BaseApiController $result = VehicleLogic::oneLevelRent($params); //返回结果 if($result['code'] == 1){ - return $this->success('操作成功'); + return $this->success($result['msg']); + }else{ + return $this->fail($result['msg']); + } + } + + /* + * 三轮车单辆出租 + */ + public function singleRent() { + //获取参数 + $params = $this->request->post(['lessor_company_id','tenant_company_id','car_id','start_time','end_time']); + //验证参数 + if(empty($params['lessor_company_id']) || empty($params['tenant_company_id']) || empty($params['car_id']) || empty($params['start_time']) || empty($params['end_time'])){ + return $this->fail('缺少必要参数'); + } + if(!checkDateIsValid($params['start_time']) || !checkDateIsValid($params['end_time'])){ + return $this->fail('时间格式错误'); + } + //写入数据 + $result = VehicleLogic::twoLevelRent($params); + //返回结果 + if($result['code'] == 1){ + return $this->success($result['msg']); }else{ return $this->fail($result['msg']); } diff --git a/app/api/logic/LogisticsLogic.php b/app/api/logic/LogisticsLogic.php index ae55f20c..af7bbcd7 100644 --- a/app/api/logic/LogisticsLogic.php +++ b/app/api/logic/LogisticsLogic.php @@ -173,7 +173,7 @@ class LogisticsLogic extends BaseLogic //查找商家信息 $shop = Merchant::field('mer_id,mer_name,real_name,mer_phone,mer_address,long,lat')->where('mer_id',$order['mer_id'])->find(); //获取队长用户信息 - $captain = Courier::field('id,company_id,nickname,mobile')->where("CONCAT_WS(',',province,city,area,street,village,brigade) = '". $order['user_address_code']."'")->where('is_contract',1)->where('is_captain',1)->find(); + $captain = Courier::field('id,company_id,nickname,mobile')->where("CONCAT_WS(',',province,city,area,street,village,brigade) = '". $order['user_address_code']."'")->where('is_captain',1)->find(); if(!$captain) return ['code'=>0, 'msg'=>'无法确定所在小队']; //获取配送员信息 $courier = Company::field('company_name,user_id,master_name,master_phone')->where('id',$captain['company_id'])->find(); @@ -376,4 +376,14 @@ class LogisticsLogic extends BaseLogic } } + public static function getCoutier($code):bool { + //获取队长用户信息 + $captain = Courier::field('id,company_id,nickname,mobile')->where("CONCAT_WS(',',province,city,area,street,village,brigade) = '". $code ."'")->where('is_captain',1)->find(); + if(!$captain) return false; + //获取配送员信息 + $courier = Company::field('company_name,user_id,master_name,master_phone')->where('id',$captain['company_id'])->find(); + if(!$courier) return false; + return true; + } + } \ No newline at end of file diff --git a/app/api/logic/VehicleLogic.php b/app/api/logic/VehicleLogic.php index b2341728..e7521d16 100644 --- a/app/api/logic/VehicleLogic.php +++ b/app/api/logic/VehicleLogic.php @@ -18,6 +18,7 @@ namespace app\api\logic; use app\common\logic\BaseLogic; use app\common\model\vehicle\Company; use app\common\model\vehicle\Vehicle; +use app\common\model\vehicle\VehicleRent; /** @@ -27,12 +28,9 @@ use app\common\model\vehicle\Vehicle; */ class VehicleLogic extends BaseLogic { - /** + /* * 获取未出租的车辆列表 * @return array - * @throws \think\db\exception\DataNotFoundException - * @throws \think\db\exception\DbException - * @throws \think\db\exception\ModelNotFoundException */ public static function lists($params):array { $offset = !empty($params['page_no']) ? $params['page_no'] : 1; @@ -40,14 +38,88 @@ class VehicleLogic extends BaseLogic return Vehicle::field('id,license,gps_imei')->where('status',0)->where('is_del',0)->order('create_time desc')->page($offset, $length)->select()->toArray(); } + /* + * 批量出租(一级出租) + * return array + */ public static function oneLevelRent($params):array { //获取承租公司信息 - $company = Company::where('id',$params['company_id'])->find(); + $company = Company::field('id,user_id,company_name,master_name,master_phone')->where('id',$params['company_id'])->find(); //验证公司信息 if(!$company){ return ['code'=>0,'msg'=>'未找到承租公司']; } - $ids = explode(',',$params['tricycle_ids']); - dump($company['company_name'],$ids); + //设置数据 + $ids = explode(',',$params['car_ids']); + $data = []; + foreach($ids as $v){ + $car = Vehicle::where('id',$v)->find(); + if($car){ + $data[] = [ + 'car_id' => $v, + 'lessee_one_company_id' => $company['id'], + 'lessee_one_company' => $company['company_name'], + 'lessee_one_user_id' => $company['user_id'], + 'lessee_one_user' => $company['master_name'], + 'lessee_one_phone' => $company['master_phone'], + 'lessee_one_start_time' => strtotime($params['start_time']), + 'lessee_one_end_time' => strtotime($params['end_time']), + 'lessee_one_flag' => 1, + ]; + } + } + //写入数据 + VehicleRent::startTrans(); + try { + (new VehicleRent()) -> saveAll($data); + VehicleRent::commit(); + return ['code'=>1,'msg'=>'请求成功']; + }catch (\Exception $e) { + VehicleRent::rollback(); + return ['code'=>0,'msg'=>$e->getMessage()]; + } + } + + /* + * 单个出租(二级出租) + */ + public static function twoLevelRent($params):array { + //获取数据 + $rent = VehicleRent::where('car_id',$params['car_id'])->where('lessee_one_company_id',$params['lessor_company_id'])->find(); + if(!$rent){ + return ['code'=>0,'msg'=>'未找到车辆信息']; + } + //判断租赁时间 + if(strtotime($params['start_time']) < strtotime($rent['lessee_one_start_time']) || strtotime($params['end_time']) > strtotime($rent['lessee_one_end_time'])){ + return ['code'=>0,'msg'=>'租赁时间超出范围']; + } + //获取第二承租方公司信息 + $company = Company::field('id,user_id,company_name,master_name,master_phone')->where('id',$params['tenant_company_id'])->find(); + //验证公司信息 + if(!$company){ + return ['code'=>0,'msg'=>'未找到承租公司']; + } + //设置数据 + $data = [ + 'id' => $rent['id'], + 'lessee_two_company_id' => $company['id'], + 'lessee_two_company_name' => $company['company_name'], + 'lessee_two_user_id' => $company['user_id'], + 'lessee_two_user' => $company['master_name'], + 'lessee_two_phone' => $company['master_phone'], + 'lessee_two_start_time' => strtotime($params['start_time']), + 'lessee_two_end_time' => strtotime($params['end_time']), + 'lessee_two_flag' => 1, + ]; + //写入数据 + VehicleRent::startTrans(); + try { + VehicleRent::update($data); + VehicleRent::commit(); + return ['code'=>1,'msg'=>'请求成功']; + }catch (\Exception $e) { + VehicleRent::rollback(); + return ['code'=>0,'msg'=>$e->getMessage()]; + } } } diff --git a/app/api/route/app.php b/app/api/route/app.php index 5e5d764e..a072a9c8 100755 --- a/app/api/route/app.php +++ b/app/api/route/app.php @@ -21,7 +21,7 @@ Route::rule('confirmReceipt','Logistics/userConfirmReceipt','post'); Route::rule('cancelOrder','Logistics/userCancelOrder','post'); Route::rule('courierData','Logistics/courierData','get'); -Route::rule('userMessage','Logistics/sendMessageToApp','get'); +Route::rule('hasCourier','Logistics/hasCourier','get'); /*-------------------------------------------------------------------------------------------*/ @@ -32,4 +32,5 @@ Route::rule('getCarHistory','Gps/getCarHistory','get'); /*-------------------------------------------------------------------------------------------*/ Route::rule('tricycle','Vehicle/tricycle','get'); -Route::rule('multipleRent','Vehicle/multipleRent','post'); \ No newline at end of file +Route::rule('multipleRent','Vehicle/multipleRent','post'); +Route::rule('singleRent','Vehicle/singleRent','post'); \ No newline at end of file diff --git a/app/common/model/vehicle/VehicleRent.php b/app/common/model/vehicle/VehicleRent.php index ba3577f7..b069ec39 100644 --- a/app/common/model/vehicle/VehicleRent.php +++ b/app/common/model/vehicle/VehicleRent.php @@ -6,5 +6,35 @@ use app\common\model\BaseModel; class VehicleRent extends BaseModel { + public function getLesseeOneStartTimeAttr($value): string + { + if(empty($value)){ + return 0; + } + return date('Y-m-d',$value); + } + public function getLesseeOneEndTimeAttr($value): string + { + if(empty($value)){ + return 0; + } + return date('Y-m-d',$value); + } + + public function getLesseeTwoStartTimeAttr($value): string + { + if(empty($value)){ + return 0; + } + return date('Y-m-d',$value); + } + + public function getLesseeTwoEndTimeAttr($value): string + { + if(empty($value)){ + return 0; + } + return date('Y-m-d',$value); + } } \ No newline at end of file