|
@@ -0,0 +1,173 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace App\Service\Transport;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+use App\Model\Box;
|
|
|
|
+use App\Model\BoxDetail;
|
|
|
|
+use App\Model\Header_ext;
|
|
|
|
+use App\Service\Service;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 发货相关工厂模式
|
|
|
|
+ * @package App\Models
|
|
|
|
+ */
|
|
|
|
+class TransportHookService extends Service
|
|
|
|
+{
|
|
|
|
+
|
|
|
|
+ protected static $instance;
|
|
|
|
+ protected static $transport_header;
|
|
|
|
+ protected static $transport_detail_header;
|
|
|
|
+
|
|
|
|
+ public function __construct(){
|
|
|
|
+
|
|
|
|
+ self::$transport_header = Header_ext::where('type','box')->pluck('value','key')->toArray();
|
|
|
|
+ self::$transport_detail_header = Header_ext::where('type','box_detail')->pluck('value','key')->toArray();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static function getInstance(): self
|
|
|
|
+ {
|
|
|
|
+ if (self::$instance == null) {
|
|
|
|
+ self::$instance = new HeaderWordHookService();
|
|
|
|
+ }
|
|
|
|
+ return self::$instance;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 包装单新增
|
|
|
|
+ * @param $data
|
|
|
|
+ * @return array
|
|
|
|
+ */
|
|
|
|
+ public function boxInsert($data){
|
|
|
|
+ $box = new Box();
|
|
|
|
+ $data['order_no'] = $this->setOrderNo();
|
|
|
|
+ if(!isset($data['out_order_no'])) return [false,'out_order_no is not exist'];
|
|
|
|
+ list($status,$box) = $this->dealBox($box,$data);
|
|
|
|
+ if(!$status) return [false,$box];
|
|
|
|
+ $box->save();
|
|
|
|
+ list($status,$msg) = $this->boxDetailInsert($data);
|
|
|
|
+ if(!$status) return [false,$msg];
|
|
|
|
+
|
|
|
|
+ return [true,$box];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param $box
|
|
|
|
+ * @param $data
|
|
|
|
+ * @return mixed
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ public function dealBox($box,$data){
|
|
|
|
+
|
|
|
|
+ $box->order_no = $data['order_no'];
|
|
|
|
+ $box->out_order_no = $data['out_order_no'];
|
|
|
|
+ $box->ext_1 = isset($data['ext_1']) ? $data['ext_1'] : '';
|
|
|
|
+ $box->ext_2 = isset($data['ext_2']) ? $data['ext_2'] : '';
|
|
|
|
+ $box->ext_3 = isset($data['ext_3']) ? $data['ext_3'] : '';
|
|
|
|
+ $box->ext_4 = isset($data['ext_4']) ? $data['ext_4'] : '';
|
|
|
|
+ $box->ext_5 = isset($data['ext_5']) ? $data['ext_5'] : '';
|
|
|
|
+
|
|
|
|
+ return [true,$box];
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 包装单详情新增
|
|
|
|
+ * @param $data
|
|
|
|
+ * @return array
|
|
|
|
+ */
|
|
|
|
+ public function boxDetailInsert($data){
|
|
|
|
+ $order_no = $data['order_no'];
|
|
|
|
+ $out_order_no = $data['out_order_no'];
|
|
|
|
+ $box_detail = new BoxDetail(['channel'=>$order_no]);
|
|
|
|
+
|
|
|
|
+ if(!isset($data['detail'])) return [false,'detail is not exist'];
|
|
|
|
+
|
|
|
|
+ $insert = $data['detail'];
|
|
|
|
+
|
|
|
|
+ list($status,$insert) = $this->dealBoxDetail($insert,$order_no,$out_order_no);
|
|
|
|
+ if(!$status) return [false,$insert];
|
|
|
|
+ $box_detail->insert($insert);
|
|
|
|
+ return [true,''];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 包装单详情数据处理
|
|
|
|
+ * @param $data
|
|
|
|
+ * @return array
|
|
|
|
+ */
|
|
|
|
+ public function dealBoxDetail($data,$order_no,$out_order_no){
|
|
|
|
+ $insert = [];
|
|
|
|
+ $time = time();
|
|
|
|
+ foreach ($data as $v){
|
|
|
|
+ if(!isset($v['top_id'])) return [false,'top_id is not exist'];
|
|
|
|
+ if(!isset($v['code'])) return [false,'code is not exist'];
|
|
|
|
+ if(!isset($v['title'])) return [false,'title is not exist'];
|
|
|
|
+
|
|
|
|
+ $insert[] = [
|
|
|
|
+ 'order_no' => $order_no,
|
|
|
|
+ 'out_order_no' => $out_order_no,
|
|
|
|
+ 'top_id' => $v['top_id'],
|
|
|
|
+ 'code' => $v['code'],
|
|
|
|
+ 'title' => $v['title'],
|
|
|
|
+ 'type' => isset($v['type'])?$v['type'] : 1,
|
|
|
|
+ 'crt_time' => $time,
|
|
|
|
+ 'upd_time' => $time,
|
|
|
|
+ 'ext_1' => isset($v['ext_1']) ? $v['ext_1'] : '',
|
|
|
|
+ 'ext_2' => isset($v['ext_2']) ? $v['ext_2'] : '',
|
|
|
|
+ 'ext_3' => isset($v['ext_3']) ? $v['ext_3'] : '',
|
|
|
|
+ 'ext_4' => isset($v['ext_4']) ? $v['ext_4'] : '',
|
|
|
|
+ 'ext_5' => isset($v['ext_5']) ? $v['ext_5'] : '',
|
|
|
|
+
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return [true,$insert];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return string
|
|
|
|
+ */
|
|
|
|
+ public function setOrderNo(){
|
|
|
|
+
|
|
|
|
+ return date('YmdHis').rand(1000,9999);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param $data
|
|
|
|
+ * @return array
|
|
|
|
+ */
|
|
|
|
+ public function boxList($data){
|
|
|
|
+ $box = new Box();
|
|
|
|
+ $list = $this->limit($box,'*',$data);
|
|
|
|
+
|
|
|
|
+ return [true,$list];
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @param $data
|
|
|
|
+ * @return array
|
|
|
|
+ */
|
|
|
|
+ public function boxDetail($data){
|
|
|
|
+ $order_no = $data['order_no'];
|
|
|
|
+
|
|
|
|
+ $box = new BoxDetail(['channel'=>$order_no]);
|
|
|
|
+
|
|
|
|
+ $list = $this->limit($box,'*',$data);
|
|
|
|
+
|
|
|
|
+ return [true,$list];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|