Преглед на файлове

修改任务认领失败

ajun преди 5 години
родител
ревизия
49a415161c

+ 1 - 1
app/Demand.php

@@ -34,7 +34,7 @@ class Demand extends Model
         return $this->belongsTo(User::class, 'initiator', 'id');
     }
 
-    public function handler(): BelongsTo
+    public function handle(): BelongsTo
     {
         return $this->belongsTo(User::class, 'handler', 'id');
     }

+ 12 - 8
app/Http/Controllers/DemandController.php

@@ -27,7 +27,7 @@ class DemandController extends Controller
     {
         // 查询权限
 
-        $demands = Demand::query()->with(['processes', 'initiator', 'handler', 'uploadFile'])->filter($filters)->paginate($request['paginate'] ?? 50);
+        $demands = Demand::query()->with(['initiator', 'handle', 'uploadFile', 'processes'])->filter($filters)->orderByDesc('demands.id')->paginate($request['paginate'] ?? 50);
 
         return view('maintenance.demand.index', compact('demands'));
     }
@@ -64,10 +64,13 @@ class DemandController extends Controller
         $this->gate('需求管理-问题-编辑');
         $demand = Demand::query()->find($request['id'])->first();
 
+        if($demand['initiator'] != Auth::user()['id'])
+            $this->error('非当前需求创建人不可修改');
+
         $bool = $demand->update($request->all());
 
         if ($bool) {
-            $demand->loadMissing('authority', 'initiator', 'handler', 'uploadFile', 'processes');
+            $demand->loadMissing('authority', 'initiator', 'handle', 'uploadFile', 'processes');
             $this->success($demand);
         }
         $this->error('需求更新出现异常');
@@ -79,19 +82,19 @@ class DemandController extends Controller
      */
     public function uploadFileApi(DemandRequest $request, DemandService $service)
     {
-        // 文件上传
-
         $demand = Demand::query()->find($request['id'])->first();
 
         $service->saveUPLoadFile($demand, $request->file('file'));
 
-        $demand->loadMissing('authority', 'initiator', 'handler', 'uploadFile', 'processes');
+        $demand->loadMissing('authority', 'initiator', 'handle', 'uploadFile', 'processes');
 
         $this->success($demand);
     }
 
 
     /**
+     * 删除需求
+     *
      * @param DemandRequest $request
      */
     public function destroyApi(DemandRequest $request)
@@ -109,7 +112,7 @@ class DemandController extends Controller
     }
 
     /**
-     * 完结问题
+     * 完结需求
      *
      * @param DemandRequest $request
      * @param DemandService $service
@@ -126,14 +129,15 @@ class DemandController extends Controller
     }
 
     /**
-     * 问题认领
+     * 需求认领
      *
      * @param DemandRequest $request
      * @param DemandService $service
      */
     public function claimApi(DemandRequest $request,DemandService $service)
     {
-        $demand = Demand::query()->find($request['id'])->first();
+        /** @var Demand  $demand */
+        $demand = Demand::query()->where('id',$request['id'])->first();
         $handler = Auth::user()['id'];
 
         $result = $service->claimDemand($demand,$handler);

+ 21 - 2
app/Http/Controllers/DemandProcessController.php

@@ -2,9 +2,28 @@
 
 namespace App\Http\Controllers;
 
+use App\Components\AsyncResponse;
 use App\DemandProcess;
-use Illuminate\Http\Request;
+use App\Http\Requests\Demand\Process\DemandProcessRequest;
+use Illuminate\Support\Facades\Auth;
 
 class DemandProcessController extends Controller
 {
- }
+    use AsyncResponse;
+
+    /**
+     * 添加处理记录
+     *
+     * @param DemandProcessRequest $request
+     */
+    public function storeApi(DemandProcessRequest $request)
+    {
+        $params = $request->all();
+        $params['processor'] = Auth::user()['id'];
+        $demandProcess = DemandProcess::query()->create($params);
+
+        $demandProcess->loadMissing('processor');
+        $this->success($demandProcess);
+    }
+
+}

+ 52 - 0
app/Http/Requests/Demand/Process/DemandProcessRequest.php

@@ -0,0 +1,52 @@
+<?php
+
+
+namespace App\Http\Requests\Demand\Process;
+
+use App\Traits\RequestApiFormValidation;
+use Illuminate\Foundation\Http\FormRequest;
+use Illuminate\Support\Facades\Route;
+
+class DemandProcessRequest extends FormRequest
+{
+    use RequestApiFormValidation;
+
+    private $storeApiRules = [
+        'demand_id' => 'required',
+        'explain' => 'required'
+    ];
+
+    private $storeApiMessage = [
+        'demand_id.required' => '问题未指定',
+        'explain.required' => '说明不能为空'
+    ];
+
+    public function authorize(): bool
+    {
+        return true;
+    }
+
+    public function rules(): array
+    {
+        $currentRoute = Route::getCurrentRoute();
+        $routeName = $currentRoute->getName();
+        switch ($routeName) {
+            case 'demand.process.storeApi':
+                return $this->storeApiRules;
+            default :
+                return [];
+        }
+    }
+
+    public function messages(): array
+    {
+        $currentRoute = Route::getCurrentRoute();
+        $routeName = $currentRoute->getName();
+        switch ($routeName) {
+            case 'demand.process.storeApi':
+                return $this->storeApiMessage;
+            default :
+                return [];
+        }
+    }
+}

