LiveReward.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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. /**
  13. * 直播间礼物
  14. */
  15. use basic\ModelBasic;
  16. use service\SystemConfigService;
  17. use traits\ModelTrait;
  18. use app\wap\model\user\User;
  19. class LiveReward extends ModelBasic
  20. {
  21. use ModelTrait;
  22. public static function getLiveRewardList($where,$page = 0,$limit = 10)
  23. {
  24. $model = self::where('live_id',$where['live_id'])->where('is_show',1);
  25. $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();
  26. $list = count($list) ? $list->toArray() : [];
  27. $gold_info = SystemConfigService::more(['gold_name','gold_image']);
  28. foreach ($list as &$item) {
  29. $userinfo = User::where('uid', $item['uid'])->field(['nickname', 'avatar'])->find();
  30. if ($userinfo) {
  31. $item['nickname'] = $userinfo['nickname'];
  32. $item['avatar'] = $userinfo['avatar'];
  33. } else {
  34. $item['nickname'] = '';
  35. $item['avatar'] = '';
  36. }
  37. }
  38. $page--;
  39. return ['list'=>$list,'page'=> $page,'gold_info' => $gold_info];
  40. }
  41. /**插入打赏数据
  42. * @param $data
  43. * @return bool|int|string
  44. */
  45. public static function insertLiveRewardData($data)
  46. {
  47. if (!$data || !is_array($data)) {
  48. return false;
  49. }
  50. return self::insertGetId($data);
  51. }
  52. /**获取当前用户打赏
  53. * @param array $where
  54. * @return array|bool
  55. * @throws \think\Exception
  56. * @throws \think\db\exception\DataNotFoundException
  57. * @throws \think\db\exception\ModelNotFoundException
  58. * @throws \think\exception\DbException
  59. */
  60. public static function getLiveRewardOne(array $where)
  61. {
  62. if (!$where) return false;
  63. $data = self::where($where)->field('sum(total_price) as total_price,uid,gift_id,id')->group('uid')->find();
  64. $data = $data ? $data->toArray() : [];
  65. if (!$data) return $data;
  66. $userinfo = User::where('uid', $data['uid'])->field(['nickname', 'avatar'])->find();
  67. if ($userinfo) {
  68. $data['nickname'] = $userinfo['nickname'];
  69. $data['avatar'] = $userinfo['avatar'];
  70. } else {
  71. $data['nickname'] = '';
  72. $data['avatar'] = '';
  73. }
  74. return $data;
  75. }
  76. }