Merge remote-tracking branch 'origin/master'

This commit is contained in:
kuang.yife 2023-05-20 23:49:02 +08:00
commit f7cca0de02
23 changed files with 142 additions and 34 deletions

View File

@ -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<Long> 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<OrderTemplateGoods> 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<AppGoodsRequest> appGoodsList = appOrderRequest.getGoodsList();

View File

@ -39,6 +39,7 @@ public class OrderGoodsController extends BaseController {
@GetMapping()
public String orderGoods(Long orderId, ModelMap mmap) {
OrderMaster orderMaster = orderMasterService.selectById(orderId);
mmap.put("orderId", orderId);
mmap.put("orderMaster", orderMaster);
return prefix;
}

View File

@ -74,6 +74,8 @@ public class AdapaySyncTimer {
String orderNo = AdapayUtils.createOrderNo(AdapayOrderType.DRAW_CASH);
JSONObject drawCash = adapayService.drawCash(deptId, orderNo, "T1", avlBalance, memberId, "提现", null);
log.info("Worker[{},{}]提现结果: {}", workerBank.getWorkerId(), workerBank.getName(), drawCash.toJSONString());
} else {
log.error("Worker[{},{}]查询账户余额失败: {}", workerBank.getWorkerId(), workerBank.getName(), accountBalance.toJSONString());
}
} catch (BaseAdaPayException e) {
log.error(e.getMessage(), e);
@ -101,6 +103,8 @@ public class AdapaySyncTimer {
String orderNo = AdapayUtils.createOrderNo(AdapayOrderType.DRAW_CASH);
JSONObject drawCash = adapayService.drawCash(deptId, orderNo, "T1", avlBalance, memberId, "提现", null);
log.info("Customer[{},{}]提现结果: {}", customer.getCustomerId(), customer.getName(), drawCash.toJSONString());
} else {
log.error("Customer[{},{}]查询账户余额失败: {}", customer.getCustomerId(), customer.getName(), accountBalance.toJSONString());
}
} catch (BaseAdaPayException e) {
log.error(e.getMessage(), e);
@ -108,6 +112,9 @@ public class AdapaySyncTimer {
}
}
/**
* 定时同步提现状态
*/
@Scheduled(fixedRate = 5 * 60 * 1000L)
public void syncDrawCash() {
List<DrawCashRecord> records = drawCashRecordMapper.selectByStatus("pending");
@ -147,7 +154,7 @@ public class AdapaySyncTimer {
// 更新提现记录表状态
drawCashRecordMapper.updateStatus(record.getId(), "succeeded");
// 更新子订单表状态
orderDetailService.updateDrawCashStatus(record.getId(), 2, new Date());
orderDetailService.updateDrawCashStatus(record.getId(), 2, null, new Date());
break;
// 提现失败
case "F":
@ -155,7 +162,7 @@ public class AdapaySyncTimer {
// 更新提现记录表状态
drawCashRecordMapper.updateStatus(record.getId(), "failed");
// 更新子订单表状态
orderDetailService.updateDrawCashStatus(record.getId(), -1, null);
orderDetailService.updateDrawCashStatus(record.getId(), -1, null, null);
break;
default:
break;

View File

@ -13,7 +13,7 @@
<div class="row">
<div class="col-sm-12 search-collapse">
<form id="order-goods-form">
<input type="hidden" id="orderId" name="orderId" th:value="${orderMaster.id}">
<!-- <input type="hidden" id="orderId" name="orderId" th:value="${orderMaster.id}">-->
</form>
</div>
<div class="col-sm-12 select-table table-striped">
@ -50,7 +50,7 @@
function queryOrderGoodsList() {
var options = {
url: prefix + "/list",
url: prefix + "/list?orderDetailId=" + orderId,
modalName: "订单商品",
search: false,
showSearch: false,

View File

@ -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);
}

View File

@ -63,4 +63,5 @@ public interface CustomerMapper {
*/
List<Customer> selectByIds(@Param("customerIds") Collection<Long> customerIds);
Customer selectByAccount(String account);
}

View File

@ -49,4 +49,6 @@ public interface CustomerAddressService {
* @return 修改成功条数
*/
int updateCustomerAddress(CustomerAddress customerAddress);
CustomerAddress selectByCustomerAndAddress(Long customerId, Long provinceId, Long cityId, Long countryId, String address);
}

View File

@ -73,4 +73,6 @@ public interface CustomerService {
* @return Customer
*/
List<Customer> selectByIds(Set<Long> customerIds);
Customer selectByAccount(String account);
}

View File

@ -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);
}
}

