| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <?php
- namespace backend\controllers;
- use common\components\configDict;
- use common\models\xhPicture;
- use common\models\xhPictureCategory;
- use common\models\xhTrainClass;
- use common\models\xhTrainTeacher;
- use common\services\xhPictureCategoryService;
- use common\services\xhPictureService;
- use common\services\xhTrainClassService;
- use common\services\xhUploadService;
- use Yii;
- use yii\data\Pagination;
- use common\services\xhWifiService;
- use common\components\util;
- use common\components\weixinUtil;
- use common\components\page;
- use common\models\xhShop;
- use common\models\xhWifi;
- use common\services\xhMerchantService;
- use common\services\xhShopService;
- class TeachController extends BackendController
- {
- public function actionCourse()
- {
- $query = xhTrainClass::find();
- $query->where(['merchantId' => $this->merchantId]);
- $countQuery = clone $query;
- $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 20]);
- $models = $query->offset($pages->offset)->limit($pages->limit)->asArray()->all();
- return $this->render('course', ['models' => $models, 'pages' => $pages]);
- }
- public function actionEdit()
- {
- $id = Yii::$app->request->get('id', 0);
- $info = xhTrainClass::getById($id);
- return $this->render('edit', ['info' => $info]);
- }
- public function actionSaveEdit()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'];
- $post['merchantId'] = $this->merchantId;
- unset($post['_csrf']);
- unset($post['id']);
- xhTrainClassService::updateById($id, $post);
- util::successInfo('修改成功!');
- }
- public function actionIndex()
- {
- $get = Yii::$app->request->get();
- $categoryId = isset($get['categoryId']) ? $get['categoryId'] : 0;
- $category = xhPictureCategoryService::showCategory($this->merchantId);
- $ids = array_column($category, 'id');
- $categoryId = empty($categoryId) ? array_shift($ids) : $categoryId;
- $categoryInfo = xhPictureCategory::getById($categoryId);
- $shapeId = isset($categoryInfo['shape']) ? $categoryInfo['shape'] : 0;
- $shapeData = configDict::getConfig('imgShapeGetId');
- $shapeInfo = isset($shapeData[$shapeId]) ? $shapeData[$shapeId] : [];
- $query = xhPicture::find();
- $merchantId = $this->merchantId;
- $query->where(['merchantId' => $merchantId, 'categoryId' => $categoryId]);
- $countQuery = clone $query;
- $count = $countQuery->count();
- $query->orderBy('picSort desc');
- $page = isset($get['page']) ? $get['page'] : 1;
- $pageSize = 20;
- $offset = ($page - 1) * $pageSize;
- $models = $query->offset($offset)->limit($pageSize)->asArray()->all();
- $page = new page($count, $page, $pageSize);
- $paging = $page->fpage();
- return $this->render('index', ['category' => $category, 'categoryInfo' => $categoryInfo,
- 'models' => $models, 'paging' => $paging, 'categoryId' => $categoryId,'shapeInfo'=>$shapeInfo]);
- }
- public function actionApply()
- {
- return $this->render('apply');
- }
- public function actionUploadImg()
- {
- $categoryId = Yii::$app->request->post('categoryId', 0);
- $categoryInfo = xhPictureCategory::getById($categoryId);
- if (empty($categoryInfo)) {
- util::failInfo('图片分类找不到');
- }
- $merchantId = $this->merchantId;
- $shapeId = $categoryInfo['shape'];
- $shapeData = configDict::getConfig('imgShapeGetId');
- switch($shapeData[$shapeId]['name']){
- case 'square':
- $result = xhUploadService::squareImgUp($merchantId);
- break;
- case 'rectangle':
- $result = xhUploadService::rectangleImgUp($merchantId);
- break;
- case 'focus':
- $result = xhUploadService::focusImgUp($merchantId);
- break;
- default:
- $result = xhUploadService::squareImgUp($merchantId);
- }
- if(isset($result['code']) || $result['code'] == 'A0002'){
- util::failInfo();
- }
- $time = time();
- $maxInfo = xhPicture::find()->where(['merchantId' => 1, 'categoryId' => $categoryId])->orderBy('picSort desc')->one();
- $picSort = isset($maxInfo['picSort']) ? $maxInfo['picSort'] : 0;
- $picSort++;
- $data = ['merchantId' => 1, 'categoryId' => $categoryId, 'picSort' => $picSort, 'mobileUrl' => $result['middleImg'],
- 'mobileUrlSmall' => $result['smallImg'], 'mobileUrlBig' => $result['bigImg'], 'addTime' => 1, 'categoryType' => 0, 'addTime' => $time];
- $respond = xhPicture::add($data);
- $id = isset($respond['id']) ? $respond['id'] : 0;
- if (empty($id)) {
- util::failInfo('上传失败');
- }
- $arr['id'] = $id;
- $arr['url'] = $result['middleImg'];
- $arr['picSort'] = isset($respond['picSort']) ? $respond['picSort'] : 0;
- util::successInfo('success', 'A0001', $arr);
- }
- public function actionDelImg()
- {
- $id = Yii::$app->request->get('id', 0);
- $info = xhPicture::find()->where(['id' => $id])->one();
- if (isset($info->merchantId) == false || $info->merchantId != $this->merchantId) {
- util::failInfo();
- }
- $info->delete();
- util::successInfo();
- }
- public function actionChangeOrder()
- {
- $id = Yii::$app->request->get('id', 0);
- $num = Yii::$app->request->get('num', 0);
- $info = xhPicture::find()->where(['id' => $id])->asArray()->one();
- if ($info['merchantId'] != $this->merchantId) {
- util::failInfo();
- }
- xhPicture::updateById($id, ['picSort' => $num]);
- util::successInfo();
- }
- public function actionTeacher()
- {
- $query = xhTrainTeacher::find();
- $query->where(['merchantId' => $this->merchantId]);
- $countQuery = clone $query;
- $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 100]);
- $models = $query->offset($pages->offset)->limit($pages->limit)->asArray()->all();
- return $this->render('teacher', ['models' => $models, 'pages' => $pages]);
- }
- public function actionTeacherAdd()
- {
- return $this->render('teacherAdd');
- }
- public function actionTeacherEdit()
- {
- $id = Yii::$app->request->get('id', 0);
- $info = xhTrainTeacher::getById($id);
- return $this->render('teacherEdit', ['info' => $info]);
- }
- /**
- * 讲师编辑保存
- * @author shishaohua
- * @time 2019/3/24
- */
- public function actionTeacherSaveEdit()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'];
- $post['merchantId'] = $this->merchantId;
- unset($post['_csrf']);
- unset($post['id']);
- $info = xhTrainTeacher::find()->where(['id' => $id])->one();
- if ($info['merchantId'] != $this->merchantId) {
- util::failInfo();
- }
- xhTrainTeacher::updateById($id, $post);
- util::successInfo('修改成功!');
- }
- /**
- * 讲师添加保存
- * @author shishaohua
- * @time 2019/3/24
- */
- public function actionTeacherSaveAdd()
- {
- $post = Yii::$app->request->post();
- $post['merchantId'] = $this->merchantId;
- unset($post['_csrf']);
- xhTrainTeacher::add($post);
- util::successInfo('添加成功');
- }
- public function actionTeacherDel()
- {
- $id = Yii::$app->request->get('id', 0);
- if (in_array($id, [1, 2])) {
- util::failInfo('创始人不能删除');
- }
- $info = xhTrainTeacher::find()->where(['id' => $id])->one();
- if ($info['merchantId'] != $this->merchantId) {
- util::failInfo();
- }
- $info->delete();
- util::successInfo();
- }
- /**
- * 上传老师头像
- * @author shishaohua
- * @time 2019/3/24
- */
- public function actionUploadTeacherAvatar()
- {
- $merchantId = $this->merchantId;
- $result = xhUploadService::originalImgUp($merchantId);
- $url = $result['url'];
- util::successInfo('success', 'A0001', ['url' => $url]);
- }
- }
|