package final import ( "fmt" "zhiyuan/pkg/db" "zhiyuan/pkg/utils" "github.com/gin-gonic/gin" ) type FinalSupplierContract struct { ID int64 `json:"id" prop:"add:false"` Name string `json:"name" label:"名称" type:"string" prop:"add edit"` SupplierId int64 `json:"supplierId" label:"材料商ID" type:"int" prop:"add" search:"="` StartDate int64 `json:"startdate" label:"开始日期" type:"int" prop:"add edit"` EndDate int64 `json:"enddate" label:"截止日期" type:"int" prop:"add edit"` Remark string `json:"remark" label:"备注" type:"string" prop:"edit"` Info string `json:"info" label:"返点" type:"string" prop:"edit"` State int64 `json:"state" label:"状态" type:"int" prop:"edit" default:"0" search:"="` DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"` CreatedAt int64 `json:"created_at" prop:"add:false"` UpdatedAt int64 `json:"updated_at" prop:"add:false"` db.BaseModel } type ContractPoint struct { Amount float64 `json:"amount"` Point float64 `json:"point"` } func (FinalSupplierContract) TableName() string { return "zy_final_supplier_contract" } func (FinalSupplierContract) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { return true } func (FinalSupplierContract) OnePrivilege(c *gin.Context, id int64) bool { return true } func (FinalSupplierContract) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error { return nil } func (FinalSupplierContract) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error { return nil } func (FinalSupplierContract) DelPrivilege(c *gin.Context, id int64) error { return nil } func (FinalSupplierContract) Page() bool { return false } func (FinalSupplierContract) Count() bool { return true } func (FinalSupplierContract) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel { return []db.JoinModel{} } func FinalSupplierContractPoints(info string) []ContractPoint { dest := make([]ContractPoint, 0) utils.JsonDecode(info).To(&dest) return dest } type FinalSupplierContractStatist struct { AmountTotal float64 `json:"amount_total" type:"float" prop:"select:ifnull(sum(order.total),0)"` DeductionTotal float64 `json:"deduction_total" type:"float" prop:"select:ifnull(sum(deduction.amount),0)"` FinalSupplierContract } func (model FinalSupplierContractStatist) GroupBy() string { return fmt.Sprintf("`%s`.`id`", model.TableName()) } func (model FinalSupplierContractStatist) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool { return model.FinalSupplierContract.ListPrivilege(c, data, s) } func (model FinalSupplierContractStatist) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel { return append(model.FinalSupplierContract.LeftJoin(data, s), db.JoinModel{ Model: FinalSupplierContractDeduction{}, As: "deduction", On: []string{ fmt.Sprintf("`deduction`.`contractId` = `%s`.`id` and `deduction`.`deleted_at` = 0", model.TableName()), }, }, db.JoinModel{ Model: FinalMaterialSettle{}, As: "settle", On: []string{ "`settle`.`id` = `deduction`.`settleId` and `settle`.`state` != -1 and `settle`.`deleted_at` = 0", }, }, db.JoinModel{ Model: FinalMaterialOrder{}, As: "order", On: []string{ fmt.Sprintf("`order`.`settle_id` = `settle`.`id` and `order`.`over_time` >= `%s`.`startdate` and `order`.`over_time` < `%s`.`enddate`+24*3600 and `order`.`deleted_at` = 0", model.TableName(), model.TableName()), }, }) }