RedpackLog.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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, create_time, 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'] = $_u['cover_photo'];
  31. $_t = strtotime($v['create_time']);
  32. $v['create_time'] = date('H:i', $_t);
  33. $v['create_time_int'] = $_t;
  34. $list[$k] = $v;
  35. }
  36. return $list;
  37. }
  38. /**
  39. * 用户是否已领取
  40. * @param $userId
  41. * @param $trxId
  42. * @return int
  43. */
  44. public function userGrabbed($userId, $trxId) {
  45. if (!$userId) {
  46. return 0;
  47. }
  48. return $this->objTable->getCount(['redpack_trx_id' => $trxId, 'user_id' => $userId]);
  49. }
  50. /**
  51. * 更新最佳
  52. * @author solu
  53. * @param $trxId
  54. * @throws DB_Exception
  55. */
  56. public function updateBest($trxId) {
  57. if (!$trxId) {
  58. return;
  59. }
  60. $id = $this->objTable->getOne(['redpack_trx_id' => $trxId], [
  61. '_field' => 'id',
  62. '_sortKey' => 'quantity_int DESC',
  63. ]);
  64. if (!$id) {
  65. return;
  66. }
  67. $this->objTable->updateObject(['best' => 1], ['id' => $id]);
  68. }
  69. }