hsby.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. package models
  2. import (
  3. "fmt"
  4. "mtp2_if/db"
  5. "mtp2_if/utils"
  6. "time"
  7. )
  8. // Hsbygoodsex 商品扩展表
  9. type Hsbygoodsex struct {
  10. Goodsid int32 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商 品ID
  11. Hotindex int32 `json:"hotindex" xorm:"'HOTINDEX'"` // 景点热度
  12. Descprovinceid int64 `json:"descprovinceid" xorm:"'DESCPROVINCEID'"` // 目的地(省)
  13. Desccityid int64 `json:"desccityid" xorm:"'DESCCITYID'"` // 目的地(市)
  14. Vendorid int32 `json:"vendorid" xorm:"'VENDORID'"` // 供应商ID
  15. Goodsdesc string `json:"goodsdesc" xorm:"'GOODSDESC'"` // 商品详情
  16. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  17. Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
  18. Modifierid int64 `json:"modifierid" xorm:"'MODIFIERID'"` // 修改人
  19. Modifytime time.Time `json:"modifytime" xorm:"'MODIFYTIME'"` // 修改时间
  20. Memberratio float64 `json:"memberratio" xorm:"'MEMBERRATIO'"` // 会员货款比例 [71]
  21. Videourls string `json:"videourls" xorm:"'VIDEOURLS'"` // 介绍视频[多张用逗号分隔]
  22. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  23. }
  24. // TableName is HSBY_GOODSEX
  25. func (Hsbygoodsex) TableName() string {
  26. return "HSBY_GOODSEX"
  27. }
  28. // Hsbysupplierinfo 供应商表
  29. type Hsbysupplierinfo struct {
  30. Vendorid int32 `json:"vendorid" xorm:"'VENDORID'" binding:"required"` // 供应商ID(SEQ_HSBY_SUPPLIERINFO)
  31. Vendorname string `json:"vendorname" xorm:"'VENDORNAME'"` // 名称描述客服电话名称
  32. Vendordesc string `json:"vendordesc" xorm:"'VENDORDESC'"` // 描述
  33. Vendorphone string `json:"vendorphone" xorm:"'VENDORPHONE'"` // 客服电话
  34. Vendorattr string `json:"vendorattr" xorm:"'VENDORATTR'"` // 附件(多张,逗号分隔)
  35. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  36. Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
  37. Modifierid int64 `json:"modifierid" xorm:"'MODIFIERID'"` // 修改人
  38. Modifytime time.Time `json:"modifytime" xorm:"'MODIFYTIME'"` // 修改时间
  39. }
  40. // TableName is HSBY_SUPPLIERINFO
  41. func (Hsbysupplierinfo) TableName() string {
  42. return "HSBY_SUPPLIERINFO"
  43. }
  44. // HsbyTopGoods 热门商品列表
  45. type HsbyTopGoods struct {
  46. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID(自增ID SEQ_GOODS)
  47. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  48. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  49. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  50. Marketid int64 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 所属市场ID
  51. Hotindex int32 `json:"hotindex" xorm:"'HOTINDEX'"` // 景点热度
  52. Videourls string `json:"videourls" xorm:"'VIDEOURLS'"` // 介绍视频[多张用逗号分隔]
  53. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  54. Currency string `json:"currency" xorm:"'CURRENCY'"` // 货币
  55. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  56. Last float64 `json:"last" xorm:"-"` // 现价
  57. }
  58. // GetHsbyTopGoods 获取热门商品列表
  59. // 参数 marketID int 所属市场ID
  60. // 参数 descProvinceID int 目标省ID
  61. // 参数 descCityID int 目标城市ID
  62. // 返回 []TopGoods 热门商品列表
  63. // 返回 error error
  64. func GetHsbyTopGoods(marketID int, descProvinceID int, descCityID int) ([]HsbyTopGoods, error) {
  65. // 热门商品为二级市场(挂牌点选)下的商品信息
  66. engine := db.GetEngine()
  67. topGoodses := make([]HsbyTopGoods, 0)
  68. // 获取挂牌商品信息,以及扩展表信息
  69. session := engine.Table("GOODS").
  70. Select(`GOODS.*,
  71. HSBY_GOODSEX.HOTINDEX, HSBY_GOODSEX.VIDEOURLS, HSBY_GOODSEX.PICURLS,
  72. ENUMDICITEM.ENUMDICNAME CURRENCY, ENUMDICITEM.PARAM2 CURRENCYSIGN`).
  73. Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
  74. Join("LEFT", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMNAME = GOODS.CURRENCYID and ENUMDICITEM.ENUMDICCODE = 'currency'").
  75. Where("GOODS.MARKETID = ?", marketID)
  76. if descProvinceID > 0 {
  77. session = session.And("HSBY_GOODSEX.DESCPROVINCEID = ?", descProvinceID)
  78. }
  79. if descCityID > 0 {
  80. session = session.And("HSBY_GOODSEX.DESCCITYID = ?", descCityID)
  81. }
  82. if err := session.Find(&topGoodses); err != nil {
  83. return nil, err
  84. }
  85. if len(topGoodses) == 0 {
  86. // 无数据
  87. return topGoodses, nil
  88. }
  89. // 获取商品ID列表
  90. goodsCodes := ""
  91. for _, v := range topGoodses {
  92. if len(goodsCodes) == 0 {
  93. goodsCodes = v.Goodscode
  94. } else {
  95. goodsCodes += "," + v.Goodscode
  96. }
  97. }
  98. // 获取商品现价
  99. quoteDays, err := GetQuoteDays(goodsCodes)
  100. if err != nil {
  101. return nil, err
  102. }
  103. for i, g := range topGoodses {
  104. for _, q := range quoteDays {
  105. if g.Goodscode == q.Goodscode {
  106. if q.Last != 0 {
  107. topGoods := &topGoodses[i]
  108. topGoods.Last = utils.IntToFloat64(int(q.Last), int(g.Decimalplace))
  109. }
  110. continue
  111. }
  112. }
  113. }
  114. return topGoodses, nil
  115. }
  116. // HsbyListingGoodsDetail 二级市场(挂牌点选)商品信息详情
  117. type HsbyListingGoodsDetail struct {
  118. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID(自增ID SEQ_GOODS)
  119. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  120. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  121. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  122. Marketid int64 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 所属市场ID
  123. Hotindex int32 `json:"hotindex" xorm:"'HOTINDEX'"` // 景点热度
  124. Videourls string `json:"videourls" xorm:"'VIDEOURLS'"` // 介绍视频[多张用逗号分隔]
  125. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  126. Descprovinceid int64 `json:"descprovinceid" xorm:"'DESCPROVINCEID'"` // 目的地(省)ID
  127. Desccityid int64 `json:"desccityid" xorm:"'DESCCITYID'"` // 目的地(市)ID
  128. Goodsdesc string `json:"goodsdesc" xorm:"'GOODSDESC'"` // 商品详情
  129. Currency string `json:"currency" xorm:"'CURRENCY'"` // 货币
  130. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  131. Vendorname string `json:"vendorname" xorm:"'VENDORNAME'"` // 供应商名称
  132. Vendorphone string `json:"vendorphone" xorm:"'VENDORPHONE'"` // 供应商客服电话
  133. Vendorattr string `json:"vendorattr" xorm:"'VENDORATTR'"` // 供应商附件(多张,逗号分隔)
  134. Last float64 `json:"last" xorm:"-"` // 现价
  135. Limitup float64 `json:"limitup" xorm:"-"` // 涨停价
  136. Limitdown float64 `json:"limitdown" xorm:"-"` // 跌停价
  137. }
  138. // GetHsbyListingGoodsDetail 获取二级市场(挂牌点选)商品信息详情
  139. // 参数 goodsID int 目标商品ID
  140. // 返回 *HsbyListingGoodsDetail 二级市场(挂牌点选)商品信息详情,查询无结果返回nil
  141. // 返回 error error
  142. func GetHsbyListingGoodsDetail(goodsID int) (*HsbyListingGoodsDetail, error) {
  143. engine := db.GetEngine()
  144. details := make([]HsbyListingGoodsDetail, 0)
  145. // 获取挂牌商品信息,以及扩展表信息
  146. // FIXME: - 这里使用Get方法,会造成SQL语句的嵌套出错,后期再研究
  147. session := engine.Table("GOODS").
  148. Select(`GOODS.GOODSID, GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.MARKETID,
  149. HSBY_GOODSEX.HOTINDEX, HSBY_GOODSEX.VIDEOURLS, HSBY_GOODSEX.PICURLS, HSBY_GOODSEX.DESCPROVINCEID, HSBY_GOODSEX.Desccityid, HSBY_GOODSEX.Goodsdesc,
  150. ENUMDICITEM.ENUMDICNAME CURRENCY, ENUMDICITEM.PARAM2 CURRENCYSIGN,
  151. HSBY_SUPPLIERINFO.VENDORNAME, HSBY_SUPPLIERINFO.VENDORPHONE, HSBY_SUPPLIERINFO.VENDORATTR`).
  152. Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
  153. Join("LEFT", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMNAME = GOODS.CURRENCYID and ENUMDICITEM.ENUMDICCODE = 'currency'").
  154. Join("LEFT", "HSBY_SUPPLIERINFO", "HSBY_SUPPLIERINFO.VENDORID = HSBY_GOODSEX.VENDORID").
  155. Where("GOODS.GOODSID = ?", goodsID)
  156. if err := session.Find(&details); err != nil {
  157. return nil, err
  158. }
  159. // 无目标商品
  160. if len(details) == 0 {
  161. return nil, nil
  162. }
  163. hsbyListingGoodsDetail := details[0]
  164. // 获取商品现价和涨跌停价
  165. quoteDays, err := GetQuoteDays(hsbyListingGoodsDetail.Goodscode)
  166. if err != nil {
  167. return nil, err
  168. }
  169. if len(quoteDays) > 0 {
  170. if quoteDays[0].Last != 0 {
  171. hsbyListingGoodsDetail.Last = utils.IntToFloat64(int(quoteDays[0].Last), int(hsbyListingGoodsDetail.Decimalplace))
  172. }
  173. if quoteDays[0].Limitup != 0 {
  174. hsbyListingGoodsDetail.Limitup = utils.IntToFloat64(int(quoteDays[0].Limitup), int(hsbyListingGoodsDetail.Decimalplace))
  175. }
  176. if quoteDays[0].Limitdown != 0 {
  177. hsbyListingGoodsDetail.Limitdown = utils.IntToFloat64(int(quoteDays[0].Limitdown), int(hsbyListingGoodsDetail.Decimalplace))
  178. }
  179. }
  180. return &hsbyListingGoodsDetail, nil
  181. }
  182. // HsbyGoodsOrderDetail 二级市场挂牌商品当前可摘委托单信息
  183. type HsbyGoodsOrderDetail struct {
  184. Orderid int64 `json:"orderid" xorm:"'ORDERID'" binding:"required"` // 委托单号(100+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
  185. Buyorsell int32 `json:"buyorsell" xorm:"'BUYORSELL'" binding:"required"` // 买卖 - 0:买 1:卖
  186. Ordertime time.Time `json:"ordertime" xorm:"'ORDERTIME'" binding:"required"` // 委托时间
  187. Orderprice float64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格
  188. Enableqty int64 `json:"enableqty" xorm:"ENABLEQTY"` // 可用数量
  189. Customername string `json:"customername" xorm:"'CUSTOMERNAME'"` // 客户名称(企业名称),已脱敏
  190. Currencysign string `json:"currencysign" xorm:"-"` // 货币符号
  191. Goodunit string `json:"goodunit" xorm:"-"` // 报价单位
  192. }
  193. // GetHsbyGoodsOrderDetails 获取二级市场(挂牌点选)商品对应的挂牌委托单信息
  194. // 参数 goodsID int 商品ID
  195. // 返回 []HsbyGoodsOrderDetail 转让(卖出)挂牌委托单
  196. // 返回 []HsbyGoodsOrderDetail 求购(买入)挂牌委托单
  197. // 返回 error error
  198. func GetHsbyGoodsOrderDetails(goodsID int) ([]HsbyGoodsOrderDetail, []HsbyGoodsOrderDetail, error) {
  199. engine := db.GetEngine()
  200. // 获取与目标商品相关的挂牌委托单信息(ListingSelectType = 1 or 3; OrderStatus =3 or 7)
  201. hsbyGoodsOrderDetails := make([]HsbyGoodsOrderDetail, 0)
  202. if err := engine.Table("TRADE_ORDERDETAIL").
  203. Select(`TRADE_ORDERDETAIL.ORDERID, TRADE_ORDERDETAIL.BUYORSELL, TRADE_ORDERDETAIL.ORDERTIME, TRADE_ORDERDETAIL.ORDERPRICE, (TRADE_ORDERDETAIL.ORDERQTY - TRADE_ORDERDETAIL.TRADEQTY - TRADE_ORDERDETAIL.CANCELQTY) ENABLEQTY,
  204. substr(USERINFO.CUSTOMERNAME,0,1)||'****' as CUSTOMERNAME`).
  205. Join("LEFT", "TAACCOUNT", "TAACCOUNT.ACCOUNTID = TRADE_ORDERDETAIL.ACCOUNTID").
  206. Join("LEFT", "USERINFO", "USERINFO.USERID = TAACCOUNT.RELATEDUSERID").
  207. Where("(TRADE_ORDERDETAIL.LISTINGSELECTTYPE = 1 or TRADE_ORDERDETAIL.LISTINGSELECTTYPE = 3) and (TRADE_ORDERDETAIL.ORDERSTATUS = 3 or TRADE_ORDERDETAIL.ORDERSTATUS = 7)").
  208. And("TRADE_ORDERDETAIL.GOODSID = ?", goodsID).Find(&hsbyGoodsOrderDetails); err != nil {
  209. return nil, nil, err
  210. }
  211. sellOrderDetails := make([]HsbyGoodsOrderDetail, 0)
  212. buyOrderDetails := make([]HsbyGoodsOrderDetail, 0)
  213. if len(hsbyGoodsOrderDetails) == 0 {
  214. // 无数据
  215. return sellOrderDetails, buyOrderDetails, nil
  216. }
  217. // 获取商品货币符号和报价单位
  218. goods, err := GetGoods(goodsID)
  219. if err != nil {
  220. return nil, nil, err
  221. }
  222. currencyEnums, err := GetEnumDicItem("currency", int(goods.Currencyid))
  223. if err != nil {
  224. return nil, nil, err
  225. }
  226. currencysign := ""
  227. if len(currencyEnums) > 0 {
  228. currencysign = currencyEnums[0].Param2
  229. }
  230. goodsUnitEnums, err := GetEnumDicItem("goodsunit", int(goods.Goodunitid))
  231. if err != nil {
  232. return nil, nil, err
  233. }
  234. goodsUnit := ""
  235. if len(goodsUnitEnums) > 0 {
  236. goodsUnit = goodsUnitEnums[0].Enumdicname
  237. }
  238. for i := range hsbyGoodsOrderDetails {
  239. orderDetail := &hsbyGoodsOrderDetails[i]
  240. // 设置货币符号和报价单位
  241. orderDetail.Currencysign = currencysign
  242. orderDetail.Goodunit = goodsUnit
  243. // 分解转让(卖)和求购(买)单
  244. if orderDetail.Buyorsell == 1 {
  245. sellOrderDetails = append(sellOrderDetails, *orderDetail)
  246. }
  247. if orderDetail.Buyorsell == 0 {
  248. buyOrderDetails = append(buyOrderDetails, *orderDetail)
  249. }
  250. }
  251. return sellOrderDetails, buyOrderDetails, nil
  252. }
  253. // HybsMyBuyOrderDetail 我的订单(一二级市场的买方向委托单)
  254. type HybsMyBuyOrderDetail struct {
  255. Orderid int64 `json:"orderid" xorm:"'ORDERID'" binding:"required"` // 委托单号(100+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
  256. Marketid int32 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 市场ID
  257. Goodsid int32 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID
  258. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账户ID[报价币种]
  259. Buyorsell int32 `json:"buyorsell" xorm:"'BUYORSELL'" binding:"required"` // 买卖 - 0:买 1:卖
  260. Orderprice float64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格
  261. Orderqty int64 `json:"orderqty" xorm:"'ORDERQTY'" binding:"required"` // 委托数量
  262. Tradeqty int64 `json:"tradeqty" xorm:"'TRADEQTY'"` // 成交数量
  263. Cancelqty int64 `json:"cancelqty" xorm:"'CANCELQTY'"` // 撤单数量
  264. Ordertime time.Time `json:"ordertime" xorm:"'ORDERTIME'" binding:"required"` // 委托时间
  265. Listingselecttype int32 `json:"listingselecttype" xorm:"'LISTINGSELECTTYPE'"` // 挂牌点选类型 - 1:挂牌 2:摘牌 3:先摘后挂
  266. Orderstatus int32 `json:"orderstatus" xorm:"'ORDERSTATUS'"` // 委托状态 - 1: 委托请求 2:待冻结 3:委托成功 4: 委托失败 5:配对成功 6: 已撤销 7:部分成交 8:已成交 9:部成部撤 10:成交失败 11:已拒绝 12:经过摘牌(先摘后挂专用-先摘后挂已摘过) 13:冻结成功(通道交易专用) 14:通道已撤 15:通道部成部撤 16:成交失败违约(荷兰式竞拍专用)
  267. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  268. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  269. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  270. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  271. Trademode uint32 `json:"trademode" xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
  272. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  273. Vendorname string `json:"vendorname" xorm:"'VENDORNAME'"` // 供应商名称
  274. MyBuyStatus int `json:"mybuystatus" xorm:"-"` // "我的订单"显示状态- 1:抢购中 2:求购中 3:已完成 4:已撤消 5:委托失败
  275. }
  276. // GetHsbyBuyMyOrderDetails 获取“我的订单”数据(包括一二级市场)
  277. // 输入 accountIDs string 资金账户列表
  278. // 输入 myBuyStatus int "我的订单"状态, 1:抢购中 2:求购中 3:已完成
  279. // 输出 []HybsMyBuyOrderDetail “我的订单”数据
  280. // 输出 error error
  281. func GetHsbyBuyMyOrderDetails(accountIDs string, myBuyStatus int) ([]HybsMyBuyOrderDetail, error) {
  282. // 获取市场信息
  283. markets, err := GetMarkets()
  284. if err != nil {
  285. return nil, err
  286. }
  287. engine := db.GetEngine()
  288. // 委托状态
  289. orderStatus := "0" // 单据状态,为0的时候查询全部
  290. marketID := 0 // 我的订单包括一二级市场的单据,目前暂时由服务直接报相关类型的第一个市场
  291. switch myBuyStatus {
  292. case 1: // 抢购中 (一级市场)
  293. // 获取市场ID
  294. for _, v := range markets {
  295. if v.Trademode == 71 { // 预售挂牌
  296. marketID = int(v.Marketid)
  297. break
  298. }
  299. }
  300. orderStatus = "3,7"
  301. case 2: // 求购中(二级市场)
  302. // 获取市场ID
  303. for _, v := range markets {
  304. if v.Trademode == 16 { // 挂牌点选
  305. marketID = int(v.Marketid)
  306. break
  307. }
  308. }
  309. orderStatus = "3,7"
  310. case 3: // 已完成
  311. orderStatus = "8,9"
  312. }
  313. hybsMyBuyOrderDetails := make([]HybsMyBuyOrderDetail, 0)
  314. session := engine.Table("TRADE_ORDERDETAIL").
  315. Select(`TRADE_ORDERDETAIL.*,
  316. GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE,
  317. HSBY_GOODSEX.PICURLS,
  318. MARKET.TRADEMODE,
  319. ENUMDICITEM.PARAM2 CURRENCYSIGN,
  320. HSBY_SUPPLIERINFO.VENDORNAME`).
  321. Join("LEFT", "GOODS", "GOODS.GOODSID = TRADE_ORDERDETAIL.GOODSID").
  322. Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
  323. Join("LEFT", "ENUMDICITEM", "GOODS.CURRENCYID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'currency'").
  324. Join("LEFT", "MARKET", "MARKET.MARKETID = TRADE_ORDERDETAIL.MARKETID").
  325. Join("LEFT", "HSBY_SUPPLIERINFO", "HSBY_SUPPLIERINFO.VENDORID = HSBY_GOODSEX.VENDORID").
  326. Where(fmt.Sprintf("TRADE_ORDERDETAIL.ACCOUNTID in (%s)", accountIDs))
  327. // 是否过滤市场(抢购中、求购中)
  328. if marketID > 0 {
  329. session = session.And("TRADE_ORDERDETAIL.MARKETID = ?", marketID)
  330. }
  331. // 是否过滤状态(抢购中、求购中、已完成)
  332. if orderStatus != "0" {
  333. session = session.And(fmt.Sprintf("TRADE_ORDERDETAIL.ORDERSTATUS in (%s)", orderStatus))
  334. }
  335. if err := session.Find(&hybsMyBuyOrderDetails); err != nil {
  336. return nil, err
  337. }
  338. // 设置“我的订单”显示状态
  339. for i := range hybsMyBuyOrderDetails {
  340. detail := &hybsMyBuyOrderDetails[i]
  341. if detail.Trademode == 71 && (detail.Orderstatus == 3 || detail.Orderstatus == 7) {
  342. // 抢购中
  343. detail.MyBuyStatus = 1
  344. } else if detail.Trademode == 16 && (detail.Orderstatus == 3 || detail.Orderstatus == 7) {
  345. // 求购中
  346. detail.MyBuyStatus = 2
  347. } else if detail.Orderstatus == 8 || detail.Orderstatus == 9 {
  348. // 已完成
  349. detail.MyBuyStatus = 3
  350. } else if detail.Orderstatus == 6 {
  351. // 已撤销
  352. detail.MyBuyStatus = 4
  353. } else if detail.Orderstatus == 4 {
  354. // 委托失败
  355. detail.MyBuyStatus = 5
  356. }
  357. }
  358. return hybsMyBuyOrderDetails, nil
  359. }
  360. // HsbyMyGoods 我的商品(买方向持仓)
  361. type HsbyMyGoods struct {
  362. Accountid int64 `json:"accountid" xorm:"'ACCOUNTID'" binding:"required"` // 账号Id
  363. Goodsid int32 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品Id
  364. Buycurpositionqty int64 `json:"buycurpositionqty" xorm:"'BUYCURPOSITIONQTY'"` // 买当前持仓总数量
  365. Buycurholderamount float64 `json:"buycurholderamount" xorm:"'BUYCURHOLDERAMOUNT'"` // 买当前持仓总金额[商品币种]
  366. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  367. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  368. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  369. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  370. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  371. }
  372. // GetHsbyMyGoods 获取“我的商品”信息
  373. // 输入 accountIDs string 资金账户列表,格式 1,2,3
  374. // 输出 []HsbyMyGoods “我的商品”信息
  375. // 输入 error error
  376. func GetHsbyMyGoods(accountIDs string) ([]HsbyMyGoods, error) {
  377. engine := db.GetEngine()
  378. hsbyMyGoodses := make([]HsbyMyGoods, 0)
  379. if err := engine.Table("TRADEPOSITION").
  380. Select(`TRADEPOSITION.*,
  381. GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE,
  382. HSBY_GOODSEX.PICURLS,
  383. ENUMDICITEM.PARAM2 CURRENCYSIGN`).
  384. Join("LEFT", "GOODS", "GOODS.GOODSID = TRADEPOSITION.GOODSID").
  385. Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
  386. Join("LEFT", "ENUMDICITEM", "GOODS.CURRENCYID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'currency'").
  387. Where(fmt.Sprintf("TRADEPOSITION.ACCOUNTID in (%s)", accountIDs)).Find(&hsbyMyGoodses); err != nil {
  388. return nil, err
  389. }
  390. return hsbyMyGoodses, nil
  391. }