123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- package com.minpay.shouhuo.orderdrawaction;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import com.minpay.common.service.IPropertiesService;
- import com.minpay.common.service.IPublicService;
- import com.minpay.common.util.CommonUtil;
- import com.minpay.common.util.DateUtil;
- import com.minpay.db.table.mapper.VmEquipmentInfMapper;
- import com.minpay.db.table.mapper.VmOrderDetailsMapper;
- import com.minpay.db.table.mapper.VmOrderDrawDetailMapper;
- import com.minpay.db.table.mapper.VmOrderInfMapper;
- import com.minpay.db.table.mapper.VmProEquRelMapper;
- import com.minpay.db.table.model.VmEquipmentInf;
- import com.minpay.db.table.model.VmOrderDetails;
- import com.minpay.db.table.model.VmOrderDetailsExample;
- import com.minpay.db.table.model.VmOrderDrawDetail;
- import com.minpay.db.table.model.VmOrderInf;
- import com.minpay.db.table.model.VmProEquRel;
- import com.minpay.db.table.own.mapper.OrderDrawMapper;
- import com.minpay.shouhuo.deliveryaction.DeliveryAction;
- import com.startup.minpay.frame.business.IMINAction;
- import com.startup.minpay.frame.business.res.MINActionResult;
- import com.startup.minpay.frame.exception.MINBusinessException;
- import com.startup.minpay.frame.service.base.IMINDataBaseService;
- import com.startup.minpay.frame.service.base.Service;
- import com.startup.minpay.frame.target.MINAction;
- import com.startup.minpay.frame.target.MINComponent;
- /**
- * 订单成功回调接口
- * @author dudm@minpay.cc
- *
- */
- @MINComponent
- public class OrderDrawAction implements IMINAction{
-
- /**订单成功回调接口*/
- public static final String EDIT_ORDER_DRAW = "editOrderDraw";
-
- /**幸运购*/
- public static final String ORDER_DRAW_LUCKY = "orderDrawLucky";
-
- /**游戏购*/
- public static final String ORDER_DRAW_GAME = "orderDrawGame";
-
- /**二游戏购*/
- public static final String TWO_ORDER_DRAW_GAME = "twoOrderDrawGame";
- /**
- * 订单成功回调接口
- * @param orderInf 付款订单
- * @return
- * @throws MINBusinessException
- */
- @MINAction(value = EDIT_ORDER_DRAW)
- public MINActionResult editOrderDraw(VmOrderInf orderInf) throws MINBusinessException{
- MINActionResult res = new MINActionResult();
- //是抽奖商品
- if("01".equals(orderInf.getProType())){
- //通过订单id获取商品设备关联表id
- VmOrderDetailsExample detailsExample = new VmOrderDetailsExample();
- detailsExample.createCriteria().andOrderIdEqualTo(orderInf.getId())
- .andChannelEqualTo(orderInf.getChannel());
- List<VmOrderDetails> list = Service.lookup(IMINDataBaseService.class)
- .getMybatisMapper(VmOrderDetailsMapper.class)
- .selectByExample(detailsExample);
- String gameId = orderInf.getGameId();
- if(list.size() != 0){
- //获取设备商品信息
- VmProEquRel proEquRel = Service.lookup(IMINDataBaseService.class)
- .getMybatisMapper(VmProEquRelMapper.class)
- .selectByPrimaryKey(list.get(0).getProEquRelId());
- // 游戏类型(GAME_TYEP:00:不参与,10:游戏购 20:幸运购)
- /*if("00".equals(proEquRel.getGameType())) {
- return res;
- }else if("20".equals(proEquRel.getGameType())) {//幸运购
- orderDrawLucky(orderInf,proEquRel);
- }else if("10".equals(proEquRel.getGameType())){//游戏购
- orderDrawGame(orderInf,proEquRel);
- }else if("30".equals(proEquRel.getGameType())){//幸运游戏购
- twoOrderDrawGame(orderInf,proEquRel);
- }*/
- if("100001".equals(gameId)) {//幸运购
- orderDrawLucky(orderInf,proEquRel);
- }else if("100002".equals(gameId)){//游戏购
- orderDrawGame(orderInf,proEquRel);
- }
-
- // 获取最终游戏类型
- /*if(CommonUtil.isEmpty(proEquRel.getGameType())) {
- // 获取设备信息
- VmEquipmentInf eqInf = Service.lookup(IMINDataBaseService.class)
- .getMybatisMapper(VmEquipmentInfMapper.class)
- .selectByPrimaryKey(proEquRel.getEquipmentId());
-
- if("20".equals(eqInf.getGameType())) {//幸运购
- orderDrawLucky(orderInf,proEquRel);
- }else if("10".equals(eqInf.getGameType())){//游戏购
- orderDrawGame(orderInf,proEquRel);
- }else if("30".equals(eqInf.getGameType())){//幸运游戏购
- twoOrderDrawGame(orderInf,proEquRel);
- }
- }*/
- }
- }
-
- return res;
- }
-
- /**
- * 幸运购判断
- * @return
- * @throws MINBusinessException
- */
- @MINAction(value = ORDER_DRAW_LUCKY)
- public void orderDrawLucky(VmOrderInf orderInf,VmProEquRel proEquRel) throws MINBusinessException{
- String payOrderNo = orderInf.getPayOrderno(); //支付订单号
- String orderAmt = orderInf.getOrderAmt(); //付款金额
- String sallPrice = proEquRel.getSallPrice(); //售货价
- //订单号除去金额*100的余数
- int remainder = CommonUtil.objToint((payOrderNo)) % CommonUtil.objToint((CommonUtil.multiply(sallPrice,"100")));
- //支付金额*100
- int luckyNum = CommonUtil.objToint(CommonUtil.multiply(orderAmt,"100"));
- //中奖
- if(luckyNum >= remainder){
- orderInf.setIsDraw("01");
- //中奖后生成提货信息
- DeliveryAction.createDeliveryInfo(orderInf.getId(),"");
- }
- orderInf.setIsUsed("00");
- Service.lookup(IMINDataBaseService.class)
- .getMybatisMapper(VmOrderInfMapper.class)
- .updateByPrimaryKey(orderInf);
- }
-
- /**
- * 游戏购判断
- * @return
- * @throws MINBusinessException
- */
- @MINAction(value = ORDER_DRAW_GAME)
- public void orderDrawGame(VmOrderInf orderInf,VmProEquRel proEquRel) throws MINBusinessException{
- VmOrderDetailsExample detailsExample = new VmOrderDetailsExample();
- detailsExample.createCriteria().andOrderIdEqualTo(orderInf.getId())
- .andChannelEqualTo(orderInf.getChannel());
- List<VmOrderDetails> list = Service.lookup(IMINDataBaseService.class)
- .getMybatisMapper(VmOrderDetailsMapper.class)
- .selectByExample(detailsExample);
- if(list.size()!=1){
- throw new MINBusinessException("订单信息错误!");
- }
- String sallPrice = proEquRel.getSallPrice(); //售货价
- String costPrice = proEquRel.getCostPrice(); //成本价
- String promotionPrice = "0";
- if(proEquRel.getIsPromotion().equals("0")){//促销价
- promotionPrice = proEquRel.getPromotionPrice();
- }
- Map<String,String> map = new HashMap<String,String>();
- map.put("channel", orderInf.getChannel());
- map.put("perId", list.get(0).getProEquRelId());
- //查询所有未使用的购买此货道订单
- List<Map<String, String>> drawGame = Service.lookup(IMINDataBaseService.class)
- .getMybatisMapper(OrderDrawMapper.class)
- .queryDrawGame(map);
- String allPrice = "0"; //所有订单总金额
- for (Map<String, String> map2 : drawGame) {
- allPrice = CommonUtil.add(map2.get("ordetAmt"),allPrice);
- }
- //总金额与价格比较
- int i = CommonUtil.compare(allPrice, CommonUtil.add(CommonUtil.add(sallPrice,costPrice),promotionPrice));
- //中奖
- if(i>=0){
- for (Map<String, String> map2 : drawGame) {
- VmOrderInf vmOrderInf = new VmOrderInf();
- vmOrderInf.setId(map2.get("ordNo"));
- vmOrderInf.setIsUsed("00");
- //修改所有购买此货道订单为已使用
- Service.lookup(IMINDataBaseService.class)
- .getMybatisMapper(VmOrderInfMapper.class)
- .updateByPrimaryKeySelective(vmOrderInf);
- }
- //修改本订单中奖
- orderInf.setIsDraw("01");
- Service.lookup(IMINDataBaseService.class)
- .getMybatisMapper(VmOrderInfMapper.class)
- .updateByPrimaryKey(orderInf);
- //中奖后生成提货信息
- DeliveryAction.createDeliveryInfo(orderInf.getId(),"");
- }
- }
- /**
- * 幸运游戏购
- * @return
- * @throws MINBusinessException
- */
- @MINAction(value = TWO_ORDER_DRAW_GAME)
- public void twoOrderDrawGame(VmOrderInf orderInf,VmProEquRel proEquRel) throws MINBusinessException{
- //获取当前时间
- String dateTime = DateUtil.getCurrentDateTimeString();
- //获取当前日期
- String nowDate = DateUtil.getCurrentDateString();
- //开始时间
- String startTime = nowDate.concat("000000");
- //结束时间
- String endTime = nowDate.concat("999999");
- VmOrderDetailsExample detailsExample = new VmOrderDetailsExample();
- detailsExample.createCriteria().andOrderIdEqualTo(orderInf.getId())
- .andChannelEqualTo(orderInf.getChannel());
- List<VmOrderDetails> list = Service.lookup(IMINDataBaseService.class)
- .getMybatisMapper(VmOrderDetailsMapper.class)
- .selectByExample(detailsExample);
- if(list.size()!=1){
- throw new MINBusinessException("订单信息错误!");
- }
- //查询金额条件
- Map<String,String> map = new HashMap<String,String>();
- map.put("channel", orderInf.getChannel());
- map.put("relId", proEquRel.getId());
- map.put("startTime", startTime);
- map.put("endTime", endTime);
- //查询所有订单金额
- List<Map<String, String>> drawGame = Service.lookup(IMINDataBaseService.class)
- .getMybatisMapper(OrderDrawMapper.class)
- .queryall(map);
- //幸运值幅度范围
- String rang = Service.lookup(IPropertiesService.class)
- .getSystemProperties()
- .get(orderInf.getChannel() + "_RANG")
- .getKey();
- //商品售货价
- String sallPrice = proEquRel.getSallPrice();
- System.out.println("===============================商品售货价"+sallPrice);
- //商品购买数量
- String buyNumber = list.get(0).getProNums();
- System.out.println("===============================商品购买数量"+buyNumber);
- //幸运值
- String luckNo = proEquRel.getLuck();
- /*if(CommonUtil.isEmpty(proEquRel.getLuck())){
- VmEquipmentInf equipmentInf = Service.lookup(IMINDataBaseService.class)
- .getMybatisMapper(VmEquipmentInfMapper.class)
- .selectByPrimaryKey(proEquRel.getEquipmentId());
- luckNo = equipmentInf.getLuck();
- }*/
- //幸运值区间最大值
- String max = CommonUtil.add(luckNo, rang);
- System.out.println("===============================幸运值区间最大值"+max);
- //幸运值区间最小值
- String min = CommonUtil.subtract(luckNo,rang);
- System.out.println("===============================幸运值区间最小值"+min);
- //支付类型 1:1倍支付 3:3倍支付 5:5倍支付
- String payType = orderInf.getPayType();
- System.out.println("===============================支付倍数"+payType);
- //本订单中奖金额
- String drawMoneys = orderInf.getDrawPrice();
- //抽奖次数
- int number = Integer.parseInt(orderInf.getNumber());
- System.out.println("===============================抽奖次数"+number);
- //正常商品购买总价格
- String buyAmount = drawGame.get(0).get("buyAmount");
- //抽奖商品购买总金额
- String drawAmount = drawGame.get(0).get("drawAmount");
- System.out.println("===============================货道今日总收入"+buyAmount+"+"+drawAmount);
- //抽奖商品支出总金额
- String drawPrice = drawGame.get(0).get("drawPrice");
- // 商品已经抽奖价格+商品价格本身/2
- drawPrice = CommonUtil.add(drawPrice, CommonUtil.divide(proEquRel.getSallPrice(), "2"));
- System.out.println("===============================货道今日中奖金额"+drawPrice);
- String drawNumber = "0";
- for (int i = 0; i < number; i++) {
- //准备中奖详情数据
- VmOrderDrawDetail detail = new VmOrderDrawDetail();
- //获取中奖详情表主键
- String id = Service.lookup(IPublicService.class).getSequence("VM_ORDER_DRAW_ID");
- detail.setId(id); //中奖详情id
- detail.setNumber(String.valueOf(i+1)); //抽奖第几次
- detail.setOrderId(orderInf.getId()); //订单id
- detail.setChannel(orderInf.getChannel()); //渠道
- detail.setIsDraw("00"); //未中奖
- detail.setCreateUser(orderInf.getCreateUser()); //创建人
- detail.setCreateTime(dateTime); //创建时间
- detail.setModifyUser(orderInf.getCreateUser()); //修改人
- detail.setModifyTime(dateTime); //修改时间
- //抽奖商品购买总金额增加
- drawAmount= CommonUtil.add(drawAmount, payType);
-
- //计算抽奖过程
- //利润比
- String divide = CommonUtil.multiply(CommonUtil.divide(CommonUtil.subtract(CommonUtil.add(buyAmount, drawAmount), drawPrice),
- CommonUtil.add(buyAmount, drawAmount)),"100");
- System.out.println("===============================利润比乘100"+divide);
- //利润比和最大值相比
- int divMax = CommonUtil.compare(divide, max);
- //利润比和最小值相比
- int divMin = CommonUtil.compare(divide, min);
- //声明本次概率
- String probability = Service.lookup(IPropertiesService.class)
- .getSystemProperties()
- .get(orderInf.getChannel() + "_PROBABILITY")
- .getKey();
- if(divMax == 1){
- //比幸运值大需要提升概率将利润比降低下来
- probability = Service.lookup(IPropertiesService.class)
- .getSystemProperties()
- .get(orderInf.getChannel() + "_PROBABILITY_UP")
- .getKey();
- }
- if(divMin == -1){
- //比幸运值小需要降低概率将利润比提升回来
- probability = Service.lookup(IPropertiesService.class)
- .getSystemProperties()
- .get(orderInf.getChannel() + "_PROBABILITY_DOWN")
- .getKey();
- }
- System.out.println("===============================中奖率"+probability);
- //获取1到100内的随机数
- double num = Math.random() * 100;
- String randNum = String.valueOf(num);
- System.out.println("===============================随机数"+randNum);
- int compare = CommonUtil.compare(probability, randNum);
- //如果中奖
- if(compare != -1){
- drawNumber = CommonUtil.add(drawNumber, buyNumber);
- //中奖后生成提货信息
- DeliveryAction.createDeliveryInfo(orderInf.getId(),drawNumber);
- //如果中奖 支出总金额增加
- drawPrice= CommonUtil.add(drawPrice, CommonUtil.multiply(sallPrice, buyNumber));
- //如果中奖 本订单中奖金额增加
- drawMoneys= CommonUtil.add(drawMoneys, CommonUtil.multiply(sallPrice, buyNumber));
- //将本订单中奖金额修改
- orderInf.setDrawPrice(drawMoneys);
- //将订单定为中奖状态
- orderInf.setIsDraw("01");
- //将中奖详情定为中奖状态
- detail.setIsDraw("01");
- System.out.println("===============================中奖"+",货道中奖金额为"+drawPrice);
- System.out.println("===============================中奖金额为"+drawMoneys);
- }
- Service.lookup(IMINDataBaseService.class)
- .getMybatisMapper(VmOrderDrawDetailMapper.class)
- .insertSelective(detail);
- }
- orderInf.setModifyTime(dateTime); //订单修改时间
- //修改订单
- Service.lookup(IMINDataBaseService.class)
- .getMybatisMapper(VmOrderInfMapper.class)
- .updateByPrimaryKeySelective(orderInf);
-
- }
- }
|