From a70b9da8a2a1a10984cc09ebaae98861836f836f Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期三, 08 一月 2025 20:42:41 +0800
Subject: [PATCH] bug修改

---
 manage/src/main/java/com/jilongda/manage/model/TLensWarehousingDetail.java     |    4 +
 manage/src/main/java/com/jilongda/manage/controller/TCouponController.java     |    2 
 manage/src/main/java/com/jilongda/manage/controller/TOrderController.java      |  108 +++++++++++++++++++++++++++++++++---
 applet/src/main/java/com/jilongda/applet/service/impl/TAppUserServiceImpl.java |   30 ++++++++++
 manage/src/main/resources/mapping/TCouponReceiveMapper.xml                     |    3 
 manage/src/main/java/com/jilongda/manage/model/TWarehousing.java               |    2 
 manage/src/main/java/com/jilongda/manage/model/TFrameWarehousingDetail.java    |    4 +
 manage/src/main/java/com/jilongda/manage/query/TWarehousingDetailQuery.java    |    2 
 8 files changed, 140 insertions(+), 15 deletions(-)

diff --git a/applet/src/main/java/com/jilongda/applet/service/impl/TAppUserServiceImpl.java b/applet/src/main/java/com/jilongda/applet/service/impl/TAppUserServiceImpl.java
index 11d9750..fca3a33 100644
--- a/applet/src/main/java/com/jilongda/applet/service/impl/TAppUserServiceImpl.java
+++ b/applet/src/main/java/com/jilongda/applet/service/impl/TAppUserServiceImpl.java
@@ -1,8 +1,13 @@
 package com.jilongda.applet.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.jilongda.applet.mapper.TCouponMapper;
+import com.jilongda.applet.mapper.TCouponReceiveMapper;
 import com.jilongda.applet.model.TAppUser;
 import com.jilongda.applet.mapper.TAppUserMapper;
+import com.jilongda.applet.model.TCoupon;
+import com.jilongda.applet.model.TCouponReceive;
 import com.jilongda.applet.service.TAppUserService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.jilongda.applet.utils.RptUtils;
