Live.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. *
  7. * ============================================================================
  8. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  9. * 网站地址: https://www.valimart.net/
  10. * ----------------------------------------------------------------------------
  11. *
  12. * ============================================================================
  13. * 公共数据控制器
  14. */
  15. class Live extends MobileMall {
  16. public function initialize() {
  17. parent::initialize();
  18. }
  19. /**
  20. * @api {POST} api/Live/get_live_list 获取直播列表
  21. * @apiVersion 1.0.0
  22. * @apiGroup Live
  23. * @apiParam {Int} page 页码
  24. * @apiParam {Int} per_page 每页数量
  25. * @apiParam {Int} gc_id 分类ID
  26. * @apiParam {String} keyword 关键词
  27. *
  28. * @apiSuccess {String} code 返回码,10000为成功
  29. * @apiSuccess {String} message 返回消息
  30. * @apiSuccess {Object} result 返回数据
  31. * @apiSuccess {Int} result.page_total 总页数
  32. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  33. * @apiSuccess {Object[]} result.goodsclass_list 分类列表
  34. * @apiSuccess {Object[]} result.live_apply_list 直播列表
  35. * @apiSuccess {String} result.live_apply_list.store_name 店铺名称
  36. * @apiSuccess {String} result.live_apply_list.store_avatar 店铺头像
  37. * @apiSuccess {String} result.live_apply_list.area_info 店铺地区
  38. * @apiSuccess {String} result.live_apply_list.live_apply_cover_image_url 直播图片封面地址
  39. * @apiSuccess {String} result.live_apply_list.live_apply_cover_video_url 直播视频封面地址
  40. * @apiSuccess {Int} result.live_apply_list.goods_count 直播商品数
  41. * @apiSuccess {String} result.live_apply_list.gc_name 直播商品分类名称
  42. * @apiSuccess {Object[]} result.live_apply_list.goods_list 直播商品列表
  43. */
  44. public function get_live_list() {
  45. $condition = array();
  46. $condition[] = array('live_apply_state', '=', 1);
  47. $condition[] = array('live_apply_end_time', '>', TIMESTAMP);
  48. $goodsclass_model = model('goodsclass');
  49. //获取分类
  50. $cache_key = 'api-member-live';
  51. $temp = rcache($cache_key);
  52. if (empty($temp)) {
  53. $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');
  54. $goodsclass_list = array();
  55. $live_apply_ids = array();
  56. foreach ($gc_id_array as $v) {
  57. $temp = $goodsclass_model->getGoodsclassInfoById($v);
  58. if ($temp) {
  59. $goodsclass_list[] = $temp;
  60. }
  61. $live_apply_ids[$v] = Db::name('live_apply_goods')->distinct(true)->where('gc_id_1', $v)->column('live_apply_id');
  62. }
  63. $temp = array('goodsclass_list' => $goodsclass_list, 'live_apply_ids' => $live_apply_ids);
  64. wcache($cache_key, $temp);
  65. }
  66. $goodsclass_list = $temp['goodsclass_list'];
  67. $live_apply_ids = $temp['live_apply_ids'];
  68. $gc_id = intval(input('param.gc_id'));
  69. $keyword = input('param.keyword');
  70. $goods_model = model('goods');
  71. $live_apply_model = model('live_apply');
  72. if ($gc_id > 0) {
  73. $condition[] = array('live_apply_id', 'in', isset($live_apply_ids[$gc_id]) ? $live_apply_ids[$gc_id] : array());
  74. }
  75. if ($keyword) {
  76. $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'));
  77. }
  78. $live_apply_list = $live_apply_model->getLiveApplyList($condition);
  79. $store_model = model('store');
  80. foreach ($live_apply_list as $key => $val) {
  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_count'] = count($live_apply_goods_list);
  99. $live_apply_list[$key]['gc_name'] = '';
  100. $live_apply_list[$key]['goods_list'] = array();
  101. foreach ($live_apply_goods_list as $v) {
  102. if (!$live_apply_list[$key]['gc_name']) {
  103. $gc_info = $goodsclass_model->getGoodsclassInfoById($v['gc_id_2']);
  104. if ($gc_info) {
  105. $live_apply_list[$key]['gc_name'] = $gc_info['gc_name'];
  106. }
  107. }
  108. if (count($live_apply_list[$key]['goods_list']) < 2) {
  109. $goods_info = $goods_model->getGoodsCommonInfoByID($v['goods_commonid']);
  110. if ($goods_info && $goods_info['goods_state'] == 1 && $goods_info['goods_verify'] == 1) {
  111. $goods_info['goods_image'] = goods_cthumb($goods_info['goods_image']);
  112. $live_apply_list[$key]['goods_list'][] = $goods_info;
  113. }
  114. } else {
  115. break;
  116. }
  117. }
  118. }
  119. $result = array('goodsclass_list' => $goodsclass_list, 'live_apply_list' => $live_apply_list);
  120. $result = array_merge($result, mobile_page(is_object($live_apply_model->page_info) ? $live_apply_model->page_info : ''));
  121. ds_json_encode(10000, '', $result);
  122. }
  123. public function get_minipro_live_list() {
  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. }
  196. ?>