|
@@ -346,4 +346,112 @@ class FinishedOrderService extends Service
|
|
]);
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public function mobileAdd($data,$user){
|
|
|
|
+ //数据校验以及填充
|
|
|
|
+ list($status,$msg,$count_arr) = $this->orderMobileRule($data);
|
|
|
|
+ if(!$status) return [$status,$msg];
|
|
|
|
+
|
|
|
|
+ try{
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+
|
|
|
|
+ //生产数据的源数据
|
|
|
|
+ $result = $msg;
|
|
|
|
+ $time = time();
|
|
|
|
+
|
|
|
|
+ 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'];
|
|
|
|
+ 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'])
|
|
|
|
+ ->where('process_id',$value['process_id'])
|
|
|
|
+ ->where('dispatch_no',$value['dispatch_no'])
|
|
|
|
+ ->take($d['quantity'])
|
|
|
|
+ ->update([
|
|
|
|
+ 'finished_time' => $time,
|
|
|
|
+ 'status' => 2,
|
|
|
|
+ 'finished_id' => $d['finished_id'],
|
|
|
|
+ 'team_id' => $d['team_id'],
|
|
|
|
+ 'equipment_id' => $d['equipment_id']
|
|
|
|
+ ]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $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)){
|
|
|
|
+ //生成产成品入库
|
|
|
|
+ $sqlServerModel = new FyySqlServerService();
|
|
|
|
+ list($status,$msg) = $sqlServerModel->U8Rdrecord10Save($insert_sql_server);
|
|
|
|
+ if(! $status) {
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ return [false,$msg];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ DB::commit();
|
|
|
|
+ }catch (\Exception $e){
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ return [false,$e->getLine().':'.$e->getMessage()];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return [true,'保存成功!'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function orderMobileRule($data){
|
|
|
|
+ if(empty($data)) return [false,'数据不能为空!',''];
|
|
|
|
+
|
|
|
|
+ $post = [];
|
|
|
|
+ foreach ($data as $value){
|
|
|
|
+ if(empty($value['quantity'])) return [false,'数量必须填写!',''];
|
|
|
|
+ if(empty($value['finished_id']) && empty($value['team_id'])) return [false,'人员和班组必须填写一项!',''];
|
|
|
|
+ if(isset($post[$value['id']])){
|
|
|
|
+ $post[$value['id']] += $value['quantity'];
|
|
|
|
+ }else{
|
|
|
|
+ $post[$value['id']] = $value['quantity'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $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')
|
|
|
|
+ ->orderBy('id','desc')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+ foreach ($result as $key => $value){
|
|
|
|
+ if(($post[$value['id']] + $value['finished_num']) > $value['dispatch_quantity']) return [false,"{$value['dispatch_no']}单号的完工数量不能大于派工数量",''];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return [true, $result,$post];
|
|
|
|
+ }
|
|
}
|
|
}
|