|
|
package controllers
|
|
|
|
|
|
import (
|
|
|
"crypto/md5"
|
|
|
"encoding/hex"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
"github.com/beego/beego/v2/client/httplib"
|
|
|
"os"
|
|
|
"path"
|
|
|
"regexp"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
"unicode/utf8"
|
|
|
|
|
|
"github.com/360EntSecGroup-Skylar/excelize/v2"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/constant"
|
|
|
|
|
|
"github.com/astaxie/beego/logs"
|
|
|
orderCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/command"
|
|
|
orderQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/query"
|
|
|
orderService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/orderinfo/service"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/utils"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib/exceltool"
|
|
|
)
|
...
|
...
|
@@ -62,6 +71,7 @@ func (postData *postPurposeOrderDetail) Valid() error { |
|
|
}
|
|
|
if postData.PartnerId == 0 {
|
|
|
return lib.ThrowError(lib.ARG_ERROR, "合伙人信息必填")
|
|
|
|
|
|
}
|
|
|
if len(postData.OrderDist) == 0 {
|
|
|
return lib.ThrowError(lib.ARG_ERROR, "订单区域必填")
|
...
|
...
|
@@ -141,10 +151,19 @@ func (postData *postOrderPurposeDelivery) Valid() error { |
|
|
return nil
|
|
|
}
|
|
|
|
|
|
//PageListOrderReal 获取实发订单列表
|
|
|
/**
|
|
|
* @Author SteveChan
|
|
|
* @Description // 获取实发订单列表,修改搜索条件
|
|
|
* @Date 20:23 2021/1/10
|
|
|
* @Param
|
|
|
* @return
|
|
|
**/
|
|
|
func (c *OrderInfoController) PageListOrderReal() {
|
|
|
type Parameter struct {
|
|
|
SearchText string `json:"searchText"`
|
|
|
//SearchText string `json:"searchText"`
|
|
|
PartnerName string `json:"partnerName"` // 合伙人姓名
|
|
|
OrderCode string `json:"orderCode"` // 订单号
|
|
|
DeliveryCode string `json:"deliveryCode"` // 发货单号
|
|
|
PartnerCategory int `json:"PartnerCategory"`
|
|
|
PageSize int `json:"pageSize"`
|
|
|
PageNumber int `json:"pageNumber"`
|
...
|
...
|
@@ -222,7 +241,10 @@ func (c *OrderInfoController) PageListOrderReal() { |
|
|
companyId := c.GetUserCompany()
|
|
|
orderSrv := orderService.NewOrderInfoService(nil)
|
|
|
orderinfos, cnt, err := orderSrv.PageListOrderBase(orderQuery.ListOrderBaseQuery{
|
|
|
PartnerOrCode: param.SearchText,
|
|
|
//PartnerOrCode: param.SearchText,
|
|
|
PartnerName: param.PartnerName,
|
|
|
OrderCode: param.OrderCode,
|
|
|
DeliveryCode: param.DeliveryCode,
|
|
|
OrderType: domain.OrderReal,
|
|
|
Limit: param.PageSize,
|
|
|
Offset: (param.PageNumber - 1) * param.PageSize,
|
...
|
...
|
@@ -506,7 +528,10 @@ func (c *OrderInfoController) RemoveOrderReal() { |
|
|
//ListOrderForExcel excel 导出实际订单的列表
|
|
|
func (c *OrderInfoController) ListOrderForExcel() {
|
|
|
type Parameter struct {
|
|
|
SearchText string `json:"searchText"`
|
|
|
//SearchText string `json:"searchText"`
|
|
|
PartnerName string `json:"partnerName"` // 合伙人姓名
|
|
|
OrderCode string `json:"orderCode"` // 订单号
|
|
|
DeliveryCode string `json:"deliveryCode"` // 发货单号
|
|
|
PartnerCategory int `json:"PartnerCategory"`
|
|
|
UpdateTime []string `json:"updateTime"`
|
|
|
CreateTime []string `json:"createTime"`
|
...
|
...
|
@@ -576,7 +601,10 @@ func (c *OrderInfoController) ListOrderForExcel() { |
|
|
companyId := c.GetUserCompany()
|
|
|
orderSrv := orderService.NewOrderInfoService(nil)
|
|
|
orderinfos, columns, err := orderSrv.ListOrderForExcel(orderQuery.ListOrderBaseQuery{
|
|
|
PartnerOrCode: param.SearchText,
|
|
|
//PartnerOrCode: param.SearchText,
|
|
|
PartnerName: param.PartnerName,
|
|
|
OrderCode: param.OrderCode,
|
|
|
DeliveryCode: param.DeliveryCode,
|
|
|
OrderType: domain.OrderReal,
|
|
|
CompanyId: companyId,
|
|
|
PartnerCategory: param.PartnerCategory,
|
...
|
...
|
@@ -603,3 +631,576 @@ func (c *OrderInfoController) ListOrderForExcel() { |
|
|
c.ResponseExcelByFile(c.Ctx, excelMaker)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @Author SteveChan
|
|
|
* @Description // 下载导入模板
|
|
|
* @Date 16:48 2021/1/8
|
|
|
* @Param
|
|
|
* @return
|
|
|
**/
|
|
|
func (c *OrderInfoController) DownloadTemplate() {
|
|
|
type Parameter struct {
|
|
|
TYPE string `json:"type"`
|
|
|
}
|
|
|
|
|
|
var (
|
|
|
param Parameter
|
|
|
err error
|
|
|
)
|
|
|
|
|
|
if err = c.BindJsonData(¶m); err != nil {
|
|
|
logs.Error(err)
|
|
|
c.ResponseError(errors.New("json数据解析失败"))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 校验类型编码
|
|
|
if param.TYPE != "PARTNER_ORDER_FILE" {
|
|
|
c.ResponseError(errors.New("类型编码错误"))
|
|
|
}
|
|
|
|
|
|
// 创建下载文件夹
|
|
|
mkErr := os.Mkdir("download", os.ModePerm)
|
|
|
if mkErr != nil {
|
|
|
fmt.Println(mkErr)
|
|
|
}
|
|
|
|
|
|
// 获取导入模板
|
|
|
req := httplib.Get("http://suplus-file-dev.fjmaimaimai.com/upload/file/2021010803305336443.xlsx")
|
|
|
err = req.ToFile(constant.IMPORT_EXCEL)
|
|
|
if err != nil {
|
|
|
logs.Error("could not save to file: ", err)
|
|
|
}
|
|
|
|
|
|
// 返回字段定义
|
|
|
ret := map[string]interface{}{}
|
|
|
|
|
|
resp, err := req.Response()
|
|
|
if err != nil {
|
|
|
logs.Error("could not get response: ", err)
|
|
|
} else {
|
|
|
logs.Info(resp)
|
|
|
ret = map[string]interface{}{
|
|
|
"url": "http://" + c.Ctx.Request.Host + "/partnermg/download/订单数据模板.xlsx",
|
|
|
}
|
|
|
c.ResponseData(ret)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @Author SteveChan
|
|
|
* @Description // 导入excel订单
|
|
|
* @Date 10:52 2021/1/6
|
|
|
* @Param
|
|
|
* @return
|
|
|
**/
|
|
|
func (c *OrderInfoController) ImportOrderFromExcel() {
|
|
|
// 获取参数
|
|
|
typeCode := c.GetString("type")
|
|
|
file, h, _ := c.GetFile("file")
|
|
|
companyId := c.GetUserCompany()
|
|
|
|
|
|
if typeCode != "PARTNER_ORDER_FILE" {
|
|
|
c.ResponseError(errors.New("类型编码错误"))
|
|
|
}
|
|
|
|
|
|
// 返回字段定义
|
|
|
ret := map[string]interface{}{}
|
|
|
|
|
|
// 返回信息表头定义 0: 订单号, 1: 发货单号, 2: 客户名称, 3: 订单区域, 4: 编号, 5: 合伙人, 6: 类型, 7: 业务员抽成比例, 8: 产品名称, 9: 数量, 10: 单价, 11: 合伙人分红比例
|
|
|
var tableHeader = []string{"错误详情", "行号", "订单号", "发货单号", "客户名称", "订单区域", "编号", "合伙人", "类型", "业务员抽成比例", "产品名称", "数量", "单价", "合伙人分红比例"}
|
|
|
|
|
|
// 文件后缀名校验
|
|
|
ext := path.Ext(h.Filename)
|
|
|
AllowExtMap := map[string]bool{
|
|
|
".xlsx": true,
|
|
|
}
|
|
|
if _, ok := AllowExtMap[ext]; !ok {
|
|
|
c.ResponseError(errors.New("文件后缀名不符合上传要求,请上传正确格式的文件"))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 打开文件
|
|
|
xlsx, err := excelize.OpenReader(file)
|
|
|
if err != nil {
|
|
|
c.ResponseError(errors.New("文件打开失败,请确定文件能够正常打开"))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 文件行数校验
|
|
|
rows, _ := xlsx.GetRows("工作表1")
|
|
|
if len(rows) > 303 {
|
|
|
c.ResponseError(errors.New("导入文件的行数超过300行,请调整行数后重新导入"))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 文件列数据校验
|
|
|
overColumnLine := make([]interface{}, 0)
|
|
|
for i, row := range rows {
|
|
|
if i > 2 && row != nil {
|
|
|
if len(row) > constant.EXCEL_COLUMN {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "存在无效的数据列,请删除无效的列数据") // 错误信息
|
|
|
s := strconv.Itoa(i + 1)
|
|
|
tmpRow = append(tmpRow, s) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
overColumnLine = append(overColumnLine, tmpRow)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if len(overColumnLine) > 0 {
|
|
|
ret = map[string]interface{}{
|
|
|
"successCount": 0,
|
|
|
"fail": map[string]interface{}{
|
|
|
"tableHeader": tableHeader,
|
|
|
"tableData": overColumnLine,
|
|
|
},
|
|
|
}
|
|
|
c.ResponseData(ret)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 数据行计数
|
|
|
rowCnt := 0
|
|
|
|
|
|
// 空文件校验
|
|
|
if len(rows) < 3 {
|
|
|
c.ResponseError(errors.New("导入的excel文件为空文件,请上传正确的文件"))
|
|
|
}
|
|
|
|
|
|
// 必填项校验
|
|
|
nullLine := make([]interface{}, 0)
|
|
|
|
|
|
nullFlag := false
|
|
|
for i, row := range rows {
|
|
|
if i > 2 && row != nil {
|
|
|
rowCnt++
|
|
|
if len(row) == constant.EXCEL_COLUMN { // 必填项内容为空
|
|
|
var tmpRow = row
|
|
|
nullCell := make([]interface{}, 0)
|
|
|
var myRow []string
|
|
|
for j, _ := range row {
|
|
|
if j != 7 { // 业务员抽成比例非必填
|
|
|
if row[j] == "" || row[j] == " " { // 空字符补位
|
|
|
tmpRow[j] = ""
|
|
|
col := strconv.Itoa(j + 1)
|
|
|
nullCell = append(nullCell, col)
|
|
|
nullFlag = true
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if nullFlag {
|
|
|
s := strconv.Itoa(i + 1)
|
|
|
b := strings.Replace(strings.Trim(fmt.Sprint(nullCell), "[]"), " ", ",", -1)
|
|
|
myRow = append(myRow, "第"+s+"行的第"+b+"列必填项为空") // 错误信息
|
|
|
myRow = append(myRow, s) // 行号
|
|
|
myRow = append(myRow, tmpRow...) // 错误行数据
|
|
|
nullLine = append(nullLine, myRow)
|
|
|
nullFlag = false
|
|
|
}
|
|
|
} else if len(row) > 0 && len(row) < constant.EXCEL_COLUMN { // 必填项不存在
|
|
|
var myRow []string
|
|
|
myRow = append(myRow, "必填项为空")
|
|
|
s := strconv.Itoa(i + 1)
|
|
|
myRow = append(myRow, s) // 行号
|
|
|
myRow = append(myRow, row...) // 错误行数据
|
|
|
emptyCell := make([]interface{}, 0)
|
|
|
// 错误信息
|
|
|
for k := 0; k < constant.EXCEL_COLUMN-len(row); k++ { // 空字符补位
|
|
|
myRow = append(myRow, "")
|
|
|
}
|
|
|
for k, cell := range myRow {
|
|
|
if k != 0 && cell == "" {
|
|
|
emptyCell = append(emptyCell, k-1)
|
|
|
}
|
|
|
}
|
|
|
b := strings.Replace(strings.Trim(fmt.Sprint(emptyCell), "[]"), " ", ",", -1)
|
|
|
myRow[0] = "第" + s + "行的第" + b + "列必填项为空"
|
|
|
nullLine = append(nullLine, myRow)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 空单元格返回
|
|
|
if len(nullLine) > 0 {
|
|
|
ret = map[string]interface{}{
|
|
|
"successCount": 0,
|
|
|
"fail": map[string]interface{}{
|
|
|
"tableHeader": tableHeader,
|
|
|
"tableData": nullLine,
|
|
|
},
|
|
|
}
|
|
|
c.ResponseData(ret)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 内容校验
|
|
|
errorLine := make([]interface{}, 0)
|
|
|
var partnerType = []string{"事业合伙", "业务合伙", "研发合伙", "业务-产品应用合伙"}
|
|
|
for i, row := range rows {
|
|
|
if i > 2 && row != nil && len(row) == constant.EXCEL_COLUMN { // 数据行
|
|
|
var myRow []string
|
|
|
for j, cell := range row {
|
|
|
|
|
|
r := strconv.Itoa(i + 1)
|
|
|
col := strconv.Itoa(j + 1)
|
|
|
|
|
|
switch j {
|
|
|
case 0, 1, 2, 3, 4, 5, 8: // 订单号、发货单号、客户名称、订单区域、编号、合伙人、产品名称长度校验
|
|
|
{
|
|
|
cellStr := strings.TrimSpace(cell)
|
|
|
lenCellStr := utf8.RuneCountInString(cellStr)
|
|
|
|
|
|
if lenCellStr > 50 {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列"+tableHeader[j+2]+"长度超过50位,请重新输入") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
}
|
|
|
case 6: // 合伙人类型校验(事业合伙、业务合伙、研发合伙、业务-产品应用合伙)
|
|
|
{
|
|
|
if !utils.IsContain(partnerType, cell) {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列合伙人类型错误,合伙人类型必须为以下类型:事业合伙、业务合伙、研发合伙、业务-产品应用合伙") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
}
|
|
|
case 7: // 业务员抽成比例,非必填,精确到小数点后两位
|
|
|
{
|
|
|
if len(cell) > 0 {
|
|
|
|
|
|
// 参数类型转换
|
|
|
shareRatio, err := strconv.ParseFloat(cell, 64)
|
|
|
if err != nil {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列业务员抽成比例格式错误,业务员抽成比例必须为数字") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
|
|
|
// 比例不能超过100%
|
|
|
if shareRatio > 100 {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列业务员抽成比例超过限额,请输入正确的业务员抽成比例,并保留两位小数") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
|
|
|
// 长度校验
|
|
|
regexpStr := `^(100|[1-9]\d|\d)(.\d{1,2})?$`
|
|
|
ok := regexp.MustCompile(regexpStr).MatchString(cell)
|
|
|
if !ok {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列业务员抽成比例超过最大长度,请输入正确的业务员抽成比例,并保留两位小数") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
case 9: // 数量不超过16位正整数
|
|
|
{
|
|
|
//参数类型转换
|
|
|
orderNum, err := strconv.ParseInt(cell, 10, 64)
|
|
|
if err != nil {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列产品数量格式错误,产品数量必须整数") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
|
|
|
// 长度校验
|
|
|
if orderNum > 1e16 {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列产品数量长度超过最大限制十六位整数,请重新填写") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
}
|
|
|
case 10: // 单价,精确到小数点后两位,小数点左侧最多可输入16位数字
|
|
|
{
|
|
|
|
|
|
// 参数类型转换
|
|
|
univalent, typeErr := strconv.ParseFloat(cell, 64)
|
|
|
if typeErr != nil {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列单价格式错误,产品单价必须为数字类型") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
|
|
|
// 长度校验
|
|
|
if univalent >= 1e16 {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列产品单价超过最大限制,产品单价小数点前面不能超过十六位数字,并保留两位小数") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
}
|
|
|
case 11: // 合伙人分红比例,精确到小数点后两位
|
|
|
{
|
|
|
//参数类型转换
|
|
|
partnerRatio, parseErr := strconv.ParseFloat(cell, 64)
|
|
|
if parseErr != nil {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列合伙人分红比例类型错误,合伙人分红比例必须为数字") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
|
|
|
// 合伙人分红比例超额
|
|
|
if partnerRatio > 100 {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列合伙人分红比例超过限额,请输入正确的合伙人分红比例,并保留两位小数") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
|
|
|
// 长度判断
|
|
|
regexpStr := `^(100|[1-9]\d|\d)(.\d{1,2})?$`
|
|
|
ok := regexp.MustCompile(regexpStr).MatchString(cell)
|
|
|
if !ok {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "第"+r+"行第"+col+"列合伙人分红比例超过最大长度,请输入正确的合伙人分红比例,并保留两位小数") // 错误信息
|
|
|
tmpRow = append(tmpRow, r) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
myRow = tmpRow
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if myRow != nil {
|
|
|
errorLine = append(errorLine, myRow)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 内容错误行返回
|
|
|
if len(errorLine) > 0 {
|
|
|
ret = map[string]interface{}{
|
|
|
"successCount": 0,
|
|
|
"fail": map[string]interface{}{
|
|
|
"tableHeader": tableHeader,
|
|
|
"tableData": errorLine,
|
|
|
},
|
|
|
}
|
|
|
c.ResponseData(ret)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 创建订单服务
|
|
|
orderSrv := orderService.NewOrderInfoService(nil)
|
|
|
|
|
|
// 合伙人检索错误
|
|
|
partnerDataList := make([]interface{}, 0)
|
|
|
|
|
|
// 聚合订单产品
|
|
|
var orderCommands = make(map[string]*orderCmd.CreateOrderCommand, 0)
|
|
|
for i, row := range rows {
|
|
|
if i > 2 && len(row) == constant.EXCEL_COLUMN {
|
|
|
hashValue := md5.Sum([]byte(row[0] + row[1] + row[4] + row[6])) // 根据:订单号+发货单号+合伙人编号+合伙类型计算哈希值
|
|
|
hashString := hex.EncodeToString(hashValue[:])
|
|
|
|
|
|
if _, ok := orderCommands[hashString]; !ok {
|
|
|
//订单相关,0: 订单号, 1: 发货单号, 2: 客户名称, 3: 订单区域, 4: 编号, 5: 合伙人, 6: 类型, 7: 业务抽成比例,
|
|
|
sbPercent, _ := strconv.ParseFloat(row[7], 64) //业务抽成比例
|
|
|
|
|
|
//产品相关,8: 产品名称, 9: 数量, 10: 单价, 11: 合伙人分红比例
|
|
|
amount, _ := strconv.ParseInt(row[9], 10, 64) // 数量
|
|
|
price, _ := strconv.ParseFloat(row[10], 64) // 单价
|
|
|
percent, _ := strconv.ParseFloat(row[11], 64) // 合伙人分红比例
|
|
|
|
|
|
// 获取partnerId
|
|
|
var partnerInfo *domain.PartnerInfo
|
|
|
|
|
|
orderQueryData := orderQuery.GetPartnerIdQuery{
|
|
|
Code: row[4],
|
|
|
PartnerCategory: 0,
|
|
|
CompanyId: companyId,
|
|
|
}
|
|
|
|
|
|
// 1: 事业合伙、2: 业务合伙、3: 研发合伙、4: 业务-产品应用合伙
|
|
|
switch row[6] {
|
|
|
case "事业合伙":
|
|
|
orderQueryData.PartnerCategory = 1
|
|
|
case "业务合伙":
|
|
|
orderQueryData.PartnerCategory = 2
|
|
|
case "研发合伙":
|
|
|
orderQueryData.PartnerCategory = 3
|
|
|
case "业务-产品应用合伙":
|
|
|
orderQueryData.PartnerCategory = 4
|
|
|
default:
|
|
|
orderQueryData.PartnerCategory = 0
|
|
|
}
|
|
|
|
|
|
// 初始化建订单命令集
|
|
|
orderCommands[hashString] = &orderCmd.CreateOrderCommand{
|
|
|
OrderType: 0,
|
|
|
OrderCode: row[0],
|
|
|
DeliveryCode: row[1],
|
|
|
BuyerName: row[2],
|
|
|
OrderRegion: row[3],
|
|
|
PartnerId: 0, // 根据合伙人类型+合伙人编号查找合伙人id
|
|
|
SalesmanBonusPercent: sbPercent,
|
|
|
Goods: []orderCmd.OrderGoodData{
|
|
|
{
|
|
|
GoodName: row[8],
|
|
|
PlanGoodNumber: int(amount),
|
|
|
Price: price,
|
|
|
PartnerBonusPercent: percent,
|
|
|
LineNumber: i,
|
|
|
},
|
|
|
},
|
|
|
CompanyId: companyId,
|
|
|
PartnerCategory: int64(orderQueryData.PartnerCategory),
|
|
|
LineNumbers: []int{i}, // 记录行号
|
|
|
}
|
|
|
|
|
|
partnerInfo, err = orderSrv.GetPartnerIdByCodeAndCategory(orderQueryData)
|
|
|
if err != nil || partnerInfo == nil { // 检索合伙人错误
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, err.Error()) // 错误信息
|
|
|
s := strconv.Itoa(i + 1)
|
|
|
tmpRow = append(tmpRow, s) // 行号
|
|
|
tmpRow = append(tmpRow, row...) // 错误行数据
|
|
|
partnerDataList = append(partnerDataList, tmpRow)
|
|
|
}
|
|
|
if partnerInfo != nil {
|
|
|
orderCommands[hashString].PartnerId = partnerInfo.Partner.Id
|
|
|
}
|
|
|
} else {
|
|
|
//产品相关,8: 产品名称, 9: 数量, 10: 单价, 11: 合伙人分红比例
|
|
|
amount, _ := strconv.ParseInt(row[9], 10, 64) // 数量
|
|
|
price, _ := strconv.ParseFloat(row[10], 64) // 单价
|
|
|
percent, _ := strconv.ParseFloat(row[11], 64) // 合伙人分红比例
|
|
|
|
|
|
// 记录同一笔订单产品
|
|
|
orderCommands[hashString].Goods = append(orderCommands[hashString].Goods, orderCmd.OrderGoodData{
|
|
|
GoodName: row[8],
|
|
|
PlanGoodNumber: int(amount),
|
|
|
Price: price,
|
|
|
PartnerBonusPercent: percent,
|
|
|
LineNumber: i, // 记录行号
|
|
|
})
|
|
|
|
|
|
// 记录聚合行号
|
|
|
orderCommands[hashString].LineNumbers = append(orderCommands[hashString].LineNumbers, i)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if len(partnerDataList) > 0 {
|
|
|
ret = map[string]interface{}{
|
|
|
"successCount": 0,
|
|
|
"fail": map[string]interface{}{
|
|
|
"tableHeader": tableHeader,
|
|
|
"tableData": partnerDataList,
|
|
|
},
|
|
|
}
|
|
|
c.ResponseData(ret)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 产品数量校验
|
|
|
productNumberError := make([]interface{}, 0)
|
|
|
|
|
|
// 批量创建订单命令集和产品数量校验
|
|
|
var createOrderCommands []*orderCmd.CreateOrderCommand
|
|
|
for _, orderCommand := range orderCommands {
|
|
|
if len(orderCommand.Goods) > 50 { // 产品数量校验
|
|
|
for _, line := range orderCommand.LineNumbers {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, "单笔订单产品超过50种") // 错误信息
|
|
|
s := strconv.Itoa(line + 1)
|
|
|
tmpRow = append(tmpRow, s) // 行号
|
|
|
tmpRow = append(tmpRow, rows[line]...) // 错误行数据
|
|
|
productNumberError = append(productNumberError, tmpRow)
|
|
|
}
|
|
|
} else {
|
|
|
createOrderCommands = append(createOrderCommands, orderCommand)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if len(productNumberError) > 0 {
|
|
|
ret = map[string]interface{}{
|
|
|
"successCount": 0,
|
|
|
"fail": map[string]interface{}{
|
|
|
"tableHeader": tableHeader,
|
|
|
"tableData": productNumberError,
|
|
|
},
|
|
|
}
|
|
|
c.ResponseData(ret)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// 新增失败记录
|
|
|
failureDataList := make([]interface{}, 0)
|
|
|
|
|
|
// 新增成功记录计数
|
|
|
var successDataCount int64
|
|
|
|
|
|
// 批量新增订单
|
|
|
errorDataList, createError := orderSrv.CreateNewOrderByImport(createOrderCommands)
|
|
|
if createError != nil {
|
|
|
c.ResponseError(createError)
|
|
|
return
|
|
|
} else {
|
|
|
if len(errorDataList) > 0 { // 导入失败返回
|
|
|
successDataCount = 0
|
|
|
// 错误记录处理
|
|
|
for _, errorData := range errorDataList {
|
|
|
if len(errorData.GoodLine) == 0 { // 订单错误
|
|
|
for _, line := range errorData.LineNumbers {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, errorData.Error.Error()) // 错误信息
|
|
|
s := strconv.Itoa(line + 1)
|
|
|
tmpRow = append(tmpRow, s) // 行号
|
|
|
tmpRow = append(tmpRow, rows[line]...) // 错误行数据
|
|
|
failureDataList = append(failureDataList, tmpRow)
|
|
|
}
|
|
|
} else if len(errorData.GoodLine) > 0 { // 订单产品错误
|
|
|
for line := range errorData.GoodLine {
|
|
|
var tmpRow []string
|
|
|
tmpRow = append(tmpRow, errorData.Error.Error()) // 错误信息
|
|
|
s := strconv.Itoa(line + 1)
|
|
|
tmpRow = append(tmpRow, s) // 行号
|
|
|
tmpRow = append(tmpRow, rows[line]...) // 错误行数据
|
|
|
failureDataList = append(failureDataList, tmpRow)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
ret = map[string]interface{}{
|
|
|
"successCount": successDataCount,
|
|
|
"fail": map[string]interface{}{
|
|
|
"tableHeader": tableHeader,
|
|
|
"tableData": failureDataList,
|
|
|
},
|
|
|
}
|
|
|
} else { // 导入成功返回
|
|
|
successDataCount = int64(rowCnt - len(failureDataList))
|
|
|
if successDataCount == int64(rowCnt) {
|
|
|
ret = map[string]interface{}{
|
|
|
"successCount": successDataCount,
|
|
|
"fail": nil,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 返回错误详情
|
|
|
c.ResponseData(ret)
|
|
|
return
|
|
|
} |
...
|
...
|
|