|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace App\Service\Box;
|
|
namespace App\Service\Box;
|
|
|
|
|
|
|
|
+use App\Jobs\BoxAddJob;
|
|
use App\Model\Box;
|
|
use App\Model\Box;
|
|
use App\Model\BoxDetail;
|
|
use App\Model\BoxDetail;
|
|
use App\Model\DispatchSub;
|
|
use App\Model\DispatchSub;
|
|
@@ -27,7 +28,7 @@ class BoxService extends Service
|
|
protected static $box_header;
|
|
protected static $box_header;
|
|
protected static $box_detail_header;
|
|
protected static $box_detail_header;
|
|
protected static $box_hook;
|
|
protected static $box_hook;
|
|
- public $lock_key = 'hc_box_add';
|
|
|
|
|
|
+ public $lock_key = 'hc_box_new_add';
|
|
|
|
|
|
public function __construct()
|
|
public function __construct()
|
|
{
|
|
{
|
|
@@ -36,16 +37,72 @@ class BoxService extends Service
|
|
self::$box_hook = BoxHookService::getInstance();
|
|
self::$box_hook = BoxHookService::getInstance();
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 包装
|
|
|
|
- * @param $data
|
|
|
|
- * @return array
|
|
|
|
- */
|
|
|
|
public function boxIn($data,$user)
|
|
public function boxIn($data,$user)
|
|
{
|
|
{
|
|
- //不超时
|
|
|
|
- ini_set('max_execution_time', 0);
|
|
|
|
|
|
+ list($status, $msg) = $this->boxInRule($data, $user);
|
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
|
+
|
|
|
|
+ //限制频率
|
|
|
|
+ $limit_key = $this->lock_key;
|
|
|
|
+ list($status,$msg) = $this->limitingSendRequestBackgNeed($limit_key);
|
|
|
|
+ if(! $status) return [false, '请稍后操作'];
|
|
|
|
+
|
|
|
|
+ $job = BoxAddJob::dispatch($data,$user)->onQueue(BoxAddJob::job);
|
|
|
|
+ if(! $job) {
|
|
|
|
+ $this->dellimitingSendRequestBackgNeed($limit_key);
|
|
|
|
+ return [false,'任务未进入后台队列,请联系管理员'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return [true, ''];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function boxInRule($data,$user)
|
|
|
|
+ {
|
|
|
|
+ try{
|
|
|
|
+ $ids = [];
|
|
|
|
+ $sale_ids = [];
|
|
|
|
+ $data = $data['param'];
|
|
|
|
+ $key_list = [];
|
|
|
|
+ foreach ($data as $v) {
|
|
|
|
+ if($v['id'] < 0) $sale_ids[] = -$v['id'];
|
|
|
|
+ else $ids[] = $v['id'];
|
|
|
|
+ if($v['id'] < 0) $v['id'] = -$v['id'];
|
|
|
|
+ $total = 0;
|
|
|
|
+ foreach ($v['params'] as $vv) {
|
|
|
|
+ $total += $vv;
|
|
|
|
+ }
|
|
|
|
+ $key_list[$v['id']] = [
|
|
|
|
+ 'detail' => $v['params'],
|
|
|
|
+ 'total' => $total,
|
|
|
|
+ 'team_id' => isset($v['team_id']) ? $v['team_id'] : 0,
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //数据获取
|
|
|
|
+ $product_list = OrdersProduct::wherein('id', $ids)->get()->toArray();
|
|
|
|
+
|
|
|
|
+ //校验
|
|
|
|
+ $flag = "";
|
|
|
|
+ foreach ($product_list as $value){
|
|
|
|
+ $key = $value['out_order_no'] . $value['product_no'] . $value['technology_name'];
|
|
|
|
+ if(! empty($flag)){
|
|
|
|
+ if($flag != $key) return [false , "一次包装只允许包一种产品的一种颜色!"];
|
|
|
|
+ }else{
|
|
|
|
+ $flag = $key;
|
|
|
|
+ }
|
|
|
|
+ $num_list = $key_list[$value['id']];
|
|
|
|
+ $total = $num_list['total'];
|
|
|
|
+ $un_box_num = bcsub($value['dispatch_complete_quantity'] , $value['box_num'],3);
|
|
|
|
+ if ($total > $un_box_num) return [false, $value['product_title'] . ' ' . $value['technology_name'] . ' 可包装的数量不足'];
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ return [true, ''];
|
|
|
|
+ }catch (\Throwable $e){
|
|
|
|
+ return [false,$e->getFile() . '|' . $e->getLine(). '|' .$e->getMessage()];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function boxInSettle($data, $user){
|
|
$ids = [];
|
|
$ids = [];
|
|
$sale_ids = [];
|
|
$sale_ids = [];
|
|
$top_order_no = $data['order_no'];
|
|
$top_order_no = $data['order_no'];
|
|
@@ -70,28 +127,12 @@ class BoxService extends Service
|
|
}
|
|
}
|
|
$insert = [];
|
|
$insert = [];
|
|
|
|
|
|
- //限制频率
|
|
|
|
$limit_key = $this->lock_key;
|
|
$limit_key = $this->lock_key;
|
|
- list($status,$msg) = $this->limitingSendRequestBackgNeed($limit_key);
|
|
|
|
- if(! $status) return [false, '正在生成包装数据,以及用友数据,请稍后操作!'];
|
|
|
|
-
|
|
|
|
try{
|
|
try{
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
|
|
|
|
//数据获取
|
|
//数据获取
|
|
$product_list = OrdersProduct::wherein('id', $ids)->get()->toArray();
|
|
$product_list = OrdersProduct::wherein('id', $ids)->get()->toArray();
|
|
- $flag = "";
|
|
|
|
- foreach ($product_list as $value){
|
|
|
|
- $key = $value['out_order_no'] . $value['product_no'] . $value['technology_name'];
|
|
|
|
- if(! empty($flag)){
|
|
|
|
- if($flag != $key) {
|
|
|
|
- $this->dellimitingSendRequestBackgNeed($limit_key);
|
|
|
|
- return [false , "一次包装只允许包一种产品的一种颜色!"];
|
|
|
|
- }
|
|
|
|
- }else{
|
|
|
|
- $flag = $key;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
$sale_product_list = SaleOrdersProduct::wherein('id', $sale_ids)->get()->toArray();
|
|
$sale_product_list = SaleOrdersProduct::wherein('id', $sale_ids)->get()->toArray();
|
|
|
|
|
|
//生产订单包装----------------
|
|
//生产订单包装----------------
|
|
@@ -101,11 +142,6 @@ class BoxService extends Service
|
|
$total = $num_list['total'];
|
|
$total = $num_list['total'];
|
|
$detail = $num_list['detail'];
|
|
$detail = $num_list['detail'];
|
|
$team_id = $num_list['team_id'];
|
|
$team_id = $num_list['team_id'];
|
|
- $un_box_num = bcsub($v['dispatch_complete_quantity'] , $v['box_num'],3);
|
|
|
|
- if ($total > $un_box_num) {
|
|
|
|
- $this->dellimitingSendRequestBackgNeed($limit_key);
|
|
|
|
- return [false, $v['product_title'] . ' ' . $v['technology_name'] . ' 可包装的数量不足'];
|
|
|
|
- }
|
|
|
|
|
|
|
|
$ext_1 = $v['product_no'];//产品编号
|
|
$ext_1 = $v['product_no'];//产品编号
|
|
$ext_2 = $v['technology_material']; //工艺材质 废弃
|
|
$ext_2 = $v['technology_material']; //工艺材质 废弃
|
|
@@ -143,54 +179,6 @@ class BoxService extends Service
|
|
]);
|
|
]);
|
|
}
|
|
}
|
|
|
|
|
|
- //销售订单包装----------------todo 目前只能按找生产包所以continue
|
|
|
|
-// foreach ($sale_product_list as $v) {continue;
|
|
|
|
-// $box_type = 0;
|
|
|
|
-// if($v['id'] < 0) {
|
|
|
|
-// $v['id'] = -$v['id'];
|
|
|
|
-// $box_type = 1;
|
|
|
|
-// }
|
|
|
|
-// $num_list = $key_list[$v['id']];
|
|
|
|
-// $total = $num_list['total'];
|
|
|
|
-// $detail = $num_list['detail'];
|
|
|
|
-// $team_id = $num_list['team_id'];
|
|
|
|
-// $box_detail = new BoxDetail(['channel'=>$top_order_no]);
|
|
|
|
-// $un_box_num = $v['order_quantity'] - $v['box_num'] - $box_detail->where('top_id',$v['id'])->where('del_time',0)->where('box_type',1)->sum('num');
|
|
|
|
-// if ($total > $un_box_num) return [false, $v['product_title'] . '数量不足'];
|
|
|
|
-//
|
|
|
|
-// $ext_1 = $v['product_no'];//产品编号
|
|
|
|
-// $ext_2 = $v['technology_material']; //工艺材质 废弃
|
|
|
|
-// $ext_3 = $v['technology_name'];//工艺名称 改为颜色
|
|
|
|
-// $ext_4 = $v['wood_name'];//木皮 废弃
|
|
|
|
-// $ext_5 = $v['process_mark'];//工艺备注 废弃
|
|
|
|
-// $ext_8 = $v['product_title'];//产品名称
|
|
|
|
-// $out_order_no = $insert['out_order_no'] = $v['out_order_no'];
|
|
|
|
-// $top_id = $v['id'];
|
|
|
|
-// foreach ($detail as $vv){
|
|
|
|
-// $box_insert[] = [
|
|
|
|
-// 'out_order_no' => $out_order_no,
|
|
|
|
-// 'top_id' => $top_id,
|
|
|
|
-// 'orders_product_id' => 0,
|
|
|
|
-// 'ext_1' => $ext_1,
|
|
|
|
-// 'ext_2' => $ext_2,
|
|
|
|
-// 'ext_3' => $ext_3,
|
|
|
|
-// 'ext_4' => $ext_4,
|
|
|
|
-// 'ext_5' => $ext_5,
|
|
|
|
-// 'ext_8' => $ext_8,
|
|
|
|
-// 'num' => $vv,
|
|
|
|
-// 'price' => $v['price'],
|
|
|
|
-// 'box_type' => $box_type,
|
|
|
|
-// 'team_id' => $team_id,
|
|
|
|
-// 'shipment_order_no' => $transport_no,
|
|
|
|
-// ];
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// //修改销售订单 包装数量
|
|
|
|
-// SaleOrdersProduct::where('id',$v['id'])->update([
|
|
|
|
-// 'box_num' => DB::raw('box_num + '.$total),
|
|
|
|
-// ]);
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
//客户名称
|
|
//客户名称
|
|
$ext_1 = "";
|
|
$ext_1 = "";
|
|
if(empty($ext_1) && isset($sale_product_list[0]['customer_name'])) $ext_1 = $sale_product_list[0]['customer_name'];
|
|
if(empty($ext_1) && isset($sale_product_list[0]['customer_name'])) $ext_1 = $sale_product_list[0]['customer_name'];
|
|
@@ -204,7 +192,7 @@ class BoxService extends Service
|
|
if(! $status) {
|
|
if(! $status) {
|
|
$this->dellimitingSendRequestBackgNeed($limit_key);
|
|
$this->dellimitingSendRequestBackgNeed($limit_key);
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
- return [false,$msg];
|
|
|
|
|
|
+ return [false, $msg];
|
|
}
|
|
}
|
|
|
|
|
|
//更新完工数量
|
|
//更新完工数量
|
|
@@ -212,7 +200,7 @@ class BoxService extends Service
|
|
if(! $status) {
|
|
if(! $status) {
|
|
$this->dellimitingSendRequestBackgNeed($limit_key);
|
|
$this->dellimitingSendRequestBackgNeed($limit_key);
|
|
DB::rollBack();
|
|
DB::rollBack();
|
|
- return [false,$msg1];
|
|
|
|
|
|
+ return [false, $msg1];
|
|
}
|
|
}
|
|
|
|
|
|
//用友 ------产成品入库
|
|
//用友 ------产成品入库
|
|
@@ -228,6 +216,7 @@ class BoxService extends Service
|
|
}
|
|
}
|
|
|
|
|
|
DB::commit();
|
|
DB::commit();
|
|
|
|
+
|
|
$this->dellimitingSendRequestBackgNeed($limit_key);
|
|
$this->dellimitingSendRequestBackgNeed($limit_key);
|
|
return [true, ['package_data' => $package_data]];
|
|
return [true, ['package_data' => $package_data]];
|
|
}catch (\Throwable $e){
|
|
}catch (\Throwable $e){
|
|
@@ -236,7 +225,7 @@ class BoxService extends Service
|
|
if (str_contains($e->getMessage(), '1062') || str_contains($e->getMessage(), 'Duplicate entry')) {
|
|
if (str_contains($e->getMessage(), '1062') || str_contains($e->getMessage(), 'Duplicate entry')) {
|
|
return [false, '网络波动,请重新操作!'];
|
|
return [false, '网络波动,请重新操作!'];
|
|
}
|
|
}
|
|
- return [false,$e->getLine().':'.$e->getMessage()];
|
|
|
|
|
|
+ return [false, $e->getFile(). '|' .$e->getLine().'|'.$e->getMessage()];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|