|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
+use App\Commodity;
|
|
|
use App\Feature;
|
|
|
use App\Jobs\OrderCreateInstantBill;
|
|
|
use App\Jobs\OrderFreeze;
|
|
|
@@ -11,6 +12,7 @@ use App\OracleActAllocationDetails;
|
|
|
use App\OracleDOCASNHeader;
|
|
|
use App\OracleDOCOrderHeader;
|
|
|
use App\Order;
|
|
|
+use App\OrderCommodity;
|
|
|
use App\OrderIssue;
|
|
|
use App\Owner;
|
|
|
use App\OwnerFeeDetail;
|
|
|
@@ -1339,6 +1341,35 @@ sql;
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 恢复不存在商品订单
|
|
|
+ *
|
|
|
+ * @param Order|\stdClass $order
|
|
|
+ */
|
|
|
+ public function notExistToRecover(Order $order)
|
|
|
+ {
|
|
|
+ $sql = <<<sql
|
|
|
+SELECT customerid,orderno,sku,orderlineno,qty_each FROM ACT_ALLOCATION_DETAILS WHERE orderno = ?
|
|
|
+sql;
|
|
|
|
|
|
+ $allocations = DB::connection("oracle")->select(DB::raw($sql),[$order->code]);
|
|
|
+ if (!$allocations)return;
|
|
|
+ $insert[] = [];
|
|
|
+ $sku = array_column($allocations,"sku");
|
|
|
+ app("CommodityService")->notExistToCreate($order->owner_id,$sku);
|
|
|
+ $commodities = Commodity::query()->where("owner_id",$order->owner_id)->whereIn("sku",$sku)->get();
|
|
|
+ $commodityMap = [];
|
|
|
+ foreach ($commodities as $commodity)$commodityMap[$commodity->sku] = $commodity->id;
|
|
|
+ foreach ($allocations as $allocation){
|
|
|
+ if (!($commodityMap[$allocation->sku] ?? false))LogService::log(__CLASS__,"ERROR-SKU对应商品在FLUX不存在",json_encode($allocation,JSON_UNESCAPED_UNICODE));
|
|
|
+ $insert[] = [
|
|
|
+ 'order_id' => $order->id,
|
|
|
+ 'commodity_id' => $commodityMap[$allocation->sku] ?? null,
|
|
|
+ 'amount' => $allocation->qty_each,
|
|
|
+ 'location' => $allocation->location,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ OrderCommodity::query()->insert($insert);
|
|
|
+ }
|
|
|
|
|
|
}
|