diff --git a/application/plugins/wallet/Common.php b/application/plugins/wallet/Common.php index 186a46c2164cd415b188098a9fe796194f44a5eb..a4bb674a11e23b4961033a1ee7ff3eb66fc12c86 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 c7dfadd2592ca73d2d85bc632e39f8ca27175c84..f975fd272686249ba4e1a717dc4c9f1d1c530d97 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 0f2df5d03cf3b2f9a710a07602123a233e047141..f0ed2773d6e2c0c82bf12f38049f405fc3b224e7 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 0d989cd090ebcbdb7c2e55085d1ab1adf9b81e3e..cf0b10945a989a4180a52642e8a0f5fd5231f7d4 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);