1557492053 3 年之前
父节点
当前提交
7b4737af81

+ 36 - 1
app/api/controller/Admin.php

@@ -31,4 +31,39 @@ class Admin extends BaseController
         return $this->ok($res);
     }
 
-}
+    /**
+     * @param Request $request
+     * @return \think\response\Json
+     * @throws \app\exception\BaseException
+     */
+    public function performance(Request $request) {
+        $params = $request->param();
+        predicate(isset($params['username']), lang("username err"));
+        predicate(isset($params['password']), lang("password err"));
+        $res = $this->service->performance($params['username'], md5($params['password']));
+        predicate($res->bool, $res->message);
+        return $this->ok($res);
+    }
+
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 1 - 0
app/api/lang/zh-cn.php

@@ -46,6 +46,7 @@ return [
     "Stores do not exist"           =>  "门店不存在",
     "inventory shortage"            =>  "库存不足",
     "No customer found"             =>  "未找到客户",
+    'Account password error'        =>  "账号密码错误!",
 ];
 
 

+ 4 - 0
app/api/route/app.php

@@ -35,6 +35,10 @@ Route::group('api/payment', function () {
     Route::rule('channels', 'api/payment/channels');
 })->middleware(\app\common\middleware\VerifySessionToken::class);
 
+Route::group('api/user', function () {
+    Route::rule('performance', 'api/admin/performance');
+})->middleware(\app\common\middleware\VerifySessionToken::class);
+
 
 
 

+ 60 - 3
app/api/service/AdminService.php

@@ -6,7 +6,9 @@ namespace app\api\service;
 
 use app\admin\controller\AuthGroup;
 use app\common\model\AdminModel;
-use app\common\model\AuthGroupModel;
+use app\common\model\OrderProductModel;
+use app\common\model\ProductCategoryModel;
+use app\common\model\ProductModel;
 use app\common\model\StoreModel;
 
 class AdminService extends \app\BaseService
@@ -14,11 +16,17 @@ class AdminService extends \app\BaseService
 
     private $adminModel;
     private $storeModel;
+    private $productModel;
+    private $orderProductModel;
+    private $productCategoryModel;
 
     public function __construct()
     {
         $this->adminModel = new AdminModel();
         $this->storeModel = new StoreModel();
+        $this->productModel = new ProductModel();
+        $this->orderProductModel = new OrderProductModel();
+        $this->productCategoryModel = new ProductCategoryModel();
     }
 
     public function search($text = null) {
@@ -45,7 +53,6 @@ class AdminService extends \app\BaseService
         return $admins;
     }
 
-
     public function fetchMenus($admin_id) {
         $admin = $this->adminModel->findById($admin_id);
         $group = $admin['access']['group'];
@@ -57,11 +64,37 @@ class AdminService extends \app\BaseService
         return array_map(function ($id) use($fmt_reception_rules) {
             return $fmt_reception_rules[$id];
         },$reception_rule_ids);
+    }
+
+    public function performance($username, $password, $start_time = null, $end_time = null) {
+        $admin = $this->adminModel->loadByLogin($username, $password);
+        if(!$admin) return $this->fail(lang("Account password error"));
+        $counts = $this->orderProductModel->countByAdviser($admin->id, $start_time, $end_time);
+        $res = [
+            'total_sales' => fixed2Float($counts[0]),
+            'numerology' => "{$counts[1]}/{$counts[2]}",
+            'crape_myrtle'  =>  rand(1000,100000),
+            'geomancy_serve' =>  rand(1000,100000),
+        ];
+        $items = [
+            ['key' => '商品销售总额', 'value' => fixed2Float($counts[3])],
+            ['key' => '大商品销售总额', 'value' => fixed2Float($counts[4])],
+            ['key' => '服务销售总额', 'value' => fixed2Float($counts[5])],
+        ];
+        $categorys = $this->productCategoryModel->findAll();
+        foreach ($categorys as $category) {
+            array_push($items, [
+                'key' => $category->name,
+                'value' => rand(1,999),
+            ]);
+        }
+        $res['items'] = $items;
 
+        return $this->ok($res);
+    }
 
 
 
