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');//合同名称 $sign_party=request()->input('sign_party',[]);//签署区域关键词 $texts=request()->input('texts',[]);//乙方方签署区域关键词 if (empty($name)) return $this->apiResponseError('请填写合同名称'); if (mb_strlen($name) > 100) return $this->apiResponseError('合同名称最大100'); if (empty($sign_party)) return $this->apiResponseError('请填写签署区信息'); $file_url =request()->input('file_url','');//文件 if (empty($file_url)){ return $this->apiResponseError('请上传文件'); } if (empty($texts)){ return $this->apiResponseError('请填写变量'); } $wordData = file_get_contents($file_url); //检查合同名称是否存在 $info = Contract::where('name',$name)->where('is_del',0)->select(['id'])->first(); if (!empty($info)) { return $this->apiResponseError('合同名称已存在'); } $pathInfo = pathinfo($file_url); $extension = $pathInfo['extension'];//获取文件扩展名 $file_name = $name.'.'.$extension; $file_path = 'storage/contract/'.date('Ymd').'/'; CommonServer::creatServer()->creatDir($file_path); $path=public_path($file_path); file_put_contents($path . $file_name,$wordData); $contracts_file = $file_path.$file_name; $data = compact('name','contracts_file','sign_party','texts'); 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 getContractInfo() { $id = request()->input('id','');//获取需要删除的id if(empty($id)) return $this->apiResponseError('缺少必要参数'); $info = Contract::where('id',$id)->first(); if (empty($info)) { return $this->apiResponseError('没有找到该记录'); } return $this->apiResponseSuccess('成功',$info); } /** * 删除 * @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('删除失败'); } } }