202506111809
This commit is contained in:
parent
214b63d038
commit
502becec4d
|
|
@ -27,6 +27,7 @@ import java.util.ArrayList;
|
|||
import java.util.Date;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.stream.Collectors;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import com.ruoyi.system.ControllerUtil.AppletControllerUtil;
|
||||
|
|
@ -104,6 +105,125 @@ public class AppletController extends BaseController {
|
|||
private IGoodsOrderService goodsOrderService;
|
||||
@Autowired
|
||||
private ICouponsService couponsService;
|
||||
@Autowired
|
||||
private IWorkerSignService workerSignService;
|
||||
|
||||
|
||||
// /**
|
||||
// * 创建服务订单
|
||||
// *
|
||||
// * @param params 请求参数,包含商品信息、地址信息和预约时间
|
||||
// * @param request HTTP请求对象
|
||||
// * @return 返回创建结果
|
||||
// */
|
||||
// @PostMapping("/api/service/create/order")
|
||||
// public AjaxResult createServiceNewOrder(@RequestBody Map<String, Object> params, HttpServletRequest request) {
|
||||
// try {
|
||||
// // 1. 验证用户登录状态
|
||||
// String token = request.getHeader("token");
|
||||
// Map<String, Object> userValidation = AppletLoginUtil.validateUserToken(token, usersService);
|
||||
// if (!(Boolean) userValidation.get("valid")) {
|
||||
// return error("用户未登录或token无效");
|
||||
// }
|
||||
//
|
||||
// // 2. 获取用户信息
|
||||
// Users user = (Users) userValidation.get("user");
|
||||
// if (user == null) {
|
||||
// return error("用户信息获取失败");
|
||||
// }
|
||||
//
|
||||
// // 3. 解析订单参数
|
||||
// if (params == null || params.get("0") == null) {
|
||||
// return error("订单参数不能为空");
|
||||
// }
|
||||
// Map<String, Object> orderParams = (Map<String, Object>) params.get("0");
|
||||
//
|
||||
// // 4. 验证必要参数
|
||||
// Long productId = Long.valueOf(orderParams.get("product_id").toString());
|
||||
// Long addressId = Long.valueOf(orderParams.get("address_id").toString());
|
||||
// String makeTime = orderParams.get("make_time").toString();
|
||||
// String sku = orderParams.get("sku") != null ? orderParams.get("sku").toString() : "";
|
||||
//
|
||||
// // 5. 查询商品信息
|
||||
// ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId);
|
||||
// if (serviceGoods == null) {
|
||||
// return error("商品不存在");
|
||||
// }
|
||||
//
|
||||
// // 6. 查询地址信息
|
||||
// UserAddress userAddress = userAddressService.selectUserAddressById(addressId);
|
||||
// if (userAddress == null) {
|
||||
// return error("地址不存在");
|
||||
// }
|
||||
//
|
||||
// // 7. 创建订单对象
|
||||
// Order order = new Order();
|
||||
// order.setType(1); // 1:服务项目
|
||||
// order.setCreateType(1); // 1:用户自主下单
|
||||
// order.setUid(user.getId());
|
||||
// order.setUname(user.getName());
|
||||
// order.setProductId(productId);
|
||||
// order.setProductName(serviceGoods.getTitle());
|
||||
// order.setName(userAddress.getName());
|
||||
// order.setPhone(userAddress.getPhone());
|
||||
// order.setAddress(userAddress.getAddressInfo());
|
||||
// order.setAddressId(addressId);
|
||||
// order.setSku(sku);
|
||||
//
|
||||
// // 解析预约时间
|
||||
// String[] makeTimeArr = makeTime.split(" ");
|
||||
// if (makeTimeArr.length != 2) {
|
||||
// return error("预约时间格式错误");
|
||||
// }
|
||||
// // 将日期字符串转换为时间戳
|
||||
// try {
|
||||
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
// Date date = sdf.parse(makeTimeArr[0]);
|
||||
// order.setMakeTime(date.getTime() / 1000); // 转换为秒级时间戳
|
||||
// order.setMakeHour(makeTimeArr[1]); // 设置预约时间段
|
||||
// } catch (Exception e) {
|
||||
// return error("预约时间格式错误");
|
||||
// }
|
||||
//
|
||||
// order.setNum(1L); // 默认数量为1
|
||||
// order.setTotalPrice(serviceGoods.getPrice()); // 总价等于商品价格
|
||||
// order.setGoodPrice(serviceGoods.getPrice()); // 商品金额
|
||||
// order.setServicePrice(BigDecimal.ZERO); // 服务金额默认为0
|
||||
// order.setPayPrice(serviceGoods.getPrice()); // 支付金额等于总价
|
||||
// order.setStatus(1L); // 1:待接单
|
||||
// order.setReceiveType(1L); // 1:自由抢单
|
||||
// order.setIsAccept(0); // 0:未接单
|
||||
// order.setIsComment(0); // 0:未评价
|
||||
// order.setIsPause(0); // 0:未暂停
|
||||
//
|
||||
// // 8. 生成订单号
|
||||
// String orderId = generateOrderId();
|
||||
// order.setOrderId(orderId);
|
||||
// order.setMainOrderId(orderId);
|
||||
//
|
||||
// // 9. 保存订单
|
||||
// int result = orderService.insertOrder(order);
|
||||
// if (result > 0) {
|
||||
// return success("预约成功");
|
||||
// } else {
|
||||
// return error("预约失败,请稍后重试");
|
||||
// }
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// return error("预约失败:" + e.getMessage());
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 生成订单号
|
||||
* 格式:年月日时分秒 + 4位随机数
|
||||
*/
|
||||
private String generateNewOrderId() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String timeStr = sdf.format(new Date());
|
||||
int random = (int) ((Math.random() * 9 + 1) * 1000);
|
||||
return timeStr + random;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务分类列表
|
||||
|
|
@ -692,7 +812,7 @@ public class AppletController extends BaseController {
|
|||
|
||||
// 5. 查询用户地址列表
|
||||
OrderApple order = new OrderApple();
|
||||
order.setType(1);
|
||||
// order.setType(1);
|
||||
order.setUid(user.getId());
|
||||
|
||||
if (StringUtils.isNotNull(status) && !"".equals(status)) {
|
||||
|
|
@ -783,37 +903,37 @@ public class AppletController extends BaseController {
|
|||
public AjaxResult getgoodsorderlst(@RequestBody Map<String, Object> params,
|
||||
HttpServletRequest request) {
|
||||
try {
|
||||
int page = (int) params.get("page");
|
||||
int limit = (int) params.get("limit");
|
||||
String status = (String) params.get("status");
|
||||
int page = (int) params.get("page");
|
||||
int limit = (int) params.get("limit");
|
||||
String status = (String) params.get("status");
|
||||
|
||||
// 1. 验证分页参数
|
||||
Map<String, Object> pageValidation = PageUtil.validatePageParams(page, limit);
|
||||
if (!(Boolean) pageValidation.get("valid")) {
|
||||
// 1. 验证分页参数
|
||||
Map<String, Object> pageValidation = PageUtil.validatePageParams(page, limit);
|
||||
if (!(Boolean) pageValidation.get("valid")) {
|
||||
return AppletControllerUtil.appletWarning((String) pageValidation.get("message"));
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 验证用户登录状态
|
||||
String token = request.getHeader("token");
|
||||
Map<String, Object> userValidation = AppletLoginUtil.validateUserToken(token, usersService);
|
||||
if (!(Boolean) userValidation.get("valid")) {
|
||||
// 2. 验证用户登录状态
|
||||
String token = request.getHeader("token");
|
||||
Map<String, Object> userValidation = AppletLoginUtil.validateUserToken(token, usersService);
|
||||
if (!(Boolean) userValidation.get("valid")) {
|
||||
return AppletControllerUtil.appletUnauthorized();
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 获取用户信息
|
||||
Users user = (Users) userValidation.get("user");
|
||||
if (user == null) {
|
||||
// 3. 获取用户信息
|
||||
Users user = (Users) userValidation.get("user");
|
||||
if (user == null) {
|
||||
return AppletControllerUtil.appletWarning("用户信息获取失败");
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 设置分页参数
|
||||
PageHelper.startPage(page, limit);
|
||||
// 4. 设置分页参数
|
||||
PageHelper.startPage(page, limit);
|
||||
|
||||
// 5. 构建查询条件
|
||||
GoodsOrder queryOrder = new GoodsOrder();
|
||||
queryOrder.setUid(user.getId());
|
||||
|
||||
if (StringUtils.isNotNull(status) && !"".equals(status)) {
|
||||
if (StringUtils.isNotNull(status) && !"".equals(status)) {
|
||||
queryOrder.setStatus(Long.valueOf(status));
|
||||
}
|
||||
|
||||
|
|
@ -1178,8 +1298,8 @@ public class AppletController extends BaseController {
|
|||
@GetMapping(value = "/api/user/info")
|
||||
public AjaxResult getUserInfo(HttpServletRequest request) {
|
||||
try {
|
||||
Map<String, Object> order_num = new HashMap<>();
|
||||
Map<String, Object> goods_order_num = new HashMap<>();
|
||||
Map<String, Object> order_num = new HashMap<>();
|
||||
Map<String, Object> goods_order_num = new HashMap<>();
|
||||
// 1. 验证用户登录状态
|
||||
String token = request.getHeader("token");
|
||||
Map<String, Object> userValidation = AppletLoginUtil.validateUserToken(token, usersService);
|
||||
|
|
@ -2217,18 +2337,38 @@ public class AppletController extends BaseController {
|
|||
}
|
||||
}
|
||||
} else if (status == 4L) {
|
||||
// 待领取的优惠券
|
||||
// 待领取的优惠券 - 只返回手动领取(type=2)且剩余数量大于0的优惠券
|
||||
Coupons couponsQuery = new Coupons();
|
||||
couponsQuery.setStatus(1L); // 启用状态
|
||||
couponsQuery.setType(2L); // 手动领取类型
|
||||
List<Coupons> availableCoupons = couponsService.selectCouponsList(couponsQuery);
|
||||
|
||||
for (Coupons coupon : availableCoupons) {
|
||||
if (isCouponAvailableToReceive(coupon, user.getId(), currentTime)) {
|
||||
// 创建一个临时的CouponUser对象来保持返回格式一致
|
||||
// 检查剩余数量大于0且用户可领取
|
||||
if (coupon.getCount() != null && coupon.getCount() > 0 &&
|
||||
isCouponAvailableToReceive(coupon, user.getId(), currentTime)) {
|
||||
// 创建一个临时的CouponUser对象,包含完整的优惠券信息
|
||||
CouponUser tempCouponUser = new CouponUser();
|
||||
tempCouponUser.setCouponId(coupon.getId());
|
||||
tempCouponUser.setUid(user.getId());
|
||||
tempCouponUser.setStatus(0L); // 待领取状态
|
||||
tempCouponUser.setCouponTitle(coupon.getTitle());
|
||||
tempCouponUser.setCouponPrice(coupon.getPrice() != null ? coupon.getPrice().intValue() : 0);
|
||||
tempCouponUser.setMinPrice(coupon.getMinPrice() != null ? coupon.getMinPrice().longValue() : 0L);
|
||||
tempCouponUser.setCateId(coupon.getCateId());
|
||||
tempCouponUser.setProductId(coupon.getProductId());
|
||||
tempCouponUser.setReceiveType(coupon.getReceiveType() != null ? coupon.getReceiveType().toString() : "1");
|
||||
|
||||
// 设置有效期
|
||||
if (coupon.getCouponTime() != null) {
|
||||
// 如果有固定的有效期天数,计算失效时间
|
||||
long loseTime = currentTime + (coupon.getCouponTime() * 24 * 60 * 60);
|
||||
tempCouponUser.setLoseTime(String.valueOf(loseTime));
|
||||
} else if (coupon.getEndTime() != null) {
|
||||
// 如果有结束时间,使用结束时间作为失效时间
|
||||
tempCouponUser.setLoseTime(String.valueOf(coupon.getEndTime()));
|
||||
}
|
||||
|
||||
filteredList.add(tempCouponUser);
|
||||
}
|
||||
}
|
||||
|
|
@ -4083,4 +4223,616 @@ public class AppletController extends BaseController {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建服务订单
|
||||
*
|
||||
* @param params 请求参数,包含商品信息、地址信息和预约时间
|
||||
* @param request HTTP请求对象
|
||||
* @return 返回创建结果
|
||||
*/
|
||||
@PostMapping("/api/service/create/order")
|
||||
public AjaxResult createServiceOrder(@RequestBody Map<String, Object> params, HttpServletRequest request) {
|
||||
try {
|
||||
// 1. 验证用户登录状态
|
||||
String token = request.getHeader("token");
|
||||
Map<String, Object> userValidation = AppletLoginUtil.validateUserToken(token, usersService);
|
||||
if (!(Boolean) userValidation.get("valid")) {
|
||||
return error("用户未登录或token无效");
|
||||
}
|
||||
|
||||
// 2. 获取用户信息
|
||||
Users user = (Users) userValidation.get("user");
|
||||
if (user == null) {
|
||||
return error("用户信息获取失败");
|
||||
}
|
||||
|
||||
// 3. 解析订单参数
|
||||
if (params == null || params.get("0") == null) {
|
||||
return error("订单参数不能为空");
|
||||
}
|
||||
Map<String, Object> orderParams = (Map<String, Object>) params.get("0");
|
||||
|
||||
// 4. 验证必要参数
|
||||
Long productId = Long.valueOf(orderParams.get("product_id").toString());
|
||||
Long addressId = Long.valueOf(orderParams.get("address_id").toString());
|
||||
String makeTime = orderParams.get("make_time").toString();
|
||||
String sku = orderParams.get("sku") != null ? orderParams.get("sku").toString() : "";
|
||||
|
||||
// 5. 查询商品信息
|
||||
ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId);
|
||||
if (serviceGoods == null) {
|
||||
return error("商品不存在");
|
||||
}
|
||||
|
||||
// 6. 查询地址信息
|
||||
UserAddress userAddress = userAddressService.selectUserAddressById(addressId);
|
||||
if (userAddress == null) {
|
||||
return error("地址不存在");
|
||||
}
|
||||
|
||||
// 7. 创建订单对象
|
||||
Order order = new Order();
|
||||
order.setType(1); // 1:服务项目
|
||||
order.setCreateType(1); // 1:用户自主下单
|
||||
order.setUid(user.getId());
|
||||
order.setUname(user.getName());
|
||||
order.setProductId(productId);
|
||||
order.setProductName(serviceGoods.getTitle());
|
||||
order.setName(userAddress.getName());
|
||||
order.setPhone(userAddress.getPhone());
|
||||
order.setAddress(userAddress.getAddressInfo());
|
||||
order.setAddressId(addressId);
|
||||
order.setSku(sku);
|
||||
|
||||
// 解析预约时间
|
||||
String[] makeTimeArr = makeTime.split(" ");
|
||||
if (makeTimeArr.length != 2) {
|
||||
return error("预约时间格式错误");
|
||||
}
|
||||
// 将日期字符串转换为时间戳
|
||||
try {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date date = sdf.parse(makeTimeArr[0]);
|
||||
order.setMakeTime(date.getTime() / 1000); // 转换为秒级时间戳
|
||||
order.setMakeHour(makeTimeArr[1]); // 设置预约时间段
|
||||
} catch (Exception e) {
|
||||
return error("预约时间格式错误");
|
||||
}
|
||||
|
||||
order.setNum(1L); // 默认数量为1
|
||||
order.setTotalPrice(serviceGoods.getPrice()); // 总价等于商品价格
|
||||
order.setGoodPrice(serviceGoods.getPrice()); // 商品金额
|
||||
order.setServicePrice(BigDecimal.ZERO); // 服务金额默认为0
|
||||
order.setPayPrice(serviceGoods.getPrice()); // 支付金额等于总价
|
||||
order.setStatus(1L); // 1:待接单
|
||||
order.setReceiveType(1L); // 1:自由抢单
|
||||
order.setIsAccept(0); // 0:未接单
|
||||
order.setIsComment(0); // 0:未评价
|
||||
order.setIsPause(0); // 0:未暂停
|
||||
// 8. 生成订单号
|
||||
String orderId = generateOrderId();
|
||||
order.setOrderId(orderId);
|
||||
order.setMainOrderId(orderId);
|
||||
// 9. 保存订单
|
||||
int result = orderService.insertOrder(order);
|
||||
if (result > 0) {
|
||||
//10预约后添加到订单记录中
|
||||
OrderLog orderLog = new OrderLog();
|
||||
orderLog.setOid(order.getId());
|
||||
orderLog.setOrderId(order.getOrderId());
|
||||
orderLog.setTitle("订单生成");
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("name", "预约成功,将尽快为主人派单");
|
||||
orderLog.setType(new BigDecimal(1.0));
|
||||
orderLog.setContent(jsonObject.toString());
|
||||
orderLogService.insertOrderLog(orderLog);
|
||||
return success("预约成功");
|
||||
} else {
|
||||
return error("预约失败,请稍后重试");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
return error("预约失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成订单号
|
||||
* 格式:年月日时分秒 + 4位随机数
|
||||
*/
|
||||
private String generateOrderId() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
String timeStr = sdf.format(new Date());
|
||||
int random = (int) ((Math.random() * 9 + 1) * 1000);
|
||||
return timeStr + random;
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消服务订单
|
||||
*
|
||||
* @param params 请求参数,包含订单ID和取消原因
|
||||
* @param request HTTP请求对象
|
||||
* @return 返回取消结果
|
||||
*/
|
||||
@PostMapping("/api/service/cancel/order")
|
||||
public AjaxResult cancelServiceOrder(@RequestBody Map<String, Object> params, HttpServletRequest request) {
|
||||
try {
|
||||
// 1. 验证用户登录状态
|
||||
String token = request.getHeader("token");
|
||||
Map<String, Object> userValidation = AppletLoginUtil.validateUserToken(token, usersService);
|
||||
if (!(Boolean) userValidation.get("valid")) {
|
||||
return error("用户未登录或token无效");
|
||||
}
|
||||
|
||||
// 2. 获取用户信息
|
||||
Users user = (Users) userValidation.get("user");
|
||||
if (user == null) {
|
||||
return error("用户信息获取失败");
|
||||
}
|
||||
|
||||
// 3. 验证必要参数
|
||||
if (params == null || params.get("id") == null || params.get("content") == null) {
|
||||
return error("参数不能为空");
|
||||
}
|
||||
Long orderId = Long.valueOf(params.get("id").toString());
|
||||
String cancelReason = params.get("content").toString();
|
||||
|
||||
// 4. 查询订单信息
|
||||
Order orderQuery = new Order();
|
||||
orderQuery.setId(orderId);
|
||||
orderQuery.setUid(user.getId()); // 确保是用户自己的订单
|
||||
List<Order> orders = orderService.selectOrderList(orderQuery);
|
||||
|
||||
if (orders == null || orders.isEmpty()) {
|
||||
return error("订单不存在");
|
||||
}
|
||||
Order order = orders.get(0);
|
||||
|
||||
// 5. 验证订单状态是否可以取消
|
||||
if (order.getStatus() != 1L) {
|
||||
return error("当前订单状态不可取消");
|
||||
}
|
||||
|
||||
// 6. 更新订单状态为已取消(5)
|
||||
Order updateOrder = new Order();
|
||||
updateOrder.setId(orderId);
|
||||
updateOrder.setStatus(5L);
|
||||
int result = orderService.updateOrder(updateOrder);
|
||||
|
||||
if (result > 0) {
|
||||
// 7. 添加订单日志
|
||||
OrderLog orderLog = new OrderLog();
|
||||
orderLog.setOid(orderId);
|
||||
orderLog.setOrderId(order.getOrderId());
|
||||
orderLog.setTitle("订单取消");
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("name", "用户取消订单,原因:" + cancelReason);
|
||||
orderLog.setType(new BigDecimal(9.0));
|
||||
orderLog.setContent(jsonObject.toString());
|
||||
orderLogService.insertOrderLog(orderLog);
|
||||
|
||||
return success("取消成功");
|
||||
} else {
|
||||
return error("取消失败,请稍后重试");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
return error("取消失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 师傅接单
|
||||
*
|
||||
* @param id 订单ID
|
||||
* @param request HTTP请求对象
|
||||
* @return 返回接单结果
|
||||
*/
|
||||
@GetMapping("/api/worker/accept/order/{id}")
|
||||
public AjaxResult acceptServiceOrder(@PathVariable("id") Long id, HttpServletRequest request) {
|
||||
try {
|
||||
// 1. 验证用户登录状态
|
||||
String token = request.getHeader("token");
|
||||
Map<String, Object> userValidation = AppletLoginUtil.validateUserToken(token, usersService);
|
||||
if (!(Boolean) userValidation.get("valid")) {
|
||||
return error("用户未登录或token无效");
|
||||
}
|
||||
|
||||
// 2. 获取师傅信息
|
||||
Users worker = (Users) userValidation.get("user");
|
||||
if (worker == null) {
|
||||
return error("用户信息获取失败");
|
||||
}
|
||||
|
||||
// 3. 查询订单信息
|
||||
Order order = orderService.selectOrderById(id);
|
||||
if (order == null) {
|
||||
return error("订单不存在");
|
||||
}
|
||||
|
||||
// 4. 验证订单状态是否可以接单
|
||||
if (order.getStatus() != 1L) {
|
||||
return error("当前订单状态不可接单");
|
||||
}
|
||||
|
||||
// 5. 更新订单信息
|
||||
order.setStatus(2L); // 更新状态为待服务
|
||||
order.setJsonStatus(2); // 更新为接单状态
|
||||
order.setWorkerId(worker.getId()); // 设置接单师傅ID
|
||||
order.setWorkerPhone(worker.getPhone()); // 设置师傅电话
|
||||
order.setIsPause(1); // 设置暂停状态为1
|
||||
order.setReceiveType(3L); // 设置接单类型为3
|
||||
order.setReceiveTime(new Date()); // 设置接单时间
|
||||
order.setIsAccept(1); // 设置已接单
|
||||
|
||||
// 6. 添加订单日志
|
||||
OrderLog orderLog = new OrderLog();
|
||||
orderLog.setOid(order.getId());
|
||||
orderLog.setOrderId(order.getOrderId());
|
||||
orderLog.setTitle("师傅接单");
|
||||
orderLog.setWorkerId(worker.getId());
|
||||
orderLog.setFirstWorkerId(worker.getId());
|
||||
orderLog.setIsPause(1);
|
||||
orderLog.setType(new BigDecimal("2.0"));
|
||||
|
||||
JSONObject content = new JSONObject();
|
||||
content.put("name", "师傅已接单,请等待上门服务");
|
||||
orderLog.setContent(content.toString());
|
||||
|
||||
// 7. 保存订单和日志
|
||||
int result = orderService.updateOrder(order);
|
||||
if (result > 0) {
|
||||
orderLogService.insertOrderLog(orderLog);
|
||||
return success("接单成功");
|
||||
} else {
|
||||
return error("接单失败,请稍后重试");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
return error("接单失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/api/worker/order/lst")
|
||||
public AjaxResult getWorkerOrderList(@RequestBody Map<String, Object> params, HttpServletRequest request) {
|
||||
try {
|
||||
// 获取当前用户token
|
||||
String token = request.getHeader("token");
|
||||
Map<String, Object> userData = AppletControllerUtil.getUserData(token, usersService);
|
||||
if ((int) userData.get("code") != 200) {
|
||||
return AjaxResult.error("用户未登录");
|
||||
}
|
||||
Users user = (Users) userData.get("user");
|
||||
Long userId = user.getId();
|
||||
|
||||
// 获取分页参数
|
||||
int page = params.containsKey("page") ? Integer.parseInt(params.get("page").toString()) : 1;
|
||||
int limit = params.containsKey("limit") ? Integer.parseInt(params.get("limit").toString()) : 15;
|
||||
int status = params.containsKey("status") ? Integer.parseInt(params.get("status").toString()) : 0;
|
||||
String day = params.containsKey("day") ? params.get("day").toString() : "";
|
||||
|
||||
// 查询工人的订单日志
|
||||
OrderLog queryLog = new OrderLog();
|
||||
queryLog.setWorkerId(userId);
|
||||
queryLog.setType(new BigDecimal("2.0")); // type=2 的数据
|
||||
|
||||
// 执行分页查询
|
||||
PageHelper.startPage(page, limit);
|
||||
List<OrderLog> orderLogs = orderLogService.selectOrderLogList(queryLog);
|
||||
PageInfo<OrderLog> pageInfo = new PageInfo<>(orderLogs);
|
||||
|
||||
// 构建返回数据
|
||||
List<Map<String, Object>> resultList = new ArrayList<>();
|
||||
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
|
||||
for (OrderLog log : orderLogs) {
|
||||
// 获取订单信息
|
||||
Order order = orderService.selectOrderById(log.getOid());
|
||||
if (order != null) {
|
||||
// 状态筛选
|
||||
boolean statusMatch = false;
|
||||
if (status == 0) {
|
||||
statusMatch = true;
|
||||
} else if (status == 2 && order.getStatus() != null && order.getStatus() == 2L) {
|
||||
statusMatch = true;
|
||||
} else if (status == 3 && order.getStatus() != null && order.getStatus() == 3L) {
|
||||
statusMatch = true;
|
||||
} else if (status == 4 && order.getStatus() != null && order.getStatus() == 5L) {
|
||||
statusMatch = true;
|
||||
} else if (status == 5 && order.getStatus() != null && order.getStatus() == 6L) {
|
||||
statusMatch = true;
|
||||
}
|
||||
// 日期筛选
|
||||
boolean dayMatch = true;
|
||||
if (day != null && !day.trim().isEmpty() && order.getCreatedAt() != null) {
|
||||
String orderDay = sdf.format(order.getCreatedAt());
|
||||
dayMatch = day.equals(orderDay);
|
||||
}
|
||||
if (statusMatch && dayMatch) {
|
||||
Map<String, Object> orderMap = new HashMap<>();
|
||||
// 填充订单基本信息
|
||||
orderMap.put("id", order.getId());
|
||||
orderMap.put("type", order.getType());
|
||||
orderMap.put("main_order_id", order.getMainOrderId());
|
||||
orderMap.put("order_id", order.getOrderId());
|
||||
orderMap.put("transaction_id", order.getTransactionId());
|
||||
orderMap.put("create_type", order.getCreateType());
|
||||
orderMap.put("create_phone", order.getCreatePhone());
|
||||
orderMap.put("uid", order.getUid());
|
||||
orderMap.put("product_id", order.getProductId());
|
||||
orderMap.put("name", order.getName());
|
||||
orderMap.put("phone", order.getPhone());
|
||||
orderMap.put("make_time", order.getMakeTime());
|
||||
orderMap.put("make_hour", order.getMakeHour());
|
||||
orderMap.put("num", order.getNum());
|
||||
orderMap.put("total_price", order.getTotalPrice());
|
||||
orderMap.put("good_price", order.getGoodPrice());
|
||||
orderMap.put("service_price", order.getServicePrice());
|
||||
orderMap.put("pay_price", order.getPayPrice());
|
||||
orderMap.put("coupon_id", order.getCouponId());
|
||||
orderMap.put("deduction", order.getDeduction());
|
||||
orderMap.put("pay_time", order.getPayTime());
|
||||
orderMap.put("status", order.getStatus());
|
||||
orderMap.put("is_pause", order.getIsPause());
|
||||
orderMap.put("mark", order.getMark());
|
||||
orderMap.put("address_id", order.getAddressId());
|
||||
orderMap.put("sku", order.getSku());
|
||||
orderMap.put("worker_id", order.getWorkerId());
|
||||
orderMap.put("first_worker_id", order.getFirstWorkerId());
|
||||
orderMap.put("receive_time", order.getReceiveTime());
|
||||
orderMap.put("is_comment", order.getIsComment());
|
||||
orderMap.put("receive_type", order.getReceiveType());
|
||||
orderMap.put("is_accept", order.getIsAccept());
|
||||
orderMap.put("created_at", order.getCreatedAt());
|
||||
orderMap.put("updated_at", order.getUpdatedAt());
|
||||
orderMap.put("deleted_at", order.getDeletedAt());
|
||||
orderMap.put("log_type", log.getType());
|
||||
|
||||
// 获取地址信息
|
||||
if (order.getAddressId() != null) {
|
||||
UserAddress address = userAddressService.selectUserAddressById(order.getAddressId());
|
||||
if (address != null) {
|
||||
Map<String, Object> addressMap = new HashMap<>();
|
||||
addressMap.put("id", address.getId());
|
||||
addressMap.put("uid", address.getUid());
|
||||
addressMap.put("name", address.getName());
|
||||
addressMap.put("phone", address.getPhone());
|
||||
addressMap.put("latitude", address.getLatitude());
|
||||
addressMap.put("longitude", address.getLongitude());
|
||||
addressMap.put("address_name", address.getAddressName());
|
||||
addressMap.put("address_info", address.getAddressInfo());
|
||||
addressMap.put("info", address.getInfo());
|
||||
addressMap.put("is_default", address.getIsDefault());
|
||||
addressMap.put("created_at", address.getCreatedAt());
|
||||
addressMap.put("updated_at", address.getUpdatedAt());
|
||||
addressMap.put("deleted_at", address.getDeletedAt());
|
||||
orderMap.put("address", addressMap);
|
||||
orderMap.put("address_has", addressMap);
|
||||
}
|
||||
}
|
||||
// 获取商品信息
|
||||
if (order.getProductId() != null) {
|
||||
ServiceGoods product = serviceGoodsService.selectServiceGoodsById(order.getProductId());
|
||||
if (product != null) {
|
||||
Map<String, Object> productMap = new HashMap<>();
|
||||
productMap.put("id", product.getId());
|
||||
productMap.put("icon", "https://img.huafurenjia.cn/"+product.getIcon());
|
||||
productMap.put("title", product.getTitle());
|
||||
productMap.put("price", product.getPrice());
|
||||
productMap.put("sku_type", product.getSkuType());
|
||||
productMap.put("price_zn", product.getPriceZn());
|
||||
orderMap.put("product", productMap);
|
||||
}
|
||||
}
|
||||
resultList.add(orderMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 构建分页数据
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("current_page", pageInfo.getPageNum());
|
||||
data.put("data", resultList);
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("data", data);
|
||||
return AjaxResult.success(result);
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("获取工人订单列表失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取师傅工作台统计数据
|
||||
* 返回格式见json.txt
|
||||
*/
|
||||
@GetMapping("/api/worker/stat")
|
||||
public AjaxResult getWorkerStat(HttpServletRequest request) {
|
||||
try {
|
||||
// 1. 校验token并获取用户
|
||||
String token = request.getHeader("token");
|
||||
Map<String, Object> userValidation = AppletLoginUtil.validateUserToken(token, usersService);
|
||||
if (!(Boolean) userValidation.get("valid")) {
|
||||
return AppletControllerUtil.appletUnauthorized();
|
||||
}
|
||||
Users user = (Users) userValidation.get("user");
|
||||
if (user == null) {
|
||||
return AppletControllerUtil.appletWarning("用户信息获取失败");
|
||||
}
|
||||
// 2. 查询config_one配置
|
||||
SiteConfig configQuery = new SiteConfig();
|
||||
configQuery.setName("config_one");
|
||||
List<SiteConfig> configList = siteConfigService.selectSiteConfigList(configQuery);
|
||||
Object configObj = null;
|
||||
if (configList != null && !configList.isEmpty()) {
|
||||
String configValue = configList.get(0).getValue();
|
||||
if (configValue != null && !configValue.trim().isEmpty()) {
|
||||
configObj = com.alibaba.fastjson2.JSONObject.parse(configValue);
|
||||
}
|
||||
}
|
||||
// 3. 判断今日是否签到
|
||||
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
|
||||
String todayStr = sdf.format(new java.util.Date());
|
||||
com.ruoyi.system.domain.WorkerSign signQuery = new com.ruoyi.system.domain.WorkerSign();
|
||||
signQuery.setUid(String.valueOf(user.getId()));
|
||||
signQuery.setTime(sdf.parse(todayStr));
|
||||
boolean signed = false;
|
||||
java.util.List<com.ruoyi.system.domain.WorkerSign> signList = workerSignService.selectWorkerSignList(signQuery);
|
||||
if (signList != null && !signList.isEmpty()) {
|
||||
signed = true;
|
||||
}
|
||||
// 4. 构建user数据
|
||||
Map<String, Object> userMap = buildUserInfoResponse(user);
|
||||
// 5. 构建返回结构
|
||||
java.util.Map<String, Object> data = new java.util.HashMap<>();
|
||||
data.put("day_count", 0);
|
||||
data.put("mouth_count", 0);
|
||||
data.put("income", 0);
|
||||
data.put("user", userMap);
|
||||
data.put("sign", signed);
|
||||
data.put("config", configObj);
|
||||
java.util.Map<String, Object> result = new java.util.HashMap<>();
|
||||
result.put("code", 200);
|
||||
result.put("msg", "OK");
|
||||
result.put("data", data);
|
||||
return AjaxResult.success(result);
|
||||
} catch (Exception e) {
|
||||
return AppletControllerUtil.appletError("获取师傅统计数据失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 师傅端订单详情接口
|
||||
* 返回结构见json.txt
|
||||
*/
|
||||
@GetMapping("/api/worker/order/info/{id}")
|
||||
public AjaxResult getWorkerOrderInfo(@PathVariable("id") Long id, HttpServletRequest request) {
|
||||
try {
|
||||
// 1. 校验token并获取师傅信息
|
||||
String token = request.getHeader("token");
|
||||
Map<String, Object> userValidation = AppletLoginUtil.validateUserToken(token, usersService);
|
||||
if (!(Boolean) userValidation.get("valid")) {
|
||||
return AppletControllerUtil.appletUnauthorized();
|
||||
}
|
||||
Users worker = (Users) userValidation.get("user");
|
||||
if (worker == null) {
|
||||
return AppletControllerUtil.appletWarning("用户信息获取失败");
|
||||
}
|
||||
// 2. 查询订单
|
||||
Order order = orderService.selectOrderById(id);
|
||||
if (order == null) {
|
||||
return AppletControllerUtil.appletWarning("订单不存在");
|
||||
}
|
||||
// 3. 查询用户信息
|
||||
Users user = usersService.selectUsersById(order.getUid());
|
||||
// 4. 查询地址信息
|
||||
UserAddress address = null;
|
||||
if (order.getAddressId() != null) {
|
||||
address = userAddressService.selectUserAddressById(order.getAddressId());
|
||||
}
|
||||
// 5. 查询商品信息
|
||||
ServiceGoods product = null;
|
||||
if (order.getProductId() != null) {
|
||||
product = serviceGoodsService.selectServiceGoodsById(order.getProductId());
|
||||
}
|
||||
// 6. 查询订单日志
|
||||
OrderLog logQuery = new OrderLog();
|
||||
logQuery.setOid(order.getId());
|
||||
List<OrderLog> logList = orderLogService.selectOrderLogList(logQuery);
|
||||
List<Map<String, Object>> logArr = new ArrayList<>();
|
||||
for (OrderLog log : logList) {
|
||||
Map<String, Object> logMap = new HashMap<>();
|
||||
logMap.put("id", log.getId());
|
||||
logMap.put("oid", log.getOid());
|
||||
logMap.put("order_id", log.getOrderId());
|
||||
logMap.put("log_order_id", log.getLogOrderId());
|
||||
logMap.put("title", log.getTitle());
|
||||
logMap.put("type", log.getType());
|
||||
// content字段为json字符串,需转为对象
|
||||
Object contentObj = null;
|
||||
try {
|
||||
if (log.getContent() != null) {
|
||||
contentObj = com.alibaba.fastjson2.JSONObject.parse(log.getContent());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
contentObj = log.getContent();
|
||||
}
|
||||
logMap.put("content", contentObj);
|
||||
logMap.put("deposit", log.getDeposit());
|
||||
logMap.put("dep_paid", log.getDepPaid());
|
||||
logMap.put("dep_pay_time", log.getDepPayTime());
|
||||
logMap.put("dep_log_id", log.getDepLogId());
|
||||
logMap.put("price", log.getPrice());
|
||||
logMap.put("paid", log.getPaid());
|
||||
logMap.put("pay_time", log.getPayTime());
|
||||
logMap.put("log_id", log.getLogId());
|
||||
logMap.put("worker_id", log.getWorkerId());
|
||||
logMap.put("first_worker_id", log.getFirstWorkerId());
|
||||
logMap.put("give_up", log.getGiveUp());
|
||||
logMap.put("worker_cost", log.getWorkerCost());
|
||||
logMap.put("reduction_price", log.getReductionPrice());
|
||||
logMap.put("is_pause", log.getIsPause());
|
||||
logMap.put("coupon_id", log.getCouponId());
|
||||
logMap.put("deduction", log.getDeduction());
|
||||
logMap.put("worker_log_id", log.getWorkerLogId());
|
||||
logMap.put("created_at", log.getCreatedAt());
|
||||
logMap.put("updated_at", log.getUpdatedAt());
|
||||
logMap.put("deleted_at", log.getDeletedAt());
|
||||
logArr.add(logMap);
|
||||
}
|
||||
// 7. 构建返回数据
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("id", order.getId());
|
||||
data.put("type", order.getType());
|
||||
data.put("main_order_id", order.getMainOrderId());
|
||||
data.put("order_id", order.getOrderId());
|
||||
data.put("transaction_id", order.getTransactionId());
|
||||
data.put("create_type", order.getCreateType());
|
||||
data.put("create_phone", order.getCreatePhone());
|
||||
data.put("uid", order.getUid());
|
||||
data.put("product_id", order.getProductId());
|
||||
data.put("name", order.getName());
|
||||
data.put("phone", order.getPhone());
|
||||
data.put("address", address);
|
||||
data.put("make_time", order.getMakeTime());
|
||||
data.put("make_hour", order.getMakeHour());
|
||||
data.put("num", order.getNum());
|
||||
data.put("total_price", order.getTotalPrice());
|
||||
data.put("good_price", order.getGoodPrice());
|
||||
data.put("service_price", order.getServicePrice());
|
||||
data.put("pay_price", order.getPayPrice());
|
||||
data.put("coupon_id", order.getCouponId());
|
||||
data.put("deduction", order.getDeduction());
|
||||
data.put("pay_time", order.getPayTime());
|
||||
data.put("status", order.getStatus());
|
||||
data.put("is_pause", order.getIsPause());
|
||||
data.put("mark", order.getMark());
|
||||
data.put("address_id", order.getAddressId());
|
||||
data.put("sku", order.getSku());
|
||||
data.put("worker_id", order.getWorkerId());
|
||||
data.put("first_worker_id", order.getFirstWorkerId());
|
||||
data.put("receive_time", order.getReceiveTime());
|
||||
data.put("is_comment", order.getIsComment());
|
||||
data.put("receive_type", order.getReceiveType());
|
||||
data.put("is_accept", order.getIsAccept());
|
||||
data.put("middle_phone", order.getMiddlePhone());
|
||||
data.put("user_phone", order.getUserPhone());
|
||||
data.put("worker_phone", order.getWorkerPhone());
|
||||
data.put("address_en", order.getAddressEn());
|
||||
data.put("uid_admin", order.getUidAdmin());
|
||||
data.put("address_admin", order.getAddressAdmin());
|
||||
data.put("log_status", order.getLogStatus());
|
||||
data.put("log_json", order.getLogJson());
|
||||
data.put("json_status", order.getJsonStatus());
|
||||
data.put("log_images", order.getLogImages());
|
||||
data.put("created_at", order.getCreatedAt());
|
||||
data.put("updated_at", order.getUpdatedAt());
|
||||
data.put("deleted_at", order.getDeletedAt());
|
||||
data.put("phone_xx", order.getPhone()); // 可脱敏处理
|
||||
data.put("user", user);
|
||||
data.put("product", product);
|
||||
data.put("log", logArr);
|
||||
return AjaxResult.success(data);
|
||||
} catch (Exception e) {
|
||||
return AppletControllerUtil.appletError("查询师傅订单详情失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue