loustwo пре 4 година
родитељ
комит
26777e48db

+ 2 - 2
app/Console/Commands/EndReceivingTask.php

@@ -20,7 +20,7 @@ class EndReceivingTask extends Command
      *
      * @var string
      */
-    protected $description = '完结 入库开单任务';
+    protected $description = '延时完结 入库开单任务';
 
     /**
      * Create a new command instance.
@@ -41,7 +41,7 @@ class EndReceivingTask extends Command
     {
         /** @var ReceivingTaskService $service */
         $service = app(ReceivingTaskService::class);
-        $service->endReceivingTask();
+        $service->overtimeToCompleteTask();
         return 1;
     }
 }

+ 7 - 2
app/Filters/ReceivingTaskFilters.php

@@ -37,6 +37,7 @@ class ReceivingTaskFilters{
                 $this->$filter($value, $this->queryBuilder);
             }
         }
+        $this->afterApply();
         return $this->queryBuilder;
     }
 
@@ -48,6 +49,12 @@ class ReceivingTaskFilters{
         return $this->deliveryAppointmentCarQuery;
     }
 
+    public function afterApply(){
+        if ($this->deliveryAppointmentCarQuery){
+            $this->queryBuilder->whereIn('delivery_appointment_car_id',$this->deliveryAppointmentCarQuery);
+        }
+    }
+
     public function id($ids){
         $this->searchWay($this->queryBuilder,$ids,'id');
     }
@@ -76,6 +83,4 @@ class ReceivingTaskFilters{
         $this->queryBuilder->where('created_at','<=',$created_at_end." 23:59:59");
     }
 
-
-
 }

+ 13 - 1
app/Http/Controllers/ReceivingTaskController.php

@@ -9,6 +9,7 @@ use App\ReceivingTask;
 use App\Services\OwnerService;
 use App\Services\ReceivingTaskService;
 use App\Warehouse;
+use Illuminate\Support\Facades\Gate;
 use Illuminate\Support\Facades\Request;
 
 class ReceivingTaskController extends Controller
