zhangxu
2022-07-20 6d74163dc2d9675d0af367c86a0c9c70cbd18cd3
提交 | 用户 | age
3d1d18 1 package com.hx.phip.util.api;
Z 2
3 import com.alibaba.fastjson.JSONArray;
4 import com.alibaba.fastjson.JSONObject;
5 import com.hx.common.service.CommonService;
6 import com.hx.mybatisTool.SqlSentence;
b8f1f4 7 import com.hx.phiappt.common.OperationReasonConstants;
3d1d18 8 import com.hx.phiappt.common.OrderItemConstants;
Z 9 import com.hx.phiappt.common.OrderLogConstants;
5e61ff 10 import com.hx.phiappt.constants.tool.CouponTool;
3d1d18 11 import com.hx.phiappt.constants.tool.SqlSplicingTool;
b8f1f4 12 //import com.hx.phiappt.constants.tool.ValueAddedFundTool;
5e61ff 13 import com.hx.phiappt.dao.mapper.*;
3d1d18 14 import com.hx.phiappt.model.*;
5e61ff 15 import com.hx.phiappt.model.activity.ActivityAction;
Z 16 import com.hx.phiappt.model.activity.ActivityCondition;
17 import com.hx.phiappt.model.activity.ActivityGroup;
18 import com.hx.phiappt.model.activity.ActivityRule;
a223c3 19 import com.hx.phiappt.model.cardItem.CardEquity;
3d1d18 20 import com.hx.phiappt.model.cardItem.CardItem;
a223c3 21 import com.hx.phiappt.model.cardItem.CardItemInfo;
3d1d18 22 import com.hx.phiappt.model.consumables.Consumables;
5e61ff 23 import com.hx.phiappt.model.coupon.CouponReleaseRecordItem;
3d1d18 24 import com.hx.phiappt.model.limit.MemberLimit;
Z 25 import com.hx.phiappt.model.memberLevel.MemberLevel;
a0b1c4 26 import com.hx.phiappt.model.order.*;
36ecbd 27 import com.hx.phiappt.model.project.ProjectShopPrice;
3d1d18 28 import com.hx.phiappt.model.promotion.Promotion;
b8f1f4 29 import com.hx.phiappt.model.userMoney.UserMoneyUnclaimed;
5e61ff 30 import com.hx.phip.config.CustomParameter;
3d1d18 31 import com.hx.phip.dao.mapper.*;
a4679e 32 import com.hx.phip.dao.mapper.CardEquityMapper;
Z 33 import com.hx.phip.dao.mapper.CardItemInfoMapper;
5e61ff 34 import com.hx.phip.dao.mapper.CardItemMapper;
Z 35 import com.hx.phip.dao.mapper.ConsumablesMapper;
36 import com.hx.phip.dao.mapper.EmployeeMapper;
a4679e 37 import com.hx.phip.dao.mapper.KoapOrderItemMapper;
5e61ff 38 import com.hx.phip.dao.mapper.MemberLevelMapper;
Z 39 import com.hx.phip.dao.mapper.MemberLimitMapper;
40 import com.hx.phip.dao.mapper.OrderDeveloperMapper;
6d7416 41 import com.hx.phip.dao.mapper.OrderInfoMapper;
a4679e 42 import com.hx.phip.dao.mapper.OrderItemSonMapper;
5e61ff 43 import com.hx.phip.dao.mapper.OrderLogMapper;
Z 44 import com.hx.phip.dao.mapper.OrdersTotalMapper;
45 import com.hx.phip.dao.mapper.ProjectMapper;
46 import com.hx.phip.dao.mapper.PromotionMapper;
47 import com.hx.phip.dao.mapper.ShopMapper;
48 import com.hx.phip.dao.mapper.SystemParameterMapper;
49 import com.hx.phip.dao.mapper.UserMapper;
b6c757 50 import com.hx.phip.dto.OperatorDto;
3d1d18 51 import com.hx.phip.tool.CreateNo;
Z 52 import com.hx.util.StringUtils;
5e61ff 53 import com.platform.constants.PlatformPattern;
3d1d18 54 import com.platform.exception.PlatTipsException;
Z 55 import com.platform.resultTool.PlatformCode;
5e61ff 56 import org.apache.commons.collections.map.HashedMap;
3d1d18 57 import org.slf4j.Logger;
Z 58 import org.slf4j.LoggerFactory;
59
a223c3 60 import java.io.Serializable;
3d1d18 61 import java.math.BigDecimal;
5e61ff 62 import java.util.Arrays;
3d1d18 63 import java.util.HashMap;
Z 64 import java.util.List;
65 import java.util.Map;
66 import java.util.stream.Collectors;
67
68 /**
69  * 订单-开单工具类
70  */
71 public class OrderAddUtil {
72     private static final Logger logger = LoggerFactory.getLogger(OrderAddUtil.class);
73
74
75
76     /**
77      * 处理一级子订单信息
78      * @param ordersTotal
79      * @param items
80      * @param shopId
81      * @param jsonObject
82      * @param map
83      */
84     public static Map<String,Object> handOrderItem(OrdersTotal ordersTotal, List<OrderItem> items, String shopId, JSONArray jsonObject, Map<String, Object> map,BigDecimal totalPrice,BigDecimal shouldOrderTotal,
85                                                    BigDecimal discountTotal,CommonService commonService,SystemParameterMapper systemParameterMapper) {
86         BigDecimal buyNum;
87         BigDecimal actualTotal =BigDecimal.ZERO;//子订单实付金额
88         BigDecimal sonTotalPrice =BigDecimal.ZERO;//子订单订单总额
89         SqlSentence sqlSentence;
90         Map<String,Object> objectMap=new HashMap<>();;
91         //计算总订单金额信息,填补子订单信息
92         for(OrderItem vo:items){
93             buyNum=new BigDecimal(vo.getBuyNum());
94             //子订单编号
95             String orderNum = CreateNo.createTimeNo(systemParameterMapper, "SO", 16, "yyyyMMdd");//订单编号
96             vo.setOrderNo(orderNum);
97             map.put("specsValue","");
98             map.put("unit","");
99             map.put("specsId","");
100             map.put("shopId",shopId);
101             if(vo.getType().equals(OrderItemConstants.TYPE_PROJECT)){
102                 //处理项目
103                 sqlSentence=new SqlSentence();
104                 sqlSentence.setM(objectMap);
105                 objectMap.put("commonId",vo.getCommonId());
106                 sqlSentence.setSqlSentence("SELECT p.* FROM project p LEFT JOIN syn_project sp ON p.apiId=sp.projectId WHERE  (p.id=#{m.commonId} or sp.id=#{m.commonId}) and p.isDel =0 and p.isUp =1");
107                 Project project=commonService.selectOne(ProjectMapper.class,sqlSentence);
36ecbd 108                 if(project==null){
Z 109                     throw new PlatTipsException(PlatformCode.ERROR_TIPS,"找不到项目:"+vo.getCommonId());
3dad1c 110                 }
f55684 111 //                //计算项目价格,如果总订单有康博佳标识代表是康博佳订单不需要任何处理直接拿去康博佳的总金额,每个门店价格不一样,如果没有设置门店价格就使用项目售价
Z 112 //                BigDecimal price=priceJudge(ordersTotal, commonService,project.getId(),shopId);
113 //                project.setPrice(BigDecimal.ZERO.compareTo(price)==0?project.getPrice():price);
3d1d18 114                 Map<String, BigDecimal> bigDecimalMap = handleProject(jsonObject, map, vo, actualTotal, sonTotalPrice, discountTotal, buyNum,commonService,project);
Z 115                 actualTotal=bigDecimalMap.get("actualTotal");
116                 sonTotalPrice=bigDecimalMap.get("sonTotalPrice");
117                 discountTotal=bigDecimalMap.get("discountTotal");
118             }else if(vo.getType().equals(OrderItemConstants.TYPE_RETAIL)){
119                 //处理商品
120                 Map<String, BigDecimal> bigDecimalMap =handleConsumables(jsonObject, map, vo, actualTotal, sonTotalPrice, discountTotal, buyNum,commonService);
121                 actualTotal=bigDecimalMap.get("actualTotal");
122                 sonTotalPrice=bigDecimalMap.get("sonTotalPrice");
123                 discountTotal=bigDecimalMap.get("discountTotal");
124             }else if(vo.getType().equals(OrderItemConstants.TYPE_MEAL)){//套餐  暂定
125
139adf 126             }else if(vo.getType().equals(OrderItemConstants.TYPE_CARD) ){//卡项  暂定
3d1d18 127                 //处理卡项
Z 128                 Map<String, BigDecimal> bigDecimalMap =handleCardItem(jsonObject, map, vo, actualTotal, sonTotalPrice, discountTotal, buyNum,
129                         ordersTotal.getUserId(),commonService);
130                 actualTotal=bigDecimalMap.get("actualTotal");
131                 sonTotalPrice=bigDecimalMap.get("sonTotalPrice");
132                 discountTotal=bigDecimalMap.get("discountTotal");
133             }else if(vo.getType().equals(OrderItemConstants.TYPE_PROMOTION)){//促销  暂定
134                 //处理卡项
135                 Map<String, BigDecimal> bigDecimalMap =handlePromotion(jsonObject, map, vo, actualTotal, sonTotalPrice, discountTotal, buyNum,
139adf 136                         ordersTotal.getUserId(),commonService);
Z 137                 actualTotal=bigDecimalMap.get("actualTotal");
138                 sonTotalPrice=bigDecimalMap.get("sonTotalPrice");
139                 discountTotal=bigDecimalMap.get("discountTotal");
140             }else if(vo.getType().equals(OrderItemConstants.CARD_BAG)){//卡包
efd16f 141                 if(StringUtils.isEmpty(vo.getUserCardId())){
Z 142                     throw new PlatTipsException(PlatformCode.ERROR_TIPS,"下单:开卡包订单需要卡包标识!");
143                 }
139adf 144                 //处理卡项
Z 145                 Map<String, BigDecimal> bigDecimalMap =handleCardBag(jsonObject, map, vo, actualTotal, sonTotalPrice, discountTotal, buyNum,
3d1d18 146                         ordersTotal.getUserId(),commonService);
Z 147                 actualTotal=bigDecimalMap.get("actualTotal");
148                 sonTotalPrice=bigDecimalMap.get("sonTotalPrice");
149                 discountTotal=bigDecimalMap.get("discountTotal");
150             }
151
152
153             //子订单实付金额
154             vo.setActualTotal(actualTotal);
155             vo.setUserPaidTotal(BigDecimal.ZERO);
156             //子订单总额
157             vo.setTotal(sonTotalPrice);
158
159             totalPrice=totalPrice.add(vo.getTotal());//订单总金额
160             shouldOrderTotal=shouldOrderTotal.add(vo.getActualTotal());//订单应付支付总金额
161             sonTotalPrice=BigDecimal.ZERO;
162         }
163         objectMap.clear();
164         objectMap.put("items",items);
165         objectMap.put("totalPrice",totalPrice);
166         objectMap.put("shouldOrderTotal",shouldOrderTotal);
167         objectMap.put("discountTotal",discountTotal);
168         return objectMap;
169     }
170
171     /**
172      * 创建总订单
173      * @param ordersTotal           总订单信息
174      * @param operator              操作人map
175      * @param user                  用户资料
176      * @param userMoney             用户资金信息
177      * @param commonService
178      */
5e61ff 179     public static OrdersTotal createOrder(OrdersTotal ordersTotal, Map<String, String> operator, User user, UserMoney userMoney, CustomParameter customParameter,CommonService commonService) {
25b55e 180         if(ordersTotal!=null && StringUtils.noNull(ordersTotal.getIntegral())){
Z 181             User users=commonService.selectOneByKeyBlob(UserMapper.class,ordersTotal.getInviteeId());
182             if(users!=null){
183                 ordersTotal.setUserBelongingType(users.getUserBelongingType());
184             }
5e61ff 185         }
Z 186         //活动规则金额判断
ead0a9 187         if( ordersTotal.getActivityIds() !=null && ordersTotal.getActivityIds().size()>0){
5e61ff 188             BigDecimal price=activityRule(ordersTotal,commonService,operator,userMoney,customParameter,user,0);
e1f4c1 189             if(price !=BigDecimal.ZERO){
Z 190                 ordersTotal.setActivityTotal(ordersTotal.getShouldTotal().subtract(price));
191                 ordersTotal.setShouldTotal(price);
192             }
25b55e 193         }
3f118d 194
Z 195         if(StringUtils.noNull(ordersTotal.getKoapOrderId())){
196             BigDecimal koapItemMoney = SynOrderUtil.koapItemMoney(ordersTotal.getKoapOrderId(), commonService);
197
198             ordersTotal.setShouldTotal(koapItemMoney);
199             ordersTotal.setTotal(koapItemMoney);
3d1d18 200         }
Z 201         ordersTotal.setUserLevel(user.getUserLevel());
202         ordersTotal.setCIQ(user.getCIQ());
203         ordersTotal.setStoredValueFund(userMoney ==null ?"":userMoney.getStoredValueFund());
204         ordersTotal.setValueAddedFund(userMoney ==null ?"":userMoney.getValueAddedFund());
205         ordersTotal.setIntegral(userMoney ==null ?"":userMoney.getIntegral());
206         //创建总订单
207         commonService.insert(OrdersTotalMapper.class,ordersTotal);
a0b1c4 208
Z 209         //如果有用活动规则将活动规则保存在orderInfo
6e75a2 210         if( ordersTotal.getActivityIds()!=null && ordersTotal.getActivityIds().size()>0){
a0b1c4 211             //查询活动规则基础信息
Z 212             ActivityRule activityRule=commonService.selectOneByKey(ActivityRuleMapper.class,ordersTotal.getActivityIds().get(0));
213             if(activityRule!=null){
214                 OrderInfo orderInfo = new OrderInfo();
215                 orderInfo.setOrderId(ordersTotal.getId());
216                 orderInfo.setActivityId(activityRule.getId());
217                 orderInfo.setActivityName(activityRule.getName());
218                 commonService.insert(OrderInfoMapper.class,orderInfo);
219             }
220         }
3d1d18 221         //生成订单日志
Z 222         commonService.insert(OrderLogMapper.class,ApiOrderUtil.setOrderLog(ordersTotal,null,operator.get("operatorId"),operator.get("operatorName"),"",0, OrderLogConstants.LOG_TYPE_CREATE));
223         return ordersTotal;
224     }
225
226     /**
b6c757 227      * 创建总订单
W 228      * @param ordersTotal           总订单信息
229      * @param operator              操作人
230      * @param user                  用户资料
231      * @param userMoney             用户资金信息
232      * @param commonService
233      */
234     public static OrdersTotal createOrderNew(OrdersTotal ordersTotal, OperatorDto operator, User user, UserMoney userMoney, CommonService commonService) {
235         if(ordersTotal!=null && StringUtils.noNull(ordersTotal.getIntegral())){
236             User users=commonService.selectOneByKeyBlob(UserMapper.class,ordersTotal.getInviteeId());
237             if(users!=null){
238                 ordersTotal.setUserBelongingType(users.getUserBelongingType());
239             }
240         }
241         ordersTotal.setUserLevel(user.getUserLevel());
242         ordersTotal.setCIQ(user.getCIQ());
243         ordersTotal.setStoredValueFund(userMoney ==null ?"":userMoney.getStoredValueFund());
244         ordersTotal.setValueAddedFund(userMoney ==null ?"":userMoney.getValueAddedFund());
245         ordersTotal.setIntegral(userMoney ==null ?"":userMoney.getIntegral());
246         //创建总订单
247         commonService.insert(OrdersTotalMapper.class,ordersTotal);
248         //生成订单日志
249         commonService.insert(OrderLogMapper.class,ApiOrderUtil.setOrderLog(ordersTotal,null,operator.getOperatorId(),operator.getOperatorName(),"",0, OrderLogConstants.LOG_TYPE_CREATE));
250         return ordersTotal;
251     }
252
253     /**
3d1d18 254      *  开单-处理项目方法
Z 255      * @param jsonObject            规格json
256      * @param map                   参数集合
257      * @param vo                    一级子订单
258      * @param actualTotal           商品实付金额
259      * @param sonTotalPrice         商品订单总额
260      * @param discountTotal         折扣总金额
261      * @param buyNum                购买次数
262      * @param project                项目对象
263      * @return
264      */
265     public static Map<String, BigDecimal> handleProject(JSONArray jsonObject, Map<String, Object> map, OrderItem vo,
266                                                   BigDecimal actualTotal, BigDecimal sonTotalPrice, BigDecimal discountTotal, BigDecimal buyNum,
267                                                   CommonService commonService,Project project) {
36ecbd 268
3d1d18 269         if(project.getPrice()==null){
Z 270             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"项目:"+project.getName()+",没有销售价格,请填写销售单价再进行创建订单");
271         }
272         //项目实付金额=项目的销售价格*购买数量*折扣
273         actualTotal = project.getPrice().multiply(buyNum).multiply(vo.getDiscount().divide(new BigDecimal(100)));
274
275         //项目订单总额=项目原价*购买数量,如果项目没有原价就用现价
f55684 276         sonTotalPrice=sonTotalPrice.add(project.getOriginalPrice()==null || BigDecimal.ZERO.compareTo(project.getOriginalPrice())==0?project.getPrice().multiply(buyNum):project.getOriginalPrice().multiply(buyNum));
3d1d18 277
Z 278         //优惠金额=项目的销售单价*数量-用户实付金额;
279         discountTotal=discountTotal.add(project.getPrice().multiply(buyNum).subtract(actualTotal));
280
281         vo.setSingle(project.getTreatmentItemsNum()==null?1:project.getTreatmentItemsNum());//单次疗程数量
282         vo.setUsedTotal(vo.getSingle()*vo.getBuyNum()); //总次疗程次数,单次疗程次数*购买的总量
283         vo.setOriPrice(project.getOriginalPrice());//原价,项目的原价
284         vo.setCurPrice(project.getPrice());//现价,项目的销售单价格
285
286         map.put("specsTitle",project.getSpecification());
287         map.put("unit","");
288
289         jsonObject.add(map);
290         vo.setSpecs(StringUtils.isEmpty(project.getSpecification())?"[]":jsonObject.toString());//规格
291         vo.setGoodsNo(project.getCoding());//项目编号
292         vo.setGoodsName(project.getName());//项目名称
293         vo.setGoodsImage("");//项目主图
294
295         Map<String,BigDecimal> moneyMap=new HashMap<>();
296         moneyMap.put("actualTotal",actualTotal);
297         moneyMap.put("sonTotalPrice",sonTotalPrice);
298         moneyMap.put("discountTotal",discountTotal);
299         return moneyMap;
300     }
301
302     /**
303      *  开单-处理商品方法
304      * @param jsonObject            规格json
305      * @param map                   参数集合
306      * @param vo                    一级子订单
307      * @param actualTotal           商品实付金额
308      * @param sonTotalPrice         商品订单总额
309      * @param discountTotal         折扣总金额
310      * @param buyNum                购买次数
311      * @return
312      */
313     public static Map<String,BigDecimal> handleConsumables(JSONArray jsonObject, Map<String, Object> map, OrderItem vo,
314                                                      BigDecimal actualTotal,BigDecimal sonTotalPrice,BigDecimal discountTotal,BigDecimal buyNum,
315                                                      CommonService commonService) {
316         Consumables consumables = commonService.selectOneByKey(ConsumablesMapper.class,vo.getCommonId());
317         if(consumables==null){
318             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"找不到项目:"+vo.getCommonId());
319         }
320         if(consumables.getPrice()==null){
321             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"商品:"+consumables.getName()+",没有销售价格,请填写销售单价在进行创建订单");
322         }
323         //商品实付金额=商品的销售价格*购买数量*折扣
324         actualTotal = consumables.getPrice().multiply(buyNum).multiply(vo.getDiscount().divide(new BigDecimal(100)));
325
326         //商品订单总额=项目销售价*购买数量
327         sonTotalPrice=sonTotalPrice.add(consumables.getPrice().multiply(buyNum));
328
329         //优惠金额=商品的销售单价*数量-用户实付金额;
330         discountTotal=discountTotal.add(consumables.getPrice().multiply(buyNum).subtract(actualTotal));
331
332         vo.setSingle(0);//单次疗程数量
333         vo.setUsedTotal(vo.getSingle()*vo.getBuyNum());//总次疗程次数,单次疗程次数*购买的总量
334         vo.setOriPrice(consumables.getPrice());//原价,项目的销售价
335         vo.setCurPrice(consumables.getPrice());//现价
336
337         map.put("specsTitle",consumables.getSpec());
338         map.put("unit",consumables.getUnitName());
339         jsonObject.add(map);
340         vo.setSpecs(StringUtils.isEmpty(consumables.getSpec())?"[]":jsonObject.toString());//规格
341         vo.setGoodsNo(consumables.getSerialNumber());//项目编号
342         vo.setGoodsName(consumables.getName());//项目名称
343         vo.setGoodsImage("");//项目主图
344
345         Map<String,BigDecimal> moneyMap=new HashMap<>();
346         moneyMap.put("actualTotal",actualTotal);
347         moneyMap.put("sonTotalPrice",sonTotalPrice);
348         moneyMap.put("discountTotal",discountTotal);
349         return moneyMap;
350     }
351
352     /**
353      *  开单-处理卡项方法
354      * @param jsonObject            规格json
355      * @param map                   参数集合
356      * @param vo                    一级子订单
357      * @param actualTotal           商品实付金额
358      * @param sonTotalPrice         商品订单总额
359      * @param discountTotal         折扣总金额
360      * @param buyNum                购买次数
361      * @param userId                用户id
362      * @return
363      */
364     public static Map<String,BigDecimal> handleCardItem(JSONArray jsonObject, Map<String, Object> map, OrderItem vo,
365                                                   BigDecimal actualTotal,BigDecimal sonTotalPrice,BigDecimal discountTotal,
366                                                   BigDecimal buyNum,String userId, CommonService commonService) {
8d68ed 367         SqlSentence sqlSentence = new SqlSentence();
Z 368         Map<String,Object> sqlMp=new HashMap<>();
369         sqlSentence.setM(sqlMp);
370         sqlMp.put("status",CardItem.SALES);
371         sqlMp.put("isUp",BaseEntity.YES);
372         sqlMp.put("isDel",BaseEntity.NO);
d7bf76 373         sqlMp.put("commonId",vo.getCommonId());
Z 374         sqlSentence.setSqlSentence("select * from card_item where  id=#{m.commonId} and  status=#{m.status} and isUp=#{m.isUp} and isDel=#{m.isDel}");
375         CardItem cardItem=commonService.selectOne(CardItemMapper.class,sqlSentence);
3d1d18 376         if(cardItem==null){
8d68ed 377             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"找不到该卡项,请确保卡项状态必须是销售中并且是上架状态,卡项标识:"+vo.getCommonId());
3d1d18 378         }
Z 379         if(cardItem.getTotal()==null){
380             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"促销:"+cardItem.getName()+",没有销售价格,请填写销售单价在进行创建订单");
381         }
382         User user=commonService.selectOneByKey(UserMapper.class,userId);
383         if(user==null){
384             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"处理促销操作:未找到该用户信息");
385         }
8d68ed 386         sqlMp.clear();
3d1d18 387         sqlMp.put("isDel", BaseEntity.NO);
Z 388         //限制会员等级购买
389         sqlMp.put("foreignKey",cardItem.getId());
390         checkMemberLevel(sqlSentence, user, OrderItemConstants.TYPE_CARD,commonService);
391
392         JSONObject param = new JSONObject();
393         param.put("commonId",cardItem.getId());
394         param.put("userId",userId);
395         param.put("shopId",map.get("shopId"));
396         //卡项/促销/项目购买限制
397         LimitPlatformUtil.limitMethod(commonService,param.toJSONString());
398
68da72 399         //商品实付金额=卡项的销售价格*购买数量*折扣
3d1d18 400         actualTotal = cardItem.getTotal().multiply(buyNum).multiply(vo.getDiscount().divide(new BigDecimal(100)));
Z 401
402         //商品订单总额=项目销售价*购买数量
403         sonTotalPrice=sonTotalPrice.add(cardItem.getTotal().multiply(buyNum));
404
405         //优惠金额=商品的销售单价*数量-用户实付金额;
406         discountTotal=discountTotal.add(cardItem.getTotal().multiply(buyNum).subtract(actualTotal));
407
408         vo.setSingle(0);//单次疗程数量
409         vo.setUsedTotal(vo.getSingle()*vo.getBuyNum());//总次疗程次数,单次疗程次数*购买的总量
410         vo.setOriPrice(cardItem.getTotal());//原价,项目的销售价
411         vo.setCurPrice(cardItem.getTotal());//现价
412
413         vo.setSpecs("[]");//规格
d7bf76 414         vo.setGoodsNo(cardItem.getCode());//卡项编号
3d1d18 415         vo.setGoodsName(cardItem.getName());//卡项名称
Z 416         vo.setGoodsImage("");//卡项主图
417
418         Map<String,BigDecimal> moneyMap=new HashMap<>();
419         moneyMap.put("actualTotal",actualTotal);
420         moneyMap.put("sonTotalPrice",sonTotalPrice);
421         moneyMap.put("discountTotal",discountTotal);
422         return moneyMap;
423     }
424
425     /**
426      * 开单-处理促销方法
427      * @param jsonObject            规格json
428      * @param map                   参数集合
429      * @param vo                    一级子订单
430      * @param actualTotal           商品实付金额
431      * @param sonTotalPrice         商品订单总额
432      * @param discountTotal         折扣总金额
433      * @param buyNum                购买次数
434      * @param userId                用户id
435      * @return
436      */
437     public static Map<String,BigDecimal> handlePromotion(JSONArray jsonObject, Map<String, Object> map, OrderItem vo,
438                                                    BigDecimal actualTotal, BigDecimal sonTotalPrice, BigDecimal discountTotal,
439                                                    BigDecimal buyNum, String userId, CommonService commonService) {
d7bf76 440         SqlSentence sqlSentence = new SqlSentence();
Z 441         Map<String,Object> sqlMp=new HashMap<>();
442         sqlSentence.setM(sqlMp);
443         sqlMp.put("status",Promotion.IN_PROGRESS);
444         sqlMp.put("isUp",BaseEntity.YES);
445         sqlMp.put("isDel",BaseEntity.NO);
446         sqlMp.put("commonId",vo.getCommonId());
447         sqlSentence.setSqlSentence("select * from promotion where  id=#{m.commonId} and  status=#{m.status} and isUp=#{m.isUp} and isDel=#{m.isDel}");
448         Promotion promotion=commonService.selectOne(PromotionMapper.class,sqlSentence);
3d1d18 449         if(promotion==null){
d7bf76 450             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"找不到该促销,请确保促销状态必须是销售中并且是上架状态,促销标识:"+vo.getCommonId());
3d1d18 451         }
Z 452         if(promotion.getTotal()==null){
453             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"促销:"+promotion.getName()+",没有销售价格,请填写销售单价在进行创建订单");
454         }
455         User user=commonService.selectOneByKey(UserMapper.class,userId);
456         if(user==null){
457             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"处理促销操作:未找到该用户信息");
458         }
459         //限制会员等级购买
d7bf76 460         sqlMp.clear();
3d1d18 461         sqlSentence.setM(sqlMp);
Z 462         sqlMp.put("isDel",BaseEntity.NO);
463         sqlMp.put("foreignKey",promotion.getId());
464         checkMemberLevel(sqlSentence, user, OrderItemConstants.TYPE_PROMOTION,commonService);
465
466         JSONObject param = new JSONObject();
467         param.put("commonId",promotion.getId());
468         param.put("userId",userId);
469         param.put("shopId",map.get("shopId"));
470         //卡项/促销/项目购买限制
471         LimitPlatformUtil.limitMethod(commonService,param.toJSONString());
472
68da72 473         //商品实付金额=促销的销售价格*购买数量*折扣
3d1d18 474         actualTotal = promotion.getTotal().multiply(buyNum).multiply(vo.getDiscount().divide(new BigDecimal(100)));
Z 475
476         //商品订单总额=项目销售价*购买数量
477         sonTotalPrice=sonTotalPrice.add(promotion.getTotal().multiply(buyNum));
478
479         //优惠金额=商品的销售单价*数量-用户实付金额;
480         discountTotal=discountTotal.add(promotion.getTotal().multiply(buyNum).subtract(actualTotal));
481
482         vo.setSingle(0);//单次疗程数量
483         vo.setUsedTotal(vo.getSingle()*vo.getBuyNum());//总次疗程次数,单次疗程次数*购买的总量
484         vo.setOriPrice(promotion.getTotal());//原价,项目的销售价
485         vo.setCurPrice(promotion.getTotal());//现价
486
487         vo.setSpecs("[]");//规格
d7bf76 488         vo.setGoodsNo(promotion.getCode());//促销编号
3d1d18 489         vo.setGoodsName(promotion.getName());//促销名称
Z 490         vo.setGoodsImage("");//促销主图
491
492         Map<String,BigDecimal> moneyMap=new HashMap<>();
493         moneyMap.put("actualTotal",actualTotal);
494         moneyMap.put("sonTotalPrice",sonTotalPrice);
495         moneyMap.put("discountTotal",discountTotal);
496         return moneyMap;
497     }
498
499     /**
500      * 检查会员等级限制
501      * @param sqlSentence
502      * @param user
503      * @param type
504      * @param commonService
505      */
506     public static void checkMemberLevel(SqlSentence sqlSentence, User user,String type,CommonService commonService) {
507         sqlSentence.setSqlSentence("select * from member_limit where isDel=#{m.isDel} and foreignKey=#{m.foreignKey}");
508         List<MemberLimit> list=commonService.selectList(MemberLimitMapper.class,sqlSentence);
509         StringBuffer stringBuffer = null;
510         if(list!=null && list.size()>0){
511             List<String> collect = list.stream().map(o -> o.getMemberId()).collect(Collectors.toList());
512             stringBuffer=new StringBuffer();
513             stringBuffer.append("select hisName from member_level where isDel=#{m.isDel} and id in( ");
514             SqlSplicingTool.selectIn(stringBuffer,collect);
515             sqlSentence.setSqlSentence(stringBuffer.toString());
516             List<MemberLevel> memberList=commonService.selectList(MemberLevelMapper.class,sqlSentence);
517             if(memberList!=null){
518                 List<String> memberNameList = memberList.stream().map(o -> o.getHisName()).collect(Collectors.toList());
519                 if(!memberNameList.contains(user.getUserLevel())){
520                     String name=OrderItemConstants.TYPE_CARD.equals(type)?"卡项":"促销";
521                     throw new PlatTipsException(PlatformCode.ERROR_TIPS,"该"+name+"不能购买,该用户等级不在"+name+"范围之内");
522                 }
523             }
524         }
525     }
526
527     /**
528      * 设置用户默认的开发人信息
529      * @param ordersTotal
530      * @return
531      */
532     public static User handUserDeveloper(OrdersTotal ordersTotal,CommonService commonService,List<String> orderTypeList) {
533         //如果开发人集合为空,那么默认用户的所属顾问
534         SqlSentence sqlSentence = new SqlSentence();
535         Map<String,Object> map=new HashMap<>();
536         sqlSentence.setM(map);
537         map.put("shopId",ordersTotal.getDeveloperShopId());
538         User user = commonService.selectOneByKey(UserMapper.class,ordersTotal.getUserId());
539         if(StringUtils.noNull(user.getHisCorpUserId()) && !orderTypeList.contains(ordersTotal.getType())) {
540             map.put("hisCorpUserId",user.getHisCorpUserId());
541             sqlSentence.setSqlSentence("SELECT s.* FROM employee_role er LEFT JOIN shop s ON er.shopId = s.id WHERE er.isDel=0 and er.employeeId = #{m.hisCorpUserId} AND er.roleUniqueStr ='adviser_leader' and s.id=#{m.shopId}");
542             Shop userShop = commonService.selectOne(ShopMapper.class,sqlSentence);
543             if (userShop == null) {
544                 throw new PlatTipsException(PlatformCode.ERROR_TIPS, "用户绑定的顾问不在该门店");
545             }
546             Employee userAdiver =commonService.selectOneByKey(EmployeeMapper.class,user.getHisCorpUserId());
547             //开发人门店标识(用户绑定的销售顾问)
548             ordersTotal.setDeveloperShopId(userShop.getId());
549             //开发人门店名称
550             ordersTotal.setDeveloperShopName(userShop.getName());
551             ordersTotal.setDeveloperId(userAdiver.getId());
552             ordersTotal.setDeveloperName(userAdiver.getCnName());
553         }
5e61ff 554         //荣爷说开发人必填此处不需要默认用户的咨询师  22-05-27
Z 555 //        else if(!orderTypeList.contains(ordersTotal.getType())){
556 //            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"请填写好开发人或者用户绑定一个销售顾问在重试");
557 //        }
3d1d18 558         return user;
Z 559     }
560
561
562
563     /**
564      * 创建开发人集合记录
565      * @param ordersTotal
566      * @param orderDeveloperList
567      */
568     public static void creatDeveloperList(OrdersTotal ordersTotal, List<OrderDeveloper> orderDeveloperList,CommonService commonService) {
569         if(orderDeveloperList !=null && orderDeveloperList.size()>0){
570             for(OrderDeveloper vo:orderDeveloperList){
571                 vo.setOrderId(ordersTotal.getId());//总订单id
572                 commonService.insert(OrderDeveloperMapper.class,vo);
573             }
574         }
575     }
576
36ecbd 577     /**
Z 578      * 价格判断
579      * @param ordersTotal           总订单
580      * @param commonService
581      * @param commonId              公共标识,/项目/商品/卡项/促销/
582      * @return
583      */
5e61ff 584     public static BigDecimal priceJudge(OrdersTotal ordersTotal, CommonService commonService,  String commonId,String shopId) {
36ecbd 585         BigDecimal price=BigDecimal.ZERO;
Z 586         SqlSentence sqlSentence=new SqlSentence();
587         Map<String, Object> objectMap=new HashMap<>();
d73b3b 588         sqlSentence.setM(objectMap);
36ecbd 589         if(StringUtils.noNull(ordersTotal.getKoapOrderId())){
Z 590             objectMap.put("koapId",ordersTotal.getKoapOrderId());
591             sqlSentence.setSqlSentence("SELECT * FROM koap_order_item WHERE orderId=#{m.koapId}");
592             List<KoapOrderItem> koapOrderItemList=commonService.selectList(KoapOrderItemMapper.class,sqlSentence);
593             if(koapOrderItemList==null || koapOrderItemList.size()==0){
594                 throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"结账:未找到康博佳子订单");
595             }
596             //康博佳子订单的应收金额之和(这个金额要等于paymentList里面的所有之和)
d73b3b 597             price=koapOrderItemList.stream().map(o -> o.getChargeAmount()).reduce(BigDecimal.ZERO, BigDecimal::add);
36ecbd 598         }else{
Z 599             objectMap.put("id",commonId);
d73b3b 600             objectMap.put("shopId",shopId);
36ecbd 601             objectMap.put("isUp",BaseEntity.YES);
Z 602             sqlSentence.setSqlSentence("SELECT * FROM project_shop_price WHERE commonId=#{m.id} and shopId=#{m.shopId} and isUp=#{m.isUp}");
603             ProjectShopPrice shopPrice=commonService.selectOne(ProjectShopPriceMapper.class,sqlSentence);
604             if(shopPrice!=null){
605                 price=shopPrice.getPrice();
606             }
607         }
608         return price;
609     }
5e61ff 610
Z 611
612     /**
613      * 计算活动规则价格,如果是折扣或者满减就需要在创建订单计算好价格(荣爷说),其他动作分别都在结账处理
614      * @param ordersTotal
615      * @param type             0:创建订单,1:结账,类型区分来源,如果是创建订单则只需要判断是否有满减或者折扣进行口减总订单的金额,如果是结账则只需要进行将积分、增值金额、优惠券
616      * @return
617      */
618     public static BigDecimal activityRule(OrdersTotal ordersTotal,CommonService commonService,Map<String, String> operator,UserMoney userMoney,
619                                           CustomParameter customParameter,User user,Integer type) {
620         BigDecimal price=BigDecimal.ZERO;
621         if(ordersTotal.getActivityIds() !=null && ordersTotal.getActivityIds().size()>0){
622             //查询活动规则基础信息
623             ActivityRule activityRule=commonService.selectOneByKey(ActivityRuleMapper.class,ordersTotal.getActivityIds().get(0));
624             if(activityRule!=null){
625                 SqlSentence sqlSentence = new SqlSentence();
626                 Map<String,Object> map=new HashedMap();
627                 sqlSentence.setM(map);
628                 map.put("isDel",BaseEntity.NO);
629                 map.put("ruleId",activityRule.getId());
630                 sqlSentence.setSqlSentence("select * from activity_group where isDel=#{m.isDel} and activityRuleId=#{m.ruleId}");
631                 //查找活动规则的分组
632                 List<ActivityGroup> activityGroup = commonService.selectList(ActivityGroupMapper.class, sqlSentence);
633                 if(activityGroup!=null && activityGroup.size()>0){
634                     BigDecimal convert=BigDecimal.ZERO;
635                     for (ActivityGroup group : activityGroup) {
636                         map.put("activityGroupId",group.getId());
637                         //type=0,代表是创建订单,需要将活动规则的满减或者满减(折扣)进行价格计算
638                         if(type==0){
639                             price=fullReduce(convert,ordersTotal,sqlSentence,commonService);
640                         }else if(type==1){
641                             //如果是结账需要将活动规则的增值金、积分、优惠券到账
642                             otherAction(convert,ordersTotal,operator,userMoney,customParameter,sqlSentence,user,commonService);
643                         }
644
645                     }
646                 }
647             }
648         }
649         return price;
650     }
651
652
653     /**
654      * 活动规则-处理满减(金额/折扣)动作方法
655      * @param commonService
656      * @param convert
657      * @param ordersTotal
658      * @return
659      */
660     public static BigDecimal fullReduce(BigDecimal convert,OrdersTotal ordersTotal,SqlSentence sqlSentence,CommonService commonService){
661         sqlSentence.setSqlSentence("select * from activity_action where activityGroupId=#{m.activityGroupId} and (type='full_reduce' or type='discount') ");
662         //查找活动组的满减金额或者满减(折扣)的动作,满减金额或者满减折扣一个组中只能存在一个
663         List<ActivityAction> activityActions = commonService.selectList(ActivityActionMapper.class, sqlSentence);
664         if(activityActions!=null && activityActions.size()==1){
665             sqlSentence.setSqlSentence("select * from activity_condition where activityGroupId=#{m.activityGroupId}");
666             //根据活动组来查询活动的条件集合,同时满足才能进行满减金额或者满减折扣
667             List<ActivityCondition> activityConditions = commonService.selectList(ActivityConditionMapper.class, sqlSentence);
668             if(activityConditions!=null && activityConditions.size()>0){
669                 boolean flag=false;
670                 for(ActivityCondition activityCondition:activityConditions){
671                     convert=new BigDecimal(activityCondition.getWorth());
672                     boolean isFull = checkCondition(ordersTotal, commonService, convert, activityCondition);
673                     //只要有一条条件不满足就直接返回活动价格,一个组里面所有条件都需要同时满足
674                     if(!isFull){
e1f4c1 675                         throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"活动规则:该订单不满足活动规则条件,请仔细检查活动,活动规则条件标识:"+activityCondition.getId());
Z 676 //                        return BigDecimal.ZERO;
5e61ff 677                     }
e1f4c1 678                     logger.info("开单:isFull:{}",isFull);
5e61ff 679                     flag=isFull;
Z 680                 }
681                 if(flag){
e1f4c1 682                     logger.info("开单:isFull:{}",flag);
5e61ff 683                     for (ActivityAction activityAction : activityActions) {
Z 684                         convert=new BigDecimal(activityAction.getWorth());
685                         if(ActivityAction.TYPE_DISCOUNT.equals(activityAction.getType())){
686                             return ordersTotal.getShouldTotal().multiply(convert).divide(new BigDecimal(100));
687                         }else if(ActivityAction.TYPE_FULL_REDUCE.equals(activityAction.getType())){
688                             return ordersTotal.getShouldTotal().subtract(convert);
689                         }
690                     }
691                 }
692             }
693         }else if(activityActions!=null && activityActions.size()>1){
694             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"活动规则:创建订单时找到一个组中同时存在折扣和满减");
695         }
696         return BigDecimal.ZERO;
697     }
698
699     /**
700      * 活动规则-其他动作(增值金、积分、优惠券)  结账使用
701      * @param convert
702      * @param ordersTotal                   总订单
703      * @param operator                      操作人map
704      * @param userMoney                     用户资金信息
705      * @param customParameter
706      * @param sqlSentence
707      * @param commonService
708      */
709     private static void otherAction(BigDecimal convert, OrdersTotal ordersTotal,Map<String, String> operator,UserMoney userMoney,
710                                     CustomParameter customParameter,SqlSentence sqlSentence,User user,CommonService commonService) {
711         List<String> fullTypeList = Arrays.asList(ActivityAction.TYPE_FULL_REDUCE, ActivityAction.TYPE_DISCOUNT);
712         sqlSentence.setSqlSentence("select * from activity_action where activityGroupId=#{m.activityGroupId} ");
713         //查找活动组的满减金额或者满减(折扣)的动作,满减金额或者满减折扣一个组中只能存在一个
714         List<ActivityAction> activityActions = commonService.selectList(ActivityActionMapper.class, sqlSentence);
715         if(activityActions!=null && activityActions.size()>0){
716             activityActions= activityActions.stream().filter(o -> !fullTypeList.contains(o.getType())).collect(Collectors.toList());
717             sqlSentence.setSqlSentence("select * from activity_condition where activityGroupId=#{m.activityGroupId}");
718             //根据活动组来查询活动的条件集合,同时满足才能进行满减金额或者满减折扣
719             List<ActivityCondition> activityConditions = commonService.selectList(ActivityConditionMapper.class, sqlSentence);
720             if(activityConditions!=null && activityConditions.size()>0){
721                 boolean flag=false;
722                 for(ActivityCondition activityCondition:activityConditions){
723                     convert=new BigDecimal(activityCondition.getWorth());
e1f4c1 724                     if(ordersTotal.getActivityTotal()!=null){
Z 725                         convert=convert.subtract(ordersTotal.getActivityTotal());
726                     }
5e61ff 727                     boolean isFull = checkCondition(ordersTotal, commonService, convert, activityCondition);
Z 728                     //只要有一条条件不满足就结束
729                     if(!isFull){
e1f4c1 730                         throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"活动规则:该订单结账不满足活动规则条件,请仔细检查活动,活动规则条件标识:"+activityCondition.getId());
5e61ff 731                     }
e1f4c1 732                     logger.info("结账:isFull:{}",isFull);
5e61ff 733                     flag=isFull;
Z 734                 }
735                 if(flag){
e1f4c1 736                     logger.info("结账:isFull:{}",flag);
5e61ff 737                     //用户信息集合
Z 738                     net.sf.json.JSONArray array;
739                     net.sf.json.JSONObject object;
740                     CouponReleaseRecordItem couponReleaseRecordItem;
b8f1f4 741                     BigDecimal worth;
5e61ff 742                     for (ActivityAction activityAction : activityActions) {
e1f4c1 743
5e61ff 744                         switch (activityAction.getType()){
Z 745                             case ActivityAction.TYPE_VALUEADDEDFUND:
e1f4c1 746                                 worth=new BigDecimal(activityAction.getWorth());
5e61ff 747                                 //增加增值金
b8f1f4 748 //                                ValueAddedFundTool.add(ordersTotal.getUserId(),ordersTotal.getId(),convert);
5e61ff 749 //                                UserMoneyUtil.dealValueAddFund(operator,ordersTotal.getUserId(),userMoney,convert,customParameter,commonService,1);
670322 750                                 UserMoneyUtil.setUserMoneyUnclaimed(ordersTotal, activityAction.getId(),worth,UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,OperationReasonConstants.OP_REASON_ACTIVITY_RULE_GIFT,commonService,UserMoneyUnclaimed.YES);
5e61ff 751                                 break;
Z 752                             case ActivityAction.TYPE_INTEGRAL:
e1f4c1 753                                 worth=new BigDecimal(activityAction.getWorth());
5e61ff 754                                 //增加积分,积分先暂时不做是否过期
Z 755 //                                ValueAddedFundTool.add(ordersTotal.getUserId(),ordersTotal.getId(),convert);
b8f1f4 756 //                                UserMoneyUtil.dealIntegral(operator,ordersTotal.getUserId(),userMoney,convert,customParameter,commonService,1);
670322 757                                 UserMoneyUtil.setUserMoneyUnclaimed(ordersTotal, activityAction.getId(),worth,UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_ACTIVITY_RULE_GIFT,commonService,UserMoneyUnclaimed.YES);
5e61ff 758                                 break;
Z 759                             case ActivityAction.TYPE_COUPON:
4a6b11 760                                 if(ActivityAction.TYPE_PLATFORM_CRM.equals(activityAction.getPlatformType())){
f2b53d 761                                     SynOrderUtil.sendCrmCoupon(customParameter, user.getTel(),user.getApiId(), activityAction.getCrmCouponId());
4a6b11 762                                 }else if(ActivityAction.TYPE_PLATFORM_PHIS.equals(activityAction.getPlatformType())){
Z 763                                     object=new net.sf.json.JSONObject();
764                                     object.put("apiId",user.getApiId());
765                                     object.put("createTime",user.getCreateTime());
766                                     object.put("gender",user.getGender());
767                                     object.put("id",user.getId());
768                                     object.put("imgUrl",user.getImgUrl());
769                                     object.put("name",user.getName());
770                                     object.put("tel",user.getTel());
771                                     array=new net.sf.json.JSONArray();
772                                     array.add(object);
773                                     couponReleaseRecordItem=new CouponReleaseRecordItem();
774                                     couponReleaseRecordItem.setCouponId(activityAction.getWorth());
775                                     couponReleaseRecordItem.setRecordName("系统赠送");
776                                     //赠送优惠券给用户
777                                     CouponTool.sendCoupon(couponReleaseRecordItem,operator.get("operatorId"),operator.get("operatorName"),operator.get("roleId"),array,commonService);
778                                 }
5e61ff 779                                 break;
Z 780                         }
781
782                     }
783                 }
784             }
785         }
786     }
787
788     /**
789      * 活动规则-判断条件是否符合
790      * @param ordersTotal               总订单
791      * @param commonService
792      * @param convert                   条件值
793      * @param activityCondition         条件对象
794      * @return
795      */
796     private static boolean checkCondition(OrdersTotal ordersTotal, CommonService commonService, BigDecimal convert, ActivityCondition activityCondition) {
797         boolean flag=false;
798         if(ActivityCondition.TYPE_ORDER.equals(activityCondition.getGenre())){
799             switch (activityCondition.getSymbol()){
800                 case "<":
801                     if(ordersTotal.getShouldTotal().compareTo(convert)<0){
802                         flag=true;
803                     }
804                     break;
805                 case ">":
806                     if(ordersTotal.getShouldTotal().compareTo(convert)>0){
807                         flag=true;
808                     }
809                     break;
810                 case "<=":
811                     if(ordersTotal.getShouldTotal().compareTo(convert)<=0){
812                         flag=true;
813                     }
814                     break;
815                 case ">=":
816                     if(ordersTotal.getShouldTotal().compareTo(convert)>=0){
817                         flag=true;
818                     }
819                 case "=":
820                     if(ordersTotal.getShouldTotal().compareTo(convert)==0){
821                         flag=true;
822                     }
823                     break;
824                 default:
825                     break;
826             }
827         }else if(ActivityCondition.TYPE_USER.equals(activityCondition.getGenre())){
828             switch (activityCondition.getSymbol()){
829                 case "=":
830                     if(ActivityCondition.CONDITION_USER_LEVEL.equals(activityCondition.getPrerequisite())){
831                         User user=commonService.selectOneByKey(UserMapper.class,ordersTotal.getUserId());
832                         if(user==null){
833                             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"活动规则:条件为用户条件时根据订单未找到该用户信息");
834                         }
835                         if(activityCondition.getWorth().equals(user.getUserLevel())){
836                             flag=true;
837                         }
838                     }else if(ActivityCondition.CONDITION_USER_CLINCH_TAG.equals(activityCondition.getPrerequisite())){
839
840                     }
841                     break;
842                 case "in":
843                     if(ActivityCondition.CONDITION_USER_LEVEL.equals(activityCondition.getPrerequisite())){
844                         List<String> worths = Arrays.asList(activityCondition.getWorth().split(","));
845                         User user=commonService.selectOneByKey(UserMapper.class,ordersTotal.getUserId());
846                         if(user==null){
847                             throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"活动规则:条件为用户条件时根据订单未找到该用户信息");
848                         }
849                         if(worths.contains(user.getUserLevel())){
850                             flag=true;
851                         }
852                     }else if(ActivityCondition.CONDITION_USER_CLINCH_TAG.equals(activityCondition.getPrerequisite())){
853
854                     }
855                     break;
856                 default:
857                     break;
858             }
859         }
860         return flag;
861     }
621356 862
Z 863
864     /**
139adf 865      *  开单-处理卡包方法
Z 866      * @param jsonObject            规格json
867      * @param map                   参数集合
868      * @param vo                    一级子订单
869      * @param actualTotal           商品实付金额
870      * @param sonTotalPrice         商品订单总额
871      * @param discountTotal         折扣总金额
872      * @param buyNum                购买次数
873      * @param userId                用户id
874      * @return
875      */
876     public static Map<String,BigDecimal> handleCardBag(JSONArray jsonObject, Map<String, Object> map, OrderItem vo,
877                                                         BigDecimal actualTotal,BigDecimal sonTotalPrice,BigDecimal discountTotal,
878                                                         BigDecimal buyNum,String userId, CommonService commonService) {
879         SqlSentence sqlSentence = new SqlSentence();
880         Map<String,Object> sqlMp=new HashMap<>();
881         sqlSentence.setM(sqlMp);
882         sqlMp.put("status",CardItem.SALES);
883         sqlMp.put("isUp",BaseEntity.YES);
884         sqlMp.put("isDel",BaseEntity.NO);
885         sqlMp.put("commonId",vo.getCommonId());
886         sqlSentence.setSqlSentence("select * from card_item where  id=#{m.commonId} and  status=#{m.status} and isUp=#{m.isUp} and isDel=#{m.isDel}");
887         CardItem cardItem=commonService.selectOne(CardItemMapper.class,sqlSentence);
888         if(cardItem==null){
a223c3 889             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"卡包:找不到该卡项,请确保卡项状态必须是销售中并且是上架状态,卡项标识:"+vo.getCommonId());
139adf 890         }
Z 891         if(cardItem.getTotal()==null){
a223c3 892             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"卡包:"+cardItem.getName()+",没有销售价格,请填写销售单价在进行创建订单");
139adf 893         }
Z 894         User user=commonService.selectOneByKey(UserMapper.class,userId);
895         if(user==null){
a223c3 896             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"卡包:处理促销操作:未找到该用户信息");
Z 897         }
898         sqlSentence.setSqlSentence("select * from card_equity where  cardItemId=#{m.commonId}  and isDel=#{m.isDel}");
899         List<CardEquity> cardEquities=commonService.selectList(CardEquityMapper.class,sqlSentence);
900         if(cardEquities==null || cardEquities.size()==0){
901             throw new PlatTipsException(PlatformCode.ERROR_TIPS,"卡包:"+cardItem.getName()+",没有找到权益信息!");
902         }
903         BigDecimal sumCardBagMoney =BigDecimal.ZERO;
904         BigDecimal userNum =null;
905         if(vo.getCardItemInfoIds()!=null && vo.getCardItemInfoIds().size()>0){
906             for(CardItemInfo info:vo.getCardItemInfoIds()){
907                 userNum=new BigDecimal(info.getUserNum());
908                 sqlMp.clear();
909                 sqlMp.put("id",info.getId());
910                 sqlSentence.setSqlSentence("select * from card_item_info where  id =#{m.id} and isDel=0  ");
911                 CardItemInfo cardItemInfo = commonService.selectOne(CardItemInfoMapper.class, sqlSentence);
912                 if(cardItemInfo!=null){
913                     BigDecimal shareMoney=cardItemInfo.getShareMoney()==null?cardItemInfo.getEveryShareMoney():cardItemInfo.getShareMoney();
914                     sumCardBagMoney=sumCardBagMoney.add(shareMoney.multiply(userNum));
915                 }
916             }
139adf 917         }
Z 918         sqlMp.clear();
919         sqlMp.put("isDel", BaseEntity.NO);
920         //限制会员等级购买
921         sqlMp.put("foreignKey",cardItem.getId());
922         checkMemberLevel(sqlSentence, user, OrderItemConstants.TYPE_CARD,commonService);
923
924         JSONObject param = new JSONObject();
925         param.put("commonId",cardItem.getId());
926         param.put("userId",userId);
927         param.put("shopId",map.get("shopId"));
928         //卡项/促销/项目购买限制
929         LimitPlatformUtil.limitMethod(commonService,param.toJSONString());
930
931         //商品实付金额=卡项的销售价格*购买数量*折扣
932         actualTotal = BigDecimal.ZERO;
933
934         //商品订单总额=项目销售价*购买数量
a223c3 935         sonTotalPrice=sumCardBagMoney;
139adf 936
Z 937         //优惠金额=商品的销售单价*数量-用户实付金额;
a223c3 938         discountTotal=discountTotal.add(sumCardBagMoney.multiply(buyNum).subtract(actualTotal));
139adf 939
Z 940         vo.setSingle(0);//单次疗程数量
941         vo.setUsedTotal(vo.getSingle()*vo.getBuyNum());//总次疗程次数,单次疗程次数*购买的总量
a223c3 942         vo.setOriPrice(sumCardBagMoney);//原价,项目的销售价
Z 943         vo.setCurPrice(sumCardBagMoney);//现价
139adf 944
Z 945         vo.setSpecs("[]");//规格
946         vo.setGoodsNo(cardItem.getCode());//卡项编号
947         vo.setGoodsName(cardItem.getName());//卡项名称
948         vo.setGoodsImage("");//卡项主图
949
950         Map<String,BigDecimal> moneyMap=new HashMap<>();
951         moneyMap.put("actualTotal",actualTotal);
952         moneyMap.put("sonTotalPrice",sonTotalPrice);
953         moneyMap.put("discountTotal",discountTotal);
954         return moneyMap;
955     }
a223c3 956
Z 957
958     /**
959      * 开单-创建卡项的二级子订单
960      * @param ordersId    总订单标识
961      * @param vo
962      * @param
963      */
964     public static void createOrderItemSonCard(String ordersId, OrderItem vo, CardItemInfo cardItemInfo,Integer type,CommonService commonService) {
965 //        for(CardItemInfo cardItemInfo:cardItemInfos){
966             if(cardItemInfo.getPrice()==null){
967                 throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"开单:卡项组合项目价格为空,组合项标识:"+cardItemInfo.getId());
968             }
969             if(cardItemInfo.getMaxNum()==null && cardItemInfo.getEveryDrawNum()==null){
970                 throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"开单:卡项组合项目最大次数或者每次划扣的扣减次数为空,组合项标识:"+cardItemInfo.getId());
971             }
972             BigDecimal total = cardItemInfo.getPrice().multiply(new BigDecimal(cardItemInfo.getMaxNum() ==null ?cardItemInfo.getEveryDrawNum():cardItemInfo.getMaxNum()));
7889c6 973             OrderItemSon orderItemSon=new OrderItemSon();
a223c3 974             orderItemSon.setType(cardItemInfo.getCommonType());
Z 975             orderItemSon.setGoodsNo(cardItemInfo.getCommonCode());
976             orderItemSon.setGoodsId(cardItemInfo.getCommonId());
977             orderItemSon.setGoodsName(cardItemInfo.getCommonName());
978             orderItemSon.setGoodsImage("");//暂定为空
979             orderItemSon.setSpecs(cardItemInfo.getSpecJson());
980             orderItemSon.setTotal(total);
981             orderItemSon.setActualTotal(total);
982             orderItemSon.setOriPrice(cardItemInfo.getShareMoney()==null?cardItemInfo.getEveryShareMoney():cardItemInfo.getShareMoney());
983             orderItemSon.setCurPrice(cardItemInfo.getShareMoney()==null?cardItemInfo.getEveryShareMoney():cardItemInfo.getShareMoney());
984             orderItemSon.setUsedTotal(0);//暂定为0
985             orderItemSon.setUsedOne(0);//暂定为0
a01b23 986             orderItemSon.setBuyNum(OrderItemConstants.CARD_BAG.equals(vo.getType())?cardItemInfo.getUserNum():cardItemInfo.getMaxNum() ==null ?cardItemInfo.getEveryDrawNum():cardItemInfo.getMaxNum());
a223c3 987             orderItemSon.setOrderId(ordersId);
Z 988             orderItemSon.setOrderItemId(vo.getId());
989             orderItemSon.setCardItemInfoId(cardItemInfo.getId());
990             orderItemSon.setCardEquityId(cardItemInfo.getCardEquityId());
991             orderItemSon.setIsCardBag(type==0?0:1);
992             commonService.insert(OrderItemSonMapper.class,orderItemSon);
993 //        }
994     }
3d1d18 995 }