SellerMiniproLive.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <?php
  2. /**
  3. * 机构直播管理
  4. */
  5. namespace app\api\controller;
  6. use think\facade\Lang;
  7. /**
  8. * ============================================================================
  9. * DSKMS多用户商城
  10. * ============================================================================
  11. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  12. * 网站地址: https://www.valimart.net/
  13. * ----------------------------------------------------------------------------
  14. *
  15. * ============================================================================
  16. * 控制器
  17. */
  18. class SellerMiniproLive extends MobileSeller {
  19. private $errorMsg=array(
  20. '-1'=>'系统错误',
  21. '1'=>'未创建直播间',
  22. '1003'=>'商品id不存在',
  23. '47001'=>'入参格式不符合规范',
  24. '200002'=>'入参错误',
  25. '300001'=>'禁止创建/更新商品 或 禁止编辑&更新房间',
  26. '300002'=>'名称长度不符合规则',
  27. '300006'=>'图片上传失败(如:mediaID过期)',
  28. '300022'=>'此房间号不存在',
  29. '300023'=>'房间状态 拦截(当前房间状态不允许此操作)',
  30. '300024'=>'商品不存在',
  31. '300025'=>'商品审核未通过',
  32. '300026'=>'房间商品数量已经满额',
  33. '300027'=>'导入商品失败',
  34. '300028'=>'房间名称违规',
  35. '300029'=>'主播昵称违规',
  36. '300030'=>'主播微信号不合法',
  37. '300031'=>'直播间封面图不合规',
  38. '300032'=>'直播间分享图违规',
  39. '300033'=>'添加商品超过直播间上限',
  40. '300034'=>'主播微信昵称长度不符合要求',
  41. '300035'=>'主播微信号不存在',
  42. '300036'=>'主播微信号未实名认证',
  43. '300037'=>'购物直播频道封面图不合规',
  44. '300038'=>'未在小程序管理后台配置客服',
  45. '300039'=>'主播副号微信号不合法',
  46. '300040'=>'名称含有非限定字符(含有特殊字符)',
  47. '300041'=>'创建者微信号不合法',
  48. '300042'=>'推流中禁止编辑房间',
  49. '300043'=>'每天只允许一场直播开启关注',
  50. '500001'=>'副号不合规',
  51. '500002'=>'副号未实名',
  52. '500003'=>'已经设置过副号了,不能重复设置',
  53. '500004'=>'不能设置重复的副号',
  54. '500005'=>'副号不能和主号重复',
  55. '600001'=>'用户已被添加为小助手',
  56. '600002'=>'找不到用户',
  57. '9410000'=>'直播间列表为空',
  58. '9410001'=>'获取房间失败',
  59. '9410002'=>'获取商品失败',
  60. '9410003'=>'获取回放失败'
  61. );
  62. public function initialize() {
  63. parent::initialize();
  64. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/live.lang.php');
  65. }
  66. /**
  67. * @api {POST} api/SellerMiniproLive/get_room_list 直播间列表
  68. * @apiVersion 1.0.0
  69. * @apiGroup SellerMiniproLive
  70. *
  71. * @apiHeader {String} X-DS-KEY 卖家授权token
  72. *
  73. * @apiParam {Int} page 页码
  74. * @apiParam {Int} pagesize 每页显示数量
  75. *
  76. * @apiSuccess {String} code 返回码,10000为成功
  77. * @apiSuccess {String} message 返回消息
  78. * @apiSuccess {String} result 返回数据
  79. */
  80. public function get_room_list(){
  81. $minipro_live_model=model('minipro_live');
  82. $minipro_live_room_goods_model=model('minipro_live_room_goods');
  83. $room_list=$minipro_live_model->getMiniproLiveList(array(array('member_id','=',$this->store_info['member_id'])));
  84. foreach($room_list as $key => $val){
  85. $room_list[$key]['goods_list']=$minipro_live_room_goods_model->getMiniproLiveRoomGoodsList(array(array('minipro_live_id','=',$val['minipro_live_id'])));
  86. foreach($room_list[$key]['goods_list'] as $k => $v){
  87. $room_list[$key]['goods_list'][$k]['goods_image_url']=goods_cthumb($v['goods_image'], 480, $v['store_id']);
  88. }
  89. }
  90. $result = array_merge(array('minipro_live_list' => $room_list), mobile_page($minipro_live_model->page_info));
  91. ds_json_encode(10000, '', $result);
  92. }
  93. /**
  94. * @api {POST} api/SellerMiniproLive/get_room_info 直播间信息
  95. * @apiVersion 1.0.0
  96. * @apiGroup SellerMiniproLive
  97. *
  98. * @apiHeader {String} X-DS-KEY 卖家授权token
  99. *
  100. * @apiParam {Int} minipro_live_id 直播id
  101. *
  102. * @apiSuccess {String} code 返回码,10000为成功
  103. * @apiSuccess {String} message 返回消息
  104. * @apiSuccess {String} result 返回数据
  105. */
  106. public function get_room_info(){
  107. $minipro_live_id=intval(input('param.minipro_live_id'));
  108. $minipro_live_model=model('minipro_live');
  109. $room_info=$minipro_live_model->getMiniproLiveInfo(array(array('member_id','=',$this->store_info['member_id']),array('minipro_live_id','=',$minipro_live_id)));
  110. if(!$room_info){
  111. ds_json_encode(10001, lang('minipro_live_empty'));
  112. }
  113. ds_json_encode(10000, '', array('minipro_live_info' => $room_info));
  114. }
  115. /**
  116. * @api {POST} api/SellerMiniproLive/add_room 新增直播间
  117. * @apiVersion 1.0.0
  118. * @apiGroup SellerMiniproLive
  119. *
  120. * @apiHeader {String} X-DS-KEY 卖家授权token
  121. *
  122. * @apiParam {Int} goods_id 商品id
  123. *
  124. * @apiSuccess {String} code 返回码,10000为成功
  125. * @apiSuccess {String} message 返回消息
  126. * @apiSuccess {String} result 返回数据
  127. */
  128. public function add_room(){
  129. $wechat_model=model('wechat');
  130. $wechat_model->getOneWxconfig();
  131. $accessToken = $wechat_model->getAccessToken('miniprogram', 0);
  132. if($wechat_model->error_code){
  133. ds_json_encode(10001, $wechat_model->error_message);
  134. }
  135. $data=array(
  136. 'name'=>input('param.minipro_live_name'),
  137. 'coverImg'=>input('param.coverImg'),
  138. 'startTime'=>input('param.minipro_live_start_time'),
  139. 'endTime'=>input('param.minipro_live_end_time'),
  140. 'anchorName'=>input('param.minipro_live_nickname'),
  141. 'anchorWechat'=>input('param.minipro_live_wxid'),
  142. 'shareImg'=>input('param.feedsImg'),
  143. 'feedsImg'=>input('param.feedsImg'),
  144. 'isFeedsPublic'=>0,
  145. 'type'=>0,
  146. 'screenType'=>0,
  147. 'closeLike'=>0,
  148. 'closeGoods'=>0,
  149. 'closeComment'=>0,
  150. 'closeReplay'=>0,
  151. 'closeShare'=>0,
  152. 'closeKf'=>1,
  153. );
  154. if(!$data['name'] || !$data['coverImg'] || !$data['startTime'] || !$data['endTime'] || !$data['anchorName'] || !$data['anchorWechat'] || !$data['shareImg']){
  155. ds_json_encode(10001, lang('minipro_live_data_incomplete'));
  156. }
  157. if(mb_strlen($data['name'])<3 || mb_strlen($data['name'])>17){
  158. ds_json_encode(10001, lang('minipro_live_name_error'));
  159. }
  160. if($data['startTime']<(TIMESTAMP-10*60)){
  161. ds_json_encode(10001, lang('minipro_live_start_time_error'));
  162. }
  163. $time=$data['endTime']-$data['startTime'];
  164. if($time<0 || $time>(72*3600)){
  165. ds_json_encode(10001, lang('minipro_live_time_error'));
  166. }
  167. if(mb_strlen($data['anchorName'])<2 || mb_strlen($data['anchorName'])>15){
  168. ds_json_encode(10001, lang('minipro_live_author_error'));
  169. }
  170. $res=http_request('https://api.weixin.qq.com/wxaapi/broadcast/room/create?access_token='.$accessToken,'POST',$data);
  171. $res= json_decode($res,true);
  172. if(!$res || $res['errcode']){
  173. $msg=lang('minipro_live_add_fail').$res['errcode'];
  174. if(isset($this->errorMsg[$res['errcode']])){
  175. $msg=$this->errorMsg[$res['errcode']];
  176. }else if(isset($res['errmsg'])){
  177. $msg=$res['errmsg'];
  178. }
  179. ds_json_encode(10001, $msg);
  180. }
  181. $minipro_live_model=model('minipro_live');
  182. $minipro_live_model->addMiniproLive(array(
  183. 'minipro_live_name'=>$data['name'],
  184. 'member_id'=>$this->store_info['member_id'],
  185. 'store_id'=>$this->store_info['store_id'],
  186. 'minipro_live_wxid'=>$data['anchorWechat'],
  187. 'minipro_live_nickname'=>$data['anchorName'],
  188. 'minipro_live_start_time'=>$data['startTime'],
  189. 'minipro_live_end_time'=>$data['endTime'],
  190. 'minipro_live_image'=>input('param.minipro_live_image'),
  191. 'minipro_live_add_time'=>TIMESTAMP,
  192. 'minipro_live_room_id'=>$res['roomId'],
  193. ));
  194. ds_json_encode(10000,'',array('roomId'=>$res['roomId']));
  195. }
  196. /**
  197. * @api {POST} api/SellerMiniproLive/import_room_goods 导入直播间商品
  198. * @apiVersion 1.0.0
  199. * @apiGroup SellerMiniproLive
  200. *
  201. * @apiHeader {String} X-DS-KEY 卖家授权token
  202. *
  203. * @apiParam {Int} goods_id 商品id
  204. *
  205. * @apiSuccess {String} code 返回码,10000为成功
  206. * @apiSuccess {String} message 返回消息
  207. * @apiSuccess {String} result 返回数据
  208. */
  209. public function import_room_goods(){
  210. $wechat_model=model('wechat');
  211. $wechat_model->getOneWxconfig();
  212. $accessToken = $wechat_model->getAccessToken('miniprogram', 0);
  213. if($wechat_model->error_code){
  214. ds_json_encode(10001, $wechat_model->error_message);
  215. }
  216. $roomId=input('param.roomId');
  217. $ids=input('param.ids/a');
  218. $minipro_live_model=model('minipro_live');
  219. $minipro_live_info=$minipro_live_model->getMiniproLiveInfo(array(array('minipro_live_room_id','=',$roomId),array('member_id','=',$this->store_info['member_id'])));
  220. if(!$minipro_live_info){
  221. ds_json_encode(10001, lang('minipro_live_empty'));
  222. }
  223. $data=array(
  224. 'roomId'=>$roomId,
  225. 'ids'=>$ids,
  226. );
  227. $res=http_request('https://api.weixin.qq.com/wxaapi/broadcast/room/addgoods?access_token='.$accessToken,'POST',$data);
  228. $res= json_decode($res,true);
  229. if(!$res || $res['errcode']){
  230. ds_json_encode(10001, isset($res['errmsg'])?$res['errmsg']:lang('minipro_live_import_goods_fail').$res['errcode']);
  231. }
  232. $minipro_live_room_goods_model=model('minipro_live_room_goods');
  233. $minipro_live_goods_model=model('minipro_live_goods');
  234. $goods_model=model('goods');
  235. $minipro_live_goods_list=$minipro_live_goods_model->getMiniproLiveGoodsList(array(array('minipro_live_goods_result_id','in',$ids)));
  236. foreach($minipro_live_goods_list as $val){
  237. $data=array(
  238. 'minipro_live_id'=>$minipro_live_info['minipro_live_id'],
  239. 'store_id'=>$val['store_id'],
  240. 'store_name'=>$val['store_name'],
  241. 'goods_id'=>$val['goods_id'],
  242. 'goods_commonid'=>$val['goods_commonid'],
  243. 'goods_name'=>$val['goods_name'],
  244. 'goods_image'=>$val['goods_image'],
  245. 'goods_price'=>$val['goods_price'],
  246. 'minipro_live_goods_result_id'=>$val['minipro_live_goods_result_id'],
  247. );
  248. $goods_info=$goods_model->getGoodsCommonInfoByID($val['goods_commonid']);
  249. if($goods_info){
  250. $data['gc_id']=$goods_info['gc_id'];
  251. $data['gc_id_1']=$goods_info['gc_id_1'];
  252. $data['gc_id_2']=$goods_info['gc_id_2'];
  253. $data['gc_id_3']=$goods_info['gc_id_3'];
  254. $data['gc_name']=$goods_info['gc_name'];
  255. }
  256. $minipro_live_room_goods_model->addMiniproLiveRoomGoods($data);
  257. }
  258. ds_json_encode(10000);
  259. }
  260. /**
  261. * @api {POST} api/SellerMiniproLive/get_goods_list 商品列表
  262. * @apiVersion 1.0.0
  263. * @apiGroup SellerMiniproLive
  264. *
  265. * @apiHeader {String} X-DS-KEY 卖家授权token
  266. *
  267. * @apiParam {Int} goods_id 商品id
  268. *
  269. * @apiSuccess {String} code 返回码,10000为成功
  270. * @apiSuccess {String} message 返回消息
  271. * @apiSuccess {String} result 返回数据
  272. */
  273. public function get_goods_list(){
  274. $condition = array();
  275. $condition[] = array('goodscommon.store_id', '=', $this->store_info['store_id']);
  276. $condition[] = array('goodscommon.goods_verify', '=', 1);
  277. $condition[] = array('goodscommon.goods_state', '=', 1);
  278. $fields = 'goods_id,goodscommon.gc_id,goodscommon.store_id,goodscommon.goods_commonid,goodscommon.goods_name,goodscommon.goods_price,goodscommon.goods_addtime,goodscommon.goods_image,goodscommon.goods_state,goodscommon.goods_lock';
  279. $goods_model = model('goods');
  280. $goods_list = $goods_model->getGoodsUnionList($condition, $fields , 'goodscommon.goods_commonid desc','goodscommon.goods_commonid', $this->pagesize);
  281. $minipro_live_goods_model=model('minipro_live_goods');
  282. foreach($goods_list as $key => $val){
  283. $goods_list[$key]['goods_image_url'] = goods_cthumb($val['goods_image'], 480, $val['store_id']);
  284. $minipro_live_goods_info=$minipro_live_goods_model->getMiniproLiveGoodsInfo(array(array('goods_commonid','=',$val['goods_commonid'])));
  285. $goods_list[$key]['minipro_live_goods_info'] = $minipro_live_goods_info;
  286. }
  287. $result = array_merge(array('goods_list' => $goods_list), mobile_page($goods_model->page_info));
  288. ds_json_encode(10000, '', $result);
  289. }
  290. /**
  291. * @api {POST} api/SellerMiniproLive/upload_media 上传临时素材
  292. * @apiVersion 1.0.0
  293. * @apiGroup SellerMiniproLive
  294. *
  295. * @apiHeader {String} X-DS-KEY 卖家授权token
  296. *
  297. * @apiParam {File} file 文件
  298. *
  299. * @apiSuccess {String} code 返回码,10000为成功
  300. * @apiSuccess {String} message 返回消息
  301. * @apiSuccess {String} result 返回数据
  302. */
  303. public function upload_media() {
  304. $wechat_model=model('wechat');
  305. $wechat_model->getOneWxconfig();
  306. $res=$wechat_model->uploadMedia('image',$_FILES['file']['tmp_name'], $_FILES['file']['type'], $_FILES['file']['name']);
  307. if(!$res['code']){
  308. ds_json_encode(10001, $res['msg']);
  309. }
  310. $media_id=$res['data'];
  311. $file_name='';
  312. if(input('param.save')){
  313. $res = ds_upload_pic(ATTACH_MINIPRO_LIVE, 'file');
  314. if (!$res['code']) {
  315. ds_json_encode(10001, $res['msg']);
  316. }
  317. $file_name=$res['data']['file_name'];
  318. }
  319. ds_json_encode(10000,'',array('media_id'=>$media_id,'file_name'=>$file_name));
  320. }
  321. }