微信小程序打卡接口

This commit is contained in:
xiezhijun 2021-03-22 15:51:55 +08:00
parent 636a808d3a
commit 1d66f7334a
6 changed files with 200 additions and 1 deletions

View File

@ -0,0 +1,160 @@
package com.stdiet.web.controller.custom;
import com.itextpdf.io.util.DateTimeUtil;
import com.stdiet.common.core.controller.BaseController;
import com.stdiet.common.core.domain.AjaxResult;
import com.stdiet.common.core.page.TableDataInfo;
import com.stdiet.common.utils.StringUtils;
import com.stdiet.common.utils.oss.AliyunOSSUtils;
import com.stdiet.common.utils.sign.AesUtils;
import com.stdiet.custom.domain.*;
import com.stdiet.custom.dto.response.CustomerCaseResponse;
import com.stdiet.custom.page.WxLogInfo;
import com.stdiet.custom.service.ISysCustomerCaseService;
import com.stdiet.custom.service.ISysOrderService;
import com.stdiet.custom.service.ISysWxUserInfoService;
import com.stdiet.custom.service.ISysWxUserLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
/**
* 微信小程序统一Controller
*/
@RestController
@RequestMapping("/wx/applet")
public class WechatAppletController extends BaseController {
@Autowired
private ISysCustomerCaseService sysCustomerCaseService;
@Autowired
private ISysWxUserLogService sysWxUserLogService;
@Autowired
private ISysWxUserInfoService sysWxUserInfoService;
@Autowired
private ISysOrderService sysOrderService;
/**
* 查询微信小程序中展示的客户案例
*/
@GetMapping("/caseList")
public TableDataInfo caseList(SysCustomerCase sysCustomerCase)
{
startPage();
sysCustomerCase.setKeywordArray(StringUtils.isNotEmpty(sysCustomerCase.getKeyword()) ? sysCustomerCase.getKeyword().split(",") : null);
List<CustomerCaseResponse> list = sysCustomerCaseService.getWxCustomerCaseList(sysCustomerCase);
//处理ID加密
dealIdEnc(list);
return getDataTable(list);
}
/**
* 查询客户案例文件列表
*/
@GetMapping("/getFileByCaseId")
public AjaxResult getFileByCaseId(@RequestParam("caseId")String caseId)
{
Long id = StringUtils.isNotEmpty(caseId) ? Long.parseLong(AesUtils.decrypt(caseId, null)) : null;
CustomerCaseResponse customerCaseResponse = new CustomerCaseResponse();
customerCaseResponse.setId(caseId);
if(id != null){
List<SysCustomerCaseFile> list = sysCustomerCaseService.getFileListByCaseId(id);
List<String> fileUrl = new ArrayList<>();
for (SysCustomerCaseFile caseFile : list) {
fileUrl.add(caseFile.getFileUrl());
}
List<String> downUrlList = AliyunOSSUtils.generatePresignedUrl(fileUrl);
customerCaseResponse.setFileList(downUrlList);
}else{
customerCaseResponse.setFileList(new ArrayList<>());
}
return AjaxResult.success(customerCaseResponse);
}
/**
* 同步客户信息返回订单数量
* @param sysWxUserInfo
* @return
*/
@PostMapping("/synchroCustomerInfo")
public AjaxResult synchroCustomerInfo(@RequestBody SysWxUserInfo sysWxUserInfo) {
if(StringUtils.isEmpty(sysWxUserInfo.getOpenid()) || StringUtils.isEmpty(sysWxUserInfo.getPhone())){
return AjaxResult.error("手机号为空");
}
// 查询微信用户
SysWxUserInfo userInfo = sysWxUserInfoService.selectSysWxUserInfoById(sysWxUserInfo.getOpenid());
if(userInfo != null){
//更新数据
sysWxUserInfoService.updateSysWxUserInfo(sysWxUserInfo);
}else{
sysWxUserInfoService.insertSysWxUserInfo(sysWxUserInfo);
}
//查询是否下单
SysCustomer param = new SysCustomer();
param.setPhone(sysWxUserInfo.getPhone());
int orderCount = sysOrderService.getOrderCountByCustomer(param);
//返回订单数量
return AjaxResult.success(orderCount);
}
/**
* 微信小程序获取客户打卡记录
* @param sysWxUserLog
* @return
*/
@GetMapping(value = "/getPunchLogs")
public TableDataInfo getPunchLogs(SysWxUserLog sysWxUserLog) {
startPage();
List<WxLogInfo> list = sysWxUserLogService.selectWxLogInfoList(sysWxUserLog);
return getDataTable(list);
}
/**
* 今日是否打卡
* @param openid
* @return
*/
@GetMapping(value = "/checkNowPunchLog/{openid}")
public AjaxResult checkNowPunchLog(@PathVariable String openid) {
int count = StringUtils.isEmpty(openid) ? 0 : sysWxUserLogService.checkWxLogInfoCount(openid);
return AjaxResult.success(count);
}
/**
* 微信小程序打卡
* @param sysWxUserLog
* @return
*/
@PostMapping(value = "/addPunchLog")
public AjaxResult addPunchLog(@RequestBody SysWxUserLog sysWxUserLog) {
// 查询微信用户
SysWxUserInfo userInfo = StringUtils.isEmpty(sysWxUserLog.getOpenid()) ? null : sysWxUserInfoService.selectSysWxUserInfoById(sysWxUserLog.getOpenid());
if (userInfo == null) {
return AjaxResult.error("不存在客户");
}
//查询今日是否已打卡
int count = sysWxUserLogService.checkWxLogInfoCount(sysWxUserLog.getOpenid());
if(count > 0){
return AjaxResult.error("今日已打卡,不可重复打卡");
}
sysWxUserLog.setLogTime(DateTimeUtil.getCurrentTimeDate());
return toAjax(sysWxUserLogService.insertSysWxUserLog(sysWxUserLog));
}
/**
* 处理返回值的ID加密
* @param list
* @return
*/
private void dealIdEnc(List<CustomerCaseResponse> list){
for (CustomerCaseResponse cus : list) {
cus.setId(AesUtils.encrypt(cus.getId()+"", null));
}
}
}

