Browse Source

胡庆余堂

cqp 1 month ago
parent
commit
e59f80732b

+ 4 - 88
app/Http/Controllers/Api/StatisticsController.php

@@ -7,10 +7,10 @@ use Illuminate\Http\Request;
 
 class StatisticsController extends BaseController
 {
-    public function statisticsRevenueCost(Request $request){
+    public function statisticsEmployee(Request $request){
         $service = new StatisticsService();
         $userData = $request->userData;
-        list($status,$data) = $service->statisticsRevenueCost($request->all(),$userData);
+        list($status,$data) = $service->statisticsEmployee($request->all(),$userData);
 
         if($status){
             return $this->json_return(200,'',$data);
@@ -19,94 +19,10 @@ class StatisticsController extends BaseController
         }
     }
 
-    public function statisticsRevenueCostOne(Request $request){
+    public function statisticsDevice(Request $request){
         $service = new StatisticsService();
         $userData = $request->userData;
-        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 statisticsRevenueCostTwo(Request $request){
-        $service = new StatisticsService();
-        $userData = $request->userData;
-        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;
-        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;
-        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;
-        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;
-        list($status,$data) = $service->statisticsEmployeeSalary($request->all(),$userData);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function statisticsFreightFee(Request $request){
-        $service = new StatisticsService();
-        $userData = $request->userData;
-        list($status,$data) = $service->statisticsFreightFee($request->all(),$userData);
-
-        if($status){
-            return $this->json_return(200,'',$data);
-        }else{
-            return $this->json_return(201,$data);
-        }
-    }
-
-    public function statisticsFreightFeeDetail(Request $request){
-        $service = new StatisticsService();
-        $userData = $request->userData;
-        list($status,$data) = $service->statisticsFreightFeeDetail($request->all(),$userData);
+        list($status,$data) = $service->statisticsDevice($request->all(),$userData);
 
         if($status){
             return $this->json_return(200,'',$data);

+ 16 - 1
app/Model/Device.php

@@ -15,5 +15,20 @@ class Device extends UseScopeBaseModel
         2 => '禁用',
     ];
 
-    public static $field = ['title','id','code','crt_id','crt_time','size','mark','is_use'];
+    public static $field = ['title','id','code','crt_id','crt_time','size','mark','is_use','type','type_2'];
+
+    const type_one = 1;
+    const type_two = 2;
+    const type_three = 3;
+
+    public static $type = [
+        self::type_one => '电子设备',
+        self::type_two => '机器设备',
+        self::type_three => '办公设备',
+    ];
+
+    public static $type_2 = [
+        self::type_one => '专用',
+        self::type_two => '共用',
+    ];
 }

+ 2 - 0
app/Model/RdDetails.php

@@ -12,6 +12,8 @@ class RdDetails extends Model
     const UPDATED_AT = 'upd_time';
     protected $dateFormat = 'U';
 
+    public static $field = ['rd_id','id','type','data_id'];
+
     const type_one = 1;
     const type_two = 2;
     public static $type_name = [

+ 19 - 0
app/Service/DeviceService.php

@@ -22,6 +22,11 @@ class DeviceService extends Service
             $model->size = $data['size'] ?? '';
             $model->mark = $data['mark'] ?? '';
             $model->is_use = $data['is_use'] ?? 0;
+            $model->type = $data['type'] ?? 0;
+            $model->type_2 = $data['type_2'] ?? 0;
+            $model->in_time = $data['in_time'] ?? 0;
+            $model->power = $data['power'] ?? '';
+            $model->number = $data['number'] ?? 0;
             $model->save();
 
             $time = time();
@@ -52,6 +57,11 @@ class DeviceService extends Service
             $model->size = $data['size'] ?? '';
             $model->mark = $data['mark'] ?? '';
             $model->is_use = $data['is_use'] ?? 0;
+            $model->type = $data['type'] ?? 0;
+            $model->type_2 = $data['type_2'] ?? 0;
+            $model->in_time = $data['in_time'] ?? 0;
+            $model->power = $data['power'] ?? '';
+            $model->number = $data['number'] ?? 0;
             $model->crt_id = $user['id'];
             $model->save();
 
@@ -158,6 +168,8 @@ class DeviceService extends Service
         if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
         if(! empty($data['id'])) $model->whereIn('id', $data['id']);
         if(! empty($data['is_use'])) $model->where('is_use', $data['is_use']);
+        if(! empty($data['type'])) $model->where('type', $data['type']);
+        if(! empty($data['type_2'])) $model->where('type_2', $data['type_2']);
         if(! empty($data['crt_id'])) $model->whereIn('crt_id', $data['crt_id']);
         if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
             $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
@@ -181,6 +193,11 @@ class DeviceService extends Service
         if(empty($data['title'])) return [false, '名称不能为空'];
         if(empty($data['is_use'])) return [false, '是否启用不能为空'];
         if(! isset(Device::Use[$data['is_use']])) return [false, '是否启用错误'];
+        if(empty($data['type'])) return [false, '固定资产类型不能为空'];
+        if(! isset(Device::$type[$data['type']])) return [false, '固定资产类型错误'];
+        if(! empty($data['in_time'])) $data['in_time'] = $this->changeDateToDate($data['in_time']);
+        if(empty($data['type_2'])) return [false, '类型不能为空'];
+        if(! isset(Device::$type_2[$data['type_2']])) return [false, '类型错误'];
 
         if(! empty($data['details'])){
             list($status, $msg) = $this->checkArrayRepeat($data['details'],'time','设备年月');
@@ -219,6 +236,8 @@ class DeviceService extends Service
             $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d H:i:s',$value['crt_time']) : '';
             $data['data'][$key]['crt_name'] = $emp[$value['crt_id']] ?? '';
             $data['data'][$key]['is_use_title'] = Device::Use[$value['is_use']] ?? '';
+            $data['data'][$key]['type_title'] = Device::$type[$value['type']] ?? '';
+            $data['data'][$key]['type_2_title'] = Device::$type_2[$value['type_2']] ?? '';
         }
 
         return $data;

+ 220 - 791
app/Service/StatisticsService.php

@@ -2,845 +2,274 @@
 
 namespace App\Service;
 
-use App\Model\EmployeeIndex;
-use App\Model\FreightFee;
-use App\Model\GiveOut;
-use App\Model\RevenueCost;
-use App\Model\RevenueCostTotal;
-use App\Model\SalaryEmployee;
+use App\Model\Device;
+use App\Model\DeviceDetails;
+use App\Model\Employee;
+use App\Model\EmployeeDetails;
+use App\Model\Item;
+use App\Model\RdDetails;
 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']);
-        if(! empty($data['id'])) $model->whereIn('id',$data['id']);
-
-        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);
-
-        $list['count'] = $this->countTotal($list['data'], $user['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'].'%');
-        if(! empty($data['id'])) $model->whereIn('id',$data['id']);
-
-        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);
-
-        $list['count'] = $this->countTotal($list['data'], $user['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');
-            $field[] = DB::raw('max(employee_id_2) as employee_id_2');
-            $field[] = DB::raw("MAX(COALESCE(employee_id_2_title, '')) as employee_id_2_title");
-        }
-        $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'].'%');
-        if(! empty($data['employee_id_1'])) $model->where('employee_id_1', 'LIKE', $data['employee_id_1']);
-        if(! empty($data['employee_id_2'])) $model->where('employee_id_2', 'LIKE', $data['employee_id_2']);
-        if(! empty($data['employee_id_2_title'])) $model->where('employee_id_2_title', 'LIKE', '%'.$data['employee_id_2_title'].'%');
-        if(! empty($data['channel_finance_array'])) {
-            $array = explode("\n", str_replace(["\r\n", "\r"], "\n", $data['channel_finance_array']));
-            $model->whereIn('channel_finance', $array);
-        }
-        if(! empty($data['id'])) $model->whereIn('order_id',$data['id']);
-
-        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);
-
-        $list['count'] = $this->countTotal($list['data'], $user['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'],8) : 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'],
-                'channel_finance' => $value['channel_finance'],
-                '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) . '%',
-                'voucher_type_title' => RevenueCost::$voucher_type[$value['voucher_type']] ?? "",
-            ];
-        }
-        $footer = $this->countTotal($result, $user['header_default']);
-        $footer['profit_rate'] = $footer['profit_rate'] . "%";
-        $footer = array_merge( [
-            'order_number'        => '',
-            'customer_code'       => '',
-            'customer_title'      => '',
-            'channel_finance'     => '',
-            'product_code'        => '',
-            'product_title'       => '',
-            'product_size'        => '',
-            'unit'                => '',
-            'quantity'            => '',
-            'payment_amount'      => '',
-            'price_1'             => '',
-            'price_1_total'       => '',
-            'price_4'             => '',
-            'price_4_total'       => '',
-            'profit'              => '',
-            'profit_rate'         => '',
-            'customer_profit_rate'=> '',
-            'voucher_type_title'  => '',
-        ], $footer);
-        $detail[] = $footer;
-
-        $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)
-                    ->whereNotNull('rc.employee_id_2')
-                    ->where('rc.employee_id_2', '<>', '')
-                    ->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'].'%');
-        if(! empty($data['id'])) $model->whereIn('employee_index.id', $data['id']);
-
-        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);
-
-        $list['count'] = $this->countTotal($list['data'], $user['header_default']);
-
-        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)
+    public function statisticsEmployeeCommon($data,$user){
+        if(empty($data['order_time'][0]) || ! empty($data['order_time'][1])) return [false, '时间不能为空'];
+
+        list($start_time, $end_time) = $this->changeDateToTimeStampAboutRange($data['order_time'],false);
+        if ($start_time === null || $end_time === null || $start_time > $end_time) return [false, "时间的区间无效"];
+
+        $day = $this->returnDays([
+            0 => $start_time,
+            1 => $end_time,
+        ]);
+        if($day > 365) return [false, '查询时间仅支持范围区间在365天内'];
+
+        $model = RdDetails::from('rd_details as a')
+            ->leftJoin('rd as b','b.id','a.rd_id')
+            ->where('a.del_time',0)
+            ->where('b.del_time',0)
+            ->where('b.order_time', '>=', $start_time)
+            ->where('b.order_time', '<=', $end_time)
+            ->where('a.type', RdDetails::type_one)
+            ->select('b.item_id','b.total_hours','a.data_id')
             ->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'].'%');
-        if(! empty($data['id'])) $model->whereIn('id', $data['id']);
-
-        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);
-
-        $list['count'] = $this->countTotal($list['data'], $user['header_default']);
-
-        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;
-    }
 
