Commit 3020ccff by caiyt

调整订单取单号逻辑及微信支付逻辑

parent 7d5256bc
...@@ -8,7 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -8,7 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@RestController @RestController
@RequestMapping("/test") @RequestMapping("/v1")
@Slf4j @Slf4j
public class MachineApiController { public class MachineApiController {
@Autowired @Autowired
......
package com.soss.web.controller.coffee; package com.soss.web.controller.coffee;
import com.alibaba.fastjson.JSONObject;
import com.soss.common.annotation.Log; import com.soss.common.annotation.Log;
import com.soss.common.constant.HttpStatus; import com.soss.common.constant.HttpStatus;
import com.soss.common.core.controller.BaseController; import com.soss.common.core.controller.BaseController;
...@@ -10,6 +11,7 @@ import com.soss.common.enums.BusinessType; ...@@ -10,6 +11,7 @@ import com.soss.common.enums.BusinessType;
import com.soss.common.exception.ServiceException; import com.soss.common.exception.ServiceException;
import com.soss.framework.web.service.TokenService; import com.soss.framework.web.service.TokenService;
import com.soss.framework.web.service.WeixinServiceImpl; import com.soss.framework.web.service.WeixinServiceImpl;
import com.soss.system.constants.OrderStatusConstant;
import com.soss.system.domain.Order; import com.soss.system.domain.Order;
import com.soss.system.domain.vo.CouponVo; import com.soss.system.domain.vo.CouponVo;
import com.soss.system.domain.vo.OrderQuery; import com.soss.system.domain.vo.OrderQuery;
...@@ -19,6 +21,7 @@ import com.soss.system.service.impl.OrderServiceImpl; ...@@ -19,6 +21,7 @@ import com.soss.system.service.impl.OrderServiceImpl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -27,6 +30,7 @@ import javax.servlet.http.HttpServletRequest; ...@@ -27,6 +30,7 @@ import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
/** /**
* 订单Controller * 订单Controller
...@@ -145,6 +149,8 @@ public class OrderController extends BaseController { ...@@ -145,6 +149,8 @@ public class OrderController extends BaseController {
Map payInfo = weixinService.pay(request, "hooloo", order.getOrderNo(), order.getUserId(), amount); Map payInfo = weixinService.pay(request, "hooloo", order.getOrderNo(), order.getUserId(), amount);
if (payInfo != null) { if (payInfo != null) {
payInfo.put("orderId", order.getId()); payInfo.put("orderId", order.getId());
order.setPayParam(JSONObject.toJSONString(payInfo));
orderService.updateById(order);
return AjaxResult.success(payInfo); return AjaxResult.success(payInfo);
} else { } else {
throw new ServiceException("微信支付发生异常"); throw new ServiceException("微信支付发生异常");
...@@ -154,8 +160,14 @@ public class OrderController extends BaseController { ...@@ -154,8 +160,14 @@ public class OrderController extends BaseController {
@RequestMapping("/payOrder") @RequestMapping("/payOrder")
public AjaxResult cancel(HttpServletRequest request, Long orderId) { public AjaxResult cancel(HttpServletRequest request, Long orderId) {
Order order = orderService.selectOrderById(orderId); Order order = orderService.selectOrderById(orderId);
order.setOrderNo(orderService.getOrderNo(order.getSource())); Assert.notNull(order, "order not exists");
orderService.updateOrder(order); Assert.isTrue(Objects.equals(order.getState(), OrderStatusConstant.Unpaid), "订单当前状态不支持该操作");
if (StringUtils.hasText(order.getPayParam())) {
return AjaxResult.success(JSONObject.parseObject(order.getPayParam()));
}
// order.setOrderNo(orderService.getOrderNo(order.getSource()));
// orderService.updateOrder(order);
int amount = order.getPaidAmount().movePointRight(2).intValue(); int amount = order.getPaidAmount().movePointRight(2).intValue();
if (amount == 0) { if (amount == 0) {
return AjaxResult.success(); return AjaxResult.success();
...@@ -182,4 +194,14 @@ public class OrderController extends BaseController { ...@@ -182,4 +194,14 @@ public class OrderController extends BaseController {
public AjaxResult cancel(Long orderId) { public AjaxResult cancel(Long orderId) {
return toAjax(orderService.cancel(orderId)); return toAjax(orderService.cancel(orderId));
} }
@GetMapping("/init/{id}")
public AjaxResult initPickCode(@PathVariable Long id) {
Order order = orderService.selectById(id);
Assert.notNull(order, "order not exists");
String pickCode = weixinService.generatePickCode(order);
order.setPickCode(pickCode);
orderService.updateById(order);
return AjaxResult.success();
}
} }
...@@ -146,6 +146,11 @@ public class Order implements Serializable { ...@@ -146,6 +146,11 @@ public class Order implements Serializable {
private Boolean sendMsgFlag3; private Boolean sendMsgFlag3;
/** /**
* 支付参数
*/
private String payParam;
/**
* 创建时间 * 创建时间
*/ */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
......
...@@ -2,139 +2,31 @@ package com.soss.system.domain.vo.orderTaking; ...@@ -2,139 +2,31 @@ package com.soss.system.domain.vo.orderTaking;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import java.util.List; import java.util.List;
@Data
public class GoodsVo { public class GoodsVo {
private String goodsId; private String goodsId;
private String name; private String name;
private String price; private String price;
public List<SkuVo> getSkus() {
return skus;
}
public void setSkus(List<SkuVo> skus) {
this.skus = skus;
}
private List<SkuVo> skus; private List<SkuVo> skus;
public String getGoodsId() { private String discount;
return goodsId; private String pictures;
} private JSONObject pics;
public void setGoodsId(String goodsId) {
this.goodsId = goodsId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getDiscount() {
return discount;
}
public void setDiscount(String discount) {
this.discount = discount;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getRemarks() {
return remarks;
}
public void setRemarks(String remarks) {
this.remarks = remarks;
}
public List<String> getTags() {
return tags;
}
public void setTags(List<String> tags) {
this.tags = tags;
}
private String discount;
private String pictures;
private JSONObject pics;
public String getPictures() {
return pictures;
}
public void setPictures(String pictures) {
this.pictures = pictures;
}
public JSONArray getSpecs() {
return specs;
}
public void setSpecs(JSONArray specs) {
this.specs = specs;
}
public JSONObject getPics() {
return pics;
}
public String getSpecString() {
return specString;
}
public void setSpecString(String specString) {
this.specString = specString;
}
public void setPics(JSONObject pics) {
this.pics = pics;
}
private String desc; private String desc;
private String remarks; private String remarks;
public String getIsRecommend() {
return isRecommend;
}
public void setIsRecommend(String isRecommend) {
this.isRecommend = isRecommend;
}
private List<String> tags; private List<String> tags;
private JSONArray specs; private JSONArray specs;
private String specString;
private String specString; private String isRecommend;
private String isRecommend; private String category;
} }
...@@ -107,6 +107,10 @@ public class OrderServiceImpl implements IOrderService { ...@@ -107,6 +107,10 @@ public class OrderServiceImpl implements IOrderService {
return orderMapper.selectOrderById(id); return orderMapper.selectOrderById(id);
} }
public void updateById(Order order) {
orderMapper.updateOrder(order);
}
/** /**
* 查询订单列表 * 查询订单列表
* *
...@@ -474,21 +478,22 @@ public class OrderServiceImpl implements IOrderService { ...@@ -474,21 +478,22 @@ public class OrderServiceImpl implements IOrderService {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
String key = calendar.getTime().toString().substring(0, 3); String key = calendar.getTime().toString().substring(0, 3);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String format = simpleDateFormat.format(new Date()); String format = simpleDateFormat.format(calendar.getTime());
String redisKey = "shopId" + format + shopId; String redisKey = "shopId" + format + shopId;
RedisAtomicInteger redisAtomicInteger = new RedisAtomicInteger(redisKey, SpringUtils.getBean(StringRedisTemplate.class).getConnectionFactory()); RedisAtomicInteger redisAtomicInteger = new RedisAtomicInteger(redisKey, SpringUtils.getBean(StringRedisTemplate.class).getConnectionFactory());
if (redisAtomicInteger.get() == 0) { if (redisAtomicInteger.get() == 0) {
redisAtomicInteger.set((int) (1000 * Math.random())); redisAtomicInteger.set((int) (998 * Math.random() + 1));
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
LocalDateTime expireTime = DateUtils.addDaysAndGetBegin(now, 1); LocalDateTime expireTime = DateUtils.addDaysAndGetBegin(now, 1);
long seconds = Duration.between(now, expireTime).getSeconds(); long seconds = Duration.between(now, expireTime).getSeconds();
redisAtomicInteger.expire(seconds, TimeUnit.SECONDS); redisAtomicInteger.expire(seconds, TimeUnit.SECONDS);
} }
int orderNum = redisAtomicInteger.addAndGet(3); int delta = (int) (Math.random() * 8 + 1);
if (orderNum % 999 == 0) { int orderNum = redisAtomicInteger.addAndGet(delta);
orderNum = redisAtomicInteger.addAndGet(1); if (orderNum > 999) {
redisAtomicInteger.set(1);
orderNum = 1;
} }
orderNum %= 999;
return key + String.format("%03d", orderNum); return key + String.format("%03d", orderNum);
} }
...@@ -642,6 +647,7 @@ public class OrderServiceImpl implements IOrderService { ...@@ -642,6 +647,7 @@ public class OrderServiceImpl implements IOrderService {
List<CategoryVo> categorys = infoByShop.getCategorys(); List<CategoryVo> categorys = infoByShop.getCategorys();
List<GoodsVo> ccs = new ArrayList<>(); List<GoodsVo> ccs = new ArrayList<>();
if (categorys != null && !categorys.isEmpty()) { if (categorys != null && !categorys.isEmpty()) {
Set<String> cateAndGoodsIdSet = new HashSet<>();
for (CategoryVo category : categorys) { for (CategoryVo category : categorys) {
if (category.getId() == 0) { if (category.getId() == 0) {
continue; continue;
...@@ -651,6 +657,12 @@ public class OrderServiceImpl implements IOrderService { ...@@ -651,6 +657,12 @@ public class OrderServiceImpl implements IOrderService {
continue; continue;
} }
for (GoodsVo good : goods) { for (GoodsVo good : goods) {
String cateAndGoodsIdStr = good.getCategory() + good.getGoodsId();
if(cateAndGoodsIdSet.contains(cateAndGoodsIdStr)) {
continue;
} else {
cateAndGoodsIdSet.add(cateAndGoodsIdStr);
}
List<SkuVo> skuVoList = new ArrayList<>(); List<SkuVo> skuVoList = new ArrayList<>();
if (good.getSkus() == null || good.getSkus().isEmpty()) { if (good.getSkus() == null || good.getSkus().isEmpty()) {
continue; continue;
......
...@@ -174,6 +174,7 @@ public class OrderTakingServiceImpl { ...@@ -174,6 +174,7 @@ public class OrderTakingServiceImpl {
goodsVo.setPics(JSONObject.parseObject(good.getPics())); goodsVo.setPics(JSONObject.parseObject(good.getPics()));
goodsVo.setRemarks(good.getRemarks()); goodsVo.setRemarks(good.getRemarks());
goodsVo.setSpecs(buildGoodsSpec(good.getSpec())); goodsVo.setSpecs(buildGoodsSpec(good.getSpec()));
goodsVo.setCategory(good.getCategory());
goodsVo.setSpecString(null); goodsVo.setSpecString(null);
if(recommendGoodsId.contains(String.valueOf(good.getId()))){ if(recommendGoodsId.contains(String.valueOf(good.getId()))){
goodsVo.setIsRecommend("1"); goodsVo.setIsRecommend("1");
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
<result property="sendMsgFlag1" column="send_msg_flag1"/> <result property="sendMsgFlag1" column="send_msg_flag1"/>
<result property="sendMsgFlag2" column="send_msg_flag2"/> <result property="sendMsgFlag2" column="send_msg_flag2"/>
<result property="sendMsgFlag3" column="send_msg_flag3"/> <result property="sendMsgFlag3" column="send_msg_flag3"/>
<result property="payParam" column="pay_param"/>
<result property="createdAt" column="created_at"/> <result property="createdAt" column="created_at"/>
<result property="updatedAt" column="updated_at"/> <result property="updatedAt" column="updated_at"/>
</resultMap> </resultMap>
...@@ -61,6 +62,7 @@ ...@@ -61,6 +62,7 @@
<if test="sendMsgFlag1 != null">and send_msg_flag1 = #{sendMsgFlag1}</if> <if test="sendMsgFlag1 != null">and send_msg_flag1 = #{sendMsgFlag1}</if>
<if test="sendMsgFlag2 != null">and send_msg_flag2 = #{sendMsgFlag2}</if> <if test="sendMsgFlag2 != null">and send_msg_flag2 = #{sendMsgFlag2}</if>
<if test="sendMsgFlag3 != null">and send_msg_flag3 = #{sendMsgFlag3}</if> <if test="sendMsgFlag3 != null">and send_msg_flag3 = #{sendMsgFlag3}</if>
<if test="payParam != null">and pay_param = #{payParam}</if>
<if test="createdAt != null ">and created_at = #{createdAt}</if> <if test="createdAt != null ">and created_at = #{createdAt}</if>
<if test="updatedAt != null ">and updated_at = #{updatedAt}</if> <if test="updatedAt != null ">and updated_at = #{updatedAt}</if>
...@@ -97,6 +99,7 @@ ...@@ -97,6 +99,7 @@
<if test="sendMsgFlag1 != null">send_msg_flag1,</if> <if test="sendMsgFlag1 != null">send_msg_flag1,</if>
<if test="sendMsgFlag2 != null">send_msg_flag2,</if> <if test="sendMsgFlag2 != null">send_msg_flag2,</if>
<if test="sendMsgFlag3 != null">send_msg_flag3,</if> <if test="sendMsgFlag3 != null">send_msg_flag3,</if>
<if test="payParam != null">pay_param,</if>
<if test="createdAt != null">created_at,</if> <if test="createdAt != null">created_at,</if>
<if test="updatedAt != null">updated_at,</if> <if test="updatedAt != null">updated_at,</if>
</trim> </trim>
...@@ -123,6 +126,7 @@ ...@@ -123,6 +126,7 @@
<if test="sendMsgFlag1 != null">#{sendMsgFlag1},</if> <if test="sendMsgFlag1 != null">#{sendMsgFlag1},</if>
<if test="sendMsgFlag2 != null">#{sendMsgFlag2},</if> <if test="sendMsgFlag2 != null">#{sendMsgFlag2},</if>
<if test="sendMsgFlag3 != null">#{sendMsgFlag3},</if> <if test="sendMsgFlag3 != null">#{sendMsgFlag3},</if>
<if test="payParam != null">#{pay_param},</if>
<if test="createdAt != null">#{createdAt},</if> <if test="createdAt != null">#{createdAt},</if>
<if test="updatedAt != null">#{updatedAt},</if> <if test="updatedAt != null">#{updatedAt},</if>
</trim> </trim>
...@@ -153,6 +157,7 @@ ...@@ -153,6 +157,7 @@
<if test="sendMsgFlag1 != null">send_msg_flag1 = #{sendMsgFlag1},</if> <if test="sendMsgFlag1 != null">send_msg_flag1 = #{sendMsgFlag1},</if>
<if test="sendMsgFlag2 != null">send_msg_flag2 = #{sendMsgFlag2},</if> <if test="sendMsgFlag2 != null">send_msg_flag2 = #{sendMsgFlag2},</if>
<if test="sendMsgFlag3 != null">send_msg_flag3 = #{sendMsgFlag3},</if> <if test="sendMsgFlag3 != null">send_msg_flag3 = #{sendMsgFlag3},</if>
<if test="payParam != null">pay_param = #{payParam},</if>
<if test="updatedAt != null">updated_at = #{updatedAt},</if> <if test="updatedAt != null">updated_at = #{updatedAt},</if>
</trim> </trim>
where id = #{id} where id = #{id}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment