From 9f0c4cca20b21d7b62faefd4c4dd5fa302f70fd0 Mon Sep 17 00:00:00 2001 From: devil_gong Date: Tue, 7 May 2019 18:01:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=A6=E6=88=B7=E5=85=85=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/plugins/wallet/Common.php | 17 ++++++++++------- application/plugins/wallet/Recharge.php | 1 + .../plugins/wallet/service/BaseService.php | 6 ++++++ .../plugins/wallet/service/PayService.php | 17 +++++++++++++++++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/application/plugins/wallet/Common.php b/application/plugins/wallet/Common.php index 186a46c21..a4bb674a1 100644 --- a/application/plugins/wallet/Common.php +++ b/application/plugins/wallet/Common.php @@ -56,20 +56,19 @@ class Common extends Controller // 发起支付 - 支付方式 $this->assign('buy_payment_list', PaymentService::BuyPaymentList(['is_enable'=>1, 'is_open_user'=>1])); - // 用户钱包信息 - $this->user_wallet = WalletService::UserWallet(['user'=>$this->user]); - $this->assign('user_wallet', $this->user_wallet['data']); + // 用户钱包 + $user_wallet = WalletService::UserWallet(['user'=>$this->user]); // 用户钱包状态 $wallet_error = ''; - if(isset($this->user_wallet['code']) and $this->user_wallet['code'] == 0) + if(isset($user_wallet['code']) and $user_wallet['code'] == 0) { - if(!isset($this->user_wallet['data']['status']) || $this->user_wallet['data']['status'] != 0) + if(!isset($user_wallet['data']['status']) || $user_wallet['data']['status'] != 0) { - $wallet_error = array_key_exists($this->user_wallet['data']['status'], WalletService::$wallet_status_list) ? '用户钱包[ '.WalletService::$wallet_status_list[$this->user_wallet['data']['status']]['name'].' ]' : '用户钱包状态异常错误'; + $wallet_error = array_key_exists($user_wallet['data']['status'], WalletService::$wallet_status_list) ? '用户钱包[ '.WalletService::$wallet_status_list[$user_wallet['data']['status']]['name'].' ]' : '用户钱包状态异常错误'; } } else { - $wallet_error = isset($this->user_wallet['msg']) ? $this->user_wallet['msg'] : '用户钱包异常错误'; + $wallet_error = isset($user_wallet['msg']) ? $user_wallet['msg'] : '用户钱包异常错误'; } $this->assign('wallet_error', $wallet_error); @@ -78,6 +77,10 @@ class Common extends Controller { exit(json_encode(DataReturn($wallet_error, -50))); } + + // 用户钱包信息 + $this->user_wallet = $user_wallet['data']; + $this->assign('user_wallet', $user_wallet['data']); } } ?> \ No newline at end of file diff --git a/application/plugins/wallet/Recharge.php b/application/plugins/wallet/Recharge.php index c7dfadd25..f975fd272 100755 --- a/application/plugins/wallet/Recharge.php +++ b/application/plugins/wallet/Recharge.php @@ -101,6 +101,7 @@ class Recharge extends Common // 用户 $params['user'] = $this->user; + $params['user_wallet'] = $this->user_wallet; return BaseService::RechargeCreate($params); } diff --git a/application/plugins/wallet/service/BaseService.php b/application/plugins/wallet/service/BaseService.php index 0f2df5d03..f0ed2773d 100755 --- a/application/plugins/wallet/service/BaseService.php +++ b/application/plugins/wallet/service/BaseService.php @@ -133,6 +133,11 @@ class BaseService 'key_name' => 'user', 'error_msg' => '用户信息有误', ], + [ + 'checked_type' => 'empty', + 'key_name' => 'user_wallet', + 'error_msg' => '用户钱包有误', + ], [ 'checked_type' => 'fun', 'key_name' => 'money', @@ -155,6 +160,7 @@ class BaseService // 添加 $data = [ 'recharge_no' => date('YmdHis').GetNumberCode(6), + 'wallet_id' => $params['user_wallet']['id'], 'user_id' => $params['user']['id'], 'money' => PriceNumberFormat($params['money']), 'status' => 0, diff --git a/application/plugins/wallet/service/PayService.php b/application/plugins/wallet/service/PayService.php index 0d989cd09..cf0b10945 100644 --- a/application/plugins/wallet/service/PayService.php +++ b/application/plugins/wallet/service/PayService.php @@ -14,6 +14,7 @@ use think\Db; use app\service\PaymentService; use app\service\PayLogService; use app\service\MessageService; +use app\plugins\wallet\service\WalletService; /** * 支付服务层 @@ -344,6 +345,22 @@ class PayService ); if(Db::name('PluginsWalletRecharge')->where(['id'=>$params['recharge']['id']])->update($upd_data)) { + $log_data = [ + 'user_id' => $wallet['user_id'], + 'wallet_id' => $wallet['id'], + 'business_type' => 0, + 'operation_type' => ($wallet[$v['field']] < $data[$v['field']]) ? 1 : 0, + 'money_type' => $v['money_type'], + 'operation_money' => ($wallet[$v['field']] < $data[$v['field']]) ? PriceNumberFormat($data[$v['field']]-$wallet[$v['field']]) : PriceNumberFormat($wallet[$v['field']]-$data[$v['field']]), + 'original_money' => $wallet[$v['field']], + 'latest_money' => $data[$v['field']], + 'msg' => '管理员操作'.$operation_msg, + ]; + if(!self::WalletLogInsert($log_data)) + { + Db::rollback(); + return DataReturn('日志添加失败', -101); + } // 提交事务 Db::commit(); return DataReturn('支付成功', 0); -- GitLab