Ver código fonte

项目耗材--附件文件上传

haozi 5 anos atrás
pai
commit
2aa3161889

+ 4 - 2
app/Http/Controllers/OwnerMaterialController.php

@@ -9,6 +9,7 @@ use App\Material;
 use App\OwnerMaterial;
 use App\Services\OwnerService;
 use App\file;
+use App\UploadFile;
 use Faker\Provider\Uuid;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Auth;
@@ -70,8 +71,8 @@ class OwnerMaterialController extends Controller
             if(!$file)$this->error('请选择上传文件');
             $fileType = $file->getMimeType();// 文件类型
             $fileName = strtolower($file->getClientOriginalExtension());// 文件名
-            $path = $file->storeAs("ownerMaterial", Uuid::uuid() . "." . $fileName);
-            $file = file::query()->create([
+            $path = $file->storeAs("ownerMaterial", Uuid::uuid() . "." . $fileName/*,'public'*/);
+            $file = UploadFile::query()->create([
                 'table_name' => 'owner_material',
                 'table_id' => $ownerMaterial['id'],
                 'url' => $path,
@@ -90,6 +91,7 @@ class OwnerMaterialController extends Controller
         if(!Gate::allows('项目耗材'))return ['success'=>false,"data"=>"无权操作"];
         $file = $request->input("file");
         $name = $request->input("name");
+//        return response()->file(storage_path().'/app/public/'.$file);
         return Storage::download($file,$name);
     }
 }

+ 7 - 7
app/Http/Controllers/ProcurementController.php

@@ -59,7 +59,7 @@ class ProcurementController extends Controller
         $owner_ids=app('UserService')->getPermittingOwnerIds(auth()->user());
         $procurements = Procurement::query()
             ->filter($filters)
-            ->with(['initiator','ownerMaterial.material','ownerMaterial.owner'=>function($query)use($owner_ids){
+            ->with(['initiator','ownerMaterial.file','ownerMaterial.material','ownerMaterial.owner'=>function($query)use($owner_ids){
                 $query->with('customer')->whereIn('id',$owner_ids);
             }])->paginate($param['paginate'] ?? 50);
         /** @var OwnerMaterialService $ownerMaterialService*/
@@ -96,7 +96,7 @@ class ProcurementController extends Controller
         $param=$request->all(['owner_material_id','quantity','amount','unit_price']);
         try {
             $procurement=$this->newProcurement($param,Auth::user()['id']);
-            $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer']);
+            $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer','ownerMaterial.file']);
             if ($procurement) return ['success' => true,'data' => $procurement];
             else return ['success' => false, 'message' => '添加失败'];
         } catch (\Exception $e) {
@@ -128,7 +128,7 @@ class ProcurementController extends Controller
             $procurementService=app(ProcurementService::class);
             $deadline=$procurementService->computeDeadline($procurement->created_at);
             $procurement->update(['code'=>$procurement_code,'deadline'=>$deadline]);
-            $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer']);
+            $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer','ownerMaterial.file']);
             if ($procurement) return ['success' => true,'data' => $procurement];
             else return ['success' => false, 'message' => '添加失败'];
         } catch (\Exception $e) {
@@ -159,7 +159,7 @@ class ProcurementController extends Controller
             $procurementService=app(ProcurementService::class);
             $deadline=$procurementService->computeDeadline($procurement->created_at);
             $procurement->update(['code'=>$procurement_code,'deadline'=>$deadline]);
-            $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer']);
+            $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer','ownerMaterial.file']);
             if ($procurement) return ['success' => true,'data' => $procurement];
             else return ['success' => false, 'message' => '添加失败'];
         } catch (\Exception $e) {
@@ -200,7 +200,7 @@ class ProcurementController extends Controller
                 'cost_price'=>$param['offer'],
                 'supplier_id'=>$param['supplier_id'],
             ]);
-            $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer']);
+            $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer','ownerMaterial.file']);
             if ($procurement) return ['success' => true,'data' => $procurement];
             else return ['success' => false, 'message' => '发起采购失败'];
         } catch (\Exception $e) {
@@ -227,7 +227,7 @@ class ProcurementController extends Controller
         try {
             $procurement=Procurement::query()->find($id);
             if ($procurement->cost_price!=$cost_price)$procurement->update(['cost_price'=>$cost_price]);
-            $procurement = $procurement->loadMissing(['initiator','supplier','ownerMaterial.material','ownerMaterial.owner.customer']);
+            $procurement = $procurement->loadMissing(['initiator','supplier','ownerMaterial.material','ownerMaterial.owner.customer','ownerMaterial.file']);
             if ($procurement) return ['success' => true,'data' => $procurement];
             else return ['success' => false, 'message' => '修改采购单价失败!'];
         } catch (\Exception $e) {
@@ -247,7 +247,7 @@ class ProcurementController extends Controller
             }else{
                 $pro=$this->newProcurement($procurement,Auth::user()['id'],$procurement->type);
             }
-            $pro->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer']);
+            $pro->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer','ownerMaterial.file']);
             $collect->add($pro);
         }
         if (!empty($collect)) return ['success' => true,'data' => $collect];

+ 2 - 2
app/Http/Controllers/api/procurement/wechat/ProcurementController.php

@@ -40,7 +40,7 @@ class ProcurementController extends Controller
     {
         $id=$request->input('id');
         $procurement=Procurement::query()
-            ->with(['ownerMaterial.material','ownerMaterial.owner'])
+            ->with(['ownerMaterial.material','ownerMaterial.owner','ownerMaterial.file'])
             ->find($id);
         $procurement->deadline=Carbon::parse($procurement->deadline)->diffInMilliseconds(Carbon::now());
         if ($procurement) return response()->json(['status'=>1,'data'=>$procurement], 200);
@@ -143,7 +143,7 @@ class ProcurementController extends Controller
     public function getProcurementDeliveryById(Request $request)
     {
         $procurementDelivery=ProcurementDeliverie::query()
-            ->with(['procurement.ownerMaterial.material','receiver.userDetail','procurement.ownerMaterial.owner.customer','procurement.supplier',])
+            ->with(['procurement.ownerMaterial.material','receiver.userDetail','procurement.ownerMaterial.owner.customer','procurement.supplier','procurement.ownerMaterial.file'])
             ->find($request->input('id'));
         if ($procurementDelivery) return response()->json(['status'=>1,'data'=>$procurementDelivery], 200);
     }

+ 24 - 12
resources/views/procurement/procurement/index.blade.php

@@ -84,11 +84,20 @@
                 <td>@{{ procurement_type[procurement.type] }}</td>
                 <td><span v-if="procurement.owner_material.owner.customer">@{{ procurement.owner_material.owner.customer.company_name }}</span></td>
                 <td class="tooltipTarget" style="max-width: 200px;overflow:hidden"><span v-if="procurement.owner_material.material">@{{ procurement.owner_material.material.code }}</span></td>
-                <td class="text-muted"><span v-if="procurement.owner_material.material">@{{ procurement.owner_material.material.name }}</span></td>
-                <td class="text-muted"><span v-if="procurement.owner_material">@{{ procurement.owner_material.size }}</span></td>
-                <td class="text-muted"><span v-if="procurement.owner_material">@{{ procurement.owner_material.special }}</span></td>
-                <td class="text-muted"><span v-if="procurement.owner_material">@{{ procurement.owner_material.specification }}</span></td>
-                <td></td>
+                <td class=""><span v-if="procurement.owner_material.material">@{{ procurement.owner_material.material.name }}</span></td>
+                <td class=""><span v-if="procurement.owner_material">@{{ procurement.owner_material.size }}</span></td>
+                <td class=""><span v-if="procurement.owner_material">@{{ procurement.owner_material.special }}</span></td>
+                <td class=""><span v-if="procurement.owner_material">@{{ procurement.owner_material.specification }}</span></td>
+                <td>
+                    <div class="align-center text-center" >
+                            <span v-if="procurement.owner_material.file">
+                        <a target='_blank' :href="getDownFileUrl(procurement.owner_material)" class="text-primary text-decoration is-hover"  style="cursor: default" >
+                            <i class="fa fa-download"></i>&nbsp;@{{ procurement.owner_material.file.file_name }}
+                        </a>
+                    </span>
+                            <span v-else>-</span>
+                    </div>
+                </td>
                 <td>@{{ procurement.quantity }}</td>
                 <td><span>@{{ procurement.unit_price }}</span></td>
                 <td><span></span></td>
@@ -201,14 +210,14 @@
                     },
                     {name: 'code', value: '采购编号', neglect: true},
                     {name: 'owner_id', value: '项目', class: ''},
-                    {name: 'type', value: '单据类型', class: 'text-muted'},
-                    {name: 'company_name', value: '采购公司', class: 'text-muted'},
-                    {name: 'material_code', value: '耗材编号', class: 'text-muted'},
+                    {name: 'type', value: '单据类型', class: ''},
+                    {name: 'company_name', value: '采购公司', class: ''},
+                    {name: 'material_code', value: '耗材编号', class: ''},
                     {name: 'material_name', value: '耗材'},
-                    {name: 'size', value: '尺寸大小', class: 'text-muted'},
-                    {name: 'special', value: '特殊要求', class: 'text-muted'},
-                    {name: 'specification', value: '材质规格', class: 'text-muted'},
-                    {name: '附件', value: '附件', class: 'text-muted'},
+                    {name: 'size', value: '尺寸大小', class: ''},
+                    {name: 'special', value: '特殊要求', class: ''},
+                    {name: 'specification', value: '材质规格', class: ''},
+                    {name: '附件', value: '附件', class: ''},
                     {name: 'quantity', value: '采购数量', neglect: true},
                     {name: 'unit_price', value: '销售单价(元)', neglect: true},
                     {name: '', value: '送货数量', neglect: true},
@@ -472,6 +481,9 @@
                         window.tempTip.show("网络错误:" + err);
                     });
                 },
+                getDownFileUrl(ownerMaterial){
+                    return '{{ url("maintenance/ownerMaterial/downFile?file=")}}'+ownerMaterial.file.url+'&name='+ownerMaterial.file.file_name;
+                },
             }
         });
     </script>

+ 1 - 1
routes/apiLocal.php

@@ -122,7 +122,7 @@ Route::group(['prefix' => 'ownerMaterial'],function(){
     Route::post('store','OwnerMaterialController@storeApi');
     Route::post('update','OwnerMaterialController@updateApi');
     Route::delete('{id}','OwnerMaterialController@destroyApi');
-    Route::post('uploadFile','OwnerMaterialController@uploadFileApi');
+    Route::post('uploadFile','OwnerMaterialController@fileApi');
 });
 
 /** 供应商 */