cqp 8 月之前
父节点
当前提交
83adc4f2d2

+ 76 - 0
app/Http/Controllers/Api/CustomerSupplyController.php

@@ -0,0 +1,76 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Service\CustomerSupplyService;
+use Illuminate\Http\Request;
+
+class CustomerSupplyController extends BaseController
+{
+    public function customerSupplyEdit(Request $request)
+    {
+        $service = new CustomerSupplyService();
+        $user = $request->userData;
+        list($status,$data) = $service->customerSupplyEdit($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function customerSupplyAdd(Request $request)
+    {
+        $service = new CustomerSupplyService();
+        $user = $request->userData;
+        list($status,$data) = $service->customerSupplyAdd($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+
+    }
+
+    public function customerSupplyDel(Request $request)
+    {
+        $service = new CustomerSupplyService();
+        $user = $request->userData;
+        list($status,$data) = $service->customerSupplyDel($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+
+    }
+
+    public function customerSupplyList(Request $request)
+    {
+        $service = new CustomerSupplyService();
+        $user = $request->userData;
+        list($status,$data) = $service->customerSupplyList($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function customerSupplyDetail(Request $request)
+    {
+        $service = new CustomerSupplyService();
+        $user = $request->userData;
+        list($status,$data) = $service->customerSupplyDetail($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+}

+ 76 - 0
app/Http/Controllers/Api/QuantizationController.php

@@ -0,0 +1,76 @@
+<?php
+
+namespace App\Http\Controllers\Api;
+
+use App\Service\QuantizationService;
+use Illuminate\Http\Request;
+
+class QuantizationController extends BaseController
+{
+    public function quantizationEdit(Request $request)
+    {
+        $service = new QuantizationService();
+        $user = $request->userData;
+        list($status,$data) = $service->quantizationEdit($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function quantizationAdd(Request $request)
+    {
+        $service = new QuantizationService();
+        $user = $request->userData;
+        list($status,$data) = $service->quantizationAdd($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+
+    }
+
+    public function quantizationDel(Request $request)
+    {
+        $service = new QuantizationService();
+        $user = $request->userData;
+        list($status,$data) = $service->quantizationDel($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+
+    }
+
+    public function quantizationList(Request $request)
+    {
+        $service = new QuantizationService();
+        $user = $request->userData;
+        list($status,$data) = $service->quantizationList($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
+    public function quantizationDetail(Request $request)
+    {
+        $service = new QuantizationService();
+        $user = $request->userData;
+        list($status,$data) = $service->quantizationDetail($request->all(),$user);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+}

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

@@ -1,73 +0,0 @@
-<?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;
-        list($status,$data) = $service->synPersonDepart($request->all(),$userData);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function synRevenueCost(Request $request)
-    {
-        $service = new TPlusServerService();
-        $error = $service->getError();
-        if(! empty($error)) return $this->json_return(201, $error);
-
-        $userData = $request->userData;
-        list($status,$data) = $service->synRevenueCost($request->all(),$userData);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function synSalaryEmployee(Request $request)
-    {
-        $service = new TPlusServerService();
-        $error = $service->getError();
-        if(! empty($error)) return $this->json_return(201, $error);
-
-        $userData = $request->userData;
-        list($status,$data) = $service->synSalaryEmployee($request->all(),$userData);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function synFreightFee(Request $request)
-    {
-        $service = new TPlusServerService();
-        $error = $service->getError();
-        if(! empty($error)) return $this->json_return(201, $error);
-
-        $userData = $request->userData;
-        list($status,$data) = $service->synFreightFee($request->all(),$userData);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-}

+ 37 - 0
app/Model/CustomerSupply.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace App\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+class CustomerSupply extends Model
+{
+    protected $guarded = [];
+    protected $table = "customer_supply"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    const employee_column = "crt_id";
+
+    protected $dateFormat = 'U';
+    const status_one = 1;
+    const status_two = 2;
+    const status_three = 3;
+    const status_four = 4;
+    const status_five = 5;
+
+    public static $status_name = [
+        self::status_one => '拿下',
+        self::status_two => '接洽',
+        self::status_three => '风险',
+        self::status_four => '核心',
+        self::status_five => '放弃',
+    ];
+
+    const type_one = 1;
+    const type_two = 2;
+
+    public static $type_name = [
+        self::type_one => '客户',
+        self::type_two => '供应商',
+    ];
+}

+ 2 - 2
app/Model/RevenueCostMain.php → app/Model/CustomerSupplyDetails.php

@@ -4,10 +4,10 @@ namespace App\Model;
 
 use Illuminate\Database\Eloquent\Model;
 
-class RevenueCostMain extends Model
+class CustomerSupplyDetails extends Model
 {
     protected $guarded = [];
-    protected $table = "revenue_cost_main"; //指定表
+    protected $table = "customer_supply_details"; //指定表
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';

+ 0 - 19
app/Model/EmployeeFoursShop.php

@@ -1,19 +0,0 @@
-<?php
-
-namespace App\Model;
-
-use Illuminate\Database\Eloquent\Model;
-
-/**
- * 人员绑定的四s店
- * Class Unit
- * @package App\Models
- */
-class EmployeeFoursShop extends Model
-{
-    protected $table = "employee_fours_shop"; //指定表
-    const CREATED_AT = null;
-    const UPDATED_AT = null;
-    protected $dateFormat = 'U';
-
-}

+ 0 - 63
app/Model/EmployeeIndex.php

@@ -1,63 +0,0 @@
-<?php
-
-namespace App\Model;
-
-class EmployeeIndex extends UseScopeBaseModel
-{
-    protected $guarded = [];
-    protected $table = "employee_index"; //指定表
-    const CREATED_AT = 'crt_time';
-    const UPDATED_AT = 'upd_time';
-    const employee_column = 'employee_id';
-    protected $dateFormat = 'U';
-
-    //指标类型
-    const TYPE_ONE = 1;
-    const TYPE_TWO = 2;
-    const TYPE_THREE = 3;
-    const TYPE_FOUR = 4;
-    const TYPE_FIVE = 5;
-    const TYPE_SIX = 6;
-    const TYPE_SEVEN = 7;
-    const TYPE_EIGHT = 8;
-    const TYPE_NINE = 9;
-    const TYPE_TEN = 10;
-    const TYPE_EVE = 11;
-    const TYPE_TWL = 12;
-
-    public static $type_name = [
-        Self::TYPE_ONE => '预支分红比例',
-        Self::TYPE_TWO => '月度指标金额',
-        Self::TYPE_THREE => '季度指标金额',
-        Self::TYPE_FOUR => '指标比例',
-        Self::TYPE_FIVE => '分红比例',
-        Self::TYPE_SIX => '基本工资',
-        Self::TYPE_SEVEN => '退损比例',
-        Self::TYPE_EIGHT => '销售奖金',
-        Self::TYPE_NINE => '其他补贴1',
-        Self::TYPE_TEN => '其他补贴2',
-        Self::TYPE_EVE => '其他补贴3',
-        Self::TYPE_TWL => '销售工资',
-    ];
-
-    public static $positive = [
-        Self::TYPE_ONE => '预支分红比例',
-        Self::TYPE_TWO => '月度指标金额',
-        Self::TYPE_THREE => '季度指标金额',
-        Self::TYPE_FOUR => '指标比例',
-        Self::TYPE_FIVE => '分红比例',
-        Self::TYPE_SIX => '基本工资',
-        Self::TYPE_SEVEN => '退损比例',
-        Self::TYPE_EIGHT => '销售奖金',
-    ];
-
-    public static $positive_2 = [
-        Self::TYPE_TWL => '销售工资',
-    ];
-
-    public static $null = [
-        Self::TYPE_NINE => '其他补贴1',
-        Self::TYPE_TEN => '其他补贴2',
-        Self::TYPE_EVE => '其他补贴3',
-    ];
-}

+ 0 - 28
app/Model/FreightFee.php

@@ -1,28 +0,0 @@
-<?php
-
-namespace App\Model;
-
-class FreightFee extends UseScopeBaseModel
-{
-    protected $table = "freight_fee"; //指定表
-    const CREATED_AT = 'crt_time';
-    const UPDATED_AT = 'upd_time';
-    protected $dateFormat = 'U';
-
-    const businessTypeNormal = 65;
-    const businessTypeReturn = 66;
-    const deliveryModeNormal = 70519;
-    const deliveryModeRightNow = 70536;
-    public static $delivery = [
-        self::deliveryModeNormal => '纯自提',
-        self::deliveryModeRightNow => '当日达',
-    ];
-    public static $business = [
-        self::businessTypeNormal => '普通销售',
-        self::businessTypeReturn => '销售退货',
-    ];
-
-    const employee_column = 'employee_id_1';
-
-    public static $field = ['order_time','id'];
-}

+ 14 - 1
app/Model/Organization.php

@@ -8,6 +8,19 @@ class Organization extends UseScopeBaseModel
     const CREATED_AT = 'crt_time';
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
+    const employee_column = "crt_id";
+
+    public static $field = ['title','id','code','industry_name','industry_ranking','address','crt_id','crt_time','founding_time','type','decision_depart','decision_maker','new_product_rule','old_product_rule'];
+
+    const type_one = 1;
+    const type_two = 2;
+    const type_three = 3;
+    const type_four = 4;
+    public static $type_name = [
+        self::type_one => '国企',
+        self::type_two => '央企',
+        self::type_three => '私企',
+        self::type_four => '外企',
+    ];
 
-    public static $field = ['area','id','region','kilometer','min_freight_fee','one_and_five','crt_id','crt_time'];
 }

+ 28 - 0
app/Model/OrganizationDetails.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace App\Model;
+
+class OrganizationDetails extends UseScopeBaseModel
+{
+    protected $table = "organization_details"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+
+    const type_one = 1;
+    const type_two = 2;
+    const type_three = 3;
+    const type_four = 4;
+    const type_five = 5;
+    const type_six = 6;
+    const type_seven = 7;
+    public static $type_name = [
+        self::type_one => '上级单位',
+        self::type_two => '下级单位',
+        self::type_three => '营收信息',
+        self::type_four => '主营业务',
+        self::type_five => '主要需求',
+        self::type_six => '竟对主要需求',
+        self::type_seven => '客户主要需求',
+    ];
+}

+ 20 - 0
app/Model/Quantization.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace App\Model;
+
+class Quantization extends UseScopeBaseModel
+{
+    protected $table = "quantization"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+
+    public static $field = ['title','id','code','crt_time','is_use','crt_id'];
+
+    const is_use_zero = 0;
+    const is_use_one = 1;
+    public static $is_use_name = [
+        self::is_use_zero => '停用',
+        self::is_use_one => '启用',
+    ];
+}

+ 11 - 0
app/Model/QuantizationDetails.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace App\Model;
+
+class QuantizationDetails extends UseScopeBaseModel
+{
+    protected $table = "quantization_details"; //指定表
+    const CREATED_AT = 'crt_time';
+    const UPDATED_AT = 'upd_time';
+    protected $dateFormat = 'U';
+}

+ 0 - 45
app/Model/RevenueCost.php

@@ -1,45 +0,0 @@
-<?php
-
-namespace App\Model;
-
-class RevenueCost extends UseScopeBaseModel
-{
-    protected $guarded = [];
-    protected $table = "revenue_cost"; //指定表
-    const CREATED_AT = 'crt_time';
-    const UPDATED_AT = 'upd_time';
-    const employee_column = 'employee_id_1';
-    protected $dateFormat = 'U';
-
-    const ORDER_ONE = 1;
-    const ORDER_TWO = 2;
-    const ORDER_THREE = 3;
-
-    public static $order_type = [
-        self::ORDER_ONE => '销货单',
-        self::ORDER_TWO => '销售发票',
-        self::ORDER_THREE => '回款单'
-    ];
-
-    const job = 'yf_revenue_cost';
-    const job2 = 'salary_employee';
-    const job3 = 'freight_fee';
-
-    public static $field = ['id','order_time','order_type','price_1','price_1_total','price_2','price_2_total','price_3','price_3_total','price_4','price_4_total','payment_amount','profit','profit_rate','employee_id_1','employee_id_1_title'];
-    public static $field_xhd = ['id','order_type','order_number','order_time','employee_id_1','employee_id_1_title','employee_id_2','employee_id_2_title','customer_code','customer_title','channel_finance','channel_details','product_code','product_title','product_size','unit','price_1','price_1_total','price_2','price_2_total','quantity','price_3','price_3_total','price_4','price_4_total','profit','profit_rate'];
-    public static $field_xsfp = ['id','order_type','order_number','order_time','employee_id_1','employee_id_1_title','employee_id_2','employee_id_2_title','customer_code','customer_title','product_code','product_title','product_size','unit','price_1','price_1_total','price_2','price_2_total','quantity','price_4','price_4_total','profit','profit_rate'];
-    public static $field_hkd_main = ['order_id as id','order_type','order_number','order_time','employee_id_1','employee_id_1_title','employee_id_2','employee_id_2_title','payment_amount','profit','order_id'];
-    public static $field_hkd_detail = ['order_type','order_number','order_time','employee_id_1','employee_id_1_title','employee_id_2','employee_id_2_title','customer_code','customer_title','product_code','product_title','product_size','unit','price_1','price_1_total','price_2','price_2_total','quantity','price_3','price_3_total','price_4','price_4_total','profit','profit_rate','order_number_upstream','payment_amount','customer_profit_rate','voucher_type','channel_finance'];
-    public static $field_hkd_profit_main = ['rc.employee_id_2','rc.employee_id_2_title','rc.payment_amount','employee_index.start_time','employee_index.end_time','employee_index.index','employee_index.id'];
-    public static $field_hkd_salary_main = ['order_id as id','order_type','order_number','order_time','employee_id_1','employee_id_1_title','payment_amount','profit','order_id','channel_finance'];
-
-    public static $voucher_type = [
-         45 => "期初应收",
-         24 => "期初其他应收",
-         131 => "期初收入单",
-         112 => "费用单",
-         113 => "收入单",
-         129 => "其他应收单",
-         20 => "销售发票",
-    ];
-}

+ 0 - 16
app/Model/RevenueCostTotal.php

@@ -1,16 +0,0 @@
-<?php
-
-namespace App\Model;
-
-class RevenueCostTotal extends UseScopeBaseModel
-{
-    protected $guarded = [];
-    protected $table = "revenue_cost_total"; //指定表
-    const CREATED_AT = 'crt_time';
-    const UPDATED_AT = 'upd_time';
-    const employee_column = 'employee_id_1';
-    protected $dateFormat = 'U';
-
-    public static $field = ['id','order_type','profit','profit_rate','order_time','income','adjust','business','employee_id_1','employee_id_1_title'];
-
-}

+ 0 - 15
app/Model/SalaryEmployee.php

@@ -1,15 +0,0 @@
-<?php
-
-namespace App\Model;
-
-class SalaryEmployee extends UseScopeBaseModel
-{
-    protected $guarded = [];
-    protected $table = "salary_employee"; //指定表
-    const CREATED_AT = 'crt_time';
-    const UPDATED_AT = 'upd_time';
-    const employee_column = 'employee_id_1';
-    protected $dateFormat = 'U';
-
-    public static $field = ['id','order_time','order_type','payment_amount','payment_amount_not_include_activity','payment_amount_activity','payment_amount_lower_than_rate','payment_amount_greater_than_rate','business','sale_bonus','index_1','pay_in_advance','basic_salary','should_pay','employee_id_1','employee_id_1_title'];
-}

+ 0 - 38
app/Model/U8Job.php

@@ -1,38 +0,0 @@
-<?php
-
-namespace App\Model;
-
-use Illuminate\Database\Eloquent\Model;
-
-
-class U8Job extends Model
-{
-    protected $table = "u8_job"; //指定表
-    const CREATED_AT = 'crt_time';
-    const UPDATED_AT = 'upd_time';
-    protected $dateFormat = 'U';
-
-    const success = 1;
-    const failed = 2;
-
-    const one = 1;
-    const two = 2;
-    const three = 3;
-    public static $type = [
-        self::one,
-        self::two,
-    ];
-    public static $type_title = [
-        self::one => '采购单同步',
-        self::two => '销售订单(合同同步)',
-    ];
-
-    const job1 = 't9u8_purchase';
-    const job2 = 't9u8_sales';
-    const job3 = 't9u8_stock';
-    public static $job = [
-        self::one => self::job1,
-        self::two => self::job2,
-        self::three => self::job3,
-    ];
-}

+ 1 - 43
app/Model/UseScopeBaseModel.php

@@ -14,49 +14,6 @@ class UseScopeBaseModel extends Model
         parent::__construct($attributes);
     }
 
-    //顶级部门过滤
-    public function scopeTopClear($query, $user, $search)
-    {
-        //是否所有部门
-        $is_all_depart = $user['is_all_depart'] ?? 0;
-        //权限范围内的部门
-        $depart_range = $user['depart_range'] ?? [];
-
-        //顶级部门
-        $search_depart_id = $search['top_depart_id'] ?? 0;
-        if(empty($search_depart_id)){
-            //默认进来 自身顶级公司
-            $top_depart_id = $user['depart_top'][0] ?? [];
-            $top_depart_id = $top_depart_id['depart_id'] ?? 0;
-        }else{
-            //查询 顶级公司
-            $top_depart_id = $search_depart_id;
-        }
-
-        if($is_all_depart){
-            //所有部门
-            if(empty($search_depart_id)){
-                //全部
-                $query->whereIn('top_depart_id', $depart_range);
-            }else{
-                //查看某个分社
-                $query->where('top_depart_id', $top_depart_id);
-            }
-        }else{
-            //某个分社全部
-            $query->where('top_depart_id', $top_depart_id);
-        }
-
-        //获取当前门店下
-        if(! empty($search['get_my_top_depart_data'])){
-            $depart = ! empty($user['depart_top'][0]) ? $user['depart_top'][0]: [];
-            $depart_id = $depart['depart_id'] ?? 0;
-            $query->where('top_depart_id', $depart_id);
-        }
-
-        return $query;
-    }
-
     public function scopeClear($query, $user, $search)
     {
         //权限范围内的部门
@@ -76,6 +33,7 @@ class UseScopeBaseModel extends Model
 
     //最高权限
     private function makeModel(&$query, $auth_type, $user, $depart_range, $column){
+        $auth_type = 2;$depart_range= [2];
         if(empty($column)) return;
 
         if($auth_type == Employee::AUTH_ONE){

+ 277 - 0
app/Service/CustomerSupplyService.php

@@ -0,0 +1,277 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\Employee;
+use App\Model\CustomerSupply;
+use App\Model\CustomerSupplyDetails;
+use App\Model\Organization;
+use Illuminate\Support\Facades\DB;
+
+class CustomerSupplyService extends Service
+{
+    public function customerSupplyEdit($data,$user){
+        list($status,$msg) = $this->customerSupplyRule($data, $user, false);
+        if(!$status) return [$status,$msg];
+
+        try {
+            DB::beginTransaction();
+
+            $model = CustomerSupply::where('id',$data['id'])->first();
+            $model->code = $data['code'] ?? '';
+            $model->title = $data['title'] ?? '';
+            $model->type = $data['type'] ?? 0;
+            $model->status = $data['status'] ?? 0;
+            $model->address = $data['address'] ?? "";
+            $model->year = $data['year'] ?? 0;
+            $model->first_scene = $data['first_scene'] ?? "";
+            $model->business = $data['business'] ?? "";
+            $model->connect_man = $data['connect_man'] ?? "";
+            $model->gender = $data['gender'] ?? "";
+            $model->interest = $data['interest'] ?? "";
+            $model->family = $data['family'] ?? "";
+            $model->ability = $data['ability'] ?? "";
+            $model->profession = $data['profession'] ?? "";
+            $model->mobile = $data['mobile'] ?? "";
+            $model->open = $data['open'] ?? "";
+            $model->attitude = $data['attitude'] ?? "";
+            $model->style = $data['style'] ?? "";
+            $model->save();
+
+            $time = time();
+            CustomerSupplyDetails::where('del_time',0)
+                ->where('customer_supply_id', $model->id)
+                ->update(['del_time' => $time]);
+            $this->saveDetail($model->id, $time, $data);
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
+    public function customerSupplyAdd($data,$user){
+        list($status,$msg) = $this->customerSupplyRule($data, $user);
+        if(!$status) return [$status,$msg];
+
+        try {
+            DB::beginTransaction();
+
+            $model = new CustomerSupply();
+            $model->code = $data['code'] ?? '';
+            $model->title = $data['title'] ?? '';
+            $model->type = $data['type'] ?? 0;
+            $model->status = $data['status'] ?? 0;
+            $model->address = $data['address'] ?? "";
+            $model->year = $data['year'] ?? 0;
+            $model->first_scene = $data['first_scene'] ?? "";
+            $model->business = $data['business'] ?? "";
+            $model->connect_man = $data['connect_man'] ?? "";
+            $model->gender = $data['gender'] ?? "";
+            $model->interest = $data['interest'] ?? "";
+            $model->family = $data['family'] ?? "";
+            $model->ability = $data['ability'] ?? "";
+            $model->profession = $data['profession'] ?? "";
+            $model->mobile = $data['mobile'] ?? "";
+            $model->open = $data['open'] ?? "";
+            $model->attitude = $data['attitude'] ?? "";
+            $model->style = $data['style'] ?? "";
+            $model->crt_id = $user['id'];
+            $model->save();
+
+            $account = str_pad($model->id, 10, '0', STR_PAD_LEFT);
+            CustomerSupply::where('id', $model->id)
+                ->update(['account'=> $account]);
+
+            $this->saveDetail($model->id, time(), $data);
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
+    private function saveDetail($id, $time, $data){
+        if(! empty($data['organization'])){
+            $unit = [];
+            foreach ($data['organization'] as $value){
+                $unit[] = [
+                    'customer_supply_id' => $id,
+                    'organization_id' => $value['organization_id'],
+                    'position' => $value['position'],
+                    'background' => $value['background'],
+                    'leader' => $value['leader'],
+                    'fg_leader' => $value['fg_leader'],
+                    'relationship' => $value['relationship'],
+                    'point_demand' => $value['point_demand'],
+                    'values' => $value['values'],
+                    'crt_time' => $time,
+                ];
+            }
+            if(! empty($unit)) CustomerSupplyDetails::insert($unit);
+        }
+    }
+
+    private function getDetail($id){
+        $data = CustomerSupplyDetails::where('del_time',0)
+            ->where('customer_supply_id', $id)
+            ->get()->toArray();
+
+        $map = Organization::whereIn('id', array_column($data['organization_id']))
+            ->pluck('title','id')
+            ->toArray();
+        $unit = [];
+        foreach ($data as $value){
+            $title = $map[$value['organization_id']] ?? "";
+            $unit[] = [
+                'organization_id' => $value['organization_id'],
+                'organization_title' => $title,
+                'position' => $value['position'],
+                'background' => $value['background'],
+                'leader' => $value['leader'],
+                'fg_leader' => $value['fg_leader'],
+                'relationship' => $value['relationship'],
+                'point_demand' => $value['point_demand'],
+                'values' => $value['values'],
+            ];
+        }
+
+        $detail = [
+            'organization' => $unit,
+        ];
+
+        foreach ($detail as $key => $value) {
+            if (empty($value)) {
+                $detail[$key] = (object)[]; // 转成 stdClass 对象
+            }
+        }
+
+        return $detail;
+    }
+
+    public function customerSupplyDel($data){
+        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
+
+        try {
+            DB::beginTransaction();
+            $time = time();
+
+            CustomerSupply::where('del_time',0)
+                ->whereIn('id',$data['id'])
+                ->update(['del_time' => $time]);
+
+            CustomerSupplyDetails::where('del_time',0)
+                ->where('customer_supply_id', $data['id'])
+                ->update(['del_time' => $time]);
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
+    public function customerSupplyDetail($data, $user){
+        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
+        $customer = CustomerSupply::where('del_time',0)
+            ->where('id',$data['id'])
+            ->first();
+        if(empty($customer)) return [false,'人员不存在或已被删除'];
+        $customer = $customer->toArray();
+        $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('emp_name');
+        $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
+
+        $details = $this->getDetail($data['id']);
+        $customer = array_merge($customer, $details);
+
+        return [true, $customer];
+    }
+
+    public function customerSupplyCommon($data,$user, $field = []){
+        if(empty($field)) $field = CustomerSupply::$field;
+
+        $model = CustomerSupply::Clear($user,$data);
+        $model = $model->where('del_time',0)
+            ->select($field)
+            ->orderby('id', 'desc');
+
+        if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
+        if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
+        if(! empty($data['type'])) $model->where('type', $data['type']);
+        if(! empty($data['id'])) $model->whereIn('id', $data['id']);
+        if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
+            $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
+            $model->where('crt_time','>=',$return[0]);
+            $model->where('crt_time','<=',$return[1]);
+        }
+
+        return $model;
+    }
+
+    public function customerSupplyList($data,$user){
+        $model = $this->customerSupplyCommon($data, $user);
+        $list = $this->limit($model,'',$data);
+        $list = $this->fillData($list,$user,$data);
+
+        return [true, $list];
+    }
+
+    public function customerSupplyRule(&$data, $user, $is_add = true){
+        if(empty($data['code'])) return [false, '编码不能为空'];
+        if(empty($data['title'])) return [false, '名称不能为空'];
+        if(empty($data['type'])) return [false, '人员类型不能为空'];
+        if(! isset(CustomerSupply::$type_name[$data['type']])) return [false, '人员类型错误'];
+        if(! empty($data['status']) && ! isset(CustomerSupply::$status_name[$data['status']])) return [false, '合作状态错误'];
+
+        if(! empty($data['organization'])){
+            $ids = array_column($data['organization'], 'organization_id');
+            // 检查空值
+            if (in_array('', $ids, true) || in_array(null, $ids, true)) {
+                return [false, '组织不能为空'];
+            }
+            // 检查重复
+            if (count($ids) !== count(array_unique($ids))) {
+                return [false, '组织不能重复'];
+            }
+        }
+
+        if($is_add){
+            $bool = CustomerSupply::where('code',$data['code'])
+                ->where('crt_id', $user['id'])
+                ->where('del_time',0)
+                ->exists();
+        }else{
+            if(empty($data['id'])) return [false,'ID不能为空'];
+            $bool = CustomerSupply::where('code',$data['code'])
+                ->where('crt_id', $user['id'])
+                ->where('id','<>',$data['id'])
+                ->where('del_time',0)
+                ->exists();
+        }
+        if($bool) return [false, '编码已存在'];
+
+        return [true, $data];
+    }
+
+    public function fillData($data, $user, $search){
+        if(empty($data['data'])) return $data;
+
+        $emp = (new EmployeeService())->getEmployeeMap(array_unique(array_column($data['data'],'id')));
+        foreach ($data['data'] as $key => $value){
+            $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
+            $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
+            $data['data'][$key]['type_title'] = CustomerSupply::$type_name[$value['type']] ?? '';
+            $data['data'][$key]['status_title'] = CustomerSupply::$status_name[$data['status']] ?? '';
+        }
+
+        return $data;
+    }
+}

+ 4 - 2
app/Service/DimensionService.php

@@ -3,6 +3,7 @@
 namespace App\Service;
 
 use App\Model\Dimension;
+use App\Model\Employee;
 use Illuminate\Support\Facades\DB;
 
 class DimensionService extends Service
@@ -17,7 +18,7 @@ class DimensionService extends Service
             $model = Dimension::where('id',$data['id'])->first();
             $model->title = $data['title'] ?? '';
             $model->code = $data['code'] ?? '';
-            $model->type = $data['type'] ?? 0;
+//            $model->type = $data['type'] ?? 0;
             $model->is_use = $data['is_use'] ?? 0;
             $model->sort = $data['sort'] ?? 0;
             $model->save();
@@ -81,7 +82,7 @@ class DimensionService extends Service
         $customer = Dimension::where('del_time',0)
             ->where('id',$data['id'])
             ->first();
-        if(empty($customer)) return [false,'运费设置不存在或已被删除'];
+        if(empty($customer)) return [false,'维度选项不存在或已被删除'];
         $customer = $customer->toArray();
 
         $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('emp_name');
@@ -100,6 +101,7 @@ class DimensionService extends Service
         if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
         if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
         if(! empty($data['id'])) $model->whereIn('id', $data['id']);
+        if(isset($data['is_use'])) $model->where('is_use', $data['is_use']);
         if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
             $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
             $model->where('crt_time','>=',$return[0]);

+ 177 - 40
app/Service/OrganizationService.php

@@ -4,6 +4,7 @@ namespace App\Service;
 
 use App\Model\Employee;
 use App\Model\Organization;
+use App\Model\OrganizationDetails;
 use Illuminate\Support\Facades\DB;
 
 class OrganizationService extends Service
@@ -16,15 +17,25 @@ class OrganizationService extends Service
             DB::beginTransaction();
 
             $model = Organization::where('id',$data['id'])->first();
-            $model->area = $data['area'] ?? '';
-            $model->region = $data['region'] ?? '';
-            $model->kilometer = $data['kilometer'] ?? 0;
-            $model->min_freight_fee = $data['min_freight_fee'] ?? 0;
-            $model->one_and_five = $data['one_and_five'] ?? 0;
-            $model->greater_than_five = $data['greater_than_five'] ?? 0;
-            $model->company = $data['company'] ?? "";
+            $model->code = $data['code'] ?? '';
+            $model->title = $data['title'] ?? '';
+            $model->industry_name = $data['industry_name'] ?? "";
+            $model->industry_ranking = $data['industry_ranking'] ?? "";
+            $model->address = $data['address'] ?? "";
+            $model->founding_time = $data['founding_time'] ?? 0;
+            $model->type = $data['type'] ?? 0;
+            $model->decision_depart = $data['decision_depart'] ?? "";
+            $model->decision_maker = $data['decision_maker'] ?? "";
+            $model->new_product_rule = $data['new_product_rule'] ?? "";
+            $model->old_product_rule = $data['old_product_rule'] ?? "";
             $model->save();
 
+            $time = time();
+            OrganizationDetails::where('del_time',0)
+                ->where('organization_id', $model->id)
+                ->update(['del_time' => $time]);
+            $this->saveDetail($model->id, $time, $data);
+
             DB::commit();
         }catch (\Exception $exception){
             DB::rollBack();
@@ -42,16 +53,22 @@ class OrganizationService extends Service
             DB::beginTransaction();
 
             $model = new Organization();
-            $model->area = $data['area'] ?? '';
-            $model->region = $data['region'] ?? '';
-            $model->kilometer = $data['kilometer'] ?? 0;
-            $model->min_freight_fee = $data['min_freight_fee'] ?? 0;
-            $model->one_and_five = $data['one_and_five'] ?? 0;
-            $model->greater_than_five = $data['greater_than_five'] ?? 0;
-            $model->company = $data['company'] ?? "";
+            $model->code = $data['code'] ?? '';
+            $model->title = $data['title'] ?? '';
+            $model->industry_name = $data['industry_name'] ?? "";
+            $model->industry_ranking = $data['industry_ranking'] ?? "";
+            $model->address = $data['address'] ?? "";
+            $model->founding_time = $data['founding_time'] ?? 0;
+            $model->type = $data['type'] ?? 0;
+            $model->decision_depart = $data['decision_depart'] ?? "";
+            $model->decision_maker = $data['decision_maker'] ?? "";
+            $model->new_product_rule = $data['new_product_rule'] ?? "";
+            $model->old_product_rule = $data['old_product_rule'] ?? "";
             $model->crt_id = $user['id'];
             $model->save();
 
+            $this->saveDetail($model->id, time(), $data);
+
             DB::commit();
         }catch (\Exception $exception){
             DB::rollBack();
@@ -61,6 +78,98 @@ class OrganizationService extends Service
         return [true, ''];
     }
 
+    private function saveDetail($id, $time, $data){
+        if(! empty($data['unit_list'])){
+            $unit = [];
+            foreach ($data['unit_list'] as $value){
+                $unit[] = [
+                    'organization_id' => $id,
+                    'type' => $value['type'],
+                    'unit' => $value['unit'],
+                    'crt_time' => $time,
+                ];
+            }
+            if(! empty($unit)) OrganizationDetails::insert($unit);
+        }
+
+        if(! empty($data['receipt_list'])){
+            $receipt = [];
+            foreach ($data['receipt_list'] as $value){
+                $start_time = strtotime($value['start_time'] . "-01");
+                $end_time = strtotime($value['end_time'] . "-01");
+                if(empty($value['receipt'])) continue;
+                $receipt[] = [
+                    'organization_id' => $id,
+                    'type' => $value['type'],
+                    'start_time' => $start_time,
+                    'end_time' => $end_time,
+                    'receipt' => $value['receipt'],
+                    'crt_time' => $time,
+                ];
+            }
+            if(! empty($receipt)) OrganizationDetails::insert($receipt);
+        }
+
+        if(! empty($data['requirement_list'])){
+            $requirement = [];
+            foreach ($data['requirement_list'] as $value){
+                $requirement[] = [
+                    'organization_id' => $id,
+                    'type' => $value['type'],
+                    'requirement' => $value['requirement'],
+                    'month_usage' => $value['month_usage'],
+                    'reference_value' => $value['reference_value'],
+                    'crt_time' => $time,
+                ];
+            }
+            if(! empty($requirement)) OrganizationDetails::insert($requirement);
+        }
+    }
+
+    private function getDetail($id){
+        $data = OrganizationDetails::where('del_time',0)
+            ->where('organization_id', $id)
+            ->get()->toArray();
+
+        $unit = $receipt = $requirement = [];
+        foreach ($data as $value){
+            if(in_array($value['type'], [OrganizationDetails::type_one, OrganizationDetails::type_two])) {
+                $unit[] = [
+                    'type' => $value['type'],
+                    'unit' => $value['unit'],
+                ];
+            }elseif(in_array($value['type'], [OrganizationDetails::type_three])){
+                $receipt[] = [
+                    'type' => $value['type'],
+                    'start_time' => date("Y-m", $value['start_time']),
+                    'end_time' => date("Y-m", $value['end_time']),
+                    'receipt' => $value['receipt'],
+                ];
+            }else{
+                $requirement[] = [
+                    'type' => $value['type'],
+                    'requirement' => $value['requirement'],
+                    'month_usage' => $value['month_usage'],
+                    'reference_value' => $value['reference_value'],
+                ];
+            }
+        }
+
+        $detail = [
+            'unit_list' => $unit,
+            'receipt_list' => $receipt,
+            'requirement_list' => $requirement,
+        ];
+
+        foreach ($detail as $key => $value) {
+            if (empty($value)) {
+                $detail[$key] = (object)[]; // 转成 stdClass 对象
+            }
+        }
+
+        return $detail;
+    }
+
     public function organizationDel($data){
         if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
 
@@ -72,6 +181,10 @@ class OrganizationService extends Service
                 ->whereIn('id',$data['id'])
                 ->update(['del_time' => $time]);
 
+            OrganizationDetails::where('del_time',0)
+                ->where('organization_id', $data['id'])
+                ->update(['del_time' => $time]);
+
             DB::commit();
         }catch (\Exception $exception){
             DB::rollBack();
@@ -81,30 +194,34 @@ class OrganizationService extends Service
         return [true, ''];
     }
 
-    public function organizationDetail($data,$user){
+    public function organizationDetail($data, $user){
         if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
         $customer = Organization::where('del_time',0)
             ->where('id',$data['id'])
             ->first();
-        if(empty($customer)) return [false,'运费设置不存在或已被删除'];
+        if(empty($customer)) return [false,'组织不存在或已被删除'];
         $customer = $customer->toArray();
-
+        $customer['founding_time']  = ! empty($customer['founding_time']) ? date("Y-m-d", $customer['founding_time']) : "";
         $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('emp_name');
         $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
 
+        $details = $this->getDetail($data['id']);
+        $customer = array_merge($customer, $details);
+
         return [true, $customer];
     }
 
     public function organizationCommon($data,$user, $field = []){
         if(empty($field)) $field = Organization::$field;
 
-        $model = Organization::where('del_time',0)
+        $model = Organization::Clear($user,$data);
+        $model = $model->where('del_time',0)
             ->select($field)
             ->orderby('id', 'desc');
 
-        if(! empty($data['area'])) $model->where('area', 'LIKE', '%'.$data['area'].'%');
-        if(! empty($data['region'])) $model->where('region', 'LIKE', '%'.$data['region'].'%');
-        if(! empty($data['company'])) $model->where('company', 'LIKE', '%'.$data['company'].'%');
+        if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
+        if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
+        if(! empty($data['type'])) $model->where('type', $data['type']);
         if(! empty($data['id'])) $model->whereIn('id', $data['id']);
         if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
             $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
@@ -124,35 +241,52 @@ class OrganizationService extends Service
     }
 
     public function organizationRule(&$data, $user, $is_add = true){
-        if(empty($data['area'])) return [false, '所属区域不能为空'];
-        if(empty($data['region'])) return [false, '区域不能为空'];
-
-        if(! empty($data['kilometer'])){
-            $res = $this->checkNumber($data['kilometer'],2,'positive');
-            if(! $res['valid']) return [false,'公里数:' . $res['error']];
-        }
-        if(! empty($data['min_freight_fee'])){
-            $res = $this->checkNumber($data['min_freight_fee'],2,'positive');
-            if(! $res['valid']) return [false,'最低运费:' . $res['error']];
+        if(empty($data['code'])) return [false, '编码不能为空'];
+        if(empty($data['title'])) return [false, '名称不能为空'];
+        if(! empty($data['type']) && ! isset(Organization::$type_name[$data['type']])) return [false, '组织类型错误'];
+        if(! empty($data['founding_time'])) $data['founding_time'] = $this->changeDateToDate($data['founding_time']);
+
+        if(! empty($data['unit_list'])){
+            foreach ($data['unit_list'] as $value){
+                if(empty($value['type'])) return [false, '上下级单位类型不能为空'];
+                if(empty($value['unit'])) return [false, '上下级单位名称不能为空'];
+            }
         }
-        if(! empty($data['one_and_five'])){
-            $res = $this->checkNumber($data['one_and_five'],2,'positive');
-            if(! $res['valid']) return [false,'1-5吨:' . $res['error']];
+
+        if(! empty($data['receipt_list'])){
+            foreach ($data['receipt_list'] as $value){
+                if(empty($value['type'])) return [false, '营收信息类型不能为空'];
+                if(empty($value['start_time']) || empty($value['end_time'])) return [false, '营收日期范围不能为空'];
+                $start_time = strtotime($value['start_time'] . "-01");
+                $end_time = strtotime($value['end_time'] . "-01");
+                if(! $start_time || ! $end_time) return [false, '营收日期范围错误'];
+                if(empty($value['receipt'])) return [false, '营收数据不能为空'];
+            }
         }
-        if(! empty($data['greater_than_five'])){
-            $res = $this->checkNumber($data['greater_than_five'],2,'positive');
-            if(! $res['valid']) return [false,'5吨以上:' . $res['error']];
+
+        if(! empty($data['requirement_list'])){
+            foreach ($data['requirement_list'] as $value){
+                if(empty($value['type'])) return [false, '需求信息类型不能为空'];
+                if(empty($value['requirement'])) return [false, '需求信息名不能为空'];
+                if(empty($value['month_usage'])) return [false, '月用量不能为空'];
+                if(empty($value['reference_value'])) return [false, '参考价不能为空'];
+            }
         }
 
         if($is_add){
-
+            $bool = Organization::where('code',$data['code'])
+                ->where('crt_id', $user['id'])
+                ->where('del_time',0)
+                ->exists();
         }else{
             if(empty($data['id'])) return [false,'ID不能为空'];
-            $bool = Organization::where('id',$data['id'])
+            $bool = Organization::where('code',$data['code'])
+                ->where('crt_id', $user['id'])
+                ->where('id','<>',$data['id'])
                 ->where('del_time',0)
                 ->exists();
-            if(! $bool) return [false,'运费设置不存在或已被删除'];
         }
+        if($bool) return [false, '编码已存在'];
 
         return [true, $data];
     }
@@ -160,9 +294,12 @@ class OrganizationService extends Service
     public function fillData($data, $user, $search){
         if(empty($data['data'])) return $data;
 
+        $emp = (new EmployeeService())->getEmployeeMap(array_unique(array_column($data['data'],'id')));
         foreach ($data['data'] as $key => $value){
             $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
+            $data['data'][$key]['founding_time'] = $value['founding_time'] ? date('Y-m-d',$value['founding_time']) : '';
             $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
+            $data['data'][$key]['type_title'] = Organization::$type_name[$value['type']] ?? '';
         }
 
         return $data;

+ 204 - 0
app/Service/QuantizationService.php

@@ -0,0 +1,204 @@
+<?php
+
+namespace App\Service;
+
+use App\Model\Dimension;
+use App\Model\Employee;
+use App\Model\Quantization;
+use App\Model\QuantizationDetails;
+use Illuminate\Support\Facades\DB;
+
+class QuantizationService extends Service
+{
+    public function quantizationEdit($data,$user){
+        list($status,$msg) = $this->quantizationRule($data, $user, false);
+        if(!$status) return [$status,$msg];
+
+        try {
+            DB::beginTransaction();
+
+            $model = Quantization::where('id',$data['id'])->first();
+            $model->title = $data['title'] ?? '';
+            $model->code = $data['code'] ?? '';
+            $model->is_use = $data['is_use'] ?? 0;
+            $model->save();
+
+            $time = time();
+            QuantizationDetails::where('del_time',0)
+                ->where('quantization_id', $data['id'])
+                ->update(['del_time' => $time]);
+
+            $details = [];
+            foreach ($data['details'] as $value){
+                $details[] = [
+                    'quantization_id' => $data['id'],
+                    'title' => $value['title'],
+                    'dimension_id' => $value['dimension_id'],
+                    'rate' => $value['rate'],
+                    'crt_time' => $time,
+                ];
+            }
+            if(! empty($details)) QuantizationDetails::insert($details);
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
+    public function quantizationAdd($data,$user){
+        list($status,$msg) = $this->quantizationRule($data, $user);
+        if(!$status) return [$status,$msg];
+
+        try {
+            DB::beginTransaction();
+
+            $model = new Quantization();
+            $model->title = $data['title'] ?? '';
+            $model->code = $data['code'] ?? '';
+            $model->is_use = $data['is_use'] ?? 0;
+            $model->crt_id = $user['id'];
+            $model->save();
+
+            $details = [];
+            $time = time();
+            foreach ($data['details'] as $value){
+                $details[] = [
+                    'quantization_id' => $model->id,
+                    'title' => $value['title'],
+                    'dimension_id' => $value['dimension_id'],
+                    'rate' => $value['rate'],
+                    'crt_time' => $time,
+                ];
+            }
+            if(! empty($details)) QuantizationDetails::insert($details);
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
+    public function quantizationDel($data){
+        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
+
+        try {
+            DB::beginTransaction();
+            $time = time();
+
+            Quantization::where('del_time',0)
+                ->whereIn('id',$data['id'])
+                ->update(['del_time' => $time]);
+
+            QuantizationDetails::where('del_time',0)
+                ->whereIn('quantization_id', $data['id'])
+                ->update(['del_time' => $time]);
+
+            DB::commit();
+        }catch (\Exception $exception){
+            DB::rollBack();
+            return [false,$exception->getMessage()];
+        }
+
+        return [true, ''];
+    }
+
+    public function quantizationDetail($data,$user){
+        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
+        $customer = Quantization::where('del_time',0)
+            ->where('id',$data['id'])
+            ->first();
+        if(empty($customer)) return [false,'量化档案不存在或已被删除'];
+        $customer = $customer->toArray();
+
+        $details = QuantizationDetails::from('quantization_details as a')
+            ->leftJoin('dimension as b','b.id','a.dimension_id')
+            ->where('a.del_time',0)
+            ->where('a.quantization_id', $data['id'])
+            ->select('a.title','a.dimension_id','a.rate','b.title','b.type')
+            ->get()->toArray();
+        foreach ($details as $key => $value){
+            $details[$key]['type_title'] = Dimension::$type_name[$value['type']] ?? '';
+        }
+        $customer['details'] = $details;
+        $customer['crt_name'] = Employee::where('id',$customer['crt_id'])->value('emp_name');
+        $customer['crt_time'] = $customer['crt_time'] ? date("Y-m-d H:i:s",$customer['crt_time']): '';
+
+        return [true, $customer];
+    }
+
+    public function quantizationCommon($data,$user, $field = []){
+        if(empty($field)) $field = Quantization::$field;
+
+        $model = Quantization::where('del_time',0)
+            ->select($field)
+            ->orderby('id', 'desc');
+
+        if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
+        if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
+        if(! empty($data['id'])) $model->whereIn('id', $data['id']);
+        if(isset($data['is_use'])) $model->where('is_use', $data['is_use']);
+        if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
+            $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
+            $model->where('crt_time','>=',$return[0]);
+            $model->where('crt_time','<=',$return[1]);
+        }
+
+        return $model;
+    }
+
+    public function quantizationList($data,$user){
+        $model = $this->quantizationCommon($data, $user);
+        $list = $this->limit($model,'',$data);
+        $list = $this->fillData($list,$user);
+
+        return [true, $list];
+    }
+
+    public function quantizationRule(&$data, $user, $is_add = true){
+        if(empty($data['title'])) return [false, '名称不能为空'];
+        if(empty($data['code'])) return [false, '编码不能为空'];
+        if(empty($data['details'])) return [false, '维度明细不能为空'];
+        foreach ($data['details'] as $value){
+            if(empty($value['title'])) return [false, '维度名称不能为空'];
+            if(empty($value['dimension_id'])) return [false, '选项不能为空'];
+            if(empty($value['rate'])) return [false, '占比不能为空'];
+        }
+        $rate_total = floatval(array_sum(array_column($data['details'],'rate')));
+        if($rate_total != 100.0) return [false, '占比之和必须等于100'];
+
+        if($is_add){
+            $bool = Quantization::where('code',$data['code'])
+                ->where('del_time',0)
+                ->exists();
+        }else{
+            if(empty($data['id'])) return [false,'ID不能为空'];
+            $bool = Quantization::where('code',$data['code'])
+                ->where('id','<>',$data['id'])
+                ->where('del_time',0)
+                ->exists();
+        }
+        if(! $bool) return [false,'编码已存在'];
+
+        return [true, $data];
+    }
+
+    public function fillData($data, $user){
+        if(empty($data['data'])) return $data;
+
+        $emp = (new EmployeeService())->getEmployeeMap(array_unique(array_column($data['data'],'id')));
+        foreach ($data['data'] as $key => $value){
+            $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
+            $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
+            $data['data'][$key]['is_use_title'] = Quantization::$is_use_name[$value['is_use']] ?? '';
+        }
+
+        return $data;
+    }
+}

+ 0 - 86
app/Service/TPlusDatabaseServerService.php

@@ -1,86 +0,0 @@
-<?php
-
-namespace App\Service;
-
-use Illuminate\Support\Facades\Config;
-use Illuminate\Support\Facades\DB;
-use Illuminate\Support\Facades\Log;
-
-class TPlusDatabaseServerService extends Service
-{
-    public $db = null;
-    public $error = null; // 错误信息
-
-    public function __construct()
-    {
-        $this->createConnection();
-    }
-
-    private function createConnection()
-    {
-        // 主数据库连接
-        $mainConnName = 'sqlsrv_main_' . uniqid();
-        $mainConfig = [
-            'driver' => 'sqlsrv',
-            'host' => env('SQLSRV_HOST'),
-            'port' => env('SQLSRV_PORT'),
-            'database' => env('SQLSRV_DATABASE'),
-            'username' => env('SQLSRV_USERNAME'),
-            'password' => env('SQLSRV_PASSWORD'),
-            'options' => [
-                \PDO::SQLSRV_ATTR_QUERY_TIMEOUT => 30, // SQL Server专用超时
-                \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
-            ],
-        ];
-
-        Config::set("database.connections.{$mainConnName}", $mainConfig);
-        $this->db = DB::connection($mainConnName);
-
-        // 测试连接有效性
-        $this->validateConnection($this->db);
-    }
-
-    private function validateConnection($connection)
-    {
-        try {
-            $pdo = $connection->getPdo();
-            $stmt = $pdo->prepare("SELECT 1 AS connection_test");
-            $stmt->execute();
-            $result = $stmt->fetch(\PDO::FETCH_ASSOC);
-
-            if (empty($result) || $result['connection_test'] != 1) {
-                $this->error = "T+数据库连接失败";
-            }
-        } catch (\Throwable $e) {
-            $this->error = "T+数据库连接验证失败: " . $e->getMessage();
-        }
-    }
-
-    public function __destruct()
-    {
-        // 主动关闭连接
-        $this->safeDisconnect($this->db);
-    }
-
-    private function safeDisconnect(&$connection)
-    {
-        try {
-            if ($connection instanceof \Illuminate\Database\Connection) {
-                // 物理断开连接
-                $connection->disconnect();
-
-                // 清除连接引用
-                $connection = null;
-
-//                Log::info("动作", [
-//                    'param' => "执行了析构",
-//                ]);
-            }
-        } catch (\Throwable $e) {
-            // 静默处理断开错误
-//            Log::info("错误", [
-//                'param' => $e->getMessage(),
-//            ]);
-        }
-    }
-}

+ 0 - 1399
app/Service/TPlusServerService.php

@@ -1,1399 +0,0 @@
-<?php
-
-namespace App\Service;
-
-use App\Jobs\ProcessDataJob;
-use App\Model\Depart;
-use App\Model\Employee;
-use App\Model\EmployeeDepartPermission;
-use App\Model\EmployeeIndex;
-use App\Model\Organization;
-use App\Model\FreightFee;
-use App\Model\Product;
-use App\Model\RevenueCost;
-use App\Model\RevenueCostTotal;
-use App\Model\SalaryEmployee;
-use Illuminate\Database\Schema\Blueprint;
-use Illuminate\Support\Facades\DB;
-use Illuminate\Support\Facades\Schema;
-
-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;
-    }
-
-    private $table = "tmp_revenue_cost_data";
-    private $table_2 = "tmp_salary_employee";
-    private $table_3 = "tmp_freight_fee";
-
-    /**
-     * 同步人员部门
-     *
-     * @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, ''];
-    }
-
-    /**
-     * 收入成本统计同步
-     *
-     * @param array $data
-     * @param array $user
-     * @return array
-     */
-    public function synRevenueCost($data, $user){
-        if(empty($data['crt_time'][0]) || empty($data['crt_time'][1])) return [false, '同步时间不能为空'];
-        list($start_time, $end_time) = $this->changeDateToTimeStampAboutRange($data['crt_time'],false);
-        if ($start_time === null || $end_time === null || $start_time > $end_time) return [false, "同步时间:时间区间无效"];
-        list($bool, $bool_msg) = $this->isOverThreeMonths($start_time, $end_time);
-        if(! $bool) return [false, $bool_msg];
-        $data['start_timeStamp'] = $start_time;
-        $data['end_timeStamp'] = $end_time;
-        $start = date('Y-m-d H:i:s.000', $start_time);
-        $end = date('Y-m-d H:i:s.000', $end_time);
-        $data['start_time'] = $start;
-        $data['end_time'] = $end;
-        $data['operation_time'] = time();
-        if(empty($data['type'])) return [false, '同步类型不能为空'];
-        if(in_array($data['type'],[1,2,3,4])){
-            list($status,$msg) = $this->limitingSendRequest($this->table);
-            if(! $status) return [false, '收入成本相关信息同步正在后台运行,请稍后'];
-
-//            //同步
-//            list($status, $msg) = $this->synRevenueCostFromTPlus($data, $user);
-//            if(! $status) {
-//                return [false, $msg];
-//            }
-
-            //队列
-            ProcessDataJob::dispatch($data, $user)->onQueue(RevenueCost::job);
-        }else{
-            return [false, '同步类型错误'];
-        }
-
-        return [true, '收入成本相关信息同步已进入后台任务'];
-    }
-
-    public function synRevenueCostFromTPlus($data, $user){
-        //创建临时表 如果不存在
-        $this->createTmpTable();
-        //清理临时表 如果内容不为空
-        $this->clearTmpTable();
-        $type = $data['type'];
-
-        //写入临时数据
-        if($type == 1){
-            list($status, $msg) = $this->xhdTPlus($data, $user);
-            if(! $status) return [false, $msg];
-            list($status, $msg) = $this->xsfpTPlus($data, $user);
-            if(! $status) return [false, $msg];
-            list($status, $msg) = $this->hkdTPlus($data, $user);
-            if(! $status) return [false, $msg];
-        }elseif ($type == 2){
-            list($status, $msg) = $this->xhdTPlus($data, $user);
-            if(! $status) return [false, $msg];
-        }elseif ($type == 3){
-            list($status, $msg) = $this->xsfpTPlus($data, $user);
-            if(! $status) return [false, $msg];
-        }elseif ($type == 4){
-            list($status, $msg) = $this->hkdTPlus($data, $user);
-            if(! $status) return [false, $msg];
-        }
-
-        //更新数据
-        list($status,$msg) = $this->updateRevenueCost($data);
-        if(! $status) return [false, $msg];
-
-//        //更新主表数据
-//        list($status,$msg) = $this->updateRevenueCostTotal($data);
-//        if(! $status) return [false, $msg];
-
-        //都成功后 清理临时表
-        $this->clearTmpTable();
-        //释放redis
-        $this->delTableKey();
-
-        return [true, '同步成功'];
-    }
-
-    private function xhdTPlus($data, $user){
-        try {
-            $table = $this->table;
-            $limit = 500;
-            $lastId = 0;
-
-            do {
-                $rows = $this->databaseService->table('SA_SaleDelivery_b as sd_b')
-                    ->join('SA_SaleDelivery as sd', 'sd_b.idSaleDeliveryDTO', '=', 'sd.ID')
-                    ->leftJoin('AA_Partner as pn', 'sd.idsettlecustomer', '=', 'pn.ID')
-                    ->leftJoin('AA_Person as ps', 'sd.idclerk', '=', 'ps.ID')
-                    ->leftJoin('AA_Person as ps2', 'pn.idsaleman', '=', 'ps2.ID')
-                    ->leftJoin('AA_Inventory as it', 'sd_b.idinventory', '=', 'it.ID')
-                    ->leftJoin('AA_Unit as ui', 'sd_b.idbaseunit', '=', 'ui.ID')
-                    ->where('sd.voucherdate', '>=', $data['start_time'])
-                    ->where('sd.voucherdate', '<=', $data['end_time'])
-                    ->where('sd_b.ID', '>', $lastId) // 用真实字段
-                    ->orderBy('sd_b.ID')
-                    ->limit($limit)
-                    ->selectRaw("
-                        COALESCE(sd.ID, 0) as order_id,
-                        COALESCE(sd.code, '') as order_number,
-                        sd.voucherdate as order_time,
-                        sd.voucherState as order_state,
-                        COALESCE(ps.name, '') as employee_id_1_title,
-                        COALESCE(sd.idclerk, 0) as employee_id_1,
-                        COALESCE(ps2.name, '') as employee_id_2_title,
-                        COALESCE(pn.idsaleman, 0) as employee_id_2,
-                        COALESCE(pn.code, '') as customer_code,
-                        COALESCE(pn.name, '') as customer_title,
-                        COALESCE(pn.priuserdefnvc14, '') as customer_profit_rate,
-                        COALESCE(sd.pubuserdefnvc11, '') as channel_finance,
-                        COALESCE(sd.pubuserdefnvc12, '') as channel_details,
-                        COALESCE(it.code, '') as product_code,
-                        COALESCE(it.name, '') as product_title,
-                        COALESCE(it.specification, '') as product_size,
-                        COALESCE(ui.name, '') as unit,
-                        COALESCE(sd_b.quantity, 0) as quantity,
-                        COALESCE(sd_b.taxPrice, 0) as price_3,
-                        COALESCE(sd_b.taxAmount, 0) as price_3_total,
-                        COALESCE(sd_b.ID, 0) as id_detail,
-                        COALESCE(sd_b.pubuserdefdecm9, 0) as is_activity
-                    ")
-                    ->get();
-
-                if ($rows->isEmpty()) break;
-
-                $dataArray = Collect($rows)->map(function ($object) {
-                    return (array)$object;
-                })->toArray();
-
-                //存货档案
-                $product = Product::where('del_time', 0)
-                    ->whereIn('code', array_unique(array_column($dataArray, 'product_code')))
-                    ->select('code', 'write_off_price', 'freight_price', 'business_cost')
-                    ->get()->toArray();
-                $product_map = array_column($product, null, 'code');
-
-                //组织数据
-                foreach ($dataArray as $key => $value) {
-                    $customer_profit_rate = rtrim($value['customer_profit_rate'],'%');
-                    if(is_numeric($customer_profit_rate)){
-                        $customer_profit_rate = bcdiv($customer_profit_rate,100,3);
-                    }else{
-                        $customer_profit_rate = 0;
-                    }
-                    $dataArray[$key]['customer_profit_rate'] = $customer_profit_rate;
-                    $p_tmp = $product_map[$value['product_code']] ?? [];
-                    $dataArray[$key]['order_type'] = RevenueCost::ORDER_ONE;
-                    $dataArray[$key]['order_time'] = strtotime($value['order_time']);
-                    $write_off_price = $p_tmp['write_off_price'] ?? 0;
-                    $dataArray[$key]['price_1'] = $write_off_price;
-                    $dataArray[$key]['price_1_total'] = bcmul($write_off_price, $value['quantity'], 2);
-                    $freight_price = $p_tmp['freight_price'] ?? 0;
-                    $dataArray[$key]['price_2'] = $freight_price;
-                    $dataArray[$key]['price_2_total'] = bcmul($freight_price, $value['quantity'], 2);
-                    $business_cost = $p_tmp['business_cost'] ?? 0;
-                    $dataArray[$key]['price_4'] = $business_cost;
-                    $price_4_total = bcmul($business_cost, $value['quantity'], 2);
-                    $dataArray[$key]['price_4_total'] = bcmul($business_cost, $value['quantity'], 2);
-                    $profit = bcsub($value['price_3_total'], $price_4_total, 2);
-                    $dataArray[$key]['profit'] = $profit;
-                    $dataArray[$key]['profit_rate'] = $value['price_3_total'] > 0 ? bcdiv($profit, $value['price_3_total'], 2) : 0;
-                }
-
-                DB::table($table)->insert($dataArray);
-
-                // 更新 lastId 继续下一批
-                $lastId = end($dataArray)['id_detail'] ?? $lastId;
-
-            } while (count($rows) === $limit);
-        }catch  (\Throwable $exception){
-            return [false, "销货单同步异常" . $exception->getMessage() . "|" . $exception->getLine() . "|" . $exception->getFile()];
-        }
-
-        return [true, ''];
-    }
-
-    private function xsfpTPlus($data, $user){
-        try {
-            $table = $this->table;
-            $limit = 500;
-            $lastId = 0;
-
-            do {
-                $rows = $this->databaseService->table('SA_SaleInvoice_b as si_b')
-                    ->join('SA_SaleInvoice as si', 'si_b.idSaleInvoiceDTO', '=', 'si.ID')
-                    ->leftJoin('SA_SaleDelivery_b as sd_b', 'si_b.sourceVoucherDetailId', '=', 'sd_b.ID')
-                    ->leftJoin('AA_Partner as pn', 'si.idsettlecustomer', '=', 'pn.ID')
-                    ->leftJoin('AA_Person as ps', 'si.idclerk', '=', 'ps.ID')
-                    ->leftJoin('AA_Person as ps2', 'pn.idsaleman', '=', 'ps2.ID')
-                    ->leftJoin('AA_Inventory as it', 'si_b.idinventory', '=', 'it.ID')
-                    ->leftJoin('AA_Unit as ui', 'si_b.idbaseunit', '=', 'ui.ID')
-                    ->where('si.voucherdate','>=',$data['start_time'])
-                    ->where('si.voucherdate','<=',$data['end_time'])
-                    ->where('si_b.ID', '>', $lastId) // 用真实字段
-                    ->orderBy('si_b.ID')
-                    ->limit($limit)
-                    ->selectRaw("
-                        COALESCE(si.ID, 0) as order_id,
-                        COALESCE(si.code, '') as order_number,
-                        si.voucherdate as order_time,
-                        si.voucherState as order_state,
-                        COALESCE(pn.code, '') as customer_code,
-                        COALESCE(pn.name, '') as customer_title,
-                        COALESCE(pn.priuserdefnvc14, '') as customer_profit_rate,
-                        COALESCE(si.idclerk, 0) as employee_id_1,
-                        COALESCE(ps.name, '') as employee_id_1_title,
-                        COALESCE(pn.idsaleman, 0) as employee_id_2,
-                        COALESCE(ps2.name, '') as employee_id_2_title,
-                        COALESCE(it.code, '') as product_code,
-                        COALESCE(it.name, '') as product_title,
-                        COALESCE(it.specification, '') as product_size,
-                        COALESCE(ui.name, '') as unit,
-                        COALESCE(si_b.quantity, 0) as quantity,
-                        COALESCE(si_b.taxPrice, 0) as price_1,
-                        COALESCE(si_b.taxAmount, 0) as price_1_total,
-                        COALESCE(si_b.ID, 0) as id_detail,
-                        COALESCE(si_b.sourceVoucherDetailId, 0) as id_detail_upstream,
-                        COALESCE(si_b.sourceVoucherCode, '') as order_number_upstream,
-                        COALESCE(sd_b.pubuserdefdecm9, 0) as is_activity
-                    ")
-                    ->get();
-
-                if ($rows->isEmpty()) break;
-
-                $dataArray = Collect($rows)->map(function ($object) {
-                    return (array)$object;
-                })->toArray();
-
-                //存货档案
-                $product = Product::where('del_time',0)
-                    ->whereIn('code', array_unique(array_column($dataArray,'product_code')))
-                    ->select('code','business_cost')
-                    ->get()->toArray();
-                $product_map = array_column($product,null,'code');
-
-                //组织数据
-                foreach ($dataArray as $key => $value){
-                    $customer_profit_rate = rtrim($value['customer_profit_rate'],'%');
-                    if(is_numeric($customer_profit_rate)){
-                        $customer_profit_rate = bcdiv($customer_profit_rate,100,3);
-                    }else{
-                        $customer_profit_rate = 0;
-                    }
-                    $dataArray[$key]['customer_profit_rate'] = $customer_profit_rate;
-                    $p_tmp = $product_map[$value['product_code']] ?? [];
-                    $dataArray[$key]['order_type'] = RevenueCost::ORDER_TWO;
-                    $dataArray[$key]['order_time'] = strtotime($value['order_time']);
-                    $business_cost = $p_tmp['business_cost'] ?? 0;
-                    $dataArray[$key]['price_4'] = $business_cost;
-                    $price_4_total = bcmul($business_cost, $value['quantity'],2);
-                    $dataArray[$key]['price_4_total'] = bcmul($business_cost, $value['quantity'],2);
-                    $profit = bcsub($value['price_1_total'], $price_4_total,2);
-                    $dataArray[$key]['profit'] = $profit;
-                    $dataArray[$key]['profit_rate'] = $value['price_1_total'] > 0 ? bcdiv($profit, $value['price_1_total'],2) : 0;
-                }
-
-                DB::table($table)->insert($dataArray);
-
-                // 更新 lastId 继续下一批
-                $lastId = end($dataArray)['id_detail'] ?? $lastId;
-
-            } while (count($rows) === $limit);
-        }catch  (\Throwable $exception){
-            return [false, "销售发票同步异常" . $exception->getMessage() . "|" . $exception->getLine() . "|" . $exception->getFile()];
-        }
-
-        return [true, ''];
-    }
-
-    private function hkdTPlus($data, $user){
-        try{
-            $table = $this->table;
-            $limit = 500;
-            $lastId = 0;
-
-            do {
-                $rows = $this->databaseService->table('ARAP_ReceivePayment_b as rp_b')
-                    ->join('ARAP_ReceivePayment as rp', 'rp_b.idArapReceivePaymentDTO', '=', 'rp.ID')
-//                    ->leftJoin('SA_SaleInvoice_b as si_b', 'rp_b.voucherDetailID', '=', 'si_b.ID')
-//                    ->leftJoin('SA_SaleInvoice as si', 'si_b.idSaleInvoiceDTO', '=', 'si.ID')
-//                    ->leftJoin('SA_SaleDelivery_b as sd_b', 'si_b.sourceVoucherDetailId', '=', 'sd_b.ID')
-                    // 发票子表关联(仅限 idvouchertype = 20)
-                    ->leftJoin('SA_SaleInvoice_b as si_b', function ($join) {
-                        $join->on('rp_b.voucherDetailID', '=', 'si_b.ID')
-                            ->where('rp_b.idvouchertype', '=', 20);
-                    })
-                    ->leftJoin('SA_SaleInvoice as si', function ($join) {
-                        $join->on('si_b.idSaleInvoiceDTO', '=', 'si.ID')
-                            ->where('rp_b.idvouchertype', '=', 20);
-                    })
-                    ->leftJoin('SA_SaleDelivery_b as sd_b', function ($join) {
-                        $join->on('si_b.sourceVoucherDetailId', '=', 'sd_b.ID')
-                            ->where('rp_b.idvouchertype', '=', 20);
-                    })
-                    ->leftJoin('AA_Partner as pn', 'si.idsettlecustomer', '=', 'pn.ID')
-                    ->leftJoin('AA_Person as ps', 'rp.idperson', '=', 'ps.ID')
-                    ->leftJoin('AA_Person as ps2', 'pn.idsaleman', '=', 'ps2.ID')
-                    ->leftJoin('AA_Inventory as it', 'si_b.idinventory', '=', 'it.ID')
-                    ->leftJoin('AA_Unit as ui', 'si_b.idbaseunit', '=', 'ui.ID')
-                    ->where('rp.voucherdate','>=',$data['start_time'])
-                    ->where('rp.voucherdate','<=',$data['end_time'])
-//                    ->where('rp_b.idvouchertype','=', 20) // 销售发票
-                    ->where('rp.isReceiveFlag','=', 1)
-                    ->where('rp_b.ID', '>', $lastId)
-                    ->orderBy('rp_b.ID')
-                    ->limit($limit)
-//                    ->selectRaw("
-//                        COALESCE(rp.ID, 0) as order_id,
-//                        COALESCE(rp.code, '') as order_number,
-//                        rp.voucherdate as order_time,
-//                        COALESCE(pn.code, '') as customer_code,
-//                        COALESCE(pn.name, '') as customer_title,
-//                        COALESCE(pn.priuserdefnvc14, '') as customer_profit_rate,
-//                        COALESCE(it.code, '') as product_code,
-//                        COALESCE(it.name, '') as product_title,
-//                        COALESCE(rp.idperson, 0) as employee_id_1,
-//                        COALESCE(ps.name, '') as employee_id_1_title,
-//                        COALESCE(pn.idsaleman, 0) as employee_id_2,
-//                        COALESCE(ps2.name, '') as employee_id_2_title,
-//                        COALESCE(it.specification, '') as product_size,
-//                        COALESCE(ui.name, '') as unit,
-//                        COALESCE(si_b.quantity, 0) as quantity,
-//                        COALESCE(si_b.taxPrice, 0) as price_1,
-//                        COALESCE(si_b.taxAmount, 0) as price_1_total,
-//                        COALESCE(rp_b.amount, 0) as payment_amount,
-//                        COALESCE(rp_b.ID, 0) as id_detail,
-//                        COALESCE(rp_b.voucherDetailID, 0) as id_detail_upstream,
-//                        COALESCE(rp_b.voucherCode, '') as order_number_upstream,
-//                        COALESCE(sd_b.pubuserdefdecm9, 0) as is_activity
-//                    ")
-                    ->selectRaw("
-                        COALESCE(rp.ID, 0) as order_id,
-                        COALESCE(rp.code, '') as order_number,
-                        rp.voucherdate as order_time,
-                        rp.voucherstate as order_state,
-                        COALESCE(rp.pubuserdefnvc11, '') as channel_finance,
-                        COALESCE(rp.pubuserdefnvc12, '') as channel_details,
-                        COALESCE(pn.code, '') as customer_code,
-                        COALESCE(pn.name, '') as customer_title,
-                        COALESCE(pn.priuserdefnvc14, '') as customer_profit_rate,
-                        CASE WHEN rp_b.idvouchertype = 20 THEN COALESCE(it.code, '') ELSE '' END as product_code,
-                        CASE WHEN rp_b.idvouchertype = 20 THEN COALESCE(it.name, '') ELSE '' END as product_title,
-                        COALESCE(rp.idperson, 0) as employee_id_1,
-                        COALESCE(ps.name, '') as employee_id_1_title,
-                        COALESCE(pn.idsaleman, 0) as employee_id_2,
-                        COALESCE(ps2.name, '') as employee_id_2_title,
-                        CASE WHEN rp_b.idvouchertype = 20 THEN COALESCE(it.specification, '') ELSE '' END as product_size,
-                        CASE WHEN rp_b.idvouchertype = 20 THEN COALESCE(ui.name, '') ELSE '' END as unit,
-                        CASE WHEN rp_b.idvouchertype = 20 THEN COALESCE(si_b.quantity, 0) ELSE 0 END as quantity,
-                        CASE WHEN rp_b.idvouchertype = 20 THEN COALESCE(si_b.taxPrice, 0) ELSE 0 END as price_1,
-                        CASE WHEN rp_b.idvouchertype = 20 THEN COALESCE(si_b.taxAmount, 0) ELSE 0 END as price_1_total,
-                        COALESCE(rp_b.origCurrentAmount, 0) as payment_amount,
-                        COALESCE(rp_b.ID, 0) as id_detail,
-                        COALESCE(rp_b.voucherDetailID, 0) as id_detail_upstream,
-                        COALESCE(rp_b.voucherCode, '') as order_number_upstream,
-                        CASE WHEN rp_b.idvouchertype = 20 THEN COALESCE(sd_b.pubuserdefdecm9, 0) ELSE 0 END as is_activity,
-                        rp_b.idvouchertype as voucher_type
-                    ")
-                    ->get();
-//                COALESCE(rp_b.amount, 0) as payment_amount,
-
-                if ($rows->isEmpty()) break;
-
-                $dataArray = Collect($rows)->map(function ($object) {
-                    return (array)$object;
-                })->toArray();
-
-                //存货档案
-                $product = Product::where('del_time',0)
-                    ->whereIn('code', array_unique(array_column($dataArray,'product_code')))
-                    ->select('code','business_cost')
-                    ->get()->toArray();
-                $product_map = array_column($product,null,'code');
-
-                //组织数据
-                foreach ($dataArray as $key => $value){
-                    $customer_profit_rate = rtrim($value['customer_profit_rate'],'%');
-                    if(is_numeric($customer_profit_rate)){
-                        $customer_profit_rate = bcdiv($customer_profit_rate,100,3);
-                    }else{
-                        $customer_profit_rate = 0;
-                    }
-                    $dataArray[$key]['customer_profit_rate'] = $customer_profit_rate;
-                    $p_tmp = $product_map[$value['product_code']] ?? [];
-                    $dataArray[$key]['order_type'] = RevenueCost::ORDER_THREE;
-                    $dataArray[$key]['order_time'] = strtotime($value['order_time']);
-                    $business_cost = $p_tmp['business_cost'] ?? 0;
-                    $dataArray[$key]['price_4'] = $business_cost;
-                    $price_4_total = bcmul($business_cost, $value['quantity'],2);
-                    $dataArray[$key]['price_4_total'] = $price_4_total;
-                    $profit = bcsub($value['price_1_total'], $price_4_total,2);
-                    $dataArray[$key]['profit'] = $profit;
-                    $dataArray[$key]['profit_rate'] = $value['price_1_total'] > 0 ? bcdiv($profit, $value['price_1_total'],2) : 0;
-                }
-
-                DB::table($table)->insert($dataArray);
-
-                // 更新 lastId 继续下一批
-                $lastId = end($dataArray)['id_detail'] ?? $lastId;
-
-            } while (count($rows) === $limit);
-
-        }catch (\Throwable $exception){
-            return [false, "回款单同步异常" . $exception->getMessage() . "|" . $exception->getLine() . "|" . $exception->getFile()];
-        }
-
-        return [true, ''];
-    }
-
-    private function updateRevenueCost($data){
-        try {
-            $start_timeStamp = $data['start_timeStamp'];
-            $end_timeStamp = $data['end_timeStamp'];
-            $tmpTable = $this->table;
-            $time = time();
-            $ergs = $data;
-
-            DB::transaction(function () use ($start_timeStamp, $end_timeStamp, $tmpTable,$time, $ergs) {
-                // 1. 先软删除旧数据(你已有)
-                RevenueCost::where('del_time', 0)
-                    ->where('order_time', '>=', $start_timeStamp)
-                    ->where('order_time', '<=', $end_timeStamp)
-                    ->update(['del_time' => $time]);
-
-                // 2. 分批从临时表插入新数据
-                $batchSize = 500;
-                $lastId = 0;
-                do {
-                    $chunk = DB::table($tmpTable)
-                        ->where('id', '>', $lastId)
-                        ->orderBy('id')
-                        ->limit($batchSize)
-                        ->get();
-
-                    if ($chunk->isEmpty()) {
-                        break;
-                    }
-
-                    $data = $chunk->map(function ($item) use($time){
-                        return [
-                            'order_id' => $item->order_id,
-                            'order_number' => $item->order_number,
-                            'order_time' => $item->order_time,
-                            'order_state' => $item->order_state,
-                            'employee_id_1_title' => $item->employee_id_1_title,
-                            'employee_id_1' => $item->employee_id_1 ?? 0,
-                            'employee_id_2' => $item->employee_id_2 ?? 0,
-                            'employee_id_2_title' => $item->employee_id_2_title ?? "",
-                            'customer_code' => $item->customer_code,
-                            'customer_title' => $item->customer_title,
-                            'channel_finance' => $item->channel_finance,
-                            'channel_details' => $item->channel_details,
-                            'product_code' => $item->product_code,
-                            'product_title' => $item->product_title,
-                            'product_size' => $item->product_size,
-                            'unit' => $item->unit,
-                            'quantity' => $item->quantity,
-                            'price_1' => $item->price_1,
-                            'price_1_total' => $item->price_1_total,
-                            'price_2' => $item->price_2,
-                            'price_2_total' => $item->price_2_total,
-                            'price_3' => $item->price_3,
-                            'price_3_total' => $item->price_3_total,
-                            'price_4' => $item->price_4,
-                            'price_4_total' => $item->price_4_total,
-                            'profit' => $item->profit,
-                            'profit_rate' => $item->profit_rate,
-                            'id_detail' => $item->id_detail,
-                            'order_type' => $item->order_type,
-                            'payment_amount' => $item->payment_amount ?? 0,
-                            'id_detail_upstream' => $item->id_detail_upstream?? 0,
-                            'order_number_upstream' => $item->order_number_upstream ?? "",
-                            'is_activity' => $item->is_activity ?? 0,
-                            'customer_profit_rate' => $item->customer_profit_rate ?? '',
-                            'voucher_type' => $item->voucher_type ?? 0,
-                            'crt_time' => $time,
-                        ];
-                    })->toArray();
-
-                    // 每批单独插入(可选:加小事务)
-                    RevenueCost::insert($data);
-
-                    // 更新 lastId
-                    $lastId = $chunk->last()->id;
-
-                } while ($chunk->count() == $batchSize);
-
-                // 3. 更新主表
-                list($status, $msg) = $this->updateRevenueCostTotal($ergs);
-                if (! $status) {
-                    throw new \Exception($msg);
-                }
-            });
-        }catch  (\Throwable $exception){
-            return [false, "单据明细同步异常" . $exception->getMessage() . "|" . $exception->getLine() . "|" . $exception->getFile()];
-        }
-
-        return [true, ''];
-    }
-
-    private function updateRevenueCostTotal($data){
-        try {
-            $start_timeStamp = $data['start_timeStamp'];
-            $end_timeStamp = $data['end_timeStamp'];
-            $time = time();
-
-            //组织写入数据
-            $return = [];
-            $update_stamp = [];
-            DB::table('revenue_cost')
-                ->where('del_time',0)
-                ->where('order_time', '>=', $start_timeStamp)
-                ->where('order_time', '<=', $end_timeStamp)
-                ->select(RevenueCost::$field)
-                ->chunkById(100, function ($data) use(&$return,&$update_stamp){
-                    $dataArray = Collect($data)->map(function ($object){
-                        return (array)$object;
-                    })->toArray();
-                    foreach ($dataArray as $value){
-                        //变成每个月第一天的时间戳
-                        $time = date("Y-m-01", $value['order_time']);
-                        $stamp = strtotime($time);
-                        if(! in_array($stamp, $update_stamp)) $update_stamp[] = $stamp;
-                        if($value['order_type'] == RevenueCost::ORDER_ONE){
-                            $income = $value['price_3_total'];
-                        }elseif ($value['order_type'] == RevenueCost::ORDER_TWO){
-                            $income = $value['price_1_total'];
-                        }else{
-                            $income = $value['payment_amount'];
-                        }
-                        $adjust = $income < 0 ? $income : 0;
-                        $business = $value['price_4_total'];
-                        if(isset($return[$stamp][$value['order_type']][$value['employee_id_1']])){
-                            $income_total = bcadd($return[$stamp][$value['order_type']][$value['employee_id_1']]['income'], $income,2);
-                            $adjust_total = bcadd($return[$stamp][$value['order_type']][$value['employee_id_1']]['adjust'], $adjust,2);
-                            $business_total = bcadd($return[$stamp][$value['order_type']][$value['employee_id_1']]['business'], $business,2);
-                            $return[$stamp][$value['order_type']][$value['employee_id_1']]['income'] = $income_total;
-                            $return[$stamp][$value['order_type']][$value['employee_id_1']]['adjust'] = $adjust_total;
-                            $return[$stamp][$value['order_type']][$value['employee_id_1']]['business'] = $business_total;
-                        }else{
-                            $return[$stamp][$value['order_type']][$value['employee_id_1']] = [
-                                'income' => $income,
-                                'adjust' => $adjust,
-                                'business' => $business,
-                                'order_time' => $stamp,
-                                'employee_id_1_title' => $value['employee_id_1_title'],
-                            ];
-                        }
-                    }
-                });
-            $insert = [];
-            foreach ($return as $value){
-                foreach ($value as $order_type => $val){
-                   foreach ($val as $employee_id => $v){
-                        $profit = bcsub($v['income'], $v['business'],2);
-                        $profit_rate = $v['income'] > 0 ? bcdiv($profit, $v['income'],2) : 0;
-                        $v['profit'] = $profit;
-                        $v['profit_rate'] = $profit_rate;
-                        $v['order_type'] = $order_type;
-                        $v['employee_id_1'] = $employee_id;
-                        $v['crt_time'] = $time;
-                        $insert[] = $v;
-                    }
-                }
-            }
-
-            RevenueCostTotal::where('del_time', 0)
-                ->whereIn('order_time', $update_stamp)
-                ->update(['del_time' => $time]);
-
-            RevenueCostTotal::insert($insert);
-        }catch  (\Throwable $exception){
-            return [false, "主表同步异常" . $exception->getMessage() . "|" . $exception->getLine() . "|" . $exception->getFile()];
-        }
-
-        return [true, ''];
-    }
-
-    private function createTmpTable(){
-        $table = $this->table;
-        if (! Schema::hasTable($table)) {
-            // 可以通过 migration 创建,或程序启动时检查
-            Schema::create($table, function (Blueprint $table) {
-                $table->bigIncrements('id'); // BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY
-                $table->integer('order_type')->default(0);
-                $table->bigInteger('order_id')->default(0);
-                $table->string('order_number', 50)->default('');
-                $table->integer('order_time')->nullable();
-                $table->integer('order_state')->default(0);
-                $table->string('employee_id_1_title', 100)->default('');
-                $table->bigInteger('employee_id_1')->default(0);
-                $table->bigInteger('employee_id_2')->default(0);
-                $table->string('employee_id_2_title', 100)->default('');
-                $table->string('customer_code', 50)->default('');
-                $table->string('customer_title', 100)->default('');
-                $table->string('channel_finance', 50)->nullable();
-                $table->string('channel_details', 50)->nullable();
-                $table->string('product_code', 50)->default('');
-                $table->string('product_title', 100)->default('');
-                $table->string('product_size', 100)->nullable();
-                $table->string('unit', 20)->nullable();
-                $table->decimal('quantity', 12, 2)->default(0);
-                $table->decimal('price_1', 12, 2)->default(0); // 销项成本
-                $table->decimal('price_1_total', 12, 2)->default(0);
-                $table->decimal('price_2', 12, 2)->default(0); // 运费
-                $table->decimal('price_2_total', 12, 2)->default(0);
-                $table->decimal('price_3', 12, 2)->default(0); // 含税单价
-                $table->decimal('price_3_total', 12, 2)->default(0); // 含税金额
-                $table->decimal('price_4', 12, 2)->default(0); // 业务成本
-                $table->decimal('price_4_total', 12, 2)->default(0);
-                $table->decimal('profit', 12, 2)->default(0);
-                $table->decimal('payment_amount', 12, 2)->default(0);
-                $table->decimal('profit_rate', 10, 3)->default(0);
-                $table->bigInteger('id_detail')->default(0);
-                $table->bigInteger('id_detail_upstream')->default(0);
-                $table->string('order_number_upstream', 100)->nullable();
-                $table->decimal('is_activity', 2, 0)->default(0);
-                $table->string('customer_profit_rate', 20)->default('');
-                $table->bigInteger('voucher_type')->default(0);
-            });
-        }
-    }
-
-    public function clearTmpTable($type = 1){
-        if($type == 1){
-            if (Schema::hasTable($this->table)) DB::table($this->table)->truncate();
-        }elseif ($type == 2){
-            if (Schema::hasTable($this->table_2)) DB::table($this->table_2)->truncate();
-        }elseif ($type == 3){
-            if (Schema::hasTable($this->table_3)) DB::table($this->table_3)->truncate();
-        }
-    }
-
-    public function delTableKey($type = 1){
-        $key = $this->table;
-        if($type == 2) $key = $this->table_2;
-        if($type == 3) $key = $this->table_3;
-        $this->dellimitingSendRequest($key);
-    }
-
-    public function synSalaryEmployee($data, $user){
-        if(empty($data['crt_time'][0]) || empty($data['crt_time'][1])) return [false, '同步时间不能为空'];
-        list($start_time, $end_time) = $this->changeDateToTimeStampAboutRange($data['crt_time'],false);
-        if ($start_time === null || $end_time === null || $start_time > $end_time) return [false, "同步时间:时间区间无效"];
-        list($bool, $bool_msg) = $this->isOverThreeMonths($start_time, $end_time);
-        if(! $bool) return [false, $bool_msg];
-        $data['start_timeStamp'] = $start_time;
-        $data['end_timeStamp'] = $end_time;
-        $data['start_time'] = strtotime(date("Y-m-01",$data['start_timeStamp']));
-        $data['end_time'] = strtotime(date("Y-m-01"),$data['end_timeStamp']);
-        $data['operation_time'] = time();
-        $data['type'] = 5;
-
-        list($status,$msg) = $this->limitingSendRequest($this->table_2);
-        if(! $status) return [false, '业务员工资同步正在后台运行,请稍后'];
-
-        //同步
-//        list($status, $msg) = $this->synSalaryEmployeeFromMine($data, $user);
-//        if(! $status) {
-//            $this->dellimitingSendRequest($this->table_2);
-//            return [false, $msg];
-//        }
-
-        //队列
-        ProcessDataJob::dispatch($data, $user, 2)->onQueue(RevenueCost::job2);
-
-        return [true, '业务员工资相关信息同步已进入后台任务'];
-    }
-
-    public function synSalaryEmployeeFromMine($data, $user){
-        //创建临时表 如果不存在
-        $this->createTmpTable2();
-        //清理临时表 如果内容不为空
-        $this->clearTmpTable(2);
-
-        //写入临时表
-        DB::table('revenue_cost')
-            ->where('del_time', 0)
-            ->where('order_type', RevenueCost::ORDER_THREE)
-            ->where('order_time','>=',$data['start_timeStamp'])
-            ->where('order_time','<=',$data['end_timeStamp'])
-            ->select([
-                'employee_id_1',
-                'employee_id_1_title',
-                'order_time as time',
-                DB::raw("DATE_FORMAT(FROM_UNIXTIME(order_time), '%Y-%m-01') as order_time"),
-                DB::raw("SUM(payment_amount) as payment_amount"),
-                DB::raw("SUM(CASE WHEN is_activity = 0 THEN payment_amount ELSE 0 END) as payment_amount_not_include_activity"),
-                DB::raw("SUM(CASE WHEN is_activity = 1 THEN payment_amount ELSE 0 END) as payment_amount_activity"),
-                DB::raw("SUM(CASE WHEN profit_rate < customer_profit_rate and is_activity = 0 THEN payment_amount ELSE 0 END) as payment_amount_lower_than_rate"),
-                DB::raw("SUM(CASE WHEN profit_rate >= customer_profit_rate and is_activity = 0 THEN payment_amount ELSE 0 END) as payment_amount_greater_than_rate"),
-                DB::raw("SUM(CASE WHEN profit_rate >= customer_profit_rate and is_activity = 0 THEN price_4_total ELSE 0 END) as business"),
-                DB::raw("ROW_NUMBER() OVER (ORDER BY MIN(id)) as fake_id")
-            ])
-            ->groupBy('employee_id_1', DB::raw("DATE_FORMAT(FROM_UNIXTIME(order_time), '%Y-%m-01')"))
-            ->orderBy('order_time', 'desc')
-            ->chunkById(500, function ($data){
-                $dataArray = Collect($data)->map(function ($object){
-                    return (array)$object;
-                })->toArray();
-
-                $indexes = $this->getEmployeeIndex($dataArray);
-                foreach ($dataArray as $key => $value){
-                    $value['index_' . EmployeeIndex::TYPE_ONE] = 0;
-                    $value['index_' . EmployeeIndex::TYPE_SIX] = 0;
-                    $value['index_' . EmployeeIndex::TYPE_EIGHT] = 0;
-                    $this->findIndex($indexes, $value);
-
-                    $dataArray[$key]['order_type'] = RevenueCost::ORDER_THREE;
-                    $dataArray[$key]['order_time'] = strtotime($value['order_time']);
-                    $dataArray[$key]['sale_bonus'] = $value['index_' . EmployeeIndex::TYPE_EIGHT];
-                    $dataArray[$key]['index_' . EmployeeIndex::TYPE_ONE] = $value['index_' . EmployeeIndex::TYPE_ONE];
-                    $rate = bcdiv($value['index_' . EmployeeIndex::TYPE_ONE],100,2);
-                    $pay_in_advance = bcmul($rate, $value['payment_amount_greater_than_rate'],2);
-                    $dataArray[$key]['pay_in_advance'] = $pay_in_advance;
-                    $dataArray[$key]['basic_salary'] = $value['index_' . EmployeeIndex::TYPE_SIX];
-                    $dataArray[$key]['should_pay'] = bcadd(bcadd($value['index_' . EmployeeIndex::TYPE_EIGHT], $pay_in_advance,2),$value['index_' . EmployeeIndex::TYPE_SIX],2);
-
-                    unset($dataArray[$key]['fake_id']);
-                    unset($dataArray[$key]['time']);
-                }
-
-                DB::table($this->table_2)->insert($dataArray);
-            }, 'fake_id');
-
-        //更新数据
-        list($status,$msg) = $this->updateSalaryEmployee($data);
-        if(! $status) return [false, $msg];
-
-        //清理临时表 如果内容不为空
-        $this->clearTmpTable(2);
-        //释放redis
-        $this->delTableKey(2);
-
-        return [true, '同步成功'];
-    }
-
-    private function getEmployeeIndex($existingData)
-    {
-        if (empty($existingData)) {
-            return collect();
-        }
-
-        // 取出所有涉及的 employee_id 和时间区间
-        $employeeIds = array_column($existingData, 'employee_id_1');
-        $time = array_column($existingData, 'time');
-        $minStart = ! empty($time) ? min($time) : 0;
-        $maxEnd   = ! empty($time) ? max($time) : 0;
-
-        // 一次性查出这些员工在最大区间范围内的所有指标
-        $results = EmployeeIndex::where('del_time', 0)
-            ->whereIn('type', [EmployeeIndex::TYPE_ONE, EmployeeIndex::TYPE_EIGHT, EmployeeIndex::TYPE_SIX])
-            ->whereIn('employee_id', $employeeIds)
-            ->where('start_time', '<=', $maxEnd)
-            ->where('end_time', '>=', $minStart)
-            ->select('start_time','end_time','employee_id','index','type')
-            ->get();
-
-        return $results;
-    }
-
-    private function findIndex($indexes, &$value){
-        // 找到所有符合条件的 index(可能多个 type)
-        $matchedIndexes = $indexes->filter(function ($item) use ($value) {
-            return $item['employee_id'] == $value['employee_id_1']
-                && $item['start_time'] <= $value['time']
-                && $item['end_time'] >= $value['time'];
-        });
-        // 按 type 去重,只保留第一次出现的
-        $uniqueByType = [];
-        foreach ($matchedIndexes as $item) {
-            $index = "index_" . $item['type'];
-            if (! isset($uniqueByType[$index])) {
-                $uniqueByType[$index] = $item['index'];
-            }
-        }
-        $value = array_merge($value, $uniqueByType);
-    }
-
-    private function createTmpTable2(){
-        $table = $this->table_2;
-        if (! Schema::hasTable($table)) {
-            // 可以通过 migration 创建,或程序启动时检查
-            Schema::create($table, function (Blueprint $table) {
-                $table->bigIncrements('id'); // BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY
-                $table->integer('order_type')->default(0);
-                $table->integer('order_time')->default(0);
-                $table->string('employee_id_1_title', 100)->default('');
-                $table->bigInteger('employee_id_1')->default(0);
-                $table->decimal('payment_amount', 12, 2)->default(0);
-                $table->decimal('payment_amount_not_include_activity', 12, 2)->default(0);
-                $table->decimal('payment_amount_activity', 12, 2)->default(0);
-                $table->decimal('payment_amount_lower_than_rate', 12, 2)->default(0);
-                $table->decimal('payment_amount_greater_than_rate', 12, 2)->default(0);
-                $table->decimal('business', 12, 2)->default(0);
-                $table->decimal('sale_bonus', 12, 2)->default(0);
-                $table->decimal('index_1', 10, 2)->default(0);
-                $table->decimal('pay_in_advance', 12, 2)->default(0);
-                $table->decimal('basic_salary', 12, 2)->default(0);
-                $table->decimal('should_pay', 12, 2)->default(0);
-            });
-        }
-    }
-
-    private function updateSalaryEmployee($data){
-        try {
-            $start_timeStamp = $data['start_time'];
-            $end_timeStamp = $data['end_time'];
-            $tmpTable = $this->table_2;
-            $time = time();
-            $ergs = $data;
-
-            DB::transaction(function () use ($start_timeStamp, $end_timeStamp, $tmpTable,$time, $ergs) {
-                // 1. 先软删除旧数据(你已有)
-                SalaryEmployee::where('del_time', 0)
-                    ->where('order_time', '>=', $start_timeStamp)
-                    ->where('order_time', '<=', $end_timeStamp)
-                    ->update(['del_time' => $time]);
-
-                // 2. 分批从临时表插入新数据
-                $batchSize = 500;
-                $lastId = 0;
-                do {
-                    $chunk = DB::table($tmpTable)
-                        ->where('id', '>', $lastId)
-                        ->orderBy('id')
-                        ->limit($batchSize)
-                        ->get();
-
-                    if ($chunk->isEmpty()) {
-                        break;
-                    }
-
-                    $data = $chunk->map(function ($item) use($time){
-                        return [
-                            'order_type' => $item->order_type,
-                            'order_time' => $item->order_time,
-                            'employee_id_1_title' => $item->employee_id_1_title,
-                            'employee_id_1' => $item->employee_id_1 ?? 0,
-                            'payment_amount' => $item->payment_amount,
-                            'payment_amount_not_include_activity' => $item->payment_amount_not_include_activity,
-                            'payment_amount_activity' => $item->payment_amount_activity,
-                            'payment_amount_lower_than_rate' => $item->payment_amount_lower_than_rate,
-                            'payment_amount_greater_than_rate' => $item->payment_amount_greater_than_rate,
-                            'business' => $item->business,
-                            'sale_bonus' => $item->sale_bonus,
-                            'index_1' => $item->index_1,
-                            'pay_in_advance' => $item->pay_in_advance,
-                            'basic_salary' => $item->basic_salary,
-                            'should_pay' => $item->should_pay,
-                            'crt_time' => $time,
-                        ];
-                    })->toArray();
-
-                    // 每批单独插入(可选:加小事务)
-                    SalaryEmployee::insert($data);
-
-                    // 更新 lastId
-                    $lastId = $chunk->last()->id;
-
-                } while ($chunk->count() == $batchSize);
-            });
-        }catch  (\Throwable $exception){
-            return [false, "单据明细同步异常" . $exception->getMessage() . "|" . $exception->getLine() . "|" . $exception->getFile()];
-        }
-
-        return [true, ''];
-    }
-
-    public function synFreightFee($data, $user){
-        if(empty($data['crt_time'][0]) || empty($data['crt_time'][1])) return [false, '同步时间不能为空'];
-        list($start_time, $end_time) = $this->changeDateToTimeStampAboutRange($data['crt_time'],false);
-        if ($start_time === null || $end_time === null || $start_time > $end_time) return [false, "同步时间:时间区间无效"];
-        list($bool, $bool_msg) = $this->isOverThreeMonths($start_time, $end_time);
-        if(! $bool) return [false, $bool_msg];
-        $data['start_timeStamp'] = $start_time;
-        $data['end_timeStamp'] = $end_time;
-        $start = date('Y-m-d H:i:s.000', $start_time);
-        $end = date('Y-m-d H:i:s.000', $end_time);
-        $data['start_time'] = $start;
-        $data['end_time'] = $end;
-        $data['operation_time'] = time();
-        $data['type'] = 6;
-
-//        list($status, $msg) = $this->synFreightFeeFromMine($data, $user);dd($status, $msg);
-        list($status,$msg) = $this->limitingSendRequest($this->table_3);
-        if(! $status) return [false, '运费统计同步正在后台运行,请稍后'];
-
-        //同步
-//        list($status, $msg) = $this->synFreightFeeFromMine($data, $user);
-//        if(! $status) {
-//            $this->dellimitingSendRequest($this->table_3);
-//            return [false, $msg];
-//        }
-
-        //队列
-        ProcessDataJob::dispatch($data, $user, 3)->onQueue(RevenueCost::job3);
-
-        return [true, '运费统计同步已进入后台任务'];
-    }
-
-    public function synFreightFeeFromMine($data, $user){
-        //创建临时表 如果不存在
-        $this->createTmpTable3();
-        //清理临时表 如果内容不为空
-        $this->clearTmpTable(3);
-
-        //生成临时数据
-        list($status, $msg) = $this->getFreightData($data);
-        if(! $status) return [false, $msg];
-
-        //写入
-        list($status, $msg) = $this->updateFreightFeeFromMine($data);
-        if(! $status) return [false, $msg];
-
-        //清理临时表 如果内容不为空
-        $this->clearTmpTable(3);
-        //释放redis
-        $this->delTableKey(3);
-
-        return [true, '同步成功'];
-    }
-
-    private function createTmpTable3(){
-        $table = $this->table_3;
-        if (! Schema::hasTable($table)) {
-            // 可以通过 migration 创建,或程序启动时检查
-            Schema::create($table, function (Blueprint $table) {
-                // 主键
-                $table->bigIncrements('id');
-                // 原始字段
-                $table->bigInteger('order_id')->default(0)->comment('订单ID');
-                $table->string('order_number')->default('')->comment('订单编号');
-                $table->dateTime('order_time')->nullable()->comment('订单时间');
-                $table->integer('order_state')->default(0)->comment('订单状态');
-                $table->string('employee_id_1_title')->default('')->comment('业务员1名称');
-                $table->bigInteger('employee_id_1')->default(0)->comment('业务员1 ID');
-                $table->string('employee_id_2_title')->default('')->comment('上级管理人员名称');
-                $table->bigInteger('employee_id_2')->default(0)->comment('上级管理人员ID');
-                $table->string('customer_code')->default('')->comment('客户编码');
-                $table->string('customer_title')->default('')->comment('客户名称');
-                $table->decimal('customer_store_price', 10, 2)->default(0)->comment('客户卸货费单价');
-                $table->string('product_code')->default('')->comment('产品编码');
-                $table->string('product_title')->default('')->comment('产品名称');
-                $table->string('product_size')->default('')->comment('产品规格');
-                $table->decimal('product_box_size', 10, 2)->default(0)->comment('装箱数');
-                $table->decimal('product_weight', 10, 3)->default(0)->comment('单件重量(kg)');
-                $table->decimal('product_store_price', 10, 2)->default(0)->comment('门店卸货费单价');
-                $table->decimal('product_store_price2', 10, 2)->default(0)->comment('到货装卸费单价');
-                $table->string('product_category')->default('')->comment('货类');
-                $table->string('unit')->default('')->comment('单位');
-                $table->decimal('quantity', 12, 3)->default(0)->comment('数量');
-                $table->decimal('price_3', 12, 2)->default(0)->comment('含税单价');
-                $table->decimal('price_3_total', 14, 2)->default(0)->comment('含税金额');
-                $table->bigInteger('id_detail')->default(0)->comment('明细ID');
-                $table->boolean('is_present')->default(false)->comment('是否赠品');
-                $table->string('mark')->default('')->comment('订单备注');
-                $table->string('item_mark')->default('')->comment('明细备注');
-                $table->bigInteger('warehouse_id')->default(0)->comment('仓库ID');
-                $table->string('warehouse_name')->default('')->comment('仓库名称');
-                $table->bigInteger('business_type_id')->default(0)->comment('业务类型ID');
-                $table->string('business_type_title')->default('')->comment('业务类型名称');
-                $table->string('address')->default('')->comment('送货地址');
-                $table->string('area_hs')->default('')->comment('区域');
-                $table->string('delivery_mode')->default('')->comment('配送方式');
-                $table->decimal('sl_fee', 10, 2)->default(0)->comment('上楼费');
-                // 新增的计算字段
-                $table->integer('xs')->default(0)->comment('箱数');
-                $table->decimal('weight', 12, 4)->default(0)->comment('总重量(kg)');
-                $table->tinyInteger('area_range')->default(1)->comment('运价区间 (1: <5kg, 2: >=5kg)');
-                $table->decimal('freight_unit_price', 10, 2)->default(0)->comment('配送费单价');
-                $table->decimal('freight_amount', 12, 4)->default(0)->comment('配送费金额');
-                $table->decimal('js_single_amount', 12, 4)->default(0)->comment('结算金额');
-                $table->decimal('min_freight_amount', 12, 2)->default(0)->comment('地区最低运价');
-                $table->decimal('customer_store_zx_fee', 12, 4)->default(0)->comment('门店卸货费');
-                $table->decimal('dh_fee', 12, 4)->default(0)->comment('到货装卸费');
-            });
-        }
-    }
-
-    private function getFreightData($data){
-        //写入临时表
-        try {
-            $table = $this->table_3;
-            $limit = 500;
-            $lastId = 0;
-
-            do {
-                $rows = $this->databaseService->table('SA_SaleDelivery_b as sd_b')
-                    ->join('SA_SaleDelivery as sd', 'sd_b.idSaleDeliveryDTO', '=', 'sd.ID')
-                    ->leftJoin('AA_Partner as pn', 'sd.idcustomer', '=', 'pn.ID') // 客户
-                    ->leftJoin('AA_Person as ps', 'sd.idclerk', '=', 'ps.ID') // 业务员
-                    ->leftJoin('AA_Person as ps2', 'pn.idsaleman', '=', 'ps2.ID')
-                    ->leftJoin('AA_Inventory as it', 'sd_b.idinventory', '=', 'it.ID')
-                    ->leftJoin('AA_Unit as ui', 'sd_b.idbaseunit', '=', 'ui.ID')
-                    ->leftJoin('AA_Warehouse as wa', 'sd_b.idwarehouse', '=', 'wa.id')
-                    ->leftJoin('AA_Busitype as bs', 'sd.idbusinesstype', '=', 'bs.id')
-                    ->where('sd.voucherdate', '>=', $data['start_time'])
-                    ->where('sd.voucherdate', '<=', $data['end_time'])
-                    ->where('sd.voucherState', '=', 189) //181  未审核   189  已审核
-                    ->where('sd_b.ID', '>', $lastId) // 用真实字段
-                    ->orderBy('sd_b.ID')
-                    ->limit($limit)
-                    ->selectRaw("
-                        COALESCE(sd.ID, 0) as order_id,
-                        COALESCE(sd.code, '') as order_number,
-                        sd.voucherdate as order_time,
-                        sd.voucherState as order_state,
-                        COALESCE(ps.name, '') as employee_id_1_title,
-                        COALESCE(sd.idclerk, 0) as employee_id_1,
-                        COALESCE(ps2.name, '') as employee_id_2_title,
-                        COALESCE(pn.idsaleman, 0) as employee_id_2,
-                        COALESCE(pn.code, '') as customer_code,
-                        COALESCE(pn.name, '') as customer_title,
-                        COALESCE(pn.priuserdefdecm3, 0) as customer_store_price,
-                        COALESCE(it.code, '') as product_code,
-                        COALESCE(it.name, '') as product_title,
-                        COALESCE(it.specification, '') as product_size,
-                        COALESCE(it.priuserdefdecm1, 0) as product_box_size,
-                        COALESCE(it.priuserdefdecm3, 0) as product_weight,
-                        COALESCE(it.priuserdefdecm10, 0) as product_store_price,
-                        COALESCE(it.priuserdefdecm11, 0) as product_store_price2,
-                        COALESCE(it.priuserdefnvc5, '') as product_category,
-                        COALESCE(ui.name, '') as unit,
-                        COALESCE(sd_b.quantity, 0) as quantity,
-                        COALESCE(sd_b.taxPrice, 0) as price_3,
-                        COALESCE(sd_b.taxAmount, 0) as price_3_total,
-                        COALESCE(sd_b.ID, 0) as id_detail,
-                        COALESCE(sd_b.isPresent, 0) as is_present,
-                        COALESCE(sd_b.DetailMemo, '') as item_mark,
-                        COALESCE(sd.memo, '') as mark,
-                        sd_b.idwarehouse as warehouse_id,
-                        COALESCE(wa.name, '') as warehouse_name,
-                        sd.idbusinesstype as business_type_id,
-                        COALESCE(bs.name , '') as business_type_title,
-                        COALESCE(sd.address , '') as address,
-                        COALESCE(sd.priuserdefnvc2 , '') as area_hs,
-                        COALESCE(sd.deliveryMode , 0) as delivery_mode,
-                        COALESCE(sd.priuserdefdecm5 , 0) as sl_fee
-                    ")
-                    ->get();
-
-                if ($rows->isEmpty()) break;
-
-                $dataArray = Collect($rows)->map(function ($object) {
-                    return (array)$object;
-                })->toArray();
-
-                $freight = Organization::where('del_time',0)
-                    ->whereIn('region',array_column($dataArray,'area_hs'))
-                    ->select('region','one_and_five','greater_than_five','min_freight_fee')
-                    ->get()->toArray();
-                $freight_map = array_column($freight,null,'region');
-
-                //组织数据
-                foreach ($dataArray as $key => $value) {
-                    $quantity = abs($value['quantity']);
-                    //箱数
-                    $xs = 0;
-                    if(! empty($value['product_box_size']) && is_numeric($value['product_box_size']) && $value['product_box_size'] > 0) $xs = ceil($quantity / $value['product_box_size']);
-                    $dataArray[$key]['xs'] = $xs;
-                    //总重量
-                    $weight = 0;
-                    if(! empty($value['product_weight']) && is_numeric($value['product_weight']) && $value['product_weight'] > 0) $weight = bcdiv(bcmul($xs, $value['product_weight']),1000,4);
-                    $dataArray[$key]['weight'] = $weight;
-                    //运价区间
-                    $area_range = 1;
-                    if($weight >= 5) $area_range = 2;
-                    $dataArray[$key]['area_range'] = $area_range;
-                    //配送费单价
-                    $freight = $min_freight = 0;
-                    if(isset($freight_map[$value['area_hs']])) {
-                        $tmp = $freight_map[$value['area_hs']];
-                        if($area_range == 1){
-                            $freight = $tmp['one_and_five'];
-                        }else{
-                            $freight = $tmp['greater_than_five'];
-                        }
-                        $min_freight = $tmp['min_freight_fee'];
-                    }
-                    $dataArray[$key]['freight_unit_price'] = $freight;
-                    //地区最低运价
-                    $dataArray[$key]['min_freight_amount'] = $min_freight;
-
-                    //纯自提不计算-------------------------------------------------------
-                    if($value['delivery_mode'] == FreightFee::deliveryModeNormal){
-                        //配送费金额
-                        $dataArray[$key]['freight_amount'] = 0;
-                        //结算金额 记录的是每一条的
-                        $dataArray[$key]['js_single_amount'] = 0;
-                        //门店卸货费
-                        $dataArray[$key]['customer_store_zx_fee'] = 0;
-                        //到货装卸费
-                        $dataArray[$key]['dh_fee'] = 0;
-                    }else{
-                        //配送费金额
-                        $freight_amount = bcmul($weight, $freight,4);
-                        $dataArray[$key]['freight_amount'] = $freight_amount;
-                        //结算金额 记录的是每一条的
-                        $dataArray[$key]['js_single_amount'] = $freight_amount;
-                        //门店卸货费
-                        $customer_store_price = 0;
-                        if(! empty($value['customer_store_price']) && is_numeric($value['customer_store_price']) && $value['customer_store_price'] > 0){
-                            $customer_store_price = bcmul($value['customer_store_price'], $xs,4);
-                        }else{
-                            if(! empty($value['product_store_price']) && is_numeric($value['product_store_price']) && $value['product_store_price'] > 0){
-                                $customer_store_price = bcmul($value['product_store_price'], $xs,4);
-                            }
-                        }
-                        $dataArray[$key]['customer_store_zx_fee'] = $customer_store_price;
-                        //到货装卸费
-                        $product_store_price2 = 0;
-                        if(! empty($value['product_store_price2']) && is_numeric($value['product_store_price2']))  $product_store_price2 = $value['product_store_price2'];
-                        if(! empty($value['product_category']) && $value['product_category'] == "礼盒"){
-                            $dh_fee = bcmul($xs, $product_store_price2,4);
-                        }else{
-                            $dh_fee = bcmul($weight, $product_store_price2,4);
-                        }
-                        if($value['business_type_id'] == FreightFee::businessTypeReturn) $dh_fee = bcmul($dh_fee,2,4);
-                        $dataArray[$key]['dh_fee'] = $dh_fee;
-                    }
-                }
-
-                DB::table($table)->insert($dataArray);
-
-                // 更新 lastId 继续下一批
-                $lastId = end($dataArray)['id_detail'] ?? $lastId;
-
-            } while (count($rows) === $limit);
-        }catch  (\Throwable $exception){
-            return [false, "运费获取销货单数据异常" . $exception->getMessage() . "|" . $exception->getLine() . "|" . $exception->getFile()];
-        }
-
-        return [true, ''];
-    }
-
-    private function updateFreightFeeFromMine($data){
-        try {
-            $start_timeStamp = $data['start_timeStamp'];
-            $end_timeStamp = $data['end_timeStamp'];
-            $tmpTable = $this->table_3;
-            $time = time();
-            $ergs = $data;
-
-            DB::transaction(function () use ($start_timeStamp, $end_timeStamp, $tmpTable,$time, $ergs) {
-                // 1. 先软删除旧数据(你已有)
-                FreightFee::where('del_time', 0)
-                    ->where('order_time', '>=', $start_timeStamp)
-                    ->where('order_time', '<=', $end_timeStamp)
-                    ->update(['del_time' => $time]);
-
-                // 2. 分批从临时表插入新数据
-                $batchSize = 500;
-                $lastId = 0;
-                do {
-                    $chunk = DB::table($tmpTable)
-                        ->where('id', '>', $lastId)
-                        ->orderBy('id')
-                        ->limit($batchSize)
-                        ->get();
-
-                    if ($chunk->isEmpty()) {
-                        break;
-                    }
-
-                    $data = $chunk->map(function ($item) use($time){
-                        return [
-                            // 基础字段(按你给的顺序)
-                            'order_id' => $item->order_id ?? 0,
-                            'order_number' => $item->order_number ?? '',
-                            'order_time' => $item->order_time ? strtotime($item->order_time) : 0,
-                            'order_state' => $item->order_state ?? 0,
-                            'employee_id_1_title' => $item->employee_id_1_title ?? '',
-                            'employee_id_1' => $item->employee_id_1 ?? 0,
-                            'employee_id_2_title' => $item->employee_id_2_title ?? '',
-                            'employee_id_2' => $item->employee_id_2 ?? 0,
-                            'customer_code' => $item->customer_code ?? '',
-                            'customer_title' => $item->customer_title ?? '',
-                            'customer_store_price' => $item->customer_store_price ?? 0,
-                            'product_code' => $item->product_code ?? '',
-                            'product_title' => $item->product_title ?? '',
-                            'product_size' => $item->product_size ?? '',
-                            'product_box_size' => $item->product_box_size ?? 0,
-                            'product_weight' => $item->product_weight ?? 0,
-                            'product_store_price' => $item->product_store_price ?? 0,
-                            'product_store_price2' => $item->product_store_price2 ?? 0,
-                            'product_category' => $item->product_category ?? '',
-                            'unit' => $item->unit ?? '',
-                            'quantity' => $item->quantity ?? 0,
-                            'price_3' => $item->price_3 ?? 0,
-                            'price_3_total' => $item->price_3_total ?? 0,
-                            'id_detail' => $item->id_detail ?? 0,
-                            'is_present' => $item->is_present ?? '',
-                            'mark' => $item->mark ?? '',
-                            'item_mark' => $item->item_mark ?? '',
-                            'warehouse_id' => $item->warehouse_id ?? 0,
-                            'warehouse_name' => $item->warehouse_name ?? '',
-                            'business_type_id' => $item->business_type_id ?? 0,
-                            'business_type_title' => $item->business_type_title ?? '',
-                            'address' => $item->address ?? '',
-                            'area_hs' => $item->area_hs ?? '',
-                            'delivery_mode' => $item->delivery_mode ?? 0,
-                            'sl_fee' => $item->sl_fee ?? 0,
-                            'xs' => $item->xs,
-                            'weight' => $item->weight ?? 0,
-                            'area_range' => $item->area_range ?? 0,
-                            'freight_unit_price' => $item->freight_unit_price ?? 0,
-                            'freight_amount' => $item->freight_amount ?? 0,
-                            'js_single_amount' => $item->js_single_amount ?? 0,
-                            'min_freight_amount' => $item->min_freight_amount ?? 0,
-                            'customer_store_zx_fee' => $item->customer_store_zx_fee ?? 0,
-                            'dh_fee' => $item->dh_fee ?? 0,
-                            'crt_time' => $time,
-                        ];
-                    })->toArray();
-
-                    // 每批单独插入(可选:加小事务)
-                    FreightFee::insert($data);
-
-                    // 更新 lastId
-                    $lastId = $chunk->last()->id;
-
-                } while ($chunk->count() == $batchSize);
-            });
-        }catch  (\Throwable $exception){
-            return [false, "单据明细同步异常" . $exception->getMessage() . "|" . $exception->getLine() . "|" . $exception->getFile()];
-        }
-
-        return [true, ''];
-    }
-}

+ 0 - 35
config/excel/giveOutTable.php

@@ -1,35 +0,0 @@
-<?php
-return [
-    [
-        'key' =>'employee_id_1_title',
-        'value' => '业务员名',
-        'required' => true,
-        'default' => "",
-        'comments' => '人员名称',
-    ],
-    [
-        'key' =>'send_time',
-        'value' => '发放日期',
-        'required' => true,
-        'default' => "",
-    ],
-    [
-        'key' =>'belong_time',
-        'value' => '归属日期',
-        'required' => true,
-        'default' => "",
-        'comments' => '时间段(2025-01-03|2025-01-05),时间(2025-01-03)',
-    ],
-    [
-        'key' =>'give_out_amount',
-        'value' => '分红已发放金额',
-        'required' => true,
-        'default' => 0,
-    ],
-    [
-        'key' =>'mark',
-        'value' => '备注',
-        'required' => false,
-        'default' => "",
-    ],
-];

+ 0 - 74
config/excel/productTable.php

@@ -1,74 +0,0 @@
-<?php
-return [
-    [
-        'key' =>'code',
-        'value' => '存货编码',
-        'required' => true,
-        'unique' => true,
-    ],
-    [
-        'key' =>'title',
-        'value' => '存货名称',
-        'required' => true,
-    ],
-    [
-        'key' =>'size',
-        'value' => '规格型号',
-        'required' => false,
-        'default' => "",
-    ],
-    [
-        'key' =>'category',
-        'value' => '所属类别',
-        'required' => false,
-        'default' => "",
-    ],
-    [
-        'key' =>'unit',
-        'value' => '计量单位',
-        'required' => false,
-        'default' => "",
-    ],
-    [
-        'key' =>'cost',
-        'value' => '成本单价',
-        'required' => false,
-        'default' => 0,
-    ],
-    [
-        'key' =>'business_cost',
-        'value' => '业务成本单价',
-        'required' => false,
-        'default' => 0,
-    ],
-    [
-        'key' =>'major_client_settlement_price',
-        'value' => '大客户结算单价',
-        'required' => false,
-        'default' => 0,
-    ],
-    [
-        'key' =>'write_off_price',
-        'value' => '核销单价',
-        'required' => false,
-        'default' => 0,
-    ],
-    [
-        'key' => 'return_change_price',
-        'value' => '退货损耗单价',
-        'required' => false,
-        'default' => 0,
-    ],
-    [
-        'key' => 'freight_price',
-        'value' => '运费单价',
-        'required' => false,
-        'default' => 0,
-    ],
-    [
-        'key' => 'mark',
-        'value' => '备注',
-        'required' => false,
-        'default' => "",
-    ],
-];

+ 25 - 1
config/header/62.php

@@ -15,9 +15,33 @@ return [
         'value' => '组织名称',
     ],
     [
-        'key' =>'industry',
+        'key' =>'type_title',
+        'value' => '类型',
+    ],
+    [
+        'key' =>'decision_depart',
+        'value' => '决策部门',
+    ],
+    [
+        'key' =>'decision_maker',
+        'value' => '决策人',
+    ],
+    [
+        'key' =>'industry_name',
         'value' => '行业名称',
     ],
+    [
+        'key' =>'industry_ranking',
+        'value' => '行业排名',
+    ],
+    [
+        'key' =>'address',
+        'value' => '地点',
+    ],
+    [
+        'key' =>'founding_time',
+        'value' => '成立时间',
+    ],
     [
         'key' =>'crt_name',
         'value' => '创建人',

+ 12 - 16
config/header/66.php

@@ -7,31 +7,27 @@
 
 return [
     [
-        'key' =>'area',
-        'value' => '所属区域',
+        'key' =>'code',
+        'value' => '编码',
     ],
     [
-        'key' =>'region',
-        'value' => '地区',
+        'key' =>'title',
+        'value' => '名称',
     ],
     [
-        'key' =>'kilometer',
-        'value' => '公里数',
+        'key' =>'type_title',
+        'value' => '类型',
     ],
     [
-        'key' =>'min_freight_fee',
-        'value' => '最低运费',
+        'key' =>'status_title',
+        'value' => '合作状态',
     ],
     [
-        'key' =>'one_and_five',
-        'value' => '1-5吨',
+        'key' =>'crt_name',
+        'value' => '创建人',
     ],
     [
-        'key' =>'greater_than_five',
-        'value' => '5吨以上',
-    ],
-    [
-        'key' =>'company',
-        'value' => '物流公司',
+        'key' =>'crt_title',
+        'value' => '创建时间',
     ],
 ];

+ 29 - 0
config/header/78.php

@@ -0,0 +1,29 @@
+<?php
+/**
+ * '菜单ID' => [
+ *     '字段英文名' =》 '字段中文名'
+ * ]
+ */
+
+return [
+    [
+        'key' =>'code',
+        'value' => '编码',
+    ],
+    [
+        'key' =>'title',
+        'value' => '名称',
+    ],
+    [
+        'key' =>'is_use_title',
+        'value' => '是否启用',
+    ],
+    [
+        'key' =>'crt_name',
+        'value' => '创建人',
+    ],
+    [
+        'key' =>'crt_time',
+        'value' => '创建时间',
+    ],
+];

+ 20 - 33
routes/api.php

@@ -88,13 +88,6 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('employeeRole', 'Api\EmployeeController@employeeRole');
     $route->any('getEmployeeImg', 'Api\EmployeeController@getEmployeeImg');
 
-    //维度选项
-    $route->any('dimensionList', 'Api\DimensionController@dimensionList');
-    $route->any('dimensionEdit', 'Api\DimensionController@dimensionEdit');
-    $route->any('dimensionAdd', 'Api\DimensionController@dimensionAdd');
-    $route->any('dimensionDel', 'Api\DimensionController@dimensionDel');
-    $route->any('dimensionDetail', 'Api\DimensionController@dimensionDetail');
-
     //组织
     $route->any('organizationList', 'Api\OrganizationController@organizationList');
     $route->any('organizationEdit', 'Api\OrganizationController@organizationEdit');
@@ -102,12 +95,26 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('organizationDel', 'Api\OrganizationController@organizationDel');
     $route->any('organizationDetail', 'Api\OrganizationController@organizationDetail');
 
-    //发放
-    $route->any('giveOutList', 'Api\GiveOutController@giveOutList');
-    $route->any('giveOutEdit', 'Api\GiveOutController@giveOutEdit');
-    $route->any('giveOutAdd', 'Api\GiveOutController@giveOutAdd');
-    $route->any('giveOutDel', 'Api\GiveOutController@giveOutDel');
-    $route->any('giveOutDetail', 'Api\GiveOutController@giveOutDetail');
+    //客户供应商
+    $route->any('customerSupplyList', 'Api\CustomerSupplyController@customerSupplyList');
+    $route->any('customerSupplyEdit', 'Api\CustomerSupplyController@customerSupplyEdit');
+    $route->any('customerSupplyAdd', 'Api\CustomerSupplyController@customerSupplyAdd');
+    $route->any('customerSupplyDel', 'Api\CustomerSupplyController@customerSupplyDel');
+    $route->any('customerSupplyDetail', 'Api\CustomerSupplyController@customerSupplyDetail');
+
+    //维度选项
+    $route->any('dimensionList', 'Api\DimensionController@dimensionList');
+    $route->any('dimensionEdit', 'Api\DimensionController@dimensionEdit');
+    $route->any('dimensionAdd', 'Api\DimensionController@dimensionAdd');
+    $route->any('dimensionDel', 'Api\DimensionController@dimensionDel');
+    $route->any('dimensionDetail', 'Api\DimensionController@dimensionDetail');
+
+    //量化
+    $route->any('quantizationList', 'Api\QuantizationController@quantizationList');
+    $route->any('quantizationEdit', 'Api\QuantizationController@quantizationEdit');
+    $route->any('quantizationAdd', 'Api\QuantizationController@quantizationAdd');
+    $route->any('quantizationDel', 'Api\QuantizationController@quantizationDel');
+    $route->any('quantizationDetail', 'Api\QuantizationController@quantizationDetail');
 
     //获取默认表头
     $route->any('getTableHead','Api\TableHeadController@tableHeadGet');
@@ -130,24 +137,4 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('importAll','Api\ImportController@importAll');
     //导出统一方法
     $route->any('exportFile', 'Api\ExportFileController@exportFile');
-
-    //同步T+人员部门结构
-    $route->any('synPersonDepart', 'Api\TPlusController@synPersonDepart');
-    $route->any('synRevenueCost', 'Api\TPlusController@synRevenueCost');
-    $route->any('synSalaryEmployee', 'Api\TPlusController@synSalaryEmployee');
-    $route->any('synFreightFee', 'Api\TPlusController@synFreightFee');
-
-    //收入成本
-    $route->any('statisticsRevenueCost', 'Api\StatisticsController@statisticsRevenueCost');
-    $route->any('statisticsRevenueCostOne', 'Api\StatisticsController@statisticsRevenueCostOne');
-    $route->any('statisticsRevenueCostTwo', 'Api\StatisticsController@statisticsRevenueCostTwo');
-    $route->any('statisticsRevenueCostThree', 'Api\StatisticsController@statisticsRevenueCostThree');
-    $route->any('statisticsRevenueCostThreeDetail', 'Api\StatisticsController@statisticsRevenueCostThreeDetail');
-    //利润分配
-    $route->any('statisticsProfit', 'Api\StatisticsController@statisticsProfit');
-    //业务员工资
-    $route->any('statisticsEmployeeSalary', 'Api\StatisticsController@statisticsEmployeeSalary');
-    //运费
-    $route->any('statisticsFreightFee', 'Api\StatisticsController@statisticsFreightFee');
-    $route->any('statisticsFreightFeeDetail', 'Api\StatisticsController@statisticsFreightFeeDetail');
 });