ShopNoticeController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\shop\classes\ShopNoticeClass;
  4. use common\components\util;
  5. use Yii;
  6. /**
  7. * 零售花店通知公告
  8. */
  9. class ShopNoticeController extends BaseController
  10. {
  11. /**
  12. * 管理端公告列表
  13. * 支持 title / position / status 筛选(PC 公告管理设计稿)
  14. */
  15. public function actionList()
  16. {
  17. $get = Yii::$app->request->get();
  18. $params = [
  19. 'mainId' => $this->mainId,
  20. 'title' => $get['title'] ?? '',
  21. 'isDel' => 0,
  22. 'order' => 'id DESC',
  23. ];
  24. // 展示位置:1商城首页 2分类菜单 4购物车 8订单提交
  25. if (isset($get['position']) && $get['position'] !== '' && $get['position'] !== null) {
  26. $params['position'] = $get['position'];
  27. }
  28. // 状态:1显示中 0已隐藏;不传则查全部
  29. if (isset($get['status']) && $get['status'] !== '' && $get['status'] !== null) {
  30. $params['status'] = $get['status'];
  31. }
  32. $list = ShopNoticeClass::searchList($params);
  33. util::success($list);
  34. }
  35. /**
  36. * 客户端公告列表(仅显示中的公告)
  37. */
  38. public function actionShowList()
  39. {
  40. $get = Yii::$app->request->get();
  41. $list = ShopNoticeClass::searchList([
  42. 'mainId' => $this->mainId,
  43. 'title' => $get['title'] ?? '',
  44. 'position' => $get['position'] ?? '',
  45. 'isDel' => 0,
  46. 'status' => 1,
  47. 'order' => 'sort DESC, id DESC',
  48. ]);
  49. util::success($list);
  50. }
  51. /**
  52. * 新增公告
  53. */
  54. public function actionAdd()
  55. {
  56. $post = Yii::$app->request->post();
  57. $post['mainId'] = $this->mainId;
  58. $post['staffId'] = intval($this->shopAdminId);
  59. $id = ShopNoticeClass::addNotice($post);
  60. $info = ShopNoticeClass::getDetail($id);
  61. util::success($info);
  62. }
  63. /**
  64. * 更新公告
  65. */
  66. public function actionUpdate()
  67. {
  68. $post = Yii::$app->request->post();
  69. $id = intval($post['id'] ?? 0);
  70. if ($id <= 0) {
  71. util::fail('公告id不对');
  72. }
  73. $info = ShopNoticeClass::getById($id);
  74. ShopNoticeClass::valid($info, $this->mainId);
  75. $post['staffId'] = intval($this->shopAdminId);
  76. ShopNoticeClass::updateNotice($id, $post);
  77. util::complete('修改成功');
  78. }
  79. /**
  80. * 公告详情
  81. */
  82. public function actionDetail()
  83. {
  84. $id = intval(Yii::$app->request->get('id', 0));
  85. if ($id <= 0) {
  86. util::fail('公告id不对');
  87. }
  88. $info = ShopNoticeClass::getById($id);
  89. ShopNoticeClass::valid($info, $this->mainId);
  90. util::success(ShopNoticeClass::getDetail($id));
  91. }
  92. /**
  93. * 软删除公告
  94. */
  95. public function actionDelete()
  96. {
  97. $id = intval(Yii::$app->request->post('id', Yii::$app->request->get('id', 0)));
  98. if ($id <= 0) {
  99. util::fail('公告id不对');
  100. }
  101. $info = ShopNoticeClass::getById($id);
  102. ShopNoticeClass::valid($info, $this->mainId);
  103. ShopNoticeClass::deleteNotice($id, intval($this->shopAdminId));
  104. util::complete('删除成功');
  105. }
  106. /**
  107. * 上下架公告
  108. */
  109. public function actionUpdateStatus()
  110. {
  111. $id = intval(Yii::$app->request->post('id', Yii::$app->request->get('id', 0)));
  112. $status = intval(Yii::$app->request->post('status', Yii::$app->request->get('status', 0)));
  113. if ($id <= 0) {
  114. util::fail('公告id不对');
  115. }
  116. $info = ShopNoticeClass::getById($id);
  117. ShopNoticeClass::valid($info, $this->mainId);
  118. ShopNoticeClass::updateStatus($id, $status, intval($this->shopAdminId));
  119. util::complete('操作成功');
  120. }
  121. }