|
|
@@ -5,7 +5,6 @@ import (
|
|
|
"database/sql"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
- "github.com/gogf/gf/container/garray"
|
|
|
"io/ioutil"
|
|
|
"net/http"
|
|
|
"os"
|
|
|
@@ -14,11 +13,15 @@ import (
|
|
|
"strings"
|
|
|
"time"
|
|
|
|
|
|
+ "github.com/gogf/gf/container/garray"
|
|
|
+
|
|
|
"dashoo.cn/opms_libary/micro_srv"
|
|
|
"dashoo.cn/opms_libary/myerrors"
|
|
|
"dashoo.cn/opms_libary/plugin/dingtalk"
|
|
|
"github.com/gogf/gf/database/gdb"
|
|
|
"github.com/gogf/gf/frame/g"
|
|
|
+ "github.com/gogf/gf/os/gcron"
|
|
|
+ "github.com/gogf/gf/os/glog"
|
|
|
"github.com/gogf/gf/os/gtime"
|
|
|
"github.com/gogf/gf/util/gconv"
|
|
|
"github.com/gogf/gf/util/gvalid"
|
|
|
@@ -165,6 +168,12 @@ func (s *distributorService) Create(ctx context.Context, req *model.AddDistribut
|
|
|
if req.RegisterDistrict == "" {
|
|
|
return 0, myerrors.TipsError("注册地不能为空")
|
|
|
}
|
|
|
+ if req.BelongSaleId == 0 {
|
|
|
+ return 0, myerrors.TipsError("归属销售ID不能为空")
|
|
|
+ }
|
|
|
+ if req.BelongSale == "" {
|
|
|
+ return 0, myerrors.TipsError("归属销售不能为空")
|
|
|
+ }
|
|
|
} else {
|
|
|
if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
|
|
|
return 0, err
|
|
|
@@ -204,7 +213,24 @@ func (s *distributorService) Create(ctx context.Context, req *model.AddDistribut
|
|
|
err = s.AddDynamicsByCurrentUser(tx, int(id), "创建经销商/代理商", map[string]interface{}{})
|
|
|
return err
|
|
|
})
|
|
|
- return id, txerr
|
|
|
+ if txerr != nil {
|
|
|
+ return 0, txerr
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.ProvinceId == 0 || req.BelongSaleId == 0 || req.Capital == 0 || req.RegisterDistrict == "" || req.BusinessScope == "" || req.SaleNum == 0 || req.CustomerType == "" || req.ExistedProduct == "" || req.HistoryCustomer == "" {
|
|
|
+ msg := g.MapStrStr{
|
|
|
+ "msgTitle": "经销商信息完善提醒",
|
|
|
+ "msgContent": fmt.Sprintf("<p>经销商:%s 的必要信息未填写完整,请及时完善</p>", req.DistName),
|
|
|
+ "msgType": "20",
|
|
|
+ "recvUserIds": strconv.Itoa(req.BelongSaleId),
|
|
|
+ "msgStatus": "10",
|
|
|
+ "sendType": "10",
|
|
|
+ }
|
|
|
+ if err := service.CreateSystemMessage(msg); err != nil {
|
|
|
+ g.Log().Error("经销商信息完善提醒异常:", err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return id, nil
|
|
|
}
|
|
|
|
|
|
var ProcessCodeDistProxyCreate = "PROC-9494B87D-DE96-49EE-B676-D3913911BE21" // 创建代理商
|
|
|
@@ -1268,3 +1294,44 @@ func UploadDingtalk(uid, url, name string) ([]byte, error) {
|
|
|
}
|
|
|
return json.Marshal(file)
|
|
|
}
|
|
|
+
|
|
|
+func init() {
|
|
|
+ c := gcron.New()
|
|
|
+ // 每天凌晨2点执行
|
|
|
+ c.Add("0 0 2 * * *", notifyToComplete)
|
|
|
+}
|
|
|
+
|
|
|
+func notifyToComplete() {
|
|
|
+ defer func() {
|
|
|
+ if r := recover(); r != nil {
|
|
|
+ glog.Errorf("完善经销商定时提醒异常 %v", r)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ tenant := g.Config().GetString("micro_srv.tenant")
|
|
|
+ if tenant == "" {
|
|
|
+ glog.Error("定时任务租户码未设置,请前往配置")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ dao := base.NewBaseDistributorDao(tenant)
|
|
|
+ created := gtime.Now().Add(-time.Hour * 24 * 30)
|
|
|
+ dist, err := dao.Where("province_id = 0 or belong_sale_id = 0 or capital = 0 or register_district = '' or business_scope = '' or sale_num = 0 or customer_type = '' or existed_product = '' or history_customer = ''").Where("created_time < ?", created).Where("dist_type = 10").All()
|
|
|
+ if err != nil {
|
|
|
+ glog.Errorf("完善经销商定时提醒异常 %s", err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, d := range dist {
|
|
|
+ msg := g.MapStrStr{
|
|
|
+ "msgTitle": "经销商信息完善提醒",
|
|
|
+ "msgContent": fmt.Sprintf("<p>经销商:%s 的必要信息未填写完整,请及时完善</p>", d.DistName),
|
|
|
+ "msgType": "20",
|
|
|
+ "recvUserIds": strconv.Itoa(d.BelongSaleId),
|
|
|
+ "msgStatus": "10",
|
|
|
+ "sendType": "10",
|
|
|
+ }
|
|
|
+ if err := service.CreateSystemMessage(msg); err != nil {
|
|
|
+ g.Log().Error("经销商信息完善提醒异常:%s", err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|