Commit b8b83fd0 authored by shajiaiming's avatar shajiaiming

新版探索应用

parent b340acf5
<?php
namespace api\controllers;
use common\models\psources\ExploreAppCategory;
use Yii;
use api\base\BaseController;
class ExploreController extends BaseController
{
public function actionIndex()
{
$header = Yii::$app->request->headers;
$platform_id = $header['FZM-PLATFORM-ID'] ?? null;
if(false == $platform_id){
$msg = '参数错误';
$code = -1;
$data = null;
goto doEnd;
}
$app_category_model = ExploreAppCategory::find()->where(['platform_id' => $platform_id])->all();
foreach ($app_category_model as &$val){
foreach($val->applications as $app){
$app->name = $app->name[$this->lang];
}
$val->name = $val->name[$this->lang];
$val->apps = $val->applications;
unset($val->id);
unset($val->sort);
unset($val->platform_id);
}
$data = $app_category_model;
$msg = 'success';
$code = 0;
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
use yii\db\Expression;
use common\core\BaseActiveRecord;
use yii\behaviors\TimestampBehavior;
class ExploreApp extends BaseActiveRecord
{
const STATUS_ON = 1; //激活
const STATUS_OFF = 0; //未激活
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => new Expression('NOW()')
]
];
}
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{explore_app}}';
}
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public function rules()
{
return [
[['name', 'icon', 'app_url', 'slogan', 'type', 'status', 'platform_id', 'app_category_id'], 'required'],
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['name', 'icon', 'app_url', 'slogan', 'type', 'status', 'platform_id', 'app_category_id'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function getAppCategory()
{
return $this->hasOne(ExploreAppCategory::className(), ['id' => 'app_category_id']);
}
public static function getCasesStatus()
{
return [
self::STATUS_ON => '激活',
self::STATUS_OFF => '未激活',
];
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class ExploreAppCategory extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{explore_app_category}}';
}
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public function rules()
{
return [
[['name', 'sort', 'style', 'platform_id'], 'required'],
];
}
public function attributes()
{
return array_merge(parent::attributes(), ['apps']);
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['name', 'sort', 'style', 'platform_id'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function getApplications()
{
return $this->hasMany(ExploreApp::className(), ['app_category_id' => 'id'])->select(['name', 'icon', 'app_url', 'slogan']);
}
}
\ 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