hsby.go 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756
  1. package models
  2. import (
  3. "encoding/hex"
  4. "fmt"
  5. "math"
  6. "mtp2_if/db"
  7. "mtp2_if/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. // Hsbygoodsex 商品扩展表
  13. type Hsbygoodsex struct {
  14. Goodsid int32 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商 品ID
  15. Hotindex int32 `json:"hotindex" xorm:"'HOTINDEX'"` // 景点热度
  16. Descprovinceid int64 `json:"descprovinceid" xorm:"'DESCPROVINCEID'"` // 目的地(省)
  17. Desccityid int64 `json:"desccityid" xorm:"'DESCCITYID'"` // 目的地(市)
  18. Vendorid int32 `json:"vendorid" xorm:"'VENDORID'"` // 供应商ID
  19. Goodsdesc string `json:"goodsdesc" xorm:"'GOODSDESC'"` // 商品详情
  20. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  21. Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
  22. Modifierid int64 `json:"modifierid" xorm:"'MODIFIERID'"` // 修改人
  23. Modifytime time.Time `json:"modifytime" xorm:"'MODIFYTIME'"` // 修改时间
  24. Memberratio float64 `json:"memberratio" xorm:"'MEMBERRATIO'"` // 会员货款比例 [71]
  25. Videourls string `json:"videourls" xorm:"'VIDEOURLS'"` // 介绍视频[多张用逗号分隔]
  26. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  27. Goodsprice float64 `json:"goodsprice" xorm:"'GOODSPRICE'"` // 商品价格
  28. Categoryid int32 `json:"categoryid" xorm:"'CATEGORYID'"` // 类别ID(WRCATEGORY)
  29. }
  30. // TableName is HSBY_GOODSEX
  31. func (Hsbygoodsex) TableName() string {
  32. return "HSBY_GOODSEX"
  33. }
  34. // Hsbysupplierinfo 供应商表
  35. type Hsbysupplierinfo struct {
  36. Vendorid int32 `json:"vendorid" xorm:"'VENDORID'" binding:"required"` // 供应商ID(SEQ_HSBY_SUPPLIERINFO)
  37. Vendorname string `json:"vendorname" xorm:"'VENDORNAME'"` // 名称描述客服电话名称
  38. Vendordesc string `json:"vendordesc" xorm:"'VENDORDESC'"` // 描述
  39. Vendorphone string `json:"vendorphone" xorm:"'VENDORPHONE'"` // 客服电话
  40. Vendorattr string `json:"vendorattr" xorm:"'VENDORATTR'"` // 附件(多张,逗号分隔)
  41. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  42. Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
  43. Modifierid int64 `json:"modifierid" xorm:"'MODIFIERID'"` // 修改人
  44. Modifytime time.Time `json:"modifytime" xorm:"'MODIFYTIME'"` // 修改时间
  45. }
  46. // TableName is HSBY_SUPPLIERINFO
  47. func (Hsbysupplierinfo) TableName() string {
  48. return "HSBY_SUPPLIERINFO"
  49. }
  50. // Tradepayorder 交易待付款表
  51. type Tradepayorder struct {
  52. Tradeid int64 `json:"tradeid" xorm:"'TRADEID'" binding:"required"` // 成交单号(101+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
  53. Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  54. Marketid int32 `json:"marketid" xorm:"'MARKETID'"` // 市场ID
  55. Goodsid int32 `json:"goodsid" xorm:"'GOODSID'"` // 商品ID
  56. Buyorderid int64 `json:"buyorderid" xorm:"'BUYORDERID'"` // 买方委托单号
  57. Buyaccountid int64 `json:"buyaccountid" xorm:"'BUYACCOUNTID'"` // 买方账号ID[报价币种]
  58. Sellorderid int64 `json:"sellorderid" xorm:"'SELLORDERID'"` // 卖方委托单号
  59. Sellaccountid int64 `json:"sellaccountid" xorm:"'SELLACCOUNTID'"` // 卖方账号ID[报价币种]
  60. Tradeamount float64 `json:"tradeamount" xorm:"'TRADEAMOUNT'"` // 成交金额
  61. Tradecharge float64 `json:"tradecharge" xorm:"'TRADECHARGE'"` // 成交手续费(买方)
  62. Payflag int32 `json:"payflag" xorm:"'PAYFLAG'"` // 付款标识 - 1:未支付 2:已支付 3:已过期 4:已撤销 5:结算过期 6:预售终止
  63. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  64. Paytime time.Time `json:"paytime" xorm:"'PAYTIME'"` // 付款时间
  65. Paylimitedtime time.Time `json:"paylimitedtime" xorm:"'PAYLIMITEDTIME'"` // 支付期限
  66. Offamount float64 `json:"offamount" xorm:"'OFFAMOUNT'"` // 优惠金额
  67. Tradeprice float64 `json:"tradeprice" xorm:"'TRADEPRICE'"` // 成交价格
  68. Tradeqty int64 `json:"tradeqty" xorm:"'TRADEQTY'"` // 成交数量
  69. Payamount float64 `json:"payamount" xorm:"'PAYAMOUNT'"` // 支付金额 = TradeAmount + TradeCharge - OffAmount
  70. }
  71. // TableName is TRADE_PAYORDER
  72. func (Tradepayorder) TableName() string {
  73. return "TRADE_PAYORDER"
  74. }
  75. // Coupontype 优惠券类型表
  76. type Coupontype struct {
  77. Coupontypeid int32 `json:"coupontypeid" xorm:"'COUPONTYPEID'" binding:"required"` // 优惠券类型ID - SEQ_COUPONTYPE
  78. Areauserid int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  79. Couponname string `json:"couponname" xorm:"'COUPONNAME'"` // 优惠券名称
  80. Couponcategroy int32 `json:"couponcategroy" xorm:"'COUPONCATEGROY'"` // 种类 - 1:现金券 2:折扣券 3:折扣券(单张)
  81. Conditionvalue float64 `json:"conditionvalue" xorm:"'CONDITIONVALUE'"` // 条件阈值(可为0)
  82. Couponvalue float64 `json:"couponvalue" xorm:"'COUPONVALUE'"` // 面值[1:现金券 - 抵扣值 2:折扣券-折扣值]
  83. Limitedflag int32 `json:"limitedflag" xorm:"'LIMITEDFLAG'"` // 是否指定商品 - 0:不限 1:限制
  84. Limitedgoodsids string `json:"limitedgoodsids" xorm:"'LIMITEDGOODSIDS'"` // 指定商品IDs[逗号分隔,前后加逗号]
  85. Isgeneral int32 `json:"isgeneral" xorm:"'ISGENERAL'"` // 是否通用券 - 0:否 1:是
  86. Userscope string `json:"userscope" xorm:"'USERSCOPE'"` // 卖家范围(用户ID,逗号分隔,前后加逗号) [IsGeneral =0时使用]
  87. Qty int64 `json:"qty" xorm:"'QTY'"` // 数量
  88. Curqty int64 `json:"curqty" xorm:"'CURQTY'"` // 剩余数量
  89. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  90. Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
  91. Modifierid int64 `json:"modifierid" xorm:"'MODIFIERID'"` // 修改人
  92. Modifytime time.Time `json:"modifytime" xorm:"'MODIFYTIME'"` // 修改时间
  93. Usedqty int64 `json:"usedqty" xorm:"'USEDQTY'"` // 使用量
  94. Isvalid int32 `json:"isvalid" xorm:"'ISVALID'"` // 是否有效 - 0:无效 1:有效
  95. Expiredqty int64 `json:"expiredqty" xorm:"'EXPIREDQTY'"` // 失效量
  96. }
  97. // TableName is COUPONTYPE
  98. func (Coupontype) TableName() string {
  99. return "COUPONTYPE"
  100. }
  101. // Couponposition 优惠券头寸表 - 导历史(期末为0的清除)
  102. type Couponposition struct {
  103. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 资金账户ID
  104. Coupontypeid int32 `json:"coupontypeid" xorm:"'COUPONTYPEID'" binding:"required"` // 优惠券类型ID
  105. Userid int64 `json:"userid" xorm:"'USERID'"` // 用户ID
  106. Oriqty int64 `json:"oriqty" xorm:"'ORIQTY'"` // 期初数量
  107. Orifreezeqty int64 `json:"orifreezeqty" xorm:"'ORIFREEZEQTY'"` // 期初冻结数量
  108. Curqty int64 `json:"curqty" xorm:"'CURQTY'"` // 期末数量
  109. Curfreezeqty int64 `json:"curfreezeqty" xorm:"'CURFREEZEQTY'"` // 期末冻结数量
  110. Todayincrease int64 `json:"todayincrease" xorm:"'TODAYINCREASE'"` // 今日增加
  111. Todaydecrease int64 `json:"todaydecrease" xorm:"'TODAYDECREASE'"` // 今日减少
  112. }
  113. // TableName is COUPONPOSITION
  114. func (Couponposition) TableName() string {
  115. return "COUPONPOSITION"
  116. }
  117. // Couponhold 优惠券持仓表 - 导历史(不清当前表) - 每一个数量一条记录
  118. type Couponhold struct {
  119. Couponholdid int64 `json:"couponholdid" xorm:"'COUPONHOLDID'" binding:"required"` // 优惠券持仓ID(229+Unix秒时间戳(10位)+xxxxxx)
  120. Giveapplyid int64 `json:"giveapplyid" xorm:"'GIVEAPPLYID'"` // 发放申请ID(SEQ_COUPONGIVEAPPLY)
  121. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 资金账户ID
  122. Coupontypeid int32 `json:"coupontypeid" xorm:"'COUPONTYPEID'"` // 优惠券类型ID - SEQ_COUPONTYPE
  123. Couponcategroy int32 `json:"couponcategroy" xorm:"'COUPONCATEGROY'"` // 种类 - 1:现金券 2:折扣券 3:折扣券(单个商品)
  124. Conditionvalue float64 `json:"conditionvalue" xorm:"'CONDITIONVALUE'"` // 条件阈值(可为0)
  125. Couponvalue float64 `json:"couponvalue" xorm:"'COUPONVALUE'"` // 面值[1:现金券 - 抵扣值 2:折扣券-折扣值]
  126. Limitedflag int32 `json:"limitedflag" xorm:"'LIMITEDFLAG'"` // 是否指定商品 - 0:不限 1:限制
  127. Limitedgoodsids string `json:"limitedgoodsids" xorm:"'LIMITEDGOODSIDS'"` // 指定商品IDs[逗号分隔]
  128. Isgeneral int32 `json:"isgeneral" xorm:"'ISGENERAL'"` // 是否通用券 - 0:否 1:是
  129. Userscope string `json:"userscope" xorm:"'USERSCOPE'"` // 卖家范围(用户ID,逗号分隔) [IsGeneral =0时使用]
  130. Userid int64 `json:"userid" xorm:"'USERID'"` // 用户ID
  131. Qty int64 `json:"qty" xorm:"'QTY'"` // 数量(按1平铺)
  132. Startdate time.Time `json:"startdate" xorm:"'STARTDATE'"` // 开始日期
  133. Holdstatus int32 `json:"holdstatus" xorm:"'HOLDSTATUS'"` // 持仓状态 - 1:未生效 2:已生效 3:已使用 4:已过期
  134. Enddate time.Time `json:"enddate" xorm:"'ENDDATE'"` // 结束日期
  135. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  136. }
  137. // TableName is COUPONHOLD
  138. func (Couponhold) TableName() string {
  139. return "COUPONHOLD"
  140. }
  141. // HsbyTopGoods 热卖商品(二级市场挂牌点选)
  142. type HsbyTopGoods struct {
  143. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID(自增ID SEQ_GOODS)
  144. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  145. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  146. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  147. Marketid int64 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 所属市场ID
  148. Quoteminunit int64 `json:"quoteminunit" xorm:"'QUOTEMINUNIT'"` // 行情最小变动单位 [整数,报价小数位一起使用]
  149. Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
  150. Hotindex int32 `json:"hotindex" xorm:"'HOTINDEX'"` // 景点热度
  151. Videourls string `json:"videourls" xorm:"'VIDEOURLS'"` // 介绍视频[多张用逗号分隔]
  152. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  153. Currency string `json:"currency" xorm:"'CURRENCY'"` // 货币
  154. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  155. Trademode int32 `json:"trademode" xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
  156. Last float64 `json:"last" xorm:"-"` // 现价
  157. }
  158. // GetHsbyTopGoodses 获取热门商品列表
  159. // 参数 marketIDs string 所属市场ID列表, 格式 1,2,3
  160. // 参数 descProvinceID int 目标省ID
  161. // 参数 descCityID int 目标城市ID
  162. // 返回 []TopGoods 热门商品列表
  163. // 返回 error error
  164. func GetHsbyTopGoodses(marketIDs string, descProvinceID, descCityID int) ([]HsbyTopGoods, error) {
  165. // 热门商品为二级市场(挂牌点选)下的商品信息
  166. engine := db.GetEngine()
  167. topGoodses := make([]HsbyTopGoods, 0)
  168. // 获取挂牌商品信息,以及扩展表信息
  169. // 与商城不一样的是,挂牌点选以商品表作为主表,同一商品可有多个委托单
  170. session := engine.Table("GOODS").
  171. Select(`GOODS.*,
  172. HSBY_GOODSEX.HOTINDEX, HSBY_GOODSEX.VIDEOURLS, HSBY_GOODSEX.PICURLS,
  173. ENUMDICITEM.ENUMDICNAME CURRENCY, ENUMDICITEM.PARAM2 CURRENCYSIGN,
  174. MARKET.TRADEMODE`).
  175. Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
  176. Join("LEFT", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMNAME = GOODS.CURRENCYID and ENUMDICITEM.ENUMDICCODE = 'currency'").
  177. Join("LEFT", "MARKET", "MARKET.MARKETID = GOODS.MARKETID").
  178. Where(fmt.Sprintf("GOODS.GOODSSTATUS = 3 and GOODS.MARKETID in (%s)", marketIDs)) // 二级市场只获取 3:上市 状态的商品
  179. if descProvinceID > 0 {
  180. session = session.And("HSBY_GOODSEX.DESCPROVINCEID = ?", descProvinceID)
  181. }
  182. if descCityID > 0 {
  183. session = session.And("HSBY_GOODSEX.DESCCITYID = ?", descCityID)
  184. }
  185. if err := session.Find(&topGoodses); err != nil {
  186. return nil, err
  187. }
  188. if len(topGoodses) == 0 {
  189. // 无数据
  190. return topGoodses, nil
  191. }
  192. // 获取商品ID列表
  193. goodsCodes := ""
  194. for _, v := range topGoodses {
  195. if len(goodsCodes) == 0 {
  196. goodsCodes = v.Goodscode
  197. } else {
  198. goodsCodes += "," + v.Goodscode
  199. }
  200. }
  201. // 获取商品现价
  202. quoteDays, err := GetQuoteDays(goodsCodes)
  203. if err != nil {
  204. return nil, err
  205. }
  206. for i, g := range topGoodses {
  207. topGoods := &topGoodses[i]
  208. // FIXME: - 这里应该使用 Duck Typing,后期再处理
  209. // 计算最小变动单位
  210. // lotSize := float64(topGoods.Quoteminunit) * math.Pow(0.1, float64(topGoods.Decimalplace))
  211. // topGoods.LotSize, _ = strconv.ParseFloat(utils.FormatFloat(lotSize, int(topGoods.Decimalplace)), 64)
  212. for _, q := range quoteDays {
  213. if g.Goodscode == q.Goodscode {
  214. if q.Last != 0 {
  215. topGoods.Last = utils.IntToFloat64(int(q.Last), int(g.Decimalplace))
  216. }
  217. // 没有现价则尝试用昨结
  218. if topGoods.Last == 0 && q.Presettle != 0 {
  219. topGoods.Last = utils.IntToFloat64(int(q.Presettle), int(g.Decimalplace))
  220. }
  221. continue
  222. }
  223. }
  224. }
  225. return topGoodses, nil
  226. }
  227. // HsbyListingGoodsDetail 二级市场(挂牌点选)商品信息详情
  228. type HsbyListingGoodsDetail struct {
  229. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID(自增ID SEQ_GOODS)
  230. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  231. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  232. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  233. Marketid int64 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 所属市场ID
  234. Quoteminunit int64 `json:"quoteminunit" xorm:"'QUOTEMINUNIT'"` // 行情最小变动单位 [整数,报价小数位一起使用]
  235. Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
  236. Hotindex int32 `json:"hotindex" xorm:"'HOTINDEX'"` // 景点热度
  237. Videourls string `json:"videourls" xorm:"'VIDEOURLS'"` // 介绍视频[多张用逗号分隔]
  238. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  239. Descprovinceid int64 `json:"descprovinceid" xorm:"'DESCPROVINCEID'"` // 目的地(省)ID
  240. Desccityid int64 `json:"desccityid" xorm:"'DESCCITYID'"` // 目的地(市)ID
  241. Goodsdesc string `json:"goodsdesc" xorm:"'GOODSDESC'"` // 商品详情
  242. Goodsprice float64 `json:"goodsprice" xorm:"'GOODSPRICE'"` // 商品价格
  243. Currency string `json:"currency" xorm:"'CURRENCY'"` // 货币
  244. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  245. Vendorname string `json:"vendorname" xorm:"'VENDORNAME'"` // 供应商名称
  246. Vendorphone string `json:"vendorphone" xorm:"'VENDORPHONE'"` // 供应商客服电话
  247. Vendorattr string `json:"vendorattr" xorm:"'VENDORATTR'"` // 供应商附件(多张,逗号分隔)
  248. Trademode int32 `json:"trademode" xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
  249. Last float64 `json:"last" xorm:"-"` // 现价
  250. Limitup float64 `json:"limitup" xorm:"-"` // 涨停价
  251. Limitdown float64 `json:"limitdown" xorm:"-"` // 跌停价
  252. StepValue float64 `json:"stepvalue" xorm:"-"` // 价格最小变动单位
  253. LotSize int `json:"lotsize" xorm:"-"` // 手数最小变动单位
  254. }
  255. // GetHsbyListingGoodsDetail 获取二级市场(挂牌点选)商品信息详情
  256. // 参数 goodsID int 目标商品ID
  257. // 返回 *HsbyListingGoodsDetail 二级市场(挂牌点选)商品信息详情,查询无结果返回nil
  258. // 返回 error error
  259. func GetHsbyListingGoodsDetail(goodsID int) (*HsbyListingGoodsDetail, error) {
  260. engine := db.GetEngine()
  261. details := make([]HsbyListingGoodsDetail, 0)
  262. // 获取挂牌商品信息,以及扩展表信息
  263. // FIXME: - 这里使用Get方法,会造成SQL语句的嵌套出错,后期再研究
  264. session := engine.Table("GOODS").
  265. Select(`GOODS.GOODSID, GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.MARKETID, GOODS.QUOTEMINUNIT, GOODS.AGREEUNIT,
  266. HSBY_GOODSEX.HOTINDEX, HSBY_GOODSEX.VIDEOURLS, HSBY_GOODSEX.PICURLS, HSBY_GOODSEX.DESCPROVINCEID, HSBY_GOODSEX.Desccityid, HSBY_GOODSEX.Goodsdesc, HSBY_GOODSEX.GOODSPRICE,
  267. ENUMDICITEM.ENUMDICNAME CURRENCY, ENUMDICITEM.PARAM2 CURRENCYSIGN,
  268. HSBY_SUPPLIERINFO.VENDORNAME, HSBY_SUPPLIERINFO.VENDORPHONE, HSBY_SUPPLIERINFO.VENDORATTR,
  269. MARKET.TRADEMODE`).
  270. Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
  271. Join("LEFT", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMNAME = GOODS.CURRENCYID and ENUMDICITEM.ENUMDICCODE = 'currency'").
  272. Join("LEFT", "HSBY_SUPPLIERINFO", "HSBY_SUPPLIERINFO.VENDORID = HSBY_GOODSEX.VENDORID").
  273. Join("LEFT", "MARKET", "MARKET.MARKETID = GOODS.MARKETID").
  274. Where("GOODS.GOODSID = ?", goodsID)
  275. if err := session.Find(&details); err != nil {
  276. return nil, err
  277. }
  278. // 无目标商品
  279. if len(details) == 0 {
  280. return nil, nil
  281. }
  282. hsbyListingGoodsDetail := details[0]
  283. // 获取商品现价和涨跌停价
  284. quoteDays, err := GetQuoteDays(hsbyListingGoodsDetail.Goodscode)
  285. if err != nil {
  286. return nil, err
  287. }
  288. if len(quoteDays) > 0 {
  289. if quoteDays[0].Last != 0 {
  290. hsbyListingGoodsDetail.Last = utils.IntToFloat64(int(quoteDays[0].Last), int(hsbyListingGoodsDetail.Decimalplace))
  291. }
  292. // 没有现价则尝试用昨结
  293. if hsbyListingGoodsDetail.Last == 0 && quoteDays[0].Presettle != 0 {
  294. hsbyListingGoodsDetail.Last = utils.IntToFloat64(int(quoteDays[0].Presettle), int(hsbyListingGoodsDetail.Decimalplace))
  295. }
  296. if quoteDays[0].Limitup != 0 {
  297. hsbyListingGoodsDetail.Limitup = utils.IntToFloat64(int(quoteDays[0].Limitup), int(hsbyListingGoodsDetail.Decimalplace))
  298. }
  299. if quoteDays[0].Limitdown != 0 {
  300. hsbyListingGoodsDetail.Limitdown = utils.IntToFloat64(int(quoteDays[0].Limitdown), int(hsbyListingGoodsDetail.Decimalplace))
  301. }
  302. }
  303. // 计算价格最小变动单位
  304. stepValue := float64(hsbyListingGoodsDetail.Quoteminunit) * math.Pow(0.1, float64(hsbyListingGoodsDetail.Decimalplace))
  305. hsbyListingGoodsDetail.StepValue, _ = strconv.ParseFloat(utils.FormatFloat(stepValue, int(hsbyListingGoodsDetail.Decimalplace)), 64)
  306. // 计算手数最小变动单位
  307. hsbyListingGoodsDetail.LotSize = 1
  308. return &hsbyListingGoodsDetail, nil
  309. }
  310. // HsbyGoodsOrderDetail 二级市场挂牌商品当前可摘委托单信息
  311. type HsbyGoodsOrderDetail struct {
  312. Orderid string `json:"orderid" xorm:"'ORDERID'" binding:"required"` // 委托单号(100+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
  313. Buyorsell int32 `json:"buyorsell" xorm:"'BUYORSELL'" binding:"required"` // 买卖 - 0:买 1:卖
  314. Ordertime time.Time `json:"ordertime" xorm:"'ORDERTIME'" binding:"required"` // 委托时间
  315. Orderprice float64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格
  316. Enableqty int64 `json:"enableqty" xorm:"ENABLEQTY"` // 可用数量
  317. Customername string `json:"customername" xorm:"'CUSTOMERNAME'"` // 客户名称(企业名称),已脱敏
  318. Currencysign string `json:"currencysign" xorm:"-"` // 货币符号
  319. Goodunit string `json:"goodunit" xorm:"-"` // 报价单位
  320. }
  321. // GetHsbyGoodsOrderDetails 获取二级市场(挂牌点选)商品对应的挂牌委托单信息
  322. // 输入 goodsID int 商品ID
  323. // 输入 buyOrSell int 挂牌委托单方向(对手单方向),0:买 1:卖
  324. // 输入 price float64 参考价格。买方向委托单则价格小于等于(站在摘牌人的角度);卖方向委托单则价格大于等于
  325. // 输出 []HsbyGoodsOrderDetail 商品对应的挂牌委托单信息
  326. // 输出 error error
  327. func GetHsbyGoodsOrderDetails(goodsID, buyOrSell int, price float64, accountIDs string) ([]HsbyGoodsOrderDetail, error) {
  328. engine := db.GetEngine()
  329. // 获取与目标商品相关的挂牌委托单信息(ListingSelectType = 1 or 3; OrderStatus =3 or 7)
  330. hsbyGoodsOrderDetails := make([]HsbyGoodsOrderDetail, 0)
  331. session := engine.Table("TRADE_ORDERDETAIL").
  332. Select(`to_char(TRADE_ORDERDETAIL.ORDERID) ORDERID, TRADE_ORDERDETAIL.BUYORSELL, TRADE_ORDERDETAIL.ORDERTIME, TRADE_ORDERDETAIL.ORDERPRICE, (TRADE_ORDERDETAIL.ORDERQTY - TRADE_ORDERDETAIL.TRADEQTY - TRADE_ORDERDETAIL.CANCELQTY) ENABLEQTY,
  333. substr(USERINFO.CUSTOMERNAME,0,1)||'****' as CUSTOMERNAME`).
  334. Join("LEFT", "TAACCOUNT", "TAACCOUNT.ACCOUNTID = TRADE_ORDERDETAIL.ACCOUNTID").
  335. Join("LEFT", "USERINFO", "USERINFO.USERID = TAACCOUNT.RELATEDUSERID").
  336. Where("(TRADE_ORDERDETAIL.LISTINGSELECTTYPE = 1 or TRADE_ORDERDETAIL.LISTINGSELECTTYPE = 3) and (TRADE_ORDERDETAIL.ORDERSTATUS = 3 or TRADE_ORDERDETAIL.ORDERSTATUS = 7)").
  337. And("TRADE_ORDERDETAIL.GOODSID = ?", goodsID).
  338. And("TRADE_ORDERDETAIL.BUYORSELL = ?", buyOrSell)
  339. if len(accountIDs) > 0 {
  340. session = session.And(fmt.Sprintf("TRADE_ORDERDETAIL.ACCOUNTID not in (%s)", accountIDs))
  341. }
  342. if price > 0 {
  343. if buyOrSell == 0 {
  344. // 对手单买方向委托单则价格大于等于(站在摘牌人的角度,摘牌方面是卖,我的闲置下单)
  345. session = session.And("TRADE_ORDERDETAIL.ORDERPRICE >= ?", price)
  346. } else {
  347. // 对手单卖方向委托单则价格小于等于(站在摘牌人的角度,摘牌方面是买,热门商品下单)
  348. session = session.And("TRADE_ORDERDETAIL.ORDERPRICE <= ?", price)
  349. }
  350. }
  351. if err := session.Find(&hsbyGoodsOrderDetails); err != nil {
  352. return nil, err
  353. }
  354. // 获取商品货币符号和报价单位
  355. goods, err := GetGoods(goodsID)
  356. if err != nil {
  357. return nil, err
  358. }
  359. currencyEnums, err := GetEnumDicItem("currency", int(goods.Currencyid))
  360. if err != nil {
  361. return nil, err
  362. }
  363. currencysign := ""
  364. if len(currencyEnums) > 0 {
  365. currencysign = currencyEnums[0].Param2
  366. }
  367. goodsUnitEnums, err := GetEnumDicItem("goodsunit", int(goods.Goodunitid))
  368. if err != nil {
  369. return nil, err
  370. }
  371. goodsUnit := ""
  372. if len(goodsUnitEnums) > 0 {
  373. goodsUnit = goodsUnitEnums[0].Enumdicname
  374. }
  375. for i := range hsbyGoodsOrderDetails {
  376. orderDetail := &hsbyGoodsOrderDetails[i]
  377. // 设置货币符号和报价单位
  378. orderDetail.Currencysign = currencysign
  379. orderDetail.Goodunit = goodsUnit
  380. }
  381. return hsbyGoodsOrderDetails, nil
  382. }
  383. // HybsMyBuyOrderDetail 我的订单(一二级市场的买方向委托单)
  384. type HybsMyBuyOrderDetail struct {
  385. Orderid string `json:"orderid" xorm:"'ORDERID'" binding:"required"` // 委托单号(100+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
  386. Marketid int32 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 市场ID
  387. Goodsid int32 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID
  388. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账户ID[报价币种]
  389. Buyorsell int32 `json:"buyorsell" xorm:"'BUYORSELL'" binding:"required"` // 买卖 - 0:买 1:卖
  390. Orderprice float64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格
  391. Orderqty int64 `json:"orderqty" xorm:"'ORDERQTY'" binding:"required"` // 委托数量
  392. Tradeqty int64 `json:"tradeqty" xorm:"'TRADEQTY'"` // 成交数量
  393. Cancelqty int64 `json:"cancelqty" xorm:"'CANCELQTY'"` // 撤单数量
  394. Ordertime time.Time `json:"ordertime" xorm:"'ORDERTIME'" binding:"required"` // 委托时间
  395. Listingselecttype int32 `json:"listingselecttype" xorm:"'LISTINGSELECTTYPE'"` // 挂牌点选类型 - 1:挂牌 2:摘牌 3:先摘后挂
  396. Orderstatus int32 `json:"orderstatus" xorm:"'ORDERSTATUS'"` // 委托状态 - 1: 委托请求 2:待冻结 3:委托成功 4: 委托失败 5:配对成功 6: 已撤销 7:部分成交 8:已成交 9:部成部撤 10:成交失败 11:已拒绝 12:经过摘牌(先摘后挂专用-先摘后挂已摘过) 13:冻结成功(通道交易专用) 14:通道已撤 15:通道部成部撤 16:成交失败违约(荷兰式竞拍专用)
  397. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  398. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  399. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  400. Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
  401. Picurls1 string `json:"picurls1" xorm:"'PICURLS1'"` // 预售商品介绍图片[多张用逗号分隔]
  402. Picurls2 string `json:"picurls2" xorm:"'PICURLS2'"` // 挂牌商品介绍图片[多张用逗号分隔]
  403. Trademode uint32 `json:"trademode" xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
  404. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  405. Vendorname1 string `json:"vendorname1" xorm:"'VENDORNAME1'"` // 预售商品供应商名称
  406. Vendorname2 string `json:"vendorname2" xorm:"'VENDORNAME2'"` // 挂牌商品供应商名称
  407. MyBuyStatus int `json:"mybuystatus" xorm:"-"` // "我的订单"显示状态- 1:抢购中 2:求购中 3:已完成 4:已撤消 5:委托失败
  408. Orderamount float64 `json:"orderamount" xorm:"-"` // 委托金额
  409. }
  410. // GetHsbyBuyMyOrderDetails 获取“我的订单”数据(包括一二级市场)
  411. // 输入 accountIDs string 资金账户列表
  412. // 输入 myBuyStatus int "我的订单"状态, 1:抢购中 2:求购中 3:已完成
  413. // 输出 []HybsMyBuyOrderDetail “我的订单”数据
  414. // 输出 error error
  415. func GetHsbyBuyMyOrderDetails(accountIDs string, myBuyStatus int) ([]HybsMyBuyOrderDetail, error) {
  416. // 获取市场信息
  417. markets, err := GetMarkets()
  418. if err != nil {
  419. return nil, err
  420. }
  421. engine := db.GetEngine()
  422. // 委托状态
  423. orderStatus := "0" // 单据状态,为0的时候查询全部
  424. marketIDs := "" // 我的订单包括一二级市场的单据
  425. // FIXME: myBuyStatus 目前终端不传
  426. switch myBuyStatus {
  427. case 1: // 抢购中 (一级市场)
  428. // 获取市场ID
  429. for _, v := range markets {
  430. if v.Trademode == 71 { // 预售挂牌
  431. if len(marketIDs) == 0 {
  432. marketIDs = strconv.Itoa(int(v.Marketid))
  433. } else {
  434. marketIDs += "," + strconv.Itoa(int(v.Marketid))
  435. }
  436. }
  437. }
  438. orderStatus = "3,7"
  439. case 2: // 求购中(二级市场)
  440. // 获取市场ID
  441. for _, v := range markets {
  442. if v.Trademode == 16 { // 挂牌点选
  443. if len(marketIDs) == 0 {
  444. marketIDs = strconv.Itoa(int(v.Marketid))
  445. } else {
  446. marketIDs += "," + strconv.Itoa(int(v.Marketid))
  447. }
  448. }
  449. }
  450. orderStatus = "3,7"
  451. case 3: // 已完成
  452. orderStatus = "8,9"
  453. }
  454. // 默认取 TradeMode = 16 or 71 的市场
  455. if len(marketIDs) == 0 {
  456. for _, v := range markets {
  457. if v.Trademode == 16 || v.Trademode == 71 || v.Trademode == 70 {
  458. if len(marketIDs) == 0 {
  459. marketIDs = strconv.Itoa(int(v.Marketid))
  460. } else {
  461. marketIDs += "," + strconv.Itoa(int(v.Marketid))
  462. }
  463. }
  464. }
  465. }
  466. hybsMyBuyOrderDetails := make([]HybsMyBuyOrderDetail, 0)
  467. // "我的订单"都是买委托
  468. session := engine.Table("TRADE_ORDERDETAIL").
  469. Select(`to_char(TRADE_ORDERDETAIL.ORDERID) ORDERID, TRADE_ORDERDETAIL.*,
  470. GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.AGREEUNIT,
  471. HG1.PICURLS PICURLS1,
  472. HG2.PICURLS PICURLS2,
  473. MARKET.TRADEMODE,
  474. ENUMDICITEM.PARAM2 CURRENCYSIGN,
  475. HS1.VENDORNAME VENDORNAME1,
  476. HS2.VENDORNAME VENDORNAME2`).
  477. Join("LEFT", "GOODS", "GOODS.GOODSID = TRADE_ORDERDETAIL.GOODSID").
  478. Join("LEFT", "CPTRADE_PRESALEGOODSEX", "CPTRADE_PRESALEGOODSEX.GOODSID = TRADE_ORDERDETAIL.GOODSID").
  479. Join("LEFT", "HSBY_GOODSEX HG1", "HG1.GOODSID = CPTRADE_PRESALEGOODSEX.RELATEDGOODSID").
  480. Join("LEFT", "HSBY_GOODSEX HG2", "HG2.GOODSID = GOODS.GOODSID").
  481. Join("LEFT", "ENUMDICITEM", "GOODS.CURRENCYID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'currency'").
  482. Join("LEFT", "MARKET", "MARKET.MARKETID = TRADE_ORDERDETAIL.MARKETID").
  483. Join("LEFT", "HSBY_SUPPLIERINFO HS1", "HS1.VENDORID = HG1.VENDORID").
  484. Join("LEFT", "HSBY_SUPPLIERINFO HS2", "HS2.VENDORID = HG2.VENDORID").
  485. Where(fmt.Sprintf("TRADE_ORDERDETAIL.BUYORSELL = 0 and TRADE_ORDERDETAIL.ACCOUNTID in (%s)", accountIDs)).
  486. And(fmt.Sprintf("TRADE_ORDERDETAIL.MARKETID in (%s)", marketIDs))
  487. // 是否过滤状态(抢购中、求购中、已完成)
  488. if orderStatus != "0" {
  489. session = session.And(fmt.Sprintf("TRADE_ORDERDETAIL.ORDERSTATUS in (%s)", orderStatus))
  490. }
  491. if err := session.Find(&hybsMyBuyOrderDetails); err != nil {
  492. return nil, err
  493. }
  494. // 设置“我的订单”显示状态
  495. for i := range hybsMyBuyOrderDetails {
  496. detail := &hybsMyBuyOrderDetails[i]
  497. // 委托金额 = 委托价格 * 委托数量 * 合约单位
  498. detail.Orderamount = detail.Orderprice * float64(detail.Orderqty) * float64(detail.Agreeunit)
  499. if detail.Trademode == 71 && (detail.Orderstatus == 3 || detail.Orderstatus == 7) {
  500. // 抢购中
  501. detail.MyBuyStatus = 1
  502. } else if detail.Trademode == 16 && (detail.Orderstatus == 3 || detail.Orderstatus == 7) {
  503. // 求购中
  504. detail.MyBuyStatus = 2
  505. } else if detail.Orderstatus == 8 || detail.Orderstatus == 9 {
  506. // 已完成
  507. detail.MyBuyStatus = 3
  508. } else if detail.Orderstatus == 6 || detail.Orderstatus == 22 {
  509. // 已撤销
  510. detail.MyBuyStatus = 4
  511. } else if detail.Orderstatus == 4 {
  512. // 委托失败
  513. detail.MyBuyStatus = 5
  514. }
  515. }
  516. return hybsMyBuyOrderDetails, nil
  517. }
  518. // HsbyMyGoods 我的商品(买方向持仓)
  519. type HsbyMyGoods struct {
  520. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账号Id
  521. Goodsid int32 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品Id
  522. Buycurpositionqty int64 `json:"buycurpositionqty" xorm:"'BUYCURPOSITIONQTY'"` // 买当前持仓总数量
  523. Buycurholderamount float64 `json:"buycurholderamount" xorm:"'BUYCURHOLDERAMOUNT'"` // 买当前持仓总金额[商品币种]
  524. EnableQty int64 `json:"enableqty" xorm:"'ENABLEQTY'"` // 可用数量
  525. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  526. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  527. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  528. Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
  529. Goodsstatus int64 `json:"goodsstatus" xorm:"'GOODSSTATUS'"` // 商品状态- 1:待审核 2:未上市 3:上市 4:已注销 5:审核拒绝 6:退市 7:待退市
  530. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  531. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  532. Trademode int32 `json:"trademode" xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
  533. Buyaverageprice float64 `json:"buyaverageprice" xorm:"-"` // 持仓均价
  534. }
  535. // GetHsbyMyGoods 获取“我的商品”信息
  536. // 输入 accountIDs string 资金账户列表,格式 1,2,3
  537. // 输出 []HsbyMyGoods “我的商品”信息
  538. // 输入 error error
  539. func GetHsbyMyGoods(accountIDs string) ([]HsbyMyGoods, error) {
  540. engine := db.GetEngine()
  541. hsbyMyGoodses := make([]HsbyMyGoods, 0)
  542. // 此定制版本,只查询出当前手数(期末)大于0的数据 (TRADEPOSITION.BUYCURPOSITIONQTY > 0)
  543. if err := engine.Table("TRADEPOSITION TP").
  544. Select(`TP.*, (TP.BUYCURPOSITIONQTY - TP.BUYFROZENQTY - TP.BUYOTHERFROZENQTY) ENABLEQTY,
  545. G.GOODSCODE, G.GOODSNAME, G.DECIMALPLACE, G.AGREEUNIT, G.GOODSSTATUS,
  546. GX.PICURLS,
  547. E.PARAM2 CURRENCYSIGN,
  548. M.TRADEMODE`).
  549. Join("LEFT", "GOODS G", "G.GOODSID = TP.GOODSID").
  550. Join("INNER", "HSBY_GOODSEX GX", "GX.GOODSID = G.GOODSID").
  551. Join("LEFT", "ENUMDICITEM E", "G.CURRENCYID = E.ENUMITEMNAME and E.ENUMDICCODE = 'currency'").
  552. Join("LEFT", "MARKET M", "M.MARKETID = G.MARKETID").
  553. Where(fmt.Sprintf("TP.BUYCURPOSITIONQTY > 0 and TP.ACCOUNTID in (%s)", accountIDs)).Find(&hsbyMyGoodses); err != nil {
  554. return nil, err
  555. }
  556. for i := range hsbyMyGoodses {
  557. myGoods := &hsbyMyGoodses[i]
  558. // 持仓均价
  559. averagePrice := myGoods.Buycurholderamount / float64(myGoods.Buycurpositionqty) / myGoods.Agreeunit
  560. myGoods.Buyaverageprice, _ = strconv.ParseFloat(utils.FormatFloat(averagePrice, int(myGoods.Decimalplace)), 64)
  561. }
  562. return hsbyMyGoodses, nil
  563. }
  564. // HsbyPreGoods 新品上市商品(一级市场产能预售)
  565. type HsbyPreGoods struct {
  566. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID(自增ID SEQ_GOODS)
  567. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  568. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  569. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  570. Marketid int64 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 所属市场ID
  571. Goodsstatus int64 `json:"goodsstatus" xorm:"'GOODSSTATUS'"` // 商品状态- 2:未上市 3:上市
  572. Quoteminunit int64 `json:"quoteminunit" xorm:"'QUOTEMINUNIT'"` // 行情最小变动单位 [整数,报价小数位一起使用]
  573. Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
  574. Listingdate time.Time `json:"listingdate" xorm:"'LISTINGDATE'"` // 交易开始日期
  575. Lasttradedate time.Time `json:"lasttradedate" xorm:"'LASTTRADEDATE'"` // 最后交易日期(状态:待退市)
  576. Relatedgoodsid int64 `json:"relatedgoodsid" xorm:"'RELATEDGOODSID'"` // 关联交易合约ID
  577. Presaleqty int64 `json:"presaleqty" xorm:"'PRESALEQTY'"` // 预售数量
  578. Refprice float64 `json:"refprice" xorm:"'REFPRICE'"` // 参考价格[一口价]
  579. Presaledqty int64 `json:"presaledqty" xorm:"'PRESALEDQTY'"` // 已预售量(预售结束时更新)
  580. EnableQty int64 `json:"enableqty" xorm:"ENABLEQTY"` // 剩余数量
  581. Currency string `json:"currency" xorm:"'CURRENCY'"` // 货币
  582. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  583. Videourls string `json:"videourls" xorm:"'VIDEOURLS'"` // 介绍视频[多张用逗号分隔]
  584. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  585. Trademode int32 `json:"trademode" xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
  586. }
  587. // GetHsbyPreGoodses 获取“新品上市”商品列表(一级市场产能预售)
  588. // 输入 marketIDs string 市场ID列表,格式 1,2,3
  589. // 输入 descProvinceID int 省ID
  590. // 输入 descCityID int 市ID
  591. // 输出 []HsbyPreGoods “新品上市”商品列表
  592. // 输出 error error
  593. func GetHsbyPreGoodses(marketIDs string, descProvinceID, descCityID int) ([]HsbyPreGoods, error) {
  594. engine := db.GetEngine()
  595. // 注意:一级产能预售市场使用的商品实际上是和二级市场有关系的,所以要使用 CPTRADE_PRESALEGOODSEX.RELATEDGOODSID 进行关联
  596. // 注意:CPTRADE_PRESALEGOODSEX 表的开始与结束时间是给大宗用的
  597. preGoodses := make([]HsbyPreGoods, 0)
  598. session := engine.Table("GOODS").
  599. Select(`GOODS.*,
  600. CPTRADE_PRESALEGOODSEX.RELATEDGOODSID, CPTRADE_PRESALEGOODSEX.PRESALEQTY, CPTRADE_PRESALEGOODSEX.REFPRICE,
  601. CPTRADE_PRESALEGOODSEX.PRESALEDQTY, (CPTRADE_PRESALEGOODSEX.PRESALEQTY - CPTRADE_PRESALEGOODSEX.PRESALEDQTY) ENABLEQTY,
  602. ENUMDICITEM.ENUMDICNAME CURRENCY, ENUMDICITEM.PARAM2 CURRENCYSIGN,
  603. HSBY_GOODSEX.VIDEOURLS, HSBY_GOODSEX.PICURLS,
  604. MARKET.TRADEMODE`).
  605. Join("INNER", "CPTRADE_PRESALEGOODSEX", "CPTRADE_PRESALEGOODSEX.GOODSID = GOODS.GOODSID").
  606. Join("LEFT", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMNAME = GOODS.CURRENCYID and ENUMDICITEM.ENUMDICCODE = 'currency'").
  607. Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = CPTRADE_PRESALEGOODSEX.RELATEDGOODSID").
  608. Join("LEFT", "MARKET", "MARKET.MARKETID = GOODS.MARKETID").
  609. Where(fmt.Sprintf("GOODS.GOODSSTATUS in (2,3) and GOODS.MARKETID in (%s)", marketIDs)) // 一级市场获取 2:未上市 3:上市 状态的商品
  610. if descProvinceID > 0 {
  611. session = session.And("HSBY_GOODSEX.DESCPROVINCEID = ?", descProvinceID)
  612. }
  613. if descCityID > 0 {
  614. session = session.And("HSBY_GOODSEX.DESCCITYID = ?", descCityID)
  615. }
  616. if err := session.Find(&preGoodses); err != nil {
  617. return nil, err
  618. }
  619. // for i := range preGoodses {
  620. // preGoods := &preGoodses[i]
  621. // // FIXME: - 这里应该使用 Duck Typing,后期再处理
  622. // // 计算最小变动单位
  623. // lotSize := float64(preGoods.Quoteminunit) * math.Pow(0.1, float64(preGoods.Decimalplace))
  624. // preGoods.LotSize, _ = strconv.ParseFloat(utils.FormatFloat(lotSize, int(preGoods.Decimalplace)), 64)
  625. // }
  626. return preGoodses, nil
  627. }
  628. // HsbyPreGoodsDetail 一级市场(产能预售)商品信息详情
  629. type HsbyPreGoodsDetail struct {
  630. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID(自增ID SEQ_GOODS)
  631. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  632. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  633. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  634. Marketid int64 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 所属市场ID
  635. Goodsstatus int64 `json:"goodsstatus" xorm:"'GOODSSTATUS'"` // 商品状态- 2:未上市 3:上市
  636. Quoteminunit int64 `json:"quoteminunit" xorm:"'QUOTEMINUNIT'"` // 行情最小变动单位 [整数,报价小数位一起使用]
  637. Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
  638. Listingdate time.Time `json:"listingdate" xorm:"'LISTINGDATE'"` // 交易开始日期
  639. Lasttradedate time.Time `json:"lasttradedate" xorm:"'LASTTRADEDATE'"` // 最后交易日期(状态:待退市)
  640. Relatedgoodsid int64 `json:"relatedgoodsid" xorm:"'RELATEDGOODSID'"` // 关联交易合约ID
  641. Presaleqty int64 `json:"presaleqty" xorm:"'PRESALEQTY'"` // 预售数量
  642. Refprice float64 `json:"refprice" xorm:"'REFPRICE'"` // 参考价格[一口价]
  643. Presaledqty int64 `json:"presaledqty" xorm:"'PRESALEDQTY'"` // 已预售量(预售结束时更新)
  644. EnableQty int64 `json:"enableqty" xorm:"ENABLEQTY"` // 剩余数量
  645. Videourls string `json:"videourls" xorm:"'VIDEOURLS'"` // 介绍视频[多张用逗号分隔]
  646. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  647. Descprovinceid int64 `json:"descprovinceid" xorm:"'DESCPROVINCEID'"` // 目的地(省)ID
  648. Desccityid int64 `json:"desccityid" xorm:"'DESCCITYID'"` // 目的地(市)ID
  649. Goodsdesc string `json:"goodsdesc" xorm:"'GOODSDESC'"` // 商品详情
  650. Currency string `json:"currency" xorm:"'CURRENCY'"` // 货币
  651. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  652. Goodunit string `json:"goodunit" xorm:"GOODUNIT"` // 报价单位
  653. Vendorname string `json:"vendorname" xorm:"'VENDORNAME'"` // 供应商名称
  654. Vendorphone string `json:"vendorphone" xorm:"'VENDORPHONE'"` // 供应商客服电话
  655. Vendorattr string `json:"vendorattr" xorm:"'VENDORATTR'"` // 供应商附件(多张,逗号分隔)
  656. Trademode int32 `json:"trademode" xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
  657. Customername string `json:"customername" xorm:"'CUSTOMERNAME'"` // 发行单位
  658. StepValue float64 `json:"stepvalue" xorm:"-"` // 价格最小变动单位
  659. LotSize int `json:"lotsize" xorm:"-"` // 手数最小变动单位
  660. Buymaxqty int `json:"buymaxqty" xorm:"'-'"` // 购买上限 [71] - 0为不限
  661. }
  662. // GetHsbyPreGoodsDetail 获取一级市场(产能预售)商品信息详情
  663. // 参数 goodsID int 目标商品ID
  664. // 返回 *HsbyListingGoodsDetail 二级市场(挂牌点选)商品信息详情,查询无结果返回nil
  665. // 返回 error error
  666. func GetHsbyPreGoodsDetail(goodsID, accountID int) (*HsbyPreGoodsDetail, error) {
  667. engine := db.GetEngine()
  668. details := make([]HsbyPreGoodsDetail, 0)
  669. // 获取挂牌商品信息,以及扩展表信息
  670. // FIXME: - 这里使用Get方法,会造成SQL语句的嵌套出错,后期再研究
  671. session := engine.Table("GOODS").
  672. Select(`GOODS.*,
  673. CPTRADE_PRESALEGOODSEX.RELATEDGOODSID, CPTRADE_PRESALEGOODSEX.PRESALEQTY, CPTRADE_PRESALEGOODSEX.REFPRICE,
  674. CPTRADE_PRESALEGOODSEX.PRESALEDQTY, (CPTRADE_PRESALEGOODSEX.PRESALEQTY - CPTRADE_PRESALEGOODSEX.PRESALEDQTY) ENABLEQTY,
  675. HSBY_GOODSEX.VIDEOURLS, HSBY_GOODSEX.PICURLS, HSBY_GOODSEX.DESCPROVINCEID, HSBY_GOODSEX.Desccityid, HSBY_GOODSEX.Goodsdesc,
  676. ENUMDICITEM.ENUMDICNAME CURRENCY, ENUMDICITEM.PARAM2 CURRENCYSIGN,
  677. E1.ENUMDICNAME GOODUNIT,
  678. HSBY_SUPPLIERINFO.VENDORNAME, HSBY_SUPPLIERINFO.VENDORPHONE, HSBY_SUPPLIERINFO.VENDORATTR,
  679. MARKET.TRADEMODE,
  680. USERINFO.CUSTOMERNAME`).
  681. Join("INNER", "CPTRADE_PRESALEGOODSEX", "CPTRADE_PRESALEGOODSEX.GOODSID = GOODS.GOODSID").
  682. Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = CPTRADE_PRESALEGOODSEX.RELATEDGOODSID").
  683. Join("LEFT", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMNAME = GOODS.CURRENCYID and ENUMDICITEM.ENUMDICCODE = 'currency'").
  684. Join("LEFT", "ENUMDICITEM E1", "E1.ENUMITEMNAME = GOODS.GOODUNITID and E1.ENUMDICCODE = 'goodsunit'").
  685. Join("LEFT", "HSBY_SUPPLIERINFO", "HSBY_SUPPLIERINFO.VENDORID = HSBY_GOODSEX.VENDORID").
  686. Join("LEFT", "MARKET", "MARKET.MARKETID = GOODS.MARKETID").
  687. Join("LEFT", "USERINFO", "USERINFO.USERID = CPTRADE_PRESALEGOODSEX.USERID").
  688. Where("GOODS.GOODSID = ?", goodsID)
  689. if err := session.Find(&details); err != nil {
  690. return nil, err
  691. }
  692. // 无目标商品
  693. if len(details) == 0 {
  694. return nil, nil
  695. }
  696. preGoodsDetail := details[0]
  697. // FIXME: - 这里应该使用 Duck Typing,后期再处理
  698. // 计算价格最小变动单位
  699. stepValue := float64(preGoodsDetail.Quoteminunit) * math.Pow(0.1, float64(preGoodsDetail.Decimalplace))
  700. preGoodsDetail.StepValue, _ = strconv.ParseFloat(utils.FormatFloat(stepValue, int(preGoodsDetail.Decimalplace)), 64)
  701. // 计算手数最小变动单位,一级市场固定为1
  702. preGoodsDetail.LotSize = 1
  703. // 获取购买上限
  704. if accountID != 0 {
  705. buyMaxQty, err := GetCPTradeBuyLimit(goodsID, accountID)
  706. if err != nil {
  707. return nil, err
  708. }
  709. preGoodsDetail.Buymaxqty = buyMaxQty
  710. }
  711. return &preGoodsDetail, nil
  712. }
  713. // HsbySellMyDetail "我的闲置"单据信息(发布中 - 二级市场卖挂,3:委托成功、7:部分成交; 已完成 - 二级市场成交单,包括历史数据)
  714. type HsbySellMyDetail struct {
  715. Orderid string `json:"orderid" xorm:"'ORDERID'" binding:"required"` // 单号(发布中 - 委托单号;已完成 - 成交单号)
  716. Marketid int32 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 市场ID
  717. Goodsid int32 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID
  718. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账户ID[报价币种]
  719. Buyorsell int32 `json:"buyorsell" xorm:"'BUYORSELL'" binding:"required"` // 买卖 - 0:买 1:卖
  720. Price float64 `json:"price" xorm:"'PRICE'"` // 价格
  721. Time time.Time `json:"time" xorm:"'TIME'" binding:"required"` // 时间
  722. Qty int64 `json:"qty" xorm:"'QTY'"` // 数量
  723. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  724. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  725. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  726. Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
  727. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  728. Trademode uint32 `json:"trademode" xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
  729. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  730. Vendorname string `json:"vendorname" xorm:"'VENDORNAME'"` // 供应商名称
  731. OrderType int32 `json:"ordertype" xorm:"'ORDERTYPE'"` // 单据类型:0 - 发布中, 1 - 已完成
  732. }
  733. // GetHsbySellMyOrderDetails 获取"我的闲置 - 发布中"单据信息
  734. // 输入 accountIDs string 资金账户列表
  735. // 输出 []HsbySellMyDetail "我的闲置 - 发布中"单据信息
  736. // 输出 error error
  737. func GetHsbySellMyOrderDetails(accountIDs string) ([]HsbySellMyDetail, error) {
  738. // 获取市场信息
  739. markets, err := GetMarkets()
  740. if err != nil {
  741. return nil, err
  742. }
  743. engine := db.GetEngine()
  744. marketIDs := "" // 我的闲置-发布中: 二级市场卖挂牌、三级商城
  745. for _, v := range markets {
  746. if v.Trademode == 16 || v.Trademode == 70 {
  747. if len(marketIDs) == 0 {
  748. marketIDs = strconv.Itoa(int(v.Marketid))
  749. } else {
  750. marketIDs += "," + strconv.Itoa(int(v.Marketid))
  751. }
  752. }
  753. }
  754. orderDetails := make([]HsbySellMyDetail, 0)
  755. // “我的闲置 - 发布中”都是卖挂委托
  756. session := engine.Table("TRADE_ORDERDETAIL").
  757. Select(`to_char(TRADE_ORDERDETAIL.ORDERID) ORDERID,
  758. TRADE_ORDERDETAIL.MARKETID, TRADE_ORDERDETAIL.GOODSID, TRADE_ORDERDETAIL.ACCOUNTID, TRADE_ORDERDETAIL.BUYORSELL,
  759. TRADE_ORDERDETAIL.ORDERPRICE PRICE, TRADE_ORDERDETAIL.ORDERTIME TIME,
  760. (TRADE_ORDERDETAIL.ORDERQTY - TRADE_ORDERDETAIL.TRADEQTY - TRADE_ORDERDETAIL.CANCELQTY) QTY,
  761. GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.AGREEUNIT,
  762. HSBY_GOODSEX.PICURLS,
  763. MARKET.TRADEMODE,
  764. ENUMDICITEM.PARAM2 CURRENCYSIGN,
  765. HSBY_SUPPLIERINFO.VENDORNAME,
  766. 0 ORDERTYPE`).
  767. Join("LEFT", "GOODS", "GOODS.GOODSID = TRADE_ORDERDETAIL.GOODSID").
  768. Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
  769. Join("LEFT", "ENUMDICITEM", "GOODS.CURRENCYID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'currency'").
  770. Join("LEFT", "MARKET", "MARKET.MARKETID = TRADE_ORDERDETAIL.MARKETID").
  771. Join("LEFT", "HSBY_SUPPLIERINFO", "HSBY_SUPPLIERINFO.VENDORID = HSBY_GOODSEX.VENDORID").
  772. Where(fmt.Sprintf(`TRADE_ORDERDETAIL.BUYORSELL = 1 and TRADE_ORDERDETAIL.LISTINGSELECTTYPE = 1 and (TRADE_ORDERDETAIL.ORDERSTATUS = 3 or TRADE_ORDERDETAIL.ORDERSTATUS = 7)
  773. and TRADE_ORDERDETAIL.ACCOUNTID in (%s)`, accountIDs)).
  774. And(fmt.Sprintf("TRADE_ORDERDETAIL.MARKETID in (%s)", marketIDs))
  775. if err := session.Find(&orderDetails); err != nil {
  776. return nil, err
  777. }
  778. return orderDetails, nil
  779. }
  780. // GetHsbySellMyTradeDetails 获取"我的闲置 - 已完成"单据信息
  781. // 输入 accountIDs string 资金账户列表
  782. // 输出 []HsbySellMyDetail "我的闲置 - 已完成"单据信息
  783. // 输出 error error
  784. func GetHsbySellMyTradeDetails(accountIDs string) ([]HsbySellMyDetail, error) {
  785. // 获取市场信息
  786. markets, err := GetMarkets()
  787. if err != nil {
  788. return nil, err
  789. }
  790. engine := db.GetEngine()
  791. marketIDs := "" // 我的闲置-发布中: 二级市场卖方向成交单(包括历史成交单)
  792. // 默认取 TradeMode = 16
  793. for _, v := range markets {
  794. if v.Trademode == 16 {
  795. if len(marketIDs) == 0 {
  796. marketIDs = strconv.Itoa(int(v.Marketid))
  797. } else {
  798. marketIDs += "," + strconv.Itoa(int(v.Marketid))
  799. }
  800. }
  801. }
  802. orders := make([]HsbySellMyDetail, 0)
  803. // 当前成交单
  804. curOrders := make([]HsbySellMyDetail, 0)
  805. if err := engine.Table("TRADE_TRADEDETAIL").
  806. Select(`to_char(TRADE_TRADEDETAIL.TRADEID) ORDERID,
  807. TRADE_TRADEDETAIL.MARKETID, TRADE_TRADEDETAIL.GOODSID, TRADE_TRADEDETAIL.ACCOUNTID, TRADE_TRADEDETAIL.BUYORSELL,
  808. TRADE_TRADEDETAIL.TRADEPRICE PRICE, TRADE_TRADEDETAIL.TRADEQTY QTY, TRADE_TRADEDETAIL.TRADETIME TIME, TRADE_TRADEDETAIL.TRADEAMOUNT AMOUNT,
  809. GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.AGREEUNIT,
  810. HSBY_GOODSEX.PICURLS,
  811. MARKET.TRADEMODE,
  812. ENUMDICITEM.PARAM2 CURRENCYSIGN,
  813. HSBY_SUPPLIERINFO.VENDORNAME,
  814. 1 ORDERTYPE`).
  815. Join("LEFT", "GOODS", "GOODS.GOODSID = TRADE_TRADEDETAIL.GOODSID").
  816. Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
  817. Join("LEFT", "ENUMDICITEM", "GOODS.CURRENCYID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'currency'").
  818. Join("LEFT", "MARKET", "MARKET.MARKETID = TRADE_TRADEDETAIL.MARKETID").
  819. Join("LEFT", "HSBY_SUPPLIERINFO", "HSBY_SUPPLIERINFO.VENDORID = HSBY_GOODSEX.VENDORID").
  820. Where(fmt.Sprintf(`TRADE_TRADEDETAIL.BUYORSELL = 1 and TRADE_TRADEDETAIL.TRADETYPE in (1,24)
  821. and TRADE_TRADEDETAIL.ACCOUNTID in (%s)`, accountIDs)).
  822. And(fmt.Sprintf("TRADE_TRADEDETAIL.MARKETID in (%s)", marketIDs)).Find(&curOrders); err != nil {
  823. return nil, err
  824. }
  825. if len(curOrders) > 0 {
  826. orders = append(orders, curOrders...)
  827. }
  828. // 历史成交单
  829. hisOrders := make([]HsbySellMyDetail, 0)
  830. if err := engine.Table("HIS_TRADE_TRADEDETAIL").
  831. Select(`to_char(HIS_TRADE_TRADEDETAIL.TRADEID) ORDERID,
  832. HIS_TRADE_TRADEDETAIL.MARKETID, HIS_TRADE_TRADEDETAIL.GOODSID, HIS_TRADE_TRADEDETAIL.ACCOUNTID, HIS_TRADE_TRADEDETAIL.BUYORSELL,
  833. HIS_TRADE_TRADEDETAIL.TRADEPRICE PRICE, HIS_TRADE_TRADEDETAIL.TRADEQTY QTY, HIS_TRADE_TRADEDETAIL.TRADETIME TIME, HIS_TRADE_TRADEDETAIL.TRADEAMOUNT AMOUNT,
  834. GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.AGREEUNIT,
  835. HSBY_GOODSEX.PICURLS,
  836. MARKET.TRADEMODE,
  837. ENUMDICITEM.PARAM2 CURRENCYSIGN,
  838. HSBY_SUPPLIERINFO.VENDORNAME,
  839. 1 ORDERTYPE`).
  840. Join("LEFT", "GOODS", "GOODS.GOODSID = HIS_TRADE_TRADEDETAIL.GOODSID").
  841. Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
  842. Join("LEFT", "ENUMDICITEM", "GOODS.CURRENCYID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'currency'").
  843. Join("LEFT", "MARKET", "MARKET.MARKETID = HIS_TRADE_TRADEDETAIL.MARKETID").
  844. Join("LEFT", "HSBY_SUPPLIERINFO", "HSBY_SUPPLIERINFO.VENDORID = HSBY_GOODSEX.VENDORID").
  845. Where(fmt.Sprintf(`HIS_TRADE_TRADEDETAIL.BUYORSELL = 1 and HIS_TRADE_TRADEDETAIL.TRADETYPE in (1,24) and HIS_TRADE_TRADEDETAIL.ISVALIDDATA = 1
  846. and HIS_TRADE_TRADEDETAIL.ACCOUNTID in (%s)`, accountIDs)).
  847. And(fmt.Sprintf("HIS_TRADE_TRADEDETAIL.MARKETID in (%s)", marketIDs)).Find(&hisOrders); err != nil {
  848. return nil, err
  849. }
  850. if len(hisOrders) > 0 {
  851. orders = append(orders, hisOrders...)
  852. }
  853. return orders, nil
  854. }
  855. // HsbyMyPackage 我的包裹信息
  856. type HsbyMyPackage struct {
  857. Takeorderid string `json:"takeorderid" xorm:"'TAKEORDERID'" binding:"required"` // 提货单号(905+Unix秒时间戳(10位)+xxxxxx)
  858. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 账户ID
  859. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'"` // 商品ID
  860. Userid int64 `json:"userid" xorm:"'USERID'"` // 用户ID
  861. Qty float64 `json:"qty" xorm:"'QTY'"` // 提货数量
  862. Reqtime time.Time `json:"reqtime" xorm:"'REQTIME'"` // 更新时间
  863. Recivername string `json:"recivername" xorm:"'RECIVERNAME'"` // 提货人姓名
  864. Cardtypeid int32 `json:"cardtypeid" xorm:"'CARDTYPEID'"` // 提货人证件类型
  865. Cardnum string `json:"cardnum" xorm:"'CARDNUM'"` // 提货人证件号码
  866. Phonenum string `json:"phonenum" xorm:"'PHONENUM'"` // 提货人联系方式
  867. Takemode int32 `json:"takemode" xorm:"'TAKEMODE'"` // 提货方式 - 2:自提 3:配送
  868. Address string `json:"address" xorm:"'ADDRESS'"` // 提货人详细地址
  869. Takeremark string `json:"takeremark" xorm:"'TAKEREMARK'"` // 提货备注
  870. Takeorderstatus int32 `json:"takeorderstatus" xorm:"'TAKEORDERSTATUS'"` // 提货状态 - 1:待发货 2:已发货 3:已收货
  871. Auditer int32 `json:"auditer" xorm:"'AUDITER'"` // 审核人
  872. Audittime time.Time `json:"audittime" xorm:"'AUDITTIME'"` // 审核时间
  873. Checkremark string `json:"checkremark" xorm:"'CHECKREMARK'"` // 审核备注
  874. Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  875. Marketid int32 `json:"marketid" xorm:"'MARKETID'"` // 市场ID
  876. Handlestatus int32 `json:"handlestatus" xorm:"'HANDLESTATUS'"` // 处理状态
  877. Amount float64 `json:"amount" xorm:"'AMOUNT'"` // 提货金额
  878. Averageprice float64 `json:"averageprice" xorm:"'AVERAGEPRICE'"` // 均价
  879. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  880. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  881. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  882. Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
  883. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  884. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  885. Vendorname string `json:"vendorname" xorm:"'VENDORNAME'"` // 供应商名称
  886. }
  887. // GetHsbyMyPackages 获取我的包裹信息
  888. // 输入 accountIDs string 资金账户列表
  889. // 输入 takeOrderStatus int 提货状态 - 1:待发货 2:已发货 3:已收货
  890. // 输出 []HsbyMyPackage 我的包裹信息
  891. // 输出 error error
  892. func GetHsbyMyPackages(accountIDs string, takeOrderStatus int) ([]HsbyMyPackage, error) {
  893. engine := db.GetEngine()
  894. myPackages := make([]HsbyMyPackage, 0)
  895. session := engine.Table("TRADE_GOODSPICKUP").
  896. Select(`to_char(TRADE_GOODSPICKUP.TAKEORDERID) TAKEORDERID, (DIVISION.PATHNAME || TRADE_GOODSPICKUP.ADDRESS) ADDRESS, TRADE_GOODSPICKUP.*,
  897. (TRADE_GOODSPICKUP.AMOUNT/TRADE_GOODSPICKUP.QTY/GOODS.AGREEUNIT) AVERAGEPRICE,
  898. GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.AGREEUNIT,
  899. HSBY_GOODSEX.PICURLS,
  900. ENUMDICITEM.PARAM2 CURRENCYSIGN,
  901. HSBY_SUPPLIERINFO.VENDORNAME`).
  902. Join("LEFT", "GOODS", "GOODS.GOODSID = TRADE_GOODSPICKUP.GOODSID").
  903. Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
  904. Join("LEFT", "ENUMDICITEM", "GOODS.CURRENCYID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'currency'").
  905. Join("LEFT", "HSBY_SUPPLIERINFO", "HSBY_SUPPLIERINFO.VENDORID = HSBY_GOODSEX.VENDORID").
  906. Join("LEFT", "DIVISION", "DIVISION.AUTOID = TRADE_GOODSPICKUP.DISTRICTID").
  907. Where(fmt.Sprintf("TRADE_GOODSPICKUP.ACCOUNTID in (%s)", accountIDs))
  908. if takeOrderStatus > 0 {
  909. session = session.And("TAKEORDERSTATUS = ?", takeOrderStatus)
  910. }
  911. if err := session.Find(&myPackages); err != nil {
  912. return nil, err
  913. }
  914. // FIXME:- 目前暂时在服务端对手机号码进行解密
  915. key, _ := hex.DecodeString(utils.AESSecretKey)
  916. for i := range myPackages {
  917. myPackage := &myPackages[i]
  918. if len(myPackage.Phonenum) > 0 {
  919. // 解密手机号码
  920. if phonenum, err := hex.DecodeString(myPackage.Phonenum); err == nil { // hex -> []byte
  921. if mobile, err := utils.AESDecrypt(phonenum, key); err == nil {
  922. myPackage.Phonenum = string(mobile)
  923. }
  924. }
  925. }
  926. }
  927. return myPackages, nil
  928. }
  929. // SetHsbyMyPackagesStatus 设置我的包裹提货状态
  930. func SetHsbyMyPackagesStatus(takeOrderID string, accountID, status int) error {
  931. engine := db.GetEngine()
  932. sql := fmt.Sprintf("update TRADE_GOODSPICKUP set TAKEORDERSTATUS = %d where TAKEORDERID = %s and ACCOUNTID = %d", status, takeOrderID, accountID)
  933. _, err := engine.Exec(sql)
  934. return err
  935. }
  936. // GetHsbyProvincesAndCities 获取省市信息数组
  937. // 参数 provinceID int 省ID,选填
  938. // 返回 []Division 枚举信息数组
  939. // 返回 error error
  940. func GetHsbyProvincesAndCities(provinceID int) ([]Division, error) {
  941. engine := db.GetEngine()
  942. divisions := make([]Division, 0)
  943. session := engine.Where("DIVISIONLEVEL = 'province' or DIVISIONLEVEL = 'city'").
  944. And(`AUTOID in (
  945. (select DESCPROVINCEID AUTOID from HSBY_GOODSEX inner join GOODS on GOODS.GOODSID = HSBY_GOODSEX.GOODSID and GOODS.GOODSSTATUS in (2,3))
  946. union all
  947. (select DESCCITYID AUTOID from HSBY_GOODSEX inner join GOODS on GOODS.GOODSID = HSBY_GOODSEX.GOODSID and GOODS.GOODSSTATUS in (2,3))
  948. )`)
  949. if provinceID > 0 {
  950. session = session.And("AUTOID = ?", provinceID)
  951. }
  952. if err := session.Find(&divisions); err != nil {
  953. return nil, err
  954. }
  955. return divisions, nil
  956. }
  957. // HsbyBuyMyTradeDetail "我的订单 - 已完成"单据信息(一二级市场成交单,包括历史数据)
  958. type HsbyBuyMyTradeDetail struct {
  959. Orderid string `json:"orderid" xorm:"'ORDERID'" binding:"required"` // 单号(成交单号)
  960. Marketid int32 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 市场ID
  961. Goodsid int32 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID
  962. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账户ID[报价币种]
  963. Buyorsell int32 `json:"buyorsell" xorm:"'BUYORSELL'" binding:"required"` // 买卖 - 0:买 1:卖
  964. Price float64 `json:"price" xorm:"'PRICE'"` // 价格
  965. Qty int64 `json:"qty" xorm:"'QTY'" binding:"required"` // 数量
  966. Time time.Time `json:"time" xorm:"'TIME'" binding:"required"` // 时间
  967. Amount float64 `json:"amount" xorm:"'AMOUNT'"` // 金额 = 价格 * 数量 * 合约单位
  968. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  969. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  970. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  971. Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
  972. Picurls1 string `json:"picurls1" xorm:"'PICURLS1'"` // 预售商品介绍图片[多张用逗号分隔]
  973. Picurls2 string `json:"picurls2" xorm:"'PICURLS2'"` // 挂牌商品介绍图片[多张用逗号分隔]
  974. Trademode uint32 `json:"trademode" xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
  975. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  976. Vendorname1 string `json:"vendorname1" xorm:"'VENDORNAME1'"` // 预售商品供应商名称
  977. Vendorname2 string `json:"vendorname2" xorm:"'VENDORNAME2'"` // 挂牌商品供应商名称
  978. }
  979. // GetHsbyBuyMyTradeDetails 获取"我的订单 - 已完成"单据信息(一二级市场成交单,包括历史数据)
  980. // 输入 accountIDs string 资金账户列表
  981. // 输出 []HsbyBuyMyTradeDetail "我的订单 - 已完成"单据信息
  982. // 输出 error error
  983. func GetHsbyBuyMyTradeDetails(accountIDs string) ([]HsbyBuyMyTradeDetail, error) {
  984. // 获取市场信息
  985. markets, err := GetMarkets()
  986. if err != nil {
  987. return nil, err
  988. }
  989. engine := db.GetEngine()
  990. marketIDs := "" // 我的订单包括一二级市场卖方向成交单(包括历史成交单)
  991. // 默认取 TradeMode = 16
  992. for _, v := range markets {
  993. if v.Trademode == 16 || v.Trademode == 71 {
  994. if len(marketIDs) == 0 {
  995. marketIDs = strconv.Itoa(int(v.Marketid))
  996. } else {
  997. marketIDs += "," + strconv.Itoa(int(v.Marketid))
  998. }
  999. }
  1000. }
  1001. orders := make([]HsbyBuyMyTradeDetail, 0)
  1002. // 当前成交单
  1003. curOrders := make([]HsbyBuyMyTradeDetail, 0)
  1004. if err := engine.Table("TRADE_TRADEDETAIL").
  1005. Select(`to_char(TRADE_TRADEDETAIL.TRADEID) ORDERID,
  1006. TRADE_TRADEDETAIL.MARKETID, TRADE_TRADEDETAIL.GOODSID, TRADE_TRADEDETAIL.ACCOUNTID, TRADE_TRADEDETAIL.BUYORSELL,
  1007. TRADE_TRADEDETAIL.TRADEPRICE PRICE, TRADE_TRADEDETAIL.TRADEQTY QTY, TRADE_TRADEDETAIL.TRADETIME TIME, TRADE_TRADEDETAIL.TRADEAMOUNT AMOUNT,
  1008. GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.AGREEUNIT,
  1009. HG1.PICURLS PICURLS1, HG2.PICURLS PICURLS2,
  1010. MARKET.TRADEMODE,
  1011. ENUMDICITEM.PARAM2 CURRENCYSIGN,
  1012. HS1.VENDORNAME VENDORNAME1, HS2.VENDORNAME VENDORNAME2`).
  1013. Join("LEFT", "GOODS", "GOODS.GOODSID = TRADE_TRADEDETAIL.GOODSID").
  1014. Join("LEFT", "CPTRADE_PRESALEGOODSEX", "CPTRADE_PRESALEGOODSEX.GOODSID = TRADE_TRADEDETAIL.GOODSID").
  1015. Join("LEFT", "HSBY_GOODSEX HG1", "HG1.GOODSID = CPTRADE_PRESALEGOODSEX.RELATEDGOODSID").
  1016. Join("LEFT", "HSBY_GOODSEX HG2", "HG2.GOODSID = GOODS.GOODSID").
  1017. Join("LEFT", "ENUMDICITEM", "GOODS.CURRENCYID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'currency'").
  1018. Join("LEFT", "MARKET", "MARKET.MARKETID = TRADE_TRADEDETAIL.MARKETID").
  1019. Join("LEFT", "HSBY_SUPPLIERINFO HS1", "HS1.VENDORID = HG1.VENDORID").
  1020. Join("LEFT", "HSBY_SUPPLIERINFO HS2", "HS2.VENDORID = HG2.VENDORID").
  1021. Where(fmt.Sprintf(`TRADE_TRADEDETAIL.BUYORSELL = 0 and TRADE_TRADEDETAIL.TRADETYPE in (1,24)
  1022. and TRADE_TRADEDETAIL.ACCOUNTID in (%s)`, accountIDs)).
  1023. And(fmt.Sprintf("TRADE_TRADEDETAIL.MARKETID in (%s)", marketIDs)).Find(&curOrders); err != nil {
  1024. return nil, err
  1025. }
  1026. if len(curOrders) > 0 {
  1027. orders = append(orders, curOrders...)
  1028. }
  1029. // 历史成交单
  1030. hisOrders := make([]HsbyBuyMyTradeDetail, 0)
  1031. if err := engine.Table("HIS_TRADE_TRADEDETAIL").
  1032. Select(`to_char(HIS_TRADE_TRADEDETAIL.TRADEID) ORDERID,
  1033. HIS_TRADE_TRADEDETAIL.MARKETID, HIS_TRADE_TRADEDETAIL.GOODSID, HIS_TRADE_TRADEDETAIL.ACCOUNTID, HIS_TRADE_TRADEDETAIL.BUYORSELL,
  1034. HIS_TRADE_TRADEDETAIL.TRADEPRICE PRICE, HIS_TRADE_TRADEDETAIL.TRADEQTY QTY, HIS_TRADE_TRADEDETAIL.TRADETIME TIME, HIS_TRADE_TRADEDETAIL.TRADEAMOUNT AMOUNT,
  1035. GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.AGREEUNIT,
  1036. HG1.PICURLS PICURLS1, HG2.PICURLS PICURLS2,
  1037. MARKET.TRADEMODE,
  1038. ENUMDICITEM.PARAM2 CURRENCYSIGN,
  1039. HS1.VENDORNAME VENDORNAME1, HS2.VENDORNAME VENDORNAME2`).
  1040. Join("LEFT", "GOODS", "GOODS.GOODSID = HIS_TRADE_TRADEDETAIL.GOODSID").
  1041. Join("LEFT", "CPTRADE_PRESALEGOODSEX", "CPTRADE_PRESALEGOODSEX.GOODSID = HIS_TRADE_TRADEDETAIL.GOODSID").
  1042. Join("LEFT", "HSBY_GOODSEX HG1", "HG1.GOODSID = CPTRADE_PRESALEGOODSEX.RELATEDGOODSID").
  1043. Join("LEFT", "HSBY_GOODSEX HG2", "HG2.GOODSID = GOODS.GOODSID").
  1044. Join("LEFT", "ENUMDICITEM", "GOODS.CURRENCYID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'currency'").
  1045. Join("LEFT", "MARKET", "MARKET.MARKETID = HIS_TRADE_TRADEDETAIL.MARKETID").
  1046. Join("LEFT", "HSBY_SUPPLIERINFO HS1", "HS1.VENDORID = HG1.VENDORID").
  1047. Join("LEFT", "HSBY_SUPPLIERINFO HS2", "HS2.VENDORID = HG2.VENDORID").
  1048. Where(fmt.Sprintf(`HIS_TRADE_TRADEDETAIL.BUYORSELL = 0 and HIS_TRADE_TRADEDETAIL.TRADETYPE in (1,24) and HIS_TRADE_TRADEDETAIL.ISVALIDDATA = 1
  1049. and HIS_TRADE_TRADEDETAIL.ACCOUNTID in (%s)`, accountIDs)).
  1050. And(fmt.Sprintf("HIS_TRADE_TRADEDETAIL.MARKETID in (%s)", marketIDs)).Find(&hisOrders); err != nil {
  1051. return nil, err
  1052. }
  1053. if len(hisOrders) > 0 {
  1054. orders = append(orders, hisOrders...)
  1055. }
  1056. return orders, nil
  1057. }
  1058. // HsbyBuyMyPayOrder "我的订单 - 待付款"单据信息(一二级市场待付款信息)
  1059. type HsbyBuyMyPayOrder struct {
  1060. Tradeid string `json:"tradeid" xorm:"'TRADEIDSTR'" binding:"required"` // 成交单号(101+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
  1061. Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  1062. Marketid int32 `json:"marketid" xorm:"'MARKETID'"` // 市场ID
  1063. Goodsid int32 `json:"goodsid" xorm:"'GOODSID'"` // 商品ID
  1064. Buyorderid string `json:"buyorderid" xorm:"'BUYORDERIDSTR'"` // 买方委托单号
  1065. Buyaccountid int64 `json:"buyaccountid" xorm:"'BUYACCOUNTID'"` // 买方账号ID[报价币种]
  1066. Sellorderid string `json:"sellorderid" xorm:"'SELLORDERIDSTR'"` // 卖方委托单号
  1067. Sellaccountid int64 `json:"sellaccountid" xorm:"'SELLACCOUNTID'"` // 卖方账号ID[报价币种]
  1068. Tradeamount float64 `json:"tradeamount" xorm:"'TRADEAMOUNT'"` // 成交金额
  1069. Tradecharge float64 `json:"tradecharge" xorm:"'TRADECHARGE'"` // 成交手续费(买方)
  1070. Payflag int32 `json:"payflag" xorm:"'PAYFLAG'"` // 付款标识 - 1:未支付 2:已支付 3:已过期 4:已撤销 5:结算过期 6:预售终止
  1071. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  1072. Paytime time.Time `json:"paytime" xorm:"'PAYTIME'"` // 付款时间
  1073. Paylimitedtime time.Time `json:"paylimitedtime" xorm:"'PAYLIMITEDTIME'"` // 支付期限
  1074. Offamount float64 `json:"offamount" xorm:"'OFFAMOUNT'"` // 优惠金额
  1075. Tradeprice float64 `json:"tradeprice" xorm:"'TRADEPRICE'"` // 成交价格
  1076. Tradeqty int64 `json:"tradeqty" xorm:"'TRADEQTY'"` // 成交数量
  1077. Payamount float64 `json:"payamount" xorm:"'PAYAMOUNT'"` // 支付金额 = TradeAmount + TradeCharge - OffAmount
  1078. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  1079. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  1080. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  1081. Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
  1082. Picurls1 string `json:"picurls1" xorm:"'PICURLS1'"` // 预售商品介绍图片[多张用逗号分隔]
  1083. Picurls2 string `json:"picurls2" xorm:"'PICURLS2'"` // 挂牌商品介绍图片[多张用逗号分隔]
  1084. Trademode uint32 `json:"trademode" xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
  1085. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  1086. Vendorname1 string `json:"vendorname1" xorm:"'VENDORNAME1'"` // 预售商品供应商名称
  1087. Vendorname2 string `json:"vendorname2" xorm:"'VENDORNAME2'"` // 挂牌商品供应商名称
  1088. }
  1089. // GetHsbyBuyMyPayOrders 获取待付款信息
  1090. func GetHsbyBuyMyPayOrders(accountIDs string, buyOrderID, sellOrderID int) ([]HsbyBuyMyPayOrder, error) {
  1091. // 获取市场信息
  1092. markets, err := GetMarkets()
  1093. if err != nil {
  1094. return nil, err
  1095. }
  1096. engine := db.GetEngine()
  1097. marketIDs := "" // 我的订单包括一二级市场卖方向成交单
  1098. // 默认取 TradeMode = 16
  1099. for _, v := range markets {
  1100. if v.Trademode == 16 || v.Trademode == 71 || v.Trademode == 70 {
  1101. if len(marketIDs) == 0 {
  1102. marketIDs = strconv.Itoa(int(v.Marketid))
  1103. } else {
  1104. marketIDs += "," + strconv.Itoa(int(v.Marketid))
  1105. }
  1106. }
  1107. }
  1108. orders := make([]HsbyBuyMyPayOrder, 0)
  1109. session := engine.Table("TRADE_PAYORDER TP").
  1110. Select(`to_char(TP.TRADEID) TRADEIDSTR, to_char(TP.BUYORDERID) BUYORDERIDSTR, to_char(TP.SELLORDERID) SELLORDERIDSTR, TP.*,
  1111. GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.AGREEUNIT,
  1112. HG1.PICURLS PICURLS1, HG2.PICURLS PICURLS2,
  1113. MARKET.TRADEMODE,
  1114. ENUMDICITEM.PARAM2 CURRENCYSIGN,
  1115. HS1.VENDORNAME VENDORNAME1, HS2.VENDORNAME VENDORNAME2`).
  1116. Join("LEFT", "GOODS", "GOODS.GOODSID = TP.GOODSID").
  1117. Join("LEFT", "CPTRADE_PRESALEGOODSEX CP", "CP.GOODSID = TP.GOODSID").
  1118. Join("LEFT", "HSBY_GOODSEX HG1", "HG1.GOODSID = CP.RELATEDGOODSID").
  1119. Join("LEFT", "HSBY_GOODSEX HG2", "HG2.GOODSID = GOODS.GOODSID").
  1120. Join("LEFT", "ENUMDICITEM", "GOODS.CURRENCYID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'currency'").
  1121. Join("LEFT", "MARKET", "MARKET.MARKETID = TP.MARKETID").
  1122. Join("LEFT", "HSBY_SUPPLIERINFO HS1", "HS1.VENDORID = HG1.VENDORID").
  1123. Join("LEFT", "HSBY_SUPPLIERINFO HS2", "HS2.VENDORID = HG2.VENDORID").
  1124. Where(fmt.Sprintf(`TP.PAYFLAG = 1 and TP.BUYACCOUNTID in (%s)`, accountIDs)).
  1125. And(fmt.Sprintf("TP.MARKETID in (%s)", marketIDs))
  1126. if buyOrderID != 0 {
  1127. session = session.And("TP.BUYORDERID = ?", buyOrderID)
  1128. }
  1129. if sellOrderID != 0 {
  1130. session = session.And("TP.SELLORDERID = ?", sellOrderID)
  1131. }
  1132. if err := session.Find(&orders); err != nil {
  1133. return nil, err
  1134. }
  1135. return orders, nil
  1136. }
  1137. // HsbyMarketInfo 海商报业相关市场信息
  1138. type HsbyMarketInfo struct {
  1139. Marketid int32 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 市场ID正常5位,前三位固定:两位表示交易模式, 一位表示交易属性(1:收益权,2:所有权) 其它特殊市场:0-系统 1-交割服务 2-账户服务3-履约服务 4-仓单服务 5-积分服务 6-银行服务
  1140. Marketname string `json:"marketname" xorm:"'MARKETNAME'"` // 市场名称
  1141. Trademode int32 `json:"trademode" xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
  1142. Marketstatus int32 `json:"marketstatus" xorm:"'MARKETSTATUS'" binding:"required"` // 生效状态(ValidStatus枚举): 1:待生效 2:正常 3:注销
  1143. }
  1144. // GetHsbyMarketInfos 获取海商报业相关市场信息
  1145. func GetHsbyMarketInfos() ([]HsbyMarketInfo, error) {
  1146. engine := db.GetEngine()
  1147. markets := make([]HsbyMarketInfo, 0)
  1148. if err := engine.Table("MARKET").Where("TRADEMODE in (71,16,70)").Find(&markets); err != nil {
  1149. return nil, err
  1150. }
  1151. return markets, nil
  1152. }
  1153. // HsbySellCollectionOrder 我的闲置中收款信息
  1154. type HsbySellCollectionOrder struct {
  1155. Tradeid string `json:"tradeid" xorm:"'TRADEIDSTR'" binding:"required"` // 成交单号(101+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
  1156. Tradedate string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyyMMdd)
  1157. Marketid int32 `json:"marketid" xorm:"'MARKETID'"` // 市场ID
  1158. Goodsid int32 `json:"goodsid" xorm:"'GOODSID'"` // 商品ID
  1159. Buyorderid string `json:"buyorderid" xorm:"'BUYORDERIDSTR'"` // 买方委托单号
  1160. Buyaccountid int64 `json:"buyaccountid" xorm:"'BUYACCOUNTID'"` // 买方账号ID[报价币种]
  1161. Sellorderid string `json:"sellorderid" xorm:"'SELLORDERIDSTR'"` // 卖方委托单号
  1162. Sellaccountid int64 `json:"sellaccountid" xorm:"'SELLACCOUNTID'"` // 卖方账号ID[报价币种]
  1163. Tradeamount float64 `json:"tradeamount" xorm:"'TRADEAMOUNT'"` // 成交金额
  1164. Tradecharge float64 `json:"tradecharge" xorm:"'TRADECHARGE'"` // 成交手续费(买方)
  1165. Payflag int32 `json:"payflag" xorm:"'PAYFLAG'"` // 付款标识 - 1:未支付 2:已支付 3:已过期 4:已撤销 5:结算过期 6:预售终止
  1166. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  1167. Paytime time.Time `json:"paytime" xorm:"'PAYTIME'"` // 付款时间
  1168. Paylimitedtime time.Time `json:"paylimitedtime" xorm:"'PAYLIMITEDTIME'"` // 支付期限
  1169. Offamount float64 `json:"offamount" xorm:"'OFFAMOUNT'"` // 优惠金额
  1170. Tradeprice float64 `json:"tradeprice" xorm:"'TRADEPRICE'"` // 成交价格
  1171. Tradeqty int64 `json:"tradeqty" xorm:"'TRADEQTY'"` // 成交数量
  1172. Payamount float64 `json:"payamount" xorm:"'PAYAMOUNT'"` // 支付金额 = TradeAmount + TradeCharge - OffAmount
  1173. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  1174. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  1175. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  1176. Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
  1177. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 商品介绍图片[多张用逗号分隔]
  1178. Trademode uint32 `json:"trademode" xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
  1179. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  1180. }
  1181. // GetHsbySellCollectionOrders 获取我的闲置中待收款信息
  1182. func GetHsbySellCollectionOrders(accountIDs string) ([]HsbySellCollectionOrder, error) {
  1183. // 获取市场信息
  1184. markets, err := GetMarkets()
  1185. if err != nil {
  1186. return nil, err
  1187. }
  1188. engine := db.GetEngine()
  1189. marketIDs := ""
  1190. for _, v := range markets {
  1191. if v.Trademode == 16 || v.Trademode == 70 {
  1192. if len(marketIDs) == 0 {
  1193. marketIDs = strconv.Itoa(int(v.Marketid))
  1194. } else {
  1195. marketIDs += "," + strconv.Itoa(int(v.Marketid))
  1196. }
  1197. }
  1198. }
  1199. orders := make([]HsbySellCollectionOrder, 0)
  1200. session := engine.Table("TRADE_PAYORDER TP").
  1201. Select(`to_char(TP.TRADEID) TRADEIDSTR, to_char(TP.BUYORDERID) BUYORDERIDSTR, to_char(TP.SELLORDERID) SELLORDERIDSTR, TP.*,
  1202. G.GOODSCODE, G.GOODSNAME, G.DECIMALPLACE, G.AGREEUNIT,
  1203. HG.PICURLS,
  1204. M.TRADEMODE,
  1205. E.PARAM2 CURRENCYSIGN`).
  1206. Join("LEFT", "GOODS G", "G.GOODSID = TP.GOODSID").
  1207. Join("LEFT", "HSBY_GOODSEX HG", "HG.GOODSID = G.GOODSID").
  1208. Join("LEFT", "ENUMDICITEM E", "G.CURRENCYID = E.ENUMITEMNAME and E.ENUMDICCODE = 'currency'").
  1209. Join("LEFT", "MARKET M", "M.MARKETID = TP.MARKETID").
  1210. Join("LEFT", "HSBY_SUPPLIERINFO HS", "HS.VENDORID = HG.VENDORID").
  1211. Where(fmt.Sprintf(`TP.PAYFLAG = 1 and TP.SELLACCOUNTID in (%s)`, accountIDs)).
  1212. And(fmt.Sprintf("TP.MARKETID in (%s)", marketIDs))
  1213. if err := session.Find(&orders); err != nil {
  1214. return nil, err
  1215. }
  1216. return orders, nil
  1217. }
  1218. // HsbyMarketGoods 特卖商城商品(三级市场商场)
  1219. type HsbyMarketGoods struct {
  1220. Orderid string `json:"orderid" xorm:"'ORDERIDSTR'" binding:"required"` // 委托单号(100+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
  1221. Marketid int32 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 市场ID
  1222. Goodsid int32 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID
  1223. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账户ID[报价币种]
  1224. Buyorsell int32 `json:"buyorsell" xorm:"'BUYORSELL'" binding:"required"` // 买卖 - 0:买 1:卖
  1225. Orderprice float64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格
  1226. Orderstatus int32 `json:"orderstatus" xorm:"'ORDERSTATUS'"` // 委托状态 - 1: 委托请求 2:待冻结 3:委托成功 4: 委托失败 5:配对成功 6: 已撤销 7:部分成交 8:已成交 9:部成部撤 10:成交失败 11:已拒绝 12:经过摘牌(先摘后挂专用-先摘后挂已摘过) 13:冻结成功(通道交易专用) 14:通道已撤 15:通道部成部撤 16:成交失败违约(荷兰式竞拍专用)
  1227. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  1228. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  1229. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  1230. Quoteminunit int64 `json:"quoteminunit" xorm:"'QUOTEMINUNIT'"` // 行情最小变动单位 [整数,报价小数位一起使用]
  1231. Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
  1232. Hotindex int32 `json:"hotindex" xorm:"'HOTINDEX'"` // 景点热度
  1233. Videourls string `json:"videourls" xorm:"'VIDEOURLS'"` // 介绍视频[多张用逗号分隔]
  1234. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  1235. Categoryid int32 `json:"categoryid" xorm:"'CATEGORYID'"` // 类别ID(WRCATEGORY)
  1236. Currency string `json:"currency" xorm:"'CURRENCY'"` // 货币
  1237. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  1238. Trademode int32 `json:"trademode" xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
  1239. Customername string `json:"customername" xorm:"'CUSTOMERNAME'"` // 卖家名称
  1240. HasCoupon bool `json:"hascoupon" xorm:"-"` // 是否可用优惠卷
  1241. SellUserID int `json:"sellUserID" xorm:"-"` // 卖方UserID
  1242. }
  1243. // GetHsbyMarketGoodses 获取商城商品列表(三级商城)
  1244. func GetHsbyMarketGoodses(marketIDs string, accountID, categoryID int, goodsIDs string, couponTypeID int) ([]HsbyMarketGoods, error) {
  1245. engine := db.GetEngine()
  1246. // 获取优惠卷类型信息
  1247. var couponType Coupontype
  1248. if _, err := engine.Where("ISVALID = 1 and COUPONTYPEID = ?", couponTypeID).Get(&couponType); err != nil {
  1249. return nil, err
  1250. }
  1251. orders := make([]HsbyMarketGoods, 0)
  1252. // 与挂牌点选不一样的是商城是以委托单为主表;已经卖完的委托单不显示
  1253. session := engine.Table("TRADE_ORDERDETAIL T").
  1254. Select(`to_char(T.ORDERID) ORDERIDSTR, T.*,
  1255. G.GOODSCODE, G.GOODSNAME, G.DECIMALPLACE, G.QUOTEMINUNIT, G.AGREEUNIT,
  1256. GX.HOTINDEX, GX.PICURLS, GX.CATEGORYID, GX.GOODSDESC,
  1257. E.ENUMDICNAME CURRENCY, E.PARAM2 CURRENCYSIGN,
  1258. M.TRADEMODE,
  1259. U.CUSTOMERNAME`).
  1260. Join("LEFT", "GOODS G", "G.GOODSID = T.GOODSID").
  1261. Join("LEFT", "HSBY_GOODSEX GX", "GX.GOODSID = T.GOODSID").
  1262. Join("LEFT", "ENUMDICITEM E", "E.ENUMITEMNAME = G.CURRENCYID and E.ENUMDICCODE = 'currency'").
  1263. Join("LEFT", "MARKET M", "M.MARKETID = T.MARKETID").
  1264. Join("LEFT", "TAACCOUNT TA", "TA.ACCOUNTID = T.ACCOUNTID").
  1265. Join("LEFT", "USERINFO U", "U.USERID = TA.RELATEDUSERID").
  1266. Where(fmt.Sprintf("T.MARKETID in (%s)", marketIDs)).
  1267. And("T.ORDERSTATUS in (3,7) and T.BUYORSELL = 1 and (T.ORDERQTY - T.TRADEQTY - T.CANCELQTY) > 0")
  1268. if categoryID != 0 {
  1269. session = session.And("GX.CATEGORYID = ?", categoryID)
  1270. }
  1271. if len(goodsIDs) > 0 {
  1272. session = session.And(fmt.Sprintf("G.GOODSID in (%s)", goodsIDs))
  1273. }
  1274. if couponTypeID > 0 {
  1275. if couponType.Coupontypeid == 0 {
  1276. // 没有查询到对应的优惠卷,直接返回空数组
  1277. return make([]HsbyMarketGoods, 0), nil
  1278. }
  1279. // 优惠卷特定商品
  1280. if couponType.Limitedflag == 1 {
  1281. // 去掉头尾逗号
  1282. limitedGoodsIDs := couponType.Limitedgoodsids
  1283. if strings.HasPrefix(limitedGoodsIDs, ",") && strings.HasSuffix(limitedGoodsIDs, ",") {
  1284. limitedGoodsIDs = limitedGoodsIDs[1 : len(limitedGoodsIDs)-1]
  1285. }
  1286. session = session.And(fmt.Sprintf("T.GOODSID in (%s)", limitedGoodsIDs))
  1287. }
  1288. // 优惠卷特定卖家
  1289. if couponType.Isgeneral == 0 {
  1290. // 去掉头尾逗号
  1291. userScope := couponType.Userscope
  1292. if strings.HasPrefix(userScope, ",") && strings.HasSuffix(userScope, ",") {
  1293. userScope = userScope[1 : len(userScope)-1]
  1294. }
  1295. // 查询对应的卖家资金账户信息
  1296. taAccounts := make([]Taaccount, 0)
  1297. if err := engine.Where(fmt.Sprintf("RELATEDUSERID in (%s)", userScope)).Find(&taAccounts); err != nil {
  1298. return nil, err
  1299. }
  1300. sellAccountIDs := ""
  1301. for _, v := range taAccounts {
  1302. if len(sellAccountIDs) == 0 {
  1303. sellAccountIDs = strconv.Itoa(int(v.Accountid))
  1304. } else {
  1305. sellAccountIDs += "," + strconv.Itoa(int(v.Accountid))
  1306. }
  1307. }
  1308. session = session.And(fmt.Sprintf("T.ACCOUNTID in (%s)", sellAccountIDs))
  1309. }
  1310. }
  1311. if err := session.Find(&orders); err != nil {
  1312. return nil, err
  1313. }
  1314. // 获取当前账户的优惠卷
  1315. type myCouponPosition struct {
  1316. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 资金账户ID
  1317. Coupontypeid int32 `json:"coupontypeid" xorm:"'COUPONTYPEID'" binding:"required"` // 优惠券类型ID
  1318. Curqty int64 `json:"curqty" xorm:"'CURQTY'"` // 期末数量
  1319. Curfreezeqty int64 `json:"curfreezeqty" xorm:"'CURFREEZEQTY'"` // 期末冻结数量
  1320. Limitedflag int32 `json:"limitedflag" xorm:"'LIMITEDFLAG'"` // 是否指定商品 - 0:不限 1:限制
  1321. Limitedgoodsids string `json:"limitedgoodsids" xorm:"'LIMITEDGOODSIDS'"` // 指定商品IDs[逗号分隔,前后加逗号]
  1322. Isgeneral int32 `json:"isgeneral" xorm:"'ISGENERAL'"` // 是否通用券 - 0:否 1:是
  1323. Userscope string `json:"userscope" xorm:"'USERSCOPE'"` // 卖家范围(用户ID,逗号分隔,前后加逗号) [IsGeneral =0时使用]
  1324. }
  1325. myCouponPositions := make([]myCouponPosition, 0)
  1326. if accountID != 0 {
  1327. if err := engine.Table("COUPONPOSITION C").
  1328. Select(`C.ACCOUNTID, C.COUPONTYPEID, C.CURQTY, C.CURFREEZEQTY,
  1329. CT.LIMITEDFLAG, CT.LIMITEDGOODSIDS, CT.ISGENERAL, CT.USERSCOPE`).
  1330. Join("INNER", "COUPONTYPE CT", "CT.COUPONTYPEID = C.COUPONTYPEID").
  1331. Where("C.ACCOUNTID = ?", accountID).Find(&myCouponPositions); err != nil {
  1332. return nil, err
  1333. }
  1334. }
  1335. // 是否有优惠卷可用
  1336. if len(orders) > 0 && len(myCouponPositions) > 0 {
  1337. for _, coupon := range myCouponPositions {
  1338. if coupon.Limitedflag == 0 && coupon.Isgeneral == 1 {
  1339. // 有不指定商品的通用卷则所有委托单都可以用卷
  1340. for i := range orders {
  1341. order := &orders[i]
  1342. order.HasCoupon = true
  1343. }
  1344. break
  1345. } else {
  1346. for i := range orders {
  1347. order := &orders[i]
  1348. // 获取卖家UserID
  1349. userInfo, err := GetUserInfoByAccountID(int(order.Accountid))
  1350. if err != nil {
  1351. continue
  1352. }
  1353. order.SellUserID = int(userInfo.Userid)
  1354. // order.Customername = userInfo.Customername
  1355. tmpGoodsID := fmt.Sprintf(",%d,", order.Goodsid)
  1356. tmpUserID := fmt.Sprintf(",%d,", userInfo.Userid)
  1357. // 优惠卷是否可用于商品
  1358. isRightGoods := false
  1359. if coupon.Limitedflag == 0 {
  1360. isRightGoods = true
  1361. } else {
  1362. if strings.Contains(coupon.Limitedgoodsids, tmpGoodsID) {
  1363. isRightGoods = true
  1364. }
  1365. }
  1366. // 优惠卷是否可用于卖家
  1367. isRightAccount := false
  1368. if coupon.Isgeneral == 1 {
  1369. isRightAccount = true
  1370. } else {
  1371. if strings.Contains(coupon.Userscope, tmpUserID) {
  1372. isRightAccount = true
  1373. }
  1374. }
  1375. if isRightGoods && isRightAccount {
  1376. order.HasCoupon = true
  1377. }
  1378. }
  1379. }
  1380. }
  1381. }
  1382. return orders, nil
  1383. }
  1384. // HsbyMarketGoodsDetail 特卖商城商品(三级市场商场)
  1385. type HsbyMarketGoodsDetail struct {
  1386. Orderid string `json:"orderid" xorm:"'ORDERIDSTR'" binding:"required"` // 委托单号(100+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
  1387. Marketid int32 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 市场ID
  1388. Goodsid int32 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID
  1389. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账户ID[报价币种]
  1390. Buyorsell int32 `json:"buyorsell" xorm:"'BUYORSELL'" binding:"required"` // 买卖 - 0:买 1:卖
  1391. Orderprice float64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格
  1392. Orderqty int64 `json:"orderqty" xorm:"'ORDERQTY'" binding:"required"` // 委托数量
  1393. Tradeqty int64 `json:"tradeqty" xorm:"'TRADEQTY'"` // 成交数量
  1394. Cancelqty int64 `json:"cancelqty" xorm:"'CANCELQTY'"` // 撤单数量
  1395. Orderstatus int32 `json:"orderstatus" xorm:"'ORDERSTATUS'"` // 委托状态 - 1: 委托请求 2:待冻结 3:委托成功 4: 委托失败 5:配对成功 6: 已撤销 7:部分成交 8:已成交 9:部成部撤 10:成交失败 11:已拒绝 12:经过摘牌(先摘后挂专用-先摘后挂已摘过) 13:冻结成功(通道交易专用) 14:通道已撤 15:通道部成部撤 16:成交失败违约(荷兰式竞拍专用)
  1396. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  1397. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  1398. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  1399. Quoteminunit int64 `json:"quoteminunit" xorm:"'QUOTEMINUNIT'"` // 行情最小变动单位 [整数,报价小数位一起使用]
  1400. Agreeunit float64 `json:"agreeunit" xorm:"'AGREEUNIT'"` // 合约单位
  1401. Hotindex int32 `json:"hotindex" xorm:"'HOTINDEX'"` // 景点热度
  1402. Videourls string `json:"videourls" xorm:"'VIDEOURLS'"` // 介绍视频[多张用逗号分隔]
  1403. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  1404. Categoryid int32 `json:"categoryid" xorm:"'CATEGORYID'"` // 类别ID(WRCATEGORY)
  1405. Goodsdesc string `json:"goodsdesc" xorm:"'GOODSDESC'"` // 商品详情
  1406. Currency string `json:"currency" xorm:"'CURRENCY'"` // 货币
  1407. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  1408. Trademode int32 `json:"trademode" xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
  1409. Vendorname string `json:"vendorname" xorm:"'VENDORNAME'"` // 供应商名称
  1410. Customername string `json:"customername" xorm:"'CUSTOMERNAME'"` // 卖家名称
  1411. SellUserID int `json:"sellUserID" xorm:"SELLUSERID"` // 卖方UserID
  1412. }
  1413. // GetHsbyMarketGoodsDetail 获取商城商品详情(三级商城)
  1414. func GetHsbyMarketGoodsDetail(orderID int) (*HsbyMarketGoodsDetail, error) {
  1415. engine := db.GetEngine()
  1416. orders := make([]HsbyMarketGoodsDetail, 0)
  1417. // 与挂牌点选不一样的是商城是以委托单为主表
  1418. session := engine.Table("TRADE_ORDERDETAIL T").
  1419. Select(`to_char(T.ORDERID) ORDERIDSTR, T.*,
  1420. G.GOODSCODE, G.GOODSNAME, G.DECIMALPLACE, G.QUOTEMINUNIT, G.AGREEUNIT,
  1421. GX.HOTINDEX, GX.VIDEOURLS, GX.PICURLS, GX.CATEGORYID, GX.GOODSDESC,
  1422. E.ENUMDICNAME CURRENCY, E.PARAM2 CURRENCYSIGN,
  1423. M.TRADEMODE,
  1424. H.VENDORNAME,
  1425. U.USERID SELLUSERID, U.CUSTOMERNAME`).
  1426. Join("LEFT", "GOODS G", "G.GOODSID = T.GOODSID").
  1427. Join("LEFT", "HSBY_GOODSEX GX", "GX.GOODSID = T.GOODSID").
  1428. Join("LEFT", "ENUMDICITEM E", "E.ENUMITEMNAME = G.CURRENCYID and E.ENUMDICCODE = 'currency'").
  1429. Join("LEFT", "MARKET M", "M.MARKETID = T.MARKETID").
  1430. Join("LEFT", "HSBY_SUPPLIERINFO H", "H.VENDORID = GX.VENDORID").
  1431. Join("LEFT", "TAACCOUNT TA", "TA.ACCOUNTID = T.ACCOUNTID").
  1432. Join("LEFT", "USERINFO U", "U.USERID = TA.RELATEDUSERID").
  1433. Where("T.ORDERID = ?", orderID)
  1434. if err := session.Find(&orders); err != nil {
  1435. return nil, err
  1436. }
  1437. // 无目标商品
  1438. if len(orders) == 0 {
  1439. return nil, nil
  1440. }
  1441. hsbyMarketGoodsDetail := orders[0]
  1442. return &hsbyMarketGoodsDetail, nil
  1443. }
  1444. // MyCoupon 我的优惠卷
  1445. type MyCoupon struct {
  1446. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 资金账户ID
  1447. Coupontypeid int32 `json:"coupontypeid" xorm:"'COUPONTYPEID'" binding:"required"` // 优惠券类型ID
  1448. Userid int64 `json:"userid" xorm:"'USERID'"` // 用户ID
  1449. Oriqty int64 `json:"oriqty" xorm:"'ORIQTY'"` // 期初数量
  1450. Orifreezeqty int64 `json:"orifreezeqty" xorm:"'ORIFREEZEQTY'"` // 期初冻结数量
  1451. Curqty int64 `json:"curqty" xorm:"'CURQTY'"` // 期末数量
  1452. Curfreezeqty int64 `json:"curfreezeqty" xorm:"'CURFREEZEQTY'"` // 期末冻结数量
  1453. Todayincrease int64 `json:"todayincrease" xorm:"'TODAYINCREASE'"` // 今日增加
  1454. Todaydecrease int64 `json:"todaydecrease" xorm:"'TODAYDECREASE'"` // 今日减少
  1455. Areauserid int64 `json:"areauserid" xorm:"'AREAUSERID'"` // 所属机构
  1456. Couponname string `json:"couponname" xorm:"'COUPONNAME'"` // 优惠券名称
  1457. Couponcategroy int32 `json:"couponcategroy" xorm:"'COUPONCATEGROY'"` // 种类 - 1:现金券 2:折扣券 3:折扣券(单张)
  1458. Conditionvalue float64 `json:"conditionvalue" xorm:"'CONDITIONVALUE'"` // 条件阈值(可为0)
  1459. Couponvalue float64 `json:"couponvalue" xorm:"'COUPONVALUE'"` // 面值[1:现金券 - 抵扣值 2:折扣券-折扣值]
  1460. Limitedflag int32 `json:"limitedflag" xorm:"'LIMITEDFLAG'"` // 是否指定商品 - 0:不限 1:限制
  1461. Limitedgoodsids string `json:"limitedgoodsids" xorm:"'LIMITEDGOODSIDS'"` // 指定商品IDs[逗号分隔,前后加逗号]
  1462. Isgeneral int32 `json:"isgeneral" xorm:"'ISGENERAL'"` // 是否通用券 - 0:否 1:是
  1463. Userscope string `json:"userscope" xorm:"'USERSCOPE'"` // 卖家范围(用户ID,逗号分隔,前后加逗号) [IsGeneral =0时使用]
  1464. IsUnusable bool `json:"isunusable" xorm:"-"` // 是否不可用
  1465. ReasonType int `json:"reasontype"` // 不可用原因 - 0:未确认 1:不可用于此商品 2:不可用于此卖家
  1466. }
  1467. // GetMyCoupons 获取我的优惠卷信息
  1468. func GetMyCoupons(accountIDs string, goodsID, sellUserID int) ([]MyCoupon, error) {
  1469. engine := db.GetEngine()
  1470. myCoupons := make([]MyCoupon, 0)
  1471. session := engine.Table("COUPONPOSITION CP").
  1472. Join("INNER", "COUPONTYPE CT", "CT.COUPONTYPEID = CP.COUPONTYPEID").
  1473. Where(fmt.Sprintf("CP.ACCOUNTID in (%s)", accountIDs))
  1474. if err := session.Find(&myCoupons); err != nil {
  1475. return nil, err
  1476. }
  1477. // 如果传入了商品ID和卖方UserID,则判断优惠卷是否可用
  1478. if goodsID != 0 && sellUserID != 0 && len(myCoupons) > 0 {
  1479. for i := range myCoupons {
  1480. myCoupon := &myCoupons[i]
  1481. // 优惠卷是否可用于商品
  1482. isRightGoods := false
  1483. if myCoupon.Limitedflag == 0 {
  1484. isRightGoods = true
  1485. } else {
  1486. if strings.Contains(myCoupon.Limitedgoodsids, fmt.Sprintf(",%d,", goodsID)) {
  1487. isRightGoods = true
  1488. }
  1489. }
  1490. // 优惠卷是否可用于卖家
  1491. isRightAccount := false
  1492. if myCoupon.Isgeneral == 1 {
  1493. isRightAccount = true
  1494. } else {
  1495. if strings.Contains(myCoupon.Userscope, fmt.Sprintf(",%d,", sellUserID)) {
  1496. isRightAccount = true
  1497. }
  1498. }
  1499. if !isRightGoods {
  1500. myCoupon.IsUnusable = true
  1501. myCoupon.ReasonType = 1
  1502. }
  1503. if !isRightAccount {
  1504. myCoupon.IsUnusable = true
  1505. myCoupon.ReasonType = 2
  1506. }
  1507. }
  1508. }
  1509. return myCoupons, nil
  1510. }
  1511. // MyCouponHold 我的优惠卷持仓
  1512. type MyCouponHold struct {
  1513. Couponholdid int64 `json:"couponholdid" xorm:"'COUPONHOLDID'" binding:"required"` // 优惠券持仓ID(229+Unix秒时间戳(10位)+xxxxxx)
  1514. Giveapplyid int64 `json:"giveapplyid" xorm:"'GIVEAPPLYID'"` // 发放申请ID(SEQ_COUPONGIVEAPPLY)
  1515. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 资金账户ID
  1516. Coupontypeid int32 `json:"coupontypeid" xorm:"'COUPONTYPEID'"` // 优惠券类型ID - SEQ_COUPONTYPE
  1517. Couponcategroy int32 `json:"couponcategroy" xorm:"'COUPONCATEGROY'"` // 种类 - 1:现金券 2:折扣券 3:折扣券(单个商品)
  1518. Conditionvalue float64 `json:"conditionvalue" xorm:"'CONDITIONVALUE'"` // 条件阈值(可为0)
  1519. Couponvalue float64 `json:"couponvalue" xorm:"'COUPONVALUE'"` // 面值[1:现金券 - 抵扣值 2:折扣券-折扣值]
  1520. Limitedflag int32 `json:"limitedflag" xorm:"'LIMITEDFLAG'"` // 是否指定商品 - 0:不限 1:限制
  1521. Limitedgoodsids string `json:"limitedgoodsids" xorm:"'LIMITEDGOODSIDS'"` // 指定商品IDs[逗号分隔]
  1522. Isgeneral int32 `json:"isgeneral" xorm:"'ISGENERAL'"` // 是否通用券 - 0:否 1:是
  1523. Userscope string `json:"userscope" xorm:"'USERSCOPE'"` // 卖家范围(用户ID,逗号分隔) [IsGeneral =0时使用]
  1524. Userid int64 `json:"userid" xorm:"'USERID'"` // 用户ID
  1525. Qty int64 `json:"qty" xorm:"'QTY'"` // 数量(按1平铺)
  1526. Startdate time.Time `json:"startdate" xorm:"'STARTDATE'"` // 开始日期
  1527. Holdstatus int32 `json:"holdstatus" xorm:"'HOLDSTATUS'"` // 持仓状态 - 1:未生效 2:已生效 3:已使用 4:已过期
  1528. Enddate time.Time `json:"enddate" xorm:"'ENDDATE'"` // 结束日期
  1529. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  1530. Couponname string `json:"couponname" xorm:"'COUPONNAME'"` // 优惠券名称
  1531. }
  1532. // GetMyCouponHolds 获取优惠卷明细
  1533. func GetMyCouponHolds(accountIDs string, holdStatus string) ([]MyCouponHold, error) {
  1534. engine := db.GetEngine()
  1535. myCouponHolds := make([]MyCouponHold, 0)
  1536. session := engine.Table("COUPONHOLD CH").
  1537. Select(`CH.*, CT.COUPONNAME`).
  1538. Join("INNER", "COUPONTYPE CT", "CT.COUPONTYPEID = CH.COUPONTYPEID").
  1539. Where(fmt.Sprintf("CH.ACCOUNTID in (%s)", accountIDs))
  1540. if len(holdStatus) > 0 {
  1541. session = session.And(fmt.Sprintf("CH.HOLDSTATUS in (%s)", holdStatus))
  1542. }
  1543. if err := session.Find(&myCouponHolds); err != nil {
  1544. return nil, err
  1545. }
  1546. return myCouponHolds, nil
  1547. }