/** 分配云豆 */ public function actionDistribute() { $request = Yii::$app->request; if ($request->isPost) { $user = Yii::$app->session->get('user'); $bitcoin = intval($request->post('distribute_bitcoin_number')); $userId = $request->post('distribute_bitcoin_userId'); if ($bitcoin <= 0) { CommonFunctions::createAlertMessage("分配云豆失败,因为您未填写云豆数量或云豆数量未大于0", "error"); } elseif ($bitcoin > Users::findBitcoin($user['userId'])) { CommonFunctions::createAlertMessage("分配云豆失败,因为您的云豆余额不足", "error"); } else { Users::distributeBitcoin($user['userId'], $userId, $bitcoin); CommonFunctions::createAlertMessage("成功分配给用户号为" . $userId . "的用户" . $bitcoin . "云豆。", "success"); } } else { CommonFunctions::createAlertMessage("非法提交", "error"); } return $this->redirect(['user/previous']); }
echo Html::endForm(); ?> </div> </div> <table class="table table-bordered table-striped margin-bottom-20"> <tr> <td><strong>总计提现金额:</strong><?php echo Withdraw::findTotalMoney($user['userId']); ?> (元)</td> <td><strong>总计消耗云豆:</strong><?php echo Withdraw::findTotalBitcoin($user['userId']); ?> (颗)</td> <td><strong>剩余云豆:</strong><?php echo Users::findBitcoin($user['userId']); ?> (颗)</td> </tr> </table> <table class="table table-hover table-bordered text-align-center"> <thead class="bordered-blue"> <tr> <th class="text-align-center">序号</th> <th class="text-align-center">用户名称</th> <th class="text-align-center">提现金额(元)</th> <th class="text-align-center">消耗云豆(颗) </th><th class="text-align-center">申请提现时间</th> <th class="text-align-center">发票金额</th> <th class="text-align-center">发票单号</th> <th class="text-align-center">状态</th>
/** 在线练习支付 */ public function actionPay() { $request = Yii::$app->request; if ($request->isAjax) { $session = Yii::$app->session; $user = $session->get('user'); //先查询该用户是否有练习记录,防止重复付款 $practiceRecord = PracticeRecord::findByUser($user['userId']); if ($practiceRecord) { return 'success您已经可以在线练习,不需要重新付款,如果重复出现付款页面请刷新该页面。'; } $schemeId = $request->post('schemeId'); /** @var $scheme \common\models\Scheme */ $scheme = Scheme::findOne($schemeId); if (!$scheme) { return '该方案已停用'; } $leftBitcoin = Users::findBitcoin($user['userId']); if ($leftBitcoin < $scheme['payBitcoin']) { return '您的云豆余额不足'; } IncomeConsume::saveRecord($user['userId'], $scheme['payBitcoin'], Scheme::USAGE_PRACTICE, IncomeConsume::TYPE_CONSUME); PracticeRecord::saveRecord($user['userId'], $scheme); return 'success支付成功'; } throw new Exception("非法支付"); }
</div> </div> <?php if ($practiceRecordFlag && $schemes) { ?> <div class="modal fade" id="pay_modal" tabindex="-1" role="dialog" aria-labelledby="在线学习支付"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="myModalLabel">在线学习支付</h4> </div> <div class="modal-body"> <p class="margin-bottom-20">您还剩余云豆:<strong><?php echo Users::findBitcoin($sessionUser['userId']); ?> </strong>颗</p> <input type="hidden" name="schemeId" value=""> <?php foreach ($schemes as $scheme) { ?> <div class="pic_box_3 practice_select" data-id="<?php echo $scheme['schemeId']; ?> "> <div class="bitcoin"><?php echo $scheme['payBitcoin']; ?> <small>云豆</small></div> <div class="rmb">使用<?php
/** * 计算用户提现的钱应该扣除的云豆数 * @param $user * @param $money * @return float|mixed * @throws Exception */ public static function calculateWithdrawBitcoin($user, $money) { $role = $user['role']; $leftBitcoin = Users::findBitcoin($user['userId']); //获取用户剩余云豆 $schemes = Scheme::findWithdrawScheme($role); if ($role == Users::ROLE_AA) { $scheme = $schemes[0]; return $money / $scheme['getMoney'] * $scheme['payBitcoin']; } elseif ($role == Users::ROLE_AAA) { $totalBitcoin = IncomeConsume::findTotalIncome($user['userId']); //获取该用户累计获得多少云豆 $withdrawBitcoin = $totalBitcoin - $leftBitcoin; //已经提现掉的云豆数 $scheme_low = $schemes[0]; $scheme_high = $schemes[1]; if ($withdrawBitcoin >= $scheme_high['totalBitcoin']) { //已经提现的云豆数大于高比例需要的云豆数,直接按照高比例算 return $money / $scheme_high['getMoney'] * $scheme_high['payBitcoin']; } else { //按照第比例算或分段算 if ($totalBitcoin >= $scheme_high['totalBitcoin']) { //累计云豆数量达到高比例提现,分段算 $lowBitcoin = $scheme_high['totalBitcoin'] - $withdrawBitcoin; //按照低比例算的云豆 $lowMoney = $lowBitcoin / $scheme_low['payBitcoin'] * $scheme_low['getMoney']; //低比例最大可提现的钱 if ($money <= $lowMoney) { //用户体现的钱未达到低比例最大提现的钱,按低比例计算云豆 return $money / $scheme_low['getMoney'] * $scheme_low['payBitcoin']; } else { //用户体现的钱超过低比例最大提现的钱,未超过部分为所有低比例云豆数,超过部分按高比例计算云豆 return $lowBitcoin + ($money - $lowMoney) / $scheme_high['getMoney'] * $scheme_high['payBitcoin']; } } else { //按低比例算 return $money / $scheme_low['getMoney'] * $scheme_low['payBitcoin']; } } } else { throw new Exception("role 未定义"); } }