Browse Source

得润宝

cqp 2 tuần trước cách đây
mục cha
commit
1bbd7476d1

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

@@ -1,76 +0,0 @@
-<?php
-
-namespace App\Http\Controllers\Api;
-
-use App\Service\FreightService;
-use Illuminate\Http\Request;
-
-class FreightController extends BaseController
-{
-    public function freightEdit(Request $request)
-    {
-        $service = new FreightService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->freightEdit($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function freightAdd(Request $request)
-    {
-        $service = new FreightService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->freightAdd($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-
-    }
-
-    public function freightDel(Request $request)
-    {
-        $service = new FreightService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->freightDel($request->all());
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-
-    }
-
-    public function freightList(Request $request)
-    {
-        $service = new FreightService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->freightList($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function freightDetail(Request $request)
-    {
-        $service = new FreightService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->freightDetail($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-}

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

@@ -1,76 +0,0 @@
-<?php
-
-namespace App\Http\Controllers\Api;
-
-use App\Service\GiveOutService;
-use Illuminate\Http\Request;
-
-class GiveOutController extends BaseController
-{
-    public function giveOutEdit(Request $request)
-    {
-        $service = new GiveOutService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->giveOutEdit($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function giveOutAdd(Request $request)
-    {
-        $service = new GiveOutService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->giveOutAdd($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-
-    }
-
-    public function giveOutDel(Request $request)
-    {
-        $service = new GiveOutService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->giveOutDel($request->all());
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-
-    }
-
-    public function giveOutList(Request $request)
-    {
-        $service = new GiveOutService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->giveOutList($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function giveOutDetail(Request $request)
-    {
-        $service = new GiveOutService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->giveOutDetail($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-}

+ 0 - 129
app/Http/Controllers/Api/ProductController.php

@@ -1,129 +0,0 @@
-<?php
-
-namespace App\Http\Controllers\Api;
-
-
-use App\Service\ProductService;
-use Illuminate\Http\Request;
-
-class ProductController extends BaseController
-{
-    public function productCategoryEdit(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->productCategoryEdit($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-    
-    public function productCategoryAdd(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->productCategoryAdd($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-    
-    public function productCategoryDel(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->productCategoryDel($request->all());
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function productCategoryList(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->productCategoryList($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function productEdit(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->productEdit($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function productAdd(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->productAdd($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-
-    }
-
-    public function productDel(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->productDel($request->all());
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-
-    }
-
-    public function productList(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->productList($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function productDetail(Request $request)
-    {
-        $service = new ProductService();
-        $user = $request->userData->toArray();
-        list($status,$data) = $service->productDetail($request->all(),$user);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-}

+ 0 - 81
app/Http/Controllers/Api/StatisticsController.php

@@ -1,81 +0,0 @@
-<?php
-
-namespace App\Http\Controllers\Api;
-
-use App\Service\StatisticsService;
-use Illuminate\Http\Request;
-
-class StatisticsController extends BaseController
-{
-    public function statisticsRevenueCost(Request $request){
-        $service = new StatisticsService();
-        $userData = $request->userData->toArray();
-        list($status,$data) = $service->statisticsRevenueCost($request->all(),$userData);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function statisticsRevenueCostOneAndTwo(Request $request){
-        $service = new StatisticsService();
-        $userData = $request->userData->toArray();
-        list($status,$data) = $service->statisticsRevenueCostOneAndTwo($request->all(),$userData);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function statisticsRevenueCostThree(Request $request){
-        $service = new StatisticsService();
-        $userData = $request->userData->toArray();
-        list($status,$data) = $service->statisticsRevenueCostThree($request->all(),$userData);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function statisticsRevenueCostThreeDetail(Request $request){
-        $service = new StatisticsService();
-        $userData = $request->userData->toArray();
-        list($status,$data) = $service->statisticsRevenueCostThreeDetail($request->all(),$userData);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function statisticsProfit(Request $request){
-        $service = new StatisticsService();
-        $userData = $request->userData->toArray();
-        list($status,$data) = $service->statisticsProfit($request->all(),$userData);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function statisticsEmployeeSalary(Request $request){
-        $service = new StatisticsService();
-        $userData = $request->userData->toArray();
-        list($status,$data) = $service->statisticsEmployeeSalary($request->all(),$userData);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-}

+ 0 - 37
app/Http/Middleware/CheckWeinxin.php

@@ -1,37 +0,0 @@
-<?php
-
-namespace App\Http\Middleware;
-
-use App\Model\WxEmployeeOfficial;
-use App\Service\EmployeeService;
-use Closure;
-use Illuminate\Http\Request;
-
-class CheckWeinxin
-{
-    /**
-     * Handle an incoming request.
-     *
-     * @param  Request  $request
-     * @param Closure $next
-     * @return mixed
-     */
-    public function handle($request, Closure $next)
-    {
-        $token = $request->header('ciphertext');
-        if (empty($token)) return response()->json(['code'=>401,'msg'=>'缺少openid','data'=>null]);
-
-        //校验openid是否绑定
-        $employee = new WxEmployeeOfficial();
-        $employee_id = $employee->where('openid',$token)->value('employee_id');
-        if ($employee_id < 0) return response()->json(['code'=>401,'msg'=>'用户信息错误!','data'=>null]);
-
-        //校验用户
-        $checkResult = EmployeeService::checkWxUser($employee_id);
-        list($state, $data) = $checkResult;
-        if(! $state) return response()->json(['code'=>401,'msg'=>$data,'data'=>null]);
-        $request->userData = $data;
-
-        return $next($request);
-    }
-}

+ 0 - 128
app/Http/Middleware/CheckWx.php

@@ -1,128 +0,0 @@
-<?php
-
-namespace App\Http\Middleware;
-
-use App\Model\Employee;
-use App\Model\ProductInventorySet;
-use App\Model\WxEmployee;
-use App\Service\EmployeeService;
-use App\Service\Wx\WxEmployeeService;
-use Closure;
-
-class CheckWx
-{
-    /**
-     * Handle an incoming request.
-     *
-     * @param  \Illuminate\Http\Request  $request
-     * @param  \Closure  $next
-     * @return mixed
-     */
-    public function handle($request, Closure $next)
-    {
-        $data=$request->all();
-
-        if (!isset($data['openid'])) return response()->json(['code'=> 202,'msg'=>'缺少openid','data'=>null]);
-        $openid = $data['openid'];
-        //校验openid是否绑定
-        $employee = new WxEmployee();
-        $employee = $employee->where('openid',$openid)->first();
-        if (empty($employee)) return response()->json(['code'=> 202,'msg'=>'用户授权信息不存在!','data'=>null]);
-        $employee = $employee->toArray();
-        if (empty($employee['mobile'])) return response()->json(['code'=> 202,'msg'=>'用户手机信息不存在!','data'=>null]);
-        if (empty($employee['employee_id'])) {
-            //找到对应的账号
-            $emp = Employee::where('del_time',0)
-                ->where('mobile',$employee['mobile'])
-                ->where('state',Employee::USE)
-                ->select('id')
-                ->first();
-            if(empty($emp)) return response()->json(['code'=> 202,'msg'=>'用户手机信息未匹配到系统账号,请录入手机号!','data'=>null]);
-            $emp = $emp->toArray();
-            WxEmployee::where('id',$employee['id'])->update(['employee_id' => $emp['id']]);
-            $employee['employee_id'] = $emp['id'];
-        }
-
-        //当前请求接口
-        $uri = $request->path();
-        //不需要校验是否绑定账号的接口
-        $url = config('nocheck');
-
-        if(in_array($uri,$url)){
-            $request->userData = new Employee();
-        }else{
-            $employee_id = $employee['employee_id'];
-            if(empty($employee_id)) return response()->json(['code'=> 202,'msg'=>'用户未绑定账号!','data'=>null]);
-            //校验用户
-            $service = new WxEmployeeService();
-            $checkResult = $service->checkWxUser($employee_id);
-            list($state, $data) = $checkResult;
-            if(! $state) return response()->json(['code'=> 202,'msg'=>$data,'data'=>null]);
-
-            //人员角色
-            $data['role'] = EmployeeService::getPersonRole($employee_id);
-            //角色里所有菜单权限
-            $data['role_authority'] = EmployeeService::getPersonRoleQx($data['role']);
-            //角色里特殊的按钮
-            $data['special_button'] = EmployeeService::getSpecialButton($data['role'],$employee_id);
-
-            //当前门店
-            $userSetTopDepartId = $request->input('userSetTopDepartId');
-            if(empty($userSetTopDepartId)) return response()->json(['code'=>202,'msg'=>'当前门店信息缺失','data'=>null]);
-
-            $return = EmployeeService::getLoginDepart($employee_id, $userSetTopDepartId);
-            //所属部门
-            $data['rule_depart'] = $return[0] ?? [];
-            //顶级公司
-            $data['depart_top'] = $return[1] ?? [];
-            $top = array_column($data['depart_top'],'depart_id');
-            if(! in_array($userSetTopDepartId, $top)) return response()->json(['code'=>202,'msg'=>'当前门店不在权限内,请重新选择!','data'=>null]);
-            //部门对应的顶级公司
-            $data['depart_map'] = $return[2] ?? [];
-            //权限范围内的部门以及公司
-            $data['depart_range'] = $return[3] ?? [];
-            //是否有所有的部门权限
-            $data['is_all_depart'] = $return[4] ?? 0;
-            //总公司
-            $data['head'] = $return[5] ?? [];
-            //当前部门
-            $data['depart_select'] = $return[6] ?? [];
-            //是否库存校验(默认校验)
-            $my_top = $data['depart_top'][0] ?? [];
-            $is_check_stock = empty($my_top['is_stock']) ? ProductInventorySet::type_one : $my_top['is_stock'];
-            $data['is_check_stock'] = $is_check_stock;
-
-            $query = config('morequery');
-            $url = $request->path();
-
-            //菜单ID
-            $menu = $query['menu'] ?? [];
-            if(isset($menu[$url])){
-                $param = $menu[$url];
-                if(is_array($param)){
-                    $key = $param['key'];
-                    $get = $request->input($key);
-                    $menu_id = $param['array'][$get] ?? 0;
-                }else{
-                    $menu_id = $param ?? 0;
-                }
-                $request->merge(['menu_id' => $menu_id]);
-            }
-
-            $menu2 = $query['is_list_search'] ?? [];
-            if(in_array($url, $menu2)) {
-                if(! empty($data['is_list_search']) && ! empty($request->is_list_search)){//列表页呈现
-                    $request->merge(['get_my_top_depart_data' => 0]);
-                }else{//建单据选择
-                    $request->merge(['get_my_top_depart_data' => 1]);
-                }
-            }
-
-            $request->merge(['from_wx' => 1]);
-
-            $request->userData = $data;
-        }
-
-        return $next($request);
-    }
-}

+ 1 - 8
app/Jobs/ProcessDataJob.php

@@ -34,20 +34,13 @@ class ProcessDataJob implements ShouldQueue
 
     public function handle()
     {
-        $service = new TPlusServerService();
         try {
             $data = $this->data;
             $user = $this->user;
             $type = $this->type;
 
-            if($type == 1){
-                //收付款单
-                list($status, $msg) = $service->synRevenueCostFromTPlus($data, $user);
-            }else{
-                list($status, $msg) = $service->synSalaryEmployeeFromMine($data, $user);
-            }
 
-            $this->finalDo($msg, $service);
+//            $this->finalDo($msg, $service);
         } catch (\Throwable $e) {
             $this->finalDo("异常:" . $e->getMessage(), $service);
             $this->delete();

+ 0 - 13
app/Model/Freight.php

@@ -1,13 +0,0 @@
-<?php
-
-namespace App\Model;
-
-class Freight extends UseScopeBaseModel
-{
-    protected $table = "freight"; //指定表
-    const CREATED_AT = 'crt_time';
-    const UPDATED_AT = 'upd_time';
-    protected $dateFormat = 'U';
-
-    public static $field = ['area','id','region','kilometer','min_freight_fee','one_and_five','greater_than_five','crt_id','crt_time','company'];
-}

+ 0 - 14
app/Model/GiveOut.php

@@ -1,14 +0,0 @@
-<?php
-
-namespace App\Model;
-
-class GiveOut extends UseScopeBaseModel
-{
-    protected $table = "give_out"; //指定表
-    const CREATED_AT = 'crt_time';
-    const UPDATED_AT = 'upd_time';
-    const employee_column = 'employee_id_1';
-    protected $dateFormat = 'U';
-
-    public static $field = ['give_out_amount','id','mark','employee_id_1','employee_id_1_title','send_time','start_time','end_time'];
-}

+ 0 - 13
app/Model/Product.php

@@ -1,13 +0,0 @@
-<?php
-
-namespace App\Model;
-
-class Product extends UseScopeBaseModel
-{
-    protected $table = "product"; //指定表
-    const CREATED_AT = 'crt_time';
-    const UPDATED_AT = 'upd_time';
-    protected $dateFormat = 'U';
-
-    public static $field = ['title','id','category','code','size','unit','business_cost','write_off_price','cost','write_off_price','crt_id','crt_time','mark','return_change_price','freight_price','major_client_settlement_price'];
-}

+ 0 - 19
app/Model/ProductInfo.php

@@ -1,19 +0,0 @@
-<?php
-
-namespace App\Model;
-
-use Illuminate\Database\Eloquent\Model;
-
-class ProductInfo extends Model
-{
-    protected $table = "product_info"; //指定表
-    const CREATED_AT = 'crt_time';
-    const UPDATED_AT = 'upd_time';
-    protected $dateFormat = 'U';
-    const type_one = 1; // 图片
-    const type_two = 2; // 文件
-    public static $type = [
-        self::type_one,
-        self::type_two,
-    ];
-}

+ 0 - 34
app/Model/RevenueCost.php

@@ -1,34 +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';
-
-    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'];
-    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','employee_id_2','employee_id_2_title','payment_amount','profit','order_id'];
-}

+ 0 - 14
app/Model/RevenueCostMain.php

@@ -1,14 +0,0 @@
-<?php
-
-namespace App\Model;
-
-use Illuminate\Database\Eloquent\Model;
-
-class RevenueCostMain extends Model
-{
-    protected $guarded = [];
-    protected $table = "revenue_cost_main"; //指定表
-    const CREATED_AT = 'crt_time';
-    const UPDATED_AT = 'upd_time';
-    protected $dateFormat = 'U';
-}

+ 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 - 172
app/Service/FreightService.php

@@ -1,172 +0,0 @@
-<?php
-
-namespace App\Service;
-
-use App\Model\Employee;
-use App\Model\Freight;
-use Illuminate\Support\Facades\DB;
-
-/**
- * 运费设置
- */
-class FreightService extends Service
-{
-    public function freightEdit($data,$user){
-        list($status,$msg) = $this->freightRule($data, $user, false);
-        if(!$status) return [$status,$msg];
-
-        try {
-            DB::beginTransaction();
-
-            $model = Freight::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->save();
-
-            DB::commit();
-        }catch (\Exception $exception){
-            DB::rollBack();
-            return [false,$exception->getMessage()];
-        }
-
-        return [true, ''];
-    }
-
-    public function freightAdd($data,$user){
-        list($status,$msg) = $this->freightRule($data, $user);
-        if(!$status) return [$status,$msg];
-
-        try {
-            DB::beginTransaction();
-
-            $model = new Freight();
-            $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->crt_id = $user['id'];
-            $model->save();
-
-            DB::commit();
-        }catch (\Exception $exception){
-            DB::rollBack();
-            return [false,$exception->getMessage()];
-        }
-
-        return [true, ''];
-    }
-
-    public function freightDel($data){
-        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
-
-        try {
-            DB::beginTransaction();
-            $time = time();
-
-            Freight::where('del_time',0)
-                ->whereIn('id',$data['id'])
-                ->update(['del_time' => $time]);
-
-            DB::commit();
-        }catch (\Exception $exception){
-            DB::rollBack();
-            return [false,$exception->getMessage()];
-        }
-
-        return [true, ''];
-    }
-
-    public function freightDetail($data,$user){
-        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
-        $customer = Freight::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']): '';
-
-        return [true, $customer];
-    }
-
-    public function freightCommon($data,$user, $field = []){
-        if(empty($field)) $field = Freight::$field;
-
-        $model = Freight::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['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 freightList($data,$user){
-        $model = $this->freightCommon($data, $user);
-        $list = $this->limit($model,'',$data);
-        $list = $this->fillData($list,$user,$data);
-
-        return [true, $list];
-    }
-
-    public function freightRule(&$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['one_and_five'])){
-            $res = $this->checkNumber($data['one_and_five'],2,'positive');
-            if(! $res['valid']) return [false,'1-5吨:' . $res['error']];
-        }
-        if(! empty($data['greater_than_five'])){
-            $res = $this->checkNumber($data['greater_than_five'],2,'positive');
-            if(! $res['valid']) return [false,'5吨以上:' . $res['error']];
-        }
-
-        if($is_add){
-
-        }else{
-            if(empty($data['id'])) return [false,'ID不能为空'];
-            $bool = Freight::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;
-
-        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']] ?? '';
-        }
-
-        return $data;
-    }
-}

+ 0 - 180
app/Service/GiveOutService.php

@@ -1,180 +0,0 @@
-<?php
-
-namespace App\Service;
-
-use App\Model\Employee;
-use App\Model\GiveOut;
-use Illuminate\Support\Facades\DB;
-
-/**
- * 发放
- */
-class GiveOutService extends Service
-{
-    public function giveOutEdit($data,$user){
-        list($status,$msg) = $this->giveOutRule($data, $user, false);
-        if(!$status) return [$status,$msg];
-
-        try {
-            DB::beginTransaction();
-
-            $model = GiveOut::where('id',$data['id'])->first();
-            $model->give_out_amount = $data['give_out_amount'] ?? 0;
-            $model->employee_id_1 = $data['employee_id_1'] ?? 0;
-            $model->employee_id_1_title = $data['employee_id_1_title'] ?? "";
-            $model->send_time = $data['send_time'] ?? 0;
-            $model->start_time = $data['start_time'] ?? 0;
-            $model->end_time = $data['end_time'] ?? 0;
-            $model->mark = $data['mark'] ?? "";
-            $model->save();
-
-            DB::commit();
-        }catch (\Exception $exception){
-            DB::rollBack();
-            return [false,$exception->getMessage()];
-        }
-
-        return [true, ''];
-    }
-
-    public function giveOutAdd($data,$user){
-        list($status,$msg) = $this->giveOutRule($data, $user);
-        if(!$status) return [$status,$msg];
-
-        try {
-            DB::beginTransaction();
-
-            $model = new GiveOut();
-            $model->give_out_amount = $data['give_out_amount'] ?? 0;
-            $model->employee_id_1 = $data['employee_id_1'] ?? 0;
-            $model->employee_id_1_title = $data['employee_id_1_title'] ?? "";
-            $model->send_time = $data['send_time'] ?? 0;
-            $model->start_time = $data['start_time'] ?? 0;
-            $model->end_time = $data['end_time'] ?? 0;
-            $model->crt_id = $user['id'];
-            $model->mark = $data['mark'] ?? "";
-            $model->save();
-
-            DB::commit();
-        }catch (\Exception $exception){
-            DB::rollBack();
-            return [false,$exception->getMessage()];
-        }
-
-        return [true, ''];
-    }
-
-    public function giveOutDel($data){
-        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
-
-        try {
-            DB::beginTransaction();
-            $time = time();
-
-            GiveOut::where('del_time',0)
-                ->whereIn('id',$data['id'])
-                ->update(['del_time' => $time]);
-
-            DB::commit();
-        }catch (\Exception $exception){
-            DB::rollBack();
-            return [false,$exception->getMessage()];
-        }
-
-        return [true, ''];
-    }
-
-    public function giveOutDetail($data,$user){
-        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
-        $customer = GiveOut::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']): '';
-
-        return [true, $customer];
-    }
-
-    public function giveOutCommon($data,$user, $field = []){
-        if(empty($field)) $field = GiveOut::$field;
-
-        $model = GiveOut::Clear($user,$data);
-        $model = $model->where('del_time',0)
-            ->select($field)
-            ->orderby('id', 'desc');
-
-        if(! empty($data['employee_id_1_title'])) $model->where('employee_id_1_title', 'LIKE', '%'.$data['employee_id_1_title'].'%');
-        if(! empty($data['send_time'][0]) && ! empty($data['send_time'][1])) {
-            $return = $this->changeDateToTimeStampAboutRange($data['send_time']);
-            $model->where('send_time','>=',$return[0]);
-            $model->where('send_time','<=',$return[1]);
-        }
-        if(! empty($data['belong_time'][0]) && ! empty($data['belong_time'][1])) {
-            $return = $this->changeDateToTimeStampAboutRange($data['belong_time']);
-            $model->where('start_time','>=',$return[0]);
-            $model->where('end_time','<=',$return[1]);
-        }
-
-        return $model;
-    }
-
-    public function giveOutList($data,$user){
-        $model = $this->giveOutCommon($data, $user);
-        $list = $this->limit($model,'',$data);
-        $list = $this->fillData($list);
-
-        return [true, $list];
-    }
-
-    public function giveOutRule(&$data, $user, $is_add = true){
-        if(empty($data['give_out_amount'])) return [false, '分红已发金额不能为空'];
-        $res = $this->checkNumber($data['give_out_amount'],2,'positive');
-        if(! $res['valid']) return [false,'分红已发金额:' . $res['error']];
-        if(empty($data['employee_id_1'])) return [false, '业务员不能为空'];
-        $employee = Employee::where('del_time',0)
-            ->where('id',$data['employee_id_1'])
-            ->first();
-        if(empty($employee)) return [false, '业务员不存在或已被删除'];
-        $data['employee_id_1_title'] = $employee->emp_name;
-
-        if(empty($data['send_time'])) return [false, '发放日期不能为空'];
-        $data['send_time'] = $this->changeDateToDate($data['send_time']);
-        if($data['send_time'] == null) return [false, '发放日期错误'];
-
-        if(empty($data['belong_time'][0]) || empty($data['belong_time'][1])) return [false, '归属日期不能为空'];
-        list($start_time,$end_time) = $this->changeDateToTimeStampAboutRange($data['belong_time'], false);
-        if ($start_time === null || $end_time === null || $start_time > $end_time) return [false, "归属日期的区间无效"];
-        $data['start_time'] = $start_time;
-        $data['end_time'] = $end_time;
-
-        if($is_add){
-
-        }else{
-            if(empty($data['id'])) return [false,'ID不能为空'];
-            $bool = GiveOut::where('id',$data['id'])
-                ->where('del_time',0)
-                ->exists();
-            if(! $bool) return [false,'发放记录不存在或已被删除'];
-        }
-
-        return [true, $data];
-    }
-
-    public function fillData($data){
-        if(empty($data['data'])) return $data;
-
-        foreach ($data['data'] as $key => $value){
-            $data['data'][$key]['send_time'] = $value['send_time'] ? date('Y-m-d',$value['send_time']) : '';
-            $start = $value['start_time'] ? date('Y-m-d',$value['start_time']) : '';
-            $end = $value['end_time'] ? date('Y-m-d',$value['end_time']) : '';
-            $string = "";
-            if(! empty($start) && ! empty($end)) $string = $start . "|" . $end;
-            $data['data'][$key]['belong_time'] = $string;
-        }
-
-        return $data;
-    }
-}

+ 0 - 381
app/Service/ProductService.php

@@ -1,381 +0,0 @@
-<?php
-
-namespace App\Service;
-
-use App\Model\Employee;
-use App\Model\Product;
-use Illuminate\Support\Facades\DB;
-
-/**
- * 产品管理
- */
-class ProductService extends Service
-{
-    /**
-     * 产品分类编辑
-     * @param $data
-     * @param $user
-     * @return array
-     */
-    public function productCategoryEdit($data,$user){
-        list($status,$msg) = $this->productCategoryRule($data,$user,false);
-        if(!$status) return [$status,$msg];
-
-        $update = $msg['data'][0];
-
-        $model = new ProductCategory();
-        $model->where('id',$data['id'])->update($update);
-
-        return [true,''];
-    }
-
-    /**
-     * 产品分类新增
-     * @param $data
-     * @param $user
-     * @return array
-     */
-    public function productCategoryAdd($data,$user){
-        list($status,$msg) = $this->productCategoryRule($data,$user);
-        if(!$status) return [$status,$msg];
-
-        ProductCategory::insert($msg['data']);
-
-        return [true,''];
-    }
-
-    /**
-     * 产品分类删除
-     * @param $data
-     * @return array
-     */
-    public function productCategoryDel($data){
-        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
-
-        $bool = Product::where('del_time',0)
-            ->where('product_category_id',$data['id'])
-            ->exists();
-        if($bool) return [false,'产品分类下已添加产品,操作失败'];
-
-        try {
-            DB::beginTransaction();
-
-            ProductCategory::where('id',$data['id'])->update([
-                'del_time' => time()
-            ]);
-
-            DB::commit();
-        }catch (\Exception $exception){
-            DB::rollBack();
-            return [false,$exception->getMessage()];
-        }
-
-        return [true,''];
-    }
-
-    /**
-     * 产品分类列表
-     * @param $data
-     * @param $user
-     * @return array
-     */
-    public function productCategoryList($data,$user){
-        $model = ProductCategory::leftJoin('product_category_orderby as a', function ($join) {
-                $join->on('product_category.id', '=', 'a.category_id')
-                    ->where('a.del_time',0);
-            })
-            ->where('product_category.del_time',0)
-            ->select('product_category.title','product_category.id','product_category.parent_id','product_category.is_edit_unit_price')
-            ->orderByRaw('IF(a.sort IS NULL, product_category.id, a.sort) ASC'); // 排序逻辑:优先按 a.sort 排序,没有关联时按主表 id 排序
-
-        if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
-        if(isset($data['is_edit_unit_price'])) $model->where('is_edit_unit_price', $data['is_edit_unit_price']);
-
-        $list = $model->get()->toArray();
-        foreach ($list as $key => $value){
-            $list[$key]['is_edit_unit_price_title'] = ProductCategory::$is_edit_unit_price[$value['is_edit_unit_price']] ?? "";
-        }
-
-        $list_tree = $list;
-        if(! empty($list_tree)) {
-            $list_tree = $this->makeTree(0,$list_tree);
-            $list_tree = $this->set_sort_circle($list_tree);
-        }
-
-        return [200, ['data' => $list,'tree' => $list_tree]];
-    }
-
-    /**
-     * 产品分类参数规则
-     * @param $data
-     * @param $is_add
-     * @return array
-     */
-    public function productCategoryRule($data,$user, $is_add = true){
-        if($this->isEmpty($data,'data')) return [false,'数据不能为空!'];
-
-        $title = array_column($data['data'],'title');
-        $title = array_map(function($val) {
-            return $val !== null ? $val : 0;
-        }, $title);
-        $title_count = array_count_values($title);
-        foreach ($title as $value){
-            if(empty($value)) return [false,'名称不能为空!'];
-            if($title_count[$value] > 1) return [false,'名称不能重复'];
-        }
-
-        foreach ($data['data'] as $key => $value){
-            $data['data'][$key]['upd_time'] = time();
-
-            if($is_add){
-                $parent_id = 0;
-                if(! empty($value['parent_id'])) {
-                    $bool = Product::where('del_time',0)
-                        ->where('product_category_id',$value['parent_id'])
-                        ->exists();
-                    if($bool) {
-                        $title = ProductCategory::where('id',$value['parent_id'])->select('title')->value('title');
-                        return [false,'产品分类:'. $title .'下已添加产品,不允许添加子分类'];
-                    }
-                    $parent_id = $value['parent_id'];
-                }
-
-                $data['data'][$key]['parent_id'] = $parent_id;
-                $data['data'][$key]['crt_time'] = time();
-                $data['data'][$key]['depart_id'] = $data['depart_id'];
-                $data['data'][$key]['top_depart_id'] = $data['top_depart_id'];
-
-                $bool = ProductCategory::where('title',$value['title'])
-                    ->where('top_depart_id',$data['top_depart_id'])
-                    ->where('del_time',0)
-                    ->exists();
-            }else{
-                if($this->isEmpty($data,'id')) return [false,'id不能为空!'];
-                $top_depart_id = ProductCategory::where('id',$data['id'])->value('top_depart_id');
-                $bool = ProductCategory::where('title',$value['title'])
-                    ->where('id','<>',$data['id'])
-                    ->where('del_time',0)
-                    ->exists();
-            }
-            if($bool) return [false,'分类名称不能重复'];
-        }
-
-        return [true, $data];
-    }
-
-    /**
-     * 产品编辑
-     * @param $data
-     * @param $user
-     * @return array
-     */
-    public function productEdit($data,$user){
-        list($status,$msg) = $this->productRule($data, $user, false);
-        if(!$status) return [$status,$msg];
-
-        try {
-            DB::beginTransaction();
-
-            $model = Product::where('id',$data['id'])->first();
-            $model->category = $data['category'] ?? '';
-            $model->title = $data['title'];
-            $model->code = $data['code'] ?? '';
-            $model->size = $data['size'] ?? '';
-            $model->unit = $data['unit'] ?? '';
-            $model->business_cost = $data['business_cost'] ?? 0;
-            $model->cost = $data['cost'] ?? 0;
-            $model->write_off_price = $data['write_off_price'] ?? 0;
-            $model->major_client_settlement_price = $data['major_client_settlement_price'] ?? 0;
-            $model->return_change_price = $data['return_change_price'] ?? 0;
-            $model->freight_price = $data['freight_price'] ?? 0;
-            $model->mark = $data['mark'] ?? '';
-            $model->save();
-
-            DB::commit();
-        }catch (\Exception $exception){
-            DB::rollBack();
-            return [false,$exception->getMessage()];
-        }
-
-        return [true, ''];
-    }
-
-    /**
-     * 产品新增
-     * @param $data
-     * @param $user
-     * @return array
-     */
-    public function productAdd($data,$user){
-        list($status,$msg) = $this->productRule($data, $user);
-        if(!$status) return [$status,$msg];
-
-        try {
-            DB::beginTransaction();
-
-            $model = new Product();
-            $model->category = $data['category'] ?? '';
-            $model->title = $data['title'];
-            $model->code = $data['code'] ?? '';
-            $model->size = $data['size'] ?? '';
-            $model->unit = $data['unit'] ?? '';
-            $model->business_cost = $data['business_cost'] ?? 0;
-            $model->cost = $data['cost'] ?? 0;
-            $model->write_off_price = $data['write_off_price'] ?? 0;
-            $model->major_client_settlement_price = $data['major_client_settlement_price'] ?? 0;
-            $model->return_change_price = $data['return_change_price'] ?? 0;
-            $model->freight_price = $data['freight_price'] ?? 0;
-            $model->mark = $data['mark'] ?? '';
-            $model->crt_id = $user['id'];
-            $model->save();
-
-            DB::commit();
-        }catch (\Exception $exception){
-            DB::rollBack();
-            return [false,$exception->getMessage()];
-        }
-
-        return [true, ''];
-    }
-
-    /**
-     * 产品删除
-     * @param $data
-     * @return array
-     */
-    public function productDel($data){
-        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
-
-        try {
-            DB::beginTransaction();
-            $time = time();
-
-            Product::where('del_time',0)->whereIn('id',$data['id'])->update(['del_time' => $time]);
-
-            DB::commit();
-        }catch (\Exception $exception){
-            DB::rollBack();
-            return [false,$exception->getMessage()];
-        }
-
-        return [true, ''];
-    }
-
-    /**
-     * 产品详情
-     * @param $data
-     * @param $user
-     * @return array
-     */
-    public function productDetail($data,$user){
-        if($this->isEmpty($data,'id')) return [false,'请选择数据!'];
-        $customer = Product::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']): '';
-
-        return [true, $customer];
-    }
-
-    public function productCommon($data,$user, $field = []){
-        if(empty($field)) $field = Product::$field;
-
-        $model = Product::where('del_time',0)
-            ->select($field)
-            ->orderby('code', 'asc');
-
-        if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
-        if(! empty($data['category'])) $model->where('category', 'LIKE', '%'.$data['category'].'%');
-        if(! empty($data['size'])) $model->where('size', 'LIKE', '%'.$data['size'].'%');
-        if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
-        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;
-    }
-
-    /**
-     * 产品列表
-     * @param $data
-     * @param $user
-     * @return array
-     */
-    public function productList($data,$user){
-        $model = $this->productCommon($data, $user);
-        $list = $this->limit($model,'',$data);
-        $list = $this->fillData($list,$user,$data);
-
-        return [true, $list];
-    }
-
-    /**
-     * 产品参数规则
-     * @param $data
-     * @param $is_add
-     * @return array
-     */
-    public function productRule(&$data, $user, $is_add = true){
-        if(empty($data['code'])) return [false,'产品编码不能为空'];
-        if(empty($data['title'])) return [false,'产品名称不能为空'];
-        if(! isset($data['cost'])) return [false, '请填写成本'];
-        if(! isset($data['business_cost'])) return [false, '请填写业务成本'];
-        $res = $this->checkNumber($data['cost']);
-        if(! $res['valid']) return [false,'成本:' . $res['error']];
-        $res = $this->checkNumber($data['business_cost']);
-        if(! $res['valid']) return [false,'业务成本:' . $res['error']];
-        if(! empty($data['write_off_price'])){
-            $res = $this->checkNumber($data['write_off_price']);
-            if(! $res['valid']) return [false,'核销单价:' . $res['error']];
-        }
-        if(! empty($data['major_client_settlement_price'])){
-            $res = $this->checkNumber($data['major_client_settlement_price']);
-            if(! $res['valid']) return [false,'大客户结算单价:' . $res['error']];
-        }
-        if(! empty($data['return_change_price'])){
-            $res = $this->checkNumber($data['return_change_price']);
-            if(! $res['valid']) return [false,'退货损耗单价:' . $res['error']];
-        }
-        if(! empty($data['freight_price'])){
-            $res = $this->checkNumber($data['freight_price']);
-            if(! $res['valid']) return [false,'运费单价:' . $res['error']];
-        }
-
-        if($is_add){
-            $bool = Product::where('code', $data['code'])
-                ->where('del_time',0)
-                ->exists();
-        }else{
-            if(empty($data['id'])) return [false,'ID不能为空'];
-            $bool = Product::where('code', $data['code'])
-                ->where('id','<>',$data['id'])
-                ->where('del_time',0)
-                ->exists();
-        }
-        if($bool) return [false,'产品编码不能重复'];
-
-        return [true, $data];
-    }
-
-    /**
-     * 拼接数据
-     * @param $data
-     * @return array
-     */
-    public function fillData($data, $user, $search){
-        if(empty($data['data'])) return $data;
-
-        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']] ?? '';
-        }
-
-        return $data;
-    }
-}

+ 0 - 1114
app/Service/RangeService.php

@@ -1,1114 +0,0 @@
-<?php
-
-namespace App\Service;
-
-use App\Model\BasicType;
-use App\Model\BasicTypeAllUse;
-use App\Model\Construction;
-use App\Model\ConstructionInfo;
-use App\Model\Customer;
-use App\Model\CustomerInfo;
-use App\Model\Depart;
-use App\Model\Employee;
-use App\Model\Inventory;
-use App\Model\InvoiceOrder;
-use App\Model\OaOrder;
-use App\Model\OaOrderSub;
-use App\Model\OaOrderSubEmployee;
-use App\Model\PaymentReceipt;
-use App\Model\PaymentReceiptInfo;
-use App\Model\Product;
-use App\Model\ProductAdjustment;
-use App\Model\PurchaseOrder;
-use App\Model\ReturnExchangeOrder;
-use App\Model\SalesOrder;
-use App\Model\SalesOrderInfo;
-use App\Model\SeeRange;
-use App\Model\SportsBag;
-use Illuminate\Support\Facades\DB;
-
-class RangeService extends Service
-{
-    //设置可见范围 除了合同
-    public function seeRange($data,$user){
-        if(empty($data['data_type'])) return [false, "可见范围数据类型不能为空"];
-        if(! in_array($data['data_type'], SeeRange::$type)) return [false, "可见范围数据类型错误"];
-        if(empty($data['data_id'])) return [false,'可见范围数据ID不能为空'];
-
-        $time = time();
-        SeeRange::where('del_time',0)
-            ->where('data_type',$data['data_type'])
-            ->where('data_id',$data['data_id'])
-            ->whereIn('type',[SeeRange::data_one, SeeRange::data_two])
-            ->update(['del_time' => $time]);
-
-        if(! empty($data['depart'])){
-            $insert = [];
-            foreach ($data['depart'] as $value){
-                $insert[] = [
-                    'data_id' => $data['data_id'],
-                    'data_type' => $data['data_type'],
-                    'param_id' => $value,
-                    'type' => SeeRange::data_one,
-                    'crt_time' => $time,
-                ];
-            }
-            SeeRange::insert($insert);
-        }
-
-        if(! empty($data['employee'])){
-            $insert = [];
-            foreach ($data['employee'] as $value){
-                $insert[] = [
-                    'data_id' => $data['data_id'],
-                    'data_type' => $data['data_type'],
-                    'param_id' => $value,
-                    'type' => SeeRange::data_two,
-                    'crt_time' => $time,
-                ];
-            }
-            SeeRange::insert($insert);
-        }
-
-        return [true,''];
-    }
-
-    //可见范围删除
-    public function RangeDelete($data_id = 0, $data_type = 0){
-        if(empty($data_id) || empty($data_type)) return;
-
-        SeeRange::where('del_time',0)
-            ->where('data_id',$data_id)
-            ->where('data_type',$data_type)
-            ->update(['del_time'=> time()]);
-    }
-
-    //获取可见范围详情
-    public function RangeDetail($data_id = 0, $data_type = 0){
-        if(empty($data_id) || empty($data_type)) return [];
-
-        $see = SeeRange::where('del_time',0)
-            ->where('data_id',$data_id)
-            ->where('data_type',$data_type)
-            ->get()->toArray();
-        $depart_map = Depart::where('del_time',0)->pluck('title','id')->toArray();
-        $emp_map = Employee::where('del_time',0)->pluck('emp_name','id')->toArray();
-
-        $depart = $employee = $depart2 = [];
-        foreach ($see as $value){
-            if ($value['type'] == SeeRange::data_one){
-                $name = $depart_map[$value['param_id']] ?? "";
-                if(! empty($name)){
-                    $tmp = [
-                        'id' => $value['param_id'],
-                        'name' => $depart_map[$value['param_id']] ?? "",
-                    ];
-                    $depart[] = $tmp;
-                }
-            }elseif ($value['type'] == SeeRange::data_two){
-                $name = $emp_map[$value['param_id']] ?? '';
-                if(! empty($name)){
-                    $tmp = [
-                        'id' => $value['param_id'],
-                        'name' => $emp_map[$value['param_id']] ?? '',
-                    ];
-                    $employee[] = $tmp;
-                }
-            }elseif ($value['type'] == SeeRange::data_three){
-                $name = $depart_map[$value['param_id']] ?? '';
-                if(! empty($name)) {
-                    $tmp = [
-                        'id' => $value['param_id'],
-                        'name' => $depart_map[$value['param_id']] ?? '',
-                    ];
-                    $depart2[] = $tmp;
-                }
-            }
-        }
-
-        return [$depart, $employee, $depart2];
-    }
-
-    //获取可见范围数据id
-    public static function getRangeDataId($user,$data_type){
-        $user_id = $user['id'];
-        $depart_id = $user['depart_range'];
-        $type = SeeRange::data_two;
-        $type2 = [SeeRange::data_one,SeeRange::data_three];
-        $type2 = implode(',',$type2);
-        $depart_str = implode(',',$depart_id);
-        if(empty($depart_str)) {
-            $string = "param_id = 0";
-        }else{
-            $string = "param_id IN({$depart_str})";
-        }
-        // 人为当前用户时, 或部门在当前用户范围内
-        $str = "(param_id = $user_id AND type = $type) OR ($string AND type IN ({$type2}))";
-
-        // 可见部门 可见人 可以看见
-        $data_id = SeeRange::where('del_time',0)
-            ->where('data_type', $data_type)
-            ->where(function ($query) use($str) {
-                $query->whereRaw($str);
-            })->select('data_id')->get()->toArray();
-        return array_unique(array_column($data_id,'data_id'));
-    }
-
-    //获取客户可见数据
-    public static function customerRange($user,$search){
-        // 销售人员/负责人 3协同人  可以看见
-        $customer_id = CustomerInfo::where('del_time',0)
-           ->where('data_id',$user['id'])
-           ->whereIn('type',CustomerInfo::$see_man)
-           ->select('customer_id')->get()->toArray();
-        $return_id = array_unique(array_column($customer_id,'customer_id'));
-        //可见范围id
-        $rang_id = Self::getRangeDataId($user,SeeRange::type_one);
-        //并和
-        $return_id = array_unique(array_merge_recursive($return_id,$rang_id));
-
-        if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
-            // 分批查询数据库,避免 IN 查询太长
-            $filtered_ids = [];
-            foreach (array_chunk($return_id, 500) as $chunk) {
-                $filtered_ids = array_merge($filtered_ids, Customer::whereIn('id', $chunk)
-                    ->where('top_depart_id', $search['top_depart_id'])
-                    ->where('del_time', 0)
-                    ->pluck('id')
-                    ->toArray());
-            }
-
-            $return_id = $filtered_ids;
-
-//            $id = DB::table('customer')
-//                ->where('del_time',0)
-//                ->where('top_depart_id',$search['top_depart_id'])
-//                ->select('id')->get()->toArray();
-//            $id = array_column($id,'id');
-//            foreach ($return_id as $key => $value){
-//                if(! in_array($value,$id)) unset($return_id[$key]);
-//            }
-        }
-
-        return $return_id;
-    }
-
-    //获取施工单可见数据
-    public static function constructionRange($user,$search){
-        //单据中选择的签订负责协同人
-        $construction_id = ConstructionInfo::where('del_time',0)
-            ->where('employee_id',$user['id'])
-            ->select('construction_id')
-            ->get()->toArray();
-        $return_id = array_unique(array_column($construction_id,'construction_id'));
-
-        //可见范围id
-        $return = Self::getRangeDataId($user,SeeRange::type_two);
-        $return_id = array_unique(array_merge_recursive($return_id,$return));
-
-        if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
-            $id = DB::table('construction')
-                ->where('del_time',0)
-                ->where('top_depart_id',$search['top_depart_id'])
-                ->select('id')->get()->toArray();
-            $id = array_column($id,'id');
-            foreach ($return_id as $key => $value){
-                if(! in_array($value,$id)) unset($return_id[$key]);
-            }
-        }
-
-        if(isset($search['is_check'])){
-            $args = self::constructionCheck($user,$search);
-            $result = Construction::whereIn('id',$return_id)
-                ->when(! empty($args), function ($query) use ($args) {
-                    return $query->whereRaw($args);
-                })
-                ->select('id')
-                ->get()->toArray();
-            $return_id = array_column($result,'id');
-        }
-
-        return $return_id;
-    }
-
-    //获取发货单可见数据
-    public static function invoiceRange($user,$search){
-        //可见范围id
-        $return_id = Self::getRangeDataId($user,SeeRange::type_three);
-
-        if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
-            $id = DB::table('invoice_order')
-                ->where('del_time',0)
-                ->where('top_depart_id',$search['top_depart_id'])
-                ->select('id')->get()->toArray();
-            $id = array_column($id,'id');
-            foreach ($return_id as $key => $value){
-                if(! in_array($value,$id)) unset($return_id[$key]);
-            }
-        }
-
-        if(isset($search['is_check'])){
-            $args = self::invoiceCheck($user,$search);
-            $result = InvoiceOrder::whereIn('id',$return_id)
-                ->when(! empty($args), function ($query) use ($args) {
-                    return $query->whereRaw($args);
-                })
-                ->select('id')
-                ->get()->toArray();
-            $return_id = array_column($result,'id');
-        }
-
-        return $return_id;
-    }
-
-    //获取产品可见数据
-    public static function productRange($user,$search){
-        //可见范围id
-        $return_id = Self::getRangeDataId($user,SeeRange::type_four);
-
-        if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
-            $id = DB::table('product')
-                ->where('del_time',0)
-                ->where('top_depart_id',$search['top_depart_id'])
-                ->select('id')->get()->toArray();
-            $id = array_column($id,'id');
-            foreach ($return_id as $key => $value){
-                if(! in_array($value,$id)) unset($return_id[$key]);
-            }
-        }
-
-        return $return_id;
-    }
-
-    //获取产品不可见数据
-    public static function productRangeNot($user,$search){
-        //不可见范围id
-        $return_id = Self::getRangeDataId($user,SeeRange::type_four);
-
-        //分社管理员
-        if(empty($user['is_all_depart']) && ! empty($user['is_manager'])) {
-            $depart = array_shift($user['rule_depart']);
-            $depart_id = $depart['depart_id'] ?? 0;
-            $id = DB::table('product')
-                ->where('del_time',0)
-                ->where('top_depart_id',$depart_id)
-                ->select('id')->get()->toArray();
-            $id = array_column($id,'id');
-            foreach ($return_id as $key => $value){
-                if(in_array($value,$id)) unset($return_id[$key]);
-            }
-        }
-
-        return $return_id;
-    }
-
-    //获取采购单可见数据
-    public static function purchaseRange($user,$search){
-        //可见范围id
-        $return_id = Self::getRangeDataId($user,SeeRange::type_five);
-
-        if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
-            $id = DB::table('purchase_order')
-                ->where('del_time',0)
-                ->where('top_depart_id',$search['top_depart_id'])
-                ->select('id')->get()->toArray();
-            $id = array_column($id,'id');
-            foreach ($return_id as $key => $value){
-                if(! in_array($value,$id)) unset($return_id[$key]);
-            }
-        }
-
-        if(isset($search['is_check'])){
-            $args = self::purchaseCheck($user,$search);
-            $result = PurchaseOrder::whereIn('id',$return_id)
-                ->when(! empty($args), function ($query) use ($args) {
-                    return $query->whereRaw($args);
-                })
-                ->select('id')
-                ->get()->toArray();
-            $return_id = array_column($result,'id');
-        }
-
-        return $return_id;
-    }
-
-    //获取退换货单可见数据
-    public static function returnExchangeOrderRange($user,$search){
-        //可见范围id
-        $return_id = Self::getRangeDataId($user,SeeRange::type_six);
-        if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
-            $id = DB::table('return_exchange_order')
-                ->where('del_time',0)
-                ->where('top_depart_id',$search['top_depart_id'])
-                ->select('id')->get()->toArray();
-            $id = array_column($id,'id');
-            foreach ($return_id as $key => $value){
-                if(! in_array($value,$id)) unset($return_id[$key]);
-            }
-        }
-
-        if(isset($search['is_check'])){
-            $args = self::returnExchangeOrderCheck($user,$search);
-            $result = ReturnExchangeOrder::whereIn('id',$return_id)
-                ->when(! empty($args), function ($query) use ($args) {
-                    return $query->whereRaw($args);
-                })
-                ->select('id')
-                ->get()->toArray();
-            $return_id = array_column($result,'id');
-        }
-
-        return $return_id;
-    }
-
-    //获取合同可见数据
-    public static function salesOrderRange($user,$search){
-        //单据中选择的签订负责协同人
-        $sales_order_id = SalesOrderInfo::where('del_time',0)
-            ->whereIn('type',SalesOrderInfo::$man)
-            ->where('data_id',$user['id'])
-            ->select('sales_order_id')
-            ->get()->toArray();
-        $sales_order_id = array_unique(array_column($sales_order_id,'sales_order_id'));
-
-        $bool = ! empty($search['top_depart_id']) && ! empty($user['is_all_depart']);
-        if(! $bool){
-            $current_top_depart_id = $user['depart_top'][0] ?? [];
-            $current_top_depart_id = $current_top_depart_id['depart_id'] ?? 0;
-            //查找是否合同指派了门店
-            $dispatch_company = SeeRange::where('del_time',0)
-                ->whereIn('data_id',$sales_order_id)
-                ->where('param_id', $current_top_depart_id)
-                ->where('data_type',SeeRange::type_seven)
-                ->where('type',SeeRange::data_three)
-                ->select('data_id')
-                ->get()->toArray();
-            $dispatch_company = array_column($dispatch_company,'data_id');
-
-            // 找出仅在 $array1 中存在的元素
-            $diff1 = array_diff($sales_order_id, $dispatch_company);
-
-            $sales_order_id = SalesOrder::whereIn('id', $diff1)
-                ->where('top_depart_id',$current_top_depart_id)
-                ->select('id')
-                ->get()->toArray();
-            $sales_order_id = array_column($sales_order_id,'sales_order_id');
-            $sales_order_id = array_merge_recursive($sales_order_id,$dispatch_company);
-        }
-
-        //指派后 可见范围id
-        $return = Self::getRangeDataId($user,SeeRange::type_seven);
-
-        $return_id = array_unique(array_merge_recursive($sales_order_id,$return));
-        if($bool){
-            $id = DB::table('sales_order')
-                ->where('del_time',0)
-                ->where('top_depart_id',$search['top_depart_id'])
-                ->select('id')->get()->toArray();
-            $id = array_column($id,'id');
-            foreach ($return_id as $key => $value){
-                if(! in_array($value,$id)) unset($return_id[$key]);
-            }
-        }
-
-        if(isset($search['is_check'])){
-            $args = self::salesOrderCheck($user,$search);
-            $result = SalesOrder::whereIn('id',$return_id)
-                ->when(! empty($args), function ($query) use ($args) {
-                    return $query->whereRaw($args);
-                })
-                ->select('id')
-                ->get()->toArray();
-            $return_id = array_column($result,'id');
-        }
-
-        return $return_id;
-    }
-
-    //获取特殊采购单可见数据
-    public static function purchaseSpecialRange($user,$search){
-        //可见范围id
-        $return_id = Self::getRangeDataId($user,SeeRange::type_ten);
-
-//        if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
-//            $id = DB::table('purchase_order')
-//                ->where('del_time',0)
-//                ->where('top_depart_id',$search['top_depart_id'])
-//                ->select('id')->get()->toArray();
-//            $id = array_column($id,'id');
-//            foreach ($return_id as $key => $value){
-//                if(! in_array($value,$id)) unset($return_id[$key]);
-//            }
-//        }
-
-        return $return_id;
-    }
-
-    //获取供应商可见数据
-    public static function supplierRange($user,$search){
-        //可见范围id
-        $return_id = Self::getRangeDataId($user,SeeRange::type_nine);
-
-        if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
-            $id = DB::table('supplier')
-                ->where('del_time',0)
-                ->where('top_depart_id',$search['top_depart_id'])
-                ->select('id')->get()->toArray();
-            $id = array_column($id,'id');
-            foreach ($return_id as $key => $value){
-                if(! in_array($value,$id)) unset($return_id[$key]);
-            }
-        }
-
-        return $return_id;
-    }
-
-    //获取活动包可见数据
-    public static function sportsBagRange($user,$search){
-        //可见范围id
-        $return_id = Self::getRangeDataId($user,SeeRange::type_eight);
-
-        if(! empty($search['top_depart_id']) && ! empty($user['is_all_depart'])){
-            $id = DB::table('sports_bag')
-                ->where('del_time',0)
-                ->where('top_depart_id',$search['top_depart_id'])
-                ->select('id')->get()->toArray();
-            $id = array_column($id,'id');
-            foreach ($return_id as $key => $value){
-                if(! in_array($value,$id)) unset($return_id[$key]);
-            }
-        }
-
-        return $return_id;
-    }
-
-    //产品不可见部门
-    public static function productNotSeeRange($product_id){
-        $return = [];
-        $result = SeeRange::where('del_time',0)
-            ->where('data_type', SeeRange::type_four)
-            ->whereIn('data_id',$product_id)
-            ->where('type',SeeRange::data_one)
-            ->select('param_id as depart_id','data_id as product_id')
-            ->get()->toArray();
-        foreach ($result as $value){
-            $return[$value['product_id']][] = $value['depart_id'];
-        }
-
-        return $return;
-    }
-
-    //产品签订人负责人
-    public function salesOrderSearch($data){
-        $return1 = $return2 = [];
-        if(! empty($data['qd'])){
-            $emp_id = Employee::where('del_time',0)
-                ->where('emp_name','LIKE', '%'.$data['qd'].'%')
-                ->select('id')->get()->toArray();
-            $emp_id = array_column($emp_id,'id');
-            //单据中选择的签订人
-            $sales_order_id = SalesOrderInfo::where('del_time',0)
-                ->where('type',SalesOrderInfo::type_one)
-                ->whereIn('data_id',$emp_id)
-                ->select('sales_order_id')
-                ->get()->toArray();
-            $return1 = array_unique(array_column($sales_order_id,'sales_order_id'));
-        }
-        if(! empty($data['fz'])){
-            $emp_id = Employee::where('del_time',0)
-                ->where('emp_name','LIKE', '%'.$data['fz'].'%')
-                ->select('id')->get()->toArray();
-            $emp_id = array_column($emp_id,'id');
-            //单据中选择的负责人
-            $sales_order_id = SalesOrderInfo::where('del_time',0)
-                ->where('type',SalesOrderInfo::type_two)
-                ->whereIn('data_id',$emp_id)
-                ->select('sales_order_id')
-                ->get()->toArray();
-            $return2 = array_unique(array_column($sales_order_id,'sales_order_id'));
-        }
-
-        if(! empty($data['qd']) && ! empty($data['fz'])){
-            $return = array_intersect($return1, $return2);
-        }elseif(!empty($data['qd'])){
-            $return = $return1;
-        }else{
-            $return = $return2;
-        }
-
-        return $return;
-    }
-
-    //指派门店
-    public function salesOrderZpSearch($data){
-        $return = SeeRange::where('del_time',0)
-            ->where('param_id',$data['zp'])
-            ->where('data_type',SeeRange::type_seven)
-            ->where('type',SeeRange::data_three)
-            ->select('data_id')
-            ->get()->toArray();
-
-        return array_column($return,'data_id');
-    }
-
-    //客户创建人
-    public function salesOrderCustomerCrtSearch($user,$data){
-        $emp_id = Employee::where('del_time',0)
-            ->where('emp_name','LIKE', '%'.$data['customer_crt_name'].'%')
-            ->select('id')->get()->toArray();
-        $emp_id = array_column($emp_id,'id');
-
-        $model2 = Customer::Clear($user,$data);
-        $customer = $model2->where('del_time',0)
-            ->whereIn('crt_id', $emp_id)
-            ->select('id')
-            ->get()->toArray();
-
-        return array_column($customer,'id');
-    }
-
-    //收付款人搜索
-    public function paymentReceiptSearch($data){
-        $emp_id = Employee::where('del_time',0)
-            ->where('emp_name','LIKE', '%'.$data['belong'].'%')
-            ->select('id')->get()->toArray();
-        $emp_id = array_column($emp_id,'id');
-        //单据中选择的签订人
-        $id = PaymentReceiptInfo::where('del_time',0)
-            ->where('type',PaymentReceiptInfo::type_two)
-            ->whereIn('data_id',$emp_id)
-            ->select('payment_receipt_id')
-            ->get()->toArray();
-        return array_unique(array_column($id,'payment_receipt_id'));
-    }
-
-    //创建人
-    public function crtNameSearch($data){
-        $emp_id = Employee::where('del_time',0)
-            ->where('emp_name','LIKE', '%'.$data['crt_name'].'%')
-            ->select('id')->get()->toArray();
-        return array_column($emp_id,'id');
-    }
-
-    public function crtContactSearch($data){
-        $id = CustomerInfo::where('del_time',0)
-            ->where('type',CustomerInfo::type_one)
-            ->where('contact_info','LIKE', '%'.$data['title_t'].'%')
-            ->select('customer_id')->get()->toArray();
-        return array_column($id,'customer_id');
-    }
-
-    //负责人
-    public function customerSearch($data){
-        $emp_id = Employee::where('del_time',0)
-            ->where('emp_name','LIKE', '%'.$data['fz'].'%')
-            ->select('id')->get()->toArray();
-        $emp_id = array_column($emp_id,'id');
-        //单据中选择的负责人
-        $customer_id = CustomerInfo::where('del_time',0)
-            ->where('type',CustomerInfo::type_two)
-            ->whereIn('data_id',$emp_id)
-            ->select('customer_id')
-            ->get()->toArray();
-
-        return array_unique(array_column($customer_id,'customer_id'));;
-    }
-
-    //获取可见人施工单
-    public function RangeConstructionEmpDetail($data_id = 0){
-        if(empty($data_id)) return [];
-
-        $see = ConstructionInfo::where('del_time',0)
-            ->whereIn('construction_id',$data_id)
-            ->where('type',ConstructionInfo::type_three)
-            ->get()->toArray();
-        $emp_map = Employee::where('del_time',0)
-            ->whereIn('id',array_column($see,'employee_id'))
-            ->pluck('emp_name','id')->toArray();
-
-        $employee = [];
-        foreach ($see as $value){
-            $name = $emp_map[$value['employee_id']] ?? '';
-            if(! empty($name)){
-                $tmp = [
-                    'id' => $value['employee_id'],
-                    'emp_name' => $emp_map[$value['employee_id']] ?? '',
-                ];
-                $employee[$value['construction_id']][] = $tmp;
-            }
-        }
-
-        return $employee;
-    }
-
-    //客户类型
-    public function customerBasicTypeSearch($customer_type, $type){
-        $result = BasicType::where('del_time',0)
-            ->whereIn('type',$type)
-            ->where('title', $customer_type)
-            ->select('id')->get()->toArray();
-        return array_column($result,'id');
-    }
-
-    public function customerBasicTypeAllUseSearch($customer_type, $type){
-        $result = BasicTypeAllUse::where('del_time',0)
-            ->whereIn('type',$type)
-            ->where('title', $customer_type)
-            ->select('id')->get()->toArray();
-        return array_column($result,'id');
-    }
-
-    //全部 待审 已审核 -----------------------------------------------
-    public static function sportsBagCheck($user,$search){
-        $args = "";
-        if($search['is_check'] == 1) {
-            list($status, $id) = self::getWaitForSportsCheck($user,$search);
-
-            //待审核
-            $check = implode(",", SportsBag::$wait_check);
-            $args = "(state IN (" . implode(",", SportsBag::$wait_check) ."))";
-
-            if($status) {
-                $wait_for_me = $search['wait_for_me'] ?? 0;
-                $check_2 = implode(',', array_diff(SportsBag::$wait_check, [SportsBag::STATE_ONE]));
-                $id = implode(",", $id);
-
-                if($wait_for_me){
-                    if(empty($id)) {
-                        $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }else{
-                        $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }
-                }
-            }
-        }elseif($search['is_check'] == 2){
-            //已审
-            $args = "(state = ". SportsBag::STATE_TWO . ")";
-        }
-
-        return $args;
-    }
-
-    private static function getWaitForSportsCheck($user, $search){
-        if(! isset($search['wait_for_me'])) return [false, []];
-
-        //获取待审核
-        $args = "(state = " . SportsBag::STATE_ONE . ")";
-        $data = SportsBag::where('del_time',0)
-            ->whereRaw($args)
-            ->select('order_number','id')
-            ->get()->toArray();
-        if(empty($data)) return [true, []];
-
-        list($status,$msg) = self::getWaitCommon($data,$user);
-        return [$status, $msg];
-    }
-
-    public static function paymentReceiptCheck($user,$search){
-        $args = "";
-        if($search['is_check'] == 1) {
-            list($status, $id) = self::getWaitForPaymentCheck($user,$search);
-
-            //待审核
-            $check = implode(",", SportsBag::$wait_check);
-            $args = "(state IN (" . $check ."))";
-
-            if($status) {
-                $wait_for_me = $search['wait_for_me'] ?? 0;
-                $id = implode(",", $id);
-                $check_2 = implode(',', array_diff(SportsBag::$wait_check, [PaymentReceipt::STATE_ONE]));
-                if($wait_for_me){
-                    if(empty($id)) {
-                        $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }else{
-                        $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }
-                }
-            }
-        }elseif($search['is_check'] == 2){
-            //已审
-            $args = "(state = ". PaymentReceipt::STATE_TWO . ")";
-        }
-
-        return $args;
-    }
-
-    private static function getWaitForPaymentCheck($user, $search){
-        if(! isset($search['wait_for_me'])) return [false, []];
-
-        //获取待审核
-        $args = "(state = " . PaymentReceipt::STATE_ONE . ")";
-        $data = PaymentReceipt::where('del_time',0)
-            ->whereRaw($args)
-            ->select('order_number','id')
-            ->get()->toArray();
-        if(empty($data)) return [true, []];
-
-        list($status,$msg) = self::getWaitCommon($data,$user);
-        return [$status, $msg];
-    }
-
-    public static function salesOrderCheck($user,$search){
-        $args = "";
-        if($search['is_check'] == 1) {
-            list($status, $id) = self::getWaitForSalesCheck($user,$search);
-
-            //待审核
-            $check = implode(",", SalesOrder::$wait_check);
-            $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state IN (" . $check ."))";
-
-            if($status) {
-                $wait_for_me = $search['wait_for_me'] ?? 0;
-
-                $check_2 = implode(',', array_diff(SalesOrder::$wait_check, [SalesOrder::State_one]));
-                $id = implode(",", $id);
-                if($wait_for_me){
-                    if(empty($id)) {
-                        $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }else{
-                        $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }
-                }
-            }
-        }elseif($search['is_check'] == 2){
-            //已审 线上订单的已审核是2  其它是 3
-            $args = SalesOrder::search;
-        }
-
-        return $args;
-    }
-
-    private static function getWaitForSalesCheck($user, $search){
-        if(! isset($search['wait_for_me'])) return [false, []];
-
-        //获取待审核合同
-        $args = "(sales_order_type = " . SalesOrder::Order_type_one . " and state = " . SalesOrder::State_one . ")";
-        $data = SalesOrder::where('del_time',0)
-            ->whereRaw($args)
-            ->select('order_number','id')
-            ->get()->toArray();
-        if(empty($data)) return [true, []];
-
-        list($status,$msg) = self::getWaitCommon($data,$user);
-        return [$status, $msg];
-    }
-
-    public static function invoiceCheck($user,$search){
-        $args = "";
-        if($search['is_check'] == 1) {
-            list($status, $id) = self::getWaitForInvoiceCheck($user,$search);
-
-            //待审核
-            $check = implode(",", InvoiceOrder::$wait_check);
-            $args = "(state IN (" . $check ."))";
-
-            if($status) {
-                $wait_for_me = $search['wait_for_me'] ?? 0;
-
-                $check_2 = implode(',', array_diff(InvoiceOrder::$wait_check, [InvoiceOrder::STATE_ONE]));
-                $id = implode(",", $id);
-                if($wait_for_me){
-                    if(empty($id)) {
-                        $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }else{
-                        $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }
-                }
-            }
-        }elseif($search['is_check'] == 2){
-            //已审
-            $args = "(state = ". InvoiceOrder::STATE_TWO . ")";
-        }
-
-        return $args;
-    }
-
-    private static function getWaitForInvoiceCheck($user, $search){
-        if(! isset($search['wait_for_me'])) return [false, []];
-
-        //获取待审核数据
-        $args = "(state = " . InvoiceOrder::STATE_ONE . ")";
-        $data = InvoiceOrder::where('del_time',0)
-            ->whereRaw($args)
-            ->select('order_number','id')
-            ->get()->toArray();
-        if(empty($data)) return [true, []];
-
-        list($status,$msg) = self::getWaitCommon($data,$user);
-        return [$status, $msg];
-    }
-
-    public static function returnExchangeOrderCheck($user,$search){
-        $args = "";
-        if($search['is_check'] == 1) {
-            list($status, $id) = self::getWaitForReturnExchangeCheck($user,$search);
-
-            //待审核
-            $check = implode(",", ReturnExchangeOrder::$wait_check);
-            $args = "(state IN (" . $check ."))";
-
-            if($status) {
-                $wait_for_me = $search['wait_for_me'] ?? 0;
-
-                $check_2 = implode(',', array_diff(ReturnExchangeOrder::$wait_check, [ReturnExchangeOrder::State_one]));
-                $id = implode(",", $id);
-                if($wait_for_me){
-                    if(empty($id)) {
-                        $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }else{
-                        $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }
-                }
-            }
-        }elseif($search['is_check'] == 2){
-            //已审
-            $args = "(state = ". ReturnExchangeOrder::State_two . ")";
-        }
-
-        return $args;
-    }
-
-    private static function getWaitForReturnExchangeCheck($user, $search){
-        if(! isset($search['wait_for_me'])) return [false, []];
-
-        //获取待审核数据
-        $args = "(state = " . ReturnExchangeOrder::State_one . ")";
-        $data = ReturnExchangeOrder::where('del_time',0)
-            ->whereRaw($args)
-            ->select('order_number','id')
-            ->get()->toArray();
-        if(empty($data)) return [true, []];
-
-        list($status,$msg) = self::getWaitCommon($data,$user);
-        return [$status, $msg];
-    }
-
-    public static function constructionCheck($user,$search){
-        $args = "";
-        if($search['is_check'] == 1) {
-            list($status, $id) = self::getWaitForConstructionCheck($user,$search);
-
-            //待审核
-            $check = implode(",", Construction::$wait_check);
-            $args = "(state IN (" . $check ."))";
-
-            if($status) {
-                $wait_for_me = $search['wait_for_me'] ?? 0;
-
-                $check_2 = implode(',', array_diff(Construction::$wait_check, [Construction::STATE_ONE]));
-                $id = implode(",", $id);
-                if($wait_for_me){
-                    if(empty($id)) {
-                        $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }else{
-                        $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }
-                }
-            }
-        }elseif($search['is_check'] == 2){
-            //已审
-            $args = "(state >= ". Construction::STATE_TWO . ")";
-        }
-
-        return $args;
-    }
-
-    private static function getWaitForConstructionCheck($user, $search){
-        if(! isset($search['wait_for_me'])) return [false, []];
-
-        //获取待审核数据
-        $args = "(state = " . Construction::STATE_ONE . ")";
-        $data = Construction::where('del_time',0)
-            ->whereRaw($args)
-            ->select('order_number','id')
-            ->get()->toArray();
-        if(empty($data)) return [true, []];
-
-        list($status,$msg) = self::getWaitCommon($data,$user);
-        return [$status, $msg];
-    }
-
-    public static function purchaseCheck($user,$search){
-        $args = "";
-        if($search['is_check'] == 1) {
-            list($status, $id) = self::getWaitForPurchaseCheck($user,$search);
-
-            //待审核
-            $check = implode(",", PurchaseOrder::$wait_check);
-            $args = "(state IN (" . $check ."))";
-
-            if($status) {
-                $wait_for_me = $search['wait_for_me'] ?? 0;
-
-                $check_2 = implode(',', array_diff(PurchaseOrder::$wait_check, [PurchaseOrder::STATE_ONE]));
-                $id = implode(",", $id);
-                if($wait_for_me){
-                    if(empty($id)) {
-                        $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }else{
-                        $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }
-                }
-            }
-        }elseif($search['is_check'] == 2){
-            //已审
-            $args = "(state >= ". PurchaseOrder::STATE_TWO . ")";
-        }
-
-        return $args;
-    }
-
-    private static function getWaitForPurchaseCheck($user, $search){
-        if(! isset($search['wait_for_me'])) return [false, []];
-
-        //获取待审核数据
-        $args = "(state = " . PurchaseOrder::STATE_ONE . ")";
-        $data = PurchaseOrder::where('del_time',0)
-            ->whereRaw($args)
-            ->select('order_number','id')
-            ->get()->toArray();
-        if(empty($data)) return [true, []];
-
-        list($status,$msg) = self::getWaitCommon($data,$user);
-        return [$status, $msg];
-    }
-
-    public static function inventoryCheck($user,$search){
-        $args = "";
-        if($search['is_check'] == 1) {
-            list($status, $id) = self::getWaitForinventoryCheck($user,$search);
-
-            //待审核
-            $check = implode(",", Inventory::$wait_check);
-            $args = "(state IN (" . $check ."))";
-
-            if($status) {
-                $wait_for_me = $search['wait_for_me'] ?? 0;
-
-                $check_2 = implode(',', array_diff(Inventory::$wait_check, [Inventory::STATE_ONE]));
-                $id = implode(",", $id);
-                if($wait_for_me){
-                    if(empty($id)) {
-                        $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }else{
-                        $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }
-                }
-            }
-        }elseif($search['is_check'] == 2){
-            //已审
-            $args = "(state >= ". Inventory::STATE_TWO . ")";
-        }
-
-        return $args;
-    }
-
-    private static function getWaitForinventoryCheck($user, $search){
-        if(! isset($search['wait_for_me'])) return [false, []];
-
-        //获取待审核数据
-        $args = "(state = " . Inventory::STATE_ONE . ")";
-        $data = Inventory::where('del_time',0)
-            ->whereRaw($args)
-            ->select('order_number','id')
-            ->get()->toArray();
-        if(empty($data)) return [true, []];
-
-        list($status,$msg) = self::getWaitCommon($data,$user);
-        return [$status, $msg];
-    }
-
-    public static function productAdjustmentCheck($user,$search){
-        $args = "";
-        if($search['is_check'] == 1) {
-            list($status, $id) = self::getProductAdjustmentCheck($user,$search);
-
-            //待审核
-            $check = implode(",", ProductAdjustment::$wait_check);
-            $args = "(state IN (" . $check ."))";
-
-            if($status) {
-                $wait_for_me = $search['wait_for_me'] ?? 0;
-
-                $check_2 = implode(',', array_diff(ProductAdjustment::$wait_check, [ProductAdjustment::STATE_ONE]));
-                $id = implode(",", $id);
-                if($wait_for_me){
-                    if(empty($id)) {
-                        $args = "(state IN (" . $check .") and (1=0 or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }else{
-                        $args = "(state IN (" . $check .") and (id IN (" . $id .") or (crt_id = " . $user['id'] ." and state IN (" . $check_2 ."))))";
-                    }
-                }
-            }
-        }elseif($search['is_check'] == 2){
-            //已审
-            $args = "(state >= ". ProductAdjustment::STATE_TWO . ")";
-        }
-
-        return $args;
-    }
-
-    private static function getProductAdjustmentCheck($user, $search){
-        if(! isset($search['wait_for_me'])) return [false, []];
-
-        //获取待审核数据
-        $args = "(state = " . ProductAdjustment::STATE_ONE . ")";
-        $data = ProductAdjustment::where('del_time',0)
-            ->whereRaw($args)
-            ->select('order_number','id')
-            ->get()->toArray();
-        if(empty($data)) return [true, []];
-
-        list($status,$msg) = self::getWaitCommon($data,$user);
-        return [$status, $msg];
-    }
-
-    private static function getWaitCommon($data,$user){
-        $data_map = array_column($data,'id','order_number');
-        //查找对应审批流数据
-        $orderNoGroups = OaOrder::whereIn('order_no', array_column($data,'order_number'))
-            ->get()
-            ->groupBy('order_no');
-        $maxIds = $orderNoGroups->map(function ($group) {
-            return $group->max('id');
-        });
-        $map = $maxIds->toArray();
-        if(empty($map)) return [true, []];
-        $oa_order_id = array_values($map);
-        $map2 = array_flip($map);
-        unset($map);
-
-        //获取审批流下的人
-        $list = OaOrderSub::whereIn('oa_order_id', $oa_order_id)
-            ->whereIn('state',[0,1])
-            ->select('id','state','oa_order_id')
-            ->orderBy('id', 'desc')
-            ->get()->toArray();
-        $subEmployeeList = OaOrderSubEmployee::whereIn('oa_order_id', $oa_order_id)
-            ->where('employee_id',$user['id'])
-            ->get()->toArray();
-        if(empty($subEmployeeList)) return [true, []];
-
-        //每条数据对应的人
-        $emp_id_key_list = [];
-        foreach ($subEmployeeList as $v) {
-            $emp_id_key_list[$v['oa_order_sub_id']][] = $v['employee_id'];
-        }
-        unset($subEmployeeList);
-
-        $flag = $id = [];
-        foreach ($list as $v) {
-            //不存在单号或者已存在单号返回数据
-            if(empty($v['oa_order_id']) || isset($flag[$v['oa_order_id']])) continue;
-            $emp_tmp = $emp_id_key_list[$v['id']] ?? [];
-            $flag[$v['oa_order_id']] = $emp_tmp;
-            $order_number = $map2[$v['oa_order_id']] ?? "";
-            $sales_id = $data_map[$order_number] ?? 0;
-            if(in_array($user['id'], $emp_tmp)) $id[] = $sales_id;
-        }
-        unset($flag);
-
-        return [true, $id];
-    }
-    //全部 待审 已审核 -----------------------------------------------
-}

+ 0 - 441
app/Service/StatisticsService.php

@@ -1,441 +0,0 @@
-<?php
-
-namespace App\Service;
-
-use App\Model\EmployeeIndex;
-use App\Model\GiveOut;
-use App\Model\RevenueCost;
-use App\Model\RevenueCostTotal;
-use App\Model\SalaryEmployee;
-use Illuminate\Support\Facades\DB;
-
-class StatisticsService extends Service
-{
-    public function statisticsRevenueCostCommon($data,$user, $field = []){
-        if(empty($field)) $field = RevenueCostTotal::$field;
-        $model = RevenueCostTotal::Clear($user,$data);
-
-        $model = $model->where('del_time',0)
-            ->select($field)
-            ->orderby('id', 'desc');
-
-        if(! empty($data['employee_id_1_title'])) $model->where('employee_id_1_title', 'LIKE', '%'.$data['employee_id_1_title'].'%');
-        if(! empty($data['order_time'][0]) && ! empty($data['order_time'][1])){
-            list($start_time, $end_time) = $this->changeDateToTimeStampAboutRange($data['order_time'],false);
-            if ($start_time === null || $end_time === null || $start_time > $end_time) return [false, "单据日期的区间无效"];
-            $model->where('order_time', '>=', $start_time)
-                ->where('order_time', '<', $end_time);
-        }
-        if(! empty($data['order_type'])) $model->where('order_type',$data['order_type']);
-
-        return [true, $model];
-    }
-
-    public function statisticsRevenueCost($data,$user){
-        list($status, $model) = $this->statisticsRevenueCostCommon($data, $user);
-        if(! $status) return [false, $model];
-        $list = $this->limit($model,'',$data);
-        $list = $this->statisticsRevenueCostFillData($list);
-
-        $header_default = config("header.68") ?? [];
-        $list['count'] = $this->countTotal($list['data'], $header_default);
-        return [true, $list];
-    }
-
-    public function statisticsRevenueCostFillData($data){
-        if(empty($data['data'])) return $data;
-
-        foreach ($data['data'] as $key => $value){
-            $time = date("Y-m", $value['order_time']);
-            $data['data'][$key]['order_time'] = $time;
-            $data['data'][$key]['order_type_title'] = RevenueCost::$order_type[$value['order_type']] ?? "";
-            $data['data'][$key]['profit_rate'] = bcmul($value['profit_rate'], 100,2);
-        }
-
-        return $data;
-    }
-
-    public function statisticsRevenueCostOneAndTwoCommon($data,$user, $field = []){
-        if(empty($data['order_type']) || ! isset(RevenueCost::$order_type[$data['order_type']])) return [false, '单据类型不存在或错误'];
-
-        if(empty($field)) {
-            if($data['order_type'] == 1){
-                $field = RevenueCost::$field_xhd;
-            }else{
-                $field = RevenueCost::$field_xsfp;
-            }
-        }
-        $model = RevenueCost::Clear($user,$data);
-
-        $model = $model->where('del_time',0)
-            ->where('order_type',$data['order_type'])
-            ->select($field)
-            ->orderby('id', 'desc');
-        if(! empty($data['order_time'][0]) && ! empty($data['order_time'][1])){
-            list($start_time, $end_time) = $this->changeDateToTimeStampAboutRange($data['order_time'],false);
-            if ($start_time === null || $end_time === null || $start_time > $end_time) return [false, "单据日期的区间无效"];
-            $model->where('order_time', '>=', $start_time)
-                ->where('order_time', '<=', $end_time);
-        }
-        if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
-        if(! empty($data['customer_title'])) $model->where('customer_title', 'LIKE', '%'.$data['customer_title'].'%');
-        if(! empty($data['employee_id_1_title'])) $model->where('employee_id_1_title', 'LIKE', '%'.$data['employee_id_1_title'].'%');
-
-        return [true, $model];
-    }
-
-    public function statisticsRevenueCostOneAndTwo($data,$user){
-        list($status, $model) = $this->statisticsRevenueCostOneAndTwoCommon($data, $user);
-        if(! $status) return [false, $model];
-        $list = $this->limit($model,'',$data);
-        $list = $this->statisticsRevenueCostOneAndTwoFillData($list);
-
-        if($data['order_type'] == 1){
-            $header_default = config("header.69") ?? [];
-        }else{
-            $header_default = config("header.70") ?? [];
-        }
-        $list['count'] = $this->countTotal($list['data'], $header_default);
-
-        return [true, $list];
-    }
-
-    public function statisticsRevenueCostOneAndTwoFillData($data){
-        if(empty($data['data'])) return $data;
-
-        foreach ($data['data'] as $key => $value){
-            $data['data'][$key]['profit_rate'] = bcmul($value['profit_rate'], 100,2);
-            $data['data'][$key]['order_time'] = $value['order_time'] ? date("Y-m-d", $value['order_time']) : "";
-        }
-
-        return $data;
-    }
-
-    public function statisticsRevenueCostThreeCommon($data,$user, $field = []){
-        if(empty($field)) {
-            $field = RevenueCost::$field_hkd_salary_main;
-            $field[] = DB::raw('sum(payment_amount) as payment_amount');
-            $field[] = DB::raw('sum(price_4_total) as price_4_total');
-            $field[] = DB::raw('sum(profit) as profit');
-        }
-        $model = RevenueCost::Clear($user,$data);
-
-        $model = $model->where('del_time',0)
-            ->where('order_type',RevenueCost::ORDER_THREE)
-            ->select($field)
-            ->groupby('order_id')
-            ->orderby('id', 'desc');
-        if(! empty($data['order_time'][0]) && ! empty($data['order_time'][1])){
-            list($start_time, $end_time) = $this->changeDateToTimeStampAboutRange($data['order_time'],false);
-            if ($start_time === null || $end_time === null || $start_time > $end_time) return [false, "单据日期的区间无效"];
-            $model->where('order_time', '>=', $start_time)
-                ->where('order_time', '<=', $end_time);
-        }
-        if(! empty($data['order_number'])) $model->where('order_number', 'LIKE', '%'.$data['order_number'].'%');
-        if(! empty($data['employee_id_1_title'])) $model->where('employee_id_1_title', 'LIKE', '%'.$data['employee_id_1_title'].'%');
-
-        return [true, $model];
-    }
-
-    public function statisticsRevenueCostThree($data,$user){
-        list($status, $model) = $this->statisticsRevenueCostThreeCommon($data, $user);
-        if(! $status) return [false, $model];
-        $list = $this->limit($model,'',$data);
-        $list = $this->statisticsRevenueCostThreeFillData($list);
-
-        $header_default = config("header.71") ?? [];
-        $list['count'] = $this->countTotal($list['data'], $header_default);
-
-        return [true, $list];
-    }
-
-    public function statisticsRevenueCostThreeFillData($data){
-        if(empty($data['data'])) return $data;
-
-        foreach ($data['data'] as $key => $value){
-            $profit_rate = $value['payment_amount'] > 0 ? bcdiv($value['profit'], $value['payment_amount'],2) : 0;
-            $data['data'][$key]['profit_rate'] = bcmul($profit_rate, 100,2);
-            $data['data'][$key]['order_time'] = $value['order_time'] ? date("Y-m-d", $value['order_time']) : "";
-        }
-
-        return $data;
-    }
-
-    public function statisticsRevenueCostThreeDetail($data,$user){
-        if(empty($data['order_number'])) return [false, '回款单号不能为空'];
-        $result = RevenueCost::where('del_time',0)
-            ->where('order_type',RevenueCost::ORDER_THREE)
-            ->where('order_number',$data['order_number'])
-            ->select(RevenueCost::$field_hkd_detail)
-            ->get()->toArray();
-        if(empty($result)) return [false, "回款单不存在或已被删除"];
-
-        $detail = [];
-        foreach ($result as $value){
-            $detail[] = [
-                'order_number' => $value['order_number_upstream'],
-                'customer_code' => $value['customer_code'],
-                'customer_title' => $value['customer_title'],
-                'product_code' => $value['product_code'],
-                'product_title' => $value['product_title'],
-                'product_size' => $value['product_size'],
-                'unit' => $value['unit'],
-                'quantity' => $value['quantity'],
-                'payment_amount' => $value['payment_amount'],
-                'price_1' => $value['price_1'],
-                'price_1_total' => $value['price_1_total'],
-                'price_4' => $value['price_4'],
-                'price_4_total' => $value['price_4_total'],
-                'profit' => $value['profit'],
-                'profit_rate' => bcmul($value['profit_rate'],100,2) . '%',
-                'customer_profit_rate' => bcmul($value['customer_profit_rate'],100,2) . '%',
-            ];
-        }
-
-        $first = $result[0];
-        $order = [
-            'order_number' => $data['order_number'],
-            'order_time' => date("Y-m-d",$first['order_time']),
-            'employee_id_1_title' => $first['employee_id_1_title'],
-            'detail' => $detail
-        ];
-
-        return [true, $order];
-    }
-
-    public function statisticsProfitCommon($data,$user, $field = []){
-        if(empty($field)) {
-            $field = RevenueCost::$field_hkd_profit_main;
-            $field[] = DB::raw('COALESCE(SUM(rc.payment_amount), 0) AS payment_amount');
-        }
-
-        $type = RevenueCost::ORDER_THREE;
-        $model = EmployeeIndex::Clear($user, $data)
-            ->where('employee_index.del_time', 0)
-            ->where('employee_index.type', EmployeeIndex::TYPE_THREE)
-            ->leftJoin(DB::raw('revenue_cost as rc'), function ($join) use ($type) {
-                $join->on('rc.employee_id_2', '=', 'employee_index.employee_id')
-                    ->where('rc.del_time', 0)
-                    ->where('rc.order_type', $type)
-                    ->whereRaw('rc.order_time >= employee_index.start_time')
-                    ->whereRaw('rc.order_time <= employee_index.end_time');
-            })
-            ->select($field)
-            ->groupBy('employee_index.employee_id', 'employee_index.start_time', 'employee_index.end_time')
-            ->orderBy('employee_index.end_time', 'desc');
-
-//        $type = RevenueCost::ORDER_THREE;
-//        $model = EmployeeIndex::where('employee_index.del_time',0)
-//            ->where('employee_index.type',EmployeeIndex::TYPE_THREE)
-//            ->leftJoin(DB::raw('revenue_cost as rc'), function ($join) use ($type) {
-//                $join->on('rc.employee_id_2', '=', 'employee_index.employee_id')
-//                    ->where('rc.del_time', 0)
-//                    ->where('rc.order_type', $type)
-//                    ->whereRaw('rc.order_time >= employee_index.start_time')
-//                    ->whereRaw('rc.order_time <= employee_index.end_time');
-//            })
-//            ->select($field)
-//            ->groupBy('employee_index.employee_id', 'employee_index.start_time', 'employee_index.end_time')
-//            ->orderBy('employee_index.end_time','desc');
-
-        if(! empty($data['order_time'][0]) && ! empty($data['order_time'][1])){;
-            list($start_time, $end_time) = $this->changeDateToTimeStampAboutRange($data['order_time'],false);
-            if ($start_time === null || $end_time === null || $start_time > $end_time) return [false, "单据日期的区间无效"];
-            $model->where('employee_index.start_time', '<=', $end_time)
-                ->where('employee_index.end_time', '>=', $start_time);
-        }
-        if(! empty($data['employee_id_2_title'])) $model->where('rc.employee_id_2_title', 'LIKE', '%'.$data['employee_id_2_title'].'%');
-
-        return [true, $model];
-    }
-
-    public function statisticsProfit($data,$user){
-        list($status, $model) = $this->statisticsProfitCommon($data, $user);
-        if(! $status) return [false, $model];
-        $list = $this->limit($model,'',$data);
-        $list = $this->statisticsProfitFillData($list);
-
-        return [true, $list];
-    }
-
-    public function statisticsProfitFillData($data){
-        if(empty($data['data'])) return $data;
-
-        //获取应发放金额需要的指标
-        $indexes = $this->getEmployeeIndex($data['data']);
-        //已发
-        $indexes_give = $this->getEmployeeGiveOut($data['data']);
-
-        foreach ($data['data'] as $key => $value){
-            $start = $value['start_time'] ? date('Y-m-d',$value['start_time']) : '';
-            $end = $value['end_time'] ? date('Y-m-d',$value['end_time']) : '';
-            $string = "";
-            if(! empty($start) && ! empty($end)) $string = $start . "-" . $end;
-            $value['check_time'] = $string;
-            $value['index_' . EmployeeIndex::TYPE_ONE] = 0;
-            $value['index_' . EmployeeIndex::TYPE_FIVE] = 0;
-            //指标
-            $this->makeIndex($indexes, $value, $data['data'][$key]);
-            //应付
-            $this->makeShouldPay($value,$data['data'][$key]);
-            //已付
-            $this->makePayed($indexes_give, $value,$data['data'][$key]);
-            //未付
-            $not_pay = bcsub($data['data'][$key]['should_pay'], $data['data'][$key]['payed'],2);
-            $data['data'][$key]['not_pay'] = $not_pay;
-        }
-
-        return $data;
-    }
-
-    private function getEmployeeIndex($existingData)
-    {
-        if (empty($existingData)) {
-            return collect();
-        }
-
-        // 取出所有涉及的 employee_id 和时间区间
-        $employeeIds = array_column($existingData, 'employee_id_2');
-        $start_time = array_column($existingData, 'start_time');
-        $minStart = ! empty($start_time) ? min($start_time) : 0;
-        $end_time = array_column($existingData, 'end_time');
-        $maxEnd   = ! empty($end_time) ? max($end_time) : 0;
-
-        // 一次性查出这些员工在最大区间范围内的所有指标
-        $results = EmployeeIndex::where('del_time', 0)
-            ->whereIn('type', [EmployeeIndex::TYPE_ONE, EmployeeIndex::TYPE_FIVE])
-            ->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 getEmployeeGiveOut($existingData)
-    {
-        if (empty($existingData)) {
-            return collect();
-        }
-
-        // 取出所有涉及的 employee_id 和时间区间
-        $employeeIds = array_column($existingData, 'employee_id_2');
-
-        $start_time = array_column($existingData, 'start_time');
-        $minStart = ! empty($start_time) ? min($start_time) : 0;
-        $end_time = array_column($existingData, 'end_time');
-        $maxEnd   = ! empty($end_time) ? max($end_time) : 0;
-
-        // 一次性查出这些员工在最大区间范围内的所有指标
-        $results = GiveOut::where('del_time', 0)
-            ->whereIn('employee_id_1', $employeeIds)
-            ->where('start_time', '<=', $maxEnd)
-            ->where('end_time', '>=', $minStart)
-            ->select('start_time','end_time','employee_id_1 as employee_id','give_out_amount')
-            ->get();
-
-        return $results;
-    }
-
-    private function makeIndex($indexes, $value, &$data){
-        // 找到所有符合条件的 index(可能多个 type)
-        $matchedIndexes = $indexes->filter(function ($item) use ($value) {
-            return $item['employee_id'] == $value['employee_id_2']
-                && $item['start_time'] <= $value['end_time']
-                && $item['end_time'] >= $value['start_time'];
-        });
-        // 按 type 去重,只保留第一次出现的
-        $uniqueByType = [];
-        foreach ($matchedIndexes as $item) {
-            $index = "index_" . $item['type'];
-            if (! isset($uniqueByType[$index])) {
-                $uniqueByType[$index] = $item['index'];
-            }
-        }
-        $data = array_merge($value, $uniqueByType);
-    }
-
-    private function makeShouldPay($value, &$data){
-        $index_1 = bcdiv($data['index_1'],100,2);
-        $index_5 = bcdiv($data['index_5'],100,2);
-        // 分红比例/2
-        $a = bcdiv($index_5,2,2);
-        // 季度预支分红比例/2
-        $b = bcdiv($index_1,2,2);
-        //(分红比例/2-季度预支分红比例/2)
-        $c = bcsub($a, $b,2);
-        $data['part_left'] = $c;
-        if($value['payment_amount'] < $value['index']){
-            //回款金额*(分红比例/2-季度预支分红比例/2);
-            $shouldPay = bcmul($value['payment_amount'], $c,2);
-        }else{
-            //回款金额-季度指标金额
-            $d = bcsub($value['payment_amount'], $value['index'],2);
-            //(回款金额-季度指标金额)*15%
-            $e = bcmul($d, 0.15,2);
-            //(回款金额-季度指标金额)*15%/2
-            $e = bcdiv($e,2,2);
-            //(分红比例/2-季度预支分红比例/2+(回款金额-季度指标金额)*15%/2)
-            $rate = bcadd($c, $e,2);
-//                $data['data'][$key]['rate'] = $rate;
-            //回款金额*(分红比例/2-回款金额*季度预支分红比例/2+(回款金额-季度指标金额)*15%/2)
-            $shouldPay = bcmul($value['payment_amount'], $rate,2);
-        }
-        $data['should_pay'] = $shouldPay;
-    }
-
-    private function makePayed($indexes, $value, &$data){
-        $matchedIndexes_give = $indexes->filter(function ($item) use ($value) {
-            return $item['employee_id'] == $value['employee_id_2']
-                && $item['start_time'] <= $value['end_time']
-                && $item['end_time'] >= $value['start_time'];
-        });
-        $give_out = 0;
-        foreach ($matchedIndexes_give as $item) {
-            $give_out = bcadd($item['give_out_amount'], $give_out,2);
-        }
-        $data['payed'] = $give_out;
-    }
-
-    public function statisticsEmployeeSalaryCommon($data,$user, $field = []){
-        if(empty($field)) {
-            $field = SalaryEmployee::$field;
-        }
-        $model = SalaryEmployee::Clear($user,$data);
-
-        $model = $model->where('del_time',0)
-            ->where('order_type',RevenueCost::ORDER_THREE)
-            ->select($field)
-            ->orderby('order_time', 'desc');
-        if(! empty($data['order_time'][0]) && ! empty($data['order_time'][1])){
-            $start_time = strtotime($data['order_time'][0] . "-01");
-            $end_time = strtotime($data['order_time'][1] . "-01");
-            $model->where('order_time', '>=', $start_time)
-                ->where('order_time', '<=', $end_time);
-        }
-        if(! empty($data['employee_id_1_title'])) $model->where('employee_id_1_title', 'LIKE', '%'.$data['employee_id_1_title'].'%');
-
-        return [true, $model];
-    }
-
-    public function statisticsEmployeeSalary($data,$user){
-        list($status, $model) = $this->statisticsEmployeeSalaryCommon($data, $user);
-        if(! $status) return [false, $model];
-        $list = $this->limit($model,'',$data);
-        $list = $this->statisticsEmployeeSalaryFillData($list);
-
-        return [true, $list];
-    }
-
-    public function statisticsEmployeeSalaryFillData($data){
-        if(empty($data['data'])) return $data;
-
-        foreach ($data['data'] as $key => $value){
-            $order_time = $value['order_time'] ? date('Y-m',$value['order_time']) : '';
-            $data['data'][$key]['order_time'] = $order_time;
-        }
-
-        return $data;
-    }
-}

+ 0 - 43
routes/api.php

@@ -88,27 +88,6 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('employeeRole', 'Api\EmployeeController@employeeRole');
     $route->any('getEmployeeImg', 'Api\EmployeeController@getEmployeeImg');
 
-    //产品名称
-    $route->any('productList', 'Api\ProductController@productList');
-    $route->any('productEdit', 'Api\ProductController@productEdit');
-    $route->any('productAdd', 'Api\ProductController@productAdd');
-    $route->any('productDel', 'Api\ProductController@productDel');
-    $route->any('productDetail', 'Api\ProductController@productDetail');
-
-    //运费设置
-    $route->any('freightList', 'Api\FreightController@freightList');
-    $route->any('freightEdit', 'Api\FreightController@freightEdit');
-    $route->any('freightAdd', 'Api\FreightController@freightAdd');
-    $route->any('freightDel', 'Api\FreightController@freightDel');
-    $route->any('freightDetail', 'Api\FreightController@freightDetail');
-
-    //发放
-    $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('getTableHead','Api\TableHeadController@tableHeadGet');
     //设置表头
@@ -119,32 +98,10 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     //设置搜索项
     $route->any('setTableSearch','Api\TableHeadController@tableSearchAdd');
 
-    //获取默认打开筛选
-    $route->any('getFilter','Api\TableHeadController@filterGet');
-    //设置默认打开筛选
-    $route->any('setFilter','Api\TableHeadController@filterAdd');
-
     //获取下载模板
     $route->any('getTableTitleXls','Api\ImportController@getTableTitleXls');
     //导入统一方法
     $route->any('importAll','Api\ImportController@importAll');
     //导出统一方法
     $route->any('exportFile', 'Api\ExportFileController@exportFile');
-
-    //同步T+人员部门结构
-    $route->any('synPersonDepart', 'Api\TPlusController@synPersonDepart');
-    $route->any('synRevenueCost', 'Api\TPlusController@synRevenueCost');
-    $route->any('synSalaryEmployee', 'Api\TPlusController@synSalaryEmployee');
-
-    //收入成本
-    $route->any('statisticsRevenueCost', 'Api\StatisticsController@statisticsRevenueCost');
-    $route->any('statisticsRevenueCostOneAndTwo', 'Api\StatisticsController@statisticsRevenueCostOneAndTwo');
-    $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');
 });