ShopNoticeController.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace mall\controllers;
  3. use bizHd\shop\classes\ShopNoticeClass;
  4. use common\components\util;
  5. use Yii;
  6. /**
  7. * 商城客户端:门店通知公告(xhShopNotice)
  8. */
  9. class ShopNoticeController extends BaseController
  10. {
  11. /** 列表允许未登录浏览(详情仍需登录) */
  12. public $guestAccess = ['show-list'];
  13. /**
  14. * 客户端公告列表(仅上架、未删除)
  15. * GET /shop-notice/show-list?position=2
  16. * 未登录可浏览:依赖 account 解析 mainId,与登录态无关
  17. */
  18. public function actionShowList()
  19. {
  20. // 无门店主账号时返回空列表(不要求 user,避免分类/首页公告空白或 toast)
  21. if (empty($this->mainId)) {
  22. util::success([
  23. 'totalNum' => 0,
  24. 'totalPage' => 0,
  25. 'moreData' => 0,
  26. 'list' => [],
  27. ]);
  28. }
  29. $get = Yii::$app->request->get();
  30. $list = ShopNoticeClass::searchList([
  31. 'mainId' => $this->mainId,
  32. 'title' => $get['title'] ?? '',
  33. 'position' => $get['position'] ?? '',
  34. 'isDel' => 0,
  35. 'status' => 1,
  36. 'order' => 'sort DESC, id DESC',
  37. ]);
  38. util::success($list);
  39. }
  40. /**
  41. * 客户端公告详情
  42. * GET /shop-notice/detail?id=
  43. */
  44. public function actionDetail()
  45. {
  46. $user = $this->user;
  47. if (empty($user) || empty($this->mainId)) {
  48. util::fail('请先登录哈');
  49. }
  50. $id = intval(Yii::$app->request->get('id', 0));
  51. if ($id <= 0) {
  52. util::fail('公告id不对');
  53. }
  54. $info = ShopNoticeClass::getById($id);
  55. ShopNoticeClass::valid($info, $this->mainId);
  56. if (intval($info['status']) !== 1) {
  57. util::fail('公告已下架');
  58. }
  59. util::success(ShopNoticeClass::getDetail($id));
  60. }
  61. }