LiveReward.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\model\live;
  12. use basic\ModelBasic;
  13. use service\SystemConfigService;
  14. use traits\ModelTrait;
  15. use app\wap\model\user\User;
  16. /**直播间礼物
  17. * Class LiveReward
  18. * @package app\wap\model\live
  19. */
  20. class LiveReward extends ModelBasic
  21. {
  22. use ModelTrait;
  23. /**直播礼物排行榜
  24. * @param $where
  25. * @param int $page
  26. * @param int $limit
  27. * @return array
  28. * @throws \think\db\exception\DataNotFoundException
  29. * @throws \think\db\exception\ModelNotFoundException
  30. * @throws \think\exception\DbException
  31. */
  32. public static function getLiveRewardList($where, $page = 0, $limit = 10)
  33. {
  34. $model = self::where('live_id', $where['live_id'])->where('is_show', 1);
  35. $list = $model->field('sum(total_price) as total_price,uid,gift_id,id,gift_price,gift_num')->group('uid')->order('total_price desc')->page($page, $limit)->select();
  36. $list = count($list) ? $list->toArray() : [];
  37. $gold_info = SystemConfigService::more(['gold_name', 'gold_image']);
  38. foreach ($list as &$item) {
  39. $userinfo = User::where('uid', $item['uid'])->field(['nickname', 'avatar'])->find();
  40. if ($userinfo) {
  41. $item['nickname'] = $userinfo['nickname'];
  42. $item['avatar'] = $userinfo['avatar'];
  43. } else {
  44. $item['nickname'] = '';
  45. $item['avatar'] = '';
  46. }
  47. }
  48. $page--;
  49. return ['list' => $list, 'page' => $page, 'gold_info' => $gold_info];
  50. }
  51. /**插入打赏数据
  52. * @param $data
  53. * @return bool|int|string
  54. */
  55. public static function insertLiveRewardData($data)
  56. {
  57. if (!$data || !is_array($data)) {
  58. return false;
  59. }
  60. return self::insertGetId($data);
  61. }
  62. /**获取当前用户打赏
  63. * @param array $where
  64. * @return array|bool
  65. * @throws \think\Exception
  66. * @throws \think\db\exception\DataNotFoundException
  67. * @throws \think\db\exception\ModelNotFoundException
  68. * @throws \think\exception\DbException
  69. */
  70. public static function getLiveRewardOne(array $where)
  71. {
  72. if (!$where) return false;
  73. $data = self::where($where)->field('sum(total_price) as total_price,uid,gift_id,id')->group('uid')->find();
  74. $data = $data ? $data->toArray() : [];
  75. if (!$data) return $data;
  76. $userinfo = User::where('uid', $data['uid'])->field(['nickname', 'avatar'])->find();
  77. if ($userinfo) {
  78. $data['nickname'] = $userinfo['nickname'];
  79. $data['avatar'] = $userinfo['avatar'];
  80. } else {
  81. $data['nickname'] = '';
  82. $data['avatar'] = '';
  83. }
  84. return $data;
  85. }
  86. }