|
@@ -1170,14 +1170,8 @@ class BoxService extends Service
|
|
|
if(empty($orders_product_id_map)) return [true,''];
|
|
|
$production_list = array_keys($orders_product_id_map);
|
|
|
|
|
|
- //组织派工数据
|
|
|
- $dispatch = DispatchSub::where('del_time',0)
|
|
|
- ->whereIn('order_product_id', $production_list)
|
|
|
- ->get()->toArray();
|
|
|
+ $dispatch = $this->getDispatch($production_list, $orders_product_id_map);
|
|
|
if(empty($dispatch)) return [true,''];
|
|
|
- foreach ($dispatch as $key => $value){
|
|
|
- $dispatch[$key]['out_number'] = $orders_product_id_map[$value['order_product_id']] ?? 0;
|
|
|
- }
|
|
|
|
|
|
try {
|
|
|
DB::beginTransaction();
|
|
@@ -1216,6 +1210,61 @@ class BoxService extends Service
|
|
|
return [true, ''];
|
|
|
}
|
|
|
|
|
|
+ public function getDispatch($order_product_id,$map){
|
|
|
+ $order = OrdersProduct::where('del_time',0)
|
|
|
+ ->where('id', $order_product_id)
|
|
|
+ ->select('id', 'process_id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $order_map = [];
|
|
|
+ foreach ($order as $value){
|
|
|
+ $order_map[$value['id']] = explode(',', $value['process_id']);
|
|
|
+ }
|
|
|
+
|
|
|
+ //组织派工数据
|
|
|
+ $dispatch = DispatchSub::where('del_time',0)
|
|
|
+ ->whereIn('order_product_id', $order_product_id)
|
|
|
+ ->where('finished_num','>',0)
|
|
|
+ ->get()->toArray();
|
|
|
+ if(empty($dispatch)) return [];
|
|
|
+ $dispatch_map = [];
|
|
|
+ foreach ($dispatch as $value){
|
|
|
+ $key = $value['order_product_id'] . '|' . $value['crt_time']; //同一次下的派工单
|
|
|
+ $dispatch_map[$key][] = $value;
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = []; $tmp = [];
|
|
|
+ foreach ($dispatch_map as $key => $value){
|
|
|
+ foreach ($value as $v){
|
|
|
+ $process = $order_map[$v['order_product_id']] ?? [];
|
|
|
+ $num = $map[$v['order_product_id']];
|
|
|
+
|
|
|
+ if(in_array($v['process_id'], $process)){
|
|
|
+ $str = $v['order_product_id'] . $v['process_id'];
|
|
|
+ $tmp_v = $tmp[$str] ?? 0;
|
|
|
+ $num = bcsub($num, $tmp_v,3);
|
|
|
+ if($num <= 0) continue;
|
|
|
+
|
|
|
+ if($v['finished_num'] >= $num){
|
|
|
+ $v['out_number'] = $num;
|
|
|
+ $result[] = $v;
|
|
|
+ }else{
|
|
|
+ $v['out_number'] = $v['finished_num'];
|
|
|
+ $result[] = $v;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(isset($tmp[$str])){
|
|
|
+ $num = bcadd($tmp[$str], $v['out_number'],3);
|
|
|
+ $tmp[$str] = $num;
|
|
|
+ }else{
|
|
|
+ $tmp[$str] = $v['out_number'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }unset($tmp);
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
public function boxAdd($data)
|
|
|
{
|
|
|
list($status,$msg) = $this->boxAddRule($data);
|
|
@@ -1414,10 +1463,8 @@ class BoxService extends Service
|
|
|
->orderBy('id','desc');
|
|
|
|
|
|
if(! empty($data['order_no'])) $model->where('order_no', 'LIKE', '%'.$data['order_no'].'%');
|
|
|
- if(! empty($data['out_order_no']) || ! empty($data['shipment_order_no'])) {
|
|
|
- $id = $this->searchDetail($data);
|
|
|
- $model->whereIn('order_no', $id);
|
|
|
- }
|
|
|
+ if(! empty($data['shipment_order_no'])) $model->where('shipment_order_no', 'LIKE', '%'.$data['shipment_order_no'].'%');
|
|
|
+ if(! empty($data['out_order_no'])) $model->where('out_order_no', 'LIKE', '%'.$data['out_order_no'].'%');
|
|
|
if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) $model->whereBetween('crt_time',[$data['crt_time'][0],$data['crt_time'][1]]);
|
|
|
if(isset($data['status'])) $model->where('status',$data['status']);
|
|
|
|
|
@@ -1490,7 +1537,22 @@ class BoxService extends Service
|
|
|
|
|
|
public function searchDetail($data){
|
|
|
$out_order_no = $data['out_order_no'] ?? '';
|
|
|
- $shipment_order_no = $data['shipment_order_no'] ?? '';
|
|
|
+ $box = Box::where('del_time',0)
|
|
|
+ ->where('out_order_no', 'LIKE', '%'. $out_order_no .'%')
|
|
|
+ ->select('top_order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ if(empty($box)) return [];
|
|
|
+
|
|
|
+ $order_no = [];
|
|
|
+ foreach ($box as $value){
|
|
|
+ $model = new BoxDetail(['channel'=> $value['top_order_no']]);
|
|
|
+ $result = $model->where('del_time',0)
|
|
|
+ ->where('order_no',$box['order_no'])
|
|
|
+ ->select('order_no')
|
|
|
+ ->get()->toArray();
|
|
|
+ $detail_list = array_merge($order_no, array_column($result, 'order_no'));
|
|
|
+
|
|
|
+ }
|
|
|
$result = BoxDetail::where('del_time',0)
|
|
|
->when(! empty($out_order_no), function ($query) use ($out_order_no) {
|
|
|
return $query->where('out_order_no', 'LIKE', '%'. $out_order_no .'%');
|