This commit is contained in:
kuang.yife 2024-01-29 17:26:04 +08:00
parent c6b3fdaf03
commit 43df3100ed
6 changed files with 400 additions and 12 deletions

View File

@ -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;

View File

@ -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<SysOrderRequest> util = new ExcelUtil<SysOrderRequest>(SysOrderRequest.class);
List<SysOrderRequest> 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<SysOrderGoodsStandards> 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<GoodsStandard> 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<String, Object> 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<Worker> workList = workerService.getWorkList(new Worker());

View File

@ -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;
}

View File

@ -259,7 +259,7 @@
</div>
</div>
<div class="m-t condition-btn">
<a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatus: 0})">
<a class="btn btn-default btn-outline" onclick="selectConditionBtn(this, {orderStatus: 0, workerId : -2})">
新订单
(<span id="newOrderNum">0</span>)
</a>
@ -313,6 +313,10 @@
shiro:hasPermission="order:order:export">
<i class="fa fa-download"></i> 导出
</a>
<a class="btn btn-warning" onclick="$.table.importExcel()"
shiro:hasPermission="order:order:import">
<i class="fa fa-download"></i> 导入
</a>
<a class="btn btn-default" onclick="mergePay()">
<i class="fa fa-money"></i> 付款
</a>
@ -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 @@
</script>
</body>
<script id="importTpl" type="text/template">
<form enctype="multipart/form-data" class="mt20 mb10">
<div class="col-xs-offset-1">
<input type="file" id="file" name="file"/>
<div class="mt10 pt5">
<input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在,更新这条数据。"> 是否更新已经存在的用户数据
&nbsp; <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
</div>
<font color="red" class="pull-left mt10">
提示仅允许导入“xls”或“xlsx”格式文件
</font>
</div>
</form>
</script>
</html>

View File

@ -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'))
</if>
<if test="workerId == -2">
and om.worker_id IS not NULL
</if>
<if test="payMode != null">
AND om.pay_mode = #{payMode}
</if>
@ -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'))
</if>
<if test="workerId == -2">
AND om.worker_id IS not NULL
</if>
<if test="payMode != null">
AND om.pay_mode = #{payMode}
</if>
@ -478,7 +484,7 @@
<select id="differentStatusOrderCount" resultType="com.ghy.order.domain.OrderMasterCount" parameterType="com.ghy.order.domain.OrderMaster">
select
count(case when om.order_status = 0 then 1 else null end) as newOrderNum,
count(case when om.order_status = 0 and om.worker_id is not null then 1 else null end) as newOrderNum,
count(case when om.order_status = 1 then 1 else null end) as acceptedOrderNum,
count(case when om.order_status = 1 and om.is_call = '01' then 1 else null end) as notAppointedOrderNum,
count(case when om.order_status = 1 and om.is_call = '02' then 1 else null end) as notArrangedOrderNum,

View File

@ -103,14 +103,14 @@ public class OrderServiceImpl implements OrderService {
if (overTime30min.before(now) && overTime1h.after(now)) {
// 30min未接单为超时
log.info("主订单[{}]超时30分钟", order.getId());
orderMasterService.updateTimeout(order.getId(), 1);
// orderMasterService.updateTimeout(order.getId(), 1);
timeout = true;
}
}
if (flag && order.getWorkerId() != null) {
log.info("主订单[{}]超时60分钟", order.getId());
// 已超时 60min后取消超时状态 清空workerId
orderMasterService.updateTimeout(order.getId(), 0);
// orderMasterService.updateTimeout(order.getId(), 0);
orderMasterService.removeWorker(order.getId());
}
return;
@ -129,12 +129,12 @@ public class OrderServiceImpl implements OrderService {
if (overTime30min.before(now)) {
// 30min未接单为超时
log.info("主订单[{}]超时30分钟", order.getId());
orderMasterService.updateTimeout(order.getId(), 1);
// orderMasterService.updateTimeout(order.getId(), 1);
timeout = true;
}
}
if (timeout) {
if (false) {
if (overTime4h.before(now) && ZERO.equals(fineTimes)) {
log.info("主订单[{}]超时4小时", order.getId());
orderMasterService.updateTimeout(order.getId(), 1, 1);