|
@@ -3,8 +3,16 @@ package com.fs.app.controller;
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONArray;
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fs.app.annotation.Login;
|
|
import com.fs.app.annotation.Login;
|
|
|
import com.fs.common.core.domain.R;
|
|
import com.fs.common.core.domain.R;
|
|
|
|
|
+import com.fs.common.core.redis.RedisCache;
|
|
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
|
|
+import com.fs.common.utils.http.HttpUtils;
|
|
|
|
|
+import com.fs.company.domain.Company;
|
|
|
|
|
+import com.fs.company.domain.CompanyUser;
|
|
|
|
|
+import com.fs.company.service.ICompanyService;
|
|
|
|
|
+import com.fs.company.service.ICompanyUserService;
|
|
|
import com.fs.store.domain.FsStoreProduct;
|
|
import com.fs.store.domain.FsStoreProduct;
|
|
|
import com.fs.store.domain.FsStoreProductAttrValue;
|
|
import com.fs.store.domain.FsStoreProductAttrValue;
|
|
|
import com.fs.store.domain.FsStoreProductPackage;
|
|
import com.fs.store.domain.FsStoreProductPackage;
|
|
@@ -13,14 +21,19 @@ import com.fs.store.dto.StorePackageProductDTO;
|
|
|
import com.fs.store.param.FsStoreProductPackageQueryParam;
|
|
import com.fs.store.param.FsStoreProductPackageQueryParam;
|
|
|
import com.fs.store.service.IFsStoreProductAttrValueService;
|
|
import com.fs.store.service.IFsStoreProductAttrValueService;
|
|
|
import com.fs.store.service.IFsStoreProductPackageService;
|
|
import com.fs.store.service.IFsStoreProductPackageService;
|
|
|
|
|
+import com.fs.store.service.IFsStoreProductPackageUniqueCodeService;
|
|
|
import com.fs.store.service.IFsStoreProductService;
|
|
import com.fs.store.service.IFsStoreProductService;
|
|
|
import com.fs.store.vo.FsStoreProductPacketVO;
|
|
import com.fs.store.vo.FsStoreProductPacketVO;
|
|
|
|
|
+import com.fs.wx.miniapp.config.WxMaProperties;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
@@ -35,12 +48,24 @@ import java.util.List;
|
|
|
@RequestMapping(value="/app/storeProductPackage")
|
|
@RequestMapping(value="/app/storeProductPackage")
|
|
|
public class StoreProductPackageController extends AppBaseController {
|
|
public class StoreProductPackageController extends AppBaseController {
|
|
|
|
|
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(StoreProductPackageController.class);
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IFsStoreProductPackageService productPackageService;
|
|
private IFsStoreProductPackageService productPackageService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IFsStoreProductAttrValueService attrValueService;
|
|
private IFsStoreProductAttrValueService attrValueService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private IFsStoreProductService storeProductService;
|
|
private IFsStoreProductService storeProductService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IFsStoreProductPackageUniqueCodeService productPackageUniqueCodeService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ICompanyService companyService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ICompanyUserService companyUserService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private WxMaProperties properties;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private RedisCache redisCache;
|
|
|
@Login
|
|
@Login
|
|
|
@ApiOperation("获取套餐列表")
|
|
@ApiOperation("获取套餐列表")
|
|
|
@GetMapping("/getStoreProductPackage")
|
|
@GetMapping("/getStoreProductPackage")
|
|
@@ -82,4 +107,102 @@ public class StoreProductPackageController extends AppBaseController {
|
|
|
return R.ok().put("data",storeProductPackage);
|
|
return R.ok().put("data",storeProductPackage);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @ApiOperation("套餐urlScheme")
|
|
|
|
|
+ @GetMapping("/getPackageAppletScheme")
|
|
|
|
|
+ public R getPackageAppletScheme(@RequestParam("packageId") Long packageId,
|
|
|
|
|
+ @RequestParam("companyId") Long companyId,
|
|
|
|
|
+ @RequestParam("companyUserId") Long companyUserId,
|
|
|
|
|
+ @RequestParam("path") String path) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (StringUtils.isEmpty(path)) {
|
|
|
|
|
+ return R.error("path不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ FsStoreProductPackage storeProductPackage = productPackageService.selectFsStoreProductPackageById(packageId);
|
|
|
|
|
+ if (storeProductPackage == null) {
|
|
|
|
|
+ return R.error("套餐不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ Company company = companyService.selectCompanyById(companyId);
|
|
|
|
|
+ if (company == null) {
|
|
|
|
|
+ return R.error("公司不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+ CompanyUser companyUser = companyUserService.selectCompanyUserById(companyUserId);
|
|
|
|
|
+ if (companyUser == null) {
|
|
|
|
|
+ return R.error("未查询到销售信息,链接生成失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!companyId.equals(companyUser.getCompanyId())) {
|
|
|
|
|
+ return R.error("销售与公司信息不匹配");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ R uniqueCodeResult = productPackageUniqueCodeService.createUniqueCode(packageId, companyId, companyUserId);
|
|
|
|
|
+ if (!uniqueCodeResult.isSuccess()) {
|
|
|
|
|
+ return uniqueCodeResult;
|
|
|
|
|
+ }
|
|
|
|
|
+ String uniqueCode = (String) uniqueCodeResult.get("uniqueCode");
|
|
|
|
|
+
|
|
|
|
|
+ String queryParam = "packageId=" + packageId + "&companyId=" + companyId + "&companyUserId=" + companyUserId + "&shareUniqueCode=" + uniqueCode;
|
|
|
|
|
+ String pageUrl = path.contains("?") ? path + "&" + queryParam : path + "?" + queryParam;
|
|
|
|
|
+ String appId = properties.getConfigs().get(0).getAppid();
|
|
|
|
|
+ String secret = properties.getConfigs().get(0).getSecret();
|
|
|
|
|
+
|
|
|
|
|
+ String cacheKey = "wx:access_token:" + appId;
|
|
|
|
|
+ String access_token = redisCache.getCacheObject(cacheKey);
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isEmpty(access_token)) {
|
|
|
|
|
+ String rspStr = HttpUtils.sendGet("https://api.weixin.qq.com/cgi-bin/token", "grant_type=client_credential&" + "appid=" + appId + "&secret=" + secret);
|
|
|
|
|
+ JSONObject obj = JSONObject.parseObject(rspStr);
|
|
|
|
|
+ access_token = obj.getString("access_token");
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isEmpty(access_token)) {
|
|
|
|
|
+ log.error("获取微信 access_token 失败: {}", obj);
|
|
|
|
|
+ return R.error("获取微信 access_token 失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ redisCache.setCacheObject(cacheKey, access_token, 7200, java.util.concurrent.TimeUnit.SECONDS);
|
|
|
|
|
+ log.info("微信 access_token 已刷新并缓存,appId: {}", appId);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.debug("从 Redis 缓存中获取 access_token,appId: {}", appId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject jump_wxaObj = new JSONObject();
|
|
|
|
|
+ jump_wxaObj.put("page_url", pageUrl);
|
|
|
|
|
+ String paramStr = jump_wxaObj.toJSONString();
|
|
|
|
|
+ String postStr = HttpUtils.sendPost("https://api.weixin.qq.com/wxa/genwxashortlink?access_token=" + access_token, paramStr);
|
|
|
|
|
+ JSONObject obj = JSONObject.parseObject(postStr);
|
|
|
|
|
+
|
|
|
|
|
+ if (obj != null && (obj.getInteger("errcode") != null && obj.getInteger("errcode") == 40001)) {
|
|
|
|
|
+ log.warn("access_token 已失效,清除缓存并重新获取,appId: {}", appId);
|
|
|
|
|
+ redisCache.deleteObject(cacheKey);
|
|
|
|
|
+ String rspStr = HttpUtils.sendGet("https://api.weixin.qq.com/cgi-bin/token", "grant_type=client_credential&" + "appid=" + appId + "&secret=" + secret);
|
|
|
|
|
+ JSONObject tokenObj = JSONObject.parseObject(rspStr);
|
|
|
|
|
+ access_token = tokenObj.getString("access_token");
|
|
|
|
|
+ if (StringUtils.isNotEmpty(access_token)) {
|
|
|
|
|
+ redisCache.setCacheObject(cacheKey, access_token, 7200, java.util.concurrent.TimeUnit.SECONDS);
|
|
|
|
|
+ postStr = HttpUtils.sendPost("https://api.weixin.qq.com/wxa/genwxashortlink?access_token=" + access_token, paramStr);
|
|
|
|
|
+ obj = JSONObject.parseObject(postStr);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return R.ok().put("result", obj).put("uniqueCode", uniqueCode);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("生成小程序 Scheme 失败", e);
|
|
|
|
|
+ return R.error("操作失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Login
|
|
|
|
|
+ @ApiOperation("生成套餐分享唯一编码")
|
|
|
|
|
+ @PostMapping("/createUniqueCode")
|
|
|
|
|
+ public R createUniqueCode(@RequestParam("packageId") Long packageId,
|
|
|
|
|
+ @RequestParam("companyId") Long companyId,
|
|
|
|
|
+ @RequestParam("companyUserId") Long companyUserId) {
|
|
|
|
|
+ return productPackageUniqueCodeService.createUniqueCode(packageId, companyId, companyUserId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Login
|
|
|
|
|
+ @ApiOperation("校验套餐分享唯一编码是否已使用")
|
|
|
|
|
+ @GetMapping("/checkUniqueCode")
|
|
|
|
|
+ public R checkUniqueCode(@RequestParam("uniqueCode") String uniqueCode) {
|
|
|
|
|
+ return productPackageUniqueCodeService.checkUniqueCode(uniqueCode);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|