Commit 9f204057 authored by shajiaiming's avatar shajiaiming

Merge branch 'master' into feature/platform_currency

parents eaf8a7c8 c2e3bf26
<?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
......@@ -20,6 +20,7 @@ use common\models\psources\CoinPlatformWithHold;
use common\models\psources\CoinRecommend;
use common\models\psources\MinerFee;
use Yii;
use yii\data\Pagination;
/**
* 币种信息管理控制器
......@@ -143,9 +144,9 @@ class CoinController extends BaseController
$coin_infos = Coin::getCoinInfoByIds($coin_ids, $select, 'id');
foreach ($coin_infos as $key => &$val) {
$nickname = json_decode($val['nickname'], true);
$val['nickname'] = $nickname[$this->lang];
$val['nickname'] = isset($nickname[$this->lang]) ? $nickname[$this->lang] : '';
$introduce = json_decode($val['introduce'], true);
$val['introduce'] = $introduce[$this->lang];
$val['introduce'] = isset($introduce[$this->lang]) ? $introduce[$this->lang] : '';
}
//获取行情信息
$coin_names = array_column($coin_infos, 'name');
......@@ -254,8 +255,8 @@ class CoinController extends BaseController
if (!isset($value['nickname']) || empty($value['nickname'])) continue;
$nickname = json_decode($value['nickname'], true);
$introduce = json_decode($value['introduce'], true);
$value['nickname'] = $nickname[$this->lang];
$value['introduce'] = $introduce[$this->lang];
$value['nickname'] = isset($nickname[$this->lang]) ? $nickname[$this->lang] : '';
$value['introduce'] = isset($introduce[$this->lang]) ? $introduce[$this->lang] : '';
$value['chain_quotation'] = $chain_quotation[$value['chain']] ?: null;
$value['chain_rmb'] = isset($value['chain_quotation']['rmb']) ? $value['chain_quotation']['rmb'] : 0;
$value['chain_usd'] = isset($value['chain_quotation']['usd']) ? $value['chain_quotation']['usd'] : 0;
......@@ -265,6 +266,66 @@ class CoinController extends BaseController
}
}
public function actionSearch()
{
$params = Yii::$app->request->post();
$chain = isset($params['chain']) ? $params['chain'] : '';
$keyword = isset($params['keyword']) ? $params['keyword'] : '';
$platform = isset($params['platform']) ? $params['platform'] : '';
$platform_id = isset($params['platform_id']) ? $params['platform_id'] : '';
$page = empty($params['page']) ? 1 : $params['page'];
$limit = empty($params['limit']) ? 10 : $params['limit'];
if (false == $platform_id) {
$msg = '参数错误';
$code = -1;
$data = null;
goto doEnd;
}
$query = Coin::find()
->select('id, sid, icon, name, optional_name, nickname, platform, chain, address as contract_address, treaty')
->where(['platform_id' => (int)$platform_id])
->orderBy('id');
if (false != $chain) {
$query->andWhere(['chain' => $chain]);
}
if (false != $platform) {
$query->andWhere(['platform' => $platform]);
}
if (false != $keyword) {
$query->andWhere(['or', ['like', 'address', $keyword], ['like', 'name', $keyword], ['like', 'nickname', $keyword]]);
}
$data = $query->offset(($page - 1) * $limit)->limit($limit)->asArray()->all();
$count = $query->count();
if (false != $data) {
$chains = array_unique(array_column($data, 'chain'));
$chain_quotation = [];
foreach ($chains as $key => $value) {
$chain_quotation[$value] = ExchangeBusiness::getquatation($value);
}
foreach ($data as $key => $value) {
$data[$key]['chain_quotation'] = $chain_quotation[$value['chain']] ?: null;
}
foreach ($data as $key => &$value) {
$nickname = json_decode($value['nickname'], true);
$value['nickname'] = $nickname[$this->lang];
$value['chain_rmb'] = isset($value['chain_quotation']['rmb']) ? $value['chain_quotation']['rmb'] : 0;
$value['chain_usd'] = isset($value['chain_quotation']['usd']) ? $value['chain_quotation']['usd'] : 0;
}
}
$code = 0;
doEnd :
return ['code' => $code, 'data' => $data, 'count' => $count];
}
/**
* 按照名称搜索币种
*
......
......@@ -30,7 +30,7 @@ class ExploreController extends BaseController
}
foreach ($app_category_model as $key => $val) {
unset($val->apps);
$val->name = $val->name[$this->lang];
$val->name = isset($val->name[$this->lang]) ? $val->name[$this->lang] : '';
$apps_model = ExploreApp::find()->select('id, name, icon, type, app_url, slogan')
->where(['app_category_id' => (int)$val->id, 'status' => ExploreApp::STATUS_ON])
->orderBy('sort')
......@@ -41,7 +41,7 @@ class ExploreController extends BaseController
continue;
}
foreach ($apps_model as &$app) {
$app->name = $app->name[$this->lang];
$app->name = isset($app->name[$this->lang]) ? $app->name[$this->lang] : '';
}
$val->apps = $apps_model;
unset($val->sort);
......@@ -79,9 +79,9 @@ class ExploreController extends BaseController
}
foreach ($app_category_model as &$val) {
foreach ($val->applications as $app) {
$app->name = $app->name[$this->lang];
$app->name = isset($app->name[$this->lang]) ? $app->name[$this->lang] : '';
}
$val->name = $val->name[$this->lang];
$val->name = isset($val->name[$this->lang]) ? $val->name[$this->lang] : '';
$val->apps = $val->applications;
unset($val->id);
unset($val->sort);
......@@ -124,7 +124,7 @@ class ExploreController extends BaseController
goto doEnd;
}
foreach ($apps_model as &$app) {
$app->name = $app->name[$this->lang];
$app->name = isset($app->name[$this->lang]) ? $app->name[$this->lang] : '';
}
$data = $apps_model;
$msg = 'success';
......
......@@ -92,15 +92,11 @@ class ApplicationCategoryController extends BaseController
$fields = ['id', 'name', 'sort', 'icon', 'banner', 'banner_url'];
$params = $this->initParams(Yii::$app->request->post(), $fields);
$params['platform_id'] = Yii::$app->user->identity->platform_id;
$lang = [
'zh-CN',
'en-US',
'ja'
];
$name_arr = $params['name'];
$name = [];
foreach ($name_arr as $key => $val) {
$name[$lang[$key]] = $val;
foreach (Yii::$app->params['lang'] as $key => $val) {
$name[$val] = isset($name_arr[$val]) ? $name_arr[$val] : '';
}
unset($params['name']);
......@@ -124,15 +120,10 @@ class ApplicationCategoryController extends BaseController
$category = CoinApplicationCategory::getCategoryById($params['id']);
$params['platform_id'] = $category->platform_id;
$application_category->setScenario(CoinApplicationCategoryForm::SCENARIO_EDIT);
$lang = [
'zh-CN',
'en-US',
'ja'
];
$name_arr = $params['name'];
$name = [];
foreach ($name_arr as $key => $val) {
$name[$lang[$key]] = $val;
foreach (Yii::$app->params['lang'] as $key => $val) {
$name[$val] = isset($name_arr[$val]) ? $name_arr[$val] : '';
}
unset($params['name']);
......@@ -150,6 +141,7 @@ class ApplicationCategoryController extends BaseController
$coin['name_ja'] = isset($name_arr['ja']) ? $name_arr['ja'] : '';
$coin['name_zh'] = isset($name_arr['zh-CN']) ? $name_arr['zh-CN'] : '';
$coin['name_en'] = isset($name_arr['en-US']) ? $name_arr['en-US'] : '';
$coin['name_ko'] = isset($name_arr['ko']) ? $name_arr['ko'] : '';
$this->layout = false;
return $this->render('edit', ['model' => $coin]);
}
......
......@@ -65,15 +65,10 @@ class ApplicationController extends BaseController
$category_id = Yii::$app->request->get('category_id');
$fields = ['category_id', 'h5_icon', 'official_url', 'introduce_image', 'show_width', 'show_height', 'open_type', 'open_type_app', 'platform_type', 'name', 'sort', 'icon', 'type', 'native_url', 'native_login_url', 'h5_url', 'android_url', 'ios_url', 'app_store_url', 'advertise', 'description', 'redirect_type', 'platform_id'];
$data = Yii::$app->request->post();
$lang = [
'zh-CN',
'en-US',
'ja'
];
$name_arr = $data['name'];
$name = [];
foreach ($name_arr as $key => $val){
$name[$lang[$key]] = $val;
foreach (Yii::$app->params['lang'] as $key => $val) {
$name[$val] = isset($name_arr[$val]) ? $name_arr[$val] : '';
}
unset($data['name']);
$data['name'] = $name;
......@@ -104,21 +99,15 @@ class ApplicationController extends BaseController
$fields = ['category_id', 'id', 'h5_icon', 'official_url', 'introduce_image', 'show_width', 'show_height', 'open_type', 'open_type_app', 'platform_type', 'name', 'sort', 'icon', 'type', 'native_url', 'native_login_url', 'h5_url', 'android_url', 'ios_url', 'app_store_url', 'advertise', 'description', 'redirect_type', 'platform_id'];
$data = Yii::$app->request->post();
$lang = [
'zh-CN',
'en-US',
'ja'
];
$name_arr = $data['name'];
$name = [];
foreach ($name_arr as $key => $val){
$name[$lang[$key]] = $val;
foreach (Yii::$app->params['lang'] as $key => $val) {
$name[$val] = isset($name_arr[$val]) ? $name_arr[$val] : '';
}
unset($data['name']);
$data['name'] = $name;
$data['open_type_app'] = (0 == $data['open_type_app']) ? 1 : $data['open_type_app'];
#var_dump($data);exit;
$params = array_merge($data, ['platform_id' => Yii::$app->user->identity->platform_id]);
$params = $this->initParams($params, $fields);
$coin_applicateion_form = new CoinApplicationForm();
......@@ -165,9 +154,10 @@ class ApplicationController extends BaseController
#echo json_encode($applicate);exit;
$applicate['sort'] = $app_cate->sort;
$name_arr = json_decode($applicate['name'], true);
$applicate['name_ja'] = $name_arr['ja'];
$applicate['name_en'] = $name_arr['en-US'];
$applicate['name_zh'] = $name_arr['zh-CN'];
$applicate['name_ja'] = isset($name_arr['ja']) ? $name_arr['ja'] : '';
$applicate['name_en'] = isset($name_arr['en-US']) ? $name_arr['en-US'] : '';
$applicate['name_zh'] = isset($name_arr['zh-CN']) ? $name_arr['zh-CN'] : '';
$applicate['name_ko'] = isset($name_arr['ko']) ? $name_arr['ko'] : '';
$this->layout = false;
return $this->render('edit', ['item' => $applicate, 'category_id' => $category_id]);
}
......
......@@ -95,22 +95,18 @@ class CoinController extends BaseController
$data['name'] = strtoupper(trim($data['name']));
$data['platform'] = $data['platform'];
$data['chain'] = strtoupper($data['chain']);
$lang = [
'zh-CN',
'en-US',
'ja',
'ko'
];
$nickname_arr = $data['nickname'];
$introduce_arr = $data['introduce'];
$nickname = [];
$introduce = [];
foreach ($nickname_arr as $key => $val) {
$nickname[$lang[$key]] = trim($val);
foreach (Yii::$app->params['lang'] as $key => $val) {
$nickname[$val] = isset($nickname_arr[$val]) ? $nickname_arr[$val] : '';
}
foreach ($introduce_arr as $key => $val) {
$introduce[$lang[$key]] = $val;
foreach (Yii::$app->params['lang'] as $key => $val) {
$introduce[$val] = isset($introduce_arr[$val]) ? $introduce_arr[$val] : '';
}
unset($data['nickname']);
unset($data['introduce']);
$data['nickname'] = $nickname;
......@@ -168,21 +164,15 @@ class CoinController extends BaseController
$can = true;
}
if ($can) {
$lang = [
'zh-CN',
'en-US',
'ja',
'ko'
];
$nickname_arr = $data['nickname'];
$introduce_arr = $data['introduce'];
$nickname = [];
$introduce = [];
foreach ($nickname_arr as $key => $val) {
$nickname[$lang[$key]] = $val;
foreach (Yii::$app->params['lang'] as $key => $val) {
$nickname[$val] = isset($nickname_arr[$val]) ? $nickname_arr[$val] : '';
}
foreach ($introduce_arr as $key => $val) {
$introduce[$lang[$key]] = $val;
foreach (Yii::$app->params['lang'] as $key => $val) {
$introduce[$val] = isset($introduce_arr[$val]) ? $introduce_arr[$val] : '';
}
unset($data['nickname']);
$data['nickname'] = $nickname;
......
......@@ -21,7 +21,7 @@
<div class="layui-inline">
<label class="layui-form-label">中文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="name[]" required lay-verify="required" placeholder=""
<input class="layui-input" name="name[zh-CN]" required lay-verify="required" placeholder=""
autocomplete="off" value=""
class="layui-input">
</div>
......@@ -29,13 +29,19 @@
<div class="layui-inline">
<label class="layui-form-label">英文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="name[]" value="">
<input class="layui-input" name="name[en-US]" value="">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">日文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="name[]" value="">
<input class="layui-input" name="name[ja]" value="">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">韩文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="name[ko]" value="">
</div>
</div>
<div class="layui-form-item layui-form-text">
......
......@@ -21,19 +21,25 @@
<div class="layui-inline">
<label class="layui-form-label">中文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="name[]" value="<?= $model['name_zh'] ?>">
<input class="layui-input" name="name[zh-CN]" value="<?= $model['name_zh'] ?>">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">英文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="name[]" value="<?= $model['name_en'] ?>">
<input class="layui-input" name="name[en-US]" value="<?= $model['name_en'] ?>">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">日文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="name[]" value="<?= $model['name_ja'] ?>">
<input class="layui-input" name="name[ja]" value="<?= $model['name_ja'] ?>">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">韩文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="name[ko]" value="<?= $model['name_ko'] ?>">
</div>
</div>
<div class="layui-form-item layui-form-text">
......
......@@ -48,19 +48,25 @@
<div class="layui-form-item">
<label class="layui-form-label">中文名</label>
<div class="layui-input-block">
<input class="layui-input" name="name[]" value="" lay-verify="required">
<input class="layui-input" name="name[zh-CN]" value="" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">英文名</label>
<div class="layui-input-block">
<input class="layui-input" name="name[]" value="" lay-verify="required">
<input class="layui-input" name="name[en-US]" value="" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">日文名</label>
<div class="layui-input-block">
<input class="layui-input" name="name[]" value="" lay-verify="required">
<input class="layui-input" name="name[ja]" value="" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">韩文名</label>
<div class="layui-input-block">
<input class="layui-input" name="name[ko]" value="" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
......
......@@ -51,19 +51,25 @@
<div class="layui-form-item">
<label class="layui-form-label">中文名</label>
<div class="layui-input-block">
<input class="layui-input" name="name[]" value="<?= $item['name_zh'] ?>" lay-verify="required">
<input class="layui-input" name="name[zh-CN]" value="<?= $item['name_zh'] ?>" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">英文名</label>
<div class="layui-input-block">
<input class="layui-input" name="name[]" value="<?= $item['name_en'] ?>" lay-verify="required">
<input class="layui-input" name="name[en-US]" value="<?= $item['name_en'] ?>" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">日文名</label>
<div class="layui-input-block">
<input class="layui-input" name="name[]" value="<?= $item['name_ja'] ?>" lay-verify="required">
<input class="layui-input" name="name[ja]" value="<?= $item['name_ja'] ?>" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">韩文名</label>
<div class="layui-input-block">
<input class="layui-input" name="name[ko]" value="<?= $item['name_ko'] ?>" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
......
......@@ -34,19 +34,25 @@
<div class="layui-inline">
<label class="layui-form-label">中文名</label>
<div class="layui-input-block" style="width: 190px">
<input class="layui-input" name="nickname[]" value="<?= $model->nickname['zh-CN'] ?>">
<input class="layui-input" name="nickname[zh-CN]" value="<?= $model->nickname['zh-CN'] ?>">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">英文名</label>
<div class="layui-input-block" style="width: 190px">
<input class="layui-input" name="nickname[]" value="<?= $model->nickname['en-US'] ?>">
<input class="layui-input" name="nickname[en-US]" value="<?= $model->nickname['en-US'] ?>">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">日文名</label>
<div class="layui-input-block" style="width: 190px">
<input class="layui-input" name="nickname[]" value="<?= $model->nickname['ja'] ?>">
<input class="layui-input" name="nickname[ja]" value="<?= $model->nickname['ja'] ?>">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">韩文名</label>
<div class="layui-input-block" style="width: 190px">
<input class="layui-input" name="nickname[ko]" value="<?= $model->nickname['ko'] ?>">
</div>
</div>
<div class="layui-form-item">
......@@ -135,19 +141,25 @@
<div class="layui-form-item">
<label class="layui-form-label">中文介绍</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="introduce[]"><?= $model->introduce['zh-CN'] ?></textarea>
<textarea class="layui-textarea" name="introduce[zh-CN]"><?= $model->introduce['zh-CN'] ?></textarea>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">英文介绍</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="introduce[]"><?= $model->introduce['en-US'] ?></textarea>
<textarea class="layui-textarea" name="introduce[en-US]"><?= $model->introduce['en-US'] ?></textarea>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">日文介绍</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="introduce[]"><?= $model->introduce['ja'] ?></textarea>
<textarea class="layui-textarea" name="introduce[ja]"><?= $model->introduce['ja'] ?></textarea>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">韩文介绍</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="introduce[ko]"><?= $model->introduce['ko'] ?></textarea>
</div>
</div>
<div class="layui-inline">
......
......@@ -34,19 +34,25 @@
<div class="layui-inline">
<label class="layui-form-label">中文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="nickname[]" value="<?= $model->nickname['zh-CN'] ?>">
<input class="layui-input" name="nickname[zh-CN]" value="<?= isset($model->nickname['zh-CN']) ? $model->nickname['zh-CN'] : '' ?>">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">英文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="nickname[]" value="<?= $model->nickname['en-US'] ?>">
<input class="layui-input" name="nickname[en-US]" value="<?= isset($model->nickname['en-US']) ? $model->nickname['en-US'] : '' ?>">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">日文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="nickname[]" value="<?= $model->nickname['ja'] ?>">
<input class="layui-input" name="nickname[ja]" value="<?= isset($model->nickname['ja']) ? $model->nickname['ja'] : '' ?>">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">韩文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="nickname[ko]" value="<?= isset($model->nickname['ko']) ? $model->nickname['ko'] : '' ?>">
</div>
</div>
<div class="layui-form-item">
......@@ -141,19 +147,25 @@
<div class="layui-form-item">
<label class="layui-form-label">中文介绍</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="introduce[]"><?= $model->introduce['zh-CN'] ?></textarea>
<textarea class="layui-textarea" name="introduce[zh-CN]"><?= isset($model->introduce['zh-CN']) ? $model->introduce['zh-CN'] : '' ?></textarea>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">英文介绍</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="introduce[]"><?= $model->introduce['en-US'] ?></textarea>
<textarea class="layui-textarea" name="introduce[en-US]"><?= isset($model->introduce['en-US']) ? $model->introduce['en-US'] : '' ?></textarea>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">日文介绍</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="introduce[]"><?= $model->introduce['ja'] ?></textarea>
<textarea class="layui-textarea" name="introduce[ja]"><?= isset($model->introduce['ja']) ? $model->introduce['ja'] : '' ?></textarea>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">韩文介绍</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="introduce[ko]"><?= isset($model->introduce['ko']) ? $model->introduce['ko'] : '' ?></textarea>
</div>
</div>
<div class="layui-inline">
......
......@@ -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
......@@ -12,16 +12,11 @@ use common\service\trusteeship\TrusteeShipService;
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