final_supplier_contract.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package final
  2. import (
  3. "fmt"
  4. "zhiyuan/pkg/db"
  5. "zhiyuan/pkg/utils"
  6. "github.com/gin-gonic/gin"
  7. )
  8. type FinalSupplierContract struct {
  9. ID int64 `json:"id" prop:"add:false"`
  10. Name string `json:"name" label:"名称" type:"string" prop:"add edit"`
  11. SupplierId int64 `json:"supplierId" label:"材料商ID" type:"int" prop:"add" search:"="`
  12. StartDate int64 `json:"startdate" label:"开始日期" type:"int" prop:"add edit"`
  13. EndDate int64 `json:"enddate" label:"截止日期" type:"int" prop:"add edit"`
  14. Remark string `json:"remark" label:"备注" type:"string" prop:"edit"`
  15. Info string `json:"info" label:"返点" type:"string" prop:"edit"`
  16. State int64 `json:"state" label:"状态" type:"int" prop:"edit" default:"0" search:"="`
  17. DeletedAt int64 `json:"deleted_at" prop:"add:false select:false"`
  18. CreatedAt int64 `json:"created_at" prop:"add:false"`
  19. UpdatedAt int64 `json:"updated_at" prop:"add:false"`
  20. db.BaseModel
  21. }
  22. type ContractPoint struct {
  23. Amount float64 `json:"amount"`
  24. Point float64 `json:"point"`
  25. }
  26. func (FinalSupplierContract) TableName() string {
  27. return "zy_final_supplier_contract"
  28. }
  29. func (FinalSupplierContract) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  30. return true
  31. }
  32. func (FinalSupplierContract) OnePrivilege(c *gin.Context, id int64) bool {
  33. return true
  34. }
  35. func (FinalSupplierContract) AddPrivilege(c *gin.Context, data map[string]interface{}, post map[string]interface{}) error {
  36. return nil
  37. }
  38. func (FinalSupplierContract) EditPrivilege(c *gin.Context, id int64, data map[string]interface{}, post map[string]interface{}) error {
  39. return nil
  40. }
  41. func (FinalSupplierContract) DelPrivilege(c *gin.Context, id int64) error {
  42. return nil
  43. }
  44. func (FinalSupplierContract) Page() bool {
  45. return false
  46. }
  47. func (FinalSupplierContract) Count() bool {
  48. return true
  49. }
  50. func (FinalSupplierContract) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  51. return []db.JoinModel{}
  52. }
  53. func FinalSupplierContractPoints(info string) []ContractPoint {
  54. dest := make([]ContractPoint, 0)
  55. utils.JsonDecode(info).To(&dest)
  56. return dest
  57. }
  58. type FinalSupplierContractStatist struct {
  59. AmountTotal float64 `json:"amount_total" type:"float" prop:"select:ifnull(sum(order.total),0)"`
  60. DeductionTotal float64 `json:"deduction_total" type:"float" prop:"select:ifnull(sum(deduction.amount),0)"`
  61. FinalSupplierContract
  62. }
  63. func (model FinalSupplierContractStatist) GroupBy() string {
  64. return fmt.Sprintf("`%s`.`id`", model.TableName())
  65. }
  66. func (model FinalSupplierContractStatist) ListPrivilege(c *gin.Context, data map[string]interface{}, s *db.Select) bool {
  67. return model.FinalSupplierContract.ListPrivilege(c, data, s)
  68. }
  69. func (model FinalSupplierContractStatist) LeftJoin(data map[string]interface{}, s *db.Select) []db.JoinModel {
  70. return append(model.FinalSupplierContract.LeftJoin(data, s), db.JoinModel{
  71. Model: FinalSupplierContractDeduction{},
  72. As: "deduction",
  73. On: []string{
  74. fmt.Sprintf("`deduction`.`contractId` = `%s`.`id` and `deduction`.`deleted_at` = 0", model.TableName()),
  75. },
  76. }, db.JoinModel{
  77. Model: FinalMaterialSettle{},
  78. As: "settle",
  79. On: []string{
  80. "`settle`.`id` = `deduction`.`settleId` and `settle`.`state` != -1 and `settle`.`deleted_at` = 0",
  81. },
  82. }, db.JoinModel{
  83. Model: FinalMaterialOrder{},
  84. As: "order",
  85. On: []string{
  86. 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()),
  87. },
  88. })
  89. }