|
|
@@ -5,10 +5,17 @@ import (
|
|
|
"database/sql"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
+ "io/ioutil"
|
|
|
+ "net/http"
|
|
|
+ "os"
|
|
|
+ "path"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
|
|
|
+ "dashoo.cn/opms_libary/micro_srv"
|
|
|
"dashoo.cn/opms_libary/myerrors"
|
|
|
- "github.com/gogf/gf/container/garray"
|
|
|
+ "dashoo.cn/opms_libary/plugin/dingtalk"
|
|
|
"github.com/gogf/gf/database/gdb"
|
|
|
"github.com/gogf/gf/frame/g"
|
|
|
"github.com/gogf/gf/os/gtime"
|
|
|
@@ -21,7 +28,12 @@ import (
|
|
|
model "dashoo.cn/micro/app/model/base"
|
|
|
contractmodel "dashoo.cn/micro/app/model/contract"
|
|
|
projmodel "dashoo.cn/micro/app/model/proj"
|
|
|
+ workflowmodel "dashoo.cn/micro/app/model/workflow"
|
|
|
"dashoo.cn/micro/app/service"
|
|
|
+ workflowService "dashoo.cn/micro/app/service/workflow"
|
|
|
+ "dashoo.cn/opms_libary/plugin/dingtalk/message"
|
|
|
+ "dashoo.cn/opms_libary/plugin/dingtalk/workflow"
|
|
|
+ "dashoo.cn/opms_libary/utils"
|
|
|
)
|
|
|
|
|
|
type distributorService struct {
|
|
|
@@ -50,12 +62,9 @@ func NewDistributorService(ctx context.Context) (svc *distributorService, err er
|
|
|
}
|
|
|
|
|
|
// GetList 经销商信息列表
|
|
|
-func (s *distributorService) GetList(req *model.BaseDistributorSearchReq) (total int, distributorList []*model.BaseDistributorListRsp, err error) {
|
|
|
+func (s *distributorService) GetList(ctx context.Context, req *model.BaseDistributorSearchReq) (total int, distributorList []*model.BaseDistributorListRsp, err error) {
|
|
|
distributorModel := s.Dao.FieldsEx(s.Dao.C.DeletedTime)
|
|
|
- // 用户仅有销售工程师角色展示自己的数据,其他人可以看到所有数据
|
|
|
- if garray.NewStrArrayFrom(s.CxtUser.Roles, true).Contains("SalesEngineer") {
|
|
|
- distributorModel = distributorModel.WhereIn("belong_sale_id", s.DataScope["userIds"])
|
|
|
- }
|
|
|
+ distributorModel = distributorModel.DataScope(ctx, "belong_sale_id")
|
|
|
if req.DistCode != "" {
|
|
|
distributorModel = distributorModel.WhereLike(s.Dao.C.DistCode, "%"+req.DistCode+"%")
|
|
|
}
|
|
|
@@ -139,25 +148,114 @@ func (s *distributorService) getDistributorCode(distCode string) (string, error)
|
|
|
}
|
|
|
|
|
|
// Create 经销商创建
|
|
|
-func (s *distributorService) Create(req *model.AddDistributor) (lastId int64, err error) {
|
|
|
+func (s *distributorService) Create(ctx context.Context, req *model.AddDistributor) (int64, error) {
|
|
|
DistributorData := new(model.BaseDistributor)
|
|
|
- if err = gconv.Struct(req, DistributorData); err != nil {
|
|
|
- return
|
|
|
+ if err := gconv.Struct(req, DistributorData); err != nil {
|
|
|
+ return 0, err
|
|
|
}
|
|
|
- DistributorData.DistCode, err = s.getDistributorCode("JXS")
|
|
|
+ code, err := s.getDistributorCode("JXS")
|
|
|
if err != nil {
|
|
|
return 0, err
|
|
|
}
|
|
|
+ DistributorData.DistCode = code
|
|
|
+ if DistributorData.DistType == "20" {
|
|
|
+ DistributorData.ApproItem = "创建代理商"
|
|
|
+ DistributorData.ApproStatus = "20"
|
|
|
+ if req.ContractUrl != "" && req.ContractFileName == "" {
|
|
|
+ return 0, myerrors.TipsError("合同文件名不能为空")
|
|
|
+ }
|
|
|
+ }
|
|
|
service.SetCreatedInfo(DistributorData, s.GetCxtUserId(), s.GetCxtUserName())
|
|
|
- lastId, err = s.Dao.InsertAndGetId(DistributorData)
|
|
|
- if err != nil {
|
|
|
- return 0, err
|
|
|
+ var id int64
|
|
|
+ txerr := s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
|
|
|
+ id, err = tx.InsertAndGetId("base_distributor", DistributorData)
|
|
|
+ if err != nil {
|
|
|
+ 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
|
|
|
+ })
|
|
|
+ return id, txerr
|
|
|
+}
|
|
|
+
|
|
|
+var ProcessCodeDistProxyCreate = "PROC-9494B87D-DE96-49EE-B676-D3913911BE21" // 创建代理商
|
|
|
+
|
|
|
+func (s *distributorService) createDingtalkProcess(ctx context.Context, ent *model.BaseDistributor, contractFileName string) error {
|
|
|
+ var fileinfoByte []byte
|
|
|
+ if ent.ContractUrl != "" {
|
|
|
+ var err error
|
|
|
+ fileinfoByte, err = UploadDingtalk(s.CxtUser.DingtalkId, ent.ContractUrl, contractFileName)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
}
|
|
|
- err = s.Dao.DB.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
|
|
|
- err = s.AddDynamicsByCurrentUser(tx, int(lastId), "创建经销商/代理商", map[string]interface{}{})
|
|
|
+
|
|
|
+ workflowSrv, err := workflowService.NewFlowService(ctx)
|
|
|
+ if err != nil {
|
|
|
return err
|
|
|
+ }
|
|
|
+ bizCode := strconv.Itoa(ent.Id)
|
|
|
+ form := []*workflow.StartProcessInstanceRequestFormComponentValues{
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField-K2AD4O5B"),
|
|
|
+ Name: utils.String("代理商名称"),
|
|
|
+ Value: utils.String(ent.DistName),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_DZ2HNXRKHCG"),
|
|
|
+ Name: utils.String("所在省"),
|
|
|
+ Value: utils.String(ent.ProvinceDesc),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_1M07EV7YVOPS0"),
|
|
|
+ Name: utils.String("业务范围"),
|
|
|
+ Value: utils.String(ent.BusinessScope),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_UGJ0UKCU5DS0"),
|
|
|
+ Name: utils.String("注册资金(万元)"),
|
|
|
+ Value: utils.String(strconv.FormatFloat(ent.Capital, 'f', 2, 64)),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_1RC4FO1WUZ4W0"),
|
|
|
+ Name: utils.String("注册地"),
|
|
|
+ Value: utils.String(ent.RegisterDistrict),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_FKM6LUQYLFS0"),
|
|
|
+ Name: utils.String("现有销售人数"),
|
|
|
+ Value: utils.String(strconv.Itoa(ent.SaleNum)),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_1L89WCJM3ZMO0"),
|
|
|
+ Name: utils.String("已有代理名牌和产品"),
|
|
|
+ Value: utils.String(ent.ExistedProduct),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_P5JA5OZ5XKW0"),
|
|
|
+ Name: utils.String("历史合作的终端客户名称"),
|
|
|
+ Value: utils.String(ent.HistoryCustomer),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ if len(fileinfoByte) != 0 {
|
|
|
+ form = append(form, &workflow.StartProcessInstanceRequestFormComponentValues{
|
|
|
+ Id: utils.String("DDAttachment_SD6QFFBOSAO0"),
|
|
|
+ Name: utils.String("代理合同"),
|
|
|
+ Value: utils.String(string(fileinfoByte)),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ _, err = workflowSrv.StartProcessInstance(bizCode, workflowmodel.DistProxyCreate, "", &workflow.StartProcessInstanceRequest{
|
|
|
+ ProcessCode: &ProcessCodeDistProxyCreate,
|
|
|
+ FormComponentValues: form,
|
|
|
})
|
|
|
- return
|
|
|
+ return err
|
|
|
}
|
|
|
|
|
|
// GetEntityById 详情
|
|
|
@@ -184,15 +282,19 @@ func (s *distributorService) GetEntityById(id int64) (distributorInfo *model.Bas
|
|
|
|
|
|
// UpdateById 修改数据
|
|
|
func (s *distributorService) UpdateById(req *model.UpdateDistributorReq) (err error) {
|
|
|
- count, err := s.Dao.Where("id = ", req.Id).Count()
|
|
|
+ ent, err := s.Dao.Where("id = ", req.Id).One()
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
return
|
|
|
}
|
|
|
- if count == 0 {
|
|
|
+ if ent == nil {
|
|
|
err = myerrors.TipsError("无修改数据")
|
|
|
return
|
|
|
}
|
|
|
+ if ent.ApproStatus == "20" {
|
|
|
+ err = myerrors.TipsError("不能修改待审核数据")
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
distData := new(model.BaseDistributor)
|
|
|
if err = gconv.Struct(req, distData); err != nil {
|
|
|
@@ -217,6 +319,9 @@ func (s *distributorService) ToProxy(ctx context.Context, req *model.Distributor
|
|
|
if validErr != nil {
|
|
|
return myerrors.TipsError(validErr.Current().Error())
|
|
|
}
|
|
|
+ if req.ContractUrl != "" && req.ContractFileName == "" {
|
|
|
+ return myerrors.TipsError("合同文件名不能为空")
|
|
|
+ }
|
|
|
|
|
|
ent, err := s.Dao.Where("id = ?", req.Id).One()
|
|
|
if err != nil {
|
|
|
@@ -225,49 +330,102 @@ 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(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
|
|
|
+ txerr := s.Dao.DB.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) error {
|
|
|
_, err = tx.Update("base_distributor", map[string]interface{}{
|
|
|
- "dist_type": "20",
|
|
|
- "customer_type": req.CustomerType,
|
|
|
- "proxy_start_time": req.ProxyStartTime,
|
|
|
- "proxy_end_time": req.ProxyEndTime,
|
|
|
- "proxy_district": req.ProxyDistrict,
|
|
|
- "contract_url": req.ContractUrl,
|
|
|
+ "appro_status": "20",
|
|
|
+ "appro_data": string(approvalDataByte),
|
|
|
+ "appro_item": "经销商转代理商",
|
|
|
}, "id = ?", req.Id)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- _, err = tx.Insert("base_distributor_record", model.BaseDistributorRecord{
|
|
|
- DistId: req.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(),
|
|
|
- })
|
|
|
+ return s.toProxyDingtalkProcess(ctx, ent, req)
|
|
|
+ })
|
|
|
+ return txerr
|
|
|
+}
|
|
|
+
|
|
|
+var ProcessCodeDistToProxy = "PROC-39C96165-131C-48EC-B8C0-AA528E0C9F3A" // 经销商转代理商
|
|
|
+func (s *distributorService) toProxyDingtalkProcess(ctx context.Context, ent *model.BaseDistributor, req *model.DistributorToProxyReq) error {
|
|
|
+ var fileinfoByte []byte
|
|
|
+ if req.ContractUrl != "" {
|
|
|
+ var err error
|
|
|
+ fileinfoByte, err = UploadDingtalk(s.CxtUser.DingtalkId, req.ContractUrl, req.ContractFileName)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- err = s.AddDynamicsByCurrentUser(tx, req.Id, "转为代理商", map[string]interface{}{})
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
+ }
|
|
|
+
|
|
|
+ cusTypeMap, err := service.GetDictDataByType(ctx, "cust_idy")
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ cusType := []string{}
|
|
|
+ for _, t := range strings.Split(req.CustomerType, ",") {
|
|
|
+ if v := cusTypeMap[t]; v != "" {
|
|
|
+ cusType = append(cusType, v)
|
|
|
}
|
|
|
- return nil
|
|
|
+ }
|
|
|
+ custTypeByte, err := json.Marshal(cusType)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ proxyTime := req.ProxyStartTime.Time.Format("2006/01/02") + "-" +
|
|
|
+ req.ProxyEndTime.Time.Format("2006/01/02")
|
|
|
+
|
|
|
+ workflowSrv, err := workflowService.NewFlowService(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ form := []*workflow.StartProcessInstanceRequestFormComponentValues{
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField-K2AD4O5B"),
|
|
|
+ Name: utils.String("代理商名称"),
|
|
|
+ Value: utils.String(ent.DistName),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("DDSelectField_X3ALRAZA4BK0"),
|
|
|
+ Name: utils.String("授权客户类型"),
|
|
|
+ Value: utils.String(string(custTypeByte)),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_1M07EV7YVOPS0"),
|
|
|
+ Name: utils.String("授权代理区域"),
|
|
|
+ Value: utils.String(req.ProxyDistrict),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_UGJ0UKCU5DS0"),
|
|
|
+ Name: utils.String("代理签约有效期"),
|
|
|
+ Value: utils.String(proxyTime),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ if len(fileinfoByte) != 0 {
|
|
|
+ form = append(form, &workflow.StartProcessInstanceRequestFormComponentValues{
|
|
|
+ Id: utils.String("DDAttachment_SD6QFFBOSAO0"),
|
|
|
+ Name: utils.String("代理合同"),
|
|
|
+ Value: utils.String(string(fileinfoByte)),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ bizCode := strconv.Itoa(ent.Id)
|
|
|
+ _, err = workflowSrv.StartProcessInstance(bizCode, workflowmodel.DistToProxy, "", &workflow.StartProcessInstanceRequest{
|
|
|
+ ProcessCode: &ProcessCodeDistToProxy,
|
|
|
+ FormComponentValues: form,
|
|
|
})
|
|
|
- return txerr
|
|
|
+ return err
|
|
|
}
|
|
|
|
|
|
func (s *distributorService) Renew(ctx context.Context, req *model.DistributorRenewReq) (err error) {
|
|
|
@@ -275,6 +433,9 @@ func (s *distributorService) Renew(ctx context.Context, req *model.DistributorRe
|
|
|
if validErr != nil {
|
|
|
return myerrors.TipsError(validErr.Current().Error())
|
|
|
}
|
|
|
+ if req.ContractUrl != "" && req.ContractFileName == "" {
|
|
|
+ return myerrors.TipsError("合同文件名不能为空")
|
|
|
+ }
|
|
|
|
|
|
ent, err := s.Dao.Where("id = ?", req.Id).One()
|
|
|
if err != nil {
|
|
|
@@ -284,47 +445,102 @@ func (s *distributorService) Renew(ctx context.Context, req *model.DistributorRe
|
|
|
return myerrors.TipsError(fmt.Sprintf("代理商/经销商不存在: %d", req.Id))
|
|
|
}
|
|
|
|
|
|
- txerr := s.Dao.DB.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
|
|
|
+ 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{}{
|
|
|
- "customer_type": req.CustomerType,
|
|
|
- "proxy_start_time": req.ProxyStartTime,
|
|
|
- "proxy_end_time": req.ProxyEndTime,
|
|
|
- "proxy_district": req.ProxyDistrict,
|
|
|
- "contract_url": req.ContractUrl,
|
|
|
+ "appro_status": "20",
|
|
|
+ "appro_data": string(approvalDataByte),
|
|
|
+ "appro_item": "代理商续签",
|
|
|
}, "id = ?", req.Id)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- _, err = tx.Insert("base_distributor_record", model.BaseDistributorRecord{
|
|
|
- DistId: req.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(),
|
|
|
- })
|
|
|
+ return s.renewDingtalkProcess(ctx, ent, req)
|
|
|
+ })
|
|
|
+ return txerr
|
|
|
+}
|
|
|
+
|
|
|
+var ProcessCodeDistRenew = "PROC-33514974-4E38-430F-A852-D5694944F20B" // 代理商续签
|
|
|
+func (s *distributorService) renewDingtalkProcess(ctx context.Context, ent *model.BaseDistributor, req *model.DistributorRenewReq) error {
|
|
|
+ var fileinfoByte []byte
|
|
|
+ if req.ContractUrl != "" {
|
|
|
+ var err error
|
|
|
+ fileinfoByte, err = UploadDingtalk(s.CxtUser.DingtalkId, req.ContractUrl, req.ContractFileName)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- err = s.AddDynamicsByCurrentUser(tx, req.Id, "续签代理商", map[string]interface{}{})
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
+ }
|
|
|
+
|
|
|
+ cusTypeMap, err := service.GetDictDataByType(ctx, "cust_idy")
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ cusType := []string{}
|
|
|
+ for _, t := range strings.Split(req.CustomerType, ",") {
|
|
|
+ if v := cusTypeMap[t]; v != "" {
|
|
|
+ cusType = append(cusType, v)
|
|
|
}
|
|
|
- return nil
|
|
|
+ }
|
|
|
+ custTypeByte, err := json.Marshal(cusType)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ proxyTime := req.ProxyStartTime.Time.Format("2006/01/02") + "-" +
|
|
|
+ req.ProxyEndTime.Time.Format("2006/01/02")
|
|
|
+
|
|
|
+ workflowSrv, err := workflowService.NewFlowService(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ form := []*workflow.StartProcessInstanceRequestFormComponentValues{
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField-K2AD4O5B"),
|
|
|
+ Name: utils.String("代理商名称"),
|
|
|
+ Value: utils.String(ent.DistName),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("DDSelectField_X3ALRAZA4BK0"),
|
|
|
+ Name: utils.String("授权客户类型"),
|
|
|
+ Value: utils.String(string(custTypeByte)),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_1M07EV7YVOPS0"),
|
|
|
+ Name: utils.String("授权代理区域"),
|
|
|
+ Value: utils.String(req.ProxyDistrict),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField_UGJ0UKCU5DS0"),
|
|
|
+ Name: utils.String("代理签约有效期"),
|
|
|
+ Value: utils.String(proxyTime),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ if len(fileinfoByte) != 0 {
|
|
|
+ form = append(form, &workflow.StartProcessInstanceRequestFormComponentValues{
|
|
|
+ Id: utils.String("DDAttachment_SD6QFFBOSAO0"),
|
|
|
+ Name: utils.String("代理合同"),
|
|
|
+ Value: utils.String(string(fileinfoByte)),
|
|
|
+ })
|
|
|
+ }
|
|
|
+ bizCode := strconv.Itoa(ent.Id)
|
|
|
+ _, err = workflowSrv.StartProcessInstance(bizCode, workflowmodel.DistProxyRenew, "", &workflow.StartProcessInstanceRequest{
|
|
|
+ ProcessCode: &ProcessCodeDistRenew,
|
|
|
+ FormComponentValues: form,
|
|
|
})
|
|
|
- return txerr
|
|
|
+ return err
|
|
|
}
|
|
|
|
|
|
func (s *distributorService) ToDist(ctx context.Context, req *model.DistributorToDistReq) (err error) {
|
|
|
@@ -341,45 +557,56 @@ func (s *distributorService) ToDist(ctx context.Context, req *model.DistributorT
|
|
|
return myerrors.TipsError(fmt.Sprintf("代理商/经销商不存在: %d", req.Id))
|
|
|
}
|
|
|
|
|
|
- txerr := s.Dao.DB.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
|
|
|
+ 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{}{
|
|
|
- "dist_type": "10",
|
|
|
+ "appro_status": "20",
|
|
|
+ "appro_data": string(approvalDataByte),
|
|
|
+ "appro_item": "代理商转经销商",
|
|
|
}, "id = ?", req.Id)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- _, err = tx.Insert("base_distributor_record", model.BaseDistributorRecord{
|
|
|
- DistId: req.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 = s.AddDynamicsByCurrentUser(tx, req.Id, "转为经销商", map[string]interface{}{})
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- return nil
|
|
|
+ return s.toDistDingtalkProcess(ctx, ent, req)
|
|
|
})
|
|
|
return txerr
|
|
|
}
|
|
|
|
|
|
+var ProcessCodeProxyToDist = "PROC-59A0E9F5-8233-41D5-B36D-021F3E8B48D2" // 代理商转经销商
|
|
|
+func (s *distributorService) toDistDingtalkProcess(ctx context.Context, ent *model.BaseDistributor, req *model.DistributorToDistReq) error {
|
|
|
+ workflowSrv, err := workflowService.NewFlowService(ctx)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ form := []*workflow.StartProcessInstanceRequestFormComponentValues{
|
|
|
+ {
|
|
|
+ Id: utils.String("TextField-K2AD4O5B"),
|
|
|
+ Name: utils.String("代理商名称"),
|
|
|
+ Value: utils.String(ent.DistName),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ Id: utils.String("TextareaField_5XMN9CGTDAS0"),
|
|
|
+ Name: utils.String("转移原因"),
|
|
|
+ Value: utils.String(req.ToDistReason),
|
|
|
+ },
|
|
|
+ }
|
|
|
+ bizCode := strconv.Itoa(ent.Id)
|
|
|
+ _, err = workflowSrv.StartProcessInstance(bizCode, workflowmodel.DistToDist, "", &workflow.StartProcessInstanceRequest{
|
|
|
+ ProcessCode: &ProcessCodeProxyToDist,
|
|
|
+ FormComponentValues: form,
|
|
|
+ })
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
func (s *distributorService) TransRecord(ctx context.Context, req *model.DistributorTransRecordReq) (int, []*model.BaseDistributorRecord, error) {
|
|
|
dao := s.RecordDao.As("a")
|
|
|
if req.DistId != 0 {
|
|
|
@@ -620,3 +847,402 @@ func (s distributorService) DynamicsList(ctx context.Context, req *model.Distrib
|
|
|
}
|
|
|
return total, ret, err
|
|
|
}
|
|
|
+
|
|
|
+func DownFile(url string) ([]byte, error) {
|
|
|
+ r, err := http.Get(url)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ if r.StatusCode != http.StatusOK {
|
|
|
+ return nil, fmt.Errorf("DownFile from %s StatusCode %d", url, r.StatusCode)
|
|
|
+ }
|
|
|
+ defer r.Body.Close()
|
|
|
+ return ioutil.ReadAll(r.Body)
|
|
|
+}
|
|
|
+
|
|
|
+// '审核状态 20 待审核 30 审核已同意 40 审核已拒绝 50 审核已撤销'
|
|
|
+func ApprovalProxyCreate(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())
|
|
|
+ }
|
|
|
+ distdao := base.NewBaseDistributorDao(tenant)
|
|
|
+
|
|
|
+ entId, err := strconv.Atoi(flow.BizCode)
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("创建代理商钉钉审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
|
|
|
+ }
|
|
|
+ ent, err := distdao.Where("id = ?", entId).One()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if ent == 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 = distdao.Where("id = ?", entId).Data(map[string]interface{}{
|
|
|
+ "appro_status": "50",
|
|
|
+ "appro_data": "",
|
|
|
+ }).Update()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ pass := msg.Result == "agree"
|
|
|
+ if !pass {
|
|
|
+ _, err = distdao.Where("id = ?", entId).Data(map[string]interface{}{
|
|
|
+ "appro_status": "40",
|
|
|
+ "appro_data": "",
|
|
|
+ }).Update()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ _, err = distdao.Where("id = ?", entId).Data(map[string]interface{}{
|
|
|
+ "appro_status": "30",
|
|
|
+ "appro_data": "",
|
|
|
+ }).Update()
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+func ApprovalDistToProxy(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())
|
|
|
+ }
|
|
|
+ distdao := base.NewBaseDistributorDao(tenant)
|
|
|
+
|
|
|
+ entId, err := strconv.Atoi(flow.BizCode)
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("经销商转代理商钉钉审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
|
|
|
+ }
|
|
|
+ ent, err := distdao.Where("id = ?", entId).One()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if ent == 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 = distdao.Where("id = ?", entId).Data(map[string]interface{}{
|
|
|
+ "appro_status": "50",
|
|
|
+ "appro_data": "",
|
|
|
+ }).Update()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ pass := msg.Result == "agree"
|
|
|
+ if !pass {
|
|
|
+ _, err = distdao.Where("id = ?", entId).Data(map[string]interface{}{
|
|
|
+ "appro_status": "40",
|
|
|
+ "appro_data": "",
|
|
|
+ }).Update()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ approData := model.ToProxyApproveData{}
|
|
|
+ err = json.Unmarshal([]byte(ent.ApproData), &approData)
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("经销商转代理商钉钉审批 ApproData 解析异常:%s Id: %d ApproData:%s", flow.BizCode, flow.Id, ent.ApproData)
|
|
|
+ }
|
|
|
+
|
|
|
+ txerr := distdao.DB.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
|
|
|
+ _, err = tx.Update("base_distributor", map[string]interface{}{
|
|
|
+ "dist_type": "20",
|
|
|
+ "appro_status": "30",
|
|
|
+ "appro_data": "",
|
|
|
+ "customer_type": approData.CustomerType,
|
|
|
+ "proxy_start_time": approData.ProxyStartTime,
|
|
|
+ "proxy_end_time": approData.ProxyEndTime,
|
|
|
+ "proxy_district": approData.ProxyDistrict,
|
|
|
+ "contract_url": approData.ContractUrl,
|
|
|
+ }, "id = ?", ent.Id)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ _, err = tx.Insert("base_distributor_record", model.BaseDistributorRecord{
|
|
|
+ DistId: ent.Id,
|
|
|
+ DistType: "20",
|
|
|
+ BusinessScope: ent.BusinessScope,
|
|
|
+ CustomerType: approData.CustomerType,
|
|
|
+ ProxyDistrict: approData.ProxyDistrict,
|
|
|
+ ProxyStartTime: approData.ProxyStartTime,
|
|
|
+ ProxyEndTime: approData.ProxyEndTime,
|
|
|
+ ContractUrl: approData.ContractUrl,
|
|
|
+ ExistedProduct: ent.ExistedProduct,
|
|
|
+ HistoryCustomer: ent.HistoryCustomer,
|
|
|
+ ToDistReason: "",
|
|
|
+ Remark: "",
|
|
|
+ CreatedBy: approData.OperatedId,
|
|
|
+ CreatedName: approData.OperatedName,
|
|
|
+ CreatedTime: gtime.Now(),
|
|
|
+ UpdatedBy: approData.OperatedId,
|
|
|
+ UpdatedName: approData.OperatedName,
|
|
|
+ UpdatedTime: gtime.Now(),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ err = addDynamicsByCurrentUser(tx, ent.Id, "转为代理商",
|
|
|
+ approData, approData.OperatedId, approData.OperatedName)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ })
|
|
|
+ return txerr
|
|
|
+}
|
|
|
+
|
|
|
+func ApprovalDistRenew(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())
|
|
|
+ }
|
|
|
+ distdao := base.NewBaseDistributorDao(tenant)
|
|
|
+
|
|
|
+ entId, err := strconv.Atoi(flow.BizCode)
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("代理商续签钉钉审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
|
|
|
+ }
|
|
|
+ ent, err := distdao.Where("id = ?", entId).One()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if ent == 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 = distdao.Where("id = ?", entId).Data(map[string]interface{}{
|
|
|
+ "appro_status": "50",
|
|
|
+ "appro_data": "",
|
|
|
+ }).Update()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ pass := msg.Result == "agree"
|
|
|
+ if !pass {
|
|
|
+ _, err = distdao.Where("id = ?", entId).Data(map[string]interface{}{
|
|
|
+ "appro_status": "40",
|
|
|
+ "appro_data": "",
|
|
|
+ }).Update()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ approData := model.RenewApproveData{}
|
|
|
+ err = json.Unmarshal([]byte(ent.ApproData), &approData)
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("代理商续签钉钉审批 ApproData 解析异常:%s Id: %d ApproData:%s", flow.BizCode, flow.Id, ent.ApproData)
|
|
|
+ }
|
|
|
+
|
|
|
+ txerr := distdao.DB.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
|
|
|
+ _, err = tx.Update("base_distributor", map[string]interface{}{
|
|
|
+ "appro_status": "30",
|
|
|
+ "appro_data": "",
|
|
|
+ "customer_type": approData.CustomerType,
|
|
|
+ "proxy_start_time": approData.ProxyStartTime,
|
|
|
+ "proxy_end_time": approData.ProxyEndTime,
|
|
|
+ "proxy_district": approData.ProxyDistrict,
|
|
|
+ "contract_url": approData.ContractUrl,
|
|
|
+ }, "id = ?", ent.Id)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ _, err = tx.Insert("base_distributor_record", model.BaseDistributorRecord{
|
|
|
+ DistId: ent.Id,
|
|
|
+ DistType: "20",
|
|
|
+ BusinessScope: ent.BusinessScope,
|
|
|
+ CustomerType: approData.CustomerType,
|
|
|
+ ProxyDistrict: approData.ProxyDistrict,
|
|
|
+ ProxyStartTime: approData.ProxyStartTime,
|
|
|
+ ProxyEndTime: approData.ProxyEndTime,
|
|
|
+ ContractUrl: approData.ContractUrl,
|
|
|
+ ExistedProduct: ent.ExistedProduct,
|
|
|
+ HistoryCustomer: ent.HistoryCustomer,
|
|
|
+ ToDistReason: "",
|
|
|
+ Remark: "",
|
|
|
+ CreatedBy: approData.OperatedId,
|
|
|
+ CreatedName: approData.OperatedName,
|
|
|
+ CreatedTime: gtime.Now(),
|
|
|
+ UpdatedBy: approData.OperatedId,
|
|
|
+ UpdatedName: approData.OperatedName,
|
|
|
+ UpdatedTime: gtime.Now(),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ err = addDynamicsByCurrentUser(tx, ent.Id, "续签代理商",
|
|
|
+ approData, approData.OperatedId, approData.OperatedName)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ })
|
|
|
+ return txerr
|
|
|
+}
|
|
|
+
|
|
|
+func ApprovalDistToDist(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())
|
|
|
+ }
|
|
|
+ distdao := base.NewBaseDistributorDao(tenant)
|
|
|
+
|
|
|
+ entId, err := strconv.Atoi(flow.BizCode)
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("代理商转经销商钉钉审批 bizCode 不合法:%s Id: %d", flow.BizCode, flow.Id)
|
|
|
+ }
|
|
|
+ ent, err := distdao.Where("id = ?", entId).One()
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ if ent == 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 = distdao.Where("id = ?", entId).Data(map[string]interface{}{
|
|
|
+ "appro_status": "50",
|
|
|
+ "appro_data": "",
|
|
|
+ }).Update()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ pass := msg.Result == "agree"
|
|
|
+ if !pass {
|
|
|
+ _, err = distdao.Where("id = ?", entId).Data(map[string]interface{}{
|
|
|
+ "appro_status": "40",
|
|
|
+ "appro_data": "",
|
|
|
+ }).Update()
|
|
|
+ return err
|
|
|
+ }
|
|
|
+
|
|
|
+ approData := model.ToDistApproveData{}
|
|
|
+ err = json.Unmarshal([]byte(ent.ApproData), &approData)
|
|
|
+ if err != nil {
|
|
|
+ return fmt.Errorf("代理商转经销商钉钉审批 ApproData 解析异常:%s Id: %d ApproData:%s", flow.BizCode, flow.Id, ent.ApproData)
|
|
|
+ }
|
|
|
+
|
|
|
+ txerr := distdao.DB.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
|
|
|
+ _, err = tx.Update("base_distributor", map[string]interface{}{
|
|
|
+ "dist_type": "10",
|
|
|
+ "appro_status": "30",
|
|
|
+ "appro_data": "",
|
|
|
+ }, "id = ?", ent.Id)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ _, 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: approData.ToDistReason,
|
|
|
+ Remark: "",
|
|
|
+ CreatedBy: approData.OperatedId,
|
|
|
+ CreatedName: approData.OperatedName,
|
|
|
+ CreatedTime: gtime.Now(),
|
|
|
+ UpdatedBy: approData.OperatedId,
|
|
|
+ UpdatedName: approData.OperatedName,
|
|
|
+ UpdatedTime: gtime.Now(),
|
|
|
+ })
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ err = addDynamicsByCurrentUser(tx, ent.Id, "转为经销商",
|
|
|
+ approData, approData.OperatedId, approData.OperatedName)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+ })
|
|
|
+ return txerr
|
|
|
+}
|
|
|
+
|
|
|
+func addDynamicsByCurrentUser(tx *gdb.TX, distId int, opnType string, content interface{}, operatedId int, opreatedName string) error {
|
|
|
+ contentByte, err := json.Marshal(content)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ _, err = tx.InsertAndGetId("base_distributor_dynamics", model.BaseDistributorDynamics{
|
|
|
+ DistId: distId,
|
|
|
+ OpnPeopleId: operatedId,
|
|
|
+ OpnPeople: opreatedName,
|
|
|
+ OpnDate: gtime.Now(),
|
|
|
+ OpnType: opnType,
|
|
|
+ OpnContent: string(contentByte),
|
|
|
+ Remark: "",
|
|
|
+ CreatedBy: operatedId,
|
|
|
+ CreatedName: opreatedName,
|
|
|
+ CreatedTime: gtime.Now(),
|
|
|
+ UpdatedBy: operatedId,
|
|
|
+ UpdatedName: opreatedName,
|
|
|
+ UpdatedTime: gtime.Now(),
|
|
|
+ })
|
|
|
+ return err
|
|
|
+}
|
|
|
+
|
|
|
+func UploadDingtalk(uid, url, name string) ([]byte, error) {
|
|
|
+ if uid == "" {
|
|
|
+ return nil, fmt.Errorf("该用户钉钉 uid 为空")
|
|
|
+ }
|
|
|
+ filedata, err := DownFile(url)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ filepath := path.Join(os.TempDir(), name)
|
|
|
+ err = ioutil.WriteFile(filepath, filedata, 0644)
|
|
|
+ if err != nil {
|
|
|
+ return nil, fmt.Errorf("WriteFile %s %s", filepath, err)
|
|
|
+ }
|
|
|
+ defer os.Remove(filepath)
|
|
|
+
|
|
|
+ resp, err := dingtalk.Client.GetStorage().UploadFile(service.DingTalkSpaceId, uid, name, filepath)
|
|
|
+ if err != nil {
|
|
|
+ return nil, fmt.Errorf("钉钉上传文件异常 %s", err.Error())
|
|
|
+ }
|
|
|
+ file := []contractmodel.DingFileInfo{
|
|
|
+ {
|
|
|
+ SpaceId: resp.Dentry.SpaceId,
|
|
|
+ FileId: resp.Dentry.Id,
|
|
|
+ FileName: resp.Dentry.Name,
|
|
|
+ FileSize: resp.Dentry.Size,
|
|
|
+ FileType: resp.Dentry.Extension,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ return json.Marshal(file)
|
|
|
+}
|