hsby.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. package models
  2. import (
  3. "mtp2_if/db"
  4. "mtp2_if/utils"
  5. "time"
  6. )
  7. // Hsbygoodsex 商品扩展表
  8. type Hsbygoodsex struct {
  9. Goodsid int32 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商 品ID
  10. Hotindex int32 `json:"hotindex" xorm:"'HOTINDEX'"` // 景点热度
  11. Descprovinceid int64 `json:"descprovinceid" xorm:"'DESCPROVINCEID'"` // 目的地(省)
  12. Desccityid int64 `json:"desccityid" xorm:"'DESCCITYID'"` // 目的地(市)
  13. Vendorid int32 `json:"vendorid" xorm:"'VENDORID'"` // 供应商ID
  14. Goodsdesc string `json:"goodsdesc" xorm:"'GOODSDESC'"` // 商品详情
  15. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  16. Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
  17. Modifierid int64 `json:"modifierid" xorm:"'MODIFIERID'"` // 修改人
  18. Modifytime time.Time `json:"modifytime" xorm:"'MODIFYTIME'"` // 修改时间
  19. Memberratio float64 `json:"memberratio" xorm:"'MEMBERRATIO'"` // 会员货款比例 [71]
  20. Videourls string `json:"videourls" xorm:"'VIDEOURLS'"` // 介绍视频[多张用逗号分隔]
  21. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  22. }
  23. // Hsbysupplierinfo 供应商表
  24. type Hsbysupplierinfo struct {
  25. Vendorid int32 `json:"vendorid" xorm:"'VENDORID'" binding:"required"` // 供应商ID(SEQ_HSBY_SUPPLIERINFO)
  26. Vendorname string `json:"vendorname" xorm:"'VENDORNAME'"` // 名称描述客服电话名称
  27. Vendordesc string `json:"vendordesc" xorm:"'VENDORDESC'"` // 描述
  28. Vendorphone string `json:"vendorphone" xorm:"'VENDORPHONE'"` // 客服电话
  29. Vendorattr string `json:"vendorattr" xorm:"'VENDORATTR'"` // 附件(多张,逗号分隔)
  30. Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间
  31. Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人
  32. Modifierid int64 `json:"modifierid" xorm:"'MODIFIERID'"` // 修改人
  33. Modifytime time.Time `json:"modifytime" xorm:"'MODIFYTIME'"` // 修改时间
  34. }
  35. // TableName is HSBY_SUPPLIERINFO
  36. func (Hsbysupplierinfo) TableName() string {
  37. return "HSBY_SUPPLIERINFO"
  38. }
  39. // TableName is HSBY_GOODSEX
  40. func (Hsbygoodsex) TableName() string {
  41. return "HSBY_GOODSEX"
  42. }
  43. // HsbyTopGoods 热门商品列表
  44. type HsbyTopGoods struct {
  45. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID(自增ID SEQ_GOODS)
  46. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  47. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  48. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  49. Marketid int64 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 所属市场ID
  50. Hotindex int32 `json:"hotindex" xorm:"'HOTINDEX'"` // 景点热度
  51. Videourls string `json:"videourls" xorm:"'VIDEOURLS'"` // 介绍视频[多张用逗号分隔]
  52. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  53. Currency string `json:"currency" xorm:"'CURRENCY'"` // 货币
  54. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  55. Last float64 `json:"last" xorm:"-"` // 现价
  56. }
  57. // GetHsbyTopGoods 获取热门商品列表
  58. // 参数 marketID int 所属市场ID
  59. // 参数 descProvinceID int 目标省ID
  60. // 参数 descCityID int 目标城市ID
  61. // 返回 []TopGoods 热门商品列表
  62. // 返回 error error
  63. func GetHsbyTopGoods(marketID int, descProvinceID int, descCityID int) ([]HsbyTopGoods, error) {
  64. // 热门商品为二级市场(挂牌点选)下的商品信息
  65. engine := db.GetEngine()
  66. topGoodses := make([]HsbyTopGoods, 0)
  67. // 获取挂牌商品信息,以及扩展表信息
  68. session := engine.Table("GOODS").
  69. Select(`GOODS.*,
  70. HSBY_GOODSEX.HOTINDEX, HSBY_GOODSEX.VIDEOURLS, HSBY_GOODSEX.PICURLS,
  71. ENUMDICITEM.ENUMDICNAME CURRENCY, ENUMDICITEM.PARAM2 CURRENCYSIGN`).
  72. Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
  73. Join("LEFT", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMNAME = GOODS.CURRENCYID and ENUMDICITEM.ENUMDICCODE = 'currency'").
  74. Where("GOODS.MARKETID = ?", marketID)
  75. if descProvinceID > 0 {
  76. session = session.And("HSBY_GOODSEX.DESCPROVINCEID = ?", descProvinceID)
  77. }
  78. if descCityID > 0 {
  79. session = session.And("HSBY_GOODSEX.DESCCITYID = ?", descCityID)
  80. }
  81. if err := session.Find(&topGoodses); err != nil {
  82. return nil, err
  83. }
  84. if len(topGoodses) == 0 {
  85. // 无数据
  86. return topGoodses, nil
  87. }
  88. // 获取商品ID列表
  89. goodsCodes := ""
  90. for _, v := range topGoodses {
  91. if len(goodsCodes) == 0 {
  92. goodsCodes = v.Goodscode
  93. } else {
  94. goodsCodes += "," + v.Goodscode
  95. }
  96. }
  97. // 获取商品现价
  98. quoteDays, err := GetQuoteDays(goodsCodes)
  99. if err != nil {
  100. return nil, err
  101. }
  102. for i, g := range topGoodses {
  103. for _, q := range quoteDays {
  104. if g.Goodscode == q.Goodscode {
  105. if q.Last != 0 {
  106. topGoods := &topGoodses[i]
  107. topGoods.Last = utils.IntToFloat64(int(q.Last), int(g.Decimalplace))
  108. }
  109. continue
  110. }
  111. }
  112. }
  113. return topGoodses, nil
  114. }
  115. // HsbyListingGoodsDetail 二级市场(挂牌点选)商品信息详情
  116. type HsbyListingGoodsDetail struct {
  117. Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID(自增ID SEQ_GOODS)
  118. Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
  119. Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称
  120. Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位
  121. Marketid int64 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 所属市场ID
  122. Hotindex int32 `json:"hotindex" xorm:"'HOTINDEX'"` // 景点热度
  123. Videourls string `json:"videourls" xorm:"'VIDEOURLS'"` // 介绍视频[多张用逗号分隔]
  124. Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
  125. Descprovinceid int64 `json:"descprovinceid" xorm:"'DESCPROVINCEID'"` // 目的地(省)ID
  126. Desccityid int64 `json:"desccityid" xorm:"'DESCCITYID'"` // 目的地(市)ID
  127. Goodsdesc string `json:"goodsdesc" xorm:"'GOODSDESC'"` // 商品详情
  128. Currency string `json:"currency" xorm:"'CURRENCY'"` // 货币
  129. Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
  130. Vendorname string `json:"vendorname" xorm:"'VENDORNAME'"` // 供应商名称
  131. Vendorphone string `json:"vendorphone" xorm:"'VENDORPHONE'"` // 客服电话
  132. Vendorattr string `json:"vendorattr" xorm:"'VENDORATTR'"` // 附件(多张,逗号分隔)
  133. Last float64 `json:"last" xorm:"-"` // 现价
  134. }
  135. // GetHsbyListingGoodsDetail 获取二级市场(挂牌点选)商品信息详情
  136. // 参数 goodsID int 目标商品ID
  137. // 返回 *HsbyListingGoodsDetail 二级市场(挂牌点选)商品信息详情,查询无结果返回nil
  138. // 返回 error error
  139. func GetHsbyListingGoodsDetail(goodsID int) (*HsbyListingGoodsDetail, error) {
  140. engine := db.GetEngine()
  141. details := make([]HsbyListingGoodsDetail, 0)
  142. // 获取挂牌商品信息,以及扩展表信息
  143. // FIXME: - 这里使用Get方法,会造成SQL语句的嵌套出错,后期再研究
  144. session := engine.Table("GOODS").
  145. Select(`GOODS.GOODSID, GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.MARKETID,
  146. HSBY_GOODSEX.HOTINDEX, HSBY_GOODSEX.VIDEOURLS, HSBY_GOODSEX.PICURLS, HSBY_GOODSEX.DESCPROVINCEID, HSBY_GOODSEX.Desccityid, HSBY_GOODSEX.Goodsdesc,
  147. ENUMDICITEM.ENUMDICNAME CURRENCY, ENUMDICITEM.PARAM2 CURRENCYSIGN,
  148. HSBY_SUPPLIERINFO.VENDORNAME, HSBY_SUPPLIERINFO.VENDORPHONE, HSBY_SUPPLIERINFO.VENDORATTR`).
  149. Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
  150. Join("LEFT", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMNAME = GOODS.CURRENCYID and ENUMDICITEM.ENUMDICCODE = 'currency'").
  151. Join("LEFT", "HSBY_SUPPLIERINFO", "HSBY_SUPPLIERINFO.VENDORID = HSBY_GOODSEX.VENDORID").
  152. Where("GOODS.GOODSID = ?", goodsID)
  153. if err := session.Find(&details); err != nil {
  154. return nil, err
  155. }
  156. // 无目标商品
  157. if len(details) == 0 {
  158. return nil, nil
  159. }
  160. hsbyListingGoodsDetail := details[0]
  161. // 获取商品现价
  162. quoteDays, err := GetQuoteDays(hsbyListingGoodsDetail.Goodscode)
  163. if err != nil {
  164. return nil, err
  165. }
  166. if len(quoteDays) > 0 {
  167. if quoteDays[0].Last != 0 {
  168. hsbyListingGoodsDetail.Last = utils.IntToFloat64(int(quoteDays[0].Last), int(hsbyListingGoodsDetail.Decimalplace))
  169. }
  170. }
  171. return &hsbyListingGoodsDetail, nil
  172. }
  173. // HsbyGoodsOrderDetail 二级市场挂牌商品当前可摘委托单信息
  174. type HsbyGoodsOrderDetail struct {
  175. Orderid int64 `json:"orderid" xorm:"'ORDERID'" binding:"required"` // 委托单号(100+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
  176. Buyorsell int32 `json:"buyorsell" xorm:"'BUYORSELL'" binding:"required"` // 买卖 - 0:买 1:卖
  177. Ordertime time.Time `json:"ordertime" xorm:"'ORDERTIME'" binding:"required"` // 委托时间
  178. Orderprice float64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格
  179. Enableqty int64 `json:"enableqty" xorm:"ENABLEQTY"` // 可用数量
  180. Customername string `json:"customername" xorm:"'CUSTOMERNAME'"` // 客户名称(企业名称),已脱敏
  181. Currencysign string `json:"currencysign" xorm:"-"` // 货币符号
  182. Goodunit string `json:"goodunit" xorm:"-"` // 报价单位
  183. }
  184. // GetHsbyGoodsOrderDetails 获取二级市场(挂牌点选)商品对应的挂牌委托单信息
  185. // 参数 goodsID int 商品ID
  186. // 返回 []HsbyGoodsOrderDetail 转让(卖出)挂牌委托单
  187. // 返回 []HsbyGoodsOrderDetail 求购(买入)挂牌委托单
  188. // 返回 error error
  189. func GetHsbyGoodsOrderDetails(goodsID int) ([]HsbyGoodsOrderDetail, []HsbyGoodsOrderDetail, error) {
  190. engine := db.GetEngine()
  191. // 获取与目标商品相关的挂牌委托单信息(ListingSelectType = 1 or 3; OrderStatus =3 or 7)
  192. hsbyGoodsOrderDetails := make([]HsbyGoodsOrderDetail, 0)
  193. if err := engine.Table("TRADE_ORDERDETAIL").
  194. Select(`TRADE_ORDERDETAIL.ORDERID, TRADE_ORDERDETAIL.BUYORSELL, TRADE_ORDERDETAIL.ORDERTIME, TRADE_ORDERDETAIL.ORDERPRICE, (TRADE_ORDERDETAIL.ORDERQTY - TRADE_ORDERDETAIL.TRADEQTY - TRADE_ORDERDETAIL.CANCELQTY) ENABLEQTY,
  195. substr(USERINFO.CUSTOMERNAME,0,1)||'****' as CUSTOMERNAME`).
  196. Join("LEFT", "TAACCOUNT", "TAACCOUNT.ACCOUNTID = TRADE_ORDERDETAIL.ACCOUNTID").
  197. Join("LEFT", "USERINFO", "USERINFO.USERID = TAACCOUNT.RELATEDUSERID").
  198. Where("(TRADE_ORDERDETAIL.LISTINGSELECTTYPE = 1 or TRADE_ORDERDETAIL.LISTINGSELECTTYPE = 3) and (TRADE_ORDERDETAIL.ORDERSTATUS = 3 or TRADE_ORDERDETAIL.ORDERSTATUS = 7)").
  199. And("TRADE_ORDERDETAIL.GOODSID = ?", goodsID).Find(&hsbyGoodsOrderDetails); err != nil {
  200. return nil, nil, err
  201. }
  202. sellOrderDetails := make([]HsbyGoodsOrderDetail, 0)
  203. buyOrderDetails := make([]HsbyGoodsOrderDetail, 0)
  204. if len(hsbyGoodsOrderDetails) == 0 {
  205. // 无数据
  206. return sellOrderDetails, buyOrderDetails, nil
  207. }
  208. // 获取商品货币符号和报价单位
  209. goods, err := GetGoods(goodsID)
  210. if err != nil {
  211. return nil, nil, err
  212. }
  213. currencyEnums, err := GetEnumDicItem("currency", int(goods.Currencyid))
  214. if err != nil {
  215. return nil, nil, err
  216. }
  217. currencysign := ""
  218. if len(currencyEnums) > 0 {
  219. currencysign = currencyEnums[0].Param2
  220. }
  221. goodsUnitEnums, err := GetEnumDicItem("goodsunit", int(goods.Goodunitid))
  222. if err != nil {
  223. return nil, nil, err
  224. }
  225. goodsUnit := ""
  226. if len(goodsUnitEnums) > 0 {
  227. goodsUnit = goodsUnitEnums[0].Enumdicname
  228. }
  229. for i := range hsbyGoodsOrderDetails {
  230. orderDetail := &hsbyGoodsOrderDetails[i]
  231. // 设置货币符号和报价单位
  232. orderDetail.Currencysign = currencysign
  233. orderDetail.Goodunit = goodsUnit
  234. // 分解转让(卖)和求购(买)单
  235. if orderDetail.Buyorsell == 1 {
  236. sellOrderDetails = append(sellOrderDetails, *orderDetail)
  237. }
  238. if orderDetail.Buyorsell == 0 {
  239. buyOrderDetails = append(buyOrderDetails, *orderDetail)
  240. }
  241. }
  242. return sellOrderDetails, buyOrderDetails, nil
  243. }