|
@@ -15,6 +15,7 @@ use App\Model\OrdersProductProcess;
|
|
|
use App\Model\Process;
|
|
|
use App\Model\SaleOrdersProduct;
|
|
|
use App\Model\Scrapp;
|
|
|
+use App\Model\ScrappCount;
|
|
|
use App\Model\Team;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
@@ -53,7 +54,8 @@ class FinishedOrderService extends Service
|
|
|
|
|
|
$user = [
|
|
|
'id' => $user['id'],
|
|
|
- 'operate_time' => time()
|
|
|
+ 'operate_time' => time(),
|
|
|
+ 'zt' => Request()->header('zt'),
|
|
|
];
|
|
|
$redis = [
|
|
|
'result' => $msg,
|
|
@@ -100,7 +102,7 @@ class FinishedOrderService extends Service
|
|
|
}
|
|
|
|
|
|
if(! empty($insert_sql_server)){
|
|
|
- $sqlServerModel = new FyySqlServerService($user['id']);
|
|
|
+ $sqlServerModel = new FyySqlServerService($user);
|
|
|
if($sqlServerModel->error) return [false,$sqlServerModel->error];
|
|
|
foreach ($insert_sql_server as $value){
|
|
|
list($status,$msg) = $sqlServerModel->U8Rdrecord10Save($value);
|
|
@@ -126,10 +128,11 @@ class FinishedOrderService extends Service
|
|
|
DispatchSub::where('id',$value['id'])->update([
|
|
|
'finished_num' => $finished_num,
|
|
|
'waste_num' => $waste[$key],
|
|
|
- 'job_status' => 0
|
|
|
+ 'job_status' => 0,
|
|
|
+ 'dispatch_quantity' => DB::raw("dispatch_quantity + {$waste[$key]}"),//派工数量增加 派工单可以继续派送
|
|
|
]);
|
|
|
|
|
|
- $insert_waste = [];
|
|
|
+ $insert_waste = $insert_dispatch = $scrapp = [];
|
|
|
if(! empty($data['waste'][$key])){
|
|
|
foreach ($data['waste'][$key] as $v){
|
|
|
for($i = 0 ;$i < $v['num']; $i++){
|
|
@@ -141,13 +144,50 @@ class FinishedOrderService extends Service
|
|
|
'process_id' => $value['process_id'],
|
|
|
'crt_time' => $time,
|
|
|
'dispatch_no' => $value['dispatch_no'],
|
|
|
- 'status' => 4,
|
|
|
+ 'status' => 4,//不良品
|
|
|
'team_id' => $team_tmp,
|
|
|
'finished_id' => $finished_id_tmp,
|
|
|
'equipment_id' => $equipment_id_tmp,
|
|
|
'scrapp_id' => $v['scrapp_id']
|
|
|
];
|
|
|
+ $insert_dispatch[] = [
|
|
|
+ 'order_product_id' => $value['order_product_id'],
|
|
|
+ 'out_order_no' => $value['out_order_no'],
|
|
|
+ 'order_no' => $value['order_no'],
|
|
|
+ 'product_no' => $value['product_no'],
|
|
|
+ 'product_title' => $value['product_title'],
|
|
|
+ 'process_id' => $value['process_id'],
|
|
|
+ 'crt_time' => $time,
|
|
|
+ 'dispatch_no' => $value['dispatch_no'],
|
|
|
+ 'status' => 1, //已派工
|
|
|
+ 'team_id' => 0,
|
|
|
+ 'finished_id' => 0,
|
|
|
+ 'equipment_id' => 0,
|
|
|
+ 'scrapp_id' => 0
|
|
|
+ ];
|
|
|
}
|
|
|
+ $scrapp[] = [
|
|
|
+ 'sale_orders_product_id' => $value['sale_orders_product_id'],
|
|
|
+ 'order_product_id' => $value['order_product_id'],
|
|
|
+ 'out_order_no' => $value['out_order_no'],
|
|
|
+ 'order_no' => $value['order_no'],
|
|
|
+ 'customer_no' => $value['customer_no'],
|
|
|
+ 'customer_name' => $value['customer_name'],
|
|
|
+ 'product_no' => $value['product_no'],
|
|
|
+ 'product_title' => $value['product_title'],
|
|
|
+ 'product_size' => $value['product_size'],
|
|
|
+ 'product_unit' => $value['product_unit'],
|
|
|
+ 'technology_material' => $value['technology_material'],
|
|
|
+ 'technology_name' => $value['technology_name'],
|
|
|
+ 'wood_name' => $value['wood_name'],
|
|
|
+ 'price' => $value['price'],
|
|
|
+ 'process_mark' => $value['process_mark'],
|
|
|
+ 'table_body_mark' => $value['table_body_mark'],
|
|
|
+ 'table_header_mark' => $value['table_header_mark'],
|
|
|
+ 'crt_time' => $time,
|
|
|
+ 'scrapp_num' => $v['num'],
|
|
|
+ 'scrapp_id' => $v['scrapp_id']
|
|
|
+ ];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -166,6 +206,8 @@ 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($waste[$key])){
|
|
@@ -173,6 +215,7 @@ class FinishedOrderService extends Service
|
|
|
OrdersProduct::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}"),//已派工数量增加
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
@@ -198,8 +241,6 @@ class FinishedOrderService extends Service
|
|
|
public function orderDetail($data){
|
|
|
if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
|
|
|
|
|
|
-
|
|
|
-
|
|
|
$first = DispatchSub::where('id',$data['id'])->first();
|
|
|
$process_model = new OrdersProductProcess(['channel' => date("Ymd",$first->out_order_no_time)]);
|
|
|
|
|
@@ -222,8 +263,6 @@ class FinishedOrderService extends Service
|
|
|
}
|
|
|
|
|
|
public function is_same_month($timestamp1,$timestamp2){
|
|
|
-
|
|
|
-
|
|
|
// 格式化时间戳为年份和月份
|
|
|
$year1 = date('Y', $timestamp1);
|
|
|
$month1 = date('m', $timestamp1);
|
|
@@ -250,7 +289,7 @@ class FinishedOrderService extends Service
|
|
|
if($bool) return [false,'正在队列中,请不要重复操作!'];
|
|
|
|
|
|
$result = DispatchSub::whereIn('id',$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','customer_name','technology_material','technology_name','wood_name')
|
|
|
+ ->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','technology_material','technology_name','wood_name','customer_no','out_order_no','waste_num','product_size','product_unit','process_mark','table_body_mark','table_header_mark','sale_orders_product_id')
|
|
|
->orderBy('id','desc')
|
|
|
->get()->toArray();
|
|
|
|
|
@@ -260,7 +299,8 @@ class FinishedOrderService extends Service
|
|
|
}
|
|
|
foreach ($result as $key => $value){
|
|
|
$tmp = $waste[$key] ?? 0;
|
|
|
- if(($data['quantity'][$key] + $value['finished_num'] + $tmp) > $value['dispatch_quantity']) return [false,'完工数量加上损耗数量不能大于派工数量'];
|
|
|
+ $quantity_tmp = $data['quantity'][$key] + $value['finished_num'] + $value['waste_num'] + $tmp;
|
|
|
+ if($quantity_tmp > $value['dispatch_quantity']) return [false,'完工数量加上损耗数量不能大于派工数量'];
|
|
|
}
|
|
|
|
|
|
return [true, $result];
|
|
@@ -419,7 +459,8 @@ class FinishedOrderService extends Service
|
|
|
|
|
|
$user = [
|
|
|
'id' => $user['id'],
|
|
|
- 'operate_time' => time()
|
|
|
+ 'operate_time' => time(),
|
|
|
+ 'zt' => Request()->header('zt'),
|
|
|
];
|
|
|
$redis = [
|
|
|
'result' => $msg,
|
|
@@ -465,7 +506,7 @@ class FinishedOrderService extends Service
|
|
|
}
|
|
|
|
|
|
if(! empty($insert_sql_server)){
|
|
|
- $sqlServerModel = new FyySqlServerService($user['id']);
|
|
|
+ $sqlServerModel = new FyySqlServerService($user);
|
|
|
if($sqlServerModel->error) return [false,$sqlServerModel->error];
|
|
|
foreach ($insert_sql_server as $value){
|
|
|
list($status,$msg) = $sqlServerModel->U8Rdrecord10Save($value);
|
|
@@ -494,11 +535,13 @@ class FinishedOrderService extends Service
|
|
|
$time = time();
|
|
|
foreach ($result as $value){
|
|
|
$finished_num = $value['quantity'] + $value['finished_num'];
|
|
|
+ $watste_num = $waste[$value['id']] ?? 0;
|
|
|
DispatchSub::where('id',$value['id'])
|
|
|
->update([
|
|
|
'finished_num' => $finished_num,
|
|
|
- 'waste_num' => $waste[$value['id']] ?? 0,
|
|
|
- 'job_status' => 0
|
|
|
+ 'waste_num' => $watste_num,
|
|
|
+ 'job_status' => 0,
|
|
|
+ 'dispatch_quantity' => DB::raw("dispatch_quantity + {$watste_num}"),//派工数量增加 派工单可以继续派送
|
|
|
]);
|
|
|
//生产订单数量
|
|
|
if(! empty($waste2[$value['order_product_id']])){
|
|
@@ -506,10 +549,11 @@ class FinishedOrderService extends Service
|
|
|
OrdersProduct::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}"),//已派工数量增加
|
|
|
]);
|
|
|
}
|
|
|
- //损耗
|
|
|
- $insert_waste = [];
|
|
|
+ //损耗和派工 损耗统计
|
|
|
+ $insert_waste = $insert_dispatch = $scrapp = [];
|
|
|
//工序
|
|
|
$process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
|
|
|
foreach ($data as $d){
|
|
@@ -531,6 +575,7 @@ class FinishedOrderService extends Service
|
|
|
for($i = 0 ;$i < $v['num']; $i++){
|
|
|
$insert_waste[] = [
|
|
|
'order_product_id' => $value['order_product_id'],
|
|
|
+ 'out_order_no' => $value['out_order_no'],
|
|
|
'order_no' => $value['order_no'],
|
|
|
'product_no' => $value['product_no'],
|
|
|
'product_title' => $value['product_title'],
|
|
@@ -543,12 +588,51 @@ class FinishedOrderService extends Service
|
|
|
'equipment_id' => $d['equipment_id'],
|
|
|
'scrapp_id' => $v['scrapp_id']
|
|
|
];
|
|
|
+ $insert_dispatch[] = [
|
|
|
+ 'order_product_id' => $value['order_product_id'],
|
|
|
+ 'out_order_no' => $value['out_order_no'],
|
|
|
+ 'order_no' => $value['order_no'],
|
|
|
+ 'product_no' => $value['product_no'],
|
|
|
+ 'product_title' => $value['product_title'],
|
|
|
+ 'process_id' => $value['process_id'],
|
|
|
+ 'crt_time' => $time,
|
|
|
+ 'dispatch_no' => $value['dispatch_no'],
|
|
|
+ 'status' => 1, //已派工
|
|
|
+ 'team_id' => 0,
|
|
|
+ 'finished_id' => 0,
|
|
|
+ 'equipment_id' => 0,
|
|
|
+ 'scrapp_id' => 0
|
|
|
+ ];
|
|
|
}
|
|
|
+ $scrapp[] = [
|
|
|
+ 'sale_orders_product_id' => $value['sale_orders_product_id'],
|
|
|
+ 'order_product_id' => $value['order_product_id'],
|
|
|
+ 'out_order_no' => $value['out_order_no'],
|
|
|
+ 'order_no' => $value['order_no'],
|
|
|
+ 'customer_no' => $value['customer_no'],
|
|
|
+ 'customer_name' => $value['customer_name'],
|
|
|
+ 'product_no' => $value['product_no'],
|
|
|
+ 'product_title' => $value['product_title'],
|
|
|
+ 'product_size' => $value['product_size'],
|
|
|
+ 'product_unit' => $value['product_unit'],
|
|
|
+ 'technology_material' => $value['technology_material'],
|
|
|
+ 'technology_name' => $value['technology_name'],
|
|
|
+ 'wood_name' => $value['wood_name'],
|
|
|
+ 'price' => $value['price'],
|
|
|
+ 'process_mark' => $value['process_mark'],
|
|
|
+ 'table_body_mark' => $value['table_body_mark'],
|
|
|
+ 'table_header_mark' => $value['table_header_mark'],
|
|
|
+ 'crt_time' => $time,
|
|
|
+ 'scrapp_num' => $v['num'],
|
|
|
+ 'scrapp_id' => $v['scrapp_id']
|
|
|
+ ];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if(! empty($insert_waste)) $process_model->insert($insert_waste);
|
|
|
+ if(! empty($insert_dispatch)) $process_model->insert($insert_dispatch);
|
|
|
+ if(! empty($scrapp)) ScrappCount::insert($scrapp);
|
|
|
}
|
|
|
|
|
|
//反写数量
|
|
@@ -593,13 +677,14 @@ class FinishedOrderService extends Service
|
|
|
}
|
|
|
|
|
|
$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','technology_material','technology_name','wood_name')
|
|
|
+ ->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','technology_material','technology_name','wood_name','customer_no','out_order_no','waste_num','product_size','product_unit','process_mark','table_body_mark','table_header_mark','sale_orders_product_id')
|
|
|
->orderBy('id','desc')
|
|
|
->get()->toArray();
|
|
|
|
|
|
foreach ($result as $key => $value){
|
|
|
$tmp = $waste[$value['id']] ?? 0;
|
|
|
- if(($post[$value['id']] + $value['finished_num'] + $tmp) > $value['dispatch_quantity']) return [false,"完工数量加上损耗数量不能大于派工数量",''];
|
|
|
+ $quantity_tmp = $post[$value['id']] + $value['finished_num'] + $value['waste_num'] + $tmp;
|
|
|
+ if($quantity_tmp > $value['dispatch_quantity']) return [false,"完工数量加上损耗数量不能大于派工数量",''];
|
|
|
}
|
|
|
|
|
|
return [true, $result, $post];
|