diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/ajax/AjaxMemberController.java b/ruoyi-business/src/main/java/com/ruoyi/business/ajax/AjaxMemberController.java index cb36d062f..9504840d0 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/ajax/AjaxMemberController.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/ajax/AjaxMemberController.java @@ -38,6 +38,7 @@ public class AjaxMemberController extends AuthController { resultMap.put("douBalance", member.getDouBalance()); resultMap.put("douPerson", member.getDouPerson()); resultMap.put("douTeam", member.getDouTeam()); + resultMap.put("douSpecial", member.getDouSpecial()); resultMap.put("douField", member.getDouField()); return AjaxResult.success(resultMap); } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/ajax/AjaxOrderController.java b/ruoyi-business/src/main/java/com/ruoyi/business/ajax/AjaxOrderController.java index 559928f64..662eb1944 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/ajax/AjaxOrderController.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/ajax/AjaxOrderController.java @@ -1,9 +1,6 @@ package com.ruoyi.business.ajax; -import com.ruoyi.business.domain.BizMember; -import com.ruoyi.business.domain.BizMemberAddress; -import com.ruoyi.business.domain.BizOrder; -import com.ruoyi.business.domain.BizProduct; +import com.ruoyi.business.domain.*; import com.ruoyi.business.service.*; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; @@ -62,7 +59,7 @@ public class AjaxOrderController extends AuthController { Long userID = getUserID(); Map resultMap = new HashMap(); //取出福豆余额 - resultMap.put("douBalance", bizMemberService.selectBizMemberDou(userID, BizMember.DOU_BALANCE)); + resultMap.put("douBalance", bizMemberService.selectBizMemberDou(userID, BizAccount.DOU_BALANCE)); //取出默认地址 BizMemberAddress defaultAddress = bizMemberAddressService.selectDefaultAddressByMemberId(userID); resultMap.put("defaultAddress", defaultAddress); @@ -84,7 +81,25 @@ public class AjaxOrderController extends AuthController { { Long userID = getUserID(); + return bizOrderService.orderAdd(userID, productID, productNum, addressID, remark); + } - return AjaxResult.success(); + //取消订单 + @PostMapping("/orderCancel") + public AjaxResult orderCancel(Long orderID) + { + Long userID = getUserID(); + + //TODO 取消订单延后(专项划拨处理??) + return bizOrderService.orderConfirm(userID, orderID); + } + + //订单收货 + @PostMapping("/orderConfirm") + public AjaxResult orderConfirm(Long orderID) + { + Long userID = getUserID(); + + return bizOrderService.orderConfirm(userID, orderID); } } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/controller/BizProductController.java b/ruoyi-business/src/main/java/com/ruoyi/business/controller/BizProductController.java index 182fda646..fdea6a806 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/controller/BizProductController.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/controller/BizProductController.java @@ -100,7 +100,7 @@ public class BizProductController extends BaseController Date now = new Date(); bizProduct.setCreateBy(ShiroUtils.getLoginName()); bizProduct.setCreateTime(now); - bizProduct.setProductCode("BPD" + DateUtils.dateTimeNow("YYYYMMDDHHMMSSSSS")); + bizProduct.setProductCode("BPD" + DateUtils.getMilliTime()); //如果上架设置上架时间 if (bizProduct.getOnlineStatus() == 1) { bizProduct.setOnlineTime(now); diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/controller/BizProductTypeController.java b/ruoyi-business/src/main/java/com/ruoyi/business/controller/BizProductTypeController.java index 37b0f75fc..63f2fb775 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/controller/BizProductTypeController.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/controller/BizProductTypeController.java @@ -92,7 +92,7 @@ public class BizProductTypeController extends BaseController { bizProductType.setCreateBy(ShiroUtils.getLoginName()); bizProductType.setCreateTime(new Date()); - bizProductType.setProductTypeCode("BPT" + DateUtils.dateTimeNow("YYYYMMDDHHMMSSSSS")); + bizProductType.setProductTypeCode("BPT" + DateUtils.getMilliTime()); return toAjax(bizProductTypeService.insertBizProductType(bizProductType)); } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/domain/BizAccount.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/BizAccount.java index 147d0d3ce..bc9bd182a 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/domain/BizAccount.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/BizAccount.java @@ -16,6 +16,13 @@ public class BizAccount extends BaseEntity { private static final long serialVersionUID = 1L; + //用户豆账户(0-福豆余额,1-个人福豆,2-团队福豆, 3-福豆田) + public static final int DOU_BALANCE = 0; + public static final int DOU_PERSON = 1; + public static final int DOU_TEAM = 2; + public static final int DOU_SPECIAL = 3; + public static final int DOU_FIELD = 4; + /** 会员账户ID */ private Long id; @@ -58,12 +65,12 @@ public class BizAccount extends BaseEntity { return accountType; } - public void setAmount(BigDecimal amount) + public void setAmount(BigDecimal amount) { this.amount = amount; } - public BigDecimal getAmount() + public BigDecimal getAmount() { return amount; } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/domain/BizAccountDetail.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/BizAccountDetail.java new file mode 100644 index 000000000..b40bf02d0 --- /dev/null +++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/BizAccountDetail.java @@ -0,0 +1,185 @@ +package com.ruoyi.business.domain; + +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.math.BigDecimal; +/** + * 会员账户明细对象 biz_account_detail + * + * @author ruoyi + * @date 2020-09-17 + */ +public class BizAccountDetail extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + //福豆改变类型 + public static final int DOU_CHANGE_TYPE_ADD = 1; + public static final int DOU_CHANGE_TYPE_REDUSE = -1; + //福豆使用类型 + public static final int DOU_DETAIL_TYPE_CHARGE = 1; + public static final int DOU_DETAIL_TYPE_DRAW = 2; + public static final int DOU_DETAIL_TYPE_EXCHANGE = 3; + public static final int DOU_DETAIL_TYPE_RESET = 4; + public static final int DOU_DETAIL_TYPE_ORDER = 5; + //福豆使用备注 + public static final String DOU_DESC_RECOMM = "直推奖励"; + public static final String DOU_DESC_SECOND = "二级推荐奖励"; + public static final String DOU_DESC_TEAM = "团队奖励"; + public static final String DOU_DESC_SPECIAL1 = "专项账户充值"; + public static final String DOU_DESC_SPECIAL2 = "专项划拨"; + public static final String DOU_DESC_ORDER = "订单消费"; + + /** 会员账户明细ID */ + private Long id; + + /** 会员ID */ + @Excel(name = "会员ID") + private Long memberId; + + /** 会员账户ID */ + @Excel(name = "会员账户ID") + private Long accountId; + + /** 账户类型:0-福豆余额,1-个人福豆,2-团队福豆,3-专项福豆,4-福豆田 */ + @Excel(name = "账户类型:0-福豆余额,1-个人福豆,2-团队福豆,3-专项福豆,4-福豆田") + private Integer accountType; + + /** 业务订单编号: 三方支付/兑现申请/团队明细 */ + @Excel(name = "业务订单编号: 三方支付/兑现申请/团队明细") + private String businessNo; + + /** 变更类型;1:收入(加);-1:支出(减) */ + @Excel(name = "变更类型;1:收入(加);-1:支出(减)") + private Integer changeType; + + /** 变动详情.1:充值;2:提现;3:转账;4:冲正;5:支付 */ + @Excel(name = "变动详情.1:充值;2:提现;3:转账;4:冲正;5:支付") + private Integer typeDetail; + + /** 账户变更前金额 */ + @Excel(name = "账户变更前金额") + private Long beforeAmount; + + /** 账户变更后金额 */ + @Excel(name = "账户变更后金额") + private Long afterAmount; + + /** 交易备注:充值【一级推荐奖励】,充值【二级推荐奖励】,充值【团队奖励】,充值【专项划拨】,转账【专项划拨】 */ + @Excel(name = "交易备注:充值【一级推荐奖励】,充值【二级推荐奖励】,充值【团队奖励】,充值【专项划拨】,转账【专项划拨】") + private String changeDesc; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + public void setMemberId(Long memberId) + { + this.memberId = memberId; + } + + public Long getMemberId() + { + return memberId; + } + public void setAccountId(Long accountId) + { + this.accountId = accountId; + } + + public Long getAccountId() + { + return accountId; + } + public void setAccountType(Integer accountType) + { + this.accountType = accountType; + } + + public Integer getAccountType() + { + return accountType; + } + public void setBusinessNo(String businessNo) + { + this.businessNo = businessNo; + } + + public String getBusinessNo() + { + return businessNo; + } + public void setChangeType(Integer changeType) + { + this.changeType = changeType; + } + + public Integer getChangeType() + { + return changeType; + } + public void setTypeDetail(Integer typeDetail) + { + this.typeDetail = typeDetail; + } + + public Integer getTypeDetail() + { + return typeDetail; + } + public void setBeforeAmount(Long beforeAmount) + { + this.beforeAmount = beforeAmount; + } + + public Long getBeforeAmount() + { + return beforeAmount; + } + public void setAfterAmount(Long afterAmount) + { + this.afterAmount = afterAmount; + } + + public Long getAfterAmount() + { + return afterAmount; + } + public void setChangeDesc(String changeDesc) + { + this.changeDesc = changeDesc; + } + + public String getChangeDesc() + { + return changeDesc; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("memberId", getMemberId()) + .append("accountId", getAccountId()) + .append("accountType", getAccountType()) + .append("businessNo", getBusinessNo()) + .append("changeType", getChangeType()) + .append("typeDetail", getTypeDetail()) + .append("beforeAmount", getBeforeAmount()) + .append("afterAmount", getAfterAmount()) + .append("changeDesc", getChangeDesc()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .toString(); + } +} \ No newline at end of file diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/domain/BizMember.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/BizMember.java index e8c4036ca..2aaf2f033 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/domain/BizMember.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/BizMember.java @@ -15,12 +15,6 @@ public class BizMember extends BaseEntity { private static final long serialVersionUID = 1L; - //用户豆账户(0-福豆余额,1-个人福豆,2-团队福豆, 3-福豆田) - public static final int DOU_BALANCE = 0; - public static final int DOU_PERSON = 1; - public static final int DOU_TEAM = 2; - public static final int DOU_FIELD = 3; - /** 会员ID */ private Long id; @@ -69,6 +63,9 @@ public class BizMember extends BaseEntity @Excel(name = "团队福豆") private Long douTeam; + @Excel(name = "专项福豆") + private Long douSpecial; + @Excel(name = "福豆田") private Long douField; @@ -196,6 +193,14 @@ public class BizMember extends BaseEntity this.douTeam = douTeam; } + public Long getDouSpecial() { + return douSpecial; + } + + public void setDouSpecial(Long douSpecial) { + this.douSpecial = douSpecial; + } + public Long getDouField() { return douField; } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/domain/BizOrderDetail.java b/ruoyi-business/src/main/java/com/ruoyi/business/domain/BizOrderDetail.java new file mode 100644 index 000000000..5256319f8 --- /dev/null +++ b/ruoyi-business/src/main/java/com/ruoyi/business/domain/BizOrderDetail.java @@ -0,0 +1,126 @@ +package com.ruoyi.business.domain; + +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.math.BigDecimal; +/** + * 订单明细对象 biz_order_detail + * + * @author ruoyi + * @date 2020-09-17 + */ +public class BizOrderDetail extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 订单明细ID */ + private Long id; + + /** 订单ID */ + @Excel(name = "订单ID") + private Long orderId; + + /** 订单编码 */ + @Excel(name = "订单编码") + private String orderSn; + + /** 产品ID */ + @Excel(name = "产品ID") + private Long productId; + + /** 产品编码 */ + @Excel(name = "产品编码") + private String productCode; + + /** 商品数量 */ + @Excel(name = "商品数量") + private Integer productCount; + + /** 商品金额 */ + @Excel(name = "商品金额") + private BigDecimal productAmount; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + public void setOrderId(Long orderId) + { + this.orderId = orderId; + } + + public Long getOrderId() + { + return orderId; + } + public void setOrderSn(String orderSn) + { + this.orderSn = orderSn; + } + + public String getOrderSn() + { + return orderSn; + } + public void setProductId(Long productId) + { + this.productId = productId; + } + + public Long getProductId() + { + return productId; + } + public void setProductCode(String productCode) + { + this.productCode = productCode; + } + + public String getProductCode() + { + return productCode; + } + public void setProductCount(Integer productCount) + { + this.productCount = productCount; + } + + public Integer getProductCount() + { + return productCount; + } + public void setProductAmount(BigDecimal productAmount) + { + this.productAmount = productAmount; + } + + public BigDecimal getProductAmount() + { + return productAmount; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("orderId", getOrderId()) + .append("orderSn", getOrderSn()) + .append("productId", getProductId()) + .append("productCode", getProductCode()) + .append("productCount", getProductCount()) + .append("productAmount", getProductAmount()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .toString(); + } +} \ No newline at end of file diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/mapper/BizAccountMapper.java b/ruoyi-business/src/main/java/com/ruoyi/business/mapper/BizAccountMapper.java index 068622160..59e08e2ea 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/mapper/BizAccountMapper.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/mapper/BizAccountMapper.java @@ -1,6 +1,7 @@ package com.ruoyi.business.mapper; import com.ruoyi.business.domain.BizAccount; +import com.ruoyi.business.domain.BizAccountDetail; import java.util.List; @@ -59,4 +60,20 @@ public interface BizAccountMapper * @return 结果 */ public int deleteBizAccountByIds(String[] ids); + + /** + * 查询会员账户明细列表 + * + * @param bizAccountDetail 会员账户明细 + * @return 会员账户明细集合 + */ + public List selectBizAccountDetailList(BizAccountDetail bizAccountDetail); + + /** + * 新增会员账户明细 + * + * @param bizAccountDetail 会员账户明细 + * @return 结果 + */ + public int insertBizAccountDetail(BizAccountDetail bizAccountDetail); } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/mapper/BizOrderMapper.java b/ruoyi-business/src/main/java/com/ruoyi/business/mapper/BizOrderMapper.java index 25d2ea41c..9ec294a10 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/mapper/BizOrderMapper.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/mapper/BizOrderMapper.java @@ -2,6 +2,7 @@ package com.ruoyi.business.mapper; import java.util.List; import com.ruoyi.business.domain.BizOrder; +import com.ruoyi.business.domain.BizOrderDetail; /** * 订单Mapper接口 @@ -58,4 +59,12 @@ public interface BizOrderMapper * @return 结果 */ public int deleteBizOrderByIds(String[] ids); + + /** + * 新增订单明细 + * + * @param bizOrderDetail 订单明细 + * @return 结果 + */ + public int insertBizOrderDetail(BizOrderDetail bizOrderDetail); } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/IBizAccountService.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/IBizAccountService.java index 803334f1b..bc8de81f3 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/IBizAccountService.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/IBizAccountService.java @@ -59,4 +59,12 @@ public interface IBizAccountService * @return 结果 */ public int deleteBizAccountById(Long id); + + /** + * 会员福豆变动明细 + * + * @param memberID accountType detailType money businessInfo desc + * @return boolean + */ + public boolean accountChange(Long memberID, int accountType, int detailType, Long money, String businessInfo, String desc); } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/IBizMemberService.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/IBizMemberService.java index 98e1527c3..419757b87 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/IBizMemberService.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/IBizMemberService.java @@ -76,4 +76,5 @@ public interface IBizMemberService * @return 结果 */ public int deleteBizMemberById(Long id); + } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/IBizOrderService.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/IBizOrderService.java index dc5f70618..3c58079af 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/IBizOrderService.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/IBizOrderService.java @@ -2,6 +2,7 @@ package com.ruoyi.business.service; import java.util.List; import com.ruoyi.business.domain.BizOrder; +import com.ruoyi.common.core.domain.AjaxResult; /** * 订单Service接口 @@ -66,4 +67,20 @@ public interface IBizOrderService * @return 结果 */ public int deleteBizOrderById(Long id); + + /** + * 添加订单 + * + * @param + * @return AjaxResult + */ + public AjaxResult orderAdd(Long memberID, Long productID, int productNum, Long addressID, String remark); + + /** + * 订单收货 + * + * @param + * @return AjaxResult + */ + public AjaxResult orderConfirm(Long userID, Long orderID); } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/BizAccountServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/BizAccountServiceImpl.java index 8a5a908a7..274fbf79a 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/BizAccountServiceImpl.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/BizAccountServiceImpl.java @@ -1,8 +1,11 @@ package com.ruoyi.business.service.impl; +import java.math.BigDecimal; +import java.util.Date; import java.util.List; import com.ruoyi.business.domain.BizAccount; +import com.ruoyi.business.domain.BizAccountDetail; import com.ruoyi.business.mapper.BizAccountMapper; import com.ruoyi.business.service.IBizAccountService; import com.ruoyi.common.utils.DateUtils; @@ -95,4 +98,49 @@ public class BizAccountServiceImpl implements IBizAccountService { return bizAccountMapper.deleteBizAccountById(id); } + + /** + * 会员福豆变动明细 + * + * @param memberID accountType detailType money businessInfo desc + * @return boolean + */ + @Override + public boolean accountChange(Long memberID, int accountType, int detailType, Long money, String businessInfo, String desc) + { + //取出用户账户 + BizAccount bizAccount = new BizAccount(); + bizAccount.setMemberId(memberID); + bizAccount.setAccountType(accountType); + List accountList = bizAccountMapper.selectBizAccountList(bizAccount); + if (accountList.size() == 0) { + return false; + } + bizAccount = accountList.get(0); + //减去的话判断金额 + int changeType = money >= 0 ? BizAccountDetail.DOU_CHANGE_TYPE_ADD : BizAccountDetail.DOU_CHANGE_TYPE_REDUSE; + Long beforeMoney = bizAccount.getAmount().longValue(); + if (changeType == BizAccountDetail.DOU_CHANGE_TYPE_REDUSE && beforeMoney < -money) { + return false; + } + //增加余额 + Long afterMoney = beforeMoney + money; + bizAccount.setAmount(new BigDecimal(afterMoney)); + bizAccountMapper.updateBizAccount(bizAccount); + + //详细记录 + BizAccountDetail detail = new BizAccountDetail(); + detail.setMemberId(memberID); + detail.setAccountId(bizAccount.getId()); + detail.setAccountType(accountType); + detail.setBusinessNo(businessInfo); + detail.setChangeType(changeType); + detail.setTypeDetail(detailType); + detail.setBeforeAmount(beforeMoney); + detail.setAfterAmount(afterMoney); + detail.setChangeDesc(desc); + detail.setUpdateTime(new Date()); + bizAccountMapper.insertBizAccountDetail(detail); + return true; + } } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/BizMemberAddressServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/BizMemberAddressServiceImpl.java index ef6e2db5f..53971a0ea 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/BizMemberAddressServiceImpl.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/BizMemberAddressServiceImpl.java @@ -39,6 +39,7 @@ public class BizMemberAddressServiceImpl implements IBizMemberAddressService * @param memberID 会员ID * @return 会员收货地址 */ + @Override public BizMemberAddress selectDefaultAddressByMemberId(Long memberID) { return bizMemberAddressMapper.selectDefaultAddressByMemberId(memberID); @@ -50,6 +51,7 @@ public class BizMemberAddressServiceImpl implements IBizMemberAddressService * @param memberID 会员ID * @return int */ + @Override public int cancelDefaultAddress(Long memberID) { return bizMemberAddressMapper.cancelDefaultAddress(memberID); diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/BizMemberServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/BizMemberServiceImpl.java index 25161a9bb..c535efc2c 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/BizMemberServiceImpl.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/BizMemberServiceImpl.java @@ -1,9 +1,14 @@ package com.ruoyi.business.service.impl; +import java.math.BigDecimal; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import com.ruoyi.business.domain.BizAccount; +import com.ruoyi.business.domain.BizAccountDetail; +import com.ruoyi.business.mapper.BizAccountMapper; import com.ruoyi.common.utils.DateUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -24,6 +29,9 @@ public class BizMemberServiceImpl implements IBizMemberService @Autowired private BizMemberMapper bizMemberMapper; + @Autowired + private BizAccountMapper bizAccountMapper; + /** * 查询会员 * @@ -66,6 +74,7 @@ public class BizMemberServiceImpl implements IBizMemberService * @param memberID type * @return 结果 */ + @Override public Long selectBizMemberDou(Long memberID, int type) { Map map = new HashMap<>(); @@ -123,4 +132,5 @@ public class BizMemberServiceImpl implements IBizMemberService { return bizMemberMapper.deleteBizMemberById(id); } + } diff --git a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/BizOrderServiceImpl.java b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/BizOrderServiceImpl.java index 7682deae9..e0dd6ae98 100644 --- a/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/BizOrderServiceImpl.java +++ b/ruoyi-business/src/main/java/com/ruoyi/business/service/impl/BizOrderServiceImpl.java @@ -1,15 +1,23 @@ package com.ruoyi.business.service.impl; +import java.math.BigDecimal; import java.util.Date; import java.util.List; + +import com.ruoyi.business.domain.*; +import com.ruoyi.business.mapper.BizMemberAddressMapper; +import com.ruoyi.business.mapper.BizMemberMapper; +import com.ruoyi.business.mapper.BizProductMapper; +import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.StringUtils; import com.ruoyi.framework.util.ShiroUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.business.mapper.BizOrderMapper; -import com.ruoyi.business.domain.BizOrder; import com.ruoyi.business.service.IBizOrderService; import com.ruoyi.common.core.text.Convert; +import org.springframework.transaction.annotation.Transactional; /** * 订单Service业务层处理 @@ -23,6 +31,18 @@ public class BizOrderServiceImpl implements IBizOrderService @Autowired private BizOrderMapper bizOrderMapper; + @Autowired + private BizProductMapper bizProductMapper; + + @Autowired + private BizMemberMapper bizMemberMapper; + + @Autowired + private BizMemberAddressMapper bizMemberAddressMapper; + + @Autowired + private BizAccountServiceImpl bizAccountService; + /** * 查询订单 * @@ -79,6 +99,7 @@ public class BizOrderServiceImpl implements IBizOrderService * @param orderID 订单ID * @return 结果 */ + @Override public int deliverBizOrder(Long orderID) { BizOrder bizOrder = bizOrderMapper.selectBizOrderById(orderID); @@ -118,4 +139,100 @@ public class BizOrderServiceImpl implements IBizOrderService { return bizOrderMapper.deleteBizOrderById(id); } + + /** + * 添加订单 + * + * @param + * @return AjaxResult + */ + @Override + @Transactional + public AjaxResult orderAdd(Long memberID, Long productID, int productNum, Long addressID, String remark) + { + if (productNum <= 0 || productNum > 99) { //检测数量 + return AjaxResult.error("商品数目异常"); + } + if (StringUtils.isEmpty(remark) || remark.length() > 30) { //检测备注 + return AjaxResult.error("备注信息异常"); + } + //取出商品 + BizProduct product = bizProductMapper.selectBizProductById(productID); + if (product == null || product.getOnlineStatus() == 0) { //检测上架 + return AjaxResult.error("该商品不存在"); + } + //订单总价 + Long amount = product.getAmount(); + Long orderTotal = amount * productNum; + //判断余额 + BizMember member = bizMemberMapper.selectBizMemberById(memberID); + Long douBalance = member.getDouBalance(); + if (douBalance < orderTotal) { + return AjaxResult.error("福豆余额不足"); + } + Long cashbackAmount = product.getCashbackAmount() * productNum; + //TODO cashbackAmount 专项划拨金额等级判断 + + //判断地址 + BizMemberAddress address = bizMemberAddressMapper.selectBizMemberAddressById(addressID); + if (address == null || !address.getMemberID().equals(memberID)) { + return AjaxResult.error("收货地址不正确"); + } + + //创建订单 + BizOrder order = new BizOrder(); + order.setOrderSn("ORD" + DateUtils.getMilliTime()); + order.setMemberId(memberID); + order.setMobile(address.getMobile()); + order.setMemberName(member.getMemberName()); + order.setOrderAmount(new BigDecimal(orderTotal)); + order.setOrderStatus(BizOrder.STATUS_PAYED); //已支付 + order.setRemark(remark); + order.setAddressDetail(address.getAddress()); + order.setAddressId(addressID); + insertBizOrder(order); + //订单详情 + BizOrderDetail orderDetail = new BizOrderDetail(); + orderDetail.setOrderId(order.getId()); + orderDetail.setOrderSn(order.getOrderSn()); + orderDetail.setProductId(productID); + orderDetail.setProductCode(product.getProductName()); + orderDetail.setProductCount(productNum); + orderDetail.setProductAmount(new BigDecimal(amount)); + bizOrderMapper.insertBizOrderDetail(orderDetail); + //减去福豆余额账户 + boolean result = bizAccountService.accountChange(memberID, BizAccount.DOU_BALANCE, BizAccountDetail.DOU_DETAIL_TYPE_ORDER, -orderTotal, String.valueOf(order.getId()), BizAccountDetail.DOU_DESC_ORDER); + if (!result) { + return AjaxResult.error("扣款失败,请联系管理员"); + } + //增加专项账户 + if(cashbackAmount > 0) { + result = bizAccountService.accountChange(memberID, BizAccount.DOU_SPECIAL, BizAccountDetail.DOU_DETAIL_TYPE_CHARGE, cashbackAmount, String.valueOf(order.getId()), BizAccountDetail.DOU_DESC_SPECIAL1); + if (!result) { + return AjaxResult.error("扣款失败,请联系管理员"); + } + } + return AjaxResult.success(); + } + + /** + * 订单收货 + * + * @param + * @return AjaxResult + */ + @Override + @Transactional + public AjaxResult orderConfirm(Long userID, Long orderID) + { + BizOrder order = selectBizOrderById(orderID); + //验证 + if (order == null || order.getMemberId() != userID || order.getOrderStatus() != BizOrder.STATUS_DELIVERY) { + return AjaxResult.error("订单操作失败"); + } + order.setOrderStatus(BizOrder.STATUS_COMPLETED); + order.setUpdateBy(String.valueOf(userID)); + updateBizOrder(order); + return AjaxResult.success(); + } } diff --git a/ruoyi-business/src/main/resources/mapper/business/BizAccountMapper.xml b/ruoyi-business/src/main/resources/mapper/business/BizAccountMapper.xml index 02b296e8b..359b4b0ff 100644 --- a/ruoyi-business/src/main/resources/mapper/business/BizAccountMapper.xml +++ b/ruoyi-business/src/main/resources/mapper/business/BizAccountMapper.xml @@ -15,6 +15,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + + + + + + + + + + select id, member_id, account_type, amount, create_by, create_time, update_by, update_time from biz_account @@ -24,7 +41,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and member_id = #{memberId} and account_type = #{accountType} - and amount = #{amount} @@ -80,4 +96,48 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + insert into biz_account_detail + + member_id, + account_id, + account_type, + business_no, + change_type, + type_detail, + before_amount, + after_amount, + change_desc, + create_by, + create_time, + update_by, + update_time, + + + #{memberId}, + #{accountId}, + #{accountType}, + #{businessNo}, + #{changeType}, + #{typeDetail}, + #{beforeAmount}, + #{afterAmount}, + #{changeDesc}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + \ No newline at end of file diff --git a/ruoyi-business/src/main/resources/mapper/business/BizMemberMapper.xml b/ruoyi-business/src/main/resources/mapper/business/BizMemberMapper.xml index a2b043c21..56a884a19 100644 --- a/ruoyi-business/src/main/resources/mapper/business/BizMemberMapper.xml +++ b/ruoyi-business/src/main/resources/mapper/business/BizMemberMapper.xml @@ -26,7 +26,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" (select amount from biz_account where member_id = a.id and account_type = 0) douBalance, (select amount from biz_account where member_id = a.id and account_type = 1) douPerson, (select amount from biz_account where member_id = a.id and account_type = 2) douTeam, - (select amount from biz_account where member_id = a.id and account_type = 3) douField + (select amount from biz_account where member_id = a.id and account_type = 3) douSpecial, + (select amount from biz_account where member_id = a.id and account_type = 4) douField from biz_member a diff --git a/ruoyi-business/src/main/resources/mapper/business/BizOrderMapper.xml b/ruoyi-business/src/main/resources/mapper/business/BizOrderMapper.xml index 9d24ee9b5..ba67f5e36 100644 --- a/ruoyi-business/src/main/resources/mapper/business/BizOrderMapper.xml +++ b/ruoyi-business/src/main/resources/mapper/business/BizOrderMapper.xml @@ -21,13 +21,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + + + + + + + select a.id, order_sn, a.member_id, a.mobile, a.member_name, order_amount, order_status, remark, address_detail, address_id, a.create_by, a.create_time, a.update_by, a.update_time, b.mobile addressMobile, b.member_name addressName, b.province_name addressProvince, b.city_name addressCity, b.area_name addressArea, c.productName, c.productCount, c.productAmount from biz_order a left join biz_member_address b on a.member_id = b.member_id - left join (select max(id), order_id, product_code productName, product_count productCount, product_amount productAmount from biz_order_detail group by product_id) c + left join (select max(id), order_id, product_code productName, product_count productCount, product_amount productAmount from biz_order_detail group by order_id) c on a.id = c.order_id @@ -111,4 +125,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + insert into biz_order_detail + + order_id, + order_sn, + product_id, + product_code, + product_count, + product_amount, + create_by, + create_time, + update_by, + update_time, + + + #{orderId}, + #{orderSn}, + #{productId}, + #{productCode}, + #{productCount}, + #{productAmount}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + \ No newline at end of file diff --git a/ruoyi-business/src/main/resources/templates/business/member/member.html b/ruoyi-business/src/main/resources/templates/business/member/member.html index 83d527f32..73b157a2f 100644 --- a/ruoyi-business/src/main/resources/templates/business/member/member.html +++ b/ruoyi-business/src/main/resources/templates/business/member/member.html @@ -104,6 +104,11 @@ align: 'center', title: '福豆田' }, + { + field: 'douSpecial', + align: 'center', + title: '专项福豆' + }, { field: 'memberType', title: '会员类型', diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java index 8ff95f1b7..4620fcc52 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/DateUtils.java @@ -22,7 +22,9 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss"; public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss"; - + + public static String YYYY_MM_DD_HH_MM_SS_SSS = "yyyyMMddHHmmssSSS"; + private static String[] parsePatterns = { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", @@ -53,6 +55,11 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils return dateTimeNow(YYYY_MM_DD_HH_MM_SS); } + public static final String getMilliTime() + { + return dateTimeNow(YYYY_MM_DD_HH_MM_SS_SSS); + } + public static final String dateTimeNow() { return dateTimeNow(YYYYMMDDHHMMSS);