root 2 年之前
父節點
當前提交
d0fc5cbd36
共有 6 個文件被更改,包括 262 次插入43 次删除
  1. 13 5
      app/Http/Controllers/Api/TestController.php
  2. 19 0
      app/Model/Box.php
  3. 69 0
      app/Model/BoxDetail.php
  4. 19 0
      app/Model/Header_ext.php
  5. 141 0
      app/Service/Box/BoxHookService.php
  6. 1 38
      routes/api.php

+ 13 - 5
app/Http/Controllers/Api/TestController.php

@@ -2,17 +2,25 @@
 
 namespace App\Http\Controllers\Api;
 
-use App\Service\TechnologyService;
+
+use App\Model\BoxDetail;
+use App\Service\MeasureService;
 use Illuminate\Http\Request;
-use Illuminate\Support\Facades\DB;
+
 
 class TestController extends BaseController
 {
-    public function test(Request $request)
+    public function aa(Request $request)
     {
-        $list = DB::connection('sqlsrvs')->table('SO_SOMain')->first()->toArray();
-        var_dump($list);die;
+        $model = new BoxDetail(['channel'=>date('YmdHis')]);
+        var_dump($model);
+
     }
 
 
+
+
+
+
+
 }

+ 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';
+
+}

+ 69 - 0
app/Model/BoxDetail.php

@@ -0,0 +1,69 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Schema;
+
+/**
+ *
+ * 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';
+    protected $guarded = [];
+
+    protected $month = [
+        1 => '01_03',
+        2 => '01_03',
+        3 => '01_03',
+        4 => '04_06',
+        5 => '04_06',
+        6 => '04_06',
+        7 => '07_09',
+        8 => '07_09',
+        9 => '07_09',
+        10 => '10_12',
+        11 => '10_12',
+        12 => '10_12',
+    ];
+
+    public function __construct(array $attributes = [])
+    {
+        parent::__construct($attributes);
+        if (isset($attributes['channel']) && $attributes['channel'] > 0) {
+            $channel = $attributes['channel'];
+            $month = (int)substr($channel,4,2);
+            $channel = substr($channel,0,4).$this->month[$month];
+            $this->setTableById($channel);
+        }
+    }
+
+
+    /**
+     * @param $channel
+     */
+    // 动态指定数据表
+    public function setTableById($channel)
+    {
+        if ($channel > 0) {
+            $tb = $this->table.'_' . (string)$channel;
+            $this->createTable($tb);
+            $this->setTable($tb);
+        }
+
+    }
+
+    public function createTable($channel){
+//        $table_name = 'box_detail_' . (string)$channel;
+        if(!Schema::hasTable($channel)){
+            DB::update('create table '.$channel.' like box_detail');
+        }
+    }
+}

+ 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';
+
+}

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

@@ -0,0 +1,141 @@
+<?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){
+        $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 = [];
+        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);
+    }
+
+
+
+}

+ 1 - 38
routes/api.php

@@ -18,7 +18,7 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
 });
 
 Route::any('login', 'Api\LoginController@login');
-Route::any('test', 'Api\TestController@test');
+Route::any('test', 'Api\TestController@aa');
 Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('menuAdd', 'Api\SysMenuController@add');
     $route->any('menuEdit', 'Api\SysMenuController@edit');
@@ -45,7 +45,6 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('teamEdit', 'Api\EmployeeController@teamEdit');
     $route->any('teamDel', 'Api\EmployeeController@teamDel');
     $route->any('teamList', 'Api\EmployeeController@teamList');
-    $route->any('teamDetail', 'Api\EmployeeController@teamDetail');
 
     $route->any('employeeDepart', 'Api\EmployeeController@employeeDepart');
     $route->any('employeeTeam', 'Api\EmployeeController@employeeTeam');
@@ -86,31 +85,6 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('technologyDel', 'Api\TechnologyController@technologyDel');
     $route->any('technologyCopy', 'Api\TechnologyController@technologyCopy');
 
-    //设备档案
-    $route->any('equipmentAdd', 'Api\EquipmentController@equipmentAdd');
-    $route->any('equipmentEdit', 'Api\EquipmentController@equipmentEdit');
-    $route->any('equipmentDel', 'Api\EquipmentController@equipmentDel');
-    $route->any('equipmentList', 'Api\EquipmentController@equipmentList');
-
-    //报废原因
-    $route->any('scrappAdd', 'Api\ScrappController@scrappAdd');
-    $route->any('scrappEdit', 'Api\ScrappController@scrappEdit');
-    $route->any('scrappDel', 'Api\ScrappController@scrappDel');
-    $route->any('scrappList', 'Api\ScrappController@scrappList');
-
-    //福羊羊销售订单
-    $route->any('fyyAdd', 'Api\FyyOrderController@add');
-    $route->any('fyyEdit', 'Api\FyyOrderController@edit');
-    $route->any('fyyDel', 'Api\FyyOrderController@del');
-    $route->any('fyyList', 'Api\FyyOrderController@orderList');
-    $route->any('fyyRefreshOnHandQuantity', 'Api\FyyOrderController@fyyRefreshOnHandQuantity');
-
-    //生产订单
-    $route->any('productionAdd', 'Api\ProductionOrderController@add');
-    $route->any('productionEdit', 'Api\ProductionOrderController@edit');
-    $route->any('productionDel', 'Api\ProductionOrderController@del');
-    $route->any('productionList', 'Api\ProductionOrderController@orderList');
-
     $route->any('productList', 'Api\MaterialController@productList');
     $route->any('productEdit', 'Api\MaterialController@edit');
     $route->any('productAdd', 'Api\MaterialController@edd');
@@ -136,15 +110,4 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('boxTransport', 'Api\OrderTransportController@boxTransport');
     $route->any('transportConfirm', 'Api\OrderTransportController@transportConfirm');
     $route->any('deviceList', 'Api\Device\DeviceController@deviceList');
-    //oa
-    $route->any('oaList', 'Api\OaController@oaList');
-    $route->any('oaDetail', 'Api\OaController@oaDetail');
-    $route->any('oaAdd', 'Api\OaController@oaAdd');
-    $route->any('oaEdit', 'Api\OaController@oaEdit');
-    $route->any('oaDel', 'Api\OaController@oaDel');
-    $route->any('createOaOrder', 'Api\OaController@createOaOrder');
-    $route->any('oaOrderList', 'Api\OaController@oaOrderList');
-    $route->any('oaOrderDetail', 'Api\OaController@oaOrderDetail');
-    $route->any('oaCheck', 'Api\OaController@oaCheck');
-    $route->any('oaSubType', 'Api\OaController@oaSubType');
 });