Commit f229d7fd authored by shajiaiming's avatar shajiaiming

应用添加

parent e9f78ac6
...@@ -12,18 +12,6 @@ class ExploreApp extends BaseActiveRecord ...@@ -12,18 +12,6 @@ class ExploreApp extends BaseActiveRecord
const STATUS_ON = 1; //激活 const STATUS_ON = 1; //激活
const STATUS_OFF = 0; //未激活 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() public static function getDb()
{ {
return Yii::$app->get('p_sources'); return Yii::$app->get('p_sources');
......
...@@ -140,35 +140,66 @@ class ExploreAppController extends BaseController ...@@ -140,35 +140,66 @@ class ExploreAppController extends BaseController
{ {
$msg = 'ok'; $msg = 'ok';
$code = 0; $code = 0;
$platform_id = Yii::$app->request->getPlatformId();; $data = null;
$category_id = Yii::$app->request->get('id', 0); $platform_id = Yii::$app->request->getPlatformId();
$page = Yii::$app->request->get('page', 1); if (Yii::$app->request->isGet) {
if (false == $platform_id || false == $category_id) { $category_id = Yii::$app->request->get('id', 0);
$msg = '参数错误'; $page = Yii::$app->request->get('page', 1);
$code = -1; if (false == $platform_id || false == $category_id) {
$data = null; $msg = '参数错误';
$code = -1;
$data = null;
goto doEnd;
}
$query = ExploreApp::find()
->select('id, name, icon, sort, status')
->where(['app_category_id' => $category_id])
->andWhere(['platform_id' => $platform_id])
->asArray();
$app_model = $query->offset(($page - 1) * 10)->limit(10)->asArray()->all();
foreach ($app_model as &$val) {
$name = json_decode($val['name'], true);
$val['name'] = $name['zh-CN'];
}
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => '10']);
$data = [
'list' => $app_model,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => 10,
'currentPage' => $page,
]
];
goto doEnd; goto doEnd;
} }
$query = ExploreApp::find()
->select('id, name, icon, sort, status, created_at') if (Yii::$app->request->isPost){
->where(['app_category_id' => $category_id]) $model = new ExploreApp();
->andWhere(['platform_id' => $platform_id]) $model->setScenario(ExploreApp::SCENARIOS_CREATE);
->asArray(); $params = Yii::$app->request->post();
$app_model = $query->offset(($page - 1) * 10)->limit(10)->asArray()->all(); $params['platform_id'] = $platform_id;
foreach ($app_model as &$val) { $lang = [
$name = json_decode($val['name'], true); 'zh-CN',
$val['name'] = $name['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_model,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => 10,
'currentPage' => $page,
]
];
doEnd : doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data]; return ['code' => $code, 'msg' => $msg, 'data' => $data];
} }
......
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