-    }
 
 
 
@@ -87,3 +120,27 @@ class AdminService extends \app\BaseService
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 5 - 3
app/api/service/OrderService.php

@@ -143,13 +143,15 @@ class OrderService extends \app\BaseService
                     'order_no' => $order_no,
                     'customer_id' => $customer->id,
                     'product_id' => $store_product['product']['id'],
+                    'product_category_id'   => $store_product['product']['category_id'],
+                    'is_serve'  =>  $store_product['product']['is_serve'],
                     'store_product_id' => $store_product['id'],
                     'product_name' => $store_product['product']['name'],
-                    'adviser_1_id' => isset($store_products_param->adviser_1_id) ?? null,
+                    'adviser_1_id' => isset($store_products_param->adviser_1_id) ? $store_products_param->adviser_1_id : null,
                     'adviser_1_name'  => isset($store_products_param->adviser_1_id) ? $fmt_users[$store_products_param->adviser_1_id]['nickname'] : null,
-                    'adviser_2_id' => isset($store_products_param->adviser_2_id) ?? null,
+                    'adviser_2_id' => isset($store_products_param->adviser_2_id) ? $store_products_param->adviser_2_id : null,
                     'adviser_2_name'  => isset($store_products_param->adviser_2_id) ? $fmt_users[$store_products_param->adviser_2_id]['nickname'] : null,
-                    'teacher_id' => isset($store_products_param->teacher_id) ?? null,
+                    'teacher_id' => isset($store_products_param->teacher_id) ? $store_products_param->teacher_id : null,
                     'teacher_name'  => isset($store_products_param->teacher_id) ? $fmt_users[$store_products_param->teacher_id]['nickname'] : null,
                     'is_upload_numerology' => $store_product['product']['is_upload_numerology'],
                     'is_upload' => 0,

+ 43 - 0
app/common/model/OrderProductModel.php

@@ -46,6 +46,49 @@ class OrderProductModel extends BaseModel
             ->count();
     }
 
+    public function countByAdviser($adviser_1_id,$start_time = null, $end_time = null) {
+        $where = [
+            ['is_delete', '=', 0],
+            ['adviser_1_id', '=', $adviser_1_id],
+        ];
+        if($start_time) array_push($where, ['create_time', '>=', $start_time]);
+        if($end_time) array_push($where, ['create_time', '<=', $end_time]);
+        return [
+            $this->where($where)->sum('real_price'),
+            $this->where(array_merge($where,[
+                ['is_upload_numerology', '=', 1],
+                ['is_upload', '=', 1]
+            ]))->count(),
+            $this->where([
+                ['is_delete', '=', 0],
+                ['adviser_1_id', '=', $adviser_1_id],
+                ['is_upload_numerology', '=', 1],
+            ])->count(),
+            $this->where([
+                ['is_delete', '=', 0],
+                ['adviser_1_id', '=', $adviser_1_id],
+                ['is_serve', '=', 0],
+            ])->sum('real_price'),
+            $this->where([
+                ['is_delete', '=', 0],
+                ['adviser_1_id', '=', $adviser_1_id],
+                ['teacher_id', '>', 0],
+            ])->sum('real_price'),
+            $this->where([
+                ['is_delete', '=', 0],
+                ['adviser_1_id', '=', $adviser_1_id],
+                ['is_serve', '=', 1],
+            ])->sum('real_price'),
+        ];
+    }
+
+    public function groupByAdviser($adviser_1_id, $start_time = null, $end_time = null) {
+        return $this->where([
+            ['is_delete', '=', 0],
+            ['adviser_1_id', '=', $adviser_1_id],
+        ])->sum('real_price');
+    }
+
 
 
 }