NotifyController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\notify\classes\NotifyClass;
  4. use bizGhs\shop\classes\ShopAdminClass;
  5. use common\components\util;
  6. use Yii;
  7. class NotifyController extends BaseController
  8. {
  9. //全部设置为已读 ssh 20230802
  10. public function actionAllRead()
  11. {
  12. NotifyClass::updateByCondition(['mainId' => $this->mainId, 'staffId' => $this->shopAdminId], ['read' => 1]);
  13. $staffId = $this->shopAdminId;
  14. ShopAdminClass::updateById($staffId, ['notifyNum' => 0]);
  15. util::complete('操作成功');
  16. }
  17. //通知列表 ssh 20230802
  18. public function actionList()
  19. {
  20. $get = Yii::$app->request->get();
  21. $staffId = $this->shopAdminId;
  22. $where = ['mainId' => $this->mainId, 'staffId' => $staffId];
  23. $read = $get['read'] ?? '';
  24. if (is_numeric($read)) {
  25. $where['read'] = $read;
  26. }
  27. $list = NotifyClass::getNotifyList($where);
  28. util::success($list);
  29. }
  30. //已读操作 ssh 20230802
  31. public function actionRead()
  32. {
  33. $get = Yii::$app->request->get();
  34. $id = $get['id'] ?? 0;
  35. $notify = NotifyClass::getById($id, true);
  36. if (empty($notify)) {
  37. util::fail('没有找到消息');
  38. }
  39. if ($notify->mainId != $this->mainId || $notify->staffId != $this->shopAdminId) {
  40. util::fail('没有权限');
  41. }
  42. if ($notify->read == 1) {
  43. util::complete();
  44. }
  45. $notify->read = 1;
  46. $notify->save();
  47. $staff = $this->shopAdmin;
  48. $notifyNum = $staff->notifyNum ?? 0;
  49. if ($notifyNum > 0) {
  50. $notifyNum--;
  51. }
  52. $staff->notifyNum = $notifyNum;
  53. $staff->save();
  54. util::complete();
  55. }
  56. }