| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 | <?phpnamespace App\Service\Box;use App\Model\Box;use App\Model\BoxDetail;use App\Model\Header_ext;use App\Model\OrdersProduct;use App\Model\SaleOrdersProduct;use App\Service\Service;use Illuminate\Support\Facades\DB;/** * 包装相关 * @package App\Models */class BoxService extends Service{    protected static $instance;    protected static $box_header;    protected static $box_detail_header;    protected static $box_hook;    public $lock_key = 'box';    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)    {        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) {            $ids[] = $v['id'];            $total = 0;            foreach ($v['param'] as $vv) {                $total += $vv;            }            $key_list[$v['id']] = [                'detail' => $v['param'],                'total' => $total,            ];        }        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),                ]);            }            DB::commit();            return [true,''];        }catch (\Exception $e){            DB::rollBack();            return [false,$e->getLine().':'.$e->getMessage()];        }    }    /**     * 包装详情1     * @param $data     * @return array     */    public function boxDetail($data)    {        list($status, $data) = self::$box_hook->boxDetail($data);        if (!$status) return [false, $data];        return [true, $data];    }    public function boxProductList($data){        $box = new Box();        if(!isset($data['id'])) return [false,'id not found'];        $model = OrdersProduct::where('del_time',0)->wherein('sale_orders_product_id',$data['id'])            ->select('id','order_no','out_order_no','out_order_no_time','customer_no','customer_name','table_header_mark','product_no','product_title','product_size','product_unit','order_quantity','technology_material','technology_name','wood_name','process_mark','table_body_mark','out_crt_man','out_checker_man','out_checker_time','production_quantity','production_time','production_no','status','sale_orders_product_id')            ->orderBy('id','desc')->get()->toArray();        $data = [            [                'id' => 1,                'out_order_no' => '销售订单号',                'production_time' => '下生产时间时间戳',                'customer_no' => '客户编码',                'customer_name' => '客户名称',                'product_no' => '产品编码',                'product_title' => '产品名称',                'product_size' => '产品规格',                'type' => '1生产包装2备用包装',                'is_box_num' => '已包装数量',                'un_box_num' => '未包装',                'sale_num' => '销售数量',            ]        ];        return [true,$data];    }}
 |