@@ -13,6 +18,9 @@
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 
@@ -26,6 +34,10 @@
  */
 @Service
 public class TAppUserServiceImpl extends ServiceImpl<TAppUserMapper, TAppUser> implements TAppUserService {
+    @Autowired
+    private TCouponMapper couponMapper;
+    @Autowired
+    private TCouponReceiveMapper couponReceiveMapper;
     @Override
     public TAppUser wxLogin(AppletUserDecodeData appletUserDecodeData) {
         // 通过手机号查询用户,是否已存在手动导入用户,包含支付宝用户
@@ -39,6 +51,24 @@
             appUser.setName(StringUtils.hasLength(appUser.getName())?appUser.getName(): RptUtils.around(appletUserDecodeData.getPhoneNumber(),3,4));
             appUser.setOpenId(appletUserDecodeData.getOpenId());
             this.save(appUser);
+            // 查询有没有注册发放的优惠券活动
+            List<TCoupon> tCoupons = couponMapper.selectList(new LambdaQueryWrapper<TCoupon>()
+                    .eq(TCoupon::getType, 1)
+                    .eq(TCoupon::getGrantStatus, 1));
+            for (TCoupon tCoupon : tCoupons) {
+                TCouponReceive tCouponReceive = new TCouponReceive();
+                tCouponReceive.setCouponId(tCoupon.getId());
+                tCouponReceive.setUserId(appUser.getId());
+                tCouponReceive.setType(1);
+                tCouponReceive.setAmount(tCoupon.getAmount());
+                tCouponReceive.setStoreId(tCoupon.getStoreId());
+                if (tCoupon.getTime()!=0){
+                    tCouponReceive.setEndTime(LocalDateTime.now().plusDays(tCoupon.getTime()));
+                }
+                tCouponReceive.setAmountCondition(tCoupon.getAmountCondition());
+                tCouponReceive.setStatus(1);
+                couponReceiveMapper.insert(tCouponReceive);
+            }
         }else {
             if(appUser.getStatus()!=1){
                 throw new ServiceException("账号被冻结,请联系管理员");
diff --git a/manage/src/main/java/com/jilongda/manage/controller/TCouponController.java b/manage/src/main/java/com/jilongda/manage/controller/TCouponController.java
index cd25446..c925cd1 100644
--- a/manage/src/main/java/com/jilongda/manage/controller/TCouponController.java
+++ b/manage/src/main/java/com/jilongda/manage/controller/TCouponController.java
@@ -104,7 +104,7 @@
                     TCouponReceive tCouponReceive = new TCouponReceive();
                     tCouponReceive.setCouponId(dto.getId());
                     tCouponReceive.setUserId(userId);
-                    tCouponReceive.setType(2);
+                    tCouponReceive.setType(3);
                     tCouponReceive.setAmount(dto.getAmount());
                     tCouponReceive.setStoreId(dto.getStoreId());
                     if (dto.getTime()!=0){
diff --git a/manage/src/main/java/com/jilongda/manage/controller/TOrderController.java b/manage/src/main/java/com/jilongda/manage/controller/TOrderController.java
index 5770045..f17d8e8 100644
--- a/manage/src/main/java/com/jilongda/manage/controller/TOrderController.java
+++ b/manage/src/main/java/com/jilongda/manage/controller/TOrderController.java
@@ -28,6 +28,7 @@
 import org.springframework.web.multipart.MultipartFile;
 
 import java.math.BigDecimal;
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -70,6 +71,17 @@
     private TBrandService brandService;
     @Autowired
     private TOptometryService optometryService;
+    @Autowired
+    private TWarehousingService warehousingService;
+    @Autowired
+    private TLensWarehousingDetailService lensWarehousingDetailService;
+    @Autowired
+    private TFrameWarehousingDetailService frameWarehousingDetailService;
+    @Autowired
+    private TSupplierService supplierService;
+    @Autowired
+    private TMaterialService materialService;
+
     @PostMapping("/obs-upload")
     @ApiOperation(value = "文件上传",tags = "管理后台-文件上传")
     public ApiResult<String> uploadOSS(@RequestPart("file") MultipartFile file) {
@@ -178,15 +190,10 @@
             TAppUser byId = tAppUserService.getById(dto.getUserId());
             dto.setName(byId.getName());
             dto.setPhone(byId.getPhone());
+
         }
         orderService.save(dto);
-        List<TOptometryDetail> optometryDetails = dto.getOptometryDetails();
-        if (!CollectionUtils.isEmpty(optometryDetails)){
-            for (TOptometryDetail optometryDetail : optometryDetails) {
-                optometryDetail.setOrderId(dto.getId());
-            }
-            optometryDetailService.saveBatch(optometryDetails);
-        }
+
 
         List<TOrderGoods> orderGoods = dto.getOrderGoods();
         List<TLensGoods> tLensGoods = new ArrayList<>();
@@ -206,10 +213,10 @@
                 }
                 TBrand one1 = brandService.lambdaQuery().eq(TBrand::getName, orderGood.getBrandName())
                         .eq(TBrand::getType, 2).one();
-                TLensSeries one2 = lensSeriesService.lambdaQuery().eq(TLensSeries::getName, orderGood.getSeriesName())
+                TLensSeries lensSeries = lensSeriesService.lambdaQuery().eq(TLensSeries::getName, orderGood.getSeriesName())
                         .eq(TLensSeries::getBrandId, one1.getId()).one();
                 TLensGoods one = lensGoodsService.lambdaQuery()
-                        .eq(StringUtils.hasLength(orderGood.getSeriesName()),TLensGoods::getSeriesId, one2.getId())
+                        .eq(StringUtils.hasLength(orderGood.getSeriesName()),TLensGoods::getSeriesId, lensSeries.getId())
                         .eq(StringUtils.hasLength(orderGood.getRefractiveIndex()),TLensGoods::getRefractiveIndex, orderGood.getRefractiveIndex())
                         .eq(orderGood.getType()!=null,TLensGoods::getLensType, orderGood.getType())
                         .eq(split.length>0,TLensGoods::getBallMirror, split[0])
@@ -222,6 +229,39 @@
                     // 减少对应库存
                     one.setTotal(one.getTotal()-1);
                     tLensGoods.add(one);
+                    // 生成销售订单主表
+
+                    TWarehousing tWarehousing = new TWarehousing();
+                    tWarehousing.setStatus(5);
+                    tWarehousing.setType(2);
+                    tWarehousing.setStoreId(dto.getStoreId());
+                    tWarehousing.setRemark("销售订单-镜片");
+                    tWarehousing.setOrderNum(dto.getId()+"");
+                    warehousingService.save(tWarehousing);
+                    // 生成明细记录
+                    TLensWarehousingDetail tLensWarehousingDetail = new TLensWarehousingDetail();
+                    tLensWarehousingDetail.setBrand(orderGood.getBrandName());
+                    TSupplier supplier = supplierService.getById(lensSeries.getSupplierId());
+                    if (supplier!=null){
+                        tLensWarehousingDetail.setSupplier(supplier.getName());
+                    }
+                    tLensWarehousingDetail.setSeries(lensSeries.getName());
+                    tLensWarehousingDetail.setRefractiveIndex(orderGood.getRefractiveIndex());
+                    if (StringUtils.hasLength(orderGood.getLLens())){
+                        tLensWarehousingDetail.setBallMirror(orderGood.getLLens().split(",")[0]);
+                        tLensWarehousingDetail.setColumnMirror(orderGood.getLLens().split(",")[0]);
+                    }
+                    if (StringUtils.hasLength(orderGood.getRLens())){
+                        tLensWarehousingDetail.setBallMirror(orderGood.getRLens().split(",")[0]);
+                        tLensWarehousingDetail.setColumnMirror(orderGood.getRLens().split(",")[0]);
+                    }
+                    tLensWarehousingDetail.setType(orderGood.getType());
+                    tLensWarehousingDetail.setTotal(1);
+                    tLensWarehousingDetail.setSeriesId(lensSeries.getId());
+                    tLensWarehousingDetail.setWarehousingId(tWarehousing.getId());
+                    tLensWarehousingDetail.setOrderId(dto.getId());
+                    lensWarehousingDetailService.save(tLensWarehousingDetail);
+
                 }else {
                     return ApiResult.failed("商品库存不足");
                 }
@@ -240,11 +280,61 @@
                     // 增加对应库存
                     one.setTotal(one.getTotal()-1);
                     tFrameGoods.add(one);
+                    // 生成销售订单主表
+                    TWarehousing tWarehousing = new TWarehousing();
+                    tWarehousing.setStatus(5);
+                    tWarehousing.setType(1);
+                    tWarehousing.setStoreId(dto.getStoreId());
+                    tWarehousing.setRemark("销售订单-镜架");
+                    tWarehousing.setOrderNum(dto.getId()+"");
+                    warehousingService.save(tWarehousing);
+                    // 生成明细记录
+                    TBrand brand = brandService.getById(one1.getBrandId());
+
+                    TFrameWarehousingDetail tFrameWarehousingDetail = new TFrameWarehousingDetail();
+                    tFrameWarehousingDetail.setWarehousingId(tWarehousing.getId());
+                    if (brand!=null){
+                        tFrameWarehousingDetail.setBrand(brand.getName());
+                    }
+                    TSupplier supplier = supplierService.getById(one1.getSupplierId());
+                    if (supplier!=null){
+                        tFrameWarehousingDetail.setSupplier(supplier.getName());
+                    }
+                    TMaterial material = materialService.getById(one1.getMaterialId());
+                    if (material!=null){
+                        tFrameWarehousingDetail.setMaterial(material.getName());
+                    }
+                    tFrameWarehousingDetail.setTotal(1);
+                    tFrameWarehousingDetail.setColor(orderGood.getColor());
+                    tFrameWarehousingDetail.setModel(one1.getName());
+                    tFrameWarehousingDetail.setModelId(one1.getId());
+                    tFrameWarehousingDetail.setOrderId(dto.getId());
+                    frameWarehousingDetailService.save(tFrameWarehousingDetail);
+
                 }else{
                     return ApiResult.failed("商品库存不足");
                 }
             }
         }
