LiveReward.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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\merchant\model\live;
  12. /**
  13. * 直播间礼物
  14. */
  15. use basic\ModelBasic;
  16. use service\SystemConfigService;
  17. use traits\ModelTrait;
  18. use app\merchant\model\user\User;
  19. use app\merchant\model\live\LiveGift;
  20. use app\merchant\model\merchant\Merchant;
  21. class LiveReward extends ModelBasic
  22. {
  23. use ModelTrait;
  24. public static function getLiveRewardList($where)
  25. {
  26. $data = self::setWhere($where, 'g')->field('g.total_price,g.uid,g.gift_id,g.id,g.live_id,from_unixtime(g.add_time) as add_time,g.gift_price,g.gift_num,u.avatar,u.nickname,l.live_title,s.mer_id')->order('g.add_time desc')
  27. ->page((int)$where['page'], (int)$where['limit'])->select();
  28. $data = count($data) ? $data->toArray() : [];
  29. foreach ($data as &$item) {
  30. $live_gift = LiveGift::liveGiftOne($item['gift_id']);
  31. $item['gift_name'] = $live_gift ? $live_gift['live_gift_name'] : "";
  32. $item['gift_image'] = $live_gift ? $live_gift['live_gift_show_img'] : "";
  33. }
  34. $count = self::setWhere($where, 'g')->count();
  35. return compact('data', 'count');
  36. }
  37. //设置条件
  38. public static function setWhere($where, $alert = '', $model = null)
  39. {
  40. $model = $model === null ? new self() : $model;
  41. if ($alert) $model = $model->alias($alert);
  42. $alert = $alert ? $alert . '.' : '';
  43. $model->whereIn($alert . 'is_show', [0, 1]);
  44. $model->join('__LIVE_STUDIO__ l', $alert . 'live_id = l.id');
  45. $model->join('__USER__ u', $alert . 'uid = u.uid');
  46. $model->join('__SPECIAL__ s', 's.id = l.special_id');
  47. if (isset($where['live_id']) && $where['live_id']) {
  48. $model->where($alert . 'live_id', $where['live_id']);
  49. }
  50. if (isset($where['gift_id']) && $where['gift_id']) {
  51. $model->where($alert . 'gift_id', $where['gift_id']);
  52. }
  53. if (isset($where['mer_id']) && $where['mer_id']) {
  54. $model->where('s.mer_id', $where['mer_id']);
  55. }
  56. if (isset($where['user_info']) && $where['user_info']) {
  57. $userinfo = User::whereLike('nickname', "%" . $where['user_info'] . "%")->whereOr('phone', $where['user_info'])->field('uid')->find();
  58. $model->where($alert . 'uid', $userinfo ? $userinfo['uid'] : 0);
  59. }
  60. if (isset($where['date']) && ($where['date'] != '' || $where['date'] != 0)) {
  61. $where['data'] = $where['date'];
  62. $model = self::getModelTime($where, $model, $alert . 'add_time');
  63. }
  64. return $model;
  65. }
  66. public static function getBadge($where)
  67. {
  68. $data = self::setWhere($where, 'g')->field(['sum(g.total_price) as total_price', 'sum(g.gift_num) as gift_num'])->find();
  69. $data = $data ? $data->toArray() : [];
  70. return [
  71. [
  72. 'name' => '虚拟币总额',
  73. 'field' => '个',
  74. 'count' => $data['total_price'],
  75. 'background_color' => 'layui-bg-blue',
  76. 'col' => 3
  77. ],
  78. [
  79. 'name' => '礼物数量',
  80. 'field' => '件',
  81. 'count' => $data['gift_num'],
  82. 'background_color' => 'layui-bg-blue',
  83. 'col' => 3
  84. ]
  85. ];
  86. }
  87. //设置条件
  88. public static function setRewardWhere($where, $alert = '', $model = null)
  89. {
  90. $model = $model === null ? new self() : $model;
  91. if ($alert) $model = $model->alias($alert);
  92. $alert = $alert ? $alert . '.' : '';
  93. $model->whereIn($alert . 'is_show', [0, 1]);
  94. $model->where($alert . 'is_extract', 0);
  95. $model->join('__LIVE_STUDIO__ l', $alert . 'live_id = l.id');
  96. $model->join('__SPECIAL__ s', 's.id = l.special_id');
  97. if (isset($where['live_id']) && $where['live_id']) {
  98. $model->where($alert . 'live_id', $where['live_id']);
  99. }
  100. if (isset($where['mer_id']) && $where['mer_id']) {
  101. $model->where('s.mer_id', $where['mer_id']);
  102. }
  103. if (isset($where['date']) && ($where['date'] != '' || $where['date'] != 0)) {
  104. $where['data'] = $where['date'];
  105. $model = self::getModelTime($where, $model, $alert . 'add_time');
  106. }
  107. return $model->group('g.live_id');
  108. }
  109. public static function get_mer_live_reward_list($where)
  110. {
  111. $data = self::setRewardWhere($where, 'g')->field('sum(g.total_price) as total_price,g.live_id,l.stream_name,l.live_title,l.live_image')->order('g.add_time desc')
  112. ->page((int)$where['page'], (int)$where['limit'])->select();
  113. $data = count($data) ? $data->toArray() : [];
  114. $gold_divide = Merchant::where('id', $where['mer_id'])->value('gold_divide');
  115. $gold_divide = bcdiv($gold_divide, 100, 2);
  116. foreach ($data as $key => &$value) {
  117. $value['rawal'] = bcmul($value['total_price'], $gold_divide, 0);
  118. }
  119. $count = self::setRewardWhere($where, 'g')->count();
  120. return compact('data', 'count');
  121. }
  122. public static function get_mer_live_reward($where)
  123. {
  124. $data = self::setRewardWhere($where, 'g')->field('sum(g.total_price) as total_price')->find();
  125. return $data;
  126. }
  127. }