LiveStudio.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 traits\ModelTrait;
  14. use think\Db;
  15. use think\Url;
  16. use app\wap\model\special\Special;
  17. use service\SystemConfigService;
  18. use app\wap\model\user\WechatUser;
  19. use app\wap\model\user\User;
  20. use app\wap\model\routine\RoutineTemplate;
  21. use service\WechatTemplateService;
  22. use app\wap\model\wap\SmsTemplate;
  23. use app\wap\model\store\StoreOrder;
  24. use app\index\controller\PushJob;
  25. /**直播信息表
  26. * Class LiveStudio
  27. * @package app\wap\model\live
  28. */
  29. class LiveStudio extends ModelBasic
  30. {
  31. use ModelTrait;
  32. /**列表获取
  33. * @param $limit
  34. * @param $is_member
  35. * @return array
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. * @throws \think\exception\DbException
  39. */
  40. public static function getLiveList($limit, $is_member)
  41. {
  42. $model = self::where(['l.is_del' => 0, 's.is_show' => 1, 's.status' => 1, 's.is_del' => 0])->alias('l')
  43. ->join('special s', 's.id = l.special_id');
  44. if (!$is_member) $model = $model->where(['s.is_mer_visible' => 0]);
  45. $list = $model->field(['s.title', 's.image', 's.browse_count', 's.status','s.fake_sales', 's.is_mer_visible', 'l.is_play', 's.id', 'l.playback_record_id', 'l.start_play_time'])
  46. ->limit($limit)->order('s.sort DESC,l.sort DESC,l.add_time DESC')->select();
  47. $list = count($list) > 0 ? $list->toArray() : [];
  48. foreach ($list as $key => &$item) {
  49. if ($item['playback_record_id'] && !$item['is_play']) {
  50. $item['status'] = 2;//没在直播 有回放
  51. } else if ($item['is_play']) {
  52. $item['status'] = 1;//正在直播
  53. } else if (!$item['playback_record_id'] && !$item['is_play'] && strtotime($item['start_play_time']) > time()) {
  54. $item['status'] = 3;//等待直播
  55. } else {
  56. $item['status'] = 4;//直播结束
  57. }
  58. if ($item['start_play_time']) {
  59. $item['start_play_time'] = date('m-d H:i', strtotime($item['start_play_time']));
  60. }
  61. $count = Special::learning_records($item['id']);
  62. $item['records'] = processingData(bcadd($count, $item['fake_sales'], 0));
  63. }
  64. return $list;
  65. }
  66. /**获取单个直播
  67. * @param $live_one_id
  68. * @return array|false|\PDOStatement|string|\think\Model
  69. * @throws \think\db\exception\DataNotFoundException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. * @throws \think\exception\DbException
  72. */
  73. public static function getLiveOne($live_one_id)
  74. {
  75. return self::where(['l.is_del' => 0, 's.is_show' => 1,'s.status' => 1, 's.is_del' => 0])->alias('l')
  76. ->join('special s', 's.id = l.special_id')
  77. ->field(['s.title', 's.image', 'l.is_play', 's.id'])
  78. ->where('l.is_play', 1)->where('s.id', $live_one_id)
  79. ->order('l.sort DESC,l.add_time DESC')->find();
  80. }
  81. public function getStartPlayTimeAttr($time)
  82. {
  83. return $time;//返回create_time原始数据,不进行时间戳转换。
  84. }
  85. /**直播提醒
  86. * @return bool
  87. * @throws \think\db\exception\DataNotFoundException
  88. * @throws \think\db\exception\ModelNotFoundException
  89. * @throws \think\exception\DbException
  90. */
  91. public static function userRemindList()
  92. {
  93. $data = self::where(['l.is_del' => 0, 'l.is_remind' => 1, 'l.is_reminded' => 0, 's.is_show' => 1,'s.status' => 1, 's.is_del' => 0])->alias('l')
  94. ->join('special s', 's.id = l.special_id')->field('l.*,s.pay_type,s.member_pay_type')->select();
  95. $data = count($data) > 0 ? $data->toArray() : [];
  96. if (count($data) <= 0) return true;
  97. foreach ($data as $key => $item) {
  98. $start_play_time = strtotime($item['start_play_time']);
  99. if (bcsub($start_play_time, time(), 0) > bcmul($item['remind_time'], 60, 0)) continue;
  100. self::where('id', $item['id'])->update(['is_reminded' => 1]);
  101. if (bcsub($start_play_time, time(), 0) > 0) {
  102. if ($item['pay_type'] == 1 && $item['member_pay_type'] == 1) {
  103. $orderList = StoreOrder::where(['cart_id' => $item['special_id'], 'type' => 0])->column("uid");
  104. } elseif ($item['pay_type'] == 1 && $item['member_pay_type'] == 0) {
  105. $order = StoreOrder::where(['cart_id' => $item['special_id'], 'type' => 0])->column("uid");
  106. $user = User::where('is_h5user', 0)->where('level', 1)->column("uid");
  107. $orderList = array_merge($order, $user);
  108. } else {
  109. $orderList = User::where('is_h5user', 0)->column("uid");
  110. }
  111. if(count($orderList)<0) continue;
  112. $orderList = array_unique($orderList);
  113. $dat['id'] = $item['special_id'];
  114. $dat['site_url'] = SystemConfigService::get('site_url');
  115. $dat['live_title'] = $item['live_title'];
  116. $dat['start_play_time'] = $item['start_play_time'];
  117. foreach ($orderList as $k => $v) {
  118. $dat['uid'] = $v;
  119. PushJob::actionWithDoPinkJob($dat, 'doLiveStudioJob');
  120. }
  121. }
  122. }
  123. }
  124. }