コード例 #1
0
 /** 查询 */
 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]);
 }
コード例 #2
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]);
 }
コード例 #3
0
 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();
 }
コード例 #4
0
ファイル: Money.php プロジェクト: krissss/YunDou-advanced
 /**
  * 查询用户的提现记录
  * @param $userId
  * @return array|\yii\db\ActiveRecord[]
  */
 public static function findWithdrawByUser($userId)
 {
     return Money::find()->where(['userId' => $userId, 'type' => Money::TYPE_WITHDRAW])->orderBy(['createDate' => SORT_DESC])->all();
 }
コード例 #5
0
 /** 资金查询 */
 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]);
 }