Răsfoiți Sursa

feature/无审批:去除oms中审批流功能

yanglingling 1 an în urmă
părinte
comite
c7366a00f5

+ 113 - 55
opms_parent/app/service/base/base_distributor.go

@@ -195,7 +195,7 @@ func (s *distributorService) Create(ctx context.Context, req *model.AddDistribut
 	DistributorData.DistCode = code
 	if DistributorData.DistType == "20" {
 		DistributorData.ApproItem = "创建代理商"
-		DistributorData.ApproStatus = "20"
+		DistributorData.ApproStatus = "30"
 		if req.ContractUrl != "" && req.ContractFileName == "" {
 			return 0, myerrors.TipsError("合同文件名不能为空")
 		}
@@ -208,12 +208,6 @@ func (s *distributorService) Create(ctx context.Context, req *model.AddDistribut
 			return err
 		}
 		DistributorData.Id = int(id)
-		if DistributorData.DistType == "20" {
-			err = s.createDingtalkProcess(ctx, DistributorData, req.ContractFileName)
-			if err != nil {
-				return err
-			}
-		}
 		err = s.AddDynamicsByCurrentUser(tx, int(id), "创建经销商/代理商", map[string]interface{}{})
 		return err
 	})
@@ -389,30 +383,54 @@ func (s *distributorService) ToProxy(ctx context.Context, req *model.Distributor
 	if ent == nil {
 		return myerrors.TipsError(fmt.Sprintf("代理商/经销商不存在: %d", req.Id))
 	}
-	approvalData := model.ToProxyApproveData{
-		CustomerType:   req.CustomerType,
-		ProxyStartTime: req.ProxyStartTime,
-		ProxyEndTime:   req.ProxyEndTime,
-		ProxyDistrict:  req.ProxyDistrict,
-		ContractUrl:    req.ContractUrl,
-		OperatedId:     s.CxtUser.Id,
-		OperatedName:   s.CxtUser.NickName,
-	}
-	approvalDataByte, err := json.Marshal(approvalData)
-	if err != nil {
-		return err
-	}
 
 	txerr := s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
 		_, err = tx.Update("base_distributor", map[string]interface{}{
-			"appro_status": "20",
-			"appro_data":   string(approvalDataByte),
-			"appro_item":   "经销商转代理商",
+			"dist_type":        "20",
+			"appro_status":     "30",
+			"appro_data":       "",
+			"appro_item":       "经销商转代理商",
+			"customer_type":    req.CustomerType,
+			"proxy_start_time": req.ProxyStartTime,
+			"proxy_end_time":   req.ProxyEndTime,
+			"proxy_district":   req.ProxyDistrict,
+			"contract_url":     req.ContractUrl,
 		}, "id = ?", req.Id)
 		if err != nil {
 			return err
 		}
-		return s.toProxyDingtalkProcess(ctx, ent, req)
+
+		_, err = tx.Insert("base_distributor_record", model.BaseDistributorRecord{
+			DistId:          ent.Id,
+			DistType:        "20",
+			BusinessScope:   ent.BusinessScope,
+			CustomerType:    req.CustomerType,
+			ProxyDistrict:   req.ProxyDistrict,
+			ProxyStartTime:  req.ProxyStartTime,
+			ProxyEndTime:    req.ProxyEndTime,
+			ContractUrl:     req.ContractUrl,
+			ExistedProduct:  ent.ExistedProduct,
+			HistoryCustomer: ent.HistoryCustomer,
+			ToDistReason:    "",
+			Remark:          "",
+			CreatedBy:       s.GetCxtUserId(),
+			CreatedName:     s.GetCxtUserName(),
+			CreatedTime:     gtime.Now(),
+			UpdatedBy:       s.GetCxtUserId(),
+			UpdatedName:     s.GetCxtUserName(),
+			UpdatedTime:     gtime.Now(),
+		})
+		if err != nil {
+			return err
+		}
+
+		err = addDynamicsByCurrentUser(tx, ent.Id, "转为代理商",
+			req, s.GetCxtUserId(), s.GetCxtUserName())
+		if err != nil {
+			return err
+		}
+
+		return nil
 	})
 	return txerr
 }
@@ -504,30 +522,51 @@ func (s *distributorService) Renew(ctx context.Context, req *model.DistributorRe
 		return myerrors.TipsError(fmt.Sprintf("代理商/经销商不存在: %d", req.Id))
 	}
 
-	approvalData := model.RenewApproveData{
-		CustomerType:   req.CustomerType,
-		ProxyStartTime: req.ProxyStartTime,
-		ProxyEndTime:   req.ProxyEndTime,
-		ProxyDistrict:  req.ProxyDistrict,
-		ContractUrl:    req.ContractUrl,
-		OperatedId:     s.CxtUser.Id,
-		OperatedName:   s.CxtUser.NickName,
-	}
-	approvalDataByte, err := json.Marshal(approvalData)
-	if err != nil {
-		return err
-	}
-
 	txerr := s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
 		_, err = tx.Update("base_distributor", map[string]interface{}{
-			"appro_status": "20",
-			"appro_data":   string(approvalDataByte),
-			"appro_item":   "代理商续签",
+			"appro_status":     "30",
+			"appro_data":       "",
+			"appro_item":       "代理商续签",
+			"customer_type":    req.CustomerType,
+			"proxy_start_time": req.ProxyStartTime,
+			"proxy_end_time":   req.ProxyEndTime,
+			"proxy_district":   req.ProxyDistrict,
+			"contract_url":     req.ContractUrl,
 		}, "id = ?", req.Id)
 		if err != nil {
 			return err
 		}
-		return s.renewDingtalkProcess(ctx, ent, req)
+
+		_, err = tx.Insert("base_distributor_record", model.BaseDistributorRecord{
+			DistId:          ent.Id,
+			DistType:        "20",
+			BusinessScope:   ent.BusinessScope,
+			CustomerType:    req.CustomerType,
+			ProxyDistrict:   req.ProxyDistrict,
+			ProxyStartTime:  req.ProxyStartTime,
+			ProxyEndTime:    req.ProxyEndTime,
+			ContractUrl:     req.ContractUrl,
+			ExistedProduct:  ent.ExistedProduct,
+			HistoryCustomer: ent.HistoryCustomer,
+			ToDistReason:    "",
+			Remark:          "",
+			CreatedBy:       s.GetCxtUserId(),
+			CreatedName:     s.GetCxtUserName(),
+			CreatedTime:     gtime.Now(),
+			UpdatedBy:       s.GetCxtUserId(),
+			UpdatedName:     s.GetCxtUserName(),
+			UpdatedTime:     gtime.Now(),
+		})
+		if err != nil {
+			return err
+		}
+		err = addDynamicsByCurrentUser(tx, ent.Id, "续签代理商",
+			req, s.GetCxtUserId(), s.GetCxtUserName())
+		if err != nil {
+			return err
+		}
+
+		return nil
 	})
 	return txerr
 }
@@ -616,26 +655,45 @@ func (s *distributorService) ToDist(ctx context.Context, req *model.DistributorT
 		return myerrors.TipsError(fmt.Sprintf("代理商/经销商不存在: %d", req.Id))
 	}
 
-	approvalData := model.ToDistApproveData{
-		ToDistReason: req.ToDistReason,
-		OperatedId:   s.CxtUser.Id,
-		OperatedName: s.CxtUser.NickName,
-	}
-	approvalDataByte, err := json.Marshal(approvalData)
-	if err != nil {
-		return err
-	}
-
 	txerr := s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
 		_, err = tx.Update("base_distributor", map[string]interface{}{
-			"appro_status": "20",
-			"appro_data":   string(approvalDataByte),
+			"dist_type":    "10",
+			"appro_status": "30",
+			"appro_data":   "",
 			"appro_item":   "代理商转经销商",
 		}, "id = ?", req.Id)
 		if err != nil {
 			return err
 		}
