|
|
@@ -1174,34 +1174,7 @@ SQL;
|
|
|
$query->where("audit_stage","合并运单");
|
|
|
})->whereIn("id",$ids)->get();
|
|
|
if ($waybills->count()==0)$this->error("运单不存在或非合并运单");
|
|
|
- foreach ($waybills as $waybill){
|
|
|
- $codes = explode(",",$waybill->wms_bill_number);
|
|
|
- $bills = explode(",",$waybill->source_bill);
|
|
|
- $remark = explode(",",$waybill->ordering_remark);
|
|
|
- if (!$codes)continue;
|
|
|
- /** @var Collection $destroys */
|
|
|
- foreach (Waybill::onlyTrashed()->whereIn("wms_bill_number",$codes)->get() as $obj){
|
|
|
- unset($codes[array_search($obj->wms_bill_number,$codes)]);
|
|
|
- unset($bills[array_search($obj->source_bill,$bills)]);
|
|
|
- if (array_search($obj->ordering_remark,$remark)===false)unset($bills[array_search($obj->ordering_remark,$remark)]);
|
|
|
- $waybill->charge -= (double)$obj->charge;
|
|
|
- $waybill->collect_fee -= (double)$obj->collect_fee;
|
|
|
- $waybill->other_fee -= (double)$obj->other_fee;
|
|
|
- $waybill->warehouse_weight_other -= (double)$obj->warehouse_weight_other;
|
|
|
- $waybill->warehouse_weight -= (double)$obj->warehouse_weight;
|
|
|
- }
|
|
|
- Waybill::onlyTrashed()->whereIn("wms_bill_number",explode(",",$waybill->wms_bill_number))->restore();
|
|
|
- $waybill->merge_owner = null;
|
|
|
- $waybill->source_bill = implode(",",$bills);
|
|
|
- $waybill->wms_bill_number = implode(",",$codes);
|
|
|
- $waybill->ordering_remark = implode(",",$remark);
|
|
|
- $waybill->update();
|
|
|
- WaybillAuditLog::query()->create([
|
|
|
- 'waybill_id'=>$waybill->id,
|
|
|
- 'audit_stage'=>'拆单返回',
|
|
|
- 'user_id'=>Auth::id(),
|
|
|
- ]);
|
|
|
- }
|
|
|
+ foreach ($waybills as $waybill)$this->split($waybill);
|
|
|
DB::commit();
|
|
|
}catch (\Exception $e){
|
|
|
DB::rollBack();
|
|
|
@@ -1210,6 +1183,38 @@ SQL;
|
|
|
$this->success(count($ids)==$waybills->count() ? '运单拆单完毕' : '部分运单不符合拆单条件');
|
|
|
}
|
|
|
|
|
|
+ private function split($waybill)
|
|
|
+ {
|
|
|
+ $codes = explode(",",$waybill->wms_bill_number);
|
|
|
+ if (!$codes || count($codes)<2)return;
|
|
|
+ $bills = explode(",",$waybill->source_bill);
|
|
|
+ $remark = explode(",",$waybill->ordering_remark);
|
|
|
+ /** @var Collection $waybills */
|
|
|
+ $waybills = Waybill::onlyTrashed()->whereIn("wms_bill_number",$codes)->get();
|
|
|
+ if (!$waybills->count())return;
|
|
|
+ foreach ($waybills as $obj){
|
|
|
+ unset($codes[array_search($obj->wms_bill_number,$codes)]);
|
|
|
+ unset($bills[array_search($obj->source_bill,$bills)]);
|
|
|
+ if (array_search($obj->ordering_remark,$remark)===false)unset($bills[array_search($obj->ordering_remark,$remark)]);
|
|
|
+ $waybill->charge -= (double)$obj->charge;
|
|
|
+ $waybill->collect_fee -= (double)$obj->collect_fee;
|
|
|
+ $waybill->other_fee -= (double)$obj->other_fee;
|
|
|
+ $waybill->warehouse_weight_other -= (double)$obj->warehouse_weight_other;
|
|
|
+ $waybill->warehouse_weight -= (double)$obj->warehouse_weight;
|
|
|
+ }
|
|
|
+ Waybill::onlyTrashed()->whereIn("wms_bill_number",explode(",",$waybill->wms_bill_number))->restore();
|
|
|
+ $waybill->merge_owner = null;
|
|
|
+ $waybill->source_bill = implode(",",$bills);
|
|
|
+ $waybill->wms_bill_number = implode(",",$codes);
|
|
|
+ $waybill->ordering_remark = implode(",",$remark);
|
|
|
+ $waybill->update();
|
|
|
+ WaybillAuditLog::query()->create([
|
|
|
+ 'waybill_id'=>$waybill->id,
|
|
|
+ 'audit_stage'=>'拆单返回',
|
|
|
+ 'user_id'=>Auth::id(),
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 快递面单打印 :暂时支持 德邦
|
|
|
*/
|
|
|
@@ -1266,10 +1271,15 @@ SQL;
|
|
|
{
|
|
|
$this->gate("运输管理-编辑");
|
|
|
if (!\request("logistic"))$this->error("未选择承运商");
|
|
|
- $waybill = Waybill::query()->where("waybill_number",\request("waybill"))->whereNull("deliver_at")
|
|
|
+ $waybill = Waybill::query()->with("waybillAuditLogs:waybill_id,audit_stage")->where("waybill_number",\request("waybill"))
|
|
|
->whereNotIn("status",["已完结","无模型"])->first();
|
|
|
if (!$waybill)$this->error("运单禁止操作");
|
|
|
- if ($waybill->deliver_at)$this->error("运单已发货,请勿重复调配");
|
|
|
+ if ($waybill->deliver_at){
|
|
|
+ if ($waybill->waybillAuditLogs->where("audit_stage","单独发货")->count())$this->split($waybill);
|
|
|
+ else if(!$waybill->waybillAuditLogs->where("audit_stage","合单发货")->count())
|
|
|
+ $this->error("运单已发货,请勿重复调配");
|
|
|
+ }
|
|
|
+
|
|
|
$codes = explode("\n",\request("order"));
|
|
|
$waybills = Waybill::query()->whereIn("wms_bill_number",$codes)
|
|
|
->where("id","!=",$waybill->id)
|
|
|
@@ -1306,11 +1316,6 @@ SQL;
|
|
|
if ($waybill->status=='未审核')$waybill->status = '已审核';
|
|
|
$waybill->update();
|
|
|
Waybill::destroy($destroys);
|
|
|
- WaybillAuditLog::query()->create([
|
|
|
- 'waybill_id'=>$waybill->id,
|
|
|
- 'audit_stage'=>'合并运单',
|
|
|
- 'user_id'=>Auth::id(),
|
|
|
- ]);
|
|
|
WaybillAuditLog::query()->create([
|
|
|
'waybill_id'=>$waybill->id,
|
|
|
'audit_stage'=>'合单发货',
|