cqp vor 1 Monat
Ursprung
Commit
0f90440339

+ 0 - 72
app/Http/Controllers/Api/DataSyncToU8Controller.php

@@ -1,72 +0,0 @@
-<?php
-
-namespace App\Http\Controllers\Api;
-
-use App\Service\DataSyncToU8Service;
-use Illuminate\Http\Request;
-
-class DataSyncToU8Controller extends BaseController
-{
-    public function add(Request $request)
-    {
-        $service = new DataSyncToU8Service();
-        $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 snListAccording(Request $request)
-    {
-        $service = new DataSyncToU8Service();
-        $userData = $request->userData->toArray();
-        list($status,$data) = $service->snListAccording($request->all(),$userData);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function getSnFromU8(Request $request)
-    {
-        $service = new DataSyncToU8Service();
-        $userData = $request->userData->toArray();
-        list($status,$data) = $service->getSnFromU8($request->all(),$userData);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function getSnForWarranty(Request $request)
-    {
-        $service = new DataSyncToU8Service();
-        list($status,$data) = $service->getSnForWarranty($request->all());
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function hasWarrantyInfo(Request $request)
-    {
-        $service = new DataSyncToU8Service();
-        list($status,$data) = $service->hasWarrantyInfo($request->all());
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-}

+ 25 - 0
app/Http/Controllers/Api/TPlusController.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Service\TPlusServerService;
+use Illuminate\Http\Request;
+
+class TPlusController extends BaseController
+{
+    public function synPersonDepart(Request $request)
+    {
+        $service = new TPlusServerService();
+        $error = $service->getError();
+        if(! empty($error)) return $this->json_return(201, $error);
+
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->synPersonDepart($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+}

+ 3 - 3
app/Http/Controllers/Api/TestController.php

@@ -21,7 +21,7 @@ use App\Service\OaService;
 use App\Service\OperationLogService;
 use App\Service\OrderNoService;
 use App\Service\SalesOrderService;
-use App\Service\U8ServerService;
+use App\Service\TPlusDatabaseServerService;
 use App\Service\WDTService;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\DB;
@@ -41,14 +41,14 @@ class TestController extends BaseController
     }
 
     public function aa(){echo 'ok';die;
-        $service = new U8ServerService(true);
+        $service = new TPlusDatabaseServerService(true);
         if(! empty($service->error)) return [false, $service->error];
         list($s, $msg) = $service->getSnList(["sn_type"=>1,"code"=>"1000004805"],[]);
         return $this->json_return(200,'',$msg);dd(1111);
         $array = (new SalesOrderService())->salesOrderPdf(['id' => 37938],['id'=>1,'head'=>['id' =>2]]);dd($array);
         dd(2);$this->test3();dd(222);
         (new WDTService())->getOrderListAuto([]);dd(222);
-        $service = new U8ServerService(true);
+        $service = new TPlusDatabaseServerService(true);
         if(! empty($service->error)) return [false, $service->error];
         dd(11111);
         $this->test1();

+ 4 - 4
app/Jobs/ProcessDataJob.php

@@ -5,7 +5,7 @@ namespace App\Jobs;
 use App\Model\ErrorTable;
 use App\Model\U8Job;
 use App\Service\ProductService;
-use App\Service\U8ServerService;
+use App\Service\TPlusDatabaseServerService;
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Foundation\Bus\Dispatchable;
@@ -53,7 +53,7 @@ class ProcessDataJob implements ShouldQueue
 
     //采购
     private function U8PO_PomainSave(){
-        $service = new U8ServerService();
+        $service = new TPlusDatabaseServerService();
         if(! empty($service->error)) {
             $service->finalSettle($this->data['id'], U8Job::one, $service->error);
             return;
@@ -64,7 +64,7 @@ class ProcessDataJob implements ShouldQueue
 
     //销售(合同)
     private function U8SaleOrderSave(){
-        $service = new U8ServerService();
+        $service = new TPlusDatabaseServerService();
         if(! empty($service->error)) {
             $service->finalSettle($this->data['id'], U8Job::two, $service->error);
             return;
@@ -85,7 +85,7 @@ class ProcessDataJob implements ShouldQueue
         $service = new ProductService();
         list($status, $msg) = $service->writeStock($this->data);
 
-        $service = new U8ServerService();
+        $service = new TPlusDatabaseServerService();
         $service->finalSettle(-1, U8Job::three, $msg);
     }
 

+ 0 - 438
app/Service/DataSyncToU8Service.php

@@ -1,438 +0,0 @@
-<?php
-
-namespace App\Service;
-
-use App\Jobs\ProcessDataJob;
-use App\Model\Construction;
-use App\Model\Product;
-use App\Model\ProductCategory;
-use App\Model\ProductSnInfo;
-use App\Model\PurchaseOrder;
-use App\Model\Setting;
-use App\Model\U8Job;
-use App\Model\Warranty;
-
-class DataSyncToU8Service extends Service
-{
-    public function add($data,$user){
-        list($status,$msg) = $this->orderRule($data);
-        if(!$status) return [$status,$msg];
-
-        //操作人
-        $data['user_name'] = $user['emp_name'];
-
-//        dd((new U8ServerService())->U8PO_PomainSave($data['id']));
-        try{
-            $job = ProcessDataJob::dispatch($data)->onQueue($data['job']);
-            if(! $job) return [false,'任务没有进入队列!'];
-        }catch (\Throwable $e){
-            return [false,$e->getMessage()];
-        }
-
-        return [true,''];
-    }
-
-    public function orderRule(&$data){
-        if(empty($data['type'])) return [false,'type不能为空!'];
-        if(! in_array($data['type'],U8Job::$type)) return [false,'type不能存在!'];
-        if(empty($data['id'])) return [false,'同步数据不能为空!'];
-        $data['job'] = U8Job::$job[$data['type']] ?? "";
-        if(empty($data['job'])) return [false,'未找到同步任务!'];
-        if($data['type'] == U8Job::one){
-            //采购同步校验
-            $bool = PurchaseOrder::whereIn('id',$data['id'])
-                ->where('del_time',0)
-                ->where('supplier',0)
-                ->exists();
-            if($bool) return [false,'同步的采购单供应商不能为空!'];
-        }
-
-        return [true, ''];
-    }
-
-    public function snListAccording($data,$user){
-        //特殊的门店
-        $setting = Setting::where('setting_name','bt_top_depart_id')->first();
-        $bt_top_depart_id = $setting['setting_value'] ?? [];
-        $bt_top_depart_id = json_decode($bt_top_depart_id,true);
-
-        //当前门店
-        $current_top_depart_id = $user['depart_top'][0] ?? [];
-        $current_top_depart_id = $current_top_depart_id['depart_id'] ?? 0;
-
-        if(in_array($current_top_depart_id, $bt_top_depart_id)){
-            //总社 直接读取sn码表
-            $sn_type = 1;//总社
-        }else{
-            $sn_type = 2;//分社
-            //发货单 sn码
-        }
-
-        return [true, ['sn_type' => $sn_type]];
-    }
-
-    public function snListAccordingForOrder($data_id){
-        //特殊的门店
-        $setting = Setting::where('setting_name','bt_top_depart_id')->first();
-        $bt_top_depart_id = $setting['setting_value'] ?? [];
-        $bt_top_depart_id = json_decode($bt_top_depart_id,true);
-
-        //当前门店
-        $current_top_depart_id = Construction::where('id', $data_id)->value('top_depart_id');
-
-        if(in_array($current_top_depart_id, $bt_top_depart_id)){
-            //总社 直接读取sn码表
-            $sn_type = 1;//总社
-        }else{
-            $sn_type = 2;//分社
-            //发货单 sn码
-        }
-
-        return $sn_type;
-    }
-
-    public function getSnFromU8($data, $user){
-        if(empty($data['sn_type'])) return [false, 'sn码来源依据不能为空'];
-        if(empty($data['code'])) return [false, '产品编码不能为空'];
-        $data['depart_title'] = $this->getMyTopDepart($user,true);
-
-        $service = new U8ServerService(true);
-        if(! empty($service->error)) return [false, $service->error];
-
-        list($status,$return) = $service->getSnList($data, $user);
-//        list($status,$return) = $this->getSnList($data, $user);
-        return [$status, $return];
-    }
-
-    //todo 废弃一
-    public function getSnList($data, $user){
-        $header = ['Content-Type:application/json'];
-        $construction_id = $data['construction_id'] ?? 0;
-        $post = [
-            'urlFromT9' => 'getSnList',
-            'code' => $data['code'],
-            'sn' => $data['sn'] ?? "",
-            'sn_type' => $data['sn_type'],
-            'depart_title' => $this->getMyTopDepart($user,true),
-            'construction_id' => $construction_id,
-            'page_size' => $data['page_size'] ?? 10,
-            'page_index' => $data['page_index'] ?? 1,
-        ];
-        $post = json_encode($post);
-        list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/getSnList", $post, $header);
-        if(! $status) return [false, "用友数据获取失败"];
-
-        if($msg['code'] != 200) return [false, $msg['msg']];
-
-        return [true, $msg['data'] ?? []];
-    }
-
-    /**
-     * 校验sn码 施工单
-     * @param $data
-     * @param false $is_edit 是否补录
-     * @return array|string
-     */
-    public function checkSnConstructionRule(&$data){
-        //产品字典
-        $map = (new ProductService())->getProductDetail(array_column($data['product'],'product_id'));
-
-        $data_id = $data['id'] ?? 0;
-        $sn_map = [];
-        if($data_id) $sn_map = $this->getSn($data, ProductSnInfo::type_one);
-
-        $code = $sn = [];
-        foreach ($data['product'] as $value){
-            if(empty($value['code'])) return [false, '产品编码不能为空'];
-            $code[] = $value['code'];
-
-            //校验是否有不需要剔除的sn
-            if($data_id){
-                $sn_tmp = $sn_map[$value['code']] ?? [];
-                foreach ($sn_tmp as $val){
-                    if(! empty($val['warranty_id']) && ! in_array($val['sn'], $value['product_sn_info'])) return [false,  "产品编码:" . $value['code'] . "选择的sn码". $val['sn'] . "已生成质保信息,不允许删除"];
-                }
-            }
-
-            //没有sn码信息直接跳过
-            if(empty($value['product_sn_info'])) continue;
-            $tmp = $map[$value['product_id']] ?? [];
-            if(empty($tmp['warranty_time'])) return [false, "产品编码:" . $value['code'] . "质保时长(月)暂未设置"];
-            $bool = $this->forCheck($tmp['product_category']);
-            //非车窗膜需校验sn码
-            if(! $bool){
-                if(count($value['product_sn_info']) > $value['number']) return [false, "产品编码:" . $value['code'] . "选择的sn码数量不能超过产品数量"];
-            }
-
-            foreach ($value['product_sn_info'] as $sn_val){
-                $sn[] = $sn_val;
-            }
-        }
-        if(empty($sn)) return [true, ''];
-        if(empty($data['sn_for_u8'])) return [false, "校验用友数据信息不能为空"];
-        foreach ($data['sn_for_u8'] as $key => $value){
-            if(empty($value['auto_id'])) return [false, 'AutoID不能为空'];
-            if(empty($value['product_id'])) return [false, '产品ID不能为空'];
-            $tmp = $map[$value['product_id']] ?? [];
-            $bool = $this->forCheck($tmp['product_category']);
-            if($bool) unset($data['sn_for_u8'][$key]);
-        }
-
-        //获取在库的sn码信息
-        list($status, $msg) = $this->getSnForMap($code, $sn);
-        if(! $status) return [false, $msg];
-
-        //sn码map
-        $sn_list = $msg;
-        $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_val . "在用友中不存在"];
-            }
-        }
-
-        //校验sn是否被占用
-        list($status, $msg) = $this->snForCheck($code, $sn, $submit_info, $data);
-        if(! $status) return [false, $msg];
-
-        return [true, ''];
-    }
-
-    public function forCheck($product_category){
-        $category = json_decode($product_category,true);
-        if(in_array(ProductCategory::Special_for_sn, $category)) return true;
-        return false;
-    }
-
-    public function forCheck2($product_category){
-        $category = json_decode($product_category,true);
-        $id = ProductCategory::where('parent_id',ProductCategory::Special_for_roll_p)
-            ->where('id','<>',ProductCategory::Special_for_roll3)
-            ->select('id')
-            ->get()->toArray();
-        $id = array_column($id,'id');
-        if(empty($id)) return false;
-        foreach ($id as $value){
-            if(in_array($value, $category)) return [true, ''];
-        }
-
-        return false;
-    }
-
-    //保存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]);
-
-        $sn_type = $this->snListAccordingForOrder($data_id);
-        $update = [];
-        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['sn'],
-                        'auto_id' => $sn_val['auto_id'],
-                        'crt_time' => $time,
-                        'data_id' => $data_id,
-                        'type' => $type,
-                        'sn_type' => $sn_type,
-                    ];
-                    if(! empty($sn_val['for_update'])) $update[] = $sn_val['auto_id'];
-                }
-            }
-
-            if(! empty($update)) $this->updateSnInfo($sn_type, $update,$data_id);
-            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','warranty_id')
-            ->get()->toArray();
-
-        foreach ($sn as $value){
-            $map[$value['code']][] = [
-                'sn' => $value['sn'],
-                'warranty_id' => $value['warranty_id'],
-            ];
-        }
-
-        return $map;
-    }
-
-    //获取在库的sn码信息通过sn码和产品编码
-    public function getSnForMap($code, $sn){
-        $service = new U8ServerService(true);
-        if(! empty($service->error)) return [false, $service->error];
-
-        list($status, $msg) = $service->getSnListFormU8ForMap(['code' => $code, 'sn' => $sn]);
-        return [$status, $msg];
-
-        // todo 废弃二
-        $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(! $status) return [false, "用友数据获取失败"];
-
-        if($msg['code'] != 200) return [false, $msg['msg']];
-
-        return [true, $msg['data'] ?? []];
-    }
-
-    //获取在库的sn码信息通过sn码 客户手动创建质保
-    public function getSnForWarranty($data){
-        if(empty($data['sn'])) return [false, "产品序列码不能为空"];
-        list($status, $msg) = $this->snForWarranty($data);
-        if(! $status) return [false, $msg];
-        $return = $msg;
-
-        $product = Product::where('del_time',0)
-            ->where('code', $return['code'])
-            ->select('id','title','code','warranty_time')
-            ->first();
-        if(empty($product)) return [false, '根据产品序列码查找到的产品编码:' . $return['code'] . '在门店系统中未找到该产品'];
-        $product = $product->toArray();
-        $product['sn'] = $data['sn'];
-        $product['auto_id'] = $return['auto_id'] ?? 0;
-
-        return [true, $product];
-    }
-
-    //更新sn信息
-    public function updateSnInfo($sn_type, $sn_for_u8,$data_id){
-        $service = new U8ServerService(true);
-        if(! empty($service->error)) return [false, $service->error];
-
-        list($status, $msg) = $service->saveSnUseDataDetail($sn_type, $sn_for_u8, $data_id);
-        return [$status, $msg];
-
-        //todo 废弃三
-        $header = ['Content-Type:application/json'];
-        $post = [
-            'urlFromT9' => 'saveSnUseData',
-            'sn_type' => $sn_type,
-            'sn_for_u8' => $sn_for_u8,
-            'data_id' => $data_id,
-        ];
-        $post = json_encode($post);
-        list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/saveSnUseData", $post, $header);
-        if(! $status) return [false, "用友数据获取失败"];
-
-        if($msg['code'] != 200) return [false, $msg['msg']];
-
-        return [true, ''];
-    }
-
-    public function snForWarranty($data){
-        $service = new U8ServerService(true);
-        if(! empty($service->error)) return [false, $service->error];
-
-        list($status, $msg) = $service->getSnForWarrantyData($data);
-        if(! $status) return [false, $msg];
-        if(empty($msg)) return [false, '产品序列码不存在'];
-        return [$status, $msg];
-
-        //todo 废弃四
-        $header = ['Content-Type:application/json'];
-        $post = [
-            'urlFromT9' => 'getSnForWarranty',
-            'sn' => $data['sn'],
-        ];
-        $post = json_encode($post);
-        list($status, $msg) = $this->post_helper("https://workapi.qingyaokeji.com/api/getSnForWarranty", $post, $header);
-        if(! $status) return [false, "用友数据获取失败"];
-        if($msg['code'] != 200) return [false, $msg['msg']];
-        $return = $msg['data'] ?? [];
-        if(empty($return)) return [false, '产品序列码不存在'];
-
-        return [true, $return];
-    }
-
-    public function hasWarrantyInfo($data){
-        if(empty($data['customer_contact'])) return [false, "手机号码不能为空"];
-        $bool = Warranty::where('del_time',0)
-            ->where('customer_contact', $data['customer_contact'])
-            ->exists();
-
-        return [true, ['hasWarrantyInfo' => $bool]];
-    }
-
-    //校验sn是否被占用
-    public function snForCheck($code = [], $sn = [], $submit_info = [], $data = []){
-        $save = ProductSnInfo::where('del_time',0)
-            ->whereIn("code", $code)
-            ->whereIn('sn', $sn)
-            ->select('code','sn','data_id','type','product_id','warranty_id')
-            ->get()->toArray();
-
-        $category_map = Product::whereIn('id',array_unique(array_column($save,'product_id')))
-            ->pluck('product_category','id')
-            ->toArray();
-
-        $data_id = $data['id'] ?? 0;
-        $data_type = $data['data_type'] ?? ProductSnInfo::type_one;
-        foreach ($save as $value){
-            //车窗膜不管sn使用次数
-            $category = $category_map[$value['product_id']] ?? "";
-            $bool = $this->forCheck($category);
-            if($bool) continue;
-
-            $key = $value['code'] . $value['sn'];
-            if(in_array($key, $submit_info)) {
-                if(! $data_id){
-                    return [false, '产品编码:' . $value['code'] . '的sn码已在(' .ProductSnInfo::$type_name[$value['type']]. ')中使用'];
-                }else{
-                    if($value['type'] == ProductSnInfo::type_three){
-                        if($value['warranty_id'] != $data_id || $value['type'] != $data_type) return [false, '产品编码:' . $value['code'] . '的sn码已被' .ProductSnInfo::$type_name[$data_type] . '使用'];
-                    }else{
-                        if($value['data_id'] != $data_id || $value['type'] != $data_type) return [false, '产品编码:' . $value['code'] . '的sn码已被' .ProductSnInfo::$type_name[$data_type] . '使用'];
-                    }
-                }
-            }
-        }
-
-        return [true, ''];
-    }
-
-    public function updateByVinNo($data){
-        if(empty($data['vin_no']) || empty($data['customer_name']) || empty($data['customer_contact'])) return;
-        $vin_no = $data['vin_no'];
-        $customer_name = $data['customer_name'];
-        $customer_contact = $data['customer_contact'];
-
-        Warranty::where('del_time',0)
-            ->where('vin_no',$vin_no)
-            ->update(["customer_name" => $customer_name, 'customer_contact' => $customer_contact]);
-    }
-}

+ 20 - 103
app/Service/EmployeeService.php

@@ -277,22 +277,9 @@ class EmployeeService extends Service
      */
     public function employeeList($data,$user){
         $model = Employee::where('del_time',0)
-            ->select('number','mobile','emp_name','id','entry_time','leave_time','is_admin','state')
+            ->select('number','mobile','emp_name','id','is_admin','state')
             ->orderBy('id','desc');
 
-        if(! empty($data['depart'])) {
-            $depart = Depart::where('del_time',0)
-                ->select('id','parent_id')
-                ->get()->toArray();
-            $result = array_merge($this->getAllDescendants($depart,$data['depart']),[$data['depart']]);
-            $employee_id = DB::table('employee_depart_permission')
-                ->whereIn("depart_id", $result)
-                ->select("employee_id")
-                ->get()->toArray();
-            $employee_id = array_column($employee_id,'employee_id');
-            $model->whereIn("id", $employee_id);
-        }
-
         if(! empty($data['number'])) $model->where('number', 'LIKE', '%'.$data['number'].'%');
         if(! empty($data['emp_name'])) $model->where('emp_name', 'LIKE', '%'.$data['emp_name'].'%');
         if(! empty($data['state'])) $model->where('state',$data['state']);
@@ -339,15 +326,13 @@ class EmployeeService extends Service
             $role2[$value->employee_id][] = $value->id;
         }
 
-        $map = $this->getTopDepartSon();
-
         $res = DB::table('employee_depart_permission as a')
             ->select('a.employee_id','b.title','b.id')
             ->join('depart as b','a.depart_id','=','b.id')
             ->whereIn("a.employee_id",array_column($data['data'],'id'))
             ->orderBy('b.id')
             ->get()->toArray();
-        $depart_title = $depart_id = $man_top_depart = [];
+        $depart_title = $depart_id = [];
         foreach ($res as $value){
             if(isset($depart_title[$value->employee_id])){
                 $depart_title[$value->employee_id] .= ',' . $value->title;
@@ -355,17 +340,6 @@ class EmployeeService extends Service
                 $depart_title[$value->employee_id] = $value->title;
             }
             $depart_id[$value->employee_id][] = $value->id;
-
-            $tmp = $map[$value->id] ?? [];
-            if(empty($tmp)) continue;
-            $key = $tmp['id'] . $tmp['title'];
-            if(! isset($man_top_depart[$value->employee_id][$key])) {
-                $man_top_depart[$value->employee_id][$key] = $map[$value->id];
-            }
-        }
-
-        foreach ($man_top_depart as $key => $value){
-            $man_top_depart[$key] = array_values($value);
         }
 
         foreach ($data['data'] as $key => $value){
@@ -373,34 +347,13 @@ class EmployeeService extends Service
             $data['data'][$key]['role_name'] = $role[$value['id']] ?? '';
             $data['data'][$key]['depart'] = $depart_id[$value['id']] ?? [];
             $data['data'][$key]['depart_title'] = $depart_title[$value['id']] ?? '';
-            $data['data'][$key]['my_top'] = $man_top_depart[$value['id']] ?? [];
+            $data['data'][$key]['state_title'] = $value['state'] == Employee::USE ? "启用" : "停用";
+            $data['data'][$key]['is_admin_title'] = $value['is_admin'] ? "是" : "否";
         }
 
         return $data;
     }
 
-    //门店下所有子集
-    public function getTopDepartSon(){
-        $departList = Depart::where('del_time',0)
-            ->select('id','parent_id','title')
-            ->get()->toArray();
-
-        $map = [];
-        foreach ($departList as $value){
-            if($value['parent_id'] == 0){
-                $result = array_merge($this->getAllDescendants($departList,$value['id']),[$value['id']]);
-                foreach ($result as $val){
-                    $map[$val] = [
-                        'id' => $value['id'],
-                        'title' => $value['title'],
-                    ];
-                }
-            }
-        }
-
-        return $map;
-    }
-
     //获取当前顶级部门下人员id
     public function getEmployee($user){
         $top_depart_id = $user['depart_top'][0] ?? [];
@@ -526,10 +479,21 @@ class EmployeeService extends Service
         if(! empty($data['title'])) $model->where('title', 'LIKE', '%' . $data['title'] . '%');
 
         $list = $this->limit($model,'',$data);
+        $list = $this->fillRoleList($list);
 
         return [true, $list];
     }
 
+    public function fillRoleList($list,$user){
+        if(empty($list)) return $list;
+
+        foreach ($list as $key => $value){
+            $list[$key]['crt_time'] = $value['crt_time'] ? date("Y-m-d",$value['crt_time']) : "";
+        }
+
+        return $list;
+    }
+
     /**
      * 角色参数规则
      * @param $data
@@ -721,7 +685,7 @@ class EmployeeService extends Service
      */
     public function departList($data,$user){
         $model = Depart::where('del_time',0)
-            ->select('title','id','code','parent_id')
+            ->select('title','id','code','parent_id','is_use')
             ->orderby('id', 'asc');
 
         if(isset($data['parent_id'])) $model->where('parent_id', $data['parent_id']);
@@ -742,6 +706,10 @@ class EmployeeService extends Service
     public function fillDepartList($list,$user){
         if(empty($list)) return $list;
 
+        foreach ($list as $key => $value){
+            $list[$key]['is_use_title'] = $value['is_use'] ? "启用" : "停用";
+        }
+
         return $list;
     }
 
@@ -1362,55 +1330,4 @@ class EmployeeService extends Service
             ->get()->toArray();
         return array_column($emp,'id');
     }
-
-    public function departSetDaHuangFengID($data,$user){
-        if(empty($data['top_depart_id'])) return [false, '请选择门店'];
-        if(! isset($data['clueSourceId'])) return [false, 'clueSourceId不存在'];
-
-        $dhf_map = DepartWithDHF::where('del_time',0)
-            ->whereIn('clueSourceId',$data['clueSourceId'])
-            ->pluck('top_depart_id','clueSourceId')->toArray();
-
-        $depart_map = Depart::where('del_time',0)
-            ->whereIn('id',array_values($dhf_map))
-            ->pluck('title','id')->toArray();
-
-        $time = time();
-        $insert = [];
-        $msg = "";
-        foreach ($data['clueSourceId'] as $value){
-            $top_depart_id_tmp = $dhf_map[$value] ?? 0;
-            if(! empty($top_depart_id_tmp) && $top_depart_id_tmp != $data['top_depart_id']){
-                $title = $depart_map[$top_depart_id_tmp] ?? "";
-                $msg .= "大黄蜂clueSourceId($value)已绑定门店($title),";
-            }else{
-                $insert[] = [
-                    'top_depart_id' => $data['top_depart_id'],
-                    'clueSourceId' => $value,
-                    'crt_time' => $time
-                ];
-            }
-        }
-        if(! empty($msg)) return [false, rtrim($msg,',')];
-
-        //删除
-        DepartWithDHF::where('del_time',0)
-            ->where('top_depart_id',$data['top_depart_id'])
-            ->update(['del_time' => $time]);
-
-        //写入
-        if(! empty($insert)) DepartWithDHF::insert($insert);
-
-        return [true, ''];
-    }
-
-    public function getDepartDaHuangFengID($data,$user){
-        if(empty($data['top_depart_id'])) return [false, '门店ID不能为空'];
-
-        $clueSourceId = DepartWithDHF::where('del_time',0)
-            ->where('top_depart_id',$data['top_depart_id'])
-            ->pluck('clueSourceId')->toArray();
-
-        return [true, $clueSourceId];
-    }
 }

+ 2 - 2
app/Service/ProductService.php

@@ -181,7 +181,7 @@ class ProductService extends Service
             $model->title = $data['title'];
             $model->code = $data['code'] ?? '';
             $model->size = $data['size'] ?? '';
-            $model->unit = $data['unit'] ?? 0;
+            $model->unit = $data['unit'] ?? '';
             $model->business_cost = $data['business_cost'] ?? 0;
             $model->cost = $data['cost'] ?? 0;
             $model->write_off_price = $data['write_off_price'] ?? 0;
@@ -218,7 +218,7 @@ class ProductService extends Service
             $model->title = $data['title'];
             $model->code = $data['code'] ?? '';
             $model->size = $data['size'] ?? '';
-            $model->unit = $data['unit'] ?? 0;
+            $model->unit = $data['unit'] ?? '';
             $model->business_cost = $data['business_cost'] ?? 0;
             $model->cost = $data['cost'] ?? 0;
             $model->write_off_price = $data['write_off_price'] ?? 0;

+ 6 - 8
app/Service/U8ServerService.php → app/Service/TPlusDatabaseServerService.php

@@ -6,7 +6,7 @@ use Illuminate\Support\Facades\Config;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Log;
 
-class U8ServerService extends Service
+class TPlusDatabaseServerService extends Service
 {
     public $db = null;
     public $error = null; // 错误信息
@@ -28,10 +28,8 @@ class U8ServerService extends Service
             'username' => env('SQLSRV_USERNAME'),
             'password' => env('SQLSRV_PASSWORD'),
             'options' => [
-//                \PDO::ATTR_TIMEOUT => 30, // 查询超时30秒
                 \PDO::SQLSRV_ATTR_QUERY_TIMEOUT => 30, // SQL Server专用超时
                 \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
-//                \PDO::ATTR_PERSISTENT => false, // 重要:禁用持久连接
             ],
         ];
 
@@ -51,10 +49,10 @@ class U8ServerService extends Service
             $result = $stmt->fetch(\PDO::FETCH_ASSOC);
 
             if (empty($result) || $result['connection_test'] != 1) {
-                $this->error = "数据库连接失败";
+                $this->error = "T+数据库连接失败";
             }
         } catch (\Throwable $e) {
-            $this->error = "数据库连接验证失败: " . $e->getMessage();
+            $this->error = "T+数据库连接验证失败: " . $e->getMessage();
         }
     }
 
