|
|
@@ -16,6 +16,8 @@
|
|
|
*/
|
|
|
package org.springblade.salesPart.ship.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
@@ -28,13 +30,18 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
|
|
|
+import okhttp3.*;
|
|
|
import org.springblade.client.entity.Message;
|
|
|
import org.springblade.client.feign.IMessageClient;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.jackson.JsonUtil;
|
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
+import org.springblade.pay.tonglianPayment.entity.Parameters;
|
|
|
+import org.springblade.pay.tonglianPayment.fegin.ITongLianPaymentClient;
|
|
|
+import org.springblade.salesPart.corps.service.ICorpsAttnService;
|
|
|
import org.springblade.salesPart.entity.*;
|
|
|
import org.springblade.salesPart.enums.OrderTypeEnum;
|
|
|
import org.springblade.salesPart.excel.PjShipStockDetails;
|
|
|
@@ -73,6 +80,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.lang.reflect.Method;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.MathContext;
|
|
|
@@ -121,6 +129,10 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
|
|
|
private final IShipItemsRecordService shipItemsRecordService;
|
|
|
|
|
|
+ private final ITongLianPaymentClient parametersService;
|
|
|
+
|
|
|
+ private final ICorpsAttnService corpsAttnService;
|
|
|
+
|
|
|
/**
|
|
|
* 获取收发货订单详情
|
|
|
*
|
|
|
@@ -4918,4 +4930,107 @@ public class ShipServiceImpl extends ServiceImpl<ShipMapper, PjShip> implements
|
|
|
return R.data(ship);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R shippingNotice(PjShip ship) {
|
|
|
+ PjShip shipVersion = baseMapper.selectById(ship.getId());
|
|
|
+ if (shipVersion != null && !shipVersion.getVersion().equals(ship.getVersion())) {
|
|
|
+ throw new RuntimeException("数据已被修改,请返回列表重新操作!");
|
|
|
+ }
|
|
|
+ ship.setVersion(ship.getVersion() + 1);
|
|
|
+ ship.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ ship.setUpdateTime(new Date());
|
|
|
+ ship.setWhetherShippingNotice("1");
|
|
|
+ baseMapper.updateById(ship);
|
|
|
+ Parameters parameters = parametersService.getParametersOne();
|
|
|
+ if (ObjectUtils.isNull(parameters)) {
|
|
|
+ throw new SecurityException("未找到小程序信息");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNull(parameters.getAppSecret())) {
|
|
|
+ throw new SecurityException("未找到小程序秘钥");
|
|
|
+ }
|
|
|
+ String appIds = parameters.getSubAppid();
|
|
|
+ String appSecrets = parameters.getAppSecret();
|
|
|
+ OkHttpClient client = new OkHttpClient();
|
|
|
+ //获得token
|
|
|
+
|
|
|
+ Request request = new Request.Builder().url("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appIds + "&secret=" + appSecrets + "").build();
|
|
|
+ try {
|
|
|
+ Response responseToken = client.newCall(request).execute();
|
|
|
+ //如果请求成功,解析数据
|
|
|
+ if (responseToken.isSuccessful()) {
|
|
|
+ String body = responseToken.body().string();
|
|
|
+ //得到一个JSON对象
|
|
|
+ JSONObject object = JSON.parseObject(body);
|
|
|
+ String accessToken = object.getString("access_token");
|
|
|
+ if (ObjectUtils.isNotNull(accessToken)) {
|
|
|
+ Map<String, Object> map1 = new HashMap<>();
|
|
|
+ map1.put("logistics_type", "4");
|
|
|
+ map1.put("delivery_mode", "UNIFIED_DELIVERY");
|
|
|
+ map1.put("is_all_delivered", "");
|
|
|
+ map1.put("upload_time", new Date());
|
|
|
+ PjCorpsAttn attn = corpsAttnService.getOne(new LambdaQueryWrapper<PjCorpsAttn>()
|
|
|
+ .eq(PjCorpsAttn::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PjCorpsAttn::getIsDeleted, 0)
|
|
|
+ .eq(PjCorpsAttn::getPid, ship.getCustomerId()));
|
|
|
+ if (attn == null || ObjectUtils.isNull(attn.getUserId())) {
|
|
|
+ throw new RuntimeException("未找到客户联系人信息");
|
|
|
+ }
|
|
|
+ R<User> res = userClient.userInfoById(attn.getUserId());
|
|
|
+ if (!res.isSuccess()) {
|
|
|
+ throw new RuntimeException("未找到客户联系人对应用户信息");
|
|
|
+ }
|
|
|
+ Map<String, String> mapUser = new HashMap<>();
|
|
|
+ mapUser.put("openid", res.getData().getOpenId());
|
|
|
+ map1.put("payer", mapUser);
|
|
|
+ Map<String, Object> mapGoods = new HashMap<>();
|
|
|
+ mapGoods.put("item_desc", ship.getGoodsNames());
|
|
|
+ map1.put("shipping_list", mapGoods);
|
|
|
+ Map<String, Object> mapOrder = new HashMap<>();
|
|
|
+ mapOrder.put("order_number_type", 1);
|
|
|
+ mapOrder.put("mchid", parameters.getMerchantId());
|
|
|
+ map1.put("order_key", mapOrder);
|
|
|
+ //发送发货通知
|
|
|
+ Request requestShip = new Request.Builder()
|
|
|
+ .url("https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token=" + accessToken)
|
|
|
+ .method("post", RequestBody.create(MediaType.parse("application/json; charset=utf-8"), JsonUtil.toJson(map1)))
|
|
|
+ .post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), JsonUtil.toJson(map1)))
|
|
|
+ .build();
|
|
|
+ try {
|
|
|
+ Response responsePhone = client.newCall(requestShip).execute();
|
|
|
+ //如果请求成功,解析数据
|
|
|
+ if (responsePhone.isSuccessful()) {
|
|
|
+ String bodyShip = responsePhone.body().string();
|
|
|
+ //得到一个JSON对象
|
|
|
+ JSONObject objectShip = JSON.parseObject(bodyShip);
|
|
|
+ if (objectShip.getString("errcode").equals("0")) {
|
|
|
+ String status = objectShip.getString("errmsg");
|
|
|
+ if ("ok".equals(status)) {
|
|
|
+ return R.data("操作成功");
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("发送失败");
|
|
|
+ }
|
|
|
+ } else if (object.getString("errcode").equals("-1")) {
|
|
|
+ throw new RuntimeException("系统繁忙,此时请开发者稍候再试");
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("发送失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("发送失败");
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("access_token获取失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("发送失败");
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return R.data("操作成功");
|
|
|
+ }
|
|
|
+
|
|
|
}
|