-    public function statisticsFreightFeeCommon($data,$user, $field = []){
-        if(empty($field)) {
-            $field = FreightFee::$field;
+        if(! empty($data['item_code'])) {
+            $item_id = Item::where('code', 'LIKE', '%'.$data['item_code'].'%')
+                ->where('del_time',0)
+                ->pluck('id')
+                ->toArray();
+            $model->whereIn('b.item_id', $item_id);
         }
-        $model = FreightFee::Clear($user,$data);
 
-        $model = $model->where('del_time',0)
-            ->select($field)
-            ->groupby('order_time')
-            ->orderby('order_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('order_time', '>=', $start_time)
-                ->where('order_time', '<=', $end_time);
+        if(! empty($data['employee_title'])) {
+            $data_id = Employee::where('emp_name', 'LIKE', '%'.$data['employee_title'].'%')
+                ->where('del_time',0)
+                ->pluck('id')
+                ->toArray();
+            $model->whereIn('a.data_id', $data_id);
         }
-        if(! empty($data['employee_id_1_title'])) $model->where('employee_id_1_title', 'LIKE', '%'.$data['employee_id_1_title'].'%');
-        if(! empty($data['id'])) $model->whereIn('order_time', $data['id']);
 
-        return [true, $model];
+        return [true, [$model, [
+            0 => $start_time,
+            1 => $end_time,
+        ]]];
     }
 
-    public function statisticsFreightFee($data,$user){
-        list($status, $model) = $this->statisticsFreightFeeCommon($data, $user);
-        if(! $status) return [false, $model];
-        $list = $this->limit($model,'',$data);
-        $list = $this->statisticsFreightFeeFillData($list, $user,$data);
-
-        $list['count'] = $this->countTotal($list['data'], $user['header_default']);
+    public function statisticsEmployee($data,$user){
+        list($status, $return) = $this->statisticsEmployeeCommon($data, $user);
+        if(! $status) return [false, $return];
+        list($model, $ergs) = $return;
+        $list = $model->get()->toArray();
+        $list = $this->statisticsEmployeeFillData($list, $ergs);
 
+//        $list['count'] = $this->countTotal($list, $user['header_default']);
         return [true, $list];
     }
 
-    public function statisticsFreightFeeFillData($data, $user, $ergs){
-        if(empty($data['data'])) return $data;
-
-        $order_time = array_column($data['data'], 'order_time');
-        $model = FreightFee::Clear($user,$ergs);
-        $allFees = $model->where('del_time', 0)
-            ->whereIn('order_time', $order_time)
-            ->get()
+    public function statisticsEmployeeFillData($data, $ergs){
+        $employee_id = array_unique(array_column($data,'data_id'));
+        $employee_hours_map = EmployeeDetails::where('del_time', 0)
+            ->whereIn('employee_id', $employee_id)
+            ->whereBetween('time', $ergs)
+            ->groupBy('employee_id')
+            ->pluck(DB::raw('SUM(total_hours)'), 'employee_id')
             ->toArray();
-        $feesByDay = [];
-        foreach ($allFees as $f) {
-            $feesByDay[$f['order_time']][] = $f;
-        }
+        $employee = Employee::where('del_time',0)
+            ->where('id','<>',Employee::SPECIAL_ADMIN)
+            ->select('id','emp_name as name')
+            ->get()->toArray();
 
-        foreach ($data['data'] as $key => $value) {
-            $fees = $feesByDay[$value['order_time']] ?? [];
-            if (empty($fees)) {
-                $data['data'][$key]['total_amount'] = 0;
-                continue;
+        $employee_map = $employee_map_2 = $item_id = [];
+        foreach ($data as $value){
+            if(isset($employee_map[$value['data_id']])){
+                $total_hours = bcadd($employee_map[$value['data_id']], $value['total_hours'],2);
+                $employee_map[$value['data_id']] = $total_hours;
+            }else{
+                $employee_map[$value['data_id']] = $value['total_hours'];
+            }
+            $key = $value['data_id'];
+            if(isset($employee_map_2[$key][$value['item_id']])){
+                $total_hours_2 = bcadd($employee_map_2[$key][$value['item_id']], $value['total_hours'],2);
+                $employee_map_2[$key][$value['item_id']] = $total_hours_2;
+            }else{
+                $employee_map_2[$key][$value['item_id']] = $value['total_hours'];
             }
 
-            // 准备 time_amount(和详情逻辑一致)
-            $time_amount = [];
-            foreach ($fees as $f) {
-                if ($f['business_type_id'] == FreightFee::businessTypeNormal) {
-                    $k = $f['order_time'] . $f['area_hs'];
-                    $time_amount[$k]['amount'] = isset($time_amount[$k]['amount'])
-                        ? bcadd($f['freight_amount'], $time_amount[$k]['amount'], 4)
-                        : $f['freight_amount'];
-                    $time_amount[$k]['is_use'] = $time_amount[$k]['is_use'] ?? 0;
+            if(! in_array($value['item_id'], $item_id)) $item_id[] = $value['item_id'];
+        }
+        unset($data);
+
+        $item_total = Item::where('del_time',0)->select('code','id')->get()->toArray();
+        $item_map = array_column($item_total,'code','id');
+
+        $tmp = [];
+        foreach ($item_total as $value){
+            $tmp[$value['id']] = 0;
+        }
+        foreach ($employee as $key => $value){
+            //设置的人员在时间段内的总工时
+            $set_total_hours = $employee_hours_map[$value['id']] ?? 0;
+            $employee[$key]['set_total_hours'] = $set_total_hours;
+            //汇总研发工时单里的总工时
+            $rd_total_hours = $employee_map[$value['id']] ?? 0;
+            $employee[$key]['rd_total_hours'] = $rd_total_hours;
+            //每个项目的工时
+            $every_item_hours = $employee_map_2[$value['id']] ?? [];
+            $details = $tmp;
+            $my_item = "";
+            if(! empty($every_item_hours)){
+                foreach ($every_item_hours as $item => $item_hour){
+                    if(isset($details[$item])) $details[$item] = $item_hour;
+                    $code = $item_map[$item] ?? "";
+                    if(! empty($code)) $my_item .= $code . ",";
                 }
+                $my_item = rtrim($my_item,',');
             }
-
-            // 逐条算金额
-            $valueTotal = 0;
-            foreach ($fees as $f) {
-                $f = $this->calculateFreightFeeRow($f, $time_amount);
-                $valueTotal = bcadd($valueTotal, $f['total_amount'], 4);
+            foreach ($details as $it => $d_v){
+                $employee[$key]['item_' . $it] = $d_v;
             }
-
-            $data['data'][$key]['total_amount'] = $valueTotal;
-
-            $order_time = $value['order_time'] ? date('Y-m-d',$value['order_time']) : '';
-            $data['data'][$key]['order_time_show'] = $order_time;
-            $data['data'][$key]['id'] = $value['order_time'];
+            //自己研发的项目
+            $employee[$key]['my_item'] = $my_item;
+            $employee[$key]['position'] = "研发人员";
+            $employee[$key]['type_title'] = "专职";
+            $employee[$key]['rate_one'] = "100%";
+            $employee[$key]['rate_two'] = "100%";
+            $employee[$key]['rate_three'] = "100%";
         }
 
-        return $data;
+        return $employee;
     }
 
-    public function statisticsFreightFeeDetail($data, $user)
-    {
-        if (empty($data['order_time'])) {
-            return [false, '单据日期不能为空'];
-        }
-
-        $model = FreightFee::Clear($user,$data);
-        $fee = $model->where('del_time', 0)
-            ->where('order_time', $data['order_time'])
-            ->get()
-            ->toArray();
-
-        if (empty($fee)) {
-            return [false, '单据日期下暂无数据'];
-        }
+    public function statisticsDeviceCommon($data,$user, $field = []){
+        if(empty($data['order_time'][0]) || ! empty($data['order_time'][1])) return [false, '时间不能为空'];
+
+        list($start_time, $end_time) = $this->changeDateToTimeStampAboutRange($data['order_time'],false);
+        if ($start_time === null || $end_time === null || $start_time > $end_time) return [false, "时间的区间无效"];
+
+        $day = $this->returnDays([
+            0 => $start_time,
+            1 => $end_time,
+        ]);
+        if($day > 365) return [false, '查询时间仅支持范围区间在365天内'];
+
+        $model = RdDetails::from('rd_details as a')
+            ->leftJoin('rd as b','b.id','a.rd_id')
+            ->where('a.del_time',0)
+            ->where('b.del_time',0)
+            ->where('b.order_time', '>=', $start_time)
+            ->where('b.order_time', '<=', $end_time)
+            ->where('a.type', RdDetails::type_two)
+            ->select('b.item_id','b.total_hours','a.data_id')
+            ->orderby('order_time', 'desc');
 
-        // 按时间+地区聚合同一天、同地区的非退货配送费
-        $time_amount = [];
-        foreach ($fee as $value) {
-            if ($value['business_type_id'] == FreightFee::businessTypeNormal) {
-                $key = $value['order_time'] . $value['area_hs'];
-                $time_amount[$key]['amount'] = isset($time_amount[$key]['amount'])
-                    ? bcadd($value['freight_amount'], $time_amount[$key]['amount'], 4)
-                    : $value['freight_amount'];
-                $time_amount[$key]['is_use'] = $time_amount[$key]['is_use'] ?? 0;
-            }
+        if(! empty($data['item_code'])) {
+            $item_id = Item::where('code', 'LIKE', '%'.$data['item_code'].'%')
+                ->where('del_time',0)
+                ->pluck('id')
+                ->toArray();
+            $model->whereIn('b.item_id', $item_id);
         }
 
-        $return = [];
-        foreach ($fee as $value) {
-            $value = $this->calculateFreightFeeRow($value, $time_amount);
-            $key = $value['order_time'] . '|' . $value['area_hs'];
-            $return[$value['business_type_id']][$key][] = $value;
+        if(! empty($data['device_title'])) {
+            $data_id = Device::where('title', 'LIKE', '%'.$data['device_title'].'%')
+                ->where('del_time',0)
+                ->pluck('id')
+                ->toArray();
+            $model->whereIn('a.data_id', $data_id);
         }
 
-        $result = [];
-        // 需要合计的字段
-        $sumFields = ['xs', 'weight', 'freight_amount', 'js_amount', 'customer_store_zx_fee', 'jj_fee', 'dh_fee', 'total_amount'];
-        $sumFields_map = ['weight' => 4,'freight_amount' => 4, 'js_amount' => 4,'customer_store_zx_fee' => 4, 'jj_fee' => 4, 'dh_fee' => 4, 'total_amount' => 4];
-
-        // 业务类型 日期 地区 算一张表算运费
-        foreach ($return as $g => $group) {
-            $g_title = FreightFee::$business[$g] ?? "";
-            foreach ($group as $key => $val) {
-                $tmp_key = explode('|', $key);
-                $title = $tmp_key[1] . "(" . $g_title . ")";
-                // 计算合计
-                $sumRow = [];
-                foreach ($val as $key => $row) {
-                    $order_time = $row['order_time'] ? date('Y-m-d',$row['order_time']) : '';
-                    $val[$key]['order_time_show'] = $order_time;
-                    $val[$key]['is_present_show'] = $row['is_present'] ? '是' : '否';
-                    $delivery_mode_show = FreightFee::$delivery[$row['delivery_mode']] ?? "";
-                    $val[$key]['delivery_mode_show'] = $delivery_mode_show;
-                    $val[$key]['area_range_show'] = $row['area_range'] == 1 ? '1~5吨' : '5吨以上';
-                    foreach ($sumFields as $field) {
-                        $decimals = $sumFields_map[$field] ?? 2;
-                        $sumRow[$field] = isset($sumRow[$field])
-                            ? bcadd($sumRow[$field], $row[$field], $decimals)
-                            : $row[$field];
-                    }
-                }
+        return [true, [$model, [
+            0 => $start_time,
+            1 => $end_time,
+        ]]];
+    }
 
-                // 末行合计行(非合计字段设为空字符串)
-                $footer = [];
-                foreach ($val[0] as $field => $v) {
-                    $footer[$field] = in_array($field, $sumFields) ? $sumRow[$field] : '';
-                }
+    public function statisticsDevice($data,$user){
+        list($status, $return) = $this->statisticsDeviceCommon($data, $user);
+        if(! $status) return [false, $return];
+        list($model, $ergs) = $return;
+        $list = $model->get()->toArray();
+        $list = $this->statisticsDeviceFillData($list,$ergs);
 
-                $val[] = $footer;
+//        $list['count'] = $this->countTotal($list['data'], $user['header_default']);
 
-                $result[] = [
-                    'key' => $title,
-                    'list' => $val
-                ];
-            }
-        }
-
-        return [true, $result];
+        return [true, $list];
     }
 
-    public function statisticsFreightFeeDetailsForExport($data, $user)
-    {
-        if (empty($data['order_time'])) return [];
-
-        $model = FreightFee::Clear($user, $data);
-        $orderTimes = is_array($data['order_time']) ? $data['order_time'] : [$data['order_time']];
-
-        $fee = $model->where('del_time', 0)
-            ->whereIn('order_time', $orderTimes)
-            ->get()
+    public function statisticsDeviceFillData($data, $ergs){
+        $employee_id = array_unique(array_column($data,'data_id'));
+        $device_hours_map = DeviceDetails::where('del_time', 0)
+            ->whereIn('device_id', $employee_id)
+            ->whereBetween('time', $ergs)
+            ->groupBy('device_id')
+            ->pluck(DB::raw('SUM(total_hours)'), 'device_id')
             ->toArray();
+        $device = Device::where('del_time',0)
+            ->select('id','title as name','code','type','type_2','power','in_time','number')
+            ->get()->toArray();
 
-        // 表头定义(所有 sheet 通用)
-        $header = [
-            "仓库", "销货单备注", "业务类型", "销货单号", "销货日期", "客户",
-            "客户门店装车费单价", "业务员", "送货地址", "地区华商", "存货编码", "存货名称", "箱规",
-            "华商重量", "门店卸货费单价(华商)", "门店卸货费单价(华商)", "赠品", "货类(华商)", "运输方式",
-            "数量", "含税单价", "含税金额", "箱数", "总重量", "运价区间", "配送费单价", "配送费金额", "结算金额",
-            "门店卸货费", "上楼费", "加急费", "到货装卸费", "总金额"
-        ];
-
-        if (empty($fee)) {
-            // 返回每个请求的日期都带表头(只有表头),以便导出时每个 sheet 至少有表头
-            $resultEmpty = [];
-            foreach ($orderTimes as $ot) {
-                $dateKey = date('Y-m-d', $ot);
-                $resultEmpty[$dateKey] = [
-                    0 => $header
-                ];
-            }
-            return $resultEmpty;
-        }
-
-        // 按时间+地区聚合同一天、同地区的非退货配送费(用于 calculate 逻辑)
-        $time_amount = [];
-        foreach ($fee as $value) {
-            if ($value['business_type_id'] == FreightFee::businessTypeNormal) {
-                $key = $value['order_time'] . $value['area_hs'];
-                $time_amount[$key]['amount'] = isset($time_amount[$key]['amount'])
-                    ? bcadd($value['freight_amount'], $time_amount[$key]['amount'], 4)
-                    : $value['freight_amount'];
-                $time_amount[$key]['is_use'] = $time_amount[$key]['is_use'] ?? 0;
+        $device_map = $device_map_2 = $item_id = [];
+        foreach ($data as $value){
+            if(isset($device_map[$value['data_id']])){
+                $total_hours = bcadd($device_map[$value['data_id']], $value['total_hours'],2);
+                $device_map[$value['data_id']] = $total_hours;
+            }else{
+                $device_map[$value['data_id']] = $value['total_hours'];
             }
-        }
-
-        // 先按 order_time -> business_type_id -> (order_time|area_hs) 分组收集数据行
-        $grouped = [];
-        foreach ($fee as $value) {
-            $value = $this->calculateFreightFeeRow($value, $time_amount);
-            $key = $value['order_time'] . '|' . $value['area_hs'];
-            $grouped[$value['order_time']][$value['business_type_id']][$key][] = $value;
-        }
-
-        // 构造返回:每个日期一个 sheet(键为 YYYY-MM-DD),值为数值下标数组,0 为表头
-        $result = [];
-
-        // 需要合计的字段及小数位
-        $sumFields = ['xs','weight', 'freight_amount', 'js_amount', 'customer_store_zx_fee', 'jj_fee', 'dh_fee', 'total_amount'];
-        $sumFields_map = ['xs' => 0,'weight' => 4, 'freight_amount' => 4, 'js_amount' => 4, 'customer_store_zx_fee' => 4, 'jj_fee' => 4, 'dh_fee' => 4, 'total_amount' => 4];
-
-        // 初始化每个传入日期,确保即使某个日期无数据也有表头
-        foreach ($orderTimes as $ot) {
-            $dateKey = date('Y-m-d', $ot);
-            $result[$dateKey] = [];
-            $result[$dateKey][] = $header; // index 0 为表头
-        }
-
-        // 填充数据
-        foreach ($grouped as $order_time => $types) {
-            $dateKey = date('Y-m-d', $order_time);
-            // 若该日期未初始化(理论上不会),先初始化表头
-            if (!isset($result[$dateKey])) {
-                $result[$dateKey] = [];
-                $result[$dateKey][] = $header;
+            $key = $value['data_id'];
+            if(isset($device_map_2[$key][$value['item_id']])){
+                $total_hours_2 = bcadd($device_map_2[$key][$value['item_id']], $value['total_hours'],2);
+                $device_map_2[$key][$value['item_id']] = $total_hours_2;
+            }else{
+                $device_map_2[$key][$value['item_id']] = $value['total_hours'];
             }
 
-            foreach ($types as $business_type_id => $group) {
-                $businessTitle = FreightFee::$business[$business_type_id] ?? '';
-                foreach ($group as $key => $rows) {
-                    // 每个 key 对应一组明细(按 area_hs 分组)
-                    $sumRow = []; // 用于该分组的合计
-
-                    foreach ($rows as $row) {
-                        $date_show = $row['order_time'] ? date('Y-m-d', $row['order_time']) : "";
-                        $is_present_show = !empty($row['is_present']) ? '是' : '否';
-                        $delivery_mode_show = FreightFee::$delivery[$row['delivery_mode']] ?? "";
-                        $area_range_show = isset($row['area_range']) && $row['area_range'] == 1 ? '1~5吨' : '5吨以上';
-
-                        // 单行数据(按你指定的字段顺序)
-                        $line = [
-                            $row['warehouse_name'] ?? '', // 仓库
-                            $row['mark'] ?? '', // 销货单备注
-                            $row['business_type_title'] ?? '', // 业务类型
-                            $row['order_number'] ?? '', // 销货单号
-                            $date_show, // 销货日期
-                            $row['customer_title'] ?? '', // 客户
-                            $row['customer_store_price'] ?? 0, // 客户门店装车费单价
-                            $row['employee_id_1_title'] ?? '', // 业务员
-                            $row['address'] ?? '', // 送货地址
-                            $row['area_hs'] ?? '', // 地区华商
-                            $row['product_code'] ?? '', // 存货编码
-                            $row['product_title'] ?? '', // 存货名称
-                            $row['product_box_size'] ?? '', // 箱规
-                            $row['product_weight'] ?? 0, // 华商重量
-                            $row['product_store_price'] ?? 0, // 门店卸货费单价(华商)
-                            $row['product_store_price2'] ?? 0, // 到货装卸费单价(华商)
-                            $is_present_show, // 赠品
-                            $row['product_category'] ?? '', // 货类(华商)
-                            $delivery_mode_show, // 运输方式
-                            $row['quantity'] ?? 0, // 数量
-                            $row['price_3'] ?? 0, // 含税单价
-                            $row['price_3_total'] ?? 0, // 含税金额
-                            number_format($row['xs'] ?? 0), // 箱数
-                            $row['weight'] ?? 0, // 总重量
-                            $area_range_show, // 运价区间
-                            $row['freight_unit_price'] ?? 0, // 配送费单价
-                            $row['freight_amount'] ?? 0, // 配送费金额
-                            $row['js_amount'] ?? 0, // 结算金额
-                            $row['customer_store_zx_fee'] ?? 0, // 门店卸货费
-                            $row['sl_fee'] ?? 0, // 上楼费
-                            number_format($row['jj_fee'] ?? 0, 2), // 加急费
-                            $row['dh_fee'] ?? 0, // 到货装卸费
-                            $row['total_amount'] ?? 0, // 总金额
-                        ];
-
-                        $result[$dateKey][] = $line;
-
-                        // 累加合计
-                        foreach ($sumFields as $field) {
-                            $decimals = $sumFields_map[$field] ?? 2;
-                            $sumRow[$field] = isset($sumRow[$field])
-                                ? bcadd($sumRow[$field], $row[$field], $decimals)
-                                : ($row[$field] ?? 0);
-                        }
-                    }
-
-                    // 添加本分组合计行(合计位置与表头列对齐,其它非合计字段留空)
-                    $totalLine = [
-                        '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
-                        $sumRow['xs'] ?? 0,
-                        $sumRow['weight'] ?? 0,
-                        '', '',
-                        $sumRow['freight_amount'] ?? 0, // 配送费金额合计
-                        $sumRow['js_amount'] ?? 0, // 结算金额合计
-                        $sumRow['customer_store_zx_fee'] ?? 0, // 门店卸货费合计
-                        $sumRow['sl_fee'] ?? 0, // 上楼费合计
-                        $sumRow['jj_fee'] ?? 0, // 加急费合计
-                        $sumRow['dh_fee'] ?? 0, // 到货装卸费合计
-                        $sumRow['total_amount'] ?? 0, // 总金额合计
-                    ];
-
-                    $result[$dateKey][] = $totalLine;
+            if(! in_array($value['item_id'], $item_id)) $item_id[] = $value['item_id'];
+        }
+        unset($data);
+
+        $item_total = Item::where('del_time',0)->select('code','id')->get()->toArray();
+        $item_map = array_column($item_total,'code','id');
+
+        $tmp = [];
+        foreach ($item_total as $value){
+            $tmp[$value['id']] = 0;
+        }
+        foreach ($device as $key => $value){
+            //设置的设备在时间段内的总工时
+            $set_total_hours = $device_hours_map[$value['id']] ?? 0;
+            $device[$key]['set_total_hours'] = $set_total_hours;
+            //汇总研发工时单里的总工时
+            $rd_total_hours = $device_map[$value['id']] ?? 0;
+            $device[$key]['rd_total_hours'] = $rd_total_hours;
+            //每个项目的工时
+            $every_item_hours = $device_map_2[$value['id']] ?? [];
+
+            $details = $tmp;
+            $my_item = "";
+            if(! empty($every_item_hours)){
+                foreach ($every_item_hours as $item => $item_hour){
+                    if(isset($details[$item])) $details[$item] = $item_hour;
+                    $code = $item_map[$item] ?? "";
+                    if(! empty($code)) $my_item .= $code . ",";
                 }
+                $my_item = rtrim($my_item,',');
             }
-        }
-
-        // 确保每个日期的数组是从 0 开始的连续下标(虽然我们已经按顺序 push,但为了保险)
-
-        return $result;
-    }
-
-    protected function calculateFreightFeeRow(array $value, array &$time_amount)
-    {
-        $key = $value['order_time'] . $value['area_hs'];
-        $js_amount = 0;
-
-        if ($value['business_type_id'] == FreightFee::businessTypeNormal) {
-            $tmp_total_arr = $time_amount[$key];
-
-            // 判断是否使用最低运费
-            if ($tmp_total_arr['amount'] < $value['min_freight_amount']) {
-                if (!$time_amount[$key]['is_use']) {
-                    $js_amount = $value['min_freight_amount'];
-                    $time_amount[$key]['is_use'] = 1;
-                }
-            } else {
-                $js_amount = $value['js_single_amount'];
+            foreach ($details as $it => $d_v){
+                $device[$key]['item_' . $it] = $d_v;
             }
-        } else {
-            $js_amount = $value['js_single_amount'];
-        }
 
-        $value['js_amount'] = $js_amount;
+            $device[$key]['my_item'] = $my_item;
 
-        // 加急费
-        $jj_fee = 0;
-        if ($value['delivery_mode'] == FreightFee::deliveryModeRightNow) {
-            $jj_fee = bcmul($js_amount, 0.5, 4);
+            $device[$key]['position'] = "研发人员";
+            $device[$key]['type_title'] = Device::$type[$value['type']] ?? "";
+            $device[$key]['type_2_title'] = Device::$type_2[$value['type_2']] ?? "";
+            $device[$key]['rate_one'] = "100%";
+            $device[$key]['rate_two'] = "100%";
+            $device[$key]['rate_three'] = "100%";
         }
-        $value['jj_fee'] = $jj_fee;
-
-        // 总金额
-        $total_amount = bcadd($js_amount, $value['customer_store_zx_fee'], 4);
-        $total_amount = bcadd($total_amount, $value['sl_fee'], 4);
-        $total_amount = bcadd($total_amount, $jj_fee, 4);
-        $total_amount = bcadd($total_amount, $value['dh_fee'], 4);
-        $value['total_amount'] = $total_amount;
 
-        return $value;
+        return $device;
     }
 }

+ 25 - 0
app/Service/TableHeadService.php

@@ -2,6 +2,7 @@
 
 namespace App\Service;
 
+use App\Model\Item;
 use App\Model\TableSearchSetting;
 use App\Model\TableSetting;
 use Illuminate\Support\Facades\DB;
@@ -65,6 +66,8 @@ class TableHeadService extends Service
             ->get()->toArray();
         $header_map = array_column($header,null,'key');
         $header_default = config("header.{$data['menu_id']}") ?? [];
+        $header_f = "extra_" . $data['menu_id'];
+        if(method_exists($this,$header_f)) $this->$header_f($header_default);
 
         foreach ($header_default as $key => $value){
             if(isset($header_map[$value['key']])) {
@@ -99,6 +102,28 @@ class TableHeadService extends Service
         return [true, ['column' => $header_default, 'common' => $header_common]];
     }
 
+    private function extra_73(&$data){
+        $item_total = Item::where('del_time',0)->pluck('code','id')->toArray();
+
+        foreach ($item_total as $key => $value){
+            $data[] = [
+                "key" => "extra_" . $key,
+                "value" => $value
+            ];
+        }
+    }
+
+    private function extra_74(&$data){
+        $item_total = Item::where('del_time',0)->pluck('code','id')->toArray();
+
+        foreach ($item_total as $key => $value){
+            $data[] = [
+                "key" => "extra_" . $key,
+                "value" => $value
+            ];
+        }
+    }
+
     public function filterAdd($data, $user){
         if(! isset($data['is_filter'])) return [false,'是否打开筛选不能为空'];
         if(empty($data['menu_id'])) return [false, 'menu_id不能为空'];

+ 8 - 0
config/header/66.php

@@ -14,6 +14,14 @@ return [
         'key' =>'title',
         'value' => '名称',
     ],
+    [
+        'key' =>'type_title',
+        'value' => '固定资产类型',
+    ],
+    [
+        'key' =>'type_2_title',
+        'value' => '类型',
+    ],
     [
         'key' =>'size',
         'value' => '规格型号',

+ 18 - 64
config/header/73.php

@@ -7,85 +7,39 @@
 
 return [
     [
-        'key' =>'order_time',
-        'value' => '统计年月',
+        'key' =>'name',
+        'value' => '研发人员名',
     ],
     [
-        'key' =>'employee_id_1_title',
-        'value' => '业务员',
+        'key' =>'position',
+        'value' => '岗位',
     ],
     [
-        'key' =>'payment_amount',
-        'value' => '回款总金额',
-        'sum' => 1,
+        'key' =>'type_title',
+        'value' => '类型',
     ],
     [
-        'key' =>'payment_amount_not_include_activity',
-        'value' => '回款金额(非活动)',
-        'value1' => '业务员所有非活动属性的回款单金额总计',
-        'sum' => 1,
+        'key' =>'my_item',
+        'value' => '应用RD编号',
     ],
     [
-        'key' =>'payment_amount_activity',
-        'value' => '回款金额(活动)',
-        'value1' => '业务员所有活动属性的回款单金额总计',
-        'sum' => 1,
+        'key' =>'rate_one',
+        'value' => '应有占比',
     ],
     [
-        'key' =>'payment_amount_lower_than_rate',
-        'value' => '回款金额(毛利率低于预设的客户毛利率)',
-        'value1' => '汇总条件
-                     一:非活动属性的回款单
-                     二:回款单明细的毛利率<T+中的客户档案的毛利率
-                     达成条件,则汇总回款金额',
-        'sum' => 1,
+        'key' =>'rate_two',
+        'value' => '实际占比',
     ],
     [
-        'key' =>'payment_amount_greater_than_rate',
-        'value' => '回款金额(毛利率高于预设的客户毛利率)',
-        'value1' => '汇总条件
-                     一:非活动属性的回款单
-                     二:回款单明细的毛利率>=T+中的客户档案的毛利率
-                     达成条件,则汇总回款金额',
-        'sum' => 1,
+        'key' =>'rate_three',
+        'value' => '达成率',
     ],
     [
-        'key' =>'business',
-        'value' => '成本金额',
-        'value1' => '汇总条件
-                     一:非活动属性的回款单
-                     二:回款单明细的毛利率>=T+中的客户档案的毛利率
-                     达成条件,则汇总存货的存货业务成本金额',
-        'sum' => 1,
+        'key' =>'set_total_hours',
+        'value' => '总工时(小时)',
     ],
     [
-        'key' =>'salary_bonus',
-        'value' => '销售奖金',
-        'value1' => '人员档案中该业务员统计年月内的销售奖金',
-        'sum' => 1,
-    ],
-    [
-        'key' =>'index_1',
-        'value' => '预支分红比例',
-        'value1' => '人员档案中该业务员统计年月内的预支分红比例',
-        'split_join' => '%',
-    ],
-    [
-        'key' =>'pay_in_advance',
-        'value' => '预支分红提成',
-        'value1' => '回款金额(毛利率高于预设的客户毛利率) * 预支分红比例',
-        'sum' => 1,
-    ],
-    [
-        'key' =>'basic_salary',
-        'value' => '基本工资',
-        'value1' => '人员档案中该业务员统计年月内的基本工资',
-        'sum' => 1,
-    ],
-    [
-        'key' =>'should_pay',
-        'value' => '应发金额',
-        'value1' => '销售奖金 + 预支分红提成 + 基本工资',
-        'sum' => 1,
+        'key' =>'rd_total_hours',
+        'value' => '研发工时(小时)',
     ],
 ];

+ 34 - 28
config/header/74.php

@@ -7,49 +7,55 @@
 
 return [
     [
-        'key' =>'check_time',
-        'value' => '核算时间区间',
-        'value1' => '人员档案中预设的(季度指标金额)时间段',
+        'key' =>'name',
+        'value' => '研发设备',
     ],
     [
-        'key' =>'employee_id_2_title',
-        'value' => '上级管理人员',
+        'key' =>'code',
+        'value' => '固定资产编号',
     ],
     [
-        'key' =>'payment_amount',
-        'value' => '回款金额',
-        'sum' => 1,
+        'key' =>'type_title',
+        'value' => '固定资产类别',
     ],
     [
-        'key' =>'index',
-        'value' => '季度指标金额',
+        'key' =>'in_time',
+        'value' => '入账日期',
     ],
     [
-        'key' =>'index_1',
-        'value' => '预支分红比例%',
-        'split_join' => '%',
+        'key' =>'type_2_title',
+        'value' => '类型',
     ],
     [
-        'key' =>'index_5',
-        'value' => '分红比例%',
-        'split_join' => '%',
+        'key' =>'my_item',
+        'value' => '应用RD编号',
     ],
     [
-        'key' =>'should_pay',
-        'value' => '应发放金额',
-        'value1' => '条件一:(回款金额 < 季度指标金额)公式:回款金额 *(分红比例 / 2 - 预支分红比例 / 2);
-                     条件二:(回款金额 >= 季度指标金额) 公式:回款金额 *(分红比例 / 2 - 预支分红比例 / 2 +(回款金额 - 季度指标金额)* 0.15 / 2)
-                     ',
-        'sum' => 1,
+        'key' =>'rate_one',
+        'value' => '应有占比',
     ],
     [
-        'key' =>'payed',
-        'value' => '已发放金额',
-        'sum' => 1,
+        'key' =>'power',
+        'value' => '功率(千瓦时)',
     ],
     [
-        'key' =>'not_pay',
-        'value' => '未发放金额',
-        'sum' => 1,
+        'key' =>'number',
+        'value' => '数量',
+    ],
+    [
+        'key' =>'rate_two',
+        'value' => '实际占比',
+    ],
+    [
+        'key' =>'rate_three',
+        'value' => '达成率',
+    ],
+    [
+        'key' =>'set_total_hours',
+        'value' => '总工时(小时)',
+    ],
+    [
+        'key' =>'rd_total_hours',
+        'value' => '研发工时(小时)',
     ],
 ];

+ 4 - 0
routes/api.php

@@ -116,6 +116,10 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('rdDel', 'Api\RDController@rdDel');
     $route->any('rdDetail', 'Api\RDController@rdDetail');
 
+    //统计
+    $route->any('statisticEmployee', 'Api\StatisticsController@statisticEmployee');
+    $route->any('statisticDevice', 'Api\StatisticsController@statisticDevice');
+
     //获取默认表头
     $route->any('getTableHead','Api\TableHeadController@tableHeadGet');
     //设置表头