/** 查询 */ public function actionSearch() { $request = Yii::$app->request; $query = Yii::$app->session->getFlash('query'); if ($request->isPost) { $type = $request->post('type'); $content = $request->post('content'); } else { $type = $request->get('type'); $content = trim($request->get('content')); } if ($type || !$query) { $user = Yii::$app->session->get('user'); switch ($type) { case 'income': if ($content == 'my') { $query = IncomeConsume::find()->where(['type' => IncomeConsume::TYPE_INCOME, 'userId' => $user['userId']]); } elseif ($content == 'others') { $query = IncomeConsume::find()->where(['type' => IncomeConsume::TYPE_INCOME, 'FromUserId' => $user['userId']]); } break; case 'consume': if ($content == 'my') { $query = IncomeConsume::find()->where(['type' => IncomeConsume::TYPE_CONSUME, 'userId' => $user['userId']]); } break; case 'userId': $query = IncomeConsume::find()->where(['userId' => $user['userId']])->orWhere(['fromUserId' => $user['userId']])->andWhere(['userId' => $content]); break; case 'nickname': case 'realname': $table_a = IncomeConsume::tableName(); $table_b = Users::tableName(); $query = IncomeConsume::find()->leftJoin($table_b, "{$table_a}.userId={$table_b}.userId")->where(["{$table_a}.userId" => $user['userId']])->orWhere(["{$table_a}.fromUserId" => $user['userId']])->andWhere(['like', "{$table_b}.{$type}", $content]); break; default: $query = IncomeConsume::find()->where(['userId' => $user['userId']])->orWhere(['fromUserId' => $user['userId']]); break; } } Yii::$app->session->setFlash('query', $query); $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]); $model = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['createDate' => SORT_DESC])->all(); return $this->render('index', ['models' => $model, 'pages' => $pagination]); }
/** 云豆收支查询 */ public function actionSearch() { $user = Yii::$app->session->get('user'); $request = Yii::$app->request; $query = Yii::$app->session->getFlash('query'); if ($request->isPost) { $type = $request->post('type'); $content = $request->post('content'); } else { $type = $request->get('type'); $content = trim($request->get('content')); } if ($type || !$query) { switch ($type) { case 'income-more': $query = IncomeConsume::find()->where(['type' => IncomeConsume::TYPE_INCOME, 'userId' => $user['userId']])->andWhere(['>=', 'bitcoin', $content]); break; case 'income-equal': $query = IncomeConsume::find()->where(['type' => IncomeConsume::TYPE_INCOME, 'userId' => $user['userId']])->andwhere(['==', 'bitcoin', $content]); break; case 'income-less': $query = IncomeConsume::find()->where(['type' => IncomeConsume::TYPE_INCOME, 'userId' => $user['userId']])->andWhere(['<=', 'bitcoin', $content]); break; case 'consume-more': $query = IncomeConsume::find()->where(['type' => IncomeConsume::TYPE_CONSUME, 'userId' => $user['userId']])->andWhere(['>=', 'bitcoin', $content]); break; case 'consume-equal': $query = IncomeConsume::find()->where(['type' => IncomeConsume::TYPE_CONSUME, 'userId' => $user['userId']])->andwhere(['==', 'bitcoin', $content]); break; case 'consume-less': $query = IncomeConsume::find()->where(['type' => IncomeConsume::TYPE_CONSUME, 'userId' => $user['userId']])->andWhere(['<=', 'bitcoin', $content]); break; default: $query = IncomeConsume::find(); break; } } Yii::$app->session->setFlash('query', $query); $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]); $model = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['createDate' => SORT_DESC])->all(); return $this->render('index', ['models' => $model, 'pages' => $pagination]); }
?> </td> <td><?php echo $user->recommendCode; ?> </td> <td><?php echo $user->recommendUser['nickname']; ?> </td> <td><?php echo Money::findTotalPay($user->userId); ?> </td> <td><?php echo IncomeConsume::findTotalIncome($user->userId); ?> </td> <td><?php echo $user->bitcoin; ?> </td> <td><?php echo count(Users::findBeRecommend($user->userId)); ?> </td> <td><?php echo $user->registerDate; ?> </td> <td><?php
/** * 针对大客户充值,大客户充值自己没有返点 * 记录用户的充值,包含返点、用户余额的改变和云豆收入支出记录的记录 * @param $user * @param $money * @param $bitcoin * @param $from * @param null $operateUserId * @param null $agreement * @throws Exception */ public static function recordOneForBig($user, $money, $bitcoin, $from, $operateUserId = null, $agreement = null) { $moneyModel = new Money(); $moneyModel->userId = $user['userId']; $moneyModel->money = $money; $moneyModel->type = Money::TYPE_PAY; $moneyModel->bitcoin = $bitcoin; $moneyModel->createDate = DateFunctions::getCurrentDate(); $moneyModel->from = $from; $moneyModel->operateUserId = $operateUserId; $moneyModel->agreement = $agreement; if (!$moneyModel->save()) { throw new Exception("money save error"); } //云豆收入支出记录+用户余额改变 IncomeConsume::saveRecord($user['userId'], $bitcoin, UsageMode::USAGE_PAY, IncomeConsume::TYPE_INCOME, $operateUserId); $recommendUser = Users::findRecommendUser($user['recommendUserID']); if ($recommendUser) { //存在推荐用户 $rebateScheme = Scheme::findRebateScheme(Users::ROLE_BIG); if ($rebateScheme && $money >= $rebateScheme['payMoney']) { //存在返点方案,并且达到当前返点的起始要求 $proportion = Yii::$app->params['proportion']; $addBitcoin = $money * $proportion * $rebateScheme['rebate']; //返点云豆,返给推荐人 IncomeConsume::saveRecord($recommendUser['userId'], $addBitcoin, UsageMode::USAGE_REBATE_BIG, IncomeConsume::TYPE_INCOME, $user['userId']); } } }
/** * 分配云豆 * @param $fromUserId //大客户ID * @param $toUserId //分配给的用户ID * @param $bitcoin */ public static function distributeBitcoin($fromUserId, $toUserId, $bitcoin) { IncomeConsume::saveRecord($toUserId, $bitcoin, UsageMode::USAGE_DISTRIBUTE_INCOME, IncomeConsume::TYPE_INCOME, $fromUserId); //分配用户收入云豆 IncomeConsume::saveRecord($fromUserId, $bitcoin, UsageMode::USAGE_DISTRIBUTE_CONSUME, IncomeConsume::TYPE_CONSUME, $toUserId); //大客户支出云豆 }
<input type="text" name="content" class="form-control" placeholder="请输入查找内容"> <button type="submit" class="btn btn-small btn btn-primary">查找</button> </div> <?php echo Html::endForm(); ?> </div> </div> <table class="table table-bordered table-striped margin-bottom-20"> <tr class="font_bg_color"> <td><strong>总计收入云豆:</strong><?php echo IncomeConsume::findTotalIncome($user['userId']); ?> (颗)</td> <td><strong>总计支出云豆:</strong><?php echo IncomeConsume::findTotalConsume($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> </tr> </thead>
/** * 统计所有用户支出的云豆数 * @return int */ public static function findTotalUsersConsume() { $table = IncomeConsume::tableName(); $bitcoin = (new Query())->select('sum(bitcoin)')->from($table)->where(['type' => IncomeConsume::TYPE_CONSUME])->one(); if ($bitcoin['sum(bitcoin)']) { return $bitcoin['sum(bitcoin)']; } else { return 0; } }
/** 在线练习支付 */ 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("非法支付"); }
<input type="text" name="content" class="form-control" placeholder="请输入查找内容"> <button type="submit" class="btn btn-small btn btn-primary">查找</button> </div> <?php echo Html::endForm(); ?> </div> </div> <table class="table table-bordered table-striped margin-bottom-20"> <tr> <td><strong>总计收入云豆:</strong><?php echo IncomeConsume::findTotalUsersConsume(); ?> (颗)</td> <td><strong>总计支出云豆: </strong><?php echo IncomeConsume::findTotalUsersIncome(); ?> (颗)</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> </tr>
/** * 计算用户提现的钱应该扣除的云豆数 * @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 未定义"); } }
/** 云豆收支记录查询 */ public function actionSearch() { $request = Yii::$app->request; $query = Yii::$app->session->getFlash('query'); if ($request->isPost) { $type = $request->post('type'); $content = $request->post('content'); } else { $type = $request->get('type'); $content = trim($request->get('content')); } if ($type || !$query) { switch ($type) { case 'usageModeName': $query = IncomeConsume::find()->where(['usageModeId' => $content]); break; case 'nickname': $table_a = IncomeConsume::tableName(); $table_b = Users::tableName(); $query = IncomeConsume::find()->leftJoin($table_b, "{$table_a}.userId={$table_b}.userId")->where(['like', "{$table_b}.nickname", $content]); break; case 'income-more': $query = IncomeConsume::find()->where(['type' => IncomeConsume::TYPE_INCOME])->andWhere(['>=', 'bitcoin', $content]); break; case 'income-equal': $query = IncomeConsume::find()->where(['type' => IncomeConsume::TYPE_INCOME])->andwhere(['==', 'bitcoin', $content]); break; case 'income-less': $query = IncomeConsume::find()->where(['type' => IncomeConsume::TYPE_INCOME])->andWhere(['<=', 'bitcoin', $content]); break; case 'pay-more': $query = IncomeConsume::find()->where(['type' => IncomeConsume::TYPE_CONSUME])->andWhere(['>=', 'bitcoin', $content]); break; case 'pay-equal': $query = IncomeConsume::find()->where(['type' => IncomeConsume::TYPE_CONSUME])->andwhere(['==', 'bitcoin', $content]); break; case 'pay-less': $query = IncomeConsume::find()->where(['type' => IncomeConsume::TYPE_CONSUME])->andWhere(['<=', 'bitcoin', $content]); break; case 'role': $role = ''; if ($content == 'a' || $content == 'A' || $content == 'A级') { $role = Users::ROLE_A; } elseif (strstr('金牌伙伴', $content)) { $role = Users::ROLE_AA; } elseif (strstr('钻石伙伴', $content)) { $role = Users::ROLE_AAA; } elseif ($content == '管理员') { $role = Users::ROLE_ADMIN; } $table_a = IncomeConsume::tableName(); $table_b = Users::tableName(); $query = IncomeConsume::find()->leftJoin($table_b, "{$table_a}.userId={$table_b}.userId")->where(["{$table_b}.role" => $role]); break; case 'type': $query = IncomeConsume::find()->where(['type' => $content]); break; default: $query = IncomeConsume::find(); break; } } Yii::$app->session->setFlash('query', $query); $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]); $model = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['incomeConsumeId' => SORT_DESC])->all(); return $this->render('index', ['models' => $model, 'pages' => $pagination]); }