RedpackLog.php 1.9 KB

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