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',
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user