package com.hx.phip.order.controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.hx.common.BaseController; import com.hx.exception.TipsException; import com.hx.phiappt.common.OrderButtonConstants; import com.hx.phiappt.common.OrderTotalConstants; import com.hx.phiappt.model.SysAdmin; import com.hx.phiappt.model.order.OrderDeveloper; import com.hx.phiappt.model.order.OrderGoodsSpecs; import com.hx.phiappt.model.order.OrderItem; import com.hx.phiappt.model.order.OrdersTotal; import com.hx.phip.common.Constants; import com.hx.phip.order.service.OrderService; import com.hx.phip.service.SysAdminService; import com.hx.phip.tool.CreateNo; import com.hx.resultTool.Result; import com.hx.util.StringUtils; import com.platform.constants.LoginConstant; import com.platform.entity.ThirtApplication; import com.platform.exception.PlatTipsException; import com.platform.resultTool.PlatformCode; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.math.BigDecimal; import java.util.List; /** * 订单控制器 * @USER: zhouxiang * @DATE: 2021/12/03 */ @RestController @RequestMapping("/order") public class OrderController extends BaseController { @Resource private OrderService orderService; /** * 创建订单 */ @RequestMapping(value = "/add",method = RequestMethod.POST) public Result orderAdd(HttpServletRequest request, @RequestBody String param) { if(StringUtils.isEmpty(param)){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"请传订单参数"); } ThirtApplication thirtApplication= (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY); JSONObject object = JSONObject.parseObject(param); //获取总订单对象 OrdersTotal orderTotal = JSONObject.parseObject(object.getString("orderTotal"), OrdersTotal.class); //校验参数成功的订单 orderTotal = checkOrderTotalParam(orderTotal); orderTotal.setAppId(thirtApplication==null ?"":thirtApplication.getAppId()); //获取订单的子订单 List orderItem = JSONObject.parseArray(object.getString("orderItem"), OrderItem.class); if(orderItem==null || orderItem.size()==0){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"订单的子订单不能为空"); } orderItem=checkOrderItem(orderItem); //获取开发人员集合 List orderDeveloperList = JSONObject.parseArray(object.getString("orderDeveloper"), OrderDeveloper.class); Integer type = object.getInteger("type");//用于判断前端点了什么按钮,目前有草稿,提交,结账 String operatorId = object.getString("operatorId");//操作人id String shopId = object.getString("shopId");//操作人的门店id orderService.add(orderTotal,orderItem,type,orderDeveloperList,operatorId,shopId); return Result.success(); } /** * 结账 * @param param */ @RequestMapping(value = "/pay",method = RequestMethod.POST) public Result orderPay(@RequestBody String param) throws Exception { if(StringUtils.isEmpty(param)){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"请传订单参数"); } JSONObject object = JSONObject.parseObject(param); Integer type = object.getInteger("type");//是否是按项目付款,0:否,1:是 // if(type == null){ // throw new TipsException("请传结账类型"); // } String orderId = object.getString("orderId");//订单id if(StringUtils.isEmpty(orderId)){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"请传订单id"); } String total = object.getString("total");//应付的总金额 if(StringUtils.isEmpty(total)){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"请传应付的总金额"); } JSONArray amountList = object.getJSONArray("amount");//用户真正支付的金额集合 if(amountList ==null || amountList.size()==0){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"请传用户真实付款金额"); } String operatorId = object.getString("operatorId");//操作人员id if(StringUtils.isEmpty(operatorId)){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"请传用户操作人标识"); } orderService.orderPay(type,orderId,total,amountList,operatorId); return Result.success(); } /** * 测试充值储值金 * */ @RequestMapping(value = "/test",method = RequestMethod.POST) public void test(String value,String storeValue,String userId) { orderService.test(value,storeValue,userId); } /*子订单参数校验*/ private List checkOrderItem(List orderItem) { orderItem.forEach(o->{ if(StringUtils.isEmpty(o.getType())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"订单的子订单商品类型为空"); } if(o.getBuyNum()==null){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"订单的子订单购买数量为空"); } if(StringUtils.isEmpty(o.getCommonId())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"订单的子订单项目id/商品id为空"); } if(o.getDiscount()==null){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"折扣为空,默认:100"); } }); return orderItem; } /*总订单参数校验*/ private OrdersTotal checkOrderTotalParam(OrdersTotal orderTotal){ if(StringUtils.isEmpty(orderTotal.getType())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"订单类型为空"); } // if(StringUtils.isEmpty(orderTotal.getAppId())){ // throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"来源应用appId为空"); // } if(StringUtils.isEmpty(orderTotal.getSourceName())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"订单来源名称为空"); } if(StringUtils.isEmpty(orderTotal.getUserId())){ throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"用户Id为空"); } // if(StringUtils.isEmpty(orderTotal.getChannelType())){ // throwParamException("渠道类型不能为空"); // } // if(StringUtils.isEmpty(orderTotal.getCommonId())){ // throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"渠道标识不能为空"); // } // if(StringUtils.isEmpty(orderTotal.getCommonName())){ // throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"渠道名称不能为空"); // } // if(StringUtils.isEmpty(orderTotal.getDepartmentCode())){ // throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"科室编码不能为空"); // } // if(StringUtils.isEmpty(orderTotal.getDepartmentName())){ // throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"科室名称不能为空"); // } return orderTotal; } }