root 1 year ago
parent
commit
e51358c670
4 changed files with 197 additions and 0 deletions
  1. 19 0
      app/Model/Box.php
  2. 19 0
      app/Model/BoxDetail.php
  3. 19 0
      app/Model/Header_ext.php
  4. 140 0
      app/Service/Box/BoxHookService.php

+ 19 - 0
app/Model/Box.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ *
+ * Class Unit
+ * @package App\Models
+ */
+class Box extends Model
+{
+    protected $table = "box"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+
+}

+ 19 - 0
app/Model/BoxDetail.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ *
+ * Class Unit
+ * @package App\Models
+ */
+class BoxDetail extends Model
+{
+    protected $table = "box_detail"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+
+}

+ 19 - 0
app/Model/Header_ext.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ *
+ * Class Unit
+ * @package App\Models
+ */
+class Header_ext extends Model
+{
+    protected $table = "header_ext"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+
+}

+ 140 - 0
app/Service/Box/BoxHookService.php

@@ -0,0 +1,140 @@
+<?php
+
+namespace App\Service\Box;
+
+
+
+use App\Model\Box;
+use App\Model\BoxDetail;
+use App\Model\Header_ext;
+use App\Service\Service;
+
+/**
+ * 包装相关工厂模式
+ * @package App\Models
+ */
+class BoxHookService extends Service
+{
+
+    protected static $instance;
+    protected static $box_header;
+    protected static $box_detail_header;
+
+    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();
+
+    }
+
+    public static function getInstance(): self
+    {
+        if (self::$instance == null) {
+            self::$instance = new BoxHookService();
+        }
+        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,$box) =  $this->boxDetailInsert($data);
+        if(!$status) return [false,$box];
+
+        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){
+        $box_detail = new BoxDetail();
+
+        if(!isset($data['detail'])) return [false,'detail is not exist'];
+
+        $insert = $data['detail'];
+        $order_no = $data['order_no'];
+        $out_order_no = $data['out_order_no'];
+        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 = [];
+        foreach ($data as $v){
+            if(!isset($data['top_id'])) return [false,'top_id is not exist'];
+            if(!isset($data['code'])) return [false,'code is not exist'];
+            if(!isset($data['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'],
+                'ext_1' => isset($data['ext_1']) ? $data['ext_1'] : '',
+                'ext_2' => isset($data['ext_2']) ? $data['ext_2'] : '',
+                'ext_3' => isset($data['ext_3']) ? $data['ext_3'] : '',
+                'ext_4' => isset($data['ext_4']) ? $data['ext_4'] : '',
+                'ext_5' => isset($data['ext_5']) ? $data['ext_5'] : '',
+
+            ];
+        }
+
+
+        return [true,$insert];
+    }
+
+
+    /**
+     * @return string
+     */
+    public function setOrderNo(){
+
+        return date('YmdHis').rand(1000,9999);
+    }
+
+
+
+}