Live.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace app\home\controller;
  3. use think\facade\View;
  4. use think\facade\Lang;
  5. use think\facade\Db;
  6. /**
  7. *
  8. *
  9. * ----------------------------------------------------------------------------
  10. *
  11. * 控制器
  12. */
  13. class Live extends BaseMall
  14. {
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/live.lang.php');
  19. }
  20. public function index()
  21. {
  22. // View::assign('floor_block', $floor_block);
  23. return View::fetch($this->template_dir . 'index');
  24. }
  25. public function get_live_list()
  26. {
  27. $state = input('param.state');
  28. $goodsclass_model = model('goodsclass');
  29. //获取分类
  30. $cache_key = 'api-member-live';
  31. $temp = rcache($cache_key);
  32. if (empty($temp)) {
  33. $gc_id_array = Db::name('live_apply_goods')->distinct(true)->where('1=1')->column('gc_id_1');
  34. $goodsclass_list = array();
  35. $live_apply_ids = array();
  36. foreach ($gc_id_array as $v) {
  37. $goodsclass_list[] = $goodsclass_model->getGoodsclassInfoById($v);
  38. $live_apply_ids[$v] = Db::name('live_apply_goods')->distinct(true)->where('gc_id_1', $v)->column('live_apply_id');
  39. }
  40. $temp = array('goodsclass_list' => $goodsclass_list, 'live_apply_ids' => $live_apply_ids);
  41. wcache($cache_key, $temp);
  42. }
  43. $goodsclass_list = $temp['goodsclass_list'];
  44. $live_apply_ids = $temp['live_apply_ids'];
  45. $gc_id = intval(input('param.gc_id'));
  46. $keyword = input('param.keyword');
  47. $goods_model = model('goods');
  48. $live_apply_model = model('live_apply');
  49. $condition = array();
  50. $condition[] = array('live_apply_state', '=', 1);
  51. // $condition[] = array('live_apply_end_time', '>', TIMESTAMP);
  52. switch ($state) {
  53. case 2: //未开播
  54. $condition[] = array('live_apply_play_time', '>', TIMESTAMP);
  55. break;
  56. case 3: //已结束
  57. $condition[] = array('live_apply_end_time', '<', TIMESTAMP);
  58. $condition[] = array('live_apply_video', '<>', '');
  59. break;
  60. default: //直播中
  61. $condition[] = array('live_apply_play_time', '<', TIMESTAMP);
  62. $condition[] = array('live_apply_end_time', '>', TIMESTAMP);
  63. break;
  64. }
  65. if ($gc_id > 0) {
  66. $condition[] = array('live_apply_id', 'in', isset($live_apply_ids[$gc_id]) ? $live_apply_ids[$gc_id] : array());
  67. }
  68. if ($keyword) {
  69. $condition[] = array('live_apply_id', 'in', Db::name('live_apply_goods')->distinct(true)->where(array(array('store_name|goods_name|gc_name', 'like', $keyword)))->column('live_apply_id'));
  70. }
  71. $live_apply_list = $live_apply_model->getLiveApplyList($condition);
  72. $store_model = model('store');
  73. foreach ($live_apply_list as $key => $val) {
  74. $live_apply_list[$key]['live_apply_play_time_text'] = date('Y-m-d H:i', $val['live_apply_play_time']);
  75. $live_apply_list[$key]['state'] = 1;
  76. if ($val['live_apply_play_time'] > TIMESTAMP) {
  77. $live_apply_list[$key]['state'] = 2;
  78. } elseif ($val['live_apply_end_time'] < TIMESTAMP) {
  79. $live_apply_list[$key]['state'] = 3;
  80. }
  81. if ($val['live_apply_user_type'] == 2) {
  82. $store_info = $store_model->getStoreInfoByID($val['live_apply_user_id']);
  83. if (!$store_info) {
  84. unset($live_apply_list[$key]);
  85. continue;
  86. }
  87. $live_apply_list[$key]['store_name'] = $store_info['store_name'];
  88. $live_apply_list[$key]['store_avatar'] = get_store_logo($store_info['store_avatar']);
  89. $live_apply_list[$key]['area_info'] = $store_info['area_info'];
  90. }
  91. $live_apply_list[$key]['live_apply_cover_image_url'] = ds_get_pic(ATTACH_COMMON, config('ds_config.default_goods_image'));
  92. if ($val['live_apply_cover_video']) {
  93. $live_apply_list[$key]['live_apply_cover_video_url'] = ds_get_pic(ATTACH_LIVE_APPLY . '/' . $val['live_apply_user_id'], $val['live_apply_cover_video']);
  94. } elseif ($val['live_apply_cover_image']) {
  95. $live_apply_list[$key]['live_apply_cover_image_url'] = ds_get_pic(ATTACH_LIVE_APPLY . '/' . $val['live_apply_user_id'], $val['live_apply_cover_image']);
  96. }
  97. $live_apply_goods_list = $live_apply_model->getLiveApplyGoodsList(array(array('live_apply_id', '=', $val['live_apply_id'])));
  98. $live_apply_list[$key]['goods_list'] = array();
  99. foreach ($live_apply_goods_list as $v) {
  100. $goods_info = $goods_model->getGoodsCommonInfoByID($v['goods_commonid']);
  101. if ($goods_info && $goods_info['goods_state'] == 1 && $goods_info['goods_verify'] == 1) {
  102. $goods_info['goods_image'] = goods_cthumb($goods_info['goods_image']);
  103. $live_apply_list[$key]['goods_list'][] = $goods_info;
  104. }
  105. }
  106. }
  107. $result = array('goodsclass_list' => $goodsclass_list, 'live_apply_list' => $live_apply_list);
  108. $extend_data = array();
  109. $extend_data['hasmore'] = false;
  110. $current_page = $live_apply_model->page_info->currentPage();
  111. if ($current_page <= 0) {
  112. $current_page = 1;
  113. }
  114. if ($current_page >= $live_apply_model->page_info->lastPage()) {
  115. $extend_data['hasmore'] = false;
  116. } else {
  117. $extend_data['hasmore'] = true;
  118. }
  119. $result = array_merge($result, $extend_data);
  120. ds_json_encode(10000, '', $result);
  121. }
  122. }