BoxService.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace App\Service\Box;
  3. use App\Model\Box;
  4. use App\Model\BoxDetail;
  5. use App\Model\Header_ext;
  6. use App\Model\SaleOrdersProduct;
  7. use App\Service\Service;
  8. /**
  9. * 包装相关
  10. * @package App\Models
  11. */
  12. class BoxService extends Service
  13. {
  14. protected static $instance;
  15. protected static $box_header;
  16. protected static $box_detail_header;
  17. protected static $box_hook;
  18. public function __construct(){
  19. self::$box_header = Header_ext::where('type','box')->pluck('value','key')->toArray();
  20. self::$box_detail_header = Header_ext::where('type','box_detail')->pluck('value','key')->toArray();
  21. self::$box_hook = BoxHookService::getInstance();
  22. }
  23. /**
  24. * 包装
  25. * @param $data
  26. * @return array
  27. */
  28. public function boxIn($data){
  29. // $param = $data['param'];
  30. $param = [
  31. [
  32. 'id'=>716,
  33. 'param'=>[
  34. '1',
  35. '1'
  36. ],
  37. ],[
  38. 'id'=>723,
  39. 'param'=>[
  40. '40',
  41. '40'
  42. ],
  43. ],
  44. ];
  45. $ids = [];
  46. $key_list = [];
  47. foreach ($param as $v){
  48. $ids[] = $v['id'];
  49. $total = 0;
  50. foreach ($v['param'] as $vv){
  51. $total += $vv;
  52. }
  53. $key_list[$v['id']] = [
  54. 'detail' => $v['param'],
  55. 'total' => $total,
  56. ];
  57. }
  58. $product_list = SaleOrdersProduct::wherein('id',$ids)->get()->toArray();
  59. foreach ($product_list as $v){
  60. $num_list = $key_list[$v['id']];
  61. $total = $num_list['total'];
  62. $detail = $num_list['detail'];
  63. $un_box_num = $v['order_quantity'] - $v['box_num'];
  64. if($num_list['total'] > $un_box_num) return [false,$v['product_title'].'数量不足'];
  65. }
  66. //$data = [
  67. // 'out_order_no' => 'test123',
  68. // 'top_id' => '1',
  69. // 'ext_1' => '1',
  70. // 'ext_2' => '2',
  71. // 'ext_3' => '3',
  72. // 'ext_4' => '4',
  73. // 'ext_5' => '5',
  74. // 'detail' => [
  75. // [
  76. // 'top_id' => '1',
  77. // 'code' => '001',
  78. // 'title' => '产品名称',
  79. // 'ext_1' => '1',
  80. // 'ext_2' => '2',
  81. // 'ext_3' => '3',
  82. // 'ext_4' => '4',
  83. // 'ext_5' => '5',
  84. // ],[
  85. // 'top_id' => '2',
  86. // 'code' => '002',
  87. // 'title' => '产品名称1',
  88. // 'ext_1' => '11',
  89. // 'ext_2' => '22',
  90. // 'ext_3' => '33',
  91. // 'ext_4' => '44',
  92. // 'ext_5' => '55',
  93. // ],
  94. // ],
  95. // ];
  96. return [true,''];
  97. }
  98. /**
  99. * 包装详情1
  100. * @param $data
  101. * @return array
  102. */
  103. public function boxDetail($data){
  104. list($status,$data) = self::$box_hook->boxList($data);
  105. if(!$status) return [false,$data];
  106. return [true,$data];
  107. }
  108. }