Commit 24dae7f9 authored by shajiaiming's avatar shajiaiming

应用类别相关接口

parent 93423ebe
...@@ -39,6 +39,7 @@ class ExploreAppCategory extends BaseActiveRecord ...@@ -39,6 +39,7 @@ class ExploreAppCategory extends BaseActiveRecord
{ {
$scenarios = [ $scenarios = [
self:: SCENARIOS_CREATE => ['name', 'sort', 'limit', 'style', 'platform_id'], self:: SCENARIOS_CREATE => ['name', 'sort', 'limit', 'style', 'platform_id'],
self:: SCENARIOS_UPDATE => ['name', 'sort', 'limit', 'style', 'platform_id'],
]; ];
return array_merge(parent:: scenarios(), $scenarios); return array_merge(parent:: scenarios(), $scenarios);
} }
......
...@@ -69,6 +69,73 @@ class ExploreAppController extends BaseController ...@@ -69,6 +69,73 @@ class ExploreAppController extends BaseController
return ['code' => $code, 'msg' => $msg, 'data' => $data]; return ['code' => $code, 'msg' => $msg, 'data' => $data];
} }
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() public function actionApps()
{ {
$msg = 'ok'; $msg = 'ok';
......
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