|
@@ -88,6 +88,8 @@ class FinishedOrderService extends Service
|
|
|
|
|
|
//工序表
|
|
|
$process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
|
|
|
+ $process_model->setConnection($user['zt']);
|
|
|
+
|
|
|
$process_id = $process_model->select('process_id')
|
|
|
->where('sort',$process_model->where('del_time',0)
|
|
|
->where('order_product_id',$value['order_product_id'])
|
|
@@ -125,7 +127,9 @@ class FinishedOrderService extends Service
|
|
|
$equipment_id_tmp = $data['equipment_id'][$key];
|
|
|
$finished_num = $value['quantity'] + $value['finished_num'];
|
|
|
|
|
|
- DispatchSub::where('id',$value['id'])->update([
|
|
|
+ $model = new DispatchSub();
|
|
|
+ $model->setConnection($user['zt']);
|
|
|
+ $model->where('id',$value['id'])->update([
|
|
|
'finished_num' => $finished_num,
|
|
|
'waste_num' => $waste[$key],
|
|
|
'job_status' => 0,
|
|
@@ -193,6 +197,7 @@ class FinishedOrderService extends Service
|
|
|
|
|
|
//工序表
|
|
|
$process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
|
|
|
+ $process_model->setConnection($user['zt']);
|
|
|
$process_model->where('order_product_id',$value['order_product_id'])
|
|
|
->where('process_id',$value['process_id'])
|
|
|
->where('dispatch_no',$value['dispatch_no'])
|
|
@@ -207,12 +212,18 @@ class FinishedOrderService extends Service
|
|
|
|
|
|
if(! empty($insert_waste)) $process_model->insert($insert_waste);
|
|
|
if(! empty($insert_dispatch)) $process_model->insert($insert_dispatch);
|
|
|
- if(! empty($scrapp)) ScrappCount::insert($scrapp);
|
|
|
+ if(! empty($scrapp)) {
|
|
|
+ $scrapp_model = new ScrappCount();
|
|
|
+ $scrapp_model->setConnection($user['zt']);
|
|
|
+ $scrapp_model->insert($scrapp);
|
|
|
+ }
|
|
|
|
|
|
//生产订单数量
|
|
|
if(! empty($waste[$key])){
|
|
|
$num = $waste[$key];
|
|
|
- OrdersProduct::where('id',$value['order_product_id'])->update([
|
|
|
+ $model2 = new OrdersProduct();
|
|
|
+ $model2->setConnection($user['zt']);
|
|
|
+ $model2->where('id',$value['order_product_id'])->update([
|
|
|
'production_quantity' => DB::raw("production_quantity + {$num}"),
|
|
|
'scrapp_num' => DB::raw("scrapp_num + {$num}"),
|
|
|
'dispatch_complete_quantity' => DB::raw("dispatch_complete_quantity + {$num}"),//已派工数量增加
|
|
@@ -221,8 +232,8 @@ class FinishedOrderService extends Service
|
|
|
}
|
|
|
|
|
|
//反写数量
|
|
|
- $this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'));
|
|
|
- $this->writeFinishedQuantityByOrdersProductId(array_column($result,'order_product_id'));
|
|
|
+ $this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'),$user['zt']);
|
|
|
+ $this->writeFinishedQuantityByOrdersProductId(array_column($result,'order_product_id'),$user['zt']);
|
|
|
DB::commit();
|
|
|
}catch (\Exception $e){
|
|
|
DB::rollBack();
|
|
@@ -413,10 +424,12 @@ class FinishedOrderService extends Service
|
|
|
}
|
|
|
|
|
|
//反写写完工数量(根据销售订单id)
|
|
|
- public function writeFinishedQuantity($sale_orders_product_id){
|
|
|
+ public function writeFinishedQuantity($sale_orders_product_id,$zt){
|
|
|
if(empty($sale_orders_product_id)) return;
|
|
|
|
|
|
- $result = DispatchSub::where('del_time',0)
|
|
|
+ $models = new DispatchSub();
|
|
|
+ $models->setConnection($zt);
|
|
|
+ $result = $models->where('del_time',0)
|
|
|
->whereIn('sale_orders_product_id',$sale_orders_product_id)
|
|
|
->select(DB::raw("sum(finished_num) as finished_num"),'sale_orders_product_id')
|
|
|
->groupby('sale_orders_product_id')
|
|
@@ -425,15 +438,17 @@ class FinishedOrderService extends Service
|
|
|
|
|
|
if(empty($result)) return;
|
|
|
|
|
|
+ $models = new SaleOrdersProduct();
|
|
|
+ $models->setConnection($zt);
|
|
|
foreach ($result as $key => $value){
|
|
|
- SaleOrdersProduct::where('id',$key)->update([
|
|
|
+ $models->where('id',$key)->update([
|
|
|
'finished_num' => $value
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//反写写完工数量(根据生产订单id)
|
|
|
- public function writeFinishedQuantityByOrdersProductId($order_product_id){
|
|
|
+ public function writeFinishedQuantityByOrdersProductId($order_product_id,$zt){
|
|
|
if(empty($order_product_id)) return;
|
|
|
|
|
|
$result = DispatchSub::where('del_time',0)
|
|
@@ -491,6 +506,8 @@ class FinishedOrderService extends Service
|
|
|
$result[$key]['quantity'] = $quantity_tmp;
|
|
|
|
|
|
$process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
|
|
|
+ $process_model->setConnection($user['zt']);
|
|
|
+
|
|
|
$process_id = $process_model->select('process_id')
|
|
|
->where('sort',$process_model->where('del_time',0)
|
|
|
->where('order_product_id',$value['order_product_id'])
|
|
@@ -536,7 +553,9 @@ class FinishedOrderService extends Service
|
|
|
foreach ($result as $value){
|
|
|
$finished_num = $value['quantity'] + $value['finished_num'];
|
|
|
$watste_num = $waste[$value['id']] ?? 0;
|
|
|
- DispatchSub::where('id',$value['id'])
|
|
|
+ $model = new DispatchSub();
|
|
|
+ $model->setConnection($user['zt']);
|
|
|
+ $model->where('id',$value['id'])
|
|
|
->update([
|
|
|
'finished_num' => $finished_num,
|
|
|
'waste_num' => $watste_num,
|
|
@@ -546,7 +565,9 @@ class FinishedOrderService extends Service
|
|
|
//生产订单数量
|
|
|
if(! empty($waste2[$value['order_product_id']])){
|
|
|
$num = $waste2[$value['order_product_id']];
|
|
|
- OrdersProduct::where('id',$value['order_product_id'])->update([
|
|
|
+ $model2 = new OrdersProduct();
|
|
|
+ $model2->setConnection($user['zt']);
|
|
|
+ $model2->where('id',$value['order_product_id'])->update([
|
|
|
'production_quantity' => DB::raw("production_quantity + {$num}"),
|
|
|
'scrapp_num' => DB::raw("scrapp_num + {$num}"),
|
|
|
'dispatch_complete_quantity' => DB::raw("dispatch_complete_quantity + {$num}"),//已派工数量增加
|
|
@@ -556,6 +577,7 @@ class FinishedOrderService extends Service
|
|
|
$insert_waste = $insert_dispatch = $scrapp = [];
|
|
|
//工序
|
|
|
$process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
|
|
|
+ $process_model->setConnection($user['zt']);
|
|
|
foreach ($data as $d){
|
|
|
if($d['id'] == $value['id']){
|
|
|
$process_model->where('order_product_id',$value['order_product_id'])
|
|
@@ -632,12 +654,16 @@ class FinishedOrderService extends Service
|
|
|
}
|
|
|
if(! empty($insert_waste)) $process_model->insert($insert_waste);
|
|
|
if(! empty($insert_dispatch)) $process_model->insert($insert_dispatch);
|
|
|
- if(! empty($scrapp)) ScrappCount::insert($scrapp);
|
|
|
+ if(! empty($scrapp)) {
|
|
|
+ $scrapp_model = new ScrappCount();
|
|
|
+ $scrapp_model->setConnection($user['zt']);
|
|
|
+ $scrapp_model->insert($scrapp);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//反写数量
|
|
|
- $this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'));
|
|
|
- $this->writeFinishedQuantityByOrdersProductId(array_column($result,'order_product_id'));
|
|
|
+ $this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'),$user['zt']);
|
|
|
+ $this->writeFinishedQuantityByOrdersProductId(array_column($result,'order_product_id'),$user['zt']);
|
|
|
DB::commit();
|
|
|
//本地数据写入结束-----------
|
|
|
}catch (\Exception $e){
|