猫妈狗爸伴宠师小程序后端代码
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.

385 lines
16 KiB

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