|
|
@@ -115,102 +115,6 @@ class OrderIssue extends Model
|
|
|
return $createLog->user->name ?? '';
|
|
|
}
|
|
|
|
|
|
- public function 同步退单状态(){
|
|
|
- $rejectedItems = [];
|
|
|
- $orderItems = [];
|
|
|
- $orderIssueId = $this['id'];
|
|
|
- if ($this->logistic_number_return ?? false) {
|
|
|
- $rejectedBillItems = RejectedBillItem::query()->with('quality')
|
|
|
- ->whereHas('rejectedBill.orderIssue', function ($query) use ($orderIssueId) {
|
|
|
- $query->where('id',$orderIssueId);
|
|
|
- })->get();
|
|
|
- if($rejectedBillItems->where('quality.name','残次')->count() > 0){
|
|
|
- $this->update(['rejecting_status' => '差异退回']);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (count($rejectedBillItems) == 0) {
|
|
|
- $this->update(['rejecting_status' => '未退回']);
|
|
|
- return;
|
|
|
- }
|
|
|
- $barcodeGoods = data_get($rejectedBillItems,'*.barcode_goods');
|
|
|
- $commodityBarcodes = CommodityBarcode::query()->with('commodity')->whereIn('code',$barcodeGoods)->get();
|
|
|
- $commodities = Commodity::query()->whereIn('sku',$barcodeGoods)->get();
|
|
|
-
|
|
|
- foreach ($rejectedBillItems as $item) {
|
|
|
- $barcode_goods = (string)$item->barcode_goods;
|
|
|
- $commodity = $commodities->where('sku',$barcode_goods)->first();
|
|
|
- if(!$commodity){
|
|
|
- $commodityBarcode = $commodityBarcodes->where('code',$barcode_goods)->first();
|
|
|
- $barcode_goods = $commodityBarcode->commodity->sku ?? $barcode_goods;
|
|
|
- }
|
|
|
- if (!isset($rejectedItems[$barcode_goods])){
|
|
|
- $rejectedItems[$barcode_goods] = 0;
|
|
|
- }
|
|
|
- $rejectedItems[(string)$barcode_goods] += $item->amount;
|
|
|
- }
|
|
|
- } else {
|
|
|
- $this->update(['rejecting_status' => '未退回']);
|
|
|
- return;
|
|
|
- }
|
|
|
- if ($this->order_id ?? false) {
|
|
|
- $items = OrderPackageCommodities::query()
|
|
|
- ->with(['commodity','package.order.issue'])
|
|
|
- ->whereHas('package.order.issue', function ($query) use ($orderIssueId) {
|
|
|
- $query->where('id', $orderIssueId);
|
|
|
- })->get();
|
|
|
- if (count($items) > 0) {
|
|
|
- foreach ($items as $item) {
|
|
|
- $sku = $item['commodity']['sku'];
|
|
|
- if (! isset($orderItems[$sku]) ?? false){
|
|
|
- $orderItems[$sku] = 0;
|
|
|
- }
|
|
|
- $orderItems[$sku] += $item->amount;
|
|
|
- }
|
|
|
- } else {
|
|
|
- $this->update(['rejecting_status' => '无']);
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- $rejectedExcess = 0; // 退回差异
|
|
|
- $rejectedReview = 0; // 退回复核 $rejectedItems == $orderItems
|
|
|
- foreach ($rejectedItems as $key => $items) {
|
|
|
- if ($orderItems[$key] ?? false) {
|
|
|
- if ($rejectedItems[$key] == $orderItems[$key])
|
|
|
- $rejectedReview++;
|
|
|
- } else
|
|
|
- $rejectedExcess++;
|
|
|
- }
|
|
|
- if ($rejectedExcess > 0) {
|
|
|
- $this->update(['rejecting_status' => '差异退回']);
|
|
|
- return;
|
|
|
- }
|
|
|
- // 全部退回 部分退回 超量退回 差异退回 未退回 无
|
|
|
- $isExcess = 0; // 超量 $orderItems < $rejectedItems
|
|
|
- $isDiff = 0; // 部分 $orderItems > $rejectedItems
|
|
|
- $isAccord = 0; // 相同 $orderItems == $rejectedItems
|
|
|
- $isLack = 0; // 缺少 $orderItems != $rejectedItems
|
|
|
- foreach ($orderItems as $key => $item) {
|
|
|
- if ($rejectedItems[$key] ?? false) {
|
|
|
- if ($orderItems[$key] < $rejectedItems[$key])
|
|
|
- $isExcess++;
|
|
|
- else if ($orderItems[$key] > $rejectedItems[$key])
|
|
|
- $isDiff++;
|
|
|
- else if ($orderItems[$key] == $rejectedItems[$key])
|
|
|
- $isAccord++;
|
|
|
- } else
|
|
|
- $isLack++;
|
|
|
- }
|
|
|
-
|
|
|
- if($isAccord == $rejectedReview && $isLack == 0 && $isExcess == 0 && $isDiff==0 && $rejectedExcess == 0 )
|
|
|
- $this->update(['rejecting_status' => '全部退回']);
|
|
|
- else if($isExcess > 0 && $isAccord == $rejectedReview && $isDiff == 0 && $isLack == 0)
|
|
|
- $this->update(['rejecting_status' => '超量退回']);
|
|
|
- else if($isDiff >=0 && $isAccord == $rejectedReview && $isLack >=0 && $rejectedExcess ==0 && $isExcess==0)
|
|
|
- $this->update(['rejecting_status' => '部分退回']);
|
|
|
- else if($isLack >= 0 && $rejectedExcess>=0 && $isDiff>=0 && $isLack>=0 && $isExcess>=0 && $rejectedReview>=0)
|
|
|
- $this->update(['rejecting_status' => '差异退回']);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 同步退货状态
|
|
|
*/
|
|
|
@@ -348,6 +252,20 @@ class OrderIssue extends Model
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public function syncRejected($logistic_number)
|
|
|
+ {
|
|
|
+ $query = RejectedBill::query()->selectRaw('id');
|
|
|
+ if(is_array($logistic_number)){
|
|
|
+ $query->whereIn('logistic_number_return',$logistic_number);
|
|
|
+ }elseif (is_string($logistic_number)){
|
|
|
+ $query->where('logistic_number_return',$logistic_number);
|
|
|
+ }else return;
|
|
|
+ $items = RejectedBillItem::query()->whereIn('id_rejected_bill',$query);
|
|
|
+ if($items->count() > 0) $this->update(['is_new_rejecting'=>'有']);
|
|
|
+ elseif($items->count() == 0) $this->update(['is_new_rejecting'=>'无']);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* @param array|string $logistic_number
|
|
|
* @return array|void
|
|
|
@@ -355,6 +273,7 @@ class OrderIssue extends Model
|
|
|
public function joinRejectedBill($logistic_number)
|
|
|
{
|
|
|
if(!$logistic_number)return null;
|
|
|
+ $this->syncRejected($logistic_number);
|
|
|
if(is_array($logistic_number)){
|
|
|
return $this->rejectedBills()->sync($logistic_number,false);
|
|
|
}
|