Commit 1c451300 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/explore' into develop

parents bf65c011 24dae7f9
......@@ -105,6 +105,7 @@ class ApplicationCategoryController extends BaseController
unset($params['name']);
$params['name'] = $name;
echo json_encode($params);exit;
$model->load($params, '');
$result = $model->add();
if (0 === $result['code']) {
......
......@@ -35,15 +35,25 @@ class ExploreAppCategory extends BaseActiveRecord
return array_merge(parent::attributes(), ['apps']);
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['name', 'sort', 'limit', 'style', 'platform_id'],
self:: SCENARIOS_UPDATE => ['name', 'sort', 'limit', 'style', 'platform_id'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function attributeLabels()
{
return [
'name' => '应用分类名称',
'sort' => '应用分类排序',
'limit' => '该分类下首页可显示的应用数量',
'style' => '应用分类展示样式'
];
}
public function getApplications()
{
return $this->hasMany(ExploreApp::className(), ['app_category_id' => 'id'])->select(['name', 'icon', 'app_url', 'slogan']);
......
......@@ -6,45 +6,137 @@ use Yii;
use yii\data\Pagination;
use wallet\base\BaseController;
use common\models\psources\ExploreApp;
use common\models\psources\CoinBannerItem;
use common\models\psources\ExploreAppCategory;
class ExploreController extends BaseController
class ExploreAppController extends BaseController
{
/**
* landing
* @return array
* @throws \yii\base\Exception
* @throws \yii\base\InvalidConfigException
*/
public function actionIndex()
public function actionCategory()
{
$msg = 'ok';
$code = 0;
$data = null;
$page = Yii::$app->request->get('page', 1);
$platform_id = Yii::$app->request->getPlatformId();
$query = ExploreAppCategory::find()->where(['platform_id' => $platform_id])->asArray();
$app_category_model = $query->offset(($page - 1) * 10)->limit(10)->asArray()->all();
foreach ($app_category_model as &$val) {
$name = json_decode($val['name'], true);
$val['name'] = $name['zh-CN'];
unset($val['platform_id']);
if (Yii::$app->request->isPost) {
$model = new ExploreAppCategory();
$model->setScenario(ExploreAppCategory::SCENARIOS_CREATE);
$params = Yii::$app->request->post();
$params['platform_id'] = $platform_id;
$lang = [
'zh-CN',
'en-US',
'ja'
];
$name_arr = $params['name'];
$name = [];
foreach ($name_arr as $key => $val) {
$name[$lang[$key]] = $val;
}
unset($params['name']);
$params['name'] = $name;
if ($model->load($params, '') && $model->save()) {
goto doEnd;
}
$msg = $model->errors;
$code = -1;
goto doEnd;
}
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => '10']);
$data = [
'list' => $app_category_model,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => 10,
'currentPage' => $page,
]
];
if (Yii::$app->request->isGet) {
$query = ExploreAppCategory::find()->where(['platform_id' => $platform_id])->asArray();
$app_category_model = $query->offset(($page - 1) * 10)->limit(10)->asArray()->all();
foreach ($app_category_model as &$val) {
$name = json_decode($val['name'], true);
$val['name'] = $name['zh-CN'];
unset($val['platform_id']);
}
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => '10']);
$data = [
'list' => $app_category_model,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => 10,
'currentPage' => $page,
]
];
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionCategory()
public function actionCategoryUpdate()
{
$msg = 'ok';
$code = 0;
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
if (Yii::$app->request->isGet) {
$id = Yii::$app->request->get('id');
$data = ExploreAppCategory::find()->select('id, name, sort, limit, style')->where(['platform_id' => $platform_id, 'id' => $id])->asArray()->one();
}
if (Yii::$app->request->isPut) {
$id = Yii::$app->request->get('id');
$model = ExploreAppCategory::findOne($id);
$model->setScenario(ExploreAppCategory::SCENARIOS_UPDATE);
$params = Yii::$app->request->post();
$params['platform_id'] = $platform_id;
$lang = [
'zh-CN',
'en-US',
'ja'
];
$name_arr = $params['name'];
$name = [];
foreach ($name_arr as $key => $val) {
$name[$lang[$key]] = $val;
}
unset($params['name']);
$params['name'] = $name;
if ($model->load($params, '') && $model->update()) {
goto doEnd;
}
$msg = $model->errors;
$code = -1;
goto doEnd;
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionCategoryRemove()
{
$msg = 'ok';
$code = 0;
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
if (Yii::$app->request->isDelete) {
$id = Yii::$app->request->get('id');
$model_app = ExploreApp::find()->where(['app_category_id' => (int)$id])->asArray()->all();
if (false != $model_app){
$msg = '请先删除该类别下的应用';
$code = -1;
goto doEnd;
}
$model = ExploreAppCategory::find()->where(['id' => $id, 'platform_id' => $platform_id])->one();
if (!$model->delete()){
$msg = '删除失败';
$code = -1;
goto doEnd;
}
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionApps()
{
$msg = 'ok';
$code = 0;
......@@ -80,36 +172,4 @@ class ExploreController extends BaseController
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionBanner()
{
$msg = 'ok';
$code = 0;
$platform_id = Yii::$app->request->getPlatformId();
$page = Yii::$app->request->get('page', 1);
if (false == $platform_id) {
$msg = '参数错误';
$code = -1;
$data = null;
goto doEnd;
}
$query = CoinBannerItem::find()
->select('id, banner_url, image_url')
->where(['platform_id' => $platform_id])
->asArray();
$banner_model = $query->offset(($page - 1) * 10)->limit(10)->asArray()->all();
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => '10']);
$data = [
'list' => $banner_model,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => 10,
'currentPage' => $page,
]
];
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
}
\ No newline at end of file
<?php
namespace wallet\controllers;
use Yii;
use yii\data\Pagination;
use wallet\base\BaseController;
use common\models\psources\CoinBannerItem;
class ExploreBannerController extends BaseController
{
public function actionBanner()
{
$msg = 'ok';
$code = 0;
$platform_id = Yii::$app->request->getPlatformId();
$page = Yii::$app->request->get('page', 1);
if (false == $platform_id) {
$msg = '参数错误';
$code = -1;
$data = null;
goto doEnd;
}
$query = CoinBannerItem::find()
->select('id, banner_url, image_url')
->where(['platform_id' => $platform_id])
->asArray();
$banner_model = $query->offset(($page - 1) * 10)->limit(10)->asArray()->all();
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => '10']);
$data = [
'list' => $banner_model,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => 10,
'currentPage' => $page,
]
];
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
}
\ No newline at end of file
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