mirror of
https://github.com/janickiy/yii2-nomer
synced 2025-03-09 15:39:59 +00:00
add files to project
This commit is contained in:
commit
5cac498444
3729 changed files with 836998 additions and 0 deletions
44
modules/admin/controllers/AccountsController.php
Normal file
44
modules/admin/controllers/AccountsController.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use app\models\Telegram;
|
||||
use yii\helpers\Url;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
class AccountsController extends AdminController
|
||||
{
|
||||
public function actionTelegram()
|
||||
{
|
||||
$model = new Telegram();
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => Telegram::find(),
|
||||
'sort' => ['defaultOrder' => ['id' => SORT_DESC]]
|
||||
]);
|
||||
|
||||
if (Yii::$app->getRequest()->getIsPost()) {
|
||||
$model->load(Yii::$app->getRequest()->post());
|
||||
|
||||
if (!$model->validate()) {
|
||||
return $this->render('telegram', compact('model', 'dataProvider'));
|
||||
}
|
||||
|
||||
$model->save();
|
||||
$this->refresh();
|
||||
}
|
||||
|
||||
return $this->render('telegram', compact('model', 'dataProvider'));
|
||||
}
|
||||
|
||||
public function actionDeleteTelegram($id)
|
||||
{
|
||||
if ($instance = Telegram::findOne($id)) $instance->delete();
|
||||
if (!$instance) throw new NotFoundHttpException('Инстанс не найден.');
|
||||
$referrer = Yii::$app->getRequest()->getReferrer();
|
||||
$url = $referrer ? $referrer : Url::to(['accounts/telegram']);
|
||||
return $this->redirect($url);
|
||||
}
|
||||
}
|
29
modules/admin/controllers/AdminController.php
Normal file
29
modules/admin/controllers/AdminController.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use yii\filters\AccessControl;
|
||||
use yii\web\Controller;
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'access' => [
|
||||
'class' => AccessControl::className(),
|
||||
'rules' => [
|
||||
[
|
||||
'allow' => true,
|
||||
'roles' => ['@'],
|
||||
'matchCallback' => function ($rule, $action) {
|
||||
/* @var $identity \app\models\User */
|
||||
$identity = \Yii::$app->getUser()->getIdentity();
|
||||
return $identity->is_admin;
|
||||
}
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
42
modules/admin/controllers/AppleController.php
Normal file
42
modules/admin/controllers/AppleController.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use app\models\AppleSubscribeEvent;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class AppleController extends AdminController {
|
||||
|
||||
public function actionIndex() {
|
||||
$query = AppleSubscribeEvent::find();
|
||||
$subId = \Yii::$app->request->get("sub_id");
|
||||
if($subId) {
|
||||
$query->andWhere(["subscription_id" => $subId]);
|
||||
}
|
||||
$tm_start = \Yii::$app->request->get("tm_start");
|
||||
if($tm_start) {
|
||||
$query->andWhere([">=", "original_start_date", $tm_start]);
|
||||
}
|
||||
|
||||
$tm_end = \Yii::$app->request->get("tm_end");
|
||||
if($tm_end) {
|
||||
$query->andWhere(["<=", "original_start_date", $tm_end]);
|
||||
}
|
||||
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
"query" => $query
|
||||
]);
|
||||
|
||||
$sData = AppleSubscribeEvent::find()->select(["subscription_id", "subscription_name"])->groupBy(["subscription_id", "subscription_name"])->all();
|
||||
$subs = ArrayHelper::map($sData, "subscription_id", "subscription_name");
|
||||
|
||||
return $this->render("index", [
|
||||
"dataProvider" => $dataProvider,
|
||||
"subs" => $subs,
|
||||
"subId" => $subId,
|
||||
"tm_start" => $tm_start,
|
||||
"tm_end" => $tm_end
|
||||
]);
|
||||
}
|
||||
}
|
19
modules/admin/controllers/CallsController.php
Normal file
19
modules/admin/controllers/CallsController.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use app\models\Call;
|
||||
use yii\data\ActiveDataProvider;
|
||||
|
||||
class CallsController extends AdminController
|
||||
{
|
||||
public function actionIndex()
|
||||
{
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => Call::find()->with('organization')->where(['status' => 'dtmf-1']),
|
||||
'sort' => ['defaultOrder' => ['id' => SORT_DESC]]
|
||||
]);
|
||||
|
||||
return $this->render('index', compact('dataProvider'));
|
||||
}
|
||||
}
|
26
modules/admin/controllers/CheckoutsController.php
Normal file
26
modules/admin/controllers/CheckoutsController.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use app\models\Checkout;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\db\Expression;
|
||||
use yii\web\Controller;
|
||||
|
||||
class CheckoutsController extends AdminController {
|
||||
|
||||
public function actionIndex() {
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
"query" => Checkout::find()->where(["tm_done" => null])
|
||||
]);
|
||||
|
||||
return $this->render("index", ["dataProvider" => $dataProvider]);
|
||||
}
|
||||
|
||||
public function actionDone($id) {
|
||||
$checkout = Checkout::find()->where(["id" => $id])->one();
|
||||
$checkout->tm_done = new Expression("NOW()");
|
||||
$checkout->save();
|
||||
|
||||
return $this->redirect(["index"]);
|
||||
}
|
||||
}
|
319
modules/admin/controllers/DashboardController.php
Normal file
319
modules/admin/controllers/DashboardController.php
Normal file
|
@ -0,0 +1,319 @@
|
|||
<?php
|
||||
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use app\models\ApplePayment;
|
||||
use app\models\Payment;
|
||||
use app\models\ResultCache;
|
||||
use app\models\SearchRequest;
|
||||
use app\models\User;
|
||||
use app\models\UserSub;
|
||||
use app\models\Wallet;
|
||||
use Yii;
|
||||
use yii\db\Expression;
|
||||
use yii\db\Query;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class DashboardController extends AdminController
|
||||
{
|
||||
public function actionIndex()
|
||||
{
|
||||
$start = Yii::$app->request->get('tm_start', date('Y-m-d', strtotime('-7 days')));
|
||||
$end = Yii::$app->request->get('tm_end', date('Y-m-d'));
|
||||
|
||||
$searchRequests = (new Query())
|
||||
->select([
|
||||
'to_char(requests.tm, \'YYYY-MM-DD\') as date',
|
||||
'count(1) as requests',
|
||||
])
|
||||
->from('requests')
|
||||
->where(['>=', 'requests.tm', $start . ' 00:00:00'])
|
||||
->andWhere(['<=', 'requests.tm', $end . ' 23:59:59'])
|
||||
->groupBy(['date'])
|
||||
->orderBy(['date' => SORT_ASC])
|
||||
->all();
|
||||
|
||||
$users = (new Query())
|
||||
->select(['to_char(tm_create, \'YYYY-MM-DD\') as date', 'count(1) as count'])
|
||||
->from('users')
|
||||
->where(['<=', 'tm_create', $end . ' 23:59:59'])
|
||||
->andWhere(['>=', 'tm_create', $start . ' 00:00:00'])
|
||||
->groupBy('date')
|
||||
->orderBy(['date' => SORT_ASC])
|
||||
->all();
|
||||
|
||||
$applePayments = (new Query())
|
||||
->select(['to_char(tm, \'YYYY-MM-DD\') as date', 'count(1) as count'])
|
||||
->from('apple_payments')
|
||||
->where(['<=', 'tm', $end . ' 23:59:59'])
|
||||
->andWhere(['>=', 'tm', $start . ' 00:00:00'])
|
||||
->andWhere(["refund" => 0])
|
||||
->andWhere([">", "sum", 0])
|
||||
->groupBy('date')
|
||||
->orderBy(['date' => SORT_ASC])
|
||||
->all();
|
||||
|
||||
$requestsStats = [];
|
||||
|
||||
$defaultStats = [
|
||||
'requests' => 0,
|
||||
'registrations' => 0,
|
||||
'applePayments' => 0
|
||||
];
|
||||
|
||||
|
||||
foreach ($searchRequests as $searchRequest) {
|
||||
if (!isset($requestsStats[$searchRequest['date']])) $requestsStats[$searchRequest['date']] = $defaultStats;
|
||||
|
||||
$requestsStats[$searchRequest['date']]['requests'] = $searchRequest['requests'];
|
||||
}
|
||||
|
||||
foreach ($users as $user) {
|
||||
if (!isset($requestsStats[$user['date']])) $requestsStats[$user['date']] = $defaultStats;
|
||||
$requestsStats[$user['date']]['registrations'] = $user['count'];
|
||||
}
|
||||
|
||||
foreach ($applePayments as $applePayment) {
|
||||
if (!isset($requestsStats[$applePayment['date']])) $requestsStats[$applePayment['date']] = $defaultStats;
|
||||
$requestsStats[$applePayment['date']]['applePayments'] = $applePayment['count'];
|
||||
}
|
||||
|
||||
ksort($requestsStats);
|
||||
|
||||
$payments = Payment::find()
|
||||
->where(['>=', 'tm', date('Y-m-d 00:00:00', strtotime('-30 days'))])
|
||||
->andWhere(["NOT IN", "type_id", [Payment::TYPE_TESTAPPLE, Payment::TYPE_ANDROID, Payment::TYPE_APPLE]])
|
||||
->all();
|
||||
|
||||
$today = (new yii\db\Query())
|
||||
->select([
|
||||
new Expression('SUM(amount) as sum'),
|
||||
new Expression('COUNT(1) as bills'),
|
||||
new Expression('COUNT(DISTINCT user_id) as bills_users'),
|
||||
new Expression('(SELECT COUNT(1) FROM payments p WHERE
|
||||
extract(month from p.tm) = '.date("m").'
|
||||
AND extract(year from p.tm) = '.date("Y").'
|
||||
AND extract(day from p.tm) = '.date("d").'
|
||||
AND p.user_id IN (SELECT user_id FROM payments GROUP BY user_id HAVING COUNT(1) > 1)) as rebills'),
|
||||
new Expression('(SELECT COUNT(DISTINCT user_id) FROM payments p WHERE
|
||||
extract(month from p.tm) = '.date("m").'
|
||||
AND extract(year from p.tm) = '.date("Y").'
|
||||
AND extract(day from p.tm) = '.date("d").'
|
||||
AND p.user_id IN (SELECT user_id FROM payments GROUP BY user_id HAVING COUNT(1) > 1)) as rebills_users')
|
||||
])
|
||||
->from(Payment::tableName().' p')
|
||||
->where(["=", new Expression("extract(month from tm)"), date("m")])
|
||||
->andWhere(["=", new Expression("extract(year from tm)"), date("Y")])
|
||||
->andWhere(["=", new Expression("extract(day from tm)"), date("d")])
|
||||
->andWhere(["NOT IN", "type_id", [Payment::TYPE_TESTAPPLE, Payment::TYPE_APPLE]])
|
||||
->one();
|
||||
|
||||
$todayAndroid = (new yii\db\Query())
|
||||
->select([
|
||||
new Expression('SUM(amount) as sum'),
|
||||
new Expression('COUNT(1) as bills'),
|
||||
new Expression('COUNT(DISTINCT user_id) as bills_users'),
|
||||
new Expression('(SELECT COUNT(1) FROM payments p WHERE
|
||||
extract(month from p.tm) = '.date("m").'
|
||||
AND extract(year from p.tm) = '.date("Y").'
|
||||
AND extract(day from p.tm) = '.date("d").'
|
||||
AND p.user_id IN (SELECT user_id FROM payments GROUP BY user_id HAVING COUNT(1) > 1)) as rebills'),
|
||||
new Expression('(SELECT COUNT(DISTINCT user_id) FROM payments p WHERE
|
||||
p.user_id IN (SELECT user_id FROM payments GROUP BY user_id HAVING COUNT(1) > 1)) as rebills_users')
|
||||
])
|
||||
->from(Payment::tableName().' p')
|
||||
->where(["=", new Expression("extract(month from tm)"), date("m")])
|
||||
->andWhere(["=", new Expression("extract(year from tm)"), date("Y")])
|
||||
->andWhere(["=", new Expression("extract(day from tm)"), date("d")])
|
||||
->andWhere(["type_id" => Payment::TYPE_ANDROID])
|
||||
->one();
|
||||
|
||||
$todayIos = (new yii\db\Query())
|
||||
->select([
|
||||
new Expression('SUM(amount) as sum'),
|
||||
new Expression('COUNT(1) as bills')
|
||||
])
|
||||
->from(ApplePayment::tableName())
|
||||
->where(["=", "tm", date("Y-m-d")])
|
||||
->one();
|
||||
|
||||
$yesterday = (new yii\db\Query())
|
||||
//->select([new Expression('SUM(amount) as sum'), new Expression('COUNT(1) as bills'), new Expression('COUNT(1) - (COUNT(DISTINCT user_id) + COUNT(case when user_id is NULL then 1 else null end)) as rebills')])
|
||||
->select([
|
||||
new Expression('SUM(amount) as sum'),
|
||||
new Expression('COUNT(DISTINCT user_id) as bills_users'),
|
||||
new Expression('COUNT(1) as bills'),
|
||||
new Expression('(SELECT COUNT(1) FROM payments p WHERE
|
||||
extract(month from p.tm) = '.date("m", strtotime("-1 day")).'
|
||||
AND extract(year from p.tm) = '.date("Y", strtotime("-1 day")).'
|
||||
AND extract(day from p.tm) = '.date("d", strtotime("-1 day")).'
|
||||
AND p.user_id IN (SELECT user_id FROM payments GROUP BY user_id HAVING COUNT(1) > 1)) as rebills'),
|
||||
new Expression('(SELECT COUNT(DISTINCT user_id) FROM payments p WHERE
|
||||
extract(month from p.tm) = '.date("m", strtotime("-1 day")).'
|
||||
AND extract(year from p.tm) = '.date("Y", strtotime("-1 day")).'
|
||||
AND extract(day from p.tm) = '.date("d", strtotime("-1 day")).'
|
||||
AND p.user_id IN (SELECT user_id FROM payments GROUP BY user_id HAVING COUNT(1) > 1)) as rebills_users')
|
||||
])
|
||||
->from(Payment::tableName().' p')
|
||||
->where(["=", new Expression("extract(month from tm)"), date("m", strtotime("-1 day"))])
|
||||
->andWhere(["=", new Expression("extract(year from tm)"), date("Y", strtotime("-1 day"))])
|
||||
->andWhere(["=", new Expression("extract(day from tm)"), date("d", strtotime("-1 day"))])
|
||||
->andWhere(["NOT IN", "type_id", [Payment::TYPE_TESTAPPLE, Payment::TYPE_APPLE]])
|
||||
->one();
|
||||
|
||||
$yesterdayIos = (new yii\db\Query())
|
||||
->select([
|
||||
new Expression('SUM(amount) as sum'),
|
||||
new Expression('COUNT(1) as bills')
|
||||
])
|
||||
->from(ApplePayment::tableName())
|
||||
->where(["=", "tm", date("Y-m-d", strtotime("-1 day"))])
|
||||
->one();
|
||||
|
||||
$last30days = (new yii\db\Query())
|
||||
//->select([new Expression('SUM(amount) as sum'), new Expression('COUNT(1) as bills'), new Expression('COUNT(1) - (COUNT(DISTINCT user_id) + COUNT(case when user_id is NULL then 1 else null end)) as rebills')])
|
||||
->select([
|
||||
new Expression('SUM(amount) as sum'),
|
||||
new Expression('COUNT(DISTINCT user_id) as bills_users'),
|
||||
new Expression('COUNT(1) as bills'),
|
||||
new Expression('(SELECT COUNT(1) FROM payments p WHERE
|
||||
tm >= \''.date("Y-m-d 00:00:00", strtotime("-30 days")).'\'
|
||||
AND p.user_id IN (SELECT user_id FROM payments GROUP BY user_id HAVING COUNT(1) > 1)) as rebills'),
|
||||
new Expression('(SELECT COUNT(DISTINCT user_id) FROM payments p WHERE
|
||||
tm >= \''.date("Y-m-d 00:00:00", strtotime("-30 days")).'\'
|
||||
AND p.user_id IN (SELECT user_id FROM payments GROUP BY user_id HAVING COUNT(1) > 1)) as rebills_users')
|
||||
])
|
||||
->from(Payment::tableName())
|
||||
->where([">=", "tm", date("Y-m-d 00:00:00", strtotime("-30 days"))])
|
||||
->andWhere(["<>", "type_id", Payment::TYPE_TESTAPPLE])
|
||||
->andWhere(["IS NOT", "site_id", null])
|
||||
->one();
|
||||
|
||||
$last30Android = (new yii\db\Query())
|
||||
->select([new Expression('SUM(amount) as sum'), new Expression('COUNT(1) as bills'), new Expression('COUNT(1) - (COUNT(DISTINCT user_id) + COUNT(case when user_id is NULL then 1 else null end)) as rebills')])
|
||||
->from(Payment::tableName())
|
||||
->where([">=", "tm", date("Y-m-d 00:00:00", strtotime("-30 days"))])
|
||||
->andWhere(["type_id" => Payment::TYPE_ANDROID])
|
||||
->one();
|
||||
|
||||
$last30Ios = (new yii\db\Query())
|
||||
->select([
|
||||
new Expression('SUM(amount) as sum'),
|
||||
new Expression('COUNT(1) as bills')
|
||||
])
|
||||
->from(ApplePayment::tableName())
|
||||
->where([">=", "tm", date("Y-m-d", strtotime("-30 days"))])
|
||||
->one();
|
||||
|
||||
$yandexWalletsSum = Wallet::find()->where(["type_id" => Wallet::TYPE_YANDEX])->sum("balance");
|
||||
$qiwiWalletsSum = Wallet::find()->where(["type_id" => Wallet::TYPE_QIWI])->sum("balance");
|
||||
|
||||
$start = Yii::$app->request->get('tm_start', date('Y-m-d', strtotime('-1 days')));
|
||||
$end = Yii::$app->request->get('tm_end', date('Y-m-d'));
|
||||
|
||||
$results = (new Query())
|
||||
->select(['to_char(requests.tm, \'YYYY-MM-DD\') as date', 'request_results.type_id', '
|
||||
CASE
|
||||
WHEN (request_results.data = \'null\' OR request_results.data = \'[]\')
|
||||
THEN false
|
||||
ELSE true
|
||||
END as success', 'count(1)'])
|
||||
->from('requests')
|
||||
->innerJoin('request_results', ['requests.id' => new Expression('request_id')])
|
||||
->where(['>', 'requests.tm', date('Y-m-d', strtotime('-1 days'))])
|
||||
->groupBy(['date', 'request_results.type_id', 'success'])
|
||||
->orderBy(['date' => SORT_ASC, 'request_results.type_id' => SORT_ASC, 'success' => SORT_ASC])
|
||||
->all();
|
||||
|
||||
$sourcesStats = [];
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (!isset($sourcesStats[$result['date']])) $sourcesStats[$result['date']] = [];
|
||||
if (!isset($sourcesStats[$result['date']][$result['type_id']])) {
|
||||
$sourcesStats[$result['date']][$result['type_id']] = [
|
||||
'all' => 0,
|
||||
'success' => 0
|
||||
];
|
||||
}
|
||||
|
||||
$sourcesStats[$result['date']][$result['type_id']]['all'] += $result['count'];
|
||||
if ($result['success']) $sourcesStats[$result['date']][$result['type_id']]['success'] += $result['count'];
|
||||
}
|
||||
|
||||
//print_r($sourcesStats); die();
|
||||
|
||||
$sourcesDays = array_keys($sourcesStats);
|
||||
|
||||
krsort($sourcesDays);
|
||||
|
||||
$types = [];
|
||||
|
||||
foreach ($sourcesStats as $key => $value) {
|
||||
$types = array_merge($types, array_keys($value));
|
||||
}
|
||||
|
||||
$types = array_filter(array_unique($types));
|
||||
|
||||
$sourcesToday = $sourcesDays[count($sourcesDays) - 1];
|
||||
$sourcesYesterday = $sourcesDays[count($sourcesDays) - 2];
|
||||
|
||||
$typesError = [];
|
||||
|
||||
foreach($types as $type) {
|
||||
if(in_array($type, [ResultCache::TYPE_GETCONTACT, ResultCache::TYPE_VK_OPEN, ResultCache::TYPE_VK])) continue;
|
||||
$todayPercent = round(ArrayHelper::getValue($sourcesStats, [$sourcesToday, $type, "success"], 0) / ArrayHelper::getValue($sourcesStats, [$sourcesToday, $type, 'all'], 1) * 100, 2, PHP_ROUND_HALF_DOWN);
|
||||
$yesterdayPercent = round(
|
||||
ArrayHelper::getValue($sourcesStats, [$sourcesYesterday, $type, 'success'], 0)
|
||||
/
|
||||
ArrayHelper::getValue($sourcesStats, [$sourcesYesterday, $type, 'all'], 1) * 100, 2, PHP_ROUND_HALF_DOWN);
|
||||
if($yesterdayPercent > 0) {
|
||||
if($todayPercent < ($yesterdayPercent / 2)) {
|
||||
$typesError[] = ResultCache::getTypeName($type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$avitoStats = \Yii::$app->cache->get("avito");
|
||||
|
||||
$notifyTokens = User::find()->where(["IS NOT", "token", null])->count(1);
|
||||
$notifyTokensWithoutSubs = User::find()->joinWith("subs")->where(["IS NOT", "token", null])->andWhere([UserSub::tableName().'.id' => null])->count(1);
|
||||
|
||||
$todaySubs = UserSub::find()->where(new Expression(
|
||||
"extract(month from tm_purchase) = ".date("m")."
|
||||
AND extract(year from tm_purchase) = ".date("Y")."
|
||||
AND extract(day from tm_purchase) = ".date("d")
|
||||
))->count(1);
|
||||
|
||||
$yesterdaySubs = UserSub::find()->where(new Expression(
|
||||
"extract(month from tm_purchase) = ".date("m", strtotime("-1 day"))."
|
||||
AND extract(year from tm_purchase) = ".date("Y", strtotime("-1 day"))."
|
||||
AND extract(day from tm_purchase) = ".date("d", strtotime("-1 day"))
|
||||
))->count(1);
|
||||
|
||||
$last30daysSubs = UserSub::find()->where([">=", "tm_purchase", date("Y-m-d 00:00:00", strtotime("-30 days"))])->count(1);
|
||||
|
||||
return $this->render('index', [
|
||||
'start' => $start,
|
||||
'end' => $end,
|
||||
'requestsStats' => $requestsStats,
|
||||
'payments' => $payments,
|
||||
'today' => $today,
|
||||
'yesterday' => $yesterday,
|
||||
'yesterdayIos' => $yesterdayIos,
|
||||
'last30days' => $last30days,
|
||||
'yandexWalletsSum' => $yandexWalletsSum,
|
||||
'qiwiWalletsSum' => $qiwiWalletsSum,
|
||||
'typesError' => $typesError,
|
||||
'last30Android' => $last30Android,
|
||||
'last30Ios' => $last30Ios,
|
||||
'todayAndroid' => $todayAndroid,
|
||||
'todayIos' => $todayIos,
|
||||
'avitoStats' => $avitoStats,
|
||||
'notifyTokens' => $notifyTokens,
|
||||
'notifyTokensWithoutSubs' => $notifyTokensWithoutSubs,
|
||||
'todaySubs' => $todaySubs,
|
||||
'yesterdaySubs' => $yesterdaySubs,
|
||||
'last30daysSubs' => $last30daysSubs
|
||||
]);
|
||||
}
|
||||
}
|
168
modules/admin/controllers/HistoryController.php
Normal file
168
modules/admin/controllers/HistoryController.php
Normal file
|
@ -0,0 +1,168 @@
|
|||
<?php
|
||||
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use app\models\Payment;
|
||||
use app\models\Site;
|
||||
use Yii;
|
||||
use app\models\SearchRequest;
|
||||
use app\models\forms\AdminHistoryFilterForm;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\db\Expression;
|
||||
use yii\db\Query;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\web\Controller;
|
||||
|
||||
class HistoryController extends AdminController
|
||||
{
|
||||
public function actionIndex()
|
||||
{
|
||||
$model = new AdminHistoryFilterForm();
|
||||
|
||||
$model->load(Yii::$app->getRequest()->get());
|
||||
|
||||
$today = date('Y-m-d');
|
||||
|
||||
if (!$model->from) {
|
||||
$model->from = $today;
|
||||
}
|
||||
|
||||
if (!$model->to) {
|
||||
$model->to = $today;
|
||||
}
|
||||
|
||||
$queries = (new Query())
|
||||
->select(['
|
||||
CASE
|
||||
WHEN (user_id IS NULL)
|
||||
THEN false
|
||||
ELSE true
|
||||
END as registred', 'count(1)'])
|
||||
->from(SearchRequest::tableName())
|
||||
->join('LEFT JOIN', 'users', 'requests.user_id = users.id')
|
||||
->where(['>=', 'tm', $model->from . ' 00:00:00'])
|
||||
->andWhere(['<=', 'tm', $model->to . ' 23:59:59'])
|
||||
->andWhere(['or', ['users.is_admin' => false], ['users.is_admin' => null]])
|
||||
->groupBy('registred')
|
||||
->all();
|
||||
|
||||
$users = Yii::$app->getDb()->createCommand('
|
||||
SELECT COUNT(DISTINCT user_id)
|
||||
FROM (SELECT DISTINCT phone, tm FROM requests WHERE user_id IS NULL) r1
|
||||
JOIN (SELECT DISTINCT phone, tm, user_id FROM requests WHERE user_id IS NOT NULL) r2
|
||||
ON r1.phone = r2.phone
|
||||
WHERE r1.tm >= :tm_start AND r1.tm <= :tm_end AND r1.tm < r2.tm;', [
|
||||
':tm_start' => $model->from . ' 00:00:00',
|
||||
':tm_end' => $model->to . ' 23:59:59'
|
||||
])->queryAll();
|
||||
|
||||
$phones = SearchRequest::find()
|
||||
->select('requests.phone')
|
||||
->joinWith(['user'])
|
||||
->where(['>=', 'tm', $model->from . ' 00:00:00'])
|
||||
->andWhere(['<=', 'tm', $model->to . ' 23:59:59'])
|
||||
->andWhere(['or', ['users.is_admin' => false], ['users.is_admin' => null]])
|
||||
->distinct()
|
||||
->count();
|
||||
|
||||
$sources = (new Query())
|
||||
->select(['source_id', new Expression('COUNT(1)')])
|
||||
->from('requests')
|
||||
->join('LEFT JOIN', 'users', 'requests.user_id = users.id')
|
||||
->where(['>=', 'tm', $model->from . ' 00:00:00'])
|
||||
->andWhere(['<=', 'tm', $model->to . ' 23:59:59'])
|
||||
->andWhere(['or', ['users.is_admin' => false], ['users.is_admin' => null]])
|
||||
->groupBy('source_id')
|
||||
->orderBy('source_id')
|
||||
->all();
|
||||
|
||||
$sitesRequests = (new Query())
|
||||
->select(['site_id', 'is_payed', 'source_id', new Expression('COUNT(1) as c')])
|
||||
->from('requests')
|
||||
->leftJoin('users', 'requests.user_id = users.id')
|
||||
->where(['>=', 'tm', $model->from . ' 00:00:00'])
|
||||
->andWhere(['<=', 'tm', $model->to . ' 23:59:59'])
|
||||
->andWhere(['or', ['users.is_admin' => false], ['users.is_admin' => null]])
|
||||
->groupBy(['site_id', 'is_payed', 'source_id'])
|
||||
->orderBy(['site_id' => SORT_ASC, 'is_payed' => SORT_ASC, 'source_id' => SORT_ASC])
|
||||
->all();
|
||||
|
||||
$sitesData = [];
|
||||
foreach($sitesRequests as $sr) {
|
||||
$is_payed = in_array($sr["is_payed"], [1, 2]);
|
||||
if(!isset($sitesData[$sr["site_id"]][$sr["source_id"]][$is_payed])) {
|
||||
$sitesData[$sr["site_id"]][$sr["source_id"]][$is_payed] = 0;
|
||||
}
|
||||
$sitesData[$sr["site_id"]][$sr["source_id"]][$is_payed] += $sr["c"];
|
||||
}
|
||||
|
||||
$type = \Yii::$app->request->get("type", null);
|
||||
|
||||
$query = SearchRequest::find()
|
||||
->andWhere(['>=', 'tm', $model->from . ' 00:00:00'])
|
||||
->andWhere(['<=', 'tm', $model->to . ' 23:59:59'])
|
||||
->andWhere(['or', ['users.is_admin' => false], ['users.is_admin' => null]])
|
||||
->joinWith(['user']);
|
||||
|
||||
switch($type) {
|
||||
case 1:
|
||||
$query->andWhere(["is_payed" => 0, "is_has_name" => false, "is_has_photo" => false]);
|
||||
break;
|
||||
case 2:
|
||||
$query->andWhere(["is_payed" => 0, "is_has_name" => true, "is_has_photo" => true]);
|
||||
break;
|
||||
case 3:
|
||||
$query->andWhere(["is_payed" => 0, "is_has_name" => true, "is_has_photo" => false]);
|
||||
break;
|
||||
case 4:
|
||||
$query->andWhere(["is_payed" => [1, 2]]);
|
||||
break;
|
||||
case 5:
|
||||
$query->andWhere(["is_payed" => 2]);
|
||||
break;
|
||||
case 6:
|
||||
$query->andWhere(["is_payed" => 1]);
|
||||
break;
|
||||
case 7:
|
||||
$query->andWhere(["user_id" => null]);
|
||||
break;
|
||||
case 8:
|
||||
$query->andWhere(["is not", "user_id", null])->andWhere(["is_payed" => 0]);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
$siteID = \Yii::$app->request->get("site_id", null);
|
||||
if($siteID) {
|
||||
$query->andWhere(['site_id' => $siteID]);
|
||||
}
|
||||
|
||||
if ($model->user) {
|
||||
$query->andWhere(['user_id' => $model->user]);
|
||||
}
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query,
|
||||
'sort' => ['defaultOrder' => ['id' => SORT_DESC]]
|
||||
]);
|
||||
|
||||
$sites = Site::find()->orderBy(["id" => SORT_ASC])->asArray()->indexBy("id")->all();
|
||||
|
||||
$payments = Payment::find()->select(["site_id", new Expression("SUM(amount) as sum")])->where([">=", "tm", date("Y-m-d H:i:s", strtotime("-30 days"))])->groupBy("site_id")->indexBy("site_id")->asArray()->all();
|
||||
$searches = SearchRequest::find()->select(["site_id", new Expression("count(1) as count")])->where([">=", "tm", date("Y-m-d H:i:s", strtotime("-30 days"))])->groupBy("site_id")->indexBy("site_id")->asArray()->all();
|
||||
|
||||
return $this->render('index', [
|
||||
'payments' => $payments,
|
||||
'searches' => $searches,
|
||||
'model' => $model,
|
||||
'dataProvider' => $dataProvider,
|
||||
'queries' => $queries,
|
||||
'users' => $users,
|
||||
'phones' => $phones,
|
||||
'sources' => $sources,
|
||||
'sites' => $sites,
|
||||
'sitesData' => $sitesData
|
||||
]);
|
||||
}
|
||||
}
|
133
modules/admin/controllers/NotifyController.php
Normal file
133
modules/admin/controllers/NotifyController.php
Normal file
|
@ -0,0 +1,133 @@
|
|||
<?php
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use app\models\Notification;
|
||||
use app\models\NotificationResult;
|
||||
use app\models\User;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\db\Expression;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\Json;
|
||||
use yii\web\Controller;
|
||||
|
||||
class NotifyController extends Controller {
|
||||
|
||||
public function actionIndex() {
|
||||
if(\Yii::$app->request->isPost) {
|
||||
$post = \Yii::$app->request->post();
|
||||
|
||||
$notify = new Notification();
|
||||
$notify->message = ArrayHelper::getValue($post, "message");
|
||||
$notify->payload = ArrayHelper::getValue($post, "payload");
|
||||
$notify->tm_create = new Expression("NOW()");
|
||||
$notify->tm_send = new Expression("NOW()");
|
||||
if($notify->save()) {
|
||||
$whom = ArrayHelper::getValue($post, "whom");
|
||||
switch ($whom) {
|
||||
case "all":
|
||||
$users = \Yii::$app->db->createCommand("SELECT id, token FROM users u WHERE AND u.token is NOT NULL")->queryAll();
|
||||
break;
|
||||
default:
|
||||
$users = \Yii::$app->db->createCommand("SELECT u.id, token FROM users u LEFT JOIN subs s ON s.user_id = u.id WHERE s.id is null AND u.token is NOT NULL")->queryAll();
|
||||
break;
|
||||
}
|
||||
//$users = \Yii::$app->db->createCommand("SELECT u.id, token FROM users u WHERE id = 79630")->queryAll();
|
||||
foreach($users as $u) {
|
||||
$notifyResult = new NotificationResult();
|
||||
$notifyResult->notify_id = $notify->id;
|
||||
$notifyResult->user_id = ArrayHelper::getValue($u, "id");
|
||||
$notifyResult->status = 0;
|
||||
$notifyResult->save();
|
||||
}
|
||||
|
||||
$tokensData = ArrayHelper::getColumn($users, "token");
|
||||
for($i = 0; $i <= ceil(count($tokensData)/100); $i++) {
|
||||
$tokens = array_slice($tokensData, $i * 100, 100);
|
||||
$fields = [
|
||||
'x' => $i,
|
||||
'id' => $notify->id,
|
||||
'message' => $notify->message,
|
||||
'payload' => $notify->payload,
|
||||
'tokens' => Json::encode($tokens)
|
||||
];
|
||||
$fields_string = http_build_query($fields);
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL,"http://apinomer.com:9999/send");
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$response = curl_exec ($ch);
|
||||
|
||||
curl_close ($ch);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $this->redirect(["notify/index"]);
|
||||
}
|
||||
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
"query" => Notification::find()->orderBy(["id" => SORT_DESC])
|
||||
]);
|
||||
|
||||
return $this->render("index", [
|
||||
"dataProvider" => $dataProvider
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionStatus() {
|
||||
$id = \Yii::$app->request->get("id");
|
||||
$token = \Yii::$app->request->get("token");
|
||||
$status = \Yii::$app->request->get("status");
|
||||
|
||||
$user = User::find()->where(["token" => $token])->one();
|
||||
$result = NotificationResult::find()->where(["user_id" => $user->id, "notify_id" => $id])->one();
|
||||
$result->status = $status;
|
||||
$result->save();
|
||||
return "OK";
|
||||
}
|
||||
|
||||
public function actionSend() {
|
||||
/*
|
||||
$tokens = \Yii::$app->db->createCommand("SELECT token FROM users u LEFT JOIN subs s ON s.user_id = u.id WHERE s.id is null AND u.token is NOT NULL")->queryColumn();
|
||||
|
||||
$payload = [
|
||||
"message" => [
|
||||
"item" => "com.wcaller.Wcaller.sub.month.5",
|
||||
"title" => "Получите премиум доступ",
|
||||
"- Полная проверка по всем базам\n- Включено 10 проверок в месяц\n- Скидка 30% на покупку проверок!"
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
$fields = [
|
||||
'message' => "Мы начислили вам 2 бесплатных поиска, попробуйте наше приложение, уверены оно вам понравится!",
|
||||
'payload' => Json::encode($payload),
|
||||
'tokens' => Json::encode($tokens)
|
||||
];
|
||||
$fields_string = http_build_query($fields);
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL,"http://nomer.io:9999/send");
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$server_output = curl_exec ($ch);
|
||||
|
||||
curl_close ($ch);
|
||||
|
||||
print_r($tokens);
|
||||
*/
|
||||
}
|
||||
}
|
37
modules/admin/controllers/PaymentsController.php
Normal file
37
modules/admin/controllers/PaymentsController.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use app\models\Payment;
|
||||
use app\models\UserSub;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\db\Expression;
|
||||
use yii\db\Query;
|
||||
|
||||
class PaymentsController extends AdminController
|
||||
{
|
||||
public function actionIndex()
|
||||
{
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => Payment::find()
|
||||
->orderBy(['id' => SORT_DESC])
|
||||
->where(['>=', 'tm', date('Y-m-d 00:00:00', strtotime('-7 day'))])
|
||||
->andWhere(["<>", "type_id", Payment::TYPE_TESTAPPLE])
|
||||
->orderBy(['tm' => SORT_DESC])
|
||||
->with(["site", "user", "user.payments"])
|
||||
]);
|
||||
|
||||
$dataProvider->pagination = false;
|
||||
|
||||
$todaySubs = UserSub::find()->where(new Expression(
|
||||
"extract(month from tm_purchase) = ".date("m")."
|
||||
AND extract(year from tm_purchase) = ".date("Y")."
|
||||
AND extract(day from tm_purchase) = ".date("d")
|
||||
))->count(1);
|
||||
|
||||
return $this->render('index', [
|
||||
'dataProvider' => $dataProvider,
|
||||
'todaySubs' => $todaySubs
|
||||
]);
|
||||
}
|
||||
}
|
46
modules/admin/controllers/PlatiController.php
Normal file
46
modules/admin/controllers/PlatiController.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use app\components\coupon;
|
||||
use app\models\PlatiCode;
|
||||
use yii\data\ActiveDataProvider;
|
||||
|
||||
class PlatiController extends AdminController {
|
||||
|
||||
public function actionNew() {
|
||||
$checks = \Yii::$app->request->get("checks");
|
||||
$count = \Yii::$app->request->get("count");
|
||||
|
||||
$codes = coupon::generate_coupons($count, [
|
||||
"length" => 12,
|
||||
"letters" => true,
|
||||
"numbers" => true,
|
||||
"symbols" => false,
|
||||
"mixed_case" => true,
|
||||
"mask" => "XXX-XXX-XXX-XXX"
|
||||
]);
|
||||
|
||||
$newCodes = [];
|
||||
foreach($codes as $code) {
|
||||
$platiCode = PlatiCode::find()->where(["code" => $code])->one();
|
||||
if($platiCode) continue;
|
||||
$platiCode = new PlatiCode();
|
||||
$platiCode->code = $code;
|
||||
$platiCode->checks = $checks;
|
||||
$platiCode->save();
|
||||
$newCodes[] = $code."<br>Для зачисления проверок введите код на сайте https://nomer.io/pay/coupon";
|
||||
}
|
||||
$file = \Yii::getAlias('@runtime')."/".uniqid("coupons").".txt";
|
||||
file_put_contents($file, join("\n", $newCodes));
|
||||
|
||||
\Yii::$app->response->sendFile($file);
|
||||
}
|
||||
|
||||
public function actionIndex() {
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => PlatiCode::find()
|
||||
]);
|
||||
|
||||
return $this->render('index', ["dataProvider" => $dataProvider]);
|
||||
}
|
||||
}
|
20
modules/admin/controllers/ReferralsController.php
Normal file
20
modules/admin/controllers/ReferralsController.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use app\models\User;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class ReferralsController extends AdminController {
|
||||
|
||||
public function actionIndex() {
|
||||
$users = User::find()->where([">", "ref_id", 0])->asArray()->all();
|
||||
|
||||
$refIds = ArrayHelper::getColumn($users, "ref_id");
|
||||
$refIds = array_unique($refIds);
|
||||
$refs = User::find()->where(["id" => $refIds])->all();
|
||||
|
||||
return $this->render("index", [
|
||||
"refs" => $refs
|
||||
]);
|
||||
}
|
||||
}
|
18
modules/admin/controllers/RepostsController.php
Normal file
18
modules/admin/controllers/RepostsController.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use app\models\Repost;
|
||||
use yii\data\ActiveDataProvider;
|
||||
|
||||
class RepostsController extends AdminController {
|
||||
|
||||
public function actionIndex() {
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
"query" => Repost::find()->orderBy(["tm" => SORT_DESC])
|
||||
]);
|
||||
|
||||
return $this->render("index", [
|
||||
"dataProvider" => $dataProvider
|
||||
]);
|
||||
}
|
||||
}
|
77
modules/admin/controllers/RetargetingController.php
Normal file
77
modules/admin/controllers/RetargetingController.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use app\models\Retargeting;
|
||||
use yii\base\Exception;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\db\Expression;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class RetargetingController extends AdminController {
|
||||
|
||||
public function actionIndex() {
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => Retargeting::find()->orderBy(["id" => SORT_DESC])
|
||||
]);
|
||||
|
||||
$todaySent = Retargeting::find()
|
||||
->where(['status' => Retargeting::STATUS_SENT])
|
||||
->andWhere(["=", new Expression("extract(month from tm_send)"), date("m")])
|
||||
->andWhere(["=", new Expression("extract(year from tm_send)"), date("Y")])
|
||||
->andWhere(["=", new Expression("extract(day from tm_send)"), date("d")])
|
||||
->count();
|
||||
|
||||
$todayRead = Retargeting::find()
|
||||
->where(['status' => Retargeting::STATUS_READ])
|
||||
->andWhere(["=", new Expression("extract(month from tm_read)"), date("m")])
|
||||
->andWhere(["=", new Expression("extract(year from tm_read)"), date("Y")])
|
||||
->andWhere(["=", new Expression("extract(day from tm_read)"), date("d")])
|
||||
->count();
|
||||
|
||||
$todayClick = Retargeting::find()
|
||||
->where(['status' => Retargeting::STATUS_CLICK])
|
||||
->andWhere(["=", new Expression("extract(month from tm_click)"), date("m")])
|
||||
->andWhere(["=", new Expression("extract(year from tm_click)"), date("Y")])
|
||||
->andWhere(["=", new Expression("extract(day from tm_click)"), date("d")])
|
||||
->count();
|
||||
|
||||
$yesterdaySent = Retargeting::find()
|
||||
->where(['status' => Retargeting::STATUS_SENT])
|
||||
->andWhere(["=", new Expression("extract(month from tm_send)"), date("m", strtotime("-1 day"))])
|
||||
->andWhere(["=", new Expression("extract(year from tm_send)"), date("Y", strtotime("-1 day"))])
|
||||
->andWhere(["=", new Expression("extract(day from tm_send)"), date("d", strtotime("-1 day") )])
|
||||
->count();
|
||||
|
||||
$yesterdayRead = Retargeting::find()
|
||||
->where(['status' => Retargeting::STATUS_READ])
|
||||
->andWhere(["=", new Expression("extract(month from tm_read)"), date("m", strtotime("-1 day"))])
|
||||
->andWhere(["=", new Expression("extract(year from tm_read)"), date("Y", strtotime("-1 day"))])
|
||||
->andWhere(["=", new Expression("extract(day from tm_read)"), date("d", strtotime("-1 day"))])
|
||||
->count();
|
||||
|
||||
$yesterdayClick = Retargeting::find()
|
||||
->where(['status' => Retargeting::STATUS_CLICK])
|
||||
->andWhere(["=", new Expression("extract(month from tm_click)"), date("m", strtotime("-1 day"))])
|
||||
->andWhere(["=", new Expression("extract(year from tm_click)"), date("Y", strtotime("-1 day"))])
|
||||
->andWhere(["=", new Expression("extract(day from tm_click)"), date("d", strtotime("-1 day"))])
|
||||
->count();
|
||||
|
||||
$monthSent = Retargeting::find()
|
||||
->where(['status' => Retargeting::STATUS_SENT])
|
||||
->andWhere([">=", "tm_send", date("Y-m-d 00:00:00", strtotime("-30 days"))])
|
||||
->count();
|
||||
|
||||
$monthRead = Retargeting::find()
|
||||
->where(['status' => Retargeting::STATUS_READ])
|
||||
->andWhere([">=", "tm_read", date("Y-m-d 00:00:00", strtotime("-30 days"))])
|
||||
->count();
|
||||
|
||||
$monthClick = Retargeting::find()
|
||||
->where(['status' => Retargeting::STATUS_CLICK])
|
||||
->andWhere([">=", "tm_click", date("Y-m-d 00:00:00", strtotime("-30 days"))])
|
||||
->count();
|
||||
|
||||
return $this->render("index", compact('todaySent', 'todayRead', 'todayClick','yesterdaySent','yesterdayRead','yesterdayClick', 'monthSent', 'monthRead','monthClick'));
|
||||
}
|
||||
}
|
112
modules/admin/controllers/SettingsController.php
Normal file
112
modules/admin/controllers/SettingsController.php
Normal file
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use app\models\UrlFilter;
|
||||
use Yii;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use app\models\Settings;
|
||||
use app\models\User;
|
||||
use yii\data\SqlDataProvider;
|
||||
use yii\db\Query;
|
||||
use yii\helpers\Url;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
class SettingsController extends AdminController
|
||||
{
|
||||
public function actionIndex($tab = 'index')
|
||||
{
|
||||
switch ($tab) {
|
||||
case 'index': {
|
||||
if (Yii::$app->getRequest()->getIsPost()) {
|
||||
foreach (Yii::$app->getRequest()->post() as $key => $value) {
|
||||
Settings::set($key, $value);
|
||||
}
|
||||
|
||||
return $this->redirect(['settings/index', 'tab' => 'index']);
|
||||
}
|
||||
}
|
||||
case 'bans': {
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => User::find()->where(['status' => 0]),
|
||||
'sort' => ['defaultOrder' => ['id' => SORT_DESC]]
|
||||
]);
|
||||
|
||||
return $this->render('index', compact('tab', 'dataProvider'));
|
||||
}
|
||||
case 'domains': {
|
||||
$model = new UrlFilter();
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => UrlFilter::find(),
|
||||
'sort' => ['defaultOrder' => ['id' => SORT_DESC]]
|
||||
]);
|
||||
|
||||
if (Yii::$app->getRequest()->getIsPost()) {
|
||||
$model->load(Yii::$app->getRequest()->post());
|
||||
|
||||
if (!$model->validate()) {
|
||||
return $this->render('index', compact('model', 'dataProvider'));
|
||||
}
|
||||
|
||||
$model->save();
|
||||
$this->refresh();
|
||||
}
|
||||
|
||||
return $this->render('index', compact('tab', 'model', 'dataProvider'));
|
||||
}
|
||||
case 'fingerprints': {
|
||||
$dataProvider = new SqlDataProvider([
|
||||
'sql' => \Yii::$app->db->createCommand("SELECT hash, array_agg(user_id) as user_ids, array_agg(ip) as ips FROM \"user_fingerprints\" GROUP BY \"hash\" HAVING COUNT(1) > 1")->rawSql,
|
||||
'sort' => false
|
||||
]);
|
||||
|
||||
return $this->render('index', compact('tab', 'dataProvider'));
|
||||
}
|
||||
case 'blocked-phones': {
|
||||
$results = (new Query())
|
||||
->select(['to_char(tm, \'YYYY-MM-DD\') as date', 'status', 'count(1) as count'])
|
||||
->from('block')
|
||||
->groupBy(['date', 'status'])
|
||||
->orderBy(['date' => SORT_DESC, 'status' => SORT_ASC])
|
||||
->all();
|
||||
|
||||
$phones = [];
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (!isset($phones[$result['date']])) $phones[$result['date']] = [
|
||||
'all' => 0,
|
||||
'unconfirmed' => 0,
|
||||
'confirmed' => 0,
|
||||
'vip' => 0
|
||||
];
|
||||
|
||||
switch ($result['status']) {
|
||||
case 0:
|
||||
$phones[$result['date']]['unconfirmed'] = $result['count'];
|
||||
break;
|
||||
case 1:
|
||||
$phones[$result['date']]['confirmed'] = $result['count'];
|
||||
break;
|
||||
case 2:
|
||||
$phones[$result['date']]['vip'] = $result['count'];
|
||||
break;
|
||||
}
|
||||
|
||||
$phones[$result['date']]['all'] += $result['count'];
|
||||
}
|
||||
|
||||
return $this->render('index', compact('tab', 'phones'));
|
||||
}
|
||||
default: throw new NotFoundHttpException('Страница не найдена.');
|
||||
}
|
||||
}
|
||||
|
||||
public function actionDeleteDomain($id)
|
||||
{
|
||||
if ($domain = UrlFilter::findOne($id)) $domain->delete();
|
||||
if (!$domain) throw new NotFoundHttpException('Домен не найден.');
|
||||
$referrer = Yii::$app->getRequest()->getReferrer();
|
||||
$url = $referrer ? $referrer : Url::to(['settings/index', 'tab' => 'domains']);
|
||||
return $this->redirect($url);
|
||||
}
|
||||
}
|
67
modules/admin/controllers/SitesController.php
Normal file
67
modules/admin/controllers/SitesController.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use app\models\Payment;
|
||||
use app\models\SearchRequest;
|
||||
use Yii;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use app\models\Site;
|
||||
use yii\db\Expression;
|
||||
|
||||
class SitesController extends AdminController
|
||||
{
|
||||
public function actionIndex()
|
||||
{
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => Site::find()->orderBy("id")->where(["not in", "id", [6, 14]])
|
||||
]);
|
||||
|
||||
$dataProvider->pagination = false;
|
||||
|
||||
$payments = Payment::find()->select(["site_id", new Expression("SUM(amount) as sum")])->where([">=", "tm", date("Y-m-d H:i:s", strtotime("-30 days"))])->groupBy("site_id")->indexBy("site_id")->asArray()->all();
|
||||
$seaches = SearchRequest::find()->select(["site_id", new Expression("count(1) as count")])->where([">=", "tm", date("Y-m-d H:i:s", strtotime("-30 days"))])->groupBy("site_id")->indexBy("site_id")->asArray()->all();
|
||||
//$applePayments = SearchRequest::find()->select(["site_id", new Expression("count(1) as count")])->where([">=", "tm", date("Y-m-d H:i:s", strtotime("-30 days"))])->groupBy("site_id")->indexBy("site_id")->asArray()->all();
|
||||
|
||||
return $this->render('index', compact('dataProvider', 'payments', 'seaches'));
|
||||
}
|
||||
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new Site();
|
||||
|
||||
if ($model->load(Yii::$app->getRequest()->post()) && $model->save()) {
|
||||
return $this->redirect(['sites/index']);
|
||||
}
|
||||
|
||||
return $this->render('create', compact('model'));
|
||||
}
|
||||
|
||||
public function actionUpdate($id)
|
||||
{
|
||||
$model = Site::find()->where(compact('id'))->one();
|
||||
|
||||
if ($model->load(Yii::$app->getRequest()->post()) && $model->save()) {
|
||||
return $this->redirect(['sites/index']);
|
||||
}
|
||||
|
||||
return $this->render('update', compact('model'));
|
||||
}
|
||||
|
||||
public function actionDelete($id)
|
||||
{
|
||||
$model = Site::find()->where(compact('id'))->one();
|
||||
|
||||
$model->delete();
|
||||
|
||||
return $this->redirect(['sites/index']);
|
||||
}
|
||||
|
||||
public function actionSetDemo($id)
|
||||
{
|
||||
$model = Site::find()->where(compact('id'))->one();
|
||||
$model->is_demo = !$model->is_demo;
|
||||
$model->save();
|
||||
return $this->redirect(Yii::$app->getRequest()->getReferrer());
|
||||
}
|
||||
}
|
86
modules/admin/controllers/StatsController.php
Normal file
86
modules/admin/controllers/StatsController.php
Normal file
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\data\ArrayDataProvider;
|
||||
use yii\db\Expression;
|
||||
use yii\db\Query;
|
||||
use app\models\SearchRequest;
|
||||
|
||||
class StatsController extends AdminController
|
||||
{
|
||||
public function actionIndex()
|
||||
{
|
||||
$start = Yii::$app->request->get('tm_start', date('Y-m-d', strtotime('-7 days')));
|
||||
$end = Yii::$app->request->get('tm_end', date('Y-m-d'));
|
||||
|
||||
$results = (new Query())
|
||||
->select(['to_char(requests.tm, \'YYYY-MM-DD\') as date', 'request_results.type_id', '
|
||||
CASE
|
||||
WHEN (request_results.data = \'null\' OR request_results.data = \'[]\')
|
||||
THEN false
|
||||
ELSE true
|
||||
END as success', 'count(1)'])
|
||||
->from('requests')
|
||||
->innerJoin('request_results', ['requests.id' => new Expression('request_id')])
|
||||
->where(['>', 'requests.tm', date('Y-m-d', strtotime('-7 days'))])
|
||||
->groupBy(['date', 'request_results.type_id', 'success'])
|
||||
->orderBy(['date' => SORT_ASC, 'request_results.type_id' => SORT_ASC, 'success' => SORT_ASC])
|
||||
->all();
|
||||
|
||||
$sourcesStats = [];
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (!isset($sourcesStats[$result['date']])) $sourcesStats[$result['date']] = [];
|
||||
if (!isset($sourcesStats[$result['date']][$result['type_id']])) {
|
||||
$sourcesStats[$result['date']][$result['type_id']] = [
|
||||
'all' => 0,
|
||||
'success' => 0
|
||||
];
|
||||
}
|
||||
|
||||
$sourcesStats[$result['date']][$result['type_id']]['all'] += $result['count'];
|
||||
if ($result['success']) $sourcesStats[$result['date']][$result['type_id']]['success'] += $result['count'];
|
||||
}
|
||||
|
||||
return $this->render('index', compact('start', 'end', 'sourcesStats'));
|
||||
}
|
||||
|
||||
public function actionDetailed($type, $date, $filter = 'all')
|
||||
{
|
||||
$type = (int) $type;
|
||||
|
||||
$query = (new Query())
|
||||
->select(['requests.id', 'requests.phone', '
|
||||
CASE
|
||||
WHEN (request_results.data = \'null\' OR request_results.data = \'[]\')
|
||||
THEN false
|
||||
ELSE true
|
||||
END as success', 'requests.tm'])
|
||||
->from('requests')
|
||||
->innerJoin('request_results', ['requests.id' => new Expression('request_id')])
|
||||
->where(['request_results.type_id' => $type])
|
||||
->andWhere(['>=', 'requests.tm', $date . ' 00:00:00'])
|
||||
->andWhere(['<=', 'requests.tm', $date . ' 23:59:59']);
|
||||
|
||||
switch ($filter) {
|
||||
case 'found': $query->andWhere(['and', ['<>', 'request_results.data', 'null'], ['<>', 'request_results.data', '[]']]); break;
|
||||
case 'not_found': $query->andWhere(['or', ['request_results.data' => 'null'], ['request_results.data' => '[]']]); break;
|
||||
default: $filter = 'all'; break;
|
||||
}
|
||||
|
||||
$requests = $query->all();
|
||||
|
||||
$dataProvider = new ArrayDataProvider([
|
||||
'allModels' => $requests,
|
||||
'sort' => [
|
||||
'attributes' => ['id', 'success'],
|
||||
'defaultOrder' => ['id' => SORT_DESC]
|
||||
]
|
||||
]);
|
||||
|
||||
return $this->render('detailed', compact('type', 'date', 'filter', 'dataProvider'));
|
||||
}
|
||||
}
|
32
modules/admin/controllers/SubscriptionsController.php
Normal file
32
modules/admin/controllers/SubscriptionsController.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use app\models\UserSub;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\db\Expression;
|
||||
use yii\web\User;
|
||||
|
||||
class SubscriptionsController extends AdminController {
|
||||
|
||||
public function actionIndex() {
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
"query" => UserSub::find()
|
||||
]);
|
||||
|
||||
return $this->render("index", [
|
||||
"dataProvider" => $dataProvider
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionTest() {
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
"query" => UserSub::find()->from(UserSub::tableName()." s")->innerJoin(UserSub::tableName()." s2", "s.original_transaction_id = s2.original_transaction_id")->where(new Expression("s.tm_expires::date - s.tm_purchase::date = 3"))->andWhere(new Expression("s2.tm_expires::date - s2.tm_purchase::date > 5"))
|
||||
]);
|
||||
|
||||
return $this->render("index", [
|
||||
"dataProvider" => $dataProvider
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
}
|
165
modules/admin/controllers/TicketsController.php
Normal file
165
modules/admin/controllers/TicketsController.php
Normal file
|
@ -0,0 +1,165 @@
|
|||
<?php
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use app\models\Site;
|
||||
use app\models\Ticket;
|
||||
use app\models\TicketComment;
|
||||
use app\models\TicketReply;
|
||||
use app\models\User;
|
||||
use yii\base\Exception;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\db\Expression;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class TicketsController extends AdminController {
|
||||
|
||||
public function actionIndex() {
|
||||
$statuses = [0, 1];
|
||||
|
||||
if(\Yii::$app->getUser()->getId() == 1) {
|
||||
$statuses = [0, 1, 7];
|
||||
}
|
||||
|
||||
$query = Ticket::find()->where(["is_deleted" => 0, "status" => $statuses])->with("user")->orderBy(["id" => SORT_DESC]);
|
||||
$ticketsNotRead = new ActiveDataProvider([
|
||||
'query' => $query
|
||||
]);
|
||||
|
||||
$tIds = ArrayHelper::getColumn($ticketsNotRead->getModels(), "id");
|
||||
|
||||
$tickets = new ActiveDataProvider([
|
||||
'query' => Ticket::find()->where(["NOT IN", "id", $tIds])->andWhere(["is_deleted" => 0])->with("user")->orderBy(["id" => SORT_DESC])
|
||||
]);
|
||||
|
||||
|
||||
return $this->render("index", [
|
||||
"tickets" => $tickets,
|
||||
"ticketsNotRead" => $ticketsNotRead
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionIgnore($id) {
|
||||
$ticket = Ticket::find()->where(["id" => $id])->one();
|
||||
$ticket->status = 6;
|
||||
$ticket->tm_close = new Expression('NOW()');
|
||||
$ticket->save(false);
|
||||
|
||||
return $this->redirect(["tickets/index"]);
|
||||
}
|
||||
|
||||
public function actionDevelop($id) {
|
||||
$ticket = Ticket::find()->where(["id" => $id])->one();
|
||||
$ticket->status = 7;
|
||||
$ticket->tm_close = new Expression('NOW()');
|
||||
$ticket->save(false);
|
||||
|
||||
return $this->redirect(["tickets/index"]);
|
||||
}
|
||||
|
||||
public function actionClose($id) {
|
||||
$ticket = Ticket::find()->where(["id" => $id])->one();
|
||||
$ticket->status = 4;
|
||||
$ticket->tm_close = new Expression('NOW()');
|
||||
$ticket->save(false);
|
||||
|
||||
return $this->redirect(["tickets/index"]);
|
||||
}
|
||||
|
||||
public function actionDelete($id) {
|
||||
$ticket = Ticket::find()->where(["id" => $id])->one();
|
||||
$ticket->is_deleted = true;
|
||||
$ticket->save(false);
|
||||
|
||||
return $this->redirect(["tickets/index"]);
|
||||
}
|
||||
|
||||
public function actionReopen($id) {
|
||||
$ticket = Ticket::find()->where(["id" => $id])->one();
|
||||
$ticket->status = 1;
|
||||
$ticket->save(false);
|
||||
|
||||
return $this->redirect(["tickets/view", "id" => $id]);
|
||||
}
|
||||
|
||||
public function actionCommentDelete($id) {
|
||||
$comment = TicketComment::find()->where(["id" => $id])->one();
|
||||
$comment->is_deleted = true;
|
||||
$comment->save();
|
||||
|
||||
return $this->redirect(["tickets/view", "id" => $comment->ticket_id]);
|
||||
}
|
||||
|
||||
public function actionAddReply($id) {
|
||||
$ticket = Ticket::find()->where(["id" => $id])->one();
|
||||
|
||||
$text = \Yii::$app->request->post("text");
|
||||
|
||||
if(trim($text) != "") {
|
||||
$reply = new TicketReply();
|
||||
$reply->subject_id = $ticket->subject_id;
|
||||
$reply->text = $text;
|
||||
$reply->save();
|
||||
return $this->renderAjax('_reply', ['reply' => $reply]);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function actionView($id) {
|
||||
$ticket = Ticket::find()->where(["id" => $id])->one();
|
||||
|
||||
TicketComment::updateAll(["tm_read" => new Expression('NOW()')], "ticket_id = ".$ticket->id." AND tm_read is null AND user_id <> ".\Yii::$app->getUser()->id);
|
||||
|
||||
if($ticket->status == 0) {
|
||||
$ticket->status = 1;
|
||||
}
|
||||
|
||||
$ticket->tm_read = new Expression('NOW()');
|
||||
$ticket->save(false);
|
||||
|
||||
$comments = new ActiveDataProvider([
|
||||
"query" => TicketComment::find()->where(["ticket_id" => $ticket->id, "is_deleted" => 0])->orderBy(["id" => SORT_ASC])
|
||||
]);
|
||||
|
||||
$comment = new TicketComment();
|
||||
|
||||
$replies = TicketReply::find()->all();
|
||||
|
||||
return $this->render("view", [
|
||||
"ticket" => $ticket,
|
||||
"comments" => $comments,
|
||||
"comment" => $comment,
|
||||
"replies" => $replies
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionComment($id) {
|
||||
$comment = new TicketComment();
|
||||
$comment->load(\Yii::$app->request->post());
|
||||
$comment->ticket_id = $id;
|
||||
|
||||
$comment->save();
|
||||
|
||||
$ticket = Ticket::find()->where(["id" => $id])->one();
|
||||
$user = User::find()->where(["id" => $ticket->user_id])->one();
|
||||
$site = Site::find()->where(["id" => $ticket->site_id])->one();
|
||||
|
||||
$ticket->status = 2;
|
||||
$ticket->save(false);
|
||||
|
||||
try {
|
||||
if(preg_match('/@/', $user->email)) {
|
||||
\Yii::$app->mailer->compose()
|
||||
->setHtmlBody("Администратор оставил новый ответ.<br><a href='https://".$site->name."/feedback'></a>")
|
||||
->setFrom('noreply@'.$site->name)
|
||||
->setTo($user->email)
|
||||
->setSubject($site->name." - новый отет на запрос")
|
||||
->send();
|
||||
}
|
||||
} catch (Exception $e) {}
|
||||
|
||||
|
||||
return $this->redirect(["tickets/view", "id" => $id]);
|
||||
}
|
||||
}
|
77
modules/admin/controllers/TokensController.php
Normal file
77
modules/admin/controllers/TokensController.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\Url;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use app\models\Token;
|
||||
|
||||
class TokensController extends AdminController
|
||||
{
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'access' => [
|
||||
'class' => AccessControl::className(),
|
||||
'except' => ['query'],
|
||||
'rules' => [
|
||||
[
|
||||
'allow' => true,
|
||||
'roles' => ['@'],
|
||||
'matchCallback' => function ($rule, $action) {
|
||||
/* @var $identity \app\models\User */
|
||||
$identity = \Yii::$app->getUser()->getIdentity();
|
||||
return $identity->is_admin;
|
||||
}
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
$model = new Token();
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => Token::find(),
|
||||
'sort' => ['defaultOrder' => ['id' => SORT_DESC]]
|
||||
]);
|
||||
|
||||
if (Yii::$app->getRequest()->getIsPost()) {
|
||||
$model->load(Yii::$app->getRequest()->post());
|
||||
|
||||
if (!$model->validate()) {
|
||||
return $this->render('index', compact('model', 'dataProvider'));
|
||||
}
|
||||
|
||||
$model->save();
|
||||
$this->refresh();
|
||||
}
|
||||
|
||||
return $this->render('index', compact('model', 'dataProvider'));
|
||||
}
|
||||
|
||||
public function actionDelete($id)
|
||||
{
|
||||
if ($domain = Token::findOne($id)) $domain->delete();
|
||||
if (!$domain) throw new NotFoundHttpException('Токен не найден.');
|
||||
$referrer = Yii::$app->getRequest()->getReferrer();
|
||||
$url = $referrer ? $referrer : Url::to(['tokens/index']);
|
||||
return $this->redirect($url);
|
||||
}
|
||||
|
||||
public function actionQuery($server, $type)
|
||||
{
|
||||
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
|
||||
return ArrayHelper::getColumn(Token::find()
|
||||
->where(['type' => $type])
|
||||
->andWhere(['server_id' => $server])
|
||||
->andWhere(['status' => Token::STATUS_ACTIVE])
|
||||
->all(), 'token');
|
||||
}
|
||||
}
|
198
modules/admin/controllers/UsersController.php
Normal file
198
modules/admin/controllers/UsersController.php
Normal file
|
@ -0,0 +1,198 @@
|
|||
<?php
|
||||
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use app\models\UserAuthLog;
|
||||
use Yii;
|
||||
use app\models\Payment;
|
||||
use app\models\SearchRequest;
|
||||
use app\models\User;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\data\Sort;
|
||||
use yii\db\Query;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
class UsersController extends AdminController
|
||||
{
|
||||
public function actionIndex()
|
||||
{
|
||||
$tm_start = Yii::$app->getRequest()->get('tm_start', date('Y-m-d'));
|
||||
$tm_end = Yii::$app->getRequest()->get('tm_end', date('Y-m-d'));
|
||||
$email = Yii::$app->getRequest()->get('email');
|
||||
$isVIP = (bool) Yii::$app->getRequest()->get('is_vip', 0);
|
||||
$isAdmin = (bool) Yii::$app->getRequest()->get('is_admin', 0);
|
||||
$withChecks = (bool) Yii::$app->getRequest()->get('with_checks', 0);
|
||||
|
||||
$registrationsQuery = (new Query())
|
||||
->select(['auth.source', 'count(users.id)'])
|
||||
->from('users')
|
||||
->join('LEFT JOIN', 'auth', 'auth.user_id = users.id')
|
||||
->groupBy('auth.source')
|
||||
->orderBy(['auth.source' => SORT_ASC]);
|
||||
|
||||
if ($isVIP) $registrationsQuery->andWhere(['users.is_vip' => true]);
|
||||
if ($isAdmin) $registrationsQuery->andWhere(['users.is_admin' => true]);
|
||||
|
||||
if (!$isVIP && !$isAdmin && !$withChecks) {
|
||||
$registrationsQuery->andWhere(['>=', 'users.tm_create', $tm_start . ' 00:00:00'])
|
||||
->andWhere(['<=', 'users.tm_create', $tm_end . ' 23:59:59']);
|
||||
}
|
||||
|
||||
if ($withChecks) $registrationsQuery->andWhere(['>', 'users.checks', 0]);
|
||||
|
||||
$registrations = $registrationsQuery->all();
|
||||
|
||||
$registrationConfirmsQuery = (new Query())
|
||||
->select(['auth.source', 'count(users.id)'])
|
||||
->from('users')
|
||||
->join('LEFT JOIN', 'auth', 'auth.user_id = users.id')
|
||||
->andWhere(['is_confirm' => true])
|
||||
->groupBy('auth.source')
|
||||
->orderBy(['auth.source' => SORT_ASC])
|
||||
->indexBy('source');
|
||||
|
||||
if ($isVIP) $registrationConfirmsQuery->andWhere(['users.is_vip' => true]);
|
||||
if ($isAdmin) $registrationConfirmsQuery->andWhere(['users.is_admin' => true]);
|
||||
|
||||
if (!$isVIP && !$isAdmin && !$withChecks) {
|
||||
$registrationConfirmsQuery->andWhere(['>=', 'users.tm_create', $tm_start . ' 00:00:00'])
|
||||
->andWhere(['<=', 'users.tm_create', $tm_end . ' 23:59:59']);
|
||||
}
|
||||
|
||||
if ($withChecks) $registrationConfirmsQuery->andWhere(['>', 'users.checks', 0]);
|
||||
|
||||
$registrationConfirms = $registrationConfirmsQuery->all();
|
||||
|
||||
$query = User::find();
|
||||
|
||||
if ($email) $query->andWhere(['ilike', 'email', $email]);
|
||||
if ($isVIP) $query->andWhere(['is_vip' => true]);
|
||||
if ($isAdmin) $query->andWhere(['is_admin' => true]);
|
||||
|
||||
if (!$email && !$isVIP && !$isAdmin && !$withChecks) {
|
||||
$query
|
||||
->where(['>=', 'tm_create', $tm_start . ' 00:00:00'])
|
||||
->andWhere(['<=', 'tm_create', $tm_end . ' 23:59:59']);
|
||||
}
|
||||
|
||||
if ($withChecks) $query->andWhere(['>', 'checks', 0]);
|
||||
|
||||
$phones = \Yii::$app->db->createCommand("select count(1) from users where tm_create >='".$tm_start." 00:00:00' AND tm_create <= '".$tm_end." 23:59:59' and exists (select * from regexp_matches(users.email, '^[0-9]{11,12}$'))")->queryScalar();
|
||||
$registrations[] = ["source" => "phone", "count" => $phones];
|
||||
|
||||
$ios = \Yii::$app->db->createCommand("select count(1) from users where tm_create >='".$tm_start." 00:00:00' AND tm_create <= '".$tm_end." 23:59:59' and email is null and exists (select * from regexp_matches(users.uuid, '^[0-9A-Z-]{36}$'))")->queryScalar();
|
||||
$registrations[] = ["source" => "iOS", "count" => $ios];
|
||||
|
||||
$android = \Yii::$app->db->createCommand("select count(1) from users where tm_create >='".$tm_start." 00:00:00' AND tm_create <= '".$tm_end." 23:59:59' and email is not null and exists (select * from regexp_matches(users.uuid, '^[0-9A-Za-z-]{36}$'))")->queryScalar();
|
||||
$registrations[] = ["source" => "Android", "count" => $android];
|
||||
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => $query->with(['requests']),
|
||||
'sort' => new Sort([
|
||||
'attributes' => [
|
||||
'id',
|
||||
'checks' => [
|
||||
'default' => SORT_DESC
|
||||
]
|
||||
],
|
||||
'defaultOrder' => [
|
||||
'id' => SORT_DESC
|
||||
]
|
||||
])
|
||||
]);
|
||||
|
||||
return $this->render('index', compact(
|
||||
'dataProvider',
|
||||
'registrations',
|
||||
'tm_start', 'tm_end',
|
||||
'email',
|
||||
'registrationConfirms',
|
||||
'isVIP',
|
||||
'isAdmin',
|
||||
'withChecks'
|
||||
));
|
||||
}
|
||||
|
||||
public function actionView($id)
|
||||
{
|
||||
$model = User::find()->where(compact('id'))->one();
|
||||
|
||||
if (!$model) throw new NotFoundHttpException('Пользователь не найден');
|
||||
|
||||
if (\Yii::$app->request->isPost) {
|
||||
$checks = \Yii::$app->request->post('checks');
|
||||
|
||||
if ($checks !== null) {
|
||||
$model->checks += $checks;
|
||||
$model->save();
|
||||
\Yii::$app->session->setFlash('success', 'Проверки успешно начислены');
|
||||
return $this->refresh();
|
||||
}
|
||||
|
||||
if ($model->load(Yii::$app->request->post())) {
|
||||
$model->save();
|
||||
return $this->refresh();
|
||||
}
|
||||
}
|
||||
|
||||
$history = new ActiveDataProvider([
|
||||
'query' => SearchRequest::find()->where(['user_id' => $model->id]),
|
||||
'sort' => [
|
||||
'defaultOrder' => ['id' => SORT_DESC],
|
||||
'sortParam' => 'history-sort'
|
||||
],
|
||||
'pagination' => [
|
||||
'pageParam' => 'history-page',
|
||||
'pageSize' => 25
|
||||
]
|
||||
]);
|
||||
|
||||
$payments = new ActiveDataProvider([
|
||||
'query' => Payment::find()->where(['user_id' => $model->id]),
|
||||
'sort' => [
|
||||
'defaultOrder' => ['id' => SORT_DESC],
|
||||
'sortParam' => 'payments-sort'
|
||||
],
|
||||
'pagination' => [
|
||||
'pageParam' => 'payments-page',
|
||||
'pageSize' => 25
|
||||
]
|
||||
]);
|
||||
|
||||
$auth = new ActiveDataProvider([
|
||||
'query' => UserAuthLog::find()->where(['user_id' => $model->id]),
|
||||
'sort' => [
|
||||
'defaultOrder' => ['id' => SORT_DESC],
|
||||
'sortParam' => 'auth-sort'
|
||||
],
|
||||
'pagination' => [
|
||||
'pageParam' => 'auth-page',
|
||||
'pageSize' => 25
|
||||
]
|
||||
]);
|
||||
|
||||
return $this->render('view', compact('model', 'history', 'payments', 'auth'));
|
||||
}
|
||||
|
||||
public function actionSetVip($id)
|
||||
{
|
||||
$user = User::find()->where(compact('id'))->one();
|
||||
if (!$user) throw new NotFoundHttpException('Пользователь не найден');
|
||||
$user->is_vip = !$user->is_vip;
|
||||
if (!$user->save()) {
|
||||
print_r($user->getErrors()); die();
|
||||
}
|
||||
return $this->redirect(Yii::$app->getRequest()->getReferrer());
|
||||
}
|
||||
|
||||
public function actionSetAdmin($id)
|
||||
{
|
||||
$user = User::find()->where(compact('id'))->one();
|
||||
if (!$user) throw new NotFoundHttpException('Пользователь не найден');
|
||||
$user->is_admin = !$user->is_admin;
|
||||
$user->save();
|
||||
return $this->redirect(Yii::$app->getRequest()->getReferrer());
|
||||
}
|
||||
}
|
44
modules/admin/controllers/WalletsController.php
Normal file
44
modules/admin/controllers/WalletsController.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace app\modules\admin\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use app\models\Wallet;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
class WalletsController extends AdminController
|
||||
{
|
||||
public function actionIndex()
|
||||
{
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => Wallet::find()->orderBy(['type_id' => SORT_ASC, 'balance' => SORT_DESC])->where(["status" => 1])
|
||||
]);
|
||||
$dataProvider->pagination = false;
|
||||
return $this->render('index', compact('dataProvider'));
|
||||
}
|
||||
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new Wallet();
|
||||
|
||||
if (Yii::$app->getRequest()->getIsPost() && $model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
$this->redirect(['wallets/index']);
|
||||
}
|
||||
|
||||
return $this->render('create', compact('model'));
|
||||
}
|
||||
|
||||
public function actionView($id)
|
||||
{
|
||||
$model = Wallet::find()->where(compact('id'))->one();
|
||||
|
||||
if (!$model) throw new NotFoundHttpException('Кошелёк не найден.');
|
||||
|
||||
if (Yii::$app->getRequest()->getIsPost() && $model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
$this->redirect(['wallets/index']);
|
||||
}
|
||||
|
||||
return $this->render('view', compact('model'));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue