Browse Source

调整采购管理,询价单页面显示

haozi 5 năm trước cách đây
mục cha
commit
ac9e8ebc88

+ 12 - 8
app/Http/Controllers/ProcurementController.php

@@ -66,11 +66,16 @@ class ProcurementController extends Controller
         $owner_ids=app('UserService')->getPermittingOwnerIds(auth()->user());
         $procurements = Procurement::query()
             ->filter($filters)
-            ->with(['initiator','ownerMaterial.file','ownerMaterial.material','ownerMaterial.owner'=>function($query)use($owner_ids){
+            ->with(['initiator','ownerMaterial.file','ownerMaterial.material','supplier','ownerMaterial.owner'=>function($query)use($owner_ids){
                 $query->with('customer')->whereIn('id',$owner_ids);
             },'procurementDeliveries'])->paginate($param['paginate'] ?? 50);
         foreach ($procurements as $procurement){
             if (empty($procurement->procurementDeliveries))continue;
+            if (Carbon::now()->gt($procurement['deadline'])){
+                $procurement->isFinishEnquiry=true;
+            }else{
+                $procurement->isFinishEnquiry=false;
+            }
             $procurement->deliver_amount=$procurement->procurementDeliveries->sum('amount');
         }
         /** @var OwnerMaterialService $ownerMaterialService*/
@@ -107,7 +112,7 @@ class ProcurementController extends Controller
         $request->validated();
         $param=$request->all(['owner_material_id','quantity','amount','unit_price']);
         $procurement=$this->newProcurement($param,Auth::user()['id']);
-        $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer','ownerMaterial.file']);
+        $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer','ownerMaterial.file','supplier']);
         if ($procurement) return ['success' => true,'data' => $procurement];
         else return ['success' => false, 'message' => '添加失败'];
 
@@ -126,7 +131,6 @@ class ProcurementController extends Controller
             'initiator'=>Auth::user()['id'],
             'type'=>1,
             'status'=>0,
-            'time'=>14400000,
         ]);
         $procurement->save();
         $number_id=$procurement['id'];
@@ -137,7 +141,7 @@ class ProcurementController extends Controller
         $deadline=$procurementService->computeDeadline($procurement->created_at);
         $procurement->update(['code'=>$procurement_code,'deadline'=>$deadline]);
         dispatch(new ProcurementConfirmInform($procurement));  //推送发送订单通知消息模板  队列
-        $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer','ownerMaterial.file']);
+        $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer','ownerMaterial.file','supplier']);
         if ($procurement) return ['success' => true,'data' => $procurement];
         else return ['success' => false, 'message' => '添加失败'];
 
@@ -166,7 +170,7 @@ class ProcurementController extends Controller
         $deadline=$procurementService->computeDeadline($procurement->created_at);
         $procurement->update(['code'=>$procurement_code,'deadline'=>$deadline]);
         dispatch(new ProcurementConfirmInform($procurement));  //推送发送订单通知消息模板  队列
-        $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer','ownerMaterial.file']);
+        $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer','ownerMaterial.file','supplier']);
         if ($procurement) return ['success' => true,'data' => $procurement];
         else return ['success' => false, 'message' => '添加失败'];
 
@@ -208,7 +212,7 @@ class ProcurementController extends Controller
         ]);
         dispatch(new ProcurementReceive($procurement))->delay(now()->addHours($receive_time)); //可从系统配置获取
         dispatch(new ProcurementWaitConfirmInform($procurement));
-        $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer','ownerMaterial.file']);
+        $procurement = $procurement->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer','ownerMaterial.file','supplier']);
         if ($procurement) return ['success' => true,'data' => $procurement];
         else return ['success' => false, 'message' => '发起采购失败'];
     }
@@ -230,7 +234,7 @@ class ProcurementController extends Controller
         $cost_price=$request->input('cost_price');
         $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','ownerMaterial.file']);
+        $procurement = $procurement->loadMissing(['initiator','supplier','ownerMaterial.material','ownerMaterial.owner.customer','ownerMaterial.file','supplier']);
         if ($procurement) return ['success' => true,'data' => $procurement];
         else return ['success' => false, 'message' => '修改采购单价失败!'];
 
@@ -248,7 +252,7 @@ class ProcurementController extends Controller
             }else{
                 $pro=$this->newProcurement($procurement,Auth::user()['id'],$procurement->type);
             }
-            $pro->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer','ownerMaterial.file']);
+            $pro->loadMissing(['initiator','ownerMaterial.material','ownerMaterial.owner.customer','ownerMaterial.file','supplier']);
             $collect->add($pro);
         }
         if (!empty($collect)) return ['success' => true,'data' => $collect];

+ 0 - 5
app/Http/Controllers/TestController.php

@@ -158,11 +158,6 @@ class TestController extends Controller
     {
         return call_user_func([$this, $method], $request);
     }
