1055 lines
43 KiB
Java
1055 lines
43 KiB
Java
package com.ruoyi.system.controller;
|
||
|
||
import java.math.BigDecimal;
|
||
import java.util.*;
|
||
import javax.servlet.http.HttpServletResponse;
|
||
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import com.ruoyi.common.utils.StringUtils;
|
||
import com.ruoyi.system.ControllerUtil.*;
|
||
import com.ruoyi.system.domain.*;
|
||
import com.ruoyi.system.service.*;
|
||
import com.winnerlook.model.VoiceResponseResult;
|
||
import org.springframework.security.access.prepost.PreAuthorize;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.web.bind.annotation.GetMapping;
|
||
import org.springframework.web.bind.annotation.PostMapping;
|
||
import org.springframework.web.bind.annotation.PutMapping;
|
||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||
import org.springframework.web.bind.annotation.PathVariable;
|
||
import org.springframework.web.bind.annotation.RequestBody;
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
import org.springframework.web.bind.annotation.RestController;
|
||
import com.ruoyi.common.annotation.Log;
|
||
import com.ruoyi.common.core.controller.BaseController;
|
||
import com.ruoyi.common.core.domain.AjaxResult;
|
||
import com.ruoyi.common.enums.BusinessType;
|
||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||
import com.ruoyi.common.core.page.TableDataInfo;
|
||
import com.ruoyi.system.service.ISysUserService;
|
||
import com.ruoyi.system.service.IServiceGoodsService;
|
||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||
import com.ruoyi.system.domain.ServiceGoods;
|
||
|
||
/**
|
||
* 服务订单Controller
|
||
*
|
||
* @author ruoyi
|
||
* @date 2025-05-13
|
||
*/
|
||
@RestController
|
||
@RequestMapping("/system/Order")
|
||
public class OrderController extends BaseController {
|
||
@Autowired
|
||
private IOrderService orderService;
|
||
@Autowired
|
||
private IServiceGoodsService serviceGoodsService;
|
||
|
||
@Autowired
|
||
private IUsersPayBeforService usersPayBeforService;
|
||
|
||
|
||
@Autowired
|
||
IUsersService usersService;
|
||
@Autowired
|
||
IOrderCallService orderCallService;
|
||
@Autowired
|
||
IOrderCommentService orderCommentService;
|
||
@Autowired
|
||
IOrderSoundLogService orderSoundLogService;
|
||
@Autowired
|
||
IOrderSoundService orderSoundService;
|
||
@Autowired
|
||
IUserAddressService userAddressService;
|
||
|
||
|
||
@Autowired
|
||
IOrderLogService orderLogService;
|
||
@Autowired
|
||
INotifyOrderService notifyOrderService;
|
||
@Autowired
|
||
private ISysUserService sysUserService;
|
||
|
||
/**
|
||
* 查询服务订单列表
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:list')")
|
||
@GetMapping("/list")
|
||
public TableDataInfo list(Order order) {
|
||
startPage();
|
||
List<Order> list = orderService.selectOrderList(order);
|
||
for (Order orderdata : list) {
|
||
|
||
ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(orderdata.getProductId());
|
||
if (serviceGoods != null) {
|
||
orderdata.setProductName(serviceGoods.getTitle());
|
||
}
|
||
Users users = usersService.selectUsersById(orderdata.getUid());
|
||
if (users != null) {
|
||
orderdata.setUname(users.getName());
|
||
}
|
||
orderdata.setThjl(orderCallService.selectCountOrderCallByOid(orderdata.getId()));
|
||
orderdata.setFwpj(orderCommentService.selectCountOrderCommentByOid(orderdata.getOrderId()));
|
||
orderdata.setLywj(orderSoundService.selectCountOrderSoundByOid(orderdata.getId()));
|
||
orderdata.setJdjl(orderLogService.selectCountOrderLogByOrderId(orderdata.getOrderId()));
|
||
orderdata.setTzjl(notifyOrderService.selectNotifyOrderCountByOid(orderdata.getId()));
|
||
|
||
}
|
||
return getDataTable(list);
|
||
}
|
||
|
||
/**
|
||
* 导出服务订单列表
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:export')")
|
||
@Log(title = "服务订单", businessType = BusinessType.EXPORT)
|
||
@PostMapping("/export")
|
||
public void export(HttpServletResponse response, Order order) {
|
||
// 使用导出专用的关联查询,一次性获取所有数据包括关联信息
|
||
List<Order> list = orderService.selectOrderListForExport(order);
|
||
ExcelUtil<Order> util = new ExcelUtil<Order>(Order.class);
|
||
util.exportExcel(response, list, "服务订单数据");
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取服务订单详细信息
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping(value = "/{id}")
|
||
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
||
Order order = orderService.selectOrderById(id);
|
||
if (order != null){
|
||
order.setOrderLog(new OrderLog());
|
||
}
|
||
|
||
return success(order);
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取服务订单详细信息
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping(value = "generateCode")
|
||
public AjaxResult generateCode() {
|
||
return success(OrderUtil.generateCode());
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/**
|
||
* 新增服务订单
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:add')")
|
||
@Log(title = "服务订单", businessType = BusinessType.INSERT)
|
||
@PostMapping
|
||
public AjaxResult add(@RequestBody Order order) {
|
||
Order orderdata=new Order();
|
||
|
||
Users users = usersService.selectUsersById(order.getUid());
|
||
if (users == null){
|
||
return error("用户不能为空");
|
||
}
|
||
UserAddress userAddress = userAddressService.selectUserAddressById(order.getAddressId());
|
||
if (userAddress == null){
|
||
return error("地址不能为空");
|
||
}
|
||
ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId());
|
||
if (serviceGoods == null){
|
||
return error("服务不能为空");
|
||
}
|
||
|
||
orderdata.setType(1);
|
||
orderdata.setMainOrderId(GenerateCustomCode.generCreateOrder("HT"));
|
||
orderdata.setOrderId(GenerateCustomCode.generCreateOrder("SE"));
|
||
orderdata.setCreateType(1);
|
||
orderdata.setCreatePhone(users.getPhone());
|
||
orderdata.setUid(users.getId());
|
||
orderdata.setProductId(serviceGoods.getId());
|
||
orderdata.setName(userAddress.getName());
|
||
orderdata.setPhone(userAddress.getPhone());
|
||
orderdata.setAddress(userAddress.getAddressName());
|
||
orderdata.setMakeTime(order.getMakeTime());
|
||
orderdata.setMakeHour(order.getMakeHour());
|
||
orderdata.setNum(order.getNum());
|
||
orderdata.setTotalPrice(new BigDecimal(0));
|
||
orderdata.setGoodPrice(new BigDecimal(0));
|
||
orderdata.setPayPrice(new BigDecimal(0));
|
||
orderdata.setDeduction(new BigDecimal(0));
|
||
orderdata.setStatus(1L);
|
||
orderdata.setIsPause(1);
|
||
orderdata.setMark(order.getMark());
|
||
orderdata.setAddressId(userAddress.getId());
|
||
orderdata.setSku(order.getSku());
|
||
//orderdata.setReceiveTime();
|
||
orderdata.setIsComment(0);
|
||
orderdata.setReceiveType(3L);
|
||
orderdata.setIsAccept(0);
|
||
orderdata.setUidAdmin(String.valueOf(users.getId()));
|
||
orderdata.setAddressAdmin(String.valueOf(userAddress.getId()));
|
||
orderdata.setLogStatus(9);
|
||
JSONObject logJson=new JSONObject();
|
||
logJson.put("type",9);
|
||
orderdata.setLogJson(logJson.toJSONString());
|
||
orderdata.setJsonStatus(0);
|
||
orderdata.setFileData(order.getFileData());
|
||
orderdata.setOdertype(0);
|
||
orderdata.setReamk(order.getReamk());
|
||
orderdata.setBigtype(1);
|
||
orderdata.setAddressEn(userAddress.getAddressName());
|
||
//添加订单日志记录
|
||
int flg= orderService.insertOrder(orderdata);
|
||
if (flg>0){
|
||
|
||
// 添加订单日志
|
||
OrderLog orderLog = new OrderLog();
|
||
orderLog.setOid(orderdata.getId());
|
||
orderLog.setOrderId(orderdata.getOrderId());
|
||
orderLog.setTitle("订单生成");
|
||
orderLog.setType(BigDecimal.valueOf(1.0));
|
||
com.alibaba.fastjson2.JSONObject jsonObject = new com.alibaba.fastjson2.JSONObject();
|
||
jsonObject.put("name", "后台订单创建成功");
|
||
orderLog.setContent(jsonObject.toJSONString());
|
||
orderLogService.insertOrderLog(orderLog);
|
||
|
||
}
|
||
|
||
return success("操作成功");
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* 获取服务订单详细信息
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping(value = "/selectBaseProjectList/{id}")
|
||
public AjaxResult selectBaseProjectList(@PathVariable("id") Long id) {
|
||
Order order = orderService.selectOrderById(id);
|
||
if (order != null){
|
||
ServiceGoods serviceGoods=serviceGoodsService.selectServiceGoodsById(order.getProductId());
|
||
if(serviceGoods!=null){
|
||
return success(serviceGoods);
|
||
}else{
|
||
return error();
|
||
}
|
||
}else{
|
||
return error();
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* 修改服务订单
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@Log(title = "服务订单", businessType = BusinessType.UPDATE)
|
||
@PutMapping
|
||
public AjaxResult edit(@RequestBody Order order) {
|
||
//插入订单日志记录
|
||
OrderUtil orderUtil = new OrderUtil();
|
||
Order oldorder=orderService.selectOrderById(order.getId());
|
||
//验证订单状态
|
||
VerificationResult verificationResult = orderUtil.validateOrderStatusChange(order, oldorder);
|
||
if (verificationResult.getCode().equals(VerificationResult.CODE_SUCCESS)){
|
||
|
||
//特殊情况,状态不变的情况下,不插入日志记录
|
||
if (!verificationResult.getData().equals("NODATA")){
|
||
//开始服务,需要给order做标记
|
||
orderUtil.SaveOrderLog(order);
|
||
}else{
|
||
if(!order.getStatus().equals(oldorder.getStatus())){
|
||
orderUtil.SaveOrderLog(order);
|
||
}
|
||
}
|
||
return toAjax(orderService.updateOrder(order));
|
||
}else{
|
||
return error(verificationResult.getData());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 删除服务订单
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:remove')")
|
||
@Log(title = "服务订单", businessType = BusinessType.DELETE)
|
||
@DeleteMapping("/{ids}")
|
||
public AjaxResult remove(@PathVariable Long[] ids) {
|
||
return toAjax(orderService.deleteOrderByIds(ids));
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取订单接单记录
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping("/receive-records/{orderId}")
|
||
public AjaxResult getReceiveRecords(@PathVariable("orderId") String orderId) {
|
||
System.out.println("=== 获取接单记录 ===");
|
||
System.out.println("订单ID: " + orderId);
|
||
|
||
List<OrderLog> list = orderLogService.selectOrderLogByOrderIdASC(orderId);
|
||
System.out.println("查询到的日志记录数量: " + (list != null ? list.size() : "null"));
|
||
|
||
if (list != null && !list.isEmpty()) {
|
||
System.out.println("第一条记录: " + list.get(0));
|
||
for (OrderLog orderLogdata : list) {
|
||
System.out.println("处理日志记录: ID=" + orderLogdata.getId() + ", 标题=" + orderLogdata.getTitle());
|
||
if (orderLogdata.getWorkerId() != null) {
|
||
Users users = usersService.selectUsersById(orderLogdata.getWorkerId());
|
||
if (users != null) {
|
||
orderLogdata.setWorkerName(users.getName());
|
||
System.out.println("设置师傅姓名: " + users.getName());
|
||
} else {
|
||
System.out.println("未找到师傅信息,workerId: " + orderLogdata.getWorkerId());
|
||
}
|
||
} else {
|
||
System.out.println("日志记录没有师傅ID");
|
||
}
|
||
}
|
||
} else {
|
||
System.out.println("没有找到订单日志记录");
|
||
}
|
||
|
||
return success(list);
|
||
}
|
||
|
||
// /**
|
||
// * 获取订单通话记录
|
||
// */
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping("/call-records/{orderId}")
|
||
public AjaxResult getCallRecords(@PathVariable("orderId") String orderId) {
|
||
Order data = orderService.selectOrderByOrderId(orderId);
|
||
;
|
||
if (data != null) {
|
||
return success(orderCallService.selectOrderCallByOid(data.getId()));
|
||
} else {
|
||
return AjaxResult.error("订单不存在");
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 获取订单录音文件
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping("/audio-records/{orderId}")
|
||
public AjaxResult getAudioRecords(@PathVariable("orderId") String orderId) {
|
||
Order data = orderService.selectOrderByOrderId(orderId);
|
||
;
|
||
if (data != null) {
|
||
List<OrderSound> list = orderSoundService.selectOrderSoundByOid(data.getId());
|
||
for (OrderSound orderSounddata : list) {
|
||
orderSounddata.setFile("https://img.huafurenjia.cn/" + orderSounddata.getFile());
|
||
// https://img.huafurenjia.cn/
|
||
Users users = usersService.selectUsersById(orderSounddata.getWorkerUid());
|
||
Order order = orderService.selectOrderById(orderSounddata.getOid());
|
||
if (users != null) {
|
||
orderSounddata.setWorkerName(users.getName());
|
||
}
|
||
if (order != null) {
|
||
orderSounddata.setOcode(order.getOrderId());
|
||
}
|
||
}
|
||
return success(list);
|
||
} else {
|
||
return AjaxResult.error("订单不存在");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取订单通知记录
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping("/notify-records/{orderId}")
|
||
public AjaxResult getNotifyRecords(@PathVariable("orderId") String orderId) {
|
||
Order data = orderService.selectOrderByOrderId(orderId);
|
||
;
|
||
if (data != null) {
|
||
return success(notifyOrderService.selectNotifyOrderByOid(data.getId()));
|
||
} else {
|
||
return AjaxResult.error("订单不存在");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取订单通知记录
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping("/comment-records/{orderId}")
|
||
public AjaxResult getCommentRecords(@PathVariable("orderId") String orderId) {
|
||
Order data = orderService.selectOrderByOrderId(orderId);
|
||
;
|
||
if (data != null) {
|
||
List<OrderComment> list = orderCommentService.selectOrderCommentByOid(data.getOrderId());
|
||
for (OrderComment orderCommentdata : list) {
|
||
Users users = usersService.selectUsersById(orderCommentdata.getUid());
|
||
if (users != null) {
|
||
orderCommentdata.setUname(users.getName());
|
||
}
|
||
}
|
||
return success(list);
|
||
} else {
|
||
return AjaxResult.error("订单不存在");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取用户下拉列表
|
||
*/
|
||
@GetMapping("/userOptions")
|
||
public AjaxResult getUserOptions() {
|
||
List<SysUser> users = sysUserService.selectUserList(new SysUser());
|
||
return AjaxResult.success(users);
|
||
}
|
||
|
||
/**
|
||
* 获取商品下拉列表
|
||
*/
|
||
@GetMapping("/serviceGoodsOptions")
|
||
public AjaxResult getServiceGoodsOptions() {
|
||
List<ServiceGoods> goods = serviceGoodsService.selectServiceGoodsList(new ServiceGoods());
|
||
return AjaxResult.success(goods);
|
||
}
|
||
|
||
/**
|
||
* 派单接口
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@Log(title = "订单派单", businessType = BusinessType.UPDATE)
|
||
@PostMapping("/dispatch")
|
||
public AjaxResult dispatch(@RequestBody Map<String, Object> params) {
|
||
try {
|
||
Long orderId = Long.valueOf(params.get("orderId").toString());
|
||
Integer receiveType = Integer.valueOf(params.get("receiveType").toString());
|
||
Long workerId = null;
|
||
if (params.get("workerId") != null) {
|
||
workerId = Long.valueOf(params.get("workerId").toString());
|
||
}
|
||
// 查询师傅
|
||
Users users = usersService.selectUsersById(workerId);
|
||
if (users == null) {
|
||
return error("工人不存在");
|
||
}
|
||
|
||
// 查询订单
|
||
Order order = orderService.selectOrderById(orderId);
|
||
if (order == null) {
|
||
return error("订单不存在");
|
||
}
|
||
|
||
// 验证订单状态
|
||
if (order.getStatus() != 1) {
|
||
return error("只有待接单状态的订单才能派单");
|
||
}
|
||
//给师傅派单的时候的推送
|
||
ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId());
|
||
WXsendMsgUtil.sendMsgForWorkerInfo(users.getOpenid(), order, serviceGoods);
|
||
DispatchUtil.creatWorkerForOrder(order,users);
|
||
//
|
||
// // 更新订单的派单类型
|
||
// order.setReceiveType(receiveType.longValue());
|
||
//
|
||
// // 如果是指定工人,需要验证工人信息
|
||
// if (receiveType == 3 && workerId != null) {
|
||
// // 这里可以添加工人验证逻辑
|
||
// // 暂时跳过工人验证
|
||
// }
|
||
//
|
||
// // 更新订单状态为待服务
|
||
// order.setStatus(2L);
|
||
|
||
return toAjax(1);
|
||
} catch (Exception e) {
|
||
return error("派单失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取可派单工人列表
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:query')")
|
||
@GetMapping("/getCanDoWorkerList")
|
||
public TableDataInfo getCanDoWorkerList(Users users) {
|
||
startPage();
|
||
List<Users> list = usersService.selectUsersList(users);
|
||
return getDataTable(list);
|
||
}
|
||
|
||
/**
|
||
* 获取所有工人列表(用于订单处理)
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@GetMapping("/getWorkerList")
|
||
public AjaxResult getWorkerList() {
|
||
Users users = new Users();
|
||
users.setType("2"); // 工人类型
|
||
List<Users> list = usersService.selectUsersList(users);
|
||
return AjaxResult.success(list);
|
||
}
|
||
|
||
/**
|
||
* 更换师傅接口
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@Log(title = "更换师傅", businessType = BusinessType.UPDATE)
|
||
@PostMapping("/change-worker")
|
||
public AjaxResult changeWorker(@RequestBody Map<String, Object> params) {
|
||
try {
|
||
String orderId = params.get("orderId").toString();
|
||
|
||
// 这里调用具体的业务逻辑,您来实现
|
||
// 例如:调用DispatchUtil进行重新派单
|
||
|
||
return success("更换师傅成功");
|
||
} catch (Exception e) {
|
||
return error("更换师傅失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 接单接口
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@Log(title = "订单接单", businessType = BusinessType.UPDATE)
|
||
@PostMapping("/accept-order")
|
||
public AjaxResult acceptOrder(@RequestBody Map<String, Object> params) {
|
||
try {
|
||
String orderId = params.get("orderId").toString();
|
||
// Long workerId = null;
|
||
// if (params.get("workerId") != null) {
|
||
// workerId = Long.valueOf(params.get("workerId").toString());
|
||
// }
|
||
|
||
// 2. 查询订单
|
||
Order order = orderService.selectOrderByOrderId(orderId);
|
||
if (order == null) {
|
||
return error("订单不存在");
|
||
}
|
||
Long workerId =order.getWorkerId();
|
||
// 如果没有传递workerId,使用订单中的workerId
|
||
// if (workerId == null) {
|
||
// workerId = order.getWorkerId();
|
||
// }
|
||
|
||
if (workerId == null) {
|
||
return error("订单未分配师傅,无法接单");
|
||
}
|
||
|
||
Users worker = usersService.selectUsersById(workerId);
|
||
if (worker == null) {
|
||
return error("工人不存在");
|
||
}
|
||
|
||
// 3. 验证订单状态(允许状态1和2的订单接单)
|
||
if (order.getStatus() == null || (order.getStatus() != 1L && order.getStatus() != 2L)) {
|
||
return error("当前订单状态不可接单,只有待支付或待服务状态的订单才能接单");
|
||
}
|
||
|
||
// 4. 设置接单相关字段
|
||
order.setWorkerId(worker.getId());
|
||
order.setWorkerPhone(worker.getPhone());
|
||
order.setIsPause(1); // 1:未暂停
|
||
order.setReceiveType(3L); // 3:平台派单
|
||
order.setReceiveTime(new Date());
|
||
order.setIsAccept(1); // 1:已接单
|
||
order.setJsonStatus(2); // 服务进度:2=接单
|
||
order.setStatus(2L); // 设置为待服务状态
|
||
order.setLogStatus(9);
|
||
|
||
com.alibaba.fastjson2.JSONObject json = new com.alibaba.fastjson2.JSONObject();
|
||
json.put("type", 1);
|
||
order.setLogJson(json.toJSONString());
|
||
|
||
// 更新订单
|
||
int updateResult = orderService.updateOrder(order);
|
||
if (updateResult <= 0) {
|
||
return error("更新订单失败");
|
||
}
|
||
|
||
// 5. 写入日志
|
||
OrderLog orderLog = new OrderLog();
|
||
orderLog.setOid(order.getId());
|
||
orderLog.setOrderId(order.getOrderId());
|
||
orderLog.setTitle("师傅接单");
|
||
orderLog.setType(new BigDecimal(2.0));
|
||
orderLog.setCreatedAt(new Date());
|
||
|
||
com.alibaba.fastjson2.JSONObject logContent = new com.alibaba.fastjson2.JSONObject();
|
||
logContent.put("name", "同意系统配单");
|
||
orderLog.setContent(logContent.toJSONString());
|
||
orderLog.setWorkerId(order.getWorkerId());
|
||
orderLog.setWorkerLogId(order.getWorkerId());
|
||
|
||
int logResult = orderLogService.insertOrderLog(orderLog);
|
||
if (logResult <= 0) {
|
||
return error("记录接单日志失败");
|
||
}
|
||
|
||
// 6. 绑定号码(如果有相关工具类)
|
||
try {
|
||
Map<String, Object> bindmap = OrderBindWorkerUtil.getOrderBindWorker(order.getId());
|
||
// 这里可以处理绑定结果
|
||
} catch (Exception e) {
|
||
// 绑定失败不影响接单流程
|
||
System.out.println("绑定号码失败:" + e.getMessage());
|
||
}
|
||
|
||
return success("接单成功");
|
||
} catch (Exception e) {
|
||
return error("接单失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 出发上门接口
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@Log(title = "出发上门", businessType = BusinessType.UPDATE)
|
||
@PostMapping("/departure")
|
||
public AjaxResult departure(@RequestBody Map<String, Object> params) {
|
||
try {
|
||
// 参数验证
|
||
if (params == null || params.isEmpty()) {
|
||
return error("请求参数不能为空");
|
||
}
|
||
|
||
String orderId = params.get("orderId") != null ? params.get("orderId").toString() : null;
|
||
if (orderId == null || orderId.trim().isEmpty()) {
|
||
return error("订单号不能为空");
|
||
}
|
||
|
||
// 查询订单信息
|
||
Order order = orderService.selectOrderByOrderId(orderId);
|
||
if (order == null) {
|
||
return error("订单不存在");
|
||
}
|
||
|
||
// 验证订单状态(只有已接单状态的订单才能出发上门)
|
||
if (order.getStatus() == null || order.getStatus() != 2L) {
|
||
return error("当前订单状态不可出发上门,只有已接单状态的订单才能出发上门");
|
||
}
|
||
|
||
// 验证是否已分配师傅
|
||
if (order.getWorkerId() == null) {
|
||
return error("订单未分配师傅,无法出发上门");
|
||
}
|
||
|
||
// 验证师傅是否已接单
|
||
if (order.getIsAccept() == null || order.getIsAccept() != 1) {
|
||
return error("师傅未接单,无法出发上门");
|
||
}
|
||
|
||
|
||
// if (order.getStatus() == null || order.getStatus() != 2L) {
|
||
// return AppletControllerUtil.appletWarning("订单状态不正确");
|
||
// }
|
||
// if (order.getJsonStatus() == null || order.getJsonStatus() != 3) {
|
||
// return AppletControllerUtil.appletWarning("订单进度不正确");
|
||
// }
|
||
|
||
order.setJsonStatus(4); // 出发上门
|
||
com.alibaba.fastjson2.JSONObject typeJson = new com.alibaba.fastjson2.JSONObject();
|
||
typeJson.put("type", 3);
|
||
order.setLogJson(typeJson.toJSONString());
|
||
// 5. 保存
|
||
orderService.updateOrder(order);
|
||
// 4. 写订单日志
|
||
OrderLog orderLog = new OrderLog();
|
||
orderLog.setOid(order.getId());
|
||
orderLog.setOrderId(order.getOrderId());
|
||
orderLog.setWorkerId(order.getWorkerId());
|
||
orderLog.setWorkerLogId(order.getWorkerId());
|
||
orderLog.setTitle("出发上门");
|
||
com.alibaba.fastjson2.JSONObject typeJson1 = new com.alibaba.fastjson2.JSONObject();
|
||
typeJson1.put("name", "师傅收到派单信息准备出发");
|
||
orderLog.setType(new BigDecimal("3.0"));
|
||
orderLog.setContent(typeJson1.toJSONString());
|
||
orderLogService.insertOrderLog(orderLog);
|
||
ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId());
|
||
Users user=usersService.selectUsersById(order.getUid());
|
||
//小程序推送给用户师傅已经出发
|
||
WXsendMsgUtil.sendStartDoorMoney(user.getOpenid(), order, serviceGoods);
|
||
|
||
return success("出发上门成功");
|
||
} catch (Exception e) {
|
||
return error("出发上门失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 确认到达接口
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@Log(title = "确认到达", businessType = BusinessType.UPDATE)
|
||
@PostMapping("/confirm-arrival")
|
||
public AjaxResult confirmArrival(@RequestBody Map<String, Object> params) {
|
||
try {
|
||
// 参数验证
|
||
if (params == null || params.isEmpty()) {
|
||
return error("请求参数不能为空");
|
||
}
|
||
|
||
String orderId = params.get("orderId") != null ? params.get("orderId").toString() : null;
|
||
if (orderId == null || orderId.trim().isEmpty()) {
|
||
return error("订单号不能为空");
|
||
}
|
||
|
||
// 查询订单信息
|
||
Order order = orderService.selectOrderByOrderId(orderId);
|
||
if (order == null) {
|
||
return error("订单不存在");
|
||
}
|
||
|
||
// 验证订单状态(只有已出发上门状态的订单才能确认到达)
|
||
if (order.getStatus() == null || order.getStatus() != 2L) {
|
||
return error("当前订单状态不可确认到达,只有已出发上门状态的订单才能确认到达");
|
||
}
|
||
|
||
// 验证是否已分配师傅
|
||
if (order.getWorkerId() == null) {
|
||
return error("订单未分配师傅,无法确认到达");
|
||
}
|
||
|
||
// 验证师傅是否已接单
|
||
if (order.getIsAccept() == null || order.getIsAccept() != 1) {
|
||
return error("师傅未接单,无法确认到达");
|
||
}
|
||
|
||
// 验证订单进度状态(应该是出发上门状态)
|
||
if (order.getJsonStatus() == null || order.getJsonStatus() != 4) {
|
||
return error("订单进度状态不正确,只有出发上门状态的订单才能确认到达");
|
||
}
|
||
|
||
|
||
order.setJsonStatus(5); // 确认到达
|
||
com.alibaba.fastjson2.JSONObject typeJson = new com.alibaba.fastjson2.JSONObject();
|
||
typeJson.put("type", 4);
|
||
order.setLogJson(typeJson.toJSONString());
|
||
// 6. 保存
|
||
orderService.updateOrder(order);
|
||
// 5. 写订单日志
|
||
//一口价直接开始服务,没有报价的环节
|
||
// if (order.getOdertype()!= 0){
|
||
// OrderLog orderLog = new OrderLog();
|
||
// orderLog.setOid(order.getId());
|
||
// orderLog.setOrderId(order.getOrderId());
|
||
// orderLog.setWorkerId(workerId);
|
||
// orderLog.setLatitude(latitude);
|
||
// orderLog.setLongitude(longitude);
|
||
// orderLog.setAddressName(addressName);
|
||
// orderLog.setWorkerLogId(workerId);
|
||
// orderLog.setTitle("师傅到达");
|
||
// orderLog.setType(new BigDecimal("5.0"));
|
||
// com.alibaba.fastjson2.JSONObject content = new com.alibaba.fastjson2.JSONObject();
|
||
// content.put("name", "师傅到达服务地点,开始服务工作");
|
||
// orderLog.setContent(content.toJSONString());
|
||
// // 6. 保存
|
||
// orderLogService.insertOrderLog(orderLog);
|
||
// ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId());
|
||
// // WXsendMsgUtil.sendMsgForWorkerInfo(user.getOpenid(), order, serviceGoods);
|
||
// return AppletControllerUtil.appletSuccess("师傅已经上门");
|
||
// }
|
||
OrderLog orderLog = new OrderLog();
|
||
orderLog.setOid(order.getId());
|
||
orderLog.setOrderId(order.getOrderId());
|
||
orderLog.setWorkerId(order.getWorkerId());
|
||
orderLog.setWorkerLogId(order.getWorkerId());
|
||
orderLog.setTitle("师傅到达");
|
||
orderLog.setType(new BigDecimal("4.0"));
|
||
com.alibaba.fastjson2.JSONObject content = new com.alibaba.fastjson2.JSONObject();
|
||
content.put("name", "师傅到达服务地点");
|
||
orderLog.setContent(content.toJSONString());
|
||
// 6. 保存
|
||
orderLogService.insertOrderLog(orderLog);
|
||
//解绑订单虚拟号
|
||
//需要解绑原订单上原师傅和客户的虚拟号
|
||
VoiceResponseResult resultObj = YunXinPhoneUtilAPI.httpsPrivacyUnbind(order.getWorkerPhone(), order.getUserPhone(), order.getMiddlePhone());
|
||
if (resultObj.getResult().equals("000000")) {
|
||
// order.setWorkerPhone(null);
|
||
// order.setUserPhone(null);
|
||
// order.setMiddlePhone(null);
|
||
// orderService.updateOrder(order);
|
||
orderService.updateOrderPhone(order.getId());
|
||
} // 4. 更新订单状
|
||
//解绑号码
|
||
YunXinPhoneUtilAPI.httpsPrivacyUnbind(order.getWorkerPhone(), order.getUserPhone(), order.getMiddlePhone());
|
||
// 小程序推送给用户师傅已经到达
|
||
|
||
ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId());
|
||
//师傅到达的时候给客户的微信推送
|
||
Users user = usersService.selectUsersById(order.getUid());
|
||
WXsendMsgUtil.sendWorkerIsComing(user.getOpenid(), order, serviceGoods);
|
||
|
||
return success("确认到达成功");
|
||
} catch (Exception e) {
|
||
return error("确认到达失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 结束订单接口
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@Log(title = "结束订单", businessType = BusinessType.UPDATE)
|
||
@PostMapping("/end-order")
|
||
public AjaxResult endOrder(@RequestBody Map<String, Object> params) {
|
||
try {
|
||
// 参数校验
|
||
if (params == null || params.isEmpty()) {
|
||
return error("请求参数不能为空");
|
||
}
|
||
String orderId = params.get("orderId") != null ? params.get("orderId").toString() : null;
|
||
if (orderId == null || orderId.trim().isEmpty()) {
|
||
return error("订单号不能为空");
|
||
}
|
||
String doorFee=params.get("doorFee") != null ? params.get("doorFee").toString() : null;
|
||
// 查询订单
|
||
Order order = orderService.selectOrderByOrderId(orderId);
|
||
if (order == null) {
|
||
return error("订单不存在");
|
||
}
|
||
RefundUtil refundUtil = new RefundUtil();
|
||
// 3.1 更新订单状态为7(已结束)
|
||
Order updateOrder = new Order();
|
||
updateOrder.setId(order.getId());
|
||
updateOrder.setStatus(7L);
|
||
updateOrder.setServicePrice(new BigDecimal(0));
|
||
updateOrder.setGoodPrice(new BigDecimal(0));
|
||
updateOrder.setTotalPrice(new BigDecimal(0));
|
||
orderService.updateOrder(updateOrder);
|
||
String logOrderId = GenerateCustomCode.generCreateOrder("DSB");
|
||
// 3.2 插入订单日志
|
||
OrderLog log = new OrderLog();
|
||
com.alibaba.fastjson2.JSONObject jsonObject = new com.alibaba.fastjson2.JSONObject();
|
||
//1.1结束订单就要删除客户未支付的付款数据
|
||
UsersPayBefor payBefor = new UsersPayBefor();
|
||
payBefor.setLastorderid(order.getOrderId());
|
||
payBefor.setStatus(1L);
|
||
List<UsersPayBefor> payBeforList = usersPayBeforService.selectUsersPayBeforList(payBefor);
|
||
for (UsersPayBefor payBeforInfo : payBeforList) {
|
||
usersPayBeforService.deleteUsersPayBeforById(payBeforInfo.getId());
|
||
}
|
||
|
||
//1.2如果这个订单有支付数据,还要给客户退回去
|
||
UsersPayBefor userpayBefor = usersPayBeforService.selectUsersPayBeforByOrderId(order.getOrderId());
|
||
if (userpayBefor != null) {
|
||
Users user = usersService.selectUsersById(order.getUid());
|
||
//退回其他对应支付时产生的金额和积分
|
||
BenefitPointsUtil.refundServiceAndConsumption(order.getId(), user, userpayBefor.getServicemoney(),userpayBefor.getShopmoney());
|
||
System.out.println("=== 开始退款处理,2222222222订单号: " + userpayBefor.getStatus() + " ===");
|
||
// if (usersPayBefor.getStatus() == 2){
|
||
System.out.println("=== 开始退款处理,2222222222订单号: " + order.getOrderId() + " ===");
|
||
refundUtil.refundOrder(order.getOrderId());
|
||
// }
|
||
}
|
||
//1.3找到订单日志的报价数据将报价的支付数据给抹除
|
||
OrderLog orderLog = new OrderLog();
|
||
orderLog.setOrderId(order.getOrderId());
|
||
orderLog.setType(new BigDecimal(5));
|
||
List<OrderLog> orderLogList = orderLogService.selectOrderLogList(orderLog);
|
||
if (!orderLogList.isEmpty()) {
|
||
orderLogService.updateOrderLogEnd(orderLogList.getFirst().getId());
|
||
}
|
||
|
||
if (StringUtils.isNotBlank(doorFee)&&!doorFee.equals("0")){
|
||
log.setPaid(1L);
|
||
log.setPrice(new BigDecimal(doorFee));
|
||
jsonObject.put("name","师傅提前结束订单,上门费"+doorFee+"元");
|
||
}else{
|
||
jsonObject.put("name","师傅提前结束订单,无其他费用");
|
||
}
|
||
|
||
log.setLogOrderId(logOrderId);
|
||
log.setOid(order.getId());
|
||
log.setOrderId(order.getOrderId());
|
||
log.setTitle("结束订单");
|
||
log.setType(BigDecimal.valueOf(10));
|
||
log.setContent(jsonObject.toJSONString());
|
||
//Long workerId = getCurrentWorkerId(request); // 需实现
|
||
log.setWorkerId(order.getWorkerId());
|
||
log.setCreatedAt(new Date());
|
||
log.setUpdatedAt(new Date());
|
||
orderLogService.insertOrderLog(log);
|
||
if (StringUtils.isNotBlank(doorFee)){
|
||
BigDecimal totalAmount=log.getPrice();
|
||
Users userinfo = usersService.selectUsersById(order.getUid());
|
||
PayBeforeUtil payBeforeUtil = new PayBeforeUtil();
|
||
payBeforeUtil.createPayBefore(userinfo, totalAmount, logOrderId, log.getId(),
|
||
null, 7L, null, null,
|
||
null, null, null,1L,null,order.getOrderId(), null);
|
||
ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId());
|
||
//微信推送师傅设置上门费
|
||
WXsendMsgUtil.sendMsgForUserDoorMoney(userinfo.getOpenid(), order, serviceGoods);
|
||
}
|
||
|
||
// 3.4 解绑虚拟号
|
||
if (order.getMiddlePhone() != null) {
|
||
VoiceResponseResult unbind = YunXinPhoneUtilAPI.httpsPrivacyUnbind(order.getWorkerPhone(), order.getUserPhone(), order.getMiddlePhone());
|
||
if (unbind.getResult().equals("000000")) {
|
||
orderService.updateOrderPhone(order.getId());
|
||
}
|
||
}
|
||
// return AjaxResult.success("订单结束成功");
|
||
|
||
return success("订单已结束");
|
||
} catch (Exception e) {
|
||
return error("结束订单失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 开始服务接口
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@Log(title = "开始服务", businessType = BusinessType.UPDATE)
|
||
@PostMapping("/start-service")
|
||
public AjaxResult startService(@RequestBody Map<String, Object> params) {
|
||
try {
|
||
String orderId = params.get("orderId").toString();
|
||
String image = params.get("image").toString();
|
||
if (StringUtils.isBlank(image)) {
|
||
return error("需上传图片");
|
||
}
|
||
Order order = orderService.selectOrderByOrderId(orderId);
|
||
if (order == null) {
|
||
return error("订单不存在");
|
||
}
|
||
|
||
OrderLog newlogdata =new OrderLog();
|
||
newlogdata.setType(new BigDecimal("6.0"));
|
||
newlogdata.setOid(order.getId());
|
||
//如果没有进行服务的记录就是开启服务
|
||
List<OrderLog> logList = orderLogService.selectOrderLogList(newlogdata);
|
||
if (logList.isEmpty()){
|
||
// 2. 组装日志内容为数组格式
|
||
Map<String, Object> logItem = new LinkedHashMap<>();
|
||
logItem.put("name", "师傅开始服务");
|
||
logItem.put("image", params.get("image"));
|
||
logItem.put("type", 1);
|
||
List<Object> logArr = new ArrayList<>();
|
||
logArr.add(logItem);
|
||
String contentStr = com.alibaba.fastjson2.JSONObject.toJSONString(logArr);
|
||
// 3. 写入订单日志
|
||
OrderLog log = new OrderLog();
|
||
log.setOid(order.getId());
|
||
log.setOrderId(order.getOrderId());
|
||
log.setTitle("开始服务");
|
||
log.setType(new BigDecimal(6.0));
|
||
log.setContent(contentStr);
|
||
log.setWorkerId(order.getWorkerId());
|
||
log.setWorkerLogId(order.getWorkerId());
|
||
log.setIsPause(1);
|
||
log.setCreatedAt(new Date());
|
||
orderLogService.insertOrderLog(log);
|
||
//开始服务
|
||
// 1. 修改订单状态
|
||
order.setStatus(3L); // 服务中
|
||
order.setJsonStatus(7); // 服务中
|
||
order.setLogJson("{\"type\":6}");
|
||
order.setIsPause(1); // 服务中
|
||
order.setUpdatedAt(new Date());
|
||
int update = orderService.updateOrder(order);
|
||
return AppletControllerUtil.appletSuccess("服务已开始");
|
||
}else{
|
||
|
||
if (order.getJsonStatus() == 7) {
|
||
com.alibaba.fastjson2.JSONObject logItem = new com.alibaba.fastjson2.JSONObject();
|
||
logItem.put("name", "暂停服务");
|
||
logItem.put("image", params.get("image"));
|
||
logItem.put("reson", params.get("reson"));
|
||
logItem.put("next_time", params.get("next_time"));
|
||
logItem.put("time", new Date());
|
||
logItem.put("type", 2);
|
||
|
||
|
||
OrderLog newlogdata1 =new OrderLog();
|
||
newlogdata1.setOid(order.getId());
|
||
newlogdata1.setOrderId(order.getOrderId());
|
||
newlogdata1.setTitle("暂停服务");
|
||
newlogdata1.setIsPause(2);
|
||
newlogdata1.setContent(logItem.toJSONString());
|
||
newlogdata1.setType(new BigDecimal(6.0));
|
||
newlogdata1.setWorkerId(order.getWorkerId());
|
||
newlogdata1.setWorkerLogId(order.getWorkerId());
|
||
|
||
|
||
orderLogService.insertOrderLog(newlogdata1);
|
||
if (order != null) {
|
||
// 1. 修改订单状态
|
||
order.setStatus(3L); // 服务中
|
||
order.setJsonStatus(8); // 服务中
|
||
order.setLogJson("{\"type\":6}");
|
||
order.setIsPause(2); // 服务中
|
||
order.setUpdatedAt(new Date());
|
||
orderService.updateOrder(order);
|
||
}
|
||
return AppletControllerUtil.appletSuccess("操作成功");
|
||
}
|
||
if (order.getJsonStatus() == 8) {
|
||
com.alibaba.fastjson2.JSONObject logItem = new com.alibaba.fastjson2.JSONObject();
|
||
logItem.put("name", "继续服务");
|
||
logItem.put("image", params.get("image"));
|
||
logItem.put("time", new Date());
|
||
logItem.put("type", 1);
|
||
|
||
OrderLog newlogdata2 =new OrderLog();
|
||
newlogdata2.setOid(order.getId());
|
||
newlogdata2.setOrderId(order.getOrderId());
|
||
newlogdata2.setTitle("继续服务");
|
||
newlogdata2.setIsPause(1);
|
||
newlogdata2.setType(new BigDecimal(6.0));
|
||
newlogdata2.setWorkerId(order.getWorkerId());
|
||
newlogdata2.setWorkerLogId(order.getWorkerId());
|
||
newlogdata2.setContent(logItem.toJSONString());
|
||
orderLogService.insertOrderLog(newlogdata2);
|
||
if (order != null) {
|
||
//继续服务
|
||
order.setStatus(3L); // 服务中
|
||
order.setJsonStatus(7); // 服务中
|
||
order.setLogJson("{\"type\":6}");
|
||
order.setIsPause(1); // 服务中
|
||
order.setUpdatedAt(new Date());
|
||
orderService.updateOrder(order);
|
||
}
|
||
return AppletControllerUtil.appletSuccess("操作成功");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
// 这里调用具体的业务逻辑,您来实现
|
||
// 例如:更新订单状态为服务中,记录开始时间等
|
||
|
||
return success("开始服务成功");
|
||
} catch (Exception e) {
|
||
return error("开始服务失败:" + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 项目报价接口
|
||
*/
|
||
@PreAuthorize("@ss.hasPermi('system:Order:edit')")
|
||
@Log(title = "项目报价", businessType = BusinessType.UPDATE)
|
||
@PostMapping("/project-quote")
|
||
public AjaxResult projectQuote(@RequestBody Map<String, Object> params) {
|
||
try {
|
||
String orderId = params.get("orderId").toString();
|
||
|
||
// 这里调用具体的业务逻辑,您来实现
|
||
// 例如:创建项目报价,更新订单状态等
|
||
|
||
return success("项目报价成功");
|
||
} catch (Exception e) {
|
||
return error("项目报价失败:" + e.getMessage());
|
||
}
|
||
}
|
||
}
|