Live.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. * DSMall多用户商城
  9. * ============================================================================
  10. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  11. * 网站地址: http://www.csdeshang.com
  12. * ----------------------------------------------------------------------------
  13. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  14. * 不允许对程序代码以任何形式任何目的的再发布。
  15. * ============================================================================
  16. * 控制器
  17. */
  18. class Live extends BaseMall {
  19. public function initialize() {
  20. parent::initialize();
  21. Lang::load(base_path() . 'home/lang/'.config('lang.default_lang').'/live.lang.php');
  22. }
  23. public function index() {
  24. // View::assign('floor_block', $floor_block);
  25. return View::fetch($this->template_dir . 'index');
  26. }
  27. public function get_live_list() {
  28. $state=input('param.state');
  29. $goodsclass_model = model('goodsclass');
  30. //获取分类
  31. $cache_key = 'api-member-live';
  32. $temp = rcache($cache_key);
  33. if (empty($temp)) {
  34. $gc_id_array = Db::name('live_apply_goods')->distinct(true)->where('1=1')->column('gc_id_1');
  35. $goodsclass_list = array();
  36. $live_apply_ids = array();
  37. foreach ($gc_id_array as $v) {
  38. $goodsclass_list[] = $goodsclass_model->getGoodsclassInfoById($v);
  39. $live_apply_ids[$v] = Db::name('live_apply_goods')->distinct(true)->where('gc_id_1', $v)->column('live_apply_id');
  40. }
  41. $temp = array('goodsclass_list' => $goodsclass_list, 'live_apply_ids' => $live_apply_ids);
  42. wcache($cache_key, $temp);
  43. }
  44. $goodsclass_list = $temp['goodsclass_list'];
  45. $live_apply_ids = $temp['live_apply_ids'];
  46. $gc_id = intval(input('param.gc_id'));
  47. $keyword = input('param.keyword');
  48. $goods_model = model('goods');
  49. $live_apply_model = model('live_apply');
  50. $condition = array();
  51. $condition[] = array('live_apply_state', '=', 1);
  52. // $condition[] = array('live_apply_end_time', '>', TIMESTAMP);
  53. switch($state){
  54. case 2://未开播
  55. $condition[] = array('live_apply_play_time', '>', TIMESTAMP);
  56. break;
  57. case 3://已结束
  58. $condition[] = array('live_apply_end_time', '<', TIMESTAMP);
  59. $condition[] = array('live_apply_video','<>','');
  60. break;
  61. default://直播中
  62. $condition[] = array('live_apply_play_time', '<', TIMESTAMP);
  63. $condition[] = array('live_apply_end_time', '>', TIMESTAMP);
  64. break;
  65. }
  66. if ($gc_id > 0) {
  67. $condition[] = array('live_apply_id', 'in', isset($live_apply_ids[$gc_id]) ? $live_apply_ids[$gc_id] : array());
  68. }
  69. if ($keyword) {
  70. $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'));
  71. }
  72. $live_apply_list = $live_apply_model->getLiveApplyList($condition);
  73. $store_model = model('store');
  74. foreach ($live_apply_list as $key => $val) {
  75. $live_apply_list[$key]['live_apply_play_time_text'] = date('Y-m-d H:i',$val['live_apply_play_time']);
  76. $live_apply_list[$key]['state'] = 1;
  77. if($val['live_apply_play_time']>TIMESTAMP){
  78. $live_apply_list[$key]['state'] = 2;
  79. }elseif($val['live_apply_end_time']<TIMESTAMP){
  80. $live_apply_list[$key]['state'] = 3;
  81. }
  82. if ($val['live_apply_user_type'] == 2) {
  83. $store_info = $store_model->getStoreInfoByID($val['live_apply_user_id']);
  84. if (!$store_info) {
  85. unset($live_apply_list[$key]);
  86. continue;
  87. }
  88. $live_apply_list[$key]['store_name'] = $store_info['store_name'];
  89. $live_apply_list[$key]['store_avatar'] = get_store_logo($store_info['store_avatar']);
  90. $live_apply_list[$key]['area_info'] = $store_info['area_info'];
  91. }
  92. $live_apply_list[$key]['live_apply_cover_image_url'] = ds_get_pic(ATTACH_COMMON,config('ds_config.default_goods_image'));
  93. if ($val['live_apply_cover_video']) {
  94. $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']);
  95. } elseif ($val['live_apply_cover_image']) {
  96. $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']);
  97. }
  98. $live_apply_goods_list = $live_apply_model->getLiveApplyGoodsList(array(array('live_apply_id', '=', $val['live_apply_id'])));
  99. $live_apply_list[$key]['goods_list'] = array();
  100. foreach ($live_apply_goods_list as $v) {
  101. $goods_info = $goods_model->getGoodsCommonInfoByID($v['goods_commonid']);
  102. if ($goods_info && $goods_info['goods_state'] == 1 && $goods_info['goods_verify'] == 1) {
  103. $goods_info['goods_image'] = goods_cthumb($goods_info['goods_image']);
  104. $live_apply_list[$key]['goods_list'][] = $goods_info;
  105. }
  106. }
  107. }
  108. $result = array('goodsclass_list' => $goodsclass_list, 'live_apply_list' => $live_apply_list);
  109. $extend_data=array();
  110. $extend_data['hasmore'] = false;
  111. $current_page = $live_apply_model->page_info->currentPage();
  112. if ($current_page <= 0) {
  113. $current_page = 1;
  114. }
  115. if ($current_page >= $live_apply_model->page_info->lastPage()) {
  116. $extend_data['hasmore'] = false;
  117. }
  118. else {
  119. $extend_data['hasmore'] = true;
  120. }
  121. $result = array_merge($result, $extend_data);
  122. ds_json_encode(10000, '', $result);
  123. }
  124. }