Browse Source

feature:经销商代理商

liuyaqi 2 years ago
parent
commit
db5e6750f4
26 changed files with 4454 additions and 200 deletions
  1. 36 0
      opms_parent/app/dao/base/base_distributor_dynamics.go
  2. 36 0
      opms_parent/app/dao/base/base_distributor_record.go
  3. 36 0
      opms_parent/app/dao/base/base_distributor_target.go
  4. 208 102
      opms_parent/app/dao/base/internal/base_distributor.go
  5. 111 31
      opms_parent/app/dao/base/internal/base_distributor_contact.go
  6. 830 0
      opms_parent/app/dao/base/internal/base_distributor_dynamics.go
  7. 845 0
      opms_parent/app/dao/base/internal/base_distributor_record.go
  8. 833 0
      opms_parent/app/dao/base/internal/base_distributor_target.go
  9. 127 2
      opms_parent/app/handler/base/distributor.go
  10. 76 0
      opms_parent/app/handler/base/distributor_contact.go
  11. 73 0
      opms_parent/app/handler/base/distributor_target.go
  12. 98 36
      opms_parent/app/model/base/base_distributor.go
  13. 35 0
      opms_parent/app/model/base/base_distributor_contact.go
  14. 14 0
      opms_parent/app/model/base/base_distributor_dynamics.go
  15. 14 0
      opms_parent/app/model/base/base_distributor_record.go
  16. 52 0
      opms_parent/app/model/base/base_distributor_target.go
  17. 34 23
      opms_parent/app/model/base/internal/base_distributor.go
  18. 2 0
      opms_parent/app/model/base/internal/base_distributor_contact.go
  19. 28 0
      opms_parent/app/model/base/internal/base_distributor_dynamics.go
  20. 33 0
      opms_parent/app/model/base/internal/base_distributor_record.go
  21. 29 0
      opms_parent/app/model/base/internal/base_distributor_target.go
  22. 2 2
      opms_parent/app/model/plat/plat_followup.go
  23. 498 4
      opms_parent/app/service/base/base_distributor.go
  24. 196 0
      opms_parent/app/service/base/base_distributor_contact.go
  25. 206 0
      opms_parent/app/service/base/base_distributor_target.go
  26. 2 0
      opms_parent/main.go

+ 36 - 0
opms_parent/app/dao/base/base_distributor_dynamics.go

@@ -0,0 +1,36 @@
+// ============================================================================
+// This is auto-generated by gf cli tool only once. Fill this file as you wish.
+// ============================================================================
+
+package base
+
+import (
+	"dashoo.cn/micro/app/dao/base/internal"
+)
+
+// baseDistributorDynamicsDao is the manager for logic model data accessing
+// and custom defined data operations functions management. You can define
+// methods on it to extend its functionality as you wish.
+type baseDistributorDynamicsDao struct {
+	internal.BaseDistributorDynamicsDao
+}
+
+var (
+	// BaseDistributorDynamics is globally public accessible object for table base_distributor_dynamics operations.
+	BaseDistributorDynamics = baseDistributorDynamicsDao{
+		internal.BaseDistributorDynamics,
+	}
+)
+
+type BaseDistributorDynamicsDao struct {
+	internal.BaseDistributorDynamicsDao
+}
+
+func NewBaseDistributorDynamicsDao(tenant string) *BaseDistributorDynamicsDao {
+	dao := internal.NewBaseDistributorDynamicsDao(tenant)
+	return &BaseDistributorDynamicsDao{
+		dao,
+	}
+}
+
+// Fill with you ideas below.

+ 36 - 0
opms_parent/app/dao/base/base_distributor_record.go

@@ -0,0 +1,36 @@
+// ============================================================================
+// This is auto-generated by gf cli tool only once. Fill this file as you wish.
+// ============================================================================
+
+package base
+
+import (
+	"dashoo.cn/micro/app/dao/base/internal"
+)
+
+// baseDistributorRecordDao is the manager for logic model data accessing
+// and custom defined data operations functions management. You can define
+// methods on it to extend its functionality as you wish.
+type baseDistributorRecordDao struct {
+	internal.BaseDistributorRecordDao
+}
+
+var (
+	// BaseDistributorRecord is globally public accessible object for table base_distributor_record operations.
+	BaseDistributorRecord = baseDistributorRecordDao{
+		internal.BaseDistributorRecord,
+	}
+)
+
+type BaseDistributorRecordDao struct {
+	internal.BaseDistributorRecordDao
+}
+
+func NewBaseDistributorRecordDao(tenant string) *BaseDistributorRecordDao {
+	dao := internal.NewBaseDistributorRecordDao(tenant)
+	return &BaseDistributorRecordDao{
+		dao,
+	}
+}
+
+// Fill with you ideas below.

+ 36 - 0
opms_parent/app/dao/base/base_distributor_target.go

@@ -0,0 +1,36 @@
+// ============================================================================
+// This is auto-generated by gf cli tool only once. Fill this file as you wish.
+// ============================================================================
+
+package base
+
+import (
+	"dashoo.cn/micro/app/dao/base/internal"
+)
+
+// baseDistributorTargetDao is the manager for logic model data accessing
+// and custom defined data operations functions management. You can define
+// methods on it to extend its functionality as you wish.
+type baseDistributorTargetDao struct {
+	internal.BaseDistributorTargetDao
+}
+
+var (
+	// BaseDistributorTarget is globally public accessible object for table base_distributor_target operations.
+	BaseDistributorTarget = baseDistributorTargetDao{
+		internal.BaseDistributorTarget,
+	}
+)
+
+type BaseDistributorTargetDao struct {
+	internal.BaseDistributorTargetDao
+}
+
+func NewBaseDistributorTargetDao(tenant string) *BaseDistributorTargetDao {
+	dao := internal.NewBaseDistributorTargetDao(tenant)
+	return &BaseDistributorTargetDao{
+		dao,
+	}
+}
+
+// Fill with you ideas below.

+ 208 - 102
opms_parent/app/dao/base/internal/base_distributor.go

@@ -7,13 +7,15 @@ package internal
 import (
 	"context"
 	"database/sql"
+	"fmt"
+	"strings"
+	"time"
+
 	"github.com/gogf/gf/container/garray"
 	"github.com/gogf/gf/database/gdb"
 	"github.com/gogf/gf/frame/g"
 	"github.com/gogf/gf/frame/gmvc"
 	"github.com/gogf/gf/util/gconv"
-	"strings"
-	"time"
 
 	model "dashoo.cn/micro/app/model/base"
 )
