| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace ghs\controllers;
- use bizGhs\notify\classes\NotifyClass;
- use bizGhs\shop\classes\ShopAdminClass;
- use common\components\util;
- use Yii;
- class NotifyController extends BaseController
- {
- //全部设置为已读 ssh 20230802
- public function actionAllRead()
- {
- NotifyClass::updateByCondition(['mainId' => $this->mainId, 'staffId' => $this->shopAdminId], ['read' => 1]);
- $staffId = $this->shopAdminId;
- ShopAdminClass::updateById($staffId, ['notifyNum' => 0]);
- util::complete('操作成功');
- }
- //单个设置为已读 ssh 20231224
- public function actionSetRead()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $notify = NotifyClass::getById($id, true);
- if (empty($notify)) {
- util::fail('没有找到通知');
- }
- $staffId = $this->shopAdminId;
- $staff = $this->shopAdmin;
- if ($notify->staffId != $staffId) {
- util::fail('不是你的通知哦');
- }
- if ($notify->read == 0) {
- $beforeNum = $staff->notifyNum;
- $newNum = $beforeNum > 0 ? bcsub($beforeNum, 1) : 0;
- $staff->notifyNum = $newNum;
- $staff->save();
- }
- $notify->read = 1;
- $notify->save();
- util::complete('操作成功');
- }
- //通知列表 ssh 20230802
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $staffId = $this->shopAdminId;
- $where = ['mainId' => $this->mainId, 'staffId' => $staffId];
- $read = $get['read'] ?? '';
- if (is_numeric($read)) {
- $where['read'] = $read;
- }
- $list = NotifyClass::getNotifyList($where);
- util::success($list);
- }
- }
|