Commit cebf01b2 authored by shiyu's avatar shiyu

后台商品维护

parent a03ada73
......@@ -11,6 +11,7 @@ import com.wwdz.ch.core.util.PriceUtil;
import com.wwdz.ch.db.dao.SwitchDao;
import com.wwdz.ch.db.dao.distribution.*;
import com.wwdz.ch.db.domain.distribution.*;
import com.wwdz.ch.db.dto.request.distribution.AuctionRecordRequestDto;
import com.wwdz.ch.db.dto.request.distribution.SupplierItemRequestDto;
import com.xxdxxs.utils.DateUtils;
import com.xxdxxs.utils.EntityMapper;
......@@ -22,6 +23,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
......@@ -55,6 +58,9 @@ public class SysSupplierItemServiceImpl implements SysSupplierItemService {
@Autowired
AuctionConfigDao auctionConfigDao;
@Autowired
AuctionRecordDao auctionRecordDao;
@Override
@Transactional
......@@ -170,24 +176,15 @@ public class SysSupplierItemServiceImpl implements SysSupplierItemService {
try {
//如果价格有改动,需要把分享的链接改为无效,先查询原来商品这使得价格
SupplierItem oldSupplierItem = supplierItemDao.findById(dto.getId());
long oldDistributionPrice = oldSupplierItem.getDistributionPrice();
if (oldDistributionPrice != PriceUtil.convertPriceFromStr(dto.getDistributionPrice())) {
//把该商品所关联的所有分享链接都改为无效
distributorShareRecordDao.updateDisEnabled(dto.getId());
logger.info("商品 id:{} 更改价格,分享链接改为无效", dto.getId());
}
SupplierItem supplierItem = new SupplierItem();
EntityMapper.copyAttribute(dto, supplierItem);
supplierItem.setDistributionPrice(PriceUtil.convertPriceFromStr(dto.getDistributionPrice()));
if (StringUtils.hasLength(dto.getSupplyPrice())) {
supplierItem.setSupplyPrice(PriceUtil.convertPriceFromStr(dto.getSupplyPrice()));
}
supplierItem.setImages(dto.getImages());
supplierItem.setVideos(dto.getVideos());
supplierItemDao.update(supplierItem);
//竞拍商品,维护竞拍配置
if (dto.getType() == DistributionEnum.DistributionTypeEnum.AUCTION.getCode()) {
//判断有无出价记录,有出价记录的竞拍商品不能修改或上架
AuctionRecordRequestDto auctionRecordRequestDto = new AuctionRecordRequestDto();
auctionRecordRequestDto.setItemId(dto.getId());
long count = auctionRecordDao.count(auctionRecordRequestDto);
if (count > 0) {
return Result.failed("有出价的竞拍商品不能再次编辑");
}
AuctionConfig auctionConfig = auctionConfigDao.findByItemId(dto.getId());
auctionConfig.setStartTime(DateUtils.parseString(dto.getAuctionStartTime()));
auctionConfig.setEndTime(DateUtils.parseString(dto.getAuctionEndTime()));
......@@ -201,6 +198,21 @@ public class SysSupplierItemServiceImpl implements SysSupplierItemService {
}
auctionConfigDao.update(auctionConfig);
}
long oldDistributionPrice = oldSupplierItem.getDistributionPrice();
if (oldDistributionPrice != PriceUtil.convertPriceFromStr(dto.getDistributionPrice())) {
//把该商品所关联的所有分享链接都改为无效
distributorShareRecordDao.updateDisEnabled(dto.getId());
logger.info("商品 id:{} 更改价格,分享链接改为无效", dto.getId());
}
SupplierItem supplierItem = new SupplierItem();
EntityMapper.copyAttribute(dto, supplierItem);
supplierItem.setDistributionPrice(PriceUtil.convertPriceFromStr(dto.getDistributionPrice()));
if (StringUtils.hasLength(dto.getSupplyPrice())) {
supplierItem.setSupplyPrice(PriceUtil.convertPriceFromStr(dto.getSupplyPrice()));
}
supplierItem.setImages(dto.getImages());
supplierItem.setVideos(dto.getVideos());
supplierItemDao.update(supplierItem);
return Result.success();
} catch (Exception e) {
logger.error("编辑商品失败 error : {}", e);
......@@ -213,20 +225,26 @@ public class SysSupplierItemServiceImpl implements SysSupplierItemService {
@Override
public Result updateOnSale(SupplierItemRequestDto dto) {
try {
SupplierItem supplierItem = new SupplierItem();
supplierItem.setId(dto.getId());
supplierItem.setIsOnSale(dto.getIsOnSale());
supplierItemDao.update(supplierItem);
SupplierItem oldItem = supplierItemDao.findById(dto.getId());
//下架的是竞拍品需要把拍卖配置信息改为无效
if (oldItem.getType() == DistributionEnum.DistributionTypeEnum.AUCTION.getCode()) {
if (!dto.getIsOnSale()) {
auctionConfigDao.setEnd(dto.getId());
} else {
//判断有无出价记录,有出价记录的竞拍商品不能修改或上架
AuctionRecordRequestDto auctionRecordRequestDto = new AuctionRecordRequestDto();
auctionRecordRequestDto.setItemId(dto.getId());
long count = auctionRecordDao.count(auctionRecordRequestDto);
if (count > 0) {
return Result.failed("有出价的竞拍商品不能重新上架");
}
auctionConfigDao.setValid(dto.getId());
}
}
SupplierItem supplierItem = new SupplierItem();
supplierItem.setId(dto.getId());
supplierItem.setIsOnSale(dto.getIsOnSale());
supplierItemDao.update(supplierItem);
return Result.success();
} catch (Exception e) {
logger.error("商品上下架失败 error : {}", e);
......
......@@ -56,6 +56,11 @@ public class AuctionOfferNoticeMsg implements Entity {
*/
private String userName;
/**
* 利润
*/
private String profit;
}
......
......@@ -315,7 +315,7 @@ public class SendMsgServiceImpl implements SendMsgService {
OkHttpUtil okHttpUtil = OkHttpUtil.builder().url(url);
Map<String, Object> map = new HashMap<>();
map.put("touser", openId);
map.put("template_id", "WJkhzyY0_7AYqh19_ujK93ISwKU1oniEgKKakYOdhfs");
map.put("template_id", "VVpkASCM6OgdbyERsy--hjPAI7fWuNJwtDDMR5EqVnM");
Map<String, Object> miniprogramMap = new HashMap<>();
miniprogramMap.put("appid", APPLET_APPID);
StringBuffer stringBuffer = new StringBuffer(AUCTION_MSG_URL);
......@@ -327,13 +327,13 @@ public class SendMsgServiceImpl implements SendMsgService {
map.put("miniprogram", miniprogramMap);
Map<String, Object> paramMap = new LinkedHashMap<>();
paramMap.put("thing2", new HashMap() {{
paramMap.put("thing1", new HashMap() {{
put("value", auctionOfferNoticeMsg.getItemName().substring(0, 20));
}});
paramMap.put("thing3", new HashMap() {{
put("value", "请及时付款");
paramMap.put("amount2", new HashMap() {{
put("value", auctionOfferNoticeMsg.getCurrentPrice());
}});
String content = "付款截止时间" + DateUtils.toString(auctionOfferNoticeMsg.getPayEndTime());
String content = "预计获得利润 " + auctionOfferNoticeMsg.getProfit() + "元";
paramMap.put("time4", new HashMap() {{
put("value", content);
}});
......@@ -359,12 +359,103 @@ public class SendMsgServiceImpl implements SendMsgService {
@Override
public Result aboutToEndMsg(AuctionOfferNoticeMsg auctionOfferNoticeMsg) {
return null;
try {
String openId = auctionOfferNoticeMsg.getOpenId();
String token = officialAccountApi.getAccessToken();
String url = SEND_MSG_URL + "?access_token=" + token;
OkHttpUtil okHttpUtil = OkHttpUtil.builder().url(url);
Map<String, Object> map = new HashMap<>();
map.put("touser", openId);
map.put("template_id", "D03X6N8zIiFrkbsVWFixJrvubLTS0yA-An1-rzuz5e4");
Map<String, Object> miniprogramMap = new HashMap<>();
miniprogramMap.put("appid", APPLET_APPID);
StringBuffer stringBuffer = new StringBuffer(AUCTION_MSG_URL);
stringBuffer.append("?itemId=" + auctionOfferNoticeMsg.getItemId());
if (StringUtils.hasLength(auctionOfferNoticeMsg.getShareRecordId())) {
stringBuffer.append("&shareRecordId=" + auctionOfferNoticeMsg.getShareRecordId());
}
miniprogramMap.put("pagepath", stringBuffer.toString());
map.put("miniprogram", miniprogramMap);
Map<String, Object> paramMap = new LinkedHashMap<>();
paramMap.put("thing1", new HashMap() {{
put("value", auctionOfferNoticeMsg.getItemName().substring(0, 20));
}});
paramMap.put("amount2", new HashMap() {{
put("value", auctionOfferNoticeMsg.getAmount());
}});
String content = "竞拍将在一小时内结束";
paramMap.put("time3", new HashMap() {{
put("value", content);
}});
map.put("data", paramMap);
logger.info("============ 竞拍即将结束模板消息内容 : {}", JsonUtils.fromMap(map));
okHttpUtil.addParams(map);
okHttpUtil.post(true);
String responseStr = okHttpUtil.async();
logger.info("openid : {}, 发送通竞拍即将结束模板消息 response :{}", openId, responseStr);
String errorCode = JsonUtils.getValueByPath(responseStr, "errcode");
String errmsg = JsonUtils.getValueByPath(responseStr, "errmsg");
if (!"0".equals(errorCode)) {
logger.error("openid : {}, 发送通竞拍即将结束模板消息, errorCode : {}, errmsg : {} ", openId, errorCode, errmsg);
return Result.failed();
}
logger.info("=============发送通竞拍即将结束模板消息 成功 ===========");
return Result.success();
} catch (Exception e) {
e.printStackTrace();
}
return Result.failed();
}
@Override
public Result auctionEndMsg(AuctionOfferNoticeMsg auctionOfferNoticeMsg) {
return null;
try {
String openId = auctionOfferNoticeMsg.getOpenId();
String token = officialAccountApi.getAccessToken();
String url = SEND_MSG_URL + "?access_token=" + token;
OkHttpUtil okHttpUtil = OkHttpUtil.builder().url(url);
Map<String, Object> map = new HashMap<>();
map.put("touser", openId);
map.put("template_id", "z7EQt_ZrcSSd2GgtI4wh630v-QCXzRTG7eO86-vYvhs");
Map<String, Object> miniprogramMap = new HashMap<>();
miniprogramMap.put("appid", APPLET_APPID);
StringBuffer stringBuffer = new StringBuffer(AUCTION_MSG_URL);
stringBuffer.append("?itemId=" + auctionOfferNoticeMsg.getItemId());
if (StringUtils.hasLength(auctionOfferNoticeMsg.getShareRecordId())) {
stringBuffer.append("&shareRecordId=" + auctionOfferNoticeMsg.getShareRecordId());
}
miniprogramMap.put("pagepath", stringBuffer.toString());
map.put("miniprogram", miniprogramMap);
Map<String, Object> paramMap = new LinkedHashMap<>();
paramMap.put("thing1", new HashMap() {{
put("value", auctionOfferNoticeMsg.getItemName().substring(0, 20));
}});
paramMap.put("amount2", new HashMap() {{
put("value", auctionOfferNoticeMsg.getCurrentPrice());
}});
paramMap.put("time3", new HashMap() {{
put("value", DateUtils.toString(auctionOfferNoticeMsg.getAuctionEndTime()));
}});
map.put("data", paramMap);
logger.info("============ 竞拍结束模板消息内容 : {}", JsonUtils.fromMap(map));
okHttpUtil.addParams(map);
okHttpUtil.post(true);
String responseStr = okHttpUtil.async();
logger.info("openid : {}, 发送竞拍结束模板消息 response :{}", openId, responseStr);
String errorCode = JsonUtils.getValueByPath(responseStr, "errcode");
String errmsg = JsonUtils.getValueByPath(responseStr, "errmsg");
if (!"0".equals(errorCode)) {
logger.error("openid : {}, 发送竞拍结束模板消息, errorCode : {}, errmsg : {} ", openId, errorCode, errmsg);
return Result.failed();
}
logger.info("=============发送竞拍结束模板消息 成功 ===========");
return Result.success();
} catch (Exception e) {
e.printStackTrace();
}
return Result.failed();
}
@Override
......
......@@ -89,12 +89,12 @@ public class WxPayServiceTest {
@Test
public void refund() {
List<String> list = Arrays.asList("DA2403061107510927305", "DA2403061103288138522");
List<String> list = Arrays.asList("DA2403111801535237724");
list.forEach(orderId ->{
DistributionOrderRequestDto dto = new DistributionOrderRequestDto();
dto.setDistributionOrderId(orderId);
dto.setAmount("6.8");
dto.setRefundPrice("6.8");
dto.setAmount("3.0");
dto.setRefundPrice("3.0");
Result result = wxPayServiceApi.refund(dto);
logger.info("申请微信支付退款:{}", result);
});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment