Sfoglia il codice sorgente

安卓显示计算专线费

haozi 4 anni fa
parent
commit
b8a9e87a78

+ 9 - 3
app/Http/ApiControllers/WaybillController.php

@@ -10,6 +10,7 @@ use App\Http\Requests\Api\WaybillDispatch;
 use App\Services\WaybillService;
 use App\Waybill;
 use Illuminate\Database\Eloquent\Collection;
+use Illuminate\Support\Facades\DB;
 
 class WaybillController
 {
@@ -72,11 +73,16 @@ class WaybillController
         if ($deliverAt)$query->where("deliver_at","like",$deliverAt."%");
         /** @var Collection $waybills */
         $waybills = $query->paginate($paginate,'*', 'page',$page)->append(["carrier_name","amount_unit_name","remove_relation"]);
-        $result = null;
+        $result = [];
         if ($waybills->count()>0){
             $startDate = substr($waybills->first()->deliver_at,0,10);
             $endDate = substr($waybills->last()->deliver_at,0,10);
-            $result = ["2021-10-08"=>2];
+            $sql = <<<sql
+select sum(pick_up_fee) sum,date_format(deliver_at, '%Y-%m-%d') date from waybills where deliver_at between '{$startDate}' and '{$endDate}' group by date
+sql;
+            foreach (DB::select(DB::raw($sql)) as $item){
+                $result[$item->date] = $item->sum!==null ? (double)$item->sum : 0.0;
+            }
         }
         $this->response(["waybills"=>$waybills,"mapping"=>$result]);
     }
@@ -146,7 +152,7 @@ class WaybillController
         if (!$deliverAt || !$fee || !is_numeric($fee) || !$fee<0)
             $this->response(false,400,"非法参数或不满足需求");
         $param=array('screenDate'=>$deliverAt,'billing'=>$fee);
-        $waybills=app('waybillService')->dailyBilling($param);
+        $waybills=app('waybillService')->dailyBilling($param,true);
         if ($waybills===0 || $waybills===1 || !isset($waybills)) $this->response(false);
         $this->response(true);
     }

+ 4 - 3
app/Services/WaybillService.php

@@ -149,7 +149,7 @@ class WaybillService
         $waybills = $this->conditionQuery($param);
         return $waybills->get();
     }
-    public function dailyBilling(array $param){
+    public function dailyBilling(array $param, bool $isOnlyLogistic = false){
         if (($param['screenDate']??false)==false || ($param['billing']??false)==false) return 0; //入参错误
         $waybills = Waybill::query()->with(['owner','logistic','originationCity','destinationCity.parent',
             'uploadFiles','amountUnit','warehouseWeightUnit','carrierWeightUnit','district','order',
@@ -161,8 +161,9 @@ class WaybillService
             ->orderBy('waybills.id','desc')
             ->where('waybills.type','专线')
             ->where('waybills.amount','>',0)
-            ->where('waybills.deliver_at','like',$param['screenDate'].'%')
-            ->get();
+            ->where('waybills.deliver_at','like',$param['screenDate'].'%');
+        if ($isOnlyLogistic)$waybills->whereIn("logistic_id",app("LogisticService")->getQuery());
+        $waybills = $waybills->get();
         if ($waybills->isEmpty()) return 1;//无数据
         foreach ($waybills as $waybill){
             if (!$waybill['carrier_weight_other'] && !$waybill['carrier_weight']) return null;