Ver Fonte

工单处理 丢件处理 处理日志添加

ajun há 4 anos atrás
pai
commit
12271a8ba1

+ 1 - 1
app/Http/Controllers/WorkOrderController.php

@@ -58,7 +58,7 @@ class WorkOrderController extends Controller
         }
         $result = $service->buildOrderIssue($work_orders);
         if (!$result['success']) return $result;
-        WorkOrder::query()->defaultWith()->whereIn(  'id',$request['ids'])->get();
+        $workOrders = WorkOrder::query()->defaultWith()->whereIn('id',$request['ids'])->get();
         $service->tags($workOrders);
         return ['success' => true ,'data' => $workOrders];
     }

+ 89 - 0
app/Http/Controllers/WorkOrderProcessLogController.php

@@ -0,0 +1,89 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\WorkOrderProcessLog;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
+
+class WorkOrderProcessLogController extends Controller
+{
+    public function index()
+    {
+        //
+    }
+
+    public function create()
+    {
+        //
+    }
+
+    public function store(Request $request)
+    {
+        //
+    }
+
+    public function show(WorkOrderProcessLog $workOrderProcessLog)
+    {
+        //
+    }
+
+    public function edit(WorkOrderProcessLog $workOrderProcessLog)
+    {
+        //
+    }
+
+    public function update(Request $request, WorkOrderProcessLog $workOrderProcessLog)
+    {
+        //
+    }
+
+    public function destroy(WorkOrderProcessLog $workOrderProcessLog)
+    {
+        //
+    }
+
+    public function logisticStoreApi(Request  $request): array
+    {
+        $isExists = WorkOrderProcessLog::query()
+            ->where('work_order_id',$request->input('work_order_id'))
+            ->where('type','2')->exists();
+
+        if ($isExists){
+            return ['success' => false,'message' => '对应处理日志已存在'];
+        }
+        $params = $request->all();
+        $params['creator_id'] = Auth::user()['id'];
+        $params['type']  = '2';
+        $log = WorkOrderProcessLog::query()->create($params);
+        $log->loadMissing('creator');
+        return ['success' => true , 'data' => $log];
+    }
+
+    public function storeApi(Request $request): array
+    {
+        $isExists = WorkOrderProcessLog::query()
+            ->where('work_order_id',$request->input('work_order_id'))
+            ->where('type',1)->exists();
+        if ($isExists){
+            return ['success' => false,'message' => '对应处理日志已存在'];
+        }
+        $params = $request->all();
+        $params['creator_id'] = Auth::user()['id'];
+        $params['type']  = 1;
+        $log = WorkOrderProcessLog::query()->create($params);
+        $log->loadMissing('creator');
+        return ['success' => true , 'data' => $log];
+    }
+
+    public function updateApi(Request $request): array
+    {
+        $log = WorkOrderProcessLog::query()
+            ->where('id',$request->input('id'))->first();
+
+        $params = $request->all();
+        $params['creator_id'] = Auth::user()['id'];
+        $log->update($params);
+        return ['success' => true,'data' =>$log];
+    }
+}

+ 2 - 0
app/Providers/AppServiceProvider.php

@@ -187,6 +187,7 @@ use App\Services\NotificationService;
 use App\Services\WorkOrderDetailService;
 use App\Services\WorkOrderCommoditiesService;
 use App\Services\WorkOrderImageService;
+use App\Services\WorkOrderProcessLogService;
 
 class AppServiceProvider extends ServiceProvider
 {
@@ -383,6 +384,7 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('WorkOrderCommoditiesService',WorkOrderCommoditiesService::class);
         app()->singleton('WorkOrderDetailService',WorkOrderDetailService::class);
         app()->singleton('WorkOrderImageService',WorkOrderImageService::class);
+        app()->singleton('WorkOrderProcessLogService',WorkOrderProcessLogService::class);
         app()->singleton('WorkOrderService',WorkOrderService::class);
         app()->singleton('WorkOrderTypeService',WorkOrderTypeService::class);
     }

+ 13 - 0
app/Services/WorkOrderProcessLogService.php

@@ -0,0 +1,13 @@
+<?php 
+
+namespace App\Services;
+
+use App\Traits\ServiceAppAop;
+use App\WorkOrderProcessLog;
+
+class WorkOrderProcessLogService
+{
+    use ServiceAppAop;
+    protected $modelClass=WorkOrderProcessLog::class;
+
+}

+ 16 - 1
app/WorkOrder.php

@@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Model;
 use App\Traits\ModelLogChanging;
 use Illuminate\Database\Eloquent\Relations\BelongsTo;
 use Illuminate\Database\Eloquent\Relations\HasMany;