+        if (dto.getUserId()!=null){
+            if (dto.getCouponId()!=null){
+                List<TCouponReceive> couponReceives = couponReceiveService.lambdaQuery().eq(TCouponReceive::getUserId, dto.getUserId())
+                        .eq(TCouponReceive::getCouponId, dto.getCouponId())
+                        .orderByDesc(TCouponReceive::getCreateTime).list();
+                if (couponReceives.isEmpty())return ApiResult.failed("优惠券不存在");
+                TCouponReceive tCouponReceive = couponReceives.get(0);
+                tCouponReceive.setStatus(2);
+                tCouponReceive.setUseTime(LocalDateTime.now());
+                couponReceiveService.updateById(tCouponReceive);
+            }
+        }
+        List<TOptometryDetail> optometryDetails = dto.getOptometryDetails();
+        if (!CollectionUtils.isEmpty(optometryDetails)){
+            for (TOptometryDetail optometryDetail : optometryDetails) {
+                optometryDetail.setOrderId(dto.getId());
+            }
+            optometryDetailService.saveBatch(optometryDetails);
+        }
         orderGoodsService.saveBatch(orderGoods);
         lensGoodsService.updateBatchById(tLensGoods);
         frameGoodsService.updateBatchById(tFrameGoods);
diff --git a/manage/src/main/java/com/jilongda/manage/model/TFrameWarehousingDetail.java b/manage/src/main/java/com/jilongda/manage/model/TFrameWarehousingDetail.java
index 001cb0d..8c8cb5b 100644
--- a/manage/src/main/java/com/jilongda/manage/model/TFrameWarehousingDetail.java
+++ b/manage/src/main/java/com/jilongda/manage/model/TFrameWarehousingDetail.java
@@ -69,5 +69,9 @@
     @TableField("modelId")
     private Integer modelId;
 
