|
|
|
@ -18,7 +18,9 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.BigInteger; |
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.sql.Timestamp; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
@ -43,6 +45,10 @@ public class GoodsServiceImpl implements GoodsService { |
|
|
|
private UserMapper userMapper; |
|
|
|
@Autowired |
|
|
|
private OrderMapper orderMapper; |
|
|
|
@Autowired |
|
|
|
private AccountRatioSettingMapper accountRatioSettingMapper; |
|
|
|
@Autowired |
|
|
|
private AccountRatioDetailMapper accountRatioDetailMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Goods> getGoodsList(int page) { |
|
|
|
@ -668,20 +674,111 @@ public class GoodsServiceImpl implements GoodsService { |
|
|
|
//object
|
|
|
|
Object shopCar = RedisUtil.get(shopRedisKey); |
|
|
|
if(shopCar!=null){ |
|
|
|
carjson =JSONObject.parseObject(shopCar.toString()); |
|
|
|
String tmpGoodsIsli= carjson.getString("goods_islicode"); |
|
|
|
if(goodsIsli.equals(tmpGoodsIsli)){ |
|
|
|
JSONArray jsonArray =carjson.getJSONArray("data"); |
|
|
|
// 检查goods_isli
|
|
|
|
List goodsIsliList =new ArrayList(); |
|
|
|
for(int x=0;x<jsonArray.size();x++){ |
|
|
|
JSONObject tmpjson =(JSONObject) jsonArray.get(x); |
|
|
|
String tgoodsisli = tmpjson.getString("goods_islid"); |
|
|
|
goodsIsliList.add(tgoodsisli); |
|
|
|
} |
|
|
|
//检查是否在列表中
|
|
|
|
if(goodsIsliList.contains(goodsIsli)){ |
|
|
|
retmap.put("code",400); |
|
|
|
retmap.put("msg","该标的已添加到购物车"); |
|
|
|
} |
|
|
|
List tmpCarItem = new ArrayList(); |
|
|
|
Map tmpcar = new HashMap(); |
|
|
|
tmpcar.put("goods_isli",goodsIsli); |
|
|
|
tmpcar.put("use_years",userYears); |
|
|
|
tmpCarItem.add(tmpcar); |
|
|
|
carjson.put("data",tmpCarItem); |
|
|
|
RedisUtil.set(shopRedisKey,carjson.toJSONString()); |
|
|
|
}else{ |
|
|
|
carjson.put("goods_islicode",goodsIsli); |
|
|
|
carjson.put("use_years",userYears); |
|
|
|
Map tmpCar = new HashMap(); |
|
|
|
tmpCar.put("goods_islicode",goodsIsli); |
|
|
|
tmpCar.put("use_years",userYears); |
|
|
|
List carItem = new ArrayList(); |
|
|
|
carItem.add(tmpCar); |
|
|
|
carjson.put("data",carItem); |
|
|
|
|
|
|
|
RedisUtil.set(shopRedisKey,carjson.toJSONString()); |
|
|
|
} |
|
|
|
return retmap; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> getShoppingCar(String userIsli) { |
|
|
|
Map<String,Object> retmap =new HashMap<>(); |
|
|
|
String shopRedisKey="car_"+userIsli; |
|
|
|
Object shopCar =RedisUtil.get(shopRedisKey); |
|
|
|
JSONObject shopCarJson =JSONObject.parseObject(shopCar.toString()); |
|
|
|
JSONArray jsonArray = shopCarJson.getJSONArray("data"); |
|
|
|
//JSONObject carjson =JSONObject.parseObject(shopCar.toString());
|
|
|
|
if(shopCar==null){ |
|
|
|
//null
|
|
|
|
return retmap; |
|
|
|
} |
|
|
|
//fenpei
|
|
|
|
Map acrmap = new HashMap(); |
|
|
|
acrmap.put("is_deleted",0); |
|
|
|
acrmap.put("status",1); |
|
|
|
List<AccountRatioSetting> acrlist = accountRatioSettingMapper.getRatioSettingList(acrmap,0,1); |
|
|
|
AccountRatioSetting accountRatioSetting = acrlist.get(0); |
|
|
|
AccountRatioDetail accountRatioDetail =accountRatioDetailMapper.getAccRatioDetailByIdRole(accountRatioSetting.getId(),2); |
|
|
|
|
|
|
|
//goods information
|
|
|
|
for(int x=0;x<jsonArray.size();x++){ |
|
|
|
JSONObject jsonObject = jsonArray.getJSONObject(x); |
|
|
|
String goodsIsli= jsonObject.getString("goods_isli"); |
|
|
|
Goods goods = goodsMapper.getGoodsFuelByIsLi(goodsIsli); |
|
|
|
//
|
|
|
|
GoodsDetail goodsDetail = goodsDetailMapper.getGoodsDetailBygid(goods.getGoodsDetailId()); |
|
|
|
retmap.put("detial",goodsDetail); |
|
|
|
// 计算服务费
|
|
|
|
Integer count = jsonObject.getInteger("use_years"); |
|
|
|
if(goodsDetail.getGoodsEntrust()==1){ |
|
|
|
count=1; |
|
|
|
} |
|
|
|
BigDecimal serviceCharge=new BigDecimal(0); |
|
|
|
BigDecimal totalMoney =new BigDecimal(0); |
|
|
|
if(goodsDetail.getChargesType()==2){ |
|
|
|
if(accountRatioDetail.getCalculate()==1){ |
|
|
|
BigDecimal rate =accountRatioDetail.getRatio().divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP); |
|
|
|
serviceCharge = new BigDecimal(count).multiply(goodsDetail.getPrice()) |
|
|
|
.multiply(rate); |
|
|
|
}else{ |
|
|
|
serviceCharge = new BigDecimal(count).multiply(goodsDetail.getPrice()) |
|
|
|
.add(accountRatioDetail.getAmount()); |
|
|
|
} |
|
|
|
totalMoney = new BigDecimal(count).multiply(goodsDetail.getPrice()) |
|
|
|
.add(serviceCharge) |
|
|
|
.add(goodsDetail.getEarnestMoney()); |
|
|
|
} |
|
|
|
BigDecimal goodsPrice = new BigDecimal(count).multiply(goodsDetail.getPrice()).setScale(2); |
|
|
|
retmap.put("service_charge",serviceCharge); |
|
|
|
retmap.put("total_money",totalMoney); |
|
|
|
retmap.put("goods_price",goodsPrice); |
|
|
|
//
|
|
|
|
if(goodsDetail.getGoodsEntrust()==1 || (goodsDetail.getChargesType()==1 && goodsDetail.getGoodsEntrust()==2)){ |
|
|
|
retmap.put("transaction_count","-"); |
|
|
|
}else{ |
|
|
|
retmap.put("transaction_count",count); |
|
|
|
} |
|
|
|
//GOODS SOURCE
|
|
|
|
List<GoodsSource> goodsSource = goodsSourceMapper.getGoodsSourceByIsli(goods.getGoodsIslicode()); |
|
|
|
retmap.put("source",goodsSource); |
|
|
|
//
|
|
|
|
JSONObject userjson = SzwhApiUtils.getApiUser(userIsli); |
|
|
|
Map umap = JSONObject.parseObject(userjson.getString("data")); |
|
|
|
retmap.put("user",umap); |
|
|
|
//
|
|
|
|
retmap.put("goods",goods); |
|
|
|
} |
|
|
|
|
|
|
|
return retmap; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* query rank list |
|
|
|
* |
|
|
|
|