MiniprogramsController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. namespace backend\controllers;
  3. use backend\server\UploadFile;
  4. use Yii;
  5. use backend\base\CommonController;
  6. use backend\base\Help;
  7. use common\models\MiniRotation;
  8. class MiniprogramsController extends CommonController
  9. {
  10. private function City()
  11. {
  12. $city = new \common\models\CategoryCity();
  13. $city->state = 1;
  14. $city->pid = 0;
  15. $cityModel = $city->getList([]);
  16. return $cityModel;
  17. }
  18. /*
  19. * 小程序首页轮播-页面
  20. * */
  21. public function actionRotation()
  22. {
  23. return $this->render('rotation', ['type' => 1]);
  24. }
  25. /*
  26. * 移动首页专题入口
  27. * */
  28. public function actionEntrance()
  29. {
  30. return $this->render('rotation', ['type' => 2]);
  31. }
  32. /*
  33. * 小程序首页轮播-数据
  34. * */
  35. public function actionRotationform()
  36. {
  37. $model = new MiniRotation();
  38. $rows = $model->getList(Yii::$app->request->post());
  39. if ($rows != null) {
  40. $imgUrl = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['push_lb'];
  41. foreach ($rows as &$val) {
  42. $val['create_at'] = date('Y-m-d H:i', $val['create_at']);
  43. $val['img'] = $imgUrl . $val['img'];
  44. }
  45. return Help::JsonData(0, Yii::t('app', 'get_success'), $model->Total(Yii::$app->request->post()), $rows);
  46. }
  47. return Help::JsonCode(Help::ERROR, Yii::t('app', 'get_error'));
  48. }
  49. /*
  50. * 小程序首页轮播-添加页面
  51. */
  52. public function actionRotationadd()
  53. {
  54. $cityModel = $this->City();
  55. return $this->render('rotationadd', ['city' => $cityModel, 'type' => Yii::$app->request->get('type')]);
  56. }
  57. /*
  58. * 小程序首页轮播-添加数据
  59. */
  60. public function actionRotationaddform()
  61. {
  62. try {
  63. $model = new MiniRotation();
  64. $input = Yii::$app->request->post();
  65. $url = Yii::$app->params['img_url']['push_lb'];
  66. $img = UploadFile::InstanceImgName_v1('img', $url);
  67. if (is_string($img)) {
  68. $input['img'] = $img;
  69. }
  70. $model->load($input, '');
  71. if ($model->save()) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_success'));
  72. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_error'), $model->errors);
  73. } catch (\Exception $e) {
  74. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'add_error'), $e->getMessage());
  75. }
  76. }
  77. /*
  78. * 小程序首页轮播-修改页面
  79. */
  80. public function actionRotationedit()
  81. {
  82. $model = new MiniRotation();
  83. $input = Yii::$app->request->get();
  84. $row = $model->FindById($input['id']);
  85. if ($row != null) {
  86. $imgUrl = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['push_lb'];
  87. $row['img'] = $imgUrl . $row['img'];
  88. $cityModel = $this->City();
  89. foreach ($cityModel as &$val) {
  90. $val['checked'] = '';
  91. if ($val['id'] == $row['city']) {
  92. $val['checked'] = 'selected';
  93. }
  94. }
  95. return $this->render('rotationedit', ['model' => $row, 'city' => $cityModel]);
  96. }
  97. }
  98. /*
  99. * 小程序首页轮播-修改数据
  100. * */
  101. public function actionRotationeditform()
  102. {
  103. $model = new MiniRotation();
  104. $input = Yii::$app->request->post();
  105. $setAttribute = $model->Authenticator($input);
  106. if (is_object($setAttribute)) {
  107. $row = $model->FindById($input['id']);
  108. if ($row != null) {
  109. $row = Help::SetAttr($input, $model, $row);
  110. $url = Yii::$app->params['img_url']['push_lb'];
  111. $img = UploadFile::InstanceImgName('img', $url);
  112. if (is_string($img)) {
  113. UploadFile::delImg($url, $row->img);
  114. $row->img = $img;
  115. }
  116. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  117. }
  118. }
  119. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'), $setAttribute);
  120. }
  121. /*
  122. *小程序首页轮播-删除and禁用
  123. * */
  124. public function actionImgdelshow()
  125. {
  126. $model = new MiniRotation();
  127. $input = Yii::$app->request->post();
  128. $row = $model->FindById($input['id']);
  129. if ($row != null) {
  130. switch ($input['type']) {
  131. case 'show':
  132. if ($row->is_show == 1) {
  133. $row->is_show = 2;
  134. } else if ($row->is_show == 2) {
  135. $row->is_show = 1;
  136. }
  137. break;
  138. case 'del':
  139. if ($row->delete()) {
  140. UploadFile::delImg(Yii::$app->params['img_url']['push_lb'], $row->img);
  141. return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  142. }
  143. break;
  144. case 'expiration':
  145. $row->expiration_date = $input['expiration'];
  146. break;
  147. }
  148. if ($row->save(false)) return Help::JsonCode(Help::SUCCESS, Yii::t('app', 'edit_success'));
  149. }
  150. return Help::JsonCode(Help::ERROR, Yii::t('app', 'edit_error'));
  151. }
  152. /**
  153. * PC搜索框热门区域
  154. * @return string
  155. */
  156. public function actionHotcity()
  157. {
  158. return $this->render('hotcity', ['type' => 3]);
  159. }
  160. /**
  161. * PC搜索框热门区域添加页面
  162. * @return string
  163. */
  164. public function actionHotcityadd()
  165. {
  166. return $this->render('hotcityadd', ['type' => Yii::$app->request->get('type')]);
  167. }
  168. /**
  169. * PC搜索框热门区域修改页面
  170. * @return string
  171. */
  172. public function actionHotcityedit()
  173. {
  174. $model = new MiniRotation();
  175. $input = Yii::$app->request->get();
  176. $row = $model->FindById($input['id']);
  177. if ($row != null) {
  178. $imgUrl = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['push_lb'];
  179. $row['img'] = $imgUrl . $row['img'];
  180. return $this->render('hotcityedit', ['model' => $row]);
  181. }
  182. }
  183. }