/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = MUserAccount::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'create_time' => $this->create_time, 'amount' => $this->amount, 'status' => $this->status, 'cat' => $this->cat, 'scene_id' => $this->scene_id]); $query->andFilterWhere(['like', 'gh_id', $this->gh_id])->andFilterWhere(['like', 'openid', $this->openid])->andFilterWhere(['like', 'memo', $this->memo])->andFilterWhere(['like', 'oid', $this->oid])->andFilterWhere(['like', 'charge_mobile', $this->charge_mobile]); return $dataProvider; }
/** * This command export user account data. * @param string $filename the file to be exported to. */ public function actionUserAccount($filename = 'user-account.csv') { $file = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'exported_data' . DIRECTORY_SEPARATOR . $filename; $useraccount_records = \app\models\MUserAccount::find()->where(['cat' => \app\models\MUserAccount::CAT_CREDIT_CHARGE_MOBILE])->andWhere(['status' => \app\models\MUserAccount::STATUS_CHARGE_REQUEST])->all(); $fh = fopen($file, "w"); fprintf($fh, "充值手机号码,充值金额,申请时间\n"); foreach ($useraccount_records as $useraccount_record) { fprintf($fh, "%s,%s,%s\n", $useraccount_record->charge_mobile, intval($useraccount_record->amount / 100), $useraccount_record->create_time); $useraccount_record->updateAttributes(['status' => \app\models\MUserAccount::STATUS_CHARGE_PROCESSING]); } fclose($fh); echo "总共" . count($useraccount_records) . "条充值申请!" . PHP_EOL; }
public function actionUserAccountBalance() { \Yii::$app->db->createCommand("update wx_user set user_account_balance = 0")->execute(); $user_accounts = \app\models\MUserAccount::find()->all(); foreach ($user_accounts as $user_account) { // if ($user_account->cat == \app\models\MUserAccount::CAT_DEBIT_FAN) $user_account->user->updateCounters(['user_account_balance' => $user_account->amount]); } }