GiftUserParty.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\common\model;
  3. use addons\faqueue\library\QueueApi;
  4. use think\Model;
  5. /**
  6. * 赠送礼物模型
  7. */
  8. class GiftUserParty extends Model
  9. {
  10. // 开启自动写入时间戳字段
  11. protected $autoWriteTimestamp = 'int';
  12. // 定义时间戳字段名
  13. protected $createTime = 'createtime';
  14. protected static function init()
  15. {
  16. GiftUserParty::afterInsert(function ($giftUserParty) {
  17. if ($giftUserParty->party_id > 0) {
  18. $giftNotice = 100;
  19. $bigGiftNotice = 200;
  20. $partyInfo = $giftUserParty->party;
  21. $money = $giftUserParty->value / 100;
  22. $type = 0;
  23. if ($money >= $bigGiftNotice) {
  24. $type = 72;
  25. }elseif ($money >= $giftNotice){
  26. $type = 71;
  27. }
  28. $type > 0 and QueueApi::sendGroupMessage($type, $giftUserParty->user->nickname, $giftUserParty->toUser->nickname, $partyInfo, $giftUserParty);
  29. }
  30. });
  31. }
  32. public function user()
  33. {
  34. return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  35. }
  36. public function toUser()
  37. {
  38. return $this->belongsTo('app\common\model\User', 'user_to_id', 'id', [], 'LEFT')->setEagerlyType(0);
  39. }
  40. public function party()
  41. {
  42. return $this->belongsTo('app\common\model\Party', 'party_id', 'id', [], 'LEFT')->setEagerlyType(0);
  43. }
  44. }