!250 完成小程序消息订阅

Merge pull request !250 from 德仔/develop
This commit is contained in:
德仔
2021-05-18 14:17:19 +08:00
committed by Gitee
33 changed files with 633 additions and 669 deletions

View File

@ -7,11 +7,7 @@ import com.stdiet.common.core.redis.RedisCache;
import com.stdiet.common.utils.StringUtils;
import com.stdiet.common.utils.file.FileUploadUtils;
import com.stdiet.common.utils.file.FileUtils;
import com.stdiet.custom.domain.wechat.WxAccessToken;
import com.stdiet.custom.domain.wechat.WxFileUploadResult;
import com.stdiet.custom.utils.WxTokenUtils;
import com.stdiet.framework.config.ServerConfig;
import org.aspectj.weaver.loadtime.Aj;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -23,7 +19,6 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URLDecoder;
import java.util.concurrent.TimeUnit;
/**
* 通用请求处理

View File

@ -1,43 +0,0 @@
package com.stdiet.web.controller.custom;
import com.stdiet.common.core.controller.BaseController;
import com.stdiet.common.core.domain.AjaxResult;
import com.stdiet.common.core.redis.RedisCache;
import com.stdiet.custom.service.ISysWxService;
import com.stdiet.custom.utils.WxTokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping("/wx")
public class CusWxController extends BaseController {
@Autowired
public ISysWxService sysWxService;
@Autowired
public RedisCache redisCache;
@GetMapping("/checkSign")
public String wxCheckAuth(@RequestParam String signature, @RequestParam String timestamp, @RequestParam String nonce, @RequestParam String echostr) {
return sysWxService.wxCheckAuth(signature, timestamp, nonce, echostr);
}
@PostMapping("/checkSign")
public String autoResponse(HttpServletRequest request) {
return sysWxService.autoResponse(request);
}
@GetMapping("/accessToken")
public AjaxResult getAccessToken() {
return sysWxService.getAccessToken();
}
@GetMapping("/clearAccessToken")
public AjaxResult clearAccessToken() {
redisCache.deleteObject(WxTokenUtils.KEY_ACCESS_TOKEN);
return AjaxResult.success();
}
}

View File

@ -451,17 +451,24 @@ public class WechatAppletController extends BaseController {
if (StringUtils.isNotEmpty(sysWxUserInfo.getPhone())) {
SysCustomer sysCustomer = iSysCustomerService.getCustomerByPhone(sysWxUserInfo.getPhone());
if (StringUtils.isNull(sysCustomer)) {
return AjaxResult.error(5003, "未查到用户信息,请联系销售顾问");
// return AjaxResult.error(5003, "未查到用户信息,请联系销售顾问");
// 创建新客户
sysCustomer = new SysCustomer();
sysCustomer.setName(sysWxUserInfo.getNickName());
sysCustomer.setPhone(sysWxUserInfo.getPhone());
sysCustomer.setUpdateTime(DateUtils.getNowDate());
sysCustomer.setCreateTime(DateUtils.getNowDate());
iSysCustomerService.insertSysCustomer(sysCustomer);
}
sysWxUserInfo.setCusId(sysCustomer.getId());
sysWxUserInfo.setUpdateTime(DateUtils.getNowDate());
if (StringUtils.isNull(curWxUserInfo)) {
// 新增sys_wx_user_info
sysWxUserInfo.setCreateTime(DateUtils.getNowDate());
sysWxUserInfoService.insertSysWxUserInfo(sysWxUserInfo);
} else {
// 更新sys_wx_user_info数据
sysWxUserInfo.setUpdateTime(DateUtils.getNowDate());
sysWxUserInfoService.updateSysWxUserInfo(sysWxUserInfo);
}
// 更新对象
@ -486,6 +493,23 @@ public class WechatAppletController extends BaseController {
List<SysRecipesPlanListInfo> plans = sysRecipesPlanService.selectRecipesPlanListInfoByCusId(cusId);
SysRecipesPlanListInfo tmpPlan;
for (int i = 0; i < plans.size(); i++) {
tmpPlan = plans.get(i);
tmpPlan.setStatus(1);
if (StringUtils.isNull(tmpPlan.getSendFlag()) || tmpPlan.getSendFlag() == 0) {
tmpPlan.setSendFlag(0);
tmpPlan.setMenus(new ArrayList<>());
}
// 从excel转到线上的客户之前的食谱无效
if (i > 0 && plans.get(i - 1).getRecipesId() == null && i < plans.size() - 1 && plans.get(i + 1).getRecipesId() != null) {
for (int j = 0; j < i; j++) {
plans.get(j).setStatus(0);
}
}
}
SysOrderPause orderPause = new SysOrderPause();
orderPause.setCusId(cusId);
List<SysOrderPause> pauses = sysOrderPauseService.selectSysOrderPauseList(orderPause);
@ -534,10 +558,27 @@ public class WechatAppletController extends BaseController {
}
@GetMapping("/getToken")
public String getToken(@RequestParam String appId) throws Exception {
public String getToken(@RequestParam String appId) {
return iWechatAppletService.getAccessToken(appId);
}
@GetMapping("/subscribe")
public AjaxResult subscribe(@RequestParam String customerId, @RequestParam Long planId, @RequestParam Integer subscribed) {
// Long cusId = StringUtils.isNotEmpty(customerId) ? Long.parseLong(AesUtils.decrypt(customerId)) : 0L;
SysRecipesPlan info = new SysRecipesPlan();
info.setId(planId);
info.setSubscribed(subscribed);
return AjaxResult.success(sysRecipesPlanService.updateSysRecipesPlan(info));
}
@GetMapping("/subscribe/post")
public AjaxResult subscribePost(@RequestParam Long cusId, @RequestParam Long planId, @RequestParam String name, @RequestParam String startDate, @RequestParam String endDate, @RequestParam String remark) {
return AjaxResult.success(iWechatAppletService.postSubscribeMessage(cusId, planId, name, startDate, endDate, remark));
}
}