|
|
@@ -363,7 +363,11 @@ class WorkOrderService
|
|
|
* @var WorkOrder $work_order
|
|
|
*/
|
|
|
$work_order = $detail->workOrder;
|
|
|
- $order_issue = OrderIssue::query()->where('order_id', $work_order->order_id)->first();
|
|
|
+ $order_issue = OrderIssue::query()->withTrashed()->where('order_id', $work_order->order_id)->first();
|
|
|
+ if($order_issue->deleted_at ?? false){
|
|
|
+ $order_issue->restore();
|
|
|
+ }
|
|
|
+ $orderIssueType = app(OrderIssueTypeService::class)->firstOrCreate(['name' => '错漏发']);
|
|
|
if (!$order_issue) {
|
|
|
$order_issue = OrderIssue::query()->create([
|
|
|
'order_id' => $work_order->order_id,
|
|
|
@@ -382,16 +386,18 @@ class WorkOrderService
|
|
|
'user_owner_group_id' => $work_order->user_owner_group_id,
|
|
|
]);
|
|
|
|
|
|
- $work_order_user_workgroup_ids = $work_order->userWorkGroups()->get()->map(function($item){
|
|
|
+ $work_order_user_workgroup_ids = $work_order->userWorkGroups()->get()->map(function ($item) {
|
|
|
return $item->id;
|
|
|
})->toArray();
|
|
|
|
|
|
- $order_issue_work_groups = $order_issue->userWorkgroups()->get()->map(function($item){
|
|
|
+ $order_issue_work_groups = $order_issue->userWorkgroups()->get()->map(function ($item) {
|
|
|
return $item->id;
|
|
|
- } )->toArray();
|
|
|
- $order_issue->userWorkgroups()->attach(array_diff($work_order_user_workgroup_ids,$order_issue_work_groups));
|
|
|
+ })->toArray();
|
|
|
+ $order_issue->userWorkgroups()->attach(array_diff($work_order_user_workgroup_ids, $order_issue_work_groups));
|
|
|
$process_logs = $detail->processLogs()->where('status', '未同步')->get();
|
|
|
- $order_issue->logs()->insert($process_logs->map((function ($process_log) use ($order_issue) {
|
|
|
+
|
|
|
+
|
|
|
+ $processLogs = $process_logs->map((function ($process_log) use ($order_issue) {
|
|
|
return [
|
|
|
'order_issue_id' => $order_issue->id,
|
|
|
'user_id' => $process_log->user_id,
|
|
|
@@ -401,14 +407,37 @@ class WorkOrderService
|
|
|
'type' => $process_log->type,
|
|
|
'tag' => $process_log->tag,
|
|
|
];
|
|
|
- }))->toArray());
|
|
|
+ }))->toArray();
|
|
|
+ if ($detail->order_issue_type_id == $orderIssueType->id) {
|
|
|
+ $commodityLog = $detail->commodities()->where('check_result', '!=', '核实未错漏发')->get()->map(function ($item) use ($order_issue) {
|
|
|
+ $count = 0;
|
|
|
+ $abnormalAmount = intval($item->abnormal_amount);
|
|
|
+ $baoShiCheckAmount = intval($item->bao_shi_check_amount);
|
|
|
+ if ($item->abnormal_type === '少发') {
|
|
|
+ $count = $baoShiCheckAmount - $abnormalAmount;
|
|
|
+ } else if ($item->abnormal_type === '多发') {
|
|
|
+ $count = $abnormalAmount- $baoShiCheckAmount;
|
|
|
+ }
|
|
|
+ return [
|
|
|
+ 'order_issue_id' => $order_issue->id,
|
|
|
+ 'user_id' => Auth::id(),
|
|
|
+ 'content' => $item->sku . ' ' . $item->commodity->name . ' ' . $item->abnormal_type . '(' . $count.')',
|
|
|
+ 'created_at' => $item->updated_at,
|
|
|
+ 'updated_at' => $item->updated_at,
|
|
|
+ 'type' => '处理',
|
|
|
+ 'tag' => 0
|
|
|
+ ];
|
|
|
+ })->toArray();
|
|
|
+ $processLogs = array_merge($commodityLog, $processLogs);
|
|
|
+ }
|
|
|
+ $order_issue->logs()->insert($processLogs);
|
|
|
$this->orderIssueService->endOrderIssues([$order_issue->id]);
|
|
|
$detail->processLogs()->where('status', '未同步')->update(['status' => '同步']);
|
|
|
}
|
|
|
|
|
|
- public function customRejectedStatus($ids,$customRejectedStatus): int
|
|
|
+ public function customRejectedStatus($ids, $customRejectedStatus): int
|
|
|
{
|
|
|
- return WorkOrder::query()->whereIn('id',$ids)->update(['custom_rejected_status' => $customRejectedStatus]);
|
|
|
+ return WorkOrder::query()->whereIn('id', $ids)->update(['custom_rejected_status' => $customRejectedStatus]);
|
|
|
}
|
|
|
|
|
|
}
|