panghu 1 سال پیش
والد
کامیت
cba13ce6dd
4فایلهای تغییر یافته به همراه146 افزوده شده و 0 حذف شده
  1. 99 0
      app/Http/Controllers/AdminApi/ContractController.php
  2. 30 0
      app/Models/Contract.php
  3. 3 0
      public/nginx.htaccess
  4. 14 0
      routes/adminApi/contract.php

+ 99 - 0
app/Http/Controllers/AdminApi/ContractController.php

@@ -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('删除失败');
+        }
+    }
+}

+ 30 - 0
app/Models/Contract.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Models;
+
+use DateTimeInterface;
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * App\Models\Contract
+ *
+ * @mixin \Eloquent
+ */
+class Contract extends Model
+{
+    use HasFactory;
+    protected $guarded = ['id', 'updated_at', 'created_at'];
+
+
+    /**
+     * 为数组 / JSON 序列化准备日期。
+     *
+     * @param \DateTimeInterface $date
+     * @return string
+     */
+    protected function serializeDate(DateTimeInterface $date)
+    {
+        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
+    }
+}

+ 3 - 0
public/nginx.htaccess

@@ -0,0 +1,3 @@
+location / {
+    try_files $uri $uri/ /index.php?$query_string;
+}

+ 14 - 0
routes/adminApi/contract.php

@@ -0,0 +1,14 @@
+<?php
+
+use Illuminate\Support\Facades\Route;
+
+
+Route::group( ['domain' => env('APP_ADMIN_HOST'), 'prefix' => 'contract'],function($router){
+
+    Route::match(['get','post'],'list', 'ContractController@getContractList')->name('adminApi.contract.list');// 列表
+    Route::match(['get','post'],'save', 'ContractController@saveContract')->name('adminApi.contract.save');// 添加&编辑
+    Route::match(['get','post'],'del', 'ContractController@delContract')->name('adminApi.contract.del'); //删除
+
+});
+
+