123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- package final
- import (
- "errors"
- "fmt"
- "zhiyuan/pkg/db"
- "github.com/gin-gonic/gin"
- )
- type FinalSiteControl struct {
- ID int64 `json:"id" prop:"add:false"`
- TypeId int64 `json:"type_id" label:"类型" type:"int" prop:"add edit" search:"="`
- SiteId int64 `json:"site_id" label:"工地" type:"int" prop:"add edit" search:"="`
- Budget float64 `json:"budget" label:"控额" type:"float" prop:"edit" default:"0"`
- ChangeState int64 `json:"change_state" label:"状态" type:"int" prop:"add:false 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
- }
- func (FinalSiteControl) TableName() string {
- return "zy_final_site_control"
- }
- func (model FinalSiteControl) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
- return true
- }
- func (FinalSiteControl) OnePrivilege(c *gin.Context, id int64) bool {
- return true
- }
- func (FinalSiteControl) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
- typ, _ := db.ToInt64(data["type_id"])
- site_id, _ := db.ToInt64(data["site_id"])
- table, _ := db.GetModelMap(db.Type(FinalSiteControl{}), map[string]interface{}{"type_id": typ, "site_id": site_id, "deleted_at": 0}, nil)
- if table != nil {
- return errors.New("没有权限")
- }
- return nil
- }
- func (FinalSiteControl) AddAfter(c *gin.Context, id int64, post map[string]interface{}, data map[string]interface{}) {
- }
- func (FinalSiteControl) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
- return nil
- }
- func (FinalSiteControl) DelPrivilege(c *gin.Context, id int64) error {
- return nil
- }
- func (FinalSiteControl) Page() bool {
- return false
- }
- func (FinalSiteControl) Count() bool {
- return true
- }
- type FinalSiteControlMobile struct {
- Name string `json:"name" type:"string" prop:"select:type.name"`
- Budget float64 `json:"budget" label:"控额" type:"float" prop:"edit" default:"0"`
- LivingCount int64 `json:"living_count" type:"int" prop:"select:count(distinct(IF(table.type=1,table.id,NULL)))"`
- SettleCount int64 `json:"settle_count" type:"int" prop:"select:count(distinct(IF(table.type=0,table.id,NULL)))"`
- LivingBudget int64 `json:"living_budget" type:"int" prop:"select:zy_final_site_control.budget*type.living_proportion/100-if(count(table.id)=0,0,sum(table.total))"`
- SettleBudget int64 `json:"settle_budget" type:"int" prop:"select:zy_final_site_control.budget-if(count(table.id)=0,0,sum(table.total))"`
- LivingState int64 `json:"living_state" type:"int" prop:"select:IF((zy_final_site_control.budget!=0)and(count(distinct(IF(table.state<2,table.id,NULL)))=0)and(count(distinct(IF(table.type=1,table.id,NULL)))<type.living_count)and(count(distinct(IF(table.type=0,table.id,NULL)))=0)and((type.living_settlement=0)or(not(isnull(livingpayment.id)))),1,0)"`
- SettleState int64 `json:"settle_state" type:"int" prop:"select:IF((zy_final_site_control.budget!=0)and(count(distinct(IF(table.state<2,table.id,NULL)))=0)and((type.settle_change=0)or(site.change_state=1))and((type.settlement=0)or(not(isnull(settlepayment.id))))and(count(distinct(IF(table.type=0,table.id,NULL)))=0),1,0)"`
- AuxiliaryId int64 `json:"auxiliary_id" type:"int" prop:"select:type.auxiliary_id"`
- FinalSiteControl
- }
- func (model FinalSiteControlMobile) GroupBy() string {
- return fmt.Sprintf("`%s`.`id`", model.TableName())
- }
- func (model FinalSiteControlMobile) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
- return []db.JoinModel{{
- Model: FinalType{},
- As: "type",
- On: []string{"`type`.`id` = " + model.TableName() + ".`type_id`"},
- }, {
- Model: FinalSite{},
- As: "site",
- On: []string{"`site`.`id` = " + model.TableName() + ".`site_id`"},
- }, {
- Model: FinalSiteTable{},
- As: "table",
- On: []string{"`table`.`type_id` = " + model.TableName() + ".`type_id` and `table`.`site_id` = " + model.TableName() + ".`site_id` and `table`.`state` != -1 and `table`.`deleted_at` = 0"},
- }, {
- Model: FinalSitePayment{},
- As: "livingpayment",
- On: []string{"`livingpayment`.`type_id` = `type`.`living_settlement` and `livingpayment`.`site_id` = " + model.TableName() + ".`site_id` and `livingpayment`.`state` = 1 and `livingpayment`.`deleted_at` = 0"},
- }, {
- Model: FinalSitePayment{},
- As: "settlepayment",
- On: []string{"`settlepayment`.`type_id` = `type`.`settlement` and `settlepayment`.`site_id` = " + model.TableName() + ".`site_id` and `settlepayment`.`state` = 1 and `settlepayment`.`deleted_at` = 0"},
- }}
- }
- type FinalSiteControlStatist struct {
- Budget float64 `json:"budget" label:"控额" type:"float" prop:"edit" default:"0"`
- SubmittedTotal float64 `json:"submitted_total" type:"float" prop:"select:sum(IF(table.state!=0,ROUND(table.total),0))"`
- CompletedTotal float64 `json:"completed_total" type:"float" prop:"select:sum(IF(table.state=5,ROUND(table.total),0))"`
- FinalSiteControl
- }
- func (model FinalSiteControlStatist) GroupBy() string {
- return fmt.Sprintf("`%s`.`id`", model.TableName())
- }
- func (model FinalSiteControlStatist) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
- return []db.JoinModel{{
- Model: FinalSiteTable{},
- As: "table",
- On: []string{"`table`.`type_id` = " + model.TableName() + ".`type_id` and `table`.`site_id` = " + model.TableName() + ".`site_id` and `table`.`state` != -1 and `table`.`deleted_at` = 0"},
- }}
- }
|