@@ -80,9 +78,9 @@ class U8ServerService extends Service
             }
         } catch (\Throwable $e) {
             // 静默处理断开错误
-            Log::info("错误", [
-                'param' => $e->getMessage(),
-            ]);
+//            Log::info("错误", [
+//                'param' => $e->getMessage(),
+//            ]);
         }
     }
 }

+ 150 - 0
app/Service/TPlusServerService.php

@@ -0,0 +1,150 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\Depart;
+use App\Model\Employee;
+use App\Model\EmployeeDepartPermission;
+use Illuminate\Support\Facades\DB;
+
+class TPlusServerService extends Service
+{
+    /**
+     * @var TPlusDatabaseServerService
+     */
+    protected $databaseService;
+
+    /**
+     * @var string|null
+     */
+    protected $error;
+
+    /**
+     * TPlusServerService constructor.
+     */
+    public function __construct()
+    {
+        $service = new TPlusDatabaseServerService();
+        $this->databaseService = $service->db ;
+        $this->error = $service->error;
+    }
+
+    /**
+     * 获取错误信息
+     *
+     * @return string|null
+     */
+    public function getError()
+    {
+        return $this->error;
+    }
+
+    /**
+     * 同步人员部门
+     *
+     * @param array $data
+     * @param array $user
+     * @return array
+     */
+    public function synPersonDepart($data, $user)
+    {
+        try {
+            $this->databaseService->table('AA_Department')
+                ->select('id','idparent as parent_id','name as title','code','disabled as is_use')
+                ->chunkById(100, function ($data) {
+                    DB::transaction(function () use ($data) {
+                        $dataArray = Collect($data)->map(function ($object) {
+                            return (array)$object;
+                        })->toArray();
+
+                        $d_id = Depart::whereIn('id', array_column($dataArray,'id'))
+                            ->pluck('id')
+                            ->toArray();
+
+                        $insert = $update = [];
+                        foreach ($dataArray as $value){
+                            $is_use = $value['is_use'] ? 0 : 1;
+                            if(in_array($value['id'], $d_id)){
+                                $update[] = [
+                                    'id' => $value['id'],
+                                    'parent_id' => $value['parent_id'],
+                                    'title' => $value['title'],
+                                    'code' => $value['code'],
+                                    'is_use' => $is_use
+                                ];
+                            }else{
+                                $insert[] = [
+                                    'id' => $value['id'],
+                                    'parent_id' => $value['parent_id'],
+                                    'title' => $value['title'],
+                                    'code' => $value['code'],
+                                    'is_use' => $is_use
+                                ];
+                            }
+                        }
+                        if(! empty($insert)) Depart::insert($insert);
+                        if(! empty($update)) {
+                            foreach ($update as $value){
+                                Depart::where('id', $value['id'])
+                                    ->update($value);
+                            }
+                        }
+                    });
+                });
+            $this->databaseService->table('AA_Person')
+                ->select('id','code as number','name as emp_name','mobilePhoneNo as mobile','iddepartment as depart_id','disabled as state')
+                ->chunkById(100, function ($data) {
+                    DB::transaction(function () use ($data) {
+                        $dataArray = Collect($data)->map(function ($object) {
+                            return (array)$object;
+                        })->toArray();
+
+                        $employee_id = Employee::whereIn('id', array_column($dataArray,'id'))
+                            ->pluck('id')
+                            ->toArray();
+
+                        $insert = $update = $depart_update = [];
+                        foreach ($dataArray as $value){
+                            $state = $value['state'] ? Employee::NOT_USE : Employee::USE;
+                            if(in_array($value['id'], $employee_id)){
+                                $update[] = [
+                                    'id' => $value['id'],
+                                    'number' => $value['number'],
+                                    'emp_name' => $value['emp_name'],
+                                    'mobile' => $value['mobile'],
+                                    'state' => $state
+                                ];
+                            }else{
+                                $insert[] = [
+                                    'id' => $value['id'],
+                                    'number' => $value['number'],
+                                    'emp_name' => $value['emp_name'],
+                                    'mobile' => $value['mobile'],
+                                    'state' => $state
+                                ];
+                            }
+                            $depart_update[] = [
+                                'employee_id' => $value['id'],
+                                'depart_id' => $value['depart_id']
+                            ];
+                        }
+                        if(! empty($insert)) Employee::insert($insert);
+                        if(! empty($update)) {
+                            foreach ($update as $value){
+                                Employee::where('id', $value['id'])
+                                    ->update($value);
+                            }
+                        }
+                        if(! empty($depart_update)){
+                            EmployeeDepartPermission::whereIn('employee_id',array_column($depart_update,'employee_id'))->delete();
+                            EmployeeDepartPermission::insert($depart_update);
+                        }
+                    });
+                });
+        } catch (\Throwable $e) {
+            return [false, $e->getMessage()];
+        }
+
+        return [true, ''];
+    }
+}