-		return s.toDistDingtalkProcess(ctx, ent, req)
+		_, err = tx.Insert("base_distributor_record", model.BaseDistributorRecord{
+			DistId:          ent.Id,
+			DistType:        "10",
+			BusinessScope:   ent.BusinessScope,
+			CustomerType:    ent.CustomerType,
+			ProxyDistrict:   "",
+			ProxyStartTime:  nil,
+			ProxyEndTime:    nil,
+			ContractUrl:     "",
+			ExistedProduct:  ent.ExistedProduct,
+			HistoryCustomer: ent.HistoryCustomer,
+			ToDistReason:    req.ToDistReason,
+			Remark:          "",
+			CreatedBy:       s.GetCxtUserId(),
+			CreatedName:     s.GetCxtUserName(),
+			CreatedTime:     gtime.Now(),
+			UpdatedBy:       s.GetCxtUserId(),
+			UpdatedName:     s.GetCxtUserName(),
+			UpdatedTime:     gtime.Now(),
+		})
+		if err != nil {
+			return err
+		}
+		err = addDynamicsByCurrentUser(tx, ent.Id, "转为经销商",
+			req, s.GetCxtUserId(), s.GetCxtUserName())
+		if err != nil {
+			return err
+		}
+		return nil
 	})
 	return txerr
 }

+ 58 - 59
opms_parent/app/service/contract/ctr_contract.go

@@ -26,16 +26,12 @@ import (
 	"dashoo.cn/micro/app/service"
 	baseService "dashoo.cn/micro/app/service/base"
 	projsrv "dashoo.cn/micro/app/service/proj"
-	workflowService "dashoo.cn/micro/app/service/workflow"
-
 	"dashoo.cn/opms_libary/micro_srv"
 	"dashoo.cn/opms_libary/multipart"
 	"dashoo.cn/opms_libary/myerrors"
 	"dashoo.cn/opms_libary/plugin/dingtalk"
 	"dashoo.cn/opms_libary/plugin/dingtalk/message"
-	"dashoo.cn/opms_libary/plugin/dingtalk/workflow"
 	"dashoo.cn/opms_libary/request"
-	"dashoo.cn/opms_libary/utils"
 	"github.com/gogf/gf/database/gdb"
 	"github.com/gogf/gf/frame/g"
 	"github.com/gogf/gf/os/gcron"
@@ -867,64 +863,67 @@ func (s CtrContractService) Commit(ctx context.Context, req *model.CtrContractCo
 		return myerrors.TipsError(fmt.Sprintf("合同不存在: %d", req.Id))
 	}
 
-	fileinfoByte, err := json.Marshal(req.File)
-	if err != nil {
-		return err
-	}
+	err = s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
+		// 审批通过
+		_, err = s.Dao.TX(tx).Where("id = ?", ent.Id).Data(map[string]interface{}{
+			"appro_status": 30,
+		}).Update()
+		if err != nil {
+			return err
+		}
 
-	workflowSrv, err := workflowService.NewFlowService(ctx)
-	if err != nil {
-		return err
-	}
-	bizCode := strconv.Itoa(ent.Id)
-	_, err = workflowSrv.StartProcessInstance(bizCode, "30", "", &workflow.StartProcessInstanceRequest{
-		ProcessCode: &ContractApplyProcessCode,
-		FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
-			{
-				Id:    utils.String("DDSelectField_ESX8H30W3VK0"),
-				Name:  utils.String("合同模板"),
-				Value: utils.String(req.ContractModel),
-			},
-			{
-				Id:    utils.String("DDSelectField_13IQX96C2KAK0"),
-				Name:  utils.String("条款情况"),
-				Value: utils.String(req.Terms),
-			},
-			{
-				Id:    utils.String("TextField_1A5SA7VOG5TS0"),
-				Name:  utils.String("合同编号"),
-				Value: utils.String(ent.ContractCode),
-			},
-			{
-				Id:    utils.String("TextField_1EX61DPS3LA80"),
-				Name:  utils.String("客户名称"),
-				Value: utils.String(ent.CustName),
-			},
-			{
-				Id:    utils.String("MoneyField_X1XV4KIR0GW0"),
-				Name:  utils.String("合同金额(元)"),
-				Value: utils.String(strconv.FormatFloat(ent.ContractAmount, 'f', 2, 64)),
-			},
-			{
-				Id:    utils.String("TextareaField_1WZ5ILKBUVSW0"),
-				Name:  utils.String("付款条件"),
-				Value: utils.String(req.PayTerms),
-			},
-			{
-				Id:   utils.String("DDAttachment_1051KJYC3MBK0"),
-				Name: utils.String("附件"),
-				// Details: productForm,
-				Value: utils.String(string(fileinfoByte)),
-			},
-		},
+		// 交付状态(0发起 10项目立项 15进行中 20 完成 30审批拒绝40关闭)
+		_, err = worksrv.DeliverOrderAdd(tx, ent.Id, request.UserInfo{}, nil, "10")
+		if err != nil {
+			return err
+		}
+		if ent.ContractId != 0 {
+			oldContract, err := s.Dao.TX(tx).Where("id = ?", ent.ContractId).One()
+			if err != nil {
+				return err
+			}
+
+			softSub := ent.SoftwareMaintenanceEndTime.Sub(oldContract.SoftwareMaintenanceBeginTime).Hours() / 24 / 365
+			SoftwareMaintenanceLimit := int(softSub)
+			hardSub := ent.HardwareMaintenanceEndTime.Sub(oldContract.HardwareMaintenanceBeginTime).Hours() / 24 / 365
+			HardwareMaintenanceLimit := int(hardSub)
+			opnContent := map[string]interface{}{
+				"contractId":                      ent.ContractId,
+				"contractName":                    ent.ContractName,
+				"contractCode":                    ent.ContractCode,
+				"oldSoftwareMaintenanceBeginTime": oldContract.SoftwareMaintenanceBeginTime,
+				"oldSoftwareMaintenanceEndTime":   oldContract.SoftwareMaintenanceEndTime,
+				"oldHardwareMaintenanceBeginTime": oldContract.HardwareMaintenanceBeginTime,
+				"oldHardwareMaintenanceEndTime":   oldContract.HardwareMaintenanceEndTime,
+				"newSoftwareMaintenanceBeginTime": ent.SoftwareMaintenanceBeginTime,
+				"newSoftwareMaintenanceEndTime":   ent.SoftwareMaintenanceEndTime,
+				"newHardwareMaintenanceBeginTime": ent.HardwareMaintenanceBeginTime,
+				"newHardwareMaintenanceEndTime":   ent.HardwareMaintenanceEndTime,
+			}
+			dynamics := model.CtrContractDynamics{
+				ContractId: ent.ContractId,
+				OpnPeople:  "系统自动创建",
+				OpnDate:    gtime.Now(),
+				OpnType:    "续签合同审批通过",
+				OpnContent: gconv.String(opnContent),
+			}
+			_, err = s.Dao.DB.Model("ctr_contract_dynamics").TX(tx).Data(dynamics).InsertAndGetId()
+			if err != nil {
+				return err
+			}
+			_, err = s.Dao.TX(tx).Where("id = ?", ent.ContractId).Data(map[string]interface{}{
+				"software_maintenance_end_time": ent.SoftwareMaintenanceEndTime,
+				"hardware_maintenance_end_time": ent.HardwareMaintenanceEndTime,
+				"software_maintenance_limit":    SoftwareMaintenanceLimit,
+				"hardware_maintenance_limit":    HardwareMaintenanceLimit,
+			}).Update()
+			if err != nil {
+				return err
+			}
+		}
+		return nil
 	})
