first commit
This commit is contained in:
286
controllers/ApiController.php
Normal file
286
controllers/ApiController.php
Normal file
@ -0,0 +1,286 @@
|
||||
<?php
|
||||
|
||||
namespace app\controllers;
|
||||
|
||||
use app\common\PaginationHelper;
|
||||
use app\models\Clue;
|
||||
use app\models\Oauth;
|
||||
use app\models\OauthAccount;
|
||||
use app\models\OauthAccountLocal;
|
||||
use app\models\UserAdvertiser;
|
||||
use app\models\Xiansuo;
|
||||
use http\Url;
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\web\Controller;
|
||||
use yii\web\Response;
|
||||
use yii\filters\VerbFilter;
|
||||
use app\models\LoginForm;
|
||||
use app\models\ContactForm;
|
||||
use yii\web\UrlManager;
|
||||
|
||||
class ApiController extends Controller
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
parent::beforeAction($action);
|
||||
|
||||
if (Yii::$app->user->isGuest) {
|
||||
return $this->redirect('/login');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function actions()
|
||||
{
|
||||
return [
|
||||
'error' => [
|
||||
'class' => 'yii\web\ErrorAction',
|
||||
],
|
||||
'captcha' => [
|
||||
'class' => 'yii\captcha\CaptchaAction',
|
||||
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function actionXiansuo()
|
||||
{
|
||||
$query = Clue::find()->filterWhere(
|
||||
['like', 'telephone', Yii::$app->request->get('phone')],
|
||||
)->andFilterWhere(
|
||||
['like', 'name', Yii::$app->request->get('name')]
|
||||
)->andFilterWhere(
|
||||
['like', 'note', Yii::$app->request->get('note')]
|
||||
)->andFilterWhere(
|
||||
['convert_status' => Yii::$app->request->get('convert_status')]
|
||||
)->andFilterWhere(
|
||||
['like', 'auto_city_name', Yii::$app->request->get('city')]
|
||||
)->andFilterWhere(
|
||||
[ '>=', 'create_time_detail', Yii::$app->request->get('date_start')]
|
||||
)->andFilterWhere(
|
||||
[ '<=', 'create_time_detail', Yii::$app->request->get('date_end')]
|
||||
)->orderBy('create_time_detail DESC');
|
||||
$provider = PaginationHelper::createDataProvider($query, limit: Yii::$app->request->get('limit'));
|
||||
|
||||
$covertStatus = function ($status) {
|
||||
if ($status == 1) {
|
||||
return '合法转化';
|
||||
} elseif ($status == 2) {
|
||||
return '待确认';
|
||||
} elseif ($status == 3) {
|
||||
return '营销预览';
|
||||
} elseif ($status == 4) {
|
||||
return '其他转化';
|
||||
}
|
||||
};
|
||||
|
||||
foreach ($provider->getModels() as &$item) {
|
||||
$item['convert_status'] = $covertStatus($item['convert_status']);
|
||||
$item['telephone'] = ($item['is_virtual'] == 1 ? '【虚拟号码】' : '') . $item['telephone'];
|
||||
}
|
||||
return $this->asJson([
|
||||
'count' => $provider->totalCount,
|
||||
'code' => 0,
|
||||
'data' => $provider->models,
|
||||
'message' => 'ok',
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionXiansuoPrivate()
|
||||
{
|
||||
$localAccountList = ArrayHelper::getColumn(UserAdvertiser::find()->where(['user_id' => Yii::$app->user->id, 'is_delete' => 0])->asArray()->all() ?: [], 'advertiser_id');
|
||||
|
||||
// var_dump($localAccountList);die;
|
||||
$query = Clue::find()->where([
|
||||
'local_account_id' => $localAccountList,
|
||||
'convert_status' => 1,
|
||||
'is_virtual' => 0
|
||||
])->andFilterWhere(
|
||||
['like', 'telephone', Yii::$app->request->get('phone')],
|
||||
)->andFilterWhere(
|
||||
['like', 'name', Yii::$app->request->get('name')]
|
||||
)->andFilterWhere(
|
||||
['like', 'note', Yii::$app->request->get('note')]
|
||||
)->andFilterWhere(
|
||||
['like', 'auto_city_name', Yii::$app->request->get('city')]
|
||||
)->andFilterWhere(
|
||||
[ '>=', 'create_time_detail', Yii::$app->request->get('date_start')]
|
||||
)->andFilterWhere(
|
||||
[ '<=', 'create_time_detail', Yii::$app->request->get('date_end')]
|
||||
)->orderBy('create_time_detail DESC');
|
||||
$x = clone $query;
|
||||
$provider = PaginationHelper::createDataProvider($query, limit: Yii::$app->request->get('limit'));
|
||||
|
||||
$covertStatus = function ($status) {
|
||||
if ($status == 1) {
|
||||
return '合法转化';
|
||||
} elseif ($status == 2) {
|
||||
return '待确认';
|
||||
} elseif ($status == 3) {
|
||||
return '营销预览';
|
||||
} elseif ($status == 4) {
|
||||
return '其他转化';
|
||||
}
|
||||
};
|
||||
|
||||
foreach ($provider->getModels() as &$item) {
|
||||
$item['convert_status'] = $covertStatus($item['convert_status']);
|
||||
}
|
||||
return $this->asJson([
|
||||
'count' => $provider->totalCount,
|
||||
'code' => 0,
|
||||
'data' => $provider->models,
|
||||
'message' => 'ok',
|
||||
'sql' => $x->createCommand()->getRawSql()
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @url api/oauth-manage
|
||||
* @return Response
|
||||
*/
|
||||
public function actionOauthManage()
|
||||
{
|
||||
$query = Oauth::find();
|
||||
$provider = PaginationHelper::createDataProvider($query);
|
||||
|
||||
foreach ($provider->getModels() as &$item) {
|
||||
$item['updated_at'] = date('Y-m-d H:i:s', $item['updated_at']);
|
||||
}
|
||||
return $this->asJson([
|
||||
'count' => $provider->totalCount,
|
||||
'code' => 0,
|
||||
'data' => $provider->models,
|
||||
'message' => 'ok',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @url api/oauth-manage-config
|
||||
*/
|
||||
public function actionOauthManageConfig()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @url api/init-oauth-admin
|
||||
*/
|
||||
public function actionInitOauthAdmin()
|
||||
{
|
||||
$uid = Yii::$app->request->post('uid');
|
||||
$tr = Yii::$app->db->beginTransaction();
|
||||
// Yii::$app->oceanengine->
|
||||
// 取出授权的account
|
||||
$oauthAdmin = Oauth::find()->where(['uid' => $uid])->one();
|
||||
$oauthAdmin->is_init = 1;
|
||||
$oauthAdmin->save();
|
||||
// $accounts = json_decode($oauthAdmin->advertiser_ids, true);
|
||||
|
||||
// 清理之前所有授权的账户
|
||||
OauthAccount::updateAll(['admin_uid' => $uid], ['is_delete' => 1]);
|
||||
$accountList = Yii::$app->oceanengine->getAdminChildAccount($uid);
|
||||
|
||||
// 本地推账户
|
||||
OauthAccountLocal::updateAll(['is_delete' => 1], ['admin_uid' => $uid]);
|
||||
|
||||
// 更新account 数据
|
||||
foreach ($accountList['data']['list'] ?? [] as $account) {
|
||||
$accountQuery = OauthAccount::find()->where(['account_id' => $account['account_id']])->one() ?: new OauthAccount();
|
||||
$accountQuery->is_delete = 0;
|
||||
$accountQuery->admin_uid = $uid;
|
||||
$accountQuery->account_name = $account['account_name'];
|
||||
$accountQuery->account_id = strval($account['account_id']);
|
||||
$accountQuery->save();
|
||||
|
||||
$accountLocalList = Yii::$app->oceanengine->getAccountLocal($uid);
|
||||
foreach ($accountLocalList['data']['list'] ?? [] as $accountLocal) {
|
||||
$query = OauthAccountLocal::find()->where(['advertiser_id' => $accountLocal['advertiser_id']])->one() ?: new OauthAccountLocal();
|
||||
$query->is_delete = 0;
|
||||
$query->admin_uid = $uid;
|
||||
$query->account_id = strval($account['account_id']);
|
||||
$query->advertiser_name = strval($accountLocal['advertiser_name']);
|
||||
$query->advertiser_id = strval($accountLocal['advertiser_id']);
|
||||
$query->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$tr->commit();
|
||||
return $this->asJson([
|
||||
'code' => 0,
|
||||
'data' => [],
|
||||
'message' => 'ok',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function actionUpdateClue()
|
||||
{
|
||||
$clueId = Yii::$app->request->post('clue_id');
|
||||
$note = Yii::$app->request->post('note');
|
||||
$name = Yii::$app->request->post('name');
|
||||
$convertStatus = Yii::$app->request->post('convert_status');
|
||||
|
||||
$query = Clue::find()->where(['clue_id' => $clueId])->one();
|
||||
$query->note = $note;
|
||||
$query->name = $name;
|
||||
if ($convertStatus) {
|
||||
$query->convert_status = $convertStatus;
|
||||
}
|
||||
|
||||
$query->save();
|
||||
|
||||
return $this->asJson([
|
||||
'code' => 0,
|
||||
'data' => [],
|
||||
'message' => 'ok',
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionOauthAccountLocalUpdate()
|
||||
{
|
||||
$advIds = Yii::$app->request->post('advertiser_ids');
|
||||
if (count($advIds) > 50) {
|
||||
return $this->asJson([
|
||||
'code' => -1,
|
||||
'data' => [],
|
||||
'message' => '最多只支持50个账户。',
|
||||
]);
|
||||
}
|
||||
|
||||
$isDelete = [];
|
||||
foreach ($advIds as $advVal) {
|
||||
list($id, $accountId) = explode('|', $advVal);
|
||||
if (!isset($isDelete[$accountId])) {
|
||||
OauthAccountLocal::updateAll(['is_active' => 0], ['account_id' => $accountId]);
|
||||
$isDelete[$accountId] = true;
|
||||
}
|
||||
|
||||
$query = OauthAccountLocal::find()->where(['id' => $id])->one();
|
||||
$query->is_active = 1;
|
||||
$query->save();
|
||||
}
|
||||
|
||||
return $this->asJson([
|
||||
'code' => 0,
|
||||
'data' => [],
|
||||
'message' => 'ok',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
11
controllers/BaseController.php
Normal file
11
controllers/BaseController.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace app\controllers;
|
||||
|
||||
|
||||
use yii\web\Response;
|
||||
|
||||
class BaseController extends \yii\web\Controller
|
||||
{
|
||||
|
||||
}
|
||||
316
controllers/SiteController.php
Normal file
316
controllers/SiteController.php
Normal file
@ -0,0 +1,316 @@
|
||||
<?php
|
||||
|
||||
namespace app\controllers;
|
||||
|
||||
use app\models\Clue;
|
||||
use app\models\Oauth;
|
||||
use app\models\OauthAccount;
|
||||
use app\models\OauthAccountLocal;
|
||||
use app\models\User;
|
||||
use app\models\UserAdvertiser;
|
||||
use http\Client;
|
||||
use Yii;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\web\Controller;
|
||||
use yii\web\Response;
|
||||
use yii\filters\VerbFilter;
|
||||
use app\models\LoginForm;
|
||||
use app\models\ContactForm;
|
||||
use yii\web\UrlManager;
|
||||
|
||||
class SiteController extends Controller
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'access' => [
|
||||
'class' => AccessControl::class,
|
||||
'only' => ['logout'],
|
||||
'rules' => [
|
||||
[
|
||||
'actions' => ['logout'],
|
||||
'allow' => true,
|
||||
'roles' => ['@'],
|
||||
],
|
||||
],
|
||||
],
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::class,
|
||||
'actions' => [
|
||||
'logout' => ['get'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function actions()
|
||||
{
|
||||
return [
|
||||
'error' => [
|
||||
'class' => 'yii\web\ErrorAction',
|
||||
],
|
||||
'captcha' => [
|
||||
'class' => 'yii\captcha\CaptchaAction',
|
||||
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function beforeAction($action)
|
||||
{
|
||||
parent::beforeAction($action);
|
||||
if ($action->id == 'login') {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Yii::$app->user->isGuest) {
|
||||
return $this->redirect('/login');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays homepage.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$this->layout = 'main_index';
|
||||
if (Yii::$app->user->isGuest) {
|
||||
return $this->redirect(['site/login']);
|
||||
}
|
||||
|
||||
return $this->render('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Login action.
|
||||
*
|
||||
* @return Response|string
|
||||
*/
|
||||
public function actionLogin()
|
||||
{
|
||||
if (!Yii::$app->user->isGuest) {
|
||||
return $this->goHome();
|
||||
}
|
||||
|
||||
$model = new LoginForm();
|
||||
if ($model->load(Yii::$app->request->post()) && $model->login()) {
|
||||
return $this->goBack();
|
||||
}
|
||||
|
||||
$model->password = '';
|
||||
return $this->render('login', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logout action.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function actionLogout()
|
||||
{
|
||||
Yii::$app->user->logout();
|
||||
|
||||
return $this->goHome();
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays contact page.
|
||||
*
|
||||
* @return Response|string
|
||||
*/
|
||||
public function actionContact()
|
||||
{
|
||||
$model = new ContactForm();
|
||||
if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) {
|
||||
Yii::$app->session->setFlash('contactFormSubmitted');
|
||||
|
||||
return $this->refresh();
|
||||
}
|
||||
return $this->render('contact', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays about page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function actionAbout()
|
||||
{
|
||||
return $this->render('about');
|
||||
}
|
||||
|
||||
public function actionConsole()
|
||||
{
|
||||
$this->layout = 'main_index';
|
||||
return $this->render('console');
|
||||
}
|
||||
|
||||
public function actionXiansuo()
|
||||
{
|
||||
$this->layout = 'main_index';
|
||||
return $this->render('xiansuo');
|
||||
}
|
||||
|
||||
public function actionUsers()
|
||||
{
|
||||
$this->layout = 'main_index';
|
||||
return $this->render('users');
|
||||
}
|
||||
|
||||
public function actionUsercreate()
|
||||
{
|
||||
$this->layout = 'main_index';
|
||||
return $this->render('user/create');
|
||||
}
|
||||
|
||||
public function actionUseredit()
|
||||
{
|
||||
$id = Yii::$app->request->get('id');
|
||||
$this->layout = 'main_index';
|
||||
$advertiser = UserAdvertiser::find()->where([
|
||||
'user_id' => $id,
|
||||
'is_delete' => 0
|
||||
])->indexBy('advertiser_id')->asArray()->all() ?: [];
|
||||
|
||||
$allLocalAccount = OauthAccountLocal::find()->asArray()->all();
|
||||
$advertiserList = [];
|
||||
foreach ($allLocalAccount as $item) {
|
||||
$advertiserList[] = [
|
||||
'name' => $item['advertiser_name'],
|
||||
'value' => $item['id'],
|
||||
'selected' => isset($advertiser[$item['advertiser_id']])
|
||||
];
|
||||
}
|
||||
|
||||
return $this->render('user/edit', [
|
||||
'advertiser' => $advertiserList,
|
||||
'user_id' => $id
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionUsereditpasswprd()
|
||||
{
|
||||
$id = Yii::$app->request->get('id');
|
||||
$query = User::find()->where(['id' => $id])->asArray()->one();
|
||||
$this->layout = 'main_index';
|
||||
return $this->render('user/edit-password', [
|
||||
'query' => $query
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionOauth()
|
||||
{
|
||||
// http://j56ff926.natappfree.cc/?app_id=1852484891502756&auth_code=e7eb2c40cc7ebe38e359b283701e9406c3f1a382&material_auth_status=1&scope=%5B10000000%2C200000032%2C2%2C3%2C4%2C5%2C300000006%2C300000040%2C300000041%2C130%2C14%2C112%2C300000052%2C110%2C120%2C122%2C123%2C124%2C300000029%2C300000000%2C100000005%5D&state=your_custom_params&uid=4121395460312552
|
||||
$request = Yii::$app->request->get();
|
||||
$appId = $request['app_id'];
|
||||
$authCode = $request['auth_code'];
|
||||
$materialAuthStatus = $request['material_auth_status'];
|
||||
$scope = $request['scope'];
|
||||
$uid = $request['uid'];
|
||||
|
||||
$oauth = Oauth::find()->where(['uid' => $uid])->one();
|
||||
if (!$oauth) {
|
||||
$oauth = new Oauth();
|
||||
}
|
||||
$oauth->app_id = $appId;
|
||||
$oauth->auth_code = $authCode;
|
||||
$oauth->material_auth_status = $materialAuthStatus;
|
||||
$oauth->scope = $scope;
|
||||
$oauth->uid = $uid;
|
||||
$oauth->save();
|
||||
|
||||
$curl = new \app\common\CurlApp();
|
||||
$curl->setMethod();
|
||||
$curl->setUrl('https://ad.oceanengine.com/open_api/oauth2/access_token/');
|
||||
$curl->setPostData([
|
||||
"app_id" => Yii::$app->params['app_id'],
|
||||
"secret" => Yii::$app->params['secret'],
|
||||
"auth_code" => $authCode
|
||||
]);
|
||||
|
||||
$res = json_decode($curl->exec(), true);
|
||||
|
||||
if ($res['code'] != '0') {
|
||||
throw new \Exception($res['message']);
|
||||
}
|
||||
|
||||
$oauth->advertiser_ids = json_encode($res['data']['advertiser_ids']);
|
||||
$oauth->access_token = $res['data']['access_token'];
|
||||
$oauth->refresh_token = $res['data']['refresh_token'];
|
||||
$oauth->save();
|
||||
|
||||
echo '授权成功, 请关闭此页面';die;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function actionOauthmanage()
|
||||
{
|
||||
// TODO: 管理员验证
|
||||
|
||||
$this->layout = 'main_index';
|
||||
return $this->render('oauth-manage');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @url oauthmanageconfig
|
||||
* @return string
|
||||
*/
|
||||
public function actionOauthmanageconfig()
|
||||
{
|
||||
// TODO: 管理员验证
|
||||
|
||||
$this->layout = 'main_index';
|
||||
$adminUid = Yii::$app->request->get('uid');
|
||||
|
||||
$arr = [];
|
||||
$accounts = OauthAccount::find()->where(['admin_uid' => $adminUid, 'is_delete' => 0])->all();
|
||||
foreach ($accounts as $account) {
|
||||
$arr[$account['account_name']] = [
|
||||
'id' => $account['account_id'],
|
||||
'items' => OauthAccountLocal::find()->where(['account_id' => $account['account_id'], 'is_delete' => 0])->asArray()->all()
|
||||
];
|
||||
}
|
||||
|
||||
return $this->render('oauth-manage-config', [
|
||||
'arr' => $arr
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function actionGenjin()
|
||||
{
|
||||
$clueId = Yii::$app->request->get('clue_id');
|
||||
$note = Clue::find()->where(['clue_id' => $clueId])->one();
|
||||
$this->layout = 'main_index';
|
||||
return $this->render('genjin', [
|
||||
'clueId' => $clueId,
|
||||
'note' => $note->note,
|
||||
'name' => $note->name,
|
||||
'covert_status' => $note->convert_status
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionPrivate()
|
||||
{
|
||||
$this->layout = 'main_index';
|
||||
return $this->render('xiansuo_private');
|
||||
}
|
||||
}
|
||||
344
controllers/api/UserController.php
Normal file
344
controllers/api/UserController.php
Normal file
@ -0,0 +1,344 @@
|
||||
<?php
|
||||
|
||||
namespace app\controllers\api;
|
||||
|
||||
use app\common\PaginationHelper;
|
||||
use app\models\Clue;
|
||||
use app\models\Oauth;
|
||||
use app\models\OauthAccount;
|
||||
use app\models\OauthAccountLocal;
|
||||
use app\models\User;
|
||||
use app\models\UserAdvertiser;
|
||||
use app\models\Xiansuo;
|
||||
use http\Url;
|
||||
use Yii;
|
||||
use yii\base\DynamicModel;
|
||||
use yii\data\Pagination;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\validators\Validator;
|
||||
use yii\web\Controller;
|
||||
use yii\web\Response;
|
||||
use yii\filters\VerbFilter;
|
||||
use app\models\LoginForm;
|
||||
use app\models\ContactForm;
|
||||
use yii\web\UrlManager;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
parent::beforeAction($action);
|
||||
|
||||
if (Yii::$app->user->isGuest) {
|
||||
return $this->redirect('/login');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function actions()
|
||||
{
|
||||
return [
|
||||
'error' => [
|
||||
'class' => 'yii\web\ErrorAction',
|
||||
],
|
||||
'captcha' => [
|
||||
'class' => 'yii\captcha\CaptchaAction',
|
||||
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
$query = User::find();
|
||||
$provider = PaginationHelper::createDataProvider($query);
|
||||
|
||||
$models = $provider->getModels();
|
||||
foreach ($models as &$item) {
|
||||
$item = $item->toArray();
|
||||
$item['created_at'] = date('Y-m-d H:i:s', $item['updated_at']);
|
||||
$localAccountList = ArrayHelper::getColumn(UserAdvertiser::find()->where(['is_delete' => 0, 'user_id' => $item])->asArray()->all(), 'advertiser_name');
|
||||
$item['advertiser_status'] = implode(',', $localAccountList);
|
||||
}
|
||||
|
||||
return $this->asJson([
|
||||
'count' => $provider->totalCount,
|
||||
'code' => 0,
|
||||
'data' => $models,
|
||||
'message' => 'ok',
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = DynamicModel::validateData(Yii::$app->request->post(), [
|
||||
// ===== 用户名 =====
|
||||
[['username'], 'required'],
|
||||
[['username'], 'trim'],
|
||||
[['username'], 'string', 'min' => 4, 'max' => 20],
|
||||
[['username'], 'match', 'pattern' => '/^[a-zA-Z0-9_]+$/', 'message' => '账号只能包含字母、数字和下划线'],
|
||||
[['username'], 'unique', 'targetClass' => User::class, 'message' => '该账号已存在'],
|
||||
|
||||
// ===== 密码 =====
|
||||
[['password'], 'required'],
|
||||
[['password'], 'string', 'min' => 6, 'max' => 32],
|
||||
[['password'], 'match',
|
||||
'pattern' => '/^(?=.*[A-Za-z])(?=.*\d).+$/',
|
||||
'message' => '密码必须包含字母和数字'
|
||||
],
|
||||
]);
|
||||
|
||||
if ($model->hasErrors()) {
|
||||
return $this->asJson([
|
||||
'code' => 1,
|
||||
'msg' => current($model->getFirstErrors())
|
||||
]);
|
||||
}
|
||||
$username = Yii::$app->request->post('username');
|
||||
$password = Yii::$app->request->post('password');
|
||||
$model = new User();
|
||||
$model->username = $username;
|
||||
$model->auth_key = \Yii::$app->security->generateRandomString();
|
||||
$model->password_hash = \Yii::$app->security->generatePasswordHash($password);
|
||||
$model->email = "{$username}.com";
|
||||
$model->role = 'USER';
|
||||
$model->created_at = time();
|
||||
$model->updated_at = time();
|
||||
$model->save();
|
||||
// var_dump($model->errors);
|
||||
return $this->asJson([
|
||||
'code' => 0,
|
||||
'message' => 'ok'
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionUpdate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function actionDelete()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function actionXiansuo()
|
||||
{
|
||||
$query = Clue::find()->filterWhere(
|
||||
['like', 'telephone', Yii::$app->request->get('phone')],
|
||||
)->andFilterWhere(
|
||||
['like', 'name', Yii::$app->request->get('name')]
|
||||
)->andFilterWhere(
|
||||
['like', 'note', Yii::$app->request->get('note')]
|
||||
)->orderBy('id DESC');
|
||||
$provider = PaginationHelper::createDataProvider($query, limit: Yii::$app->request->get('limit'));
|
||||
|
||||
return $this->asJson([
|
||||
'count' => $provider->totalCount,
|
||||
'code' => 0,
|
||||
'data' => $provider->models,
|
||||
'message' => 'ok',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @url api/oauth-manage
|
||||
* @return Response
|
||||
*/
|
||||
public function actionOauthManage()
|
||||
{
|
||||
$query = Oauth::find();
|
||||
$provider = PaginationHelper::createDataProvider($query);
|
||||
|
||||
foreach ($provider->getModels() as &$item) {
|
||||
$item['updated_at'] = date('Y-m-d H:i:s', $item['updated_at']);
|
||||
}
|
||||
return $this->asJson([
|
||||
'count' => $provider->totalCount,
|
||||
'code' => 0,
|
||||
'data' => $provider->models,
|
||||
'message' => 'ok',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @url api/oauth-manage-config
|
||||
*/
|
||||
public function actionOauthManageConfig()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @url api/init-oauth-admin
|
||||
*/
|
||||
public function actionInitOauthAdmin()
|
||||
{
|
||||
$uid = Yii::$app->request->post('uid');
|
||||
$tr = Yii::$app->db->beginTransaction();
|
||||
// Yii::$app->oceanengine->
|
||||
// 取出授权的account
|
||||
$oauthAdmin = Oauth::find()->where(['uid' => $uid])->one();
|
||||
$oauthAdmin->is_init = 1;
|
||||
$oauthAdmin->save();
|
||||
// $accounts = json_decode($oauthAdmin->advertiser_ids, true);
|
||||
|
||||
// 清理之前所有授权的账户
|
||||
OauthAccount::updateAll(['admin_uid' => $uid], ['is_delete' => 1]);
|
||||
$accountList = Yii::$app->oceanengine->getAdminChildAccount($uid);
|
||||
|
||||
// 本地推账户
|
||||
OauthAccountLocal::updateAll(['is_delete' => 1], ['admin_uid' => $uid]);
|
||||
|
||||
// 更新account 数据
|
||||
foreach ($accountList['data']['list'] ?? [] as $account) {
|
||||
$accountQuery = OauthAccount::find()->where(['account_id' => $account['account_id']])->one() ?: new OauthAccount();
|
||||
$accountQuery->is_delete = 0;
|
||||
$accountQuery->admin_uid = $uid;
|
||||
$accountQuery->account_name = $account['account_name'];
|
||||
$accountQuery->account_id = strval($account['account_id']);
|
||||
$accountQuery->save();
|
||||
|
||||
$accountLocalList = Yii::$app->oceanengine->getAccountLocal($uid);
|
||||
foreach ($accountLocalList['data']['list'] ?? [] as $accountLocal) {
|
||||
$query = OauthAccountLocal::find()->where(['advertiser_id' => $accountLocal['advertiser_id']])->one() ?: new OauthAccountLocal();
|
||||
$query->is_delete = 0;
|
||||
$query->admin_uid = $uid;
|
||||
$query->account_id = strval($account['account_id']);
|
||||
$query->advertiser_name = strval($accountLocal['advertiser_name']);
|
||||
$query->advertiser_id = strval($accountLocal['advertiser_id']);
|
||||
$query->save();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$tr->commit();
|
||||
return $this->asJson([
|
||||
'code' => 0,
|
||||
'data' => [],
|
||||
'message' => 'ok',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function actionUpdateClue()
|
||||
{
|
||||
$clueId = Yii::$app->request->post('clue_id');
|
||||
$note = Yii::$app->request->post('note');
|
||||
$name = Yii::$app->request->post('name');
|
||||
|
||||
$query = Clue::find()->where(['clue_id' => $clueId])->one();
|
||||
$query->note = $note;
|
||||
$query->name = $name;
|
||||
$query->save();
|
||||
|
||||
return $this->asJson([
|
||||
'code' => 0,
|
||||
'data' => [],
|
||||
'message' => 'ok',
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionOauthAccountLocalUpdate()
|
||||
{
|
||||
$advIds = Yii::$app->request->post('advertiser_ids');
|
||||
|
||||
$isDelete = [];
|
||||
foreach ($advIds as $advVal) {
|
||||
list($id, $accountId) = explode('|', $advVal);
|
||||
if (!isset($isDelete[$accountId])) {
|
||||
OauthAccountLocal::updateAll(['is_active' => 0], ['account_id' => $accountId]);
|
||||
$isDelete[$accountId] = true;
|
||||
}
|
||||
|
||||
$query = OauthAccountLocal::find()->where(['id' => $id])->one();
|
||||
$query->is_active = 1;
|
||||
$query->save();
|
||||
}
|
||||
|
||||
return $this->asJson([
|
||||
'code' => 0,
|
||||
'data' => [],
|
||||
'message' => 'ok',
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionResetPassword()
|
||||
{
|
||||
$password = Yii::$app->request->post('password');
|
||||
$id = Yii::$app->request->post('id');
|
||||
$model = User::find()->where(['id' => $id])->one();
|
||||
$model->auth_key = \Yii::$app->security->generateRandomString();
|
||||
$model->password_hash = \Yii::$app->security->generatePasswordHash($password);
|
||||
|
||||
return $this->asJson([
|
||||
'code' => 0,
|
||||
'data' => [],
|
||||
'message' => $model->save() ? '修改成功' : '修改失败',
|
||||
]);
|
||||
}
|
||||
|
||||
// public function actionEdit()
|
||||
// {
|
||||
// $password = Yii::$app->request->post('password');
|
||||
// $id = Yii::$app->request->post('id');
|
||||
// $model = User::find()->where(['id' => $id])->one();
|
||||
// $model->auth_key = \Yii::$app->security->generateRandomString();
|
||||
// $model->password_hash = \Yii::$app->security->generatePasswordHash($password);
|
||||
//
|
||||
// return $this->asJson([
|
||||
// 'code' => 0,
|
||||
// 'data' => [],
|
||||
// 'message' => $model->save() ? '修改成功' : '修改失败',
|
||||
// ]);
|
||||
// }
|
||||
|
||||
public function actionUpdateUser()
|
||||
{
|
||||
$userId = Yii::$app->request->post('user_id');
|
||||
$select = Yii::$app->request->post('select', '');
|
||||
UserAdvertiser::updateAll(['is_delete' => 1], ['user_id' => $userId]);
|
||||
|
||||
try {
|
||||
$select = explode(',', $select);
|
||||
} catch (\Throwable $exception) {
|
||||
$select = [];
|
||||
}
|
||||
|
||||
foreach ($select as $item) {
|
||||
$query = UserAdvertiser::find()->where(['user_id' => $userId, 'local_id' => $item])->one();
|
||||
if ($query) {
|
||||
$query->is_delete = 0;
|
||||
} else {
|
||||
$model = OauthAccountLocal::find()->where(['id' => $item])->one();
|
||||
$query = new UserAdvertiser();
|
||||
$query->advertiser_id = $model->advertiser_id;
|
||||
$query->user_id = $userId;
|
||||
$query->local_id = $userId;
|
||||
$query->advertiser_name = $model->advertiser_name;
|
||||
}
|
||||
|
||||
$query->save();
|
||||
}
|
||||
|
||||
return $this->asJson([
|
||||
'code' => 0,
|
||||
'data' => [],
|
||||
'message' => 'ok',
|
||||
]);
|
||||
}
|
||||
}
|
||||
26
controllers/api/v1/IndexController.php
Normal file
26
controllers/api/v1/IndexController.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace app\controllers\api\v1;
|
||||
|
||||
use app\controllers\BaseController;
|
||||
use app\models\Brand;
|
||||
use app\models\BrandRunway;
|
||||
use yii\web\Controller;
|
||||
|
||||
class IndexController extends BaseController
|
||||
{
|
||||
public function actionMain()
|
||||
{
|
||||
|
||||
$model = BrandRunway::find()->where(['is_deleted' => 0])->limit(2)->asArray()->all();
|
||||
|
||||
foreach ($model as &$item) {
|
||||
$item['cover'] = 'http://static.23cm.cn/11133613f321ed5eae0dc597f3451cae/37fdd980e520e8632f271730a30e88fc-h480';
|
||||
$item['brand_name'] = Brand::findOne($item['brand_id'])->name;
|
||||
}
|
||||
return $this->asJson([
|
||||
'code' => 0,
|
||||
'data' => $model
|
||||
]);
|
||||
}
|
||||
}
|
||||
39
controllers/api/v1/RunwayController.php
Normal file
39
controllers/api/v1/RunwayController.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace app\controllers\api\v1;
|
||||
|
||||
use app\common\ImageHelper;
|
||||
use app\components\serializers\Serializer;
|
||||
use app\controllers\BaseController;
|
||||
use app\models\Brand;
|
||||
use app\models\BrandRunway;
|
||||
use app\models\BrandRunwayImages;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\web\Controller;
|
||||
|
||||
class RunwayController extends BaseController
|
||||
{
|
||||
|
||||
public function actionView()
|
||||
{
|
||||
|
||||
$runwayId = \Yii::$app->request->get('id');
|
||||
|
||||
$runway = BrandRunway::find()->where(['id' => $runwayId])->asArray()->one();
|
||||
$runway['brand_name'] = Brand::findOne($runway['brand_id'])->name;
|
||||
$runwayImages = BrandRunwayImages::find()->where(['runway_id' => $runway['id']])->asArray()->all();
|
||||
|
||||
foreach ($runwayImages as &$image) {
|
||||
$image['s'] = ImageHelper::imageMogr2H480(\Yii::$app->params['cdnAddress'] . $image['name']);
|
||||
$image['xl'] = ImageHelper::imageMogr2H1080(\Yii::$app->params['cdnAddress'] . $image['name']);
|
||||
}
|
||||
|
||||
return $this->asJson([
|
||||
'code' => 0,
|
||||
'data' => [
|
||||
'info' => $runway,
|
||||
'images' => $runwayImages
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user