LiveReward.php 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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\admin\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. use app\admin\model\live\LiveGift;
  20. class LiveReward extends ModelBasic
  21. {
  22. use ModelTrait;
  23. public static function getLiveRewardList($where)
  24. {
  25. $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')->order('add_time desc')
  26. ->page((int)$where['page'],(int)$where['limit'])->select();
  27. $data = count($data) ? $data->toArray() : [];
  28. foreach ($data as &$item) {
  29. $live_gift = LiveGift::liveGiftOne($item['gift_id']);
  30. $item['gift_name'] = $live_gift ? $live_gift['live_gift_name'] : "";
  31. $item['gift_image'] = $live_gift ? $live_gift['live_gift_show_img'] : "";
  32. }
  33. $count = self::setWhere($where,'g')->count();
  34. return compact('data','count');
  35. }
  36. //设置条件
  37. public static function setWhere($where, $alert = '', $model = null)
  38. {
  39. $model = $model === null ? new self() : $model;
  40. if ($alert) $model = $model->alias($alert);
  41. $alert = $alert ? $alert . '.' : '';
  42. $model->whereIn($alert.'is_show',[0,1]);
  43. $model->join('__LIVE_STUDIO__ l',$alert.'live_id = l.id');
  44. $model->join('__USER__ u',$alert.'uid = u.uid');
  45. $model->join('__SPECIAL__ s','s.id = l.special_id');
  46. if (isset($where['admin_id']) && $where['admin_id']) {
  47. $model->where('s.admin_id',$where['admin_id']);
  48. }
  49. if (isset($where['live_id']) && $where['live_id']) {
  50. $model->where($alert.'live_id',$where['live_id']);
  51. }
  52. if (isset($where['gift_id']) && $where['gift_id']) {
  53. $model->where($alert.'gift_id',$where['gift_id']);
  54. }
  55. if (isset($where['user_info']) && $where['user_info']) {
  56. $userinfo = User::whereLike('nickname' ,"%".$where['user_info']."%")->whereOr('phone',$where['user_info'])->field('uid')->find();
  57. $model->where($alert.'uid',$userinfo ? $userinfo['uid'] : 0);
  58. }
  59. if (isset($where['date']) && ($where['date'] != '' || $where['date'] != 0)) {
  60. $where['data'] = $where['date'];
  61. $model = self::getModelTime($where, $model, $alert . 'add_time');
  62. }
  63. return $model;
  64. }
  65. public static function getBadge($where)
  66. {
  67. $data = self::setWhere($where,'g')->field(['sum(g.total_price) as total_price','sum(g.gift_num) as gift_num'])->find();
  68. $data = $data ? $data->toArray() : [];
  69. return [
  70. [
  71. 'name' => '虚拟币总额',
  72. 'field' => '个',
  73. 'count' => $data['total_price'],
  74. 'background_color' => 'layui-bg-blue',
  75. 'col' => 3
  76. ],
  77. [
  78. 'name' => '礼物数量',
  79. 'field' => '件',
  80. 'count' => $data['gift_num'],
  81. 'background_color' => 'layui-bg-blue',
  82. 'col' => 3
  83. ]
  84. ];
  85. }
  86. }