@@ -28,6 +29,9 @@ class ReceivingTaskController extends Controller
 
     public function index(Request $request,ReceivingTaskFilters $filter)
     {
+        if (Gate::denies('入库管理-开单入库-查询')) {
+            return redirect('/');
+        }
         $receivingTasks = ReceivingTask::query()->with(['items','owner','wareHouse','file','deliveryAppointmentCar'])->filter($filter)->orderByDesc('created_at')->paginate(50);
         $owners = $this->ownerService->getQuery()->select('id','name')->get();
         $warehouses  = Warehouse::query()->get();
@@ -37,6 +41,9 @@ class ReceivingTaskController extends Controller
 
     public function create()
     {
+        if (Gate::denies('入库管理-开单入库-创建')) {
+            return redirect('/');
+        }
         $wareHouse = Warehouse::query()->get();
         $owners = $this->ownerService->getQuery()->select("id","code","name")->get();
         return view("store.receivingTasks.create",compact('wareHouse','owners'));
@@ -45,9 +52,15 @@ class ReceivingTaskController extends Controller
 
     public function storeApi(ReceivingTaskRequest $request): array
     {
+        if(Gate::denies('入库管理-开单入库-创建')){
+            return ['success' => false,'message' => '没有对应权限'];
+        }
         $appointment_number = $request->input('appointment_number',null);
+
         $delivery_appointment_car = DeliveryAppointmentCar::query()->where('appointment_number',$appointment_number)->first();
+
         if (!$delivery_appointment_car) return ['success' => false,'errors' =>['appointment_number' => ['对应预约号未找到']]];
+
         if (ReceivingTask::query()->where('delivery_appointment_car_id',$delivery_appointment_car->id)->exists())
             return ['success' => false, 'errors' =>['appointment_number' => ['预约号已有对应的任务']]];
         try {
@@ -56,7 +69,6 @@ class ReceivingTaskController extends Controller
             $receiving_task->loadMissing(['wareHouse','owner','deliveryAppointmentCar']);
             return ['success' => true, 'data' => $receiving_task];
         } catch (\Exception $e) {
-            dd($e->getMessage());
             return ['success' => false, 'message' => '生成入库单任务失败,请重新尝试'];
         }
     }

+ 27 - 16
app/Services/ReceivingTaskService.php

@@ -6,6 +6,7 @@ use App\DeliveryAppointment;
 use App\DeliveryAppointmentCar;
 use App\Traits\ServiceAppAop;
 use App\ReceivingTask;
+use App\Utils\IdCreate;
 use Illuminate\Support\Carbon;
 use Illuminate\Support\Facades\DB;
 use Ramsey\Uuid\Uuid;
@@ -23,25 +24,38 @@ class ReceivingTaskService
         $this->itemService =app(ReceivingTaskItemService::class);
     }
 
-
+    // 完结工单
     public function endTask($receivingTaskNumber)
+    {
+        ReceivingTask::query()->where('number', $receivingTaskNumber)->update(['status' => '完成','end_at' => now()]);
+    }
+
+    // 延时完成
+    public function overtimeToComplete($receivingTaskNumber)
     {
         ReceivingTask::query()->where('number', $receivingTaskNumber)->update(['status' => '延时完结']);
     }
 
+    // 标记任务进行中
     public function executionTask($receivingTaskNumber)
     {
         ReceivingTask::query()->where('number', $receivingTaskNumber)->update(['status' => '进行中']);
     }
 
-    public function createReceivingTask(DeliveryAppointmentCar $delivery_appointment_car, $params): ReceivingTask
+    /**
+     * 生成入库任务号
+     * @param DeliveryAppointmentCar $deliveryAppointmentCar
+     * @param $params
+     * @return ReceivingTask
+     */
+    public function createReceivingTask(DeliveryAppointmentCar $deliveryAppointmentCar, $params): ReceivingTask
     {
         // 生成入库任务号
         $task_number = $this->buildTaskNumber();
         $params['number'] = $task_number;
-        $params['delivery_appointment_car_id'] = $delivery_appointment_car->id;         // 预约号
+        $params['delivery_appointment_car_id'] = $deliveryAppointmentCar->id;         // 预约号
         $receivingTask = new ReceivingTask($params);
-        DB::transaction(function () use ($delivery_appointment_car, $params, &$receivingTask) {
+        DB::transaction(function () use ($deliveryAppointmentCar, $params, &$receivingTask) {
             $receivingTask->save();
             if ($receivingTask->id) {
                 try {
@@ -94,28 +108,25 @@ class ReceivingTaskService
         return $dirPath . DIRECTORY_SEPARATOR;
     }
 
+    /**
+     * 雪花算法生成 任务号
+     * @return string
+     */
     public function buildTaskNumber(): string
     {
-        $year_month_day = Carbon::now()->format("Ymd");
-        $current = Carbon::now()->format("Y-m-d");
-        $count = ReceivingTask::query()
-            ->where('created_at', '>=', $current . ' 00:00:00')
-            ->where('created_at', '<=', $current . ' 23.59.59')
-            ->count();
-        $count++;
-        $count = sprintf('%03s', $count);
-        return "SH$year_month_day" . $count;
+        return 'SH'.IdCreate::createOnlyId();
     }
 
     /**
-     * 完结昨天未完成的工单
+     * 延时完成昨天未完成的工单
      */
-    public function endReceivingTask(){
+    public function overtimeToCompleteTask(){
         $yesterday = Carbon::now()->subDays(1)->format("Y-m-d");
         ReceivingTask::query()
             ->where('created_at', '>=', $yesterday . ' 00:00:00')
             ->where('created_at', '<=', $yesterday . ' 23.59.59')
-            ->update(['status'=>'完成']);
+            ->whereIn('status',['创建','进行中'])
+            ->update(['status'=>'延时完成']);
 
     }
 }

+ 44 - 0
app/Utils/IdCreate.php

@@ -0,0 +1,44 @@
+<?php
+
+namespace App\Utils;
+
+/**
+ * Class IdCreate
+ * @package App\Utils
+ * 雪花算法 生成 id
+ */
+class IdCreate
+{
+    const EPOCH = 1479533469598;    //开始时间,固定一个小于当前时间的毫秒数
+    const max12bit = 4095;
+    const max41bit = 1099511627775;
+
+    static $machineId = null;      // 机器id
+
+    public static function machineId($mId = 0)
+    {
+        self::$machineId = $mId;
+    }
+
+    public static function createOnlyId()
+    {
+        // 时间戳 42字节
+        $time = floor(microtime(true) * 1000);
+        // 当前时间 与 开始时间 差值
+        $time -= self::EPOCH;
+        // 二进制的 毫秒级时间戳
+        $base = decbin(self::max41bit + $time);
+        // 机器id  10 字节
+        if (!self::$machineId) {
+            $machineid = self::$machineId;
+        } else {
+            $machineid = str_pad(decbin(self::$machineId), 10, "0", STR_PAD_LEFT);
+        }
+        // 序列数 12字节
+        $random = str_pad(decbin(mt_rand(0, self::max12bit)), 12, "0", STR_PAD_LEFT);
+        // 拼接
+        $base = $base . $machineid . $random;
+        // 转化为 十进制 返回
+        return bindec($base);
+    }
+}

+ 21 - 18
resources/views/store/receivingTasks/create.blade.php

@@ -60,7 +60,8 @@
                                 <div class="form-inline col-8">
                                     <select class="form-control form-control-sm col-12" name="owner_id" id="owner_id"
                                             :class="{'is-invalid':errors.owner_id}"
-                                            @change="getASNDetails,clearError('owner_id')"
+                                            @change="getASNDetails"
+                                            @input="clearError('owner_id')"
                                             v-model="receiving_task.owner_id">
                                         <option v-for="item in owners" :value="item.id" v-text="item.name"></option>
                                     </select>
@@ -346,11 +347,13 @@
                     </el-table>
                 </div>
                 <div class="form-group">
-                    <el-button type="primary" class="col-12" @click="submit" v-if="!submit_loading">提交</el-button>
-                    <el-button type="primary" class="col-12" :loading="true" v-if="submit_loading">提交中</el-button>
+                    <el-button type="primary" class="col-12" @click="submit" v-if="!submit_loading">提 交</el-button>
+                    <el-button type="primary" class="col-12" :loading="true" v-if="submit_loading">提  中</el-button>
                 </div>
                 <div class="form-group">
-                    <el-button type="primary" class="col-12" @click="printLodop">打印</el-button>
+                    @can('入库管理-开单入库-打印任务单')
+                    <el-button type="primary" class="col-12" @click="printLodop">打  印</el-button>
+                    @endcan
                 </div>
                 @include("store.receivingTasks._receiving_task_print")
                 @include("store.receivingTasks._clodop_print")
@@ -483,7 +486,7 @@
                         this.submit_loading = false;
                         if (res.data.success) {
                             this.successTempTip("创建成功");
-
+                            this.conversion(res.data.data);
                         } else {
                             if (res.data.errors) {
                                 let error = null;
@@ -515,7 +518,7 @@
                     }).catch(err => {
                         this.errorTempTip(err);
                     });
-                },
+                 },
                 formatAsnHeaderDetails(asnHeaderDetails) {
                     return asnHeaderDetails.map(e => this.formatAsnHeaderDetail(e));
                 },
@@ -697,7 +700,7 @@
                     } = this.receiving_task_print;
                     this.clodop.PRINT_INITA(2,0,0,0,"");
                     this.clodop.SET_PRINT_PAGESIZE(2,'76mm','130mm');
-                    this.clodop.ADD_PRINT_BARCODE(20,70,350,50,"Code39","123456789012");
+                    this.clodop.ADD_PRINT_BARCODE(20,70,350,50,"Code39",number);
                     this.clodop.SET_PRINT_STYLEA(0,"FontSize",10);
                     this.clodop.ADD_PRINT_TEXT(100,15,100,20,"收货任务号");
                     this.clodop.SET_PRINT_STYLEA(0,"FontSize",10);
@@ -738,20 +741,20 @@
                     this.clodop.ADD_PRINT_TEXT(250,245,100,20,"预约号");
                     this.clodop.SET_PRINT_STYLEA(0,"Alignment",2);
                     this.clodop.SET_PRINT_STYLEA(0,"Bold",1);
-                    this.clodop.ADD_PRINT_TEXT(100,115,250,20,"1234566554646"); // number
+                    this.clodop.ADD_PRINT_TEXT(100,115,250,20,number); // number
                     this.clodop.SET_PRINT_STYLEA(0,"FontSize",10);
                     this.clodop.SET_PRINT_STYLEA(0,"Alignment",2);
                     this.clodop.SET_PRINT_STYLEA(0,"Bold",1);
-                    this.clodop.ADD_PRINT_TEXT(130,115,130,20,"-仓库号");  // warehouse
-                    this.clodop.ADD_PRINT_TEXT(160,115,100,20,"-司机姓名"); //driver_name
-                    this.clodop.ADD_PRINT_TEXT(190,115,130,20,"-车号牌");  //plate_number
-                    this.clodop.ADD_PRINT_TEXT(220,115,100,20,"-是否提供清单"); //provide_list
-                    this.clodop.ADD_PRINT_TEXT(250,115,130,20,"-货主");  // owner
-                    this.clodop.ADD_PRINT_TEXT(130,345,100,20,"-投单员");  // for_single_member
-                    this.clodop.ADD_PRINT_TEXT(160,345,140,20,"-司机电话"); // driver_phone
-                    this.clodop.ADD_PRINT_TEXT(190,345,140,20,"-驾驶证号"); // driving_license_no
-                    this.clodop.ADD_PRINT_TEXT(220,345,100,20,"-收货类型");  // receiving_type
-                    this.clodop.ADD_PRINT_TEXT(250,345,140,20,"-预约号"); //appointment_number
+                    this.clodop.ADD_PRINT_TEXT(130,115,130,20,warehouse);  // warehouse
+                    this.clodop.ADD_PRINT_TEXT(160,115,100,20,driver_name); //driver_name
+                    this.clodop.ADD_PRINT_TEXT(190,115,130,20,plate_number);  //plate_number
+                    this.clodop.ADD_PRINT_TEXT(220,115,100,20,provide_list); //provide_list
+                    this.clodop.ADD_PRINT_TEXT(250,115,130,20,owner);  // owner
+                    this.clodop.ADD_PRINT_TEXT(130,345,100,20,for_single_member);  // for_single_member
+                    this.clodop.ADD_PRINT_TEXT(160,345,140,20,driver_phone); // driver_phone
+                    this.clodop.ADD_PRINT_TEXT(190,345,140,20,driving_license_no); // driving_license_no
+                    this.clodop.ADD_PRINT_TEXT(220,345,100,20,receiving_type);  // receiving_type
+                    this.clodop.ADD_PRINT_TEXT(250,345,140,20,appointment_number); //appointment_number
                     this.clodop.PREVIEW();
                 }
             }

+ 16 - 20
resources/views/store/receivingTasks/index.blade.php

@@ -7,21 +7,22 @@
 
 
 @section('content')
-    <div id="list" class="d-none">
-        <div class="container-fluid">
+    <div id="list" class="container-fluid d-none">
+        <div >
             <div id="form_div" style="min-width: 1220px;"></div>
             <div class="ml-3 form-inline" id="btn">
-                    <button type="button"
-                            class="ml-2 btn  btn-sm btn-outline-success "
-                            @click="printReceivingTask" >打印任务清单
-                    </button>
+                @can('入库管理-开单入库-打印任务单')
+                <button type="button"
+                        class="ml-2 btn btn-sm btn-outline-success "
+                        @click="printReceivingTask" >打印任务清单
+                </button>
+                @endcan
             </div>
             <div>
-                <table class="table  table-bordered" id="table">
-                    <tbody>
+                <table class="table table-sm table-striped table-hover table-bordered  " id="table">
                     <tr v-for="(item,i) in receiving_tasks" @click="selectTr===i+1?selectTr=0:selectTr=i+1" :class="selectTr===i+1?'focusing' : ''">
                         <td>
-                            <label><input class="checkItem" type="checkbox" :value="item.id"></label>
+                            <label><input type="checkbox" :value="item.id"></label>
                         </td>
                         <td v-text="i+1"></td>
                         <td v-text="item.number"></td>
@@ -39,7 +40,6 @@
                         <td v-text="item.driving_license_no"></td>
                         <td v-text="item.receiving_type"></td>
                     </tr>
-                    </tbody>
                 </table>
                 <div class="text-info h5 btn btn">{{$receivingTasks->count()}}/@{{ total }}</div>
                 {{ $receivingTasks->withQueryString()->links() }}
@@ -105,10 +105,8 @@
                 let data = [[
                     {name: 'created_at_start', type: 'dateTime', tip: '选择显示指定日期的起始时间', placeholder: ''},
                     {name: 'created_at_end', type: 'dateTime', tip: '选择显示指定日期的结束时间', placeholder: ''},
-                    {name: 'number', type: 'input', tip: '任务号:如模糊搜索需要在条件前后输入%号,回车提交', placeholder: '波次编号'},
-
-                    {name: 'number', type: 'input', tip: '任务号:如模糊搜索需要在条件前后输入%号,回车提交', placeholder: '波次编号'},
-                    {name: 'appointment_number', type: 'input', tip: '预约号:如模糊搜索需要在条件前后输入%号,回车提交', placeholder: '波次编号'},
+                    {name: 'number', type: 'input', tip: '任务号:如模糊搜索需要在条件前后输入%号,回车提交', placeholder: '任务号'},
+                    {name: 'appointment_number', type: 'input', tip: '预约号:如模糊搜索需要在条件前后输入%号,回车提交', placeholder: '预约号'},
                 ],[
                     {
                         name: 'owner_id',
@@ -124,7 +122,6 @@
                         tip: ['输入关键词快速定位下拉列表,回车确定', '选择要显示的仓库'],
                         placeholder: ['仓库', '定位或多选仓库']
                     },
-                    {name: 'warehouse_id', type: 'input', tip: '任务号:如模糊搜索需要在条件前后输入%号,回车提交', placeholder: '波次编号'},
                 ]];
                 this.form = new query({
                     el: '#form_div',
@@ -133,7 +130,7 @@
                 this.form.init();
 
                 let column = [
-                    {name:'index',value: '序号', neglect: true},
+                    {name:'id',value: '序号', neglect: true},
                     {name:'number',value: '收货任务号'},
                     {name:'status',value: '状态', neglect: true},
                     {name:'asn_nos',value: 'ASN单号', neglect: true},
@@ -145,9 +142,10 @@
                 ];
                 new Header({
                     el: "table",
-                    name: "orderIndex",
+                    name: "receiving_tasks",
                     column: column,
-                    data: this.models,
+                    data: this.receiving_tasks,
+                    fixedTop: ($('#form_div').height()) + ($('#btn').height()) + 1,
                 }).init();
             },
             methods: {
@@ -174,7 +172,6 @@
                     let appointment_number = this.getAppointmentNumber(task);
                     let warehouse = this.getWarehouseName(task);
                     let owner = this.getOwnerName(task);
-                    console.log(task);
                     return {
                         number: task.number,
                         status: task.status,
@@ -285,7 +282,6 @@
                         owner,                // 货主
                         appointment_number, // 预约号
                     } = this.receiving_task_print;
-                    console.log(number);
                     this.clodop.PRINT_INITA(2,0,0,0,"");
                     this.clodop.SET_PRINT_PAGESIZE(2,'76mm','130mm');
                     this.clodop.ADD_PRINT_BARCODE(20,70,350,50,"Code39",number);