cpTrade.go 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Package models 40.6.3仓单优化_产能预售
  2. package models
  3. import (
  4. "mtp2_if/db"
  5. "time"
  6. )
  7. // Cptradepresalegoodsex 产能预售商品扩展表
  8. type Cptradepresalegoodsex struct {
  9. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID
  10. Applyid int64 `json:"applyid" xorm:"'APPLYID'"` // 关联申请ID
  11. Userid int64 `json:"userid" xorm:"'USERID'"` // 卖方用户ID
  12. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 卖方账户ID
  13. Relatedgoodsid int64 `json:"relatedgoodsid" xorm:"'RELATEDGOODSID'"` // 关联交易合约ID
  14. Presaleqty int64 `json:"presaleqty" xorm:"'PRESALEQTY'"` // 预售数量
  15. Starttime time.Time `json:"starttime" xorm:"'STARTTIME'"` // 预售开始时间
  16. Endtime time.Time `json:"endtime" xorm:"'ENDTIME'"` // 预售结束时间
  17. Attachmenturl string `json:"attachmenturl" xorm:"'ATTACHMENTURL'"` // 附件地址
  18. Presalemode int32 `json:"presalemode" xorm:"'PRESALEMODE'"` // 预售模式 - 1:一口价 2:大宗式竞拍
  19. Marketid int32 `json:"marketid" xorm:"'MARKETID'"` // 预售市场ID - 根据预售模式选择市场
  20. Refprice float64 `json:"refprice" xorm:"'REFPRICE'"` // 参考价格[一口价]
  21. Startprice float64 `json:"startprice" xorm:"'STARTPRICE'"` // 起拍价[大宗式竞拍]
  22. Floorprice float64 `json:"floorprice" xorm:"'FLOORPRICE'"` // 底价[大宗式竞拍]
  23. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  24. Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  25. Relatedmarketid int64 `json:"relatedmarketid" xorm:"'RELATEDMARKETID'"` // 关联交易合约市场ID
  26. Presaledqty int64 `json:"presaledqty" xorm:"'PRESALEDQTY'"` // 已预售量(预售结束时更新) 71-委托时更新
  27. Presaledamount float64 `json:"presaledamount" xorm:"'PRESALEDAMOUNT'"` // 已预售总金额(预售结束时更新)71-委托时更新
  28. Sellstatus int32 `json:"sellstatus" xorm:"'SELLSTATUS'"` // 卖方处理状态 - 1:卖方头寸未处理 2:卖方头寸已处理
  29. Goodsdetail string `json:"goodsdetail" xorm:"'GOODSDETAIL'"` // 详情[大宗]
  30. Tradeprice float64 `json:"tradeprice" xorm:"'TRADEPRICE'"` // 成交价[大宗]
  31. Buymaxqty int64 `json:"buymaxqty" xorm:"'BUYMAXQTY'"` // 购买上限 [71] - 0为不限
  32. }
  33. // TableName is CPTRADE_PRESALEGOODSEX
  34. func (Cptradepresalegoodsex) TableName() string {
  35. return "CPTRADE_PRESALEGOODSEX"
  36. }
  37. // Cptradebuylimitedconfig 产能预售商品购买限制表
  38. type Cptradebuylimitedconfig struct {
  39. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID
  40. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账户ID
  41. Buymaxqty int64 `json:"buymaxqty" xorm:"'BUYMAXQTY'"` // 限制上限
  42. Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
  43. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  44. }
  45. // TableName is CPTRADE_BUYLIMITEDCONFIG
  46. func (Cptradebuylimitedconfig) TableName() string {
  47. return "CPTRADE_BUYLIMITEDCONFIG"
  48. }
  49. // GetCPTradeBuyLimit 获取目标预售商品购买限制
  50. func GetCPTradeBuyLimit(goodsID, accountID int) (int, error) {
  51. engine := db.GetEngine()
  52. // 先尝试从“产能预售商品购买限制表”中获取定制化信息
  53. var cptradebuylimitedconfig Cptradebuylimitedconfig
  54. has, err := engine.Where("GOODSID = ?", goodsID).And("ACCOUNTID = ?", accountID).Get(&cptradebuylimitedconfig)
  55. if err != nil {
  56. return 0, err
  57. }
  58. if has {
  59. return int(cptradebuylimitedconfig.Buymaxqty), nil
  60. }
  61. // 没有定制化信息则从“产能预售商品扩展表”获取
  62. var cptradepresalegoodsex Cptradepresalegoodsex
  63. if has, err = engine.Where("GOODSID = ?", goodsID).Get(&cptradepresalegoodsex); err != nil {
  64. return 0, err
  65. }
  66. if has {
  67. return int(cptradepresalegoodsex.Buymaxqty), nil
  68. }
  69. return 0, nil
  70. }