NotifyPullTimeService.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace addons\TinyShop\services\common;
  3. use common\components\Service;
  4. use addons\TinyShop\common\models\common\NotifyPullTime;
  5. /**
  6. * Class NotifyPullTimeService
  7. * @package addons\TinyShop\services\common
  8. * @author jianyan74 <751393839@qq.com>
  9. */
  10. class NotifyPullTimeService extends Service
  11. {
  12. /**
  13. * @param $member_id
  14. * @param $type
  15. * @param string $alert_type
  16. * @return int|mixed
  17. */
  18. public function getLastTime($member_id, $type, $alert_type = '')
  19. {
  20. $time = time();
  21. $model = $this->findByMemberId($member_id, $type, $alert_type);
  22. if (!$model) {
  23. $model = new NotifyPullTime();
  24. $model->member_id = $member_id;
  25. $model->type = $type;
  26. $model->alert_type = $alert_type;
  27. $model->last_time = $time;
  28. $model->last_id = 0;
  29. } else {
  30. $time = $model->last_time;
  31. $model->last_time = time();
  32. }
  33. $model->save();
  34. return $time;
  35. }
  36. /**
  37. * @param $member_id
  38. * @param $type
  39. * @param string $alert_type
  40. * @return array|\yii\db\ActiveRecord|null|NotifyPullTime
  41. */
  42. public function findByMemberId($member_id, $type, $alert_type = '')
  43. {
  44. // 查询最新的一条提醒时间
  45. return NotifyPullTime::find()
  46. ->where(['member_id' => $member_id, 'type' => $type])
  47. ->andFilterWhere(['merchant_id' => $this->getMerchantId()])
  48. ->andFilterWhere(['alert_type' => $alert_type])
  49. ->orderBy('last_time desc')
  50. ->one();
  51. }
  52. }
粤ICP备19079148号