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]); } }