+    @ApiModelProperty(value = "订单id")
+    @TableField("orderId")
+    private Integer orderId;
+
 
 }
diff --git a/manage/src/main/java/com/jilongda/manage/model/TLensWarehousingDetail.java b/manage/src/main/java/com/jilongda/manage/model/TLensWarehousingDetail.java
index 63fb5c9..88be1fb 100644
--- a/manage/src/main/java/com/jilongda/manage/model/TLensWarehousingDetail.java
+++ b/manage/src/main/java/com/jilongda/manage/model/TLensWarehousingDetail.java
@@ -79,5 +79,7 @@
     @TableField("code")
     private String code;
 
-
+    @ApiModelProperty(value = "订单id")
+    @TableField("orderId")
+    private Integer orderId;
 }
diff --git a/manage/src/main/java/com/jilongda/manage/model/TWarehousing.java b/manage/src/main/java/com/jilongda/manage/model/TWarehousing.java
index 53c04c0..0a99fbd 100644
--- a/manage/src/main/java/com/jilongda/manage/model/TWarehousing.java
+++ b/manage/src/main/java/com/jilongda/manage/model/TWarehousing.java
@@ -35,7 +35,7 @@
     @TableId(value = "id", type = IdType.AUTO)
     private Integer id;
 
-    @ApiModelProperty(value = "1=出库,2=入库,3=作废,4=退货")
+    @ApiModelProperty(value = "1=出库,2=入库,3=作废,4=退货  5销售订单")
     @NotNull(message = "状态不能为空")
     @TableField("status")
     private Integer status;
diff --git a/manage/src/main/java/com/jilongda/manage/query/TWarehousingDetailQuery.java b/manage/src/main/java/com/jilongda/manage/query/TWarehousingDetailQuery.java
index c085a16..d781674 100644
--- a/manage/src/main/java/com/jilongda/manage/query/TWarehousingDetailQuery.java
+++ b/manage/src/main/java/com/jilongda/manage/query/TWarehousingDetailQuery.java
@@ -24,6 +24,6 @@
     @ApiModelProperty(value = "店铺id")
     private Integer storeId;
 
-    @ApiModelProperty(value = "类型 1=出库,2=入库,3=作废,4=退货")
+    @ApiModelProperty(value = "类型 1=出库,2=入库,3=作废,4=退货 5=销售订单")
     private Integer status;
 }
diff --git a/manage/src/main/resources/mapping/TCouponReceiveMapper.xml b/manage/src/main/resources/mapping/TCouponReceiveMapper.xml
index b6e84ef..fe2bb0f 100644
--- a/manage/src/main/resources/mapping/TCouponReceiveMapper.xml
+++ b/manage/src/main/resources/mapping/TCouponReceiveMapper.xml
@@ -25,9 +25,8 @@
         id, couponId, userId, type, amount, storeId, endTime, amountCondition, status, createTime, updateTime, createBy, updateBy, isDelete
     </sql>
     <select id="pageList" resultType="com.jilongda.manage.vo.TAppUserCouponVO">
-        select t1.* ,t2.name as couponName from
+        select t1.*
             t_coupon_receive t1
-        left join t_coupon t2 on t1.couponId = t2.id
         where t1.userId = #{query.id}
         and t1.isDelete =  ${@com.jilongda.common.enums.DisabledEnum@NO.getCode()}
     </select>

--
Gitblit v1.7.1