package com.matrix.system.shopXcx.api.action; import com.matrix.system.hive.bean.SysVipInfo; import com.matrix.component.redis.RedisUserLoginUtils; import com.matrix.component.wechat.externalInterface.protocol.paramProtocol.BrandWCPayRequestData; import com.matrix.component.wechat.externalInterface.weixinUtil.WeixinServiceUtil; import com.matrix.core.constance.SystemErrorCode; import com.matrix.core.exception.GlobleException; import com.matrix.core.pojo.AjaxResult; import com.matrix.system.hive.dao.ShoppingGoodsDao; import com.matrix.system.hive.dao.SysVipInfoDao; import com.matrix.system.shopXcx.api.pojo.OrderInfoQueryPOJO; import com.matrix.system.shopXcx.api.pojo.ShopOrderDto; import com.matrix.system.shopXcx.api.service.OrderCouponGroupService; import com.matrix.system.shopXcx.api.service.ShoppingCartService; import com.matrix.system.shopXcx.api.service.WXShopOrderService; import com.matrix.system.shopXcx.api.service.WxShopCouponService; import com.matrix.system.shopXcx.api.tools.WxShopCouponUtil; import com.matrix.system.shopXcx.api.tools.WxShopOrderUtil; import com.matrix.system.shopXcx.bean.ShopOrder; import com.matrix.system.shopXcx.dao.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import java.math.BigDecimal; /** * @author jyy * @description 订单控制器 * @date 2019-06-10 10:58 */ @Controller @RequestMapping(value = "wxapi/shopOrder") public class WXShopOrderAction { @Autowired private WXShopOrderService shopOrderService; @Autowired WxShopCouponService wxShopCouponService; @Autowired private ShopReceiveAddressDao shopReceiveAddressDao; @Autowired ShoppingCartService shoppingCartService; @Autowired private ShopCouponDao shopCouponDao; @Autowired private WxShopCouponUtil wxShopCouponUtil; @Autowired private RedisUserLoginUtils redisUserLoginUtils; @Autowired ShopCouponRecordDao shopCouponRecordDao; @Autowired ShopSkuDao shopSkuDao; @Autowired ShopProductDao shopProductDao; @Autowired private WxShopOrderUtil wxShopOrderUtil; @Autowired private ShopOrderDetailsDao shopOrderDetailsDao; @Autowired OrderCouponGroupService orderCouponGroupService; @Autowired ShopOrderDao shopOrderDao; @Autowired SysVipInfoDao sysVipInfoDao; /** * 计算购物车订单价格 * * @param shopOrderDto * @return * @throws Exception */ @PostMapping(value = "/calculationCartOrder") public @ResponseBody AjaxResult calculationCartOrder(@RequestBody ShopOrderDto shopOrderDto) throws Exception { return shopOrderService.buildDiscountExplain(shopOrderDto); } @Autowired ShoppingGoodsDao shoppingGoodsDao; /** * 新增订单 * * @param shopOrderDto * @return */ @PostMapping(value = "/addShopOrder") public @ResponseBody AjaxResult addShopOrder(@RequestBody ShopOrderDto shopOrderDto) throws Exception { return shopOrderService.createShopOrder(shopOrderDto); } @Value("${wx_pay_debug_onoff}") private boolean isDebug; @Autowired private WeixinServiceUtil weixinServiceUtil; /** * 开始付款 * * @param shopOrder * @return * @throws Exception */ public BrandWCPayRequestData startPayment(ShopOrder shopOrder) throws Exception { BigDecimal unit = new BigDecimal("100"); BigDecimal money = new BigDecimal(shopOrder.getOrderMoney().toString()); BrandWCPayRequestData payData; String productNames = wxShopOrderUtil.getProductNames(shopOrder.getUserId(), shopOrder.getId()); SysVipInfo vipInfo = sysVipInfoDao.selectById(shopOrder.getUserId()); if (isDebug) { payData = weixinServiceUtil.createOrder("[测试]" + productNames, shopOrder.getOrderNo(), 1, vipInfo.getOpenId(), String.valueOf(shopOrder.getId())); } else { payData = weixinServiceUtil.createOrder(productNames, shopOrder.getOrderNo(), unit.multiply(money).intValue(), vipInfo.getOpenId(), String.valueOf(shopOrder.getId())); } ShopOrder updateParam = new ShopOrder(); updateParam.setId(shopOrder.getId()); updateParam.setWxOrderNo(payData.getPrepay_id()); shopOrderDao.updateByModel(updateParam); return payData; } /** * 订单结算 * * @param orderId 订单ID * @return */ @GetMapping(value = "orderSettlement/{orderId}") public @ResponseBody AjaxResult orderSettlement(@PathVariable("orderId") int orderId) { try { return shopOrderService.orderSettlement(orderId); } catch (Exception e) { throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL); } } /** * 查询订单支付结果 * * @param orderId * @return * @throws InterruptedException * @author JIANGYOUYAO * @email 935090232@qq.com * @date 2018年9月8日 */ @GetMapping(value = "/findOrderPayStatus/{orderId}") public @ResponseBody AjaxResult findOrderPayStatus(@PathVariable Integer orderId) throws InterruptedException { AjaxResult ajaxResult = shopOrderService.findOrderPayStatus(orderId); return ajaxResult; } /** * 获取我的订单信息 * * @return */ @PostMapping(value = "getMyOrderInfo") @ResponseBody public AjaxResult getMyOrderInfo(@RequestBody OrderInfoQueryPOJO orderInfoQueryPOJO) { AjaxResult ajaxResult = shopOrderService.getMyOrderInfo(orderInfoQueryPOJO); return ajaxResult; } /** * 通过订单ID获取订单信息 * * @return */ @GetMapping(value = "getOrderInfoById/{orderId}") @ResponseBody public AjaxResult getOrderInfoById(@PathVariable Integer orderId) { AjaxResult ajaxResult = shopOrderService.getOrderInfoById(orderId); return ajaxResult; } /** * 取消订单 * * @param * @return */ @GetMapping(value = "cancelOrderWhenWaitPay/{orderId}") @ResponseBody public AjaxResult cancelOrderWhenWaitPay(@PathVariable("orderId") Integer orderId) { return shopOrderService.cancelOrderWhenWaitPay(orderId); } /** * 删除订单 * * @param * @return */ @GetMapping(value = "delOrder/{orderId}") @ResponseBody public AjaxResult delOrderById(@PathVariable("orderId") Integer orderId) { return shopOrderService.delOrderById(orderId); } /** * 确认收货 * * @param * @return */ @GetMapping(value = "confirmPackageById/{orderId}") @ResponseBody public AjaxResult confirmPackageById(@PathVariable("orderId") Integer orderId) { return shopOrderService.confirmPackageById(orderId); } @GetMapping(value = "/getOrderStatusCount") @ResponseBody public AjaxResult getOrderStatusCount() { SysVipInfo sysVipInfo = redisUserLoginUtils.getLoginUser(SysVipInfo.class); AjaxResult result = AjaxResult.buildSuccessInstance( shopOrderDao.selectOrderStatusCount(sysVipInfo.getOpenId())); return result; } }