@@ -29,29 +31,40 @@ type BaseDistributorDao struct {
 
 // BaseDistributorColumns defines and stores column names for table base_distributor.
 type baseDistributorColumns struct {
-	Id            string // 主键
-	DistCode      string // 经销商编码
-	DistName      string // 经销商名称
-	AbbrName      string // 助记名
-	DistDesc      string // 经销商说明
-	DistBoss      string // 负责人
-	DistBossPhone string // 负责人电话
-	ProvinceId    string // 所属省份ID
-	ProvinceDesc  string // 所属省份
-	BusinessScope string // 业务范围
-	BelongSaleId  string // 归属销售ID
-	BelongSale    string // 归属销售
-	Capital       string // 注册资金
-	SaleNum       string // 销售人数
-	InvoiceHeader string // 开票抬头
-	Remark        string // 备注
-	CreatedBy     string // 创建者
-	CreatedName   string // 创建人
-	CreatedTime   string // 创建时间
-	UpdatedBy     string // 更新者
-	UpdatedName   string // 更新人
-	UpdatedTime   string // 更新时间
-	DeletedTime   string // 删除时间
+	Id               string // 主键
+	DistCode         string // 经销商编码
+	DistName         string // 经销商名称
+	AbbrName         string // 助记名
+	DistDesc         string // 经销商说明
+	DistBoss         string // 负责人
+	DistBossPhone    string // 负责人电话
+	ProvinceId       string // 所属省份ID
+	ProvinceDesc     string // 所属省份
+	BusinessScope    string // 业务范围
+	BelongSaleId     string // 归属销售ID
+	BelongSale       string // 归属销售
+	Capital          string // 注册资金
+	SaleNum          string // 销售人数
+	InvoiceHeader    string // 开票抬头
+	DistType         string // 经销商类型 10 经销商 20 代理商
+	CustomerType     string // 授权客户类型
+	ExistedProduct   string // 已有代理品牌和产品
+	AssistantSaleId  string // 助理人员Id
+	AssistantSale    string // 助理人员
+	RegisterDistrict string // 注册地
+	HistoryCustomer  string // 历史合作的终端客户名称
+	ProxyStartTime   string // 代理签约有效期开始(代理商)
+	ProxyEndTime     string // 代理签约有效期结束(代理商)
+	ProxyDistrict    string // 授权代理区域(代理商)
+	ContractUrl      string // 代理合同(代理商)
+	Remark           string // 备注
+	CreatedBy        string // 创建者
+	CreatedName      string // 创建人
+	CreatedTime      string // 创建时间
+	UpdatedBy        string // 更新者
+	UpdatedName      string // 更新人
+	UpdatedTime      string // 更新时间
+	DeletedTime      string // 删除时间
 }
 
 var (
@@ -61,29 +74,40 @@ var (
 		DB:    g.DB("default"),
 		Table: "base_distributor",
 		C: baseDistributorColumns{
-			Id:            "id",
-			DistCode:      "dist_code",
-			DistName:      "dist_name",
-			AbbrName:      "abbr_name",
-			DistDesc:      "dist_desc",
-			DistBoss:      "dist_boss",
-			DistBossPhone: "dist_boss_phone",
-			ProvinceId:    "province_id",
-			ProvinceDesc:  "province_desc",
-			BusinessScope: "business_scope",
-			BelongSaleId:  "belong_sale_id",
-			BelongSale:    "belong_sale",
-			Capital:       "capital",
-			SaleNum:       "sale_num",
-			InvoiceHeader: "invoice_header",
-			Remark:        "remark",
-			CreatedBy:     "created_by",
-			CreatedName:   "created_name",
-			CreatedTime:   "created_time",
-			UpdatedBy:     "updated_by",
-			UpdatedName:   "updated_name",
-			UpdatedTime:   "updated_time",
-			DeletedTime:   "deleted_time",
+			Id:               "id",
+			DistCode:         "dist_code",
+			DistName:         "dist_name",
+			AbbrName:         "abbr_name",
+			DistDesc:         "dist_desc",
+			DistBoss:         "dist_boss",
+			DistBossPhone:    "dist_boss_phone",
+			ProvinceId:       "province_id",
+			ProvinceDesc:     "province_desc",
+			BusinessScope:    "business_scope",
+			BelongSaleId:     "belong_sale_id",
+			BelongSale:       "belong_sale",
+			Capital:          "capital",
+			SaleNum:          "sale_num",
+			InvoiceHeader:    "invoice_header",
+			DistType:         "dist_type",
+			CustomerType:     "customer_type",
+			ExistedProduct:   "existed_product",
+			AssistantSaleId:  "assistant_sale_id",
+			AssistantSale:    "assistant_sale",
+			RegisterDistrict: "register_district",
+			HistoryCustomer:  "history_customer",
+			ProxyStartTime:   "proxy_start_time",
+			ProxyEndTime:     "proxy_end_time",
+			ProxyDistrict:    "proxy_district",
+			ContractUrl:      "contract_url",
+			Remark:           "remark",
+			CreatedBy:        "created_by",
+			CreatedName:      "created_name",
+			CreatedTime:      "created_time",
+			UpdatedBy:        "updated_by",
+			UpdatedName:      "updated_name",
+			UpdatedTime:      "updated_time",
+			DeletedTime:      "deleted_time",
 		},
 	}
 )
@@ -95,29 +119,40 @@ func NewBaseDistributorDao(tenant string) BaseDistributorDao {
 		DB:    g.DB(tenant),
 		Table: "base_distributor",
 		C: baseDistributorColumns{
-			Id:            "id",
-			DistCode:      "dist_code",
-			DistName:      "dist_name",
-			AbbrName:      "abbr_name",
-			DistDesc:      "dist_desc",
-			DistBoss:      "dist_boss",
-			DistBossPhone: "dist_boss_phone",
-			ProvinceId:    "province_id",
-			ProvinceDesc:  "province_desc",
-			BusinessScope: "business_scope",
-			BelongSaleId:  "belong_sale_id",
-			BelongSale:    "belong_sale",
-			Capital:       "capital",
-			SaleNum:       "sale_num",
-			InvoiceHeader: "invoice_header",
-			Remark:        "remark",
-			CreatedBy:     "created_by",
-			CreatedName:   "created_name",
-			CreatedTime:   "created_time",
-			UpdatedBy:     "updated_by",
-			UpdatedName:   "updated_name",
-			UpdatedTime:   "updated_time",
-			DeletedTime:   "deleted_time",
+			Id:               "id",
+			DistCode:         "dist_code",
+			DistName:         "dist_name",
+			AbbrName:         "abbr_name",
+			DistDesc:         "dist_desc",
+			DistBoss:         "dist_boss",
+			DistBossPhone:    "dist_boss_phone",
+			ProvinceId:       "province_id",
+			ProvinceDesc:     "province_desc",
+			BusinessScope:    "business_scope",
+			BelongSaleId:     "belong_sale_id",
+			BelongSale:       "belong_sale",
+			Capital:          "capital",
+			SaleNum:          "sale_num",
+			InvoiceHeader:    "invoice_header",
+			DistType:         "dist_type",
+			CustomerType:     "customer_type",
+			ExistedProduct:   "existed_product",
+			AssistantSaleId:  "assistant_sale_id",
+			AssistantSale:    "assistant_sale",
+			RegisterDistrict: "register_district",
+			HistoryCustomer:  "history_customer",
+			ProxyStartTime:   "proxy_start_time",
+			ProxyEndTime:     "proxy_end_time",
+			ProxyDistrict:    "proxy_district",
+			ContractUrl:      "contract_url",
+			Remark:           "remark",
+			CreatedBy:        "created_by",
+			CreatedName:      "created_name",
+			CreatedTime:      "created_time",
+			UpdatedBy:        "updated_by",
+			UpdatedName:      "updated_name",
+			UpdatedTime:      "updated_time",
+			DeletedTime:      "deleted_time",
 		},
 	}
 	return dao
@@ -718,28 +753,10 @@ func (d *BaseDistributorDao) Unscoped() *BaseDistributorDao {
 }
 
 // DataScope enables the DataScope feature.
-func (d *BaseDistributorDao) DataScope(ctx context.Context, userCol ...string) *BaseDistributorDao {
+func (d *BaseDistributorDao) DataScope(ctx context.Context, args ...interface{}) *BaseDistributorDao {
 	cs := ctx.Value("contextService")
 	dataScope := gconv.Map(gconv.String(gconv.Map(cs)["dataScope"]))
 	if dataScope != nil {
-		tableAs := d.TableAs
-		if d.TableAs != "" {
-			tableAs += "."
-		}
-		userIds, ok := dataScope["userIds"]
-		delete(dataScope, "userIds")
-		var orColumns []string
-		var orValues []interface{}
-		if ok && userIds != "-1" {
-			column := "created_by"
-			if len(userCol) == 1 {
-				column = userCol[0]
-			}
-			if ok, _ := d.M.HasField(column); ok {
-				orColumns = append(orColumns, tableAs+column+" IN (?) ")
-				orValues = append(orValues, userIds)
-			}
-		}
 		// 销售工程师判断
 		var salesEngineerFlag bool
 		if roles, ok := dataScope["roles"]; ok {
@@ -748,22 +765,34 @@ func (d *BaseDistributorDao) DataScope(ctx context.Context, userCol ...string) *
 				salesEngineerFlag = true
 			}
 		}
-		// 非销售工程师权限加成
-		if !salesEngineerFlag {
-			bigColumns := "is_big"
-			if ok, _ := d.M.HasField("is_big"); ok {
-				if val, ok := dataScope[bigColumns]; ok && val != "" {
-					orColumns = append(orColumns, tableAs+bigColumns+" = ? ")
-					orValues = append(orValues, val)
+		userIds, ok := dataScope["userIds"]
+		specialFlag, userCols, orColsMap := d.checkColumnsName(dataScope, args...)
+
+		var orColumns []string
+		var orValues []interface{}
+		if ok && userIds != "-1" {
+			for _, column := range userCols {
+				if ok, _ := d.M.HasField(column); ok || specialFlag {
+					orColumns = append(orColumns, column+" IN (?) ")
+					orValues = append(orValues, userIds)
 				}
-				delete(dataScope, bigColumns)
 			}
+		}
+		for col, params := range orColsMap {
+			if ok, _ := d.M.HasField(col); ok || specialFlag {
+				orColumns = append(orColumns, fmt.Sprintf(" ( %s IN (?) )", col))
+				orValues = append(orValues, params)
+			}
+		}
+
+		// 销售工程师权限加成
+		if !salesEngineerFlag {
 			var andColumns []string
 			var andValues []interface{}
-			for k, v := range dataScope {
-				if ok, _ := d.M.HasField(k); ok {
-					andColumns = append(andColumns, tableAs+k+" IN (?) ")
-					andValues = append(andValues, v)
+			for col, params := range dataScope {
+				if ok, _ := d.M.HasField(col); ok || specialFlag {
+					andColumns = append(andColumns, fmt.Sprintf(" ( %s IN (?) )", col))
+					andValues = append(andValues, params)
 				}
 			}
 			if len(andColumns) > 0 {
@@ -778,3 +807,80 @@ func (d *BaseDistributorDao) DataScope(ctx context.Context, userCol ...string) *
 	}
 	return d
 }
+
+// args 1、字段
+// args 2、字段、表名
+// args 3、字段对应关系
+func (d *BaseDistributorDao) checkColumnsName(dataScope map[string]interface{}, args ...interface{}) (bool, []string, map[string]interface{}) {
+	var userCols []string
+	tableAs, specialFlag := "", false
+	orColsMap, colsContrast := map[string]interface{}{}, map[string]interface{}{}
+
+	if d.TableAs != "" && len(args) <= 1 {
+		tableAs = d.TableAs + "."
+	}
+	if len(args) > 1 {
+		specialFlag = true
+		if val, ok := args[1].(string); ok {
+			tableAs = val + "."
+		}
+	}
+	if len(args) > 0 {
+		userCols = []string{"created_by"}
+		if column, ok := args[0].(string); ok {
+			userCols = []string{tableAs + column}
+		}
+		if cols, ok := args[0].([]string); ok {
+			for _, v := range cols {
+				userCols = append(userCols, tableAs+v)
+			}
+		}
+		if val, ok := args[0].(map[string]interface{}); ok {
+			specialFlag = true
+			colsContrast = val
+			if orcols, ok := val["orcols"]; ok {
+				if col, ok := orcols.(string); ok && gconv.String(val[col]) != "" {
+					orColsMap[col] = val[col]
+					delete(colsContrast, col)
+				}
+				if cols, ok := orcols.([]string); ok {
+					for _, col := range cols {
+						if gconv.String(val[col]) == "" {
+							continue
+						}
+						orColsMap[col] = val[col]
+						delete(colsContrast, col)
+					}
+				}
+			}
+			delete(colsContrast, "orcols")
+		}
+	}
+	bigColumns := "is_big"
+	if isBig, ok := dataScope[bigColumns]; ok {
+		if bigCol, ok := colsContrast[bigColumns]; ok {
+			orColsMap[bigCol.(string)] = isBig
+			delete(colsContrast, bigCol.(string))
+		} else {
+			if ok, _ := d.M.HasField(bigColumns); ok && specialFlag {
+				orColsMap[tableAs+bigColumns] = isBig
+			}
+		}
+	}
+
+	delete(dataScope, "userIds")
+	delete(dataScope, "roles")
+	delete(dataScope, "posts")
+	delete(dataScope, bigColumns)
+	for k, v := range dataScope {
+		if data, ok := colsContrast[k]; ok {
+			dataScope[data.(string)] = v
+		}
+		delete(dataScope, k)
+		delete(colsContrast, k)
+	}
+	for k, v := range colsContrast {
+		dataScope[k] = v
+	}
+	return specialFlag, userCols, orColsMap
+}

+ 111 - 31
opms_parent/app/dao/base/internal/base_distributor_contact.go

@@ -7,6 +7,7 @@ package internal
 import (
 	"context"
 	"database/sql"
+	"fmt"
 	"github.com/gogf/gf/container/garray"
 	"github.com/gogf/gf/database/gdb"
 	"github.com/gogf/gf/frame/g"
@@ -36,6 +37,8 @@ type baseDistributorContactColumns struct {
 	Phone       string // 电话
 	Wechat      string // 微信
 	Mail        string // 邮箱
+	Honorific   string // 尊称
+	Territory   string // 负责区域/业务线
 	Remark      string // 备注
 	CreatedBy   string // 创建者
 	CreatedName string // 创建人
@@ -60,6 +63,8 @@ var (
 			Phone:       "phone",
 			Wechat:      "wechat",
 			Mail:        "mail",
+			Honorific:   "honorific",
+			Territory:   "territory",
 			Remark:      "remark",
 			CreatedBy:   "created_by",
 			CreatedName: "created_name",
@@ -86,6 +91,8 @@ func NewBaseDistributorContactDao(tenant string) BaseDistributorContactDao {
 			Phone:       "phone",
 			Wechat:      "wechat",
 			Mail:        "mail",
+			Honorific:   "honorific",
+			Territory:   "territory",
 			Remark:      "remark",
 			CreatedBy:   "created_by",
 			CreatedName: "created_name",
@@ -694,28 +701,10 @@ func (d *BaseDistributorContactDao) Unscoped() *BaseDistributorContactDao {
 }
 
 // DataScope enables the DataScope feature.
-func (d *BaseDistributorContactDao) DataScope(ctx context.Context, userCol ...string) *BaseDistributorContactDao {
+func (d *BaseDistributorContactDao) DataScope(ctx context.Context, args ...interface{}) *BaseDistributorContactDao {
 	cs := ctx.Value("contextService")
 	dataScope := gconv.Map(gconv.String(gconv.Map(cs)["dataScope"]))
 	if dataScope != nil {
-		tableAs := d.TableAs
-		if d.TableAs != "" {
-			tableAs += "."
-		}
-		userIds, ok := dataScope["userIds"]
-		delete(dataScope, "userIds")
-		var orColumns []string
-		var orValues []interface{}
-		if ok && userIds != "-1" {
-			column := "created_by"
-			if len(userCol) == 1 {
-				column = userCol[0]
-			}
-			if ok, _ := d.M.HasField(column); ok {
-				orColumns = append(orColumns, tableAs+column+" IN (?) ")
-				orValues = append(orValues, userIds)
-			}
-		}
 		// 销售工程师判断
 		var salesEngineerFlag bool
 		if roles, ok := dataScope["roles"]; ok {
@@ -724,22 +713,34 @@ func (d *BaseDistributorContactDao) DataScope(ctx context.Context, userCol ...st
 				salesEngineerFlag = true
 			}
 		}
-		// 非销售工程师权限加成
-		if !salesEngineerFlag {
-			bigColumns := "is_big"
-			if ok, _ := d.M.HasField("is_big"); ok {
-				if val, ok := dataScope[bigColumns]; ok && val != "" {
-					orColumns = append(orColumns, tableAs+bigColumns+" = ? ")
-					orValues = append(orValues, val)
+		userIds, ok := dataScope["userIds"]
+		specialFlag, userCols, orColsMap := d.checkColumnsName(dataScope, args...)
+
+		var orColumns []string
+		var orValues []interface{}
+		if ok && userIds != "-1" {
+			for _, column := range userCols {
+				if ok, _ := d.M.HasField(column); ok || specialFlag {
+					orColumns = append(orColumns, column+" IN (?) ")
+					orValues = append(orValues, userIds)
 				}
-				delete(dataScope, bigColumns)
 			}
+		}
+		for col, params := range orColsMap {
+			if ok, _ := d.M.HasField(col); ok || specialFlag {
+				orColumns = append(orColumns, fmt.Sprintf(" ( %s IN (?) )", col))
+				orValues = append(orValues, params)
+			}
+		}
+
+		// 销售工程师权限加成
+		if !salesEngineerFlag {
 			var andColumns []string
 			var andValues []interface{}
-			for k, v := range dataScope {
-				if ok, _ := d.M.HasField(k); ok {
-					andColumns = append(andColumns, tableAs+k+" IN (?) ")
-					andValues = append(andValues, v)
+			for col, params := range dataScope {
+				if ok, _ := d.M.HasField(col); ok || specialFlag {
+					andColumns = append(andColumns, fmt.Sprintf(" ( %s IN (?) )", col))
+					andValues = append(andValues, params)
 				}
 			}
 			if len(andColumns) > 0 {
@@ -754,3 +755,82 @@ func (d *BaseDistributorContactDao) DataScope(ctx context.Context, userCol ...st
 	}
 	return d
 }
+
+// args 1、字段
+// args 2、字段、表名
+// args 3、字段对应关系
+func (d *BaseDistributorContactDao) checkColumnsName(dataScope map[string]interface{}, args ...interface{}) (bool, []string, map[string]interface{}) {
+	var userCols []string
+	tableAs, specialFlag := "", false
+	orColsMap, colsContrast := map[string]interface{}{}, map[string]interface{}{}
+
+	if d.TableAs != "" && len(args) <= 1 {
+		tableAs = d.TableAs + "."
+	}
+	if len(args) > 1 {
+		specialFlag = true
+		if val, ok := args[1].(string); ok {
+			tableAs = val + "."
+		}
+	}
+	if len(args) > 0 {
+		userCols = []string{"created_by"}
+		if column, ok := args[0].(string); ok {
+			userCols = []string{tableAs + column}
+		}
+		if cols, ok := args[0].([]string); ok {
+			for _, v := range cols {
+				userCols = append(userCols, tableAs+v)
+			}
+		}
+		if val, ok := args[0].(map[string]interface{}); ok {
+			specialFlag = true
+			colsContrast = val
+			if orcols, ok := val["orcols"]; ok {
+				if col, ok := orcols.(string); ok && gconv.String(val[col]) != "" {
+					orColsMap[col] = val[col]
+					delete(colsContrast, col)
+				}
+				if cols, ok := orcols.([]string); ok {
+					for _, col := range cols {
+						if gconv.String(val[col]) == "" {
+							continue
+						}
+						orColsMap[col] = val[col]
+						delete(colsContrast, col)
+					}
+				}
+			}
+			delete(colsContrast, "orcols")
+		}
+	}
+	bigColumns := "is_big"
+	if isBig, ok := dataScope[bigColumns]; ok {
+		if bigCol, ok := colsContrast[bigColumns]; ok {
+			orColsMap[bigCol.(string)] = isBig
+			delete(colsContrast, bigCol.(string))
+		} else {
+			if ok, _ := d.M.HasField(bigColumns); ok && specialFlag {
+				orColsMap[tableAs+bigColumns] = isBig
+			}
+		}
+	}
+
+	delete(dataScope, "userIds")
+	delete(dataScope, "roles")
+	delete(dataScope, "posts")
+	delete(dataScope, bigColumns)
+	if len(colsContrast) > 0 {
+		for k, v := range dataScope {
+			if data, ok := colsContrast[k]; ok {
+				dataScope[data.(string)] = v
+			}
+			delete(dataScope, k)
+			delete(colsContrast, k)
+		}
+		for k, v := range colsContrast {
+			dataScope[k] = v
+		}
+	}
+	return specialFlag, userCols, orColsMap
+}

+ 830 - 0
opms_parent/app/dao/base/internal/base_distributor_dynamics.go

@@ -0,0 +1,830 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
+// ==========================================================================
+
+package internal
+
+import (
+	"context"
+	"database/sql"
+	"fmt"
+	"github.com/gogf/gf/container/garray"
+	"github.com/gogf/gf/database/gdb"
+	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/frame/gmvc"
+	"github.com/gogf/gf/util/gconv"
+	"strings"
+	"time"
+
+	model "dashoo.cn/micro/app/model/base"
+)
+
+// BaseDistributorDynamicsDao is the manager for logic model data accessing and custom defined data operations functions management.
+type BaseDistributorDynamicsDao struct {
+	gmvc.M                                 // M is the core and embedded struct that inherits all chaining operations from gdb.Model.
+	C       baseDistributorDynamicsColumns // C is the short type for Columns, which contains all the column names of Table for convenient usage.
+	DB      gdb.DB                         // DB is the raw underlying database management object.
+	Table   string                         // Table is the underlying table name of the DAO.
+	TableAs string                         // TableAs is the underlying table alias name of the DAO.
+}
+
+// BaseDistributorDynamicsColumns defines and stores column names for table base_distributor_dynamics.
+type baseDistributorDynamicsColumns struct {
+	Id          string // 主键
+	DistId      string // 经销商/代理商ID
+	OpnPeopleId string // 操作人ID
+	OpnPeople   string // 操作人
+	OpnDate     string // 操作日期
+	OpnType     string // 操作类型
+	OpnContent  string // 操作内容
+	Remark      string // 备注
+	CreatedBy   string // 创建者
+	CreatedName string // 创建人
+	CreatedTime string // 创建时间
+	UpdatedBy   string // 更新者
+	UpdatedName string // 更新人
+	UpdatedTime string // 更新时间
+	DeletedTime string // 删除时间
+}
+
+var (
+	// BaseDistributorDynamics is globally public accessible object for table base_distributor_dynamics operations.
+	BaseDistributorDynamics = BaseDistributorDynamicsDao{
+		M:     g.DB("default").Model("base_distributor_dynamics").Safe(),
+		DB:    g.DB("default"),
+		Table: "base_distributor_dynamics",
+		C: baseDistributorDynamicsColumns{
+			Id:          "id",
+			DistId:      "dist_id",
+			OpnPeopleId: "opn_people_id",
+			OpnPeople:   "opn_people",
+			OpnDate:     "opn_date",
+			OpnType:     "opn_type",
+			OpnContent:  "opn_content",
+			Remark:      "remark",
+			CreatedBy:   "created_by",
+			CreatedName: "created_name",
+			CreatedTime: "created_time",
+			UpdatedBy:   "updated_by",
+			UpdatedName: "updated_name",
+			UpdatedTime: "updated_time",
+			DeletedTime: "deleted_time",
+		},
+	}
+)
+
+func NewBaseDistributorDynamicsDao(tenant string) BaseDistributorDynamicsDao {
+	var dao BaseDistributorDynamicsDao
+	dao = BaseDistributorDynamicsDao{
+		M:     g.DB(tenant).Model("base_distributor_dynamics").Safe(),
+		DB:    g.DB(tenant),
+		Table: "base_distributor_dynamics",
+		C: baseDistributorDynamicsColumns{
+			Id:          "id",
+			DistId:      "dist_id",
+			OpnPeopleId: "opn_people_id",
+			OpnPeople:   "opn_people",
+			OpnDate:     "opn_date",
+			OpnType:     "opn_type",
+			OpnContent:  "opn_content",
+			Remark:      "remark",
+			CreatedBy:   "created_by",
+			CreatedName: "created_name",
+			CreatedTime: "created_time",
+			UpdatedBy:   "updated_by",
+			UpdatedName: "updated_name",
+			UpdatedTime: "updated_time",
+			DeletedTime: "deleted_time",
+		},
+	}
+	return dao
+}
+
+// Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
+// of current DB object and with given context in it.
+// Note that this returned DB object can be used only once, so do not assign it to
+// a global or package variable for long using.
+func (d *BaseDistributorDynamicsDao) Ctx(ctx context.Context) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Ctx(ctx), Table: d.Table, TableAs: d.TableAs}
+}
+
+// GetCtx returns the context for current Model.
+// It returns "context.Background() i"s there's no context previously set.
+func (d *BaseDistributorDynamicsDao) GetCtx() context.Context {
+	return d.M.GetCtx()
+}
+
+// As sets an alias name for current table.
+func (d *BaseDistributorDynamicsDao) As(as string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.As(as), Table: d.Table, TableAs: as}
+}
+
+// TX sets the transaction for current operation.
+func (d *BaseDistributorDynamicsDao) TX(tx *gdb.TX) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.TX(tx), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Master marks the following operation on master node.
+func (d *BaseDistributorDynamicsDao) Master() *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Master(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Slave marks the following operation on slave node.
+// Note that it makes sense only if there's any slave node configured.
+func (d *BaseDistributorDynamicsDao) Slave() *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Slave(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Args sets custom arguments for model operation.
+func (d *BaseDistributorDynamicsDao) Args(args ...interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Args(args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Handler calls each of "handlers" on current Model and returns a new Model.
+// ModelHandler is a function that handles given Model and returns a new Model that is custom modified.
+func (d *BaseDistributorDynamicsDao) Handler(handlers ...gdb.ModelHandler) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Handler(handlers...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *BaseDistributorDynamicsDao) LeftJoin(table ...string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.LeftJoin(table...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *BaseDistributorDynamicsDao) RightJoin(table ...string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.RightJoin(table...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *BaseDistributorDynamicsDao) InnerJoin(table ...string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.InnerJoin(table...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Fields sets the operation fields of the model, multiple fields joined using char ','.
+// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
+func (d *BaseDistributorDynamicsDao) Fields(fieldNamesOrMapStruct ...interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Fields(fieldNamesOrMapStruct...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
+// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
+func (d *BaseDistributorDynamicsDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldCount formats and appends commonly used field "COUNT(column)" to the select fields of model.
+func (d *BaseDistributorDynamicsDao) FieldCount(column string, as ...string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.FieldCount(column, as...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldSum formats and appends commonly used field "SUM(column)" to the select fields of model.
+func (d *BaseDistributorDynamicsDao) FieldSum(column string, as ...string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.FieldSum(column, as...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldMin formats and appends commonly used field "MIN(column)" to the select fields of model.
+func (d *BaseDistributorDynamicsDao) FieldMin(column string, as ...string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.FieldMin(column, as...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldMax formats and appends commonly used field "MAX(column)" to the select fields of model.
+func (d *BaseDistributorDynamicsDao) FieldMax(column string, as ...string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.FieldMax(column, as...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldAvg formats and appends commonly used field "AVG(column)" to the select fields of model.
+func (d *BaseDistributorDynamicsDao) FieldAvg(column string, as ...string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.FieldAvg(column, as...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Option adds extra operation option for the model.
+// Deprecated, use separate operations instead.
+func (d *BaseDistributorDynamicsDao) Option(option int) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Option(option), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
+// the data and where attributes for empty values.
+func (d *BaseDistributorDynamicsDao) OmitEmpty() *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.OmitEmpty(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitEmptyWhere sets optionOmitEmptyWhere option for the model, which automatically filers
+// the Where/Having parameters for "empty" values.
+func (d *BaseDistributorDynamicsDao) OmitEmptyWhere() *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.OmitEmptyWhere(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitEmptyData sets optionOmitEmptyData option for the model, which automatically filers
+// the Data parameters for "empty" values.
+func (d *BaseDistributorDynamicsDao) OmitEmptyData() *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.OmitEmptyData(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitNil sets optionOmitNil option for the model, which automatically filers
+// the data and where parameters for "nil" values.
+func (d *BaseDistributorDynamicsDao) OmitNil() *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.OmitNil(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitNilWhere sets optionOmitNilWhere option for the model, which automatically filers
+// the Where/Having parameters for "nil" values.
+func (d *BaseDistributorDynamicsDao) OmitNilWhere() *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.OmitNilWhere(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitNilData sets optionOmitNilData option for the model, which automatically filers
+// the Data parameters for "nil" values.
+func (d *BaseDistributorDynamicsDao) OmitNilData() *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.OmitNilData(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Filter marks filtering the fields which does not exist in the fields of the operated table.
+// Note that this function supports only single table operations.
+// Deprecated, filter feature is automatically enabled from GoFrame v1.16.0, it is so no longer used.
+func (d *BaseDistributorDynamicsDao) Filter() *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Filter(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Where sets the condition statement for the model. The parameter <where> can be type of
+// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
+// multiple conditions will be joined into where statement using "AND".
+// Eg:
+// Where("uid=10000")
+// Where("uid", 10000)
+// Where("money>? AND name like ?", 99999, "vip_%")
+// Where("uid", 1).Where("name", "john")
+// Where("status IN (?)", g.Slice{1,2,3})
+// Where("age IN(?,?)", 18, 50)
+// Where(User{ Id : 1, UserName : "john"})
+func (d *BaseDistributorDynamicsDao) Where(where interface{}, args ...interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Where(where, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WherePri does the same logic as M.Where except that if the parameter <where>
+// is a single condition like int/string/float/slice, it treats the condition as the primary
+// key value. That is, if primary key is "id" and given <where> parameter as "123", the
+// WherePri function treats the condition as "id=123", but M.Where treats the condition
+// as string "123".
+func (d *BaseDistributorDynamicsDao) WherePri(where interface{}, args ...interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WherePri(where, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Having sets the having statement for the model.
+// The parameters of this function usage are as the same as function Where.
+// See Where.
+func (d *BaseDistributorDynamicsDao) Having(having interface{}, args ...interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Having(having, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Wheref builds condition string using fmt.Sprintf and arguments.
+// Note that if the number of "args" is more than the place holder in "format",
+// the extra "args" will be used as the where condition arguments of the Model.
+func (d *BaseDistributorDynamicsDao) Wheref(format string, args ...interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Wheref(format, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereLT builds "column < value" statement.
+func (d *BaseDistributorDynamicsDao) WhereLT(column string, value interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereLT(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereLTE builds "column <= value" statement.
+func (d *BaseDistributorDynamicsDao) WhereLTE(column string, value interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereLTE(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereGT builds "column > value" statement.
+func (d *BaseDistributorDynamicsDao) WhereGT(column string, value interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereGT(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereGTE builds "column >= value" statement.
+func (d *BaseDistributorDynamicsDao) WhereGTE(column string, value interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereGTE(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereBetween builds "column BETWEEN min AND max" statement.
+func (d *BaseDistributorDynamicsDao) WhereBetween(column string, min, max interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereLike builds "column LIKE like" statement.
+func (d *BaseDistributorDynamicsDao) WhereLike(column string, like interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereLike(column, like), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereIn builds "column IN (in)" statement.
+func (d *BaseDistributorDynamicsDao) WhereIn(column string, in interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereIn(column, in), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNull builds "columns[0] IS NULL AND columns[1] IS NULL ..." statement.
+func (d *BaseDistributorDynamicsDao) WhereNull(columns ...string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereNull(columns...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNotBetween builds "column NOT BETWEEN min AND max" statement.
+func (d *BaseDistributorDynamicsDao) WhereNotBetween(column string, min, max interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereNotBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNotLike builds "column NOT LIKE like" statement.
+func (d *BaseDistributorDynamicsDao) WhereNotLike(column string, like interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereNotLike(column, like), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNot builds "column != value" statement.
+func (d *BaseDistributorDynamicsDao) WhereNot(column string, value interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereNot(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNotIn builds "column NOT IN (in)" statement.
+func (d *BaseDistributorDynamicsDao) WhereNotIn(column string, in interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereNotIn(column, in), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNotNull builds "columns[0] IS NOT NULL AND columns[1] IS NOT NULL ..." statement.
+func (d *BaseDistributorDynamicsDao) WhereNotNull(columns ...string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereNotNull(columns...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOr adds "OR" condition to the where statement.
+func (d *BaseDistributorDynamicsDao) WhereOr(where interface{}, args ...interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereOr(where, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrf builds "OR" condition string using fmt.Sprintf and arguments.
+func (d *BaseDistributorDynamicsDao) WhereOrf(format string, args ...interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereOrf(format, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrLT builds "column < value" statement in "OR" conditions..
+func (d *BaseDistributorDynamicsDao) WhereOrLT(column string, value interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereOrLT(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrLTE builds "column <= value" statement in "OR" conditions..
+func (d *BaseDistributorDynamicsDao) WhereOrLTE(column string, value interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereOrLTE(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrGT builds "column > value" statement in "OR" conditions..
+func (d *BaseDistributorDynamicsDao) WhereOrGT(column string, value interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereOrGT(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrGTE builds "column >= value" statement in "OR" conditions..
+func (d *BaseDistributorDynamicsDao) WhereOrGTE(column string, value interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereOrGTE(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrBetween builds "column BETWEEN min AND max" statement in "OR" conditions.
+func (d *BaseDistributorDynamicsDao) WhereOrBetween(column string, min, max interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereOrBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrLike builds "column LIKE like" statement in "OR" conditions.
+func (d *BaseDistributorDynamicsDao) WhereOrLike(column string, like interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereOrLike(column, like), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrIn builds "column IN (in)" statement in "OR" conditions.
+func (d *BaseDistributorDynamicsDao) WhereOrIn(column string, in interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereOrIn(column, in), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrNull builds "columns[0] IS NULL OR columns[1] IS NULL ..." statement in "OR" conditions.
+func (d *BaseDistributorDynamicsDao) WhereOrNull(columns ...string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereOrNull(columns...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrNotBetween builds "column NOT BETWEEN min AND max" statement in "OR" conditions.
+func (d *BaseDistributorDynamicsDao) WhereOrNotBetween(column string, min, max interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereOrNotBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrNotLike builds "column NOT LIKE like" statement in "OR" conditions.
+func (d *BaseDistributorDynamicsDao) WhereOrNotLike(column string, like interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereOrNotLike(column, like), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrNotIn builds "column NOT IN (in)" statement.
+func (d *BaseDistributorDynamicsDao) WhereOrNotIn(column string, in interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereOrNotIn(column, in), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrNotNull builds "columns[0] IS NOT NULL OR columns[1] IS NOT NULL ..." statement in "OR" conditions.
+func (d *BaseDistributorDynamicsDao) WhereOrNotNull(columns ...string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.WhereOrNotNull(columns...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Group sets the "GROUP BY" statement for the model.
+func (d *BaseDistributorDynamicsDao) Group(groupBy ...string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Group(groupBy...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// And adds "AND" condition to the where statement.
+// Deprecated, use Where instead.
+func (d *BaseDistributorDynamicsDao) And(where interface{}, args ...interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.And(where, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Or adds "OR" condition to the where statement.
+// Deprecated, use WhereOr instead.
+func (d *BaseDistributorDynamicsDao) Or(where interface{}, args ...interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Or(where, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// GroupBy sets the "GROUP BY" statement for the model.
+func (d *BaseDistributorDynamicsDao) GroupBy(groupBy string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Group(groupBy), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Order sets the "ORDER BY" statement for the model.
+func (d *BaseDistributorDynamicsDao) Order(orderBy ...string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Order(orderBy...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OrderAsc sets the "ORDER BY xxx ASC" statement for the model.
+func (d *BaseDistributorDynamicsDao) OrderAsc(column string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.OrderAsc(column), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OrderDesc sets the "ORDER BY xxx DESC" statement for the model.
+func (d *BaseDistributorDynamicsDao) OrderDesc(column string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.OrderDesc(column), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OrderRandom sets the "ORDER BY RANDOM()" statement for the model.
+func (d *BaseDistributorDynamicsDao) OrderRandom() *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.OrderRandom(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OrderBy is alias of Model.Order.
+// See Model.Order.
+// Deprecated, use Order instead.
+func (d *BaseDistributorDynamicsDao) OrderBy(orderBy string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Order(orderBy), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Limit sets the "LIMIT" statement for the model.
+// The parameter <limit> can be either one or two number, if passed two number is passed,
+// it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
+// statement.
+func (d *BaseDistributorDynamicsDao) Limit(limit ...int) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Limit(limit...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Offset sets the "OFFSET" statement for the model.
+// It only makes sense for some databases like SQLServer, PostgreSQL, etc.
+func (d *BaseDistributorDynamicsDao) Offset(offset int) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Offset(offset), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Distinct forces the query to only return distinct results.
+func (d *BaseDistributorDynamicsDao) Distinct() *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Distinct(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Page sets the paging number for the model.
+// The parameter <page> is started from 1 for paging.
+// Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
+func (d *BaseDistributorDynamicsDao) Page(page, limit int) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Page(page, limit), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Batch sets the batch operation number for the model.
+func (d *BaseDistributorDynamicsDao) Batch(batch int) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Batch(batch), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Cache sets the cache feature for the model. It caches the result of the sql, which means
+// if there's another same sql request, it just reads and returns the result from cache, it
+// but not committed and executed into the database.
+//
+// If the parameter <duration> < 0, which means it clear the cache with given <name>.
+// If the parameter <duration> = 0, which means it never expires.
+// If the parameter <duration> > 0, which means it expires after <duration>.
+//
+// The optional parameter <name> is used to bind a name to the cache, which means you can later
+// control the cache like changing the <duration> or clearing the cache with specified <name>.
+//
+// Note that, the cache feature is disabled if the model is operating on a transaction.
+func (d *BaseDistributorDynamicsDao) Cache(duration time.Duration, name ...string) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Cache(duration, name...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Data sets the operation data for the model.
+// The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
+// Eg:
+// Data("uid=10000")
+// Data("uid", 10000)
+// Data(g.Map{"uid": 10000, "name":"john"})
+// Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
+func (d *BaseDistributorDynamicsDao) Data(data ...interface{}) *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Data(data...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// All does "SELECT FROM ..." statement for the model.
+// It retrieves the records from table and returns the result as []*model.BaseDistributorDynamics.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of M.Where function,
+// see M.Where.
+func (d *BaseDistributorDynamicsDao) All(where ...interface{}) ([]*model.BaseDistributorDynamics, error) {
+	all, err := d.M.All(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*model.BaseDistributorDynamics
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// One retrieves one record from table and returns the result as *model.BaseDistributorDynamics.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of M.Where function,
+// see M.Where.
+func (d *BaseDistributorDynamicsDao) One(where ...interface{}) (*model.BaseDistributorDynamics, error) {
+	one, err := d.M.One(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *model.BaseDistributorDynamics
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindOne retrieves and returns a single Record by M.WherePri and M.One.
+// Also see M.WherePri and M.One.
+func (d *BaseDistributorDynamicsDao) FindOne(where ...interface{}) (*model.BaseDistributorDynamics, error) {
+	one, err := d.M.FindOne(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *model.BaseDistributorDynamics
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindAll retrieves and returns Result by by M.WherePri and M.All.
+// Also see M.WherePri and M.All.
+func (d *BaseDistributorDynamicsDao) FindAll(where ...interface{}) ([]*model.BaseDistributorDynamics, error) {
+	all, err := d.M.FindAll(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*model.BaseDistributorDynamics
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// Struct retrieves one record from table and converts it into given struct.
+// The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
+// it can create the struct internally during converting.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
+// from table and <pointer> is not nil.
+//
+// Eg:
+// user := new(User)
+// err  := dao.User.Where("id", 1).Struct(user)
+//
+// user := (*User)(nil)
+// err  := dao.User.Where("id", 1).Struct(&user)
+func (d *BaseDistributorDynamicsDao) Struct(pointer interface{}, where ...interface{}) error {
+	return d.M.Struct(pointer, where...)
+}
+
+// Structs retrieves records from table and converts them into given struct slice.
+// The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
+// slice internally during converting.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
+// from table and <pointer> is not empty.
+//
+// Eg:
+// users := ([]User)(nil)
+// err   := dao.User.Structs(&users)
+//
+// users := ([]*User)(nil)
+// err   := dao.User.Structs(&users)
+func (d *BaseDistributorDynamicsDao) Structs(pointer interface{}, where ...interface{}) error {
+	return d.M.Structs(pointer, where...)
+}
+
+// Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
+// It calls function Struct if <pointer> is type of *struct/**struct.
+// It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
+//
+// Eg:
+// user  := new(User)
+// err   := dao.User.Where("id", 1).Scan(user)
+//
+// user  := (*User)(nil)
+// err   := dao.User.Where("id", 1).Scan(&user)
+//
+// users := ([]User)(nil)
+// err   := dao.User.Scan(&users)
+//
+// users := ([]*User)(nil)
+// err   := dao.User.Scan(&users)
+func (d *BaseDistributorDynamicsDao) Scan(pointer interface{}, where ...interface{}) error {
+	return d.M.Scan(pointer, where...)
+}
+
+// Chunk iterates the table with given size and callback function.
+func (d *BaseDistributorDynamicsDao) Chunk(limit int, callback func(entities []*model.BaseDistributorDynamics, err error) bool) {
+	d.M.Chunk(limit, func(result gdb.Result, err error) bool {
+		var entities []*model.BaseDistributorDynamics
+		err = result.Structs(&entities)
+		if err == sql.ErrNoRows {
+			return false
+		}
+		return callback(entities, err)
+	})
+}
+
+// LockUpdate sets the lock for update for current operation.
+func (d *BaseDistributorDynamicsDao) LockUpdate() *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.LockUpdate(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// LockShared sets the lock in share mode for current operation.
+func (d *BaseDistributorDynamicsDao) LockShared() *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.LockShared(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Unscoped enables/disables the soft deleting feature.
+func (d *BaseDistributorDynamicsDao) Unscoped() *BaseDistributorDynamicsDao {
+	return &BaseDistributorDynamicsDao{M: d.M.Unscoped(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// DataScope enables the DataScope feature.
+func (d *BaseDistributorDynamicsDao) DataScope(ctx context.Context, args ...interface{}) *BaseDistributorDynamicsDao {
+	cs := ctx.Value("contextService")
+	dataScope := gconv.Map(gconv.String(gconv.Map(cs)["dataScope"]))
+	if dataScope != nil {
+		// 销售工程师判断
+		var salesEngineerFlag bool
+		if roles, ok := dataScope["roles"]; ok {
+			arr := garray.NewArrayFrom(roles.([]interface{}), true)
+			if arr.Len() == 1 && arr.Contains("SalesEngineer") {
+				salesEngineerFlag = true
+			}
+		}
+		userIds, ok := dataScope["userIds"]
+		specialFlag, userCols, orColsMap := d.checkColumnsName(dataScope, args...)
+
+		var orColumns []string
+		var orValues []interface{}
+		if ok && userIds != "-1" {
+			for _, column := range userCols {
+				if ok, _ := d.M.HasField(column); ok || specialFlag {
+					orColumns = append(orColumns, column+" IN (?) ")
+					orValues = append(orValues, userIds)
+				}
+			}
+		}
+		for col, params := range orColsMap {
+			if ok, _ := d.M.HasField(col); ok || specialFlag {
+				orColumns = append(orColumns, fmt.Sprintf(" ( %s IN (?) )", col))
+				orValues = append(orValues, params)
+			}
+		}
+
+		// 销售工程师权限加成
+		if !salesEngineerFlag {
+			var andColumns []string
+			var andValues []interface{}
+			for col, params := range dataScope {
+				if ok, _ := d.M.HasField(col); ok || specialFlag {
+					andColumns = append(andColumns, fmt.Sprintf(" ( %s IN (?) )", col))
+					andValues = append(andValues, params)
+				}
+			}
+			if len(andColumns) > 0 {
+				andWhereSql := strings.Join(andColumns, " AND ")
+				orColumns = append(orColumns, "("+andWhereSql+")")
+				orValues = append(orValues, andValues...)
+			}
+		}
+
+		whereSql := strings.Join(orColumns, " OR ")
+		return &BaseDistributorDynamicsDao{M: d.M.Where(whereSql, orValues...).Ctx(ctx), Table: d.Table, TableAs: d.TableAs}
+	}
+	return d
+}
+
+// args 1、字段
+// args 2、字段、表名
+// args 3、字段对应关系
+func (d *BaseDistributorDynamicsDao) checkColumnsName(dataScope map[string]interface{}, args ...interface{}) (bool, []string, map[string]interface{}) {
+	var userCols []string
+	tableAs, specialFlag := "", false
+	orColsMap, colsContrast := map[string]interface{}{}, map[string]interface{}{}
+
+	if d.TableAs != "" && len(args) <= 1 {
+		tableAs = d.TableAs + "."
+	}
+	if len(args) > 1 {
+		specialFlag = true
+		if val, ok := args[1].(string); ok {
+			tableAs = val + "."
+		}
+	}
+	if len(args) > 0 {
+		userCols = []string{"created_by"}
+		if column, ok := args[0].(string); ok {
+			userCols = []string{tableAs + column}
+		}
+		if cols, ok := args[0].([]string); ok {
+			for _, v := range cols {
+				userCols = append(userCols, tableAs+v)
+			}
+		}
+		if val, ok := args[0].(map[string]interface{}); ok {
+			specialFlag = true
+			colsContrast = val
+			if orcols, ok := val["orcols"]; ok {
+				if col, ok := orcols.(string); ok && gconv.String(val[col]) != "" {
+					orColsMap[col] = val[col]
+					delete(colsContrast, col)
+				}
+				if cols, ok := orcols.([]string); ok {
+					for _, col := range cols {
+						if gconv.String(val[col]) == "" {
+							continue
+						}
+						orColsMap[col] = val[col]
+						delete(colsContrast, col)
+					}
+				}
+			}
+			delete(colsContrast, "orcols")
+		}
+	}
+	bigColumns := "is_big"
+	if isBig, ok := dataScope[bigColumns]; ok {
+		if bigCol, ok := colsContrast[bigColumns]; ok {
+			orColsMap[bigCol.(string)] = isBig
+			delete(colsContrast, bigCol.(string))
+		} else {
+			if ok, _ := d.M.HasField(bigColumns); ok && specialFlag {
+				orColsMap[tableAs+bigColumns] = isBig
+			}
+		}
+	}
+
+	delete(dataScope, "userIds")
+	delete(dataScope, "roles")
+	delete(dataScope, "posts")
+	delete(dataScope, bigColumns)
+	if len(colsContrast) > 0 {
+		for k, v := range dataScope {
+			if data, ok := colsContrast[k]; ok {
+				dataScope[data.(string)] = v
+			}
+			delete(dataScope, k)
+			delete(colsContrast, k)
+		}
+		for k, v := range colsContrast {
+			dataScope[k] = v
+		}
+	}
+	return specialFlag, userCols, orColsMap
+}

+ 845 - 0
opms_parent/app/dao/base/internal/base_distributor_record.go

@@ -0,0 +1,845 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
+// ==========================================================================
+
+package internal
+
+import (
+	"context"
+	"database/sql"
+	"fmt"
+	"github.com/gogf/gf/container/garray"
+	"github.com/gogf/gf/database/gdb"
+	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/frame/gmvc"
+	"github.com/gogf/gf/util/gconv"
+	"strings"
+	"time"
+
+	model "dashoo.cn/micro/app/model/base"
+)
+
+// BaseDistributorRecordDao is the manager for logic model data accessing and custom defined data operations functions management.
+type BaseDistributorRecordDao struct {
+	gmvc.M                               // M is the core and embedded struct that inherits all chaining operations from gdb.Model.
+	C       baseDistributorRecordColumns // C is the short type for Columns, which contains all the column names of Table for convenient usage.
+	DB      gdb.DB                       // DB is the raw underlying database management object.
+	Table   string                       // Table is the underlying table name of the DAO.
+	TableAs string                       // TableAs is the underlying table alias name of the DAO.
+}
+
+// BaseDistributorRecordColumns defines and stores column names for table base_distributor_record.
+type baseDistributorRecordColumns struct {
+	Id              string // 主键
+	DistId          string // 所属经销商
+	DistType        string // 经销商类型 10 经销商 20 代理商
+	BusinessScope   string // 业务范围
+	CustomerType    string // 授权客户类型
+	ProxyDistrict   string // 授权代理区域(代理商)
+	ProxyStartTime  string // 代理签约有效期开始(代理商)
+	ProxyEndTime    string // 代理签约有效期结束(代理商)
+	ContractUrl     string // 代理合同(代理商)
+	ExistedProduct  string // 已有代理品牌和产品
+	HistoryCustomer string // 历史合作的终端客户名称
+	ToDistReason    string // 转移经销商原因
+	Remark          string // 备注
+	CreatedBy       string // 创建者
+	CreatedName     string // 创建人
+	CreatedTime     string // 创建时间
+	UpdatedBy       string // 更新者
+	UpdatedName     string // 更新人
+	UpdatedTime     string // 更新时间
+	DeletedTime     string // 删除时间
+}
+
+var (
+	// BaseDistributorRecord is globally public accessible object for table base_distributor_record operations.
+	BaseDistributorRecord = BaseDistributorRecordDao{
+		M:     g.DB("default").Model("base_distributor_record").Safe(),
+		DB:    g.DB("default"),
+		Table: "base_distributor_record",
+		C: baseDistributorRecordColumns{
+			Id:              "id",
+			DistId:          "dist_id",
+			DistType:        "dist_type",
+			BusinessScope:   "business_scope",
+			CustomerType:    "customer_type",
+			ProxyDistrict:   "proxy_district",
+			ProxyStartTime:  "proxy_start_time",
+			ProxyEndTime:    "proxy_end_time",
+			ContractUrl:     "contract_url",
+			ExistedProduct:  "existed_product",
+			HistoryCustomer: "history_customer",
+			ToDistReason:    "to_dist_reason",
+			Remark:          "remark",
+			CreatedBy:       "created_by",
+			CreatedName:     "created_name",
+			CreatedTime:     "created_time",
+			UpdatedBy:       "updated_by",
+			UpdatedName:     "updated_name",
+			UpdatedTime:     "updated_time",
+			DeletedTime:     "deleted_time",
+		},
+	}
+)
+
+func NewBaseDistributorRecordDao(tenant string) BaseDistributorRecordDao {
+	var dao BaseDistributorRecordDao
+	dao = BaseDistributorRecordDao{
+		M:     g.DB(tenant).Model("base_distributor_record").Safe(),
+		DB:    g.DB(tenant),
+		Table: "base_distributor_record",
+		C: baseDistributorRecordColumns{
+			Id:              "id",
+			DistId:          "dist_id",
+			DistType:        "dist_type",
+			BusinessScope:   "business_scope",
+			CustomerType:    "customer_type",
+			ProxyDistrict:   "proxy_district",
+			ProxyStartTime:  "proxy_start_time",
+			ProxyEndTime:    "proxy_end_time",
+			ContractUrl:     "contract_url",
+			ExistedProduct:  "existed_product",
+			HistoryCustomer: "history_customer",
+			ToDistReason:    "to_dist_reason",
+			Remark:          "remark",
+			CreatedBy:       "created_by",
+			CreatedName:     "created_name",
+			CreatedTime:     "created_time",
+			UpdatedBy:       "updated_by",
+			UpdatedName:     "updated_name",
+			UpdatedTime:     "updated_time",
+			DeletedTime:     "deleted_time",
+		},
+	}
+	return dao
+}
+
+// Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
+// of current DB object and with given context in it.
+// Note that this returned DB object can be used only once, so do not assign it to
+// a global or package variable for long using.
+func (d *BaseDistributorRecordDao) Ctx(ctx context.Context) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Ctx(ctx), Table: d.Table, TableAs: d.TableAs}
+}
+
+// GetCtx returns the context for current Model.
+// It returns "context.Background() i"s there's no context previously set.
+func (d *BaseDistributorRecordDao) GetCtx() context.Context {
+	return d.M.GetCtx()
+}
+
+// As sets an alias name for current table.
+func (d *BaseDistributorRecordDao) As(as string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.As(as), Table: d.Table, TableAs: as}
+}
+
+// TX sets the transaction for current operation.
+func (d *BaseDistributorRecordDao) TX(tx *gdb.TX) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.TX(tx), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Master marks the following operation on master node.
+func (d *BaseDistributorRecordDao) Master() *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Master(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Slave marks the following operation on slave node.
+// Note that it makes sense only if there's any slave node configured.
+func (d *BaseDistributorRecordDao) Slave() *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Slave(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Args sets custom arguments for model operation.
+func (d *BaseDistributorRecordDao) Args(args ...interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Args(args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Handler calls each of "handlers" on current Model and returns a new Model.
+// ModelHandler is a function that handles given Model and returns a new Model that is custom modified.
+func (d *BaseDistributorRecordDao) Handler(handlers ...gdb.ModelHandler) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Handler(handlers...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *BaseDistributorRecordDao) LeftJoin(table ...string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.LeftJoin(table...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *BaseDistributorRecordDao) RightJoin(table ...string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.RightJoin(table...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *BaseDistributorRecordDao) InnerJoin(table ...string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.InnerJoin(table...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Fields sets the operation fields of the model, multiple fields joined using char ','.
+// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
+func (d *BaseDistributorRecordDao) Fields(fieldNamesOrMapStruct ...interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Fields(fieldNamesOrMapStruct...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
+// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
+func (d *BaseDistributorRecordDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldCount formats and appends commonly used field "COUNT(column)" to the select fields of model.
+func (d *BaseDistributorRecordDao) FieldCount(column string, as ...string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.FieldCount(column, as...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldSum formats and appends commonly used field "SUM(column)" to the select fields of model.
+func (d *BaseDistributorRecordDao) FieldSum(column string, as ...string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.FieldSum(column, as...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldMin formats and appends commonly used field "MIN(column)" to the select fields of model.
+func (d *BaseDistributorRecordDao) FieldMin(column string, as ...string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.FieldMin(column, as...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldMax formats and appends commonly used field "MAX(column)" to the select fields of model.
+func (d *BaseDistributorRecordDao) FieldMax(column string, as ...string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.FieldMax(column, as...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldAvg formats and appends commonly used field "AVG(column)" to the select fields of model.
+func (d *BaseDistributorRecordDao) FieldAvg(column string, as ...string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.FieldAvg(column, as...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Option adds extra operation option for the model.
+// Deprecated, use separate operations instead.
+func (d *BaseDistributorRecordDao) Option(option int) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Option(option), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
+// the data and where attributes for empty values.
+func (d *BaseDistributorRecordDao) OmitEmpty() *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.OmitEmpty(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitEmptyWhere sets optionOmitEmptyWhere option for the model, which automatically filers
+// the Where/Having parameters for "empty" values.
+func (d *BaseDistributorRecordDao) OmitEmptyWhere() *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.OmitEmptyWhere(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitEmptyData sets optionOmitEmptyData option for the model, which automatically filers
+// the Data parameters for "empty" values.
+func (d *BaseDistributorRecordDao) OmitEmptyData() *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.OmitEmptyData(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitNil sets optionOmitNil option for the model, which automatically filers
+// the data and where parameters for "nil" values.
+func (d *BaseDistributorRecordDao) OmitNil() *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.OmitNil(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitNilWhere sets optionOmitNilWhere option for the model, which automatically filers
+// the Where/Having parameters for "nil" values.
+func (d *BaseDistributorRecordDao) OmitNilWhere() *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.OmitNilWhere(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitNilData sets optionOmitNilData option for the model, which automatically filers
+// the Data parameters for "nil" values.
+func (d *BaseDistributorRecordDao) OmitNilData() *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.OmitNilData(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Filter marks filtering the fields which does not exist in the fields of the operated table.
+// Note that this function supports only single table operations.
+// Deprecated, filter feature is automatically enabled from GoFrame v1.16.0, it is so no longer used.
+func (d *BaseDistributorRecordDao) Filter() *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Filter(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Where sets the condition statement for the model. The parameter <where> can be type of
+// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
+// multiple conditions will be joined into where statement using "AND".
+// Eg:
+// Where("uid=10000")
+// Where("uid", 10000)
+// Where("money>? AND name like ?", 99999, "vip_%")
+// Where("uid", 1).Where("name", "john")
+// Where("status IN (?)", g.Slice{1,2,3})
+// Where("age IN(?,?)", 18, 50)
+// Where(User{ Id : 1, UserName : "john"})
+func (d *BaseDistributorRecordDao) Where(where interface{}, args ...interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Where(where, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WherePri does the same logic as M.Where except that if the parameter <where>
+// is a single condition like int/string/float/slice, it treats the condition as the primary
+// key value. That is, if primary key is "id" and given <where> parameter as "123", the
+// WherePri function treats the condition as "id=123", but M.Where treats the condition
+// as string "123".
+func (d *BaseDistributorRecordDao) WherePri(where interface{}, args ...interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WherePri(where, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Having sets the having statement for the model.
+// The parameters of this function usage are as the same as function Where.
+// See Where.
+func (d *BaseDistributorRecordDao) Having(having interface{}, args ...interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Having(having, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Wheref builds condition string using fmt.Sprintf and arguments.
+// Note that if the number of "args" is more than the place holder in "format",
+// the extra "args" will be used as the where condition arguments of the Model.
+func (d *BaseDistributorRecordDao) Wheref(format string, args ...interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Wheref(format, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereLT builds "column < value" statement.
+func (d *BaseDistributorRecordDao) WhereLT(column string, value interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereLT(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereLTE builds "column <= value" statement.
+func (d *BaseDistributorRecordDao) WhereLTE(column string, value interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereLTE(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereGT builds "column > value" statement.
+func (d *BaseDistributorRecordDao) WhereGT(column string, value interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereGT(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereGTE builds "column >= value" statement.
+func (d *BaseDistributorRecordDao) WhereGTE(column string, value interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereGTE(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereBetween builds "column BETWEEN min AND max" statement.
+func (d *BaseDistributorRecordDao) WhereBetween(column string, min, max interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereLike builds "column LIKE like" statement.
+func (d *BaseDistributorRecordDao) WhereLike(column string, like interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereLike(column, like), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereIn builds "column IN (in)" statement.
+func (d *BaseDistributorRecordDao) WhereIn(column string, in interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereIn(column, in), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNull builds "columns[0] IS NULL AND columns[1] IS NULL ..." statement.
+func (d *BaseDistributorRecordDao) WhereNull(columns ...string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereNull(columns...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNotBetween builds "column NOT BETWEEN min AND max" statement.
+func (d *BaseDistributorRecordDao) WhereNotBetween(column string, min, max interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereNotBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNotLike builds "column NOT LIKE like" statement.
+func (d *BaseDistributorRecordDao) WhereNotLike(column string, like interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereNotLike(column, like), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNot builds "column != value" statement.
+func (d *BaseDistributorRecordDao) WhereNot(column string, value interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereNot(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNotIn builds "column NOT IN (in)" statement.
+func (d *BaseDistributorRecordDao) WhereNotIn(column string, in interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereNotIn(column, in), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNotNull builds "columns[0] IS NOT NULL AND columns[1] IS NOT NULL ..." statement.
+func (d *BaseDistributorRecordDao) WhereNotNull(columns ...string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereNotNull(columns...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOr adds "OR" condition to the where statement.
+func (d *BaseDistributorRecordDao) WhereOr(where interface{}, args ...interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereOr(where, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrf builds "OR" condition string using fmt.Sprintf and arguments.
+func (d *BaseDistributorRecordDao) WhereOrf(format string, args ...interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereOrf(format, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrLT builds "column < value" statement in "OR" conditions..
+func (d *BaseDistributorRecordDao) WhereOrLT(column string, value interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereOrLT(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrLTE builds "column <= value" statement in "OR" conditions..
+func (d *BaseDistributorRecordDao) WhereOrLTE(column string, value interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereOrLTE(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrGT builds "column > value" statement in "OR" conditions..
+func (d *BaseDistributorRecordDao) WhereOrGT(column string, value interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereOrGT(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrGTE builds "column >= value" statement in "OR" conditions..
+func (d *BaseDistributorRecordDao) WhereOrGTE(column string, value interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereOrGTE(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrBetween builds "column BETWEEN min AND max" statement in "OR" conditions.
+func (d *BaseDistributorRecordDao) WhereOrBetween(column string, min, max interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereOrBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrLike builds "column LIKE like" statement in "OR" conditions.
+func (d *BaseDistributorRecordDao) WhereOrLike(column string, like interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereOrLike(column, like), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrIn builds "column IN (in)" statement in "OR" conditions.
+func (d *BaseDistributorRecordDao) WhereOrIn(column string, in interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereOrIn(column, in), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrNull builds "columns[0] IS NULL OR columns[1] IS NULL ..." statement in "OR" conditions.
+func (d *BaseDistributorRecordDao) WhereOrNull(columns ...string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereOrNull(columns...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrNotBetween builds "column NOT BETWEEN min AND max" statement in "OR" conditions.
+func (d *BaseDistributorRecordDao) WhereOrNotBetween(column string, min, max interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereOrNotBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrNotLike builds "column NOT LIKE like" statement in "OR" conditions.
+func (d *BaseDistributorRecordDao) WhereOrNotLike(column string, like interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereOrNotLike(column, like), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrNotIn builds "column NOT IN (in)" statement.
+func (d *BaseDistributorRecordDao) WhereOrNotIn(column string, in interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereOrNotIn(column, in), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrNotNull builds "columns[0] IS NOT NULL OR columns[1] IS NOT NULL ..." statement in "OR" conditions.
+func (d *BaseDistributorRecordDao) WhereOrNotNull(columns ...string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.WhereOrNotNull(columns...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Group sets the "GROUP BY" statement for the model.
+func (d *BaseDistributorRecordDao) Group(groupBy ...string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Group(groupBy...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// And adds "AND" condition to the where statement.
+// Deprecated, use Where instead.
+func (d *BaseDistributorRecordDao) And(where interface{}, args ...interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.And(where, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Or adds "OR" condition to the where statement.
+// Deprecated, use WhereOr instead.
+func (d *BaseDistributorRecordDao) Or(where interface{}, args ...interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Or(where, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// GroupBy sets the "GROUP BY" statement for the model.
+func (d *BaseDistributorRecordDao) GroupBy(groupBy string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Group(groupBy), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Order sets the "ORDER BY" statement for the model.
+func (d *BaseDistributorRecordDao) Order(orderBy ...string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Order(orderBy...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OrderAsc sets the "ORDER BY xxx ASC" statement for the model.
+func (d *BaseDistributorRecordDao) OrderAsc(column string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.OrderAsc(column), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OrderDesc sets the "ORDER BY xxx DESC" statement for the model.
+func (d *BaseDistributorRecordDao) OrderDesc(column string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.OrderDesc(column), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OrderRandom sets the "ORDER BY RANDOM()" statement for the model.
+func (d *BaseDistributorRecordDao) OrderRandom() *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.OrderRandom(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OrderBy is alias of Model.Order.
+// See Model.Order.
+// Deprecated, use Order instead.
+func (d *BaseDistributorRecordDao) OrderBy(orderBy string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Order(orderBy), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Limit sets the "LIMIT" statement for the model.
+// The parameter <limit> can be either one or two number, if passed two number is passed,
+// it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
+// statement.
+func (d *BaseDistributorRecordDao) Limit(limit ...int) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Limit(limit...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Offset sets the "OFFSET" statement for the model.
+// It only makes sense for some databases like SQLServer, PostgreSQL, etc.
+func (d *BaseDistributorRecordDao) Offset(offset int) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Offset(offset), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Distinct forces the query to only return distinct results.
+func (d *BaseDistributorRecordDao) Distinct() *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Distinct(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Page sets the paging number for the model.
+// The parameter <page> is started from 1 for paging.
+// Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
+func (d *BaseDistributorRecordDao) Page(page, limit int) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Page(page, limit), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Batch sets the batch operation number for the model.
+func (d *BaseDistributorRecordDao) Batch(batch int) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Batch(batch), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Cache sets the cache feature for the model. It caches the result of the sql, which means
+// if there's another same sql request, it just reads and returns the result from cache, it
+// but not committed and executed into the database.
+//
+// If the parameter <duration> < 0, which means it clear the cache with given <name>.
+// If the parameter <duration> = 0, which means it never expires.
+// If the parameter <duration> > 0, which means it expires after <duration>.
+//
+// The optional parameter <name> is used to bind a name to the cache, which means you can later
+// control the cache like changing the <duration> or clearing the cache with specified <name>.
+//
+// Note that, the cache feature is disabled if the model is operating on a transaction.
+func (d *BaseDistributorRecordDao) Cache(duration time.Duration, name ...string) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Cache(duration, name...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Data sets the operation data for the model.
+// The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
+// Eg:
+// Data("uid=10000")
+// Data("uid", 10000)
+// Data(g.Map{"uid": 10000, "name":"john"})
+// Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
+func (d *BaseDistributorRecordDao) Data(data ...interface{}) *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Data(data...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// All does "SELECT FROM ..." statement for the model.
+// It retrieves the records from table and returns the result as []*model.BaseDistributorRecord.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of M.Where function,
+// see M.Where.
+func (d *BaseDistributorRecordDao) All(where ...interface{}) ([]*model.BaseDistributorRecord, error) {
+	all, err := d.M.All(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*model.BaseDistributorRecord
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// One retrieves one record from table and returns the result as *model.BaseDistributorRecord.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of M.Where function,
+// see M.Where.
+func (d *BaseDistributorRecordDao) One(where ...interface{}) (*model.BaseDistributorRecord, error) {
+	one, err := d.M.One(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *model.BaseDistributorRecord
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindOne retrieves and returns a single Record by M.WherePri and M.One.
+// Also see M.WherePri and M.One.
+func (d *BaseDistributorRecordDao) FindOne(where ...interface{}) (*model.BaseDistributorRecord, error) {
+	one, err := d.M.FindOne(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *model.BaseDistributorRecord
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindAll retrieves and returns Result by by M.WherePri and M.All.
+// Also see M.WherePri and M.All.
+func (d *BaseDistributorRecordDao) FindAll(where ...interface{}) ([]*model.BaseDistributorRecord, error) {
+	all, err := d.M.FindAll(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*model.BaseDistributorRecord
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// Struct retrieves one record from table and converts it into given struct.
+// The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
+// it can create the struct internally during converting.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
+// from table and <pointer> is not nil.
+//
+// Eg:
+// user := new(User)
+// err  := dao.User.Where("id", 1).Struct(user)
+//
+// user := (*User)(nil)
+// err  := dao.User.Where("id", 1).Struct(&user)
+func (d *BaseDistributorRecordDao) Struct(pointer interface{}, where ...interface{}) error {
+	return d.M.Struct(pointer, where...)
+}
+
+// Structs retrieves records from table and converts them into given struct slice.
+// The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
+// slice internally during converting.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
+// from table and <pointer> is not empty.
+//
+// Eg:
+// users := ([]User)(nil)
+// err   := dao.User.Structs(&users)
+//
+// users := ([]*User)(nil)
+// err   := dao.User.Structs(&users)
+func (d *BaseDistributorRecordDao) Structs(pointer interface{}, where ...interface{}) error {
+	return d.M.Structs(pointer, where...)
+}
+
+// Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
+// It calls function Struct if <pointer> is type of *struct/**struct.
+// It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
+//
+// Eg:
+// user  := new(User)
+// err   := dao.User.Where("id", 1).Scan(user)
+//
+// user  := (*User)(nil)
+// err   := dao.User.Where("id", 1).Scan(&user)
+//
+// users := ([]User)(nil)
+// err   := dao.User.Scan(&users)
+//
+// users := ([]*User)(nil)
+// err   := dao.User.Scan(&users)
+func (d *BaseDistributorRecordDao) Scan(pointer interface{}, where ...interface{}) error {
+	return d.M.Scan(pointer, where...)
+}
+
+// Chunk iterates the table with given size and callback function.
+func (d *BaseDistributorRecordDao) Chunk(limit int, callback func(entities []*model.BaseDistributorRecord, err error) bool) {
+	d.M.Chunk(limit, func(result gdb.Result, err error) bool {
+		var entities []*model.BaseDistributorRecord
+		err = result.Structs(&entities)
+		if err == sql.ErrNoRows {
+			return false
+		}
+		return callback(entities, err)
+	})
+}
+
+// LockUpdate sets the lock for update for current operation.
+func (d *BaseDistributorRecordDao) LockUpdate() *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.LockUpdate(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// LockShared sets the lock in share mode for current operation.
+func (d *BaseDistributorRecordDao) LockShared() *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.LockShared(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Unscoped enables/disables the soft deleting feature.
+func (d *BaseDistributorRecordDao) Unscoped() *BaseDistributorRecordDao {
+	return &BaseDistributorRecordDao{M: d.M.Unscoped(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// DataScope enables the DataScope feature.
+func (d *BaseDistributorRecordDao) DataScope(ctx context.Context, args ...interface{}) *BaseDistributorRecordDao {
+	cs := ctx.Value("contextService")
+	dataScope := gconv.Map(gconv.String(gconv.Map(cs)["dataScope"]))
+	if dataScope != nil {
+		// 销售工程师判断
+		var salesEngineerFlag bool
+		if roles, ok := dataScope["roles"]; ok {
+			arr := garray.NewArrayFrom(roles.([]interface{}), true)
+			if arr.Len() == 1 && arr.Contains("SalesEngineer") {
+				salesEngineerFlag = true
+			}
+		}
+		userIds, ok := dataScope["userIds"]
+		specialFlag, userCols, orColsMap := d.checkColumnsName(dataScope, args...)
+
+		var orColumns []string
+		var orValues []interface{}
+		if ok && userIds != "-1" {
+			for _, column := range userCols {
+				if ok, _ := d.M.HasField(column); ok || specialFlag {
+					orColumns = append(orColumns, column+" IN (?) ")
+					orValues = append(orValues, userIds)
+				}
+			}
+		}
+		for col, params := range orColsMap {
+			if ok, _ := d.M.HasField(col); ok || specialFlag {
+				orColumns = append(orColumns, fmt.Sprintf(" ( %s IN (?) )", col))
+				orValues = append(orValues, params)
+			}
+		}
+
+		// 销售工程师权限加成
+		if !salesEngineerFlag {
+			var andColumns []string
+			var andValues []interface{}
+			for col, params := range dataScope {
+				if ok, _ := d.M.HasField(col); ok || specialFlag {
+					andColumns = append(andColumns, fmt.Sprintf(" ( %s IN (?) )", col))
+					andValues = append(andValues, params)
+				}
+			}
+			if len(andColumns) > 0 {
+				andWhereSql := strings.Join(andColumns, " AND ")
+				orColumns = append(orColumns, "("+andWhereSql+")")
+				orValues = append(orValues, andValues...)
+			}
+		}
+
+		whereSql := strings.Join(orColumns, " OR ")
+		return &BaseDistributorRecordDao{M: d.M.Where(whereSql, orValues...).Ctx(ctx), Table: d.Table, TableAs: d.TableAs}
+	}
+	return d
+}
+
+// args 1、字段
+// args 2、字段、表名
+// args 3、字段对应关系
+func (d *BaseDistributorRecordDao) checkColumnsName(dataScope map[string]interface{}, args ...interface{}) (bool, []string, map[string]interface{}) {
+	var userCols []string
+	tableAs, specialFlag := "", false
+	orColsMap, colsContrast := map[string]interface{}{}, map[string]interface{}{}
+
+	if d.TableAs != "" && len(args) <= 1 {
+		tableAs = d.TableAs + "."
+	}
+	if len(args) > 1 {
+		specialFlag = true
+		if val, ok := args[1].(string); ok {
+			tableAs = val + "."
+		}
+	}
+	if len(args) > 0 {
+		userCols = []string{"created_by"}
+		if column, ok := args[0].(string); ok {
+			userCols = []string{tableAs + column}
+		}
+		if cols, ok := args[0].([]string); ok {
+			for _, v := range cols {
+				userCols = append(userCols, tableAs+v)
+			}
+		}
+		if val, ok := args[0].(map[string]interface{}); ok {
+			specialFlag = true
+			colsContrast = val
+			if orcols, ok := val["orcols"]; ok {
+				if col, ok := orcols.(string); ok && gconv.String(val[col]) != "" {
+					orColsMap[col] = val[col]
+					delete(colsContrast, col)
+				}
+				if cols, ok := orcols.([]string); ok {
+					for _, col := range cols {
+						if gconv.String(val[col]) == "" {
+							continue
+						}
+						orColsMap[col] = val[col]
+						delete(colsContrast, col)
+					}
+				}
+			}
+			delete(colsContrast, "orcols")
+		}
+	}
+	bigColumns := "is_big"
+	if isBig, ok := dataScope[bigColumns]; ok {
+		if bigCol, ok := colsContrast[bigColumns]; ok {
+			orColsMap[bigCol.(string)] = isBig
+			delete(colsContrast, bigCol.(string))
+		} else {
+			if ok, _ := d.M.HasField(bigColumns); ok && specialFlag {
+				orColsMap[tableAs+bigColumns] = isBig
+			}
+		}
+	}
+
+	delete(dataScope, "userIds")
+	delete(dataScope, "roles")
+	delete(dataScope, "posts")
+	delete(dataScope, bigColumns)
+	if len(colsContrast) > 0 {
+		for k, v := range dataScope {
+			if data, ok := colsContrast[k]; ok {
+				dataScope[data.(string)] = v
+			}
+			delete(dataScope, k)
+			delete(colsContrast, k)
+		}
+		for k, v := range colsContrast {
+			dataScope[k] = v
+		}
+	}
+	return specialFlag, userCols, orColsMap
+}

+ 833 - 0
opms_parent/app/dao/base/internal/base_distributor_target.go

@@ -0,0 +1,833 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
+// ==========================================================================
+
+package internal
+
+import (
+	"context"
+	"database/sql"
+	"fmt"
+	"github.com/gogf/gf/container/garray"
+	"github.com/gogf/gf/database/gdb"
+	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/frame/gmvc"
+	"github.com/gogf/gf/util/gconv"
+	"strings"
+	"time"
+
+	model "dashoo.cn/micro/app/model/base"
+)
+
+// BaseDistributorTargetDao is the manager for logic model data accessing and custom defined data operations functions management.
+type BaseDistributorTargetDao struct {
+	gmvc.M                               // M is the core and embedded struct that inherits all chaining operations from gdb.Model.
+	C       baseDistributorTargetColumns // C is the short type for Columns, which contains all the column names of Table for convenient usage.
+	DB      gdb.DB                       // DB is the raw underlying database management object.
+	Table   string                       // Table is the underlying table name of the DAO.
+	TableAs string                       // TableAs is the underlying table alias name of the DAO.
+}
+
+// BaseDistributorTargetColumns defines and stores column names for table base_distributor_target.
+type baseDistributorTargetColumns struct {
+	Id          string // 主键
+	DistId      string // 所属经销商
+	Year        string // 年度
+	Q1          string // q1指标(万元)
+	Q2          string // q2指标(万元)
+	Q3          string // q3指标(万元)
+	Q4          string // q4指标(万元)
+	Total       string // 年度指标(万元)
+	Remark      string // 备注
+	CreatedBy   string // 创建者
+	CreatedName string // 创建人
+	CreatedTime string // 创建时间
+	UpdatedBy   string // 更新者
+	UpdatedName string // 更新人
+	UpdatedTime string // 更新时间
+	DeletedTime string // 删除时间
+}
+
+var (
+	// BaseDistributorTarget is globally public accessible object for table base_distributor_target operations.
+	BaseDistributorTarget = BaseDistributorTargetDao{
+		M:     g.DB("default").Model("base_distributor_target").Safe(),
+		DB:    g.DB("default"),
+		Table: "base_distributor_target",
+		C: baseDistributorTargetColumns{
+			Id:          "id",
+			DistId:      "dist_id",
+			Year:        "year",
+			Q1:          "q1",
+			Q2:          "q2",
+			Q3:          "q3",
+			Q4:          "q4",
+			Total:       "total",
+			Remark:      "remark",
+			CreatedBy:   "created_by",
+			CreatedName: "created_name",
+			CreatedTime: "created_time",
+			UpdatedBy:   "updated_by",
+			UpdatedName: "updated_name",
+			UpdatedTime: "updated_time",
+			DeletedTime: "deleted_time",
+		},
+	}
+)
+
+func NewBaseDistributorTargetDao(tenant string) BaseDistributorTargetDao {
+	var dao BaseDistributorTargetDao
+	dao = BaseDistributorTargetDao{
+		M:     g.DB(tenant).Model("base_distributor_target").Safe(),
+		DB:    g.DB(tenant),
+		Table: "base_distributor_target",
+		C: baseDistributorTargetColumns{
+			Id:          "id",
+			DistId:      "dist_id",
+			Year:        "year",
+			Q1:          "q1",
+			Q2:          "q2",
+			Q3:          "q3",
+			Q4:          "q4",
+			Total:       "total",
+			Remark:      "remark",
+			CreatedBy:   "created_by",
+			CreatedName: "created_name",
+			CreatedTime: "created_time",
+			UpdatedBy:   "updated_by",
+			UpdatedName: "updated_name",
+			UpdatedTime: "updated_time",
+			DeletedTime: "deleted_time",
+		},
+	}
+	return dao
+}
+
+// Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
+// of current DB object and with given context in it.
+// Note that this returned DB object can be used only once, so do not assign it to
+// a global or package variable for long using.
+func (d *BaseDistributorTargetDao) Ctx(ctx context.Context) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Ctx(ctx), Table: d.Table, TableAs: d.TableAs}
+}
+
+// GetCtx returns the context for current Model.
+// It returns "context.Background() i"s there's no context previously set.
+func (d *BaseDistributorTargetDao) GetCtx() context.Context {
+	return d.M.GetCtx()
+}
+
+// As sets an alias name for current table.
+func (d *BaseDistributorTargetDao) As(as string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.As(as), Table: d.Table, TableAs: as}
+}
+
+// TX sets the transaction for current operation.
+func (d *BaseDistributorTargetDao) TX(tx *gdb.TX) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.TX(tx), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Master marks the following operation on master node.
+func (d *BaseDistributorTargetDao) Master() *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Master(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Slave marks the following operation on slave node.
+// Note that it makes sense only if there's any slave node configured.
+func (d *BaseDistributorTargetDao) Slave() *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Slave(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Args sets custom arguments for model operation.
+func (d *BaseDistributorTargetDao) Args(args ...interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Args(args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Handler calls each of "handlers" on current Model and returns a new Model.
+// ModelHandler is a function that handles given Model and returns a new Model that is custom modified.
+func (d *BaseDistributorTargetDao) Handler(handlers ...gdb.ModelHandler) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Handler(handlers...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *BaseDistributorTargetDao) LeftJoin(table ...string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.LeftJoin(table...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *BaseDistributorTargetDao) RightJoin(table ...string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.RightJoin(table...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *BaseDistributorTargetDao) InnerJoin(table ...string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.InnerJoin(table...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Fields sets the operation fields of the model, multiple fields joined using char ','.
+// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
+func (d *BaseDistributorTargetDao) Fields(fieldNamesOrMapStruct ...interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Fields(fieldNamesOrMapStruct...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
+// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
+func (d *BaseDistributorTargetDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldCount formats and appends commonly used field "COUNT(column)" to the select fields of model.
+func (d *BaseDistributorTargetDao) FieldCount(column string, as ...string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.FieldCount(column, as...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldSum formats and appends commonly used field "SUM(column)" to the select fields of model.
+func (d *BaseDistributorTargetDao) FieldSum(column string, as ...string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.FieldSum(column, as...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldMin formats and appends commonly used field "MIN(column)" to the select fields of model.
+func (d *BaseDistributorTargetDao) FieldMin(column string, as ...string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.FieldMin(column, as...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldMax formats and appends commonly used field "MAX(column)" to the select fields of model.
+func (d *BaseDistributorTargetDao) FieldMax(column string, as ...string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.FieldMax(column, as...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// FieldAvg formats and appends commonly used field "AVG(column)" to the select fields of model.
+func (d *BaseDistributorTargetDao) FieldAvg(column string, as ...string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.FieldAvg(column, as...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Option adds extra operation option for the model.
+// Deprecated, use separate operations instead.
+func (d *BaseDistributorTargetDao) Option(option int) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Option(option), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
+// the data and where attributes for empty values.
+func (d *BaseDistributorTargetDao) OmitEmpty() *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.OmitEmpty(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitEmptyWhere sets optionOmitEmptyWhere option for the model, which automatically filers
+// the Where/Having parameters for "empty" values.
+func (d *BaseDistributorTargetDao) OmitEmptyWhere() *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.OmitEmptyWhere(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitEmptyData sets optionOmitEmptyData option for the model, which automatically filers
+// the Data parameters for "empty" values.
+func (d *BaseDistributorTargetDao) OmitEmptyData() *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.OmitEmptyData(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitNil sets optionOmitNil option for the model, which automatically filers
+// the data and where parameters for "nil" values.
+func (d *BaseDistributorTargetDao) OmitNil() *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.OmitNil(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitNilWhere sets optionOmitNilWhere option for the model, which automatically filers
+// the Where/Having parameters for "nil" values.
+func (d *BaseDistributorTargetDao) OmitNilWhere() *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.OmitNilWhere(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OmitNilData sets optionOmitNilData option for the model, which automatically filers
+// the Data parameters for "nil" values.
+func (d *BaseDistributorTargetDao) OmitNilData() *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.OmitNilData(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Filter marks filtering the fields which does not exist in the fields of the operated table.
+// Note that this function supports only single table operations.
+// Deprecated, filter feature is automatically enabled from GoFrame v1.16.0, it is so no longer used.
+func (d *BaseDistributorTargetDao) Filter() *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Filter(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Where sets the condition statement for the model. The parameter <where> can be type of
+// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
+// multiple conditions will be joined into where statement using "AND".
+// Eg:
+// Where("uid=10000")
+// Where("uid", 10000)
+// Where("money>? AND name like ?", 99999, "vip_%")
+// Where("uid", 1).Where("name", "john")
+// Where("status IN (?)", g.Slice{1,2,3})
+// Where("age IN(?,?)", 18, 50)
+// Where(User{ Id : 1, UserName : "john"})
+func (d *BaseDistributorTargetDao) Where(where interface{}, args ...interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Where(where, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WherePri does the same logic as M.Where except that if the parameter <where>
+// is a single condition like int/string/float/slice, it treats the condition as the primary
+// key value. That is, if primary key is "id" and given <where> parameter as "123", the
+// WherePri function treats the condition as "id=123", but M.Where treats the condition
+// as string "123".
+func (d *BaseDistributorTargetDao) WherePri(where interface{}, args ...interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WherePri(where, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Having sets the having statement for the model.
+// The parameters of this function usage are as the same as function Where.
+// See Where.
+func (d *BaseDistributorTargetDao) Having(having interface{}, args ...interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Having(having, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Wheref builds condition string using fmt.Sprintf and arguments.
+// Note that if the number of "args" is more than the place holder in "format",
+// the extra "args" will be used as the where condition arguments of the Model.
+func (d *BaseDistributorTargetDao) Wheref(format string, args ...interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Wheref(format, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereLT builds "column < value" statement.
+func (d *BaseDistributorTargetDao) WhereLT(column string, value interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereLT(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereLTE builds "column <= value" statement.
+func (d *BaseDistributorTargetDao) WhereLTE(column string, value interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereLTE(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereGT builds "column > value" statement.
+func (d *BaseDistributorTargetDao) WhereGT(column string, value interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereGT(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereGTE builds "column >= value" statement.
+func (d *BaseDistributorTargetDao) WhereGTE(column string, value interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereGTE(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereBetween builds "column BETWEEN min AND max" statement.
+func (d *BaseDistributorTargetDao) WhereBetween(column string, min, max interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereLike builds "column LIKE like" statement.
+func (d *BaseDistributorTargetDao) WhereLike(column string, like interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereLike(column, like), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereIn builds "column IN (in)" statement.
+func (d *BaseDistributorTargetDao) WhereIn(column string, in interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereIn(column, in), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNull builds "columns[0] IS NULL AND columns[1] IS NULL ..." statement.
+func (d *BaseDistributorTargetDao) WhereNull(columns ...string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereNull(columns...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNotBetween builds "column NOT BETWEEN min AND max" statement.
+func (d *BaseDistributorTargetDao) WhereNotBetween(column string, min, max interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereNotBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNotLike builds "column NOT LIKE like" statement.
+func (d *BaseDistributorTargetDao) WhereNotLike(column string, like interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereNotLike(column, like), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNot builds "column != value" statement.
+func (d *BaseDistributorTargetDao) WhereNot(column string, value interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereNot(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNotIn builds "column NOT IN (in)" statement.
+func (d *BaseDistributorTargetDao) WhereNotIn(column string, in interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereNotIn(column, in), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereNotNull builds "columns[0] IS NOT NULL AND columns[1] IS NOT NULL ..." statement.
+func (d *BaseDistributorTargetDao) WhereNotNull(columns ...string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereNotNull(columns...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOr adds "OR" condition to the where statement.
+func (d *BaseDistributorTargetDao) WhereOr(where interface{}, args ...interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereOr(where, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrf builds "OR" condition string using fmt.Sprintf and arguments.
+func (d *BaseDistributorTargetDao) WhereOrf(format string, args ...interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereOrf(format, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrLT builds "column < value" statement in "OR" conditions..
+func (d *BaseDistributorTargetDao) WhereOrLT(column string, value interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereOrLT(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrLTE builds "column <= value" statement in "OR" conditions..
+func (d *BaseDistributorTargetDao) WhereOrLTE(column string, value interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereOrLTE(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrGT builds "column > value" statement in "OR" conditions..
+func (d *BaseDistributorTargetDao) WhereOrGT(column string, value interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereOrGT(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrGTE builds "column >= value" statement in "OR" conditions..
+func (d *BaseDistributorTargetDao) WhereOrGTE(column string, value interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereOrGTE(column, value), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrBetween builds "column BETWEEN min AND max" statement in "OR" conditions.
+func (d *BaseDistributorTargetDao) WhereOrBetween(column string, min, max interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereOrBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrLike builds "column LIKE like" statement in "OR" conditions.
+func (d *BaseDistributorTargetDao) WhereOrLike(column string, like interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereOrLike(column, like), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrIn builds "column IN (in)" statement in "OR" conditions.
+func (d *BaseDistributorTargetDao) WhereOrIn(column string, in interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereOrIn(column, in), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrNull builds "columns[0] IS NULL OR columns[1] IS NULL ..." statement in "OR" conditions.
+func (d *BaseDistributorTargetDao) WhereOrNull(columns ...string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereOrNull(columns...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrNotBetween builds "column NOT BETWEEN min AND max" statement in "OR" conditions.
+func (d *BaseDistributorTargetDao) WhereOrNotBetween(column string, min, max interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereOrNotBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrNotLike builds "column NOT LIKE like" statement in "OR" conditions.
+func (d *BaseDistributorTargetDao) WhereOrNotLike(column string, like interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereOrNotLike(column, like), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrNotIn builds "column NOT IN (in)" statement.
+func (d *BaseDistributorTargetDao) WhereOrNotIn(column string, in interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereOrNotIn(column, in), Table: d.Table, TableAs: d.TableAs}
+}
+
+// WhereOrNotNull builds "columns[0] IS NOT NULL OR columns[1] IS NOT NULL ..." statement in "OR" conditions.
+func (d *BaseDistributorTargetDao) WhereOrNotNull(columns ...string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.WhereOrNotNull(columns...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Group sets the "GROUP BY" statement for the model.
+func (d *BaseDistributorTargetDao) Group(groupBy ...string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Group(groupBy...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// And adds "AND" condition to the where statement.
+// Deprecated, use Where instead.
+func (d *BaseDistributorTargetDao) And(where interface{}, args ...interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.And(where, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Or adds "OR" condition to the where statement.
+// Deprecated, use WhereOr instead.
+func (d *BaseDistributorTargetDao) Or(where interface{}, args ...interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Or(where, args...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// GroupBy sets the "GROUP BY" statement for the model.
+func (d *BaseDistributorTargetDao) GroupBy(groupBy string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Group(groupBy), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Order sets the "ORDER BY" statement for the model.
+func (d *BaseDistributorTargetDao) Order(orderBy ...string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Order(orderBy...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OrderAsc sets the "ORDER BY xxx ASC" statement for the model.
+func (d *BaseDistributorTargetDao) OrderAsc(column string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.OrderAsc(column), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OrderDesc sets the "ORDER BY xxx DESC" statement for the model.
+func (d *BaseDistributorTargetDao) OrderDesc(column string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.OrderDesc(column), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OrderRandom sets the "ORDER BY RANDOM()" statement for the model.
+func (d *BaseDistributorTargetDao) OrderRandom() *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.OrderRandom(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// OrderBy is alias of Model.Order.
+// See Model.Order.
+// Deprecated, use Order instead.
+func (d *BaseDistributorTargetDao) OrderBy(orderBy string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Order(orderBy), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Limit sets the "LIMIT" statement for the model.
+// The parameter <limit> can be either one or two number, if passed two number is passed,
+// it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
+// statement.
+func (d *BaseDistributorTargetDao) Limit(limit ...int) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Limit(limit...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Offset sets the "OFFSET" statement for the model.
+// It only makes sense for some databases like SQLServer, PostgreSQL, etc.
+func (d *BaseDistributorTargetDao) Offset(offset int) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Offset(offset), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Distinct forces the query to only return distinct results.
+func (d *BaseDistributorTargetDao) Distinct() *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Distinct(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Page sets the paging number for the model.
+// The parameter <page> is started from 1 for paging.
+// Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
+func (d *BaseDistributorTargetDao) Page(page, limit int) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Page(page, limit), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Batch sets the batch operation number for the model.
+func (d *BaseDistributorTargetDao) Batch(batch int) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Batch(batch), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Cache sets the cache feature for the model. It caches the result of the sql, which means
+// if there's another same sql request, it just reads and returns the result from cache, it
+// but not committed and executed into the database.
+//
+// If the parameter <duration> < 0, which means it clear the cache with given <name>.
+// If the parameter <duration> = 0, which means it never expires.
+// If the parameter <duration> > 0, which means it expires after <duration>.
+//
+// The optional parameter <name> is used to bind a name to the cache, which means you can later
+// control the cache like changing the <duration> or clearing the cache with specified <name>.
+//
+// Note that, the cache feature is disabled if the model is operating on a transaction.
+func (d *BaseDistributorTargetDao) Cache(duration time.Duration, name ...string) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Cache(duration, name...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Data sets the operation data for the model.
+// The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
+// Eg:
+// Data("uid=10000")
+// Data("uid", 10000)
+// Data(g.Map{"uid": 10000, "name":"john"})
+// Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
+func (d *BaseDistributorTargetDao) Data(data ...interface{}) *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Data(data...), Table: d.Table, TableAs: d.TableAs}
+}
+
+// All does "SELECT FROM ..." statement for the model.
+// It retrieves the records from table and returns the result as []*model.BaseDistributorTarget.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of M.Where function,
+// see M.Where.
+func (d *BaseDistributorTargetDao) All(where ...interface{}) ([]*model.BaseDistributorTarget, error) {
+	all, err := d.M.All(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*model.BaseDistributorTarget
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// One retrieves one record from table and returns the result as *model.BaseDistributorTarget.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of M.Where function,
+// see M.Where.
+func (d *BaseDistributorTargetDao) One(where ...interface{}) (*model.BaseDistributorTarget, error) {
+	one, err := d.M.One(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *model.BaseDistributorTarget
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindOne retrieves and returns a single Record by M.WherePri and M.One.
+// Also see M.WherePri and M.One.
+func (d *BaseDistributorTargetDao) FindOne(where ...interface{}) (*model.BaseDistributorTarget, error) {
+	one, err := d.M.FindOne(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *model.BaseDistributorTarget
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindAll retrieves and returns Result by by M.WherePri and M.All.
+// Also see M.WherePri and M.All.
+func (d *BaseDistributorTargetDao) FindAll(where ...interface{}) ([]*model.BaseDistributorTarget, error) {
+	all, err := d.M.FindAll(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*model.BaseDistributorTarget
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// Struct retrieves one record from table and converts it into given struct.
+// The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
+// it can create the struct internally during converting.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
+// from table and <pointer> is not nil.
+//
+// Eg:
+// user := new(User)
+// err  := dao.User.Where("id", 1).Struct(user)
+//
+// user := (*User)(nil)
+// err  := dao.User.Where("id", 1).Struct(&user)
+func (d *BaseDistributorTargetDao) Struct(pointer interface{}, where ...interface{}) error {
+	return d.M.Struct(pointer, where...)
+}
+
+// Structs retrieves records from table and converts them into given struct slice.
+// The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
+// slice internally during converting.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
+// from table and <pointer> is not empty.
+//
+// Eg:
+// users := ([]User)(nil)
+// err   := dao.User.Structs(&users)
+//
+// users := ([]*User)(nil)
+// err   := dao.User.Structs(&users)
+func (d *BaseDistributorTargetDao) Structs(pointer interface{}, where ...interface{}) error {
+	return d.M.Structs(pointer, where...)
+}
+
+// Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
+// It calls function Struct if <pointer> is type of *struct/**struct.
+// It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
+//
+// Eg:
+// user  := new(User)
+// err   := dao.User.Where("id", 1).Scan(user)
+//
+// user  := (*User)(nil)
+// err   := dao.User.Where("id", 1).Scan(&user)
+//
+// users := ([]User)(nil)
+// err   := dao.User.Scan(&users)
+//
+// users := ([]*User)(nil)
+// err   := dao.User.Scan(&users)
+func (d *BaseDistributorTargetDao) Scan(pointer interface{}, where ...interface{}) error {
+	return d.M.Scan(pointer, where...)
+}
+
+// Chunk iterates the table with given size and callback function.
+func (d *BaseDistributorTargetDao) Chunk(limit int, callback func(entities []*model.BaseDistributorTarget, err error) bool) {
+	d.M.Chunk(limit, func(result gdb.Result, err error) bool {
+		var entities []*model.BaseDistributorTarget
+		err = result.Structs(&entities)
+		if err == sql.ErrNoRows {
+			return false
+		}
+		return callback(entities, err)
+	})
+}
+
+// LockUpdate sets the lock for update for current operation.
+func (d *BaseDistributorTargetDao) LockUpdate() *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.LockUpdate(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// LockShared sets the lock in share mode for current operation.
+func (d *BaseDistributorTargetDao) LockShared() *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.LockShared(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// Unscoped enables/disables the soft deleting feature.
+func (d *BaseDistributorTargetDao) Unscoped() *BaseDistributorTargetDao {
+	return &BaseDistributorTargetDao{M: d.M.Unscoped(), Table: d.Table, TableAs: d.TableAs}
+}
+
+// DataScope enables the DataScope feature.
+func (d *BaseDistributorTargetDao) DataScope(ctx context.Context, args ...interface{}) *BaseDistributorTargetDao {
+	cs := ctx.Value("contextService")
+	dataScope := gconv.Map(gconv.String(gconv.Map(cs)["dataScope"]))
+	if dataScope != nil {
+		// 销售工程师判断
+		var salesEngineerFlag bool
+		if roles, ok := dataScope["roles"]; ok {
+			arr := garray.NewArrayFrom(roles.([]interface{}), true)
+			if arr.Len() == 1 && arr.Contains("SalesEngineer") {
+				salesEngineerFlag = true
+			}
+		}
+		userIds, ok := dataScope["userIds"]
+		specialFlag, userCols, orColsMap := d.checkColumnsName(dataScope, args...)
+
+		var orColumns []string
+		var orValues []interface{}
+		if ok && userIds != "-1" {
+			for _, column := range userCols {
+				if ok, _ := d.M.HasField(column); ok || specialFlag {
+					orColumns = append(orColumns, column+" IN (?) ")
+					orValues = append(orValues, userIds)
+				}
+			}
+		}
+		for col, params := range orColsMap {
+			if ok, _ := d.M.HasField(col); ok || specialFlag {
+				orColumns = append(orColumns, fmt.Sprintf(" ( %s IN (?) )", col))
+				orValues = append(orValues, params)
+			}
+		}
+
+		// 销售工程师权限加成
+		if !salesEngineerFlag {
+			var andColumns []string
+			var andValues []interface{}
+			for col, params := range dataScope {
+				if ok, _ := d.M.HasField(col); ok || specialFlag {
+					andColumns = append(andColumns, fmt.Sprintf(" ( %s IN (?) )", col))
+					andValues = append(andValues, params)
+				}
+			}
+			if len(andColumns) > 0 {
+				andWhereSql := strings.Join(andColumns, " AND ")
+				orColumns = append(orColumns, "("+andWhereSql+")")
+				orValues = append(orValues, andValues...)
+			}
+		}
+
+		whereSql := strings.Join(orColumns, " OR ")
+		return &BaseDistributorTargetDao{M: d.M.Where(whereSql, orValues...).Ctx(ctx), Table: d.Table, TableAs: d.TableAs}
+	}
+	return d
+}
+
+// args 1、字段
+// args 2、字段、表名
+// args 3、字段对应关系
+func (d *BaseDistributorTargetDao) checkColumnsName(dataScope map[string]interface{}, args ...interface{}) (bool, []string, map[string]interface{}) {
+	var userCols []string
+	tableAs, specialFlag := "", false
+	orColsMap, colsContrast := map[string]interface{}{}, map[string]interface{}{}
+
+	if d.TableAs != "" && len(args) <= 1 {
+		tableAs = d.TableAs + "."
+	}
+	if len(args) > 1 {
+		specialFlag = true
+		if val, ok := args[1].(string); ok {
+			tableAs = val + "."
+		}
+	}
+	if len(args) > 0 {
+		userCols = []string{"created_by"}
+		if column, ok := args[0].(string); ok {
+			userCols = []string{tableAs + column}
+		}
+		if cols, ok := args[0].([]string); ok {
+			for _, v := range cols {
+				userCols = append(userCols, tableAs+v)
+			}
+		}
+		if val, ok := args[0].(map[string]interface{}); ok {
+			specialFlag = true
+			colsContrast = val
+			if orcols, ok := val["orcols"]; ok {
+				if col, ok := orcols.(string); ok && gconv.String(val[col]) != "" {
+					orColsMap[col] = val[col]
+					delete(colsContrast, col)
+				}
+				if cols, ok := orcols.([]string); ok {
+					for _, col := range cols {
+						if gconv.String(val[col]) == "" {
+							continue
+						}
+						orColsMap[col] = val[col]
+						delete(colsContrast, col)
+					}
+				}
+			}
+			delete(colsContrast, "orcols")
+		}
+	}
+	bigColumns := "is_big"
+	if isBig, ok := dataScope[bigColumns]; ok {
+		if bigCol, ok := colsContrast[bigColumns]; ok {
+			orColsMap[bigCol.(string)] = isBig
+			delete(colsContrast, bigCol.(string))
+		} else {
+			if ok, _ := d.M.HasField(bigColumns); ok && specialFlag {
+				orColsMap[tableAs+bigColumns] = isBig
+			}
+		}
+	}
+
+	delete(dataScope, "userIds")
+	delete(dataScope, "roles")
+	delete(dataScope, "posts")
+	delete(dataScope, bigColumns)
+	if len(colsContrast) > 0 {
+		for k, v := range dataScope {
+			if data, ok := colsContrast[k]; ok {
+				dataScope[data.(string)] = v
+			}
+			delete(dataScope, k)
+			delete(colsContrast, k)
+		}
+		for k, v := range colsContrast {
+			dataScope[k] = v
+		}
+	}
+	return specialFlag, userCols, orColsMap
+}

+ 127 - 2
opms_parent/app/handler/base/distributor.go

@@ -9,12 +9,15 @@ import (
 	"github.com/gogf/gf/util/gvalid"
 
 	model "dashoo.cn/micro/app/model/base"
+	contractmodel "dashoo.cn/micro/app/model/contract"
+	projmodel "dashoo.cn/micro/app/model/proj"
 	server "dashoo.cn/micro/app/service/base"
 )
 
 type DistributorHandler struct{}
 
 // GetList 获取列表
+// Swagger:Distributor 经销商代理商 查询
 func (p *DistributorHandler) GetList(ctx context.Context, req *model.BaseDistributorSearchReq, rsp *comm_def.CommonMsg) error {
 	distributorServer, err := server.NewDistributorService(ctx)
 	if err != nil {
@@ -30,7 +33,7 @@ func (p *DistributorHandler) GetList(ctx context.Context, req *model.BaseDistrib
 	return nil
 }
 
-// Create 创建
+// Swagger:Distributor 经销商代理商 新增
 func (p *DistributorHandler) Create(ctx context.Context, req *model.AddDistributor, rsp *comm_def.CommonMsg) error {
 	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
 		return err
@@ -63,7 +66,7 @@ func (p *DistributorHandler) GetEntityById(ctx context.Context, req *comm_def.Id
 	return nil
 }
 
-// UpdateById 编辑
+// Swagger:Distributor 经销商代理商 修改
 func (p *DistributorHandler) UpdateById(ctx context.Context, req *model.UpdateDistributorReq, rsp *comm_def.CommonMsg) error {
 	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
 		return err
@@ -79,6 +82,75 @@ func (p *DistributorHandler) UpdateById(ctx context.Context, req *model.UpdateDi
 	return nil
 }
 
+// Swagger:Distributor 经销商代理商 转为代理商
+func (p *DistributorHandler) ToProxy(ctx context.Context, req *model.DistributorToProxyReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("DistributorHandler.ToProxy request %#v ", *req)
+	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
+		return err
+	}
+	distributorServer, err := server.NewDistributorService(ctx)
+	if err != nil {
+		return err
+	}
+	err = distributorServer.ToProxy(ctx, req)
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// Swagger:Distributor 经销商代理商 续签
+func (p *DistributorHandler) Renew(ctx context.Context, req *model.DistributorRenewReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("DistributorHandler.Renew request %#v ", *req)
+	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
+		return err
+	}
+	distributorServer, err := server.NewDistributorService(ctx)
+	if err != nil {
+		return err
+	}
+	err = distributorServer.Renew(ctx, req)
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// Swagger:Distributor 经销商代理商 转为经销商
+func (p *DistributorHandler) ToDist(ctx context.Context, req *model.DistributorToDistReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("DistributorHandler.ToDist request %#v ", *req)
+	if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
+		return err
+	}
+	distributorServer, err := server.NewDistributorService(ctx)
+	if err != nil {
+		return err
+	}
+	err = distributorServer.ToDist(ctx, req)
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// Swagger:Distributor 经销商代理商 历史代理
+func (c *DistributorHandler) TransRecord(ctx context.Context, req *model.DistributorTransRecordReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("DistributorHandler.TransRecord request %#v ", *req)
+	s, err := server.NewDistributorService(ctx)
+	if err != nil {
+		return err
+	}
+	total, ent, err := s.TransRecord(ctx, req)
+	if err != nil {
+		return err
+	}
+	if ent == nil {
+		ent = []*model.BaseDistributorRecord{}
+	}
+	rsp.Data = g.Map{"list": ent, "total": total}
+	return nil
+}
+
 // DeleteByIds 删掉
 func (p *DistributorHandler) DeleteByIds(ctx context.Context, req *model.DeleteDistributorReq, rsp *comm_def.CommonMsg) error {
 	distributorServer, err := server.NewDistributorService(ctx)
@@ -92,3 +164,56 @@ func (p *DistributorHandler) DeleteByIds(ctx context.Context, req *model.DeleteD
 	}
 	return nil
 }
+
+// Swagger:Distributor 经销商代理商 项目列表
+func (c *DistributorHandler) ProjectList(ctx context.Context, req *model.DistributorProjectListReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("DistributorHandler.ProjectList request %#v ", *req)
+	s, err := server.NewDistributorService(ctx)
+	if err != nil {
+		return err
+	}
+	total, ent, err := s.ProjectList(ctx, req)
+	if err != nil {
+		return err
+	}
+	if ent == nil {
+		ent = []*projmodel.ProjBusiness{}
+	}
+	rsp.Data = g.Map{"list": ent, "total": total}
+	return nil
+}
+
+// Swagger:Distributor 经销商代理商 合同列表
+func (c *DistributorHandler) ContractList(ctx context.Context, req *model.DistributorContractListReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("DistributorHandler.ContractList request %#v ", *req)
+	s, err := server.NewDistributorService(ctx)
+	if err != nil {
+		return err
+	}
+	total, ent, err := s.ContractList(ctx, req)
+	if err != nil {
+		return err
+	}
+	if ent == nil {
+		ent = []*contractmodel.CtrContractListRsp{}
+	}
+	rsp.Data = g.Map{"list": ent, "total": total}
+	return nil
+}
+
+func (c *DistributorHandler) DynamicsList(ctx context.Context, req *model.DistributorDynamicsListReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("DistributorHandler.GetDynamicsList request %#v ", *req)
+	s, err := server.NewDistributorService(ctx)
+	if err != nil {
+		return err
+	}
+	total, ent, err := s.DynamicsList(ctx, req)
+	if err != nil {
+		return err
+	}
+	if ent == nil {
+		ent = []*model.BaseDistributorDynamics{}
+	}
+	rsp.Data = g.Map{"list": ent, "total": total}
+	return nil
+}

+ 76 - 0
opms_parent/app/handler/base/distributor_contact.go

@@ -0,0 +1,76 @@
+package base
+
+import (
+	"context"
+	model "dashoo.cn/micro/app/model/base"
+	service "dashoo.cn/micro/app/service/base"
+
+	"dashoo.cn/common_definition/comm_def"
+	"github.com/gogf/gf/frame/g"
+)
+
+type BaseDistributorContact struct{}
+
+// Swagger:DistributorContact 经销商代理商联系人 查询
+func (c *BaseDistributorContact) List(ctx context.Context, req *model.BaseDistributorContactListReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("BaseDistributorContact.List request %#v ", *req)
+	s, err := service.NewBaseDistributorContactService(ctx)
+	if err != nil {
+		return err
+	}
+	total, ent, err := s.List(ctx, req)
+	if err != nil {
+		return err
+	}
+	if ent == nil {
+		ent = []*model.BaseDistributorContact{}
+	}
+	rsp.Data = map[string]interface{}{
+		"total": total,
+		"list":  ent,
+	}
+	return nil
+}
+
+// Swagger:DistributorContact 经销商代理商联系人 新增
+func (c *BaseDistributorContact) Add(ctx context.Context, req *model.BaseDistributorContactAddReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("BaseDistributorContact.Add request %#v ", *req)
+	s, err := service.NewBaseDistributorContactService(ctx)
+	if err != nil {
+		return err
+	}
+	id, err := s.Add(ctx, req)
+	if err != nil {
+		return err
+	}
+	rsp.Data = id
+	return nil
+}
+
+// Swagger:DistributorContact 经销商代理商联系人 更新
+func (c *BaseDistributorContact) Update(ctx context.Context, req *model.BaseDistributorContactUpdateReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("BaseDistributorContact.Update request %#v ", *req)
+	s, err := service.NewBaseDistributorContactService(ctx)
+	if err != nil {
+		return err
+	}
+	err = s.Update(ctx, req)
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// Swagger:DistributorContact 经销商代理商联系人 删除
+func (c *BaseDistributorContact) Delete(ctx context.Context, req *model.IdsReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("BaseDistributorContact.Delete request %#v ", *req)
+	s, err := service.NewBaseDistributorContactService(ctx)
+	if err != nil {
+		return err
+	}
+	err = s.Delete(ctx, req.Id)
+	if err != nil {
+		return err
+	}
+	return nil
+}

+ 73 - 0
opms_parent/app/handler/base/distributor_target.go

@@ -0,0 +1,73 @@
+package base
+
+import (
+	"context"
+	model "dashoo.cn/micro/app/model/base"
+	service "dashoo.cn/micro/app/service/base"
+
+	"dashoo.cn/common_definition/comm_def"
+	"github.com/gogf/gf/frame/g"
+)
+
+type BaseDistributorTarget struct{}
+
+// Swagger:DistributorTarget 经销商代理商指标 查询
+func (c *BaseDistributorTarget) List(ctx context.Context, req *model.BaseDistributorTargetListReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("BaseDistributorTarget.List request %#v ", *req)
+	s, err := service.NewBaseDistributorTargetService(ctx)
+	if err != nil {
+		return err
+	}
+	total, ent, err := s.List(ctx, req)
+	if ent == nil {
+		ent = []*model.BaseDistributorTargetListRsp{}
+	}
+	rsp.Data = map[string]interface{}{
+		"total": total,
+		"list":  ent,
+	}
+	return nil
+}
+
+// Swagger:DistributorTarget 经销商代理商指标 添加
+func (c *BaseDistributorTarget) Add(ctx context.Context, req *model.BaseDistributorTargetAddReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("BaseDistributorTarget.Add request %#v ", *req)
+	s, err := service.NewBaseDistributorTargetService(ctx)
+	if err != nil {
+		return err
+	}
+	id, err := s.Add(ctx, req)
+	if err != nil {
+		return err
+	}
+	rsp.Data = id
+	return nil
+}
+
+// Swagger:DistributorTarget 经销商代理商指标 更新
+func (c *BaseDistributorTarget) Update(ctx context.Context, req *model.BaseDistributorTargetUpdateReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("BaseDistributorTarget.Update request %#v ", *req)
+	s, err := service.NewBaseDistributorTargetService(ctx)
+	if err != nil {
+		return err
+	}
+	err = s.Update(ctx, req)
+	if err != nil {
+		return err
+	}
+	return nil
+}
+
+// Swagger:DistributorTarget 经销商代理商指标 删除
+func (c *BaseDistributorTarget) Delete(ctx context.Context, req *model.IdsReq, rsp *comm_def.CommonMsg) error {
+	g.Log().Infof("BaseDistributorTarget.Delete request %#v ", *req)
+	s, err := service.NewBaseDistributorTargetService(ctx)
+	if err != nil {
+		return err
+	}
+	err = s.Delete(ctx, req.Id)
+	if err != nil {
+		return err
+	}
+	return nil
+}

+ 98 - 36
opms_parent/app/model/base/base_distributor.go

@@ -16,46 +16,73 @@ type BaseDistributor internal.BaseDistributor
 
 // Fill with you ideas below.
 type BaseDistributorSearchReq struct {
-	DistCode   string   `json:"distCode"`   // 经销商code
-	DistName   string   `json:"distName"`   // 经销商名称
-	BelongSale string   `json:"belongSale"` // 所属经销商
-	ProvinceId []string `json:"provinceId"` //  省份ID
+	DistCode      string   `json:"distCode"`      // 经销商code
+	DistName      string   `json:"distName"`      // 经销商名称
+	BelongSale    string   `json:"belongSale"`    // 所属经销商
+	ProvinceId    []string `json:"provinceId"`    //  省份ID
+	DistType      string   `json:"distType"`      // 经销商类型
+	WithStatistic bool     `json:"withStatistic"` // 经销商统计
 	request.PageReq
 }
 
+type BaseDistributorStatistic struct {
+	ProjectNum       int     `json:"projectNum"`       // ABC项目总数量
+	AllProductAmount float64 `json:"allProductAmount"` // ABC项目出货总金额(项目出货金额字段)
+	SaledProjectNum  int     `json:"saledProjectNum"`  // 成交项目数量
+	SaledAmount      float64 `json:"saledAmount"`      // 成交总金额
+	UnpaidAmount     float64 `json:"unpaidAmount"`     // 未回款总金额
+	InvoicedAmount   float64 `json:"invoicedAmount"`   // 开票总金额
+}
+
+type BaseDistributorListRsp struct {
+	BaseDistributor
+	BaseDistributorStatistic
+	YearTarget float64 `json:"yearTarget"` // 年度代理指标
+}
+
 // 创建经销商字段
 type AddDistributor struct {
-	DistName      string `orm:"dist_name"       json:"distName"      v:"required#经销商名称不能为空"`                    // 经销商名称
-	AbbrName      string `orm:"abbr_name"       json:"abbrName"`                                                // 助记名
-	DistDesc      string `orm:"dist_desc"       json:"distDesc"`                                                // 经销商说明
-	DistBoss      string `orm:"dist_boss"       json:"distBoss"       v:"required#负责人不能为空" `                    // 负责人
-	DistBossPhone string `orm:"dist_boss_phone" json:"distBossPhone"  v:"required|phone#手机号不能为空|手机号格式错误"`       // 负责人电话
-	ProvinceId    int    `orm:"province_id"     json:"provinceId"     v:"required|min:1#所属省份Id不能为空|所属省份Id不能为空"` // 所属省份ID
-	ProvinceDesc  string `orm:"province_desc"   json:"provinceDesc"   v:"required#所属省份Id不能为空"`                  // 所属省份
-	BusinessScope string `orm:"business_scope"  json:"businessScope"  v:"required#业务范围不能为空"`                    // 业务范围
-	BelongSaleId  int    `orm:"belong_sale_id"  json:"belongSaleId"   v:"required|min:1#|归属销售ID不能为空"`           // 归属销售ID
-	BelongSale    string `orm:"belong_sale"     json:"belongSale"      v:"required#归属销售不能为空"`                   // 归属销售
-	InvoiceHeader string `json:"invoiceHeader"`                                                                 // 开票抬头
+	DistType         string      `json:"distType" v:"required#经销商类型不能为空"`                     // 经销商类型 10 经销商 20 代理商
+	DistName         string      `json:"distName" v:"required#经销商名称不能为空"`                     // 经销商名称
+	ProvinceId       int         `json:"provinceId" v:"required|min:1#所属省份Id不能为空|所属省份Id不能为空"` // 所属省份ID
+	ProvinceDesc     string      `json:"provinceDesc" v:"required#所属省份不能为空"`                  // 所属省份
+	Capital          float64     `json:"capital" v:"required#注册资金不能为空" `                      // 注册资金
+	BusinessScope    string      `json:"businessScope" v:"required#业务范围不能为空"`                 // 业务范围
+	CustomerType     string      `json:"customerType" v:"required#授权客户类型不能为空"`                // 授权客户类型
+	ExistedProduct   string      `json:"existedProduct"  v:"required#已有代理品牌和产品不能为空"`          // 已有代理品牌和产品
+	AbbrName         string      `json:"abbrName"`                                            // 助记名称
+	BelongSaleId     int         `json:"belongSaleId" v:"required|min:1#|归属销售ID不能为空"`         // 归属销售ID
+	BelongSale       string      `json:"belongSale" v:"required#归属销售不能为空"`                    // 归属销售
+	AssistantSaleId  string      `json:"assistantSaleId"`                                     // 助理人员Id
+	AssistantSale    string      `json:"assistantSale"`                                       // 助理人员
+	RegisterDistrict string      `json:"registerDistrict"`                                    // 注册地
+	SaleNum          int         `json:"saleNum"`                                             // 现有销售人数
+	HistoryCustomer  string      `json:"historyCustomer"`                                     // 历史合作的终端客户名称
+	ProxyStartTime   *gtime.Time `json:"proxyStartTime"`                                      // 代理签约有效期开始(代理商)
+	ProxyEndTime     *gtime.Time `json:"proxyEndTime"`                                        // 代理签约有效期结束(代理商)
+	ProxyDistrict    string      `json:"proxyDistrict"`                                       // 授权代理区域(代理商)
+	ContractUrl      string      `json:"contractUrl"`                                         // 代理合同(代理商)
+}
+
+type DistributorToProxyReq struct {
+	Id             int         `p:"id" json:"id" v:"required# id不能为空"`
+	CustomerType   string      `json:"customerType" v:"required#授权客户类型不能为空"`    // 授权客户类型
+	ProxyStartTime *gtime.Time `json:"proxyStartTime" v:"required#代理签约有效期不能为空"` // 代理签约有效期开始(代理商)
+	ProxyEndTime   *gtime.Time `json:"proxyEndTime" v:"required#代理签约有效期不能为空"`   // 代理签约有效期结束(代理商)
+	ProxyDistrict  string      `json:"proxyDistrict" v:"required#授权代理区域不能为空"`   // 授权代理区域(代理商)
+	ContractUrl    string      `json:"contractUrl"`                             // 代理合同(代理商)
 }
 
-// 列表返回字段
-type DistributorRonp struct {
-	Id            int           `orm:"id,primary"      json:"id"`            // 主健
-	DistCode      string        `orm:"dist_code"       json:"distCode"`      // 经销商编码
-	DistName      string        `orm:"dist_name"       json:"distName"`      // 经销商名字
-	AbbrName      string        `orm:"abbr_name"       json:"abbrName"`      // 助记名
-	DistBoss      string        `orm:"dist_boss"       json:"distBoss"`      // 负责人
-	DistBossPhone int           `orm:"dist_boss_phone" json:"distBossPhone"` // 负责人电话
-	BelongSale    string        `orm:"belong_sale"     json:"belongSale"`    // 销售
-	ProvinceDesc  string        `orm:"province_desc"   json:"provinceDesc"`  // 省份描述
-	ProvinceId    string        `orm:"province_id"   json:"provinceId"`      // 省份Id
-	BusinessScope string        `orm:"business_scope"  json:"businessScope"` // 业务范围
-	CreatedName   string        `orm:"created_name"    json:"createdName"`   // 创建人名字
-	CreatedTime   *gtime.Time   `orm:"created_time"    json:"createdTime"`   // 创建时间
-	DistDesc      string        `orm:"dist_desc"    json:"distDesc"`         // 说明
-	District      *BaseDistrict `orm:"with:id=province_id"`
-	//*Contanct
-	InvoiceHeader string `orm:"invoice_header"  json:"invoiceHeader"` // 开票抬头
+type DistributorRenewReq DistributorToProxyReq
+
+type DistributorToDistReq struct {
+	Id           int    `p:"id" json:"id" v:"required# id不能为空"`
+	ToDistReason string `json:"customerType" v:"required#转移原因不能为空"` // 转移经销商原因
+}
+
+type DistributorTransRecordReq struct {
+	request.PageReq
+	DistId int `json:"distId"` // ID
 }
 
 // 编辑参数
@@ -64,10 +91,45 @@ type UpdateDistributorReq struct {
 	Id int `p:"id" json:"id" v:"required# id不能为空"`
 }
 
+type DistributorDynamicsListReq struct {
+	request.PageReq
+	SearchText  string `json:"searchText"`  // 操作人,操作内容
+	DistId      int    `json:"distId"`      // ID
+	OpnPeopleId int    `json:"opnPeopleId"` // 操作人ID
+	OpnPeople   string `json:"opnPeople"`   // 操作人
+	OpnType     string `json:"opnType"`     // 操作类型
+}
+
+type DistributorProjectListReq struct {
+	request.PageReq
+	DistId           int         `json:"distId"`           // 经销商/代理商ID
+	SearchText       string      `json:"searchText"`       // 项目名称,项目名称
+	NboName          string      `json:"nboName"`          // 项目名称
+	CustName         string      `json:"custName"`         // 项目名称
+	CreatedTimeStart *gtime.Time `json:"createdTimeStart"` // 创建时间
+	CreatedTimeEnd   *gtime.Time `json:"createdTimeEnd"`   // 创建时间
+}
+
+type DistributorContractListReq struct {
+	request.PageReq
+	DistId          int    `json:"distId"`          // 经销商/代理商ID
+	SearchText      string `json:"searchText"`      // 合同编号,合同名称,客户名称,项目名称
+	ContractCode    string `json:"contractCode"`    // 合同编号
+	ContractName    string `json:"contractName"`    // 合同名称
+	CustId          int    `json:"custId"`          // 关联客户
+	CustName        string `json:"custName"`        // 客户名称
+	NboId           int    `json:"nboId"`           // 关联项目
+	NboName         string `json:"nboName"`         // 项目名称
+	ApproStatus     string `json:"approStatus"`     // 审批状态
+	ContractType    string `json:"contractType"`    // 合同类型
+	InchargeId      int    `json:"inchargeId"`      // 负责人ID
+	InchargeName    string `json:"inchargeName"`    // 负责人
+	SignatoryId     int    `json:"signatoryId"`     // 公司签约人ID
+	SignatoryName   string `json:"signatoryName"`   // 公司签约人
+	DistributorName string `json:"distributorName"` // 经销商
+}
+
 // 删除
 type DeleteDistributorReq struct {
 	Ids []int64 `p:"id" json:"ids" v:"required# id不能为空"`
 }
-type Contanct struct {
-	Name string `json:"name"` // 销售名
-}

+ 35 - 0
opms_parent/app/model/base/base_distributor_contact.go

@@ -6,9 +6,44 @@ package base
 
 import (
 	"dashoo.cn/micro/app/model/base/internal"
+	"dashoo.cn/opms_libary/request"
 )
 
 // BaseDistributorContact is the golang structure for table base_distributor_contact.
 type BaseDistributorContact internal.BaseDistributorContact
 
 // Fill with you ideas below.
+type BaseDistributorContactListReq struct {
+	request.PageReq
+	DistId int    `json:"distId"` // 所属经销商
+	Name   string `json:"name"`   // 姓名
+}
+
+type BaseDistributorContactAddReq struct {
+	DistId    int    `json:"distId" v:"required#请输入所属经销商"` // 所属经销商
+	Name      string `json:"name" v:"required#请输入联系人姓名"`   // 姓名
+	Post      string `json:"post"`                         // 岗位
+	Phone     string `json:"phone"`                        // 电话
+	Wechat    string `json:"wechat"`                       // 微信
+	Mail      string `json:"mail"`                         // 邮箱
+	Honorific string `json:"honorific"`                    // 尊称
+	Territory string `json:"territory"`                    // 负责区域/业务线
+	Remark    string `json:"remark"`                       // 备注
+}
+
+type BaseDistributorContactUpdateReq struct {
+	Id        int     `json:"id" v:"required#请输入Id"`
+	Name      string  `json:"name"`      // 姓名
+	Post      string  `json:"post"`      // 岗位
+	Phone     string  `json:"phone"`     // 电话
+	Wechat    *string `json:"wechat"`    // 微信
+	Mail      *string `json:"mail"`      // 邮箱
+	Honorific *string `json:"honorific"` // 尊称
+	Territory *string `json:"territory"` // 负责区域/业务线
+	Remark    *string `json:"remark"`
+}
+
+type IdsReq struct {
+	Id []int `json:"id"`
+}
+

+ 14 - 0
opms_parent/app/model/base/base_distributor_dynamics.go

@@ -0,0 +1,14 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. Fill this file as you wish.
+// ==========================================================================
+
+package base
+
+import (
+	"dashoo.cn/micro/app/model/base/internal"
+)
+
+// BaseDistributorDynamics is the golang structure for table base_distributor_dynamics.
+type BaseDistributorDynamics internal.BaseDistributorDynamics
+
+// Fill with you ideas below.

+ 14 - 0
opms_parent/app/model/base/base_distributor_record.go

@@ -0,0 +1,14 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. Fill this file as you wish.
+// ==========================================================================
+
+package base
+
+import (
+	"dashoo.cn/micro/app/model/base/internal"
+)
+
+// BaseDistributorRecord is the golang structure for table base_distributor_record.
+type BaseDistributorRecord internal.BaseDistributorRecord
+
+// Fill with you ideas below.

+ 52 - 0
opms_parent/app/model/base/base_distributor_target.go

@@ -0,0 +1,52 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. Fill this file as you wish.
+// ==========================================================================
+
+package base
+
+import (
+	"dashoo.cn/micro/app/model/base/internal"
+	"dashoo.cn/opms_libary/request"
+)
+
+// BaseDistributorTarget is the golang structure for table base_distributor_target.
+type BaseDistributorTarget internal.BaseDistributorTarget
+
+// Fill with you ideas below.
+type BaseDistributorTargetListReq struct {
+	request.PageReq
+	DistId int `json:"distId"` // 所属经销商
+	Year   int `json:"year"`   // 年度
+}
+
+type BaseDistributorTargetListRsp struct {
+	BaseDistributorTarget
+	BaseDistributorTargetStatistic
+}
+
+type BaseDistributorTargetAddReq struct {
+	DistId int     `json:"distId" v:"required#请输入所属经销商"` // 所属经销商
+	Year   int     `json:"year" v:"required#请输入年份"`      // 年度
+	Q1     float64 `json:"q1"`                           // q1指标(万元)
+	Q2     float64 `json:"q2"`                           // q2指标(万元)
+	Q3     float64 `json:"q3"`                           // q3指标(万元)
+	Q4     float64 `json:"q4"`                           // q4指标(万元)
+	Remark string  `json:"remark"`                       // 备注
+}
+
+type BaseDistributorTargetUpdateReq struct {
+	Id     int      `json:"id" v:"required#请输入Id"`
+	Q1     *float64 `json:"q1"` // q1指标(万元)
+	Q2     *float64 `json:"q2"` // q2指标(万元)
+	Q3     *float64 `json:"q3"` // q3指标(万元)
+	Q4     *float64 `json:"q4"` // q4指标(万元)
+	Remark *string  `json:"remark"`
+}
+
+type BaseDistributorTargetStatistic struct {
+	Q1Amount    float64 `json:"q1Amount"`
+	Q2Amount    float64 `json:"q2Amount"`
+	Q3Amount    float64 `json:"q3Amount"`
+	Q4Amount    float64 `json:"q4Amount"`
+	TotalAmount float64 `json:"totalAmount"`
+}

+ 34 - 23
opms_parent/app/model/base/internal/base_distributor.go

@@ -10,27 +10,38 @@ import (
 
 // BaseDistributor is the golang structure for table base_distributor.
 type BaseDistributor struct {
-	Id            int         `orm:"id,primary"      json:"id"`            // 主键
-	DistCode      string      `orm:"dist_code"       json:"distCode"`      // 经销商编码
-	DistName      string      `orm:"dist_name"       json:"distName"`      // 经销商名称
-	AbbrName      string      `orm:"abbr_name"       json:"abbrName"`      // 助记名
-	DistDesc      string      `orm:"dist_desc"       json:"distDesc"`      // 经销商说明
-	DistBoss      string      `orm:"dist_boss"       json:"distBoss"`      // 负责人
-	DistBossPhone string      `orm:"dist_boss_phone" json:"distBossPhone"` // 负责人电话
-	ProvinceId    int         `orm:"province_id"     json:"provinceId"`    // 所属省份ID
-	ProvinceDesc  string      `orm:"province_desc"   json:"provinceDesc"`  // 所属省份
-	BusinessScope string      `orm:"business_scope"  json:"businessScope"` // 业务范围
-	BelongSaleId  int         `orm:"belong_sale_id"  json:"belongSaleId"`  // 归属销售ID
-	BelongSale    string      `orm:"belong_sale"     json:"belongSale"`    // 归属销售
-	Capital       float64     `orm:"capital"         json:"capital"`       // 注册资金
-	SaleNum       int         `orm:"sale_num"        json:"saleNum"`       // 销售人数
-	InvoiceHeader string      `orm:"invoice_header"  json:"invoiceHeader"` // 开票抬头
-	Remark        string      `orm:"remark"          json:"remark"`        // 备注
-	CreatedBy     int         `orm:"created_by"      json:"createdBy"`     // 创建者
-	CreatedName   string      `orm:"created_name"    json:"createdName"`   // 创建人
-	CreatedTime   *gtime.Time `orm:"created_time"    json:"createdTime"`   // 创建时间
-	UpdatedBy     int         `orm:"updated_by"      json:"updatedBy"`     // 更新者
-	UpdatedName   string      `orm:"updated_name"    json:"updatedName"`   // 更新人
-	UpdatedTime   *gtime.Time `orm:"updated_time"    json:"updatedTime"`   // 更新时间
-	DeletedTime   *gtime.Time `orm:"deleted_time"    json:"deletedTime"`   // 删除时间
+	Id               int         `orm:"id,primary"        json:"id"`               // 主键
+	DistCode         string      `orm:"dist_code"         json:"distCode"`         // 经销商编码
+	DistName         string      `orm:"dist_name"         json:"distName"`         // 经销商名称
+	AbbrName         string      `orm:"abbr_name"         json:"abbrName"`         // 助记名
+	DistDesc         string      `orm:"dist_desc"         json:"distDesc"`         // 经销商说明
+	DistBoss         string      `orm:"dist_boss"         json:"distBoss"`         // 负责人
+	DistBossPhone    string      `orm:"dist_boss_phone"   json:"distBossPhone"`    // 负责人电话
+	ProvinceId       int         `orm:"province_id"       json:"provinceId"`       // 所属省份ID
+	ProvinceDesc     string      `orm:"province_desc"     json:"provinceDesc"`     // 所属省份
+	BusinessScope    string      `orm:"business_scope"    json:"businessScope"`    // 业务范围
+	BelongSaleId     int         `orm:"belong_sale_id"    json:"belongSaleId"`     // 归属销售ID
+	BelongSale       string      `orm:"belong_sale"       json:"belongSale"`       // 归属销售
+	Capital          float64     `orm:"capital"           json:"capital"`          // 注册资金
+	SaleNum          int         `orm:"sale_num"          json:"saleNum"`          // 销售人数
+	InvoiceHeader    string      `orm:"invoice_header"    json:"invoiceHeader"`    // 开票抬头
+	DistType         string      `orm:"dist_type"         json:"distType"`         // 经销商类型 10 经销商 20 代理商
+	CustomerType     string      `orm:"customer_type"     json:"customerType"`     // 授权客户类型
+	ExistedProduct   string      `orm:"existed_product"   json:"existedProduct"`   // 已有代理品牌和产品
+	AssistantSaleId  string      `orm:"assistant_sale_id" json:"assistantSaleId"`  // 助理人员Id
+	AssistantSale    string      `orm:"assistant_sale"    json:"assistantSale"`    // 助理人员
+	RegisterDistrict string      `orm:"register_district" json:"registerDistrict"` // 注册地
+	HistoryCustomer  string      `orm:"history_customer"  json:"historyCustomer"`  // 历史合作的终端客户名称
+	ProxyStartTime   *gtime.Time `orm:"proxy_start_time"  json:"proxyStartTime"`   // 代理签约有效期开始(代理商)
+	ProxyEndTime     *gtime.Time `orm:"proxy_end_time"    json:"proxyEndTime"`     // 代理签约有效期结束(代理商)
+	ProxyDistrict    string      `orm:"proxy_district"    json:"proxyDistrict"`    // 授权代理区域(代理商)
+	ContractUrl      string      `orm:"contract_url"      json:"contractUrl"`      // 代理合同(代理商)
+	Remark           string      `orm:"remark"            json:"remark"`           // 备注
+	CreatedBy        int         `orm:"created_by"        json:"createdBy"`        // 创建者
+	CreatedName      string      `orm:"created_name"      json:"createdName"`      // 创建人
+	CreatedTime      *gtime.Time `orm:"created_time"      json:"createdTime"`      // 创建时间
+	UpdatedBy        int         `orm:"updated_by"        json:"updatedBy"`        // 更新者
+	UpdatedName      string      `orm:"updated_name"      json:"updatedName"`      // 更新人
+	UpdatedTime      *gtime.Time `orm:"updated_time"      json:"updatedTime"`      // 更新时间
+	DeletedTime      *gtime.Time `orm:"deleted_time"      json:"deletedTime"`      // 删除时间
 }

+ 2 - 0
opms_parent/app/model/base/internal/base_distributor_contact.go

@@ -17,6 +17,8 @@ type BaseDistributorContact struct {
 	Phone       string      `orm:"phone"        json:"phone"`       // 电话
 	Wechat      string      `orm:"wechat"       json:"wechat"`      // 微信
 	Mail        string      `orm:"mail"         json:"mail"`        // 邮箱
+	Honorific   string      `orm:"honorific"    json:"honorific"`   // 尊称
+	Territory   string      `orm:"territory"    json:"territory"`   // 负责区域/业务线
 	Remark      string      `orm:"remark"       json:"remark"`      // 备注
 	CreatedBy   int         `orm:"created_by"   json:"createdBy"`   // 创建者
 	CreatedName string      `orm:"created_name" json:"createdName"` // 创建人

+ 28 - 0
opms_parent/app/model/base/internal/base_distributor_dynamics.go

@@ -0,0 +1,28 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
+// ==========================================================================
+
+package internal
+
+import (
+	"github.com/gogf/gf/os/gtime"
+)
+
+// BaseDistributorDynamics is the golang structure for table base_distributor_dynamics.
+type BaseDistributorDynamics struct {
+	Id          int         `orm:"id,primary"    json:"id"`          // 主键
+	DistId      int         `orm:"dist_id"       json:"distId"`      // 经销商/代理商ID
+	OpnPeopleId int         `orm:"opn_people_id" json:"opnPeopleId"` // 操作人ID
+	OpnPeople   string      `orm:"opn_people"    json:"opnPeople"`   // 操作人
+	OpnDate     *gtime.Time `orm:"opn_date"      json:"opnDate"`     // 操作日期
+	OpnType     string      `orm:"opn_type"      json:"opnType"`     // 操作类型
+	OpnContent  string      `orm:"opn_content"   json:"opnContent"`  // 操作内容
+	Remark      string      `orm:"remark"        json:"remark"`      // 备注
+	CreatedBy   int         `orm:"created_by"    json:"createdBy"`   // 创建者
+	CreatedName string      `orm:"created_name"  json:"createdName"` // 创建人
+	CreatedTime *gtime.Time `orm:"created_time"  json:"createdTime"` // 创建时间
+	UpdatedBy   int         `orm:"updated_by"    json:"updatedBy"`   // 更新者
+	UpdatedName string      `orm:"updated_name"  json:"updatedName"` // 更新人
+	UpdatedTime *gtime.Time `orm:"updated_time"  json:"updatedTime"` // 更新时间
+	DeletedTime *gtime.Time `orm:"deleted_time"  json:"deletedTime"` // 删除时间
+}

+ 33 - 0
opms_parent/app/model/base/internal/base_distributor_record.go

@@ -0,0 +1,33 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
+// ==========================================================================
+
+package internal
+
+import (
+	"github.com/gogf/gf/os/gtime"
+)
+
+// BaseDistributorRecord is the golang structure for table base_distributor_record.
+type BaseDistributorRecord struct {
+	Id              int         `orm:"id,primary"       json:"id"`              // 主键
+	DistId          int         `orm:"dist_id"          json:"distId"`          // 所属经销商
+	DistType        string      `orm:"dist_type"        json:"distType"`        // 经销商类型 10 经销商 20 代理商
+	BusinessScope   string      `orm:"business_scope"   json:"businessScope"`   // 业务范围
+	CustomerType    string      `orm:"customer_type"    json:"customerType"`    // 授权客户类型
+	ProxyDistrict   string      `orm:"proxy_district"   json:"proxyDistrict"`   // 授权代理区域(代理商)
+	ProxyStartTime  *gtime.Time `orm:"proxy_start_time" json:"proxyStartTime"`  // 代理签约有效期开始(代理商)
+	ProxyEndTime    *gtime.Time `orm:"proxy_end_time"   json:"proxyEndTime"`    // 代理签约有效期结束(代理商)
+	ContractUrl     string      `orm:"contract_url"     json:"contractUrl"`     // 代理合同(代理商)
+	ExistedProduct  string      `orm:"existed_product"  json:"existedProduct"`  // 已有代理品牌和产品
+	HistoryCustomer string      `orm:"history_customer" json:"historyCustomer"` // 历史合作的终端客户名称
+	ToDistReason    string      `orm:"to_dist_reason"   json:"toDistReason"`    // 转移经销商原因
+	Remark          string      `orm:"remark"           json:"remark"`          // 备注
+	CreatedBy       int         `orm:"created_by"       json:"createdBy"`       // 创建者
+	CreatedName     string      `orm:"created_name"     json:"createdName"`     // 创建人
+	CreatedTime     *gtime.Time `orm:"created_time"     json:"createdTime"`     // 创建时间
+	UpdatedBy       int         `orm:"updated_by"       json:"updatedBy"`       // 更新者
+	UpdatedName     string      `orm:"updated_name"     json:"updatedName"`     // 更新人
+	UpdatedTime     *gtime.Time `orm:"updated_time"     json:"updatedTime"`     // 更新时间
+	DeletedTime     *gtime.Time `orm:"deleted_time"     json:"deletedTime"`     // 删除时间
+}

+ 29 - 0
opms_parent/app/model/base/internal/base_distributor_target.go

@@ -0,0 +1,29 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
+// ==========================================================================
+
+package internal
+
+import (
+	"github.com/gogf/gf/os/gtime"
+)
+
+// BaseDistributorTarget is the golang structure for table base_distributor_target.
+type BaseDistributorTarget struct {
+	Id          int         `orm:"id,primary"   json:"id"`          // 主键
+	DistId      int         `orm:"dist_id"      json:"distId"`      // 所属经销商
+	Year        int         `orm:"year"         json:"year"`        // 年度
+	Q1          float64     `orm:"q1"           json:"q1"`          // q1指标(万元)
+	Q2          float64     `orm:"q2"           json:"q2"`          // q2指标(万元)
+	Q3          float64     `orm:"q3"           json:"q3"`          // q3指标(万元)
+	Q4          float64     `orm:"q4"           json:"q4"`          // q4指标(万元)
+	Total       float64     `orm:"total"        json:"total"`       // 年度指标(万元)
+	Remark      string      `orm:"remark"       json:"remark"`      // 备注
+	CreatedBy   int         `orm:"created_by"   json:"createdBy"`   // 创建者
+	CreatedName string      `orm:"created_name" json:"createdName"` // 创建人
+	CreatedTime *gtime.Time `orm:"created_time" json:"createdTime"` // 创建时间
+	UpdatedBy   int         `orm:"updated_by"   json:"updatedBy"`   // 更新者
+	UpdatedName string      `orm:"updated_name" json:"updatedName"` // 更新人
+	UpdatedTime *gtime.Time `orm:"updated_time" json:"updatedTime"` // 更新时间
+	DeletedTime *gtime.Time `orm:"deleted_time" json:"deletedTime"` // 删除时间
+}

+ 2 - 2
opms_parent/app/model/plat/plat_followup.go

@@ -40,8 +40,8 @@ type AddPlatFollowupReq struct {
 	TargetId      int                       `orm:"target_id"      json:"targetId"      v:"required|min:1#跟进对象ID不能为空|跟进对象ID不能为空"` // 跟进对象ID
 	TargetType    string                    `orm:"target_type"    json:"targetType"    v:"required#跟进对象类型不能为空"`                  // 跟进对象类型(10客户,20项目,30合同,40回款)
 	TargetName    string                    `orm:"target_name"    json:"targetName"    v:"required#跟进对象不能为空"`                    // 跟进对象
-	CustId        int                       `orm:"cust_id"        json:"custId"        v:"required|min:1#关联客户不能为空|关联客户不能为空"`     // 关联客户
-	CustName      string                    `orm:"cust_name"      json:"custName"      v:"required#客户名称不能为空"`                    // 客户名称
+	CustId        int                       `orm:"cust_id"        json:"custId"`                                                 // 关联客户
+	CustName      string                    `orm:"cust_name"      json:"custName"`                                               // 客户名称
 	ContactsId    int                       `orm:"contacts_id"    json:"contactsId"    v:"required|min:1#关联联系人不能为空|关联联系人不能为空"`   // 关联联系人
 	ContactsName  string                    `orm:"contacts_name"  json:"contactsName"  v:"required#联系人姓名不能为空"`                   // 联系人姓名
 	Reminders     string                    `orm:"reminders"      json:"reminders"`                                              // 提醒对象

+ 498 - 4
opms_parent/app/service/base/base_distributor.go

@@ -2,20 +2,37 @@ package base
 
 import (
 	"context"
+	"database/sql"
+	"encoding/json"
+	"fmt"
+	"time"
+
 	"dashoo.cn/opms_libary/myerrors"
 	"github.com/gogf/gf/container/garray"
+	"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"
 
 	"dashoo.cn/micro/app/dao/base"
+	contractdao "dashoo.cn/micro/app/dao/contract"
+	projdao "dashoo.cn/micro/app/dao/proj"
 	model "dashoo.cn/micro/app/model/base"
+	contractmodel "dashoo.cn/micro/app/model/contract"
+	projmodel "dashoo.cn/micro/app/model/proj"
 	"dashoo.cn/micro/app/service"
 )
 
 type distributorService struct {
 	*service.ContextService
 
-	Dao *base.BaseDistributorDao
+	Dao         *base.BaseDistributorDao
+	DynamicsDao *base.BaseDistributorDynamicsDao
+	TargetDao   *base.BaseDistributorTargetDao
+	RecordDao   *base.BaseDistributorRecordDao
+	ProjDao     *projdao.ProjBusinessDao
+	ContractDao *contractdao.CtrContractDao
 }
 
 func NewDistributorService(ctx context.Context) (svc *distributorService, err error) {
@@ -24,11 +41,16 @@ func NewDistributorService(ctx context.Context) (svc *distributorService, err er
 		return nil, err
 	}
 	svc.Dao = base.NewBaseDistributorDao(svc.Tenant)
+	svc.DynamicsDao = base.NewBaseDistributorDynamicsDao(svc.Tenant)
+	svc.ProjDao = projdao.NewProjBusinessDao(svc.Tenant)
+	svc.ContractDao = contractdao.NewCtrContractDao(svc.Tenant)
+	svc.TargetDao = base.NewBaseDistributorTargetDao(svc.Tenant)
+	svc.RecordDao = base.NewBaseDistributorRecordDao(svc.Tenant)
 	return svc, nil
 }
 
 // GetList 经销商信息列表
-func (s *distributorService) GetList(req *model.BaseDistributorSearchReq) (total int, distributorList []*model.DistributorRonp, err error) {
+func (s *distributorService) GetList(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") {
@@ -46,12 +68,64 @@ func (s *distributorService) GetList(req *model.BaseDistributorSearchReq) (total
 	if len(req.ProvinceId) > 0 {
 		distributorModel = distributorModel.WhereIn(s.Dao.C.ProvinceId, req.ProvinceId)
 	}
+	if req.DistType != "" {
+		distributorModel = distributorModel.WhereIn(s.Dao.C.DistType, req.DistType)
+	}
 	total, err = distributorModel.Count()
 	if err != nil {
 		err = myerrors.DbError("获取总行数失败。")
 		return
 	}
 	err = distributorModel.Page(req.GetPage()).Order("id desc").Scan(&distributorList)
+
+	if req.WithStatistic {
+		for i, dist := range distributorList {
+			statistic, err := s.statistic(dist.Id)
+			if err != nil {
+				return 0, nil, err
+			}
+			distributorList[i].BaseDistributorStatistic = statistic
+		}
+	}
+	return
+}
+
+func (s *distributorService) statistic(id int) (stat model.BaseDistributorStatistic, err error) {
+	v, err := s.Dao.DB.GetValue("select count(*) from proj_business where distributor_id=? and appro_status ='30' and nbo_type in (10,20,30) and deleted_time is null", id)
+	if err != nil {
+		return stat, err
+	}
+	stat.ProjectNum = v.Int()
+
+	v, err = s.Dao.DB.GetValue("select sum(est_trans_price) from proj_business where distributor_id=? and appro_status ='30' and nbo_type in (10,20,30) and deleted_time is null", id)
+	if err != nil {
+		return stat, err
+	}
+	stat.AllProductAmount = v.Float64()
+
+	v, err = s.Dao.DB.GetValue("select count(distinct(b.id)) from ctr_contract a left join proj_business b on a.nbo_id=b.id where a.distributor_id=? and a.appro_status ='30' and b.appro_status ='30' and a.deleted_time is null and b.deleted_time is null", id)
+	if err != nil {
+		return stat, err
+	}
+	stat.SaledProjectNum = v.Int()
+
+	v, err = s.Dao.DB.GetValue("select sum(contract_amount) from ctr_contract where distributor_id=? and appro_status='30' and deleted_time is null", id)
+	if err != nil {
+		return stat, err
+	}
+	stat.SaledAmount = v.Float64()
+
+	v, err = s.Dao.DB.GetValue("select sum(contract_amount - collected_amount) from ctr_contract where distributor_id=? and appro_status='30' and deleted_time is null", id)
+	if err != nil {
+		return stat, err
+	}
+	stat.UnpaidAmount = v.Float64()
+
+	v, err = s.Dao.DB.GetValue("select sum(invoice_amount) from ctr_contract where distributor_id=? and appro_status='30' and deleted_time is null", id)
+	if err != nil {
+		return stat, err
+	}
+	stat.InvoicedAmount = v.Float64()
 	return
 }
 
@@ -79,14 +153,31 @@ func (s *distributorService) Create(req *model.AddDistributor) (lastId int64, er
 	if err != nil {
 		return 0, 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{}{})
+		return err
+	})
 	return
 }
 
 // GetEntityById 详情
-func (s *distributorService) GetEntityById(id int64) (distributorInfo *model.DistributorRonp, err error) {
+func (s *distributorService) GetEntityById(id int64) (distributorInfo *model.BaseDistributorListRsp, err error) {
 	err = s.Dao.Where(base.BaseProduct.C.Id, id).Scan(&distributorInfo)
 	if err != nil {
-		return
+		return nil, err
+	}
+	statistic, err := s.statistic(int(id))
+	if err != nil {
+		return nil, err
+	}
+	distributorInfo.BaseDistributorStatistic = statistic
+
+	target, err := s.TargetDao.Where("dist_id = ?", id).Where("year = ?", time.Now().Year()).One()
+	if err != nil {
+		return nil, err
+	}
+	if target != nil {
+		distributorInfo.YearTarget = target.Total
 	}
 	return
 }
@@ -114,9 +205,208 @@ func (s *distributorService) UpdateById(req *model.UpdateDistributorReq) (err er
 		g.Log().Error(err)
 		return
 	}
+	err = s.Dao.DB.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
+		err = s.AddDynamicsByCurrentUser(tx, req.Id, "更新经销商/代理商", map[string]interface{}{})
+		return err
+	})
 	return
 }
 
+func (s *distributorService) ToProxy(ctx context.Context, req *model.DistributorToProxyReq) (err error) {
+	validErr := gvalid.CheckStruct(ctx, req, nil)
+	if validErr != nil {
+		return myerrors.TipsError(validErr.Current().Error())
+	}
+
+	ent, err := s.Dao.Where("id = ?", req.Id).One()
+	if err != nil {
+		return err
+	}
+	if ent == nil {
+		return myerrors.TipsError(fmt.Sprintf("代理商/经销商不存在: %d", req.Id))
+	}
+
+	txerr := s.Dao.DB.Transaction(context.TODO(), 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,
+		}, "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(),
+		})
+		if err != nil {
+			return err
+		}
+		err = s.AddDynamicsByCurrentUser(tx, req.Id, "转为代理商", map[string]interface{}{})
+		if err != nil {
+			return err
+		}
+		return nil
+	})
+	return txerr
+}
+
+func (s *distributorService) Renew(ctx context.Context, req *model.DistributorRenewReq) (err error) {
+	validErr := gvalid.CheckStruct(ctx, req, nil)
+	if validErr != nil {
+		return myerrors.TipsError(validErr.Current().Error())
+	}
+
+	ent, err := s.Dao.Where("id = ?", req.Id).One()
+	if err != nil {
+		return err
+	}
+	if ent == nil {
+		return myerrors.TipsError(fmt.Sprintf("代理商/经销商不存在: %d", req.Id))
+	}
+
+	txerr := s.Dao.DB.Transaction(context.TODO(), 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,
+		}, "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(),
+		})
+		if err != nil {
+			return err
+		}
+		err = s.AddDynamicsByCurrentUser(tx, req.Id, "续签代理商", map[string]interface{}{})
+		if err != nil {
+			return err
+		}
+		return nil
+	})
+	return txerr
+}
+
+func (s *distributorService) ToDist(ctx context.Context, req *model.DistributorToDistReq) (err error) {
+	validErr := gvalid.CheckStruct(ctx, req, nil)
+	if validErr != nil {
+		return myerrors.TipsError(validErr.Current().Error())
+	}
+
+	ent, err := s.Dao.Where("id = ?", req.Id).One()
+	if err != nil {
+		return err
+	}
+	if ent == nil {
+		return myerrors.TipsError(fmt.Sprintf("代理商/经销商不存在: %d", req.Id))
+	}
+
+	txerr := s.Dao.DB.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
+		_, err = tx.Update("base_distributor", map[string]interface{}{
+			"dist_type": "10",
+		}, "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 txerr
+}
+
+func (s *distributorService) TransRecord(ctx context.Context, req *model.DistributorTransRecordReq) (int, []*model.BaseDistributorRecord, error) {
+	dao := s.RecordDao.As("a")
+	if req.DistId != 0 {
+		dao = dao.Where("a.dist_id = ?", req.DistId)
+	}
+
+	total, err := dao.Count()
+	if err != nil {
+		return 0, nil, err
+	}
+	if req.PageNum != 0 {
+		dao = dao.Page(req.GetPage())
+	}
+	orderby := "a.created_time desc"
+	if req.OrderBy != "" {
+		orderby = req.OrderBy
+	}
+	dao = dao.Order(orderby)
+
+	ents := []*model.BaseDistributorRecord{}
+	err = dao.Structs(&ents)
+	if err != nil && err != sql.ErrNoRows {
+		return 0, nil, err
+	}
+	return total, ents, nil
+}
+
 // DeleteByIds 删除
 func (s *distributorService) DeleteByIds(ids []int64) (err error) {
 	_, err = s.Dao.WhereIn(s.Dao.C.Id, ids).Delete()
@@ -126,3 +416,207 @@ func (s *distributorService) DeleteByIds(ids []int64) (err error) {
 	return
 
 }
+
+func (s distributorService) AddDynamicsByCurrentUser(tx *gdb.TX, distId int, opnType string, content map[string]interface{}) error {
+	contentByte, err := json.Marshal(content)
+	if err != nil {
+		return err
+	}
+	_, err = tx.InsertAndGetId("base_distributor_dynamics", model.BaseDistributorDynamics{
+		DistId:      distId,
+		OpnPeopleId: s.GetCxtUserId(),
+		OpnPeople:   s.GetCxtUserName(),
+		OpnDate:     gtime.Now(),
+		OpnType:     opnType,
+		OpnContent:  string(contentByte),
+		Remark:      "",
+		CreatedBy:   s.GetCxtUserId(),
+		CreatedName: s.GetCxtUserName(),
+		CreatedTime: gtime.Now(),
+		UpdatedBy:   s.GetCxtUserId(),
+		UpdatedName: s.GetCxtUserName(),
+		UpdatedTime: gtime.Now(),
+	})
+	return err
+}
+
+func (s distributorService) ContractList(ctx context.Context, req *model.DistributorContractListReq) (int, []*contractmodel.CtrContractListRsp, error) {
+	dao := s.ContractDao.As("a")
+	if req.DistId != 0 {
+		dao = dao.Where("a.distributor_id = ?", req.DistId)
+	}
+	if req.SearchText != "" {
+		likestr := fmt.Sprintf("%%%s%%", req.SearchText)
+		dao = dao.Where("(a.contract_code LIKE ? || a.contract_name LIKE ? || a.cust_name LIKE ? || a.nbo_name LIKE ?)", likestr, likestr, likestr, likestr)
+	}
+	if req.ContractCode != "" {
+		likestr := fmt.Sprintf("%%%s%%", req.ContractCode)
+		dao = dao.Where("a.contract_code like ?", likestr)
+	}
+	if req.ContractName != "" {
+		likestr := fmt.Sprintf("%%%s%%", req.ContractName)
+		dao = dao.Where("a.contract_name like ?", likestr)
+	}
+	if req.CustId != 0 {
+		dao = dao.Where("a.cust_id = ?", req.CustId)
+	}
+	if req.CustName != "" {
+		likestr := fmt.Sprintf("%%%s%%", req.CustName)
+		dao = dao.Where("a.cust_name like ?", likestr)
+	}
+	if req.NboId != 0 {
+		dao = dao.Where("a.nbo_id = ?", req.NboId)
+	}
+	if req.NboName != "" {
+		likestr := fmt.Sprintf("%%%s%%", req.NboName)
+		dao = dao.Where("a.nbo_name like ?", likestr)
+	}
+	if req.ApproStatus != "" {
+		dao = dao.Where("a.appro_status = ?", req.ApproStatus)
+	}
+	if req.ContractType != "" {
+		dao = dao.Where("a.contract_type = ?", req.ContractType)
+	}
+	if req.InchargeId != 0 {
+		dao = dao.Where("a.incharge_id = ?", req.InchargeId)
+	}
+	if req.InchargeName != "" {
+		likestr := fmt.Sprintf("%%%s%%", req.InchargeName)
+		dao = dao.Where("a.incharge_name like ?", likestr)
+	}
+	if req.SignatoryId != 0 {
+		dao = dao.Where("a.signatory_id = ?", req.SignatoryId)
+	}
+	if req.SignatoryName != "" {
+		likestr := fmt.Sprintf("%%%s%%", req.SignatoryName)
+		dao = dao.Where("a.signatory_name like ?", likestr)
+	}
+	if req.DistributorName != "" {
+		likestr := fmt.Sprintf("%%%s%%", req.DistributorName)
+		dao = dao.Where("a.distributor_name like ?", likestr)
+	}
+	if req.BeginTime != "" {
+		dao = dao.Where("a.created_time > ?", req.BeginTime)
+	}
+	if req.EndTime != "" {
+		dao = dao.Where("a.created_time < ?", req.EndTime)
+	}
+
+	total, err := dao.Count()
+	if err != nil {
+		return 0, nil, err
+	}
+	if req.PageNum != 0 {
+		dao = dao.Page(req.GetPage())
+	}
+	orderby := "a.created_time desc"
+	if req.OrderBy != "" {
+		orderby = req.OrderBy
+	}
+	dao = dao.Order(orderby)
+
+	ents := []*contractmodel.CtrContractListRsp{}
+	err = dao.Structs(&ents)
+	if err != nil && err != sql.ErrNoRows {
+		return 0, nil, err
+	}
+	return total, ents, nil
+}
+
+func (s distributorService) ProjectList(ctx context.Context, req *model.DistributorProjectListReq) (int, []*projmodel.ProjBusiness, error) {
+	dao := &s.ProjDao.ProjBusinessDao
+	if req.DistId != 0 {
+		dao = dao.Where("distributor_id = ?", req.DistId)
+	}
+	if req.SearchText != "" {
+		likestr := fmt.Sprintf("%%%s%%", req.SearchText)
+		dao = dao.Where("(cust_name LIKE ? || nbo_name LIKE ?)", likestr, likestr)
+	}
+	if req.NboName != "" {
+		likestr := fmt.Sprintf("%%%s%%", req.NboName)
+		dao = dao.Where("nbo_name like ?", likestr)
+	}
+	if req.CustName != "" {
+		likestr := fmt.Sprintf("%%%s%%", req.CustName)
+		dao = dao.Where("cust_name like ?", likestr)
+	}
+	if req.CreatedTimeStart != nil {
+		dao = dao.Where("created_time > ?", req.CreatedTimeStart)
+	}
+	if req.CreatedTimeEnd != nil {
+		dao = dao.Where("created_time < ?", req.CreatedTimeEnd)
+	}
+
+	total, err := dao.Count()
+	if err != nil {
+		return 0, nil, err
+	}
+	if req.PageNum != 0 {
+		dao = dao.Page(req.GetPage())
+	}
+	orderby := "created_time desc"
+	if req.OrderBy != "" {
+		orderby = req.OrderBy
+	}
+	dao = dao.Order(orderby)
+
+	ents := []*projmodel.ProjBusiness{}
+	err = dao.Structs(&ents)
+	if err != nil && err != sql.ErrNoRows {
+		return 0, nil, err
+	}
+	return total, ents, nil
+}
+
+func (s distributorService) DynamicsList(ctx context.Context, req *model.DistributorDynamicsListReq) (int, interface{}, error) {
+	dao := &s.DynamicsDao.BaseDistributorDynamicsDao
+	if req.SearchText != "" {
+		likestr := fmt.Sprintf("%%%s%%", req.SearchText)
+		dao = dao.Where("(opn_people LIKE ? || opn_content LIKE ?)", likestr, likestr)
+	}
+	if req.DistId != 0 {
+		dao = dao.Where("dist_id = ?", req.DistId)
+	}
+	if req.OpnPeopleId != 0 {
+		dao = dao.Where("opn_people_id = ?", req.OpnPeopleId)
+	}
+	if req.OpnPeople != "" {
+		likestr := fmt.Sprintf("%%%s%%", req.OpnPeople)
+		dao = dao.Where("opn_people like ?", likestr)
+	}
+	if req.OpnType != "" {
+		dao = dao.Where("opn_type = ?", req.OpnType)
+	}
+	if req.BeginTime != "" {
+		dao = dao.Where("created_time > ?", req.BeginTime)
+	}
+	if req.EndTime != "" {
+		dao = dao.Where("created_time < ?", req.EndTime)
+	}
+
+	total, err := dao.Count()
+	if err != nil {
+		return 0, nil, err
+	}
+	if req.PageNum != 0 {
+		dao = dao.Page(req.GetPage())
+	}
+	orderby := "created_time desc"
+	if req.OrderBy != "" {
+		orderby = req.OrderBy
+	}
+	dao = dao.Order(orderby)
+
+	ents := []*model.BaseDistributorDynamics{}
+	err = dao.Structs(&ents)
+	if err != nil && err != sql.ErrNoRows {
+		return 0, nil, err
+	}
+
+	ret := map[string][]*model.BaseDistributorDynamics{}
+	for _, ent := range ents {
+		date := ent.OpnDate.Format("Y-m-d")
+		ret[date] = append(ret[date], ent)
+	}
+	return total, ret, err
+}

+ 196 - 0
opms_parent/app/service/base/base_distributor_contact.go

@@ -0,0 +1,196 @@
+package base
+
+import (
+	"context"
+	"database/sql"
+	"fmt"
+
+	dao "dashoo.cn/micro/app/dao/base"
+	model "dashoo.cn/micro/app/model/base"
+
+	"dashoo.cn/opms_libary/micro_srv"
+	"dashoo.cn/opms_libary/myerrors"
+	"dashoo.cn/opms_libary/request"
+	"github.com/gogf/gf/database/gdb"
+	"github.com/gogf/gf/os/glog"
+	"github.com/gogf/gf/os/gtime"
+	"github.com/gogf/gf/util/gvalid"
+)
+
+type BaseDistributorContactService struct {
+	Dao      *dao.BaseDistributorContactDao
+	DistDao  *dao.BaseDistributorDao
+	distSrv  *distributorService
+	Tenant   string
+	userInfo request.UserInfo
+}
+
+func NewBaseDistributorContactService(ctx context.Context) (*BaseDistributorContactService, error) {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return nil, fmt.Errorf("获取组合码异常:%s", err.Error())
+	}
+	// 获取用户信息
+	userInfo, err := micro_srv.GetUserInfo(ctx)
+	if err != nil {
+		return nil, fmt.Errorf("获取用户信息异常:%s", err.Error())
+	}
+	distSrv, err := NewDistributorService(ctx)
+	if err != nil {
+		return nil, err
+	}
+	return &BaseDistributorContactService{
+		Dao:      dao.NewBaseDistributorContactDao(tenant),
+		DistDao:  dao.NewBaseDistributorDao(tenant),
+		distSrv:  distSrv,
+		Tenant:   tenant,
+		userInfo: userInfo,
+	}, nil
+}
+
+func (s BaseDistributorContactService) List(ctx context.Context, req *model.BaseDistributorContactListReq) (int, []*model.BaseDistributorContact, error) {
+	dao := &s.Dao.BaseDistributorContactDao
+	if req.Name != "" {
+		likestr := fmt.Sprintf("%%%s%%", req.Name)
+		dao = dao.Where("name LIKE ?", likestr)
+	}
+	if req.DistId != 0 {
+		dao = dao.Where("dist_id = ?", req.DistId)
+	}
+
+	total, err := dao.Count()
+	if err != nil {
+		return 0, nil, err
+	}
+	if req.PageNum != 0 {
+		dao = dao.Page(req.GetPage())
+	}
+	orderby := "created_time desc"
+	if req.OrderBy != "" {
+		orderby = req.OrderBy
+	}
+	dao = dao.Order(orderby)
+
+	ents := []*model.BaseDistributorContact{}
+	err = dao.Structs(&ents)
+	if err != nil && err != sql.ErrNoRows {
+		return 0, nil, err
+	}
+	return total, ents, nil
+}
+
+func (s BaseDistributorContactService) Add(ctx context.Context, req *model.BaseDistributorContactAddReq) (int, error) {
+	validErr := gvalid.CheckStruct(ctx, req, nil)
+	if validErr != nil {
+		return 0, myerrors.TipsError(validErr.Current().Error())
+	}
+
+	t, err := s.DistDao.Where("id = ?", req.DistId).One()
+	if err != nil {
+		return 0, err
+	}
+	if t == nil {
+		return 0, myerrors.TipsError("所属经销商不存在")
+	}
+
+	id, err := s.Dao.InsertAndGetId(model.BaseDistributorContact{
+		DistId:      req.DistId,
+		Name:        req.Name,
+		Post:        req.Post,
+		Phone:       req.Phone,
+		Wechat:      req.Wechat,
+		Mail:        req.Mail,
+		Honorific:   req.Honorific,
+		Territory:   req.Territory,
+		Remark:      req.Remark,
+		CreatedBy:   int(s.userInfo.Id),
+		CreatedName: s.userInfo.NickName,
+		CreatedTime: gtime.Now(),
+		UpdatedBy:   int(s.userInfo.Id),
+		UpdatedName: s.userInfo.NickName,
+		UpdatedTime: gtime.Now(),
+	})
+	if err != nil {
+		return 0, err
+	}
+	err = s.Dao.DB.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
+		err = s.distSrv.AddDynamicsByCurrentUser(tx, req.DistId, "创建联系人", map[string]interface{}{"id": id})
+		return err
+	})
+	return int(id), err
+}
+
+func (s BaseDistributorContactService) Update(ctx context.Context, req *model.BaseDistributorContactUpdateReq) error {
+	validErr := gvalid.CheckStruct(ctx, req, nil)
+	if validErr != nil {
+		return myerrors.TipsError(validErr.Current().Error())
+	}
+
+	ent, err := s.Dao.Where("id = ?", req.Id).One()
+	if err != nil {
+		return err
+	}
+	if ent == nil {
+		return myerrors.TipsError(fmt.Sprintf("联系人不存在: %d", req.Id))
+	}
+
+	dao := &s.Dao.BaseDistributorContactDao
+	toupdate := map[string]interface{}{}
+	if req.Name != "" {
+		toupdate["name"] = req.Name
+	}
+	if req.Post != "" {
+		toupdate["post"] = req.Post
+	}
+	if req.Phone != "" {
+		toupdate["phone"] = req.Phone
+	}
+	if req.Wechat != nil {
+		toupdate["wechat"] = *req.Wechat
+	}
+	if req.Mail != nil {
+		toupdate["mail"] = *req.Mail
+	}
+	if req.Honorific != nil {
+		toupdate["honorific"] = *req.Honorific
+	}
+	if req.Territory != nil {
+		toupdate["territory"] = *req.Territory
+	}
+	if req.Remark != nil {
+		toupdate["remark"] = *req.Remark
+	}
+	if len(toupdate) != 0 {
+		toupdate["updated_by"] = int(s.userInfo.Id)
+		toupdate["updated_name"] = s.userInfo.NickName
+		toupdate["updated_time"] = gtime.Now()
+		_, err = dao.Where("Id", req.Id).Data(toupdate).Update()
+		if err != nil {
+			return err
+		}
+	}
+	return nil
+}
+
+func (s BaseDistributorContactService) Delete(ctx context.Context, id []int) error {
+	if len(id) == 0 {
+		return nil
+	}
+	_, err := s.Dao.Where("Id  IN (?)", id).Delete()
+	err = s.Dao.DB.Transaction(context.TODO(), func(ctx context.Context, tx *gdb.TX) error {
+		for _, i := range id {
+			ent, err := s.Dao.Where("id = ?", i).Unscoped().One()
+			if err != nil {
+				glog.Error(err)
+				continue
+			}
+			err = s.distSrv.AddDynamicsByCurrentUser(tx, ent.DistId, "删除联系人", map[string]interface{}{"id": i})
+			if err != nil {
+				glog.Error(err)
+				continue
+			}
+		}
+		return nil
+	})
+	return err
+}

+ 206 - 0
opms_parent/app/service/base/base_distributor_target.go

@@ -0,0 +1,206 @@
+package base
+
+import (
+	"context"
+	"database/sql"
+	"fmt"
+	"time"
+
+	dao "dashoo.cn/micro/app/dao/base"
+	contractdao "dashoo.cn/micro/app/dao/contract"
+	model "dashoo.cn/micro/app/model/base"
+
+	"dashoo.cn/opms_libary/micro_srv"
+	"dashoo.cn/opms_libary/myerrors"
+	"dashoo.cn/opms_libary/request"
+	"github.com/gogf/gf/os/gtime"
+	"github.com/gogf/gf/util/gvalid"
+)
+
+type BaseDistributorTargetService struct {
+	Dao         *dao.BaseDistributorTargetDao
+	ContractDao *contractdao.CtrContractDao
+	Tenant      string
+	userInfo    request.UserInfo
+}
+
+func NewBaseDistributorTargetService(ctx context.Context) (*BaseDistributorTargetService, error) {
+	tenant, err := micro_srv.GetTenant(ctx)
+	if err != nil {
+		return nil, fmt.Errorf("获取组合码异常:%s", err.Error())
+	}
+	// 获取用户信息
+	userInfo, err := micro_srv.GetUserInfo(ctx)
+	if err != nil {
+		return nil, fmt.Errorf("获取用户信息异常:%s", err.Error())
+	}
+	return &BaseDistributorTargetService{
+		Dao:         dao.NewBaseDistributorTargetDao(tenant),
+		ContractDao: contractdao.NewCtrContractDao(tenant),
+		Tenant:      tenant,
+		userInfo:    userInfo,
+	}, nil
+}
+
+func (s BaseDistributorTargetService) List(ctx context.Context, req *model.BaseDistributorTargetListReq) (int, []*model.BaseDistributorTargetListRsp, error) {
+	dao := &s.Dao.BaseDistributorTargetDao
+	if req.DistId != 0 {
+		dao = dao.Where("dist_id = ?", req.DistId)
+	}
+
+	total, err := dao.Count()
+	if err != nil {
+		return 0, nil, err
+	}
+	if req.PageNum != 0 {
+		dao = dao.Page(req.GetPage())
+	}
+	orderby := "created_time desc"
+	if req.OrderBy != "" {
+		orderby = req.OrderBy
+	}
+	dao = dao.Order(orderby)
+
+	ents := []*model.BaseDistributorTargetListRsp{}
+	err = dao.Structs(&ents)
+	if err != nil && err != sql.ErrNoRows {
+		return 0, nil, err
+	}
+
+	for i, dist := range ents {
+		statistic, err := s.statistic(dist.Id)
+		if err != nil {
+			return 0, nil, err
+		}
+		ents[i].BaseDistributorTargetStatistic = statistic
+	}
+	return total, ents, nil
+}
+
+func (s *BaseDistributorTargetService) statistic(id int) (stat model.BaseDistributorTargetStatistic, err error) {
+	now := time.Now()
+	ctr, err := s.ContractDao.
+		Where("appro_status = '30'").
+		Where("DATE_FORMAT(created_time, '%Y') = ?", now.Year()).
+		Where("distributor_id = ?", id).All()
+
+	var q1, q2, q3, q4 float64
+	for _, c := range ctr {
+		m := c.CreatedTime.Month()
+		if m == 1 || m == 2 || m == 3 {
+			q1 += c.ContractAmount
+		}
+		if m == 4 || m == 5 || m == 6 {
+			q2 += c.ContractAmount
+		}
+		if m == 7 || m == 8 || m == 9 {
+			q3 += c.ContractAmount
+		}
+		if m == 10 || m == 11 || m == 12 {
+			q4 += c.ContractAmount
+		}
+	}
+
+	stat.Q1Amount = q1 / 10000
+	stat.Q2Amount = q2 / 10000
+	stat.Q3Amount = q3 / 10000
+	stat.Q4Amount = q4 / 10000
+	stat.TotalAmount = q1 + q2 + q3 + q4
+	return
+}
+
+func (s BaseDistributorTargetService) Add(ctx context.Context, req *model.BaseDistributorTargetAddReq) (int, error) {
+	validErr := gvalid.CheckStruct(ctx, req, nil)
+	if validErr != nil {
+		return 0, myerrors.TipsError(validErr.Current().Error())
+	}
+
+	t, err := s.Dao.Where("dist_id = ? and year = ?", req.DistId, req.Year).One()
+	if err != nil {
+		return 0, err
+	}
+	if t != nil {
+		return 0, myerrors.TipsError(fmt.Sprintf("%d 年指标已存在", req.Year))
+	}
+
+	id, err := s.Dao.InsertAndGetId(model.BaseDistributorTarget{
+		DistId:      req.DistId,
+		Year:        req.Year,
+		Q1:          req.Q1,
+		Q2:          req.Q2,
+		Q3:          req.Q3,
+		Q4:          req.Q4,
+		Total:       req.Q1 + req.Q2 + req.Q3 + req.Q4,
+		Remark:      req.Remark,
+		CreatedBy:   int(s.userInfo.Id),
+		CreatedName: s.userInfo.NickName,
+		CreatedTime: gtime.Now(),
+		UpdatedBy:   int(s.userInfo.Id),
+		UpdatedName: s.userInfo.NickName,
+		UpdatedTime: gtime.Now(),
+	})
+	if err != nil {
+		return 0, err
+	}
+	return int(id), err
+}
+
+func (s BaseDistributorTargetService) Update(ctx context.Context, req *model.BaseDistributorTargetUpdateReq) error {
+	validErr := gvalid.CheckStruct(ctx, req, nil)
+	if validErr != nil {
+		return myerrors.TipsError(validErr.Current().Error())
+	}
+
+	ent, err := s.Dao.Where("id = ?", req.Id).One()
+	if err != nil {
+		return err
+	}
+	if ent == nil {
+		return myerrors.TipsError(fmt.Sprintf("指标不存在: %d", req.Id))
+	}
+
+	dao := &s.Dao.BaseDistributorTargetDao
+	toupdate := map[string]interface{}{}
+	q1 := ent.Q1
+	q2 := ent.Q2
+	q3 := ent.Q3
+	q4 := ent.Q4
+	if req.Q1 != nil {
+		toupdate["q1"] = *req.Q1
+		q1 = *req.Q1
+	}
+	if req.Q2 != nil {
+		toupdate["q2"] = *req.Q2
+		q2 = *req.Q2
+	}
+	if req.Q3 != nil {
+		toupdate["q3"] = *req.Q3
+		q3 = *req.Q3
+	}
+	if req.Q4 != nil {
+		toupdate["q4"] = *req.Q4
+		q4 = *req.Q4
+	}
+	if req.Remark != nil {
+		toupdate["remark"] = *req.Remark
+	}
+	if len(toupdate) != 0 {
+		toupdate["total"] = q1 + q2 + q3 + q4
+		toupdate["updated_by"] = int(s.userInfo.Id)
+		toupdate["updated_name"] = s.userInfo.NickName
+		toupdate["updated_time"] = gtime.Now()
+		_, err = dao.Where("Id", req.Id).Data(toupdate).Update()
+		if err != nil {
+			return err
+		}
+	}
+	return nil
+}
+
+func (s BaseDistributorTargetService) Delete(ctx context.Context, id []int) error {
+	if len(id) == 0 {
+		return nil
+	}
+	_, err := s.Dao.Where("Id  IN (?)", id).Delete()
+	return err
+}

+ 2 - 0
opms_parent/main.go

@@ -31,6 +31,8 @@ func main() {
 	s := micro_srv.CreateAndInitService(basePath)
 	s.RegisterName("Product", new(base.ProductHandler), "")
 	s.RegisterName("Distributor", new(base.DistributorHandler), "")
+	s.RegisterName("DistributorContact", new(base.BaseDistributorContact), "")
+	s.RegisterName("DistributorTarget", new(base.BaseDistributorTarget), "")
 	s.RegisterName("District", new(base.DistrictHandler), "")
 	s.RegisterName("Region", new(base.RegionHandler), "")
 	s.RegisterName("Customer", new(cust.CustomerHeader), "")