| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599 |
- package models
- import (
- "errors"
- "fmt"
- "mtp2_if/db"
- "mtp2_if/logger"
- "mtp2_if/utils"
- "strconv"
- "strings"
- "sync"
- "time"
- )
- // 上海铁合金项目
- // GErmcpspotgoodsprice 现货市价表
- type GErmcpspotgoodsprice struct {
- DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
- WRSTANDARDID int64 `json:"wrstandardid" xorm:"WRSTANDARDID"` // 现货商品ID(通用则为0)
- SPOTGOODSBRANDID int32 `json:"spotgoodsbrandid" xorm:"SPOTGOODSBRANDID"` // 现货品牌ID(通用则为0, 不为0则须先有商品ID)
- CURRENCYID int64 `json:"currencyid" xorm:"CURRENCYID"` // 报价货币ID
- SPOTGOODSPRICE float64 `json:"spotgoodsprice" xorm:"SPOTGOODSPRICE"` // 【最新价】当前价格
- TRADEDATE string `json:"tradedate" xorm:"TRADEDATE"` // 【日期】交易日
- OPERATESRC int32 `json:"-" xorm:"OPERATESRC"` // 最后操作来源 - 1:管理端 2:终端
- OPERATEID int64 `json:"-" xorm:"OPERATEID"` // 最后操作人
- OPERATETIME time.Time `json:"-" xorm:"OPERATETIME"` // 最后操作时间
- ISVALID int32 `json:"-" xorm:"ISVALID"` // 是否有效 - 0:无效 1:有效
- YSTSPOTGOODSPRICE float64 `json:"ystspotgoodsprice" xorm:"YSTSPOTGOODSPRICE"` // 昨价
- TODAYSPOTGOODSPRICE float64 `json:"todayspotgoodsprice" xorm:"TODAYSPOTGOODSPRICE"` // 今日指定价
- TODAYPRICEDTOTALQTY float64 `json:"todaypricedtotalqty" xorm:"TODAYPRICEDTOTALQTY"` // 今日定价总量
- TODAYPRICEDTOTALAMOUNT float64 `json:"todaypricedtotalamount" xorm:"TODAYPRICEDTOTALAMOUNT"` // 今日定价金额
- SRCMARKETNAME string `json:"srcmarketname" xorm:"SRCMARKETNAME"` // 来源市场名称
- WRSTANDARDCODE string `json:"wrstandardcode" xorm:"WRSTANDARDCODE"` // 现货商品代码
- WRSTANDARDNAME string `json:"wrstandardname" xorm:"WRSTANDARDNAME"` // 【名称】现货商品名称
- PageEx `xorm:"extends"` // 页码信息
- }
- func (r *GErmcpspotgoodsprice) calc() {
- if len(r.TRADEDATE) == 8 {
- r.TRADEDATE = fmt.Sprintf("%v-%v-%v", r.TRADEDATE[0:4], r.TRADEDATE[4:6], r.TRADEDATE[6:8])
- }
- }
- func (r *GErmcpspotgoodsprice) buildSql() string {
- var sqlId utils.SQLVal = `
- SELECT
- t.DELIVERYGOODSID ,
- t.WRSTANDARDID ,
- t.SPOTGOODSBRANDID ,
- t.CURRENCYID ,
- t.SPOTGOODSPRICE ,
- t.TRADEDATE ,
- t.YSTSPOTGOODSPRICE ,
- t.TODAYSPOTGOODSPRICE ,
- t.TODAYPRICEDTOTALQTY ,
- t.TODAYPRICEDTOTALAMOUNT,
- t.SRCMARKETNAME,
- w.WRSTANDARDCODE,
- w.WRSTANDARDNAME
- FROM ERMCP_SPOTGOODSPRICE t
- LEFT JOIN WRStandard w ON t.WRSTANDARDID = w.WRSTANDARDID
- WHERE t.SPOTGOODSBRANDID = 0 AND t.CURRENCYID = 1 AND t.ISVALID = 1
- `
- sqlId.OrderByDesc("w.WRSTANDARDNAME")
- sqlId.Page(r.Page, r.PageSize)
- return sqlId.String()
- }
- func (r *GErmcpspotgoodsprice) GetDataByPage() (interface{}, error, int, int, int) {
- sData := make([]GErmcpspotgoodsprice, 0)
- err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
- total := 0
- for i := range sData {
- sData[i].calc()
- total = sData[i].Total
- }
- return sData, err, r.Page, r.PageSize, total
- }
- type THJSigninReq struct {
- USERID int64 `form:"userid" binding:"required"` // 用户ID
- }
- type THJSigninRsp struct {
- SigninStatus int `json:"signinstatus"` // 状态操作标志 1-签到成功 2-当日已签到,不能重复签到
- }
- // Signin 用户签到
- func (r *THJSigninReq) Signin() (rsp *THJSigninRsp, err error) {
- // 资源锁
- var lock sync.Mutex
- lock.Lock()
- defer lock.Unlock()
- engine := db.GetEngine()
- // 获取目标用户信息
- if u, err := GetUserInfo(int(r.USERID)); err != nil || u == nil {
- logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
- err = errors.New("错误的用户ID")
- return nil, err
- }
- // 判断目标用户当日是否已经签到
- p := new(Thjsignin)
- if has, err := engine.Where("userid = ?", r.USERID).And("tradedate = to_char(sysdate, 'yyyymmdd')").Get(p); err != nil {
- logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
- err = errors.New("数据错误")
- return nil, err
- } else {
- if has {
- return &THJSigninRsp{SigninStatus: 2}, nil
- }
- }
- // 获取签到积配置
- c := Thjscoreconfig{
- SCORECONFIGTYPE: 2,
- }
- if has, err := engine.Get(&c); err != nil || !has {
- logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
- err = errors.New("数据错误")
- return nil, err
- }
- // 事务
- session := engine.NewSession()
- defer session.Close()
- // add Begin() before any action
- if err := session.Begin(); err != nil {
- logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
- return nil, errors.New("数据错误")
- }
- now := time.Now()
- // 签到积分配置大于0才记积分和流水
- if c.PARMA1 > 0 {
- // 判断用户积分表是否已经存在此用户
- curscore := 0
- t := Thjuserscore{USERID: r.USERID}
- has, err := session.Get(&t)
- if err != nil {
- session.Rollback()
- logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
- return nil, errors.New("数据错误")
- }
- if has {
- // 更新积分
- curscore = int(t.CURSCORE)
- t.CURSCORE += int64(c.PARMA1)
- t.UPDATETIME = now
- // _, err = session.Update(&t)
- sql := fmt.Sprintf(`UPDATE THJ_USERSCORE
- SET CURSCORE = %v, UPDATETIME = to_date('%v', 'yyyy-mm-dd hh24:mi:ss')
- WHERE USERID = %v`,
- t.CURSCORE, t.UPDATETIME.Format("2006-01-02 15:04:05"), t.USERID)
- _, err = session.Exec(sql)
- if err != nil {
- session.Rollback()
- logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
- return nil, errors.New("数据错误")
- }
- } else {
- // 新增用户积分记录
- t.CURSCORE = int64(c.PARMA1)
- t.UPDATETIME = now
- // _, err = session.Insert(&t)
- sql := fmt.Sprintf(`INSERT INTO THJ_USERSCORE VALUES (%v, %v, %v, to_date('%v', 'yyyy-mm-dd hh24:mi:ss'))`,
- t.USERID, t.CURSCORE, 0, t.UPDATETIME.Format("2006-01-02 15:04:05"))
- _, err = session.Exec(sql)
- if err != nil {
- session.Rollback()
- logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
- return nil, errors.New("数据错误")
- }
- }
- // 记录积分流水
- q := Thjuserscorelog{}
- seqMap, err := session.QueryString("SELECT SEQ_THJ_USERSCORELOG.nextval SEQID FROM dual")
- if err != nil {
- session.Rollback()
- logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
- return nil, errors.New("数据错误")
- }
- if len(seqMap) <= 0 {
- session.Rollback()
- return nil, errors.New("获取自增ID错误")
- }
- seqID, _ := strconv.Atoi(seqMap[0]["SEQID"])
- q.AUTOID = int64(seqID)
- q.USERID = r.USERID
- q.SCORECONFIGTYPE = 2 // 2:签到送积分
- q.SCORE = float64(c.PARMA1)
- q.ORISCORE = float64(curscore)
- q.CURSCORE = float64(t.CURSCORE)
- q.CREATETIME = now
- q.RELATEDORDERID = r.USERID
- // _, err = session.Insert(&q)
- sql := fmt.Sprintf(`INSERT INTO THJ_USERSCORELOG
- (AUTOID, USERID, SCORECONFIGTYPE, SCORE, ORISCORE, CURSCORE, CREATETIME)
- VALUES
- (%v, %v, %v, %v, %v, %v, to_date('%v', 'yyyy-mm-dd hh24:mi:ss'))`,
- q.AUTOID, q.USERID, q.SCORECONFIGTYPE, q.SCORE, q.ORISCORE, q.CURSCORE, q.CREATETIME.Format("2006-01-02 15:04:05"))
- _, err = session.Exec(sql)
- if err != nil {
- session.Rollback()
- logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
- return nil, errors.New("数据错误")
- }
- }
- // 增加签到记录
- sql := fmt.Sprintf(`INSERT INTO THJ_SIGNIN VALUES (%v, %v, to_date('%v', 'yyyy-mm-dd hh24:mi:ss'))`,
- r.USERID, now.Format("20060102"), now.Format("2006-01-02 15:04:05"))
- _, err = session.Exec(sql)
- if err != nil {
- session.Rollback()
- logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
- return nil, errors.New("数据错误")
- }
- // add Commit() after all actions
- err = session.Commit()
- if err != nil {
- session.Rollback()
- logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
- return nil, errors.New("数据错误")
- }
- return &THJSigninRsp{SigninStatus: 1}, nil
- }
- // 我的推荐列表
- type MyRefer struct {
- Accountname string `json:"accountname" xorm:"ACCOUNTNAME"` // 用户名(脱敏)
- Score float64 `json:"score" xorm:"SCORE"` // 积分
- CREATETIME string `json:"createtime" xorm:"CREATETIME"` // 时间(yyyy-mm-dd)
- UserID int `json:"-" form:"userid" binding:"required"` // 用户ID
- PageEx `xorm:"extends"` // 页码信息
- }
- func (r *MyRefer) calc() {
- r.Accountname = EncryptByStar(r.Accountname)
- }
- func (r *MyRefer) buildSql() string {
- var sqlId utils.SQLVal = `
- select
- u.ACCOUNTNAME,
- t.SCORE,
- to_char(t.CREATETIME, 'yyyy-mm-dd') CREATETIME
- from THJ_USERSCORELOG t
- inner join USERACCOUNT u on u.USERID = t.RELATEDORDERID
- where t.USERID = %v
- order by t.CREATETIME desc
- `
- sqlId.FormatParam(r.UserID)
- sqlId.Page(r.Page, r.PageSize)
- return sqlId.String()
- }
- func (r *MyRefer) GetDataByPage() (interface{}, error, int, int, int) {
- sData := make([]MyRefer, 0)
- err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
- total := 0
- for i := range sData {
- sData[i].calc()
- total = sData[i].Total
- }
- return sData, err, r.Page, r.PageSize, total
- }
- type GThjuserscorelog struct {
- USERID int64 `json:"-" xorm:"USERID" form:"userid" binding:"required"` // 用户ID
- SCORECONFIGTYPE int32 `json:"scoreconfigtype" xorm:"SCORECONFIGTYPE"` // 配置类型 - 1:注册红包 2:签到积分 3:推广积分 4:下级用户下单积分 5:自己采购下单积分 6:自己供求下单积分 7:抽奖配置
- SCORE float64 `json:"score" xorm:"SCORE"` // 变动积分
- ORISCORE float64 `json:"-" xorm:"ORISCORE"` // 期初积分(变动前积)
- CURSCORE float64 `json:"-" xorm:"CURSCORE"` // 期末积分(变动后积)
- CREATETIME string `json:"createtime" xorm:"CREATETIME"` // 记账时间
- REMARK string `json:"-" xorm:"REMARK"` // 备注
- RELATEDORDERID int64 `json:"-" xorm:"RELATEDORDERID"` // 关联单号
- PageEx `xorm:"extends"` // 页码信息
- }
- func (r *GThjuserscorelog) calc() {
- }
- func (r *GThjuserscorelog) buildSql() string {
- var sqlId utils.SQLVal = `
- select
- t.SCORECONFIGTYPE,
- t.SCORE,
- to_char(t.CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME
- from THJ_USERSCORELOG t
- where t.USERID = %v
- order by t.CREATETIME desc
- `
- sqlId.FormatParam(r.USERID)
- sqlId.Page(r.Page, r.PageSize)
- return sqlId.String()
- }
- func (r *GThjuserscorelog) GetDataByPage() (interface{}, error, int, int, int) {
- sData := make([]GThjuserscorelog, 0)
- err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
- total := 0
- for i := range sData {
- sData[i].calc()
- total = sData[i].Total
- }
- return sData, err, r.Page, r.PageSize, total
- }
- // THJWrstandard 现货商品表
- type THJWrstandard struct {
- WRSTANDARDID int64 `json:"wrstandardid" xorm:"WRSTANDARDID"` // 现货商品ID(自增 SEQ_GOODS 确保不重复)
- WRSTANDARDCODE string `json:"wrstandardcode" xorm:"WRSTANDARDCODE"` // 现货商品代码
- WRSTANDARDNAME string `json:"wrstandardname" xorm:"WRSTANDARDNAME" form:"wrstandardname"` // 现货商品名称(模糊查询)
- DELIVERYGOODSID int32 `json:"-" xorm:"DELIVERYGOODSID"` // 现货品种ID
- UNITID int32 `json:"-" xorm:"UNITID"` // 现货商品单位ID
- MINIVALUE int64 `json:"-" xorm:"MINIVALUE"` // 最小变动值
- MINIVALUEDP int64 `json:"-" xorm:"MINIVALUEDP"` // 最小变动值小数位
- REALMINIVALUE int64 `json:"-" xorm:"REALMINIVALUE"` // 实际最小变动值
- REALMINIVALUEDP int64 `json:"-" xorm:"REALMINIVALUEDP"` // 实际最小变动值小数位
- WRSSTATUS int32 `json:"-" xorm:"WRSSTATUS"` // 状态 - 作废 - 0:未激活 1:正常
- CREATORID int64 `json:"-" xorm:"CREATORID"` // 创建人
- CREATETIME time.Time `json:"-" xorm:"CREATETIME"` // 创建时间
- UPDATORID int64 `json:"-" xorm:"UPDATORID"` // 更新人
- UPDATETIME time.Time `json:"-" xorm:"UPDATETIME"` // 更新时间
- FACTORYITEMJSON string `json:"-" xorm:"FACTORYITEMJSON"` // 要素项定义Json[{"DGFactoryItemTypeID": ,"ItemTypeMode": ,"FactoryItemIDs": },{.....},]DGFactoryItemTypeID - 要素项类型ID --DGFactoryItem->DGFactoryItemTypeIDItemTypeMode - 要素项类型模式 --DGFactoryItem->ItemTypeModeFactoryItemIDs - 选择项IDs--DGFactoryItem->DGFactoryItemID, 逗号分隔
- ISVALID int32 `json:"-" xorm:"ISVALID"` // 是否有效 - 0:无效 1:有效
- AREAUSERID int64 `json:"-" xorm:"AREAUSERID"` // 所属机构
- REMARK string `json:"-" xorm:"REMARK"` // 备注
- CONVERTFACTOR float64 `json:"-" xorm:"CONVERTFACTOR"` // 标仓系数
- VATRATE float64 `json:"-" xorm:"VATRATE"` // 现货增值税率
- STORAGEFEE float64 `json:"-" xorm:"STORAGEFEE"` // 仓储费(固定: 111)
- THUMURLS string `json:"thumurls" xorm:"THUMURLS"` // 缩略图片(1:1)(逗号分隔)
- PICTUREURLS string `json:"-" xorm:"PICTUREURLS"` // 详情图片(逗号分隔)
- BANNERPICURL string `json:"-" xorm:"BANNERPICURL"` // Banner图(逗号分隔)
- PROVIDERUSERID int64 `json:"-" xorm:"PROVIDERUSERID"` // 供应链提供商
- PROVIDERACCOUNTID int64 `json:"-" xorm:"PROVIDERACCOUNTID"` // 供应链提供商资金账户 ID
- PageEx `xorm:"extends"` // 页码信息
- }
- func (r *THJWrstandard) calc() {
- }
- func (r *THJWrstandard) buildSql() string {
- var sqlId utils.SQLVal = `
- select
- wr.*
- from wrstandard wr
- where wr.wrstandardid in
- (select distinct t.wrstandardid
- from WR_PresaleInfo t
- where t.presalestatus = 2
- and t.marketid = 64201) and %v
- order by wr.wrstandardname;
- `
- param := "1=1"
- if r.WRSTANDARDNAME != "" {
- param = fmt.Sprintf("wr.wrstandardname like '%%%v%%'", r.WRSTANDARDNAME)
- }
- sqlId.FormatParam(param)
- sqlId.Page(r.Page, r.PageSize)
- return sqlId.String()
- }
- func (r *THJWrstandard) GetDataByPage() (interface{}, error, int, int, int) {
- sData := make([]THJWrstandard, 0)
- err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
- total := 0
- for i := range sData {
- sData[i].calc()
- total = sData[i].Total
- }
- return sData, err, r.Page, r.PageSize, total
- }
- // RegisterMoney 注册红包
- type RegisterMoney struct {
- Amount float64 `json:"amount" xorm:"AMOUNT"` // 红包
- Accountid int64 `json:"-" form:"accountid" binding:"required"` // 资金账户ID
- }
- func (r *RegisterMoney) calc() {
- }
- func (r *RegisterMoney) buildSql() string {
- var sqlId utils.SQLVal = `
- select
- t.amount
- from taaccountlog t
- where t.accountid = %v and t.businesscode = '712'
- `
- sqlId.FormatParam(r.Accountid)
- return sqlId.String()
- }
- // GetDataEx 从数据库中查询数据
- func (r *RegisterMoney) GetDataEx() (interface{}, error) {
- e := db.GetEngine()
- s := e.SQL(r.buildSql())
- sData := make([]RegisterMoney, 0)
- if err := s.Find(&sData); err != nil {
- return nil, err
- }
- for i := range sData {
- sData[i].calc()
- }
- return sData, nil
- }
- // THJWrstandardDetail_GoodsInfo 采购商品信息
- type THJWrstandardDetail_GoodsInfo struct {
- WRSTANDARDID int64 `json:"wrstandardid" xorm:"WRSTANDARDID"` // 现货商品ID(自增 SEQ_GOODS 确保不重复)
- WRSTANDARDCODE string `json:"wrstandardcode" xorm:"WRSTANDARDCODE"` // 现货商品代码
- WRSTANDARDNAME string `json:"wrstandardname" xorm:"WRSTANDARDNAME"` // 现货商品名称
- DELIVERYGOODSID int32 `json:"-" xorm:"DELIVERYGOODSID"` // 现货品种ID
- UNITID int32 `json:"-" xorm:"UNITID"` // 现货商品单位ID
- MINIVALUE int64 `json:"-" xorm:"MINIVALUE"` // 最小变动值
- MINIVALUEDP int64 `json:"-" xorm:"MINIVALUEDP"` // 最小变动值小数位
- REALMINIVALUE int64 `json:"-" xorm:"REALMINIVALUE"` // 实际最小变动值
- REALMINIVALUEDP int64 `json:"-" xorm:"REALMINIVALUEDP"` // 实际最小变动值小数位
- WRSSTATUS int32 `json:"-" xorm:"WRSSTATUS"` // 状态 - 作废 - 0:未激活 1:正常
- CREATORID int64 `json:"-" xorm:"CREATORID"` // 创建人
- CREATETIME time.Time `json:"-" xorm:"CREATETIME"` // 创建时间
- UPDATORID int64 `json:"-" xorm:"UPDATORID"` // 更新人
- UPDATETIME time.Time `json:"-" xorm:"UPDATETIME"` // 更新时间
- FACTORYITEMJSON string `json:"-" xorm:"FACTORYITEMJSON"` // 要素项定义Json[{"DGFactoryItemTypeID": ,"ItemTypeMode": ,"FactoryItemIDs": },{.....},]DGFactoryItemTypeID - 要素项类型ID --DGFactoryItem->DGFactoryItemTypeIDItemTypeMode - 要素项类型模式 --DGFactoryItem->ItemTypeModeFactoryItemIDs - 选择项IDs--DGFactoryItem->DGFactoryItemID, 逗号分隔
- ISVALID int32 `json:"-" xorm:"ISVALID"` // 是否有效 - 0:无效 1:有效
- AREAUSERID int64 `json:"-" xorm:"AREAUSERID"` // 所属机构
- REMARK string `json:"-" xorm:"REMARK"` // 备注
- CONVERTFACTOR float64 `json:"-" xorm:"CONVERTFACTOR"` // 标仓系数
- VATRATE float64 `json:"-" xorm:"VATRATE"` // 现货增值税率
- STORAGEFEE float64 `json:"-" xorm:"STORAGEFEE"` // 仓储费(固定: 111)
- THUMURLS string `json:"-" xorm:"THUMURLS"` // 缩略图片(1:1)(逗号分隔)
- PICTUREURLS string `json:"pictureurls" xorm:"PICTUREURLS"` // 详情图片(逗号分隔)
- BANNERPICURL string `json:"-" xorm:"BANNERPICURL"` // Banner图(逗号分隔)
- PROVIDERUSERID int64 `json:"-" xorm:"PROVIDERUSERID"` // 供应链提供商
- PROVIDERACCOUNTID int64 `json:"-" xorm:"PROVIDERACCOUNTID"` // 供应链提供商资金账户 ID
- SPOTGOODSPRICE float64 `json:"spotgoodsprice" xorm:"SPOTGOODSPRICE"` // 现货价格
- }
- // THJDeliveryMode 交割方式
- type THJDeliveryMode struct {
- ENUMDICNAME string `json:"enumdicname" xorm:"ENUMDICNAME"` // 枚举项名称
- ENUMITEMNAME int64 `json:"enumitemname" xorm:"ENUMITEMNAME"` // 枚举项值
- }
- // THJDeliveryMonth 交割月份
- type THJDeliveryMonth struct {
- PRESALEAPPLYID int64 `json:"presaleapplyid" xorm:"PRESALEAPPLYID"` // 预售申请ID(184+Unix秒时间戳(10位)+xxxxxx)
- ENDMONTH string `json:"endmonth" xorm:"ENDMONTH"` // 预售结束月份(yyyy-mm)
- ENDDATE string `json:"enddate" xorm:"ENDDATE"` // 预售结束日期(yyyy-mm-dd)
- ORDERQTY int64 `json:"orderqty" xorm:"ORDERQTY"` // 委托数量
- TRADEQTY int64 `json:"tradeqty" xorm:"TRADEQTY"` // 成交数量
- REMAINQTY int64 `json:"remainqty" xorm:"REMAINQTY"` // 可用数量
- }
- // THJPresaleApplyDeposit 支付方式
- type THJPresaleApplyDeposit struct {
- DEPOSITRATE float64 `json:"depositrate" xorm:"DEPOSITRATE"` // 定金比例
- DISCOUNTAMOUNT float64 `json:"discountamount" xorm:"DISCOUNTAMOUNT"` // 优惠金额(每吨)
- }
- // THJSpotGoodsPriceLog 历史价格走势
- type THJSpotGoodsPriceLog struct {
- SPOTGOODSPRICE float64 `json:"spotgoodsprice" xorm:"SPOTGOODSPRICE"` // 现货价格
- TRADEDATE string `json:"tradedate" xorm:"TRADEDATE"` // 交易日(yyyyMMdd)
- }
- type THJWrstandardDetailReq struct {
- WRSTANDARDID int64 `form:"wrstandardid" binding:"required"` // 现货商品ID
- }
- // THJWrstandardDetailRsp 采购商品详情
- type THJWrstandardDetailRsp struct {
- GoodsInfo THJWrstandardDetail_GoodsInfo // 商品信息
- DeliveryModes []THJDeliveryMode // 交割方式
- DeliveryMonth []THJDeliveryMonth // 交割月份
- PresaleApplyDeposits []THJPresaleApplyDeposit // 支付方式
- SpotGoodsPriceLogs []THJSpotGoodsPriceLog // 历史价格走势
- }
- // GetTHJWrstandardDetail 获取采购商品详情
- func (r *THJWrstandardDetailReq) GetTHJWrstandardDetail() (rsp *THJWrstandardDetailRsp, err error) {
- engine := db.GetEngine()
- // 采购商品信息
- goodsInfo := new(THJWrstandardDetail_GoodsInfo)
- sql := fmt.Sprintf(`
- select
- t.WRSTANDARDID,
- t.WRSTANDARDCODE,
- t.WRSTANDARDNAME,
- t.PICTUREURLS,
- p.SPOTGOODSPRICE
- from wrstandard t
- left join ERMCP_SpotGoodsPrice p on t.WRSTANDARDID = p.WRSTANDARDID and p.spotgoodsbrandid=0 and p.currencyid = 1
- where t.WRSTANDARDID = %v
- `, r.WRSTANDARDID)
- if _, err = engine.SQL(sql).Get(goodsInfo); err != nil {
- return
- }
- rsp.GoodsInfo = *goodsInfo
- // 交割方式
- deliveryModes := make([]THJDeliveryMode, 0)
- sql = `
- select
- t.ENUMDICNAME,
- t.ENUMITEMNAME
- from enumdicitem t
- where t.enumdiccode = 'THJDeliveryMode';
- `
- if err = engine.SQL(sql).Find(&deliveryModes); err != nil {
- return
- }
- rsp.DeliveryModes = deliveryModes
- // 交割月份
- deliveryMonths := make([]THJDeliveryMonth, 0)
- sql = fmt.Sprintf(`
- select
- t.PRESALEAPPLYID,
- to_char(t.ENDDATE, 'yyyy-mm') ENDMONTH,
- to_char(t.ENDDATE, 'yyyy-mm-dd') ENDDATE,
- t.ORDERQTY,
- t.TRADEQTY,
- (od.orderqty - od.tradeqty) REMAINQTY
- from WR_PresaleInfo t
- inner join wrtrade_orderdetail od on t.sellwrtradeorderid = od.wrtradeorderid
- where t.wrstandardid = %v
- and t.presalestatus = 2
- and od.wrtradeorderstatus in (3, 7)
- and (od.orderqty - od.tradeqty) > 0
- `, r.WRSTANDARDID)
- if err = engine.SQL(sql).Find(&deliveryMonths); err != nil {
- return
- }
- rsp.DeliveryMonth = deliveryMonths
- // 支付方式
- ids := make([]string, 0)
- for _, item := range deliveryMonths {
- ids = append(ids, strconv.Itoa(int(item.PRESALEAPPLYID)))
- }
- if len(ids) > 0 {
- presaleApplyDeposits := make([]THJPresaleApplyDeposit, 0)
- sql = fmt.Sprintf(`
- select
- t.DEPOSITRATE,
- t.DISCOUNTAMOUNT
- from THJ_PresaleApplyDeposit t
- where t.presaleapplyid in (%v)
- `, strings.Join(ids, ","))
- if err = engine.SQL(sql).Find(&presaleApplyDeposits); err != nil {
- return
- }
- rsp.PresaleApplyDeposits = presaleApplyDeposits
- }
- // 历史价格走势
- spotGoodsPriceLogs := make([]THJSpotGoodsPriceLog, 0)
- sql = fmt.Sprintf(`
- select
- t.SPOTGOODSPRICE,
- t.TRADEDATE
- from ERMCP_SpotGoodsPriceLog t
- where t.wrstandardid = %v
- order by t.operatetime
- `, r.WRSTANDARDID)
- if err = engine.SQL(sql).Find(&spotGoodsPriceLogs); err != nil {
- return
- }
- rsp.SpotGoodsPriceLogs = spotGoodsPriceLogs
- return
- }
|