/** 查询 */ 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 'pay-more': $query = Money::find()->where(['userId' => $user['userId'], 'type' => Money::TYPE_PAY])->andWhere(['>', 'money', $content]); break; case 'pay-equal': $query = Money::find()->where(['userId' => $user['userId'], 'type' => Money::TYPE_PAY])->andWhere(['=', 'money', $content]); break; case 'pay-less': $query = Money::find()->where(['userId' => $user['userId'], 'type' => Money::TYPE_PAY])->andWhere(['<', 'money', $content]); break; default: $query = Money::find()->where(['userId' => $user['userId'], 'type' => Money::TYPE_PAY]); 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]); }
/** * 微信支付成功后的通知处理 * @param $xml * @return string * @throws \yii\base\Exception */ public static function payNotify($xml) { $cache = \Yii::$app->cache; //转xml为array $xmlArray = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); if ($xmlArray['return_code'] == 'SUCCESS') { $transaction_id = $xmlArray['transaction_id']; if ('ok' == $cache->get($transaction_id)) { $msg = "订单:" . $transaction_id . ",已处理完,重复通知"; Yii::info($msg, 'wx'); echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>'; } else { $cache->set($transaction_id, 'ok', 24 * 3600); //缓存1天 $money = $xmlArray['total_fee'] / 100; //总金额(元) $attachArray = explode("|", $xmlArray['attach']); $userId = intval($attachArray[0]); //获取充值用户 $user = Users::findOne($userId); $addBitcoin = intval($attachArray[1]); //获取充值获得的云豆数 Money::recordOne($user, $money, $addBitcoin, Money::TYPE_PAY, Money::FROM_WX); //记录充值记录+返点+收入支出表变化+用户云豆数增加 $msg = "订单:" . $transaction_id . ",首次记录,userId:" . $user['userId'] . ",支付" . $money . "元,获得" . $addBitcoin . "云豆,交易类型:" . $xmlArray['trade_type'] . ",交易结束时间:" . $xmlArray['time_end']; Yii::info($msg, 'wx'); echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>'; } } else { $msg = "错误消息:" . $xmlArray['return_msg']; Yii::info($msg, 'wx'); echo 'fail'; } exit; }
public function init() { $user = Yii::$app->session->get('user'); $maxMoney = Money::findRemainMoneyByUser($user['userId']); if ($maxMoney) { $this->maxMoney = intval($maxMoney); } else { $this->maxMoney = 0; } }
/** 充值记录 */ public function actionPayRecord() { $user = Yii::$app->session->get('user'); $query = Money::find()->where(['userId' => $user['userId']])->orderBy(['createDate' => SORT_DESC]); $pagination = new Pagination(['defaultPageSize' => 20, 'totalCount' => $query->count()]); $payRecords = $query->offset($pagination->offset)->limit($pagination->limit)->all(); //print_r($pagination->offset); if ($pagination->offset > 0) { Url::remember(['account/pay-record'], 'pay-record'); } return $this->render('pay-record', ['payRecords' => $payRecords, 'pages' => $pagination]); }
public function init() { $user = Yii::$app->session->get('user'); $remainMoney = Money::findRemainMoneyByUser($user['userId']); if ($remainMoney) { $this->remainMoney = $remainMoney; } else { $this->maxInvoiceMoney = 0; } $address = $user['address']; $this->address = $address; }
public function up() { $system_user = User::getSystemUser(); $suser_id = $system_user->id; $acs = Money::find()->all(); foreach ($acs as $a) { echo "Generate for user : {$a->user_id} \n"; echo "====================\n"; /*******托管 *****/ $entrusteds = MoneyEntrusted::find()->with('work')->where(['user_id' => $a->user_id])->all(); $count = count($entrusteds); echo "Got entrusted {$count} records\n"; foreach ($entrusteds as $e) { if (!$e->work) { echo "Work is not found {$e->work_id} \n"; continue; } if ($e->type == $e::ENTRUSTED_TYPE_PREPAY) { $type = MoneyBill::TYPE_PREPAY; $origin_id = $e->work->id; } else { $type = MoneyBill::TYPE_BALANCE; $origin_id = $e->work->work_contract->id; } $this->generateSql(0 - $e->money, $e->user_id, $suser_id, $e->work->title, $origin_id, $type, $e->created_at); if ($e::STATUS_CANCELED == $e->status) { echo "Work is canceled: {$e->work_id} \n"; $this->generateSql($e->money, $suser_id, $e->user_id, $e->work->title, $origin_id, MoneyBill::TYPE_BACK_PREPAY, $e->updated_at); $record = MoneyHistory::find()->where(['user_id' => $e->user_id])->andWhere(['event_type' => MoneyHistory::EVENT_CANCEL_ENTRUST])->andWhere(['<=', 'created_at', $e->updated_at + 1])->andWhere(['>=', 'created_at', $e->updated_at - 1])->andWhere(['<', 'changed_money', 0])->one(); if ($record) { echo "need to pay cancel fee : {$record->changed_money}\n"; $this->generateSql($record->changed_money, $e->user_id, $suser_id, $e->work->title, $e->work->id, MoneyBill::TYPE_CANCEL_FEE, $e->updated_at); } } } /***** 提现 ****/ $withdraws = MoneyWithdraw::find()->where(['user_id' => $a->user_id])->all(); foreach ($withdraws as $withdraw) { echo "withdraw found: user_id:{$withdraw->user_id} money: {$withdraw->amount}\n"; $tran_time = $withdraw->tran_time ? $withdraw->tran_time : $withdraw->updated_at; $this->generateSql(0 - $withdraw->amount, $withdraw->user_id, 0, '提现款项', $withdraw->id, MoneyBill::TYPE_WITHDRAW, $tran_time); } /**** 充值 ****/ $charges = MoneyPayment::find()->where(['user_id' => $a->user_id, 'is_paid' => 1])->all(); foreach ($charges as $charge) { echo "charge found: user_id:{$charge->user_id} money: {$charge->amount}\n"; $this->generateSql($charge->amount, 0, $charge->user_id, '充值款项', $charge->id, MoneyBill::TYPE_CHARGE, $charge->updated_at); } /**** 结算 ******/ $to_me_ts = MoneyTransfer::find()->with('work')->where(['to_user_id' => $a->user_id])->all(); foreach ($to_me_ts as $t) { echo "transfer found : {$t->work->title} , money : {$t->money}\n"; $this->generateSql($t->money, $suser_id, $t->to_user_id, $t->work->title, $t->work->id, MoneyBill::TYPE_SALARY, $t->created_at); $record = MoneyHistory::find()->where(['user_id' => $t->to_user_id])->andWhere(['event_type' => MoneyHistory::EVENT_PLATFORM_FEE])->andWhere(['<=', 'created_at', $t->created_at + 1])->andWhere(['>=', 'created_at', $t->created_at - 1])->andWhere(['<', 'changed_money', 0])->one(); if ($record) { echo "need to pay service fee : {$record->changed_money}\n"; $this->generateSql($record->changed_money, $t->to_user_id, $suser_id, $t->work->title, $t->work->id, MoneyBill::TYPE_SERVICE_FEE, $t->created_at); } } } return $this->execute(); }
?> </td> <td><?php echo $user->department['name']; ?> </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
?> </td> <td><?php echo $user->nickname; ?> </td> <td><?php echo $user->department['name']; ?> </td> <td><?php echo $user->recommendCode; ?> </td> <td><?php echo Money::findTotalWithdraw($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
/** * 针对大客户充值,大客户充值自己没有返点 * 记录用户的充值,包含返点、用户余额的改变和云豆收入支出记录的记录 * @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']); } } }
<option value="pay-more">充值金额大于</option> <option value="pay-equal">充值金额等于</option> <option value="pay-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 Money::findTotalPay($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>
?> " class="btn btn-primary btn-sm pull-right margin-left-10">云豆记录</a> <a href="<?php echo Url::to(['account/invoice-apply']); ?> " class="btn btn-primary btn-sm pull-right">发票申请</a> </p> <table class="table table-striped"> <tbody> <tr> <td>总计充值:<?php echo Money::findTotalPay($user['userId']); ?> 元</td> <td>总计充值获得:+<?php echo Money::findTotalPayBitcoin($user['userId']); ?> 颗云豆</td> </tr> </tbody> </table> <p><strong>详细记录</strong></p> <table class="table table-striped text-center no-margin-bottom"> <thead> <tr> <th class="text-center">金额</th> <th class="text-center">云豆</th> <th class="text-center">日期</th> </tr> </thead> <tbody>
public function record() { $userSession = Yii::$app->session->get('user'); $user = Users::findOne($this->userId); Money::recordOneForBig($user, $this->money, $this->bitcoin, $this->from, $userSession['userId'], $this->agreement); }
/** 资金查询 */ 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 'type': $query = Money::find()->where(['type' => $content]); break; case 'userId': $query = Money::find()->Where(['userId' => $content]); break; case 'nickname': $table_a = Money::tableName(); $table_b = Users::tableName(); $query = Money::find()->leftJoin($table_b, "{$table_a}.userId={$table_b}.userId")->where(['like', "{$table_b}.nickname", $content]); break; case 'pay-more': $query = Money::find()->Where(['>=', 'money', $content])->andWhere(['type' => Money::TYPE_PAY]); break; case 'pay-equal': $query = Money::find()->where(['=', 'money', $content])->andWhere(['type' => Money::TYPE_PAY]); break; case 'pay-less': $query = Money::find()->Where(['<=', 'money', $content])->andWhere(['type' => Money::TYPE_PAY]); break; case 'withdraw-more': $query = Money::find()->Where(['>=', 'money', $content])->andWhere(['type' => Money::TYPE_WITHDRAW]); break; case 'withdraw-equal': $query = Money::find()->where(['=', 'money', $content])->andWhere(['type' => Money::TYPE_WITHDRAW]); break; case 'withdraw-less': $query = Money::find()->Where(['<=', 'money', $content])->andWhere(['type' => Money::TYPE_WITHDRAW]); 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 = Money::tableName(); $table_b = Users::tableName(); $query = Money::find()->leftJoin($table_b, "{$table_a}.userId={$table_b}.userId")->where(["{$table_b}.role" => $role]); break; default: $query = Money::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(['moneyId' => SORT_DESC])->all(); return $this->render('index', ['models' => $model, 'pages' => $pagination]); }
public function getPay() { return $this->hasOne(Money::className(), ['userId' => 'userId']); }
<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 Money::findTotalIncomeMoney(); ?> (元)</td> <td><strong>总计支出金额:</strong>- <?php echo Money::findTotalConsumeMoney(); ?> (元)</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> <th class="text-align-center">操作者</th>