|
@@ -22,6 +22,7 @@ import com.github.pagehelper.PageInfo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
@@ -635,7 +636,93 @@ public class ShipServiceImpl implements ShipService {
|
|
|
return ResponseJson.success(null);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 小程序分享发货-分享权限控制
|
|
|
+ *
|
|
|
+ * @param source 来源:1:客服扫码,2:供应商运营人员查看,3:分享码查看
|
|
|
+ * @param shopOrderId 子订单Id
|
|
|
+ * @param shareCode 分享码
|
|
|
+ * @param code 微信code
|
|
|
+ * @param encryptedData 微信加密数据
|
|
|
+ * @param iv 微信加密算法的初始向量
|
|
|
+ * @param headers HttpHeaders
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<Map<String, Object>> checkShipShareCode(Integer source, Integer shopOrderId, String shareCode, String code, String encryptedData, String iv, HttpHeaders headers) {
|
|
|
+ // 微信小程序授权登录(调用user服务,发送服务间调用POST请求)
|
|
|
+ String loginData = remoteCallService.appletsAuthorization(code, encryptedData, iv, headers);
|
|
|
+ if (StringUtils.isEmpty(loginData)){
|
|
|
+ return ResponseJson.error("微信授权登录异常!", null);
|
|
|
+ }
|
|
|
+ // 解析登录后得到 userIdentity, openId等
|
|
|
+ JSONObject userInfo = JSONObject.parseObject(loginData);
|
|
|
+ String openId = userInfo.getString("openId");
|
|
|
+ if (StringUtils.isEmpty(openId)) {
|
|
|
+ return ResponseJson.error("微信授权登录异常!", null);
|
|
|
+ }
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ resultMap.put("shopOrderId", shopOrderId);
|
|
|
+ if (1 == source) {
|
|
|
+ // 客服扫码进入
|
|
|
+ String name = shipMapper.getConsignmentName(openId);
|
|
|
+ if (StringUtils.isBlank(name)) {
|
|
|
+ return ResponseJson.error("暂无权限查看", null);
|
|
|
+ }
|
|
|
+ log.info("小程序发货,客服登入>>>>>>" + name);
|
|
|
+ resultMap.put("resultCode", 1);
|
|
|
+ return ResponseJson.success("客服权限", resultMap);
|
|
|
+ }
|
|
|
+ // 用户身份: 1协销 2会员机构 3供应商 4普通机构
|
|
|
+ Integer userIdentity = userInfo.getInteger("userIdentity");
|
|
|
+ Integer loginShopId = userInfo.getInteger("shopId");
|
|
|
+ // 供应商身份
|
|
|
+ boolean shopFlag = (null != userIdentity && 3 == userIdentity);
|
|
|
+ // 子订单所属供应商Id
|
|
|
+ Integer dbShopId = shipMapper.getShopIdByShopOrderId(shopOrderId);
|
|
|
+ if (shopFlag && loginShopId.equals(dbShopId)) {
|
|
|
+ // 供应商进入
|
|
|
+ resultMap.put("resultCode", 2);
|
|
|
+ return ResponseJson.success("供应商运营人员权限", resultMap);
|
|
|
+ }
|
|
|
+ if (2 == source) {
|
|
|
+ resultMap.put("resultCode", 2);
|
|
|
+ Integer loginUserId = userInfo.getInteger("userId");
|
|
|
+ String unionId = userInfo.getString("unionId");
|
|
|
+ resultMap.put("shopId", loginShopId);
|
|
|
+ resultMap.put("openid", openId);
|
|
|
+ resultMap.put("unionId", unionId);
|
|
|
+ resultMap.put("userId", loginUserId);
|
|
|
+ return ResponseJson.error(-1, "绑定供应商运营人员", resultMap);
|
|
|
+ } else {
|
|
|
+ // 分享码进入
|
|
|
+ resultMap.put("resultCode", 3);
|
|
|
+ // 获取采美供应商发货分享码使用记录
|
|
|
+ Integer shareCodeRecordId = shipMapper.getConsignmentShareRecordId(openId, shopOrderId);
|
|
|
+ if (null != shareCodeRecordId && shareCodeRecordId > 0) {
|
|
|
+ return ResponseJson.success("分享码人员权限", resultMap);
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(shareCode)) {
|
|
|
+ return ResponseJson.error("请联系分享人获取分享码", null);
|
|
|
+ }
|
|
|
+ OrderShareCodeVo orderCodeVo = shipMapper.getConsignmentShare(shareCode, shopOrderId);
|
|
|
+ Date date = new Date();
|
|
|
+ if (null == orderCodeVo) {
|
|
|
+ return ResponseJson.error("分享码错误", null);
|
|
|
+ } else if (orderCodeVo.getExpiredTime().compareTo(date) < 0) {
|
|
|
+ return ResponseJson.error("分享码已失效", null);
|
|
|
+ } else {
|
|
|
+ // 分享码有效, 保存分享码使用记录
|
|
|
+ OrderShareCodeRecordVo codeRecord = new OrderShareCodeRecordVo();
|
|
|
+ codeRecord.setOpenId(openId);
|
|
|
+ codeRecord.setAddTime(date);
|
|
|
+ codeRecord.setOrderId(shopOrderId);
|
|
|
+ codeRecord.setDelFlag(0);
|
|
|
+ codeRecord.setShareCodeId(orderCodeVo.getId());
|
|
|
+ shipMapper.insertConsignmentShareRecord(codeRecord);
|
|
|
+ return ResponseJson.success("分享码人员权限", resultMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|