|
@@ -3,12 +3,12 @@
|
|
|
namespace App\Service\Box;
|
|
|
|
|
|
|
|
|
-
|
|
|
use App\Model\Box;
|
|
|
use App\Model\BoxDetail;
|
|
|
use App\Model\Header_ext;
|
|
|
use App\Model\SaleOrdersProduct;
|
|
|
use App\Service\Service;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
/**
|
|
|
* 包装相关
|
|
@@ -21,48 +21,51 @@ class BoxService extends Service
|
|
|
protected static $box_header;
|
|
|
protected static $box_detail_header;
|
|
|
protected static $box_hook;
|
|
|
+ public $lock_key = 'box';
|
|
|
|
|
|
- public function __construct(){
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
|
|
|
- self::$box_header = Header_ext::where('type','box')->pluck('value','key')->toArray();
|
|
|
- self::$box_detail_header = Header_ext::where('type','box_detail')->pluck('value','key')->toArray();
|
|
|
+ self::$box_header = Header_ext::where('type', 'box')->pluck('value', 'key')->toArray();
|
|
|
+ self::$box_detail_header = Header_ext::where('type', 'box_detail')->pluck('value', 'key')->toArray();
|
|
|
self::$box_hook = BoxHookService::getInstance();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 包装
|
|
|
* @param $data
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function boxIn($data){
|
|
|
-
|
|
|
-// $param = $data['param'];
|
|
|
- $param = [
|
|
|
- [
|
|
|
- 'id'=>716,
|
|
|
- 'param'=>[
|
|
|
- '1',
|
|
|
- '1'
|
|
|
- ],
|
|
|
- ],[
|
|
|
- 'id'=>723,
|
|
|
- 'param'=>[
|
|
|
- '40',
|
|
|
- '40'
|
|
|
- ],
|
|
|
- ],
|
|
|
- ];
|
|
|
+ public function boxIn($data)
|
|
|
+ {
|
|
|
+
|
|
|
+ if(!isset($data['param'])) return [false,'not found param'];
|
|
|
+ $param = $data['param'];
|
|
|
+// $param = [
|
|
|
+// [
|
|
|
+// 'id' => 716,
|
|
|
+// 'param' => [
|
|
|
+// '1',
|
|
|
+// '1'
|
|
|
+// ],
|
|
|
+// ], [
|
|
|
+// 'id' => 723,
|
|
|
+// 'param' => [
|
|
|
+// '40',
|
|
|
+// '40'
|
|
|
+// ],
|
|
|
+// ],
|
|
|
+// ];
|
|
|
|
|
|
$ids = [];
|
|
|
$key_list = [];
|
|
|
- foreach ($param as $v){
|
|
|
+ foreach ($param as $v) {
|
|
|
$ids[] = $v['id'];
|
|
|
$total = 0;
|
|
|
|
|
|
- foreach ($v['param'] as $vv){
|
|
|
+ foreach ($v['param'] as $vv) {
|
|
|
$total += $vv;
|
|
|
}
|
|
|
$key_list[$v['id']] = [
|
|
@@ -71,47 +74,62 @@ class BoxService extends Service
|
|
|
];
|
|
|
}
|
|
|
|
|
|
- $product_list = SaleOrdersProduct::wherein('id',$ids)->get()->toArray();
|
|
|
- foreach ($product_list as $v){
|
|
|
- $num_list = $key_list[$v['id']];
|
|
|
- $total = $num_list['total'];
|
|
|
- $detail = $num_list['detail'];
|
|
|
- $un_box_num = $v['order_quantity'] - $v['box_num'];
|
|
|
- if($num_list['total'] > $un_box_num) return [false,$v['product_title'].'数量不足'];
|
|
|
+ try{
|
|
|
+ DB::beginTransaction();
|
|
|
+ $product_list = SaleOrdersProduct::wherein('id', $ids)->get()->toArray();
|
|
|
+ foreach ($product_list as $v) {
|
|
|
+ $key = $this->lock_key.'_'.$v['id'];
|
|
|
+ $lock_status = $this->isLock($key);
|
|
|
+ if(!$lock_status) return [false,'操作过于频繁'];
|
|
|
+ $num_list = $key_list[$v['id']];
|
|
|
+ $total = $num_list['total'];
|
|
|
+ $detail = $num_list['detail'];
|
|
|
+ $un_box_num = $v['order_quantity'] - $v['box_num'];
|
|
|
+ if ($total > $un_box_num) return [false, $v['product_title'] . '数量不足'];
|
|
|
+
|
|
|
+ $ext_1 = $v['customer_no'];
|
|
|
+ $ext_2 = $v['customer_name'];
|
|
|
+ $ext_3 = $v['product_no'];
|
|
|
+ $ext_4 = $v['product_title'];
|
|
|
+ $ext_5 = $v['product_size'];
|
|
|
+ $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,
|
|
|
+ 'ext_1' => $ext_1,
|
|
|
+ 'ext_2' => $ext_2,
|
|
|
+ 'ext_3' => $ext_3,
|
|
|
+ 'ext_4' => $ext_4,
|
|
|
+ 'ext_5' => $ext_5,
|
|
|
+ 'num' => $vv,
|
|
|
+
|
|
|
+ ];
|
|
|
+ list($status,$msg) = self::$box_hook->boxInsert($box_insert);
|
|
|
+
|
|
|
+ if(!$status) {
|
|
|
+ $this->delLock($key);
|
|
|
+ DB::rollBack();
|
|
|
+ return [false,$msg];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ $this->delLock($key);
|
|
|
+ SaleOrdersProduct::where('id',$top_id)->update([
|
|
|
+ 'box_num' => DB::raw('box_num + '.$total),
|
|
|
+ ]);
|
|
|
|
|
|
- }
|
|
|
|
|
|
- //$data = [
|
|
|
- // 'out_order_no' => 'test123',
|
|
|
- // 'top_id' => '1',
|
|
|
- // 'ext_1' => '1',
|
|
|
- // 'ext_2' => '2',
|
|
|
- // 'ext_3' => '3',
|
|
|
- // 'ext_4' => '4',
|
|
|
- // 'ext_5' => '5',
|
|
|
- // 'detail' => [
|
|
|
- // [
|
|
|
- // 'top_id' => '1',
|
|
|
- // 'code' => '001',
|
|
|
- // 'title' => '产品名称',
|
|
|
- // 'ext_1' => '1',
|
|
|
- // 'ext_2' => '2',
|
|
|
- // 'ext_3' => '3',
|
|
|
- // 'ext_4' => '4',
|
|
|
- // 'ext_5' => '5',
|
|
|
- // ],[
|
|
|
- // 'top_id' => '2',
|
|
|
- // 'code' => '002',
|
|
|
- // 'title' => '产品名称1',
|
|
|
- // 'ext_1' => '11',
|
|
|
- // 'ext_2' => '22',
|
|
|
- // 'ext_3' => '33',
|
|
|
- // 'ext_4' => '44',
|
|
|
- // 'ext_5' => '55',
|
|
|
- // ],
|
|
|
- // ],
|
|
|
- // ];
|
|
|
- return [true,''];
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ return [true,''];
|
|
|
+ }catch (\Exception $e){
|
|
|
+
|
|
|
+ DB::rollBack();
|
|
|
+ return [false,$e->getLine().':'.$e->getMessage()];
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -120,17 +138,12 @@ class BoxService extends Service
|
|
|
* @param $data
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function boxDetail($data){
|
|
|
- list($status,$data) = self::$box_hook->boxList($data);
|
|
|
- if(!$status) return [false,$data];
|
|
|
- return [true,$data];
|
|
|
+ public function boxDetail($data)
|
|
|
+ {
|
|
|
+ list($status, $data) = self::$box_hook->boxDetail($data);
|
|
|
+ if (!$status) return [false, $data];
|
|
|
+ return [true, $data];
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|