Jelajahi Sumber

Merge remote-tracking branch 'origin/develop' into develop

ZZH-wl 2 tahun lalu
induk
melakukan
172d5ce368

+ 69 - 2
opms_parent/app/service/base/base_distributor.go

@@ -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)
+		}
+	}
+}

+ 4 - 2
opms_parent/app/service/base/base_distributor_test.go

@@ -10,7 +10,6 @@ import (
 	"github.com/smallnest/rpcx/share"
 )
 
-
 var testTenant = "default"
 
 func fakeCtx(parent context.Context, tenant string) context.Context {
@@ -20,7 +19,6 @@ func fakeCtx(parent context.Context, tenant string) context.Context {
 	return ctx
 }
 
-
 func TestApprovalProxyCreate(t *testing.T) {
 	ctx := fakeCtx(context.Background(), testTenant)
 
@@ -39,3 +37,7 @@ func TestApprovalProxyCreate(t *testing.T) {
 		panic(err)
 	}
 }
+
+func TestNotifyToComplete(t *testing.T) {
+	notifyToComplete()
+}

+ 1 - 1
opms_parent/app/service/base/base_product.go

@@ -131,7 +131,7 @@ func (s *productService) DeleteByIds(ids []int64) (err error) {
 		rows, err := result.RowsAffected()
 		if err == nil {
 			if len(ids) != int(rows) {
-				return myerrors.TipsError(fmt.Sprintf("应更新%s行,实际更新%s行", len(ids), int(rows)))
+				return myerrors.TipsError(fmt.Sprintf("应更新%d行,实际更新%d行", len(ids), int(rows)))
 
 			}
 		}

+ 13 - 8
opms_parent/app/service/plat/plat_task_cron.go

@@ -69,6 +69,10 @@ func (c taskCron) Run() {
 	now := gtime.Now()
 	// 生成提醒数据
 	for _, task := range tasks {
+		TaskTitle := task.TaskTitle + "(须接受督办)"
+		if task.IsOverdue == "20" {
+			TaskTitle = task.TaskTitle + "(超期)"
+		}
 		// 固定日期提醒
 		if task.ReminderRule != "" {
 			rules := strings.Split(task.ReminderRule, " ")
@@ -79,8 +83,9 @@ func (c taskCron) Run() {
 					// 校验当前时间
 					remindTime := gtime.NewFromStr(fmt.Sprintf("%v %v:%v:%v", now.Format("Y-m-d"), rules[2], rules[1], rules[0]))
 					// 10分钟一次定时循环,两者相差在10分钟之内(纳秒转换1e9)
-					if (now.Nanosecond() - remindTime.Nanosecond())/(1*60*1e9) <= 10 && now.Nanosecond() > remindTime.Nanosecond() {
-						taskNotifyMessage(task.MainUserId, task.OwnerUserId, task.TaskTitle+"督办需要处理,请前往执行")
+					if (now.Nanosecond()-remindTime.Nanosecond())/(1*60*1e9) <= 10 && now.Nanosecond() > remindTime.Nanosecond() {
+
+						taskNotifyMessage(task.MainUserId, task.OwnerUserId, TaskTitle+"督办需要处理,请前往执行")
 					}
 				} else if rules[3] == "?" { // 每周提醒
 					// 校验周选项是否匹配
@@ -96,8 +101,8 @@ func (c taskCron) Run() {
 						// 校验当前时间
 						remindTime := gtime.NewFromStr(fmt.Sprintf("%v %v:%v:%v", now.Format("Y-m-d"), rules[2], rules[1], rules[0]))
 						// 10分钟一次定时循环,两者相差在10分钟之内(纳秒转换1e9)
-						if (now.Nanosecond() - remindTime.Nanosecond())/(1*60*1e9) <= 10 && now.Nanosecond() > remindTime.Nanosecond() {
-							taskNotifyMessage(task.MainUserId, task.OwnerUserId, task.TaskTitle+"督办需要处理,请前往执行")
+						if (now.Nanosecond()-remindTime.Nanosecond())/(1*60*1e9) <= 10 && now.Nanosecond() > remindTime.Nanosecond() {
+							taskNotifyMessage(task.MainUserId, task.OwnerUserId, TaskTitle+"督办需要处理,请前往执行")
 						}
 					}
 				} else { // 每月提醒
@@ -113,8 +118,8 @@ func (c taskCron) Run() {
 						// 校验当前时间
 						remindTime := gtime.NewFromStr(fmt.Sprintf("%v %v:%v:%v", now.Format("Y-m-d"), rules[2], rules[1], rules[0]))
 						// 10分钟一次定时循环,两者相差在10分钟之内(纳秒转换1e9)
-						if (now.Nanosecond() - remindTime.Nanosecond())/(1*60*1e9) <= 10 && now.Nanosecond() > remindTime.Nanosecond() {
-							taskNotifyMessage(task.MainUserId, task.OwnerUserId, task.TaskTitle+"督办需要处理,请前往执行")
+						if (now.Nanosecond()-remindTime.Nanosecond())/(1*60*1e9) <= 10 && now.Nanosecond() > remindTime.Nanosecond() {
+							taskNotifyMessage(task.MainUserId, task.OwnerUserId, TaskTitle+"督办需要处理,请前往执行")
 						}
 					}
 				}
@@ -127,7 +132,7 @@ func (c taskCron) Run() {
 			if beforeDate.After(now) {
 				// 10分钟一次定时循环,两者相差在10分钟之内(纳秒转换1e9)
 				if (beforeDate.UnixNano()-now.UnixNano())/(1*60*1e9) <= 10 {
-					taskNotifyMessage(task.MainUserId, task.OwnerUserId, task.TaskTitle+"督办即将超期,请前往执行")
+					taskNotifyMessage(task.MainUserId, task.OwnerUserId, TaskTitle+"督办即将超期,请前往执行")
 				}
 			}
 			// 超期后提醒
@@ -135,7 +140,7 @@ func (c taskCron) Run() {
 			if now.After(afterDate) {
 				// 10分钟一次定时循环,两者相差在10分钟之内(纳秒转换1e9)
 				if (now.UnixNano()-afterDate.UnixNano())/(1*60*1e9) <= 10 {
-					taskNotifyMessage(task.MainUserId, task.OwnerUserId, task.TaskTitle+"督办已超期,请确认")
+					taskNotifyMessage(task.MainUserId, task.OwnerUserId, TaskTitle+"督办已超期,请确认")
 				}
 			}
 		}

+ 63 - 1
opms_parent/script/main.go

@@ -33,7 +33,69 @@ func main() {
 	// fmt.Println(Usermap)
 	// fmt.Println(MapProvince)
 	// distContact()
-	projectRelate()
+	// projectRelate()
+	// updateclloect()
+	// updateContractIncharge()
+}
+
+func updateContractIncharge() {
+	prepareuser()
+	contractdao := contractdao.NewCtrContractDao("prod")
+	contract, err := contractdao.All()
+	if err != nil {
+		panic(err)
+	}
+	txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
+		for _, c := range contract {
+			if c.InchargeId != 0 {
+				continue
+			}
+			if Usermap[c.InchargeName].Id == 0 {
+				panic(c.InchargeName + ":seller")
+			}
+			_, err = tx.Update("ctr_contract",
+				map[string]interface{}{
+					"incharge_id": Usermap[c.InchargeName].Id,
+				}, "id = ?", c.Id)
+			if err != nil {
+				return err
+			}
+		}
+		// return fmt.Errorf("测试")
+		return nil
+	})
+	if txerr != nil {
+		panic(txerr)
+	}
+}
+
+func updateclloect() {
+	contractdao := contractdao.NewCtrContractDao("prod")
+	contract, err := contractdao.All()
+	if err != nil {
+		panic(err)
+	}
+	txerr := g.DB("prod").Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
+		for _, c := range contract {
+			v, err := tx.GetValue("select sum(collection_amount) from ctr_contract_collection where contract_id=? and appro_status='20' and deleted_time is null", c.Id)
+			if err != nil {
+				return err
+			}
+			amount := v.Float64()
+			_, err = tx.Update("ctr_contract",
+				map[string]interface{}{
+					"collected_amount": amount,
+				}, "id = ?", c.Id)
+			if err != nil {
+				return err
+			}
+		}
+		// return fmt.Errorf("测试")
+		return nil
+	})
+	if txerr != nil {
+		panic(txerr)
+	}
 }
 
 func projectRelate() {