Kirin 3 роки тому
батько
коміт
3c7b66ac23
1 змінених файлів з 83 додано та 0 видалено
  1. 83 0
      app/api/controller/user/UserController.php

+ 83 - 0
app/api/controller/user/UserController.php

@@ -698,4 +698,87 @@ class UserController
         return app('json')->success('ok', SystemStore::getStoreDispose($admin_indo['store_id']) ? SystemStore::getStoreDispose($admin_indo['store_id'])->toArray() : []);
     }
 
+    public function areaAchievementMonth(Request $request)
+    {
+        $user = $request->user();
+        if ($user['area_admin']) {
+            $where = [];
+            $where['province'] = $user['area_province'];
+            if ($user['area_admin'] == 2 || $user['area_admin'] == 1) $where['city'] = $user['area_city'];
+            if ($user['area_admin'] == 1) $where['district'] = $user['area_district'];
+            $start = StoreOrder::min('add_time');
+            $data = [];
+            while ($start < time()) {
+                $start_month = date('Y-m', $start);
+                $end = strtotime('+1month', strtotime($start_month)) - 1;
+                $frontPrice = StoreOrder:: getOrderTimeBusinessVolumePrice($start, $end, $where);
+                $frontNumber = StoreOrder:: getOrderTimeBusinessVolumeNumber($start, $end, $where);
+                $start = $end + 1;
+                $data[$start_month] = compact('frontPrice', 'frontNumber');
+            }
+            return app('json')->successful($data);
+        }
+        return app('json')->fail('非区域代理');
+    }
+
+
+    /**
+     * 订单交易额/订单数量时间统计
+     * @param Request $request
+     * @return bool
+     */
+    public function areaAchievementTime(Request $request)
+    {
+        $user = $request->user();
+        list($start, $stop, $type) = UtilService::getMore([
+            ['start', strtotime(date('Y-m'))],
+            ['stop', time()],
+            ['type', 1]
+        ], $request, true);
+        if ($user['area_admin']) {
+            $where = [];
+            $where['province'] = $user['area_province'];
+            if ($user['area_admin'] == 2 || $user['area_admin'] == 1) $where['city'] = $user['area_city'];
+            if ($user['area_admin'] == 1) $where['district'] = $user['area_district'];
+            if ($start == $stop) {
+                return app('json')->fail('开始时间不能等于结束时间');
+            }
+            if ($start > $stop) {
+                $middle = $stop;
+                $stop = $start;
+                $start = $middle;
+            }
+            $space = bcsub($stop, $start, 0);//间隔时间段
+            $front = bcsub($start, $space, 0);//第一个时间段
+            if ($type == 1) {//销售额
+                $frontPrice = StoreOrder:: getOrderTimeBusinessVolumePrice($front, $start, $where);
+                $afterPrice = StoreOrder:: getOrderTimeBusinessVolumePrice($start, $stop, $where);
+                $chartInfo = StoreOrder::chartTimePrice($start, $stop, $where);
+                $data['chart'] = $chartInfo;//营业额图表数据
+                $data['time'] = $afterPrice;//时间区间营业额
+                $increase = (float)bcsub($afterPrice, $frontPrice, 2); //同比上个时间区间增长营业额
+                $growthRate = abs($increase);
+                if ($growthRate == 0) $data['growth_rate'] = 0;
+                else if ($frontPrice == 0) $data['growth_rate'] = $growthRate;
+                else $data['growth_rate'] = (int)bcmul(bcdiv($growthRate, $frontPrice, 2), 100, 0);//时间区间增长率
+                $data['increase_time'] = abs($increase); //同比上个时间区间增长营业额
+                $data['increase_time_status'] = $increase >= 0 ? 1 : 2; //同比上个时间区间增长营业额增长 1 减少 2
+            } else {//订单数
+                $frontNumber = StoreOrder:: getOrderTimeBusinessVolumeNumber($front, $start, $where);
+                $afterNumber = StoreOrder:: getOrderTimeBusinessVolumeNumber($start, $stop, $where);
+                $chartInfo = StoreOrder::chartTimeNumber($start, $stop, $where);
+                $data['chart'] = $chartInfo;//订单数图表数据
+                $data['time'] = $afterNumber;//时间区间订单数
+                $increase = (int)bcsub($afterNumber, $frontNumber, 0); //同比上个时间区间增长订单数
+                $growthRate = abs($increase);
+                if ($growthRate == 0) $data['growth_rate'] = 0;
+                else if ($frontNumber == 0) $data['growth_rate'] = $growthRate;
+                else $data['growth_rate'] = (int)bcmul(bcdiv($growthRate, $frontNumber, 2), 100, 0);//时间区间增长率
+                $data['increase_time'] = abs($increase); //同比上个时间区间增长营业额
+                $data['increase_time_status'] = $increase >= 0 ? 1 : 2; //同比上个时间区间增长营业额增长 1 减少 2
+            }
+            return app('json')->successful($data);
+        }
+        return app('json')->fail('非区域代理');
+    }
 }