2 changed files with 193 additions and 0 deletions
@ -0,0 +1,16 @@ |
|||||
|
package cn.chjyj.szwh.constant; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
/** |
||||
|
* 订单产量 |
||||
|
*/ |
||||
|
public class OrderConstant { |
||||
|
public Map orderMap=new HashMap<>(); |
||||
|
//库存不足
|
||||
|
public static final int GOODNOSTOCK=100; |
||||
|
public static final String GOODNOSTOCK_STR="标的库存为0,不可购买"; |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,177 @@ |
|||||
|
package cn.chjyj.szwh.utils; |
||||
|
|
||||
|
import cn.chjyj.szwh.bean.Goods; |
||||
|
import cn.chjyj.szwh.bean.GoodsDetail; |
||||
|
import cn.chjyj.szwh.bean.Order; |
||||
|
import cn.chjyj.szwh.bean.OrderUser; |
||||
|
import cn.chjyj.szwh.exception.ChException; |
||||
|
import com.alibaba.fastjson2.JSONObject; |
||||
|
import org.apache.commons.lang3.StringUtils; |
||||
|
import org.apache.commons.logging.Log; |
||||
|
import org.apache.commons.logging.LogFactory; |
||||
|
|
||||
|
import java.text.ParseException; |
||||
|
import java.text.SimpleDateFormat; |
||||
|
import java.util.Calendar; |
||||
|
import java.util.Date; |
||||
|
import java.util.Random; |
||||
|
|
||||
|
public class SzOrderUtils { |
||||
|
private static Log log = LogFactory.getLog(SzOrderUtils.class); |
||||
|
/** |
||||
|
* 购买商品返回订单编号 |
||||
|
* @param userIsli |
||||
|
* @param goodsIsli |
||||
|
* @param useYears |
||||
|
* @return |
||||
|
*/ |
||||
|
public static String buyFindGoods(String userIsli,String goodsIsli,int useYears){ |
||||
|
return ""; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 检查下单过程中的异常信息 |
||||
|
* @param goods |
||||
|
* @param goodsDetail |
||||
|
* @param order |
||||
|
* @param use_isli |
||||
|
* @return |
||||
|
*/ |
||||
|
public static boolean checkOrder(Goods goods, GoodsDetail goodsDetail, Order order,String use_isli){ |
||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
||||
|
// 非工作时间购买
|
||||
|
Calendar calendar= Calendar.getInstance(); |
||||
|
int hour = calendar.get(Calendar.HOUR); |
||||
|
if (hour<9 && hour>18) { |
||||
|
throw new ChException("非正常交易日时间,请在交易日内进行交易,交易日时间为周一至周日9:00-18:00",400); |
||||
|
} |
||||
|
if(goods.getApplyOut()==1){ |
||||
|
throw new ChException("该标的已撤销,标的ISLI标识码:"+goods.getGoodsIslicode(), 400); |
||||
|
} |
||||
|
if(goods.getUserIslicode().equals(use_isli)){ |
||||
|
throw new ChException("您是标的的授权方,不可购买,标的ISLI标识码:"+goods.getGoodsIslicode(), 400); |
||||
|
} |
||||
|
if(goods.getGoodsStatus()!= 1){ |
||||
|
throw new ChException("该标的现不在上架中,标的ISLI标识码:"+goods.getGoodsIslicode(), 400); |
||||
|
} |
||||
|
if(goodsDetail.getStock()<=0 && goodsDetail.getGoodsEntrust()== 1){ |
||||
|
throw new ChException("标的库存为0,不可购买,标的ISLI标识码:"+goods.getGoodsIslicode(), 400); |
||||
|
} |
||||
|
if(goodsDetail.getContractualPeriod()==3){ |
||||
|
Date now =new Date(); |
||||
|
if(now.compareTo(goods.getContractualtimeEndTime()) >0){ |
||||
|
throw new ChException("标的委托已结束,标的ISLI标识码:"+goods.getGoodsIslicode(), 400); |
||||
|
} |
||||
|
} |
||||
|
// 检查订单支付情况
|
||||
|
if(order!=null) { |
||||
|
if (order.getStatus() == 1) { |
||||
|
throw new ChException("您的待付款订单中有标的:" + goods.getGoodsIslicode() + ",请勿重复下单", 400); |
||||
|
} else if (order.getStatus() == 2) { |
||||
|
throw new ChException("您的未完成订单中有标的:" + goods.getGoodsIslicode() + ",请勿重复下单", 400); |
||||
|
} else { |
||||
|
throw new ChException("您的已完成订单中有标的:" + goods.getGoodsIslicode() + ",请勿重复下单", 400); |
||||
|
} |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
/** |
||||
|
* 组装成订单用户 |
||||
|
* @param batchcode |
||||
|
* @param userJson |
||||
|
* @param isBuy |
||||
|
* @return |
||||
|
*/ |
||||
|
public static OrderUser mkOrderUser(String batchcode, JSONObject userJson, int isBuy){ |
||||
|
OrderUser orderUser=new OrderUser(); |
||||
|
//用户类型
|
||||
|
String uType = userJson.getString("userType"); |
||||
|
// 机构用户
|
||||
|
if("机构".equals(uType)){ |
||||
|
orderUser.setBatchcode(batchcode); |
||||
|
orderUser.setUsertype(uType); |
||||
|
Integer ustate = userJson.getInteger("state"); |
||||
|
int istate=ustate==null?0:ustate; |
||||
|
orderUser.setState(istate); |
||||
|
orderUser.setIslicode(userJson.getString("islicode")); |
||||
|
orderUser.setName(userJson.getString("name")); |
||||
|
orderUser.setUscc(userJson.getString("uscc")); |
||||
|
orderUser.setLegalsname(userJson.getString("legalsName")); |
||||
|
orderUser.setLegalstype(userJson.getString("legalsType")); |
||||
|
orderUser.setLegalsidnum(userJson.getString("legalsIdnum")); |
||||
|
//
|
||||
|
String legalsCellPhone = userJson.getString("legalsCellPhone"); |
||||
|
orderUser.setLegalscellphone(StringUtils.isBlank(legalsCellPhone)?"":legalsCellPhone); |
||||
|
orderUser.setPublicaccount(userJson.getString("publicAccount")); |
||||
|
orderUser.setBankcardtype(userJson.getString("bankCardType")); |
||||
|
orderUser.setBankname(userJson.getString("bankName")); |
||||
|
orderUser.setBanktype(userJson.getString("bankType")); |
||||
|
orderUser.setBankaccountname(userJson.getString("bankAccountName")); |
||||
|
orderUser.setCertidnum(userJson.getString("certIdnum")); |
||||
|
orderUser.setBankcellphone(userJson.getString("bankCellPhone")); |
||||
|
orderUser.setBankaddress(userJson.getString("bankAddress")); |
||||
|
}else{ |
||||
|
//个人用户
|
||||
|
orderUser.setBatchcode(batchcode); |
||||
|
orderUser.setUsertype(uType); |
||||
|
Integer ustate = userJson.getInteger("state"); |
||||
|
int istate=ustate==null?0:ustate; |
||||
|
orderUser.setState(istate); |
||||
|
orderUser.setIslicode(userJson.getString("islicode")); |
||||
|
orderUser.setName(userJson.getString("name")); |
||||
|
orderUser.setCerttype(userJson.getString("certType")); |
||||
|
orderUser.setIdnumber(userJson.getString("idNumber")); |
||||
|
orderUser.setCellphone(userJson.getString("cellPhone")); |
||||
|
orderUser.setPublicaccount(userJson.getString("publicAccount")); |
||||
|
orderUser.setBankcardtype(userJson.getString("bankCardType")); |
||||
|
orderUser.setBankname(userJson.getString("bankName")); |
||||
|
orderUser.setBankaccountname(userJson.getString("bankAccountName")); |
||||
|
orderUser.setCertidnum(userJson.getString("certIdnum")); |
||||
|
orderUser.setBankcellphone(userJson.getString("bankCellPhone")); |
||||
|
orderUser.setBankaddress(userJson.getString("bankAddress")); |
||||
|
} |
||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); |
||||
|
// 如果注册时间
|
||||
|
String registertime=userJson.getString("registertime"); |
||||
|
if(StringUtils.isNotBlank(registertime)){ |
||||
|
try { |
||||
|
Date uregDate = sdf.parse(registertime); |
||||
|
orderUser.setRegistertime(uregDate); |
||||
|
}catch (Exception ex){ |
||||
|
log.error("订单用户注册时间转码失败!"+ex.getLocalizedMessage()); |
||||
|
} |
||||
|
} |
||||
|
//认证时间
|
||||
|
String authTime = userJson.getString("authTime"); |
||||
|
if(StringUtils.isNotBlank(authTime)){ |
||||
|
try { |
||||
|
Date authDate = sdf.parse(authTime); |
||||
|
orderUser.setAttesttime(authDate); |
||||
|
}catch (ParseException ex){ |
||||
|
log.error("订单用户认证时间转码失败!"+ex.getLocalizedMessage()); |
||||
|
} |
||||
|
} |
||||
|
// 认证类型
|
||||
|
String authType = userJson.getString("authType"); |
||||
|
if(StringUtils.isNotBlank(authType)){ |
||||
|
orderUser.setAuthtype(authType); |
||||
|
} |
||||
|
|
||||
|
return orderUser; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 生成订单号 |
||||
|
* @return |
||||
|
*/ |
||||
|
public static String createOrderBatchcode(){ |
||||
|
long ntime = System.currentTimeMillis()/1000; |
||||
|
int max=9999999; |
||||
|
int min=1000000; |
||||
|
Random random = new Random(); |
||||
|
int randnum = random.nextInt(max)%(max-min+1) + min; |
||||
|
String subRand = String.valueOf(randnum).substring(1); |
||||
|
String batcode = ntime+""+subRand; |
||||
|
return batcode; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue