package com.stylefeng.guns.modular.system.controller.specialTrain; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; import com.stylefeng.guns.core.base.controller.BaseController; import com.stylefeng.guns.core.common.constant.factory.PageFactory; import com.stylefeng.guns.core.shiro.ShiroKit; import com.stylefeng.guns.core.shiro.ShiroUser; import com.stylefeng.guns.core.util.SinataUtil; import com.stylefeng.guns.modular.system.dao.OrderCancelMapper; import com.stylefeng.guns.modular.system.model.*; import com.stylefeng.guns.modular.system.service.*; import com.stylefeng.guns.modular.system.util.HttpRequestUtil; import com.stylefeng.guns.modular.system.util.PushURL; import com.stylefeng.guns.modular.system.util.ResultUtil; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.beans.factory.annotation.Autowired; import com.stylefeng.guns.core.log.LogObjectHolder; import org.springframework.web.bind.annotation.RequestParam; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 小件物流订单控制器 * * @author fengshuonan * @Date 2020-09-24 14:20:41 */ @Controller @RequestMapping("/tOrderLogistics") public class TOrderLogisticsController extends BaseController { private String PREFIX = "/system/tOrderLogistics/"; @Autowired private ITOrderLogisticsService tOrderLogisticsService; @Resource private OrderCancelMapper orderCancelMapper; @Autowired private ITUserService userService; @Autowired private ITransactionDetailsService transactionDetailsService; @Autowired private IPaymentRecordService paymentRecordService; @Autowired private IIncomeService incomeService; @Autowired private ITDriverService tDriverService; /** * 跳转到小件物流订单首页 */ @RequestMapping("") public String index() { return PREFIX + "tOrderLogistics.html"; } /** * 跳转到添加小件物流订单 */ @RequestMapping("/tOrderLogistics_add") public String tOrderLogisticsAdd() { return PREFIX + "tOrderLogistics_add.html"; } /** * 跳转到查看小件物流订单 */ @RequestMapping("/tOrderLogistics_detail/{tOrderLogisticsId}") public String tOrderLogistics_detail(@PathVariable Integer tOrderLogisticsId, Model model) { Map tOrderLogistics = tOrderLogisticsService.getLogisticsOrderDetailById(tOrderLogisticsId); model.addAttribute("item",tOrderLogistics); return PREFIX + "tOrderLogistics_detail.html"; } /** * 获取小件物流订单列表 */ @RequestMapping(value = "/list") @ResponseBody public Object list(String insertTime, String orderNum, Integer type, Integer orderSource, String userName, String userPhone, String recipient, String recipientPhone, String driver, Integer state) { String beginTime = null; String endTime = null; if (SinataUtil.isNotEmpty(insertTime)){ String[] timeArray = insertTime.split(" - "); beginTime = timeArray[0]; endTime = timeArray[1]; } Page> page = new PageFactory>().defaultPage(); page.setRecords(tOrderLogisticsService.getLogisticsOrderList(page,beginTime,endTime,ShiroKit.getUser().getRoleType(),ShiroKit.getUser().getObjectId(), orderNum,orderSource,type,userName,userPhone,recipient,recipientPhone,driver,state)); return super.packForBT(page); } @Autowired private ITDriverService itDriverService; /** * 取消小件物流订单 */ @RequestMapping(value = "/cancel") @ResponseBody public Object cancel(@RequestParam Integer tOrderLogisticsId) { try{ ShiroUser user = ShiroKit.getUser(); TOrderLogistics tOrderLogistics = tOrderLogisticsService.selectById(tOrderLogisticsId); tOrderLogistics.setState(10); //已支付的情况下进行退款操作 if(null != tOrderLogistics.getPayType() && null != tOrderLogistics.getPayMoney()) { if (tOrderLogistics.getPayType() == 3) {//余额支付 TUser tUser = userService.selectById(tOrderLogistics.getUserId()); tUser.setBalance(tUser.getBalance().add(tOrderLogistics.getPayMoney())); userService.updateById(tUser); } else { List paymentRecords = paymentRecordService.query(1, null, null, tOrderLogisticsId, tOrderLogistics.getType(), null, 2); if (paymentRecords.size() == 0) { return ResultUtil.error("订单还未进行支付"); } boolean b = false; } transactionDetailsService.saveData(tOrderLogistics.getUserId(), "小件订单取消退款", tOrderLogistics.getPayMoney().doubleValue(), 1, 1, 1, 4, tOrderLogistics.getId()); //添加负的收入明细 List incomes = incomeService.selectList(new EntityWrapper().eq("type", 2).eq("incomeId", tOrderLogistics.getId()).eq("orderType", tOrderLogistics.getType())); for(Income income : incomes){ if(income.getUserType() == 2){//处理司机的收入 TDriver driver = tDriverService.selectById(income.getObjectId()); driver.setBalance(driver.getBalance().subtract(new BigDecimal(income.getMoney()))); // driver.setLaveBusinessMoney(new BigDecimal(driver.getLaveBusinessMoney()).subtract(new BigDecimal(income.getMoney())).doubleValue()); // driver.setBusinessMoney(new BigDecimal(driver.getBusinessMoney()).subtract(new BigDecimal(income.getMoney())).doubleValue()); tDriverService.updateById(driver); } Income income1 = new Income(); BeanUtils.copyProperties(income, income1); income1.setMoney(income.getMoney() * -1); income1.setId(null); income1.setInsertTime(new Date()); incomeService.insert(income1); } } tOrderLogisticsService.updateById(tOrderLogistics); //添加取消记录 OrderCancel orderCancel = new OrderCancel(); orderCancel.setOrderId(tOrderLogistics.getId()); orderCancel.setOrderType(tOrderLogistics.getType()); orderCancel.setReason("调度端取消订单"); orderCancel.setRemark("调度“" + user.getName() + "-" + user.getId() + "”执行取消操作"); orderCancel.setState(2); orderCancel.setInsertTime(new Date()); orderCancel.setUserType(3); orderCancel.setUserId(user.getId()); orderCancelMapper.insert(orderCancel); //增加推送 Map map = new HashMap<>(); map.put("id", tOrderLogistics.getId().toString()); map.put("orderType", tOrderLogistics.getType().toString()); String result = HttpRequestUtil.postRequest(PushURL.cancel_order_url, map); System.out.println("小件物流取消:【orderId="+tOrderLogistics.getId().toString()+"】,调用接口:"+result); }catch (Exception e){ e.printStackTrace(); } return SUCCESS_TIP; } /** * 删除小件物流订单 */ @RequestMapping(value = "/delete") @ResponseBody public Object delete(@RequestParam Integer tOrderLogisticsId) { TOrderLogistics tOrderLogistics = tOrderLogisticsService.selectById(tOrderLogisticsId); tOrderLogistics.setIsDelete(2); tOrderLogisticsService.updateById(tOrderLogistics); return SUCCESS_TIP; } }