zhouzhendong пре 4 година
родитељ
комит
d2122e474d

+ 41 - 25
app/Http/Controllers/ControlPanelController.php

@@ -123,39 +123,42 @@ class ControlPanelController extends Controller
     {
         //转化为Carbon
         $start = Carbon::parse(request("start"));
-        $end = Carbon::parse(request("end"));
+        $end   = Carbon::parse(request("end"));
 
         //定义三个数组 空间换时间 避免结果集二次转换
         $title = []; //标题
         $data = []; //核心数据,二维数组
-        foreach (CarbonPeriod::create($start, $end) as $date) {
+        foreach (CarbonPeriod::create($start,$end) as $date){
             /** @var $date Carbon */
             $str = $date->format("Y-m-d");
-            $data[] = $this->getTargetData($str);
+            $data = $this->getTargetData($str);
             $title[] = $str;
         }
 
         //大于31天转换为月份显示
-        if ($end->diffInDays($start) > 31) {
+        if ($end->diffInDays($start) > 31){
             $title = [];
             $sign = []; //标记是否已被插入
             $dataTemp = []; //临时存储
 
-            foreach ($data as $datum) {
-                $month = substr($datum["date"], 0, 7);
-                if (!isset($sign[$month])) {
-                    $dataTemp[] = ["date" => $month, "total" => $datum["total"], "count" => $datum["count"], "value" => $datum["value"]];
+            foreach ($data as $datum){
+                $month = substr($datum["date"],0,7);
+                if (!isset($sign[$month])){
+                    $dataTemp[] = ["date"=>$month,"total"=>$datum["total"],"count"=>$datum["count"],"value"=>$datum["value"]];
                     $title[] = $month;
-                    $sign[$month] = count($dataTemp) - 1;
-                } else {
+                    $sign[$month] = count($dataTemp)-1;
+                }else{
                     $dataTemp[$sign[$month]]["total"] += $datum["total"];
                     $dataTemp[$sign[$month]]["count"] += $datum["count"];
-                    $dataTemp[$sign[$month]]["value"] = (string)($dataTemp[$sign[$month]]["total"] ? intval(($dataTemp[$sign[$month]]["count"] / $dataTemp[$sign[$month]]["total"]) * 100) : 0);
+                    $dataTemp[$sign[$month]]["value"] = (string)($dataTemp[$sign[$month]]["total"] ? intval(($dataTemp[$sign[$month]]["count"]/$dataTemp[$sign[$month]]["total"])*100) : 0);
                 }
             }
             $data = $dataTemp;
         }
-        $this->success(["title" => $title, "data" => $data]);
+
+        array_unshift($title, 'product');
+        array_unshift($data, $title);
+        $this->success(["title"=>date("Y-m-d",strtotime($start)),"data"=>$data]);
     }
 
 
@@ -208,22 +211,35 @@ class ControlPanelController extends Controller
      */
     private function getTargetData(string $date)
     {
-        if ($date == date("Y-m-d")) {
+        $res = [];
+        if ($date == date("Y-m-d",1622908800)){
             $sql = <<<sql
-SELECT DATE_FORMAT(order_packages.created_at,'%Y-%m-%d') date,
+SELECT DATE_FORMAT(order_packages.created_at,'%Y-%m-%d') date,IFNULL(mm.name,'未知') name ,
 SUM(CASE WHEN order_packages.weighed_at IS NOT NULL THEN 1 ELSE 0 END) AS count,
-COUNT(1) total FROM order_packages LEFT JOIN orders ON order_packages.order_id=orders.id WHERE orders.wms_status != '订单取消'
-AND order_packages.created_at >= '{$date} 00:00:00' GROUP BY date
+COUNT(1) total FROM order_packages LEFT JOIN orders ON order_packages.order_id=orders.id
+LEFT JOIN measuring_machines AS mm ON mm.id = order_packages.measuring_machine_id
+WHERE orders.wms_status != '订单取消'
+AND order_packages.created_at like '{$date}%' GROUP BY date,order_packages.measuring_machine_id
 sql;
-
-            $pack = DB::selectOne(DB::raw($sql));
-            if (!$pack) return ["date" => $date, "total" => 0, "count" => 0, "value" => 0];
-            return ["date" => $pack->date, "total" => $pack->total, "count" => $pack->count, "value" => (string)($pack->total ? intval(($pack->count / $pack->total) * 100) : 0)];
+            //todo 新写
+            $info = DB::select(DB::raw($sql));
+            if (!$info) return  $res;
+            $no_weight  =  isset($info[0]->name)  && $info[0]->name == '未知' ? $info[0]->total - $info[0]->count : 0;
+            foreach ($info as $v){
+                $res[] = [$v->name,$v->count];
+            }
+            array_push($res, ['未称重',$no_weight]);
+        }else{
+            $info = app(CacheService::class)->getOrExecute("weight.".$date,function ()use($date){
+                return OrderPackageCountingRecord::query()->where("targeted_at",$date)->get()->toArray();
+            },config("cache.expirations.forever"));
+            if (array_key_exists('date',$info)) return  $res;
+            $no_weight  =  isset($info[0]->name)  && $info[0]->name == '未知' ? $info[0]->total - $info[0]->count : 0;
+            foreach ($info as $v){
+                $res[] = [$v->name,$v->count];
+            }
+            array_push($res, ['未称重',$no_weight]);
         }
-        return app(CacheService::class)->getOrExecute("weight." . $date, function () use ($date) {
-            $count = OrderPackageCountingRecord::query()->where("targeted_at", $date)->first();
-            if (!$count) return ["date" => $date, "total" => 0, "count" => 0, "value" => 0];
-            return ["date" => $count->targeted_at, "total" => $count->total_count, "count" => $count->un_weigh_count, "value" => (string)($count->total_count ? intval(($count->un_weigh_count / $count->total_count) * 100) : 0)];
-        }, config("cache.expirations.forever"));
+        return $res;
     }
 }

+ 5 - 5
app/Http/Controllers/WaybillController.php

@@ -177,11 +177,11 @@ class WaybillController extends Controller
             'user_id'=>Auth::id(),
         ]);
         //todo 若是德邦物流 请求API创建快递单号
-//        $logistic_ids = Logistic::query()->where('name','like', '德邦%')->where('type','=','物流')->pluck('id')->toArray();
-//        if (in_array($request['logistic_id'], $logistic_ids)){
-//            $res = app('DbOpenService')->getDbOrderNo(['id' => $id]);
-//            $msg =  $res['msg']? "【申请德邦物流单号:".$res['msg']."】"  :'';
-//        }
+        $logistic_ids = Logistic::query()->where('name','like', '德邦%')->where('type','=','物流')->pluck('id')->toArray();
+        if (in_array($request['logistic_id'], $logistic_ids)){
+            $res = app('DbOpenService')->getDbOrderNo(['id' => $id]);
+            $msg =  $res['msg']? "【申请德邦物流单号:".$res['msg']."】"  :'';
+        }
         return redirect('transport/waybill/index')->with('successTip','运单“'.$waybill->waybill_number.'”调度成功 '. ($msg??''));
     }
 

+ 1 - 1
app/Logistic.php

@@ -22,7 +22,7 @@ class Logistic extends Model
     const TAGS=[
         0 => "专线",
         1 => "直发车",
-        2 => "德邦",
+        2 => "德邦物流",
     ];
 
     static function nameById($id){

+ 32 - 0
database/migrations/2021_07_30_162047_change_name_column_in_order_package_counting_records_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class ChangeNameColumnInOrderPackageCountingRecordsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('order_package_counting_records', function (Blueprint $table) {
+            $table->string('name')->nullable()->comment('称 名称');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('order_package_counting_records', function (Blueprint $table) {
+            $table->dropColumn('name');
+        });
+    }
+}

+ 33 - 32
resources/views/control/panel.blade.php

@@ -344,18 +344,22 @@
                     <div class="card">
                         <div class="card-header">
                             <div class="row">
-                                <el-date-picker size="small" class="col-6 date" @blur="loadWeightInfo()"
+                                <el-date-picker size="small" class="col-4 date" @blur="loadWeightInfo()"
                                                 type="daterange" align="right"
                                                 v-model="searchOption.weightDate" unlink-panels range-separator="-"
                                                 start-placeholder="开始日期" end-placeholder="结束日期"
                                                 value-format="yyyy-MM-dd">
                                 </el-date-picker>
-                                <label class="col-3 offset-3">
+                                <label class="col-3">
                                     <select class="form-control rounded" v-model="searchOption.weightSelect"
                                             @change="switchWeightDate()">
                                         <option v-for="(date,i) in dateOptions" :value="i">@{{ date.text }}</option>
                                     </select>
                                 </label>
+                                <el-select class="col-3"  placeholder="请选择对应货主" multiple v-model="selectWeightOwners" size="small" style="width: 50%"  @change="loadWeightInfo()">
+                                    <el-option label="选择所有" value="all"></el-option>
+                                    <el-option v-for="item in owners" :label="item.name" :value="item.id" :key="item.id"></el-option>
+                                </el-select>
                             </div>
                         </div>
                         <div class="card-body row">
@@ -434,6 +438,7 @@
                 owners:{!! $owners !!},
                 selectOrderOwners: [],
                 selectLogisticsOwners: [],
+                selectWeightOwners: [],
                 selectExceptionTypeOwners: [],
                 warehousesOrders:{!! $warehousesOrders !!},
                 orderCountingRecords:{},
@@ -959,7 +964,7 @@
                     }
                     this.cardPool.weight.showLoading('default',{text:"加 载 中",color:'#C0C0C0'});
                     let url = "{{url('apiLocal/control/panel/menu/weightApi')}}";
-                    let params = {start:this.searchOption.weightDate[0],end:this.searchOption.weightDate[1]};
+                    let params = {start:this.searchOption.weightDate[0],end:this.searchOption.weightDate[1],owner_ids:this.selectWeightOwners};
                     window.tempTip.postBasicRequest(url,params,res=>{
                         this.cardPool.weight.hideLoading();
                         this.cardPool.weight.setOption(this._setWeightData(res.title,res.data));
@@ -1017,37 +1022,33 @@
                     this.loadExceptionTypeInfo();
                 },
                 _setWeightData(title, data){
-                    return {
-                        title: {
-                            text: '已称重包裹占比',
-                            left: 'left'
+                    let temp = [];
+                    for (let i=1;i<data.length; i++){
+                        temp.push({type: 'line', smooth: true, seriesLayoutBy: 'row', emphasis: {focus: 'series'}});
+                    }
+                    temp.push({type: 'pie', id: 'pie', radius: '30%', center: ['50%', '25%'], emphasis: {focus: 'data'},
+                        label: {
+                            formatter: '{b}: {@'+title+'} ({d}%)'
                         },
+                        encode: {
+                            itemName: 'product',
+                            value: title,
+                            tooltip: title
+                        }
+                    })
+                    return {
+                        legend: {},
                         tooltip: {
-                            trigger: 'item',
-                            formatter: function (params) {
-                                return params.data.date + "<br>" + "总量:<span class='text-success font-weight-bold'>" + params.data.total + "</span><br>" + "已称:<span class='text-info font-weight-bold'>" + params.data.count + "</span>";
-                            }
-                        }, xAxis: {
-                            data: title
-                        }, yAxis: {
-                            axisLabel: {
-                                show: true,
-                                interval: 'auto',
-                                formatter: '{value} %'
-                            },
-                            max: 100
-                        }, label: {
-                            show: true,
-                            position: 'top',
-                            formatter: '{c}%',
-                            color: "red"
-                        }, series: [{
-                            type: "bar",
-                            data: data,
-                            itemStyle: {
-                                color: "RGB(62,157,231)",
-                            }
-                        }]
+                            trigger: 'axis',
+                            showContent: false
+                        },
+                        dataset: {
+                            source: data
+                        },
+                        xAxis: {type: 'category'},
+                        yAxis: {gridIndex: 0},
+                        grid: {top: '55%'},
+                        series: temp
                     };
                 },
                 _setOrderPackageReceivedSyncRecordData(title,data){

+ 17 - 18
resources/views/transport/waybill/edit.blade.php

@@ -620,15 +620,13 @@
                 is_waybillPriceModel(logistic_id,carrier_weight,carrier_weight_unit_id,destination_city_id,carrier_weight_other,carrier_weight_unit_id_other,cargo_name,total_number,total_weight,deliveryType_id,order_type,transport_type,pay_type,back_sign_bill,package_service){
                     this.errors=[];
                     let url='{{url('transport/waybill/is/waybillPriceModel')}}';
-
                     let _this=this;
                     axios.post(url,{logistic_id:logistic_id,carrier_weight:[carrier_weight,carrier_weight_other],
                             carrier_weight_unit_id:[carrier_weight_unit_id,carrier_weight_unit_id_other],destination_city_id:destination_city_id,
                             cargo_name:cargo_name, total_number:total_number,total_weight:total_weight, deliveryType_id:deliveryType_id
                             ,order_type:order_type, transport_type: transport_type, pay_type:pay_type, back_sign_bill:back_sign_bill,package_service:package_service
-                    }) .then(
+                    }).then(
                             function (response) {
-
                                 if (response.data.error){
                                     _this.errors=response.data.error;return;}
 
@@ -658,7 +656,7 @@
                     let  logistic_id=document.getElementById('logistic_id').value;
                     let carrier_weight = '',carrier_weight_unit_id='',destination_city_id='',carrier_weight_other='',carrier_weight_unit_id_other='',
                         cargo_name = '',total_number='',total_weight='',deliveryType_id='',order_type='',transport_type='',pay_type='',back_sign_bill='',package_service='';
-                    if ( logistic_id == 15 ){
+                    if ( logistic_id == 15 || type === '德邦物流'){
                         cargo_name=document.getElementById('cargo_name').value;
                         total_number=document.getElementById('total_number').value;
                         total_weight=document.getElementById('total_weight').value;
@@ -668,22 +666,23 @@
                         pay_type=document.getElementById('pay_type').value;
                         back_sign_bill=document.getElementById('back_sign_bill').value;
                         package_service=document.getElementById('package_service').value;
-                    }
-                    if (type==='专线'){
-                        carrier_weight=document.getElementById('carrier_weight').value;
-                        carrier_weight_unit_id=document.getElementById('carrier_weight_unit_id').value;
-                        destination_city_id=document.getElementById('destination_city_id').value;
-                        carrier_weight_other=document.getElementById('carrier_weight_other').value;
-                        carrier_weight_unit_id_other=document.getElementById('carrier_weight_unit_id_other').value;
-                        this.is_waybillPriceModel(logistic_id,carrier_weight,carrier_weight_unit_id,destination_city_id,
-                            carrier_weight_other,carrier_weight_unit_id_other,cargo_name,total_number,total_weight,
-                            deliveryType_id,order_type,transport_type,pay_type,back_sign_bill,package_service
+                        destination_city_id = 0;
+                        this.is_waybillPriceModel(logistic_id, carrier_weight, carrier_weight_unit_id, destination_city_id,
+                            carrier_weight_other, carrier_weight_unit_id_other, cargo_name, total_number, total_weight,
+                            deliveryType_id, order_type, transport_type, pay_type, back_sign_bill, package_service
                         );
-                    } else {
-                        this.is_waybillPriceModel(logistic_id,carrier_weight,carrier_weight_unit_id,destination_city_id,
-                            carrier_weight_other,carrier_weight_unit_id_other,cargo_name,total_number,total_weight,
-                            deliveryType_id,order_type,transport_type,pay_type,back_sign_bill,package_service
+                    }
+                    if (type==='专线') {
+                        carrier_weight = document.getElementById('carrier_weight').value;
+                        carrier_weight_unit_id = document.getElementById('carrier_weight_unit_id').value;
+                        destination_city_id = document.getElementById('destination_city_id').value;
+                        carrier_weight_other = document.getElementById('carrier_weight_other').value;
+                        carrier_weight_unit_id_other = document.getElementById('carrier_weight_unit_id_other').value;
+                        this.is_waybillPriceModel(logistic_id, carrier_weight, carrier_weight_unit_id, destination_city_id,
+                            carrier_weight_other, carrier_weight_unit_id_other, cargo_name, total_number, total_weight,
+                            deliveryType_id, order_type, transport_type, pay_type, back_sign_bill, package_service
                         );
+                    }else if(type === '直发车') {
                         document.getElementById('deliver_at').value= document.getElementById('deliver_at_date').value+' '+ document.getElementById('deliver_at_time').value;
                         this.executeSubmit();
                     }