|
@@ -80,6 +80,9 @@ class FinishedOrderService extends Service
|
|
|
|
|
|
public function addInJob($result,$data,$user){
|
|
|
try{
|
|
|
+ //获取数据库连接
|
|
|
+ $database = $this->getConnectionName($user['zt']);
|
|
|
+
|
|
|
//用友数据插入------------
|
|
|
$insert_sql_server = [];
|
|
|
foreach ($result as $key => $value){
|
|
@@ -88,7 +91,7 @@ class FinishedOrderService extends Service
|
|
|
|
|
|
//工序表
|
|
|
$process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
|
|
|
- $process_model->setConnection($user['zt']);
|
|
|
+ $process_model->setConnection($database);
|
|
|
|
|
|
$process_id = $process_model->select('process_id')
|
|
|
->where('sort',$process_model->where('del_time',0)
|
|
@@ -128,7 +131,7 @@ class FinishedOrderService extends Service
|
|
|
$finished_num = $value['quantity'] + $value['finished_num'];
|
|
|
|
|
|
$model = new DispatchSub();
|
|
|
- $model->setConnection($user['zt']);
|
|
|
+ $model->setConnection($database);
|
|
|
$model->where('id',$value['id'])->update([
|
|
|
'finished_num' => $finished_num,
|
|
|
'waste_num' => $waste[$key],
|
|
@@ -197,7 +200,7 @@ class FinishedOrderService extends Service
|
|
|
|
|
|
//工序表
|
|
|
$process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
|
|
|
- $process_model->setConnection($user['zt']);
|
|
|
+ $process_model->setConnection($database);
|
|
|
$process_model->where('order_product_id',$value['order_product_id'])
|
|
|
->where('process_id',$value['process_id'])
|
|
|
->where('dispatch_no',$value['dispatch_no'])
|
|
@@ -214,7 +217,7 @@ class FinishedOrderService extends Service
|
|
|
if(! empty($insert_dispatch)) $process_model->insert($insert_dispatch);
|
|
|
if(! empty($scrapp)) {
|
|
|
$scrapp_model = new ScrappCount();
|
|
|
- $scrapp_model->setConnection($user['zt']);
|
|
|
+ $scrapp_model->setConnection($database);
|
|
|
$scrapp_model->insert($scrapp);
|
|
|
}
|
|
|
|
|
@@ -222,7 +225,7 @@ class FinishedOrderService extends Service
|
|
|
if(! empty($waste[$key])){
|
|
|
$num = $waste[$key];
|
|
|
$model2 = new OrdersProduct();
|
|
|
- $model2->setConnection($user['zt']);
|
|
|
+ $model2->setConnection($database);
|
|
|
$model2->where('id',$value['order_product_id'])->update([
|
|
|
'production_quantity' => DB::raw("production_quantity + {$num}"),
|
|
|
'scrapp_num' => DB::raw("scrapp_num + {$num}"),
|
|
@@ -232,8 +235,8 @@ class FinishedOrderService extends Service
|
|
|
}
|
|
|
|
|
|
//反写数量
|
|
|
- $this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'),$user['zt']);
|
|
|
- $this->writeFinishedQuantityByOrdersProductId(array_column($result,'order_product_id'),$user['zt']);
|
|
|
+ $this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'),$database);
|
|
|
+ $this->writeFinishedQuantityByOrdersProductId(array_column($result,'order_product_id'),$database);
|
|
|
DB::commit();
|
|
|
}catch (\Exception $e){
|
|
|
DB::rollBack();
|
|
@@ -424,11 +427,11 @@ class FinishedOrderService extends Service
|
|
|
}
|
|
|
|
|
|
//反写写完工数量(根据销售订单id)
|
|
|
- public function writeFinishedQuantity($sale_orders_product_id,$zt){
|
|
|
+ public function writeFinishedQuantity($sale_orders_product_id,$database){
|
|
|
if(empty($sale_orders_product_id)) return;
|
|
|
|
|
|
$models = new DispatchSub();
|
|
|
- $models->setConnection($zt);
|
|
|
+ $models->setConnection($database);
|
|
|
$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')
|
|
@@ -439,7 +442,7 @@ class FinishedOrderService extends Service
|
|
|
if(empty($result)) return;
|
|
|
|
|
|
$models = new SaleOrdersProduct();
|
|
|
- $models->setConnection($zt);
|
|
|
+ $models->setConnection($database);
|
|
|
foreach ($result as $key => $value){
|
|
|
$models->where('id',$key)->update([
|
|
|
'finished_num' => $value
|
|
@@ -448,10 +451,12 @@ class FinishedOrderService extends Service
|
|
|
}
|
|
|
|
|
|
//反写写完工数量(根据生产订单id)
|
|
|
- public function writeFinishedQuantityByOrdersProductId($order_product_id,$zt){
|
|
|
+ public function writeFinishedQuantityByOrdersProductId($order_product_id,$database){
|
|
|
if(empty($order_product_id)) return;
|
|
|
|
|
|
- $result = DispatchSub::where('del_time',0)
|
|
|
+ $models = new DispatchSub();
|
|
|
+ $models->setConnection($database);
|
|
|
+ $result = $models->where('del_time',0)
|
|
|
->whereIn('order_product_id',$order_product_id)
|
|
|
->select(DB::raw("sum(finished_num) as finished_num"),'order_product_id')
|
|
|
->groupby('order_product_id')
|
|
@@ -460,8 +465,10 @@ class FinishedOrderService extends Service
|
|
|
|
|
|
if(empty($result)) return;
|
|
|
|
|
|
+ $model = new OrdersProduct();
|
|
|
+ $model->setConnection($database);
|
|
|
foreach ($result as $key => $value){
|
|
|
- OrdersProduct::where('id',$key)->update([
|
|
|
+ $model->where('id',$key)->update([
|
|
|
'finished_num' => $value
|
|
|
]);
|
|
|
}
|
|
@@ -498,6 +505,9 @@ class FinishedOrderService extends Service
|
|
|
|
|
|
public function addMobileInJob($result, $data, $count_arr,$user){
|
|
|
try{
|
|
|
+ //获取数据库连接
|
|
|
+ $database = $this->getConnectionName($user['zt']);
|
|
|
+
|
|
|
//用友数据写入------------
|
|
|
|
|
|
$insert_sql_server = [];
|
|
@@ -506,7 +516,7 @@ 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_model->setConnection($database);
|
|
|
|
|
|
$process_id = $process_model->select('process_id')
|
|
|
->where('sort',$process_model->where('del_time',0)
|
|
@@ -554,9 +564,8 @@ class FinishedOrderService extends Service
|
|
|
$finished_num = $value['quantity'] + $value['finished_num'];
|
|
|
$watste_num = $waste[$value['id']] ?? 0;
|
|
|
$model = new DispatchSub();
|
|
|
- $model->setConnection($user['zt']);
|
|
|
- $model->where('id',$value['id'])
|
|
|
- ->update([
|
|
|
+ $model->setConnection($database);
|
|
|
+ $model->where('id',$value['id'])->update([
|
|
|
'finished_num' => $finished_num,
|
|
|
'waste_num' => $watste_num,
|
|
|
'job_status' => 0,
|
|
@@ -566,7 +575,7 @@ class FinishedOrderService extends Service
|
|
|
if(! empty($waste2[$value['order_product_id']])){
|
|
|
$num = $waste2[$value['order_product_id']];
|
|
|
$model2 = new OrdersProduct();
|
|
|
- $model2->setConnection($user['zt']);
|
|
|
+ $model2->setConnection($database);
|
|
|
$model2->where('id',$value['order_product_id'])->update([
|
|
|
'production_quantity' => DB::raw("production_quantity + {$num}"),
|
|
|
'scrapp_num' => DB::raw("scrapp_num + {$num}"),
|
|
@@ -577,7 +586,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']);
|
|
|
+ $process_model->setConnection($database);
|
|
|
foreach ($data as $d){
|
|
|
if($d['id'] == $value['id']){
|
|
|
$process_model->where('order_product_id',$value['order_product_id'])
|
|
@@ -656,14 +665,14 @@ class FinishedOrderService extends Service
|
|
|
if(! empty($insert_dispatch)) $process_model->insert($insert_dispatch);
|
|
|
if(! empty($scrapp)) {
|
|
|
$scrapp_model = new ScrappCount();
|
|
|
- $scrapp_model->setConnection($user['zt']);
|
|
|
+ $scrapp_model->setConnection($database);
|
|
|
$scrapp_model->insert($scrapp);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//反写数量
|
|
|
- $this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'),$user['zt']);
|
|
|
- $this->writeFinishedQuantityByOrdersProductId(array_column($result,'order_product_id'),$user['zt']);
|
|
|
+ $this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'),$database);
|
|
|
+ $this->writeFinishedQuantityByOrdersProductId(array_column($result,'order_product_id'),$database);
|
|
|
DB::commit();
|
|
|
//本地数据写入结束-----------
|
|
|
}catch (\Exception $e){
|
|
@@ -715,4 +724,17 @@ class FinishedOrderService extends Service
|
|
|
|
|
|
return [true, $result, $post];
|
|
|
}
|
|
|
+
|
|
|
+ public function getConnectionName($name)
|
|
|
+ {
|
|
|
+ $mysql = "mysql";
|
|
|
+
|
|
|
+ if ($name === '001') {
|
|
|
+ $mysql = "mysql_001";
|
|
|
+ } elseif ($name === '002') {
|
|
|
+ $mysql = "mysql_002";
|
|
|
+ }
|
|
|
+
|
|
|
+ return $mysql;
|
|
|
+ }
|
|
|
}
|