Преглед изворни кода

feature: 添加移回公海审批、转移客户审批、申请合同发票审批

liuyaqi пре 3 година
родитељ
комит
4cd3b08a6f

+ 1 - 1
opms_parent/app/dao/contract/internal/ctr_contract_invoice.go

@@ -35,7 +35,7 @@ type ctrContractInvoiceColumns struct {
 	InvoiceAmount     string // 开票金额
 	InvoiceDate       string // 开票日期
 	InvoiceType       string // 开票类型
-	ApproStatus       string // 审核状态
+	ApproStatus       string // 审核状态 10 待提交审核 20 待审核 30 审核已同意 40 审核已拒绝 50 审核已撤销
 	InvoiceCode       string // 发票号码
 	ActualInvoiceDate string // 实际开票日期
 	CourierCode       string // 快递单号

+ 14 - 0
opms_parent/app/handler/contract/ctr_contract_invoice.go

@@ -68,6 +68,20 @@ func (c *CtrContractInvoice) Update(ctx context.Context, req *model.CtrContractI
 	return nil
 }
 
+// Swagger:CtrContractInvoice 合同发票 提交发票申请
+func (c *CtrContractInvoice) InvoiceApply(ctx context.Context, req *model.CtrContractInvoiceInvoiceApplyReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("CtrContractInvoice.InvoiceApply request %#v ", *req)
+	s, err := service.NewCtrContractInvoiceService(ctx)
+	if err != nil {
+		return err
+	}
+	err = s.InvoiceApply(ctx, req)
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
 // Swagger:CtrContractInvoice 合同发票 删除合同发票
 func (c *CtrContractInvoice) Delete(ctx context.Context, req *model.IdsReq, rsp *comm_def.CommonMsg) error {
 	g.Log().Infof("CtrContractInvoice.Delete request %#v ", *req)

+ 2 - 16
opms_parent/app/handler/cust/customer.go

@@ -151,13 +151,10 @@ func (c *CustomerHeader) TransCustomer(ctx context.Context, req *model.AssignCus
 	if err != nil {
 		return err
 	}
-	err = s.TransCustomer(req)
+	err = s.TransCustomerRequest(ctx, req)
 	if err != nil {
 		return err
 	}
-
-	//转移客户
-	s.CreateDynamics("转移客户", req, req.Ids...)
 	return nil
 }
 
@@ -170,17 +167,10 @@ func (c *CustomerHeader) AssignCustomer(ctx context.Context, req *model.AssignCu
 	if err != nil {
 		return err
 	}
-	var behavior string
-	if req.Receive == "" {
-		behavior = "分配客户"
-	} else {
-		behavior = "领取"
-	}
 	err = s.AssignCustomer(ctx, req)
 	if err != nil {
 		return err
 	}
-	s.CreateDynamics(behavior, req, req.Ids...)
 	return nil
 
 }
@@ -194,15 +184,11 @@ func (c *CustomerHeader) MoveToPubic(ctx context.Context, req *model.MoveToPubic
 	if err != nil {
 		return err
 	}
-	err = s.MoveToPubic(req.Ids)
+	err = s.MoveToPublicRequest(ctx, req)
 	if err != nil {
 
 		return err
 	}
-	if req.Remark == "" {
-		req.Remark = ""
-	}
-	s.CreateDynamics("移入公海", req, req.Ids...)
 	return nil
 }
 

+ 53 - 0
opms_parent/app/handler/dingtalk/ding_event.go

@@ -3,6 +3,7 @@ package dingtalk
 import (
 	"context"
 	model "dashoo.cn/micro/app/model/workflow"
+	contractSrv "dashoo.cn/micro/app/service/contract"
 	custServer "dashoo.cn/micro/app/service/cust"
 	"dashoo.cn/micro/app/service/dingtalk_log"
 	platServer "dashoo.cn/micro/app/service/plat"
@@ -115,6 +116,58 @@ func (h *DingHandler) handleBpmsInstanceChange(msg *message.MixMessage, ctx *din
 			return err.Error()
 		}
 		return "success"
+	case model.CustomerPublic:
+		if msg.ProcessType == "finish" || msg.ProcessType == "terminate" {
+			srv, err := custServer.NewCustomerService(ctx.SubsMessage.Ctx)
+			if err != nil {
+				glog.Error(err)
+				return err.Error()
+			}
+			err = srv.MoveToPublicApproval(instance, msg)
+			if err != nil {
+				glog.Error(err)
+				return err.Error()
+			}
+		}
+		err = s.Update(instance, msg)
+		if err != nil {
+			glog.Error(err)
+			return err.Error()
+		}
+		return "success"
+	case model.CustomerTrans:
+		if msg.ProcessType == "finish" || msg.ProcessType == "terminate" {
+			srv, err := custServer.NewCustomerService(ctx.SubsMessage.Ctx)
+			if err != nil {
+				glog.Error(err)
+				return err.Error()
+			}
+			err = srv.TransCustomerApproval(instance, msg)
+			if err != nil {
+				glog.Error(err)
+				return err.Error()
+			}
+		}
+		err = s.Update(instance, msg)
+		if err != nil {
+			glog.Error(err)
+			return err.Error()
+		}
+		return "success"
+	case model.ContractInvoice:
+		if msg.ProcessType == "finish" || msg.ProcessType == "terminate" {
+			err = contractSrv.InvoiceApplyApproval(ctx.SubsMessage.Ctx, instance, msg)
+			if err != nil {
+				glog.Error(err)
+				return err.Error()
+			}
+		}
+		err = s.Update(instance, msg)
+		if err != nil {
+			glog.Error(err)
+			return err.Error()
+		}
+		return "success"
 	case model.ProjectCreate:
 		if msg.ProcessType == "finish" || msg.ProcessType == "terminate" {
 			//srv.Handle(instance, msg)

+ 6 - 0
opms_parent/app/model/contract/ctr_contract_invoice.go

@@ -63,3 +63,9 @@ type CtrContractInvoiceUpdateReq struct {
 	CourierCode       string      `json:"courierCode"`       // 快递单号
 	Remark            *string     `json:"remark"`
 }
+
+type CtrContractInvoiceInvoiceApplyReq struct {
+	Id            int     `json:"id" v:"required#请输入Id"`
+	AllReceive    bool    `json:"allReceive"`    // 是否已回全款
+	ReceiveAmount float64 `json:"receiveAmount"` // 回款金额(元)
+}

+ 1 - 1
opms_parent/app/model/contract/internal/ctr_contract_invoice.go

@@ -19,7 +19,7 @@ type CtrContractInvoice struct {
 	InvoiceAmount     float64     `orm:"invoice_amount"      json:"invoiceAmount"`     // 开票金额
 	InvoiceDate       *gtime.Time `orm:"invoice_date"        json:"invoiceDate"`       // 开票日期
 	InvoiceType       string      `orm:"invoice_type"        json:"invoiceType"`       // 开票类型
-	ApproStatus       string      `orm:"appro_status"        json:"approStatus"`       // 审核状态
+	ApproStatus       string      `orm:"appro_status"        json:"approStatus"`       // 审核状态 10 待提交审核 20 待审核 30 审核已同意 40 审核已拒绝 50 审核已撤销
 	InvoiceCode       string      `orm:"invoice_code"        json:"invoiceCode"`       // 发票号码
 	ActualInvoiceDate *gtime.Time `orm:"actual_invoice_date" json:"actualInvoiceDate"` // 实际开票日期
 	CourierCode       string      `orm:"courier_code"        json:"courierCode"`       // 快递单号

+ 1 - 1
opms_parent/app/model/cust/cust_customer.go

@@ -156,7 +156,7 @@ type UpdateCustomer struct {
 // 移入公海
 type MoveToPubicRep struct {
 	Ids    []int64 `json:"ids,omitempty"`
-	Remark string  `json:"remark,omitempty"`
+	Remark string  `json:"remark,omitempty"` // 移回原因
 }
 
 // 客户名称

+ 4 - 1
opms_parent/app/model/workflow/plat_workflow.go

@@ -9,11 +9,14 @@ import (
 	"dashoo.cn/opms_libary/request"
 )
 
-// BizType 业务类型(10领用20项目创建30合同创建)
+// BizType 业务类型(10客户20项目创建30合同创建)
 const (
 	CustomerReceive = "11" // 领取公海客户
+	CustomerPublic  = "12" // 客户移回公海
+	CustomerTrans   = "13" // 转移客户
 	ProjectCreate   = "20" // 项目创建
 	ContractCreate  = "30" // 合同创建
+	ContractInvoice = "31" // 申请发票
 )
 
 // PlatWorkflow is the golang structure for table plat_workflow.

+ 3 - 5
opms_parent/app/service/contract/ctr_contract.go

@@ -39,8 +39,8 @@ type CtrContractService struct {
 func NewCtrContractService(ctx context.Context) (*CtrContractService, error) {
 	tenant, err := micro_srv.GetTenant(ctx)
 	if err != nil {
-		err = myerrors.TipsError(fmt.Sprintf("获取组合码异常:%s", err.Error()))
-		return nil, err //fmt.Errorf("获取组合码异常:%s", err.Error())
+		err = myerrors.TipsError(fmt.Sprintf("获取租户码异常:%s", err.Error()))
+		return nil, err //fmt.Errorf("获取租户码异常:%s", err.Error())
 	}
 	// 获取用户信息
 	userInfo, err := micro_srv.GetUserInfo(ctx)
@@ -265,7 +265,6 @@ func (s CtrContractService) BindProduct(tx *gdb.TX, id int, product []model.CtrA
 			UpdatedBy:     int(s.userInfo.Id),
 			UpdatedName:   s.userInfo.NickName,
 			UpdatedTime:   gtime.Now(),
-			DeletedTime:   gtime.Now(),
 		})
 	}
 
@@ -366,7 +365,6 @@ func (s CtrContractService) Add(ctx context.Context, req *model.CtrContractAddRe
 		UpdatedBy:         int(s.userInfo.Id),
 		UpdatedName:       s.userInfo.NickName,
 		UpdatedTime:       gtime.Now(),
-		DeletedTime:       gtime.Now(),
 	}
 
 	var id int
@@ -584,7 +582,7 @@ func (s CtrContractService) UpdateInvoiceAmount(tx *gdb.TX, id int) error {
 		return err
 	}
 
-	v, err := tx.GetValue("select sum(invoice_amount) from ctr_contract_invoice where contract_id=? and appro_status='20' and deleted_time is null", id)
+	v, err := tx.GetValue("select sum(invoice_amount) from ctr_contract_invoice where contract_id=? and appro_status='30' and deleted_time is null", id)
 	if err != nil {
 		return err
 	}

+ 2 - 3
opms_parent/app/service/contract/ctr_contract_append.go

@@ -27,8 +27,8 @@ type CtrContractAppendService struct {
 func NewCtrContractAppendService(ctx context.Context) (*CtrContractAppendService, error) {
 	tenant, err := micro_srv.GetTenant(ctx)
 	if err != nil {
-		err = myerrors.TipsError(fmt.Sprintf("获取组合码异常:%s", err.Error()))
-		return nil, err //fmt.Errorf("获取组合码异常:%s", err.Error())
+		err = myerrors.TipsError(fmt.Sprintf("获取租户码异常:%s", err.Error()))
+		return nil, err //fmt.Errorf("获取租户码异常:%s", err.Error())
 	}
 	// 获取用户信息
 	userInfo, err := micro_srv.GetUserInfo(ctx)
@@ -112,7 +112,6 @@ func (s CtrContractAppendService) Add(ctx context.Context, req *model.CtrContrac
 		UpdatedBy:   s.userInfo.Id,
 		UpdatedName: s.userInfo.NickName,
 		UpdatedTime: gtime.Now(),
-		DeletedTime: gtime.Now(),
 	}
 
 	var id int

+ 2 - 3
opms_parent/app/service/contract/ctr_contract_collection.go

@@ -29,8 +29,8 @@ type CtrContractCollectionService struct {
 func NewCtrContractCollectionService(ctx context.Context) (*CtrContractCollectionService, error) {
 	tenant, err := micro_srv.GetTenant(ctx)
 	if err != nil {
-		err = myerrors.TipsError(fmt.Sprintf("获取组合码异常:%s", err.Error()))
-		return nil, err // fmt.Errorf("获取组合码异常:%s", err.Error())
+		err = myerrors.TipsError(fmt.Sprintf("获取租户码异常:%s", err.Error()))
+		return nil, err // fmt.Errorf("获取租户码异常:%s", err.Error())
 	}
 	// 获取用户信息
 	userInfo, err := micro_srv.GetUserInfo(ctx)
@@ -145,7 +145,6 @@ func (s CtrContractCollectionService) Add(ctx context.Context, req *model.CtrCon
 		UpdatedBy:          s.userInfo.Id,
 		UpdatedName:        s.userInfo.NickName,
 		UpdatedTime:        gtime.Now(),
-		DeletedTime:        gtime.Now(),
 	}
 	var id int
 	txerr := s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {

+ 2 - 3
opms_parent/app/service/contract/ctr_contract_collection_plan.go

@@ -29,8 +29,8 @@ type CtrContractCollectionPlanService struct {
 func NewCtrContractCollectionPlanService(ctx context.Context) (*CtrContractCollectionPlanService, error) {
 	tenant, err := micro_srv.GetTenant(ctx)
 	if err != nil {
-		err = myerrors.TipsError(fmt.Sprintf("获取组合码异常:%s", err.Error()))
-		return nil, err //fmt.Errorf("获取组合码异常:%s", err.Error())
+		err = myerrors.TipsError(fmt.Sprintf("获取租户码异常:%s", err.Error()))
+		return nil, err //fmt.Errorf("获取租户码异常:%s", err.Error())
 	}
 	// 获取用户信息
 	userInfo, err := micro_srv.GetUserInfo(ctx)
@@ -156,7 +156,6 @@ func (s CtrContractCollectionPlanService) Add(ctx context.Context, req *model.Ct
 		UpdatedBy:      s.userInfo.Id,
 		UpdatedName:    s.userInfo.NickName,
 		UpdatedTime:    gtime.Now(),
-		DeletedTime:    gtime.Now(),
 	}
 
 	var id int

+ 228 - 5
opms_parent/app/service/contract/ctr_contract_invoice.go

@@ -3,13 +3,23 @@ package service
 import (
 	"context"
 	"database/sql"
+	"encoding/json"
 	"fmt"
+	"strconv"
+	"strings"
 
 	dao "dashoo.cn/micro/app/dao/contract"
+	customerDao "dashoo.cn/micro/app/dao/cust"
+	sysDao "dashoo.cn/micro/app/dao/sys"
 	model "dashoo.cn/micro/app/model/contract"
+	workflowModel "dashoo.cn/micro/app/model/workflow"
+	workflowService "dashoo.cn/micro/app/service/workflow"
+	"dashoo.cn/opms_libary/utils"
 
 	"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"
 	"github.com/gogf/gf/database/gdb"
 	"github.com/gogf/gf/os/gtime"
@@ -19,6 +29,8 @@ import (
 type CtrContractInvoiceService struct {
 	Dao         *dao.CtrContractInvoiceDao
 	ContractDao *dao.CtrContractDao
+	CustomerDao *customerDao.CustCustomerDao
+	UserDao     *sysDao.SysUserDao
 	ctrSrv      *CtrContractService
 	Tenant      string
 	userInfo    request.UserInfo
@@ -28,7 +40,7 @@ func NewCtrContractInvoiceService(ctx context.Context) (*CtrContractInvoiceServi
 	tenant, err := micro_srv.GetTenant(ctx)
 	if err != nil {
 
-		return nil, myerrors.TipsError(fmt.Sprintf("获取组合码异常:%s", err.Error())) //fmt.Errorf("获取组合码异常:%s", err.Error())
+		return nil, myerrors.TipsError(fmt.Sprintf("获取租户码异常:%s", err.Error())) //fmt.Errorf("获取租户码异常:%s", err.Error())
 	}
 	// 获取用户信息
 	userInfo, err := micro_srv.GetUserInfo(ctx)
@@ -42,6 +54,8 @@ func NewCtrContractInvoiceService(ctx context.Context) (*CtrContractInvoiceServi
 	return &CtrContractInvoiceService{
 		Dao:         dao.NewCtrContractInvoiceDao(tenant),
 		ContractDao: dao.NewCtrContractDao(tenant),
+		CustomerDao: customerDao.NewCustCustomerDao(tenant),
+		UserDao:     sysDao.NewSysUserDao(tenant),
 		ctrSrv:      ctrSrv,
 		Tenant:      tenant,
 		userInfo:    userInfo,
@@ -162,7 +176,6 @@ func (s CtrContractInvoiceService) Add(ctx context.Context, req *model.CtrContra
 		UpdatedBy:         int(s.userInfo.Id),
 		UpdatedName:       s.userInfo.NickName,
 		UpdatedTime:       gtime.Now(),
-		DeletedTime:       gtime.Now(),
 	}
 	var id int
 	txerr := s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
@@ -286,6 +299,217 @@ func (s CtrContractInvoiceService) Update(ctx context.Context, req *model.CtrCon
 	return nil
 }
 
+var InvoiceApplyProcessCode = "PROC-D2F97FDE-6277-404D-89B5-91123FEBF1B8" // 申请发票
+
+func (s CtrContractInvoiceService) InvoiceApply(ctx context.Context, req *model.CtrContractInvoiceInvoiceApplyReq) error {
+	invoice, err := s.Dao.Where("id = ?", req.Id).One()
+	if err != nil {
+		return err
+	}
+	if invoice == nil {
+		return myerrors.TipsError("发票不存在")
+	}
+	if invoice.ApproStatus != "10" {
+		return myerrors.TipsError("发票当前状态不可提交审核")
+	}
+	contract, err := s.ContractDao.Where("id = ?", invoice.ContractId).One()
+	if err != nil {
+		return err
+	}
+	if contract == nil {
+		return myerrors.TipsError("发票所属合同不存在")
+	}
+	cust, err := s.CustomerDao.Where("id = ?", invoice.CustId).One()
+	if err != nil {
+		return err
+	}
+	if cust == nil {
+		return myerrors.TipsError("发票所属合同客户不存在")
+	}
+
+	allReceive := "未回全款"
+	if req.AllReceive {
+		allReceive = "已回全款"
+	}
+
+	product, err := s.ctrSrv.CtrProductDao.Where("contract_id = ?", contract.Id).All()
+	if err != nil {
+		return err
+	}
+	// productForm := []*workflow.StartProcessInstanceRequestFormComponentValuesDetails{}
+	// for _, p := range product {
+	// 	productForm = append(productForm, &workflow.StartProcessInstanceRequestFormComponentValuesDetails{
+	// 		Details: []*workflow.StartProcessInstanceRequestFormComponentValuesDetailsDetails{
+	// 			{
+	// 				Id:    utils.String("TextField_R967EJ9XVWW0"),
+	// 				Name:  utils.String("产品名称"),
+	// 				Value: utils.String(p.ProdName),
+	// 			},
+	// 			{
+	// 				Id:    utils.String("TextField_18AAHJYNVUBG0"),
+	// 				Name:  utils.String("产品型号"),
+	// 				Value: utils.String(p.ProdCode),
+	// 			},
+	// 			{
+	// 				Id:    utils.String("NumberField_1RFPF86Y699C0"),
+	// 				Name:  utils.String("产品数量"),
+	// 				Value: utils.String(strconv.Itoa(p.ProdNum)),
+	// 			},
+	// 		},
+	// 	})
+	// }
+	productForm := []interface{}{}
+	for _, p := range product {
+		productForm = append(productForm, []*workflow.StartProcessInstanceRequestFormComponentValuesDetailsDetails{
+			{
+				Id:    utils.String("TextField_R967EJ9XVWW0"),
+				Name:  utils.String("产品名称"),
+				Value: utils.String(p.ProdName),
+			},
+			{
+				Id:    utils.String("TextField_18AAHJYNVUBG0"),
+				Name:  utils.String("产品型号"),
+				Value: utils.String(p.ProdCode),
+			},
+			{
+				Id:    utils.String("NumberField_1RFPF86Y699C0"),
+				Name:  utils.String("产品数量"),
+				Value: utils.String(strconv.Itoa(p.ProdNum)),
+			},
+		})
+	}
+	productFormByte, err := json.Marshal(productForm)
+	if err != nil {
+		return err
+	}
+
+	workflowSrv, err := workflowService.NewFlowService(ctx)
+	if err != nil {
+		return err
+	}
+	bizCode := strings.Join([]string{
+		strconv.Itoa(invoice.Id),
+		strconv.Itoa(s.userInfo.Id),
+	}, ":")
+	_, err = workflowSrv.StartProcessInstance(bizCode, "31", &workflow.StartProcessInstanceRequest{
+		ProcessCode: &InvoiceApplyProcessCode,
+		FormComponentValues: []*workflow.StartProcessInstanceRequestFormComponentValues{
+			{
+				Id:    utils.String("DDSelectField_FSWX8IG61HC0"),
+				Name:  utils.String("单选框"),
+				Value: utils.String(allReceive),
+			},
+			{
+				Id:    utils.String("TextField_LUZ9EQ3IJB40"),
+				Name:  utils.String("合同编号"),
+				Value: utils.String(contract.ContractCode),
+			},
+			{
+				Id:    utils.String("TextField_A0V5RQK1BC80"),
+				Name:  utils.String("客户编号"),
+				Value: utils.String(cust.CustCode),
+			},
+			{
+				Id:    utils.String("TextField_1E2J1LS6H9HC0"),
+				Name:  utils.String("客户名称"),
+				Value: utils.String(cust.CustName),
+			},
+			{
+				Id:   utils.String("TableField_1IGTG9NX08U80"),
+				Name: utils.String("表格"),
+				// Details: productForm,
+				Value: utils.String(string(productFormByte)),
+			},
+			{
+				Id:    utils.String("MoneyField_1D8481FCI5FK0"),
+				Name:  utils.String("合同金额(元)"),
+				Value: utils.String(strconv.FormatFloat(contract.ContractAmount, 'f', 2, 64)),
+			},
+			{
+				Id:    utils.String("MoneyField_BQ2E2JGXHGO0"),
+				Name:  utils.String("回款金额(元)"),
+				Value: utils.String(strconv.FormatFloat(req.ReceiveAmount, 'f', 2, 64)),
+			},
+			{
+				Id:    utils.String("MoneyField_V47BSZICHIO0"),
+				Name:  utils.String("开票金额(元)"),
+				Value: utils.String(strconv.FormatFloat(invoice.InvoiceAmount, 'f', 2, 64)),
+			},
+		},
+	})
+	if err != nil {
+		return err
+	}
+
+	_, err = s.Dao.Where("id = ?", invoice.Id).Data(map[string]interface{}{
+		"appro_status": 20,
+	}).Update()
+	return err
+}
+
+func InvoiceApplyApproval(ctx context.Context, flow *workflowModel.PlatWorkflow, msg *message.MixMessage) error {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return fmt.Errorf("获取租户码异常:%s", err.Error())
+	}
+	invoiceDao := dao.NewCtrContractInvoiceDao(tenant)
+	userDao := sysDao.NewSysUserDao(tenant)
+
+	bizCode := strings.Split(flow.BizCode, ":")
+	if len(bizCode) != 2 {
+		return fmt.Errorf("申请发票审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
+	}
+	invoiceId, err := strconv.Atoi(bizCode[0])
+	if err != nil {
+		return fmt.Errorf("申请发票审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
+	}
+	userId, err := strconv.Atoi(bizCode[1])
+	if err != nil {
+		return fmt.Errorf("申请发票审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
+	}
+	user, err := userDao.Where("id = ?", userId).One()
+	if err != nil {
+		return err
+	}
+	if user == nil {
+		return fmt.Errorf("用户不存在:%s Id: %d", flow.BizCode, flow.Id)
+	}
+	invoice, err := invoiceDao.Where("id = ?", invoiceId).One()
+	if err != nil {
+		return err
+	}
+	if invoice == nil {
+		return fmt.Errorf("发票不存在:%s Id: %d", flow.BizCode, flow.Id)
+	}
+
+	if msg.ProcessType != "finish" && msg.ProcessType != "terminate" {
+		return fmt.Errorf("无法识别的 ProcessType :%s", msg.ProcessType)
+	}
+	if msg.Result != "agree" && msg.Result != "refuse" && msg.Result != "" {
+		return fmt.Errorf("无法识别的 Result :%s", msg.Result)
+	}
+
+	if msg.ProcessType == "terminate" {
+		_, err = invoiceDao.Where("id = ?", invoiceId).Data(map[string]interface{}{
+			"appro_status": "50",
+		}).Update()
+		return err
+	}
+
+	pass := msg.Result == "agree"
+	if !pass {
+		_, err = invoiceDao.Where("id = ?", invoiceId).Data(map[string]interface{}{
+			"appro_status": "40",
+		}).Update()
+		return err
+	}
+
+	_, err = invoiceDao.Where("id = ?", invoiceId).Data(map[string]interface{}{
+		"appro_status": "30",
+	}).Update()
+	return err
+}
+
 func (s CtrContractInvoiceService) Delete(ctx context.Context, id []int) error {
 	if len(id) == 0 {
 		return nil
@@ -301,10 +525,9 @@ func (s CtrContractInvoiceService) Delete(ctx context.Context, id []int) error {
 			if err != nil {
 				return err
 			}
-			if ent.ApproStatus != "20" {
-				continue
+			if ent.ApproStatus == "30" {
+				contractId[ent.ContractId] = true
 			}
-			contractId[ent.ContractId] = true
 		}
 
 		_, err := tx.Delete("ctr_contract_invoice", "id in (?)", id)

+ 39 - 0
opms_parent/app/service/contract/ctr_contract_test.go

@@ -0,0 +1,39 @@
+package service
+
+import (
+	"context"
+	"testing"
+
+	modelWorkflow "dashoo.cn/micro/app/model/workflow"
+	"dashoo.cn/opms_libary/plugin/dingtalk/message"
+	"github.com/gogf/gf/frame/g"
+	"github.com/smallnest/rpcx/share"
+)
+
+var testTenant = "default"
+
+func fakeCtx(parent context.Context, tenant string) context.Context {
+	ctx := context.WithValue(parent, share.ReqMetaDataKey, map[string]string{
+		"tenant": tenant,
+	})
+	return ctx
+}
+
+func TestAssignInvoiceApplyApproval(t *testing.T) {
+	ctx := fakeCtx(context.Background(), testTenant)
+
+	instance := modelWorkflow.PlatWorkflow{}
+	err := g.DB(testTenant).Table("plat_workflow").Where("id = ?", 47).Struct(&instance)
+	if err != nil {
+		panic(err)
+	}
+	err = InvoiceApplyApproval(ctx, &instance, &message.MixMessage{
+		ProcessType: "finish",
+		// ProcessType: "terminate",
+		// Result: "agree",
+		Result: "refuse",
+	})
+	if err != nil {
+		panic(err)
+	}
+}

+ 429 - 75
opms_parent/app/service/cust/cust_customer.go

@@ -3,13 +3,15 @@ package cust
 import (
 	"bytes"
 	"context"
-	"dashoo.cn/opms_libary/plugin/dingtalk/workflow"
-	"dashoo.cn/opms_libary/utils"
 	"fmt"
 	"math"
 	"strconv"
 	"strings"
 
+	"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"
 	"github.com/360EntSecGroup-Skylar/excelize"
@@ -290,52 +292,9 @@ func (s *CustomerService) UpdateById(req *model.UpdateCustomer) (err error) {
 	return
 }
 
-// MoveToPubic 移入公海
-func (s *CustomerService) MoveToPubic(Ids []int64) (err error) {
-	count, err := s.Dao.WhereIn(s.Dao.Columns.Id, Ids).Count()
-	if err != nil {
-		g.Log().Error(err)
-		return
-	}
-	if count == 0 {
-		err = myerrors.TipsError("没有要移除的数据")
-		return
-	}
-	userName := s.GetCxtUserName()
-	currentTime := gtime.Now() //  当前时间
-	s.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
-		//更新客户信息
-		_, err = s.Dao.TX(tx).Data(g.Map{
-			"is_public":    isPublic,
-			"sales_id":     0,
-			"dept_id":      0,
-			"dept_name":    "",
-			"create_time":  currentTime,
-			"updated_by":   s.GetCxtUserId(),
-			"updated_name": userName,
-			"updated_time": currentTime,
-		}).WhereIn(s.ContactDao.Columns.Id, Ids).Update()
-		if err != nil {
-			g.Log().Error(err)
-			return err
-		}
-		//更新销售归属表结束时间
-		_, err = s.BelongDao.TX(tx).Data(
-			g.Map{
-				"updated_by":   s.GetCxtUserId(),
-				"updated_name": userName,
-				"end_date":     currentTime,
-			}).WhereIn(s.BelongDao.Columns.CustId, Ids).Update()
-		if err != nil {
-			g.Log().Error(err)
-			return err
-		}
-		return nil
-	})
-	return
-}
-
-var AssignCustomerRequestProcessCode = "PROC-FE42B2D1-6097-4DE8-8AC5-23541B7D5C8A"
+var AssignCustomerRequestProcessCode = "PROC-FE42B2D1-6097-4DE8-8AC5-23541B7D5C8A" // BizCode: 11
+var MoveToPubicRequestProcessCode = "PROC-C030BD3D-74A3-4FE5-9EBA-DF3BA9F8AEF9"    // BizCode: 12
+var TransCustomerRequestProcessCode = "PROC-03BE93D3-9A44-43A1-BA6D-D1BB75702542"  // BizCode: 13
 
 // AssignCustomerRequest 领取客户申请
 func (s *CustomerService) AssignCustomerRequest(ctx context.Context, req *model.AssignCustomerReq) error {
@@ -354,6 +313,15 @@ func (s *CustomerService) AssignCustomerRequest(ctx context.Context, req *model.
 		if v.CustStatus != "10" {
 			return myerrors.TipsError(fmt.Sprintf("客户: %s 已被领取", v.CustName))
 		}
+		if v.CustProvince == "" {
+			return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的所在省信息", v.CustName))
+		}
+		if v.CustCity == "" {
+			return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的所在市信息", v.CustName))
+		}
+		if v.CustIndustry == "" {
+			return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的客户类型信息", v.CustName))
+		}
 	}
 
 	workflowSrv, err := workflowService.NewFlowService(ctx)
@@ -375,6 +343,21 @@ func (s *CustomerService) AssignCustomerRequest(ctx context.Context, req *model.
 					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("申请人"),
@@ -454,20 +437,392 @@ func (s *CustomerService) AssignCustomerRequestApproval(flow *workflowModel.Plat
 		return err
 	}
 
+	s.CxtUser = &request.UserInfo{Id: user.Id, UserName: user.NickName}
 	err = s.ChangeCustBelong([]int64{int64(custId)}, int64(userId), user.NickName)
 	if err != nil {
 		return err
 	}
-	s.BatchCreatebelong([]*model.CustCustomer{cust}, &model.AssignCustomerReq{
+	err = s.BatchCreatebelong([]*model.CustCustomer{cust}, &model.AssignCustomerReq{
 		Ids:       []int64{int64(custId)},
 		SalesId:   int64(user.Id),
 		SalesName: user.NickName,
 		Remark:    "",
 		Receive:   Receive,
 	})
+	if err != nil {
+		return err
+	}
+
+	s.CxtUser = &request.UserInfo{Id: user.Id, UserName: user.NickName}
+	return s.CreateDynamics("领取客户", map[string]interface{}{
+		"userId": user.Id,
+		"custId": cust.Id,
+	}, int64(cust.Id))
+}
+
+// 移回公海
+func (s *CustomerService) MoveToPublicRequest(ctx context.Context, req *model.MoveToPubicRep) error {
+	if req.Remark == "" {
+		return myerrors.TipsError("请输入移回原因")
+	}
+	data, err := s.Dao.Where("id in (?)", req.Ids).All()
+	if err != nil {
+		return err
+	}
+	if len(data) == 0 {
+		return myerrors.TipsError("移回用户不能为空")
+	}
+
+	for _, v := range data {
+		if v.CustStatus == "10" {
+			return myerrors.TipsError(fmt.Sprintf("客户: %s 已被移回公海", v.CustName))
+		}
+		if v.CustStatus == "20" {
+			return myerrors.TipsError(fmt.Sprintf("客户: %s 正在等待审批", v.CustName))
+		}
+		if v.CustProvince == "" {
+			return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的所在省信息", v.CustName))
+		}
+		if v.CustCity == "" {
+			return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的所在市信息", v.CustName))
+		}
+		if v.CustIndustry == "" {
+			return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的客户类型信息", v.CustName))
+		}
+	}
+
+	workflowSrv, err := workflowService.NewFlowService(ctx)
+	if err != nil {
+		return err
+	}
+	for _, u := range data {
+		bizCode := strconv.Itoa(u.Id) + ":" + strconv.Itoa(s.GetCxtUserId())
+		_, err = workflowSrv.StartProcessInstance(bizCode, "12", &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(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
 }
 
+// 移入公海回调
+func (s *CustomerService) MoveToPublicApproval(flow *workflowModel.PlatWorkflow, msg *message.MixMessage) error {
+	bizCode := strings.Split(flow.BizCode, ":")
+	if len(bizCode) != 2 {
+		return fmt.Errorf("客户移回审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
+	}
+	custId, err := strconv.Atoi(bizCode[0])
+	if err != nil {
+		return fmt.Errorf("客户移回审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
+	}
+	userId, err := strconv.Atoi(bizCode[1])
+	if err != nil {
+		return fmt.Errorf("客户移回审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
+	}
+	user, err := s.UserDao.Where("id = ?", userId).One()
+	if err != nil {
+		return err
+	}
+	if user == nil {
+		return fmt.Errorf("用户不存在:%s Id: %d", flow.BizCode, flow.Id)
+	}
+	cust, err := s.Dao.Where("id = ?", custId).One()
+	if err != nil {
+		return err
+	}
+	if cust == nil {
+		return fmt.Errorf("客户不存在:%s Id: %d", flow.BizCode, flow.Id)
+	}
+
+	if msg.ProcessType != "finish" && msg.ProcessType != "terminate" {
+		return fmt.Errorf("无法识别的 ProcessType :%s", msg.ProcessType)
+	}
+	if msg.Result != "agree" && msg.Result != "refuse" && msg.Result != "" {
+		return fmt.Errorf("无法识别的 Result :%s", msg.Result)
+	}
+
+	if msg.ProcessType == "terminate" {
+		_, err = s.Dao.Where("id = ?", custId).Data(map[string]interface{}{
+			"cust_status": "30",
+		}).Update()
+		return err
+	}
+
+	pass := msg.Result == "agree"
+	if !pass {
+		_, err = s.Dao.Where("id = ?", custId).Data(map[string]interface{}{
+			"cust_status": "30",
+		}).Update()
+		return err
+	}
+
+	now := gtime.Now()
+	err = s.Dao.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
+		//更新客户信息
+		_, err = s.Dao.TX(tx).Data(g.Map{
+			"cust_status":  "10",
+			"is_public":    isPublic,
+			"sales_id":     0,
+			"dept_id":      0,
+			"dept_name":    "",
+			"create_time":  now,
+			"updated_by":   user.Id,
+			"updated_name": user.NickName,
+			"updated_time": now,
+		}).Where("id = ?", cust.Id).Update()
+		if err != nil {
+			return err
+		}
+		//更新销售归属表结束时间
+		_, err = s.BelongDao.TX(tx).Data(
+			g.Map{
+				"updated_by":   user.Id,
+				"updated_name": user.NickName,
+				"end_date":     now,
+			}).Where("cust_id = ?", cust.Id).Update()
+		if err != nil {
+			return err
+		}
+		return nil
+	})
+	if err != nil {
+		return err
+	}
+
+	s.CxtUser = &request.UserInfo{Id: user.Id, UserName: user.NickName}
+	return s.CreateDynamics("移入公海", map[string]interface{}{
+		"userId": user.Id,
+		"custId": cust.Id,
+	}, int64(cust.Id))
+}
+
+// 转移客户
+func (s *CustomerService) TransCustomerRequest(ctx context.Context, req *model.AssignCustomerReq) error {
+	if req.Remark == "" {
+		return myerrors.TipsError("请输入转移原因")
+	}
+	data, err := s.Dao.Where("id in (?)", req.Ids).All()
+	if err != nil {
+		return err
+	}
+	if len(data) == 0 {
+		return myerrors.TipsError("转移用户不能为空")
+	}
+
+	for _, v := range data {
+		if v.CustStatus == "10" {
+			return myerrors.TipsError(fmt.Sprintf("客户: %s 为公海客户", v.CustName))
+		}
+		if v.CustStatus == "20" {
+			return myerrors.TipsError(fmt.Sprintf("客户: %s 正在等待审批", v.CustName))
+		}
+		if v.CustProvince == "" {
+			return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的所在省信息", v.CustName))
+		}
+		if v.CustCity == "" {
+			return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的所在市信息", v.CustName))
+		}
+		if v.CustIndustry == "" {
+			return myerrors.TipsError(fmt.Sprintf("请先完善客户: %s 的客户类型信息", v.CustName))
+		}
+	}
+
+	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", &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
+		}
+
+		_, err = s.Dao.Where("id = ?", u.Id).Data(map[string]interface{}{
+			"cust_status": "20",
+		}).Update()
+		if err != nil {
+			return err
+		}
+	}
+	return nil
+}
+
+// 转移客户回调
+func (s *CustomerService) TransCustomerApproval(flow *workflowModel.PlatWorkflow, msg *message.MixMessage) error {
+	bizCode := strings.Split(flow.BizCode, ":")
+	if len(bizCode) != 3 {
+		return fmt.Errorf("转移客户审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
+	}
+	custId, err := strconv.Atoi(bizCode[0])
+	if err != nil {
+		return fmt.Errorf("转移客户审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
+	}
+	userId, err := strconv.Atoi(bizCode[1])
+	if err != nil {
+		return fmt.Errorf("转移客户审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
+	}
+	toUserId, err := strconv.Atoi(bizCode[2])
+	if err != nil {
+		return fmt.Errorf("转移客户审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
+	}
+	user, err := s.UserDao.Where("id = ?", userId).One()
+	if err != nil {
+		return err
+	}
+	if user == nil {
+		return fmt.Errorf("用户不存在:%s Id: %d", flow.BizCode, flow.Id)
+	}
+	toUser, err := s.UserDao.Where("id = ?", toUserId).One()
+	if err != nil {
+		return err
+	}
+	if toUser == nil {
+		return fmt.Errorf("用户不存在:%s Id: %d", flow.BizCode, flow.Id)
+	}
+	cust, err := s.Dao.Where("id = ?", custId).One()
+	if err != nil {
+		return err
+	}
+	if cust == nil {
+		return fmt.Errorf("客户不存在:%s Id: %d", flow.BizCode, flow.Id)
+	}
+
+	if msg.ProcessType != "finish" && msg.ProcessType != "terminate" {
+		return fmt.Errorf("无法识别的 ProcessType :%s", msg.ProcessType)
+	}
+	if msg.Result != "agree" && msg.Result != "refuse" && msg.Result != "" {
+		return fmt.Errorf("无法识别的 Result :%s", msg.Result)
+	}
+
+	if msg.ProcessType == "terminate" {
+		_, err = s.Dao.Where("id = ?", custId).Data(map[string]interface{}{
+			"cust_status": "30",
+		}).Update()
+		return err
+	}
+
+	pass := msg.Result == "agree"
+	if !pass {
+		_, err = s.Dao.Where("id = ?", custId).Data(map[string]interface{}{
+			"cust_status": "30",
+		}).Update()
+		return err
+	}
+
+	s.CxtUser = &request.UserInfo{Id: user.Id, UserName: user.NickName}
+	err = s.ChangeCustBelong([]int64{int64(custId)}, int64(toUserId), toUser.NickName)
+	if err != nil {
+		return err
+	}
+	err = s.BatchCreatebelong([]*model.CustCustomer{cust}, &model.AssignCustomerReq{
+		Ids:       []int64{int64(custId)},
+		SalesId:   int64(toUser.Id),
+		SalesName: toUser.NickName,
+		Remark:    "",
+		Receive:   OperaTion,
+	})
+	if err != nil {
+		return err
+	}
+
+	s.CxtUser = &request.UserInfo{Id: user.Id, UserName: user.NickName}
+	return s.CreateDynamics("转移客户", map[string]interface{}{
+		"userId":   user.Id,
+		"custId":   cust.Id,
+		"toUserId": toUser.Id,
+	}, int64(cust.Id))
+}
+
 // AssignCustomer 分配客户
 func (s *CustomerService) AssignCustomer(ctx context.Context, req *model.AssignCustomerReq) (err error) {
 	if req.Receive != "" {
@@ -493,13 +848,12 @@ func (s *CustomerService) AssignCustomer(ctx context.Context, req *model.AssignC
 	if err != nil {
 		return
 	}
-	if req.Receive != "" {
-		req.Receive = Receive
-	} else {
-		req.Receive = AllocaTion
+	req.Receive = AllocaTion
+	err = s.BatchCreatebelong(data, req)
+	if err != nil {
+		return err
 	}
-	s.BatchCreatebelong(data, req)
-	return
+	return s.CreateDynamics("分配客户", req, req.Ids...)
 }
 
 // GetEntityById 客户详情
@@ -568,26 +922,26 @@ func (s *CustomerService) CustAbstract(Id int64) (followInfo *model.Follow, err
 	return
 }
 
-// TransCustomer 转移客户
-func (s *CustomerService) TransCustomer(req *model.AssignCustomerReq) (err error) {
-	data, err := s.Dao.Fields("sales_id,sales_name,id").Where("id in (?)", req.Ids).All()
-	if err != nil {
-		g.Log().Error(err)
-		return err
-	}
-
-	if len(data) == 0 {
-		return myerrors.TipsError("数据不存在")
-	}
-	err = s.ChangeCustBelong(req.Ids, req.SalesId, req.SalesName)
-	if err != nil {
-		g.Log().Error(err)
-		return
-	}
-	req.Receive = OperaTion
-	s.BatchCreatebelong(data, req)
-	return
-}
+// // TransCustomer 转移客户
+// func (s *CustomerService) TransCustomer(req *model.AssignCustomerReq) (err error) {
+// 	data, err := s.Dao.Fields("sales_id,sales_name,id").Where("id in (?)", req.Ids).All()
+// 	if err != nil {
+// 		g.Log().Error(err)
+// 		return err
+// 	}
+
+// 	if len(data) == 0 {
+// 		return myerrors.TipsError("数据不存在")
+// 	}
+// 	err = s.ChangeCustBelong(req.Ids, req.SalesId, req.SalesName)
+// 	if err != nil {
+// 		g.Log().Error(err)
+// 		return
+// 	}
+// 	req.Receive = OperaTion
+// 	s.BatchCreatebelong(data, req)
+// 	return
+// }
 
 // ChangeCustBelong 变更客户所属关系
 func (s *CustomerService) ChangeCustBelong(Ids []int64, salesId int64, salesName string) (err error) {

+ 86 - 0
opms_parent/app/service/cust/cust_customer_test.go

@@ -0,0 +1,86 @@
+package cust
+
+import (
+	"context"
+	"testing"
+
+	modelWorkflow "dashoo.cn/micro/app/model/workflow"
+	"dashoo.cn/opms_libary/plugin/dingtalk/message"
+	"github.com/gogf/gf/frame/g"
+	"github.com/smallnest/rpcx/share"
+)
+
+var testTenant = "default"
+
+func fakeCtx(parent context.Context, tenant string) context.Context {
+	ctx := context.WithValue(parent, share.ReqMetaDataKey, map[string]string{
+		"tenant": tenant,
+	})
+	return ctx
+}
+
+func TestAssignCustomerRequestApproval(t *testing.T) {
+	ctx := fakeCtx(context.Background(), testTenant)
+	srv, err := NewCustomerService(ctx)
+	if err != nil {
+		panic(err)
+	}
+	instance := modelWorkflow.PlatWorkflow{}
+	err = g.DB(testTenant).Table("plat_workflow").Where("id = ?", 33).Struct(&instance)
+	if err != nil {
+		panic(err)
+	}
+	err = srv.AssignCustomerRequestApproval(&instance, &message.MixMessage{
+		ProcessType: "finish",
+		// ProcessType: "terminate",
+		Result: "agree",
+		// Result: "refuse",
+	})
+	if err != nil {
+		panic(err)
+	}
+}
+
+func TestAssignMoveToPublicApproval(t *testing.T) {
+	ctx := fakeCtx(context.Background(), testTenant)
+	srv, err := NewCustomerService(ctx)
+	if err != nil {
+		panic(err)
+	}
+	instance := modelWorkflow.PlatWorkflow{}
+	err = g.DB(testTenant).Table("plat_workflow").Where("id = ?", 25).Struct(&instance)
+	if err != nil {
+		panic(err)
+	}
+	err = srv.MoveToPublicApproval(&instance, &message.MixMessage{
+		ProcessType: "finish",
+		// ProcessType: "terminate",
+		Result: "agree",
+		// Result: "refuse",
+	})
+	if err != nil {
+		panic(err)
+	}
+}
+
+func TestAssignTransCustomerApproval(t *testing.T) {
+	ctx := fakeCtx(context.Background(), testTenant)
+	srv, err := NewCustomerService(ctx)
+	if err != nil {
+		panic(err)
+	}
+	instance := modelWorkflow.PlatWorkflow{}
+	err = g.DB(testTenant).Table("plat_workflow").Where("id = ?", 27).Struct(&instance)
+	if err != nil {
+		panic(err)
+	}
+	err = srv.TransCustomerApproval(&instance, &message.MixMessage{
+		ProcessType: "finish",
+		// ProcessType: "terminate",
+		Result: "agree",
+		// Result: "refuse",
+	})
+	if err != nil {
+		panic(err)
+	}
+}

+ 1 - 1
opms_parent/app/service/workflow/work_flow.go

@@ -50,7 +50,6 @@ func (s *workflowService) GetProcessInstanceDetail(instId string) (*workflow.Que
 // bizType:业务类型(10领用20项目创建30合同创建
 // 详情参照文档:https://open.dingtalk.com/document/orgapp/create-an-approval-instance
 func (s *workflowService) StartProcessInstance(bizCode, bizType string, flow *workflow.StartProcessInstanceRequest) (insertId int64, err error) {
-	g.Log().Info("搜索值", flow)
 	// 参数调整
 	if flow.OriginatorUserId == nil {
 		flow.OriginatorUserId = utils.String(s.GetCxtUserDingtalkUid())
@@ -58,6 +57,7 @@ func (s *workflowService) StartProcessInstance(bizCode, bizType string, flow *wo
 	if flow.DeptId == nil {
 		flow.DeptId = utils.Int64(435711466)
 	}
+	g.Log().Info("搜索值", flow)
 	// 调用钉钉接口
 	client := dingtalk.NewClient()
 	w := client.GetWorkflow()

+ 1 - 1
opms_parent/schema/contract.sql

@@ -100,7 +100,7 @@ CREATE TABLE `ctr_contract_invoice` (
     `invoice_amount` decimal(24, 6) NOT NULL COMMENT '开票金额',
     `invoice_date` datetime NOT NULL COMMENT '开票日期',
     `invoice_type` varchar(4) DEFAULT NULL COMMENT '开票类型',
-    `appro_status` varchar(4) DEFAULT NULL COMMENT '审核状态 10 未通过 20 已通过',
+    `appro_status` varchar(4) DEFAULT NULL COMMENT '审核状态 10 待提交审核 20 待审核 30 审核已同意 40 审核已拒绝 50 审核已撤销',
     `invoice_code` varchar(32) DEFAULT NULL COMMENT '发票号码',
     `actual_invoice_date` datetime DEFAULT NULL COMMENT '实际开票日期',
     `courier_code` varchar(32) DEFAULT NULL COMMENT '快递单号',

+ 1 - 0
opms_parent/schema/tmp.sql

@@ -6,3 +6,4 @@ alter table cust_customer add `cust_region_id` INT(11) COMMENT '所在区县ID'
 alter table cust_customer add `cust_region` VARCHAR(90) COMMENT '所在区县' after cust_region_id;
 alter table cust_customer modify `cust_status` VARCHAR(4) DEFAULT 10 COMMENT '客户状态(10 待领取 20 领取审批 30 已领取)';
 alter table cust_customer add `follow_up_man` VARCHAR(90) COMMENT '最后跟进人' after follow_up_date;
+alter table ctr_contract_invoice modify `appro_status` varchar(4) DEFAULT NULL COMMENT '审核状态 10 待提交审核 20 待审核 30 审核已同意 40 审核已拒绝 50 审核已撤销',