-	if err != nil {
-		return err
-	}
 
-	_, err = s.Dao.Where("id = ?", ent.Id).Data(map[string]interface{}{
-		"appro_status": 20,
-	}).Update()
 	return err
 }
 

+ 1 - 1
opms_parent/app/service/contract/ctr_contract_invoice.go

@@ -167,7 +167,7 @@ func (s CtrContractInvoiceService) Add(ctx context.Context, req *model.CtrContra
 		InvoiceAmount:     req.InvoiceAmount,
 		InvoiceDate:       req.InvoiceDate,
 		InvoiceType:       req.InvoiceType,
-		ApproStatus:       "10",
+		ApproStatus:       "30",
 		InvoiceCode:       req.InvoiceCode,
 		ActualInvoiceDate: req.ActualInvoiceDate,
 		CourierCode:       req.CourierCode,

+ 113 - 198
opms_parent/app/service/cust/cust_customer.go

@@ -11,12 +11,9 @@ import (
 	"strings"
 	"time"
 
-	"dashoo.cn/opms_libary/plugin/dingtalk/workflow"
-	"dashoo.cn/opms_libary/request"
-	"dashoo.cn/opms_libary/utils"
-
 	"dashoo.cn/opms_libary/myerrors"
 	"dashoo.cn/opms_libary/plugin/dingtalk/message"
+	"dashoo.cn/opms_libary/request"
 	"github.com/360EntSecGroup-Skylar/excelize"
 	"github.com/gogf/gf/database/gdb"
 	"github.com/gogf/gf/encoding/gjson"
@@ -30,7 +27,6 @@ import (
 	model "dashoo.cn/micro/app/model/cust"
 	workflowModel "dashoo.cn/micro/app/model/workflow"
 	"dashoo.cn/micro/app/service"
-	workflowService "dashoo.cn/micro/app/service/workflow"
 )
 
 type CustomerService struct {
@@ -394,71 +390,48 @@ func (s *CustomerService) AssignCustomerRequest(ctx context.Context, req *model.
 		}
 	}
 
-	remark, err := json.Marshal(map[string]string{
-		"applyUserId":   strconv.Itoa(s.GetCxtUserId()),
-		"applyUserName": s.GetCxtUserName(),
+	userId := s.GetCxtUserId()
+	userName := s.GetCxtUserName()
+	s.CxtUser = &request.UserInfo{Id: userId, UserName: userName}
+	err = s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
+		for _, u := range cust {
+			_, err = s.Dao.TX(tx).Where("id = ?", u.Id).Data(map[string]interface{}{
+				"is_public":   isPublic,
+				"cust_status": "10",
+			}).Update()
+			if err != nil {
+				return err
+			}
+
+			err = s.ChangeCustBelong([]int64{int64(u.Id)}, int64(userId), userName)
+			if err != nil {
+				return err
+			}
+
+			err = s.BatchCreatebelong([]*model.CustCustomer{u}, &model.AssignCustomerReq{
+				Ids:       []int64{int64(u.Id)},
+				SalesId:   int64(userId),
+				SalesName: userName,
+				Remark:    "",
+				Receive:   Receive,
+			})
+			if err != nil {
+				return err
+			}
+
+			err = s.CreateDynamics("领取客户", map[string]interface{}{
+				"userId": userId,
+				"custId": u.Id,
+			}, int64(u.Id))
+			if err != nil {
+				return err
+			}
+		}
+		return nil
 	})
 	if err != nil {
 		return err
 	}
-	workflowSrv, err := workflowService.NewFlowService(ctx)
-	if err != nil {
-		return err
-	}
-	for _, u := range cust {
-		bizCode := strconv.Itoa(u.Id) + ":" + strconv.Itoa(s.GetCxtUserId())
-		_, err = workflowSrv.StartProcessInstance(bizCode, "11", string(remark), &workflow.StartProcessInstanceRequest{
-			ProcessCode: &AssignCustomerRequestProcessCode,
-			FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
-				{
-					Id:    utils.String("TextField_1QEXO83G7GDC0"),
-					Name:  utils.String("客户编码"),
-					Value: utils.String(u.CustCode),
-				},
-				{
-					Id:    utils.String("TextField_13MDZ97RV16K0"),
-					Name:  utils.String("客户名称"),
-					Value: utils.String(u.CustName),
-				},
-				{
-					Id:    utils.String("TextField_Q32G87K9Y680"),
-					Name:  utils.String("所在省"),
-					Value: utils.String(u.CustProvince),
-				},
-				{
-					Id:    utils.String("TextField_1C81AAVZELY80"),
-					Name:  utils.String("所在市"),
-					Value: utils.String(u.CustCity),
-				},
-				{
-					Id:    utils.String("TextField_7EF74WG6AJ40"),
-					Name:  utils.String("客户类别"),
-					Value: utils.String(u.CustIndustry),
-				},
-				{
-					Id:    utils.String("TextField_1ZY48VZY6WG00"),
-					Name:  utils.String("申请人"),
-					Value: utils.String(s.GetCxtUserName()),
-				},
-				{
-					Id:    utils.String("TextareaField_5U6VKA6N1VK0"),
-					Name:  utils.String("申请说明"),
-					Value: utils.String(req.ApplyRemark),
-				},
-			},
-		})
-		if err != nil {
-			return err
-		}
-
-		_, err = s.Dao.Where("id = ?", u.Id).Data(map[string]interface{}{
-			"is_public":   noPublic,
-			"cust_status": "20",
-		}).Update()
-		if err != nil {
-			return err
-		}
-	}
 	return nil
 }
 
@@ -549,11 +522,6 @@ func (s *CustomerService) MoveToPublicRequest(ctx context.Context, req *model.Mo
 		return myerrors.TipsError("移回用户不能为空")
 	}
 
-	cusType, err := service.GetDictDataByType(ctx, "cust_idy")
-	if err != nil {
-		return err
-	}
-
 	for _, v := range data {
 		if v.CustStatus == "10" {
 			return myerrors.TipsError(fmt.Sprintf("客户: %s 已被移回公海", v.CustName))
@@ -572,71 +540,45 @@ func (s *CustomerService) MoveToPublicRequest(ctx context.Context, req *model.Mo
 		}
 	}
 
-	remark, err := json.Marshal(map[string]string{
-		"applyUserId":   strconv.Itoa(s.GetCxtUserId()),
-		"applyUserName": s.GetCxtUserName(),
-	})
-	if err != nil {
-		return err
-	}
+	userId := s.GetCxtUserId()
+	userName := s.GetCxtUserName()
+	s.CxtUser = &request.UserInfo{Id: userId, UserName: userName}
+	err = s.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
+		for _, u := range data {
+			//更新客户信息
+			_, err = s.Dao.Where("id = ?", u.Id).Data(map[string]interface{}{
+				"cust_status":  "10",
+				"is_public":    isPublic,
+				"sales_id":     0,
+				"dept_id":      0,
+				"dept_name":    "",
+				"updated_time": gtime.Now(),
+			}).Update()
+			if err != nil {
+				return err
+			}
+			//更新销售归属表结束时间
+			_, err = s.BelongDao.TX(tx).Data(g.Map{
+				"end_date": gtime.Now(),
+			}).Where("cust_id = ?", u.Id).Update()
+			if err != nil {
+				return err
+			}
 
-	workflowSrv, err := workflowService.NewFlowService(ctx)
+			err = s.CreateDynamics("移入公海", map[string]interface{}{
+				"userId": userId,
+				"custId": u.Id,
+			}, int64(u.Id))
+			if err != nil {
+				return err
+			}
+		}
+		return nil
+	})
 	if err != nil {
 		return err
 	}
