Commit 51683f82 authored by shajiaiming's avatar shajiaiming

test

parent 4482b5d7
......@@ -24,11 +24,17 @@ class ApplicationController extends BaseController
*/
public function actionIndex()
{
$recommendData = ApplicationBusiness::getRecommendList();
$condition = [];
$platform_id = Yii::$app->request->post('platform_id');
if(!empty($platform_id)){
$condition = ['platform_id' => $platform_id];
}
$recommendData = ApplicationBusiness::getRecommendList($condition);
$data['recommend'] =$recommendData;
$cate_app_data = ApplicationBusiness::getCategoryAppList(5);
$cate_app_data = ApplicationBusiness::getCategoryAppList($condition);
$data['cate_app_data'] = $cate_app_data;
$data['banner'] = ApplicationBusiness::getBannerList();
$data['banner'] = ApplicationBusiness::getBannerList($condition);
$result['code'] = 0;
$result['data'] = $data;
return $result;
......
......@@ -69,7 +69,9 @@ class AdminController extends BaseController
$model->generateAuthKey();
$model->setPassword($data['password']);
$model->platform_id = Yii::$app->user->identity->platform_id;
$auth = Yii::$app->authManager;
$roleTemp = $auth->getRole($role);
$model->platform_id = empty($roleTemp->data) ? Yii::$app->user->identity->platform_id : $roleTemp->data;
/* 保存用户数据到数据库 */
if ($model->save()) {
$auth = Yii::$app->authManager;
......
......@@ -39,6 +39,7 @@ class ApplicateRankController extends BaseController
$rank = new CoinApplicateRank();
$rank->relate_id = $applicate_id;
$rank->type = $type;
$rank->platform_id = Yii::$app->user->identity->platform_id;
$rank->save();
return ['code' => 0, 'msg' => '添加成功'];
}else{
......@@ -76,14 +77,19 @@ class ApplicateRankController extends BaseController
*/
public function actionIndex()
{
$user_platform_id = Yii::$app->user->identity->platform_id;
$condition = [];
if(1 !== $user_platform_id){
$condition = ['platform_id' => $user_platform_id];
}
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$type = $request->get('type', '');
$data = CoinApplicateRank::getApplicateList($type);
$data = CoinApplicateRank::getApplicateList($type, $user_platform_id);
return ['data' => $data, 'code' => 0];
}
$items = CoinApplication::getAllApplicate();
$items = CoinApplication::getAllApplicate($condition);
return $this->render('index',['items' => $items]);
}
......
......@@ -23,6 +23,7 @@ class ApplicateRecommendController extends BaseController
*/
public function actionAdd()
{
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
......@@ -40,14 +41,17 @@ class ApplicateRecommendController extends BaseController
if($type == 1){ //分类
$applicate_category = CoinApplicationCategory::getCategoryById($id);
$name = $applicate_category->name;
$user_platform_id = $applicate_category->platform_id;
}else{ //应用
$applicate = CoinApplication::getApplicate($id);
$name = $applicate->name;
$user_platform_id = $applicate->platform_id;
}
$recommend = new CoinApplicateRecommend();
$recommend->relate_id = $id;
$recommend->type = $type;
$recommend->name = $name;
$recommend->platform_id = $user_platform_id;
$recommend->save();
return ['code' => 0,'msg' => '首页推荐添加成功'];
}else{
......@@ -85,12 +89,20 @@ class ApplicateRecommendController extends BaseController
*/
public function actionIndex()
{
$user_platform_id = Yii::$app->user->identity->platform_id;
if(Yii::$app->request->isAjax){
Yii::$app->response->format = 'json';
$data = CoinApplicateRecommend::find()->orderBy('sort asc')->asArray()->all();
$condition = [];
if(1 !== $user_platform_id){
$condition = ['platform_id' => $user_platform_id];
}
$data = CoinApplicateRecommend::find()->joinWith('platform')->where($condition)->orderBy('sort asc')->asArray()->all();
$icon_Items = array_column($data,'icon');
$icon_Infos = CoinImage::getItemsByIds($icon_Items);
foreach ($data as &$value){
$value['coin_name'] = isset($value['platform']['name']) ? $value['platform']['name'] : '';
if($value['icon']){
$value['icon_url'] = $icon_Infos[$value['icon']]['base_url'].$icon_Infos[$value['icon']]['file_url'];
}else{
......
......@@ -22,6 +22,8 @@ class ApplicationCategoryController extends BaseController
*/
public function actionIndex()
{
$user_platform_id = Yii::$app->user->identity->platform_id;
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
......@@ -29,10 +31,18 @@ class ApplicationCategoryController extends BaseController
$limit = $request->get('limit', 10);
$name = $request->get('category_name', '');
$where = [];
if(1 !== $user_platform_id){
$where[] = ['platform_id' => $user_platform_id];
}
if($name){
$where[] = ['name' => $name];
}
$data = CoinApplicationCategory::getList($page, $limit, $where);
foreach ($data['data'] as $key => &$val){
$val['coin_name'] = isset($val['platform']['name']) ? $val['platform']['name'] : '';
}
return $data;
}
return $this->render('index');
......@@ -47,12 +57,16 @@ class ApplicationCategoryController extends BaseController
Yii::$app->response->format = 'json';
$fields = ['id','name','sort','icon','banner','banner_url'];
$params = $this->initParams(Yii::$app->request->post(), $fields);
$application_category = new CoinApplicationCategoryForm();
if($params['id']){ //edit
$category = CoinApplicationCategory::getCategoryById($params['id']);
$params['platform_id'] = $category->platform_id;
$application_category->setScenario(CoinApplicationCategoryForm::SCENARIO_EDIT);
$application_category->load($params,'');
return $application_category->edit();
}else{
$params['platform_id'] = Yii::$app->user->identity->platform_id;
$application_category->setScenario(CoinApplicationCategoryForm::SCENARIO_ADD);
$application_category->load($params,'');
return $application_category->add();
......
......@@ -32,7 +32,9 @@ class ApplicationController extends BaseController
$id = Yii::$app->request->get('id');
if($id){
$parent_category = CoinApplicationCategory::getCategoryById($id);
$cate_items = CoinApplicationCategory::getCateItemsArray();
$platform_id = Yii::$app->user->identity->platform_id;
$condition = ['platform_id' => $platform_id];
$cate_items = CoinApplicationCategory::getCateItemsArray($condition);
if($parent_category){
return $this->render('list',['parent_category' => $parent_category,'cate_items' => $cate_items]);
}else{
......@@ -54,8 +56,8 @@ class ApplicationController extends BaseController
if(Yii::$app->request->isPost){
Yii::$app->response->format = 'json';
$category_id = Yii::$app->request->get('category_id');
$fields = ['category_id','h5_icon','official_url','introduce_image','show_width','show_height','open_type','name','sort','icon','type','native_url','native_login_url','h5_url','android_url','ios_url','app_store_url','advertise','description','redirect_type'];
$params = array_merge(Yii::$app->request->post(),['category_id' => $category_id]);
$fields = ['category_id','h5_icon','official_url','introduce_image','show_width','show_height','open_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'];
$params = array_merge(Yii::$app->request->post(),['category_id' => $category_id, 'platform_id' => Yii::$app->user->identity->platform_id]);
$params = $this->initParams($params, $fields);
$coin_applicateion_form = new CoinApplicationForm();
$coin_applicateion_form->setScenario(CoinApplicationForm::SCENARIO_ADD);
......@@ -78,8 +80,9 @@ class ApplicationController extends BaseController
{
if (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json';
$fields = ['category_id','id','h5_icon','official_url','introduce_image','show_width','show_height','open_type','name','sort','icon','type','native_url','native_login_url','h5_url','android_url','ios_url','app_store_url','advertise','description','redirect_type'];
$params = $this->initParams(Yii::$app->request->post(), $fields);
$fields = ['category_id','id','h5_icon','official_url','introduce_image','show_width','show_height','open_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'];
$params = array_merge(Yii::$app->request->post(),['platform_id' => Yii::$app->user->identity->platform_id]);
$params = $this->initParams($params, $fields);
$coin_applicateion_form = new CoinApplicationForm();
$coin_applicateion_form->setScenario(CoinApplicationForm::SCENARIO_EDIT);
$coin_applicateion_form->load($params,'');
......
......@@ -2,6 +2,7 @@
namespace backend\controllers;
use common\models\psources\CoinPlatform;
use Yii;
use common\models\Admin;
use common\models\Menu;
......@@ -62,6 +63,13 @@ class AuthController extends BaseController
*/
public function actionAdd()
{
$user_platform_id = Yii::$app->user->identity->platform_id;
if ($user_platform_id == 1) {
$platforms = CoinPlatform::find()->asArray()->all();
} else {
$platforms = CoinPlatform::find()->where(['id' => $user_platform_id])->asArray()->all();
}
if (Yii::$app->request->isPost) {
$auth = Yii::$app->authManager;
$self_role = current($auth->getRolesByUser(Yii::$app->user->id));
......@@ -78,6 +86,7 @@ class AuthController extends BaseController
$role = Yii::$app->authManager->createRole($role_name);
$role->type = 1;
$role->description = $data['description'];
$role->data = $data['platform_id'];
if (Yii::$app->authManager->add($role)) {
$auth = Yii::$app->authManager;
$auth->addChild($self_role, $role);
......@@ -87,7 +96,7 @@ class AuthController extends BaseController
}
}
}
return $this->render('add');
return $this->render('add', ['platforms' => $platforms]);
}
/**
......@@ -104,8 +113,16 @@ class AuthController extends BaseController
$role = Yii::$app->authManager->getRole($item_name);
$user_platform_id = Yii::$app->user->identity->platform_id;
if ($user_platform_id == 1) {
$platforms = CoinPlatform::find()->asArray()->all();
} else {
$platforms = CoinPlatform::find()->where(['id' => $user_platform_id])->asArray()->all();
}
if (Yii::$app->request->isPost) {
$data = Yii::$app->request->post('param');
$data['name'] = trim($data['name']);
if (!$data['name']) {
......@@ -116,6 +133,7 @@ class AuthController extends BaseController
} else {
$role->name = $data['name'];
$role->description = $data['description'];
$role->data = $data['platform_id'];
if (Yii::$app->authManager->update($item_name, $role)) {
$this->success('更新成功!', $this->getForward());
}
......@@ -126,6 +144,7 @@ class AuthController extends BaseController
return $this->render('edit', [
'role' => $role,
'platforms' => $platforms
]);
}
......
......@@ -24,6 +24,7 @@ class CoinBannerController extends BaseController
*/
public function actionAdd()
{
$user_platform_id = Yii::$app->user->identity->platform_id;
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
......@@ -33,6 +34,7 @@ class CoinBannerController extends BaseController
$banner_item = new CoinBannerItem();
$banner_item->banner_url = $banner_url;
$banner_item->image_url = $image_url;
$banner_item->platform_id = $user_platform_id;
$banner_item->save();
return ['code' => 0,'msg' => 'banner添加成功'];
}else{
......@@ -69,9 +71,17 @@ class CoinBannerController extends BaseController
*/
public function actionIndex()
{
$user_platform_id = Yii::$app->user->identity->platform_id;
if(Yii::$app->request->isAjax){
Yii::$app->response->format = 'json';
$data = CoinBannerItem::getItems();
$condition = [];
if(1 !== $user_platform_id){
$condition = ['platform_id' => $user_platform_id];
}
$data = CoinBannerItem::getItems($condition);
foreach ($data as $key => &$val){
$val['coin_name'] = isset($val['platform']['name']) ? $val['platform']['name'] : '';
}
return [ 'data' =>$data, 'code' => 0];
}
return $this->render('index');
......
......@@ -26,12 +26,13 @@ class CoinApplicationCategoryForm extends BaseForm
public $pid;
public $banner;
public $banner_url;
public $platform_id;
public function scenarios()
{
return [
self::SCENARIO_ADD => ['name', 'sort', 'icon', 'banner', 'banner_url'],
self::SCENARIO_EDIT => ['id', 'name', 'sort', 'icon', 'banner', 'banner_url'],
self::SCENARIO_ADD => ['name', 'sort', 'icon', 'banner', 'banner_url', 'platform_id'],
self::SCENARIO_EDIT => ['id', 'name', 'sort', 'icon', 'banner', 'banner_url', 'platform_id'],
];
}
......@@ -44,7 +45,8 @@ class CoinApplicationCategoryForm extends BaseForm
'icon' => '图标',
'sort' => '排序',
'banner' => 'banner图片',
'banner_url' => 'banner链接'
'banner_url' => 'banner链接',
'platform_id' => '平台Id',
];
}
......
......@@ -39,12 +39,13 @@ class CoinApplicationForm extends BaseForm
public $show_width;
public $show_height;
public $open_type;
public $platform_id;
public function scenarios()
{
return [
self::SCENARIO_ADD => ['category_id','name','h5_icon','official_url','introduce_image','show_width','show_height','open_type','sort','icon','type','native_url','native_login_url','h5_url','android_url','ios_url','app_store_url','advertise','description','redirect_type'],
self::SCENARIO_EDIT => ['category_id','id','h5_icon','official_url','introduce_image','show_width','show_height','open_type','name','sort','icon','type','native_url','native_login_url','h5_url','android_url','ios_url','app_store_url','advertise','description','redirect_type'],
self::SCENARIO_ADD => ['category_id','name','h5_icon','official_url','introduce_image','show_width','show_height','open_type','sort','icon','type','native_url','native_login_url','h5_url','android_url','ios_url','app_store_url','advertise','description','redirect_type', 'platform_id'],
self::SCENARIO_EDIT => ['category_id','id','h5_icon','official_url','introduce_image','show_width','show_height','open_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'],
];
}
......@@ -72,7 +73,8 @@ class CoinApplicationForm extends BaseForm
'redirect_type' => '跳转方式',
'show_width' => '显示宽度',
'show_height' => '显示高度',
'open_type' => 'H5打开方式'
'open_type' => 'H5打开方式',
'platform_id' => '平台Id'
];
}
......
......@@ -64,6 +64,10 @@
title: '名称',
},
{
field: 'coin_name',
title: '钱包',
},
{
field: 'type',
title: '类型',
templet: '#typeTpl'
......
......@@ -134,6 +134,10 @@
title: '名称',
},
{
field: 'coin_name',
title: '钱包',
},
{
field: 'app_count',
title: '应用',
},
......
......@@ -63,6 +63,10 @@
title: '编号'
},
{
field: 'coin_name',
title: '钱包',
},
{
field: 'banner_url',
title: 'banner跳转地址',
templet: function(d){
......
......@@ -23,13 +23,13 @@ class ApplicationBusiness
* @return array|\yii\db\ActiveRecord[]
* 获取首页推荐
*/
public static function getRecommendList()
public static function getRecommendList($condition = [])
{
$data = CoinApplicateRecommend::getRecommendList();
$data = CoinApplicateRecommend::getRecommendList($condition);
$icon_Items = array_column($data,'icon');
$icon_Infos = CoinImage::getItemsByIds($icon_Items);
$disabe_applicate_Ids = CoinApplication::getDisableIds();
$disabe_applicate_category_Ids = CoinApplicationCategory::getDisableIds();
$disabe_applicate_Ids = CoinApplication::getDisableIds($condition);
$disabe_applicate_category_Ids = CoinApplicationCategory::getDisableIds($condition);
foreach ($data as $key => &$value){
if($value['type'] == 1){
if(in_array($value['app_cate_id'],$disabe_applicate_category_Ids)){
......@@ -51,15 +51,17 @@ class ApplicationBusiness
return array_values($data);
}
public static function getCategoryAppList($limit=0)
public static function getCategoryAppList($condition = [])
{
$data = CoinApplicationCategory::getAllList(['enable' => 1]);
$condition = array_merge($condition, ['enable' => 1]);
$data = CoinApplicationCategory::getAllList($condition);
$cate_app_data = [];
$icon_Items = array_column($data,'icon');
$banner_Items = array_column($data,'banner');
$image_Items = array_merge($icon_Items,$banner_Items);
$icon_Infos = CoinImage::getItemsByIds($image_Items);
$cate_app_Infos = self::getCateAppInfo($limit);
unset($condition['enable']);
$cate_app_Infos = self::getCateAppInfo($limit = 5, $condition);
foreach($data as $value){
$cate_app_item['id'] = $value['id'];
$cate_app_item['name'] = $value['name'];
......@@ -90,12 +92,20 @@ class ApplicationBusiness
* @return mixed
* 获取分类以及应用
*/
public static function getCateAppInfo($limit=0,$condition = [])
public static function getCateAppInfo($limit=0, $condition = [])
{
$app_cate_Model = CoinAppCate::find();
$query = $app_cate_Model->JoinWith(['application'], false)
->select('cate_id,app_id,name,icon,type,native_url,native_login_url,h5_url,android_url,ios_url,app_store_url,advertise,redirect_type,'.CoinAppCate::tableName().'.sort')
->orderBy(CoinAppCate::tableName().'.sort asc');
if(array_key_exists('platform_id', $condition)){
$query = $app_cate_Model->JoinWith(['application'], false)
->select('cate_id,app_id,name,icon,type,native_url,native_login_url,h5_url,android_url,ios_url,app_store_url,advertise,redirect_type,'.CoinAppCate::tableName().'.sort')
->where($condition)
->orderBy(CoinAppCate::tableName().'.sort asc');
} else {
$query = $app_cate_Model->JoinWith(['application'], false)
->select('cate_id,app_id,name,icon,type,native_url,native_login_url,h5_url,android_url,ios_url,app_store_url,advertise,redirect_type,'.CoinAppCate::tableName().'.sort')
->orderBy(CoinAppCate::tableName().'.sort asc');
}
foreach ($condition as $item) {
$query = $query->andWhere($item);
}
......@@ -322,8 +332,8 @@ class ApplicationBusiness
return $app_item;
}
public static function getBannerList()
public static function getBannerList($condition = [])
{
return CoinBannerItem::getItems();
return CoinBannerItem::getItems($condition);
}
}
\ No newline at end of file
......@@ -28,12 +28,19 @@ class CoinApplicateRank extends BaseActiveRecord
return $this->hasOne(CoinApplication::class, ['id' => 'relate_id']);
}
public static function getApplicateList($type)
public static function getApplicateList($type, $user_platform_id = null)
{
$applicate_rank_model = self::find();
$data = $applicate_rank_model->JoinWith(['application'], false)
->select('relate_id as id,sort,name,'.self::tableName().".type")
->orderBy(self::tableName().'.sort asc')->where([self::tableName().'.type' => $type])->asArray()->all();
if(1 === $user_platform_id) {
$data = $applicate_rank_model->JoinWith(['application'], false)
->select('relate_id as id,sort,name,'.self::tableName().".type")
->orderBy(self::tableName().'.sort asc')->where([self::tableName().'.type' => $type])->asArray()->all();
} else {
$data = $applicate_rank_model->JoinWith(['application'], false)
->select('relate_id as id,sort,name,'.self::tableName().".type")
->orderBy(self::tableName().'.sort asc')->where([self::tableName().'.type' => $type, self::tableName().'.platform_id' => $user_platform_id])->asArray()->all();
}
return $data;
}
......
......@@ -60,9 +60,9 @@ class CoinApplicateRecommend extends BaseActiveRecord
}
}
public static function getRecommendList()
public static function getRecommendList($condition = [])
{
return self::find()->select('relate_id as app_cate_id,name,type,icon')->asArray()->orderBy('sort asc')->all();
return self::find()->where($condition)->select('relate_id as app_cate_id,name,type,icon')->asArray()->orderBy('sort asc')->all();
}
public static function getRecommendById($id)
......@@ -70,7 +70,10 @@ class CoinApplicateRecommend extends BaseActiveRecord
return self::find()->where(['id' => $id])->one();
}
public function getPlatform()
{
return $this->hasOne(CoinPlatform::className(), ['id'=>'platform_id']);
}
}
\ No newline at end of file
......@@ -144,9 +144,9 @@ class CoinApplication extends BaseActiveRecord
return self::find()->where(['id' => $id])->one();
}
public static function getAllApplicate()
public static function getAllApplicate($condition = [])
{
return self::find()->select('id,name')->asArray()->all();
return self::find()->select('id,name')->where($condition)->asArray()->all();
}
public static function getAppItemsByName($name)
......@@ -162,9 +162,10 @@ class CoinApplication extends BaseActiveRecord
->asArray()->one();
}
public static function getDisableIds()
public static function getDisableIds($condition = [])
{
return array_column(self::find()->where(['enable' => 0])->select('id')->asArray()->all(),'id');
$condition = array_merge($condition, ['enable' => 0]);
return array_column(self::find()->where($condition)->select('id')->asArray()->all(),'id');
}
......
......@@ -46,7 +46,7 @@ class CoinApplicationCategory extends BaseActiveRecord
*/
public static function getList($page = 1, $limit = 10, $condition = [], $order_by = ['sort' => SORT_ASC], $select = [])
{
$query = self::find();
$query = self::find()->joinWith('platform');
foreach($condition as $item){
$query = $query->andWhere($item);
}
......@@ -92,9 +92,9 @@ class CoinApplicationCategory extends BaseActiveRecord
return self::find()->where(['id' => $id])->one();
}
public static function getCateItemsArray()
public static function getCateItemsArray($condition = [])
{
return self::find()->asArray()->all();
return self::find()->where($condition)->asArray()->all();
}
public static function getAllList($condition=[])
......@@ -112,11 +112,15 @@ class CoinApplicationCategory extends BaseActiveRecord
return array_column(self::find()->where(['in','id',$ids])->asArray()->all(),null,'id');
}
public static function getDisableIds()
public static function getDisableIds($condition = [])
{
return array_column(self::find()->where(['enable' => 0])->select('id')->asArray()->all(),'id');
$condition = array_merge($condition, ['enable' => 0]);
return array_column(self::find()->where($condition)->select('id')->asArray()->all(),'id');
}
public function getPlatform()
{
return $this->hasOne(CoinPlatform::className(), ['id'=>'platform_id']);
}
}
......@@ -22,13 +22,18 @@ class CoinBannerItem extends BaseActiveRecord
return '{{coin_banner_item}}';
}
public static function getItems()
public static function getItems($condition = [])
{
return self::find()->asArray()->all();
return self::find()->joinWith('platform')->where($condition)->asArray()->all();
}
public static function getBanner($id)
{
return self::find()->where(['id' => $id])->one();
}
public function getPlatform()
{
return $this->hasOne(CoinPlatform::className(), ['id'=>'platform_id']);
}
}
\ 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