Browse Source

TSpace设置

cqp 4 days ago
parent
commit
192cd00782

+ 48 - 0
app/Http/Controllers/Api/TSpaceController.php

@@ -0,0 +1,48 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Service\TSpaceService;
+use Illuminate\Http\Request;
+
+class TSpaceController extends BaseController
+{
+    public function add(Request $request)
+    {
+        $service = new TSpaceService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->add($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function edit(Request $request)
+    {
+        $service = new TSpaceService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->edit($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function detail(Request $request)
+    {
+        $service = new TSpaceService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->detail($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+}

+ 18 - 0
app/Model/ProductSnInfo.php

@@ -0,0 +1,18 @@
+<?php
+
+namespace App\Model;
+
+class ProductSnInfo extends UseScopeBaseModel
+{
+    protected $table = "product_sn_info"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+    const range_function = '';
+    const type_one = 1;
+    const type_two = 2;
+    public static $type_name = [
+        self::type_one => '施工单',
+        self::type_two => '合同',
+    ];
+}

+ 26 - 0
app/Model/TSpaceSet.php

@@ -0,0 +1,26 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class TSpaceSet extends Model
+{
+    protected $table = "t_space_set"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+
+    const Model_type_one = 1;
+    const Model_type_two = 2;
+    const Model_type_three = 3;
+    const Model_type_four = 4;
+    const Model_type_five = 5;
+    public static $model_type_title = [
+        self::Model_type_one => '顶部位置',
+        self::Model_type_two => '图片位置',
+        self::Model_type_three => '视频位置',
+        self::Model_type_four => '精选二手车',
+        self::Model_type_five => '精选商品',
+    ];
+}

+ 113 - 0
app/Service/DataSyncToU8Service.php

@@ -3,6 +3,7 @@
 namespace App\Service;
 
 use App\Jobs\ProcessDataJob;
+use App\Model\ProductSnInfo;
 use App\Model\PurchaseOrder;
 use App\Model\Setting;
 use App\Model\U8Job;
@@ -90,4 +91,116 @@ class DataSyncToU8Service extends Service
 
         return [true, $msg['data'] ?? []];
     }
+
+    //校验sn码 施工单
+    public function checkSnConstructionRule($data){
+        $code = $sn = [];
+        foreach ($data['product'] as $value){
+            //没有sn码信息直接返回
+            if(empty($value['product_sn_info'])) continue;
+            if(count($value['product_sn_info']) > $value['number']) return [false, "产品编码:" . $value['code'] . "选择的sn码数量不能超过产品数量"];
+            if(empty($value['code'])) return [false, '产品编码不能为空'];
+            $code[] = $value['code'];
+            foreach ($value['product_sn_info'] as $sn_val){
+                $sn[] = $sn_val;
+            }
+        }
+        if(empty($sn)) return [true, ''];
+
+        $header = ['Content-Type:application/json'];
+        $post = [
+            'urlFromT9' => 'getSnMap',
+            'code' => $code,
+            'sn' => $sn,
+        ];
+        $post = json_encode($post);
+        list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/getSnforMap", $post, $header);
+        if($msg['code'] != 200) return [false, $msg['msg']];
+
+        //sn码
+        $sn_list = $msg['data'];
+        $sn_map = [];
+        foreach ($sn_list as $value){
+            $key = $value['code'] . $value['sn'];
+            $sn_map[$key] = "";
+        }
+
+        $submit_info = [];
+        foreach ($data['product'] as $value){
+            if(empty($value['product_sn_info'])) continue;
+            foreach ($value['product_sn_info'] as $sn_val){
+                $key = $value['code'] . $sn_val;
+                $submit_info[] = $key;
+                if(! isset($sn_map[$key])) return [false, "产品编码:" . $value['code'] . "的sn序列码:" . $sn_val . "在用友中不存在"];
+            }
+        }
+
+        $save = ProductSnInfo::where('del_time',0)
+            ->whereIn("code", $code)
+            ->whereIn('sn', $sn)
+            ->select('code','sn','data_id','type')
+            ->get()->toArray();
+
+        $construction_id = $data['id'] ?? 0;
+        foreach ($save as $value){
+            $key = $value['code'] . $value['sn'];
+            if(in_array($key, $submit_info)) {
+                if(! $construction_id){
+                    return [false, '产品编码:' . $value['code'] . '的sn码已被' .ProductSnInfo::$type_name[$value['type']]] . '使用';
+                }else{
+                    if($value['data_id'] != $construction_id || $value['type'] != ProductSnInfo::type_one) return [false, '产品编码:' . $value['code'] . '的sn码已被' .ProductSnInfo::$type_name[$value['type']]] . '使用';
+                }
+            }
+        }
+
+        return [true, ''];
+    }
+
+    //保存sn
+    public function saveSn($data, $type, $time){
+        $data_id = $data['id'] ?? 0;
+
+        ProductSnInfo::where('del_time',0)
+            ->where('data_id', $data_id)
+            ->where('type', $type)
+            ->update(['del_time' => $time]);
+
+        if(! empty($data['product'])){
+            $insert = [];
+            foreach ($data['product'] as $value){
+                //没有sn码信息直接返回
+                if(empty($value['product_sn_info'])) continue;
+                foreach ($value['product_sn_info'] as $sn_val){
+                    $insert[] = [
+                        'product_id' => $value['product_id'],
+                        'code' => $value['code'],
+                        'sn' => $sn_val,
+                        'crt_time' => $time,
+                        'data_id' => $data_id,
+                        'type' => $type,
+                    ];
+                }
+            }
+
+            if(! empty($insert)) ProductSnInfo::insert($insert);
+        }
+    }
+
+    //获取sn详情
+    public function getSn($data, $type){
+        $data_id = $data['id'] ?? 0;
+
+        $map = [];
+        $sn = ProductSnInfo::where('del_time',0)
+            ->where('data_id', $data_id)
+            ->where('type', $type)
+            ->select('product_id','code','sn')
+            ->get()->toArray();
+
+        foreach ($sn as $value){
+            $map[$value['code']][] = $value['sn'];
+        }
+
+        return $map;
+    }
 }

+ 101 - 0
app/Service/TSpaceService.php

@@ -0,0 +1,101 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\TSpaceSet;
+use Illuminate\Support\Facades\DB;
+
+class TSpaceService extends Service
+{
+    public function add($data, $user){
+        return [true, ''];
+    }
+
+    public function edit($data, $user){
+        list($status, $msg) = $this->constructionEditOtherRule($data, $user);
+        if(! $status) return [false, $msg];
+
+        DB::beginTransaction();
+        try{
+            $set = TSpaceSet::where('del_time',0)
+                ->where('type', $data['type'])
+                ->select('file', 'id')
+                ->get()->toArray();
+            $set_map = array_column($set,'file','id');
+
+            $time = time();
+            $insert = $update = $new = $old = $id = [];
+            foreach ($data['data'] as $value){
+                $text = "";
+                if(! empty($value['text'])) $text = json_encode($data['text']);
+                if(! empty($value['id'])){
+                    $file = $set_map[$value['id']] ?? "";
+                    if($value['file'] != $file){
+                        $old[] = $file;
+                    }else{
+                        $new[] = $value['file'];
+                    }
+                    $update[] = [
+                        'id' => $value['id'],
+                        'type' => $data['type'],
+                        'text' => $text,
+                        'file' => $value['file'],
+                        'crt_time' => $time,
+                    ];
+                    $id[] = $value['id'];
+                }else{
+                    $new[] = $value['file'];
+
+                    $insert[] = [
+                        'type' => $data['type'],
+                        'text' => $text,
+                        'file' => $value['file'],
+                        'crt_time' => $time,
+                    ];
+                }
+            }
+            foreach ($set as $value){
+                if(! in_array($value['id'], $id)){
+                    $update[] = [
+                        'id' => $value['id'],
+                        'del_time' => $time,
+                    ];
+                    $old[] = $value['file'];
+                }
+            }
+
+            if(! empty($update)){
+                foreach ($update as $value){
+                    TSpaceSet::where('id',$value['id'])
+                        ->update($value);
+                }
+            }
+            if(! empty($insert)) TSpaceSet::insert($insert);
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false, $exception->getMessage()];
+        }
+
+        return [true, ['file' => ['new' => $new, 'old' => $old]]];
+    }
+
+    public function constructionEditOtherRule($data,$user){
+        if(empty($data['type'])) return [false,'TSpace首页设置类型不能为空'];
+        if(! isset(TSpaceSet::$model_type_title[$data['type']])) return [false,'TSpace首页设置类型错误'];
+        if(empty($data['data'])) return [false, '设置内容不能为空'];
+        foreach ($data['data'] as $value){
+            if(empty($value['file'])) return [false, '文件不能为空'];
+        }
+
+        return [true, ''];
+    }
+
+    public function detail($data, $user){
+        if(empty($data['table_head'])) return [false,'自定义表头不能为空'];
+        if(empty($data['menu_id'])) return [false, 'menu_id不能为空'];
+
+        return [true,''];
+    }
+}

+ 4 - 0
routes/api.php

@@ -371,6 +371,10 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('snListAccording','Api\DataSyncToU8Controller@snListAccording');
     $route->any('getSnFromU8','Api\DataSyncToU8Controller@getSnFromU8');
 
+    //TSpace首页设置
+    $route->any('tSpaceEdit', 'Api\TSpaceController@edit')->middleware('OssFileDeal');
+    $route->any('tSpaceDetail', 'Api\TSpaceController@detail');
+
     //获取下载模板
     $route->any('getTableTitleXls','Api\ImportController@getTableTitleXls');
     //导入