-	for _, u := range data {
-		bizCode := strconv.Itoa(u.Id) + ":" + strconv.Itoa(s.GetCxtUserId())
-		_, err = workflowSrv.StartProcessInstance(bizCode, "12", string(remark), &workflow.StartProcessInstanceRequest{
-			ProcessCode: &MoveToPubicRequestProcessCode,
-			FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
-				{
-					Id:    utils.String("TextField_JFWRAP0D1IO0"),
-					Name:  utils.String("客户编码"),
-					Value: utils.String(u.CustCode),
-				},
-				{
-					Id:    utils.String("TextField-K2AD4O5B"),
-					Name:  utils.String("客户名称"),
-					Value: utils.String(u.CustName),
-				},
-				{
-					Id:    utils.String("TextField_1THUAFLY5RGG0"),
-					Name:  utils.String("所在省"),
-					Value: utils.String(u.CustProvince),
-				},
-				{
-					Id:    utils.String("TextField_15SRKAQIYY680"),
-					Name:  utils.String("所在市"),
-					Value: utils.String(u.CustCity),
-				},
-				{
-					Id:    utils.String("TextField_S966SSJHCCG0"),
-					Name:  utils.String("客户类别"),
-					Value: utils.String(cusType[u.CustIndustry]),
-				},
-				{
-					Id:    utils.String("TextField_Y3EQ11P49LC0"),
-					Name:  utils.String("申请人"),
-					Value: utils.String(s.GetCxtUserName()),
-				},
-				{
-					Id:    utils.String("TextareaField_1790F8J2SPJ40"),
-					Name:  utils.String("移回原因"),
-					Value: utils.String(req.Remark),
-				},
-			},
-		})
-		if err != nil {
-			return err
-		}
 
-		_, err = s.Dao.Where("id = ?", u.Id).Data(map[string]interface{}{
-			"cust_status": "20",
-		}).Update()
-		if err != nil {
-			return err
-		}
-	}
 	return nil
 }
 
@@ -799,76 +741,49 @@ func (s *CustomerService) TransCustomerRequest(ctx context.Context, req *model.A
 		}
 	}
 
-	remark, err := json.Marshal(map[string]string{
-		"applyUserId":   strconv.Itoa(s.GetCxtUserId()),
-		"applyUserName": s.GetCxtUserName(),
-		"toUserId":      strconv.FormatInt(req.SalesId, 10),
-		"toUserName":    req.SalesName,
-	})
-	if err != nil {
-		return err
-	}
+	userId := s.GetCxtUserId()
+	userName := s.GetCxtUserName()
+	toUserId := req.SalesId
+	toUserName := req.SalesName
 
-	workflowSrv, err := workflowService.NewFlowService(ctx)
-	if err != nil {
-		return err
-	}
-	for _, u := range data {
-		bizCode := strings.Join([]string{
-			strconv.Itoa(u.Id),
-			strconv.Itoa(s.GetCxtUserId()),
-			strconv.FormatInt(req.SalesId, 10),
-		}, ":")
-		_, err = workflowSrv.StartProcessInstance(bizCode, "13", string(remark), &workflow.StartProcessInstanceRequest{
-			ProcessCode: &TransCustomerRequestProcessCode,
-			FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
-				{
-					Id:    utils.String("TextField-K2AD4O5B"),
-					Name:  utils.String("客户编码"),
-					Value: utils.String(u.CustCode),
-				},
-				{
-					Id:    utils.String("TextField_HMF1CTLP55S0"),
-					Name:  utils.String("客户名称"),
-					Value: utils.String(u.CustName),
-				},
-				{
-					Id:    utils.String("TextField_SAITVT7MNF40"),
-					Name:  utils.String("所在省"),
-					Value: utils.String(u.CustProvince),
-				},
-				{
-					Id:    utils.String("TextField_12DGEUTR74NK0"),
-					Name:  utils.String("所在市"),
-					Value: utils.String(u.CustCity),
-				},
-				{
-					Id:    utils.String("TextField_16FDRGG3URCW0"),
-					Name:  utils.String("客户类别"),
-					Value: utils.String(u.CustIndustry),
-				},
-				{
-					Id:    utils.String("TextField_1JSO6EU9XQCG0"),
-					Name:  utils.String("申请人"),
-					Value: utils.String(s.GetCxtUserName()),
-				},
-				{
-					Id:    utils.String("TextareaField_1ZSSTZFCT0G00"),
-					Name:  utils.String("转移原因"),
-					Value: utils.String(req.Remark),
-				},
-			},
-		})
-		if err != nil {
-			return err
-		}
+	s.CxtUser = &request.UserInfo{Id: userId, UserName: userName}
+	err = s.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
+		for _, u := range data {
+			_, err = s.Dao.Where("id = ?", u.Id).Data(map[string]interface{}{
+				"cust_status": "20",
+			}).Update()
+			if err != nil {
+				return err
+			}
 
-		_, err = s.Dao.Where("id = ?", u.Id).Data(map[string]interface{}{
-			"cust_status": "20",
-		}).Update()
-		if err != nil {
-			return err
+			err = s.ChangeCustBelong([]int64{int64(u.Id)}, toUserId, toUserName)
+			if err != nil {
+				return err
+			}
+			err = s.BatchCreatebelong([]*model.CustCustomer{u}, &model.AssignCustomerReq{
+				Ids:       []int64{int64(u.Id)},
+				SalesId:   toUserId,
+				SalesName: toUserName,
+				Remark:    "",
+				Receive:   OperaTion,
+			})
+			if err != nil {
+				return err
+			}
+
+			err = s.CreateDynamics("转移客户", map[string]interface{}{
+				"userId":   userId,
+				"custId":   u.Id,
+				"toUserId": toUserId,
+			}, int64(u.Id))
+			if err != nil {
+				return err
+			}
 		}
+		return nil
+	})
+	if err != nil {
+		return err
 	}
 	return nil
 }

+ 3 - 106
opms_parent/app/service/cust/cust_customer_bid_record.go

@@ -6,21 +6,16 @@ import (
 	model "dashoo.cn/micro/app/model/cust"
 	workflowModel "dashoo.cn/micro/app/model/workflow"
 	"dashoo.cn/micro/app/service"
-	workflowService "dashoo.cn/micro/app/service/workflow"
 	"dashoo.cn/opms_libary/micro_srv"
 	"dashoo.cn/opms_libary/myerrors"
 	"dashoo.cn/opms_libary/plugin/dingtalk/message"
-	"dashoo.cn/opms_libary/plugin/dingtalk/workflow"
 	"dashoo.cn/opms_libary/request"
-	"dashoo.cn/opms_libary/utils"
 	"database/sql"
 	"fmt"
 	"github.com/gogf/gf/database/gdb"
 	"github.com/gogf/gf/frame/g"
 	"github.com/gogf/gf/os/gtime"
-	"github.com/gogf/gf/util/gconv"
 	"github.com/gogf/gf/util/gvalid"
-	"strconv"
 )
 
 var BidCloseLoopCode = "PROC-35FEF564-21F8-41CA-A38F-DC1E61C21C71" // 客户招标信息闭环审批