+ 10 - 8
app/Services/DemandService.php

@@ -28,13 +28,16 @@ class DemandService
         if (!$file) return ['success' => false, 'message' => '上传图片不得为空'];
         if (!$file->isValid()) return ['success' => false, 'message' => '找不到上传图片'];
         if (!is_uploaded_file($tmpFile)) return ['success' => false, 'message' => '文件错误'];
-
+        if ($file->getSize() > 10 * 1024 * 1024) return ['success' => false, 'message' => '文件不能大于10MB'];
         $fileSuffix = $file->getClientOriginalExtension();
 
-        $fileName = date('ymd') . '-' . Uuid::uuid1();
-
-        $filePath = storage_path('app/public/files/issue/' . $fileName . '-issue' . $fileSuffix);
+        $dirPath = storage_path('app\public\files\issue');
+        if (!file_exists($dirPath)) {
+            mkdir($dirPath);
+        }
 
+        $fileName = date('ymd') . '-' . Uuid::uuid1(). '-issue.'.$fileSuffix ;
+        $filePath = storage_path('app\public\files\issue\\' . $fileName);
         $result = move_uploaded_file($tmpFile, $filePath);
 
         if (!$result) return ['success' => false, 'message' => '文件上传失败'];
@@ -74,16 +77,15 @@ class DemandService
      */
     public function claimDemand(Demand $demand, $handler): array
     {
-        if($demand['status'] !== 0)
+        if ($demand['status'] != 0)
             return ['success' => false, 'message' => '任务已被认领'];
 
-        $bool = $demand->update(['handler' => $handler]);
+        $bool = $demand->update(['handler' => $handler,'status' => 1]);
         if ($bool) {
-            $demand->loadMissing('authority', 'initiator', 'handler', 'uploadFile', 'processes');
+            $demand->loadMissing('initiator', 'handle', 'uploadFile', 'processes');
             return ['success' => true, 'data' => $demand];
         }
         return ['success' => false, 'message' => '任务认领失败'];
     }
 
-    
 }

+ 28 - 20
resources/views/maintenance/demand/_table.blade.php

@@ -1,22 +1,22 @@
 <table class="table table-striped table-bordered table-sm table-hover">
     <thead class="text-center">
-        <tr class="align-text-bottom">
-            <th rowspan="2">序号</th>
-            <th rowspan="2">类型</th>
-            <th rowspan="2">需求描述</th>
-            <th colspan="3" rowspan="1">过程</th>
-            <th rowspan="2">附件</th>
-            <th rowspan="2">发起人</th>
-            <th rowspan="2">处理人</th>
-            <th rowspan="2">发起时间</th>
-            <th rowspan="2">状态</th>
-            <th rowspan="2">操作</th>
-        </tr>
-        <tr class="thead-light">
-            <th>说明</th>
-            <th>经手人</th>
-            <th>时间</th>
-        </tr>
+    <tr class="align-text-bottom">
+        <th rowspan="2">序号</th>
+        <th rowspan="2">类型</th>
+        <th rowspan="2">需求描述</th>
+        <th colspan="3" rowspan="1">过程</th>
+        <th rowspan="2">附件</th>
+        <th rowspan="2">发起人</th>
+        <th rowspan="2">处理人</th>
+        <th rowspan="2">发起时间</th>
+        <th rowspan="2">状态</th>
+        <th rowspan="2">操作</th>
+    </tr>
+    <tr class="thead-light">
+        <th>说明</th>
+        <th>经手人</th>
+        <th>时间</th>
+    </tr>
     </thead>
     <tbody>
     <template v-if="demands.length>0">
@@ -36,14 +36,22 @@
                 <td></td>
             </template>
             <td>
+                {{-- 附件 --}}
+                <template v-if="demand.uploadFile">
+                    附件
+                </template>
+                <template v-else>
+                    <button type="button" class="btn btn-outline-secondary" @click="showUploadDiv(demand,i)">上传文件
+                    </button>
+                </template>
             </td>
             <td>@{{ demand.initiator ? demand.initiator.name : '' }}</td>
-            <td>@{{ demand.handler ? demand.handler.name : '' }}</td>
+            <td>@{{ demand.handle ? demand.handle.name : '' }}</td>
             <td>@{{ demand.created_at }}</td>
             <td>@{{ demand.status }}</td>
             <td>
-                <button class="btn btn-outline-success" @click="finishDemand(demand)"  v-if="demand.status === '处理中'">完结</button>
-                <button class="btn btn-outline-success" @click="claimDemand(demand,i)" v-if="demand.status === '未处理'">认领</button>
+                <button class="btn btn-outline-success" @click="finishDemand(demand)" v-if="demand['status'] === '处理中'">完结</button>
+                <button class="btn btn-outline-success" @click="claimDemand(demand,i)" v-if="demand['status'] === '未处理'">认领</button>
                 <button class="btn btn-outline-danger" @click="destroyDemand(demand,i)">删</button>
             </td>
         </tr>

