运营后台可设置推荐直播间
This commit is contained in:
@@ -88,4 +88,10 @@ public class Studio extends BaseEntity {
|
||||
|
||||
@ApiModelProperty(value = "直播间商品(最多展示两个商品:name/goodsImage)")
|
||||
private String roomGoodsList;
|
||||
|
||||
@ApiModelProperty(value = "推荐直播间")
|
||||
private boolean recommend;
|
||||
|
||||
@ApiModelProperty(value = "直播间状态")
|
||||
private String status;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package cn.lili.modules.broadcast.service;
|
||||
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.modules.broadcast.entity.dos.Studio;
|
||||
import cn.lili.modules.broadcast.entity.vos.StudioVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
@@ -21,6 +23,14 @@ public interface StudioService extends IService<Studio> {
|
||||
*/
|
||||
Boolean create(Studio studio);
|
||||
|
||||
/**
|
||||
* 修改直播间
|
||||
* 直播间默认手机直播
|
||||
* @param studio 直播间
|
||||
* @return 修改状态
|
||||
*/
|
||||
Boolean edit(Studio studio);
|
||||
|
||||
/**
|
||||
* 获取直播间信息
|
||||
* @param id 直播间ID
|
||||
@@ -50,4 +60,13 @@ public interface StudioService extends IService<Studio> {
|
||||
* @return 操作结果
|
||||
*/
|
||||
Boolean goodsDeleteInRoom(Integer roomId,Integer goodsId);
|
||||
|
||||
/**
|
||||
* 获取直播间列表
|
||||
* @param pageVO 分页
|
||||
* @param recommend 是否推荐
|
||||
* @param status 直播间状态
|
||||
* @return 直播间分页
|
||||
*/
|
||||
IPage<Studio> studioList(PageVO pageVO, Integer recommend, String status);
|
||||
}
|
||||
|
||||
@@ -49,6 +49,9 @@ public class CommodityServiceImpl extends ServiceImpl<CommodityMapper, Commodity
|
||||
checkCommodity(commodity);
|
||||
//添加直播商品
|
||||
JSONObject json = wechatLivePlayerUtil.addGoods(commodity);
|
||||
if(!json.getStr("errcode").equals("0")){
|
||||
throw new ServiceException(json.getStr("errmsg"));
|
||||
}
|
||||
commodity.setLiveGoodsId(Convert.toInt(json.getStr("goodsId")));
|
||||
commodity.setAuditId(json.getStr("auditId"));
|
||||
commodity.setStoreId(UserContext.getCurrentUser().getStoreId());
|
||||
|
||||
@@ -5,6 +5,8 @@ import cn.lili.common.enums.ResultCode;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.common.security.context.UserContext;
|
||||
import cn.lili.common.utils.BeanUtil;
|
||||
import cn.lili.common.utils.PageUtil;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.modules.broadcast.entity.dos.Studio;
|
||||
import cn.lili.modules.broadcast.entity.dos.StudioCommodity;
|
||||
import cn.lili.modules.broadcast.entity.vos.StudioVO;
|
||||
@@ -13,7 +15,9 @@ import cn.lili.modules.broadcast.mapper.StudioMapper;
|
||||
import cn.lili.modules.broadcast.service.StudioCommodityService;
|
||||
import cn.lili.modules.broadcast.service.StudioService;
|
||||
import cn.lili.modules.broadcast.util.WechatLivePlayerUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -41,7 +45,7 @@ public class StudioServiceImpl extends ServiceImpl<StudioMapper, Studio> impleme
|
||||
public Boolean create(Studio studio) {
|
||||
try {
|
||||
//创建小程序直播
|
||||
Map<String,String> roomMap=wechatLivePlayerUtil.create(studio);
|
||||
Map<String, String> roomMap = wechatLivePlayerUtil.create(studio);
|
||||
studio.setRoomId(Integer.parseInt(roomMap.get("roomId")));
|
||||
studio.setQrCodeUrl(roomMap.get("qrcodeUrl"));
|
||||
studio.setStoreId(UserContext.getCurrentUser().getStoreId());
|
||||
@@ -53,6 +57,12 @@ public class StudioServiceImpl extends ServiceImpl<StudioMapper, Studio> impleme
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean edit(Studio studio) {
|
||||
wechatLivePlayerUtil.editRoom(studio);
|
||||
return this.updateById(studio);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StudioVO getStudioVO(String id) {
|
||||
StudioVO studioVO = new StudioVO();
|
||||
@@ -86,8 +96,9 @@ public class StudioServiceImpl extends ServiceImpl<StudioMapper, Studio> impleme
|
||||
Studio studio = this.getByRoomId(roomId);
|
||||
studio.setRoomGoodsNum(studio.getRoomGoodsNum() != null ? studio.getRoomGoodsNum() + 1 : 1);
|
||||
//设置直播间默认的商品(前台展示)只展示两个
|
||||
if(studio.getRoomGoodsNum()<3){
|
||||
studio.setRoomGoodsList(JSONUtil.toJsonStr(commodityMapper.getSimpleCommodityByRoomId(roomId)));;
|
||||
if (studio.getRoomGoodsNum() < 3) {
|
||||
studio.setRoomGoodsList(JSONUtil.toJsonStr(commodityMapper.getSimpleCommodityByRoomId(roomId)));
|
||||
;
|
||||
}
|
||||
return this.updateById(studio);
|
||||
}
|
||||
@@ -103,14 +114,23 @@ public class StudioServiceImpl extends ServiceImpl<StudioMapper, Studio> impleme
|
||||
Studio studio = this.getByRoomId(roomId);
|
||||
studio.setRoomGoodsNum(studio.getRoomGoodsNum() - 1);
|
||||
//设置直播间默认的商品(前台展示)只展示两个
|
||||
if(studio.getRoomGoodsNum()<3){
|
||||
studio.setRoomGoodsList(JSONUtil.toJsonStr(commodityMapper.getSimpleCommodityByRoomId(roomId)));;
|
||||
if (studio.getRoomGoodsNum() < 3) {
|
||||
studio.setRoomGoodsList(JSONUtil.toJsonStr(commodityMapper.getSimpleCommodityByRoomId(roomId)));
|
||||
;
|
||||
}
|
||||
return this.updateById(studio);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<Studio> studioList(PageVO pageVO, Integer recommend, String status) {
|
||||
return this.page(PageUtil.initPage(pageVO), new QueryWrapper<Studio>()
|
||||
.eq(recommend != null, "recommend", true)
|
||||
.eq(status!=null,"status",status));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据直播间ID获取直播间
|
||||
*
|
||||
@@ -118,6 +138,6 @@ public class StudioServiceImpl extends ServiceImpl<StudioMapper, Studio> impleme
|
||||
* @return 直播间
|
||||
*/
|
||||
private Studio getByRoomId(Integer roomId) {
|
||||
return this.getOne(this.lambdaQuery().eq(Studio::getRoomId, roomId));
|
||||
return this.getOne(new LambdaQueryWrapper<Studio>().eq(Studio::getRoomId, roomId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.lili.modules.broadcast.util;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.lili.common.exception.ServiceException;
|
||||
import cn.lili.modules.base.entity.enums.ClientTypeEnum;
|
||||
import cn.lili.modules.broadcast.entity.dos.Commodity;
|
||||
import cn.lili.modules.broadcast.entity.dos.Studio;
|
||||
@@ -36,49 +37,50 @@ public class WechatLivePlayerUtil {
|
||||
* @param studio 小程序直播
|
||||
* @return 房间ID
|
||||
*/
|
||||
public Map<String,String> create(Studio studio) throws Exception{
|
||||
public Map<String, String> create(Studio studio) throws Exception {
|
||||
//获取token
|
||||
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
|
||||
//发送url
|
||||
String url = "https://api.weixin.qq.com/wxaapi/broadcast/room/create?access_token=" + token;
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
// 背景图
|
||||
map.put("coverImg", wechatMediaUtil.uploadMedia(token,"image",studio.getCoverImg()));
|
||||
// 分享图
|
||||
map.put("shareImg", wechatMediaUtil.uploadMedia(token,"image",studio.getShareImg()));
|
||||
// 购物直播频道封面图
|
||||
map.put("feedsImg", wechatMediaUtil.uploadMedia(token,"image",studio.getFeedsImg()));
|
||||
// 直播间名字
|
||||
map.put("name", studio.getName());
|
||||
// 直播计划开始时间
|
||||
map.put("startTime", studio.getStartTime());
|
||||
// 直播计划结束时间
|
||||
map.put("endTime", studio.getEndTime());
|
||||
// 主播昵称
|
||||
map.put("anchorName", studio.getAnchorName());
|
||||
// 主播微信号
|
||||
map.put("anchorWechat", studio.getAnchorWechat());
|
||||
// 直播间类型
|
||||
map.put("type", "0");
|
||||
// 是否关闭点赞
|
||||
map.put("closeLike", "0");
|
||||
// 是否关闭货架
|
||||
map.put("closeGoods", "0");
|
||||
// 是否关闭评论
|
||||
map.put("closeComment", "0");
|
||||
// 直播间名字
|
||||
map.put("closeReplay", "0");
|
||||
|
||||
//添加直播间
|
||||
Map<String, String> map = this.mockRoom(token, studio);
|
||||
String content = HttpUtils.doPostWithJson(url, map);
|
||||
JSONObject json = new JSONObject(content);
|
||||
log.info("微信小程序直播间创建结果:" + content);
|
||||
Map<String,String> roomMap=new HashMap<>();
|
||||
roomMap.put("roomId",json.getStr("roomId"));
|
||||
roomMap.put("qrcodeUrl",json.getStr("qrcode_url"));
|
||||
if (!json.getStr("errcode").equals("0")) {
|
||||
throw new ServiceException(json.getStr("errmsg"));
|
||||
}
|
||||
Map<String, String> roomMap = new HashMap<>();
|
||||
roomMap.put("roomId", json.getStr("roomId"));
|
||||
roomMap.put("qrcodeUrl", json.getStr("qrcode_url"));
|
||||
return roomMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建小程序直播间
|
||||
*
|
||||
* @param studio 小程序直播
|
||||
* @return 房间ID
|
||||
*/
|
||||
public boolean editRoom(Studio studio) {
|
||||
//获取token
|
||||
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
|
||||
//发送url
|
||||
String url = "https://api.weixin.qq.com/wxaapi/broadcast/room/editroom?access_token=" + token;
|
||||
|
||||
//修改直播间
|
||||
Map<String, String> map = this.mockRoom(token, studio);
|
||||
map.put("id", studio.getRoomId().toString());
|
||||
String content = HttpUtils.doPostWithJson(url, map);
|
||||
JSONObject json = new JSONObject(content);
|
||||
log.info("微信小程序直播间修改结果:" + content);
|
||||
if (!json.getStr("errcode").equals("0")) {
|
||||
throw new ServiceException(json.getStr("errmsg"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取直播间回放
|
||||
*
|
||||
@@ -118,16 +120,20 @@ public class WechatLivePlayerUtil {
|
||||
//获取token
|
||||
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
|
||||
//发送url
|
||||
String url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/push?access_token=" + token;
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
String url = "https://api.weixin.qq.com/wxaapi/broadcast/room/addgoods?access_token=" + token;
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
// 直播间回放
|
||||
map.put("goodsId", goodsId);
|
||||
Integer[] ids = {goodsId};
|
||||
map.put("ids", ids);
|
||||
// 商品ID
|
||||
map.put("roomId", roomId);
|
||||
String content = HttpUtils.doPostWithJson(url, map);
|
||||
JSONObject json = new JSONObject(content);
|
||||
log.info("微信小程序直播间推送商品:" + content);
|
||||
return json.getStr("errcode").equals("0");
|
||||
log.info("直播间导入商品:" + content);
|
||||
if (!json.getStr("errcode").equals("0")) {
|
||||
throw new ServiceException(json.getStr("errmsg"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -167,10 +173,10 @@ public class WechatLivePlayerUtil {
|
||||
//新建微信商品DTO
|
||||
GoodsInfo goodsInfo = new GoodsInfo(commodity);
|
||||
//上传微信临时图片
|
||||
goodsInfo.setCoverImgUrl(wechatMediaUtil.uploadMedia(token,"image",commodity.getGoodsImage()));
|
||||
Map<String,GoodsInfo> map=new HashMap<>();
|
||||
goodsInfo.setCoverImgUrl(wechatMediaUtil.uploadMedia(token, "image", commodity.getGoodsImage()));
|
||||
Map<String, GoodsInfo> map = new HashMap<>();
|
||||
//调用新增直播商品接口
|
||||
map.put("goodsInfo",goodsInfo);
|
||||
map.put("goodsInfo", goodsInfo);
|
||||
String content = HttpUtils.doPostWithJson(url, map);
|
||||
JSONObject json = new JSONObject(content);
|
||||
log.info("微信小程序添加直播商品结果:" + content);
|
||||
@@ -188,8 +194,8 @@ public class WechatLivePlayerUtil {
|
||||
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
|
||||
//发送url
|
||||
String url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/delete?access_token=" + token;
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
map.put("goodsId",goodsId);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("goodsId", goodsId);
|
||||
String content = HttpUtils.doPostWithJson(url, goodsId);
|
||||
JSONObject json = new JSONObject(content);
|
||||
log.info("微信小程序删除直播商品结果:" + content);
|
||||
@@ -207,12 +213,43 @@ public class WechatLivePlayerUtil {
|
||||
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
|
||||
//发送url
|
||||
String url = "https://api.weixin.qq.com/wxa/business/getgoodswarehouse?access_token=" + token;
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
map.put("goods_ids",goodsIdList);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("goods_ids", goodsIdList);
|
||||
String content = HttpUtils.doPostWithJson(url, map);
|
||||
JSONObject json = new JSONObject(content);
|
||||
log.info("微信小程序查询直播商品结果:" + content);
|
||||
return json;
|
||||
}
|
||||
|
||||
private Map<String, String> mockRoom(String token, Studio studio) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
// 背景图
|
||||
map.put("coverImg", wechatMediaUtil.uploadMedia(token, "image", studio.getCoverImg()));
|
||||
// 分享图
|
||||
map.put("shareImg", wechatMediaUtil.uploadMedia(token, "image", studio.getShareImg()));
|
||||
// 购物直播频道封面图
|
||||
map.put("feedsImg", wechatMediaUtil.uploadMedia(token, "image", studio.getFeedsImg()));
|
||||
// 直播间名字
|
||||
map.put("name", studio.getName());
|
||||
// 直播计划开始时间
|
||||
map.put("startTime", studio.getStartTime());
|
||||
// 直播计划结束时间
|
||||
map.put("endTime", studio.getEndTime());
|
||||
// 主播昵称
|
||||
map.put("anchorName", studio.getAnchorName());
|
||||
// 主播微信号
|
||||
map.put("anchorWechat", studio.getAnchorWechat());
|
||||
// 直播间类型
|
||||
map.put("type", "0");
|
||||
// 是否关闭点赞
|
||||
map.put("closeLike", "0");
|
||||
// 是否关闭货架
|
||||
map.put("closeGoods", "0");
|
||||
// 是否关闭评论
|
||||
map.put("closeComment", "0");
|
||||
// 直播间名字
|
||||
map.put("closeReplay", "0");
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user