1.增加直播商品
2.同步直播商品状态 3.展示状态展示直播商品列表
This commit is contained in:
parent
d9ccc4a7b7
commit
a9ec03f0a4
@ -77,7 +77,7 @@ spring:
|
||||
default-datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driverClassName: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/lilishop?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
url: jdbc:mysql://127.0.0.1:3306/Bulbasaur?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: lilishop
|
||||
maxActive: 20
|
||||
|
@ -17,7 +17,7 @@ import javax.persistence.Table;
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
@ApiModel(value = "直播商品")
|
||||
@ApiModel(value = "Commodity", description = "直播商品")
|
||||
@TableName("li_commodity")
|
||||
@Table(name = "li_commodity")
|
||||
public class Commodity extends BaseEntity {
|
||||
|
@ -0,0 +1,19 @@
|
||||
package cn.lili.modules.broadcast.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 直播商品DTO
|
||||
* 用于获取直播商品状态时使用
|
||||
*
|
||||
* @author Bulbasaur
|
||||
* @date: 2021/5/25 12:12 下午
|
||||
*/
|
||||
@Data
|
||||
public class CommodityDTO {
|
||||
|
||||
private Integer goods_id;
|
||||
private String name;
|
||||
private String url;
|
||||
private Integer audit_status;
|
||||
}
|
@ -15,8 +15,8 @@ import java.util.List;
|
||||
*/
|
||||
public interface CommodityMapper extends BaseMapper<Commodity> {
|
||||
|
||||
@Select("SELECT live_goods_id FROM li_commodity WHERE audit_status='0' or audit_status='1' AND store_id =#{storeId}")
|
||||
List<String> getAuditCommodity(String storeId);
|
||||
@Select("SELECT live_goods_id FROM li_commodity WHERE audit_status='0' or audit_status='1'")
|
||||
List<String> getAuditCommodity();
|
||||
|
||||
@Select("SELECT * FROM li_commodity c WINNER JOIN li_studio_commodity sc ON sc.goods_id = c.live_goods_id WHERE sc.room_id =#{roomId}")
|
||||
List<Commodity> getCommodityByRoomId(Integer roomId);
|
||||
|
@ -1,6 +1,8 @@
|
||||
package cn.lili.modules.broadcast.service;
|
||||
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.modules.broadcast.entity.dos.Commodity;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
@ -30,4 +32,13 @@ public interface CommodityService extends IService<Commodity> {
|
||||
* 查询微信小程序直播商品审核状态
|
||||
*/
|
||||
void getGoodsWareHouse();
|
||||
|
||||
/**
|
||||
* 查看直播商品分页
|
||||
* @param pageVO 分页
|
||||
* @param name 商品名称
|
||||
* @param auditStatus 审核状态
|
||||
* @return 直播商品分页
|
||||
*/
|
||||
IPage<Commodity> commodityList(PageVO pageVO,String name,String auditStatus);
|
||||
}
|
||||
|
@ -1,18 +1,25 @@
|
||||
package cn.lili.modules.broadcast.serviceimpl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.lili.common.security.context.UserContext;
|
||||
import cn.lili.common.utils.PageUtil;
|
||||
import cn.lili.common.vo.PageVO;
|
||||
import cn.lili.modules.broadcast.entity.dos.Commodity;
|
||||
import cn.lili.modules.broadcast.entity.dto.CommodityDTO;
|
||||
import cn.lili.modules.broadcast.mapper.CommodityMapper;
|
||||
import cn.lili.modules.broadcast.service.CommodityService;
|
||||
import cn.lili.modules.broadcast.util.WechatLivePlayerUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 直播商品业务层实现
|
||||
@ -28,7 +35,7 @@ public class CommodityServiceImpl extends ServiceImpl<CommodityMapper, Commodity
|
||||
|
||||
@Override
|
||||
public boolean addCommodity(List<Commodity> commodityList) {
|
||||
for (Commodity commodity:commodityList) {
|
||||
for (Commodity commodity : commodityList) {
|
||||
JSONObject json = wechatLivePlayerUtil.addGoods(commodity);
|
||||
commodity.setLiveGoodsId(Convert.toInt(json.getStr("goodsId")));
|
||||
commodity.setAuditId(json.getStr("auditId"));
|
||||
@ -49,18 +56,27 @@ public class CommodityServiceImpl extends ServiceImpl<CommodityMapper, Commodity
|
||||
@Override
|
||||
public void getGoodsWareHouse() {
|
||||
//查询审核中的商品
|
||||
List<String> goodsIdList = this.baseMapper.getAuditCommodity(UserContext.getCurrentUser().getStoreId());
|
||||
//同步状态
|
||||
JSONObject json = wechatLivePlayerUtil.getGoodsWareHouse(goodsIdList);
|
||||
//修改状态
|
||||
List<Map<String, String>> list = (List) json.get("goods");
|
||||
for (Map<String, String> map : list) {
|
||||
//修改审核状态
|
||||
this.update(this.lambdaUpdate()
|
||||
.eq(Commodity::getLiveGoodsId, map.get("goods_id"))
|
||||
.set(Commodity::getAuditStatus, map.get("audit_status")));
|
||||
List<String> goodsIdList = this.baseMapper.getAuditCommodity();
|
||||
if (goodsIdList.size() > 0) {
|
||||
//同步状态
|
||||
JSONObject json = wechatLivePlayerUtil.getGoodsWareHouse(goodsIdList);
|
||||
//修改状态
|
||||
List<CommodityDTO> commodityDTOList = JSONUtil.toList((JSONArray) json.get("goods"), CommodityDTO.class);
|
||||
for (CommodityDTO commodityDTO : commodityDTOList) {
|
||||
//修改审核状态
|
||||
this.update(new LambdaUpdateWrapper<Commodity>()
|
||||
.eq(Commodity::getLiveGoodsId, commodityDTO.getGoods_id())
|
||||
.set(Commodity::getAuditStatus, commodityDTO.getAudit_status()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<Commodity> commodityList(PageVO pageVO, String name, String auditStatus) {
|
||||
return this.page(PageUtil.initPage(pageVO),
|
||||
new LambdaQueryWrapper<Commodity>().like(name!=null,Commodity::getName,name)
|
||||
.eq(auditStatus!=null,Commodity::getAuditStatus,auditStatus));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -164,8 +164,12 @@ public class WechatLivePlayerUtil {
|
||||
String url = "https://api.weixin.qq.com/wxaapi/broadcast/goods/add?access_token=" + token;
|
||||
//新建微信商品DTO
|
||||
GoodsInfo goodsInfo = new GoodsInfo(commodity);
|
||||
//上传微信临时图片
|
||||
goodsInfo.setCoverImgUrl(wechatMediaUtil.uploadMedia(token,"image",commodity.getGoodsImage()));
|
||||
String content = HttpUtils.doPostWithJson(url, goodsInfo);
|
||||
Map<String,GoodsInfo> map=new HashMap<>();
|
||||
//调用新增直播商品接口
|
||||
map.put("goodsInfo",goodsInfo);
|
||||
String content = HttpUtils.doPostWithJson(url, map);
|
||||
JSONObject json = new JSONObject(content);
|
||||
log.info("微信小程序添加直播商品结果:" + content);
|
||||
return json;
|
||||
@ -182,6 +186,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);
|
||||
String content = HttpUtils.doPostWithJson(url, goodsId);
|
||||
JSONObject json = new JSONObject(content);
|
||||
log.info("微信小程序删除直播商品结果:" + content);
|
||||
@ -199,7 +205,9 @@ public class WechatLivePlayerUtil {
|
||||
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
|
||||
//发送url
|
||||
String url = "https://api.weixin.qq.com/wxa/business/getgoodswarehouse?access_token=" + token;
|
||||
String content = HttpUtils.doPostWithJson(url, 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;
|
||||
|
@ -572,6 +572,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
StringBuilder goodsName = new StringBuilder(goods.getGoodsName());
|
||||
//规格商品缩略图
|
||||
String thumbnail = "";
|
||||
String small = "";
|
||||
//规格值
|
||||
Map<String, Object> specMap = new HashMap<>();
|
||||
//商品属性
|
||||
@ -591,6 +592,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
throw new ServiceException("sku图片至少为一个");
|
||||
}
|
||||
thumbnail = goodsGalleryService.getGoodsGallery(images.get(0).get("url")).getThumbnail();
|
||||
small = goodsGalleryService.getGoodsGallery(images.get(0).get("url")).getSmall();
|
||||
} else {
|
||||
//设置商品名称
|
||||
goodsName.append(" ").append(m.getValue());
|
||||
@ -615,6 +617,7 @@ public class GoodsSkuServiceImpl extends ServiceImpl<GoodsSkuMapper, GoodsSku> i
|
||||
//设置规格信息
|
||||
sku.setGoodsName(goodsName.toString());
|
||||
sku.setThumbnail(thumbnail);
|
||||
sku.setSmall(small);
|
||||
|
||||
//规格信息
|
||||
sku.setId(Convert.toStr(map.get("id"), "").toString());
|
||||
|
@ -3,16 +3,16 @@ 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.Commodity;
|
||||
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.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@ -32,14 +32,19 @@ public class CommodityController {
|
||||
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<Commodity>> page(PageVO pageVO) {
|
||||
return ResultUtil.data(commodityService.page(PageUtil.initPage(pageVO)));
|
||||
public ResultMessage<IPage<Commodity>> page(String auditStatus, String name, PageVO pageVO) {
|
||||
return ResultUtil.data(commodityService.commodityList(pageVO, name, auditStatus));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "添加店铺直播商品")
|
||||
@ApiImplicitParam(name = "commodityList", value = "直播商品列表", paramType = "body", allowMultiple = true, dataType = "Commodity")
|
||||
@PostMapping
|
||||
public ResultMessage<Object> addCommodity(@Validated List<Commodity> commodityList) {
|
||||
public ResultMessage<Object> addCommodity(@RequestBody List<Commodity> commodityList) {
|
||||
if (commodityService.addCommodity(commodityList)) {
|
||||
return ResultUtil.success(ResultCode.SUCCESS);
|
||||
}
|
||||
@ -47,8 +52,9 @@ public class CommodityController {
|
||||
}
|
||||
|
||||
@ApiOperation(value = "删除店铺直播商品")
|
||||
@DeleteMapping
|
||||
public ResultMessage<Object> delete(String goodsId) {
|
||||
@ApiImplicitParam(name = "goodsId", value = "直播商品ID", dataType = "String", paramType = "path")
|
||||
@DeleteMapping("/{goodsId}")
|
||||
public ResultMessage<Object> delete(@PathVariable String goodsId) {
|
||||
if (commodityService.deleteCommodity(goodsId)) {
|
||||
return ResultUtil.success(ResultCode.SUCCESS);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user