diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java index 11b8f40b..0acca2d2 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java @@ -1,10 +1,13 @@ package com.ghy.web.controller.order; +import com.ghy.common.annotation.Log; import com.ghy.common.core.controller.BaseController; import com.ghy.common.core.domain.AjaxResult; import com.ghy.common.core.domain.entity.SysUser; import com.ghy.common.enums.*; +import com.ghy.common.json.JSONObject; import com.ghy.common.utils.WechatMsgUtils; +import com.ghy.common.utils.poi.ExcelUtil; import com.ghy.customer.domain.Customer; import com.ghy.customer.domain.CustomerAddress; import com.ghy.customer.service.CustomerAddressService; @@ -41,6 +44,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.time.DateUtils; +import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; @@ -48,6 +52,7 @@ import org.springframework.ui.ModelMap; import org.springframework.util.Assert; import org.springframework.util.StopWatch; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.math.BigDecimal; diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderMasterController.java b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderMasterController.java index bc0905d0..d78971f5 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderMasterController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderMasterController.java @@ -1,7 +1,6 @@ package com.ghy.web.controller.order; import cn.hutool.db.sql.Order; -import com.alibaba.fastjson.JSONObject; import com.ghy.common.adapay.model.AdapayStatusEnum; import com.ghy.common.adapay.model.PayParam; import com.ghy.common.annotation.Log; @@ -13,6 +12,7 @@ import com.ghy.common.core.page.PageDomain; import com.ghy.common.core.page.TableDataInfo; import com.ghy.common.core.page.TableSupport; import com.ghy.common.enums.*; +import com.ghy.common.json.JSONObject; import com.ghy.common.utils.*; import com.ghy.common.utils.poi.ExcelUtil; import com.ghy.customer.domain.Customer; @@ -22,6 +22,8 @@ import com.ghy.customer.service.CustomerService; import com.ghy.goods.domain.*; import com.ghy.goods.service.*; import com.ghy.order.domain.*; +import com.ghy.order.request.SysOrderAssignRequest; +import com.ghy.order.request.SysOrderGoodsStandards; import com.ghy.order.service.*; import com.ghy.payment.domain.FinancialChangeRecord; import com.ghy.payment.domain.FinancialDetail; @@ -33,10 +35,7 @@ import com.ghy.payment.service.FinancialMasterService; import com.ghy.payment.service.OrderFineRecordService; import com.ghy.system.domain.SysArea; import com.ghy.system.service.ISysAreaService; -import com.ghy.web.pojo.vo.OrderListResponse; -import com.ghy.web.pojo.vo.OrderMasterResponseVo; -import com.ghy.web.pojo.vo.OrderStandard; -import com.ghy.web.pojo.vo.OrderStandardDetail; +import com.ghy.web.pojo.vo.*; import com.ghy.worker.domain.Worker; import com.ghy.worker.domain.WorkerCertification; import com.ghy.worker.service.IWorkerCertificationService; @@ -51,11 +50,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.ui.ModelMap; +import org.springframework.util.Assert; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.math.BigDecimal; +import java.math.RoundingMode; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @@ -204,6 +206,292 @@ public class OrderMasterController extends BaseController { return AjaxResult.success(); } + @PostMapping("/importData") + @ResponseBody + @Transactional(rollbackFor = Exception.class) + public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception + { + ExcelUtil util = new ExcelUtil(SysOrderRequest.class); + List jsonObjects = util.importExcel(file.getInputStream()); + for (SysOrderRequest model : jsonObjects) { + this.sysOrder(format(model)); + } + return AjaxResult.success(jsonObjects); + } + + public SysOrderAssignRequest format(SysOrderRequest orderRequest) throws Exception{ + SysOrderAssignRequest request = new SysOrderAssignRequest(); + request.setCustomerName(orderRequest.getName()); + request.setCustomerPhone(orderRequest.getPhone()); + request.setServDate(orderRequest.getDate()); + request.setServTime(orderRequest.getTime()); + request.setGoodsBrand(orderRequest.getBrand()); + request.setOrderMode("02"); + request.setPayMode("01"); + request.setPrice(new BigDecimal(orderRequest.getPrice())); + request.setVideoUrl(orderRequest.getUrl()); + request.setImageUrl("http://gqz.opsoul.com/default.jpeg"); + List goodsStandards = new ArrayList<>(); + String [] categoryNames = orderRequest.getCategory().split("-"); + if(categoryNames.length != 4){ + throw new Exception("导入类目数据格式错误"); + }else { + // 第一层 + GoodsCategory param1 = new GoodsCategory(); + param1.setGoodsCategoryName(categoryNames[0]); + GoodsCategory category1 = goodsCategoryService.selectGoodsCategoryList(param1).get(0); + // 第二层 + GoodsCategory param2 = new GoodsCategory(); + param2.setParentCategoryId(category1.getGoodsCategoryId()); + param2.setGoodsCategoryName(categoryNames[1]); + GoodsCategory category2 = goodsCategoryService.selectGoodsCategoryList(param2).get(0); + // 第三层 + GoodsCategory param3 = new GoodsCategory(); + param3.setParentCategoryId(category2.getGoodsCategoryId()); + param3.setGoodsCategoryName(categoryNames[2]); + GoodsCategory category3 = goodsCategoryService.selectGoodsCategoryList(param3).get(0); + + DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.selectOneByGoodsCategoryId(category3.getGoodsCategoryId()); + request.setCategoryId3(deptGoodsCategory.getDeptGoodsCategoryId()); + + // 第四层 + GoodsCategory param4 = new GoodsCategory(); + param4.setParentCategoryId(category3.getGoodsCategoryId()); + param4.setGoodsCategoryName(categoryNames[3]); + GoodsCategory category4 = goodsCategoryService.selectGoodsCategoryList(param4).get(0); + + SysOrderGoodsStandards standards = new SysOrderGoodsStandards(); + DeptGoodsCategory deptGoodsCategory2 = deptGoodsCategoryService.selectOneByGoodsCategoryId(category4.getGoodsCategoryId()); + standards.setDeptCategoryId(deptGoodsCategory2.getDeptGoodsCategoryId()); + standards.setGoodsStandardNum(Integer.parseInt(orderRequest.getNum())); + goodsStandards.add(standards); + } + request.setOrderGoodsStandards(goodsStandards); + String [] addressName = orderRequest.getAddress().split("-"); + if(addressName.length == 1){ + addressName = orderRequest.getAddress().split(","); + if(addressName.length == 1){ + addressName = orderRequest.getAddress().split(" "); + } + } + if(addressName.length < 4){ + throw new Exception("导入地址数据格式错误"); + }else { + // 省 + SysArea param1 = new SysArea(); + param1.setAreaName(addressName[0]); + SysArea area1 = sysAreaService.selectSysAreaList(param1).get(0); + request.setProvinceId(area1.getAreaId()); + + // 市 + SysArea param2 = new SysArea(); + param2.setAreaName(addressName[1]); + param2.setParentCode(area1.getAreaCode()); + SysArea area2 = sysAreaService.selectSysAreaList(param2).get(0); + request.setCityId(area2.getAreaId()); + + // 区 + SysArea param3 = new SysArea(); + param3.setAreaName(addressName[2]); + param3.setParentCode(area2.getAreaCode()); + SysArea area3 = sysAreaService.selectSysAreaList(param3).get(0); + request.setDistrictId(area3.getAreaId()); + + // 详细地址 + if(addressName.length == 5){ + request.setFullAddress(addressName[3]+addressName[4]); + }else { + request.setFullAddress(addressName[3]); + } + + } + return request; + } + + public void sysOrder(@RequestBody SysOrderAssignRequest request) throws Exception { + + // 判断传递价格是否有小数 + if (new BigDecimal(request.getPrice().intValue()).compareTo(request.getPrice())!=0){ + throw new Exception("后台发单金额不能含有小数!"); + } + + // 判断是否有客户 + SysUser sysUser = getSysUser(); + Long deptId = sysUser.getDept().getDeptId(); + String loginName = sysUser.getLoginName(); + Customer customer = customerService.selectByAccount("sys_" + loginName); + if (customer == null) { + customer = new Customer(); + customer.setAccount("sys_" + loginName); + customer.setName("平台用户_" + loginName); + customerService.insertCustomer(customer); + } + + // 判断是否有客户地址 + if (request.getProvinceId() == null || request.getCityId() == null || request.getDistrictId() == null || org.apache.commons.lang3.StringUtils.isBlank(request.getFullAddress())) { + throw new Exception("请填写地址"); + } + CustomerAddress customerAddress = customerAddressService.selectByCustomerAndAddress(customer.getCustomerId(), + request.getProvinceId(), request.getCityId(), request.getDistrictId(), request.getFullAddress()); + if (customerAddress == null) { + customerAddress = new CustomerAddress(); + customerAddress.setCustomerId(customer.getCustomerId()); + customerAddress.setProvinceId(request.getProvinceId()); + customerAddress.setCityId(request.getCityId()); + customerAddress.setCountryId(request.getDistrictId()); + customerAddress.setAddress(request.getFullAddress()); + customerAddress.setIsDefault(0); + customerAddress.setPhone(request.getCustomerPhone()); + customerAddress.setName(request.getCustomerName()); + customerAddressService.insertCustomerAddress(customerAddress); + } + + // 订单总价 不能小于0 + BigDecimal orderPrice = request.getPrice().max(BigDecimal.ZERO); + Integer totalNum = 0; + for (SysOrderGoodsStandards model : request.getOrderGoodsStandards()) { + totalNum = totalNum + model.getGoodsStandardNum(); + } + // 商品单价 + BigDecimal goodsPrice = orderPrice.divide(BigDecimal.valueOf(totalNum), RoundingMode.HALF_UP); + + // 增加商品 + Goods goods = new Goods(); + goods.setDeptId(deptId); + // 后续改成 三级类目+品牌 + goods.setGoodsName(request.getGoodsBrand()); + goods.setGoodsImgUrl(request.getImageUrl()); + goods.setGoodsVideoUrl(request.getVideoUrl()); + goods.setDeptGoodsCategoryId(request.getCategoryId3()); + goods.setStatus(1); + goods.setRemark(request.getRemark()); + goodsService.insertGoods(goods); + + List goodsStandards = new ArrayList<>(); + // TODO 生成规格 -- orderGoods完成后未会写规格id + request.getOrderGoodsStandards().forEach(list -> { + DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.get(list.getDeptCategoryId()); + GoodsStandard standard = new GoodsStandard(); + standard.setGoodsStandardName(deptGoodsCategory.getGoodsCategoryName()); + standard.setDeptGoodsCategoryId(deptGoodsCategory.getDeptGoodsCategoryId()); + standard.setGoodsCategoryName(deptGoodsCategory.getGoodsCategoryName()); + standard.setGoodsPrice(goodsPrice); + standard.setGoodsId(goods.getGoodsId()); + standard.setExtMoney(BigDecimal.ZERO); + standard.setGoodsNum(list.getGoodsStandardNum()); + standard.setSaleNum(0); + goodsStandardService.insertGoodsStandard(standard); + goodsStandards.add(standard); + }); + + // 生成主单 + OrderMaster orderMaster = new OrderMaster(); + orderMaster.setDeptId(deptId); + orderMaster.setCode(orderMasterService.createOrderCode()); + orderMaster.setOrderType(0); + orderMaster.setOrderStatus(OrderStatus.RECEIVE.code()); + orderMaster.setAddressId(customerAddress.getCustomerAddressId()); + orderMaster.setPayStatus(PayStatus.WAIT_PAY.getCode()); + orderMaster.setCreateTime(new Date()); + orderMaster.setCustomerId(customer.getCustomerId()); + orderMaster.setGoodsId(goods.getGoodsId()); + orderMaster.setPayType(0); + orderMaster.setOrderMode(request.getOrderMode()); + orderMaster.setPayMode(request.getPayMode()); + orderMaster.setGoodsBrand(request.getGoodsBrand()); + orderMaster.setGoodsSpecification(request.getGoodsSpecification()); + // 存在登陆用户的情况下 + if(getSysUser() != null){ + orderMaster.setCreateBy(getSysUser().getUserId().toString()); + } + if(StringUtils.isEmpty(request.getServDate())){ + Calendar calendar = Calendar.getInstance(); + calendar.add(Calendar.DATE, 1); +// request.setServDate(); + } + // 服务时间 + String[] split = request.getServTime().split("-"); + try { + orderMaster.setExpectTimeStart(org.apache.commons.lang3.time.DateUtils.parseDate(request.getServDate() + " " + split[0], "yyyy-MM-dd hh:mm")); + orderMaster.setExpectTimeEnd(org.apache.commons.lang3.time.DateUtils.parseDate(request.getServDate() + " " + split[1], "yyyy-MM-dd hh:mm")); + } catch (Exception e) { + + } + orderMasterService.insertOrderMaster(orderMaster); + Assert.notNull(orderMaster.getId(), "OrderMaster.id is null!"); + + // 生成财务主单 + FinancialMaster financialMaster = new FinancialMaster(financialMasterService.createCode(), deptId, + orderMaster.getId(), orderMaster.getCode(), request.getPrice(), BigDecimal.ZERO, request.getPrice()); + financialMaster.setServerMoney(financialMaster.getTotalMoney()); + financialMasterService.insertFinancialMaster(financialMaster); + Assert.notNull(financialMaster.getId(), "FinancialMaster.id is null!"); + + // 生成提成类子财务单 + createDeptFinancialDetail(goodsStandards.get(0), deptId, financialMaster); + + // 生成商品订单 + goodsStandards.forEach(goodsStandard -> { + OrderGoods orderGoods = new OrderGoods(orderMaster.getId(), goodsStandard.getGoodsStandardId(), + goodsStandard.getGoodsStandardName(), goodsStandard.getGoodsNum(), 0); + orderGoodsService.insertOrderGoods(orderGoods); + }); + + // 推送公众号通知数据。 + try { + Worker assignWorker = workerService.selectById(orderMaster.getWorkerId()); + // 消息组装。 + Map params = new HashMap<>(); + // 订单编号 + params.put("character_string6", orderMaster.getCode()); + // 名称 + params.put("thing14", customer.getName()); + // 预约时间 + params.put("time4", com.ghy.common.utils.DateUtils.parseDateToStr("yyyy年MM月dd日 HH:mm", orderMaster.getExpectTimeStart())); + // 消息推送 + WechatMsgUtils.sendWeChatMsg(WechatMsgUtils.getToken(), assignWorker.getWxOpenId(), WxMsgEnum.TEXT, params); + } catch (Exception e) { + // 暂时不做任何操作。 + logger.error(e.getMessage(), e); + } + logger.info("下单成成"); + } + + private void createDeptFinancialDetail(GoodsStandard goodsStandard, Long deptId, FinancialMaster financialMaster) { + // 平台 + BigDecimal deptMoney = BigDecimal.ZERO; + // 截流扣点 + BigDecimal specialMoney = BigDecimal.ZERO; + // 服务金额 + BigDecimal serverMoney = financialMaster.getServerMoney(); + // 扣点设置类目 + DeptGoodsCategory deptGoodsCategory = deptGoodsCategoryService.get(goodsStandard.getDeptGoodsCategoryId()); + // 平台扣点 = 平台金额 + 商品单价 * 扣点比例 + deptMoney = deptMoney.add(deptGoodsCategory.getPcDeptMoney()) + .add(financialMaster.getPayMoney().multiply(BigDecimal.valueOf(Double.parseDouble(deptGoodsCategory.getPcDeptRate())))); + // 截流扣点 = 截流金额 + 商品单价 * 扣点比例 + specialMoney = specialMoney.add(deptGoodsCategory.getPcRetainMoney()) + .add(financialMaster.getPayMoney().multiply(BigDecimal.valueOf(Double.parseDouble(deptGoodsCategory.getPcRetainRate())))); + // 平台扣点记录 + FinancialDetail deptDetail = new FinancialDetail(deptId, financialDetailService.createCode(), + financialMaster.getId(), financialMaster.getCode(), deptMoney, FinancialDetailType.PLATFORM_FEE.getCode(), null); + financialDetailService.insertFinancialDetail(deptDetail); + // 剩余服务金额 + serverMoney = serverMoney.subtract(deptMoney); + + // 截流扣点记录 + FinancialDetail retainDetail = new FinancialDetail(deptId, financialDetailService.createCode(), + financialMaster.getId(), financialMaster.getCode(), specialMoney, FinancialDetailType.PLATFORM_FEE.getCode(), null); + financialDetailService.insertFinancialDetail(retainDetail); + // 剩余服务金额 + serverMoney = serverMoney.subtract(specialMoney); + + FinancialMaster fmUpdate = new FinancialMaster(); + fmUpdate.setId(financialMaster.getId()); + fmUpdate.setServerMoney(serverMoney); + financialMasterService.updateFinancialMaster(fmUpdate); + } + @GetMapping("/orderWorker/{orderId}") public String orderWorker(@PathVariable("orderId") Long orderId, ModelMap mmap) { List workList = workerService.getWorkList(new Worker()); diff --git a/ghy-admin/src/main/java/com/ghy/web/pojo/vo/SysOrderRequest.java b/ghy-admin/src/main/java/com/ghy/web/pojo/vo/SysOrderRequest.java new file mode 100644 index 00000000..67343ee6 --- /dev/null +++ b/ghy-admin/src/main/java/com/ghy/web/pojo/vo/SysOrderRequest.java @@ -0,0 +1,71 @@ +package com.ghy.web.pojo.vo; + +import com.ghy.common.annotation.Excel; +import lombok.Data; + +@Data +public class SysOrderRequest { + + @Excel(name = "seq") + private String seq; + + @Excel(name = "category") + private String category; + + @Excel(name = "brand") + private String brand; + + @Excel(name = "num") + private String num; + + @Excel(name = "date") + private String date; + + @Excel(name = "time") + private String time; + + @Excel(name = "address") + private String address; + + @Excel(name = "name") + private String name; + + @Excel(name = "phone") + private String phone; + + @Excel(name = "mode") + private String mode; + + @Excel(name = "price") + private String price; + + @Excel(name = "remark") + private String remark; + + @Excel(name = "money") + private String money; + + @Excel(name = "award") + private String award; + + @Excel(name = "url") + private String url; + + @Excel(name = "logistics") + private String logistics; + + @Excel(name = "needHll") + private String needHll; + + @Excel(name = "bh") + private String bh; + + @Excel(name = "floor") + private String floor; + + @Excel(name = "floorUp") + private String floorUp; + + @Excel(name = "bhry") + private String bhry; +} diff --git a/ghy-admin/src/main/resources/templates/order/orderManager.html b/ghy-admin/src/main/resources/templates/order/orderManager.html index f23c981d..7cf913a6 100644 --- a/ghy-admin/src/main/resources/templates/order/orderManager.html +++ b/ghy-admin/src/main/resources/templates/order/orderManager.html @@ -259,7 +259,7 @@
- + 新订单 (0) @@ -313,6 +313,10 @@ shiro:hasPermission="order:order:export"> 导出 + + 导入 + 付款 @@ -609,6 +613,7 @@ var options = { url: prefix + "/list", exportUrl: prefix + "/export", + importUrl: prefix + "/importData", queryParams: queryParams, sortName: "createTime", sortOrder: "desc", @@ -986,5 +991,18 @@ - + diff --git a/ghy-order/src/main/resources/mapper/order/OrderMasterMapper.xml b/ghy-order/src/main/resources/mapper/order/OrderMasterMapper.xml index edaadd37..0eb22662 100644 --- a/ghy-order/src/main/resources/mapper/order/OrderMasterMapper.xml +++ b/ghy-order/src/main/resources/mapper/order/OrderMasterMapper.xml @@ -155,6 +155,9 @@ AND om.worker_id IS NULL AND (om.pay_mode = '01' OR (om.pay_mode = '02' and om.pay_status = '1')) + + and om.worker_id IS not NULL + AND om.pay_mode = #{payMode} @@ -286,6 +289,9 @@ AND om.worker_id IS NULL AND (om.pay_mode = '01' OR (om.pay_mode = '02' and om.pay_status = '1')) + + AND om.worker_id IS not NULL + AND om.pay_mode = #{payMode} @@ -478,7 +484,7 @@