NotifyController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 20231224
  18. public function actionSetRead()
  19. {
  20. $get = Yii::$app->request->get();
  21. $id = $get['id'] ?? 0;
  22. $notify = NotifyClass::getById($id, true);
  23. if (empty($notify)) {
  24. util::fail('没有找到通知');
  25. }
  26. $staffId = $this->shopAdminId;
  27. $staff = $this->shopAdmin;
  28. if ($notify->staffId != $staffId) {
  29. util::fail('不是你的通知哦');
  30. }
  31. if ($notify->read == 0) {
  32. $beforeNum = $staff->notifyNum;
  33. $newNum = $beforeNum > 0 ? bcsub($beforeNum, 1) : 0;
  34. $staff->notifyNum = $newNum;
  35. $staff->save();
  36. }
  37. $notify->read = 1;
  38. $notify->save();
  39. util::complete('操作成功');
  40. }
  41. //通知列表 ssh 20230802
  42. public function actionList()
  43. {
  44. $get = Yii::$app->request->get();
  45. $staffId = $this->shopAdminId;
  46. $where = ['staffId' => $staffId];
  47. $read = $get['read'] ?? '';
  48. if (is_numeric($read)) {
  49. $where['read'] = $read;
  50. }
  51. $list = NotifyClass::getNotifyList($where);
  52. util::success($list);
  53. }
  54. }