sale.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. package models
  2. import (
  3. "database/sql"
  4. "time"
  5. "github.com/google/uuid"
  6. "github.com/guregu/null"
  7. "gorm.io/gorm"
  8. )
  9. var (
  10. _ = time.Second
  11. _ = sql.LevelDefault
  12. _ = null.Bool{}
  13. _ = uuid.UUID{}
  14. )
  15. /*
  16. DB Table Details
  17. -------------------------------------
  18. CREATE TABLE `sale` (
  19. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  20. `token_id` bigint(20) unsigned NOT NULL,
  21. `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  22. `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  23. `deleted_at` timestamp NULL DEFAULT NULL,
  24. `is_resale` tinyint(4) NOT NULL DEFAULT '0',
  25. `sale_type` enum('fixed','auction','time') COLLATE utf8mb4_bin NOT NULL,
  26. `price` double DEFAULT NULL,
  27. `start_price` double DEFAULT NULL,
  28. `start_at` timestamp NULL DEFAULT NULL,
  29. `end_at` timestamp NULL DEFAULT NULL,
  30. `uid` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  31. `currency` enum('eth','mr','mf') COLLATE utf8mb4_bin NOT NULL,
  32. `status` enum('ongoing','end','cancel') COLLATE utf8mb4_bin NOT NULL COMMENT 'Ongoing\nEnd: 판매가 일어나서 정상 종료(트랜잭션 발생)\nCancel: 판매자가 취소하는 케이스! 판매하지 않고 판매만 종료(트랜잭션 미발생)\n',
  33. `hash_data` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  34. `signature` varchar(256) COLLATE utf8mb4_bin NOT NULL,
  35. `treasury_tax` double NOT NULL,
  36. PRIMARY KEY (`id`),
  37. UNIQUE KEY `id_UNIQUE` (`id`),
  38. KEY `fk_sale_token1_idx` (`token_id`),
  39. CONSTRAINT `fk_sale_token1` FOREIGN KEY (`token_id`) REFERENCES `token` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
  40. ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
  41. JSON Sample
  42. -------------------------------------
  43. { "id": 79, "token_id": 77, "created_at": "2036-06-23T08:15:03.681534345+09:00", "updated_at": "2079-01-07T21:39:30.415341036+09:00", "deleted_at": "2311-01-12T15:25:40.427122699+09:00", "is_resale": 75, "sale_type": "LibImOuHvBkYvBlKhLaNiwVgZ", "price": 0.3331036926143512, "start_price": 0.37895024299401436, "start_at": "2219-06-08T06:32:54.134481296+09:00", "end_at": "2268-04-08T16:03:30.525325274+09:00", "uid": "PcxGvDbIOCRVcXXUVRpLjSCfd", "currency": "OuflBMihymHxsAmyJCESpMGGY", "status": "iJqTALvdjLiwOQSHVZayHZEYX", "hash_data": "QZnBmYfxODbqpkKcMkDmoeddr", "signature": "JxMcSsMLMyVHUcpKxRGwNLlJL", "treasury_tax": 0.7619896885043733}
  44. Comments
  45. -------------------------------------
  46. [ 0] column is set for unsigned
  47. [ 1] column is set for unsigned
  48. */
  49. // Sale struct is a row record of the sale table in the metarare database
  50. type Sale struct {
  51. //[ 0] id ubigint null: false primary: true isArray: false auto: true col: ubigint len: -1 default: []
  52. ID uint64 `gorm:"primary_key;AUTO_INCREMENT;column:id;type:ubigint;" json:"id"`
  53. //[ 1] token_id ubigint null: false primary: false isArray: false auto: false col: ubigint len: -1 default: []
  54. TokenID uint64 `gorm:"column:token_id;type:ubigint;" json:"token_id"`
  55. //[ 2] created_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  56. CreatedAt time.Time `gorm:"column:created_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"created_at"`
  57. //[ 3] updated_at timestamp null: false primary: false isArray: false auto: false col: timestamp len: -1 default: [CURRENT_TIMESTAMP]
  58. UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp;default:CURRENT_TIMESTAMP;" json:"updated_at"`
  59. //[ 4] deleted_at timestamp null: true primary: false isArray: false auto: false col: timestamp len: -1 default: []
  60. DeletedAt null.Time `gorm:"column:deleted_at;type:timestamp;" json:"deleted_at"`
  61. //[ 5] is_resale tinyint null: false primary: false isArray: false auto: false col: tinyint len: -1 default: [0]
  62. IsResale int32 `gorm:"column:is_resale;type:tinyint;default:0;" json:"is_resale"`
  63. //[ 6] sale_type char(7) null: false primary: false isArray: false auto: false col: char len: 7 default: []
  64. SaleType string `gorm:"column:sale_type;type:char;size:7;" json:"sale_type"`
  65. //[ 7] price double null: true primary: false isArray: false auto: false col: double len: -1 default: []
  66. Price null.Float `gorm:"column:price;type:double;" json:"price"`
  67. //[ 8] start_price double null: true primary: false isArray: false auto: false col: double len: -1 default: []
  68. StartPrice null.Float `gorm:"column:start_price;type:double;" json:"start_price"`
  69. //[ 9] start_at timestamp null: true primary: false isArray: false auto: false col: timestamp len: -1 default: []
  70. StartAt null.Time `gorm:"column:start_at;type:timestamp;" json:"start_at"`
  71. //[10] end_at timestamp null: true primary: false isArray: false auto: false col: timestamp len: -1 default: []
  72. EndAt null.Time `gorm:"column:end_at;type:timestamp;" json:"end_at"`
  73. //[11] uid varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  74. UID string `gorm:"column:uid;type:varchar;size:256;" json:"uid"`
  75. //[12] currency char(3) null: false primary: false isArray: false auto: false col: char len: 3 default: []
  76. Currency string `gorm:"column:currency;type:char;size:3;" json:"currency"`
  77. //[13] status char(7) null: false primary: false isArray: false auto: false col: char len: 7 default: []
  78. Status string `gorm:"column:status;type:char;size:7;" json:"status"` // Ongoing\nEnd: 판매가 일어나서 정상 종료(트랜잭션 발생)\nCancel: 판매자가 취소하는 케이스! 판매하지 않고 판매만 종료(트랜잭션 미발생)\n
  79. //[14] hash_data varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  80. HashData string `gorm:"column:hash_data;type:varchar;size:256;" json:"hash_data"`
  81. //[15] signature varchar(256) null: false primary: false isArray: false auto: false col: varchar len: 256 default: []
  82. Signature string `gorm:"column:signature;type:varchar;size:256;" json:"signature"`
  83. //[16] treasury_tax double null: false primary: false isArray: false auto: false col: double len: -1 default: []
  84. TreasuryTax float64 `gorm:"column:treasury_tax;type:double;" json:"treasury_tax"`
  85. Token Token
  86. BidLog BidLog
  87. }
  88. var saleTableInfo = &TableInfo{
  89. Name: "sale",
  90. Columns: []*ColumnInfo{
  91. &ColumnInfo{
  92. Index: 0,
  93. Name: "id",
  94. Comment: ``,
  95. Notes: `column is set for unsigned`,
  96. Nullable: false,
  97. DatabaseTypeName: "ubigint",
  98. DatabaseTypePretty: "ubigint",
  99. IsPrimaryKey: true,
  100. IsAutoIncrement: true,
  101. IsArray: false,
  102. ColumnType: "ubigint",
  103. ColumnLength: -1,
  104. GoFieldName: "ID",
  105. GoFieldType: "uint64",
  106. JSONFieldName: "id",
  107. ProtobufFieldName: "id",
  108. ProtobufType: "uint64",
  109. ProtobufPos: 1,
  110. },
  111. &ColumnInfo{
  112. Index: 1,
  113. Name: "token_id",
  114. Comment: ``,
  115. Notes: `column is set for unsigned`,
  116. Nullable: false,
  117. DatabaseTypeName: "ubigint",
  118. DatabaseTypePretty: "ubigint",
  119. IsPrimaryKey: false,
  120. IsAutoIncrement: false,
  121. IsArray: false,
  122. ColumnType: "ubigint",
  123. ColumnLength: -1,
  124. GoFieldName: "TokenID",
  125. GoFieldType: "uint64",
  126. JSONFieldName: "token_id",
  127. ProtobufFieldName: "token_id",
  128. ProtobufType: "uint64",
  129. ProtobufPos: 2,
  130. },
  131. &ColumnInfo{
  132. Index: 2,
  133. Name: "created_at",
  134. Comment: ``,
  135. Notes: ``,
  136. Nullable: false,
  137. DatabaseTypeName: "timestamp",
  138. DatabaseTypePretty: "timestamp",
  139. IsPrimaryKey: false,
  140. IsAutoIncrement: false,
  141. IsArray: false,
  142. ColumnType: "timestamp",
  143. ColumnLength: -1,
  144. GoFieldName: "CreatedAt",
  145. GoFieldType: "time.Time",
  146. JSONFieldName: "created_at",
  147. ProtobufFieldName: "created_at",
  148. ProtobufType: "uint64",
  149. ProtobufPos: 3,
  150. },
  151. &ColumnInfo{
  152. Index: 3,
  153. Name: "updated_at",
  154. Comment: ``,
  155. Notes: ``,
  156. Nullable: false,
  157. DatabaseTypeName: "timestamp",
  158. DatabaseTypePretty: "timestamp",
  159. IsPrimaryKey: false,
  160. IsAutoIncrement: false,
  161. IsArray: false,
  162. ColumnType: "timestamp",
  163. ColumnLength: -1,
  164. GoFieldName: "UpdatedAt",
  165. GoFieldType: "time.Time",
  166. JSONFieldName: "updated_at",
  167. ProtobufFieldName: "updated_at",
  168. ProtobufType: "uint64",
  169. ProtobufPos: 4,
  170. },
  171. &ColumnInfo{
  172. Index: 4,
  173. Name: "deleted_at",
  174. Comment: ``,
  175. Notes: ``,
  176. Nullable: true,
  177. DatabaseTypeName: "timestamp",
  178. DatabaseTypePretty: "timestamp",
  179. IsPrimaryKey: false,
  180. IsAutoIncrement: false,
  181. IsArray: false,
  182. ColumnType: "timestamp",
  183. ColumnLength: -1,
  184. GoFieldName: "DeletedAt",
  185. GoFieldType: "null.Time",
  186. JSONFieldName: "deleted_at",
  187. ProtobufFieldName: "deleted_at",
  188. ProtobufType: "uint64",
  189. ProtobufPos: 5,
  190. },
  191. &ColumnInfo{
  192. Index: 5,
  193. Name: "is_resale",
  194. Comment: ``,
  195. Notes: ``,
  196. Nullable: false,
  197. DatabaseTypeName: "tinyint",
  198. DatabaseTypePretty: "tinyint",
  199. IsPrimaryKey: false,
  200. IsAutoIncrement: false,
  201. IsArray: false,
  202. ColumnType: "tinyint",
  203. ColumnLength: -1,
  204. GoFieldName: "IsResale",
  205. GoFieldType: "int32",
  206. JSONFieldName: "is_resale",
  207. ProtobufFieldName: "is_resale",
  208. ProtobufType: "int32",
  209. ProtobufPos: 6,
  210. },
  211. &ColumnInfo{
  212. Index: 6,
  213. Name: "sale_type",
  214. Comment: ``,
  215. Notes: ``,
  216. Nullable: false,
  217. DatabaseTypeName: "char",
  218. DatabaseTypePretty: "char(7)",
  219. IsPrimaryKey: false,
  220. IsAutoIncrement: false,
  221. IsArray: false,
  222. ColumnType: "char",
  223. ColumnLength: 7,
  224. GoFieldName: "SaleType",
  225. GoFieldType: "string",
  226. JSONFieldName: "sale_type",
  227. ProtobufFieldName: "sale_type",
  228. ProtobufType: "string",
  229. ProtobufPos: 7,
  230. },
  231. &ColumnInfo{
  232. Index: 7,
  233. Name: "price",
  234. Comment: ``,
  235. Notes: ``,
  236. Nullable: true,
  237. DatabaseTypeName: "double",
  238. DatabaseTypePretty: "double",
  239. IsPrimaryKey: false,
  240. IsAutoIncrement: false,
  241. IsArray: false,
  242. ColumnType: "double",
  243. ColumnLength: -1,
  244. GoFieldName: "Price",
  245. GoFieldType: "null.Float",
  246. JSONFieldName: "price",
  247. ProtobufFieldName: "price",
  248. ProtobufType: "float",
  249. ProtobufPos: 8,
  250. },
  251. &ColumnInfo{
  252. Index: 8,
  253. Name: "start_price",
  254. Comment: ``,
  255. Notes: ``,
  256. Nullable: true,
  257. DatabaseTypeName: "double",
  258. DatabaseTypePretty: "double",
  259. IsPrimaryKey: false,
  260. IsAutoIncrement: false,
  261. IsArray: false,
  262. ColumnType: "double",
  263. ColumnLength: -1,
  264. GoFieldName: "StartPrice",
  265. GoFieldType: "null.Float",
  266. JSONFieldName: "start_price",
  267. ProtobufFieldName: "start_price",
  268. ProtobufType: "float",
  269. ProtobufPos: 9,
  270. },
  271. &ColumnInfo{
  272. Index: 9,
  273. Name: "start_at",
  274. Comment: ``,
  275. Notes: ``,
  276. Nullable: true,
  277. DatabaseTypeName: "timestamp",
  278. DatabaseTypePretty: "timestamp",
  279. IsPrimaryKey: false,
  280. IsAutoIncrement: false,
  281. IsArray: false,
  282. ColumnType: "timestamp",
  283. ColumnLength: -1,
  284. GoFieldName: "StartAt",
  285. GoFieldType: "null.Time",
  286. JSONFieldName: "start_at",
  287. ProtobufFieldName: "start_at",
  288. ProtobufType: "uint64",
  289. ProtobufPos: 10,
  290. },
  291. &ColumnInfo{
  292. Index: 10,
  293. Name: "end_at",
  294. Comment: ``,
  295. Notes: ``,
  296. Nullable: true,
  297. DatabaseTypeName: "timestamp",
  298. DatabaseTypePretty: "timestamp",
  299. IsPrimaryKey: false,
  300. IsAutoIncrement: false,
  301. IsArray: false,
  302. ColumnType: "timestamp",
  303. ColumnLength: -1,
  304. GoFieldName: "EndAt",
  305. GoFieldType: "null.Time",
  306. JSONFieldName: "end_at",
  307. ProtobufFieldName: "end_at",
  308. ProtobufType: "uint64",
  309. ProtobufPos: 11,
  310. },
  311. &ColumnInfo{
  312. Index: 11,
  313. Name: "uid",
  314. Comment: ``,
  315. Notes: ``,
  316. Nullable: false,
  317. DatabaseTypeName: "varchar",
  318. DatabaseTypePretty: "varchar(256)",
  319. IsPrimaryKey: false,
  320. IsAutoIncrement: false,
  321. IsArray: false,
  322. ColumnType: "varchar",
  323. ColumnLength: 256,
  324. GoFieldName: "UID",
  325. GoFieldType: "string",
  326. JSONFieldName: "uid",
  327. ProtobufFieldName: "uid",
  328. ProtobufType: "string",
  329. ProtobufPos: 12,
  330. },
  331. &ColumnInfo{
  332. Index: 12,
  333. Name: "currency",
  334. Comment: ``,
  335. Notes: ``,
  336. Nullable: false,
  337. DatabaseTypeName: "char",
  338. DatabaseTypePretty: "char(3)",
  339. IsPrimaryKey: false,
  340. IsAutoIncrement: false,
  341. IsArray: false,
  342. ColumnType: "char",
  343. ColumnLength: 3,
  344. GoFieldName: "Currency",
  345. GoFieldType: "string",
  346. JSONFieldName: "currency",
  347. ProtobufFieldName: "currency",
  348. ProtobufType: "string",
  349. ProtobufPos: 13,
  350. },
  351. &ColumnInfo{
  352. Index: 13,
  353. Name: "status",
  354. Comment: `Ongoing\nEnd: 판매가 일어나서 정상 종료(트랜잭션 발생)\nCancel: 판매자가 취소하는 케이스! 판매하지 않고 판매만 종료(트랜잭션 미발생)\n`,
  355. Notes: ``,
  356. Nullable: false,
  357. DatabaseTypeName: "char",
  358. DatabaseTypePretty: "char(7)",
  359. IsPrimaryKey: false,
  360. IsAutoIncrement: false,
  361. IsArray: false,
  362. ColumnType: "char",
  363. ColumnLength: 7,
  364. GoFieldName: "Status",
  365. GoFieldType: "string",
  366. JSONFieldName: "status",
  367. ProtobufFieldName: "status",
  368. ProtobufType: "string",
  369. ProtobufPos: 14,
  370. },
  371. &ColumnInfo{
  372. Index: 14,
  373. Name: "hash_data",
  374. Comment: ``,
  375. Notes: ``,
  376. Nullable: false,
  377. DatabaseTypeName: "varchar",
  378. DatabaseTypePretty: "varchar(256)",
  379. IsPrimaryKey: false,
  380. IsAutoIncrement: false,
  381. IsArray: false,
  382. ColumnType: "varchar",
  383. ColumnLength: 256,
  384. GoFieldName: "HashData",
  385. GoFieldType: "string",
  386. JSONFieldName: "hash_data",
  387. ProtobufFieldName: "hash_data",
  388. ProtobufType: "string",
  389. ProtobufPos: 15,
  390. },
  391. &ColumnInfo{
  392. Index: 15,
  393. Name: "signature",
  394. Comment: ``,
  395. Notes: ``,
  396. Nullable: false,
  397. DatabaseTypeName: "varchar",
  398. DatabaseTypePretty: "varchar(256)",
  399. IsPrimaryKey: false,
  400. IsAutoIncrement: false,
  401. IsArray: false,
  402. ColumnType: "varchar",
  403. ColumnLength: 256,
  404. GoFieldName: "Signature",
  405. GoFieldType: "string",
  406. JSONFieldName: "signature",
  407. ProtobufFieldName: "signature",
  408. ProtobufType: "string",
  409. ProtobufPos: 16,
  410. },
  411. &ColumnInfo{
  412. Index: 16,
  413. Name: "treasury_tax",
  414. Comment: ``,
  415. Notes: ``,
  416. Nullable: false,
  417. DatabaseTypeName: "double",
  418. DatabaseTypePretty: "double",
  419. IsPrimaryKey: false,
  420. IsAutoIncrement: false,
  421. IsArray: false,
  422. ColumnType: "double",
  423. ColumnLength: -1,
  424. GoFieldName: "TreasuryTax",
  425. GoFieldType: "float64",
  426. JSONFieldName: "treasury_tax",
  427. ProtobufFieldName: "treasury_tax",
  428. ProtobufType: "float",
  429. ProtobufPos: 17,
  430. },
  431. },
  432. }
  433. // TableName sets the insert table name for this struct type
  434. func (s *Sale) TableName() string {
  435. return "sale"
  436. }
  437. // BeforeSave invoked before saving, return an error if field is not populated.
  438. func (s *Sale) BeforeSave(*gorm.DB) error {
  439. return nil
  440. }
  441. // Prepare invoked before saving, can be used to populate fields etc.
  442. func (s *Sale) Prepare() {
  443. }
  444. // Validate invoked before performing action, return an error if field is not populated.
  445. func (s *Sale) Validate(action Action) error {
  446. return nil
  447. }
  448. // TableInfo return table meta data
  449. func (s *Sale) TableInfo() *TableInfo {
  450. return saleTableInfo
  451. }