|
|
@@ -6,6 +6,7 @@ use App\Components\AsyncResponse;
|
|
|
use App\Demand;
|
|
|
use App\Filters\DemandFilters;
|
|
|
use App\Http\Requests\Demand\DemandRequest;
|
|
|
+use App\Services\DemandService;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Contracts\Foundation\Application;
|
|
|
use Illuminate\Contracts\View\Factory;
|
|
|
@@ -26,22 +27,31 @@ class DemandController extends Controller
|
|
|
{
|
|
|
// 查询权限
|
|
|
|
|
|
- $demands = Demand::query()->with(['processes', 'initiator', 'handler', 'uploadFile'])->filter($filters)->paginate($request['paginate'] ?? 50);
|
|
|
+ $demands = Demand::query()->with(['processes', 'initiator', 'handler', 'uploadFile'])->filter($filters)->sql();
|
|
|
|
|
|
+ $demands = Demand::query()->with(['processes', 'initiator', 'handler', 'uploadFile'])->filter($filters)->paginate($request['paginate'] ?? 50);
|
|
|
return view('maintenance.demand.index', compact('demands'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param DemandRequest $request
|
|
|
+ * @param DemandService $service
|
|
|
*/
|
|
|
- public function storeApi(DemandRequest $request)
|
|
|
+ public function storeApi(DemandRequest $request,DemandService $service)
|
|
|
{
|
|
|
// 创建权限
|
|
|
-
|
|
|
+ /** @var Demand $demand */
|
|
|
$demand = Demand::query()->create($request->all());
|
|
|
|
|
|
- if ($demand) $this->success($demand);
|
|
|
- else $this->error('需求创建出现异常');
|
|
|
+ if ($demand) {
|
|
|
+
|
|
|
+ $file = $request->file('file');
|
|
|
+ if(isset($file))$service->saveUPLoadFile($demand,$file);
|
|
|
+
|
|
|
+ $this->success($demand);
|
|
|
+ } else{
|
|
|
+ $this->error('需求创建出现异常');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -64,32 +74,13 @@ class DemandController extends Controller
|
|
|
/**
|
|
|
* @param DemandRequest $request
|
|
|
* @param Demand $demand
|
|
|
+ * @param DemandService $service
|
|
|
*/
|
|
|
- public function uploadFileApi(DemandRequest $request, Demand $demand)
|
|
|
+ public function uploadFileApi(DemandRequest $request, Demand $demand,DemandService $service)
|
|
|
{
|
|
|
// 文件上传
|
|
|
|
|
|
-
|
|
|
- $file = $request->file('file');
|
|
|
- $tmpFile = $file->getRealPath();
|
|
|
-
|
|
|
- if (!$demand->uploadFile()) $this->error('该需求已有描述图片');
|
|
|
- if (!$file) $this->error('上传图片不得为空');
|
|
|
- if (!$file->isValid()) $this->error('找不到上传图片');
|
|
|
- if (!is_uploaded_file($tmpFile)) $this->error('文件错误');
|
|
|
-
|
|
|
- $fileSuffix = $file->getClientOriginalExtension();
|
|
|
-
|
|
|
- $fileName = date('ymd') . '-' . Uuid::uuid1();
|
|
|
-
|
|
|
- $filePath = storage_path('app/public/files/issue/' . $fileName . '-issue' . $fileSuffix);
|
|
|
-
|
|
|
- $result = move_uploaded_file($tmpFile, $filePath);
|
|
|
-
|
|
|
- if (!$result) $this->error('文件上传失败');
|
|
|
-
|
|
|
- $upLoadFile = $demand->saveFile($fileName,$fileSuffix);
|
|
|
- if(!$upLoadFile)$this->error('文件上传失败');
|
|
|
+ $service->saveUPLoadFile($demand,$request['file']);
|
|
|
|
|
|
$demand->loadMissing('authority', 'initiator', 'handler', 'uploadFile', 'processes');
|
|
|
|
|
|
@@ -112,4 +103,18 @@ class DemandController extends Controller
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 完结需求
|
|
|
+ *
|
|
|
+ * @param DemandRequest $request
|
|
|
+ * @param Demand $demand
|
|
|
+ */
|
|
|
+ public function finishApi(DemandRequest $request, Demand $demand)
|
|
|
+ {
|
|
|
+ if($demand->update(['status','1']))
|
|
|
+ $this->success($demand);
|
|
|
+ else
|
|
|
+ $this->error('修改失败');
|
|
|
+ }
|
|
|
+
|
|
|
}
|