运营后台可设置推荐直播间

This commit is contained in:
lifenlong 2021-05-28 12:10:33 +08:00
parent c58524cf94
commit 814d118d77
10 changed files with 264 additions and 63 deletions

View File

@ -1,13 +1,14 @@
package cn.lili.controller.other.broadcast;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.utils.PageUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.broadcast.entity.dos.Studio;
import cn.lili.modules.broadcast.service.StudioService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@ -29,14 +30,18 @@ public class StudioController {
private StudioService studioService;
@ApiOperation(value = "获取店铺直播间列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "recommend", value = "是否推荐", paramType = "query", dataType = "int"),
@ApiImplicitParam(name = "status", value = "直播间状态", paramType = "query", dataType = "String")
})
@GetMapping
public ResultMessage<IPage<Studio>> page(PageVO pageVO) {
return ResultUtil.data(studioService.page(PageUtil.initPage(pageVO)));
public ResultMessage<IPage<Studio>> page(PageVO pageVO, Integer recommend, String status) {
return ResultUtil.data(studioService.studioList(pageVO, recommend, status));
}
@ApiOperation(value = "获取店铺直播间回放地址")
@GetMapping("/getLiveInfo/{roomId}")
public ResultMessage<Object> getLiveInfo(Integer roomId){
public ResultMessage<Object> getLiveInfo(Integer roomId) {
return ResultUtil.data(studioService.getLiveInfo(roomId));
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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());

View File

@ -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));
}
}

View File

@ -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;
}
}

View File

@ -0,0 +1,41 @@
package cn.lili.controller.other.broadcast;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.broadcast.entity.vos.CommodityVO;
import cn.lili.modules.broadcast.service.CommodityService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 管理端,直播间管理接口
*
* @author Bulbasaur
* @date: 2021/5/28 11:56 上午
*/
@RestController
@Api(tags = "店铺端,直播商品接口")
@RequestMapping("/manager/broadcast/commodity")
public class CommodityManagerController {
@Autowired
private CommodityService commodityService;
@ApiOperation(value = "获取店铺直播商品列表")
@ApiImplicitParams({
@ApiImplicitParam(name = "name", value = "商品名称", dataType = "String", paramType = "query"),
@ApiImplicitParam(name = "auditStatus", value = "直播商品状态", dataType = "String", paramType = "query")
})
@GetMapping
public ResultMessage<IPage<CommodityVO>> page(String auditStatus, String name, PageVO pageVO) {
return ResultUtil.data(commodityService.commodityList(pageVO, name, auditStatus));
}
}

View File

@ -0,0 +1,64 @@
package cn.lili.controller.other.broadcast;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.broadcast.entity.dos.Studio;
import cn.lili.modules.broadcast.service.StudioService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 管理端,直播间接口
*
* @author Bulbasaur
* @date: 2021/5/28 11:56 上午
*/
@RestController
@Api(tags = "店铺端,直播商品接口")
@RequestMapping("/manager/broadcast/studio")
public class StudioManagerController {
@Autowired
private StudioService studioService;
@ApiOperation(value = "获取店铺直播间列表")
@ApiImplicitParam(name = "status", value = "直播间状态", paramType = "query", dataType = "String")
@GetMapping
public ResultMessage<IPage<Studio>> page(PageVO pageVO, String status) {
return ResultUtil.data(studioService.studioList(pageVO, null, status));
}
@ApiOperation(value = "获取店铺直播间详情")
@ApiImplicitParam(name = "studioId", value = "直播间ID", required = true, dataType = "String", paramType = "path")
@GetMapping("/studioInfo/{studioId}")
public ResultMessage<Studio> studioInfo(@PathVariable String studioId) {
return ResultUtil.data(studioService.getById(studioId));
}
@ApiOperation(value = "是否推荐直播间")
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "Id", required = true, dataType = "String", paramType = "path"),
@ApiImplicitParam(name = "recommend", value = "是否推荐", required = true, dataType = "boolean", paramType = "path")
})
@GetMapping("/id/{studioId}")
public ResultMessage<Object> recommend(@PathVariable String id, @PathVariable boolean recommend) {
if (studioService.update(new UpdateWrapper<Studio>()
.eq("id", id)
.set("recommend", recommend))) {
return ResultUtil.success();
}
throw new ServiceException(ResultCode.ERROR);
}
}

View File

@ -27,7 +27,7 @@ import java.util.List;
@RestController
@Api(tags = "店铺端,直播商品接口")
@RequestMapping("/store/broadcast/commodity")
public class CommodityController {
public class CommodityStoreController {
@Autowired
private CommodityService commodityService;

View File

@ -3,12 +3,10 @@ package cn.lili.controller.other.broadcast;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.utils.PageUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.broadcast.entity.dos.Studio;
import cn.lili.modules.broadcast.service.StudioService;
import cn.lili.modules.message.util.WechatAccessTokenUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@ -28,17 +26,16 @@ import org.springframework.web.bind.annotation.*;
@RestController
@Api(tags = "店铺端,直播间接口")
@RequestMapping("/store/broadcast/studio")
public class StudioController {
public class StudioStoreController {
@Autowired
private StudioService studioService;
@Autowired
private WechatAccessTokenUtil wechatAccessTokenUtil;
@ApiOperation(value = "获取店铺直播间列表")
@ApiImplicitParam(name = "status", value = "直播间状态", paramType = "query", dataType = "String")
@GetMapping
public ResultMessage<IPage<Studio>> page(PageVO pageVO) {
return ResultUtil.data(studioService.page(PageUtil.initPage(pageVO)));
public ResultMessage<IPage<Studio>> page(PageVO pageVO, String status) {
return ResultUtil.data(studioService.studioList(pageVO, null, status));
}
@ApiOperation(value = "获取店铺直播间详情")
@ -57,6 +54,15 @@ public class StudioController {
throw new ServiceException(ResultCode.ERROR);
}
@ApiOperation(value = "修改直播间")
@PutMapping("/edit")
public ResultMessage<Object> edit(@Validated Studio studio) {
if (studioService.edit(studio)) {
return ResultUtil.success(ResultCode.SUCCESS);
}
throw new ServiceException(ResultCode.ERROR);
}
@ApiOperation(value = "店铺直播间添加商品")
@ApiImplicitParams({
@ApiImplicitParam(name = "roomId", value = "房间ID", required = true, dataType = "Integer", paramType = "path"),