+ 69 - 8
resources/views/maintenance/demand/index.blade.php

@@ -31,12 +31,14 @@
                     {name: 0, value: '需求'}, {name: 1, value: '问题'}
                 ],
                 selectTr: null,
-                uploadError:[],
+                uploadError:null,
+                selectDemand:null,
+                selectIndex:null,
             },
             created() {
                 let that = this;
                 this.demands.forEach(function (item,index,self){
-                    self[index]['status'] = that.status[item['status']].value ?? '';
+                    self[index]['status'] = that.status[item['status']]['value'] ?? '';
                     self[index]['type'] = that.types[item['type']]['value']  ?? '';
                 });
             },
@@ -70,7 +72,7 @@
                             demand.status = '已处理'
                             return ;
                         }
-                        window.tempTip.show('需求完结失败'+res.data.message);
+                        window.tempTip.show('需求完结失败'+res.data.data);
                     }).catch(err=>{
                         window.tempTip.show('需求完结异常'+err);
                     });
@@ -88,38 +90,97 @@
                             this.$delete(this.demands,index);
                             return ;
                         }
-                        window.tempTip.show(res.data.message);
+                        window.tempTip.show(res.data.data);
                     }).catch(err=>{
                         window.tempTip.show('删除出现异常'+err);
                     });
                 },
                 /** 添加处理过程 */
-                addProcess(demand,explain){
+                addProcess(demand,$e){
+                    let url = '{{url('apiLocal/demand/process/store')}}';
+                    let data = {'demand_id':demand['id'],'explain':$($e.target).val()};
+
+                    window.tempTip.setDuration(3000);
+                    window.axios.post(url,data).then(res=>{
+                        if(res.data.success){
+                            demand['processes'].unshfit(res.data.data);
+                            this.$forceUpdate();
+
+                            window.tempTip.showSuccess('添加处理过程成功')
+                            return ;
+                        }
+                        window.tempTip.show('添加处理过程失败')
+                    }).catch(err=>{
+                        window.tempTip.show('添加处理过程异常:'+err);
+                    })
 
                 },
                 /** 文件上传 */
                 uploadFile(){
+                    let fileInput = document.querySelector('#upLoadFile-input');
+                    let url = '{{url('apiLocal/demand/uploadFile')}}';
+
+                    let formData = new FormData();
+                    formData.append('id',this.selectDemand);
+                    let file = fileInput.files[0];
+                    formData.append('file',file);
 
+                    window.tempTip.setDuration(3000);
+                    window.axios.post(url,formData).then(res=>{
+                        if(res.data.success){
+                            this.initDemand(res.data.data);
+                            this.$set(this.demands,this.selectIndex,res.data.data);
+                            $('#uploadFile').modal('hide');
+                            window.tempTip.showSuccess('文件上传成功');
+                            return;
+                        }
+                        window.tempTip.show('文件上传失败');
+                    }).catch(err=>{
+                        window.tempTip.show('文件上传异常:'+err);
+                    });
                 },
                 /** 修改需求描述 */
-                updateDemand(demand,$e){
+                updateDemand(demand,column,$e){
+                    let url = '{{url('apiLocal/demand/update')}}';
+                    let data = {'id':demand['id']};
+                    let value = $($e.target).val();
+                    data[column] = value;
 
+                    window.tempTip.setDuration(3000);
+                    window.axios.post(url,data).then(res=>{
+                        if(res.data.success){
+                            demand[column] = value;
+                            this.$forceUpdate();
+                            window.tempTip.showSuccess('修改需求成功');
+                            return;
+                        }
+                        window.tempTip.show(res.data.data);
+                    }).catch(err=>{
+                        window.tempTip.show('修改需求描述异常:'+err);
+                    });
                 },
                 /** 问题认领 */
                 claimDemand(demand,index){
+                    console.log(demand);
                     let url = '{{url('apiLocal/demand/claim')}}';
                     window.tempTip.setDuration(3000);
                     window.axios.post(url,{id:demand['id']}).then(res=>{
                         if(res.data.success){
-                            window.tempTip.showSuccess('认领成功!');
                             this.initDemand(res.data.data);
                             this.$set(this.demands,index,res.data.data);
+                            window.tempTip.showSuccess('认领成功!');
                             return ;
                         }
-                        window.tempTip.show(res.data.message);
+                        if(res.data.errors)window.tempTip.show(res.data.errors);
+                        else window.tempTip.show(res.data.data);
                     }).catch(err=>{
                         window.tempTip.show('认领出现异常'+err);
                     });
+                },
+                showUploadDiv(demand,index){
+                    this.selectDemand = demand['id'];
+                    this.selectIndex = index;
+                    $('#uploadFile').modal('show');
                 }
             }
         });