@@ -281,24 +276,10 @@ func (s CustCustomerBidRecordService) CloseLoop(ctx context.Context, req *model.
 	if bid.Status != "10" && bid.Status != "40" {
 		return myerrors.TipsError("该招标信息不可闭环操作")
 	}
-	// 客户信息
-	cus, err := s.CustomerDao.Where(fmt.Sprintf("id='%v'", bid.CustId)).One()
-	if err != nil {
-		return err
-	}
-	// 产品线名称
-	lineName := ""
-	line, err := s.Dao.DB.Model("sys_dict_data").Where(fmt.Sprintf("dict_value='%v' AND dict_type='sys_product_line'", bid.ProductLine)).One()
-	if err != nil && err != sql.ErrNoRows {
-		return err
-	}
-	if line != nil {
-		lineName = line["dict_label"].String()
-	}
 
 	err = s.Dao.Transaction(context.TODO(), func(ctx1 context.Context, tx *gdb.TX) error {
 		data := g.Map{
-			"status":                          "20",
+			"status":                          "30",
 			"close_loop_msg":                  req.CloseReason,
 			"channel_promotion_work":          req.ChannelPromotionWork,
 			"customer_promotion_work":         req.CustomerPromotionWork,
@@ -307,97 +288,13 @@ func (s CustCustomerBidRecordService) CloseLoop(ctx context.Context, req *model.
 			"updated_name":                    s.userInfo.NickName,
 			"updated_time":                    gtime.Now(),
 		}
-		// 改为待审批状态
+		// 改为待审批状态 -> 取消审批流,直接改为审批通过
 		_, err := s.Dao.Update(data, fmt.Sprintf("id='%v'", req.Id))
 		if err != nil {
 			return err
 		}
-		// 调用钉钉审批
-		// 审批流
-		name := ""
-		if req.CloseMethod == "已创建项目" {
-			name = req.BusinessName
-		} else if req.CloseMethod == "已创建经销商" {
-			name = req.DistributorName
-		}
-		workflowSrv, _ := workflowService.NewFlowService(ctx)
-		bizCode := strconv.Itoa(req.Id)
-		_, err = workflowSrv.StartProcessInstance(bizCode, workflowModel.BidCloseLoop, "", &workflow.StartProcessInstanceRequest{
-			ProcessCode: &BidCloseLoopCode,
-			FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
-				{
-					Id:    utils.String("TextField_1A6IA11WE4U80"),
-					Name:  utils.String("客户名称"),
-					Value: utils.String(cus.CustName),
-				},
-				{
-					Id:    utils.String("TextField_1UUQ8HFDI8TC0"),
-					Name:  utils.String("招标产品名称"),
-					Value: utils.String(bid.ProductName),
-				},
-				{
-					Id:    utils.String("NumberField_7A5EBEI9CUO0"),
-					Name:  utils.String("预算"),
-					Value: utils.String(gconv.String(bid.Budget)),
-				},
-				{
-					Id:    utils.String("DDDateField_STS0LXQAQEO0"),
-					Name:  utils.String("发布日期"),
-					Value: utils.String(gconv.String(bid.PublishedTime)),
-				},
-				{
-					Id:    utils.String("TextField_GYKX9NAXNTS0"),
-					Name:  utils.String("招标信息标题"),
-					Value: utils.String(bid.Title),
-				},
-				{
-					Id:    utils.String("TextField-K2AD4O5B"),
-					Name:  utils.String("所属销售"),
-					Value: utils.String(cus.SalesName),
-				},
-				{
-					Id:    utils.String("DDSelectField_1RVSHN0116740"),
-					Name:  utils.String("产品线"),
-					Value: utils.String(lineName),
-				},
-				{
-					Id:    utils.String("DDSelectField_21X20CB9B20W0"),
-					Name:  utils.String("闭环方式"),
-					Value: utils.String(req.CloseMethod),
-				},
-				{
-					Id:    utils.String("TextField_1GD012PXFMGW0"),
-					Name:  utils.String("名称"),
-					Value: utils.String(name),
-				},
-				{
-					Id:    utils.String("TextField_KARTQZ45DI80"),
-					Name:  utils.String("渠道推进工作"),
-					Value: utils.String(req.ChannelPromotionWork),
-				},
-				{
-					Id:    utils.String("TextField_EJ2GWZ8CD000"),
-					Name:  utils.String("客户推进工作"),
-					Value: utils.String(req.CustomerPromotionWork),
-				},
-				{
-					Id:    utils.String("TextField_LSRPAR2S1TS0"),
-					Name:  utils.String("客户后续销售机会"),
-					Value: utils.String(req.CustomerSubsequentOpportunity),
-				},
-				{
-					Id:    utils.String("TextareaField_FXZRRAQB7CW0"),
-					Name:  utils.String("申请原因"),
-					Value: utils.String(req.CloseReason),
-				},
-			},
-		})
-		if err != nil {
-			g.Log().Error(err)
-			return err
-		}
 
-		return err
+		return nil
 	})
 	return err
 }

+ 10 - 4
opms_parent/app/service/plat/plat_task.go

@@ -321,12 +321,18 @@ func (s *taskService) Create(req *model.AddPlatTaskReq) (err error) {
 	// 创建操作任务
 	id, _ := res.LastInsertId()
 	platTask.Id = int(id)
-	err = s.startDingApproval(platTask)
+
+	// 流程日志
+	err = CreateTaskLog(s, nil, int(id), s.GetCxtUserId(), s.GetCxtUserName(), "创建督办", "创建督办成功", "")
+
+	nextHandle := createNextTaskHandel(s, platTask, 10)
+	_, err = s.Dao.DB.Insert("plat_task_handle", nextHandle)
 	if err != nil {
-		return
+		return err
 	}
+
 	// 流程日志
-	err = CreateTaskLog(s, nil, int(id), s.GetCxtUserId(), s.GetCxtUserName(), "创建督办", "创建督办成功", "")
+	err = CreateTaskLog(s, nil, platTask.Id, s.GetCxtUserId(), s.GetCxtUserName(), "督办审批", "通过", "")
 
 	return
 }
@@ -433,7 +439,7 @@ func (s *taskService) ChangeStatus(req *model.ChangeStatusReq) (err error) {
 }
 
 // Handle 督办任务处理
