RedpackLog.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * 红包领取记录
  4. * @author solu
  5. */
  6. class RedpackLog extends Model {
  7. protected $tableName = 'redpack_log';
  8. protected $dbKey = 'dw_chat';
  9. /**
  10. * 红包领取信息
  11. * @author solu
  12. * @param $trxId
  13. * @return array
  14. */
  15. public function getByTrxId($trxId) {
  16. $list = $this->objTable->getAll(['redpack_trx_id' => $trxId], [
  17. '_field' => 'id, user_id, player, quantity_int, update_time_int, best, status',
  18. '_sortKey' => 'id DESC',
  19. ]);
  20. if (!$list) {
  21. return [];
  22. }
  23. $userIds = array_column($list, 'user_id');
  24. $objUser = new TableHelper('user_info', 'dw_chat');
  25. $users = $objUser->getAll(['user_id' => $userIds], ['_field' => 'user_id, nick_name, cover_photo']);
  26. $users = arrayFormatKey($users, 'user_id');
  27. foreach ($list as $k => $v) {
  28. $_u = $users[$v['user_id']];
  29. $v['nick_name'] = $_u['nick_name'];
  30. $v['cover_photo'] = awsReplaceImg($_u['cover_photo']);
  31. if ($v['update_time_int']) {
  32. $v['update_time_int'] = intval($v['update_time_int'] / 1000);
  33. } else {
  34. $v['update_time_int'] = time() * 1000;
  35. }
  36. $list[$k] = $v;
  37. }
  38. return $list;
  39. }
  40. /**
  41. * 用户是否已领取
  42. * @param $userId
  43. * @param $trxId
  44. * @return int
  45. */
  46. public function userGrabbed($userId, $trxId) {
  47. if (!$userId) {
  48. return 0;
  49. }
  50. return $this->objTable->getCount(['redpack_trx_id' => $trxId, 'user_id' => $userId]);
  51. }
  52. /**
  53. * 更新最佳
  54. * @author solu
  55. * @param $trxId
  56. * @throws DB_Exception
  57. */
  58. public function updateBest($trxId) {
  59. if (!$trxId) {
  60. return;
  61. }
  62. $id = $this->objTable->getOne(['redpack_trx_id' => $trxId], [
  63. '_field' => 'id',
  64. '_sortKey' => 'quantity_int DESC',
  65. ]);
  66. if (!$id) {
  67. return;
  68. }
  69. $this->objTable->updateObject(['best' => 1], ['id' => $id]);
  70. }
  71. }