Live.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 公共数据控制器
  10. */
  11. class Live extends MobileMall
  12. {
  13. public function initialize()
  14. {
  15. parent::initialize();
  16. }
  17. /**
  18. * @api {POST} api/Live/get_live_list 获取直播列表
  19. * @apiVersion 1.0.0
  20. * @apiGroup Live
  21. * @apiParam {Int} page 页码
  22. * @apiParam {Int} per_page 每页数量
  23. * @apiParam {Int} gc_id 分类ID
  24. * @apiParam {String} keyword 关键词
  25. *
  26. * @apiSuccess {String} code 返回码,10000为成功
  27. * @apiSuccess {String} message 返回消息
  28. * @apiSuccess {Object} result 返回数据
  29. * @apiSuccess {Int} result.page_total 总页数
  30. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  31. * @apiSuccess {Object[]} result.goodsclass_list 分类列表
  32. * @apiSuccess {Object[]} result.live_apply_list 直播列表
  33. * @apiSuccess {String} result.live_apply_list.store_name 店铺名称
  34. * @apiSuccess {String} result.live_apply_list.store_avatar 店铺头像
  35. * @apiSuccess {String} result.live_apply_list.area_info 店铺地区
  36. * @apiSuccess {String} result.live_apply_list.live_apply_cover_image_url 直播图片封面地址
  37. * @apiSuccess {String} result.live_apply_list.live_apply_cover_video_url 直播视频封面地址
  38. * @apiSuccess {Int} result.live_apply_list.goods_count 直播商品数
  39. * @apiSuccess {String} result.live_apply_list.gc_name 直播商品分类名称
  40. * @apiSuccess {Object[]} result.live_apply_list.goods_list 直播商品列表
  41. */
  42. public function get_live_list()
  43. {
  44. $condition = array();
  45. $condition[] = array('live_apply_state', '=', 1);
  46. $condition[] = array('live_apply_end_time', '>', TIMESTAMP);
  47. $goodsclass_model = model('goodsclass');
  48. //获取分类
  49. $cache_key = 'api-member-live';
  50. $temp = rcache($cache_key);
  51. if (empty($temp)) {
  52. $gc_id_array = Db::name('live_apply_goods')->alias('live_apply_goods')->join('live_apply live_apply', 'live_apply.live_apply_id=live_apply_goods.live_apply_id')->distinct(true)->where($condition)->column('gc_id_1');
  53. $goodsclass_list = array();
  54. $live_apply_ids = array();
  55. foreach ($gc_id_array as $v) {
  56. $temp = $goodsclass_model->getGoodsclassInfoById($v);
  57. if ($temp) {
  58. $goodsclass_list[] = $temp;
  59. }
  60. $live_apply_ids[$v] = Db::name('live_apply_goods')->distinct(true)->where('gc_id_1', $v)->column('live_apply_id');
  61. }
  62. $temp = array('goodsclass_list' => $goodsclass_list, 'live_apply_ids' => $live_apply_ids);
  63. wcache($cache_key, $temp);
  64. }
  65. $goodsclass_list = $temp['goodsclass_list'];
  66. $live_apply_ids = $temp['live_apply_ids'];
  67. $gc_id = intval(input('param.gc_id'));
  68. $keyword = input('param.keyword');
  69. $goods_model = model('goods');
  70. $live_apply_model = model('live_apply');
  71. if ($gc_id > 0) {
  72. $condition[] = array('live_apply_id', 'in', isset($live_apply_ids[$gc_id]) ? $live_apply_ids[$gc_id] : array());
  73. }
  74. if ($keyword) {
  75. $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'));
  76. }
  77. $live_apply_list = $live_apply_model->getLiveApplyList($condition);
  78. $store_model = model('store');
  79. foreach ($live_apply_list as $key => $val) {
  80. if ($val['live_apply_user_type'] == 2) {
  81. $store_info = $store_model->getStoreInfoByID($val['live_apply_user_id']);
  82. if (!$store_info) {
  83. unset($live_apply_list[$key]);
  84. continue;
  85. }
  86. $live_apply_list[$key]['store_name'] = $store_info['store_name'];
  87. $live_apply_list[$key]['store_avatar'] = get_store_logo($store_info['store_avatar']);
  88. $live_apply_list[$key]['area_info'] = $store_info['area_info'];
  89. }
  90. $live_apply_list[$key]['live_apply_cover_image_url'] = ds_get_pic(ATTACH_COMMON, config('ds_config.default_goods_image'));
  91. if ($val['live_apply_cover_video']) {
  92. $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']);
  93. } elseif ($val['live_apply_cover_image']) {
  94. $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']);
  95. }
  96. $live_apply_goods_list = $live_apply_model->getLiveApplyGoodsList(array(array('live_apply_id', '=', $val['live_apply_id'])));
  97. $live_apply_list[$key]['goods_count'] = count($live_apply_goods_list);
  98. $live_apply_list[$key]['gc_name'] = '';
  99. $live_apply_list[$key]['goods_list'] = array();
  100. foreach ($live_apply_goods_list as $v) {
  101. if (!$live_apply_list[$key]['gc_name']) {
  102. $gc_info = $goodsclass_model->getGoodsclassInfoById($v['gc_id_2']);
  103. if ($gc_info) {
  104. $live_apply_list[$key]['gc_name'] = $gc_info['gc_name'];
  105. }
  106. }
  107. if (count($live_apply_list[$key]['goods_list']) < 2) {
  108. $goods_info = $goods_model->getGoodsCommonInfoByID($v['goods_commonid']);
  109. if ($goods_info && $goods_info['goods_state'] == 1 && $goods_info['goods_verify'] == 1) {
  110. $goods_info['goods_image'] = goods_cthumb($goods_info['goods_image']);
  111. $live_apply_list[$key]['goods_list'][] = $goods_info;
  112. }
  113. } else {
  114. break;
  115. }
  116. }
  117. }
  118. $result = array('goodsclass_list' => $goodsclass_list, 'live_apply_list' => $live_apply_list);
  119. $result = array_merge($result, mobile_page(is_object($live_apply_model->page_info) ? $live_apply_model->page_info : ''));
  120. ds_json_encode(10000, '', $result);
  121. }
  122. public function get_minipro_live_list()
  123. {
  124. $condition = array();
  125. $condition[] = array('minipro_live_end_time', '>', TIMESTAMP);
  126. $goodsclass_model = model('goodsclass');
  127. //获取分类
  128. $cache_key = 'api-member-minipro-live';
  129. $temp = rcache($cache_key);
  130. if (empty($temp)) {
  131. $gc_id_array = Db::name('minipro_live_room_goods')->alias('minipro_live_room_goods')->join('minipro_live minipro_live', 'minipro_live.minipro_live_id=minipro_live_room_goods.minipro_live_id')->distinct(true)->where($condition)->column('gc_id_1');
  132. $goodsclass_list = array();
  133. $minipro_live_ids = array();
  134. foreach ($gc_id_array as $v) {
  135. $temp = $goodsclass_model->getGoodsclassInfoById($v);
  136. if ($temp) {
  137. $goodsclass_list[] = $temp;
  138. }
  139. $minipro_live_ids[$v] = Db::name('minipro_live_room_goods')->distinct(true)->where('gc_id_1', $v)->column('minipro_live_id');
  140. }
  141. $temp = array('goodsclass_list' => $goodsclass_list, 'minipro_live_ids' => $minipro_live_ids);
  142. wcache($cache_key, $temp);
  143. }
  144. $goodsclass_list = $temp['goodsclass_list'];
  145. $minipro_live_ids = $temp['minipro_live_ids'];
  146. $gc_id = intval(input('param.gc_id'));
  147. $keyword = input('param.keyword');
  148. $goods_model = model('goods');
  149. $minipro_live_model = model('minipro_live');
  150. if ($gc_id > 0) {
  151. $condition[] = array('minipro_live_id', 'in', isset($minipro_live_ids[$gc_id]) ? $minipro_live_ids[$gc_id] : array());
  152. }
  153. if ($keyword) {
  154. $condition[] = array('minipro_live_id', 'in', Db::name('minipro_live_room_goods')->distinct(true)->where(array(array('store_name|goods_name|gc_name', 'like', '%' . $keyword . '%')))->column('minipro_live_id'));
  155. }
  156. $minipro_live_list = $minipro_live_model->getMiniproLiveList($condition);
  157. $store_model = model('store');
  158. $minipro_live_room_goods_model = model('minipro_live_room_goods');
  159. foreach ($minipro_live_list as $key => $val) {
  160. $store_info = $store_model->getStoreInfoByID($val['store_id']);
  161. if (!$store_info) {
  162. unset($minipro_live_list[$key]);
  163. continue;
  164. }
  165. $minipro_live_list[$key]['store_name'] = $store_info['store_name'];
  166. $minipro_live_list[$key]['store_avatar'] = get_store_logo($store_info['store_avatar']);
  167. $minipro_live_list[$key]['area_info'] = $store_info['area_info'];
  168. $minipro_live_room_goods_list = $minipro_live_room_goods_model->getMiniproLiveRoomGoodsList(array(array('minipro_live_id', '=', $val['minipro_live_id'])));
  169. $minipro_live_list[$key]['minipro_live_image_url'] = ds_get_pic(ATTACH_MINIPRO_LIVE, $val['minipro_live_image']);
  170. $minipro_live_list[$key]['goods_count'] = count($minipro_live_room_goods_list);
  171. $minipro_live_list[$key]['gc_name'] = '';
  172. $minipro_live_list[$key]['goods_list'] = array();
  173. foreach ($minipro_live_room_goods_list as $v) {
  174. if (!$minipro_live_list[$key]['gc_name']) {
  175. $gc_info = $goodsclass_model->getGoodsclassInfoById($v['gc_id_2']);
  176. if ($gc_info) {
  177. $minipro_live_list[$key]['gc_name'] = $gc_info['gc_name'];
  178. }
  179. }
  180. if (count($minipro_live_list[$key]['goods_list']) < 2) {
  181. $goods_info = $goods_model->getGoodsCommonInfoByID($v['goods_commonid']);
  182. if ($goods_info && $goods_info['goods_state'] == 1 && $goods_info['goods_verify'] == 1) {
  183. $goods_info['goods_image'] = goods_cthumb($goods_info['goods_image']);
  184. $minipro_live_list[$key]['goods_list'][] = $goods_info;
  185. }
  186. } else {
  187. break;
  188. }
  189. }
  190. }
  191. $result = array('goodsclass_list' => $goodsclass_list, 'minipro_live_list' => $minipro_live_list);
  192. $result = array_merge($result, mobile_page(is_object($minipro_live_model->page_info) ? $minipro_live_model->page_info : ''));
  193. ds_json_encode(10000, '', $result);
  194. }
  195. }