后台下单时创建Customer和CustomerAddress
This commit is contained in:
parent
444c532f9a
commit
f401676e02
|
|
@ -2,8 +2,8 @@ package com.ghy.web.controller.order;
|
||||||
|
|
||||||
import com.ghy.common.core.controller.BaseController;
|
import com.ghy.common.core.controller.BaseController;
|
||||||
import com.ghy.common.core.domain.AjaxResult;
|
import com.ghy.common.core.domain.AjaxResult;
|
||||||
|
import com.ghy.common.core.domain.entity.SysUser;
|
||||||
import com.ghy.common.enums.*;
|
import com.ghy.common.enums.*;
|
||||||
import com.ghy.common.utils.StringUtils;
|
|
||||||
import com.ghy.customer.domain.Customer;
|
import com.ghy.customer.domain.Customer;
|
||||||
import com.ghy.customer.domain.CustomerAddress;
|
import com.ghy.customer.domain.CustomerAddress;
|
||||||
import com.ghy.customer.service.CustomerAddressService;
|
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.FinancialChangeRecord;
|
||||||
import com.ghy.payment.domain.FinancialDetail;
|
import com.ghy.payment.domain.FinancialDetail;
|
||||||
import com.ghy.payment.domain.FinancialMaster;
|
import com.ghy.payment.domain.FinancialMaster;
|
||||||
import com.ghy.payment.domain.OrderTimeoutRecord;
|
|
||||||
import com.ghy.payment.service.FinancialChangeRecordService;
|
import com.ghy.payment.service.FinancialChangeRecordService;
|
||||||
import com.ghy.payment.service.FinancialDetailService;
|
import com.ghy.payment.service.FinancialDetailService;
|
||||||
import com.ghy.payment.service.FinancialMasterService;
|
import com.ghy.payment.service.FinancialMasterService;
|
||||||
import com.ghy.payment.service.OrderFineRecordService;
|
|
||||||
import com.ghy.system.domain.SysArea;
|
import com.ghy.system.domain.SysArea;
|
||||||
import com.ghy.system.service.ISysAreaService;
|
import com.ghy.system.service.ISysAreaService;
|
||||||
import com.ghy.system.service.IWxMsgService;
|
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.IWorkerCertificationService;
|
||||||
import com.ghy.worker.service.WorkerService;
|
import com.ghy.worker.service.WorkerService;
|
||||||
import com.huifu.adapay.core.exception.BaseAdaPayException;
|
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.exception.ExceptionUtils;
|
||||||
import org.apache.commons.lang3.time.DateUtils;
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
|
|
@ -70,6 +69,8 @@ public class OrderController extends BaseController {
|
||||||
@Resource
|
@Resource
|
||||||
private CustomerService customerService;
|
private CustomerService customerService;
|
||||||
@Resource
|
@Resource
|
||||||
|
private CustomerAddressService customerAddressService;
|
||||||
|
@Resource
|
||||||
private GoodsService goodsService;
|
private GoodsService goodsService;
|
||||||
@Resource
|
@Resource
|
||||||
private DeptGoodsCategoryService deptGoodsCategoryService;
|
private DeptGoodsCategoryService deptGoodsCategoryService;
|
||||||
|
|
@ -92,8 +93,6 @@ public class OrderController extends BaseController {
|
||||||
@Resource
|
@Resource
|
||||||
private ISysAreaService sysAreaService;
|
private ISysAreaService sysAreaService;
|
||||||
@Resource
|
@Resource
|
||||||
private OrderFineRecordService orderFineRecordService;
|
|
||||||
@Resource
|
|
||||||
private FinancialChangeRecordService financialChangeRecordService;
|
private FinancialChangeRecordService financialChangeRecordService;
|
||||||
@Resource
|
@Resource
|
||||||
private IWorkerCertificationService workerCertificationService;
|
private IWorkerCertificationService workerCertificationService;
|
||||||
|
|
@ -143,6 +142,34 @@ public class OrderController extends BaseController {
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public AjaxResult sysOrder(@RequestBody SysOrderAssignRequest request) {
|
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());
|
request.setGoodsDeptCategoryId(request.getCategory4());
|
||||||
List<Long> ids = new ArrayList<>();
|
List<Long> ids = new ArrayList<>();
|
||||||
ids.add(request.getCategory1());
|
ids.add(request.getCategory1());
|
||||||
|
|
@ -154,10 +181,9 @@ public class OrderController extends BaseController {
|
||||||
OrderTemplateGoods orderTemplateGoods = new OrderTemplateGoods();
|
OrderTemplateGoods orderTemplateGoods = new OrderTemplateGoods();
|
||||||
orderTemplateGoods.setGoodsName(request.getGoodsBrand() + " " + deptGoodsCategory.getGoodsCategoryName());
|
orderTemplateGoods.setGoodsName(request.getGoodsBrand() + " " + deptGoodsCategory.getGoodsCategoryName());
|
||||||
orderTemplateGoods.setDeptGoodsCategoryIds(ids);
|
orderTemplateGoods.setDeptGoodsCategoryIds(ids);
|
||||||
orderTemplateGoods.setDeptGoodsCategoryNames(Arrays.asList(orderTemplateGoods.getGoodsName()));
|
orderTemplateGoods.setDeptGoodsCategoryNames(Collections.singletonList(orderTemplateGoods.getGoodsName()));
|
||||||
request.setGoods(Arrays.asList(orderTemplateGoods));
|
request.setGoods(Collections.singletonList(orderTemplateGoods));
|
||||||
String goodsBrand = request.getGoodsBrand();
|
String goodsBrand = request.getGoodsBrand();
|
||||||
Long deptId = getSysUser().getDeptId();
|
|
||||||
List<OrderTemplateGoods> goodsList = request.getGoods();
|
List<OrderTemplateGoods> goodsList = request.getGoods();
|
||||||
// 订单总价 不能小于0
|
// 订单总价 不能小于0
|
||||||
BigDecimal orderPrice = BigDecimal.valueOf(request.getPrice()).max(BigDecimal.ZERO);
|
BigDecimal orderPrice = BigDecimal.valueOf(request.getPrice()).max(BigDecimal.ZERO);
|
||||||
|
|
@ -205,10 +231,10 @@ public class OrderController extends BaseController {
|
||||||
orderMaster.setCode(orderMasterService.createOrderCode());
|
orderMaster.setCode(orderMasterService.createOrderCode());
|
||||||
orderMaster.setOrderType(0);
|
orderMaster.setOrderType(0);
|
||||||
orderMaster.setOrderStatus(OrderStatus.RECEIVE.code());
|
orderMaster.setOrderStatus(OrderStatus.RECEIVE.code());
|
||||||
orderMaster.setAddressId(request.getAddressId());
|
orderMaster.setAddressId(customerAddress.getCustomerAddressId());
|
||||||
orderMaster.setPayStatus(PayStatus.WAIT_PAY.getCode());
|
orderMaster.setPayStatus(PayStatus.WAIT_PAY.getCode());
|
||||||
orderMaster.setCreateTime(new Date());
|
orderMaster.setCreateTime(new Date());
|
||||||
orderMaster.setWorkerId(goods.getWorkerId());
|
orderMaster.setCustomerId(customer.getCustomerId());
|
||||||
orderMaster.setGoodsId(goods.getGoodsId());
|
orderMaster.setGoodsId(goods.getGoodsId());
|
||||||
orderMasterService.insertOrderMaster(orderMaster);
|
orderMasterService.insertOrderMaster(orderMaster);
|
||||||
Assert.notNull(orderMaster.getId(), "OrderMaster.id is null!");
|
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 {
|
public AjaxResult appOrder(@RequestBody AppOrderRequest appOrderRequest) throws ParseException {
|
||||||
// 校验用户信息
|
// 校验用户信息
|
||||||
Customer customer = customerService.selectByCustomerId(appOrderRequest.getCustomerId());
|
Customer customer = customerService.selectByCustomerId(appOrderRequest.getCustomerId());
|
||||||
if (StringUtils.isNull(customer)) {
|
if (customer == null) {
|
||||||
return AjaxResult.error("用户不存在!");
|
return AjaxResult.error("用户不存在!");
|
||||||
}
|
}
|
||||||
List<AppGoodsRequest> appGoodsList = appOrderRequest.getGoodsList();
|
List<AppGoodsRequest> appGoodsList = appOrderRequest.getGoodsList();
|
||||||
|
|
|
||||||
|
|
@ -50,4 +50,9 @@ public interface CustomerAddressMapper {
|
||||||
*/
|
*/
|
||||||
int updateCustomerAddress(CustomerAddress customerAddress);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,4 +63,5 @@ public interface CustomerMapper {
|
||||||
*/
|
*/
|
||||||
List<Customer> selectByIds(@Param("customerIds") Collection<Long> customerIds);
|
List<Customer> selectByIds(@Param("customerIds") Collection<Long> customerIds);
|
||||||
|
|
||||||
|
Customer selectByAccount(String account);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,4 +49,6 @@ public interface CustomerAddressService {
|
||||||
* @return 修改成功条数
|
* @return 修改成功条数
|
||||||
*/
|
*/
|
||||||
int updateCustomerAddress(CustomerAddress customerAddress);
|
int updateCustomerAddress(CustomerAddress customerAddress);
|
||||||
|
|
||||||
|
CustomerAddress selectByCustomerAndAddress(Long customerId, Long provinceId, Long cityId, Long countryId, String address);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,4 +73,6 @@ public interface CustomerService {
|
||||||
* @return Customer
|
* @return Customer
|
||||||
*/
|
*/
|
||||||
List<Customer> selectByIds(Set<Long> customerIds);
|
List<Customer> selectByIds(Set<Long> customerIds);
|
||||||
|
|
||||||
|
Customer selectByAccount(String account);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,4 +60,9 @@ public class CustomerAddressServiceImpl implements CustomerAddressService {
|
||||||
public int updateCustomerAddress(CustomerAddress customerAddress) {
|
public int updateCustomerAddress(CustomerAddress customerAddress) {
|
||||||
return customerAddressMapper.updateCustomerAddress(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,4 +104,9 @@ public class CustomerServiceImpl implements CustomerService {
|
||||||
}
|
}
|
||||||
return customerMapper.selectByIds(customerIds);
|
return customerMapper.selectByIds(customerIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Customer selectByAccount(String account) {
|
||||||
|
return customerMapper.selectByAccount(account);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,15 @@
|
||||||
WHERE customer_address_id = #{customerAddressId}
|
WHERE customer_address_id = #{customerAddressId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectByCustomerAndAddress" resultMap="CustomerAddressResult">
|
||||||
|
<include refid="selectCustomerAddress"/>
|
||||||
|
WHERE customer_id = #{customerId}
|
||||||
|
AND province_id = #{provinceId}
|
||||||
|
AND city_id = #{cityId}
|
||||||
|
AND country_id = #{countryId}
|
||||||
|
AND address = #{address}
|
||||||
|
</select>
|
||||||
|
|
||||||
<insert id="insertCustomerAddress" parameterType="com.ghy.customer.domain.CustomerAddress" useGeneratedKeys="true" keyProperty="customerAddressId">
|
<insert id="insertCustomerAddress" parameterType="com.ghy.customer.domain.CustomerAddress" useGeneratedKeys="true" keyProperty="customerAddressId">
|
||||||
insert into customer_address(
|
insert into customer_address(
|
||||||
<if test="customerId != null and customerId != 0">customer_id,</if>
|
<if test="customerId != null and customerId != 0">customer_id,</if>
|
||||||
|
|
|
||||||
|
|
@ -146,4 +146,9 @@
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectByAccount" resultMap="CustomerResult">
|
||||||
|
<include refid="selectCustomer" />
|
||||||
|
WHERE account = #{account}
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
|
|
@ -31,4 +31,13 @@ public class SysOrderAssignRequest {
|
||||||
private Long addressId;
|
private Long addressId;
|
||||||
// 发布价格(限制整数)
|
// 发布价格(限制整数)
|
||||||
private Integer price;
|
private Integer price;
|
||||||
|
|
||||||
|
private Long provinceId;
|
||||||
|
|
||||||
|
private Long cityId;
|
||||||
|
|
||||||
|
private Long countryId;
|
||||||
|
|
||||||
|
// 详细地址
|
||||||
|
private String address;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,10 +37,10 @@ public interface SysUserMapper
|
||||||
/**
|
/**
|
||||||
* 通过用户名查询用户
|
* 通过用户名查询用户
|
||||||
*
|
*
|
||||||
* @param userName 用户名
|
* @param loginName 用户名
|
||||||
* @return 用户对象信息
|
* @return 用户对象信息
|
||||||
*/
|
*/
|
||||||
public SysUser selectUserByLoginName(String userName);
|
public SysUser selectUserByLoginName(String loginName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过手机号码查询用户
|
* 通过手机号码查询用户
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,10 @@ public interface ISysUserService
|
||||||
/**
|
/**
|
||||||
* 通过用户名查询用户
|
* 通过用户名查询用户
|
||||||
*
|
*
|
||||||
* @param userName 用户名
|
* @param loginName 用户名
|
||||||
* @return 用户对象信息
|
* @return 用户对象信息
|
||||||
*/
|
*/
|
||||||
public SysUser selectUserByLoginName(String userName);
|
public SysUser selectUserByLoginName(String loginName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过手机号码查询用户
|
* 通过手机号码查询用户
|
||||||
|
|
|
||||||
|
|
@ -105,13 +105,13 @@ public class SysUserServiceImpl implements ISysUserService
|
||||||
/**
|
/**
|
||||||
* 通过用户名查询用户
|
* 通过用户名查询用户
|
||||||
*
|
*
|
||||||
* @param userName 用户名
|
* @param loginName 用户名
|
||||||
* @return 用户对象信息
|
* @return 用户对象信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SysUser selectUserByLoginName(String userName)
|
public SysUser selectUserByLoginName(String loginName)
|
||||||
{
|
{
|
||||||
return userMapper.selectUserByLoginName(userName);
|
return userMapper.selectUserByLoginName(loginName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue