package models import ( "mtp2_if/db" "mtp2_if/utils" "time" ) // Hsbygoodsex 商品扩展表 type Hsbygoodsex struct { Goodsid int32 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商 品ID Hotindex int32 `json:"hotindex" xorm:"'HOTINDEX'"` // 景点热度 Descprovinceid int64 `json:"descprovinceid" xorm:"'DESCPROVINCEID'"` // 目的地(省) Desccityid int64 `json:"desccityid" xorm:"'DESCCITYID'"` // 目的地(市) Vendorid int32 `json:"vendorid" xorm:"'VENDORID'"` // 供应商ID Goodsdesc string `json:"goodsdesc" xorm:"'GOODSDESC'"` // 商品详情 Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间 Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人 Modifierid int64 `json:"modifierid" xorm:"'MODIFIERID'"` // 修改人 Modifytime time.Time `json:"modifytime" xorm:"'MODIFYTIME'"` // 修改时间 Memberratio float64 `json:"memberratio" xorm:"'MEMBERRATIO'"` // 会员货款比例 [71] Videourls string `json:"videourls" xorm:"'VIDEOURLS'"` // 介绍视频[多张用逗号分隔] Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔] } // Hsbysupplierinfo 供应商表 type Hsbysupplierinfo struct { Vendorid int32 `json:"vendorid" xorm:"'VENDORID'" binding:"required"` // 供应商ID(SEQ_HSBY_SUPPLIERINFO) Vendorname string `json:"vendorname" xorm:"'VENDORNAME'"` // 名称描述客服电话名称 Vendordesc string `json:"vendordesc" xorm:"'VENDORDESC'"` // 描述 Vendorphone string `json:"vendorphone" xorm:"'VENDORPHONE'"` // 客服电话 Vendorattr string `json:"vendorattr" xorm:"'VENDORATTR'"` // 附件(多张,逗号分隔) Createtime time.Time `json:"createtime" xorm:"'CREATETIME'"` // 创建时间 Creatorid int64 `json:"creatorid" xorm:"'CREATORID'"` // 创建人 Modifierid int64 `json:"modifierid" xorm:"'MODIFIERID'"` // 修改人 Modifytime time.Time `json:"modifytime" xorm:"'MODIFYTIME'"` // 修改时间 } // TableName is HSBY_SUPPLIERINFO func (Hsbysupplierinfo) TableName() string { return "HSBY_SUPPLIERINFO" } // TableName is HSBY_GOODSEX func (Hsbygoodsex) TableName() string { return "HSBY_GOODSEX" } // HsbyTopGoods 热门商品列表 type HsbyTopGoods struct { Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID(自增ID SEQ_GOODS) Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部) Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称 Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位 Marketid int64 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 所属市场ID Hotindex int32 `json:"hotindex" xorm:"'HOTINDEX'"` // 景点热度 Videourls string `json:"videourls" xorm:"'VIDEOURLS'"` // 介绍视频[多张用逗号分隔] Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔] Currency string `json:"currency" xorm:"'CURRENCY'"` // 货币 Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号 Last float64 `json:"last" xorm:"-"` // 现价 } // GetHsbyTopGoods 获取热门商品列表 // 参数 marketID int 所属市场ID // 参数 descProvinceID int 目标省ID // 参数 descCityID int 目标城市ID // 返回 []TopGoods 热门商品列表 // 返回 error error func GetHsbyTopGoods(marketID int, descProvinceID int, descCityID int) ([]HsbyTopGoods, error) { // 热门商品为二级市场(挂牌点选)下的商品信息 engine := db.GetEngine() topGoodses := make([]HsbyTopGoods, 0) // 获取挂牌商品信息,以及扩展表信息 session := engine.Table("GOODS"). Select(`GOODS.*, HSBY_GOODSEX.HOTINDEX, HSBY_GOODSEX.VIDEOURLS, HSBY_GOODSEX.PICURLS, ENUMDICITEM.ENUMDICNAME CURRENCY, ENUMDICITEM.PARAM2 CURRENCYSIGN`). Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID"). Join("LEFT", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMNAME = GOODS.CURRENCYID and ENUMDICITEM.ENUMDICCODE = 'currency'"). Where("GOODS.MARKETID = ?", marketID) if descProvinceID > 0 { session = session.And("HSBY_GOODSEX.DESCPROVINCEID = ?", descProvinceID) } if descCityID > 0 { session = session.And("HSBY_GOODSEX.DESCCITYID = ?", descCityID) } if err := session.Find(&topGoodses); err != nil { return nil, err } if len(topGoodses) == 0 { // 无数据 return topGoodses, nil } // 获取商品ID列表 goodsCodes := "" for _, v := range topGoodses { if len(goodsCodes) == 0 { goodsCodes = v.Goodscode } else { goodsCodes += "," + v.Goodscode } } // 获取商品现价 quoteDays, err := GetQuoteDays(goodsCodes) if err != nil { return nil, err } for i, g := range topGoodses { for _, q := range quoteDays { if g.Goodscode == q.Goodscode { if q.Last != 0 { topGoods := &topGoodses[i] topGoods.Last = utils.IntToFloat64(int(q.Last), int(g.Decimalplace)) } continue } } } return topGoodses, nil } // HsbyListingGoodsDetail 二级市场(挂牌点选)商品信息详情 type HsbyListingGoodsDetail struct { Goodsid int64 `json:"goodsid" xorm:"'GOODSID'" binding:"required"` // 商品ID(自增ID SEQ_GOODS) Goodscode string `json:"goodscode" xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部) Goodsname string `json:"goodsname" xorm:"'GOODSNAME'" binding:"required"` // 商品名称 Decimalplace int64 `json:"decimalplace" xorm:"'DECIMALPLACE'"` // 报价小数位 Marketid int64 `json:"marketid" xorm:"'MARKETID'" binding:"required"` // 所属市场ID Hotindex int32 `json:"hotindex" xorm:"'HOTINDEX'"` // 景点热度 Videourls string `json:"videourls" xorm:"'VIDEOURLS'"` // 介绍视频[多张用逗号分隔] Picurls string `json:"picurls" xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔] Descprovinceid int64 `json:"descprovinceid" xorm:"'DESCPROVINCEID'"` // 目的地(省)ID Desccityid int64 `json:"desccityid" xorm:"'DESCCITYID'"` // 目的地(市)ID Goodsdesc string `json:"goodsdesc" xorm:"'GOODSDESC'"` // 商品详情 Currency string `json:"currency" xorm:"'CURRENCY'"` // 货币 Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号 Vendorname string `json:"vendorname" xorm:"'VENDORNAME'"` // 供应商名称 Vendorphone string `json:"vendorphone" xorm:"'VENDORPHONE'"` // 客服电话 Vendorattr string `json:"vendorattr" xorm:"'VENDORATTR'"` // 附件(多张,逗号分隔) Last float64 `json:"last" xorm:"-"` // 现价 } // GetHsbyListingGoodsDetail 获取二级市场(挂牌点选)商品信息详情 // 参数 goodsID int 目标商品ID // 返回 *HsbyListingGoodsDetail 二级市场(挂牌点选)商品信息详情,查询无结果返回nil // 返回 error error func GetHsbyListingGoodsDetail(goodsID int) (*HsbyListingGoodsDetail, error) { engine := db.GetEngine() details := make([]HsbyListingGoodsDetail, 0) // 获取挂牌商品信息,以及扩展表信息 // FIXME: - 这里使用Get方法,会造成SQL语句的嵌套出错,后期再研究 session := engine.Table("GOODS"). Select(`GOODS.GOODSID, GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.MARKETID, HSBY_GOODSEX.HOTINDEX, HSBY_GOODSEX.VIDEOURLS, HSBY_GOODSEX.PICURLS, HSBY_GOODSEX.DESCPROVINCEID, HSBY_GOODSEX.Desccityid, HSBY_GOODSEX.Goodsdesc, ENUMDICITEM.ENUMDICNAME CURRENCY, ENUMDICITEM.PARAM2 CURRENCYSIGN, HSBY_SUPPLIERINFO.VENDORNAME, HSBY_SUPPLIERINFO.VENDORPHONE, HSBY_SUPPLIERINFO.VENDORATTR`). Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID"). Join("LEFT", "ENUMDICITEM", "ENUMDICITEM.ENUMITEMNAME = GOODS.CURRENCYID and ENUMDICITEM.ENUMDICCODE = 'currency'"). Join("LEFT", "HSBY_SUPPLIERINFO", "HSBY_SUPPLIERINFO.VENDORID = HSBY_GOODSEX.VENDORID"). Where("GOODS.GOODSID = ?", goodsID) if err := session.Find(&details); err != nil { return nil, err } // 无目标商品 if len(details) == 0 { return nil, nil } hsbyListingGoodsDetail := details[0] // 获取商品现价 quoteDays, err := GetQuoteDays(hsbyListingGoodsDetail.Goodscode) if err != nil { return nil, err } if len(quoteDays) > 0 { if quoteDays[0].Last != 0 { hsbyListingGoodsDetail.Last = utils.IntToFloat64(int(quoteDays[0].Last), int(hsbyListingGoodsDetail.Decimalplace)) } } return &hsbyListingGoodsDetail, nil } // HsbyGoodsOrderDetail 二级市场挂牌商品当前可摘委托单信息 type HsbyGoodsOrderDetail struct { Orderid int64 `json:"orderid" xorm:"'ORDERID'" binding:"required"` // 委托单号(100+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx) Buyorsell int32 `json:"buyorsell" xorm:"'BUYORSELL'" binding:"required"` // 买卖 - 0:买 1:卖 Ordertime time.Time `json:"ordertime" xorm:"'ORDERTIME'" binding:"required"` // 委托时间 Orderprice float64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格 Enableqty int64 `json:"enableqty" xorm:"ENABLEQTY"` // 可用数量 Customername string `json:"customername" xorm:"'CUSTOMERNAME'"` // 客户名称(企业名称),已脱敏 Currencysign string `json:"currencysign" xorm:"-"` // 货币符号 Goodunit string `json:"goodunit" xorm:"-"` // 报价单位 } // GetHsbyGoodsOrderDetails 获取二级市场(挂牌点选)商品对应的挂牌委托单信息 // 参数 goodsID int 商品ID // 返回 []HsbyGoodsOrderDetail 转让(卖出)挂牌委托单 // 返回 []HsbyGoodsOrderDetail 求购(买入)挂牌委托单 // 返回 error error func GetHsbyGoodsOrderDetails(goodsID int) ([]HsbyGoodsOrderDetail, []HsbyGoodsOrderDetail, error) { engine := db.GetEngine() // 获取与目标商品相关的挂牌委托单信息(ListingSelectType = 1 or 3; OrderStatus =3 or 7) hsbyGoodsOrderDetails := make([]HsbyGoodsOrderDetail, 0) if err := engine.Table("TRADE_ORDERDETAIL"). Select(`TRADE_ORDERDETAIL.ORDERID, TRADE_ORDERDETAIL.BUYORSELL, TRADE_ORDERDETAIL.ORDERTIME, TRADE_ORDERDETAIL.ORDERPRICE, (TRADE_ORDERDETAIL.ORDERQTY - TRADE_ORDERDETAIL.TRADEQTY - TRADE_ORDERDETAIL.CANCELQTY) ENABLEQTY, substr(USERINFO.CUSTOMERNAME,0,1)||'****' as CUSTOMERNAME`). Join("LEFT", "TAACCOUNT", "TAACCOUNT.ACCOUNTID = TRADE_ORDERDETAIL.ACCOUNTID"). Join("LEFT", "USERINFO", "USERINFO.USERID = TAACCOUNT.RELATEDUSERID"). Where("(TRADE_ORDERDETAIL.LISTINGSELECTTYPE = 1 or TRADE_ORDERDETAIL.LISTINGSELECTTYPE = 3) and (TRADE_ORDERDETAIL.ORDERSTATUS = 3 or TRADE_ORDERDETAIL.ORDERSTATUS = 7)"). And("TRADE_ORDERDETAIL.GOODSID = ?", goodsID).Find(&hsbyGoodsOrderDetails); err != nil { return nil, nil, err } sellOrderDetails := make([]HsbyGoodsOrderDetail, 0) buyOrderDetails := make([]HsbyGoodsOrderDetail, 0) if len(hsbyGoodsOrderDetails) == 0 { // 无数据 return sellOrderDetails, buyOrderDetails, nil } // 获取商品货币符号和报价单位 goods, err := GetGoods(goodsID) if err != nil { return nil, nil, err } currencyEnums, err := GetEnumDicItem("currency", int(goods.Currencyid)) if err != nil { return nil, nil, err } currencysign := "" if len(currencyEnums) > 0 { currencysign = currencyEnums[0].Param2 } goodsUnitEnums, err := GetEnumDicItem("goodsunit", int(goods.Goodunitid)) if err != nil { return nil, nil, err } goodsUnit := "" if len(goodsUnitEnums) > 0 { goodsUnit = goodsUnitEnums[0].Enumdicname } for i := range hsbyGoodsOrderDetails { orderDetail := &hsbyGoodsOrderDetails[i] // 设置货币符号和报价单位 orderDetail.Currencysign = currencysign orderDetail.Goodunit = goodsUnit // 分解转让(卖)和求购(买)单 if orderDetail.Buyorsell == 1 { sellOrderDetails = append(sellOrderDetails, *orderDetail) } if orderDetail.Buyorsell == 0 { buyOrderDetails = append(buyOrderDetails, *orderDetail) } } return sellOrderDetails, buyOrderDetails, nil }