|
@@ -109,6 +109,7 @@ class FinishedOrderService extends Service
|
|
|
//用友数据插入结束----------
|
|
|
|
|
|
//本地数据更新
|
|
|
+ DB::beginTransaction();
|
|
|
$waste = [];
|
|
|
foreach ($data['waste'] as $key => $value){
|
|
|
$waste[$key] = array_sum(array_column($value,'num'));
|
|
@@ -167,7 +168,9 @@ class FinishedOrderService extends Service
|
|
|
|
|
|
//反写数量
|
|
|
$this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'));
|
|
|
+ DB::commit();
|
|
|
}catch (\Exception $e){
|
|
|
+ DB::rollBack();
|
|
|
return [false,$e->getFile() . $e->getLine(). $e->getMessage()];
|
|
|
}
|
|
|
|
|
@@ -373,29 +376,76 @@ class FinishedOrderService extends Service
|
|
|
list($status,$msg,$count_arr) = $this->orderMobileRule($data);
|
|
|
if(!$status) return [$status,$msg];
|
|
|
|
|
|
- try{
|
|
|
- DB::beginTransaction();
|
|
|
+ $user = [
|
|
|
+ 'id' => $user['id'],
|
|
|
+ 'operate_time' => time()
|
|
|
+ ];
|
|
|
+ $redis = [
|
|
|
+ 'result' => $msg,
|
|
|
+ 'data' => $data,
|
|
|
+ 'quantity_count' => $count_arr,
|
|
|
+ ];
|
|
|
+ $job = dispatch(new ProcessDataJob($redis,$user,3))->onQueue(ProcessDataJob::job_one);
|
|
|
+ if(! $job) return [false,'任务没有进入队列!'];
|
|
|
|
|
|
- //生产数据的源数据
|
|
|
- $result = $msg;
|
|
|
- $time = time();
|
|
|
+ //错误计数
|
|
|
+ Redis::hSet('order_failures', md5(json_encode($redis)), 0);
|
|
|
|
|
|
- date_default_timezone_set("PRC");
|
|
|
+ //标记进入队列的数据
|
|
|
+ DispatchSub::whereIn('id',array_column($msg,'id'))->update([
|
|
|
+ 'job_status' => 1,
|
|
|
+ ]);
|
|
|
|
|
|
+ return [true,'任务已进入队列!'];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addMobileInJob($result, $data, $count_arr){
|
|
|
+ try{
|
|
|
+ //用友数据写入------------
|
|
|
+ date_default_timezone_set("PRC");
|
|
|
$insert_sql_server = [];
|
|
|
foreach ($result as $key => $value){
|
|
|
$quantity_tmp = $count_arr[$value['id']];
|
|
|
$result[$key]['quantity'] = $quantity_tmp;
|
|
|
|
|
|
- $finished_num = $quantity_tmp + $value['finished_num'];
|
|
|
+ $process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
|
|
|
+ $process_id = $process_model->select('process_id')
|
|
|
+ ->where('sort',$process_model->where('del_time',0)
|
|
|
+ ->where('order_product_id',$value['order_product_id'])
|
|
|
+ ->max('sort'))
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ if(empty($process_id)) return [false,"未找到最后一道工序"];
|
|
|
+
|
|
|
+ $process_id = $process_id->process_id;
|
|
|
+ if($process_id == $value['process_id']){
|
|
|
+ $insert_sql_server[] = $result[$key];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(! empty($insert_sql_server)){
|
|
|
+ $sqlServerModel = new FyySqlServerService();
|
|
|
+ if($sqlServerModel->error) return [false,$sqlServerModel->error];
|
|
|
+ foreach ($insert_sql_server as $value){
|
|
|
+ list($status,$msg) = $sqlServerModel->U8Rdrecord10Save($value);
|
|
|
+ if(! $status) return [false,$msg];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //用友数据写入结束------------
|
|
|
+
|
|
|
+ //本地数据写入-----------
|
|
|
+ DB::beginTransaction();
|
|
|
+
|
|
|
+ $time = time();
|
|
|
+ foreach ($result as $key => $value){
|
|
|
+ $finished_num = $value['quantity'] + $value['finished_num'];
|
|
|
DispatchSub::where('id',$value['id'])
|
|
|
->update([
|
|
|
'finished_num' => $finished_num,
|
|
|
]);
|
|
|
|
|
|
- //工序表
|
|
|
+ //工序
|
|
|
$process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
|
|
|
-
|
|
|
foreach ($data as $d){
|
|
|
if($d['id'] == $value['id']){
|
|
|
$process_model->where('order_product_id',$value['order_product_id'])
|
|
@@ -411,48 +461,28 @@ class FinishedOrderService extends Service
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- $process_id = $process_model->select('process_id')
|
|
|
- ->where('sort',$process_model->where('del_time',0)
|
|
|
- ->where('order_product_id',$value['order_product_id'])
|
|
|
- ->max('sort'))
|
|
|
- ->first();
|
|
|
-
|
|
|
- if(empty($process_id)){
|
|
|
- DB::rollBack();
|
|
|
- return [false,"未找到最后一道工序"];
|
|
|
- }
|
|
|
- $process_id = $process_id->process_id;
|
|
|
- if($process_id == $value['process_id']){
|
|
|
- $insert_sql_server[] = $result[$key];
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
//反写数量
|
|
|
$this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'));
|
|
|
|
|
|
- if(! empty($insert_sql_server)){
|
|
|
- foreach ($insert_sql_server as $value){
|
|
|
- list($status,$msg) = $this->insertSqlServer($value);
|
|
|
- if(! $status) {
|
|
|
- DB::rollBack();
|
|
|
- return [false,$msg];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
DB::commit();
|
|
|
+ //本地数据写入结束-----------
|
|
|
}catch (\Exception $e){
|
|
|
DB::rollBack();
|
|
|
- return [false,$e->getLine().':'.$e->getMessage()];
|
|
|
+ return [false,$e->getFile() . $e->getLine() . $e->getMessage()];
|
|
|
}
|
|
|
|
|
|
- return [true,'保存成功!'];
|
|
|
+ return [true,''];
|
|
|
}
|
|
|
|
|
|
public function orderMobileRule($data){
|
|
|
if(empty($data)) return [false,'数据不能为空!',''];
|
|
|
|
|
|
+ $dispatch_id = array_unique(array_column($data,'id'));
|
|
|
+ $bool = DispatchSub::whereIn('id',$dispatch_id)->where('job_status',1)->exists();
|
|
|
+ if($bool) return [false,'正在队列中,请不要重复操作!'];
|
|
|
+
|
|
|
$post = [];
|
|
|
foreach ($data as $value){
|
|
|
if(empty($value['quantity'])) return [false,'数量必须填写!',''];
|
|
@@ -464,8 +494,8 @@ class FinishedOrderService extends Service
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $result = DispatchSub::whereIn('id',array_unique(array_column($data,'id')))
|
|
|
- ->select('id','finished_num','dispatch_quantity','out_order_no_time','process_id','dispatch_no','order_product_id','sale_orders_product_id','order_no','product_no','product_title','price')
|
|
|
+ $result = DispatchSub::whereIn('id',$dispatch_id)
|
|
|
+ ->select('id','finished_num','dispatch_quantity','out_order_no_time','process_id','dispatch_no','order_product_id','sale_orders_product_id','order_no','product_no','product_title','price','customer_name')
|
|
|
->orderBy('id','desc')
|
|
|
->get()->toArray();
|
|
|
|
|
@@ -473,6 +503,6 @@ class FinishedOrderService extends Service
|
|
|
if(($post[$value['id']] + $value['finished_num']) > $value['dispatch_quantity']) return [false,"{$value['dispatch_no']}单号的完工数量不能大于派工数量",''];
|
|
|
}
|
|
|
|
|
|
- return [true, $result,$post];
|
|
|
+ return [true, $result, $post];
|
|
|
}
|
|
|
}
|