123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- 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;
- /**
- * 包装相关
- * @package App\Models
- */
- class BoxService extends Service
- {
- protected static $instance;
- protected static $box_header;
- protected static $box_detail_header;
- protected static $box_hook;
- 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_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'
- ],
- ],
- ];
- $ids = [];
- $key_list = [];
- foreach ($param as $v){
- $ids[] = $v['id'];
- $total = 0;
- foreach ($v['param'] as $vv){
- $total += $vv;
- }
- $key_list[$v['id']] = [
- 'detail' => $v['param'],
- 'total' => $total,
- ];
- }
- $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'].'数量不足'];
- }
- //$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,''];
- }
- /**
- * 包装详情1
- * @param $data
- * @return array
- */
- public function boxDetail($data){
- list($status,$data) = self::$box_hook->boxList($data);
- if(!$status) return [false,$data];
- return [true,$data];
- }
- }
|