UserAction.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?php
  2. namespace App\Listeners;
  3. use App\Events\BlackUser;
  4. use App\Events\CheckPartner;
  5. use App\Events\CreatedPartner;
  6. use App\Events\LogoutUser;
  7. use App\Events\UpdatedPartner;
  8. use App\Events\UpdatedUserInfo;
  9. use App\Models\Log\UserActionModel;
  10. use Illuminate\Contracts\Queue\ShouldQueue;
  11. /**
  12. * 用户动作日志记录
  13. * Class UserAction
  14. * @package App\Listeners
  15. */
  16. class UserAction implements ShouldQueue
  17. {
  18. /**
  19. * Create the event listener.
  20. *
  21. */
  22. public function __construct()
  23. {
  24. }
  25. /**
  26. * Handle the event.
  27. *
  28. * @param object $event
  29. * @return void
  30. */
  31. public function handle($event)
  32. {
  33. }
  34. /**
  35. * 创建卡片
  36. * @param CreatedPartner $event
  37. */
  38. public function createdPartner(CreatedPartner $event)
  39. {
  40. UserActionModel::create([
  41. 'uid' => $event->stackGlobalConfig['uid'] ?? 0,
  42. 'appid' => $event->stackGlobalConfig['appid'] ?? "",
  43. 'tuid' => $event->model->uid,
  44. 'action' => '创建卡片',
  45. ]);
  46. }
  47. /**
  48. * 更新信息
  49. * @param UpdatedUserInfo $event
  50. */
  51. public function updatedUserInfo(UpdatedUserInfo $event)
  52. {
  53. $updatekeys = array(
  54. 'nickname',
  55. 'headimgurl',
  56. 'sex',
  57. 'age',
  58. 'weixin',
  59. 'qq',
  60. 'school',
  61. 'height',
  62. 'home',
  63. 'address',
  64. 'expect',
  65. 'introduce',
  66. 'photo_src',
  67. 'photo_1',
  68. 'photo_2',
  69. 'photo_3',
  70. 'photo_4',
  71. 'voice'
  72. );
  73. $upKeys = array_intersect(array_keys($event->model->getDirty()), $updatekeys);
  74. foreach ($upKeys as $key) {
  75. UserActionModel::create([
  76. 'uid' => $event->stackGlobalConfig['uid'] ?? 0,
  77. 'appid' => $event->stackGlobalConfig['appid'] ?? "",
  78. 'tuid' => $event->model->uid,
  79. 'action' => '更新卡片',
  80. 'field' => $key,
  81. 'extra' => json_encode([
  82. 'value' => $event->model->$key
  83. ], JSON_UNESCAPED_UNICODE)
  84. ]);
  85. }
  86. }
  87. /**
  88. * 卡片审核事件
  89. * @param CheckPartner $event
  90. */
  91. public function checkPartner(CheckPartner $event)
  92. {
  93. UserActionModel::create([
  94. 'uid' => $event->stackGlobalConfig['uid'] ?? 0,
  95. 'appid' => $event->stackGlobalConfig['appid'] ?? "",
  96. 'tuid' => $event->uid,
  97. 'action' => '卡片审核',
  98. 'field' => $event->field,
  99. 'extra' => json_encode([
  100. 'check' => $event->check
  101. ], JSON_UNESCAPED_UNICODE)
  102. ]);
  103. }
  104. /**
  105. * 用户注销事件
  106. * @param LogoutUser $event
  107. */
  108. public function logoutUser(LogoutUser $event)
  109. {
  110. UserActionModel::create([
  111. 'uid' => $event->stackGlobalConfig['uid'] ?? 0,
  112. 'appid' => $event->stackGlobalConfig['appid'] ?? "",
  113. 'tuid' => $event->uid,
  114. 'action' => '注销',
  115. ]);
  116. }
  117. /**
  118. * 封禁事件
  119. * @param BlackUser $event
  120. */
  121. public function blackUser(BlackUser $event)
  122. {
  123. UserActionModel::create([
  124. 'uid' => $event->stackGlobalConfig['uid'] ?? 0,
  125. 'appid' => $event->stackGlobalConfig['appid'] ?? "",
  126. 'tuid' => $event->uid,
  127. 'action' => '封禁',
  128. 'extra' => json_encode([
  129. 'endtime' => $event->endtime,
  130. 'black_type' => $event->black_type
  131. ], JSON_UNESCAPED_UNICODE)
  132. ]);
  133. }
  134. /**
  135. * 上下架事件
  136. * @param UpdatedPartner $event
  137. */
  138. public function updatedPartnerState(UpdatedPartner $event)
  139. {
  140. if ($event->model->isDirty('is_sell')) {
  141. UserActionModel::create([
  142. 'uid' => $event->stackGlobalConfig['uid'] ?? 0,
  143. 'appid' => $event->stackGlobalConfig['appid'] ?? "",
  144. 'tuid' => $event->model->uid,
  145. 'action' => '卡片显隐',
  146. 'field' => 'is_sell',
  147. 'extra' => json_encode([
  148. 'value' => $event->model->is_sell
  149. ], JSON_UNESCAPED_UNICODE)
  150. ]);
  151. }
  152. }
  153. }