|
|
|
@ -5,9 +5,7 @@ import cn.chjyj.szwh.constant.ChConstant; |
|
|
|
import cn.chjyj.szwh.exception.ChException; |
|
|
|
import cn.chjyj.szwh.mapper.*; |
|
|
|
import cn.chjyj.szwh.service.OrderService; |
|
|
|
import cn.chjyj.szwh.utils.RedisUtil; |
|
|
|
import cn.chjyj.szwh.utils.RedisUtils; |
|
|
|
import cn.chjyj.szwh.utils.SzFileUtils; |
|
|
|
import cn.chjyj.szwh.utils.*; |
|
|
|
import cn.chjyj.szwh.vo.OrderDetailVo; |
|
|
|
import com.alibaba.fastjson2.JSONArray; |
|
|
|
import com.alibaba.fastjson2.JSONObject; |
|
|
|
@ -51,6 +49,8 @@ public class OrderServiceImpl implements OrderService { |
|
|
|
private GoodsSourceMapper goodsSourceMapper; |
|
|
|
@Autowired |
|
|
|
private GoodsMapper goodsMapper; |
|
|
|
@Autowired |
|
|
|
private GoodsDetailMapper goodsDetailMapper; |
|
|
|
|
|
|
|
//分账相关
|
|
|
|
@Autowired |
|
|
|
@ -58,6 +58,13 @@ public class OrderServiceImpl implements OrderService { |
|
|
|
@Autowired |
|
|
|
private AccountRatioDetailMapper accountRatioDetailMapper; |
|
|
|
|
|
|
|
//用户账单
|
|
|
|
@Autowired |
|
|
|
private UserAccountBillMapper userAccountBillMapper; |
|
|
|
//操作日志
|
|
|
|
@Autowired |
|
|
|
private OperationLogMapper operationLogMapper; |
|
|
|
|
|
|
|
// 声明式事物\
|
|
|
|
@Autowired |
|
|
|
private DataSourceTransactionManager transactionManager; |
|
|
|
@ -521,16 +528,164 @@ public class OrderServiceImpl implements OrderService { |
|
|
|
return orderMapper.addOrder(order); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* todo |
|
|
|
* @param userIsli |
|
|
|
* @param goodsIsli |
|
|
|
* @param userYears |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public String buyFindGoods(String userIsli, String goodsIsli, int userYears) { |
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
Goods goods = goodsMapper.getGoodsByIsli(goodsIsli); |
|
|
|
if(goods==null){ |
|
|
|
log.error("create order error!"+goodsIsli+""); |
|
|
|
return null; |
|
|
|
} |
|
|
|
// goods detail
|
|
|
|
GoodsDetail goodsDetail = goodsDetailMapper.getGoodsDetailBygid(goods.getGoodsDetailId()); |
|
|
|
int count = userYears; |
|
|
|
if(goodsDetail.getGoodsEntrust()==1){ |
|
|
|
count=1; |
|
|
|
} |
|
|
|
// ratio setting
|
|
|
|
AccountRatioSetting accountRatioSetting = accountRatioSettingMapper.getUsingAccRatioSetting(); |
|
|
|
AccountRatioDetail accountRatioDetail = accountRatioDetailMapper.getAccRatioDetailByIdRole(accountRatioSetting.getId(),2); |
|
|
|
// 根据用户编号、商品编号查询是否存在订单
|
|
|
|
// check has order infomation
|
|
|
|
Map oqmap =new HashMap(); |
|
|
|
oqmap.put("o.buy_islicode",userIsli); |
|
|
|
oqmap.put("od.goods_islicode",goodsIsli); |
|
|
|
OrderDetailVo orderDetailVo = orderMapper.getOrderDetailVOByMap(oqmap); |
|
|
|
// 检查订单支付情况
|
|
|
|
if(orderDetailVo!=null) { |
|
|
|
if (orderDetailVo.getStatus() == 1) { |
|
|
|
throw new ChException("您的待付款订单中有标的:" + goods.getGoodsIslicode() + ",请勿重复下单", 400); |
|
|
|
} else if (orderDetailVo.getStatus() == 2) { |
|
|
|
throw new ChException("您的未完成订单中有标的:" + goods.getGoodsIslicode() + ",请勿重复下单", 400); |
|
|
|
} else { |
|
|
|
throw new ChException("您的已完成订单中有标的:" + goods.getGoodsIslicode() + ",请勿重复下单", 400); |
|
|
|
} |
|
|
|
} |
|
|
|
// 判断当前订单是否存在问题
|
|
|
|
Order order=new Order(); |
|
|
|
//校验订单信息合法
|
|
|
|
SzOrderUtils.checkOrder(goods,goodsDetail,userIsli); |
|
|
|
// 计算服务费等 委托方总金额
|
|
|
|
BigDecimal serviceCharge =new BigDecimal("0"); |
|
|
|
BigDecimal totalMoney= new BigDecimal("0"); |
|
|
|
int status=0;//订单状态
|
|
|
|
int payStatus=0;//支付状态
|
|
|
|
// 付费商品
|
|
|
|
if(goodsDetail.getChargesType()==2){ |
|
|
|
if(accountRatioDetail.getCalculate()==1){ |
|
|
|
Map calmap =SzOrderUtils.calOrderServiceFee(accountRatioDetail,userYears,goodsDetail.getPrice(),goodsDetail.getEarnestMoney()); |
|
|
|
serviceCharge = (BigDecimal) calmap.get("service_charge"); |
|
|
|
totalMoney = (BigDecimal) calmap.get("total_money"); |
|
|
|
}else{ |
|
|
|
//固定金额
|
|
|
|
// 购买数量*单机+固定费额
|
|
|
|
serviceCharge = new BigDecimal(count).multiply(goodsDetail.getPrice()) |
|
|
|
.add(accountRatioDetail.getAmount()); |
|
|
|
} |
|
|
|
//总的额度
|
|
|
|
totalMoney = new BigDecimal(count).multiply(goodsDetail.getPrice()) |
|
|
|
.add(serviceCharge) |
|
|
|
.add(goodsDetail.getEarnestMoney()); |
|
|
|
status=1; |
|
|
|
payStatus=1; |
|
|
|
}else{ |
|
|
|
// 免费
|
|
|
|
serviceCharge =new BigDecimal(0.00); |
|
|
|
totalMoney = new BigDecimal(0.00); |
|
|
|
status=2; |
|
|
|
payStatus=2; //已支付
|
|
|
|
} |
|
|
|
// 订单编号
|
|
|
|
String batchCode = SzOrderUtils.createOrderBatchcode(); |
|
|
|
// 增加到订单商品详情
|
|
|
|
OrderGoodsDetail orderGoodsDetail = SzOrderUtils.mkOrderGoodsDetail(goodsDetail,batchCode,count,userYears); |
|
|
|
// 补充其他未添加的属性
|
|
|
|
orderGoodsDetail.setEntrustIslicode(goods.getUserIslicode()); |
|
|
|
// 订单服务费
|
|
|
|
orderGoodsDetail.setServiceCharge(serviceCharge); |
|
|
|
//总金额
|
|
|
|
orderGoodsDetail.setMoney(totalMoney); |
|
|
|
orderGoodsDetail.setIslicode(goods.getIsLicode()); |
|
|
|
// 查找用户
|
|
|
|
OrderUser orderUser = orderUserMapper.getUserOrder(batchCode,goods.getIsLicode()); |
|
|
|
int userId=0; |
|
|
|
if(orderUser!=null){ |
|
|
|
userId = orderUser.getId(); |
|
|
|
}else{ |
|
|
|
// 获取远程用户信息
|
|
|
|
JSONObject userjson = SzwhApiUtils.getApiUser(userIsli); |
|
|
|
if(StringUtils.isBlank(userjson.getString("data"))){ |
|
|
|
log.error("未查询到用户信息,下单失败"); |
|
|
|
return null; |
|
|
|
//throw new ChException("未查询到用户信息,下单失败",400);
|
|
|
|
} |
|
|
|
//添加用户
|
|
|
|
OrderUser odu =SzOrderUtils.mkOrderUser(batchCode,userjson,0); |
|
|
|
orderUserMapper.addOrderUser(odu); |
|
|
|
userId = odu.getId(); |
|
|
|
} |
|
|
|
|
|
|
|
// 订单实体
|
|
|
|
order.setBatchcode(batchCode); |
|
|
|
order.setUserId(userId); |
|
|
|
order.setBuyIslicode(userIsli); |
|
|
|
order.setTotalServiceCharge(serviceCharge); |
|
|
|
order.setTotalMoney(totalMoney); |
|
|
|
order.setType(1); |
|
|
|
order.setStatus(status); |
|
|
|
order.setPayStatus(payStatus); |
|
|
|
// 分配设置编号
|
|
|
|
order.setAccountRatioId(accountRatioSetting.getId()); |
|
|
|
//如果是付费
|
|
|
|
if(goodsDetail.getChargesType()==1){ |
|
|
|
order.setPaymenttime(new Date()); |
|
|
|
} |
|
|
|
order.setCreatetime(new Date()); |
|
|
|
// 订单信息入库
|
|
|
|
int ret = orderMapper.addOrder(order); |
|
|
|
if(ret==1){ |
|
|
|
//if(status==2){
|
|
|
|
// 更新订单信息
|
|
|
|
//payService.payFinishOperate(batchCode);
|
|
|
|
// }
|
|
|
|
// 用户账单
|
|
|
|
UserAccountBill userAccountBill = new UserAccountBill(); |
|
|
|
userAccountBill.setUserIsli(userIsli); |
|
|
|
userAccountBill.setBatchcode(batchCode); |
|
|
|
userAccountBill.setOrderUserId(userId); |
|
|
|
userAccountBill.setServiceCharge(serviceCharge); |
|
|
|
userAccountBill.setThatdayBuyMoney(totalMoney); |
|
|
|
// save user's bill
|
|
|
|
userAccountBillMapper.addUserAccBill(userAccountBill); |
|
|
|
//调整库存
|
|
|
|
if(goodsDetail.getGoodsEntrust()==1 || goodsDetail.getContractualPeriod()==2 && goodsDetail.getGoodsEntrust()!=2){ |
|
|
|
int gdret = goodsDetailMapper.decGoodsDetailStock(goodsDetail.getId()); |
|
|
|
if(gdret==1){ |
|
|
|
String status_Str=""; |
|
|
|
// 更新goods 状态
|
|
|
|
Map gmap = new HashMap(); |
|
|
|
gmap.put("goods_status", status); |
|
|
|
if(goodsDetail.getGoodsEntrust() ==1){ |
|
|
|
goodsMapper..changeGoodsStatus(5,goods.getId()); |
|
|
|
status_Str="暂停"; |
|
|
|
}else { |
|
|
|
goodsService.changeGoodsStatus(2,goods.getId()); |
|
|
|
status_Str="下架"; |
|
|
|
} |
|
|
|
//更新订单用户状态信息
|
|
|
|
String buyUserName = orderUser.getName(); |
|
|
|
OperationLog oplog =new OperationLog(); |
|
|
|
oplog.setType("goods"); |
|
|
|
oplog.setLogid(goods.getId()); |
|
|
|
oplog.setMessage(sdf.format(new Date())+"用户"+buyUserName+"下单,"+status_Str+"该委托标的"); |
|
|
|
operationLogMapper.addLog(oplog); |
|
|
|
return batchCode; |
|
|
|
}else{ |
|
|
|
throw new ChException("标的已卖完",400); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return batchCode; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
@ -617,14 +772,24 @@ public class OrderServiceImpl implements OrderService { |
|
|
|
return outmap; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 创建订单实现方法 |
|
|
|
* @param userIsli |
|
|
|
* @param jsonArray json数组 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public Map<String, Object> createOrder(String userIsli, String goodsIsli, Integer userYears) { |
|
|
|
public Map<String, Object> createOrder(String userIsli, JSONArray jsonArray) { |
|
|
|
Map<String,Object> retmap = new HashMap<>(); |
|
|
|
User user = userMapper.getUserByIsli(userIsli); |
|
|
|
if(user==null){ |
|
|
|
retmap.put("code","error"); |
|
|
|
retmap.put("msg","用户不存在"); |
|
|
|
} |
|
|
|
if(jsonArray.size()==1){ |
|
|
|
JSONObject tmpgjson = jsonArray.getJSONObject(0); |
|
|
|
String batchcode = buyFindGoods(userIsli,tmpgjson.getString("goods_islid")) |
|
|
|
} |
|
|
|
String ureidsKey="car_"+userIsli; |
|
|
|
//查询购物车
|
|
|
|
Object shopCar = RedisUtil.get(ureidsKey); |
|
|
|
|