+ 21 - 0
config/header/63.php

@@ -0,0 +1,21 @@
+<?php
+/**
+ * '菜单ID' => [
+ *     '字段英文名' =》 '字段中文名'
+ * ]
+ */
+
+return [
+    [
+        'key' =>'code',
+        'value' => '编号',
+    ],
+    [
+        'key' =>'title',
+        'value' => '部门名称',
+    ],
+    [
+        'key' =>'is_use_title',
+        'value' => '是否启用状态',
+    ],
+];

+ 29 - 0
config/header/64.php

@@ -0,0 +1,29 @@
+<?php
+/**
+ * '菜单ID' => [
+ *     '字段英文名' =》 '字段中文名'
+ * ]
+ */
+
+return [
+    [
+        'key' =>'number',
+        'value' => '工号',
+    ],
+    [
+        'key' =>'emp_name',
+        'value' => '姓名',
+    ],
+    [
+        'key' =>'mobile',
+        'value' => '联系方式',
+    ],
+    [
+        'key' =>'state_title',
+        'value' => '账号启用状态',
+    ],
+    [
+        'key' =>'is_admin_title',
+        'value' => '是否允许登录后台',
+    ],
+];

+ 17 - 0
config/header/65.php

@@ -0,0 +1,17 @@
+<?php
+/**
+ * '菜单ID' => [
+ *     '字段英文名' =》 '字段中文名'
+ * ]
+ */
+
+return [
+    [
+        'key' =>'title',
+        'value' => '角色名称',
+    ],
+    [
+        'key' =>'crt_time',
+        'value' => '创建时间',
+    ],
+];

