|
|
@@ -4,6 +4,7 @@ namespace App\Services;
|
|
|
|
|
|
use App\Order;
|
|
|
use App\OrderCommodity;
|
|
|
+use App\Services\common\DataHandlerService;
|
|
|
use Carbon\Carbon;
|
|
|
|
|
|
Class OrderCommodityService
|
|
|
@@ -115,49 +116,6 @@ Class OrderCommodityService
|
|
|
return $map;
|
|
|
}
|
|
|
|
|
|
- private function filterInnerParams(&$orderDetails_map,&$orderCommodities_map)
|
|
|
- {
|
|
|
- $inner_params = [];
|
|
|
- if(count($orderDetails_map) == 0)return $inner_params;
|
|
|
- foreach ($orderDetails_map as $key=>&$map) {
|
|
|
- if(empty($orderCommodities_map[$key])){
|
|
|
- foreach ($map as &$item) {
|
|
|
- $inner_params[] = $item;
|
|
|
- }
|
|
|
- }elseif(count($map)>count($orderCommodities_map[$key])){
|
|
|
- foreach ($map as &$obj) {
|
|
|
- if($orderCommodities_map[$key]>0)array_shift($orderCommodities_map[$key]);
|
|
|
- elseif($orderCommodities_map[$key]==0)$inner_params[] = $obj;
|
|
|
- }
|
|
|
- } elseif(count($map)==count($orderCommodities_map[$key]))continue;
|
|
|
- unset($orderDetails_map[$key]);
|
|
|
- $map = null;
|
|
|
- }
|
|
|
- return $inner_params;
|
|
|
- }
|
|
|
- private function filterDeleteParams(&$orderDetails_map,&$orderCommodities_map)
|
|
|
- {
|
|
|
- $del_ids = [];
|
|
|
- if(count($orderDetails_map) == 0)return $del_ids;
|
|
|
- foreach ($orderCommodities_map as $key=>$map) {
|
|
|
- if(empty($orderDetails_map[$key])){
|
|
|
- foreach ($map as &$item) {
|
|
|
- $del_ids[] = $item['id'];
|
|
|
- }
|
|
|
- }elseif(count($map)>count($orderDetails_map[$key])){
|
|
|
- foreach ($map as $key1=>&$obj) {
|
|
|
- if(count($orderDetails_map[$key]) == 0){
|
|
|
- $del_ids [] = $obj['id'];
|
|
|
- unset($map[$key1]);
|
|
|
- } else{
|
|
|
- array_shift($orderDetails_map[$key]);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return $del_ids;
|
|
|
- }
|
|
|
-
|
|
|
private function createByInnerParams(&$inner_params,&$orders_map,&$commodities_maps,&$owner_id_maps)
|
|
|
{
|
|
|
$created_params = [];
|
|
|
@@ -208,5 +166,136 @@ Class OrderCommodityService
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public function syncOrderCommodity($orderHeaders)
|
|
|
+ {
|
|
|
+ /**
|
|
|
+ * @var OwnerService $ownerService
|
|
|
+ * @var CommodityService $commodityService
|
|
|
+ * @var DataHandlerService $dataHandlerService
|
|
|
+ */
|
|
|
+ $ownerService = app('OwnerService');
|
|
|
+ $commodityService = app('CommodityService');
|
|
|
+ $dataHandlerService = app('DataHandlerService');
|
|
|
+
|
|
|
+ $map = [];$owner_codes = [];
|
|
|
+ foreach ($orderHeaders as $orderHeader) {
|
|
|
+ $actAllocationDetails = $orderHeader->actAllocationDetails;
|
|
|
+ foreach ($actAllocationDetails as $actAllocationDetail) {
|
|
|
+ $key = "owner_code_{$actAllocationDetail['customerid']}_'sku'";
|
|
|
+ $owner_codes[$actAllocationDetail['customerid']] = $actAllocationDetail['customerid'];
|
|
|
+ $map[$key] = [
|
|
|
+ 'owner_code'=>$actAllocationDetail['customerid'],
|
|
|
+ 'sku'=>$actAllocationDetail['sku']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $owners = $ownerService->getOwnerByCodes($owner_codes);
|
|
|
+ $owner_map = $dataHandlerService->dataHeader(['id'],$owners);
|
|
|
+ $commodities = $commodityService->getParamsByBasSku($map);
|
|
|
+ $commodity_map = [];
|
|
|
+ foreach ($commodities as $commodity) {
|
|
|
+ $owner = $dataHandlerService->getKeyValue(['id'=>$commodity->id],$owner_map);
|
|
|
+ $key = "_owner_code_{$owner['code']}_sku_{$commodity['sku']}";
|
|
|
+ $commodity_map[$key] = $commodity;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getRegroupActAllocationDetails(&$orderHeaders,$owner_code_maps)
|
|
|
+ {
|
|
|
+ $map = [];
|
|
|
+ if($orderHeaders->count()==0) return $map;
|
|
|
+ $orderHeaders->each(function($orderHeader)use(&$map){
|
|
|
+ $orderHeader->actAllocationDetails->each(function ($details)use(&$map){
|
|
|
+ $key = "order_{$details['orderno']}_owner_code_{$details['customerid']}_sku_{$details['sku']}_location_{$details['location']}";
|
|
|
+ if(empty($map[$key]))$map[$key]=[];
|
|
|
+ $map[$key][] = [
|
|
|
+ 'code' => $details['orderno'],
|
|
|
+ 'sku' => $details['sku'],
|
|
|
+ 'owner_code'=> $details['customerid'],
|
|
|
+ 'amount' => $details['qty_each'],
|
|
|
+ 'location' => $details['location']
|
|
|
+ ];
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return $map;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getRegroupOrderCommodities(&$orderCommodities,$owner_id_maps)
|
|
|
+ {
|
|
|
+ /** @var DataHandlerService $dataHandlerService */
|
|
|
+ $dataHandlerService = app(DataHandlerService::class);
|
|
|
+ $map = [];
|
|
|
+ if($orderCommodities->count() == 0)return $map;
|
|
|
+ $orderCommodities->each(function($orderCommodity)use(&$map,$owner_id_maps,$dataHandlerService){
|
|
|
+ $order = $orderCommodity->order;
|
|
|
+ $owner = $dataHandlerService->getKeyValue(['id'=>$order->owner_id ?? ''],$owner_id_maps);
|
|
|
+ $key = "order_{($order->code ?? '')}_owner_code_{($owner->code)}_sku_{($orderCommodity->commodity->sku ?? '')}_location_{($orderCommodity->location)}";
|
|
|
+ if(empty($map[$key]))$map[$key]=[];
|
|
|
+ $map[$key] =[
|
|
|
+ 'id' => $orderCommodity->id,
|
|
|
+ 'code' => $orderCommodity->order->code ?? '',
|
|
|
+ 'sku' => $orderCommodity->commodity->sku,
|
|
|
+ 'owner_code' => $owner->code ?? '',
|
|
|
+ 'amount' => $orderCommodity->amount,
|
|
|
+ 'location' => $orderCommodity->location,
|
|
|
+ ];
|
|
|
+ });
|
|
|
+ return $map;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getUpdateParams(&$ActAllocationDetail_maps,&$orderCommodity_maps)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getDeleteIds(&$ActAllocationDetail_maps,&$orderCommodity_maps)
|
|
|
+ {
|
|
|
+ $ids = [];
|
|
|
+ foreach ($orderCommodity_maps as $key=>$orderCommodity_map) {
|
|
|
+ if(isset($ActAllocationDetail_maps[$key]))continue;
|
|
|
+ foreach ($orderCommodity_map as $key1=>$orderCommodity) {
|
|
|
+ $ids[] = $orderCommodity['id'];
|
|
|
+ unset($orderCommodity_map[$key1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $ids;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getCreateParams(&$ActAllocationDetail_maps,&$orderCommodity_maps)
|
|
|
+ {
|
|
|
+ $params = [];
|
|
|
+ foreach ($ActAllocationDetail_maps as $key=>$actAllocationDetail_map) {
|
|
|
+ if(empty($orderCommodity_maps[$key]))continue;
|
|
|
+ foreach ($actAllocationDetail_map as $actAllocationDetail) {
|
|
|
+ $params[] = $actAllocationDetail;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getInnerParamsByParams($create_params,$owner_code_map,$order_code_map,$commodity)
|
|
|
+ {
|
|
|
+ /** @var DataHandlerService $dataHandlerService */
|
|
|
+ $dataHandlerService = app(DataHandlerService::class);
|
|
|
+ $inner_params = [];
|
|
|
+ $data = (string) Carbon::now();
|
|
|
+ foreach ($create_params as $item) {
|
|
|
+ $owner = $dataHandlerService->getKeyValue(['code'=>$item['owner_code']],$owner_code_map);
|
|
|
+ $order = $dataHandlerService->getKeyValue(['code'=>$item['code']],$order_code_map);
|
|
|
+// $key = "order_{$item['code']}_owner_code_{$item['owner_code']}_sku_{($orderCommodity->commodity->sku ?? '')}_location_{($orderCommodity->location)}";
|
|
|
+ $inner_params[] = [
|
|
|
+ 'order_id' => $order['id'] ?? '',
|
|
|
+ 'commodity_id' => '',
|
|
|
+ 'amount' => '',
|
|
|
+ 'location' => '',
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|