-
-    public function test()
-    {
-        return view("test");
-    }
     public function assignBatch(){
         $batches = collect([
             [

+ 12 - 7
app/Http/Controllers/api/thirdPart/weixin/ProcurementController.php

@@ -14,6 +14,7 @@ use App\Services\ProcurementService;
 use Carbon\Carbon;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\DB;
 
 class ProcurementController extends Controller
 {
@@ -28,15 +29,11 @@ class ProcurementController extends Controller
             ->where('status',$status)
             ->get();
         $keys = [];
-        $now=Carbon::now();
         foreach ($procurements as $key=>$procurement){
             if ($procurement->procurement_quotations_count>0 && $status==0 )$keys[]= $key;
             if ($procurement->type==2 && $procurement->supplier_id )$keys[]= $key;
-            if($status==0){
-                if ($procurement->deadline>$now) $procurement->deadline=Carbon::parse($procurement->deadline)->diffInMilliseconds(); //待报价倒计时4小时
-                else $procurement->deadline=0;
-            }
-            if($status==2)$procurement->deadline=Carbon::parse($procurement->deadline)->subHours(-24)->diffInMilliseconds(Carbon::now()); //待接单倒计时24小时
+            if (Carbon::parse($procurement->deadline)->gt(Carbon::now())) $procurement->deadline=Carbon::parse($procurement->deadline)->diffInMilliseconds();
+            else $procurement->deadline=0;
         }
         $procurements = $procurements->diffKeys($keys);
         if (!empty($procurements)) return $this->success($procurements);
@@ -69,7 +66,15 @@ class ProcurementController extends Controller
             'quoted_at'=>Carbon::now()->toDateTimeString(),
             'status'=>1,//2:已报价
         ]);
-        $procurement->update(['status'=>1]);//1:已报价
+        DB::transaction(function ()use($procurement,$param,$supplier){
+            if (!$procurement->supplier_id)$procurement->update([
+                "supplier_id" => $supplier->id,
+                "status" =>1,
+                "cost_price" =>$param['offer'],
+            ]);
+            DB::commit();
+        });
+//        $procurement->update(['status'=>1]);//1:已报价
         if ($procurementQuotation) return $this->success($procurementQuotation);
     }
     //接单

+ 0 - 1
app/Jobs/ProcurementEnquiry.php

@@ -60,7 +60,6 @@ class ProcurementEnquiry implements ShouldQueue
            ]);
             dispatch(new ProcurementReceive($this->procurement))->delay(now()->addHours($receive_time)); //可从系统配置获取
             dispatch(new ProcurementWaitConfirmInform($this->procurement));
-
         }catch (\Exception $e){
             LogService::log(__METHOD__,"ERROR-采购延时选定最低报价供应商",$this->procurement->toJson()." | ".$e->getMessage());
         }

+ 2 - 0
app/Procurement.php

@@ -4,6 +4,7 @@ namespace App;
 
 use App\Services\api\UserService;
 use App\Traits\ModelTimeFormat;
+use Carbon\Carbon;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Model;
 
@@ -55,6 +56,7 @@ class Procurement extends Model
         }
     }
 
+
     public  function ownerMaterial(): \Illuminate\Database\Eloquent\Relations\HasOne
     {
         return $this->hasOne('App\OwnerMaterial','id','owner_material_id');

+ 4 - 2
app/ProcurementQuotation.php

@@ -31,10 +31,12 @@ class ProcurementQuotation extends Model
         8 => "已出账",
         9 => "完结",
     ];
-    public  function supplier(){
+    public  function supplier(): \Illuminate\Database\Eloquent\Relations\HasOne
+    {
         return $this->hasOne('App\Supplier','id','supplier_id');
     }
-    public function procurement(){
+    public function procurement(): \Illuminate\Database\Eloquent\Relations\BelongsTo
+    {
         return $this->belongsTo('App\Procurement','procurement_id','id');
     }
 

+ 10 - 2
resources/views/procurement/procurement/index.blade.php

@@ -92,7 +92,13 @@
                             <span v-else>-</span>
                     </div>
                 </td>
+                <td>
+                    <span v-if="procurement_type[procurement.type]=='询价单' && procurement.supplier" >@{{ procurement.supplier.name ??  '' }}</span>
+                </td>
                 <td>@{{ procurement.quantity }}</td>
+                <td>
+                    <span v-if="procurement_type[procurement.type]=='询价单'">@{{ procurement.cost_price }}</span>
+                </td>
                 <td><span>@{{ procurement.unit_price }}</span></td>
                 <td><span v-if="procurement.deliver_amount">@{{ procurement.deliver_amount }}</span></td>
                 <td><span>@{{ procurement.quantity*procurement.unit_price }}</span></td>
@@ -102,9 +108,9 @@
                 <td><span v-if="procurement.owner_material.owner.customer">@{{ procurement.owner_material.owner.customer.phone }}</span></td>
                 <td>
                     <span v-if="procurement_status[procurement.status]!='订单取消'">
-                        <span class="btn btn-sm btn-outline-danger" v-if="!procurement.supplier_id"
+                        <span class="btn btn-sm btn-outline-danger" v-if="procurement.status<3"
                               @click="cancel(procurement.id,procurement.type,procurement.code)">取消</span>
-                        <span class="btn btn-sm btn-outline-success" v-if="procurement_type[procurement.type]=='询价单' && !procurement.cost_price"
+                        <span class="btn btn-sm btn-outline-success" v-if="procurement_type[procurement.type]=='询价单' && procurement.isFinishEnquiry"
                               @click="initiateProcurement(procurement)">发起采购</span>
                     </span>
                 </td>
@@ -215,7 +221,9 @@
                     {name: 'special', value: '特殊要求', class: 'text-center'},
                     {name: 'specification', value: '材质规格', class: 'text-center'},
                     {name: '附件', value: '附件', class: 'text-center'},
+                    {name: 'supplier', value: '供应商', class: 'text-center'},
                     {name: 'quantity', value: '采购数量', neglect: true,class: 'text-center'},
+                    {name: 'offer', value: '采购单价(元)', neglect: true,class: 'text-center'},
                     {name: 'unit_price', value: '销售单价(元)', neglect: true,class: 'text-center'},
                     {name: '', value: '送货数量', neglect: true,class: 'text-center'},
                     {name: '', value: '销售总价(元)', neglect: true,class: 'text-center'},