|
|
@@ -14,10 +14,7 @@ import com.google.gson.Gson;
|
|
|
import com.sqx.common.constant.RedisKey;
|
|
|
import com.sqx.common.exception.SqxException;
|
|
|
import com.sqx.common.sms.SmsSendResult;
|
|
|
-import com.sqx.common.utils.DateUtils;
|
|
|
-import com.sqx.common.utils.MyGlobalThreadPool;
|
|
|
-import com.sqx.common.utils.PageUtils;
|
|
|
-import com.sqx.common.utils.Result;
|
|
|
+import com.sqx.common.utils.*;
|
|
|
import com.sqx.modules.address.dao.AddressDao;
|
|
|
import com.sqx.modules.address.entity.Address;
|
|
|
import com.sqx.modules.address.service.AddressService;
|
|
|
@@ -90,7 +87,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.net.URLDecoder;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
@@ -342,8 +342,8 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
|
|
|
tbIndent.setShopId(order.getShopId());
|
|
|
baseMapper.insert(tbIndent);
|
|
|
|
|
|
-
|
|
|
- if (!tbIndent.getIndentState().equals("11")) {
|
|
|
+ log.info("订单类型:"+order.getOrderType()+",跑腿订单状态:"+tbIndent.getIndentState());
|
|
|
+ if (order.getOrderType() == 2 && !"11".equals(tbIndent.getIndentState())) {
|
|
|
// 创建快跑者订单
|
|
|
log.info("第一次创建快跑者订单");
|
|
|
String responseBody = creatSpeedRunnerOrder(order);
|
|
|
@@ -382,6 +382,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public String creatSpeedRunnerOrder(TbOrder tbOrder){
|
|
|
// 获取店铺信息
|
|
|
GoodsShop goodsShop = goodsShopService.getById(tbOrder.getShopId());
|
|
|
@@ -391,34 +392,193 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
for (int i = 0; i < orderGoodsList.size(); i++) {
|
|
|
OrderGoods orderGoods = orderGoodsList.get(i);
|
|
|
- String skuMessage = orderGoods.getSkuMessage();
|
|
|
+ double goodsPrice = orderGoods.getGoodsPrice().doubleValue();
|
|
|
+ Integer goodsNum = orderGoods.getGoodsNum();
|
|
|
String goodsName = orderGoods.getGoodsName();
|
|
|
if (i == 0) {
|
|
|
- stringBuilder.append(goodsName).append(": ").append(skuMessage);
|
|
|
+ stringBuilder.append(goodsName).append("(").append(goodsPrice).append("x").append(goodsNum).append(")");
|
|
|
} else {
|
|
|
- stringBuilder.append(",").append(goodsName).append(":").append(skuMessage);
|
|
|
+ stringBuilder.append(",").append(goodsName).append("(").append(goodsPrice).append("x").append(goodsNum).append(")");
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
// 获取用户收货地址
|
|
|
Address address = addressService.getById(tbOrder.getAddressId());
|
|
|
|
|
|
- com.alibaba.fastjson.JSONObject body = new com.alibaba.fastjson.JSONObject();
|
|
|
- body.put("shop_id", tbOrder.getShopId());
|
|
|
- body.put("shop_name", goodsShop.getShopName());
|
|
|
- body.put("shop_tel", goodsShop.getPhone());
|
|
|
- body.put("shop_address", goodsShop.getDetailedAddress());
|
|
|
- body.put("shop_tag", goodsShop.getShopLng() + "," + goodsShop.getShopLat());
|
|
|
- body.put("order_content", stringBuilder.toString());
|
|
|
- body.put("order_note", tbOrder.getRemark());
|
|
|
- body.put("order_mark", tbOrder.getOrderSequence());
|
|
|
- body.put("order_from", goodsShop.getShopName() + "#" + tbOrder.getOrderSequence());
|
|
|
- body.put("order_time", tbOrder.getPayTime());
|
|
|
- body.put("customer_name", address.getUserName());
|
|
|
- body.put("customer_tel", address.getUserPhone());
|
|
|
- body.put("customer_address", address.getAddressDetail());
|
|
|
- body.put("customer_tag", address.getLng() + "," + address.getLat());
|
|
|
- body.put("order_no", tbOrder.getOrderNumber());
|
|
|
- body.put("order_price", tbOrder.getPayMoney());
|
|
|
+ JSONObject body = new JSONObject();
|
|
|
+ String shopId = tbOrder.getShopId()+"";
|
|
|
+ if (ObjectUtils.isNotEmpty(shopId)) {
|
|
|
+ try {
|
|
|
+ shopId = URLEncoder.encode(shopId, "UTF-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ body.put("shop_id", shopId);
|
|
|
+
|
|
|
+ String shopName = goodsShop.getShopName();
|
|
|
+ if (ObjectUtils.isNotEmpty(shopName)) {
|
|
|
+ try {
|
|
|
+ shopName = URLEncoder.encode(shopName, "UTF-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+// shopName=shopName.replaceAll("\\+","-");
|
|
|
+ }
|
|
|
+ body.put("shop_name", shopName);
|
|
|
+
|
|
|
+ String phone = goodsShop.getPhone();
|
|
|
+ if (ObjectUtils.isNotEmpty(phone)) {
|
|
|
+ try {
|
|
|
+ phone = URLEncoder.encode(phone, "UTF-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ body.put("shop_tel", phone);
|
|
|
+
|
|
|
+
|
|
|
+ String detailedAddress = goodsShop.getDetailedAddress();
|
|
|
+ if (ObjectUtils.isNotEmpty(detailedAddress)) {
|
|
|
+ try {
|
|
|
+ detailedAddress = URLEncoder.encode(detailedAddress, "UTF-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+// detailedAddress=detailedAddress.replaceAll("\\+","-");
|
|
|
+ }
|
|
|
+ body.put("shop_address", detailedAddress);
|
|
|
+
|
|
|
+
|
|
|
+ String shopTag =goodsShop.getShopLng() + "," + goodsShop.getShopLat();
|
|
|
+ if (ObjectUtils.isNotEmpty(detailedAddress)) {
|
|
|
+ try {
|
|
|
+ shopTag = URLEncoder.encode(shopTag, "UTF-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ body.put("shop_tag", shopTag);
|
|
|
+
|
|
|
+
|
|
|
+// 将+变成-
|
|
|
+ String orderContent = stringBuilder.toString();
|
|
|
+ if (ObjectUtils.isNotEmpty(orderContent)) {
|
|
|
+ try {
|
|
|
+ orderContent=orderContent.replaceAll("\\t", " ");
|
|
|
+ orderContent = URLEncoder.encode(orderContent, "UTF-8");
|
|
|
+// orderContent=orderContent.replaceAll("🦆","");
|
|
|
+// orderContent=orderContent.replaceAll("(双拼)","");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+// orderContent=orderContent.replaceAll("\\+","-");
|
|
|
+ }
|
|
|
+ body.put("order_content", orderContent);
|
|
|
+
|
|
|
+
|
|
|
+ String remark = tbOrder.getRemark();
|
|
|
+ if (ObjectUtils.isNotEmpty(remark)) {
|
|
|
+ try {
|
|
|
+ remark=remark.replaceAll("\\r\\n|\\n|\\r", " ");
|
|
|
+ remark = URLEncoder.encode(remark, "UTF-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+// remark=remark.replaceAll("\\+","-");
|
|
|
+ }
|
|
|
+ body.put("order_note", remark);
|
|
|
+
|
|
|
+ String orderSequence = tbOrder.getOrderSequence();
|
|
|
+ if (ObjectUtils.isNotEmpty(orderSequence)) {
|
|
|
+ try {
|
|
|
+ orderSequence =URLEncoder.encode(orderSequence, "UTF-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ body.put("order_mark", orderSequence);
|
|
|
+
|
|
|
+
|
|
|
+ body.put("order_from", shopName+ "#" + orderSequence);
|
|
|
+
|
|
|
+
|
|
|
+ String payTime = tbOrder.getPayTime();
|
|
|
+ if (ObjectUtils.isNotEmpty(payTime)) {
|
|
|
+ try {
|
|
|
+ payTime = URLEncoder.encode(payTime, "UTF-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ body.put("order_time", payTime);
|
|
|
+
|
|
|
+
|
|
|
+ String userName = address.getUserName();
|
|
|
+ if (ObjectUtils.isNotEmpty(userName)) {
|
|
|
+ try {
|
|
|
+ userName = URLEncoder.encode(userName, "UTF-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+// userName=userName.replaceAll("\\+","-");
|
|
|
+ }
|
|
|
+ body.put("customer_name", userName);
|
|
|
+
|
|
|
+ String userPhone = tbOrder.getPhone();
|
|
|
+ if (ObjectUtils.isNotEmpty(userPhone)) {
|
|
|
+ try {
|
|
|
+ userPhone = URLEncoder.encode(userPhone, "UTF-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ body.put("customer_tel", userPhone);
|
|
|
+
|
|
|
+
|
|
|
+ String addressDetail = address.getAddressDetail();
|
|
|
+ if (ObjectUtils.isNotEmpty(addressDetail)) {
|
|
|
+ try {
|
|
|
+ addressDetail = URLEncoder.encode(addressDetail, "UTF-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+// addressDetail=addressDetail.replaceAll("\\+","-");
|
|
|
+ }
|
|
|
+ body.put("customer_address", addressDetail);
|
|
|
+
|
|
|
+
|
|
|
+ String customerTag=address.getLng() + "," + address.getLat();
|
|
|
+ if (ObjectUtils.isNotEmpty(customerTag)) {
|
|
|
+ try {
|
|
|
+ customerTag = URLEncoder.encode(customerTag, "UTF-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ body.put("customer_tag", customerTag);
|
|
|
+
|
|
|
+
|
|
|
+ String orderNumber = tbOrder.getOrderNumber();
|
|
|
+ if (ObjectUtils.isNotEmpty(orderNumber)) {
|
|
|
+ try {
|
|
|
+ orderNumber = URLEncoder.encode(orderNumber, "UTF-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ body.put("order_no", orderNumber);
|
|
|
+
|
|
|
+ String payMoney = tbOrder.getPayMoney().toPlainString();
|
|
|
+ if (ObjectUtils.isNotEmpty(payMoney)) {
|
|
|
+ try {
|
|
|
+ payMoney = URLEncoder.encode(payMoney, "UTF-8");
|
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ body.put("order_price",payMoney);
|
|
|
body.put("pay_status", 0);
|
|
|
|
|
|
log.info("body信息:" + body);
|
|
|
@@ -429,6 +589,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
|
|
|
long currentTimeMillis = System.currentTimeMillis();
|
|
|
long currentTimeSeconds = currentTimeMillis / 1000;
|
|
|
String timestamp = String.valueOf(currentTimeSeconds);
|
|
|
+ log.info("timestamp: "+timestamp);
|
|
|
// 唯一标识符
|
|
|
String ticket = "83f0ff99-7c8e-47e8-8802-bd3754414a52";
|
|
|
// 团队token
|
|
|
@@ -436,8 +597,80 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
|
|
|
// 开发者中心的开发密钥
|
|
|
String devKey = "31RRHA4O165VFN9W2DAPDYDH8N83BT12";
|
|
|
|
|
|
+ JSONObject body2 = new JSONObject();
|
|
|
+// String shopId = tbOrder.getShopId()+"";
|
|
|
+ body2.put("shop_id", tbOrder.getShopId()+"");
|
|
|
+
|
|
|
+// String shopName = goodsShop.getShopName();
|
|
|
+ body2.put("shop_name", goodsShop.getShopName());
|
|
|
+
|
|
|
+// String phone = goodsShop.getPhone();
|
|
|
+ body2.put("shop_tel", goodsShop.getPhone());
|
|
|
+
|
|
|
+// String detailedAddress = goodsShop.getDetailedAddress();
|
|
|
+ body2.put("shop_address", goodsShop.getDetailedAddress());
|
|
|
+
|
|
|
+
|
|
|
+// String shopTag =goodsShop.getShopLng() + "," + goodsShop.getShopLat();
|
|
|
+ body2.put("shop_tag", goodsShop.getShopLng() + "," + goodsShop.getShopLat());
|
|
|
+
|
|
|
+
|
|
|
+// 将+变成-
|
|
|
+ String orderContent2 = stringBuilder.toString();
|
|
|
+ if (ObjectUtils.isNotEmpty(orderContent2)) {
|
|
|
+ orderContent2=orderContent2.replaceAll("\\t", " ");
|
|
|
+ }
|
|
|
+
|
|
|
+ body2.put("order_content", orderContent2);
|
|
|
+
|
|
|
+
|
|
|
+ String remark2 = tbOrder.getRemark();
|
|
|
+ if (ObjectUtils.isNotEmpty(remark2)) {
|
|
|
+ remark2=remark2.replaceAll("\\r\\n|\\n|\\r", " ");
|
|
|
+
|
|
|
+ // 方法2:使用Java 8+的\\R正则表达式;
|
|
|
+ }
|
|
|
+ body2.put("order_note", remark2);
|
|
|
+
|
|
|
+// String orderSequence = tbOrder.getOrderSequence();
|
|
|
+ body2.put("order_mark", tbOrder.getOrderSequence());
|
|
|
+
|
|
|
+
|
|
|
+ body2.put("order_from", goodsShop.getShopName()+ "#" + tbOrder.getOrderSequence());
|
|
|
+
|
|
|
+
|
|
|
+// String payTime = tbOrder.getPayTime();
|
|
|
+
|
|
|
+ body2.put("order_time", tbOrder.getPayTime());
|
|
|
+
|
|
|
+
|
|
|
+// String userName = address.getUserName();
|
|
|
+
|
|
|
+ body2.put("customer_name", address.getUserName());
|
|
|
+
|
|
|
+// String userPhone = address.getUserPhone();
|
|
|
+
|
|
|
+ body2.put("customer_tel", tbOrder.getPhone());
|
|
|
+
|
|
|
+
|
|
|
+// String addressDetail = address.getAddressDetail();
|
|
|
+ body2.put("customer_address", address.getAddressDetail());
|
|
|
+
|
|
|
+
|
|
|
+// String customerTag=address.getLng() + "," + address.getLat();
|
|
|
+ body2.put("customer_tag", address.getLng() + "," + address.getLat());
|
|
|
+
|
|
|
+
|
|
|
+// String orderNumber = tbOrder.getOrderNumber();
|
|
|
+
|
|
|
+ body2.put("order_no", tbOrder.getOrderNumber());
|
|
|
+
|
|
|
+// String payMoney = tbOrder.getPayMoney().toPlainString();
|
|
|
+ body2.put("order_price",tbOrder.getPayMoney().toPlainString());
|
|
|
+ body2.put("pay_status", 0);
|
|
|
+ log.info("body2信息:" + body2);
|
|
|
// 获取签名
|
|
|
- String sign = com.sqx.common.utils.SignUtil.getSign(body.toString(), devKey, teamToken, ticket, currentTimeSeconds, 1);
|
|
|
+ String sign = SignUtil.getSign(body2.toString(), devKey, teamToken, ticket, currentTimeSeconds, 1);
|
|
|
String responseBody="";
|
|
|
try {
|
|
|
log.info("创建快跑者订单");
|
|
|
@@ -445,6 +678,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
|
|
|
// 创建httppost
|
|
|
HttpPost httpPost = new HttpPost("https://open.keloop.cn/open/order/createOrder");
|
|
|
String params = "version=" + version + "×tamp=" + timestamp + "&ticket=" + ticket + "&team_token=" + teamToken + "&dev_key=" + devKey + "&sign=" + sign + "&body=" + body.toString(); // 注意:这里不需要手动编码,HttpClient会处理它。
|
|
|
+ System.out.println("params = " + params);
|
|
|
StringEntity entity = new StringEntity(params, StandardCharsets.UTF_8);
|
|
|
entity.setContentType("application/x-www-form-urlencoded"); // 设置Content-Type为application/x-www-form-urlencoded,但不是必须的,HttpClient会自动设置。
|
|
|
httpPost.setEntity(entity);
|
|
|
@@ -452,6 +686,7 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
|
|
|
log.info("创建结果:"+responseBody);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
+// throw new RuntimeException("responseBody");
|
|
|
}
|
|
|
return responseBody;
|
|
|
}
|
|
|
@@ -1436,7 +1671,27 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
|
|
|
|
|
|
// 判断是否为当前骑手订单
|
|
|
if (!Objects.equals(indentOrder.getRiderUserId(), userId)) {
|
|
|
- throw new SqxException("不能完成非本人订单!");
|
|
|
+// 不为本人则需要调用转单接口
|
|
|
+ log.info("不为接单本人,需转单");
|
|
|
+ log.info("当前骑手id:"+indentOrder.getRiderUserId()+",需要更换的骑手id:"+userId);
|
|
|
+ UserEntity userEntity = userService.getById(userId);
|
|
|
+ indentOrder.setRiderUserId(userEntity.getUserId());
|
|
|
+ indentOrder.setIsRider(1);
|
|
|
+ updateById(indentOrder);
|
|
|
+ log.info("测试是否进入转单3");
|
|
|
+ String format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
|
|
+ TransferRecordEntity tr = new TransferRecordEntity();
|
|
|
+ tr.setUserId(userEntity.getUserId());
|
|
|
+ tr.setUserName(userEntity.getUserName());
|
|
|
+ tr.setUserPhone(userEntity.getPhone());
|
|
|
+ tr.setOrderId(indentOrder.getOrderId());
|
|
|
+ tr.setReceveTime(format);
|
|
|
+ tr.setStationName(userEntity.getStationName());
|
|
|
+ tr.setDeleteFlag(0);
|
|
|
+ log.info("测试是否进入转单4,tr:"+ new Gson().toJson(tr));
|
|
|
+ int insertCount = transferRecordDao.insert(tr);
|
|
|
+ log.info("测试是否进入转单5,insertCount:"+insertCount);
|
|
|
+// throw new SqxException("不能完成非本人订单!");
|
|
|
}
|
|
|
|
|
|
RLock lock = redissonClient.getLock(String.format(RedisKey.UPDATE_INDENT_LOCK, indentOrder.getIndentNumber()));
|
|
|
@@ -1445,9 +1700,9 @@ public class TbIndentServiceImpl extends ServiceImpl<TbIndentDao, TbIndent> impl
|
|
|
indentOrder = tbIndentDao.selectById(indentOrder.getIndentId());
|
|
|
|
|
|
// 4:骑手已取货/购买 只有订单在4状态下才可以完成订单
|
|
|
- if (!"4".equals(indentOrder.getIndentState())) {
|
|
|
- throw new SqxException("订单状态已变更,请刷新页面后重试!");
|
|
|
- }
|
|
|
+// if (!"4".equals(indentOrder.getIndentState())) {
|
|
|
+//// throw new SqxException("订单状态已变更,请刷新页面后重试!");
|
|
|
+//// }
|
|
|
|
|
|
log.info("骑手通过收单码完成订单:订单id【{}】", indentOrder.getOrderId());
|
|
|
appOrderService.accomplishOrder(indentOrder.getOrderId(), 1);
|