databse_test.go 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package gopkgs
  2. import (
  3. "git.getensh.com/common/gopkgsv2/database"
  4. "git.getensh.com/common/gopkgsv2/logger"
  5. "go.uber.org/zap"
  6. "log"
  7. "testing"
  8. "time"
  9. )
  10. // TOrder ...
  11. type Order struct {
  12. Id uint64 `gorm:"column:id" json:"id"`
  13. // OrderSn 订单编号
  14. OrderSn string `gorm:"column:order_sn" json:"order_sn"`
  15. // OrderType 订单类型(1钥匙柜养车2预约养车3代驾养车4门店开单5年检6车险)
  16. OrderType uint8 `gorm:"column:order_type" json:"order_type"`
  17. // UID B端用户id
  18. Uid uint64 `gorm:"column:uid" json:"uid"`
  19. // YclUID C端用户id
  20. YclUid uint64 `gorm:"column:ycl_uid" json:"ycl_uid"`
  21. // Sid 商户id
  22. Sid uint64 `gorm:"column:sid" json:"sid"`
  23. // Shop 商户名称
  24. Shop string `gorm:"column:shop" json:"shop"`
  25. // Cid 企业id
  26. Cid uint64 `gorm:"column:cid" json:"cid"`
  27. // Company 企业名称
  28. Company string `gorm:"column:company" json:"company"`
  29. // Status 订单状态(10下单20存钥匙30服务中40第三方服务50已完成60已关闭70已过期)
  30. Status uint8 `gorm:"column:status" json:"status"`
  31. // SvcStatus 业务状态
  32. SvcStatus uint32 `gorm:"column:svc_status" json:"svc_status"`
  33. // TotalAmount 订单金额
  34. TotalAmount uint32 `gorm:"column:total_amount" json:"total_amount"`
  35. // DiscountAmount 折扣金额
  36. DiscountAmount uint32 `gorm:"column:discount_amount" json:"discount_amount"`
  37. // PayAmount 实际支付金额
  38. PayAmount uint32 `gorm:"column:pay_amount" json:"pay_amount"`
  39. ActualAmount uint32 `gorm:"column:actual_amount" json:"actual_amount"`
  40. Explain string `gorm:"column:explain" json:"explain"`
  41. ExplainUid uint64 `gorm:"column:explain_uid" json:"explain_uid"`
  42. ExplainName string `gorm:"column:explain_name" json:"explain_name"`
  43. ExplainTime time.Time `gorm:"column:explain_time" json:"explain_time"`
  44. // VehicleID 车辆id
  45. VehicleId uint64 `gorm:"column:vehicle_id" json:"vehicle_id"`
  46. // BrandID 品牌id
  47. BrandId string `gorm:"column:brand_id" json:"brand_id"`
  48. // PlateNo 车牌号
  49. PlateNo string `gorm:"column:plate_no" json:"plate_no"`
  50. // Services 服务简要
  51. Services string `gorm:"column:services" json:"services"`
  52. // Payed 支付状态 0-N,1-Y
  53. Payed uint8 `gorm:"column:payed" json:"payed"`
  54. // Commented 评论状态 0-N,1-Y
  55. Commented uint8 `gorm:"column:commented" json:"commented"`
  56. // ReservationStart 预约开始时间
  57. ReservationStart time.Time `gorm:"column:reservation_start" json:"reservation_start"`
  58. // ReservationEnd 预约结束时间
  59. ReservationEnd time.Time `gorm:"column:reservation_end" json:"reservation_end"`
  60. // CreatedTime 下单时间
  61. CreatedTime time.Time `gorm:"column:created_time" json:"created_time"`
  62. // PayedTime 支付时间
  63. PayedTime time.Time `gorm:"column:payed_time" json:"payed_time"`
  64. // CompletedTime 完成时间
  65. CompletedTime time.Time `gorm:"column:completed_time" json:"completed_time"`
  66. IsDelete int64 `gorm:"column:is_delete"`
  67. UnPrice int32 `gorm:"column:un_price" json:"un_price"`
  68. VehicleSource int64 `gorm:"column:vehicle_source" json:"vehicle_source"`
  69. }
  70. func loggerNew() *zap.Logger {
  71. return logger.New("dev",
  72. "debug",
  73. "logs/text-access.log",
  74. 100,
  75. 100,
  76. 100,
  77. false,
  78. true)
  79. }
  80. func TestDB(t *testing.T) {
  81. loggerNew()
  82. database.Setup("root", "Pwd#123456", "47.103.130.208:3308", "db_order", "utf8", 100, 10, true)
  83. db := database.DB()
  84. order := &[]Order{}
  85. db = db.Table("t_order").Where(map[string]interface{}{"sid": 1}).Find(order)
  86. //if db.Error != nil {
  87. // //log.Fatal("err: ", db.Error)
  88. //}
  89. log.Fatal("err: ", db.Error)
  90. }