final_site_control.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package final
  2. import (
  3. "errors"
  4. "fmt"
  5. "zhiyuan/pkg/db"
  6. "github.com/gin-gonic/gin"
  7. )
  8. type FinalSiteControl struct {
  9. ID int64 `json:"id" prop:"add:false"`
  10. TypeId int64 `json:"type_id" label:"类型" type:"int" prop:"add edit" search:"="`
  11. SiteId int64 `json:"site_id" label:"工地" type:"int" prop:"add edit" search:"="`
  12. Budget float64 `json:"budget" label:"控额" type:"float" prop:"edit" default:"0"`
  13. ChangeState int64 `json:"change_state" label:"状态" type:"int" prop:"add:false edit" default:"0" search:"="`
  14. DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
  15. CreatedAt int64 `json:"created_at" prop:"add:false"`
  16. UpdatedAt int64 `json:"updated_at" prop:"add:false"`
  17. db.BaseModel
  18. }
  19. func (FinalSiteControl) TableName() string {
  20. return "zy_final_site_control"
  21. }
  22. func (model FinalSiteControl) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  23. return true
  24. }
  25. func (FinalSiteControl) OnePrivilege(c *gin.Context, id int64) bool {
  26. return true
  27. }
  28. func (FinalSiteControl) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
  29. typ, _ := db.ToInt64(data["type_id"])
  30. site_id, _ := db.ToInt64(data["site_id"])
  31. table, _ := db.GetModelMap(db.Type(FinalSiteControl{}), map[string]interface{}{"type_id": typ, "site_id": site_id, "deleted_at": 0}, nil)
  32. if table != nil {
  33. return errors.New("没有权限")
  34. }
  35. return nil
  36. }
  37. func (FinalSiteControl) AddAfter(c *gin.Context, id int64, post map[string]interface{}, data map[string]interface{}) {
  38. }
  39. func (FinalSiteControl) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
  40. return nil
  41. }
  42. func (FinalSiteControl) DelPrivilege(c *gin.Context, id int64) error {
  43. return nil
  44. }
  45. func (FinalSiteControl) Page() bool {
  46. return false
  47. }
  48. func (FinalSiteControl) Count() bool {
  49. return true
  50. }
  51. type FinalSiteControlMobile struct {
  52. Name string `json:"name" type:"string" prop:"select:type.name"`
  53. Budget float64 `json:"budget" label:"控额" type:"float" prop:"edit" default:"0"`
  54. LivingCount int64 `json:"living_count" type:"int" prop:"select:count(distinct(IF(table.type=1,table.id,NULL)))"`
  55. SettleCount int64 `json:"settle_count" type:"int" prop:"select:count(distinct(IF(table.type=0,table.id,NULL)))"`
  56. 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))"`
  57. SettleBudget int64 `json:"settle_budget" type:"int" prop:"select:zy_final_site_control.budget-if(count(table.id)=0,0,sum(table.total))"`
  58. 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)"`
  59. 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)"`
  60. AuxiliaryId int64 `json:"auxiliary_id" type:"int" prop:"select:type.auxiliary_id"`
  61. FinalSiteControl
  62. }
  63. func (model FinalSiteControlMobile) GroupBy() string {
  64. return fmt.Sprintf("`%s`.`id`", model.TableName())
  65. }
  66. func (model FinalSiteControlMobile) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  67. return []db.JoinModel{{
  68. Model: FinalType{},
  69. As: "type",
  70. On: []string{"`type`.`id` = " + model.TableName() + ".`type_id`"},
  71. }, {
  72. Model: FinalSite{},
  73. As: "site",
  74. On: []string{"`site`.`id` = " + model.TableName() + ".`site_id`"},
  75. }, {
  76. Model: FinalSiteTable{},
  77. As: "table",
  78. 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"},
  79. }, {
  80. Model: FinalSitePayment{},
  81. As: "livingpayment",
  82. 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"},
  83. }, {
  84. Model: FinalSitePayment{},
  85. As: "settlepayment",
  86. On: []string{"`settlepayment`.`type_id` = `type`.`settlement` and `settlepayment`.`site_id` = " + model.TableName() + ".`site_id` and `settlepayment`.`state` = 1 and `settlepayment`.`deleted_at` = 0"},
  87. }}
  88. }
  89. type FinalSiteControlStatist struct {
  90. Budget float64 `json:"budget" label:"控额" type:"float" prop:"edit" default:"0"`
  91. SubmittedTotal float64 `json:"submitted_total" type:"float" prop:"select:sum(IF(table.state!=0,ROUND(table.total),0))"`
  92. CompletedTotal float64 `json:"completed_total" type:"float" prop:"select:sum(IF(table.state=5,ROUND(table.total),0))"`
  93. FinalSiteControl
  94. }
  95. func (model FinalSiteControlStatist) GroupBy() string {
  96. return fmt.Sprintf("`%s`.`id`", model.TableName())
  97. }
  98. func (model FinalSiteControlStatist) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  99. return []db.JoinModel{{
  100. Model: FinalSiteTable{},
  101. As: "table",
  102. 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"},
  103. }}
  104. }