ferroalloy.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. package models
  2. import (
  3. "errors"
  4. "fmt"
  5. "mtp2_if/db"
  6. "mtp2_if/logger"
  7. "mtp2_if/utils"
  8. "strconv"
  9. "strings"
  10. "sync"
  11. "time"
  12. )
  13. // 上海铁合金项目
  14. // GErmcpspotgoodsprice 现货市价表
  15. type GErmcpspotgoodsprice struct {
  16. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
  17. WRSTANDARDID int64 `json:"wrstandardid" xorm:"WRSTANDARDID"` // 现货商品ID(通用则为0)
  18. SPOTGOODSBRANDID int32 `json:"spotgoodsbrandid" xorm:"SPOTGOODSBRANDID"` // 现货品牌ID(通用则为0, 不为0则须先有商品ID)
  19. CURRENCYID int64 `json:"currencyid" xorm:"CURRENCYID"` // 报价货币ID
  20. SPOTGOODSPRICE float64 `json:"spotgoodsprice" xorm:"SPOTGOODSPRICE"` // 【最新价】当前价格
  21. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE"` // 【日期】交易日
  22. OPERATESRC int32 `json:"-" xorm:"OPERATESRC"` // 最后操作来源 - 1:管理端 2:终端
  23. OPERATEID int64 `json:"-" xorm:"OPERATEID"` // 最后操作人
  24. OPERATETIME time.Time `json:"-" xorm:"OPERATETIME"` // 最后操作时间
  25. ISVALID int32 `json:"-" xorm:"ISVALID"` // 是否有效 - 0:无效 1:有效
  26. YSTSPOTGOODSPRICE float64 `json:"ystspotgoodsprice" xorm:"YSTSPOTGOODSPRICE"` // 昨价
  27. TODAYSPOTGOODSPRICE float64 `json:"todayspotgoodsprice" xorm:"TODAYSPOTGOODSPRICE"` // 今日指定价
  28. TODAYPRICEDTOTALQTY float64 `json:"todaypricedtotalqty" xorm:"TODAYPRICEDTOTALQTY"` // 今日定价总量
  29. TODAYPRICEDTOTALAMOUNT float64 `json:"todaypricedtotalamount" xorm:"TODAYPRICEDTOTALAMOUNT"` // 今日定价金额
  30. SRCMARKETNAME string `json:"srcmarketname" xorm:"SRCMARKETNAME"` // 来源市场名称
  31. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"WRSTANDARDCODE"` // 现货商品代码
  32. WRSTANDARDNAME string `json:"wrstandardname" xorm:"WRSTANDARDNAME"` // 【名称】现货商品名称
  33. PageEx `xorm:"extends"` // 页码信息
  34. }
  35. func (r *GErmcpspotgoodsprice) calc() {
  36. if len(r.TRADEDATE) == 8 {
  37. r.TRADEDATE = fmt.Sprintf("%v-%v-%v", r.TRADEDATE[0:4], r.TRADEDATE[4:6], r.TRADEDATE[6:8])
  38. }
  39. }
  40. func (r *GErmcpspotgoodsprice) buildSql() string {
  41. var sqlId utils.SQLVal = `
  42. SELECT
  43. t.DELIVERYGOODSID ,
  44. t.WRSTANDARDID ,
  45. t.SPOTGOODSBRANDID ,
  46. t.CURRENCYID ,
  47. t.SPOTGOODSPRICE ,
  48. t.TRADEDATE ,
  49. t.YSTSPOTGOODSPRICE ,
  50. t.TODAYSPOTGOODSPRICE ,
  51. t.TODAYPRICEDTOTALQTY ,
  52. t.TODAYPRICEDTOTALAMOUNT,
  53. t.SRCMARKETNAME,
  54. w.WRSTANDARDCODE,
  55. w.WRSTANDARDNAME
  56. FROM ERMCP_SPOTGOODSPRICE t
  57. LEFT JOIN WRStandard w ON t.WRSTANDARDID = w.WRSTANDARDID
  58. WHERE t.SPOTGOODSBRANDID = 0 AND t.CURRENCYID = 1 AND t.ISVALID = 1
  59. `
  60. sqlId.OrderByDesc("w.WRSTANDARDNAME")
  61. sqlId.Page(r.Page, r.PageSize)
  62. return sqlId.String()
  63. }
  64. func (r *GErmcpspotgoodsprice) GetDataByPage() (interface{}, error, int, int, int) {
  65. sData := make([]GErmcpspotgoodsprice, 0)
  66. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  67. total := 0
  68. for i := range sData {
  69. sData[i].calc()
  70. total = sData[i].Total
  71. }
  72. return sData, err, r.Page, r.PageSize, total
  73. }
  74. type THJSigninReq struct {
  75. USERID int64 `form:"userid" binding:"required"` // 用户ID
  76. }
  77. type THJSigninRsp struct {
  78. SigninStatus int `json:"signinstatus"` // 状态操作标志 1-签到成功 2-当日已签到,不能重复签到
  79. }
  80. // Signin 用户签到
  81. func (r *THJSigninReq) Signin() (rsp *THJSigninRsp, err error) {
  82. // 资源锁
  83. var lock sync.Mutex
  84. lock.Lock()
  85. defer lock.Unlock()
  86. engine := db.GetEngine()
  87. // 获取目标用户信息
  88. if u, err := GetUserInfo(int(r.USERID)); err != nil || u == nil {
  89. logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
  90. err = errors.New("错误的用户ID")
  91. return nil, err
  92. }
  93. // 判断目标用户当日是否已经签到
  94. p := new(Thjsignin)
  95. if has, err := engine.Where("userid = ?", r.USERID).And("tradedate = to_char(sysdate, 'yyyymmdd')").Get(p); err != nil {
  96. logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
  97. err = errors.New("数据错误")
  98. return nil, err
  99. } else {
  100. if has {
  101. return &THJSigninRsp{SigninStatus: 2}, nil
  102. }
  103. }
  104. // 获取签到积配置
  105. c := Thjscoreconfig{
  106. SCORECONFIGTYPE: 2,
  107. }
  108. if has, err := engine.Get(&c); err != nil || !has {
  109. logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
  110. err = errors.New("数据错误")
  111. return nil, err
  112. }
  113. // 事务
  114. session := engine.NewSession()
  115. defer session.Close()
  116. // add Begin() before any action
  117. if err := session.Begin(); err != nil {
  118. logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
  119. return nil, errors.New("数据错误")
  120. }
  121. now := time.Now()
  122. // 签到积分配置大于0才记积分和流水
  123. if c.PARMA1 > 0 {
  124. // 判断用户积分表是否已经存在此用户
  125. curscore := 0
  126. t := Thjuserscore{USERID: r.USERID}
  127. has, err := session.Get(&t)
  128. if err != nil {
  129. session.Rollback()
  130. logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
  131. return nil, errors.New("数据错误")
  132. }
  133. if has {
  134. // 更新积分
  135. curscore = int(t.CURSCORE)
  136. t.CURSCORE += int64(c.PARMA1)
  137. t.UPDATETIME = now
  138. // _, err = session.Update(&t)
  139. sql := fmt.Sprintf(`UPDATE THJ_USERSCORE
  140. SET CURSCORE = %v, UPDATETIME = to_date('%v', 'yyyy-mm-dd hh24:mi:ss')
  141. WHERE USERID = %v`,
  142. t.CURSCORE, t.UPDATETIME.Format("2006-01-02 15:04:05"), t.USERID)
  143. _, err = session.Exec(sql)
  144. if err != nil {
  145. session.Rollback()
  146. logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
  147. return nil, errors.New("数据错误")
  148. }
  149. } else {
  150. // 新增用户积分记录
  151. t.CURSCORE = int64(c.PARMA1)
  152. t.UPDATETIME = now
  153. // _, err = session.Insert(&t)
  154. sql := fmt.Sprintf(`INSERT INTO THJ_USERSCORE VALUES (%v, %v, %v, to_date('%v', 'yyyy-mm-dd hh24:mi:ss'))`,
  155. t.USERID, t.CURSCORE, 0, t.UPDATETIME.Format("2006-01-02 15:04:05"))
  156. _, err = session.Exec(sql)
  157. if err != nil {
  158. session.Rollback()
  159. logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
  160. return nil, errors.New("数据错误")
  161. }
  162. }
  163. // 记录积分流水
  164. q := Thjuserscorelog{}
  165. seqMap, err := session.QueryString("SELECT SEQ_THJ_USERSCORELOG.nextval SEQID FROM dual")
  166. if err != nil {
  167. session.Rollback()
  168. logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
  169. return nil, errors.New("数据错误")
  170. }
  171. if len(seqMap) <= 0 {
  172. session.Rollback()
  173. return nil, errors.New("获取自增ID错误")
  174. }
  175. seqID, _ := strconv.Atoi(seqMap[0]["SEQID"])
  176. q.AUTOID = int64(seqID)
  177. q.USERID = r.USERID
  178. q.SCORECONFIGTYPE = 2 // 2:签到送积分
  179. q.SCORE = float64(c.PARMA1)
  180. q.ORISCORE = float64(curscore)
  181. q.CURSCORE = float64(t.CURSCORE)
  182. q.CREATETIME = now
  183. q.RELATEDORDERID = r.USERID
  184. // _, err = session.Insert(&q)
  185. sql := fmt.Sprintf(`INSERT INTO THJ_USERSCORELOG
  186. (AUTOID, USERID, SCORECONFIGTYPE, SCORE, ORISCORE, CURSCORE, CREATETIME)
  187. VALUES
  188. (%v, %v, %v, %v, %v, %v, to_date('%v', 'yyyy-mm-dd hh24:mi:ss'))`,
  189. q.AUTOID, q.USERID, q.SCORECONFIGTYPE, q.SCORE, q.ORISCORE, q.CURSCORE, q.CREATETIME.Format("2006-01-02 15:04:05"))
  190. _, err = session.Exec(sql)
  191. if err != nil {
  192. session.Rollback()
  193. logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
  194. return nil, errors.New("数据错误")
  195. }
  196. }
  197. // 增加签到记录
  198. sql := fmt.Sprintf(`INSERT INTO THJ_SIGNIN VALUES (%v, %v, to_date('%v', 'yyyy-mm-dd hh24:mi:ss'))`,
  199. r.USERID, now.Format("20060102"), now.Format("2006-01-02 15:04:05"))
  200. _, err = session.Exec(sql)
  201. if err != nil {
  202. session.Rollback()
  203. logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
  204. return nil, errors.New("数据错误")
  205. }
  206. // add Commit() after all actions
  207. err = session.Commit()
  208. if err != nil {
  209. session.Rollback()
  210. logger.GetLogger().Errorf("Thjsignin failed: %s", err.Error())
  211. return nil, errors.New("数据错误")
  212. }
  213. return &THJSigninRsp{SigninStatus: 1}, nil
  214. }
  215. // 我的推荐列表
  216. type MyRefer struct {
  217. Accountname string `json:"accountname" xorm:"ACCOUNTNAME"` // 用户名(脱敏)
  218. Score float64 `json:"score" xorm:"SCORE"` // 积分
  219. CREATETIME string `json:"createtime" xorm:"CREATETIME"` // 时间(yyyy-mm-dd)
  220. UserID int `json:"-" form:"userid" binding:"required"` // 用户ID
  221. PageEx `xorm:"extends"` // 页码信息
  222. }
  223. func (r *MyRefer) calc() {
  224. r.Accountname = EncryptByStar(r.Accountname)
  225. }
  226. func (r *MyRefer) buildSql() string {
  227. var sqlId utils.SQLVal = `
  228. select
  229. u.ACCOUNTNAME,
  230. t.SCORE,
  231. to_char(t.CREATETIME, 'yyyy-mm-dd') CREATETIME
  232. from THJ_USERSCORELOG t
  233. inner join USERACCOUNT u on u.USERID = t.RELATEDORDERID
  234. where t.USERID = %v
  235. order by t.CREATETIME desc
  236. `
  237. sqlId.FormatParam(r.UserID)
  238. sqlId.Page(r.Page, r.PageSize)
  239. return sqlId.String()
  240. }
  241. func (r *MyRefer) GetDataByPage() (interface{}, error, int, int, int) {
  242. sData := make([]MyRefer, 0)
  243. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  244. total := 0
  245. for i := range sData {
  246. sData[i].calc()
  247. total = sData[i].Total
  248. }
  249. return sData, err, r.Page, r.PageSize, total
  250. }
  251. type GThjuserscorelog struct {
  252. USERID int64 `json:"-" xorm:"USERID" form:"userid" binding:"required"` // 用户ID
  253. SCORECONFIGTYPE int32 `json:"scoreconfigtype" xorm:"SCORECONFIGTYPE"` // 配置类型 - 1:注册红包 2:签到积分 3:推广积分 4:下级用户下单积分 5:自己采购下单积分 6:自己供求下单积分 7:抽奖配置
  254. SCORE float64 `json:"score" xorm:"SCORE"` // 变动积分
  255. ORISCORE float64 `json:"-" xorm:"ORISCORE"` // 期初积分(变动前积)
  256. CURSCORE float64 `json:"-" xorm:"CURSCORE"` // 期末积分(变动后积)
  257. CREATETIME string `json:"createtime" xorm:"CREATETIME"` // 记账时间
  258. REMARK string `json:"-" xorm:"REMARK"` // 备注
  259. RELATEDORDERID int64 `json:"-" xorm:"RELATEDORDERID"` // 关联单号
  260. PageEx `xorm:"extends"` // 页码信息
  261. }
  262. func (r *GThjuserscorelog) calc() {
  263. }
  264. func (r *GThjuserscorelog) buildSql() string {
  265. var sqlId utils.SQLVal = `
  266. select
  267. t.SCORECONFIGTYPE,
  268. t.SCORE,
  269. to_char(t.CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME
  270. from THJ_USERSCORELOG t
  271. where t.USERID = %v
  272. order by t.CREATETIME desc
  273. `
  274. sqlId.FormatParam(r.USERID)
  275. sqlId.Page(r.Page, r.PageSize)
  276. return sqlId.String()
  277. }
  278. func (r *GThjuserscorelog) GetDataByPage() (interface{}, error, int, int, int) {
  279. sData := make([]GThjuserscorelog, 0)
  280. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  281. total := 0
  282. for i := range sData {
  283. sData[i].calc()
  284. total = sData[i].Total
  285. }
  286. return sData, err, r.Page, r.PageSize, total
  287. }
  288. // THJWrstandard 现货商品表
  289. type THJWrstandard struct {
  290. WRSTANDARDID int64 `json:"wrstandardid" xorm:"WRSTANDARDID"` // 现货商品ID(自增 SEQ_GOODS 确保不重复)
  291. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"WRSTANDARDCODE"` // 现货商品代码
  292. WRSTANDARDNAME string `json:"wrstandardname" xorm:"WRSTANDARDNAME" form:"wrstandardname"` // 现货商品名称(模糊查询)
  293. DELIVERYGOODSID int32 `json:"-" xorm:"DELIVERYGOODSID"` // 现货品种ID
  294. UNITID int32 `json:"-" xorm:"UNITID"` // 现货商品单位ID
  295. MINIVALUE int64 `json:"-" xorm:"MINIVALUE"` // 最小变动值
  296. MINIVALUEDP int64 `json:"-" xorm:"MINIVALUEDP"` // 最小变动值小数位
  297. REALMINIVALUE int64 `json:"-" xorm:"REALMINIVALUE"` // 实际最小变动值
  298. REALMINIVALUEDP int64 `json:"-" xorm:"REALMINIVALUEDP"` // 实际最小变动值小数位
  299. WRSSTATUS int32 `json:"-" xorm:"WRSSTATUS"` // 状态 - 作废 - 0:未激活 1:正常
  300. CREATORID int64 `json:"-" xorm:"CREATORID"` // 创建人
  301. CREATETIME time.Time `json:"-" xorm:"CREATETIME"` // 创建时间
  302. UPDATORID int64 `json:"-" xorm:"UPDATORID"` // 更新人
  303. UPDATETIME time.Time `json:"-" xorm:"UPDATETIME"` // 更新时间
  304. FACTORYITEMJSON string `json:"-" xorm:"FACTORYITEMJSON"` // 要素项定义Json[{"DGFactoryItemTypeID": ,"ItemTypeMode": ,"FactoryItemIDs": },{.....},]DGFactoryItemTypeID - 要素项类型ID --DGFactoryItem->DGFactoryItemTypeIDItemTypeMode - 要素项类型模式 --DGFactoryItem->ItemTypeModeFactoryItemIDs - 选择项IDs--DGFactoryItem->DGFactoryItemID, 逗号分隔
  305. ISVALID int32 `json:"-" xorm:"ISVALID"` // 是否有效 - 0:无效 1:有效
  306. AREAUSERID int64 `json:"-" xorm:"AREAUSERID"` // 所属机构
  307. REMARK string `json:"-" xorm:"REMARK"` // 备注
  308. CONVERTFACTOR float64 `json:"-" xorm:"CONVERTFACTOR"` // 标仓系数
  309. VATRATE float64 `json:"-" xorm:"VATRATE"` // 现货增值税率
  310. STORAGEFEE float64 `json:"-" xorm:"STORAGEFEE"` // 仓储费(固定: 111)
  311. THUMURLS string `json:"thumurls" xorm:"THUMURLS"` // 缩略图片(1:1)(逗号分隔)
  312. PICTUREURLS string `json:"-" xorm:"PICTUREURLS"` // 详情图片(逗号分隔)
  313. BANNERPICURL string `json:"-" xorm:"BANNERPICURL"` // Banner图(逗号分隔)
  314. PROVIDERUSERID int64 `json:"-" xorm:"PROVIDERUSERID"` // 供应链提供商
  315. PROVIDERACCOUNTID int64 `json:"-" xorm:"PROVIDERACCOUNTID"` // 供应链提供商资金账户 ID
  316. PageEx `xorm:"extends"` // 页码信息
  317. }
  318. func (r *THJWrstandard) calc() {
  319. }
  320. func (r *THJWrstandard) buildSql() string {
  321. var sqlId utils.SQLVal = `
  322. select
  323. wr.*
  324. from wrstandard wr
  325. where wr.wrstandardid in
  326. (select distinct t.wrstandardid
  327. from WR_PresaleInfo t
  328. where t.presalestatus = 2
  329. and t.marketid = 64201) and %v
  330. order by wr.wrstandardname;
  331. `
  332. param := "1=1"
  333. if r.WRSTANDARDNAME != "" {
  334. param = fmt.Sprintf("wr.wrstandardname like '%%%v%%'", r.WRSTANDARDNAME)
  335. }
  336. sqlId.FormatParam(param)
  337. sqlId.Page(r.Page, r.PageSize)
  338. return sqlId.String()
  339. }
  340. func (r *THJWrstandard) GetDataByPage() (interface{}, error, int, int, int) {
  341. sData := make([]THJWrstandard, 0)
  342. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  343. total := 0
  344. for i := range sData {
  345. sData[i].calc()
  346. total = sData[i].Total
  347. }
  348. return sData, err, r.Page, r.PageSize, total
  349. }
  350. // RegisterMoney 注册红包
  351. type RegisterMoney struct {
  352. Amount float64 `json:"amount" xorm:"AMOUNT"` // 红包
  353. Accountid int64 `json:"-" form:"accountid" binding:"required"` // 资金账户ID
  354. }
  355. func (r *RegisterMoney) calc() {
  356. }
  357. func (r *RegisterMoney) buildSql() string {
  358. var sqlId utils.SQLVal = `
  359. select
  360. t.amount
  361. from taaccountlog t
  362. where t.accountid = %v and t.businesscode = '712'
  363. `
  364. sqlId.FormatParam(r.Accountid)
  365. return sqlId.String()
  366. }
  367. // GetDataEx 从数据库中查询数据
  368. func (r *RegisterMoney) GetDataEx() (interface{}, error) {
  369. e := db.GetEngine()
  370. s := e.SQL(r.buildSql())
  371. sData := make([]RegisterMoney, 0)
  372. if err := s.Find(&sData); err != nil {
  373. return nil, err
  374. }
  375. for i := range sData {
  376. sData[i].calc()
  377. }
  378. return sData, nil
  379. }
  380. // THJWrstandardDetail_GoodsInfo 采购商品信息
  381. type THJWrstandardDetail_GoodsInfo struct {
  382. WRSTANDARDID int64 `json:"wrstandardid" xorm:"WRSTANDARDID"` // 现货商品ID(自增 SEQ_GOODS 确保不重复)
  383. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"WRSTANDARDCODE"` // 现货商品代码
  384. WRSTANDARDNAME string `json:"wrstandardname" xorm:"WRSTANDARDNAME"` // 现货商品名称
  385. DELIVERYGOODSID int32 `json:"-" xorm:"DELIVERYGOODSID"` // 现货品种ID
  386. UNITID int32 `json:"-" xorm:"UNITID"` // 现货商品单位ID
  387. MINIVALUE int64 `json:"-" xorm:"MINIVALUE"` // 最小变动值
  388. MINIVALUEDP int64 `json:"-" xorm:"MINIVALUEDP"` // 最小变动值小数位
  389. REALMINIVALUE int64 `json:"-" xorm:"REALMINIVALUE"` // 实际最小变动值
  390. REALMINIVALUEDP int64 `json:"-" xorm:"REALMINIVALUEDP"` // 实际最小变动值小数位
  391. WRSSTATUS int32 `json:"-" xorm:"WRSSTATUS"` // 状态 - 作废 - 0:未激活 1:正常
  392. CREATORID int64 `json:"-" xorm:"CREATORID"` // 创建人
  393. CREATETIME time.Time `json:"-" xorm:"CREATETIME"` // 创建时间
  394. UPDATORID int64 `json:"-" xorm:"UPDATORID"` // 更新人
  395. UPDATETIME time.Time `json:"-" xorm:"UPDATETIME"` // 更新时间
  396. FACTORYITEMJSON string `json:"-" xorm:"FACTORYITEMJSON"` // 要素项定义Json[{"DGFactoryItemTypeID": ,"ItemTypeMode": ,"FactoryItemIDs": },{.....},]DGFactoryItemTypeID - 要素项类型ID --DGFactoryItem->DGFactoryItemTypeIDItemTypeMode - 要素项类型模式 --DGFactoryItem->ItemTypeModeFactoryItemIDs - 选择项IDs--DGFactoryItem->DGFactoryItemID, 逗号分隔
  397. ISVALID int32 `json:"-" xorm:"ISVALID"` // 是否有效 - 0:无效 1:有效
  398. AREAUSERID int64 `json:"-" xorm:"AREAUSERID"` // 所属机构
  399. REMARK string `json:"-" xorm:"REMARK"` // 备注
  400. CONVERTFACTOR float64 `json:"-" xorm:"CONVERTFACTOR"` // 标仓系数
  401. VATRATE float64 `json:"-" xorm:"VATRATE"` // 现货增值税率
  402. STORAGEFEE float64 `json:"-" xorm:"STORAGEFEE"` // 仓储费(固定: 111)
  403. THUMURLS string `json:"-" xorm:"THUMURLS"` // 缩略图片(1:1)(逗号分隔)
  404. PICTUREURLS string `json:"pictureurls" xorm:"PICTUREURLS"` // 详情图片(逗号分隔)
  405. BANNERPICURL string `json:"-" xorm:"BANNERPICURL"` // Banner图(逗号分隔)
  406. PROVIDERUSERID int64 `json:"-" xorm:"PROVIDERUSERID"` // 供应链提供商
  407. PROVIDERACCOUNTID int64 `json:"-" xorm:"PROVIDERACCOUNTID"` // 供应链提供商资金账户 ID
  408. SPOTGOODSPRICE float64 `json:"spotgoodsprice" xorm:"SPOTGOODSPRICE"` // 现货价格
  409. }
  410. // THJDeliveryMode 交割方式
  411. type THJDeliveryMode struct {
  412. ENUMDICNAME string `json:"enumdicname" xorm:"ENUMDICNAME"` // 枚举项名称
  413. ENUMITEMNAME int64 `json:"enumitemname" xorm:"ENUMITEMNAME"` // 枚举项值
  414. }
  415. // THJDeliveryMonth 交割月份
  416. type THJDeliveryMonth struct {
  417. PRESALEAPPLYID int64 `json:"presaleapplyid" xorm:"PRESALEAPPLYID"` // 预售申请ID(184+Unix秒时间戳(10位)+xxxxxx)
  418. ENDMONTH string `json:"endmonth" xorm:"ENDMONTH"` // 预售结束月份(yyyy-mm)
  419. ENDDATE string `json:"enddate" xorm:"ENDDATE"` // 预售结束日期(yyyy-mm-dd)
  420. ORDERQTY int64 `json:"orderqty" xorm:"ORDERQTY"` // 委托数量
  421. TRADEQTY int64 `json:"tradeqty" xorm:"TRADEQTY"` // 成交数量
  422. REMAINQTY int64 `json:"remainqty" xorm:"REMAINQTY"` // 可用数量
  423. }
  424. // THJPresaleApplyDeposit 支付方式
  425. type THJPresaleApplyDeposit struct {
  426. DEPOSITRATE float64 `json:"depositrate" xorm:"DEPOSITRATE"` // 定金比例
  427. DISCOUNTAMOUNT float64 `json:"discountamount" xorm:"DISCOUNTAMOUNT"` // 优惠金额(每吨)
  428. }
  429. // THJSpotGoodsPriceLog 历史价格走势
  430. type THJSpotGoodsPriceLog struct {
  431. SPOTGOODSPRICE float64 `json:"spotgoodsprice" xorm:"SPOTGOODSPRICE"` // 现货价格
  432. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE"` // 交易日(yyyyMMdd)
  433. }
  434. type THJWrstandardDetailReq struct {
  435. WRSTANDARDID int64 `form:"wrstandardid" binding:"required"` // 现货商品ID
  436. }
  437. // THJWrstandardDetailRsp 采购商品详情
  438. type THJWrstandardDetailRsp struct {
  439. GoodsInfo THJWrstandardDetail_GoodsInfo // 商品信息
  440. DeliveryModes []THJDeliveryMode // 交割方式
  441. DeliveryMonth []THJDeliveryMonth // 交割月份
  442. PresaleApplyDeposits []THJPresaleApplyDeposit // 支付方式
  443. SpotGoodsPriceLogs []THJSpotGoodsPriceLog // 历史价格走势
  444. }
  445. // GetTHJWrstandardDetail 获取采购商品详情
  446. func (r *THJWrstandardDetailReq) GetTHJWrstandardDetail() (rsp *THJWrstandardDetailRsp, err error) {
  447. engine := db.GetEngine()
  448. // 采购商品信息
  449. goodsInfo := new(THJWrstandardDetail_GoodsInfo)
  450. sql := fmt.Sprintf(`
  451. select
  452. t.WRSTANDARDID,
  453. t.WRSTANDARDCODE,
  454. t.WRSTANDARDNAME,
  455. t.PICTUREURLS,
  456. p.SPOTGOODSPRICE
  457. from wrstandard t
  458. left join ERMCP_SpotGoodsPrice p on t.WRSTANDARDID = p.WRSTANDARDID and p.spotgoodsbrandid=0 and p.currencyid = 1
  459. where t.WRSTANDARDID = %v
  460. `, r.WRSTANDARDID)
  461. if _, err = engine.SQL(sql).Get(goodsInfo); err != nil {
  462. return
  463. }
  464. rsp.GoodsInfo = *goodsInfo
  465. // 交割方式
  466. deliveryModes := make([]THJDeliveryMode, 0)
  467. sql = `
  468. select
  469. t.ENUMDICNAME,
  470. t.ENUMITEMNAME
  471. from enumdicitem t
  472. where t.enumdiccode = 'THJDeliveryMode';
  473. `
  474. if err = engine.SQL(sql).Find(&deliveryModes); err != nil {
  475. return
  476. }
  477. rsp.DeliveryModes = deliveryModes
  478. // 交割月份
  479. deliveryMonths := make([]THJDeliveryMonth, 0)
  480. sql = fmt.Sprintf(`
  481. select
  482. t.PRESALEAPPLYID,
  483. to_char(t.ENDDATE, 'yyyy-mm') ENDMONTH,
  484. to_char(t.ENDDATE, 'yyyy-mm-dd') ENDDATE,
  485. t.ORDERQTY,
  486. t.TRADEQTY,
  487. (od.orderqty - od.tradeqty) REMAINQTY
  488. from WR_PresaleInfo t
  489. inner join wrtrade_orderdetail od on t.sellwrtradeorderid = od.wrtradeorderid
  490. where t.wrstandardid = %v
  491. and t.presalestatus = 2
  492. and od.wrtradeorderstatus in (3, 7)
  493. and (od.orderqty - od.tradeqty) > 0
  494. `, r.WRSTANDARDID)
  495. if err = engine.SQL(sql).Find(&deliveryMonths); err != nil {
  496. return
  497. }
  498. rsp.DeliveryMonth = deliveryMonths
  499. // 支付方式
  500. ids := make([]string, 0)
  501. for _, item := range deliveryMonths {
  502. ids = append(ids, strconv.Itoa(int(item.PRESALEAPPLYID)))
  503. }
  504. if len(ids) > 0 {
  505. presaleApplyDeposits := make([]THJPresaleApplyDeposit, 0)
  506. sql = fmt.Sprintf(`
  507. select
  508. t.DEPOSITRATE,
  509. t.DISCOUNTAMOUNT
  510. from THJ_PresaleApplyDeposit t
  511. where t.presaleapplyid in (%v)
  512. `, strings.Join(ids, ","))
  513. if err = engine.SQL(sql).Find(&presaleApplyDeposits); err != nil {
  514. return
  515. }
  516. rsp.PresaleApplyDeposits = presaleApplyDeposits
  517. }
  518. // 历史价格走势
  519. spotGoodsPriceLogs := make([]THJSpotGoodsPriceLog, 0)
  520. sql = fmt.Sprintf(`
  521. select
  522. t.SPOTGOODSPRICE,
  523. t.TRADEDATE
  524. from ERMCP_SpotGoodsPriceLog t
  525. where t.wrstandardid = %v
  526. order by t.operatetime
  527. `, r.WRSTANDARDID)
  528. if err = engine.SQL(sql).Find(&spotGoodsPriceLogs); err != nil {
  529. return
  530. }
  531. rsp.SpotGoodsPriceLogs = spotGoodsPriceLogs
  532. return
  533. }