1557492053 2 years ago
parent
commit
ec370eae3f

+ 3 - 3
.env

@@ -5,10 +5,10 @@ DEFAULT_TIMEZONE = Asia/Shanghai
 
 [DATABASE]
 TYPE = mysql
-HOSTNAME = 8.219.191.124
+HOSTNAME = 127.0.0.1
 DATABASE = yuanzhongxiu
-USERNAME = yuanzhongxiu
-PASSWORD = WPDrmPREz36y6mMb
+USERNAME = root
+PASSWORD = root
 HOSTPORT = 3306
 CHARSET = utf8
 DEBUG = true

+ 6 - 3
app/api/controller/Admin.php

@@ -21,7 +21,8 @@ class Admin extends BaseController
 
     public function search(Request $request) {
         $params = $request->param();
-        $res = $this->service->search(format_string($params['text'] ?? null));
+        predicate(isset($params['store_id']) && $params['store_id'] > 0, '门店ID错误!');
+        $res = $this->service->search($params['store_id'], format_string($params['text'] ?? null));
         return $this->ok($res);
     }
 
@@ -40,9 +41,11 @@ class Admin extends BaseController
         $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']));
+        $start_time = $params['start_time'] ?? null;
+        $end_time = $params['end_time'] ?? null;
+        $res = $this->service->performance($params['username'], $params['password'], $start_time, $end_time);
         predicate($res->bool, $res->message);
-        return $this->ok($res);
+        return $this->ok($res->data);
     }
 
 

+ 9 - 1
app/api/controller/Customer.php

@@ -57,7 +57,15 @@ class Customer extends \app\BaseController
         return $this->ok($res->data);
     }
 
-
+    public function search() {
+        $params = $this->request->param();
+        predicate(isset($params['store_id']) && $params['store_id'] > 0, 'store_id err');
+        return $this->ok($this->service->search(
+            $params['admin_id'],
+            $params['store_id'],
+            isset($params['text']) ? format_string($params['text']) : null
+        ));
+    }
 
 
 

+ 25 - 6
app/api/controller/Order.php

@@ -29,15 +29,14 @@ class Order extends \app\BaseController
             'customer_id.require'  =>  lang("Customer do not exist"),
             'products.require'  =>  lang("Products do not exist"),
         ])->requestBodyCheck($this->request);
-
+        predicate($params['products'] != "[]", '请选择商品!');
         $products = json_decode($params['products']);
         predicate($products != null, 'products 解析错误');
-
         for ($i = 0; $i < count($products); $i++) {
             $product = $products[$i];
             predicate(isset($product->store_product_id) && $product->store_product_id > 0, '门店商品ID错误!');
-            predicate($product->quantity > 0, '商品数量错误!');
-            predicate($product->adviser_1_id > 0, '销售顾问1必须存在!');
+            predicate(isset($product->quantity) && $product->quantity > 0, '商品数量错误!');
+            predicate(isset($product->adviser_1_id) && $product->adviser_1_id > 0, '销售顾问必须存在!');
             if(isset($product->adviser_2_id)) predicate($product->adviser_2_id > 0, '销售顾问2不符合规则!');
             if(isset($product->teacher_id)) predicate($product->teacher_id > 0, '老师不符合规则!');
         }