+use Illuminate\Database\Eloquent\Relations\HasOne;
 use Illuminate\Database\Eloquent\SoftDeletes;
 use Illuminate\Http\UploadedFile;
 use Illuminate\Support\Facades\Auth;
@@ -170,6 +171,17 @@ class WorkOrder extends Model
         return $this->hasMany(WorkOrderDetail::class);
     }
 
+    // 宝时处理日志
+    public function processLog(): HasOne
+    {
+        return $this->hasOne(WorkOrderProcessLog::class)->where('type','1');
+    }
+
+    // 承运商处理日志
+    public function logisticLog(): HasOne
+    {
+        return $this->hasOne(WorkOrderProcessLog::class)->where('type','2');
+    }
 
     public function scopeFilter($query, $filters)
     {
@@ -181,11 +193,14 @@ class WorkOrder extends Model
     public function scopeDefaultWith($query)
     {
         $query->with(['type', 'owner', 'issueType', 'creator','details',
+            'processLog.creator',
+            'logisticLog.creator',
             'packageImages.uploadFile',
             'commodityImages.uploadFile',
             'dealImages.uploadFile',
             'refundImages.uploadFile',
-        'reviewer', 'order' => function ($query) {
+            'reviewer',
+            'order' => function ($query) {
             /** @var Builder $query  */
             $query->with('packages', 'logistic', 'owner');
         }, 'orderIssue' => function ($query) {

+ 86 - 0
app/WorkOrderProcessLog.php

@@ -0,0 +1,86 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+use App\Traits\ModelLogChanging;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+
+class WorkOrderProcessLog extends Model
+{
+    use ModelLogChanging;
+
+    //
+    protected $fillable = [
+        'work_order_id',  // 工单
+        'type',           // 处理类型 0 无 1宝时 2 承运商
+        'is_indemnity',   // 是否赔偿 0 无 1否 2 是
+        'indemnity',      // 赔偿金
+        'creator_id',     // 创建人
+        'remark',         // 描述
+    ];
+
+    static public $enums = [
+        'type' => [
+            '' => 0,
+            '宝时' => 1,
+            '承运商' => 2,
+        ],
+        'is_indemnity' => [
+            '' => 0,
+            '是' => 1,
+            '否' => 2,
+        ],
+    ];
+
+    function __construct(array $attributes = [])
+    {
+        foreach (self::$enums as &$enum) {
+            $enum = $enum + array_flip($enum);
+        }
+        parent::__construct($attributes);
+    }
+
+    public function getTypeAttribute($value)
+    {
+        if (!$value) return '';
+        return self::$enums['type'][$value];
+    }
+
+    public function setTypeAttribute($value)
+    {
+        if (!$value) return ;
+        if (is_numeric($value)) {
+            $this->attributes['type'] = $value;
+        } else {
+            $this->attributes['type'] = self::$enums['type'][$value];
+        }
+    }
+
+    public function getIsIndemnityAttribute($value)
+    {
+        if (!$value) return '';
+        return self::$enums['is_indemnity'][$value];
+    }
+
+    public function setIsIndemnityAttribute($value)
+    {
+        if (!$value) return ;
+        if (is_numeric($value)) {
+            $this->attributes['is_indemnity'] = $value;
+        } else {
+            $this->attributes['is_indemnity'] = self::$enums['is_indemnity'][$value];
+        }
+    }
+
+    public function workOrder(): BelongsTo
+    {
+        return $this->belongsTo(WorkOrder::class);
+    }
+
+    public function creator(): BelongsTo
+    {
+        return $this->belongsTo(User::class);
+    }
+}

+ 12 - 0
database/factories/WorkOrderProcessLogFactory.php

@@ -0,0 +1,12 @@
+<?php
+
+/** @var \Illuminate\Database\Eloquent\Factory $factory */
+
+use App\WorkOrderProcessLog;
+use Faker\Generator as Faker;
+
+$factory->define(WorkOrderProcessLog::class, function (Faker $faker) {
+    return [
+        //
+    ];
+});

+ 37 - 0
database/migrations/2021_09_24_110630_create_work_order_process_logs_table.php

@@ -0,0 +1,37 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateWorkOrderProcessLogsTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('work_order_process_logs', function (Blueprint $table) {
+            $table->id();
+            $table->integer('work_order_id')->index()->comment('工单');
+            $table->tinyInteger('type')->index()->comment('工单');
+            $table->tinyInteger('is_indemnity')->comment('是否赔偿');
+            $table->decimal('indemnity',11,3)->comment('赔偿金额');
+            $table->integer('creator_id')->comment('创建人');
+            $table->string('remark')->comment('理由');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('work_order_process_logs');
+    }
+}

+ 16 - 0
database/seeds/WorkOrderProcessLogSeeder.php

@@ -0,0 +1,16 @@
+<?php
+
+use Illuminate\Database\Seeder;
+
+class WorkOrderProcessLogSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        //
+    }
+}

+ 60 - 0
resources/views/order/workOrder/_edit_process_log.blade.php

@@ -0,0 +1,60 @@
+<div class="modal fade " id="work-order-process-log-modal" tabindex="-1" role="dialog" aria-labelledby="checkModalLabel"
+     aria-hidden="true">
+    <div class="modal-dialog modal-lg modal-dialog-centered">
+        <div class="modal-content">
+            <div class="modal-header">
+                <h5 class="modal-title" id="checkModalLabel">@{{ processLog.type === 1 ? '宝时处理' : '承运商处理' }}</h5>
+                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                    <span aria-hidden="true">&times;</span>
+                </button>
+            </div>
+            <div class="modal-body">
+                {{--是否赔偿--}}
+                <div class="form-group row">
+                    <label for="work-order-logistic-number" class="col-sm-2 col-form-label text-right">是否赔偿</label>
+                    <div class="col-sm-10">
+                        <div class="custom-control custom-radio">
+                            <input type="radio" id="is-indemnity-yes" name="isIndemnity" class="custom-control-input"
+                                   value="1"
+                                   v-model="processLog['is_indemnity']">
+                            <label class="custom-control-label" for="is-indemnity-yes">赔偿</label>
+                        </div>
+                        <div class="custom-control custom-radio">
+                            <input type="radio" id="is-indemnity-no" name="isIndemnity" class="custom-control-input"
+                                   value="2"
+                                   v-model="processLog['is_indemnity']">
+                            <label class="custom-control-label" for="is-indemnity-no">不赔偿</label>
+                        </div>
+                    </div>
+                </div>
+
+                {{--描述--}}
+                <div class="form-group row" v-show="processLog['is_indemnity'] === '2'">
+                    <label for="process-log-remark" class=" col-sm-2 col-form-label text-right">理由</label>
+                    <div class="col-sm-10">
+                        <textarea name="process-log-remark" id="process-log-remark" cols="30" rows="5" class="form-control"
+                                  v-model="processLog.remark"></textarea>
+                    </div>
+                </div>
+                {{--赔偿金额--}}
+                <div class="form-group row" v-show="processLog['is_indemnity'] === '1'">
+                    <label for="process-log-indemnity" class="col-sm-2 col-form-label text-right">赔偿金额</label>
+                    <div class="col-sm-10">
+                        <input type="number" id="process-log-indemnity" class="form-control"
+                               v-model="processLog.indemnity" placeholder="赔偿金额">
+                    </div>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭
+                </button>
+
+                {{--填充工单--}}
+                {{--宝时--}}
+                <button type="button" class="btn btn-outline-primary"   v-show="processLog['type'] === 1" @click="storeProcessLog">提交</button>
+                {{--承运商--}}
+                <button type="button" class="btn btn-outline-primary"   v-show="processLog['type'] === 2" @click="storeLogisticProcessLog">提交</button>
+            </div>
+        </div>
+    </div>
+</div>

+ 98 - 3
resources/views/order/workOrder/index.blade.php

@@ -65,7 +65,13 @@
                                             审核
                                         </button>
                                     @endcan
-                                    <button class="btn btn-sm btn-outline-secondary" @click="showFillModel(item,i)" v-if="item.issue_type.name ==='快递丢件'">工单填充</button>
+
+                                    <button class="btn btn-sm btn-outline-secondary" @click="showFillModel(item,i)" v-if="item['issue_type']['name'] ==='快递丢件'">信息填充</button>
+
+                                    <button class="btn btn-sm btn-outline-secondary" @click="showEditLog(item,i,2)" v-if="['快递丢件','破损'].includes(item['issue_type']['name'])">快递处理</button>
+
+                                    <button class="btn btn-sm btn-outline-secondary" @click="showEditLog(item,i,1)" v-if="['快递丢件','破损'].includes(item['issue_type']['name'])">宝时处理</button>
+
                                 </td>
                                 <td class="text-center">@{{ item.status }}</td>
                                 <td class="text-center">@{{ item.owner ? item.owner.name : '' }}</td>
@@ -217,7 +223,7 @@
                 @include('order.workOrder._edit_issue_type')
             @endcan
             @include('order.workOrder._fill_loss_work_order')
-
+            @include('order.workOrder._edit_process_log')
         </div>
     </div>
 @endsection()
@@ -268,6 +274,15 @@
                     refundImages:[], // 退款图
                     dealImages:[], // 交易图
                 },
+                processLog:{
+                    id:null,        // log->id
+                    index:'', // 下标
+                    work_order_id:null, // work_order_id
+                    type:null,  // 类型
+                    is_indemnity:null, // 是否赔偿
+                    indemnity:null,  // 金额
+                    remark:null,
+                },
                 selectOrderPackage: null,
                 selectOrder: null,
                 selectOrderIssue: null,
@@ -719,8 +734,88 @@
                     }).catch(err=>{
                         window.template.show(err);
                     });
+                },
+                showEditLog(item,index,type){
+                    this.processLog.type = type;
+                    this.processLog.index = index;
+                    this.processLog.work_order_id = item.id;
+                    this.processLog.indemnity = null;
+                    this.processLog.is_indemnity = null;
+                    this.processLog.remark = null;
+                    $("#work-order-process-log-modal").modal('show');
+                },
+                storeLogisticProcessLog(){
+                    let url = "{{route('workOrderProcessLog.logisticLogApi')}}";
+                    let data = {
+                        'indemnity':this.processLog.indemnity,
+                        'work_order_id':this.processLog.work_order_id,
+                        'is_indemnity':this.processLog.is_indemnity,
+                        'remark':this.processLog.remark,
+                    };
+                    if(!this.verifiedProcessLog())return;
+                    window.tempTip.setDuration(9999);
+                    window.tempTip.setIndex(1999);
+                    window.tempTip.waitingTip('操作中请稍后');
+                    window.axios.post(url,data).then(res=>{
+                        window.tempTip.cancelWaitingTip();
+                        window.tempTip.setIndex(1999);
+                        window.tempTip.setDuration(2000);
+                        if (res.data.success){
+                            window.tempTip.showSuccess('创建成功');
+                            this.$set(this.workOrders[this.processLog.index],'logisticLog',res.data.data);
+                        } else{
+                            window.tempTip.show(res.data.message ? res.data.message : '创建异常,刷新页面重试');
+                        }
+                    }).catch(err=>{
+                        window.tempTip.setIndex(1999);
+                        window.tempTip.setDuration(2000);
+                        window.tempTip.show(err);
+                    });
+                },
+                storeProcessLog(){
+                    let url = "{{route('workOrderProcessLog.LogApi')}}";
+                    let data = {
+                        'indemnity':this.processLog.indemnity,
+                        'work_order_id':this.processLog.work_order_id,
+                        'is_indemnity':this.processLog.is_indemnity,
+                        'remark':this.processLog.remark,
+                    };
+                    if(!this.verifiedProcessLog())return;
+                    window.tempTip.setDuration(9999);
+                    window.tempTip.setIndex(1999);
+                    window.tempTip.waitingTip('操作中请稍后');
+                    window.axios.post(url,data).then(res=>{
+                        window.tempTip.cancelWaitingTip();
+                        window.tempTip.setIndex(1999);
+                        window.tempTip.setDuration(2000);
+                        if (res.data.success){
+                            window.tempTip.showSuccess('创建成功');
+                            this.$set(this.workOrders[this.processLog.index],'processLog',res.data.data);
+                        } else{
+                            window.tempTip.show(res.data.message ? res.data.message : '创建异常,刷新页面重试');
+                        }
+                    }).catch(err=>{
+                        window.tempTip.setIndex(1999);
+                        window.tempTip.setDuration(2000);
+                        window.tempTip.show(err);
+                    });
+                },
+                verifiedProcessLog(){
+                    window.tempTip.setIndex(1999);
+                    window.tempTip.setDuration(2000);
+                    if(this.processLog.is_indemnity === '1'){
+                        if (!this.processLog.indemnity ){
+                            window.tempTip.show('填写赔偿金额');
+                            return false;
+                        }
+                    }else if (this.processLog.is_indemnity === '2'){
+                        if (this.processLog.remark ===null  || this.processLog.remark.trim(' ').length === 0){
+                            window.tempTip.show('填写不赔偿理由');
+                            return false;
+                        }
+                    }
+                    return true;
                 }
-
             },
         });
     </script>

+ 5 - 0
routes/apiLocal.php

@@ -271,6 +271,11 @@ Route::prefix('workOrder')->group(function(){
     Route::post('updateIssueType','WorkOrderController@updateIssueTypeApi')->name('workOrder.updateIssueTypeApi'); // 修改问题类型
     Route::post('batchUpdateIssueType','WorkOrderController@batchUpdateIssueTypeApi')->name('workOrder.batchUpdateIssueTypeApi'); // 修改问题类型
     Route::delete('/{id}','WorkOrderController@destroyApi')->name('workOrder.destroyApi');
+
+    Route::prefix('process')->group(function (){
+        Route::post('log.logistic','WorkOrderProcessLogController@logisticStoreApi')->name('workOrderProcessLog.logisticLogApi');
+        Route::post('log','WorkOrderProcessLogController@storeApi')->name('workOrderProcessLog.LogApi');
+    });
  });
 /*出库*/
 Route::group(['prefix'=>'storeOut'],function(){