Browse Source

支付和临时门店

zhangxiaobin 1 year ago
parent
commit
9f4ce439a7

+ 26 - 0
application/api/controller/Companys.php

@@ -165,6 +165,32 @@ class Companys extends Api
         }
     }
 
+    public function bindTemp()
+    {
+        try {
+            $id = $this->request->param('id',0);
+            $where['id'] = $id;
+            $where['status'] = 1;
+            $company = $this->model->where($where)->find();
+            if (empty($company)) {
+                throw new Exception('未找到门店信息');
+            }
+            $userId = $this->auth->id;
+            $userWhere['id'] = $userId;
+            $user = Db::name('user')->where($userWhere)->find();
+            if ($user['temp_company_id'] != $id) {//更新绑定门店
+                $userData['temp_company_id'] = $id;
+                $userRes = model('User')->where($userWhere)->update($userData);
+                if (!$userRes) {
+                    throw new Exception('绑定门店失败');
+                }
+            }
+            $this->success();
+        } catch (Exception $e) {
+            $this->error($e->getMessage());
+        }
+    }
+
     /**
      * 保存
      * @return void

+ 28 - 2
application/api/controller/Pay.php

@@ -321,9 +321,22 @@ class Pay extends Api
             }
             $userCouponsRes = Db::name('user_coupons')->insertAll($userCouponsData);
             if (!$userCouponsRes) {
-                throw new Exception('赠送优惠失败');
+                Db::rollback();
+                return false;
             }
         }
+        //绑定门店
+        $userService = new UserService();
+        $userParams = [
+            'user_id' => $orderInfo['user_id'],
+            'company_id' => $orderInfo['company_id'],
+            'comefrom' => '',//来源
+        ];
+        $userBindRes = $userService->userWallet($userParams);
+        if (!$userBindRes['status']) {
+            Db::rollback();
+            return false;
+        }
         $userWalletWhere['user_id'] = $orderInfo['user_id'];
         $userWalletWhere['company_id'] = $orderInfo['company_id'];
         $userWalletData = Db::name('user_wallet')->where($userWalletWhere)->find();
@@ -347,7 +360,8 @@ class Pay extends Api
         ];
         $userMoneyLogRes = Db::name('user_money_log')->insertGetId($userMoneyLogData);
         if (!$userMoneyLogRes) {
-            throw new Exception('充值记录失败');
+            Db::rollback();
+            return false;
         }
         //更新钱包余额
         $update = [
@@ -465,6 +479,18 @@ class Pay extends Api
             Db::rollback();
             return false;
         }
+        //绑定门店
+        $userService = new UserService();
+        $userParams = [
+            'user_id' => $orderInfo['user_id'],
+            'company_id' => $orderInfo['company_id'],
+            'comefrom' => '',//来源
+        ];
+        $userBindRes = $userService->userWallet($userParams);
+        if (!$userBindRes['status']) {
+            Db::rollback();
+            return false;
+        }
         $orderService = new OrderService();
         $extData = json_decode($orderInfo['ext_data'], true);
         $carId = isset($extData['car_id']) ? $extData['car_id'] : 0;

+ 11 - 0
application/api/controller/PreOrder.php

@@ -103,6 +103,17 @@ class PreOrder extends Api
                 $data['createtime'] = $time;
                 $res = $this->model->insertGetId($data);
                 $id = $res;
+                //绑定门店
+                $userService = new UserService();
+                $userParams = [
+                    'user_id' => $userId,
+                    'company_id' => $companyId,
+                    'comefrom' => '',//来源
+                ];
+                $userBindRes = $userService->userWallet($userParams);
+                if (!$userBindRes['status']) {
+                    throw new Exception($userBindRes['msg']);
+                }
             } else {
                 $data['updatetime'] = $time;
                 $where['id'] = $id;

+ 5 - 0
application/api/controller/User.php

@@ -692,6 +692,11 @@ class User extends Api
     {
         try {
             $userInfo = $this->auth->getUserinfo();
+            $where['id'] = $this->auth->id;
+            $userData = Db::name('user')->where($where)->find();
+            if (!empty($userData)) {
+                $userInfo['company_id'] = $userData['company_id'];
+            }
             $userCouponsWhere['user_id'] = $this->auth->id;
             $userCouponsWhere['endtime'] = ['gt', time()];
             $userCouponsNum = Db::name('user_coupons')->where($userCouponsWhere)->sum('remain');

+ 4 - 1
application/common/library/Auth.php

@@ -26,7 +26,7 @@ class Auth
     //默认配置
     protected $config = [];
     protected $options = [];
-    protected $allowFields = ['id', 'username', 'nickname', 'mobile', 'avatar', 'score','company_id','birthday','createtime'];
+    protected $allowFields = ['id', 'username', 'nickname', 'mobile', 'avatar', 'score','company_id','temp_company_id','birthday','createtime'];
 
     public function __construct($options = [])
     {
@@ -119,6 +119,9 @@ class Auth
                 $this->setError('Account is locked');
                 return false;
             }
+            /*if ($user['company_id'] == 0 && $user['temp_company_id'] != 0) {
+                $user['company_id'] = $user['temp_company_id'];
+            }*/
             $this->_user = $user;
             $this->_logined = true;
             $this->_token = $token;

+ 8 - 2
application/common/service/UserService.php

@@ -40,7 +40,7 @@ class UserService
                 if ($user['company_id'] != $companyId) {
                     $userData['company_id'] = $companyId;
                     $userData['updatetime'] = time();
-                    $userRes = Db::name('user')->where($where['id'])->update($userData);
+                    $userRes = Db::name('user')->where($where)->update($userData);
                     if (!$userRes) {
                         throw new Exception('操作失败');
                     }
@@ -64,6 +64,7 @@ class UserService
             'msg' => '操作成功',
             'data' => [],
         ];
+        Db::startTrans();
         try {
             $userId = isset($params['user_id']) ? $params['user_id'] : 0;
             $companyId = isset($params['company_id']) ? $params['company_id'] : 0;
@@ -74,22 +75,27 @@ class UserService
             }
             $where['user_id'] = $userId;
             $where['company_id'] = $companyId;
-            $userWallet = Db::name('user_wallet')->where($where['id'])->find();
+            $userWallet = Db::name('user_wallet')->where($where)->find();
             $time = time();
             if (empty($userWallet)) {
                 $userWalletData = [
                     'user_id' => $userId,
                     'company_id' => $companyId,
+                    'staff_id' => 0,
                     'money' => 0.00,
+                    'address' => '',
                     'createtime' => $time,
                     'comefrom' => $comefrom,
+                    'remark' => '',
                 ];
                 $userWalletRes = Db::name('user_wallet')->insertGetId($userWalletData);
                 if (!$userWalletRes) {
                     throw new Exception('生成钱包失败');
                 }
             }
+            Db::commit();
         } catch (Exception $e) {
+            Db::rollback();
             $result['status'] = 0;
             $result['msg'] = $e->getMessage();
         }

+ 6 - 1
paylog/wechat/notify.txt

@@ -13,4 +13,9 @@
 2023-06-05 17:31:01 [notify][入口接收php://input流原始数据] 
 
 
-2023-06-05 17:31:01 [notify][入口接收php://input流] false
+2023-06-05 17:31:01 [notify][入口接收php://input流] false
+
+2023-06-15 11:00:03 [notify][入口接收php://input流原始数据] 
+
+
+2023-06-15 11:00:03 [notify][入口接收php://input流] false