-//步骤号(10接收  15暂存  20提交  30审批(督办人)  40评价(监办人))
+// 步骤号(10接收  15暂存  20提交  30审批(督办人)  40评价(监办人))
 func (s *taskService) Handle(req *model.HandleReq) (err error) {
 	// 步骤号(10接收  15暂存  20提交  30审批(督办人)  40评价(监办人))
 	// 处理结果(10接收20提交30审批通过40审批退回)

+ 77 - 291
opms_parent/app/service/proj/business.go

@@ -297,7 +297,7 @@ func (p *businessService) Create(req *model.AddProjBusinessReq) (err error) {
 	if business.NboType == "" {
 		business.NboType = StatusC
 	}
-	business.ApproStatus = ApprovalWaiting
+	business.ApproStatus = ApprovalOK
 	business.CustProvinceId = customer.CustProvinceId
 	business.CustProvince = customer.CustProvince
 	business.CustCityId = customer.CustCityId
@@ -308,10 +308,6 @@ func (p *businessService) Create(req *model.AddProjBusinessReq) (err error) {
 	service.SetCreatedInfo(business, p.GetCxtUserId(), p.GetCxtUserName())
 	business.FilingTime = business.CreatedTime
 
-	productLine, _ := service.GetDictLabelByTypeAndValue(p.Ctx, "sys_product_line", business.ProductLine)
-	nboSource, _ := service.GetDictLabelByTypeAndValue(p.Ctx, "proj_nbo_source", business.NboSource)
-	salesModel, _ := service.GetDictLabelByTypeAndValue(p.Ctx, "proj_sales_model", business.SalesModel)
-
 	// 事务
 	err = p.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
 		// 添加项目
@@ -326,80 +322,7 @@ func (p *businessService) Create(req *model.AddProjBusinessReq) (err error) {
 			Remark:  business.Remark,
 		}
 		_, err = p.CreateProjBusinessDynamics(tx, dynamics, business)
-		// 审批流
-		workflowSrv, _ := workflowService.NewFlowService(p.Ctx)
-		// OMS项目创建 审批
-		bizCode := business.NboCode + ":" + gconv.String(lastId)
-		business.ApproType = BusinessCreateRequestProcessCode
-		instanceId, err := workflowSrv.StartProcessInstance(bizCode, workflowModel.ProjectCreate, "", &workflow.StartProcessInstanceRequest{
-			ProcessCode: &business.ApproType,
-			FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
-				{
-					Id:    utils.String("TextField-K2AD4O5B"),
-					Name:  utils.String("项目编码"),
-					Value: utils.String(business.NboCode),
-				},
-				{
-					Id:    utils.String("TextField_BDLSECETVSG0"),
-					Name:  utils.String("项目名称"),
-					Value: utils.String(business.NboName),
-				},
-				{
-					Id:    utils.String("DDSelectField_213JKZA1OUO00"),
-					Name:  utils.String("产品线"),
-					Value: utils.String(productLine),
-				},
-				{
-					Id:    utils.String("TextField_1J9BJMOZ18F40"),
-					Name:  utils.String("客户名称"),
-					Value: utils.String(business.CustName),
-				},
-				{
-					Id:    utils.String("DDSelectField_6CQD451D3800"),
-					Name:  utils.String("项目来源"),
-					Value: utils.String(nboSource),
-				},
-				{
-					Id:    utils.String("TextField_1UQFU5BUEWDC"),
-					Name:  utils.String("历史招标信息"),
-					Value: utils.String(req.BidInfo),
-				},
-				{
-					Id:    utils.String("TextField_AEUWH63LJ0O0"),
-					Name:  utils.String("销售工程师"),
-					Value: utils.String(business.SaleName),
-				},
-				{
-					Id:    utils.String("DDSelectField_34QSUGHO2SO0"),
-					Name:  utils.String("销售模式"),
-					Value: utils.String(salesModel),
-				},
-				{
-					Id:    utils.String("TextField_1PWK6WHMGITC0"),
-					Name:  utils.String("经销商/代理商"),
-					Value: utils.String(business.DistributorName),
-				},
-				{
-					Id:    utils.String("DDSelectField_5R11VVM6GI00"),
-					Name:  utils.String("是否为战略项目"),
-					Value: utils.String(yesOrNoType[business.IsBig]),
-				},
-				{
-					Id:    utils.String("TextareaField_1GEL8JJL3H5S0"),
-					Name:  utils.String("备注"),
-					Value: utils.String(business.Remark),
-				},
-			},
-		})
-		if err != nil {
-			g.Log().Error(err)
-			return err
-		}
-		// 更新项目审批信息
-		_, err = p.Dao.TX(tx).Data(g.Map{p.Dao.C.ApproType: business.ApproType, p.Dao.C.ApproInstanceId: instanceId}).Where(p.Dao.C.Id, lastId).Update()
-		if err != nil {
-			return err
-		}
+
 		return nil
 	})
 
@@ -624,8 +547,12 @@ func (p *businessService) BusinessTransfer(req *model.BusinessTransferReq) error
 	if business == nil {
 		return myerrors.TipsError("项目已提交审批任务,无法重复提交。")
 	}
+	// 修改项目信息
 	businessMap := g.Map{
-		p.Dao.C.ApproStatus: ApprovalWaiting,
+		p.Dao.C.ApproStatus: ApprovalOK,
+		p.Dao.C.SaleId:      req.UserId,
+		p.Dao.C.SaleName:    req.UserName,
+		p.Dao.C.Remark:      req.Remark,
 	}
 	service.SetUpdatedInfo(businessMap, p.GetCxtUserId(), p.GetCxtUserName())
 
@@ -636,10 +563,7 @@ func (p *businessService) BusinessTransfer(req *model.BusinessTransferReq) error
 	opnContent["saleName"] = req.UserName
 	opnContent["remark"] = req.Remark
 
-	productLine, _ := service.GetDictLabelByTypeAndValue(p.Ctx, "sys_product_line", business.ProductLine)
-
 	// 审批流
-	workflowSrv, _ := workflowService.NewFlowService(p.Ctx)
 	err = p.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
 		// 更新项目
 		_, err = p.Dao.TX(tx).WherePri(projDao.ProjBusiness.C.Id, req.Id).Data(businessMap).Update()
@@ -658,73 +582,6 @@ func (p *businessService) BusinessTransfer(req *model.BusinessTransferReq) error
 			return err
 		}
 
-		// OMS项目转移 审批
-		bizCode := business.NboCode + ":" + strconv.Itoa(business.Id)
-		business.ApproType = BusinessTransferRequestProcessCode
-		instanceId, err := workflowSrv.StartProcessInstance(bizCode, workflowModel.ProjectTransfer, "", &workflow.StartProcessInstanceRequest{
-			ProcessCode: &business.ApproType,
-			FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
-				{
-					Id:    utils.String("TextField-K2AD4O5B"),
-					Name:  utils.String("项目编码"),
-					Value: utils.String(business.NboCode),
-				},
-				{
-					Id:    utils.String("TextField_7EFHRQ9DDF80"),
-					Name:  utils.String("项目名称"),
-					Value: utils.String(business.NboName),
-				},
-				{
-					Id:    utils.String("TextField_1T3DEY5FWV7K0"),
-					Name:  utils.String("客户名称"),
-					Value: utils.String(business.CustName),
-				},
-				{
-					Id:    utils.String("TextField_QDU06LXYKK00"),
-					Name:  utils.String("所在省"),
-					Value: utils.String(business.CustProvince),
-				},
-				{
-					Id:    utils.String("TextField_MVSOO6EG6YO0"),
-					Name:  utils.String("所在市"),
-					Value: utils.String(business.CustCity),
-				},
-				{
-					Id:    utils.String("DDSelectField_6OMVO1JV0980"),
-					Name:  utils.String("产品线"),
-					Value: utils.String(productLine),
-				},
-				{
-					Id:    utils.String("TextField_1E1WOYGKRTDS0"),
-					Name:  utils.String("项目级别"),
-					Value: utils.String(nboType[business.NboType]),
-				},
-				{
-					Id:    utils.String("TextField_NRQXWLJ17HC0"),
-					Name:  utils.String("申请人"),
-					Value: utils.String(p.GetCxtUserName()),
-				},
-				{
-					Id:    utils.String("TextField_GHSQYDGD13K0"),
-					Name:  utils.String("转移原因"),
-					Value: utils.String(req.Remark),
-				},
-				{
-					Id:    utils.String("TextField_76P8FPHH0UC0"),
-					Name:  utils.String("接收人"),
-					Value: utils.String(req.UserName),
-				},
-			},
-		})
-		if err != nil {
-			g.Log().Error(err)
-			return err
-		}
-		// 更新项目审批信息
-		_, err = p.Dao.TX(tx).Data(g.Map{p.Dao.C.ApproType: business.ApproType, p.Dao.C.ApproInstanceId: instanceId}).Where(p.Dao.C.Id, req.Id).Update()
-		if err != nil {
-			return err
-		}
 		return nil
 	})
 	return err
