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