|
@@ -0,0 +1,99 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+namespace App\Http\Controllers\AdminApi;
|
|
|
|
|
+
|
|
|
|
|
+use App\Http\Controllers\AdminController;
|
|
|
|
|
+use App\Models\Contract;
|
|
|
|
|
+use App\Servers\System\CommonServer;
|
|
|
|
|
+use Illuminate\Support\Facades\Storage;
|
|
|
|
|
+
|
|
|
|
|
+class ContractController extends AdminController
|
|
|
|
|
+{
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取项目合同
|
|
|
|
|
+ * @return \Illuminate\Http\JsonResponse
|
|
|
|
|
+ */
|
|
|
|
|
+ function getContractList(){
|
|
|
|
|
+
|
|
|
|
|
+ $where = [['is_del',0]];
|
|
|
|
|
+
|
|
|
|
|
+ $list = Contract::where($where)
|
|
|
|
|
+ ->select(['id','name','created_at'])
|
|
|
|
|
+ ->paginate(10);
|
|
|
|
|
+ return $this->apiResponseSuccess('获取列表成功', [
|
|
|
|
|
+ 'items' => $list->items(),
|
|
|
|
|
+ 'total' => $list->total(),
|
|
|
|
|
+ 'limit' => 10,
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 添加&编辑项目对应合同
|
|
|
|
|
+ * @return \Illuminate\Http\JsonResponse
|
|
|
|
|
+ * @throws \Throwable
|
|
|
|
|
+ */
|
|
|
|
|
+ function saveContract(){
|
|
|
|
|
+
|
|
|
|
|
+ $id=request()->input('id','');//id
|
|
|
|
|
+ $name=request()->input('name','');//合同名称
|
|
|
|
|
+ if (empty($name)) return $this->apiResponseError('请填写合同名称');
|
|
|
|
|
+ if (mb_strlen($name) > 100) return $this->apiResponseError('合同名称最大100');
|
|
|
|
|
+
|
|
|
|
|
+ $file =request()->file('file','');//文件
|
|
|
|
|
+ if (empty($file)){
|
|
|
|
|
+ return $this->apiResponseError('请选择文件');
|
|
|
|
|
+ }
|
|
|
|
|
+ //检查合同名称是否存在
|
|
|
|
|
+
|
|
|
|
|
+ $info = Contract::where('name',$name)->where('is_del',0)->select(['id'])->first();
|
|
|
|
|
+ if (!empty($info)) {
|
|
|
|
|
+ return $this->apiResponseError('合同名称已存在');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $file_name = $file->{'file_name'};
|
|
|
|
|
+ $contracts_file = Storage::put($file_name, $file, 'public/contract');
|
|
|
|
|
+
|
|
|
|
|
+ $data = compact('name','contracts_file');
|
|
|
|
|
+
|
|
|
|
|
+ if(empty($id)){//不存在id就创建
|
|
|
|
|
+
|
|
|
|
|
+ $res = Contract::create($data);
|
|
|
|
|
+ }else{//存在就更新
|
|
|
|
|
+ $info = Contract::where('id',$id)->first();
|
|
|
|
|
+ if (empty($info)) {
|
|
|
|
|
+ return $this->apiResponseError('没有找到该记录');
|
|
|
|
|
+ }
|
|
|
|
|
+ $res = $info->update($data);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ($res) {
|
|
|
|
|
+ return $this->apiResponseSuccess('操作成功');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return $this->apiResponseError('操作失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除
|
|
|
|
|
+ * @return \Illuminate\Http\JsonResponse
|
|
|
|
|
+ */
|
|
|
|
|
+ function delContract(){
|
|
|
|
|
+ $id = request()->input('id','');//获取需要删除的id
|
|
|
|
|
+ if(empty($id)) return $this->apiResponseError('缺少必要参数');
|
|
|
|
|
+
|
|
|
|
|
+ $info = Contract::where('id',$id)->select(['id'])->first();
|
|
|
|
|
+ if (empty($info)) {
|
|
|
|
|
+ return $this->apiResponseError('没有找到该记录');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $res = Contract::where('id',$id)->update(['is_del'=>1]);
|
|
|
|
|
+ if ($res) {
|
|
|
|
|
+ return $this->apiResponseSuccess('删除成功');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return $this->apiResponseError('删除失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|