OthersitesetController.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/4/3
  6. * Time: 下午5:14
  7. * 网站设置,水印设置 ,友情链接,关于我们
  8. */
  9. namespace backend\controllers;
  10. use Yii;
  11. use backend\base\Help;
  12. use backend\base\CommonController;
  13. use backend\server\UploadFile;
  14. use common\models\Link;
  15. use common\models\About;
  16. class OthersitesetController extends CommonController
  17. {
  18. /*
  19. * 其他管理-网站设置-首页
  20. * */
  21. public function actionHome()
  22. {
  23. $model = new \common\models\Config();
  24. $row = $model->FindById();
  25. if ($row != null) {
  26. $row['logo'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['setsite'] . $row['logo'];
  27. $row['wechat'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['setsite'] . $row['wechat'];
  28. return $this->render('sethome', ['model' => $row]);
  29. }
  30. return $this->render('home');
  31. }
  32. /*
  33. * 其他管理-网站设置-修改网站数据
  34. * */
  35. public function actionEditform()
  36. {
  37. $model = new \common\models\Config();
  38. $row = $model->FindById();
  39. $input = Yii::$app->request->post();
  40. $url = Yii::$app->params['img_url']['setsite'];
  41. $model->load($input, '');
  42. if (!$model->validate()) return Help::JsonCode(Help::ERROR, '失败', $model->errors);
  43. if ($row == null) {
  44. $model->wechat = UploadFile::InstanceImgName('wechat', $url);
  45. $model->logo = UploadFile::InstanceImgName('logo', $url);
  46. if ($model->save(false) == true) return Help::JsonCode(Help::SUCCESS, '成功');
  47. } else {
  48. $wechat = UploadFile::InstanceImgName('wechat', $url);
  49. if ($wechat != false) {
  50. UploadFile::delImg($url, $row->wechat);
  51. $row->wechat = $wechat;
  52. }
  53. $logo = UploadFile::InstanceImgName('logo', $url);
  54. if ($logo != false) {
  55. UploadFile::delImg($url, $row->logo);
  56. $row->logo = $logo;
  57. }
  58. $row = Help::SetAttr($input, $model, $row);
  59. if ($row->save(false) == true) return Help::JsonCode(Help::SUCCESS, '成功');
  60. }
  61. }
  62. //==========================友情链接============================
  63. /*
  64. * 友情链接首页页面
  65. * */
  66. public function actionFriendshiplink()
  67. {
  68. return $this->render('friendshiplink');
  69. }
  70. /*
  71. * 友情链接首页数据
  72. * */
  73. public function actionFriendshiplinkform()
  74. {
  75. $model = new Link();
  76. $rows = $model->getList(Yii::$app->request->post());
  77. if ($rows != null) {
  78. return Help::JsonData(0, '成功', $model->Total(), $rows);
  79. }
  80. }
  81. /*
  82. * 友情链接添加数据页面
  83. * */
  84. public function actionFriendshiplinkadd()
  85. {
  86. $model = new \common\models\CategoryCity();
  87. $city = $model->getList([]);
  88. $frontMenu = new \common\models\SysmenuQ();
  89. $menu = $frontMenu->getList([]);
  90. return $this->render('friendshiplinkadd', ['city' => $city, 'menu' => $menu]);
  91. }
  92. /*
  93. * 友情链接添加数据
  94. * */
  95. public function actionFriendshiplinkaddform()
  96. {
  97. $model = new Link();
  98. $input = Yii::$app->request->post('data');
  99. $link = $model->Authenticator($input);
  100. if (is_object($link)) {
  101. if ($link->save() == true) return Help::JsonCode(Help::SUCCESS, '添加成功');
  102. }
  103. return Help::JsonCode(Help::ERROR, '添加失败');
  104. }
  105. /*
  106. * 友情链接修改数据页面
  107. * */
  108. public function actionFriendshiplinkedit()
  109. {
  110. $model = new Link();
  111. $row = $model->FindById(Yii::$app->request->get('id'));
  112. if ($row != null) {
  113. $model = new \common\models\CategoryCity();
  114. $city = $model->getList([]);
  115. $frontMenu = new \common\models\SysmenuQ();
  116. $menu = $frontMenu->getList([]);
  117. return $this->render('friendshiplinkedit', ['model' => $row, 'city' => $city, 'menu' => $menu]);
  118. }
  119. }
  120. /*
  121. * 友情链接修改数据
  122. * */
  123. public function actionFriendshiplinkeditform()
  124. {
  125. $model = new Link();
  126. $input = Yii::$app->request->post('data');
  127. $link = $model->Authenticator($input);
  128. if (is_object($link)) {
  129. $row = $model->FindById($input['id']);
  130. if ($row != null) {
  131. $setAttr = Help::SetAttr($input, $link, $row);
  132. if ($setAttr->save() == true) return Help::JsonCode(Help::SUCCESS, '成功');
  133. }
  134. }
  135. return Help::JsonCode(Help::ERROR, '失败', $link);
  136. }
  137. /*
  138. * 删除友情链接
  139. * */
  140. public function actionFriendshiplinkdel()
  141. {
  142. $model = new Link();
  143. $row = $model->FindById(Yii::$app->request->post('id'));
  144. if ($row != null) {
  145. $row->del = 2;
  146. if ($row->save() == true) return Help::JsonCode(Help::SUCCESS, '操作成功');
  147. }
  148. return Help::JsonCode(Help::ERROR, '操作失败');
  149. }
  150. //==========================水印设置============================
  151. /*
  152. * 其他管理-水印设置显示页面
  153. * */
  154. public function actionHomewatermark()
  155. {
  156. $query = \common\models\CategoryWatermark::find()->asArray()->one();
  157. $positionArr = [
  158. 1 => '#1',
  159. 2 => '#2',
  160. 3 => '#3',
  161. 4 => '#4',
  162. 5 => '#5',
  163. 6 => '#6',
  164. 7 => '#7',
  165. 8 => '#8',
  166. 9 => '#9',
  167. ];
  168. if ($query != null) {
  169. $query['template'] = Yii::$app->params['watermark_img']['url'] . $query['template'];
  170. return $this->render('homewatermark', ['model' => $query, 'position' => $positionArr]);
  171. } else {
  172. return $this->render('homewatermarkadd', ['position' => $positionArr]);
  173. }
  174. }
  175. /*
  176. * 其他管理-添加 and 修改,水印设置
  177. * */
  178. public function actionEditwatermarkform()
  179. {
  180. $model = new \common\models\CategoryWatermark();
  181. $query = $model::find()->one();
  182. $input = Yii::$app->request->post();
  183. $url = Yii::$app->params['watermark_img']['url'];
  184. $model->load($input, '');
  185. $model->validate();
  186. $img = \backend\server\UploadFile::InstanceImgName('template', $url);
  187. if ($query == null) {
  188. if ($img != false) {
  189. $model->template = $img;
  190. }
  191. $result = $model->save(false);
  192. } else {
  193. $setAtt = Help::SetAttr($input, $model, $query);
  194. if ($img != false) {
  195. $setAtt->template = $img;
  196. }
  197. if (!isset($input['status'])) {
  198. $setAtt->status = 2;
  199. }
  200. $result = $setAtt->update(false);
  201. }
  202. if ($result == true) return Help::JsonCode(Help::SUCCESS, '操作成功');
  203. return Help::JsonCode(Help::ERROR, '操作失败', $model->errors);
  204. }
  205. //==========================关于我们============================
  206. public function actionAbout()
  207. {
  208. $model = new About();
  209. $about = $model->getList();
  210. if (!empty($about)) {
  211. return $this->render('about', ['about' => $about]);
  212. }
  213. return $this->render('about');
  214. }
  215. /*
  216. * 其他管理-关于我们-添加关于我们
  217. * */
  218. public function actionAddform()
  219. {
  220. $model = new About();
  221. $input = Yii::$app->request->post();
  222. $rows = $model->Authenticator($input);
  223. if (is_object($rows)) {
  224. if (isset($input['id']) && !empty($input['id'])) {
  225. $row = $model->FindById($input['id']);
  226. $authMoel = Help::SetAttr($input, $rows, $row);
  227. if ($authMoel->update() == true) return Help::JsonCode(Help::SUCCESS, '修改成功');
  228. } else {
  229. if ($rows->save() == true) return Help::JsonCode(Help::SUCCESS, '添加成功');
  230. }
  231. }
  232. }
  233. }