@@ -63,10 +62,11 @@ class Order extends \app\BaseController
         for ($i = 0; $i < count($channels); $i++) {
             $channel = $channels[$i];
             predicate(isset($channel->channel_id) && $channel->channel_id > 0, '支付渠道错误!');
-            if (isset($channel->fee)) {
+            predicate(isset($channel->type) &&  in_array($channel->type,[1, 2, 3]), '支付类型错误!');
+            if (isset($channel->fee) && ($channel->type == 1 || $channel->type == 2)) {
                 predicate($channel->fee > 0, '支付费用错误!');
             }
-            if (isset($channel->credit_card)) {
+            if (isset($channel->credit_card) && $channel->type == 3) {
                 predicate(is_array($channel->credit_card), 'credit_card 不符合规则!');
                 for ($j = 0; $j < count($channel->credit_card); $j++) {
                     $credit_card = $channel->credit_card[$j];
@@ -211,6 +211,25 @@ class Order extends \app\BaseController
         return $this->ok($r->data);
     }
 
+    /**
+     * @return \think\response\Json
+     * @throws BaseException
+     */
+    public function findOrderByOrderId() {
+        $params = $this->request->param();
+        predicate(isset($params['order_id']) && $params['order_id'] > 0, '订单ID不存在!');
+        $r = $this->service->findOrderByOrderId($params['order_id']);
+        predicate($r != null, "订单不存在!");
+        return $this->ok($r);
+    }
+
+    public function fetchOrderPayments() {
+        $params = $this->request->param();
+        predicate(isset($params['order_id']) && $params['order_id'] > 0, '订单ID不存在!');
+        $r = $this->service->fetchOrderPayments($params['order_id']);
+        return $this->ok($r);
+    }
+
 
 }
 

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

@@ -15,6 +15,7 @@ Route::group('api/product', function () {
 Route::group('api/customer', function () {
     Route::rule('add', 'api/customer/add');
     Route::rule('get', 'api/customer/getCustomer');
+    Route::rule('search', 'api/customer/search');
 })->middleware(\app\common\middleware\VerifySessionToken::class);
 
 Route::group('api/user', function () {
@@ -23,6 +24,8 @@ Route::group('api/user', function () {
 })->middleware(\app\common\middleware\VerifySessionToken::class);
 
 Route::group('api/order', function () {
+    Route::rule('findOrderByOrderId', 'api/order/findOrderByOrderId');
+    Route::rule('fetchOrderPayments', 'api/order/fetchOrderPayments');
     Route::rule('create', 'api/order/create');
     Route::rule('payment', 'api/order/payment');
     Route::rule('fetch', 'api/order/fetch');

+ 14 - 10
app/api/service/AdminService.php

@@ -29,8 +29,8 @@ class AdminService extends \app\BaseService
         $this->productCategoryModel = new ProductCategoryModel();
     }
 
-    public function search($text = null) {
-        $admins = $this->adminModel->findAdmins($text)->toArray();
+    public function search($store_id, $text = null) {
+        $admins = $this->adminModel->findAdmins($store_id, $text)->toArray();
         $store_ids = [];
 
         foreach ($admins as &$admin) {
@@ -71,10 +71,10 @@ class AdminService extends \app\BaseService
         if(!$admin) return $this->fail(lang("Account password error"));
         $counts = $this->orderProductModel->countByAdviser($admin->id, $start_time, $end_time);
         $items = [
-            ['key' => '销售总额', 'value' => fixed2Float($counts[0])],
-            ['key' => '上传命理报告数', 'value' =>  "{$counts[1]}/{$counts[2]}"],
-            ['key' => '紫薇斗数', 'value' => 0],
-            ['key' => '风水服务', 'value' => 0],
+            ['key' => '销售总额', 'value' => fixed2Float($counts[0]), "color" => "#BED5F8"],
+            ['key' => '上传命理报告数', 'value' =>  "{$counts[1]}/{$counts[2]}", "color" => "#B6EEF8"],
+            ['key' => '紫薇斗数', 'value' => 0, "color" => "#CBEEE2"],
+            ['key' => '风水服务', 'value' => 0, "color" => "#D7BFF9"],
             ['key' => '商品销售总额', 'value' => fixed2Float($counts[3])],
             ['key' => '大商品销售总额', 'value' => fixed2Float($counts[4])],
             ['key' => '服务销售总额', 'value' => fixed2Float($counts[5])]
@@ -83,17 +83,21 @@ class AdminService extends \app\BaseService
         foreach ($categorys as $category) {
             $value = $this->orderProductModel->countByAdviserProductCategoryIds($admin->id, [$category->id], $start_time, $end_time);
             if($category->name == '紫薇斗数') {
-                $res[3]['value'] = $value;
+                $res[3]['value'] = fixed2Float($value[0]);
             } else if ($category->name == '风水服务') {
-                $res[4]['value'] = $value;
+                $res[4]['value'] = fixed2Float($value[0]);
             } else {
                 array_push($items, [
                     'key' => $category->name,
-                    'value' => $value
+                    'value' => fixed2Float($value[0]).'/'.$value[1],
+                    "descript" => "总额/总数"
                 ]);
             }
         }
-        return $this->ok($items);
+        return $this->ok([
+            "user" => $admin,
+            "items" => $items
+        ]);
     }
 
 

+ 3 - 1
app/api/service/CustomerService.php

@@ -127,7 +127,9 @@ class CustomerService extends BaseService
     }
 
 
-
+    public function search($admin_id, $store_id, $text = null) {
+        return $this->customerModel->search($store_id, $text);
+    }
 
 
 

+ 30 - 17
app/api/service/OrderService.php

@@ -352,16 +352,17 @@ class OrderService extends \app\BaseService
 
         $change_zue_coin_record = null;
         $zue_coin_model = $this->zueCoinModel->findByCustomerId($customer->id);
-        if(!$zue_coin_model)
-            return $this->fail("当前客户御龙币账户余额: 0");
-        if ($zue_coin > $zue_coin_model->zue_coin)
-            return $this->fail("当前客户御龙币账户余额:{$zue_coin_model->zue_coin}");
-        $zue_coin_config = $fmt_pay_channels['11'];
-        if(!$zue_coin_config)
-            return $this->fail("御龙币设置不存在!");
-        $zue_coin_exchange_rate = $zue_coin_config['zue_coin_exchange_rate'] ?? 0; // 兑换比例
-        $zue_coin_consume_rate = $zue_coin_config['zue_coin_consume_rate'] ?? 0; // 报销比例
+        $zue_coin_exchange_rate = 0;
         if($zue_coin > 0) {
+            if(!$zue_coin_model)
+                return $this->fail("当前客户御龙币账户余额: 0");
+            if ($zue_coin > $zue_coin_model->zue_coin)
+                return $this->fail("当前客户御龙币账户余额:{$zue_coin_model->zue_coin}");
+            $zue_coin_config = $fmt_pay_channels['11'];
+            if(!$zue_coin_config)
+                return $this->fail("御龙币设置不存在!");
+            $zue_coin_exchange_rate = $zue_coin_config['zue_coin_exchange_rate'] ?? 0; // 兑换比例
+            $zue_coin_consume_rate = $zue_coin_config['zue_coin_consume_rate'] ?? 0; // 报销比例
             if($zue_coin_exchange_rate == 0 || $zue_coin_consume_rate == 0) {
                 return $this->fail("该笔订单不支持御龙币支付");
             }
@@ -432,7 +433,14 @@ class OrderService extends \app\BaseService
                 } else {
                     $update_store_products[$order_product['store_product_id']] = ['id' => $order_product['store_product_id'], 'reduce_num' => 1];
                 }
-                if ($order_product['is_gather_annuity']) {
+                if ($order_product['is_gather_annuity'] && $order_product['annuity'] > 0) {
+                    $adviser_ids = [];
+                    if($order_product['adviser_1_id']) {
+                        array_push($adviser_ids, $order_product['adviser_1_id']);
+                    }
+                    if($order_product['adviser_2_id']) {
+                        array_push($adviser_ids, $order_product['adviser_2_id']);
+                    }
                     array_push($order_annual_fees, [
                         'order_id' => $order->id,
                         'customer_id'   => $customer->id,
@@ -447,7 +455,7 @@ class OrderService extends \app\BaseService
                         'start_time' => time(),
                         'end_time' => time() + (365 * 24 * 60 * 60),
                         'order_create_time' => strtotime($order->create_time),
-                        'adviser_1_id'  =>  $order_product['adviser_1_id'],
+                        'adviser_ids'  =>  join(',', $adviser_ids),
                         'store_id' => $order->store_id,
                         'create_time'   =>  time(),
                         'update_time'   =>  time()
@@ -478,7 +486,7 @@ class OrderService extends \app\BaseService
                 'service_charge_amount' =>  $order->service_charge_amount + $service_charge,
                 'zue_coin'      =>  $order_use_zue_coin,
                 'zue_coin_amount' => $order_use_zue_coin_amount,
-                'remarks'   =>  $params['remarks']
+                'remarks'   =>  $params['remarks'] ?? null
             ];
 
             if (round($receive_amount) == round($imposed_amount)) { // 支付满了
@@ -674,7 +682,7 @@ class OrderService extends \app\BaseService
 
     public function fetchWaitGatherAnnualFee($admin_id, $text = null, $start_time = null, $end_time = null, $page = 1, $size = 10) {
         $res = $this->orderAnnualFeeModel->fetchByAdviser($admin_id, $text, $start_time, $end_time, $page, $size);
-        return [$res->items(),$res->total()];
+        return [$res[0]->items(),$res[0]->total(), $res[1]];
     }
 
     public function paymentAnnualFee($annual_fee_id) {
@@ -1004,8 +1012,7 @@ class OrderService extends \app\BaseService
                 'create_time' => time(),
                 'update_time' => time(),
             ]);
-
-            array_push($order_annual_fees, $store_product['product']['is_gather_annuity'] ?  [
+            array_push($order_annual_fees, $store_product['product']['is_gather_annuity'] && $store_product['product']['annuity'] > 0 ?  [
                 'order_id' => $order->id,
                 'customer_id'   => $order->customer_id,
                 'customer_name'   => $order->customer_name,
@@ -1014,12 +1021,12 @@ class OrderService extends \app\BaseService
                 'index' => 1,
                 'order_product_id'  => -1,
                 'order_product_name' =>  $store_product['product']['name'],
-                'fee' =>  $store_product['product']['name'],
+                'fee' =>  $store_product['product']['annuity'],
                 'is_pay' => 1,
                 'start_time' => time(),
                 'end_time' => time() + (365 * 24 * 60 * 60),
                 'order_create_time' => strtotime($order->create_time),
-                'adviser_1_id'  =>  $store_product['product']['annuity'],
+                'adviser_ids'  =>  $admin_id,
                 'store_id' => $order->store_id,
                 'create_time'   =>  time(),
                 'update_time'   =>  time()
@@ -1118,7 +1125,13 @@ class OrderService extends \app\BaseService
     }
 
 
+    public function findOrderByOrderId($order_id) {
+        return $this->orderModel->findById($order_id);
+    }
 
+    public function fetchOrderPayments($order_id) {
+        return $this->orderPaymentModel->findByOrderId($order_id);
+    }
 
 
 

+ 1 - 0
app/api/service/PaymentService.php

@@ -22,6 +22,7 @@ class PaymentService extends \app\BaseService
             $fmt = [
                 "id" => $channel['id'],
                 'name' => $channel['name'],
+                "index" => $channel['index'],
                 'icon' => $channel['icon'],
                 'type' => $channel['type'],
                 'is_upload_code' => $channel['is_upload_code'],

File diff suppressed because it is too large
+ 10 - 9
app/common.php


+ 1 - 1
app/common/middleware/VerifySessionToken.php

@@ -28,7 +28,7 @@ class VerifySessionToken
         $jwt = \Jwt::verifyToken($params['session_token']);
         if($jwt == false) {
             // $redis->srem('user:infos', $params['session_token']);
-            predicate(false, '登录失效');
+            predicate(false, '登录失效',403);
         }
         $request->setData($jwt['admin_id'], $jwt['nickname']);
         return $next($request);

+ 8 - 3
app/common/model/AdminModel.php

@@ -84,14 +84,19 @@ class AdminModel extends BaseModel
         return $this->where('id',$id)->with(['access','access.group','department'])->find();
     }
 
-    public function findAdmins($text) {
+    public function findAdmins($store_id, $text) {
         $where = [
             ['is_delete', '=', 0]
         ];
         if($text != null) {
-            array_push($where,['id|nickname','like', '%'.$text.'%']);
+            array_push($where, ['id|nickname','like', '%'.$text.'%']);
         }
-        return $this->where($where)->limit(20)->order('id', 'desc')->select();
+        return $this
+            ->where($where)
+            ->where("FIND_IN_SET('{$store_id}', store_ids)")
+            ->limit(50)
+            ->order('id', 'desc')
+            ->select();
     }
 
 }

+ 10 - 0
app/common/model/CustomerModel.php

@@ -66,5 +66,15 @@ class CustomerModel extends BaseModel
         ])->find();
     }
 
+    public function search($store_id, $text = null) {
+        $where = [
+            ['is_delete','=', 0],
+            ['store_id','=', $store_id],
+        ];
+        if($text) {
+            array_push($where, ['id|name_zh|name_en|mobile', "like", "%{$text}%"]);
+        }
+        return $this->where($where)->limit(500)->select();
+    }
 
 }

+ 14 - 9
app/common/model/OrderAnnualFeeModel.php

@@ -14,29 +14,34 @@ class OrderAnnualFeeModel extends BaseModel
         // TODO: Implement genSchema() method.
     }
 
-    public function fetchByOrderIds($order_ids, $is_pay = 0) {
+    public function fetchByOrderIds($order_ids, $is_pay = 0)
+    {
         return $this->where('is_delete', 0)
             ->where('order_id', 'in', $order_ids)
             ->where('is_pay', '=', $is_pay)
             ->select()->toArray();
     }
 
-    public function fetchByAdviser($admin_id, $text = null, $start_time = null, $end_time = null, $page = 1, $size = 10) {
+    public function fetchByAdviser($admin_id, $text = null, $start_time = null, $end_time = null, $page = 1, $size = 10)
+    {
         $where = [
             ['is_delete', '=', 0],
             ['is_pay', '=', 0],
-            ['adviser_1_id|adviser_2_id', '=', $admin_id],
         ];
-        if ($text) array_push($where, ['customer_name|customer_mobile', 'like', "%".$text."%"]);
+        if ($text) array_push($where, ['customer_name|customer_mobile', 'like', "%" . $text . "%"]);
         if ($start_time) array_push($where, ['order_create_time', '>=', $start_time]);
         if ($end_time) array_push($where, ['order_create_time', '<=', $end_time]);
-        return $this->where($where)
-            ->page($page)
-            ->paginate($size);
-
+        return [
+            $this->where($where)
+                ->where("FIND_IN_SET('{$admin_id}', adviser_ids)")
+                ->page($page)
+                ->paginate($size),
+            $this->where($where)->sum("fee")
+        ];
     }
 
-    public function fetchByOrderProductId(array $o_p_ids) {
+    public function fetchByOrderProductId(array $o_p_ids)
+    {
         $where = [
             ['is_delete', '=', 0],
             ['order_product_id', 'in', $o_p_ids],

+ 0 - 1
app/common/model/OrderModel.php

@@ -187,5 +187,4 @@ class OrderModel extends BaseModel
 
 
 
-
 }

+ 1 - 2
app/common/model/OrderPaymentModel.php

@@ -26,8 +26,7 @@ class OrderPaymentModel extends BaseModel
         return $this->where([
             ['order_id', '=', $o_id],
             ['is_delete', '=', 0],
-            ['channel_id', '=', 11],
-        ])->order('id', 'desc')->find();
+        ])->order('id', 'desc')->select();
     }
 
 

+ 3 - 3
app/common/model/OrderProductModel.php

@@ -76,13 +76,13 @@ class OrderProductModel extends BaseModel
             ]))->count(),
             $this->where(array_merge($where,[['is_upload_numerology', '=', 1]]))->count(),
             $this->where(array_merge($where, [['is_serve', '=', 0]]))->sum('real_price'),
-            $this->where(array_merge($where, [['teacher_id', '>', 0]]))->sum('real_price'),
+            $this->where(array_merge($where, [['teacher_1_id', '>', 0]]))->sum('real_price'),
             $this->where(array_merge($where, [['is_serve', '=', 1]]))->sum('real_price'),
         ];
     }
 
     public function countByAdviserProductCategoryIds($adviser_1_id, $category_ids = [], $start_time = null, $end_time = null) {
-        if (count($category_ids) == 0) return 0;
+        if (count($category_ids) == 0) return [0 , 0];
         $where = [
             ['is_delete', '=', 0],
             ['adviser_1_id', '=', $adviser_1_id],
@@ -91,7 +91,7 @@ class OrderProductModel extends BaseModel
         ];
         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');
+        return [$this->where($where)->sum('real_price'), $this->where($where)->count()];
     }
 
 

BIN
public/storage/numerology/20230106/2b8bcd868c17caae6b98e53c60403507.zip


BIN
public/storage/numerology/20230106/30568ba79b480111a2f5ce0d4745a58c.jpg


BIN
public/storage/numerology/20230106/3425bf11942816dd81eec48b3331210f.jpg


BIN
public/storage/numerology/20230106/8195aa9eb68945e56d9637a402c96d19.jpg


File diff suppressed because it is too large
+ 1 - 0
public/storage/numerology/20230106/9f24c0ee649ce9ff2e450ca16cff0115.svg


BIN
public/storage/numerology/20230106/c25f03f0bcaa9686cd1da1d8ec75a0df.jpg


BIN
public/storage/numerology/20230106/d487f5f4acb21506fc1640ed3f913149.jpg


BIN
public/storage/numerology/20230106/ef9eacd6a2fdca18e966751a35f4e7bf.jpg


BIN
public/storage/numerology/20230106/f0d971b77600e674593f2d572bf76f57.jpg