public function record() { $user = Yii::$app->session->get('user'); $model = Withdraw::find()->where(['userId' => $user['userId'], 'state' => Withdraw::STATE_APPLYING])->one(); if ($model) { return false; } $withdraw = new Withdraw(); $withdraw->userId = $user['userId']; $withdraw->money = $this->money; $withdraw->bitcoin = ceil(Scheme::calculateWithdrawBitcoin($user, $this->money)); //扣除云豆数为向上取整,有小数就整数部分加1 $withdraw->invoiceMoney = $this->invoiceMoney; $withdraw->invoiceNo = $this->invoiceNo; $withdraw->createDate = DateFunctions::getCurrentDate(); $withdraw->state = Withdraw::STATE_APPLYING; if (!$withdraw->save()) { throw new Exception("Withdraw save error"); } return true; }
/** 提现金额查询 */ 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 'withdraw-more': $query = Withdraw::find()->where(['userId' => $user['userId']])->andWhere(['>=', 'money', $content]); break; case 'withdraw-equal': $query = Withdraw::find()->where(['userId' => $user['userId']])->andWhere(['=', 'money', $content]); break; case 'withdraw-less': $query = Withdraw::find()->where(['userId' => $user['userId']])->andWhere(['<=', 'money', $content]); break; case 'state': $query = Withdraw::find()->where(['userId' => $user['userId']])->andWhere(['state' => $content]); break; default: $query = Withdraw::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]); }
<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 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">消耗云豆(颗)
/** * 根据提现编号查找提现用户的云豆余额 * @param $withdrawId * @return int */ public static function findBitcoinByWithdrawId($withdrawId) { $withdraw = Withdraw::findOne($withdrawId); if (!$withdraw) { return 0; } $user = Users::findOne($withdraw['userId']); if ($user) { return $user['bitcoin']; } else { return 0; } }
/** * 统计所有用户的提现金额 * @return int */ public static function findTotalUsersMoney() { $table = Withdraw::tableName(); $money = (new Query())->select('sum(money)')->from($table)->where(['state' => Withdraw::STATE_PASS])->one(); if ($money['sum(money)']) { return $money['sum(money)']; } else { return 0; } }
<option value="money-more">提现金额大于</option> <option value="money-equal">提现金额等于</option> <option value="money-less">提现金额小于</option> </select> <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 Withdraw::findTotalUsersMoney(); ?> (元)</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 actionSearch() { $request = Yii::$app->request; $session = Yii::$app->session; $query = $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 'nickname': $table_a = Withdraw::tableName(); $table_b = Users::tableName(); $query = Withdraw::find()->leftJoin($table_b, "{$table_a}.userId={$table_b}.userId")->where(['like', "{$table_b}.nickname", $content]); break; case 'money-more': $query = Withdraw::find()->Where(['>=', 'money', $content]); break; case 'money-equal': $query = Withdraw::find()->where(['==', 'money', $content]); break; case 'money-less': $query = Withdraw::find()->Where(['<=', 'money', $content]); break; case 'apply': $query = Withdraw::find()->where(['state' => $content]); break; case 'agree': $query = Withdraw::find()->where(['state' => $content]); break; case 'refuse': $query = Withdraw::find()->where(['state' => $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 = Withdraw::tableName(); $table_b = Users::tableName(); $query = Withdraw::find()->leftJoin($table_b, "{$table_a}.userId={$table_b}.userId")->where(["{$table_b}.role" => $role]); break; default: $query = Withdraw::find()->where(['like', $type, $content]); 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]); }