Live.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Db;
  4. /**
  5. * ============================================================================
  6. * DSMall多用户商城
  7. * ============================================================================
  8. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  9. * 网站地址: http://www.csdeshang.com
  10. * ----------------------------------------------------------------------------
  11. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  12. * 不允许对程序代码以任何形式任何目的的再发布。
  13. * ============================================================================
  14. * 公共数据控制器
  15. */
  16. class Live extends MobileMall {
  17. public function initialize() {
  18. parent::initialize();
  19. }
  20. /**
  21. * @api {POST} api/Live/get_live_list 获取直播列表
  22. * @apiVersion 1.0.0
  23. * @apiGroup Live
  24. * @apiParam {Int} page 页码
  25. * @apiParam {Int} per_page 每页数量
  26. * @apiParam {Int} gc_id 分类ID
  27. * @apiParam {String} keyword 关键词
  28. *
  29. * @apiSuccess {String} code 返回码,10000为成功
  30. * @apiSuccess {String} message 返回消息
  31. * @apiSuccess {Object} result 返回数据
  32. * @apiSuccess {Int} result.page_total 总页数
  33. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  34. * @apiSuccess {Object[]} result.goodsclass_list 分类列表
  35. * @apiSuccess {Object[]} result.live_apply_list 直播列表
  36. * @apiSuccess {String} result.live_apply_list.store_name 店铺名称
  37. * @apiSuccess {String} result.live_apply_list.store_avatar 店铺头像
  38. * @apiSuccess {String} result.live_apply_list.area_info 店铺地区
  39. * @apiSuccess {String} result.live_apply_list.live_apply_cover_image_url 直播图片封面地址
  40. * @apiSuccess {String} result.live_apply_list.live_apply_cover_video_url 直播视频封面地址
  41. * @apiSuccess {Int} result.live_apply_list.goods_count 直播商品数
  42. * @apiSuccess {String} result.live_apply_list.gc_name 直播商品分类名称
  43. * @apiSuccess {Object[]} result.live_apply_list.goods_list 直播商品列表
  44. */
  45. public function get_live_list() {
  46. $condition = array();
  47. $condition[] = array('live_apply_state', '=', 1);
  48. $condition[] = array('live_apply_end_time', '>', TIMESTAMP);
  49. $goodsclass_model = model('goodsclass');
  50. //获取分类
  51. $cache_key = 'api-member-live';
  52. $temp = rcache($cache_key);
  53. if (empty($temp)) {
  54. $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');
  55. $goodsclass_list = array();
  56. $live_apply_ids = array();
  57. foreach ($gc_id_array as $v) {
  58. $temp = $goodsclass_model->getGoodsclassInfoById($v);
  59. if ($temp) {
  60. $goodsclass_list[] = $temp;
  61. }
  62. $live_apply_ids[$v] = Db::name('live_apply_goods')->distinct(true)->where('gc_id_1', $v)->column('live_apply_id');
  63. }
  64. $temp = array('goodsclass_list' => $goodsclass_list, 'live_apply_ids' => $live_apply_ids);
  65. wcache($cache_key, $temp);
  66. }
  67. $goodsclass_list = $temp['goodsclass_list'];
  68. $live_apply_ids = $temp['live_apply_ids'];
  69. $gc_id = intval(input('param.gc_id'));
  70. $keyword = input('param.keyword');
  71. $goods_model = model('goods');
  72. $live_apply_model = model('live_apply');
  73. if ($gc_id > 0) {
  74. $condition[] = array('live_apply_id', 'in', isset($live_apply_ids[$gc_id]) ? $live_apply_ids[$gc_id] : array());
  75. }
  76. if ($keyword) {
  77. $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'));
  78. }
  79. $live_apply_list = $live_apply_model->getLiveApplyList($condition);
  80. $store_model = model('store');
  81. foreach ($live_apply_list as $key => $val) {
  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_count'] = count($live_apply_goods_list);
  100. $live_apply_list[$key]['gc_name'] = '';
  101. $live_apply_list[$key]['goods_list'] = array();
  102. foreach ($live_apply_goods_list as $v) {
  103. if (!$live_apply_list[$key]['gc_name']) {
  104. $gc_info = $goodsclass_model->getGoodsclassInfoById($v['gc_id_2']);
  105. if ($gc_info) {
  106. $live_apply_list[$key]['gc_name'] = $gc_info['gc_name'];
  107. }
  108. }
  109. if (count($live_apply_list[$key]['goods_list']) < 2) {
  110. $goods_info = $goods_model->getGoodsCommonInfoByID($v['goods_commonid']);
  111. if ($goods_info && $goods_info['goods_state'] == 1 && $goods_info['goods_verify'] == 1) {
  112. $goods_info['goods_image'] = goods_cthumb($goods_info['goods_image']);
  113. $live_apply_list[$key]['goods_list'][] = $goods_info;
  114. }
  115. } else {
  116. break;
  117. }
  118. }
  119. }
  120. $result = array('goodsclass_list' => $goodsclass_list, 'live_apply_list' => $live_apply_list);
  121. $result = array_merge($result, mobile_page(is_object($live_apply_model->page_info) ? $live_apply_model->page_info : ''));
  122. ds_json_encode(10000, '', $result);
  123. }
  124. public function get_minipro_live_list() {
  125. $condition = array();
  126. $condition[] = array('minipro_live_end_time', '>', TIMESTAMP);
  127. $goodsclass_model = model('goodsclass');
  128. //获取分类
  129. $cache_key = 'api-member-minipro-live';
  130. $temp = rcache($cache_key);
  131. if (empty($temp)) {
  132. $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');
  133. $goodsclass_list = array();
  134. $minipro_live_ids = array();
  135. foreach ($gc_id_array as $v) {
  136. $temp = $goodsclass_model->getGoodsclassInfoById($v);
  137. if ($temp) {
  138. $goodsclass_list[] = $temp;
  139. }
  140. $minipro_live_ids[$v] = Db::name('minipro_live_room_goods')->distinct(true)->where('gc_id_1', $v)->column('minipro_live_id');
  141. }
  142. $temp = array('goodsclass_list' => $goodsclass_list, 'minipro_live_ids' => $minipro_live_ids);
  143. wcache($cache_key, $temp);
  144. }
  145. $goodsclass_list = $temp['goodsclass_list'];
  146. $minipro_live_ids = $temp['minipro_live_ids'];
  147. $gc_id = intval(input('param.gc_id'));
  148. $keyword = input('param.keyword');
  149. $goods_model = model('goods');
  150. $minipro_live_model = model('minipro_live');
  151. if ($gc_id > 0) {
  152. $condition[] = array('minipro_live_id', 'in', isset($minipro_live_ids[$gc_id]) ? $minipro_live_ids[$gc_id] : array());
  153. }
  154. if ($keyword) {
  155. $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'));
  156. }
  157. $minipro_live_list = $minipro_live_model->getMiniproLiveList($condition);
  158. $store_model = model('store');
  159. $minipro_live_room_goods_model=model('minipro_live_room_goods');
  160. foreach ($minipro_live_list as $key => $val) {
  161. $store_info = $store_model->getStoreInfoByID($val['store_id']);
  162. if (!$store_info) {
  163. unset($minipro_live_list[$key]);
  164. continue;
  165. }
  166. $minipro_live_list[$key]['store_name'] = $store_info['store_name'];
  167. $minipro_live_list[$key]['store_avatar'] = get_store_logo($store_info['store_avatar']);
  168. $minipro_live_list[$key]['area_info'] = $store_info['area_info'];
  169. $minipro_live_room_goods_list = $minipro_live_room_goods_model->getMiniproLiveRoomGoodsList(array(array('minipro_live_id', '=', $val['minipro_live_id'])));
  170. $minipro_live_list[$key]['minipro_live_image_url'] = ds_get_pic( ATTACH_MINIPRO_LIVE , $val['minipro_live_image']);
  171. $minipro_live_list[$key]['goods_count'] = count($minipro_live_room_goods_list);
  172. $minipro_live_list[$key]['gc_name'] = '';
  173. $minipro_live_list[$key]['goods_list'] = array();
  174. foreach ($minipro_live_room_goods_list as $v) {
  175. if (!$minipro_live_list[$key]['gc_name']) {
  176. $gc_info = $goodsclass_model->getGoodsclassInfoById($v['gc_id_2']);
  177. if ($gc_info) {
  178. $minipro_live_list[$key]['gc_name'] = $gc_info['gc_name'];
  179. }
  180. }
  181. if (count($minipro_live_list[$key]['goods_list']) < 2) {
  182. $goods_info = $goods_model->getGoodsCommonInfoByID($v['goods_commonid']);
  183. if ($goods_info && $goods_info['goods_state'] == 1 && $goods_info['goods_verify'] == 1) {
  184. $goods_info['goods_image'] = goods_cthumb($goods_info['goods_image']);
  185. $minipro_live_list[$key]['goods_list'][] = $goods_info;
  186. }
  187. } else {
  188. break;
  189. }
  190. }
  191. }
  192. $result = array('goodsclass_list' => $goodsclass_list, 'minipro_live_list' => $minipro_live_list);
  193. $result = array_merge($result, mobile_page(is_object($minipro_live_model->page_info) ? $minipro_live_model->page_info : ''));
  194. ds_json_encode(10000, '', $result);
  195. }
  196. }
  197. ?>