|
|
@@ -37,7 +37,7 @@ class OrderPackageCommoditiesService
|
|
|
public function basedOnActAllocationDetailsStoreByOrderNo($orderNo,$orderPackage){
|
|
|
$details = OracleActAllocationDetails::query()->where('orderno', $orderNo)->get();
|
|
|
$orderPackageCommodities = OrderPackageCommodities::query()->where('order_package_id',$orderPackage['id'])->get();
|
|
|
- $this->根据详情更新OrderPackage下的商品信息($orderPackage,$orderPackageCommodities,$details,'qty');
|
|
|
+ $this->根据详情更新OrderPackage下的商品信息($orderPackage,$orderPackageCommodities,$details,'qty_each');
|
|
|
unset($details,$orderPackageCommodities);
|
|
|
}
|
|
|
|
|
|
@@ -103,7 +103,7 @@ class OrderPackageCommoditiesService
|
|
|
{
|
|
|
$details = OracleActAllocationDetails::query()->where('picktotraceid', $orderPackage->logistic_number)->get();
|
|
|
$orderPackageCommodities = OrderPackageCommodities::query()->where('order_package_id',$orderPackage['id'])->get();
|
|
|
- $this->根据详情更新OrderPackage下的商品信息($orderPackage,$orderPackageCommodities,$details,'qty');
|
|
|
+ $this->根据详情更新OrderPackage下的商品信息($orderPackage,$orderPackageCommodities,$details,'qty_each');
|
|
|
unset($details,$orderPackageCommodities);
|
|
|
}
|
|
|
|
|
|
@@ -133,9 +133,9 @@ class OrderPackageCommoditiesService
|
|
|
$commodity = Commodity::query()->create(['sku' => $sku, 'owner_id' => $owner_id, 'name' => $basSku->descr_c]);
|
|
|
}
|
|
|
try {
|
|
|
- $count = OrderPackageCommodities::query()->where(['order_package_id' => $orderPackage['id'], 'commodity_id' => $commodity['id'], 'amount' => $detail['qty']])->count();
|
|
|
+ $count = OrderPackageCommodities::query()->where(['order_package_id' => $orderPackage['id'], 'commodity_id' => $commodity['id'], 'amount' => $detail['qty_each']])->count();
|
|
|
if($count == 0){
|
|
|
- $orderPackageCommodities = OrderPackageCommodities::query()->firstOrCreate(['order_package_id' => $orderPackage['id'], 'commodity_id' => $commodity['id'], 'amount' => $detail['qty']]);
|
|
|
+ $orderPackageCommodities = OrderPackageCommodities::query()->firstOrCreate(['order_package_id' => $orderPackage['id'], 'commodity_id' => $commodity['id'], 'amount' => $detail['qty_each']]);
|
|
|
LogService::log(__METHOD__,__FUNCTION__,'创建订单包裹详情'.json_encode($orderPackageCommodities));
|
|
|
}
|
|
|
} catch (\Exception $e) {
|
|
|
@@ -145,265 +145,6 @@ class OrderPackageCommoditiesService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function getOrderPackageCommoditiesByOrderId($orderId)
|
|
|
- {
|
|
|
- $order = Order::query()->where('id', $orderId)->first();
|
|
|
- if (!$order) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- $orderPackageIds = OrderPackage::query()->select('id')->where('order_id', $order['id'])->get();
|
|
|
- if (!$orderPackageIds) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- return OrderPackageCommodities::query()->with('commodity')->whereIn('order_package_id', $orderPackageIds)->get();
|
|
|
- }
|
|
|
-
|
|
|
- public function createByOrderDetail(OracleDOCOrderDetail $detail, OrderPackage $orderPackage)
|
|
|
- {
|
|
|
- $owner = Owner::query()->where('code', $detail['customerid'])->first(); // 货主
|
|
|
- $sku = $detail->sku; // sku
|
|
|
- $owner_id = $owner->id; // 货主id
|
|
|
- $commodity = Commodity::query()->where('sku', $sku)->where('owner_id', $owner_id)->first(); // 商品
|
|
|
- if ($commodity == null) {
|
|
|
- $basSku = OracleBasSKU::query()->where('sku', $sku)->where('customerid' , $detail->customerid)->first(); // 没有找到对应的商品信息
|
|
|
- $commodity = Commodity::query()->create(['sku' => $sku, 'owner_id' => $owner_id, 'name' => $basSku->descr_c]);
|
|
|
- }
|
|
|
- return OrderPackageCommodities::query()->create(['order_package_id' => $orderPackage['id'], 'commodity_id' => $commodity['id'], 'amount' => $detail['qtyordered']]);
|
|
|
- }
|
|
|
-
|
|
|
- public function 根据WMS订单信息创建WAS订单包裹商品($orderHeaders,$oracleDOCOrderDetails,$actAllocationDetails,$orders)
|
|
|
- {
|
|
|
- /** @var CommodityService $commodityService */
|
|
|
- $commodityService = app('commodityService');
|
|
|
- $commodities = $commodityService->getWASCommoditiesByWMSOrderHeaders($orderHeaders); // 商品
|
|
|
-
|
|
|
- $orderPackages = [];
|
|
|
- $orderList = [];
|
|
|
- foreach ($orders as $order) {
|
|
|
- $orderList[$order['id']] = $order;
|
|
|
- $packages = $order['packages'] ?? [];
|
|
|
- foreach ($packages as $package) {
|
|
|
- $orderPackages[$package['logistic_number']] = $package;
|
|
|
- }
|
|
|
- }
|
|
|
- $fillables = [];
|
|
|
- foreach ($orderPackages as $key=>$orderPackage) {
|
|
|
- $logistic_number = $key;
|
|
|
- $order = $orderList[$orderPackage['order_id']];
|
|
|
- $details1 = $actAllocationDetails[strval($logistic_number)] ?? [];
|
|
|
- $details2 = [];
|
|
|
- if(count($details1)== 0){
|
|
|
- $details2 = $actAllocationDetails[$order['code']] ?? [];
|
|
|
- }
|
|
|
- if(count($details1) > 0 || count($details2) > 0){
|
|
|
- $items = $this->根据订单分配详情返回创建数组($details1,$orderPackage,$commodities,$order);
|
|
|
- foreach ($items as $item){
|
|
|
- $fillables[] = $item;
|
|
|
- }
|
|
|
- $items = $this->根据订单分配详情返回创建数组($details2,$orderPackage,$commodities,$order);
|
|
|
- foreach ($items as $item){
|
|
|
- $fillables[] = $item;
|
|
|
- }
|
|
|
- continue;
|
|
|
- }
|
|
|
- $details = $oracleDOCOrderDetails[$order['code']] ?? [];
|
|
|
- if($details->count() >0){
|
|
|
- $items = $this->根据订单详情返回创建数组($details,$orderPackage,$commodities,$order);
|
|
|
- foreach ($items as $item){
|
|
|
- $fillables[] = $item;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- try {
|
|
|
- if(count($fillables) > 0){
|
|
|
- OrderPackageCommodities::query()->insert($fillables);
|
|
|
- LogService::log(__METHOD__,__FUNCTION__,'批量创建 OrderPackageCommodities'.count($fillables).json_encode($fillables));
|
|
|
- }
|
|
|
- } catch (\Exception $e) {
|
|
|
- LogService::log(__METHOD__,__FUNCTION__,'批量创建异常 OrderPackageCommodities error '.json_encode($fillables).$e->getMessage().$e->getTraceAsString());
|
|
|
- } finally {
|
|
|
- $orderIds = data_get($orders,'*.id');
|
|
|
- return Order::query()->with('packages.commodities')->whereIn('id',$orderIds)->get();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // XXX 逻辑优化 删除不存在未完成
|
|
|
- public function 更新WAS订单快递打包商品信息($orderHeaders,$orders,$commodities)
|
|
|
- {
|
|
|
- $newItems = $this->获取WMS订单打包信息($orderHeaders,$commodities,$orders);
|
|
|
- $orderPackagesCommodities = $this->basedOrdersReturnOrderPackageCommodities($orders);
|
|
|
-
|
|
|
- $multipleData = [['id','order_package_id','commodity_id']];
|
|
|
- $packageCommodity_list_amount = [];
|
|
|
- $packageCommodity_list = [];
|
|
|
-
|
|
|
- foreach ($orderPackagesCommodities as $item) {
|
|
|
- $key = 'order_package_id='.$item['order_package_id'].' commodity_id='.$item['commodity_id'].' amount='.$item['amount'];
|
|
|
- if(!($packageCommodity_list_amount[$key] ?? false)){
|
|
|
- $packageCommodity_list_amount[$key] = [];
|
|
|
- }
|
|
|
- $packageCommodity_list_amount[$key][] = $item;
|
|
|
- $key2 = 'order_package_id'.$item['order_package_id'].' commodity_id='.$item['commodity_id'];
|
|
|
- if($packageCommodity_list[$key2] ?? false){
|
|
|
- $packageCommodity_list[$key2] = [];
|
|
|
- }
|
|
|
- $packageCommodity_list[$key2][] = $item;
|
|
|
- }
|
|
|
- foreach ($newItems as $key=>$newItem) {
|
|
|
- $key1 = 'order_package_id='.$newItem['order_package_id'].' commodity_id='.$newItem['commodity_id'].' amount='.$newItem['amount'];
|
|
|
- $packageCommodity = $packageCommodity_list_amount[$key1][0] ?? false;
|
|
|
- if($packageCommodity ?? false){
|
|
|
- unset($newItems[$key]);
|
|
|
- array_shift($packageCommodity_list_amount[$key1]);
|
|
|
- }else{
|
|
|
- $key2 = 'order_package_id'.$newItem['order_package_id'].' commodity_id='.$newItem['commodity_id'];
|
|
|
- $packageCommodity = $packageCommodity_list[$key2][0] ?? false;
|
|
|
- if($packageCommodity ?? false) {
|
|
|
- $amount = intval($newItem['amount']);
|
|
|
- if($packageCommodity['amount'] !== $amount){
|
|
|
- $data = [
|
|
|
- 'order_package_id' => $packageCommodity['order_package_id'],
|
|
|
- 'commodity_id' => $packageCommodity['commodity_id'],
|
|
|
- 'amount' => $amount,
|
|
|
- ];
|
|
|
- $multipleData[] = $data;
|
|
|
- }
|
|
|
- array_shift($packageCommodity_list[$key2]);
|
|
|
- unset($newItems[$key]);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- try {
|
|
|
- if (count($newItems) > 0) {
|
|
|
- OrderPackageCommodities::query()->insert($newItems);
|
|
|
- LogService::log(__METHOD__, __FUNCTION__, '添加打包信息' . json_encode($newItems));
|
|
|
- }
|
|
|
- }catch (\Exception $e) {
|
|
|
- LogService::log(__METHOD__, __FUNCTION__, '添加打包信息失败' . json_encode($newItems).$e->getMessage().$e->getTraceAsString());
|
|
|
- }
|
|
|
-
|
|
|
- if(count($multipleData) > 1){
|
|
|
- try {
|
|
|
- /** @var BatchUpdateService $batchUpdateService */
|
|
|
- $batchUpdateService = app('batchUpdateService');
|
|
|
- $batchUpdateService->batchUpdate('order_package_commodities', $multipleData);
|
|
|
- LogService::log(__METHOD__,__FUNCTION__,'批量更新'.count($multipleData).json_encode($multipleData));
|
|
|
- } catch (\Exception $e) {
|
|
|
- LogService::log(__METHOD__,__FUNCTION__,'批量更新失败'.json_encode($multipleData).$e->getMessage(),$e->getTraceAsString());
|
|
|
- } finally {
|
|
|
- unset($multipleData);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private function 获取WMS订单打包信息($orderHeaders,$commodities,$orders){
|
|
|
- $newItems = [];
|
|
|
-
|
|
|
- $commodities_list = [];
|
|
|
- foreach ($commodities as $commodity) {
|
|
|
- $key = 'sku='.$commodity['sku'].' owner_id='.$commodity['owner_id'];
|
|
|
- $commodities_list[$key] = $commodity;
|
|
|
- }
|
|
|
- foreach ($orderHeaders as $orderHeader) {
|
|
|
- $order = $orders[$orderHeader['orderno']] ?? null;
|
|
|
- if(!isset($order)){
|
|
|
- continue;
|
|
|
- }
|
|
|
- $orderPackages = $order['packages'];
|
|
|
- $oracleDOCOrderDetails = $orderHeader['oracleDOCOrderDetails'] ?? [];
|
|
|
- $actAllocationDetails = $orderHeader['actAllocationDetails'] ?? [];
|
|
|
-
|
|
|
- if($actAllocationDetails->count() > 0){
|
|
|
- foreach ($orderPackages as $orderPackage) {
|
|
|
- $details = [];
|
|
|
- if($orderPackage['logistic_number'] == $orderHeader['soreference5'] ){
|
|
|
- foreach ($actAllocationDetails as $detail) {
|
|
|
- if($detail['picktotraceid'] == '*' || $detail['picktotraceid'] == $orderHeader['soreference5'])
|
|
|
- $details[] = $detail;
|
|
|
- }
|
|
|
- }else{
|
|
|
- $logistic_number = $orderPackage['logistic_number'];
|
|
|
- foreach ($actAllocationDetails as $detail) {
|
|
|
- if($detail['picktotraceid'] == $logistic_number)
|
|
|
- $details[] = $detail;
|
|
|
- }
|
|
|
- }
|
|
|
- $addArr = $this->basedDetailsReturnFillables($details,$orderPackage,$commodities_list,$order,'qty');
|
|
|
- $newItems = array_merge($newItems,$addArr);
|
|
|
- }
|
|
|
- }elseif($oracleDOCOrderDetails->count() > 0){
|
|
|
- foreach ($orderPackages as $orderPackage) {
|
|
|
- $details = [];
|
|
|
- $logistic_number = $orderPackage['logistic_number'];
|
|
|
- foreach ($actAllocationDetails as $detail) {
|
|
|
- if($detail['dropid'] == $logistic_number){
|
|
|
- array_push($details,$detail);
|
|
|
- }
|
|
|
- }
|
|
|
- $addArr = $this->basedDetailsReturnFillables($details,$orderPackage,$commodities_list,$order,'qtyordered');
|
|
|
- $newItems = array_merge($newItems,$addArr);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return $newItems;
|
|
|
- }
|
|
|
-
|
|
|
- public function 根据订单详情返回创建数组($details,$orderPackage,$commodities,$order){
|
|
|
- $orderPackagerCommodities = [];
|
|
|
- foreach ($details as $detail) {
|
|
|
- $commodity = $commodities->where('sku', $detail['sku'])->where('owner_id', $order['owner_id'])->first();
|
|
|
- $fillable = [
|
|
|
- 'order_package_id' => $orderPackage['id'] ?? '',
|
|
|
- 'commodity_id' => $commodity['id'] ?? '',
|
|
|
- 'amount' => $detail['qtyordered'],
|
|
|
- ];
|
|
|
- $orderPackagerCommodities[] = $fillable;
|
|
|
- }
|
|
|
- return $orderPackagerCommodities;
|
|
|
- }
|
|
|
-
|
|
|
- public function 根据订单分配详情返回创建数组($details,$orderPackage,$commodities,$order){
|
|
|
- $orderPackagerCommodities = [];
|
|
|
- foreach ($details as $detail) {
|
|
|
-
|
|
|
- $commodity = $commodities->where('sku', $detail['sku'])->where('owner_id', $order['owner_id'])->first();
|
|
|
- $fillable = [
|
|
|
- 'order_package_id' => $orderPackage['id'] ?? '',
|
|
|
- 'commodity_id' => $commodity['id'] ?? '',
|
|
|
- 'amount' => $detail['qty'] ?? '',
|
|
|
- ];
|
|
|
- array_push($orderPackagerCommodities,$fillable);
|
|
|
- }
|
|
|
- return $orderPackagerCommodities;
|
|
|
- }
|
|
|
-
|
|
|
- public function basedOrdersReturnOrderPackageCommodities($orders){
|
|
|
- $orderPackageCommodities = [];
|
|
|
- foreach ($orders as $order) {
|
|
|
- foreach ($order['packages'] as $package) {
|
|
|
- foreach ($package['commodities'] as $commodity) {
|
|
|
- $orderPackageCommodities[] = $commodity;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return $orderPackageCommodities;
|
|
|
- }
|
|
|
-
|
|
|
- public function basedDetailsReturnFillables($details,$orderPackage,$commoditiesMap,$order,$column){
|
|
|
- $orderPackagerCommodities = [];
|
|
|
- foreach ($details as $detail) {
|
|
|
- $key = 'sku='.$detail['sku'].' owner_id='.$order['owner_id'];
|
|
|
- $commodity = $commoditiesMap[$key] ?? '';
|
|
|
- $fillable = [
|
|
|
- 'order_package_id' => $orderPackage['id'] ?? '',
|
|
|
- 'commodity_id' => $commodity['id'] ?? '',
|
|
|
- 'amount' => $detail[$column] ?? '',
|
|
|
- ];
|
|
|
- array_push($orderPackagerCommodities,$fillable);
|
|
|
- }
|
|
|
- return $orderPackagerCommodities;
|
|
|
- }
|
|
|
-
|
|
|
public function createByWmsOrder($orderHeaders)
|
|
|
{
|
|
|
if(!$orderHeaders){ return [];}
|
|
|
@@ -471,7 +212,7 @@ class OrderPackageCommoditiesService
|
|
|
$params[] = [
|
|
|
'commodity_id' =>$commodity->id,
|
|
|
'order_package_id' =>$orderPackage->id,
|
|
|
- 'amount' => $actAllocationDetail->qty,
|
|
|
+ 'amount' => $actAllocationDetail->qty_each,
|
|
|
'created_at' => $create_at
|
|
|
];
|
|
|
}
|
|
|
@@ -480,7 +221,6 @@ class OrderPackageCommoditiesService
|
|
|
return $params;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public function create(array $params){
|
|
|
if(!$params){return [];}
|
|
|
try {
|
|
|
@@ -550,16 +290,16 @@ class OrderPackageCommoditiesService
|
|
|
foreach ($actAllocationDetails as $key1=>$actAllocationDetail) {
|
|
|
foreach ( $order_package_commodities as $key=>$item) {
|
|
|
$commodity = $item->commodity;
|
|
|
- if($actAllocationDetail->sku == $commodity->sku && $item->amount == $actAllocationDetail->qty){
|
|
|
+ if($actAllocationDetail->sku == $commodity->sku && $item->amount == $actAllocationDetail->qty_each){
|
|
|
unset($order_package_commodities[$key]);
|
|
|
unset($actAllocationDetails[$key1]);
|
|
|
$deleteKey[] = $key1;
|
|
|
break;
|
|
|
- }else if($item ->sku == $commodity->sku && $item->amount != $actAllocationDetail->qty){
|
|
|
+ }else if($item ->sku == $commodity->sku && $item->amount != $actAllocationDetail->qty_each){
|
|
|
$updateParams[] = [
|
|
|
'id' => $item->id,
|
|
|
'commodity_id' => $commodity->id,
|
|
|
- 'amount' => $actAllocationDetail->qty,
|
|
|
+ 'amount' => $actAllocationDetail->qty_each,
|
|
|
'updated_at' => $updated_at
|
|
|
];
|
|
|
$deleteKey[] = $key1;
|
|
|
@@ -601,7 +341,6 @@ class OrderPackageCommoditiesService
|
|
|
})->get();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public function batchUpdateItself($column, array $params)
|
|
|
{
|
|
|
return app(BatchUpdateService::class)->batchUpdateItself('order_package_commodities', $column, $params);
|