+ 3 - 5
routes/api.php

@@ -68,9 +68,6 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('departEdit', 'Api\EmployeeController@departEdit');
     $route->any('departDel', 'Api\EmployeeController@departDel');
     $route->any('departList', 'Api\EmployeeController@departList');
-    $route->any('departSetIndex', 'Api\EmployeeController@departSetIndex');
-    $route->any('departSetDaHuangFengID', 'Api\EmployeeController@departSetDaHuangFengID');
-    $route->any('getDepartDaHuangFengID', 'Api\EmployeeController@getDepartDaHuangFengID');
 
     $route->any('roleAdd', 'Api\EmployeeController@roleAdd');
     $route->any('roleEdit', 'Api\EmployeeController@roleEdit');
@@ -85,7 +82,6 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('teamList', 'Api\EmployeeController@teamList');
     $route->any('teamDetail', 'Api\EmployeeController@teamDetail');
 
-    $route->any('getTopMessage', 'Api\EmployeeController@getTopMessage');
     $route->any('employeeDepart', 'Api\EmployeeController@employeeDepart');
     $route->any('employeeTeam', 'Api\EmployeeController@employeeTeam');
     $route->any('employeeRole', 'Api\EmployeeController@employeeRole');
@@ -118,7 +114,9 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('getTableTitleXls','Api\ImportController@getTableTitleXls');
     //导入统一方法
     $route->any('importAll','Api\ImportController@importAll');
-
     //导出统一方法
     $route->any('exportFile', 'Api\ExportFileController@exportFile');
+
+    //同步T+人员部门结构
+    $route->any('synPersonDepart', 'Api\TPlusController@synPersonDepart');
 });