mitao
2025-05-20 179c4d64313c9b7572778da4aaaf6c6584fe457d
springcloud_k8s_panzhihuazhihuishequ/service_partybuilding/src/main/java/com/panzhihua/service_dangjian/service/impl/NewFightShoppingOrderServiceImpl.java
@@ -1,11 +1,14 @@
package com.panzhihua.service_dangjian.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.model.dtos.partybuilding.NewFightIntegral;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.building.NewFightShoppingOrderVO;
import com.panzhihua.common.model.vos.user.SysUserNoticeVO;
import com.panzhihua.common.service.user.UserService;
import com.panzhihua.common.utlis.Snowflake;
import com.panzhihua.service_dangjian.dao.NewFightShoppingOrderDao;
import com.panzhihua.service_dangjian.entity.ComActIntegralUser;
@@ -14,6 +17,7 @@
import com.panzhihua.service_dangjian.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -32,12 +36,16 @@
    @Resource
    private ComActIntegralUsersService integralUsersService;
    @Resource
    private UserService userService;
    @Override
    public R getList(int pageNum,int pageSize,String userId,String goodsId,String orderNumber,
                     String goodName,String name,String cancelType,String communityId)
                     String goodName,String name,String cancelType,String communityId,String merchantId,String orderType)
    {
        Page page = new Page<NewFightShopping>(pageNum,pageSize);
        return R.ok(baseMapper.getList(page,userId,goodsId,orderNumber,goodName,name,cancelType,communityId));
        return R.ok(baseMapper.getList(page,userId,goodsId,orderNumber,goodName,name,cancelType,
                communityId, merchantId,orderType));
    }
    @Override
@@ -50,10 +58,6 @@
    public R addData(NewFightShoppingOrderVO item)
    {
        item.setOrderNumber(Snowflake.getId()+"");
        NewFightShopping goods=shoppingService.getDetails(item.getGoodsId());
        int allMoney=0;
        int getMoney=Integer.valueOf(goods.getGoodPrice());
        // 查询用户积分账户
@@ -62,12 +66,27 @@
                        .eq(ComActIntegralUser::getUserId, item.getUserId())
                        .eq(ComActIntegralUser::getCommunityId, item.getCommunityId()));
        int allMoney=0;
        int getMoney=0;
        if(integralUserDO==null)
        {
            return R.fail("积分不足!");
        }
        allMoney=integralUserDO.getIntegralAvailableSum();
        //判断是线上下单  还是商家线下下单  1线上   2线下
        if(StringUtils.equals("2",item.getOrderType()))
        {
            getMoney=Integer.valueOf(item.getPalyMoney());
        }
        else
        {
            NewFightShopping goods=shoppingService.getDetails(item.getGoodsId());
            getMoney=Integer.valueOf(goods.getGoodPrice());
        }
        if(getMoney>allMoney)
        {
@@ -75,21 +94,52 @@
        }
        item.setCancelType("0");
        item.setPalyMoney(goods.getGoodPrice());
        item.setPalyMoney(getMoney+"");
        int num= baseMapper.addData(item);
        if(num>0)
        {
            //修改个人积分总额
            allMoney=allMoney-getMoney;
            NewFightIntegral integral=new NewFightIntegral();
            integral.setIntegralNum(allMoney+"");
            integral.setAddOrReduce(2);
            integral.setCommunityId(item.getCommunityId());
            integral.setUserId(item.getUserId());
            integral.setType("9");
            integral.setIdentityType("1");
            integral.setRemark("积分兑换商品");
            if(StringUtils.equals("1",item.getOrderType()))
            {
                integral.setType("9");
                integral.setIdentityType("1");
                integral.setRemark("积分兑换商品");
            }
            else
            {
                integral.setType("10");
                integral.setIdentityType("1");
                integral.setRemark("商家兑换商品");
                integral.setMerchantId(item.getMerchantId());
                integral.setIntegralNum(item.getPalyMoney());
                SysUserNoticeVO sysUserNoticeVO = new SysUserNoticeVO();
                sysUserNoticeVO.setUserId(Long.valueOf(item.getUserId()));
                sysUserNoticeVO.setType(4);
                sysUserNoticeVO.setTitle("商家兑换成功");
                sysUserNoticeVO.setBusinessType(14);
                sysUserNoticeVO.setBusinessTitle(item.getRemark());
                sysUserNoticeVO
                        .setBusinessContent(String.format("兑换商品%s", item.getRemark()));
                sysUserNoticeVO.setStatus(0);
                sysUserNoticeVO.setBusinessStatus(1);
                sysUserNoticeVO.setBusinessId(Long.valueOf(item.getId()));
                sysUserNoticeVO.setActivityType(4);
                R r2 = userService.addNotice(sysUserNoticeVO);
                if (R.isOk(r2)) {
                    log.info("新增兑换商品通知成功【{}】", JSONObject.toJSONString(sysUserNoticeVO));
                }
            }
            integralUsersService.upIntegral(integral);
            return R.ok();
@@ -104,7 +154,7 @@
        {
            return R.ok();
        }
        return R.fail("添加失败");
        return R.fail("失败");
    }
    @Override
@@ -144,9 +194,21 @@
            integral.setAddOrReduce(1);
            integral.setCommunityId(order.getCommunityId());
            integral.setUserId(order.getUserId());
            integral.setType("9");
            integral.setIdentityType("1");
            integral.setRemark("积分兑换商品取消");
            if(StringUtils.equals("1",order.getOrderType()))
            {
                integral.setType("9");
                integral.setIdentityType("1");
                integral.setRemark("积分兑换商品取消");
            }
            else
            {
                integral.setType("10");
                integral.setIdentityType("1");
                integral.setRemark("商家兑换商品取消");
                integral.setMerchantId(order.getMerchantId());
                integral.setIntegralNum(order.getPalyMoney());
            }
            integralUsersService.upIntegral(integral);
            return R.ok();