public function actionCalculate() { /* @var $userList \app\modules\cms\models\User[] */ /* @var $partnerList \app\modules\cms\models\Partner[] */ /* @var $historyModel \app\modules\cms\models\BalanceHistory */ /* @var $historyList \app\modules\cms\models\BalanceHistory[] */ //получить всех пользователей $sum = 1000.0; //сумма за каждое зачисление $userList = \app\modules\cms\models\User::find()->all(); $historyModel = new \app\modules\cms\models\BalanceHistory(); foreach ($userList as $user) { $userId = $user->id; // echo $user->username."\r\n"; //получить всех пользователей с партнерки $partnerList = \app\modules\cms\models\Partner::find()->where(['partnerId' => $userId])->all(); //получить историю баланса по юзеру $historyList = \app\modules\cms\models\BalanceHistory::find()->partner()->all(); $historyIdList = $historyModel->idList($historyList); if (sizeof($partnerList) > sizeof($historyList)) { foreach ($partnerList as $partner) { $id = md5($partner->userId . $partner->partnerId); if (!in_array($id, $historyIdList)) { // echo "\t".$id."\r\n"; $historyModel->add($userId, $sum, $partner->user->dateCreate, $id); } } } $balance = $historyModel->getBalanceById($user->id); if (!$user->profile) { continue; } $user->profile->updateBalance($balance); } }
public function actionEmail() { $items = User::find()->select('username')->all(); foreach ($items as $item) { file_put_contents('email-user.txt', $item->username . "\r\n", FILE_APPEND); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = User::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token]); return $dataProvider; }