@@ -849,12 +706,14 @@ func (p *businessService) BusinessUpgrade(req *model.BusinessUpgradeReq, fileMap
 	if err != nil {
 		return err
 	}
-	businessMap := g.Map{p.Dao.C.ApproStatus: ApprovalWaiting}
+	var businessMap = g.Map{}
+	//businessMap = gconv.Map(req)
+	businessMap[p.Dao.C.ApproStatus] = ApprovalOK
 	service.SetUpdatedInfo(businessMap, p.GetCxtUserId(), p.GetCxtUserName())
 
 	opnContent := gconv.Map(req)
 	opnContent["origNboType"] = business.NboType
-	opnContent["approStatus"] = ApprovalWaiting
+	opnContent["approStatus"] = ApprovalOK
 	service.SetUpdatedInfo(opnContent, p.GetCxtUserId(), p.GetCxtUserName())
 
 	if fileMap == nil {
@@ -891,6 +750,42 @@ func (p *businessService) BusinessUpgrade(req *model.BusinessUpgradeReq, fileMap
 		})
 	}
 
+	upgradeType := p.getBusDingUpgradeType(business.NboType, req.NboType)
+	if upgradeType == "" {
+		return myerrors.TipsError("错误的升级类型")
+	}
+	productLineMap, err := service.GetDictDataTreeByType(p.Ctx, "sys_product_line")
+	if err != nil {
+		return err
+	}
+	productLine := gconv.String(productLineMap.Get(business.ProductLine))
+
+	businessMap[p.Dao.C.NboType] = req.NboType
+	businessMap[p.Dao.C.ProductLine] = productLine
+	if req.NboType == StatusC {
+		businessMap[p.Dao.C.ProjConversionReason] = req.ProjConversionReason
+	} else if req.NboType == StatusB { // B级项目
+		businessMap[p.Dao.C.NboBudget] = req.NboBudget
+		businessMap[p.Dao.C.DealerSalesId] = req.DealerSalesId
+		businessMap[p.Dao.C.DealerSalesName] = req.DealerSalesName
+		businessMap[p.Dao.C.DealerSalesContact] = req.DealerSalesContact
+		businessMap[p.Dao.C.EstTransPrice] = req.EstTransPrice
+	} else if req.NboType == StatusA { // A级项目
+		businessMap[p.Dao.C.PurchasingWay] = req.PurchasingWay
+		businessMap[p.Dao.C.CapitalSource] = req.CapitalSource
+		businessMap[p.Dao.C.PlanPurchaseTime] = req.PlanPurchaseTime
+		businessMap[p.Dao.C.ContactId] = req.ContactId
+		businessMap[p.Dao.C.ContactName] = req.ContactName
+		businessMap[p.Dao.C.ContactTelephone] = req.ContactTelephone
+		businessMap[p.Dao.C.MakerId] = req.MakerId
+		businessMap[p.Dao.C.MakerName] = req.MakerName
+		businessMap[p.Dao.C.MakerDept] = req.MakerDept
+		businessMap[p.Dao.C.IsAdoptDashoo] = req.IsAdoptDashoo
+		businessMap[p.Dao.C.Competitor] = req.Competitor
+		businessMap[p.Dao.C.CustomerIntentionFactory] = req.CustomerIntentionFactory
+	}
+	//businessMap[p.Dao.C.Remark] = gconv.String(g.Map{"nboType": opnContent["nboType"], "origNboType": opnContent["origNboType"]})
+
 	err = p.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
 		// 更新项目调级
 		_, err = p.Dao.TX(tx).WherePri(req.Id).Data(businessMap).Update()
@@ -902,6 +797,27 @@ func (p *businessService) BusinessUpgrade(req *model.BusinessUpgradeReq, fileMap
 		if err != nil {
 			return err
 		}
+
+		// 添加产品
+		if req != nil && (req.NboType == "20" || req.NboType == "10") {
+			// 设置产品信息
+			totalPrice, products, err := p.setProductInfo(req.Id, req.Products)
+			if err != nil {
+				return err
+			}
+			// 删除项目产品
+			_, err = projDao.NewProjBusinessProductDao(p.Tenant).TX(tx).Where(projDao.ProjBusinessProduct.C.BusId, req.Id).Delete()
+			if err != nil {
+				return err
+			}
+			// 添加项目产品
+			_, err = projDao.NewProjBusinessProductDao(p.Tenant).TX(tx).Insert(products)
+			if err != nil {
+				return err
+			}
+			businessMap[p.Dao.C.EstTransPrice] = totalPrice
+		}
+
 		// 添加项目动态
 		dynamics := model.ProjBusinessDynamics{
 			BusId:   business.Id,
@@ -912,15 +828,7 @@ func (p *businessService) BusinessUpgrade(req *model.BusinessUpgradeReq, fileMap
 		if err != nil {
 			return err
 		}
-		instanceId, err := p.BusUpgradeDingEvent(business, req, fileMap)
-		if err != nil {
-			return err
-		}
-		// 更新项目审批信息
-		_, err = p.Dao.TX(tx).Data(g.Map{p.Dao.C.ApproType: business.ApproType, p.Dao.C.ApproInstanceId: instanceId}).Where(p.Dao.C.Id, req.Id).Update()
-		if err != nil {
-			return err
-		}
+
 		return nil
 	})
 	if err != nil {
@@ -1429,20 +1337,18 @@ func (p *businessService) BusinessDowngrade(req *model.BusinessDowngradeReq) err
 	if downgradeType == "" {
 		return myerrors.TipsError("错误的降级类型")
 	}
-	businessMap := g.Map{
-		p.Dao.C.ApproStatus: ApprovalWaiting,
-	}
+	var businessMap = g.Map{}
+	businessMap = gconv.Map(req)
+	businessMap[p.Dao.C.ApproStatus] = ApprovalOK
+
 	service.SetUpdatedInfo(businessMap, p.GetCxtUserId(), p.GetCxtUserName())
 
 	opnContent := gconv.Map(req)
 	opnContent["origNboType"] = business.NboType
-	opnContent["approStatus"] = ApprovalWaiting
+	opnContent["approStatus"] = ApprovalOK
 	service.SetUpdatedInfo(opnContent, p.GetCxtUserId(), p.GetCxtUserName())
 
-	productLine, _ := service.GetDictLabelByTypeAndValue(p.Ctx, "sys_product_line", business.ProductLine)
-
 	// 审批流
-	workflowSrv, _ := workflowService.NewFlowService(p.Ctx)
 	err = p.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
 		// 更新项目调级
 		_, err = p.Dao.TX(tx).WherePri(req.Id).Data(businessMap).Update()
@@ -1459,73 +1365,7 @@ func (p *businessService) BusinessDowngrade(req *model.BusinessDowngradeReq) err
 		if err != nil {
 			return err
 		}
-		// OMS项目降级 审批
-		bizCode := business.NboCode + ":" + strconv.Itoa(business.Id)
-		business.ApproType = BusinessDowngradeRequestProcessCode
-		instanceId, err := workflowSrv.StartProcessInstance(bizCode, workflowModel.ProjectDownGrade, "", &workflow.StartProcessInstanceRequest{
-			ProcessCode: &business.ApproType,
-			FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
-				{
-					Id:    utils.String("TextField-K2AD4O5B"),
-					Name:  utils.String("项目编码"),
-					Value: utils.String(business.NboCode),
-				},
-				{
-					Id:    utils.String("TextField_BDLSECETVSG0"),
-					Name:  utils.String("项目名称"),
-					Value: utils.String(business.NboName),
-				},
-				{
-					Id:    utils.String("TextField_1J9BJMOZ18F40"),
-					Name:  utils.String("客户名称"),
-					Value: utils.String(business.CustName),
-				},
-				{
-					Id:    utils.String("TextField_GL7MQUB723K0"),
-					Name:  utils.String("所在省"),
-					Value: utils.String(business.CustProvince),
-				},
-				{
-					Id:    utils.String("TextField_CFA88QQQUUO0"),
-					Name:  utils.String("所在市"),
-					Value: utils.String(business.CustCity),
-				},
-				{
-					Id:    utils.String("DDSelectField_VSA3U380ZK00"),
-					Name:  utils.String("降级类型"),
-					Value: utils.String(downgradeType),
-				},
-				{
-					Id:    utils.String("DDSelectField_1UCNHJ0P8C5C0"),
-					Name:  utils.String("产品线"),
-					Value: utils.String(productLine),
-				},
-				{
-					Id:    utils.String("TextField_X4D3QGARU7K0"),
-					Name:  utils.String("支持内容"),
-					Value: utils.String("无"),
-				},
-				{
-					Id:    utils.String("TextField_AEUWH63LJ0O0"),
-					Name:  utils.String("销售工程师"),
-					Value: utils.String(business.SaleName),
-				},
-				{
-					Id:    utils.String("TextareaField_PTGJOKD3J7K0"),
-					Name:  utils.String("降级原因"),
-					Value: utils.String(req.Remark),
-				},
-			},
-		})
-		if err != nil {
-			g.Log().Error(err)
-			return err
-		}
-		// 更新项目审批信息
-		_, err = p.Dao.TX(tx).Data(g.Map{p.Dao.C.ApproType: business.ApproType, p.Dao.C.ApproInstanceId: instanceId}).Where(p.Dao.C.Id, req.Id).Update()
-		if err != nil {
-			return err
-		}
+
 		return nil
 	})
 	return err
