|
@@ -1,19 +1,21 @@
|
|
|
package com.minpay.shouhuo.orderdrawaction;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import com.minpay.common.bean.DrawDto;
|
|
|
+import com.minpay.common.service.IDrawService;
|
|
|
import com.minpay.common.service.IPropertiesService;
|
|
|
import com.minpay.common.service.IPublicService;
|
|
|
+import com.minpay.common.service.impl.DrawServiceImpl;
|
|
|
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;
|
|
@@ -55,7 +57,7 @@ public class OrderDrawAction implements IMINAction{
|
|
|
* @throws MINBusinessException
|
|
|
*/
|
|
|
@MINAction(value = EDIT_ORDER_DRAW)
|
|
|
- public MINActionResult editOrderDraw(VmOrderInf orderInf) throws MINBusinessException{
|
|
|
+ public MINActionResult editOrderDraw(VmOrderInf orderInf,String sysorderno) throws MINBusinessException{
|
|
|
MINActionResult res = new MINActionResult();
|
|
|
|
|
|
//是抽奖商品
|
|
@@ -67,292 +69,40 @@ public class OrderDrawAction implements IMINAction{
|
|
|
List<VmOrderDetails> list = Service.lookup(IMINDataBaseService.class)
|
|
|
.getMybatisMapper(VmOrderDetailsMapper.class)
|
|
|
.selectByExample(detailsExample);
|
|
|
- String gameId = orderInf.getGameId();
|
|
|
-
|
|
|
+ String gameId = orderInf.getGameRule();
|
|
|
+ IDrawService drawService = new DrawServiceImpl();
|
|
|
+ List<DrawDto> drawDtoList1 = new ArrayList<>();
|
|
|
+ if("0".equals(gameId)) {//幸运购
|
|
|
+ //查询当前机构的幸运够
|
|
|
+ List<DrawDto> drawDtoList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ VmOrderDetails vmOrderDetails = list.get(i);
|
|
|
+ DrawDto drawDto = new DrawDto();
|
|
|
+ drawDto.setOrderId(vmOrderDetails.getOrderId());
|
|
|
+ drawDto.setOrderDetailsId(vmOrderDetails.getDetailsId());
|
|
|
+ drawDto.setHuodaoNo(vmOrderDetails.getProEquRelId());
|
|
|
+ drawDto.setChouJiangAmt(orderInf.getOrderAmt());
|
|
|
+ drawDtoList.add(drawDto);
|
|
|
+ }
|
|
|
|
|
|
+ drawDtoList1 = drawService.xingyunDraw( orderInf.getOrderAmt(), orderInf.getId(), sysorderno,
|
|
|
+ orderInf.getEquipmentId(), drawDtoList);
|
|
|
|
|
|
- if(list.size() != 0){
|
|
|
+ }else if("1".equals(gameId)){//游戏购
|
|
|
//获取设备商品信息
|
|
|
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);
|
|
|
- }*/
|
|
|
+ .getMybatisMapper(VmProEquRelMapper.class)
|
|
|
+ .selectByPrimaryKey(list.get(0).getProEquRelId());
|
|
|
+ drawDtoList1 = drawService.orderDrawGame( orderInf, proEquRel, list.get(0));
|
|
|
|
|
|
- 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("订单信息错误!");
|
|
|
- }
|
|
|
+ //更新 订单表, 订单详情表,提货表
|
|
|
+ DeliveryAction.createDeliveryInfo(drawDtoList1);
|
|
|
|
|
|
- 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);
|
|
|
|
|
|
+ return res;
|
|
|
}
|
|
|
+
|
|
|
}
|