Commit b15e5f1e authored by shajiaiming's avatar shajiaiming

fix

parent f8efab9a
...@@ -16,6 +16,9 @@ class Notice extends BaseActiveRecord ...@@ -16,6 +16,9 @@ class Notice extends BaseActiveRecord
const STATUS_ON = 1; //激活 const STATUS_ON = 1; //激活
const STATUS_OFF = 0; //未激活 const STATUS_OFF = 0; //未激活
const TYPE_ROLL = 1; //滚动
const TYPE_POP = 0; //弹窗
//定义场景 //定义场景
const SCENARIOS_CREATE = 'create'; const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update'; const SCENARIOS_UPDATE = 'update';
...@@ -28,12 +31,32 @@ class Notice extends BaseActiveRecord ...@@ -28,12 +31,32 @@ class Notice extends BaseActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['title', 'content', 'type', 'platform_id'], 'required'], [['title', 'content', 'type', 'status', 'platform_id', 'author'], 'required'],
[['author'], 'safe'], [['status', 'type', 'platform_id'], 'integer'],
[['status', 'status', 'platform_id'], 'integer'], ['type', 'verfiyType'],
]; ];
} }
public function verfiyType($attribute, $params)
{
if ('create' == self::getScenario()){
$count = self::find()->where(['platform_id' => $this->platform_id, 'type' => $this->type])->count();
if (Notice::TYPE_ROLL == $this->type) {
if ($count >= 3) {
$this->addError($attribute, '滚动公告最多只能3条');
return false;
}
}
if (Notice::TYPE_POP == $this->type) {
if ($count >= 1) {
$this->addError($attribute, '弹窗公告最多只能3条');
return false;
}
}
}
}
public function scenarios() public function scenarios()
{ {
$scenarios = [ $scenarios = [
......
...@@ -17,12 +17,19 @@ class NoticeController extends BaseController ...@@ -17,12 +17,19 @@ class NoticeController extends BaseController
$data = null; $data = null;
$page = Yii::$app->request->get('page', 1); $page = Yii::$app->request->get('page', 1);
$size = Yii::$app->request->get('size', 10); $size = Yii::$app->request->get('size', 10);
$group = Yii::$app->request->getGroup();
if ('administrator' == $group) {
$platform_id = Yii::$app->request->get('platform_id', Yii::$app->request->getPlatformId());
} else {
$platform_id = Yii::$app->request->getPlatformId();
}
if (Yii::$app->request->isPost) { if (Yii::$app->request->isPost) {
$model = new Notice(); $model = new Notice();
$model->setScenario(Notice::SCENARIOS_CREATE); $model->setScenario(Notice::SCENARIOS_CREATE);
$params = Yii::$app->request->post(); $params = Yii::$app->request->post();
$params['platform_id'] = $platform_id; $params['platform_id'] = $platform_id;
$model->load($params, '');
if (!$model->validate()) { if (!$model->validate()) {
$msg = $model->errors; $msg = $model->errors;
$code = -1; $code = -1;
...@@ -33,11 +40,16 @@ class NoticeController extends BaseController ...@@ -33,11 +40,16 @@ class NoticeController extends BaseController
} }
if (Yii::$app->request->isGet) { if (Yii::$app->request->isGet) {
$status = Yii::$app->request->get('status', ''); $status = Yii::$app->request->get('status', 0);
$type = Yii::$app->request->get('type', 0); $type = Yii::$app->request->get('type', 0);
$query = Notice::find()->where(['platform_id' => $platform_id])->asArray(); $query = Notice::find()->select('id, title, type, create_at')->where(['platform_id' => $platform_id])->asArray();
if (false != $status) {
$query->andWhere(['status' => $status]);
}
if (false != $type) {
$query->andWhere(['type' => $type]);
}
$model = $query->offset(($page - 1) * $size)->orderBy('create_at')->limit($size)->asArray()->all(); $model = $query->offset(($page - 1) * $size)->orderBy('create_at')->limit($size)->asArray()->all();
$countQuery = clone $query; $countQuery = clone $query;
...@@ -56,16 +68,21 @@ class NoticeController extends BaseController ...@@ -56,16 +68,21 @@ class NoticeController extends BaseController
return ['code' => $code, 'msg' => $msg, 'data' => $data]; return ['code' => $code, 'msg' => $msg, 'data' => $data];
} }
public function actionCategoryUpdate() public function actionUpdate()
{ {
$msg = 'ok'; $msg = 'ok';
$code = 0; $code = 0;
$data = null; $data = null;
$group = Yii::$app->request->getGroup();
if ('administrator' == $group) {
$platform_id = Yii::$app->request->get('platform_id', Yii::$app->request->getPlatformId());
} else {
$platform_id = Yii::$app->request->getPlatformId(); $platform_id = Yii::$app->request->getPlatformId();
}
if (Yii::$app->request->isGet) { if (Yii::$app->request->isGet) {
$id = Yii::$app->request->get('id'); $id = Yii::$app->request->get('id');
$data = ExploreAppCategory::find()->select('id, name, sort, limit, style, status')->where(['platform_id' => $platform_id, 'id' => $id])->asArray()->one(); $data = Notice::find()->select('id, title, content, author, status, type')->where(['platform_id' => $platform_id, 'id' => $id])->asArray()->one();
goto doEnd; goto doEnd;
} }
...@@ -77,193 +94,32 @@ class NoticeController extends BaseController ...@@ -77,193 +94,32 @@ class NoticeController extends BaseController
$code = -1; $code = -1;
goto doEnd; goto doEnd;
} }
$model = ExploreAppCategory::findOne($id); $model = Notice::findOne($id);
if (empty($model)) {
if ($model->platform_id != $platform_id) { $msg = '数据错误';
$msg = '无权修改';
$code = -1;
goto doEnd;
}
$model->setScenario(ExploreAppCategory::SCENARIOS_UPDATE);
unset($params['id']);
$params['platform_id'] = $platform_id;
$name_arr = $params['name'];
$name = [];
foreach (Yii::$app->params['lang'] as $key => $val) {
$name[$val] = isset($name_arr[$val]) ? $name_arr[$val] : '';
}
unset($params['name']);
$params['name'] = $name;
if ($model->load($params, '') && $model->save()) {
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();
$id = Yii::$app->request->get('id');
if (false == $id) {
$msg = '参数错误';
$code = -1; $code = -1;
goto doEnd; goto doEnd;
} }
if (Yii::$app->request->isDelete) { $model->setScenario(Notice::SCENARIOS_UPDATE);
$model_app = ExploreApp::find()->where(['app_category_id' => (int)$id])->asArray()->all(); $model->load($params, '');
if (false != $model_app) { if (!$model->validate()) {
$msg = '请先删除该类别下的应用';
$code = -1;
goto doEnd;
}
$model = ExploreAppCategory::find()->where(['id' => $id, 'platform_id' => $platform_id])->one();
if ($model->platform_id != $platform_id) {
$msg = '无权修改';
$code = -1;
goto doEnd;
}
if (!$model->delete()) {
$msg = '删除失败';
$code = -1;
goto doEnd;
}
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionApps()
{
$msg = 'ok';
$code = 0;
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
if (Yii::$app->request->isGet) {
$category_id = Yii::$app->request->get('id', 0);
$page = Yii::$app->request->get('page', 1);
$size = Yii::$app->request->get('size', 10);
if (false == $platform_id || false == $category_id) {
$msg = '参数错误';
$code = -1;
$data = null;
goto doEnd;
}
$query = ExploreApp::find()
->where(['app_category_id' => $category_id])
->asArray();
$app_model = $query->offset(($page - 1) * $size)->orderBy('sort')->limit($size)->asArray()->all();
foreach ($app_model as &$val) {
$name = json_decode($val['name'], true);
$val['name'] = $name;
}
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => '10']);
$data = [
'list' => $app_model,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => $size,
'currentPage' => $page,
]
];
goto doEnd;
}
if (Yii::$app->request->isPost) {
$model = new ExploreApp();
$model->setScenario(ExploreApp::SCENARIOS_CREATE);
$params = Yii::$app->request->post();
$params['platform_id'] = $platform_id;
$name_arr = $params['name'];
$name = [];
foreach (Yii::$app->params['lang'] as $key => $val) {
$name[$val] = isset($name_arr[$val]) ? $name_arr[$val] : '';
}
unset($params['name']);
$params['name'] = $name;
if ($model->load($params, '') && $model->save()) {
goto doEnd;
}
$msg = $model->errors; $msg = $model->errors;
$code = -1; $code = -1;
goto doEnd; goto doEnd;
} }
$model->save();
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionAppUpdate()
{
$msg = 'ok';
$code = 0;
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
if (Yii::$app->request->isGet) {
$id = Yii::$app->request->get('id');
$data = ExploreApp::find()->select('id, name, icon, app_url, slogan, type, sort, status')->where(['platform_id' => $platform_id, 'id' => $id])->asArray()->one();
goto doEnd;
}
if (Yii::$app->request->isPut) {
$params = Yii::$app->request->post();
$id = isset($params['id']) ? $params['id'] : null;
if (false == $id) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
$model = ExploreApp::findOne($id);
if ($model->platform_id != $platform_id) {
$msg = '无权修改';
$code = -1;
goto doEnd;
}
$model->setScenario(ExploreApp::SCENARIOS_UPDATE);
unset($params['id']);
$params['platform_id'] = $platform_id;
$name_arr = $params['name'];
$name = [];
foreach (Yii::$app->params['lang'] as $key => $val) {
$name[$val] = isset($name_arr[$val]) ? $name_arr[$val] : '';
}
unset($params['name']);
$params['name'] = $name;
if ($model->load($params, '') && $model->save()) {
goto doEnd;
}
$msg = $model->errors;
$code = -1;
goto doEnd; goto doEnd;
} }
doEnd : doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data]; return ['code' => $code, 'msg' => $msg, 'data' => $data];
} }
public function actionAppRemove() public function actionRemove()
{ {
$msg = 'ok'; $msg = 'ok';
$code = 0; $code = 0;
$data = null; $data = null;
$group = Yii::$app->request->getGroup();
$platform_id = Yii::$app->request->getPlatformId(); $platform_id = Yii::$app->request->getPlatformId();
$id = Yii::$app->request->get('id'); $id = Yii::$app->request->get('id');
if (false == $id) { if (false == $id) {
...@@ -272,15 +128,14 @@ class NoticeController extends BaseController ...@@ -272,15 +128,14 @@ class NoticeController extends BaseController
goto doEnd; goto doEnd;
} }
if (Yii::$app->request->isDelete) { if (Yii::$app->request->isDelete) {
$model = ExploreApp::find()->where(['id' => $id, 'platform_id' => $platform_id])->one(); $model = Notice::findOne($id);
if ('administrator' != $group && $platform_id != $model->platform_id){
if ($model->platform_id != $platform_id) { $msg = '无权删除';
$msg = '无权修改';
$code = -1; $code = -1;
goto doEnd; goto doEnd;
} }
if (false == $model || !$model->delete()) { if (!$model->delete()) {
$msg = '删除失败'; $msg = '删除失败';
$code = -1; $code = -1;
goto doEnd; goto doEnd;
......
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