@@ -1684,14 +1524,12 @@ func (p *businessService) ConvertToReserve(req *model.BusinessToReserveReq) erro
 		return myerrors.TipsError("项目已提交审批任务,无法重复提交。")
 	}
 
-	productLine, _ := service.GetDictLabelByTypeAndValue(p.Ctx, "sys_product_line", business.ProductLine)
-
 	// 审批流
-	workflowSrv, _ := workflowService.NewFlowService(p.Ctx)
 	err = p.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
 		// 更新项目
 		businessMap := g.Map{
-			p.Dao.C.ApproStatus:          ApprovalWaiting,
+			p.Dao.C.ApproStatus:          ApprovalOK,
+			p.Dao.C.NboType:              StatusReserve,
 			p.Dao.C.ProjConversionTime:   gtime.Now(),
 			p.Dao.C.ProjConversionReason: req.ProjConversionReason,
 		}
@@ -1712,58 +1550,6 @@ func (p *businessService) ConvertToReserve(req *model.BusinessToReserveReq) erro
 			return err
 		}
 
-		// OMS项目转储备 审批
-		bizCode := business.NboCode + ":" + strconv.Itoa(business.Id)
-		business.ApproType = ConvertToReserveRequestProcessCode
-		instanceId, err := workflowSrv.StartProcessInstance(bizCode, workflowModel.ProjectToReserve, "", &workflow.StartProcessInstanceRequest{
-			ProcessCode: &business.ApproType,
-			FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
-				{
-					Id:    utils.String("TextField-K2AD4O5B"),
-					Name:  utils.String("项目编码"),
-					Value: utils.String(business.NboCode),
-				},
-				{
-					Id:    utils.String("TextField_CMH6TBXYR5S0"),
-					Name:  utils.String("项目名称"),
-					Value: utils.String(business.NboName),
-				},
-				{
-					Id:    utils.String("TextField_YQBGGYHQPS00"),
-					Name:  utils.String("客户名称"),
-					Value: utils.String(business.CustName),
-				},
-				{
-					Id:    utils.String("DDSelectField_VBY9YAIOK5C0"),
-					Name:  utils.String("项目级别"),
-					Value: utils.String(convertToReserveType[business.NboType]),
-				},
-				{
-					Id:    utils.String("DDSelectField_1UVBB1LZHIJK0"),
-					Name:  utils.String("产品线"),
-					Value: utils.String(productLine),
-				},
-				{
-					Id:    utils.String("TextField_1NDD3TY8KJB40"),
-					Name:  utils.String("销售工程师"),
-					Value: utils.String(business.SaleName),
-				},
-				{
-					Id:    utils.String("TextareaField_15KZFM4YHQ8W0"),
-					Name:  utils.String("转化原因"),
-					Value: utils.String(req.ProjConversionReason),
-				},
-			},
-		})
-		if err != nil {
-			g.Log().Error(err)
-			return err
-		}
-		// 更新项目审批信息
-		_, err = p.Dao.TX(tx).Data(g.Map{p.Dao.C.ApproType: business.ApproType, p.Dao.C.ApproInstanceId: instanceId}).Where(p.Dao.C.Id, req.Id).Update()
-		if err != nil {
-			return err
-		}
 		return nil
 	})
 

+ 15 - 13
opms_parent/app/service/work/deliver_order.go

@@ -4,8 +4,6 @@ import (
 	"context"
 	model "dashoo.cn/micro/app/model/base"
 	workflowModel "dashoo.cn/micro/app/model/workflow"
-	workflowService "dashoo.cn/micro/app/service/workflow"
-	"dashoo.cn/opms_libary/plugin/dingtalk/workflow"
 	"database/sql"
 	"fmt"
 	"github.com/gogf/gf/os/glog"
@@ -344,24 +342,28 @@ func (s DeliverOrderService) Add(ctx context.Context, req *work.DeliverOrderAddR
 			return err
 		}
 
-		// 提交工单 审批
-		workflowSrv, _ := workflowService.NewFlowService(ctx)
-		bizCode := gconv.String(id[0]) + ":" + req.OrderTypeCode
-		formComponentValues := make([]*workflow.StartProcessInstanceRequestFormComponentValues, 0)
-		if err = gconv.Structs(req.FormData, &formComponentValues); err != nil {
+		workOrder, err := s.Dao.TX(tx).WherePri(id[0]).One()
+		if err != nil {
 			return err
 		}
+		if workOrder == nil {
+			return fmt.Errorf("工单不存在")
+		}
 
-		_, err = workflowSrv.StartProcessInstance(bizCode, workflowModel.DeliverOrderCreate, "", &workflow.StartProcessInstanceRequest{
-			ProcessCode:         &req.OrderTypeCode,
-			FormComponentValues: formComponentValues,
-		})
+		// 审批通过
+		data := g.Map{
+			s.Dao.C.OrderStatus: "10",
+		}
+
+		s.workOrderSendMsg(workOrder, "交付工单审批通过提醒", fmt.Sprintf("<p>工单:%s 已审批通过</p>", workOrder.OrderCode))
+
+		// 项目修改
+		_, err = s.Dao.TX(tx).WherePri(workOrder.Id).Update(fmt.Sprintf("order_status='%v'", data[s.Dao.C.OrderStatus]))
 		if err != nil {
-			g.Log().Error(err)
 			return err
 		}
 
-		return err
+		return nil
 	})
 	return id, txerr
 }