GhsNoticeController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\shop\classes\GhsNoticeClass;
  4. use common\components\util;
  5. use Yii;
  6. /**
  7. * 批发端通知公告
  8. */
  9. class GhsNoticeController extends BaseController
  10. {
  11. /**
  12. * 管理端公告列表
  13. */
  14. public function actionList()
  15. {
  16. $get = Yii::$app->request->get();
  17. $list = GhsNoticeClass::searchList([
  18. 'mainId' => $this->mainId,
  19. 'title' => $get['title'] ?? '',
  20. 'isDel' => 0,
  21. 'order' => 'id DESC',
  22. ]);
  23. util::success($list);
  24. }
  25. /**
  26. * 客户端公告列表(仅显示中的公告)
  27. */
  28. public function actionShowList()
  29. {
  30. $get = Yii::$app->request->get();
  31. $list = GhsNoticeClass::searchList([
  32. 'mainId' => $this->mainId,
  33. 'title' => $get['title'] ?? '',
  34. 'position' => $get['position'] ?? '',
  35. 'isDel' => 0,
  36. 'status' => 1,
  37. 'order' => 'sort DESC, id DESC',
  38. ]);
  39. util::success($list);
  40. }
  41. /**
  42. * 新增公告
  43. */
  44. public function actionAdd()
  45. {
  46. $post = Yii::$app->request->post();
  47. $post['mainId'] = $this->mainId;
  48. $post['staffId'] = intval($this->shopAdminId);
  49. $id = GhsNoticeClass::addNotice($post);
  50. $info = GhsNoticeClass::getDetail($id);
  51. util::success($info);
  52. }
  53. /**
  54. * 更新公告
  55. */
  56. public function actionUpdate()
  57. {
  58. $post = Yii::$app->request->post();
  59. $id = intval($post['id'] ?? 0);
  60. if ($id <= 0) {
  61. util::fail('公告id不对');
  62. }
  63. $info = GhsNoticeClass::getById($id);
  64. GhsNoticeClass::valid($info, $this->mainId);
  65. $post['staffId'] = intval($this->shopAdminId);
  66. GhsNoticeClass::updateNotice($id, $post);
  67. util::complete('修改成功');
  68. }
  69. /**
  70. * 公告详情
  71. */
  72. public function actionDetail()
  73. {
  74. $id = intval(Yii::$app->request->get('id', 0));
  75. if ($id <= 0) {
  76. util::fail('公告id不对');
  77. }
  78. $info = GhsNoticeClass::getById($id);
  79. GhsNoticeClass::valid($info, $this->mainId);
  80. util::success(GhsNoticeClass::getDetail($id));
  81. }
  82. /**
  83. * 软删除公告
  84. */
  85. public function actionDelete()
  86. {
  87. $id = intval(Yii::$app->request->post('id', Yii::$app->request->get('id', 0)));
  88. if ($id <= 0) {
  89. util::fail('公告id不对');
  90. }
  91. $info = GhsNoticeClass::getById($id);
  92. GhsNoticeClass::valid($info, $this->mainId);
  93. GhsNoticeClass::deleteNotice($id, intval($this->shopAdminId));
  94. util::complete('删除成功');
  95. }
  96. /**
  97. * 上下架公告
  98. */
  99. public function actionUpdateStatus()
  100. {
  101. $id = intval(Yii::$app->request->post('id', Yii::$app->request->get('id', 0)));
  102. $status = intval(Yii::$app->request->post('status', Yii::$app->request->get('status', 0)));
  103. if ($id <= 0) {
  104. util::fail('公告id不对');
  105. }
  106. $info = GhsNoticeClass::getById($id);
  107. GhsNoticeClass::valid($info, $this->mainId);
  108. GhsNoticeClass::updateStatus($id, $status, intval($this->shopAdminId));
  109. util::complete('操作成功');
  110. }
  111. }