Yu-Gi-Oh! Deck Building and Card Inventory Management web interface written in Common Lisp, utilizing HTMX.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

236 Zeilen
7.3KB

  1. #|
  2. src/models/crystal-commerce.lisp
  3. Crystal Commerce-style Inventory Management Backend
  4. TODO All of the old style database accessores (*-BY-ID, etc) need to go.
  5. DONE It looks like the CSV listing is totally outdated after all:
  6. CL-DECK-BUILDER2> (count-dao 'cc-item)
  7. 48883 (16 bits, #xBEF3)
  8. CL-DECK-BUILDER2> (count-dao 'cl-deck-builder2.models.ygoprodeck.classes::ygo-set)
  9. 49240 (16 bits, #xC058)
  10. That's awfully close enough for me, taking into account the art cards,
  11. the duelist name tag, and prize cards! I wonder if there'd be a way to
  12. see the diff. Some cards are name "Dark Magician A" which is
  13. unfortunate!
  14. TODO Because of the previous item being DONE, this code is now
  15. outdated and stale, and probably safe to delete, unless we intend on
  16. doing more with Crystal Commerce in the future.
  17. |#
  18. (in-package #:cl-user)
  19. (defpackage #:cl-deck-builder2.models.crystal-commerce
  20. (:use #:cl
  21. #:cl-deck-builder2.db
  22. #:cl-deck-builder2.models.generics
  23. #:cl-deck-builder2.toolkit.money
  24. #:cl-deck-builder2.models.registered-table
  25. #:cl-deck-builder2.models.ygoprodeck)
  26. (:import-from #:cl-deck-builder2.models.ygoprodeck.fields
  27. #:variant-condition)
  28. (:export
  29. :cc-item
  30. :ygo-cc-item
  31. :name-of
  32. :cc-category-of
  33. :cc-wishlists-of
  34. :cc-buy-price-of
  35. :cc-sell-price-of
  36. :cc-url-of
  37. :cc-barcode-of
  38. :cc-manufacturer-sku-of
  39. :cc-asin-of
  40. :cc-msrp-of
  41. :cc-brand-of
  42. :cc-weight-of
  43. :cc-description-of
  44. :cc-qty-of
  45. :cc-max-qty-of
  46. :cc-total-qty-of
  47. :cc-domestic-only-of
  48. :cc-tax-exempt-of
  49. :cc-name-of
  50. :cc-code-of
  51. :cc-rarity-of
  52. :cc-edition-of
  53. :cc-passcode-of
  54. :cc-table-ensure-exists
  55. :cc-table-drop
  56. :cc-table-delete
  57. :cc-table-select
  58. :cc-table-select-count
  59. :cc-table-zero
  60. :cc-select-by-id
  61. :cc-select-by-passcode
  62. :cc-delete-by-id
  63. :cc-create
  64. :cc-variant-of))
  65. (in-package #:cl-deck-builder2.models.crystal-commerce)
  66. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  67. ;; Cards v2
  68. ;;
  69. (defclass cc-item ()
  70. ((name :accessor name-of
  71. :col-type :text)
  72. (category :accessor cc-category-of
  73. :col-type :text)
  74. (total-qty :accessor cc-total-qty-of
  75. :col-type :integer
  76. :initform 0)
  77. (wishlists :accessor cc-wishlists-of
  78. :col-type :integer
  79. :initform 0)
  80. (;; 10 cent buy price
  81. buy-price :accessor cc-buy-price-of
  82. :col-type :integer
  83. :initform 0.10
  84. :inflate #'currency-inflate
  85. :deflate #'currency-deflate)
  86. (;; 50 cent sell price
  87. sell-price :accessor cc-sell-price-of
  88. :col-type :integer
  89. :initform 0.50
  90. :inflate #'currency-inflate
  91. :deflate #'currency-deflate)
  92. (url :accessor cc-url-of
  93. :col-type (or :text :null))
  94. (barcode :accessor cc-barcode-of
  95. :col-type (or :text :null))
  96. (manufacturer-sku :accessor cc-manufacturer-sku-of
  97. :col-type (or :text :null))
  98. ;; Some cards don't have an ASIN: Prize Cards, for example.
  99. ;;
  100. ;; ASIN is a built in LISP function so this seems to be causing
  101. ;; issues with Djula. I renamed it to AMAZON-ASIN.
  102. (amazon-asin :accessor cc-asin-of
  103. :col-type (or :text :null))
  104. (msrp :accessor cc-msrp-of
  105. :col-type (or :integer :null)
  106. :inflate #'currency-inflate
  107. :deflate #'currency-deflate)
  108. (brand :accessor cc-brand-of
  109. :col-type (or :text :null))
  110. ;; Weight in pounds, lb, lbs.. silly
  111. (weight :accessor cc-weight-of
  112. :col-type :text
  113. :initform "0.0625")
  114. (description :accessor cc-description-of
  115. :col-type (or :text :null))
  116. (max-qty :accessor cc-max-qty-of
  117. :col-type (or :integer :null))
  118. (domestic-only :accessor cc-domestic-only-of
  119. :col-type :integer
  120. :initform 0)
  121. (tax-exempt :accessor cc-tax-exempt-of
  122. :col-type :integer
  123. :initform 0))
  124. (:metaclass registered-table-class)
  125. (:documentation "The base data from CrystalCommerce. This is what's available in a CSV export.
  126. These fields can be updated from CC CSV Export Search feature.
  127. The product descriptors. Contains information about the actual content
  128. of the card. None of this is available via CC CSV Export Feature. This
  129. information has to be updated aftewards. The Mass Updater may have
  130. some hints as to how this works.
  131. Other stuff that doesn't appear in any export or search feature, but on YGOProDeck, which we will probably take info from."))
  132. ;; Allow bogus keys so we can just apply #'make-instance 'cc-item _parsed in web view
  133. ; (defmethod initialize-instance :after ((cc-item cc-item) &key &allow-other-keys))
  134. (defclass ygo-cc-item ()
  135. ((item :accessor cc-item-of
  136. :col-type cc-item)
  137. (variant :accessor cc-variant-of
  138. :col-type variant-condition)
  139. (qty :accessor cc-qty-of
  140. :col-type :integer
  141. :initform 0)
  142. (opt-qty :accessor cc-opt-qty-of
  143. :col-type :integer
  144. :initform 0)
  145. (;; 10 cent buy price
  146. buy-price :accessor cc-buy-price-of
  147. :col-type :integer
  148. :initform 0.10
  149. :inflate #'currency-inflate
  150. :deflate #'currency-deflate)
  151. (;; 50 cent sell price
  152. sell-price :accessor cc-sell-price-of
  153. :col-type :integer
  154. :initform 0.50
  155. :inflate #'currency-inflate
  156. :deflate #'currency-deflate))
  157. (:metaclass registered-table-class)
  158. (:documentation "CC-ITEM + VARIANT relationship table."))
  159. (defmacro cc-table-delete (&body clauses)
  160. `(delete-from 'cc-item ,@clauses))
  161. (defmacro cc-table-select (&body body)
  162. `(select-dao 'cc-item ,@body))
  163. (defun cc-table-select-count (&optional fields-and-values)
  164. (count-dao 'cc-item fields-and-values))
  165. ;; TODO toolkit/db.lisp maybe?
  166. (defun zero-field (class field &optional clauses)
  167. "Set the specified FIELD of CLASS zero. You may additionally specify CLAUSES."
  168. (with-connection (db)
  169. (with-transaction
  170. (mito:execute-sql
  171. (sxql:update (sxql:make-sql-symbol
  172. (mito.dao::table-name (find-class class)))
  173. (sxql:set= (sxql:make-sql-symbol field) 0)
  174. clauses)))))
  175. (defun set-buy-sell-price (&optional (buy-price 10) (sell-price 50))
  176. "This bypasses MITO:DEFLATE (the argument is in CENTS)."
  177. (with-connection (db)
  178. (with-transaction
  179. (mito:execute-sql
  180. (sxql:update :cc_item
  181. (sxql:set= (sxql:make-sql-symbol "buy_price") buy-price
  182. (sxql:make-sql-symbol "sell_price") sell-price))
  183. (sxql:update :ygo_cc_item
  184. (sxql:set= (sxql:make-sql-symbol "buy_price") buy-price
  185. (sxql:make-sql-symbol "sell_price") sell-price))))))
  186. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  187. (defun cc-select-by-id (id &rest args)
  188. (apply #'find-dao 'cc-item :id id args))
  189. (defun cc-select-by-passcode (passcode &rest args)
  190. (apply #'find-dao 'cc-item :passcode passcode args))
  191. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  192. ;; INSERT
  193. (defun cc-create (&rest args)
  194. (apply #'create-dao 'cc-item args))
  195. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  196. ;; DELETE
  197. (defun cc-delete-by-id (id &rest args)
  198. (apply #'delete-by-values 'cc-item :id id args))