Ejemplo n.º 1
0
 /**
  * 查询所有用户一共收入的金额
  * @return int
  */
 public static function findTotalConsumeMoney()
 {
     $table = Money::tableName();
     $money = (new Query())->select('sum(money)')->from($table)->where(['type' => Money::TYPE_WITHDRAW])->one();
     if ($money['sum(money)']) {
         return $money['sum(money)'];
     } else {
         return 0;
     }
 }
Ejemplo n.º 2
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]);
 }