|
@@ -2,7 +2,7 @@
|
|
|
|
|
|
namespace App\Service;
|
|
namespace App\Service;
|
|
|
|
|
|
-use App\Model\Dispatch;
|
|
|
|
|
|
+use App\Jobs\ProcessDataJob;
|
|
use App\Model\DispatchSub;
|
|
use App\Model\DispatchSub;
|
|
use App\Model\Employee;
|
|
use App\Model\Employee;
|
|
use App\Model\EmployeeTeamPermission;
|
|
use App\Model\EmployeeTeamPermission;
|
|
@@ -10,13 +10,13 @@ use App\Model\Equipment;
|
|
use App\Model\FinishedOrder;
|
|
use App\Model\FinishedOrder;
|
|
use App\Model\FinishedOrderScrapp;
|
|
use App\Model\FinishedOrderScrapp;
|
|
use App\Model\FinishedOrderSub;
|
|
use App\Model\FinishedOrderSub;
|
|
-use App\Model\OrdersProduct;
|
|
|
|
use App\Model\OrdersProductProcess;
|
|
use App\Model\OrdersProductProcess;
|
|
use App\Model\Process;
|
|
use App\Model\Process;
|
|
use App\Model\SaleOrdersProduct;
|
|
use App\Model\SaleOrdersProduct;
|
|
use App\Model\Scrapp;
|
|
use App\Model\Scrapp;
|
|
use App\Model\Team;
|
|
use App\Model\Team;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
+use Illuminate\Support\Facades\Redis;
|
|
|
|
|
|
class FinishedOrderService extends Service
|
|
class FinishedOrderService extends Service
|
|
{
|
|
{
|
|
@@ -50,34 +50,81 @@ class FinishedOrderService extends Service
|
|
list($status,$msg) = $this->orderRule($data);
|
|
list($status,$msg) = $this->orderRule($data);
|
|
if(!$status) return [$status,$msg];
|
|
if(!$status) return [$status,$msg];
|
|
|
|
|
|
|
|
+ $user = [
|
|
|
|
+ 'id' => $user['id'],
|
|
|
|
+ 'operate_time' => time()
|
|
|
|
+ ];
|
|
|
|
+ $redis = [
|
|
|
|
+ 'result' => $msg,
|
|
|
|
+ 'data' => $data,
|
|
|
|
+ ];
|
|
|
|
+ $job = dispatch(new ProcessDataJob($redis,$user,1))->onQueue(ProcessDataJob::job_one);
|
|
|
|
+ if(! $job){
|
|
|
|
+ return [false,'任务没有进入队列!'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //错误计数
|
|
|
|
+ Redis::hSet('order_failures', md5(json_encode($redis)), 0);
|
|
|
|
+
|
|
|
|
+ //标记进入队列的数据
|
|
|
|
+ DispatchSub::whereIn('id',$data['id'])->update([
|
|
|
|
+ 'job_status' => 1,
|
|
|
|
+ ]);
|
|
|
|
+ return [true,'任务已进入队列!'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function addInJob($result,$data){
|
|
try{
|
|
try{
|
|
- DB::beginTransaction();
|
|
|
|
|
|
+ date_default_timezone_set("PRC");
|
|
|
|
+
|
|
|
|
+ //用友数据插入------------
|
|
|
|
+ $insert_sql_server = [];
|
|
|
|
+ foreach ($result as $key => $value){
|
|
|
|
+ $quantity_tmp = $data['quantity'][$key];
|
|
|
|
+ $result[$key]['quantity'] = $quantity_tmp;
|
|
|
|
+
|
|
|
|
+ //工序表
|
|
|
|
+ $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];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //用友数据插入结束----------
|
|
|
|
+
|
|
|
|
+ //本地数据更新
|
|
$waste = [];
|
|
$waste = [];
|
|
foreach ($data['waste'] as $key => $value){
|
|
foreach ($data['waste'] as $key => $value){
|
|
$waste[$key] = array_sum(array_column($value,'num'));
|
|
$waste[$key] = array_sum(array_column($value,'num'));
|
|
}
|
|
}
|
|
-
|
|
|
|
- //生产数据的源数据
|
|
|
|
- $result = $msg;
|
|
|
|
$time = time();
|
|
$time = time();
|
|
|
|
|
|
- date_default_timezone_set("PRC");
|
|
|
|
-
|
|
|
|
- $insert_sql_server = [];
|
|
|
|
foreach ($result as $key => $value){
|
|
foreach ($result as $key => $value){
|
|
- $quantity_tmp = $data['quantity'][$key];
|
|
|
|
$finished_id_tmp = $data['finish_id'][$key];
|
|
$finished_id_tmp = $data['finish_id'][$key];
|
|
$team_tmp = $data['team_id'][$key];
|
|
$team_tmp = $data['team_id'][$key];
|
|
$equipment_id_tmp = $data['equipment_id'][$key];
|
|
$equipment_id_tmp = $data['equipment_id'][$key];
|
|
- $result[$key]['quantity'] = $quantity_tmp;
|
|
|
|
|
|
+ $finished_num = $value['quantity'] + $value['finished_num'];
|
|
|
|
|
|
- $finished_num = $quantity_tmp + $value['finished_num'];
|
|
|
|
- DispatchSub::where('id',$value['id'])
|
|
|
|
- ->update([
|
|
|
|
- 'finished_num' => $finished_num,
|
|
|
|
- 'waste_num' => $waste[$key]
|
|
|
|
- ]);
|
|
|
|
|
|
+ DispatchSub::where('id',$value['id'])->update([
|
|
|
|
+ 'finished_num' => $finished_num,
|
|
|
|
+ 'waste_num' => $waste[$key]
|
|
|
|
+ ]);
|
|
|
|
|
|
$insert_waste = [];
|
|
$insert_waste = [];
|
|
if(! empty($data['waste'][$key])){
|
|
if(! empty($data['waste'][$key])){
|
|
@@ -103,26 +150,10 @@ class FinishedOrderService extends Service
|
|
|
|
|
|
//工序表
|
|
//工序表
|
|
$process_model = new OrdersProductProcess(['channel' => date("Ymd",$value['out_order_no_time'])]);
|
|
$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)){
|
|
|
|
- DB::rollBack();
|
|
|
|
- return [false,"未找到最后一道工序"];
|
|
|
|
- }
|
|
|
|
- $process_id = $process_id->process_id;
|
|
|
|
- if($process_id == $value['process_id']){
|
|
|
|
- $insert_sql_server[] = $result[$key];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
$process_model->where('order_product_id',$value['order_product_id'])
|
|
$process_model->where('order_product_id',$value['order_product_id'])
|
|
->where('process_id',$value['process_id'])
|
|
->where('process_id',$value['process_id'])
|
|
->where('dispatch_no',$value['dispatch_no'])
|
|
->where('dispatch_no',$value['dispatch_no'])
|
|
- ->take($quantity_tmp)
|
|
|
|
|
|
+ ->take($value['quantity'])
|
|
->update([
|
|
->update([
|
|
'finished_time' => $time,
|
|
'finished_time' => $time,
|
|
'status' => 2,
|
|
'status' => 2,
|
|
@@ -136,24 +167,11 @@ class FinishedOrderService extends Service
|
|
|
|
|
|
//反写数量
|
|
//反写数量
|
|
$this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'));
|
|
$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){
|
|
}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 del($data){
|
|
public function del($data){
|
|
@@ -210,6 +228,9 @@ class FinishedOrderService extends Service
|
|
if($this->isEmpty($data,'quantity')) return [false,'请填写完工数量!'];
|
|
if($this->isEmpty($data,'quantity')) return [false,'请填写完工数量!'];
|
|
if($this->isEmpty($data,'finish_id') && $this->isEmpty($data,'team_id')) return [false,'人员和班组不能都为空!'];
|
|
if($this->isEmpty($data,'finish_id') && $this->isEmpty($data,'team_id')) return [false,'人员和班组不能都为空!'];
|
|
|
|
|
|
|
|
+ $bool = DispatchSub::whereIn('id',$data['id'])->where('job_status',1)->exists();
|
|
|
|
+ if($bool) return [false,'正在队列中,请不要重复操作!'];
|
|
|
|
+
|
|
$result = DispatchSub::whereIn('id',$data['id'])
|
|
$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')
|
|
->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')
|
|
->orderBy('id','desc')
|
|
@@ -410,10 +431,14 @@ class FinishedOrderService extends Service
|
|
//反写数量
|
|
//反写数量
|
|
$this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'));
|
|
$this->writeFinishedQuantity(array_column($result,'sale_orders_product_id'));
|
|
|
|
|
|
- list($status,$msg) = $this->insertSqlServer($insert_sql_server);
|
|
|
|
- if(! $status) {
|
|
|
|
- DB::rollBack();
|
|
|
|
- return [false,$msg];
|
|
|
|
|
|
+ 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();
|
|
DB::commit();
|
|
@@ -450,14 +475,4 @@ class FinishedOrderService extends Service
|
|
|
|
|
|
return [true, $result,$post];
|
|
return [true, $result,$post];
|
|
}
|
|
}
|
|
-
|
|
|
|
- //产成品入库
|
|
|
|
- public function insertSqlServer($array){
|
|
|
|
- if(empty($array)) return [true,''];
|
|
|
|
-
|
|
|
|
- $sqlServerModel = new FyySqlServerService();
|
|
|
|
- list($status,$msg) = $sqlServerModel->U8Rdrecord10Save($array);
|
|
|
|
-
|
|
|
|
- return [$status,$msg];
|
|
|
|
- }
|
|
|
|
}
|
|
}
|