cqp il y a 4 semaines
Parent
commit
df74e1d795

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

@@ -30,4 +30,16 @@ class StatisticsController extends BaseController
             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);
+        }
+    }
 }

+ 2 - 1
app/Model/RevenueCost.php

@@ -27,5 +27,6 @@ class RevenueCost extends Model
     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 = ['order_type','order_number','order_time','employee_id_1','employee_id_1_title','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 = ['order_type','order_number','order_time','employee_id_1','employee_id_1_title','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 = ['order_type','order_number','order_time','employee_id_1','employee_id_1_title','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_hkd_main = ['order_type','order_number','order_time','employee_id_1','employee_id_1_title','employee_id_2_title'];
+    public static $field_hkd_detail = ['order_type','order_number','order_time','employee_id_1','employee_id_1_title','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'];
 }

+ 47 - 0
app/Service/StatisticsService.php

@@ -4,6 +4,7 @@ namespace App\Service;
 
 use App\Model\RevenueCost;
 use App\Model\RevenueCostTotal;
+use Illuminate\Support\Facades\DB;
 
 class StatisticsService extends Service
 {
@@ -140,4 +141,50 @@ class StatisticsService extends Service
 
         return $data;
     }
+
+    public function statisticsRevenueCostThreeCommon($data,$user, $field = []){
+        if(empty($field)) {
+            $field = RevenueCost::$field_hkd_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::where('del_time',0)
+            ->where('order_type',RevenueCost::ORDER_THREE)
+            ->select($field)
+            ->groupby('order_id')
+            ->orderby('id', 'desc');
+        if(! empty($data['order_time'])){
+            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,$user,$data);
+
+        return [true, $list];
+    }
+
+    public function statisticsRevenueCostThreeFillData($data, $user, $ergs){
+        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;
+    }
 }

+ 1 - 1
config/header/69.php

@@ -47,7 +47,7 @@ return [
         'value' => '存货名称',
     ],
     [
-        'key' =>'size',
+        'key' =>'product_size',
         'value' => '规格型号',
     ],
     [

+ 1 - 1
config/header/70.php

@@ -39,7 +39,7 @@ return [
         'value' => '存货名称',
     ],
     [
-        'key' =>'size',
+        'key' =>'product_size',
         'value' => '规格型号',
     ],
     [

+ 41 - 0
config/header/71.php

@@ -0,0 +1,41 @@
+<?php
+/**
+ * '菜单ID' => [
+ *     '字段英文名' =》 '字段中文名'
+ * ]
+ */
+
+return [
+    [
+        'key' =>'order_number',
+        'value' => '回款单号',
+    ],
+    [
+        'key' =>'order_time',
+        'value' => '单据日期',
+    ],
+    [
+        'key' =>'employee_id_1_title',
+        'value' => '业务员',
+    ],
+    [
+        'key' =>'employee_id_2_title',
+        'value' => '上级管理人员',
+    ],
+    [
+        'key' =>'payment_amount',
+        'value' => '回款金额',
+    ],
+    [
+        'key' =>'price_4_total',
+        'value' => '业务成本金额',
+    ],
+    [
+        'key' =>'profit',
+        'value' => '毛利',
+    ],
+    [
+        'key' =>'profit_rate',
+        'value' => '毛利率',
+    ],
+];

+ 1 - 0
routes/api.php

@@ -131,4 +131,5 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     //收入成本
     $route->any('statisticsRevenueCost', 'Api\StatisticsController@statisticsRevenueCost');
     $route->any('statisticsRevenueCostOneAndTwo', 'Api\StatisticsController@statisticsRevenueCostOneAndTwo');
+    $route->any('statisticsRevenueCostThree', 'Api\StatisticsController@statisticsRevenueCostThree');
 });