|
@@ -13,14 +13,14 @@ import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.pagehelper.Page;
|
|
|
+import com.zhongzheng.common.constant.Constants;
|
|
|
import com.zhongzheng.common.core.redis.RedisCache;
|
|
|
import com.zhongzheng.common.core.redis.RedisLockEntity;
|
|
|
import com.zhongzheng.common.exception.CustomException;
|
|
|
import com.zhongzheng.common.type.EncryptHandler;
|
|
|
-import com.zhongzheng.common.utils.DateUtils;
|
|
|
-import com.zhongzheng.common.utils.ServletUtils;
|
|
|
-import com.zhongzheng.common.utils.ToolsUtils;
|
|
|
+import com.zhongzheng.common.utils.*;
|
|
|
import com.zhongzheng.common.utils.http.HttpUtils;
|
|
|
+import com.zhongzheng.common.utils.ip.IpUtils;
|
|
|
import com.zhongzheng.modules.activity.domain.ActivityGoodsPrice;
|
|
|
import com.zhongzheng.modules.activity.domain.ActivityOrder;
|
|
|
import com.zhongzheng.modules.activity.service.IActivityGoodsPriceService;
|
|
@@ -2775,6 +2775,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
String businessFull = iGoodsService.getGoodsBusinessName(goodsId);
|
|
|
Goods goods = iGoodsService.getById(goodsId);
|
|
|
String tenantId = ServletUtils.getRequest().getHeader("TenantId");
|
|
|
+ if (StringUtils.isBlank(tenantId)){
|
|
|
+ tenantId = ServletUtils.getResponse().getHeader("TenantId");
|
|
|
+ }
|
|
|
SysTenant sysTenant = iSysTenantService.getById(Long.valueOf(tenantId));
|
|
|
String sevenYear = goods.getSevenYear();
|
|
|
//指定班级
|
|
@@ -3481,6 +3484,165 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String commonWithoutOrder(CommonOrderBo bo) {
|
|
|
+ if (CollectionUtils.isEmpty(bo.getOrderBos())){
|
|
|
+ throw new CustomException("开单数据为空");
|
|
|
+ }
|
|
|
+ ServletUtils.getResponse().setHeader("TenantId",bo.getTenantId());
|
|
|
+ for (CommonWithoutOrderBo orderBo : bo.getOrderBos()) {
|
|
|
+ //确定用户信息
|
|
|
+ String userCard = orderBo.getUserCard();
|
|
|
+ User user = iUserService.getOne(new LambdaQueryWrapper<User>().eq(User::getIdCard, EncryptHandler.encrypt(userCard)));
|
|
|
+ if (ObjectUtils.isNull(user)){
|
|
|
+ //校验手机号码
|
|
|
+ int count = iUserService.count(new LambdaQueryWrapper<User>().eq(User::getTelphone, EncryptHandler.encrypt(orderBo.getUserTel())));
|
|
|
+ if (count > 0){
|
|
|
+ throw new CustomException(String.format("【%s】该手机号码已绑定其他身份证,请修改",orderBo.getUserTel()));
|
|
|
+ }
|
|
|
+ //用户不存在创建用户信息
|
|
|
+ User data = new User();
|
|
|
+ data.setTelphone(orderBo.getUserTel());
|
|
|
+ //隐藏手机号作为初始昵称
|
|
|
+ data.setNickname(TelPhoneUtils.hideTelPhone(orderBo.getUserTel()));
|
|
|
+ //雪花算法产生账号ID
|
|
|
+ SnowflakeIdUtils idWorker = new SnowflakeIdUtils(3, 1);
|
|
|
+ data.setUserAccount(String.valueOf(idWorker.nextId()));
|
|
|
+ //性别
|
|
|
+ data.setSex(getGenderByIdCard(orderBo.getUserCard()));
|
|
|
+ data.setIdCard(orderBo.getUserCard());
|
|
|
+ data.setRealname(orderBo.getUserName());
|
|
|
+ data.setCompanyName(orderBo.getCompanyName());
|
|
|
+ data.setStatus(1);
|
|
|
+ data.setRegisterPlat("5");
|
|
|
+ data.setAvatar(Constants.DEFAULT_AVATAR);
|
|
|
+ data.setLastLoginTime(DateUtils.getNowTime());
|
|
|
+ data.setCreateTime(DateUtils.getNowTime());
|
|
|
+ data.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ //初始密码(身份证后6位)
|
|
|
+ String idCard = orderBo.getUserCard();
|
|
|
+ String pwd = idCard.substring(idCard.length() - 6); // 随机密码
|
|
|
+ data.setPasswordAes(EncryptHandler.encrypt(pwd));
|
|
|
+ data.setPassword(SecurityUtils.encryptPassword(pwd));
|
|
|
+ iUserService.save(data);
|
|
|
+ user = iUserService.getOne(new LambdaQueryWrapper<User>().eq(User::getIdCard, EncryptHandler.encrypt(userCard)));
|
|
|
+ }
|
|
|
+ //确认商品信息
|
|
|
+ GoodsByBusinessQuery query = new GoodsByBusinessQuery();
|
|
|
+ query.setBusinessName(orderBo.getBusinessName());
|
|
|
+ query.setMajorName(orderBo.getMajorName());
|
|
|
+ query.setYear(orderBo.getYear());
|
|
|
+ Long goodsId = baseMapper.getGoodsIdByBusiness(query);
|
|
|
+ if (ObjectUtils.isNull(goodsId)){
|
|
|
+ throw new CustomException("未正确匹配到课程");
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成订单
|
|
|
+ Order add = new Order();
|
|
|
+ add.setCreateTime(DateUtils.getNowTime());
|
|
|
+ add.setUpdateTime(DateUtils.getNowTime());
|
|
|
+ add.setUserId(user.getUserId());
|
|
|
+ add.setOrderType(3);
|
|
|
+ add.setCreateUsername("外部接口开单");//
|
|
|
+ add.setOrderFrom(7);
|
|
|
+ //订单运营类型
|
|
|
+ add.setOperationType(2);
|
|
|
+ //生成订单号
|
|
|
+ String out_trade_no = DateUtils.getDateOrderSn();
|
|
|
+
|
|
|
+ //订单商品
|
|
|
+ Goods goods = iGoodsService.getOne(new LambdaQueryWrapper<Goods>().eq(Goods::getGoodsId, goodsId));
|
|
|
+ checkBuyGoods(goods.getGoodsId(), user.getUserId(), goods.getGoodsType());
|
|
|
+ //校验是否有重复商品
|
|
|
+ if (StringUtils.isNotBlank(goods.getSevenYear())){
|
|
|
+ Long count = iOrderGoodsService.countOrderGoodsByYear(goods.getSevenYear(),goodsId,user.getUserId());
|
|
|
+ if (count > 0){
|
|
|
+ throw new CustomException(goods.getGoodsName() + ",请勿重复购买相同年份的商品");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ OrderGoods orderGoods = new OrderGoods();
|
|
|
+ orderGoods.setOrderSn(out_trade_no);
|
|
|
+ orderGoods.setGoodsId(goodsId);
|
|
|
+ orderGoods.setGoodsInputData("{}");
|
|
|
+ if (StringUtils.isNotBlank(goods.getSevenYear())){
|
|
|
+ orderGoods.setSevenYear(goods.getSevenYear());
|
|
|
+ }
|
|
|
+ //成交价
|
|
|
+ orderGoods.setGoodsPrice(goods.getStandPrice());
|
|
|
+ orderGoods.setGoodsRealPrice(goods.getStandPrice());
|
|
|
+ orderGoods.setGoodsYear(goods.getYear().toString());
|
|
|
+ orderGoods.setCreateTime(DateUtils.getNowTime());
|
|
|
+ orderGoods.setUpdateTime(DateUtils.getNowTime());
|
|
|
+
|
|
|
+ //订单价格不计算优惠
|
|
|
+ BigDecimal totalPrice = goods.getStandPrice();
|
|
|
+ //暂不计算优惠券
|
|
|
+ BigDecimal payPrice = goods.getStandPrice();
|
|
|
+ iOrderGoodsService.save(orderGoods);
|
|
|
+ //二建课程设置课程录像
|
|
|
+ setCourseVideo(user.getUserId(),goodsId,orderGoods.getOrderGoodsId());
|
|
|
+ //视频商品安排班级
|
|
|
+ if (goods.getGoodsType() == 1) {
|
|
|
+ if (Validator.isNotEmpty(goods.getStudyCount())) {
|
|
|
+ orderGoods.setStudyCount(goods.getStudyCount() - 1); //默认消耗一次学习机会
|
|
|
+ } else {
|
|
|
+ orderGoods.setStudyCount(0L);//没配置则为0
|
|
|
+ }
|
|
|
+
|
|
|
+ Long gradeId = null;
|
|
|
+
|
|
|
+ String requestId = IdUtil.simpleUUID();
|
|
|
+ RedisLockEntity redisLockEntity = new RedisLockEntity();
|
|
|
+ redisLockEntity.setLockKey(RedisLockEntity.KEY_LOCK_GRADE);
|
|
|
+ redisLockEntity.setRequestId(requestId);
|
|
|
+ boolean isArrange = false;
|
|
|
+ if (redisCache.lock(redisLockEntity)) {
|
|
|
+ isArrange = arrangeGrade(goods.getGoodsName(), goods.getGoodsId(), orderGoods.getOrderGoodsId(), gradeId, user.getUserId(), out_trade_no, goods.getBusinessId());
|
|
|
+ redisCache.unlockLua(redisLockEntity);
|
|
|
+ }
|
|
|
+ if (!isArrange) {
|
|
|
+ throw new CustomException("分班错误");
|
|
|
+ }
|
|
|
+ iOrderGoodsService.updateById(orderGoods);
|
|
|
+ }
|
|
|
+
|
|
|
+ add.setOrderSn(out_trade_no);
|
|
|
+ add.setPayPrice(payPrice);
|
|
|
+ add.setOrderPrice(totalPrice);
|
|
|
+ //完全收费
|
|
|
+ add.setOrderStatus(Order.ORDER_STATUS_PAY);
|
|
|
+ add.setStatus(1);
|
|
|
+ this.save(add);
|
|
|
+ dealFreeGoods(orderGoods, add);
|
|
|
+ }
|
|
|
+
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据身份证号码判断性别
|
|
|
+ *
|
|
|
+ * @param idCard 身份证号码
|
|
|
+ * @return "男" 或 "女"
|
|
|
+ */
|
|
|
+ private Integer getGenderByIdCard(String idCard) {
|
|
|
+ if (idCard == null || idCard.length() != 18) {
|
|
|
+ throw new IllegalArgumentException("无效的身份证号码");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取第17位字符
|
|
|
+ char genderChar = idCard.charAt(16);
|
|
|
+
|
|
|
+ // 判断奇偶性
|
|
|
+ int genderDigit = Character.getNumericValue(genderChar);
|
|
|
+ if (genderDigit % 2 == 0) {
|
|
|
+ return 2;
|
|
|
+ } else {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void questionOpen(User user, QuestionMerchant merchant,UserSubscribe userSubscribe,Long loginId,String loginName) {
|
|
|
//商家商品
|
|
|
Goods merGoods = iGoodsService.getOne(new LambdaQueryWrapper<Goods>()
|