View File

@ -5,6 +5,7 @@ import java.util.List;
import com.stdiet.custom.domain.SysCommision;
import com.stdiet.custom.domain.SysCommissionDayDetail;
import com.stdiet.custom.domain.SysCustomer;
import com.stdiet.custom.domain.SysOrder;
import com.stdiet.custom.dto.request.SysOrderCommision;
import org.apache.ibatis.annotations.Param;
@ -77,4 +78,11 @@ public interface SysOrderMapper
* @return
*/
List<SysOrder> selectSimpleOrderMessage(SysCommision sysCommision);
/**
* 查询客户订单数量
* @param sysCustomer
* @return
*/
int getOrderCountByCustomer(SysCustomer sysCustomer);
}

View File

@ -3,6 +3,8 @@ package com.stdiet.custom.service;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import com.stdiet.custom.domain.SysCustomer;
import com.stdiet.custom.domain.SysOrder;
/**
@ -75,4 +77,11 @@ public interface ISysOrderService
* @return
*/
int updateOrderServerEndDate(Long orderId, boolean updatePlan);
/**
* 查询客户订单数量
* @param sysCustomer
* @return
*/
int getOrderCountByCustomer(SysCustomer sysCustomer);
}

View File

@ -4,6 +4,7 @@ import com.stdiet.common.annotation.Excel;
import com.stdiet.common.utils.DateUtils;
import com.stdiet.common.utils.SecurityUtils;
import com.stdiet.common.utils.StringUtils;
import com.stdiet.custom.domain.SysCustomer;
import com.stdiet.custom.domain.SysOrder;
import com.stdiet.custom.mapper.SysOrderMapper;
import com.stdiet.custom.service.ISysCommissionDayService;
@ -326,4 +327,13 @@ public class SysOrderServiceImpl implements ISysOrderService {
//删除食谱计划
sysRecipesPlanService.delRecipesPlanByOrderId(orderIds);
}
/**
* 查询客户订单数量
* @param sysCustomer
* @return
*/
public int getOrderCountByCustomer(SysCustomer sysCustomer){
return sysOrderMapper.getOrderCountByCustomer(sysCustomer);
}
}

View File

@ -408,4 +408,16 @@
order by o.order_time desc
</select>
<!-- 根据客户信息查询客户的订单列表数量 -->
<select id="getOrderCountByCustomer" parameterType="SysCustomer" resultType="int">
SELECT count(so.order_id) FROM sys_order so LEFT JOIN sys_customer sc ON sc.id = so.cus_id AND sc.del_flag = 0
WHERE so.del_flag = 0
<if test="phone != null and phone != ''">
and sc.phone = #{phone}
</if>
<if test="id != null">
and sc.id = #{id}
</if>
</select>
</mapper>

View File

@ -78,7 +78,7 @@
</otherwise>
</choose>
</where>
order by log_time asc
order by log_time desc
</select>
<select id="selectSysWxUserLogById" parameterType="String" resultMap="SysWxUserLogResult">