猫妈狗爸伴宠师小程序后端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

442 lines
18 KiB

6 months ago
2 months ago
6 months ago
2 months ago
2 months ago
2 months ago
6 months ago
1 month ago
6 months ago
2 months ago
6 months ago
2 months ago
6 months ago
2 months ago
6 months ago
2 months ago
1 month ago
6 months ago
2 months ago
6 months ago
2 months ago
1 month ago
2 months ago
2 months ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
6 months ago
1 month ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
5 months ago
6 months ago
2 months ago
6 months ago
6 months ago
6 months ago
2 months ago
6 months ago
6 months ago
2 months ago
6 months ago
2 months ago
2 months ago
6 months ago
2 months ago
2 months ago
6 months ago
2 months ago
2 months ago
6 months ago
2 months ago
2 months ago
6 months ago
  1. package com.ruoyi.applet.contoller;
  2. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  3. import com.cyl.manager.staff.domain.vo.StaffVO;
  4. import com.cyl.manager.ums.domain.Member;
  5. import com.cyl.manager.ums.mapper.MemberMapper;
  6. import com.cyl.manager.ums.service.MemberWechatService;
  7. import com.ruoyi.applet.mallpojo.TeacherListRequest;
  8. import com.ruoyi.applet.pojo.dto.filterQualifiedUsersVo;
  9. import com.ruoyi.common.core.controller.BaseController;
  10. import com.ruoyi.common.core.domain.AjaxResult;
  11. import com.ruoyi.common.core.page.TableDataInfo;
  12. import com.ruoyi.common.exception.ServiceException;
  13. import com.ruoyi.common.utils.StringUtils;
  14. import com.ruoyi.model.domain.*;
  15. import com.ruoyi.model.service.*;
  16. import io.swagger.annotations.Api;
  17. import io.swagger.annotations.ApiOperation;
  18. import lombok.extern.slf4j.Slf4j;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.web.bind.annotation.*;
  21. import java.text.SimpleDateFormat;
  22. import java.time.LocalDateTime;
  23. import java.util.ArrayList;
  24. import java.util.Arrays;
  25. import java.util.Date;
  26. import java.util.List;
  27. @Slf4j
  28. @Api(description = "下单小程序端 - 派单指定相关接口")
  29. @RestController
  30. @RequestMapping("/applet/mall/teacher")
  31. public class ApiMallUserTeacherController extends BaseController {
  32. @Autowired
  33. private IAppUsersService appUsersService;
  34. @Autowired
  35. private IAppletUsersTeacherService appletUsersTeacherService;
  36. @Autowired
  37. private IAppletConfigService appletConfigService;
  38. @Autowired
  39. private IAppletAddressService appletAddressService;
  40. @Autowired
  41. private IAppletOutDateService appletOutDateService;
  42. @Autowired
  43. private IOmsOrderEvaluationService omsOrderEvaluationService;
  44. @Autowired
  45. private MemberMapper memberMapper;
  46. @Autowired
  47. private MemberWechatService memberWechatService;
  48. @Autowired
  49. private IAppletServiceLogService appletServiceLogService;
  50. @Autowired
  51. private IAApiAppletHhrWorkOutService apiAppletHhrWorkOutService;
  52. //mall-首页周边伴宠师
  53. @ApiOperation("mall-首页周边伴宠师接口")
  54. @GetMapping("/getTeacherListIndex")
  55. public TableDataInfo getTeacherListIndex() {
  56. startPage();
  57. AppUsers appUsers = new AppUsers();
  58. appUsers.setUserBcs(1);
  59. List<AppUsers> appUsersList = appUsersService.selectAppUsersList(appUsers);
  60. for (AppUsers appUsers1 : appUsersList){
  61. AppletUsersTeacher appletUsersTeacher = appletUsersTeacherService.selectAppletUsersTeacherByUserId(appUsers1.getUserId());
  62. appUsers1.setAppletUsersTeacher(appletUsersTeacher);
  63. AppletAddress appletAddress = new AppletAddress();
  64. appletAddress.setUserId(appUsers.getUserId());
  65. List<AppletAddress> appletAddresses = appletAddressService.selectAppletAddressList(appletAddress);
  66. appUsers.setAppletAddresseList(appletAddresses);
  67. }
  68. return getDataTable(appUsersList);
  69. }
  70. @ApiOperation("mall端-查询周边伴宠师列表集合接口")
  71. @GetMapping("/v2/getTeacherList")
  72. public TableDataInfo getTeacherList2(TeacherListRequest request) {
  73. startPage();
  74. List<AppUsers> appUsers2 = new ArrayList<>();
  75. if (StringUtils.isNotEmpty(request.getLatitude())){
  76. appUsers2 = appUsersService.filterQualifiedUsers(
  77. filterQualifiedUsersVo.builder()
  78. .distance("100")
  79. .companionLevel(request.getTeacherLevels())
  80. .latitude(Double.parseDouble(request.getLatitude()))
  81. .longitude(Double.parseDouble(request.getLongitude()))
  82. .petTypes(request.getPetTypes())
  83. .sex(request.getSex() == null ? null : Integer.valueOf(request.getSex() + ""))
  84. .staffName(request.getStaffName())
  85. .timeArray(StringUtils.isNotEmpty(request.getSelectedDate()) ? Arrays.asList(request.getSelectedDate().split(",")) : null)
  86. .build()
  87. );
  88. }
  89. if (appUsers2.isEmpty() && request.getIsZ() == null){
  90. AppUsers one = appUsersService.lambdaQuery().last("limit 1").one();
  91. one.setAppletAddresseList(appletAddressService.lambdaQuery().eq(AppletAddress::getUserId, one.getUserId()).list());
  92. appUsers2.add(one);
  93. }
  94. for (AppUsers users : appUsers2) {
  95. users.setEvaluationNum(omsOrderEvaluationService.lambdaQuery()
  96. .eq(OmsOrderEvaluation::getTechnicianId, users.getUserHh()).count());
  97. users.setAppletUsersTeacher(appletUsersTeacherService.lambdaQuery().eq(AppletUsersTeacher::getUserId, users.getUserId())
  98. .last("limit 1")
  99. .one());
  100. users.setServiceSummaryNum(appletServiceLogService.lambdaQuery().eq(AppletServiceLog::getUserId, users.getUserId()).count());
  101. }
  102. return getDataTable(appUsers2);
  103. }
  104. //mall端-查询周边伴宠师集合
  105. @ApiOperation("mall端-查询周边伴宠师列表集合接口")
  106. @GetMapping("/getTeacherList")
  107. public TableDataInfo getTeacherList(TeacherListRequest request) {
  108. startPage();
  109. AppUsers appUsers = new AppUsers();
  110. appUsers.setUserBcs(1);
  111. //如果伴宠师等级传入
  112. if (request.getTeacherLevels() != null) {
  113. appUsers.setUserBcsRole(request.getTeacherLevels());
  114. }
  115. //如果传入staffName
  116. if (request.getStaffName() != null) {
  117. appUsers.setUserName(request.getStaffName());
  118. }
  119. String petType =request.getPetTypes();
  120. List<AppUsers> appUsersList = appUsersService.selectAppUsersList(appUsers);
  121. List<AppUsers> appUsersListNew = new ArrayList<>();
  122. for (AppUsers appUsers1 : appUsersList){
  123. AppletUsersTeacher appletUsersTeacher = appletUsersTeacherService.selectAppletUsersTeacherByUserId(appUsers1.getUserId());
  124. appUsers1.setAppletUsersTeacher(appletUsersTeacher);
  125. AppletAddress appletAddress = new AppletAddress();
  126. appletAddress.setUserId(appUsers1.getUserId());
  127. List<AppletAddress> appletAddresses = appletAddressService.selectAppletAddressList(appletAddress);
  128. appUsers1.setAppletAddresseList(appletAddresses);
  129. //如果经纬度不为空
  130. if (request.getLatitude() != null && request.getLongitude() != null) {
  131. //查询该经纬度下3-15公里内的接单地址
  132. for (AppletAddress address : appletAddresses) {
  133. if (address.getLatitude() != null && address.getLongitude() != null) {
  134. //计算距离
  135. Double distance = getDistance(
  136. Double.parseDouble(request.getLatitude()),
  137. Double.parseDouble(request.getLongitude()),
  138. Double.parseDouble(address.getLatitude()),
  139. Double.parseDouble(address.getLongitude())
  140. );
  141. //如果距离在3-15公里内
  142. if (distance <= 100) {
  143. // 检查appUsers1是否已经存在于appUsersListNew中
  144. if (!appUsersListNew.contains(appUsers1)) {
  145. appUsers1.setDistance(distance);
  146. //如果性别不为空
  147. if (request.getSex() != null) {
  148. //判断性别跟查出来的性别相同
  149. if (request.getSex().equals(appletUsersTeacher.getSex())) {
  150. if (!appUsersListNew.contains(appUsers1)) {
  151. appUsersListNew.add(appUsers1);
  152. }
  153. }
  154. }else{
  155. if (!appUsersListNew.contains(appUsers1)) {
  156. appUsersListNew.add(appUsers1);
  157. }
  158. }
  159. // 如果写入了接单日期
  160. if (request.getSelectedDate() != null) {
  161. // 创建一个AppletOutDate对象
  162. AppletOutDate appletOutDate = new AppletOutDate();
  163. appletOutDate.setAddressId(address.getId());
  164. // 获取不接单日期列表
  165. List<AppletOutDate> appletOutDates = appletOutDateService.selectAppletOutDateList(appletOutDate);
  166. // 创建一个SimpleDateFormat对象,用于格式化日期
  167. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  168. // 提取不接单日期字符串列表
  169. List<String> outDates = new ArrayList<>();
  170. for (AppletOutDate outDate : appletOutDates) {
  171. Date date = outDate.getDate(); // 假设AppletOutDate有一个getDate()方法
  172. if (date != null) {
  173. outDates.add(dateFormat.format(date)); // 将Date格式化为字符串
  174. }
  175. }
  176. // 分割request.getSelectedDate()为多个日期
  177. String[] selectedDates = request.getSelectedDate().split(",");
  178. // 初始化一个标志,用于判断是否所有日期都不在不接单日期列表中
  179. boolean allDatesValid = true;
  180. // 检查每个日期是否不在不接单日期列表中
  181. for (String selectedDate : selectedDates) {
  182. if (outDates.contains(selectedDate.trim())) {
  183. allDatesValid = false;
  184. break;
  185. }
  186. }
  187. // 如果所有日期都不在不接单日期列表中,并且appUsers1不在列表中,则添加
  188. if (allDatesValid) {
  189. if (!appUsersListNew.contains(appUsers1)) {
  190. appUsersListNew.add(appUsers1);
  191. }
  192. } else {
  193. // 如果至少有一个日期在不接单日期列表中,检查并删除appUsers1
  194. if (appUsersListNew.contains(appUsers1)) {
  195. appUsersListNew.remove(appUsers1);
  196. }
  197. }
  198. }
  199. // 假设 petType 是一个字符串,格式为 "3,4,5"
  200. if (petType != null && appletUsersTeacher != null && appletUsersTeacher.getPetType() != null) {
  201. // 将 petType 分割为字符串数组
  202. String[] petTypes = petType.split(",");
  203. // 遍历分割后的数组,检查是否包含 appletUsersTeacher.getPetType()
  204. boolean containsPetType = false;
  205. for (String type : petTypes) {
  206. if (type.trim().equals(appletUsersTeacher.getPetType())) {
  207. containsPetType = true;
  208. break;
  209. }
  210. }
  211. if (containsPetType) {
  212. // 如果包含,检查是否已存在于列表中,不存在则添加
  213. if (!appUsersListNew.contains(appUsers1)) {
  214. appUsersListNew.add(appUsers1);
  215. }
  216. } else {
  217. // 如果不包含,检查是否存在并删除
  218. if (appUsersListNew.contains(appUsers1)) {
  219. appUsersListNew.remove(appUsers1);
  220. }
  221. }
  222. } else {
  223. // 如果 petType 为空,或者 appletUsersTeacher 或其 getPetType() 为空,则检查并添加 appUsers1
  224. if (!appUsersListNew.contains(appUsers1)) {
  225. appUsersListNew.add(appUsers1);
  226. }
  227. }
  228. }
  229. }
  230. }
  231. }
  232. }else {
  233. appUsersListNew.add(appUsersList.get(0));
  234. }
  235. }
  236. for (AppUsers users : appUsersListNew) {
  237. users.setEvaluationNum(omsOrderEvaluationService.lambdaQuery()
  238. .eq(OmsOrderEvaluation::getTechnicianId, users.getUserHh()).count());
  239. }
  240. return getDataTable(appUsersListNew);
  241. }
  242. /**
  243. * 计算两个经纬度之间的距离单位公里
  244. * @param lat1 第一个点的纬度
  245. * @param lon1 第一个点的经度
  246. * @param lat2 第二个点的纬度
  247. * @param lon2 第二个点的经度
  248. * @return 两点之间的距离公里
  249. */
  250. public static double getDistance(double lat1, double lon1, double lat2, double lon2) {
  251. // 地球半径(公里)
  252. final int EARTH_RADIUS = 6371;
  253. // 将经纬度转换为弧度
  254. double lat1Rad = Math.toRadians(lat1);
  255. double lon1Rad = Math.toRadians(lon1);
  256. double lat2Rad = Math.toRadians(lat2);
  257. double lon2Rad = Math.toRadians(lon2);
  258. // 计算纬度差和经度差
  259. double latDiff = lat2Rad - lat1Rad;
  260. double lonDiff = lon2Rad - lon1Rad;
  261. // Haversine公式计算
  262. double a = Math.pow(Math.sin(latDiff / 2), 2) +
  263. Math.cos(lat1Rad) * Math.cos(lat2Rad) *
  264. Math.pow(Math.sin(lonDiff / 2), 2);
  265. double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  266. // 计算距离
  267. double distance = EARTH_RADIUS * c;
  268. // 保留两位小数
  269. return Math.round(distance * 100) / 100.0;
  270. }
  271. //mall端-查询指定伴宠师详情
  272. @ApiOperation("mall端-查询指定伴宠师详情接口")
  273. @GetMapping("/getTeacherDetail")
  274. public AppUsers getTeacherDetail(AppUsers app) {
  275. //用户标识不能为空
  276. AppUsers appUsers = appUsersService.selectAppUsersByUserId(app.getUserId());
  277. AppletUsersTeacher appletUsersTeacher = appletUsersTeacherService.selectAppletUsersTeacherByUserId(appUsers.getUserId());
  278. appUsers.setAppletUsersTeacher(appletUsersTeacher);
  279. AppletAddress appletAddress = new AppletAddress();
  280. appletAddress.setUserId(appUsers.getUserId());
  281. List<AppletAddress> appletAddresses = appletAddressService.selectAppletAddressList(appletAddress);
  282. appUsers.setAppletAddresseList(appletAddresses);
  283. return appUsers;
  284. }
  285. //mall端-查询指定伴宠师近期评价
  286. @ApiOperation("mall端-查询指定伴宠师近期评价")
  287. @GetMapping("/getTeacherEvaluate")
  288. public AjaxResult getTeacherEvaluate(@RequestParam String id) {
  289. Page<OmsOrderEvaluation> page = omsOrderEvaluationService.lambdaQuery()
  290. .eq(OmsOrderEvaluation::getTechnicianId, id)
  291. .page(new Page<>(1, 10));
  292. for (OmsOrderEvaluation record : page.getRecords()) {
  293. record.setMember(memberMapper.selectById(record.getMemberId()));
  294. }
  295. return AjaxResult.success(page);
  296. }
  297. //mall端-系统派单的时候需要选择的伴宠师等级说明
  298. @ApiOperation("mall端-系统派单的时候需要选择的伴宠师等级说明接口")
  299. @GetMapping("/getTeacherLevels")
  300. public TableDataInfo getTeacherLevels() {
  301. AppletConfig appletConfig = new AppletConfig();
  302. appletConfig.setParamClass("order_mall");
  303. List<AppletConfig> appletConfigs = appletConfigService.selectAppletConfigList(appletConfig);
  304. return getDataTable(appletConfigs);
  305. }
  306. //mall端-下单端用户通过邀请码绑定伴宠师
  307. @ApiOperation("mall端-下单端用户通过邀请码绑定伴宠师")
  308. @GetMapping("/bindCode")
  309. public AjaxResult bindCode(String code, String openId) {
  310. if (StringUtils.isEmpty(openId)){
  311. return AjaxResult.success();
  312. }
  313. Member member = memberWechatService.isRegister(openId);
  314. if (member == null){
  315. return AjaxResult.success();
  316. }
  317. //判断当前用户有没有绑定
  318. if (StringUtils.isNotEmpty(member.getInviteCode())){
  319. return AjaxResult.success();
  320. }
  321. AppUsers users = appUsersService.bindCode(code);
  322. member.setInviteCode(code);
  323. member.setSpreadTime(LocalDateTime.now());
  324. member.setSpreadUid(users.getUserId());
  325. memberMapper.updateById(member);
  326. try {
  327. apiAppletHhrWorkOutService.checkPartnerUpgrade(users.getUserId());
  328. }catch (Exception e){
  329. log.error(e.getMessage());
  330. }
  331. return AjaxResult.success();
  332. }
  333. }