SellerMiniproLive.php 15 KB

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