diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java index 85408813..5375be3d 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java @@ -2,8 +2,8 @@ package com.ghy.web.controller.order; import com.ghy.common.core.controller.BaseController; import com.ghy.common.core.domain.AjaxResult; +import com.ghy.common.core.domain.entity.SysUser; import com.ghy.common.enums.*; -import com.ghy.common.utils.StringUtils; import com.ghy.customer.domain.Customer; import com.ghy.customer.domain.CustomerAddress; import com.ghy.customer.service.CustomerAddressService; @@ -23,11 +23,9 @@ import com.ghy.order.service.*; import com.ghy.payment.domain.FinancialChangeRecord; import com.ghy.payment.domain.FinancialDetail; import com.ghy.payment.domain.FinancialMaster; -import com.ghy.payment.domain.OrderTimeoutRecord; import com.ghy.payment.service.FinancialChangeRecordService; import com.ghy.payment.service.FinancialDetailService; import com.ghy.payment.service.FinancialMasterService; -import com.ghy.payment.service.OrderFineRecordService; import com.ghy.system.domain.SysArea; import com.ghy.system.service.ISysAreaService; import com.ghy.system.service.IWxMsgService; @@ -37,6 +35,7 @@ import com.ghy.worker.domain.WorkerCertification; import com.ghy.worker.service.IWorkerCertificationService; import com.ghy.worker.service.WorkerService; import com.huifu.adapay.core.exception.BaseAdaPayException; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.time.DateUtils; import org.springframework.beans.BeanUtils; @@ -70,6 +69,8 @@ public class OrderController extends BaseController { @Resource private CustomerService customerService; @Resource + private CustomerAddressService customerAddressService; + @Resource private GoodsService goodsService; @Resource private DeptGoodsCategoryService deptGoodsCategoryService; @@ -92,8 +93,6 @@ public class OrderController extends BaseController { @Resource private ISysAreaService sysAreaService; @Resource - private OrderFineRecordService orderFineRecordService; - @Resource private FinancialChangeRecordService financialChangeRecordService; @Resource private IWorkerCertificationService workerCertificationService; @@ -143,6 +142,34 @@ public class OrderController extends BaseController { @ResponseBody @Transactional(rollbackFor = Exception.class) public AjaxResult sysOrder(@RequestBody SysOrderAssignRequest request) { + + SysUser sysUser = getSysUser(); + Long deptId = sysUser.getDeptId(); + String loginName = sysUser.getLoginName(); + Customer customer = customerService.selectByAccount("sys_" + loginName); + if (customer == null) { + customer = new Customer(); + customer.setAccount("sys_" + loginName); + customer.setName("平台用户_" + loginName); + customerService.insertCustomer(customer); + } + + if (request.getProvinceId() == null || request.getCityId() == null || request.getCountryId() == null || StringUtils.isBlank(request.getAddress())) { + return AjaxResult.error("请填写地址"); + } + CustomerAddress customerAddress = customerAddressService.selectByCustomerAndAddress(customer.getCustomerId(), + request.getProvinceId(), request.getCityId(), request.getCountryId(), request.getAddress()); + if (customerAddress == null) { + customerAddress = new CustomerAddress(); + customerAddress.setCustomerId(customer.getCustomerId()); + customerAddress.setProvinceId(request.getProvinceId()); + customerAddress.setCityId(request.getCityId()); + customerAddress.setCountryId(request.getCountryId()); + customerAddress.setAddress(request.getAddress()); + customerAddress.setIsDefault(0); + customerAddressService.insertCustomerAddress(customerAddress); + } + request.setGoodsDeptCategoryId(request.getCategory4()); List ids = new ArrayList<>(); ids.add(request.getCategory1()); @@ -154,10 +181,9 @@ public class OrderController extends BaseController { OrderTemplateGoods orderTemplateGoods = new OrderTemplateGoods(); orderTemplateGoods.setGoodsName(request.getGoodsBrand() + " " + deptGoodsCategory.getGoodsCategoryName()); orderTemplateGoods.setDeptGoodsCategoryIds(ids); - orderTemplateGoods.setDeptGoodsCategoryNames(Arrays.asList(orderTemplateGoods.getGoodsName())); - request.setGoods(Arrays.asList(orderTemplateGoods)); + orderTemplateGoods.setDeptGoodsCategoryNames(Collections.singletonList(orderTemplateGoods.getGoodsName())); + request.setGoods(Collections.singletonList(orderTemplateGoods)); String goodsBrand = request.getGoodsBrand(); - Long deptId = getSysUser().getDeptId(); List goodsList = request.getGoods(); // 订单总价 不能小于0 BigDecimal orderPrice = BigDecimal.valueOf(request.getPrice()).max(BigDecimal.ZERO); @@ -205,10 +231,10 @@ public class OrderController extends BaseController { orderMaster.setCode(orderMasterService.createOrderCode()); orderMaster.setOrderType(0); orderMaster.setOrderStatus(OrderStatus.RECEIVE.code()); - orderMaster.setAddressId(request.getAddressId()); + orderMaster.setAddressId(customerAddress.getCustomerAddressId()); orderMaster.setPayStatus(PayStatus.WAIT_PAY.getCode()); orderMaster.setCreateTime(new Date()); - orderMaster.setWorkerId(goods.getWorkerId()); + orderMaster.setCustomerId(customer.getCustomerId()); orderMaster.setGoodsId(goods.getGoodsId()); orderMasterService.insertOrderMaster(orderMaster); Assert.notNull(orderMaster.getId(), "OrderMaster.id is null!"); @@ -406,7 +432,7 @@ public class OrderController extends BaseController { public AjaxResult appOrder(@RequestBody AppOrderRequest appOrderRequest) throws ParseException { // 校验用户信息 Customer customer = customerService.selectByCustomerId(appOrderRequest.getCustomerId()); - if (StringUtils.isNull(customer)) { + if (customer == null) { return AjaxResult.error("用户不存在!"); } List appGoodsList = appOrderRequest.getGoodsList(); diff --git a/ghy-custom/src/main/java/com/ghy/customer/mapper/CustomerAddressMapper.java b/ghy-custom/src/main/java/com/ghy/customer/mapper/CustomerAddressMapper.java index b895e1b2..7289d34b 100644 --- a/ghy-custom/src/main/java/com/ghy/customer/mapper/CustomerAddressMapper.java +++ b/ghy-custom/src/main/java/com/ghy/customer/mapper/CustomerAddressMapper.java @@ -50,4 +50,9 @@ public interface CustomerAddressMapper { */ int updateCustomerAddress(CustomerAddress customerAddress); + CustomerAddress selectByCustomerAndAddress(@Param("customerId") Long customerId, + @Param("provinceId") Long provinceId, + @Param("cityId") Long cityId, + @Param("countryId") Long countryId, + @Param("address") String address); } diff --git a/ghy-custom/src/main/java/com/ghy/customer/mapper/CustomerMapper.java b/ghy-custom/src/main/java/com/ghy/customer/mapper/CustomerMapper.java index 8729fcc8..95f83c26 100644 --- a/ghy-custom/src/main/java/com/ghy/customer/mapper/CustomerMapper.java +++ b/ghy-custom/src/main/java/com/ghy/customer/mapper/CustomerMapper.java @@ -63,4 +63,5 @@ public interface CustomerMapper { */ List selectByIds(@Param("customerIds") Collection customerIds); + Customer selectByAccount(String account); } diff --git a/ghy-custom/src/main/java/com/ghy/customer/service/CustomerAddressService.java b/ghy-custom/src/main/java/com/ghy/customer/service/CustomerAddressService.java index f03596c4..8303811e 100644 --- a/ghy-custom/src/main/java/com/ghy/customer/service/CustomerAddressService.java +++ b/ghy-custom/src/main/java/com/ghy/customer/service/CustomerAddressService.java @@ -49,4 +49,6 @@ public interface CustomerAddressService { * @return 修改成功条数 */ int updateCustomerAddress(CustomerAddress customerAddress); + + CustomerAddress selectByCustomerAndAddress(Long customerId, Long provinceId, Long cityId, Long countryId, String address); } diff --git a/ghy-custom/src/main/java/com/ghy/customer/service/CustomerService.java b/ghy-custom/src/main/java/com/ghy/customer/service/CustomerService.java index 774b73b7..2159f834 100644 --- a/ghy-custom/src/main/java/com/ghy/customer/service/CustomerService.java +++ b/ghy-custom/src/main/java/com/ghy/customer/service/CustomerService.java @@ -73,4 +73,6 @@ public interface CustomerService { * @return Customer */ List selectByIds(Set customerIds); + + Customer selectByAccount(String account); } diff --git a/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerAddressServiceImpl.java b/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerAddressServiceImpl.java index f6b94e6c..73153f91 100644 --- a/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerAddressServiceImpl.java +++ b/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerAddressServiceImpl.java @@ -60,4 +60,9 @@ public class CustomerAddressServiceImpl implements CustomerAddressService { public int updateCustomerAddress(CustomerAddress customerAddress) { return customerAddressMapper.updateCustomerAddress(customerAddress); } + + @Override + public CustomerAddress selectByCustomerAndAddress(Long customerId, Long provinceId, Long cityId, Long countryId, String address) { + return customerAddressMapper.selectByCustomerAndAddress(customerId, provinceId, cityId, countryId, address); + } } diff --git a/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerServiceImpl.java b/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerServiceImpl.java index b166e522..05f48b8e 100644 --- a/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerServiceImpl.java +++ b/ghy-custom/src/main/java/com/ghy/customer/service/impl/CustomerServiceImpl.java @@ -104,4 +104,9 @@ public class CustomerServiceImpl implements CustomerService { } return customerMapper.selectByIds(customerIds); } + + @Override + public Customer selectByAccount(String account) { + return customerMapper.selectByAccount(account); + } } diff --git a/ghy-custom/src/main/resources/mapper/customer/CustomerAddressMapper.xml b/ghy-custom/src/main/resources/mapper/customer/CustomerAddressMapper.xml index c893bd39..e4c81373 100644 --- a/ghy-custom/src/main/resources/mapper/customer/CustomerAddressMapper.xml +++ b/ghy-custom/src/main/resources/mapper/customer/CustomerAddressMapper.xml @@ -62,6 +62,15 @@ WHERE customer_address_id = #{customerAddressId} + + insert into customer_address( customer_id, diff --git a/ghy-custom/src/main/resources/mapper/customer/CustomerMapper.xml b/ghy-custom/src/main/resources/mapper/customer/CustomerMapper.xml index 3bf0e060..110a684f 100644 --- a/ghy-custom/src/main/resources/mapper/customer/CustomerMapper.xml +++ b/ghy-custom/src/main/resources/mapper/customer/CustomerMapper.xml @@ -146,4 +146,9 @@ + + diff --git a/ghy-order/src/main/java/com/ghy/order/request/SysOrderAssignRequest.java b/ghy-order/src/main/java/com/ghy/order/request/SysOrderAssignRequest.java index 8a8db7be..029d50a8 100644 --- a/ghy-order/src/main/java/com/ghy/order/request/SysOrderAssignRequest.java +++ b/ghy-order/src/main/java/com/ghy/order/request/SysOrderAssignRequest.java @@ -31,4 +31,13 @@ public class SysOrderAssignRequest { private Long addressId; // 发布价格(限制整数) private Integer price; + + private Long provinceId; + + private Long cityId; + + private Long countryId; + + // 详细地址 + private String address; } diff --git a/ghy-system/src/main/java/com/ghy/system/mapper/SysUserMapper.java b/ghy-system/src/main/java/com/ghy/system/mapper/SysUserMapper.java index 864e7f8d..dc3ef2ff 100644 --- a/ghy-system/src/main/java/com/ghy/system/mapper/SysUserMapper.java +++ b/ghy-system/src/main/java/com/ghy/system/mapper/SysUserMapper.java @@ -37,10 +37,10 @@ public interface SysUserMapper /** * 通过用户名查询用户 * - * @param userName 用户名 + * @param loginName 用户名 * @return 用户对象信息 */ - public SysUser selectUserByLoginName(String userName); + public SysUser selectUserByLoginName(String loginName); /** * 通过手机号码查询用户 diff --git a/ghy-system/src/main/java/com/ghy/system/service/ISysUserService.java b/ghy-system/src/main/java/com/ghy/system/service/ISysUserService.java index 4d49b5bd..624a3d0a 100644 --- a/ghy-system/src/main/java/com/ghy/system/service/ISysUserService.java +++ b/ghy-system/src/main/java/com/ghy/system/service/ISysUserService.java @@ -38,10 +38,10 @@ public interface ISysUserService /** * 通过用户名查询用户 * - * @param userName 用户名 + * @param loginName 用户名 * @return 用户对象信息 */ - public SysUser selectUserByLoginName(String userName); + public SysUser selectUserByLoginName(String loginName); /** * 通过手机号码查询用户 diff --git a/ghy-system/src/main/java/com/ghy/system/service/impl/SysUserServiceImpl.java b/ghy-system/src/main/java/com/ghy/system/service/impl/SysUserServiceImpl.java index 53164ae6..b2fe3fad 100644 --- a/ghy-system/src/main/java/com/ghy/system/service/impl/SysUserServiceImpl.java +++ b/ghy-system/src/main/java/com/ghy/system/service/impl/SysUserServiceImpl.java @@ -105,13 +105,13 @@ public class SysUserServiceImpl implements ISysUserService /** * 通过用户名查询用户 * - * @param userName 用户名 + * @param loginName 用户名 * @return 用户对象信息 */ @Override - public SysUser selectUserByLoginName(String userName) + public SysUser selectUserByLoginName(String loginName) { - return userMapper.selectUserByLoginName(userName); + return userMapper.selectUserByLoginName(loginName); } /**