chenqp há 7 meses atrás
pai
commit
26453da546

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

@@ -78,4 +78,16 @@ class StatisticsController extends BaseController
             return $this->json_return(201,$data);
         }
     }
+
+    public function statisticsCustomer(Request $request){
+        $service = new StatisticsService();
+        $userData = $request->userData->toArray();
+        list($status,$data) = $service->statisticsCustomer($request->all(),$userData);
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
 }

+ 1 - 0
app/Service/ImportService.php

@@ -599,6 +599,7 @@ class ImportService extends Service
             $tmp['cost'] = $value['6'] ?? 0;
             $tmp['retail_price'] = $value['7'] ?? 0;
             $tmp['product_attribute'] = $value['8'] ?? 0;
+            $tmp['build_fee'] = $value['9'] ?? 0;
             foreach ($map as $m => $v){
                 if($value[$v['col']]){
                     if(! is_numeric($value[$v['col']])) return [false,$v['name'] . ': 请输入数字且最多两位小数'];

+ 80 - 0
app/Service/StatisticsService.php

@@ -2,6 +2,8 @@
 
 namespace App\Service;
 
+use App\Model\BasicType;
+use App\Model\Customer;
 use App\Model\Depart;
 use App\Model\DepartIndex;
 use App\Model\InOutRecord;
@@ -21,6 +23,84 @@ use Illuminate\Support\Facades\DB;
 
 class StatisticsService extends Service
 {
+    public function statisticsCustomer($data,$user){
+        if(empty($data['crt_time'][0]) || empty($data['crt_time'][1])) return [false, '请选择客资创建时间区间'];
+
+        $model = Customer::Clear($user,$data);
+        $model = $model->where('del_time',0)
+            ->select('id','model_type','customer_from','top_depart_id','fp_top_depart_id')
+            ->orderby('id', 'desc');
+
+        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]);
+        }
+
+        $list = $model->get()->toArray();
+        $list1 = $this->fillStatisticsCustomer($list);
+        $list2 = $this->fillStatisticsCustomer2($list);
+
+        return [true, ['bt' => $list1, 'zz' => $list2]];
+    }
+
+    public function fillStatisticsCustomer($data){
+        if(empty($data)) return $data;
+
+        $customer_from = array_unique(array_column($data,'customer_from'));
+        $basic_type = BasicType::where('del_time',0)
+            ->whereIn('id',$customer_from)
+            ->where('type',2)
+            ->pluck('title','id')
+            ->toArray();
+
+        $return = [];
+        foreach ($data as $value){
+            $tmp = $basic_type[$value['customer_from']] ?? "";
+            if(! $tmp) continue;
+            if(isset($return[$tmp])){
+                $return[$tmp]['total'] += 1;
+            }else{
+                $return[$tmp] = [
+                    'total' => 1,
+                    'title' => $tmp
+                ];
+            }
+        }
+
+        return array_values($return);
+    }
+
+    public function fillStatisticsCustomer2($data){
+        if(empty($data)) return $data;
+
+        $depart = Depart::where('del_time',0)
+            ->where('parent_id',0)
+            ->where('is_main',0)
+            ->pluck('title','id')
+            ->toArray();
+        $return = [];
+        foreach ($depart as $key => $value){
+            $return[$key] = [
+                'title' => $value,
+                'total' => 0
+            ];
+        }
+
+        foreach ($data as $value){
+            if($value['fp_top_depart_id'] > 0){
+                if(isset($return[$value['fp_top_depart_id']])) $return[$value['fp_top_depart_id']]['total'] += 1;
+            }
+        }
+
+        $return = array_values($return);
+        usort($return, function($a, $b) {
+            return $b['total'] - $a['total'];
+        });
+
+        return $return;
+    }
+
     //销售统计饼图 根据合同类型区分(例如线上合同、线下合同)
     public function statisticsBt($data,$user){
         if(empty($data['crt_time'][0]) || empty($data['crt_time'][1])) return [false, '请选择销售订单时间区间'];

+ 4 - 0
config/excel/productTable.php

@@ -36,4 +36,8 @@ return [
         'key' =>'product_attribute',
         'value' => '产品属性',
     ],
+    [
+        'key' => 'build_fee',
+        'value' => '安装费',
+    ]
 ];

+ 4 - 0
config/header/17.php

@@ -47,6 +47,10 @@ return [
         'value' => '零售价',
     ],
     [
+        'key' => 'build_fee',
+        'value' => '安装费',
+    ],
+    [
         'key' => 'belong_to',
         'value' => '所属门店',
     ],

+ 1 - 0
routes/api.php

@@ -283,6 +283,7 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('statisticsArea', 'Api\StatisticsController@statisticsArea');
     $route->any('statisticsAreaDepart', 'Api\StatisticsController@statisticsAreaDepart');
     $route->any('statisticsAreaDepartProduct', 'Api\StatisticsController@statisticsAreaDepartProduct');
+    $route->any('statisticsCustomer', 'Api\StatisticsController@statisticsCustomer');
 
     //设置开关
     $route->any('productInventorySet', 'Api\ProductInventoryController@productInventorySet');