$params['license'], 'pic' => $params['pic'], 'gps_imei' => $params['gps_imei'], 'type' => 0, 'status' => 0, ]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 编辑 * @param array $params * @return bool * @author likeadmin * @date 2023/08/17 09:23 */ public static function edit(array $params): bool { Db::startTrans(); try { Vehicle::where('id', $params['id'])->update([ 'license' => $params['license'], 'pic' => $params['pic'], 'gps_imei' => $params['gps_imei'], 'type' => $params['type'], 'status' => $params['status'], ]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } /** * @notes 获取详情 * @param $params * @return array * @author likeadmin * @date 2023/08/17 09:23 */ public static function detail($params): array { $data = Vehicle::findOrEmpty($params['id']); $data['mileage'] = 0; //获取车辆运行轨迹 $gpsCarInfo = (new GpsLogic()) -> info($data['gps_imei']); if($gpsCarInfo['code'] == 0){ $data['track_info'] = []; $data['travel_info'] = []; }else{ //获取车辆行驶历史信息 $gpsCarHistory = (new GpsLogic()) -> history([ 'gps_car_id' => $gpsCarInfo['data']['carId'], 'start_time' => date('Y-m-d').' 00:00:00', // 'start_time' =>'2023-08-30 00:00:00', 'end_time' => date('Y-m-d').' 23:59:59' // 'end_time' => '2023-08-30 23:59:59' ]); $gpsCarHistoryData = []; if($gpsCarHistory&&$gpsCarHistory['code']==1){ foreach($gpsCarHistory['data'] as $k => $v){ $gpsCarHistoryData[$k]['lon'] = $v['lonc']; $gpsCarHistoryData[$k]['lat'] = $v['latc']; } } if(empty($gpsCarHistoryData)){ //获取车辆状态 $carStatus = (new GpsLogic()) -> status($gpsCarInfo['data']['carId']); if($carStatus && $gpsCarHistory['code']==1){ if(isset($carStatus['carStatus'])){ $gpsCarHistoryData[] = ['lat'=>$carStatus['data']['carStatus']['latc'],'lon'=>$carStatus['data']['carStatus']['lonc']]; } } } $data['track_info'] = $gpsCarHistory&&$gpsCarHistory['code']==1 ? $gpsCarHistoryData : []; //获取车辆使用情况 $travel = (new GpsLogic()) -> mileage($gpsCarInfo['data']['carId'],date('Y-m-d H:i:s',(time() - 604800)),date('Y-m-d').' 23:59:59'); $data['travel_info'] = $travel&&$travel['code'] == 1 ? $travel['data'] : []; } if($data['status'] == 2){ //获取租赁信息 $rentInfo = VehicleRent::where('car_id',$data['id'])->findOrEmpty()->toArray(); $contract = Contract::where('id',$rentInfo['contract_id'])->findOrEmpty(); $rentInfo['contract_file'] = $contract['file']; $data['rent_info'] = !empty($rentInfo) ? $rentInfo : []; //获取物流信息 $logistic = Logistics::field('order_id,order_sn,shop_name,user_name,receiver_address,qh_time,ps_time')->where('courier_id',$rentInfo['use_user_id'])->where('status',1)->limit(10)->select()->each(function($item){ $qhTime = !empty($item['qh_time']) ? strtotime($item['qh_time']) : time(); $diffTime = timeDiff($qhTime,time()); $item['diff_time'] = $diffTime['day'].'天'.$diffTime['hour'].'小时'.$diffTime['min'].'分钟'.$diffTime['sec'].'秒'; $product_count = 0; //获取产品信息 $item['products'] = Product::field('product_num,cart_info')->where('order_id', $item['order_id'])->select()->each(function($pro_item) use(&$product_count){ $pro_item['cart_info'] = json_decode($pro_item['cart_info'], true); $pro_item['goods_name'] = $pro_item['cart_info']['product']['store_name']; $pro_item['goods_unit'] = $pro_item['cart_info']['product']['unit_name']; $product_count += $pro_item['product_num']; unset($pro_item['cart_info']); return $pro_item; }); $item['product_count'] = $product_count; }); $data['logistic_info'] = !empty($logistic) ? $logistic : []; } return $data->toArray(); } public static function vehicleLogisticLists($params){ $pageNo = isset($params['page_no']) ? $params['page_no'] : 1; $pageSize = isset($params['page_size']) ? $params['page_size'] : 15; $info = Vehicle::field('id,license,status,type')->findOrEmpty($params['id'])->toArray(); $rent = VehicleRent::field('use_user_id,use_user_name,use_user_phone')->where('car_id',$info['id'])->findOrEmpty()->toArray(); $data = array_merge($info,$rent); if(!empty($rent)){ $data['total_package'] = Logistics::field('order_id')->where('courier_id',$data['use_user_id'])->where('status',1)->count(); $goodsTotal = 0; Logistics::field('order_id')->where('courier_id',$data['use_user_id'])->where('status',1)->select()->each(function($item)use(&$goodsTotal){ $count = 0; Product::field('product_num,cart_info')->where('order_id', $item['order_id'])->select()->each(function($pro_item)use(&$count){ $pro_item['cart_info'] = json_decode($pro_item['cart_info'], true); $pro_item['goods_name'] = $pro_item['cart_info']['product']['store_name']; $pro_item['goods_unit'] = $pro_item['cart_info']['product']['unit_name']; $count += $pro_item['product_num']; unset($pro_item['cart_info']); })->toArray(); $case['count'] = $count; $goodsTotal += $case['count']; }); $data['total_goods'] = $goodsTotal; //获取物流信息 $logistic = Logistics::field('order_id,order_sn,shop_name,user_name,receiver_address,qh_time,ps_time')->where('courier_id',$data['use_user_id'])->where('status',1)->page($pageNo,$pageSize)->order('qh_time desc')->select()->each(function($item){ $qhTime = !empty($item['qh_time']) ? strtotime($item['qh_time']) : time(); $diffTime = timeDiff($qhTime,time()); $item['diff_time'] = $diffTime['day'].'天'.$diffTime['hour'].'小时'.$diffTime['min'].'分钟'.$diffTime['sec'].'秒'; $product_count = 0; //获取产品信息 $item['products'] = Product::field('product_num,cart_info')->where('order_id', $item['order_id'])->select()->each(function($pro_item) use(&$product_count){ $pro_item['cart_info'] = json_decode($pro_item['cart_info'], true); $pro_item['goods_name'] = $pro_item['cart_info']['product']['store_name']; $pro_item['goods_unit'] = $pro_item['cart_info']['product']['unit_name']; $product_count += $pro_item['product_num']; unset($pro_item['cart_info']); return $pro_item; }); $item['product_count'] = $product_count; })->toArray(); }else{ $data['total_package'] = []; $data['total_goods'] = []; $logistic = []; } return ['basic'=>$data,'lists'=>$logistic,'count'=>$data['total_package'],'page_no'=>$pageNo,'page_size'=>$pageSize]; } public static function vehicleLogisticDetail($params){ $info = Vehicle::field('id,license,status,type')->findOrEmpty($params['car_id'])->toArray(); $rent = VehicleRent::field('use_user_id,use_user_name,use_user_phone')->where('car_id',$info['id'])->findOrEmpty()->toArray(); $logistic = Logistics::field('order_sn,user_name,receiver_address,shop_name,shop_address,create_time,qh_time')->where('courier_id',$rent['use_user_idgit'])->where('order_id',$params['order_id'])->findOrEmpty()->toArray(); $qhTime = !empty($logistic['qh_time']) ? strtotime($logistic['qh_time']) : time(); $diffTime = timeDiff($qhTime,time()); $logistic['diff_time'] = $diffTime['day'].'天'.$diffTime['hour'].'小时'.$diffTime['min'].'分钟'.$diffTime['sec'].'秒'; $basic = array_merge($info,$rent,$logistic); //获取商品 $goods = Product::field('product_num,cart_info')->where('order_id', $params['order_id'])->select()->each(function($pro_item){ $pro_item['cart_info'] = json_decode($pro_item['cart_info'], true); $pro_item['goods_name'] = $pro_item['cart_info']['product']['store_name']; $pro_item['goods_unit'] = $pro_item['cart_info']['product']['unit_name']; $pro_item['goods_image'] = $pro_item['cart_info']['product']['image']; $pro_item['goods_price'] = $pro_item['cart_info']['product']['price']; unset($pro_item['cart_info']); return $pro_item; }); return ['basic'=>$basic,'goods'=>$goods]; } }