| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace addons\Course\backend\controllers;
- use addons\Course\common\models\AddonsCourse;
- use addons\Course\common\models\AddonsCourseDiscuss;
- use addons\Course\common\models\AddonsCourseGroups;
- use common\enums\StatusEnum;
- class RecommendController extends BaseController
- {
- public function actionIndex()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $params = \Yii::$app->request->get();
- $where[] = ['mall_id' => $this->mall_id];
- $where[] = ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]];
- if (!empty($params['keyword'])) $where[] = ['like', 'gname', $params['keyword'] . '%', false];
- $params = [
- 'where' => $where,
- 'order' => 'sort desc',
- ];
- $page_data = AddonsCourseGroups::listPage($params);
- if (!empty($page_data['list'])) {
- foreach ($page_data['list'] as &$item) {
- $item['course_number'] = 0;
- $cid = explode(',', $item['cid']);
- if (!empty($cid)) $item['course_number'] = count($cid);
- }
- }
- return $this->success('success', $page_data);
- } else {
- return $this->error('请求方式错误');
- }
- } else {
- return $this->render('index');
- }
- }
- public function actionEdit()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isGet) {
- $params = \Yii::$app->request->get();
- $group_info = '';
- if (!empty($params['id'])) $group_info = AddonsCourseGroups::getOne([['id' => $params['id'], 'mall_id' => $this->mall_id]], true);
- $course_list = AddonsCourse::lists([
- 'where' => [
- ['mall_id' => $this->mall_id],
- ['status' => StatusEnum::ENABLED]
- ],
- 'select' => 'id,name'
- ]);
- if (!empty($group_info['cid'])) $group_info['cid'] = json_decode($group_info['cid'], true);
- $data['group_info'] = $group_info;
- $data['course_list'] = $course_list;
- return $this->success('success', $data);
- } else {
- $params = \Yii::$app->request->post();
- $res = \Yii::$app->services->validate->validate($params, [
- [['cid', 'gname', 'sort'], 'required'],
- [['id'], 'integer'],
- [['logo'], 'safe']
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $params['mall_id'] = $this->mall_id;
- if (!empty($params['cid'])) {
- $params['cid'] = json_encode(explode(',', $params['cid']));
- }
- $res = AddonsCourseGroups::setData($params);
- if ($res === false) return $this->error(AddonsCourseGroups::getStaticError());
- return $this->success('操作成功');
- }
- } else {
- return $this->render('edit');
- }
- }
- public function actionSwitchUse()
- {
- $post = \Yii::$app->request->post();
- $params['id'] = $post['id'];
- $params['mall_id'] = $this->mall_id;
- $params['status'] = $post['val'];
- $res = AddonsCourseGroups::setData($params);
- if ($res === false) return $this->error(AddonsCourseDiscuss::getStaticError());
- return $this->success('操作成功');
- }
- public function actionDelete()
- {
- $post = \Yii::$app->request->post();
- $params['id'] = $post['id'];
- $params['mall_id'] = $this->mall_id;
- $params['status'] = StatusEnum::DELETE;
- $res = AddonsCourseGroups::setData($params);
- if ($res === false) return $this->error(AddonsCourseDiscuss::getStaticError());
- return $this->success('操作成功');
- }
- }
|