Commit 175ce151 authored by shajiaiming's avatar shajiaiming

Merge branch 'master' into feature/optimize

parents f6ae9cf5 55c7d3ff
<?php
namespace api\controllers;
use Yii;
use api\base\BaseController;
use common\models\psources\ExploreApp;
use common\models\psources\CoinBannerItem;
use common\models\psources\ExploreAppCategory;
class BannerController extends BaseController
{
public function actionIndex()
{
$header = Yii::$app->request->headers;
$type = Yii::$app->request->get('type', 0);
$platform_id = $header['FZM-PLATFORM-ID'] ?? null;
$data = null;
if (false == $platform_id || false == $type) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
$model = CoinBannerItem::find()
->select('banner_url, image_url, title, sort')
->where(['platform_id' => $platform_id, 'type' => $type, 'status' => CoinBannerItem::STATUS_ON])
->orderBy('sort')
->asArray()
->all();
$data = $model;
$msg = 'success';
$code = 0;
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ class BaseRequest extends Request
{
private $user_id = 0;
private $platform_id = 0;
private $group = '';
public function getUserId()
{
......@@ -34,4 +35,14 @@ class BaseRequest extends Request
{
$this->platform_id = $value;
}
public function getGroup()
{
return $this->group;
}
public function setGroup($value)
{
$this->group = $value;
}
}
\ No newline at end of file
......@@ -36,8 +36,10 @@ class LoginStatusAuthInterceptor extends ActionFilter
$code = '40002';
goto doEnd;
}
$group = $user->group;
$user_id = $user->uid;
$platform_id = $user->platform_id;
Yii::$app->request->setGroup($group);
Yii::$app->request->setUserId($user_id);
Yii::$app->request->setPlatformId($platform_id);
return true;
......
......@@ -34,8 +34,10 @@ class UserAuthInterceptor extends ActionFilter
$msg = 'user auth error';
goto doEnd;
}
$group = $user->group;
$user_id = $user->uid;
$platform_id = $user->platform_id;
Yii::$app->request->setGroup($group);
Yii::$app->request->setUserId($user_id);
Yii::$app->request->setPlatformId($platform_id);
$user_auth = Yii::$app->params['user_auth']['user_auth'];
......
......@@ -13,6 +13,9 @@ use Yii;
class CoinBannerItem extends BaseActiveRecord
{
const STATUS_ON = 1; //激活
const STATUS_OFF = 0; //未激活
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
......@@ -30,18 +33,32 @@ class CoinBannerItem extends BaseActiveRecord
public function rules()
{
return [
[['image_url', 'platform_id'], 'required'],
[['image_url', 'platform_id', 'sort', 'status', 'type'], 'required'],
[['platform_id', 'sort', 'type', 'status', 'type'], 'integer'],
['banner_url', 'default', 'value' => '#'],
[['banner_url', 'title'], 'safe'],
[['image_url'], 'url']
[['image_url'], 'url'],
];
}
public function attributeLabels()
{
return [
'banner_url' => 'banner跳转链接',
'image_url' => 'banner图片链接',
'title' => 'banner标题',
'platform_id' => '所属平台',
'sort' => 'banner排序',
'status' => 'banner状态',
'type' => 'banner类型'
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['image_url', 'banner_url', 'title', 'platform_id'],
self:: SCENARIOS_UPDATE => ['id', 'image_url', 'banner_url', 'title', 'platform_id'],
self:: SCENARIOS_CREATE => ['banner_url', 'image_url', 'title', 'platform_id', 'sort', 'status', 'type'],
self:: SCENARIOS_UPDATE => ['id', 'banner_url', 'image_url', 'title', 'platform_id', 'sort', 'status', 'type'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
......
<?php
namespace wallet\controllers;
use Yii;
use yii\data\Pagination;
use wallet\base\BaseController;
use common\models\psources\CoinBannerItem;
class BannerController extends BaseController
{
public function actionType()
{
$data = array_unique(Yii::$app->params['banner_type']);
return ['code' => 0, 'msg' => 'success', 'data' => $data];
}
public function actionIndex()
{
$msg = 'ok';
$code = 0;
$data = null;
if (Yii::$app->request->isGet) {
$type = Yii::$app->request->get('type', 0);
$page = Yii::$app->request->get('page', 1);
$size = Yii::$app->request->get('size', 10);
$platform_id = Yii::$app->request->get('platform_id', 0);
if (false == $platform_id) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
$query = CoinBannerItem::find()->where(['platform_id' => $platform_id])->orderBy('sort');
if (false != $type) {
$query->andWhere(['type' => $type]);
}
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $size]);
$models = $query->offset($pages->offset)
->limit($pages->limit)
->all();
$data = [
'list' => $models,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => $size,
'currentPage' => (int)$page,
]
];
}
if (Yii::$app->request->isPost) {
$model = new CoinBannerItem();
$model->setScenario(CoinBannerItem::SCENARIOS_CREATE);
$model->load(Yii::$app->request->post(), '');
if (!$model->validate()) {
$msg = $model->errors;
$code = -1;
goto doEnd;
}
$model->save();
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionUpdate()
{
$msg = 'ok';
$code = 0;
$data = null;
$group = Yii::$app->request->getGroup();
$platform_id = Yii::$app->request->getPlatformId();
if (Yii::$app->request->isGet) {
$id = Yii::$app->request->get('id');
if ('administrator' == $group) {
$data = CoinBannerItem::find()->where(['id' => $id])->asArray()->one();
} else {
$data = CoinBannerItem::find()->where(['platform_id' => $platform_id, 'id' => $id])->asArray()->one();
}
goto doEnd;
}
if (Yii::$app->request->isPut) {
$params = Yii::$app->request->post();
$id = isset($params['id']) ? $params['id'] : null;
if (false == $id) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
$model = CoinBannerItem::findOne($id);
if ('administrator' != $group && $model->platform_id != $platform_id) {
$msg = '无权修改';
$code = -1;
goto doEnd;
}
$model->setScenario(CoinBannerItem::SCENARIOS_UPDATE);
$model->load(array_merge(Yii::$app->request->post(), ['platform_id' => $model->platform_id]), '');
if (!$model->validate()) {
$msg = $model->errors;
$code = -1;
goto doEnd;
}
$model->save();
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionRemove()
{
$msg = 'ok';
$code = 0;
$data = null;
$group = Yii::$app->request->getGroup();
$platform_id = Yii::$app->request->getPlatformId();
$id = Yii::$app->request->get('id');
if (false == $id) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
if (Yii::$app->request->isDelete) {
$model = CoinBannerItem::findOne($id);
if ('administrator' != $group && $model->platform_id != $platform_id) {
$msg = '无权删除';
$code = -1;
goto doEnd;
}
$model->delete();
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
}
\ No newline at end of file
......@@ -10,16 +10,11 @@ use common\models\psources\CoinPlatform;
class WalletController extends BaseController
{
/**
* landing
* @return array
* @throws \yii\base\Exception
* @throws \yii\base\InvalidConfigException
*/
public function actionList()
{
$group = Yii::$app->request->getGroup();
$platform_id = Yii::$app->request->getPlatformId();
if (1 === $platform_id) {
if ('administrator' == $group) {
$platforms = CoinPlatform::find()->select('id, name')->asArray()->all();
} else {
$platforms = CoinPlatform::find()->select('id, name')->where(['id' => $platform_id])->asArray()->all();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment