final_supplier.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package final
  2. import (
  3. "fmt"
  4. "zhiyuan/pkg/db"
  5. "github.com/gin-gonic/gin"
  6. )
  7. type FinalSupplier struct {
  8. ID int64 `json:"id" prop:"add:false"`
  9. Name string `json:"name" label:"名称" type:"string" prop:"add edit" search:"like"`
  10. AdminId int64 `json:"adminId" label:"人员ID" type:"int" prop:"add edit" search:"="`
  11. ReceiptHour int64 `json:"receipt_hour" label:"配送小时" type:"int" prop:"edit" default:"0" search:"="`
  12. StockHour int64 `json:"stock_hour" label:"备货小时" type:"int" prop:"edit" default:"0" search:"="`
  13. CustomStockHour int64 `json:"custom_stock_hour" label:"定制品备货小时" type:"int" prop:"edit" default:"0" search:"="`
  14. InstallHour int64 `json:"install_hour" label:"安装小时" type:"int" prop:"edit" default:"0" search:"="`
  15. Prepayment int64 `json:"prepayment" label:"预付款" type:"int" prop:"edit" default:"0" search:"="`
  16. WarningAmount float64 `json:"warning_amount" label:"预付款预警金额" type:"float" prop:"edit" default:"0" search:"="`
  17. NoticeIds string `json:"notice_ids" label:"预付款通知人" type:"string" prop:"edit"`
  18. Install int64 `json:"install" label:"安装" type:"int" prop:"edit" default:"0" search:"="`
  19. Reduce int64 `json:"reduce" label:"精简流程" type:"int" prop:"edit" default:"0" search:"="`
  20. State int64 `json:"state" label:"状态" type:"int" prop:"edit" default:"0" search:"="`
  21. OrderAt int64 `json:"order_at" prop:"add:false select:false"`
  22. DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
  23. CreatedAt int64 `json:"created_at" prop:"add:false"`
  24. UpdatedAt int64 `json:"updated_at" prop:"add:false"`
  25. db.BaseModel
  26. }
  27. func (FinalSupplier) TableName() string {
  28. return "zy_final_supplier"
  29. }
  30. func (FinalSupplier) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  31. return true
  32. }
  33. func (FinalSupplier) OnePrivilege(c *gin.Context, id int64) bool {
  34. return true
  35. }
  36. func (FinalSupplier) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
  37. return nil
  38. }
  39. func (FinalSupplier) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
  40. return nil
  41. }
  42. func (FinalSupplier) DelPrivilege(c *gin.Context, id int64) error {
  43. return nil
  44. }
  45. func (FinalSupplier) Page() bool {
  46. return false
  47. }
  48. func (FinalSupplier) Count() bool {
  49. return true
  50. }
  51. func (model FinalSupplier) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  52. return []db.JoinModel{}
  53. }
  54. type FinalSupplierPrepaymentStatist struct {
  55. OrderTotal float64 `json:"order_total" type:"float" prop:"select:ifnull(order.total,0)"`
  56. PrepaymentTotal float64 `json:"prepayment_total" type:"float" prop:"select:ifnull(prepayment.total,0)"`
  57. Total float64 `json:"total" type:"float" prop:"select:ifnull(prepayment.total,0)-ifnull(order.total,0)"`
  58. FinalSupplier
  59. }
  60. type FinalSupplierJoinOrder struct {
  61. db.BaseModel
  62. }
  63. func (FinalSupplierJoinOrder) TableName() string {
  64. return "(select `supplier_id`,ifnull(sum(total),0) as `total` from `zy_final_material_order` where `state` >= 0 and `deleted_at` = 0 group by `supplier_id`)"
  65. }
  66. type FinalSupplierJoinPrepayment struct {
  67. db.BaseModel
  68. }
  69. func (FinalSupplierJoinPrepayment) TableName() string {
  70. return "(select `supplierId`,ifnull(sum(amount),0) as `total` from `zy_final_supplier_prepayment` where `deleted_at` = 0 group by `supplierId`)"
  71. }
  72. func (model FinalSupplierPrepaymentStatist) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  73. s.Where = append(s.Where, fmt.Sprintf("`%s`.`prepayment` = %s", model.TableName(), s.Param(1)))
  74. return model.FinalSupplier.ListPrivilege(c, data, s)
  75. }
  76. func (model FinalSupplierPrepaymentStatist) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  77. return append(model.FinalSupplier.LeftJoin(data, s), db.JoinModel{
  78. Model: FinalSupplierJoinOrder{},
  79. As: "order",
  80. On: []string{
  81. fmt.Sprintf("`order`.`supplier_id` = `%s`.`id`", model.TableName()),
  82. },
  83. }, db.JoinModel{
  84. Model: FinalSupplierJoinPrepayment{},
  85. As: "prepayment",
  86. On: []string{
  87. fmt.Sprintf("`prepayment`.`supplierId` = `%s`.`id`", model.TableName()),
  88. },
  89. })
  90. }
  91. type FinalSupplierTimeoutStatist struct {
  92. MeasureTimeout float64 `json:"measure_timeout" type:"float" prop:"select:if(isnull(order.id),0,count(if(order.measure_time-order.notice_measure_time>7*24*60*60,1,0)))"`
  93. StockTimeout float64 `json:"stock_timeout" type:"float" prop:"select:if(isnull(order.id),0,count(if(order.take_time+if(order.is_custom=1,zy_final_supplier.custom_stock_hour,zy_final_supplier.stock_hour)*3600<order.stock_time,1,0)))"`
  94. ReceiptTimeout float64 `json:"receipt_timeout" type:"float" prop:"select:if(isnull(order.id),0,count(if(order.deliver_time>order.receipt_date,1,0)))"`
  95. InstallTimeout float64 `json:"install_timeout" type:"float" prop:"select:if(isnull(order.id),0,count(if(order.install_time>order.install_date,1,0)))"`
  96. TimeoutTotal float64 `json:"timeout_total" type:"float" prop:"select:if(isnull(order.id),0,count(if(order.measure_time-order.notice_measure_time>7*24*60*60,1,0)+if(order.take_time+if(order.is_custom=1,zy_final_supplier.custom_stock_hour,zy_final_supplier.stock_hour)*3600<order.stock_time,1,0)+if(order.deliver_time>order.receipt_date,1,0)+if(order.install_time>order.install_date,1,0)))"`
  97. FinalSupplier
  98. }
  99. func (model FinalSupplierTimeoutStatist) GroupBy() string {
  100. return fmt.Sprintf("`%s`.`id`", model.TableName())
  101. }
  102. func (model FinalSupplierTimeoutStatist) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  103. return append(model.FinalSupplier.LeftJoin(data, s), db.JoinModel{
  104. Model: FinalMaterialOrder{},
  105. As: "order",
  106. On: []string{
  107. fmt.Sprintf("`order`.`supplier_id` = `%s`.`id`", model.TableName()),
  108. },
  109. })
  110. }