View File

@ -104,4 +104,9 @@ public class CustomerServiceImpl implements CustomerService {
}
return customerMapper.selectByIds(customerIds);
}
@Override
public Customer selectByAccount(String account) {
return customerMapper.selectByAccount(account);
}
}

View File

@ -62,6 +62,15 @@
WHERE customer_address_id = #{customerAddressId}
</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 into customer_address(
<if test="customerId != null and customerId != 0">customer_id,</if>

View File

@ -146,4 +146,9 @@
</where>
</select>
<select id="selectByAccount" resultMap="CustomerResult">
<include refid="selectCustomer" />
WHERE account = #{account}
</select>
</mapper>

View File

@ -106,10 +106,12 @@ public interface OrderDetailMapper {
*
* @param drawCashId 发起提现后Adapay返回的对象ID
* @param drawCashStatus 提现状态见{@link OrderDetail#getDrawCashStatus()}
* @param drawCashTime 发起提现时间
* @param arrivalTime 提现到账时间
* @return 1
*/
int updateDrawCashStatus(@Param("drawCashId") String drawCashId, @Param("drawCashStatus") int drawCashStatus, @Param("arrivalTime") Date arrivalTime);
int updateDrawCashStatus(@Param("drawCashId") String drawCashId, @Param("drawCashStatus") int drawCashStatus,
@Param("drawCashTime") Date drawCashTime, @Param("arrivalTime") Date arrivalTime);
int deleteByMaster(Long masterId);
}

View File

@ -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;
}

View File

@ -143,10 +143,11 @@ public interface OrderDetailService {
*
* @param drawCashId 发起提现后Adapay返回的对象ID
* @param drawCashStatus 提现状态见{@link OrderDetail#getDrawCashStatus()}
* @param drawCashTime 发起提现时间
* @param arrivalTime 提现到账时间
* @return 1
*/
int updateDrawCashStatus(String drawCashId, int drawCashStatus, Date arrivalTime);
int updateDrawCashStatus(String drawCashId, int drawCashStatus, Date drawCashTime, Date arrivalTime);
/**
* 退款成功时 退款回调接口里会调用这个方法

View File

@ -746,8 +746,8 @@ public class OrderDetailServiceImpl implements OrderDetailService {
}
@Override
public int updateDrawCashStatus(String drawCashId, int drawCashStatus, Date arrivalTime) {
return orderDetailMapper.updateDrawCashStatus(drawCashId, drawCashStatus, arrivalTime);
public int updateDrawCashStatus(String drawCashId, int drawCashStatus, Date drawCashTime, Date arrivalTime) {
return orderDetailMapper.updateDrawCashStatus(drawCashId, drawCashStatus, drawCashTime, arrivalTime);
}
@Override

View File

@ -254,12 +254,14 @@ public class OrderMasterServiceImpl implements OrderMasterService {
}
}
// 大师傅的MemberId
String masterWorkerMemberId = AdapayUtils.getWorkerMemberId(orderMaster.getWorkerId(), orderMaster.getDeptId());
// 罚金分给平台账户
memberMap.merge("0", fineMoney, BigDecimal::add);
// 大师傅服务金额减去罚金后剩下的钱 如果小于等于0元 就不用分账给大师傅了
BigDecimal bigWorkerAmtSubtractFine = bigWorkerAmt.subtract(fineMoney);
if (BigDecimal.ZERO.compareTo(bigWorkerAmtSubtractFine) < 0) {
memberMap.put(AdapayUtils.getWorkerMemberId(orderMaster.getWorkerId(), orderMaster.getDeptId()), bigWorkerAmtSubtractFine);
memberMap.put(masterWorkerMemberId, bigWorkerAmtSubtractFine);
}
confirmAmt = confirmAmt.add(bigWorkerAmt);
@ -307,7 +309,24 @@ public class OrderMasterServiceImpl implements OrderMasterService {
}
String amount = member.getAmount();
try {
drawCash(orderMaster.getDeptId(), memberId, amount);
String drawCashId = drawCash(orderMaster.getDeptId(), memberId, amount);
// 判断是否为大师傅的提现
if (masterWorkerMemberId.equals(memberId)) {
// 给大师傅的子单设置提现状态和提现时间 丢到线程池里执行 避免影响原业务逻辑 2023/5/18
executor.execute(() -> {
for (OrderDetail orderDetail : orderDetails) {
if (orderMaster.getWorkerId().equals(orderDetail.getWorkerId())) {
OrderDetail odUpdate = new OrderDetail();
odUpdate.setId(orderDetail.getId());
odUpdate.setDrawCashTime(new Date());
odUpdate.setDrawCashStatus(1);
odUpdate.setDrawCashId(drawCashId);
orderDetailService.updateOrderDetail(odUpdate);
}
}
});
}
} catch (BaseAdaPayException e) {
logger.error("自动发起提现失败: orderMasterId={}, memberId={}, cashAmt={}", orderMasterId, memberId, amount, e);
}
@ -321,15 +340,18 @@ public class OrderMasterServiceImpl implements OrderMasterService {
* @param memberId Adapay实名账户ID
* @param amount 提现金额
*/
private void drawCash(Long deptId, String memberId, String amount) throws BaseAdaPayException {
private String drawCash(Long deptId, String memberId, String amount) throws BaseAdaPayException {
String orderNo = AdapayUtils.createOrderNo(AdapayOrderType.DRAW_CASH);
JSONObject response = adapayService.drawCash(deptId, orderNo, "T1", amount, memberId, "订单结算", null);
boolean status = AdapayStatusEnum.pending.code.equals(response.getString("status")) ||
AdapayStatusEnum.succeeded.code.equals(response.getString("status"));
if (!status) {
if (status) {
return response.getString("id");
} else {
//如果提现失败 把信息记录到error日志里
logger.error("提现失败: deptId={}, memberId={}, amount={}, 失败原因:{}", deptId, memberId, amount, response.getString("error_msg"));
return null;
}
}

View File

@ -392,9 +392,12 @@
</select>
<update id="updateDrawCashStatus">
UPDATE order_detail
SET draw_cash_status = #{drawCashStatus},
arrival_time = #{arrivalTime}
UPDATE order_detail SET
<if test="drawCashId != null">draw_cash_id = #{drawCashId},</if>
<if test="drawCashTime != null">draw_cash_time = #{drawCashTime},</if>
<if test="arrivalTime != null">arrival_time = #{arrivalTime},</if>
<if test="drawCashStatus != null">draw_cash_status = #{drawCashStatus},</if>
update_time = NOW()
WHERE draw_cash_id = #{drawCashId}
</update>
</mapper>

View File

@ -72,6 +72,9 @@
<if test="orderId != null and orderId != 0">
AND order_id = #{orderId}
</if>
<if test="orderDetailId != null and orderDetailId != 0">
AND order_detail_id = #{orderDetailId}
</if>
<if test="goodsStandardId != null and goodsStandardId != 0">
AND goods_standard_id = #{goodsStandardId}
</if>

View File

@ -183,7 +183,7 @@
SELECT COUNT(*) FROM order_master om
<where>
<if test="isMonitoredOrder">
AND (om.all_self_assigned = 0 or om.all_self_assigned is not null) AND om.order_status in (1,2,3,4)
AND (om.all_self_assigned = 0 or om.all_self_assigned is null) AND om.order_status in (1,2,3,4)
</if>
<if test="deptId != null and deptId != 0">
AND om.dept_id = #{deptId}

View File

@ -37,10 +37,10 @@ public interface SysUserMapper
/**
* 通过用户名查询用户
*
* @param userName 用户名
* @param loginName 用户名
* @return 用户对象信息
*/
public SysUser selectUserByLoginName(String userName);
public SysUser selectUserByLoginName(String loginName);
/**
* 通过手机号码查询用户

View File

@ -38,10 +38,10 @@ public interface ISysUserService
/**
* 通过用户名查询用户
*
* @param userName 用户名
* @param loginName 用户名
* @return 用户对象信息
*/
public SysUser selectUserByLoginName(String userName);
public SysUser selectUserByLoginName(String loginName);
/**
* 通过手机号码查询用户

View File

@ -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);
}
/**