Authored by 匡佳华

skn扣点

... ... @@ -43,6 +43,10 @@
<groupId>com.yoho.ufo</groupId>
<artifactId>ufo-platform-common</artifactId>
</dependency>
<dependency>
<groupId>com.yoho.ufo.model</groupId>
<artifactId>product-ufo-model</artifactId>
</dependency>
</dependencies>
... ...
package com.yoho.product.dal;
import com.yoho.product.model.ProductProfit;
import com.yohobuy.ufo.model.request.product.ProductProfitReqBo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ProductProfitMapper {
int insertBatchProductProfit(@Param("list") List<ProductProfit> list);
void insert(ProductProfit productProfit);
void updateDelStatus(Integer id);
int selectCount(@Param("productId") Integer productId);
void update(ProductProfit productProfit);
ProductProfit selectByProductId(@Param("productId") Integer productId);
ProductProfit selectById(Integer id);
List<ProductProfit> selectByCondition(ProductProfitReqBo reqBo);
List<ProductProfit> selectByProductIds(@Param("list") List<Integer> productIds);
}
... ...
package com.yoho.product.model;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class ProductProfit {
private Integer id;
private Integer productId;
private BigDecimal profitRate;
private BigDecimal profitMaxPrice;
private BigDecimal profitMinPrice;
private Integer delStatus;
private Integer createTime;
private Integer updateTime;
private String addUserName;
private String editUserName;
}
... ...
package com.yoho.ufo.dal.model;
import com.yoho.ufo.annotation.BatchImportField;
import lombok.Data;
@Data
public class ProductProfitImportItem {
@BatchImportField(index = 0)
private Integer productId;
@BatchImportField(index = 1)
private String profitRate;
@BatchImportField(index = 2)
private String profitMaxPrice;
@BatchImportField(index = 3)
private String profitMinPrice;
}
... ...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yoho.product.dal.ProductProfitMapper">
<resultMap id="BaseResultMap" type="com.yoho.product.model.ProductProfit">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="product_id" jdbcType="INTEGER" property="productId" />
<result column="profit_rate" jdbcType="DECIMAL" property="profitRate" />
<result column="update_time" jdbcType="INTEGER" property="updateTime" />
<result column="create_time" jdbcType="INTEGER" property="createTime" />
<result column="del_status" jdbcType="INTEGER" property="delStatus" />
<result column="edit_user_name" jdbcType="VARCHAR" property="editUserName" />
<result column="add_user_name" jdbcType="VARCHAR" property="addUserName" />
<result column="profit_max_price" jdbcType="DECIMAL" property="profitMaxPrice" />
<result column="profit_min_price" jdbcType="DECIMAL" property="profitMinPrice" />
</resultMap>
<select id="selectCount" resultType="java.lang.Integer" parameterType="java.lang.Integer">
select count(1) from product_profit
where del_status = 0
<if test="productId != null &amp;&amp; productId > 0">
and product_id = #{productId, jdbcType=INTEGER}
</if>
</select>
<select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select id, product_id, profit_rate, profit_max_price, profit_min_price
from product_profit
where id = #{id, jdbcType=INTEGER}
</select>
<select id="selectByCondition" resultMap="BaseResultMap">
select id, product_id, profit_rate, profit_max_price, profit_min_price, create_time, update_time, add_user_name, edit_user_name
from product_profit
where del_status = 0
<if test="productId != null &amp;&amp; productId > 0">
and product_id = #{productId, jdbcType=INTEGER}
</if>
limit #{startIndex}, #{rows}
</select>
<update id="updateDelStatus" parameterType="java.lang.Integer">
update product_profit
set del_status = 1
where id = #{id, jdbcType=INTEGER}
</update>
<select id="selectByProductIds" resultMap="BaseResultMap">
select product_id, add_user_name, create_time from product_profit
where del_status = 0
and product_id in
<foreach collection="list" item="productId" separator="," open="(" close=")">
#{productId, jdbcType=INTEGER}
</foreach>
</select>
<insert id="insertBatchProductProfit">
replace into product_profit
(product_id, profit_rate, update_time, create_time, add_user_name, edit_user_name, profit_max_price, profit_min_price)
values
<foreach collection="list" item="item" separator=",">
(#{item.productId, jdbcType=INTEGER},#{item.profitRate, jdbcType=DECIMAL},
#{item.updateTime, jdbcType=INTEGER},#{item.createTime, jdbcType=INTEGER},
#{item.addUserName, jdbcType=INTEGER},#{item.editUserName, jdbcType=INTEGER},
#{item.profitMaxPrice, jdbcType=DECIMAL},#{item.profitMinPrice, jdbcType=DECIMAL}
)
</foreach>
</insert>
<update id="update">
update product_profit
set product_id = #{productId, jdbcType=INTEGER},
profit_rate = #{profitRate, jdbcType=DECIMAL},
profit_max_price = #{profitMaxPrice, jdbcType=DECIMAL},
profit_min_price = #{profitMinPrice, jdbcType=DECIMAL},
edit_user_name = #{editUserName, jdbcType=VARCHAR},
update_time = #{updateTime, jdbcType=INTEGER}
where id = #{id, jdbcType=INTEGER}
</update>
<select id="selectByProductId" resultType="java.lang.Integer" resultMap="BaseResultMap">
select id from product_profit
where del_status = 0 and product_id = #{productId, jdbcType=INTEGER}
limit 1
</select>
<insert id="insert">
replace into product_profit
(product_id, profit_rate, profit_max_price, profit_min_price, add_user_name, create_time)
values
(#{productId, jdbcType=INTEGER}, #{profitRate, jdbcType=DECIMAL},
#{profitMaxPrice, jdbcType=DECIMAL}, #{profitMinPrice, jdbcType=DECIMAL},
#{addUserName, jdbcType=VARCHAR}, #{createTime, jdbcType=INTEGER})
</insert>
</mapper>
\ No newline at end of file
... ...
package com.yoho.ufo.controller.product;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.service.IProductProfitService;
import com.yoho.ufo.service.impl.UserHelper;
import com.yohobuy.ufo.model.common.ApiResponse;
import com.yohobuy.ufo.model.request.product.ProductProfitReqBo;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
/**
* 商品费率管理
*/
@RestController
@RequestMapping(value = "/productProfit")
public class ProductProfitController {
private static final Logger logger = LoggerFactory.getLogger(ProductProfitController.class);
@Autowired
IProductProfitService productProfitService;
@RequestMapping(value = "/list")
public ApiResponse getList(ProductProfitReqBo reqBo){
return productProfitService.getProductProfitPage(reqBo);
}
@RequestMapping(value = "/detail")
public ApiResponse getDetail(int id){
return productProfitService.getProductProfitDetail(id);
}
@RequestMapping(value = "/delete")
public ApiResponse deleteProductProfit(int id){ return productProfitService.deleteProductProfit(id); }
@RequestMapping(value = "/addOrUpdate")
public ApiResponse addOrUpdate(ProductProfitReqBo reqBo){
String operatorName = new UserHelper().getUserName();
if(StringUtils.isEmpty(operatorName)){
return new ApiResponse<>(400, "请先登录!", null);
}
return productProfitService.addOrUpdate(reqBo, operatorName);
}
@CrossOrigin(origins = "*")
@RequestMapping(value = "/batchImportFromXls", method = RequestMethod.POST)
public ApiResponse<Integer> batchImportFromXls(@RequestParam("file") MultipartFile file){
String operatorName = new UserHelper().getUserName();
if(StringUtils.isEmpty(operatorName)){
return new ApiResponse<>(400, "请先登录!", null);
}
if (file == null || file.getSize() == 0) {
return new ApiResponse<>(201, "请选择需要上传的文件!", null);
}
try {
return productProfitService.batchImportFromXls(file, operatorName);
}catch (PlatformException px) {
return new ApiResponse<>(px.getCode(), px.getMessage(), null);
} catch (Exception e) {
return new ApiResponse<>(201, "系统异常", null);
}
}
}
... ...
package com.yoho.ufo.service;
import com.yohobuy.ufo.model.common.ApiResponse;
import com.yohobuy.ufo.model.common.PageResponseBO;
import com.yohobuy.ufo.model.request.product.ProductProfitReqBo;
import com.yohobuy.ufo.model.request.product.ProductRequestBo;
import com.yohobuy.ufo.model.resp.product.ProductResponceBo;
import com.yohobuy.ufo.model.response.productProfit.ProductProfitRespBO;
import org.springframework.web.multipart.MultipartFile;
public interface IProductProfitService {
ApiResponse<PageResponseBO<ProductProfitRespBO>> getProductProfitPage(ProductProfitReqBo productProfitReq);
ApiResponse<ProductProfitRespBO> getProductProfitDetail(int id);
ApiResponse<Void> deleteProductProfit(int productId);
ApiResponse<Void> addOrUpdate(ProductProfitReqBo productProfitReqBo, String operatorName);
ApiResponse<Integer> batchImportFromXls(MultipartFile file, String operatorName) throws Exception;
}
... ...
package com.yoho.ufo.service.impl;
import com.yoho.message.sdk.utils.DateUtils;
import com.yoho.product.dal.ProductProfitMapper;
import com.yoho.product.model.ProductProfit;
import com.yoho.ufo.dal.model.ProductProfitImportItem;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.service.IProductProfitService;
import com.yoho.ufo.util.DateUtil;
import com.yohobuy.ufo.model.common.ApiResponse;
import com.yohobuy.ufo.model.common.PageResponseBO;
import com.yohobuy.ufo.model.request.product.ProductProfitReqBo;
import com.yohobuy.ufo.model.response.productProfit.ProductProfitRespBO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class ProductProfitServiceImpl implements IProductProfitService {
private static final Logger log = LoggerFactory.getLogger(ProductProfitServiceImpl.class);
@Autowired
ProductProfitMapper productProfitMapper;
@Autowired
private BatchService batchService;
@Override
public ApiResponse<PageResponseBO<ProductProfitRespBO>> getProductProfitPage(ProductProfitReqBo reqBo) {
int count = productProfitMapper.selectCount(reqBo.getProductId());
if( count == 0){
return new ApiResponse<>();
}
List<ProductProfit> doList = productProfitMapper.selectByCondition(reqBo);
List<ProductProfitRespBO> boList = new ArrayList<>();
for(ProductProfit productProfit : doList){
ProductProfitRespBO bo = new ProductProfitRespBO();
bo.setId(productProfit.getId());
bo.setProductId(productProfit.getProductId());
bo.setProfitRate(String.format("%.2f", productProfit.getProfitRate().multiply(BigDecimal.valueOf(100))) + '%');
bo.setProfitMaxPrice('¥' + String.valueOf(productProfit.getProfitMaxPrice()));
bo.setProfitMinPrice('¥' + String.valueOf(productProfit.getProfitMinPrice()));
bo.setAddUserName(productProfit.getAddUserName());
bo.setEditUserName(productProfit.getEditUserName());
bo.setCreateTime(DateUtil.int2DateStr(productProfit.getCreateTime(), DateUtil.DATE_TIME_FORMAT));
bo.setUpdateTime(DateUtil.int2DateStr(productProfit.getUpdateTime(), DateUtil.DATE_TIME_FORMAT));
boList.add(bo);
}
PageResponseBO<ProductProfitRespBO> page = new PageResponseBO<>(count, boList, reqBo.getPage(), reqBo.getRows());
return new ApiResponse<>(page);
}
@Override
public ApiResponse<ProductProfitRespBO> getProductProfitDetail(int id) {
ProductProfit productProfit = productProfitMapper.selectById(id);
ProductProfitRespBO respBO = new ProductProfitRespBO();
respBO.setId(productProfit.getId());
respBO.setProductId(productProfit.getProductId());
respBO.setProfitRate(String.format("%.2f", productProfit.getProfitRate().multiply(BigDecimal.valueOf(100))));
respBO.setProfitMinPrice(String.valueOf(productProfit.getProfitMinPrice()));
respBO.setProfitMaxPrice(String.valueOf(productProfit.getProfitMaxPrice()));
return new ApiResponse<>(respBO);
}
@Override
public ApiResponse<Void> deleteProductProfit(int id) {
//判断该skn是否存在
productProfitMapper.updateDelStatus(id);
return new ApiResponse<>();
}
@Override
public ApiResponse<Void> addOrUpdate(ProductProfitReqBo productProfitReqBo, String operatorName) {
ProductProfit productProfit = new ProductProfit();
productProfit.setProductId(productProfitReqBo.getProductId());
productProfit.setProfitRate(new BigDecimal(productProfitReqBo.getProfitRate()).divide(BigDecimal.valueOf(100)));
productProfit.setProfitMaxPrice(new BigDecimal(productProfitReqBo.getProfitMaxPrice()));
productProfit.setProfitMinPrice(new BigDecimal(productProfitReqBo.getProfitMinPrice()));
//新增
if(productProfitReqBo.getId() == 0){
//判断该商品是否已经配置, 不可重复添加
ProductProfit existProfit = productProfitMapper.selectByProductId(productProfitReqBo.getProductId());
if(existProfit != null && !existProfit.getId().equals(productProfitReqBo.getId())){
return new ApiResponse<>(400, "该商品已配置,不可重复配置");
}
productProfit.setAddUserName(operatorName);
productProfit.setCreateTime(DateUtils.getCurrentTimeSeconds());
productProfitMapper.insert(productProfit);
}
//修改
else{
productProfit.setId(productProfitReqBo.getId());
productProfit.setEditUserName(operatorName);
productProfit.setUpdateTime(DateUtils.getCurrentTimeSeconds());
productProfitMapper.update(productProfit);
}
return new ApiResponse<>();
}
@Override
public ApiResponse<Integer> batchImportFromXls(MultipartFile file, String operatorName) throws Exception {
List<ProductProfitImportItem> items = batchService.parseData(file, "ProductProfits", ProductProfitImportItem.class);
if(CollectionUtils.isEmpty(items)){
throw new PlatformException("导入的excel数据为空!", 400);
}
if(items.size() > 500){
throw new PlatformException("导入的excel数据不能超过500条!", 400);
}
//查询导入的数据中,那些已经保存过,获取那些已经保存过的记录的创建时间和创建人
List<Integer> productIdList = new ArrayList<>();
items.forEach(productProfitImportItem -> productIdList.add(productProfitImportItem.getProductId()));
List<ProductProfit> productProfits = productProfitMapper.selectByProductIds(productIdList);
Map<Integer, ProductProfit> productProfitMap = productProfits.stream().collect(Collectors.toMap(ProductProfit :: getProductId, ProductProfit -> ProductProfit));
//将导入数据插入到表中
ProductProfit productProfitExist;
int currentTime = DateUtils.getCurrentTimeSeconds();
List<ProductProfit> productProfitList = new ArrayList<>();
Set<Integer> productIdSet = new HashSet<>();
for(ProductProfitImportItem item : items){
if(productIdSet.contains(item.getProductId())) continue;
ProductProfit productProfit = new ProductProfit();
productProfit.setProductId(item.getProductId());
productProfit.setProfitRate(new BigDecimal(item.getProfitRate()).divide(BigDecimal.valueOf(100)));
productProfit.setProfitMaxPrice(new BigDecimal(item.getProfitMaxPrice()));
productProfit.setProfitMinPrice(new BigDecimal(item.getProfitMinPrice()));
productProfitExist = productProfitMap.get(item.getProductId());
productProfit.setCreateTime(productProfitExist != null ? productProfitExist.getCreateTime() : currentTime);
productProfit.setAddUserName(productProfitExist != null ? productProfitExist.getAddUserName() : operatorName);
productProfit.setEditUserName(operatorName);
productProfit.setUpdateTime(currentTime);
productProfitList.add(productProfit);
productIdSet.add(item.getProductId());
}
int result = productProfitMapper.insertBatchProductProfit(productProfitList);
return new ApiResponse<>(result);
}
}
... ...
... ... @@ -16,6 +16,7 @@
<url-pattern>/common/import.xlsx</url-pattern>
<url-pattern>/common/uid_import.xlsx</url-pattern>
<url-pattern>/common/importAttr.xlsx</url-pattern>
<url-pattern>/common/importProductProfit.xlsx</url-pattern>
</servlet-mapping>
... ...
<!DOCTYPE html>
<div id="tt" class="easyui-layout" fit="true" style="overflow-y: scroll">
<form name="productProfitEditForm" id="productProfitEditForm" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" id="id"/>
<div style="margin-top: 20px;margin-left: 30px">
<table border="0" style="width:95%;margin-top:5px;line-height:30px;" id="tab">
<tr style="height: 60px">
<td width="12%">商品编码<span class="requriedInput">*</span></td>
<td width="50%">
<input id="productId" name="productId" class="easyui-numberbox" style="width: 200px"/>
</td>
</tr>
<tr style="height: 60px" >
<td width="12%">平台服务费<span class="requriedInput">*</span></td>
<td width="20%">
<input id="profitRate" name="profitRate" class="easyui-numberbox" precision="2" max="100" style="width: 200px;" required="required"/>%
</td>
</tr>
<tr style="height: 60px" >
<td width="12%">平台服务费下限<span class="requriedInput">*</span></td>
<td width="20%">
<input id="profitMinPrice" name="profitMinPrice" class="easyui-numberbox" precision="2" min="0" style="width: 200px;" required="required"/>
</td>
</tr>
<tr style="height: 60px" >
<td width="12%">平台服务费上限<span class="requriedInput">*</span></td>
<td width="20%">
<input id="profitMaxPrice" name="profitMaxPrice" class="easyui-numberbox" precision="2" min="0" style="width: 200px;" required="required"/>
</td>
</tr>
</table>
</div>
</form>
</div>
<script>
$(function () {
$('#productProfitEditForm #id').val(editId);
if (editId > 0) {
$.post(contextPath + "/productProfit/detail", {
id: editId
}, function (data) {
$("#productProfitEditForm #productId").numberbox('readonly', true);
$("#productProfitEditForm").form("load", data.data);
});
}
});
</script>
\ No newline at end of file
... ...
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Yoho!Buy运营平台</title>
<script src="/ufoPlatform/js/include.js"></script>
<script src="/ufoPlatform/js/ajaxfileupload.js"></script>
<style>
.btn-download span {
line-height: 40px;
color: #87CEFA;
}
</style>
</head>
<body class="easyui-layout" fit="true">
<div region="north" style="height: 250px">
<script>
document.write(addHead('商品管理 /指定skn扣点配置', ''));
</script>
<div style="margin-left: 30px;" class="div_search">
<input id="productId" type="text" class="easyui-numberbox">
<a id="searchLinkButton" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">筛选</a>
<a id="searchAllLinkButton" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">全部</a>
<a id="addProductProfit" class="easyui-linkbutton btn-success" data-options="iconCls:'icon-search'">新增</a>
<form id="uploadForm" style="display: inline-block;">
<div id="uploadExcelButton" class="easyui-linkbutton btn-info"
style="width: 100px; height: 40px;cursor: pointer;">
<input id="upload_excel" name="upload_excel" type="file"
style="display: inline-block;width: 200px;height: 40px;margin: 0;padding: 0;opacity: 0;position: absolute;"
accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
导入EXCEL
</div>
</form>
<a href="..\..\common/importProductProfit.xlsx" style="height: 40px; display: inline-block; line-height: 40px;border: none; background: none;" class="easyui-linkbutton btn-info btn-download" target="_blank">下载样例.xlsx</a>
</div>
</div>
<div region="center">
<div style="margin-left: 30px;margin-top: 20px;height: 660px">
<table id="productProfitTable"></table>
</div>
</div>
<script type="text/javascript">
$(function () {
// 搜索
$("#searchLinkButton").linkbutton({
onClick: function () {
var param = {};
param.productId = $('#productId').textbox('getValue');
$("#productProfitTable").myDatagrid("load", param);
}
});
// 搜索全部
$("#searchAllLinkButton").linkbutton({
onClick: function () {
$('#productId').textbox('clear');
const param = {};
$("#productProfitTable").myDatagrid("load", param);
}
});
//新增
$('#addProductProfit').linkbutton({
iconCls: "icon-edit",
onClick: function () {
editProductProfit(0);
}
});
//商品编码筛选框
$("#productId").textbox({
prompt: "商品编码"
});
$("#productProfitTable").myDatagrid({
fit: true,
fitColumns: true,
nowrap: false,
url: contextPath + "/productProfit/list",
method: 'POST',
loadFilter: function (data) {
var temp = defaultLoadFilter(data);
temp.rows = temp.list;
return temp;
},
columns: [[{
title: "商品编码",
field: "productId",
width: 40,
align: "center"
}, {
title: "平台服务费",
field: "profitRate",
width: 80,
align: "center",
}, {
title: "下限",
field: "profitMinPrice",
width: 100,
align: "center"
},{
title: "上限",
field: "profitMaxPrice",
width: 100,
align: "center"
},{
title: "创建时间",
field: "createTime",
width: 100,
align: "center"
},{
title: "创建人",
field: "addUserName",
width: 100,
align: "center"
},{
title: "修改时间",
field: "updateTime",
width: 100,
align: "center"
},{
title: "修改人",
field: "editUserName",
width: 100,
align: "center"
},{
title: "操作",
field: "operations",
width: 80,
align: "center",
formatter: function (value, rowData) {
var str = "<a role='edit' dataId='" + rowData.id + "' style='margin-left:10px;background-color: #5bc0de'>编辑</a>";
str += "<a role='del' dataId='" + rowData.id + "' style='margin-left:10px;background-color: red'>删除</a>";
return str;
}
}]],
cache: false,
pagination: true,
pageSize: 10,
pageList: [10],
idField: "id",
singleSelect: false,
checkOnSelect: false,
onLoadSuccess: function () {
//编辑
$(this).myDatagrid("getPanel").find("a[role='edit']").linkbutton({
iconCls: "icon-edit",
onClick: function () {
editProductProfit($(this).attr("dataId"));
}
});
//删除
$(this).myDatagrid("getPanel").find("a[role='del']").linkbutton({
iconCls: "icon-more",
onClick: function () {
deleteProductProfit($(this).attr("dataId"));
}
});
}
});
function editProductProfit(id) {
editId = id;
var div = $("<div>").appendTo($(document.body));
var title = "编辑";
var message = "确认修改吗?";
if (id == 0) {
title = "添加";
message = "确认添加吗?";
}
$(div).myDialog({
width: "600px",
height: "400px",
title: title,
href: contextPath + "/html/productProfit/ProductProfitEdit.html",
queryParams: {
id: id
},
modal: true,
collapsible: true,
cache: false,
buttons: [{
id: "saveBtn",
text: "保存",
handler: function () {
$.messager.confirm("确认", message, function (flag) {
if (flag) {
var url = contextPath + "/productProfit/addOrUpdate";
$("#productProfitEditForm").form("submit", {
url: url,
onSubmit: function () {
if (!$("#productProfitEditForm").form("validate")) {
return false;
}
if($("#productProfitEditForm #profitMaxPrice").val() < $("#productProfitEditForm #profitMinPrice").val()){
$.messager.alert("失败", "下限不能超过上限", "error");
return false;
}
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后..."
});
return true;
},
success: function (data) {
$.messager.progress("close");
data = JSON.parse(data);
if (data.code == 200) {
$(div).dialog("close");
$("#productProfitTable").myDatagrid("reload");
$.messager.show({
title: "提示",
msg: title + "成功!",
height: 120
});
} else {
$.messager.alert("失败", data.message, "error");
}
}
});
}
});
}
}, {
text: "关闭",
iconCls: "icon-cancel",
handler: function () {
$(div).dialog("close");
}
}]
});
}
function deleteProductProfit(id) {
$.messager.confirm("确认", "确认要删除吗", function (flag) {
if (flag) {
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后...",
interval: 500,
text: ""
});
$.post(contextPath + "/productProfit/delete", {
"id": id,
}, function (data) {
$.messager.progress("close");
if (data.code == 200) {
$("#productProfitTable").myDatagrid("reload");
$.messager.show({
title: "提示",
msg: "删除成功",
height: 120
});
} else {
$.messager.alert("失败", data.message, "error");
}
}, "json");
}
});
}
//上传excel
$('#upload_excel').on('change', uploadExcel);
function uploadExcel() {
const upload = $('#upload_excel');
if (upload.val()) {
const formData = new FormData();
const name = upload.val();
formData.append('name', name);
formData.append('file', upload[0].files[0]);
$.ajax({
url: contextPath + '/productProfit/batchImportFromXls',
data: formData,
method: 'POST',
cache: false,
processData: false,
contentType: false,
xhrFields: {withCredentials: true},
success: function (res) {
if (res.code !== 200) {
$.messager.alert("失败", res.message, "error");
} else {
$('#upload_excel').val('');
$("#productProfitTable").myDatagrid("reload");
$.messager.show({
title: "提示",
msg: "导入成功!"
});
}
}
});
}
}
})
</script>
</body>
</html>
... ...