Commit cd124985 authored by 秦兴亮's avatar 秦兴亮

Merge branch 'dev' of https://gitlab.33.cn/yimu/mall-server into dev

parents 77004fe0 ef38da45
package com.fzm.mall.server.admin.goods_center.entity.vo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fzm.mall.server.admin.constant.MALLGlobalConfig;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
......@@ -49,20 +48,4 @@ public class GoodsSpuVO {
@TableField(exist = false)
private String tokenIdStr;
@ApiModelProperty(value = "1.外部nft;2.内部nft;3.内部普通")
@TableField(exist = false)
private Integer coinType;
@ApiModelProperty(value = "nft销售方式(1.原商品销售 2.拷贝销售)")
@TableField(exist = false)
private Integer nftSalesType;
public void initTokenId() {
setTokenId(Long.valueOf(getTokenIdStr().replace(MALLGlobalConfig.NFT_PREFIX, "")));
// if (commodityPass.equals(COMMODITY_PASS_OUT)) {
// setTokenId(Long.valueOf(tokenIdStr));
// } else if (commodityPass.equals(COMMODITY_PASS_AUTO) && type == 6) {
// setTokenId(Long.valueOf(getTokenIdStr().replace(MALLGlobalConfig.NFT_PREFIX, "")));
// }
}
}
......@@ -25,8 +25,4 @@ public interface SpuMapper extends BaseMapper<Spu> {
List<GoodsListVO> queryByNameOrId(@Param("merchantId") String merchantId,
@Param("spuStatusOnSale") Integer spuStatusOnSale,
@Param("goods") String goods);
GoodsSpuVO readByCoin(@Param("merchantId") String merchantId,
@Param("coin") String coin);
}
......@@ -371,7 +371,7 @@ public class SpuServiceImpl extends ServiceImpl<SpuMapper, Spu> implements ISpuS
//TODO banner 推荐商品是否删除
Spu spu = getByGoodsId(goodsId);
if (spu.getCommodityPass().equals(2)) {
if (!spu.getCommodityPass().equals(1)) {
LambdaQueryWrapper<Sku> qw1 = new LambdaQueryWrapper<>();
qw1.eq(Sku::getGoodsId, goodsId);
Sku sku = skuService.getOne(qw1);
......
......@@ -33,5 +33,5 @@ public interface IAssetService extends IService<Asset> {
*/
void integralDeduction(String oid, String uid, BigDecimal amount, String merchantId, List<OrderDetail> orderDetailList, Boolean isApproved);
void refundCoinOnChain(int tableType, String tableId, String merchantId, String coin, int number, String serialNo, String fromAddr, String toAddr);
void refundCoinOnChain(int tableType, String tableId, String merchantId, String coin, String skuId, int number, String serialNo, String fromAddr, String toAddr);
}
......@@ -11,8 +11,10 @@ import com.fzm.mall.server.admin.constant.MallResponseError;
import com.fzm.mall.server.admin.exception.MyException;
import com.fzm.mall.server.admin.goods_center.entity.vo.GoodsSpuVO;
import com.fzm.mall.server.admin.goods_center.mapper.GoodsSkuUsufructMapper;
import com.fzm.mall.server.admin.goods_center.mapper.SkuMapper;
import com.fzm.mall.server.admin.goods_center.mapper.SpuMapper;
import com.fzm.mall.server.admin.goods_center.model.GoodsSkuUsufruct;
import com.fzm.mall.server.admin.goods_center.model.Sku;
import com.fzm.mall.server.admin.goods_center.model.Spu;
import com.fzm.mall.server.admin.home_page.model.Merchant;
import com.fzm.mall.server.admin.home_page.service.IMerchantService;
......@@ -73,6 +75,8 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
private WxPayUtil wxPayUtil;
@Autowired
private GoodsSkuUsufructMapper goodsSkuUsufructMapper;
@Autowired
private SkuMapper skuMapper;
/**
* 商品订单退款-积分还原,商品币还原
......@@ -107,12 +111,13 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
}
@Override
public void refundCoinOnChain(int tableType, String tableId, String merchantId, String coin, int number, String serialNo, String fromAddr, String toAddr) {
//判断商品是否为NFT
GoodsSpuVO goodsSpu = spuMapper.readByCoin(merchantId, coin);
goodsSpu.initTokenId();
boolean isSalesNFTCopy = goodsSpu.getNftSalesType().equals(Spu.NFT_SALES_TYPE_COPY);
boolean commodityPassAuto = goodsSpu.getCommodityPass().equals(Spu.COMMODITY_PASS_AUTO);
public void refundCoinOnChain(int tableType, String tableId, String merchantId, String coin, String skuId, int number, String serialNo, String fromAddr, String toAddr) {
QueryWrapper<Sku> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("sku_id", skuId);
Sku sku = skuMapper.selectOne(queryWrapper);
boolean isSalesNFTCopy = sku.getNftSalesType().equals(Spu.NFT_SALES_TYPE_COPY);
/**
* 只有订单退款时,买家将商品币退还商家,商家刷一下退回的币的编号为可用
*/
......@@ -131,11 +136,12 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
*/
if (isSalesNFTCopy) {
serialNoList.forEach(index -> {
Long tokenId = Long.valueOf(index);
payInChain(tableType, tableId, fromAddr, toAddr, coin, 1, tokenId, commodityPassAuto, isSalesNFTCopy);
Long copyTokenId = Long.valueOf(index);
payInChain(tableType, tableId, fromAddr, toAddr, coin, 1, copyTokenId);
});
} else {
payInChain(tableType, tableId, fromAddr, toAddr, coin, number, goodsSpu.getTokenId(), commodityPassAuto, isSalesNFTCopy);
Long tokenId = Long.valueOf(coin.replace(MALLGlobalConfig.NFT_PREFIX, ""));
payInChain(tableType, tableId, fromAddr, toAddr, coin, number, tokenId);
}
}
}
......@@ -209,7 +215,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
if (update == 0) {
throw new MyException(MallResponseError.UPDATE_FAIL);
}
refundCoinOnChain(TranDto.TABLE_TYPE_ORDER_INFO, orderDetail.getOid(), merchantId, orderDetail.getCoin(), orderDetail.getNumber(), orderDetail.getSerialNo(), user.getAddress(), merchant.getTokenIssueAddr());
refundCoinOnChain(TranDto.TABLE_TYPE_ORDER_INFO, orderDetail.getOid(), merchantId, orderDetail.getCoin(), orderDetail.getSkuId(), orderDetail.getNumber(), orderDetail.getSerialNo(), user.getAddress(), merchant.getTokenIssueAddr());
});
} else {
orderDetailList.forEach(orderDetail -> {
......@@ -231,8 +237,7 @@ public class AssetServiceImpl extends ServiceImpl<AssetMapper, Asset> implements
}
}
private void payInChain(int tableType, String tableId, String fromAddr, String toAddr, String coin, int number,
Long tokenId, boolean commodityPassAuto, boolean isSalesNFTCopy) {
private void payInChain(int tableType, String tableId, String fromAddr, String toAddr, String coin, int number, Long tokenId) {
TranDto tranDto = new TranDto();
tranDto.setFromAddr(fromAddr);
tranDto.setToAddr(toAddr);
......
......@@ -128,14 +128,4 @@
</if>
</where>
</select>
<select id="readByCoin" resultType="com.fzm.mall.server.admin.goods_center.entity.vo.GoodsSpuVO">
select sp.type, sp.commodity_pass, IFNULL(n.token_id, t.token_id) tokenIdStr, s.nft_sales_type as nftSalesType
from goods_sku s
left join goods_spu sp on s.goods_id = sp.goods_id
left join goods_nft n on sp.commodity_pass = 1 and sp.type = 6 and sp.goods_id = n.goods_id
left join external_token t on sp.commodity_pass = 2 and s.commodity_pass_id = t.commodity_pass_id
where s.status = 1
and s.coin_name = #{coin} and sp.merchant_id = #{merchantId}
</select>
</mapper>
......@@ -34,4 +34,6 @@ public class UserAssetVo {
@ApiModelProperty(value = "溯源hash")
@TableField(exist = false)
private String hash;
@ApiModelProperty(value = "商品币对于skuId")
private String goodsCoin;
}
......@@ -13,9 +13,11 @@ import com.fzm.mall.server.front.asset.model.UserAssetTransferRecord;
import com.fzm.mall.server.front.asset.model.dto.UserAssetTransferRecordSaveDTO;
import com.fzm.mall.server.front.asset.model.vo.UserAssetTransferRecordVO;
import com.fzm.mall.server.front.asset.service.IUserAssetTransferRecordService;
import com.fzm.mall.server.front.constant.MALLGlobalConfig;
import com.fzm.mall.server.front.enums.QueueTTLTypeEnum;
import com.fzm.mall.server.front.goods.mapper.GoodSpuMapper;
import com.fzm.mall.server.front.goods.mapper.SkuMapper;
import com.fzm.mall.server.front.goods.model.GoodSpu;
import com.fzm.mall.server.front.goods.model.Sku;
import com.fzm.mall.server.front.goods.model.Spu;
import com.fzm.mall.server.front.mq.MsgProducer;
import com.fzm.mall.server.front.order.model.po.TranDto;
......@@ -61,7 +63,7 @@ public class UserAssetTransferRecordServiceImpl extends ServiceImpl<UserAssetTra
private UserMapper userMapper;
@Autowired
private GoodSpuMapper goodSpuMapper;
private SkuMapper skuMapper;
@Override
public void save(UserAssetTransferRecordSaveDTO saveDTO) {
......@@ -72,9 +74,18 @@ public class UserAssetTransferRecordServiceImpl extends ServiceImpl<UserAssetTra
User user = userMapper.selectOne(new QueryWrapper<User>().eq("uid", record.getUid()));
User userRecive = userMapper.selectOne(new QueryWrapper<User>().eq("address", record.getToAddress()));
GoodSpu goodsSpu = goodSpuMapper.readByCoin(record.getCoin());
goodsSpu.initTokenId();
String hash = logTransferRecord(user, userRecive, amount, record.getCoin(), goodsSpu);
QueryWrapper<Sku> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("sku_id", saveDTO.getSkuId());
Sku sku = skuMapper.selectOne(queryWrapper);
boolean isSalesNFTCopy = sku.getNftSalesType().equals(GoodSpu.NFT_SALES_TYPE_COPY);
Long tokenId;
if (isSalesNFTCopy){
tokenId = Long.valueOf(saveDTO.getCoin());
}else{
tokenId = Long.valueOf(saveDTO.getCoin().replace(MALLGlobalConfig.GOODS_NFT_PREFIX, ""));
}
String hash = logTransferRecord(user, userRecive, amount, tokenId);
record.init(userRecive.getUid(), inChain);
recordMapper.insert(record);
......@@ -85,33 +96,26 @@ public class UserAssetTransferRecordServiceImpl extends ServiceImpl<UserAssetTra
/**
* 链上转账
*/
transferInChain(user.getAddress(), record.getCoin(), record.getToAddress(), record.getNum(), record.getTransferRecordId(), hash, goodsSpu.getTokenId(), goodsSpu.getCoinType());
transferInChain(user.getAddress(), record.getCoin(), record.getToAddress(), record.getNum(), record.getTransferRecordId(), hash, tokenId);
}
}
private String logTransferRecord(User user, User userRecive, BigDecimal amount, String coin, GoodSpu goodSpu) {
private String logTransferRecord(User user, User userRecive, BigDecimal amount, Long tokenId) {
if (userRecive == null || user.getAddress().equals(userRecive.getAddress())) {
throw new RuntimeException("addr_invalid");
}
boolean isSalesNFTCopy = goodSpu.getNftSalesType().equals(GoodSpu.NFT_SALES_TYPE_COPY);
boolean commodityPassAuto = goodSpu.getCommodityPass().equals(Spu.COMMODITY_PASS_AUTO);
boolean doEvmExec = true;
/**
* 商品为外部导入或者NFT销售类型为“原商品销售”,用外部NFT转账合约
* 一幕所有的nft都是内部nft
*/
if (commodityPassAuto || isSalesNFTCopy) {
doEvmExec = false;
}
boolean doEvmExec = false;
String hash;
if (doEvmExec) {
long[] tokenIds = new long[]{goodSpu.getTokenId()};
long[] tokenIds = new long[]{tokenId};
long[] amounts = new long[]{amount.longValue()};
hash = chainUtil.evmExec(tokenIds, amounts, user.getAddress(), userRecive.getAddress());
goodSpu.setCoinType(TranDto.COIN_TYPE_NFT_OUT);
} else {
hash = chainUtil.evmTransfer(userRecive.getAddress(), user.getAddress(), goodSpu.getTokenId(), amount.longValue());
goodSpu.setCoinType(TranDto.COIN_TYPE_NFT_IN);
hash = chainUtil.evmTransfer(userRecive.getAddress(), user.getAddress(), tokenId, amount.longValue());
}
return hash;
}
......@@ -123,7 +127,7 @@ public class UserAssetTransferRecordServiceImpl extends ServiceImpl<UserAssetTra
* @param toAddress
* @param num
*/
private void transferInChain(String fromAddress, String coin, String toAddress, Integer num, String transferRecordId, String hash, Long tokenId, Integer coinType) {
private void transferInChain(String fromAddress, String coin, String toAddress, Integer num, String transferRecordId, String hash, Long tokenId) {
/**
* 如果配置为不走链,则不操作链上资产
*/
......@@ -140,7 +144,6 @@ public class UserAssetTransferRecordServiceImpl extends ServiceImpl<UserAssetTra
tranDto.setTableType(TranDto.USER_ASSET_TRANSFER);
tranDto.setHash(hash);
tranDto.setTokenId(tokenId);
tranDto.setCoinType(coinType);
producer.sendTTL(JSON.toJSONString(tranDto), QueueTTLTypeEnum.MALL_USER_ASSET_TRANSFER_TTL, 5 * 1000);
}
......
......@@ -19,8 +19,6 @@ public interface GoodSpuMapper extends BaseMapper<GoodSpu> {
@Select("select template_id from goods_spu where goods_id = #{goodsId}")
String getTemplateIdByGoodsId(@Param("goodsId") String goodsId);
GoodSpu readByCoin(@Param("coin") String coin);
@Select("select a.commodity_pass from goods_spu a left join goods_sku b on a.goods_id = b.goods_id where b.sku_id = #{skuId} ")
int getCommodityBySkuId(@Param("skuId") String skuId);
......
......@@ -5,6 +5,7 @@ import com.fzm.mall.server.front.goods.model.Sku;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fzm.mall.server.front.goods.model.vo.SkuVo;
import com.fzm.mall.server.front.order.model.vo.ShopInfoVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
......@@ -19,6 +20,7 @@ import java.util.List;
* @author fzm
* @since 2021-03-09
*/
@Mapper
public interface SkuMapper extends BaseMapper<Sku> {
@Select("select * from goods_sku where goods_id = #{goodsId} and status = 1")
List<SkuVo> getByGoodsIs(@Param("goodsId") String goodsId);
......
......@@ -75,5 +75,7 @@ public class Sku implements Serializable {
@TableField(fill = FieldFill.INSERT_UPDATE)
private Long updateTime;
@ApiModelProperty(value = "nft销售方式(1.原商品销售 2.拷贝销售)")
@TableField("nft_sales_type")
private Integer nftSalesType;
}
package com.fzm.mall.server.front.order.model.po;
import com.fzm.mall.server.front.constant.MALLGlobalConfig;
import lombok.Data;
import java.math.BigDecimal;
......@@ -59,9 +58,4 @@ public class TranDto {
* 1.外部nft;2.内部nft;3.内部普通
*/
private Integer coinType;
public void initTokenId(String tokenIdStr) {
String tokenId = tokenIdStr.replace(MALLGlobalConfig.GOODS_NFT_PREFIX,"");
setTokenId(Long.valueOf(tokenId));
}
}
......@@ -2,12 +2,4 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fzm.mall.server.front.goods.mapper.GoodSpuMapper">
<select id="readByCoin" resultType="com.fzm.mall.server.front.goods.model.GoodSpu">
select sp.type, sp.commodity_pass, IFNULL(n.token_id, t.token_id) tokenIdStr, s.nft_sales_type as nftSalesType
from goods_sku s
left join goods_spu sp on s.goods_id = sp.goods_id
left join goods_nft n on sp.commodity_pass = 1 and sp.type = 6 and sp.goods_id = n.goods_id
left join external_token t on sp.commodity_pass = 2 and s.coin_name = t.label_name
where s.status = 1 and s.coin_name = #{coin}
</select>
</mapper>
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