TeachController.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. namespace backend\controllers;
  3. use common\components\configDict;
  4. use common\models\xhPicture;
  5. use common\models\xhPictureCategory;
  6. use common\models\xhTrainClass;
  7. use common\models\xhTrainTeacher;
  8. use common\services\xhPictureCategoryService;
  9. use common\services\xhPictureService;
  10. use common\services\xhTrainClassService;
  11. use common\services\xhUploadService;
  12. use Yii;
  13. use yii\data\Pagination;
  14. use common\services\xhWifiService;
  15. use common\components\util;
  16. use common\components\weixinUtil;
  17. use common\components\page;
  18. use common\models\xhShop;
  19. use common\models\xhWifi;
  20. use common\services\xhMerchantService;
  21. use common\services\xhShopService;
  22. class TeachController extends BackendController
  23. {
  24. public function actionCourse()
  25. {
  26. $query = xhTrainClass::find();
  27. $query->where(['merchantId' => $this->merchantId]);
  28. $countQuery = clone $query;
  29. $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 20]);
  30. $models = $query->offset($pages->offset)->limit($pages->limit)->asArray()->all();
  31. return $this->render('course', ['models' => $models, 'pages' => $pages]);
  32. }
  33. public function actionEdit()
  34. {
  35. $id = Yii::$app->request->get('id', 0);
  36. $info = xhTrainClass::getById($id);
  37. return $this->render('edit', ['info' => $info]);
  38. }
  39. public function actionSaveEdit()
  40. {
  41. $post = Yii::$app->request->post();
  42. $id = $post['id'];
  43. $post['merchantId'] = $this->merchantId;
  44. unset($post['_csrf']);
  45. unset($post['id']);
  46. xhTrainClassService::updateById($id, $post);
  47. util::successInfo('修改成功!');
  48. }
  49. public function actionIndex()
  50. {
  51. $get = Yii::$app->request->get();
  52. $categoryId = isset($get['categoryId']) ? $get['categoryId'] : 0;
  53. $category = xhPictureCategoryService::showCategory($this->merchantId);
  54. $ids = array_column($category, 'id');
  55. $categoryId = empty($categoryId) ? array_shift($ids) : $categoryId;
  56. $categoryInfo = xhPictureCategory::getById($categoryId);
  57. $shapeId = isset($categoryInfo['shape']) ? $categoryInfo['shape'] : 0;
  58. $shapeData = configDict::getConfig('imgShapeGetId');
  59. $shapeInfo = isset($shapeData[$shapeId]) ? $shapeData[$shapeId] : [];
  60. $query = xhPicture::find();
  61. $merchantId = $this->merchantId;
  62. $query->where(['merchantId' => $merchantId, 'categoryId' => $categoryId]);
  63. $countQuery = clone $query;
  64. $count = $countQuery->count();
  65. $query->orderBy('picSort desc');
  66. $page = isset($get['page']) ? $get['page'] : 1;
  67. $pageSize = 20;
  68. $offset = ($page - 1) * $pageSize;
  69. $models = $query->offset($offset)->limit($pageSize)->asArray()->all();
  70. $page = new page($count, $page, $pageSize);
  71. $paging = $page->fpage();
  72. return $this->render('index', ['category' => $category, 'categoryInfo' => $categoryInfo,
  73. 'models' => $models, 'paging' => $paging, 'categoryId' => $categoryId,'shapeInfo'=>$shapeInfo]);
  74. }
  75. public function actionApply()
  76. {
  77. return $this->render('apply');
  78. }
  79. public function actionUploadImg()
  80. {
  81. $categoryId = Yii::$app->request->post('categoryId', 0);
  82. $categoryInfo = xhPictureCategory::getById($categoryId);
  83. if (empty($categoryInfo)) {
  84. util::failInfo('图片分类找不到');
  85. }
  86. $merchantId = $this->merchantId;
  87. $shapeId = $categoryInfo['shape'];
  88. $shapeData = configDict::getConfig('imgShapeGetId');
  89. switch($shapeData[$shapeId]['name']){
  90. case 'square':
  91. $result = xhUploadService::squareImgUp($merchantId);
  92. break;
  93. case 'rectangle':
  94. $result = xhUploadService::rectangleImgUp($merchantId);
  95. break;
  96. case 'focus':
  97. $result = xhUploadService::focusImgUp($merchantId);
  98. break;
  99. default:
  100. $result = xhUploadService::squareImgUp($merchantId);
  101. }
  102. if(isset($result['code']) || $result['code'] == 'A0002'){
  103. util::failInfo();
  104. }
  105. $time = time();
  106. $maxInfo = xhPicture::find()->where(['merchantId' => 1, 'categoryId' => $categoryId])->orderBy('picSort desc')->one();
  107. $picSort = isset($maxInfo['picSort']) ? $maxInfo['picSort'] : 0;
  108. $picSort++;
  109. $data = ['merchantId' => 1, 'categoryId' => $categoryId, 'picSort' => $picSort, 'mobileUrl' => $result['middleImg'],
  110. 'mobileUrlSmall' => $result['smallImg'], 'mobileUrlBig' => $result['bigImg'], 'addTime' => 1, 'categoryType' => 0, 'addTime' => $time];
  111. $respond = xhPicture::add($data);
  112. $id = isset($respond['id']) ? $respond['id'] : 0;
  113. if (empty($id)) {
  114. util::failInfo('上传失败');
  115. }
  116. $arr['id'] = $id;
  117. $arr['url'] = $result['middleImg'];
  118. $arr['picSort'] = isset($respond['picSort']) ? $respond['picSort'] : 0;
  119. util::successInfo('success', 'A0001', $arr);
  120. }
  121. public function actionDelImg()
  122. {
  123. $id = Yii::$app->request->get('id', 0);
  124. $info = xhPicture::find()->where(['id' => $id])->one();
  125. if (isset($info->merchantId) == false || $info->merchantId != $this->merchantId) {
  126. util::failInfo();
  127. }
  128. $info->delete();
  129. util::successInfo();
  130. }
  131. public function actionChangeOrder()
  132. {
  133. $id = Yii::$app->request->get('id', 0);
  134. $num = Yii::$app->request->get('num', 0);
  135. $info = xhPicture::find()->where(['id' => $id])->asArray()->one();
  136. if ($info['merchantId'] != $this->merchantId) {
  137. util::failInfo();
  138. }
  139. xhPicture::updateById($id, ['picSort' => $num]);
  140. util::successInfo();
  141. }
  142. public function actionTeacher()
  143. {
  144. $query = xhTrainTeacher::find();
  145. $query->where(['merchantId' => $this->merchantId]);
  146. $countQuery = clone $query;
  147. $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 100]);
  148. $models = $query->offset($pages->offset)->limit($pages->limit)->asArray()->all();
  149. return $this->render('teacher', ['models' => $models, 'pages' => $pages]);
  150. }
  151. public function actionTeacherAdd()
  152. {
  153. return $this->render('teacherAdd');
  154. }
  155. public function actionTeacherEdit()
  156. {
  157. $id = Yii::$app->request->get('id', 0);
  158. $info = xhTrainTeacher::getById($id);
  159. return $this->render('teacherEdit', ['info' => $info]);
  160. }
  161. /**
  162. * 讲师编辑保存
  163. * @author shishaohua
  164. * @time 2019/3/24
  165. */
  166. public function actionTeacherSaveEdit()
  167. {
  168. $post = Yii::$app->request->post();
  169. $id = $post['id'];
  170. $post['merchantId'] = $this->merchantId;
  171. unset($post['_csrf']);
  172. unset($post['id']);
  173. $info = xhTrainTeacher::find()->where(['id' => $id])->one();
  174. if ($info['merchantId'] != $this->merchantId) {
  175. util::failInfo();
  176. }
  177. xhTrainTeacher::updateById($id, $post);
  178. util::successInfo('修改成功!');
  179. }
  180. /**
  181. * 讲师添加保存
  182. * @author shishaohua
  183. * @time 2019/3/24
  184. */
  185. public function actionTeacherSaveAdd()
  186. {
  187. $post = Yii::$app->request->post();
  188. $post['merchantId'] = $this->merchantId;
  189. unset($post['_csrf']);
  190. xhTrainTeacher::add($post);
  191. util::successInfo('添加成功');
  192. }
  193. public function actionTeacherDel()
  194. {
  195. $id = Yii::$app->request->get('id', 0);
  196. if (in_array($id, [1, 2])) {
  197. util::failInfo('创始人不能删除');
  198. }
  199. $info = xhTrainTeacher::find()->where(['id' => $id])->one();
  200. if ($info['merchantId'] != $this->merchantId) {
  201. util::failInfo();
  202. }
  203. $info->delete();
  204. util::successInfo();
  205. }
  206. /**
  207. * 上传老师头像
  208. * @author shishaohua
  209. * @time 2019/3/24
  210. */
  211. public function actionUploadTeacherAvatar()
  212. {
  213. $merchantId = $this->merchantId;
  214. $result = xhUploadService::originalImgUp($merchantId);
  215. $url = $result['url'];
  216. util::successInfo('success', 'A0001', ['url' => $url]);
  217. }
  218. }