|
|
@@ -1,7 +1,8 @@
|
|
|
<?php
|
|
|
|
|
|
-namespace App\Http\Controllers\api\procurement\wechat;
|
|
|
+namespace App\Http\Controllers\api\thirdPart\weixin;
|
|
|
|
|
|
+use App\Components\ApiProcurementResponse;
|
|
|
use App\Http\Controllers\Controller;
|
|
|
use App\Procurement;
|
|
|
use App\ProcurementCheckSheet;
|
|
|
@@ -16,6 +17,7 @@ use Illuminate\Support\Facades\Auth;
|
|
|
|
|
|
class ProcurementController extends Controller
|
|
|
{
|
|
|
+ use ApiProcurementResponse;
|
|
|
|
|
|
public function getWaitQuotation(Request $request): \Illuminate\Http\JsonResponse
|
|
|
{
|
|
|
@@ -26,14 +28,18 @@ 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)$procurement->deadline=Carbon::parse($procurement->deadline)->diffInMilliseconds(Carbon::now()); //待报价倒计时4小时
|
|
|
+ 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小时
|
|
|
}
|
|
|
$procurements = $procurements->diffKeys($keys);
|
|
|
- if (!empty($procurements))return response()->json(['status'=>1,'data'=>$procurements], 200);
|
|
|
+ if (!empty($procurements)) return $this->success($procurements);
|
|
|
}
|
|
|
|
|
|
public function getQuotationDetailById(Request $request): \Illuminate\Http\JsonResponse
|
|
|
@@ -43,7 +49,7 @@ class ProcurementController extends Controller
|
|
|
->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);
|
|
|
+ if ($procurement) return $this->success($procurement);
|
|
|
}
|
|
|
//报价
|
|
|
public function setOffer(Request $request): \Illuminate\Http\JsonResponse
|
|
|
@@ -64,7 +70,7 @@ class ProcurementController extends Controller
|
|
|
'status'=>1,//2:已报价
|
|
|
]);
|
|
|
$procurement->update(['status'=>1]);//1:已报价
|
|
|
- if ($procurementQuotation) return response()->json(['status'=>1,'data'=>$procurementQuotation], 200);
|
|
|
+ if ($procurementQuotation) return $this->success($procurementQuotation);
|
|
|
}
|
|
|
//接单
|
|
|
public function accept(Request $request): \Illuminate\Http\JsonResponse
|
|
|
@@ -81,7 +87,7 @@ class ProcurementController extends Controller
|
|
|
}else{
|
|
|
$procurement->update(['status'=>4,'deadline'=>Carbon::now()->toDateTimeString()]);//4:生产中
|
|
|
}
|
|
|
- if ($procurement) return response()->json(['status'=>1,'data'=>$procurement], 200);
|
|
|
+ if ($procurement) return $this->success($procurement);
|
|
|
}
|
|
|
//生产中的订单
|
|
|
public function getProductionProcurement(): \Illuminate\Http\JsonResponse
|
|
|
@@ -91,14 +97,14 @@ class ProcurementController extends Controller
|
|
|
->whereIn('type',[0,2])
|
|
|
->where('status',4) //4:生产中
|
|
|
->get();
|
|
|
- if ($procurements) return response()->json(['status'=>1,'data'=>$procurements], 200);
|
|
|
+ if ($procurements) return $this->success($procurements);
|
|
|
}
|
|
|
//结束生产
|
|
|
public function finishProductionProcurement(Request $request): \Illuminate\Http\JsonResponse
|
|
|
{
|
|
|
$id=$request->input('id');
|
|
|
$procurement=Procurement::query()->find($id)->update(['status'=>5]);
|
|
|
- if ($procurement) return response()->json(['status'=>1,'data'=>$procurement], 200);
|
|
|
+ if ($procurement) return $this->success($procurement);
|
|
|
}
|
|
|
|
|
|
public function getProcurementDeliveries(): \Illuminate\Http\JsonResponse
|
|
|
@@ -107,7 +113,7 @@ class ProcurementController extends Controller
|
|
|
->with('procurement.ownerMaterial.material')
|
|
|
->whereIn('status',[0,1])//1:待送货,2:送货中
|
|
|
->get();
|
|
|
- if ($procurementDeliveries) return response()->json(['status'=>1,'data'=>$procurementDeliveries], 200);
|
|
|
+ if ($procurementDeliveries) return $this->success($procurementDeliveries);
|
|
|
}
|
|
|
public function makeProcurementDelivery(Request $request): \Illuminate\Http\JsonResponse
|
|
|
{
|
|
|
@@ -138,20 +144,20 @@ class ProcurementController extends Controller
|
|
|
$procurementDelivery->loadMissing( 'procurement.ownerMaterial.material');
|
|
|
//当前采购单不是打样单生成对账单
|
|
|
if ($procurement->type!=2)ProcurementCheckSheet::query()->create(['procurement_delivery_id'=>$procurementDelivery->id,'account_payable'=>$procurementDelivery->receipt_amount*$procurement->cost_price,'auditor'=>0]);
|
|
|
- if ($procurementDelivery) return response()->json(['status'=>1,'data'=>$procurementDelivery], 200);
|
|
|
+ if ($procurementDelivery) return $this->success($procurementDelivery);
|
|
|
}
|
|
|
public function getProcurementDeliveryById(Request $request): \Illuminate\Http\JsonResponse
|
|
|
{
|
|
|
$procurementDelivery=ProcurementDeliverie::query()
|
|
|
->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);
|
|
|
+ if ($procurementDelivery) return $this->success($procurementDelivery);
|
|
|
}
|
|
|
public function updateProcurementDeliveryAmount(Request $request): \Illuminate\Http\JsonResponse
|
|
|
{
|
|
|
$param=$request->all(['id','delivernum']);
|
|
|
$procurementDelivery=ProcurementDeliverie::query()->where('id',$param['id'])->update(['amount'=>$param['delivernum']]);
|
|
|
- if ($procurementDelivery)return response()->json(['status'=>1,'data'=>$procurementDelivery], 200);
|
|
|
+ if ($procurementDelivery)return $this->success($procurementDelivery);
|
|
|
}
|
|
|
|
|
|
public function getProcurementTotalBill(): \Illuminate\Http\JsonResponse
|
|
|
@@ -162,13 +168,13 @@ class ProcurementController extends Controller
|
|
|
/** @var ProcurementTotalBill $procurementTotalBill */
|
|
|
$procurementTotalBill->setCurrentMothProcurements();
|
|
|
}
|
|
|
- if ($procurementTotalBills) return response()->json(['status'=>1,'data'=>$procurementTotalBills], 200);
|
|
|
+ if ($procurementTotalBills) return $this->success($procurementTotalBills);
|
|
|
}
|
|
|
public function markProcurementTotalBillStatus(Request $request): \Illuminate\Http\JsonResponse//供应商提交对账单
|
|
|
{
|
|
|
$id=$request->input('id');
|
|
|
$procurementTotalBill=ProcurementTotalBill::query()->find($id)->update(['status'=>1]);//1:已出账
|
|
|
- return response()->json(['status'=>1,'data'=>$procurementTotalBill], 200);
|
|
|
+ return $this->success($procurementTotalBill);
|
|
|
}
|
|
|
//收货员确认收货
|
|
|
public function makeReceipt(Request $request): \Illuminate\Http\JsonResponse
|
|
|
@@ -177,7 +183,7 @@ class ProcurementController extends Controller
|
|
|
$procurementDelivery=ProcurementDeliverie::query()->with('procurement')->find($param['id']);
|
|
|
$procurementDelivery ->update(['status'=>1,'receipt_amount'=>$param['delivernum'],'created_at'=>Carbon::now()->toDateTimeString(),'signed_at'=>Carbon::now()->toDateString()]);
|
|
|
$procurementDelivery->procurement->update(['status'=>6]);
|
|
|
- if ($procurementDelivery) return response()->json(['status'=>1,'data'=>$procurementDelivery], 200);
|
|
|
+ if ($procurementDelivery) return $this->success($procurementDelivery);
|
|
|
}
|
|
|
public function supplierDeliverConfirm(Request $request): \Illuminate\Http\JsonResponse
|
|
|
{
|
|
|
@@ -190,6 +196,6 @@ class ProcurementController extends Controller
|
|
|
&& $procurementCheckSheet)
|
|
|
$procurementCheckSheet->update(['status'=>1,'account_payable'=>($procurementDelivery->receipt_amount*$procurementDelivery->procurement->cost_price)]);
|
|
|
$procurementDelivery->procurement->update(['status'=>7]);//待出账
|
|
|
- if ($procurementDelivery) return response()->json(['status'=>1,'data'=>$procurementDelivery], 200);
|
|
|
+ if ($procurementDelivery) return $this->success($procurementDelivery);
|
|
|
}
|
|
|
}
|