|
|
@@ -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/contract"
|
|
|
)
|
|
|
@@ -29,43 +31,47 @@ type CtrContractDao struct {
|
|
|
|
|
|
// CtrContractColumns defines and stores column names for table ctr_contract.
|
|
|
type ctrContractColumns struct {
|
|
|
- Id string // 主键
|
|
|
- ContractCode string // 合同编号
|
|
|
- ContractName string // 合同名称
|
|
|
- CustId string // 关联客户
|
|
|
- CustName string // 客户名称
|
|
|
- ProductLine string // 产品线
|
|
|
- IsBig string // 是否为大项目
|
|
|
- CustProvinceId string // 所在省ID
|
|
|
- CustProvince string // 所在省
|
|
|
- CustCityId string // 所在市ID
|
|
|
- CustCity string // 所在市
|
|
|
- NboId string // 关联项目
|
|
|
- NboName string // 项目名称
|
|
|
- ApproStatus string // 审核状态 10 待提交审核 20 待审核 30 审核已同意 40 审核已拒绝 50 审核已撤销
|
|
|
- ContractType string // 合同类型
|
|
|
- ContractAmount string // 合同金额
|
|
|
- InvoiceAmount string // 已开票金额
|
|
|
- CollectedAmount string // 已回款金额
|
|
|
- ContractStartTime string // 合同开始时间
|
|
|
- ContractEndTime string // 合同结束时间
|
|
|
- InchargeId string // 负责人ID
|
|
|
- InchargeName string // 负责人(销售工程师)
|
|
|
- SignatoryId string // 公司签约人ID
|
|
|
- SignatoryName string // 公司签约人
|
|
|
- SignatoryType string // 签订单位类型 10 终端用户 20 经销商 30 代理商
|
|
|
- CustSignatoryId string // 客户签约人ID
|
|
|
- CustSignatoryName string // 客户签约人
|
|
|
- DistributorId string // 经销商ID
|
|
|
- DistributorName string // 经销商
|
|
|
- Remark string // 备注
|
|
|
- CreatedBy string // 创建者
|
|
|
- CreatedName string // 创建人
|
|
|
- CreatedTime string // 创建时间
|
|
|
- UpdatedBy string // 更新者
|
|
|
- UpdatedName string // 更新人
|
|
|
- UpdatedTime string // 更新时间
|
|
|
- DeletedTime string // 删除时间
|
|
|
+ Id string // 主键
|
|
|
+ ContractCode string // 合同编号
|
|
|
+ ContractName string // 合同名称
|
|
|
+ CustId string // 关联客户
|
|
|
+ CustName string // 客户名称
|
|
|
+ ProductLine string // 产品线
|
|
|
+ IsBig string // 是否为大项目
|
|
|
+ CustProvinceId string // 所在省ID
|
|
|
+ CustProvince string // 所在省
|
|
|
+ CustCityId string // 所在市ID
|
|
|
+ CustCity string // 所在市
|
|
|
+ NboId string // 关联项目
|
|
|
+ NboName string // 项目名称
|
|
|
+ ApproStatus string // 审核状态 10 待提交审核 20 待审核 30 审核已同意 40 审核已拒绝 50 审核已撤销
|
|
|
+ ContractType string // 合同类型
|
|
|
+ ContractAmount string // 合同金额
|
|
|
+ InvoiceAmount string // 已开票金额
|
|
|
+ CollectedAmount string // 已回款金额
|
|
|
+ ContractStartTime string // 合同开始时间
|
|
|
+ ContractEndTime string // 合同结束时间
|
|
|
+ ContractSignTime string // 合同签订时间
|
|
|
+ InchargeId string // 负责人ID
|
|
|
+ InchargeName string // 负责人(销售工程师)
|
|
|
+ SignatoryId string // 公司签约人ID
|
|
|
+ SignatoryName string // 公司签约人
|
|
|
+ SignatoryType string // 签订单位类型 10 终端用户 20 经销商 30 代理商
|
|
|
+ SignatoryUnit string // 合同签订单位
|
|
|
+ EarnestMoney string // 质量/履约保证金(元)
|
|
|
+ CustSignatoryId string // 客户签约人ID
|
|
|
+ CustSignatoryName string // 客户签约人
|
|
|
+ DistributorId string // 经销商ID
|
|
|
+ DistributorName string // 经销商
|
|
|
+ ServiceFeeAgreement string // 运维服务费约定
|
|
|
+ Remark string // 备注
|
|
|
+ CreatedBy string // 创建者
|
|
|
+ CreatedName string // 创建人
|
|
|
+ CreatedTime string // 创建时间
|
|
|
+ UpdatedBy string // 更新者
|
|
|
+ UpdatedName string // 更新人
|
|
|
+ UpdatedTime string // 更新时间
|
|
|
+ DeletedTime string // 删除时间
|
|
|
}
|
|
|
|
|
|
var (
|
|
|
@@ -75,43 +81,47 @@ var (
|
|
|
DB: g.DB("default"),
|
|
|
Table: "ctr_contract",
|
|
|
C: ctrContractColumns{
|
|
|
- Id: "id",
|
|
|
- ContractCode: "contract_code",
|
|
|
- ContractName: "contract_name",
|
|
|
- CustId: "cust_id",
|
|
|
- CustName: "cust_name",
|
|
|
- ProductLine: "product_line",
|
|
|
- IsBig: "is_big",
|
|
|
- CustProvinceId: "cust_province_id",
|
|
|
- CustProvince: "cust_province",
|
|
|
- CustCityId: "cust_city_id",
|
|
|
- CustCity: "cust_city",
|
|
|
- NboId: "nbo_id",
|
|
|
- NboName: "nbo_name",
|
|
|
- ApproStatus: "appro_status",
|
|
|
- ContractType: "contract_type",
|
|
|
- ContractAmount: "contract_amount",
|
|
|
- InvoiceAmount: "invoice_amount",
|
|
|
- CollectedAmount: "collected_amount",
|
|
|
- ContractStartTime: "contract_start_time",
|
|
|
- ContractEndTime: "contract_end_time",
|
|
|
- InchargeId: "incharge_id",
|
|
|
- InchargeName: "incharge_name",
|
|
|
- SignatoryId: "signatory_id",
|
|
|
- SignatoryName: "signatory_name",
|
|
|
- SignatoryType: "signatory_type",
|
|
|
- CustSignatoryId: "cust_signatory_id",
|
|
|
- CustSignatoryName: "cust_signatory_name",
|
|
|
- DistributorId: "distributor_id",
|
|
|
- DistributorName: "distributor_name",
|
|
|
- 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",
|
|
|
+ ContractCode: "contract_code",
|
|
|
+ ContractName: "contract_name",
|
|
|
+ CustId: "cust_id",
|
|
|
+ CustName: "cust_name",
|
|
|
+ ProductLine: "product_line",
|
|
|
+ IsBig: "is_big",
|
|
|
+ CustProvinceId: "cust_province_id",
|
|
|
+ CustProvince: "cust_province",
|
|
|
+ CustCityId: "cust_city_id",
|
|
|
+ CustCity: "cust_city",
|
|
|
+ NboId: "nbo_id",
|
|
|
+ NboName: "nbo_name",
|
|
|
+ ApproStatus: "appro_status",
|
|
|
+ ContractType: "contract_type",
|
|
|
+ ContractAmount: "contract_amount",
|
|
|
+ InvoiceAmount: "invoice_amount",
|
|
|
+ CollectedAmount: "collected_amount",
|
|
|
+ ContractStartTime: "contract_start_time",
|
|
|
+ ContractEndTime: "contract_end_time",
|
|
|
+ ContractSignTime: "contract_sign_time",
|
|
|
+ InchargeId: "incharge_id",
|
|
|
+ InchargeName: "incharge_name",
|
|
|
+ SignatoryId: "signatory_id",
|
|
|
+ SignatoryName: "signatory_name",
|
|
|
+ SignatoryType: "signatory_type",
|
|
|
+ SignatoryUnit: "signatory_unit",
|
|
|
+ EarnestMoney: "earnest_money",
|
|
|
+ CustSignatoryId: "cust_signatory_id",
|
|
|
+ CustSignatoryName: "cust_signatory_name",
|
|
|
+ DistributorId: "distributor_id",
|
|
|
+ DistributorName: "distributor_name",
|
|
|
+ ServiceFeeAgreement: "service_fee_agreement",
|
|
|
+ Remark: "remark",
|
|
|
+ CreatedBy: "created_by",
|
|
|
+ CreatedName: "created_name",
|
|
|
+ CreatedTime: "created_time",
|
|
|
+ UpdatedBy: "updated_by",
|
|
|
+ UpdatedName: "updated_name",
|
|
|
+ UpdatedTime: "updated_time",
|
|
|
+ DeletedTime: "deleted_time",
|
|
|
},
|
|
|
}
|
|
|
)
|
|
|
@@ -123,43 +133,47 @@ func NewCtrContractDao(tenant string) CtrContractDao {
|
|
|
DB: g.DB(tenant),
|
|
|
Table: "ctr_contract",
|
|
|
C: ctrContractColumns{
|
|
|
- Id: "id",
|
|
|
- ContractCode: "contract_code",
|
|
|
- ContractName: "contract_name",
|
|
|
- CustId: "cust_id",
|
|
|
- CustName: "cust_name",
|
|
|
- ProductLine: "product_line",
|
|
|
- IsBig: "is_big",
|
|
|
- CustProvinceId: "cust_province_id",
|
|
|
- CustProvince: "cust_province",
|
|
|
- CustCityId: "cust_city_id",
|
|
|
- CustCity: "cust_city",
|
|
|
- NboId: "nbo_id",
|
|
|
- NboName: "nbo_name",
|
|
|
- ApproStatus: "appro_status",
|
|
|
- ContractType: "contract_type",
|
|
|
- ContractAmount: "contract_amount",
|
|
|
- InvoiceAmount: "invoice_amount",
|
|
|
- CollectedAmount: "collected_amount",
|
|
|
- ContractStartTime: "contract_start_time",
|
|
|
- ContractEndTime: "contract_end_time",
|
|
|
- InchargeId: "incharge_id",
|
|
|
- InchargeName: "incharge_name",
|
|
|
- SignatoryId: "signatory_id",
|
|
|
- SignatoryName: "signatory_name",
|
|
|
- SignatoryType: "signatory_type",
|
|
|
- CustSignatoryId: "cust_signatory_id",
|
|
|
- CustSignatoryName: "cust_signatory_name",
|
|
|
- DistributorId: "distributor_id",
|
|
|
- DistributorName: "distributor_name",
|
|
|
- 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",
|
|
|
+ ContractCode: "contract_code",
|
|
|
+ ContractName: "contract_name",
|
|
|
+ CustId: "cust_id",
|
|
|
+ CustName: "cust_name",
|
|
|
+ ProductLine: "product_line",
|
|
|
+ IsBig: "is_big",
|
|
|
+ CustProvinceId: "cust_province_id",
|
|
|
+ CustProvince: "cust_province",
|
|
|
+ CustCityId: "cust_city_id",
|
|
|
+ CustCity: "cust_city",
|
|
|
+ NboId: "nbo_id",
|
|
|
+ NboName: "nbo_name",
|
|
|
+ ApproStatus: "appro_status",
|
|
|
+ ContractType: "contract_type",
|
|
|
+ ContractAmount: "contract_amount",
|
|
|
+ InvoiceAmount: "invoice_amount",
|
|
|
+ CollectedAmount: "collected_amount",
|
|
|
+ ContractStartTime: "contract_start_time",
|
|
|
+ ContractEndTime: "contract_end_time",
|
|
|
+ ContractSignTime: "contract_sign_time",
|
|
|
+ InchargeId: "incharge_id",
|
|
|
+ InchargeName: "incharge_name",
|
|
|
+ SignatoryId: "signatory_id",
|
|
|
+ SignatoryName: "signatory_name",
|
|
|
+ SignatoryType: "signatory_type",
|
|
|
+ SignatoryUnit: "signatory_unit",
|
|
|
+ EarnestMoney: "earnest_money",
|
|
|
+ CustSignatoryId: "cust_signatory_id",
|
|
|
+ CustSignatoryName: "cust_signatory_name",
|
|
|
+ DistributorId: "distributor_id",
|
|
|
+ DistributorName: "distributor_name",
|
|
|
+ ServiceFeeAgreement: "service_fee_agreement",
|
|
|
+ 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
|
|
|
@@ -760,28 +774,10 @@ func (d *CtrContractDao) Unscoped() *CtrContractDao {
|
|
|
}
|
|
|
|
|
|
// DataScope enables the DataScope feature.
|
|
|
-func (d *CtrContractDao) DataScope(ctx context.Context, userCol ...string) *CtrContractDao {
|
|
|
+func (d *CtrContractDao) DataScope(ctx context.Context, args ...interface{}) *CtrContractDao {
|
|
|
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 {
|
|
|
@@ -790,22 +786,34 @@ func (d *CtrContractDao) DataScope(ctx context.Context, userCol ...string) *CtrC
|
|
|
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 {
|
|
|
@@ -820,3 +828,80 @@ func (d *CtrContractDao) DataScope(ctx context.Context, userCol ...string) *CtrC
|
|
|
}
|
|
|
return d
|
|
|
}
|
|
|
+
|
|
|
+// args 1、字段
|
|
|
+// args 2、字段、表名
|
|
|
+// args 3、字段对应关系
|
|
|
+func (d *CtrContractDao) 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
|
|
|
+}
|