wrTrade2.go 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566
  1. /**
  2. * @Author: zou.yingbin
  3. * @Create : 2021/7/20 18:31
  4. * @Modify : 2021/7/20 18:31
  5. */
  6. package models
  7. import (
  8. "fmt"
  9. "mtp2_if/db"
  10. "mtp2_if/utils"
  11. "strings"
  12. )
  13. // WrOrderQuote 买卖大厅行情
  14. type WrOrderQuote struct {
  15. WRFACTORTYPEID string `json:"wrfactortypeid" xorm:"'WRFACTORTYPEID'" form:"wrfactortypeid"` // 仓单要素id
  16. BUYPRICE float64 `json:"buyprice" xorm:"'BUYPRICE'"` // 买价
  17. BUYQTY float64 `json:"buyqty" xorm:"'BUYQTY'"` // 买量
  18. SELLPRICE float64 `json:"sellprice" xorm:"'SELLPRICE'"` // 卖价
  19. SELLQTY float64 `json:"sellqty" xorm:"'SELLQTY'"` // 卖量
  20. WRFACTORTYPENAME string `json:"wrfactortypename" xorm:"'WRFACTORTYPENAME'"` // 仓单要素类型名称(选择项要素的名称合并显示,逗号分隔)
  21. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 品种id
  22. WRSTANDARDID int32 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 商品id
  23. WAREHOUSEID int32 `json:"warehouseid" xorm:"'WAREHOUSEID'" form:"warehouseid"` // 仓库id
  24. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 品种名称
  25. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 品种代码
  26. WAREHOUSENAME string `json:"warehousename" xorm:"'WAREHOUSENAME'"` // 仓库名称
  27. WAREHOUSECODE string `json:"warehousecode" xorm:"'WAREHOUSECODE'"` // 仓库代码
  28. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'" form:"wrstandardname"` // 商品名称
  29. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 商品代码
  30. WRGOODSNAME string `json:"wrgoodsname" xorm:"'WRGOODSNAME'"` // 商品(商品名称+仓库要素名称 拼接)
  31. BUYPRICEMOVE float64 `json:"buypricemove" xorm:"'BUYPRICEMOVE'"` // 买升贴水(基差)
  32. SELLPRICEMOVE float64 `json:"sellpricemove" xorm:"'SELLPRICEMOVE'"` // 卖升贴水(基差)
  33. GOODSID int32 `json:"goodsid" xorm:"'GOODSID'"` // 商品id(浮动价列表才有)
  34. GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品合约(浮动价列表才有)
  35. DELIVERYMONTH string `json:"deliverymonth" xorm:"'DELIVERYMONTH'"` // 交收月
  36. ENUMDICNAME string `json:"enumdicname" xorm:"'enumdicname'"` // 单位名称
  37. PageEx `xorm:"extends"` // 页码信息
  38. HasWr int32 `json:"-" form:"haswr"` // 是否有仓单 0-没有 1-有
  39. WrPriceType int32 `json:"-" form:"wrpricetype"` // 价格方式 - 1:固定价 2-浮动价 - [挂牌]
  40. MarketId int32 `json:"-" form:"marketid"` // 市场id
  41. BRANDNAME string `json:"-" form:"brandname"` // 品牌名称
  42. }
  43. func (r *WrOrderQuote) calc() {
  44. r.WRGOODSNAME = strings.ReplaceAll(r.WRGOODSNAME, ",", "-")
  45. }
  46. // buildSqlFixedPrice 一口价
  47. func (r *WrOrderQuote) buildSqlFixedPrice() string {
  48. var sqlId utils.SQLVal = "with buyQuote as" +
  49. " (" +
  50. " select to_char(a.wrfactortypeid) wrfactortypeid, a.fixedprice buyPrice, sum(a.orderqty) buyQty" +
  51. " from (select t.wrfactortypeid," +
  52. " t.marketid," +
  53. " t.buyorsell," +
  54. " t.orderqty - t.tradeqty as orderqty," +
  55. " t.fixedprice," +
  56. " rank() over(partition by t.wrfactortypeid order by t.fixedprice desc) cnt" +
  57. " from wrtrade_orderdetail t" +
  58. " where t.wrtradetype = 1 and t.buyorsell = 0 and t.wrtradeorderstatus in(3,10) %v" +
  59. " ) a" +
  60. " where a.cnt = 1" +
  61. " group by a.wrfactortypeid, a.fixedprice)," +
  62. "sellQuote as" +
  63. " (" +
  64. " select to_char(a.wrfactortypeid) wrfactortypeid, a.fixedprice sellPrice, sum(a.orderqty) sellQty" +
  65. " from (select t.wrfactortypeid," +
  66. " t.marketid," +
  67. " t.buyorsell," +
  68. " t.orderqty - t.tradeqty as orderqty," +
  69. " t.fixedprice," +
  70. " rank() over(partition by t.wrfactortypeid order by t.fixedprice asc) cnt" +
  71. " from wrtrade_orderdetail t" +
  72. " where t.wrtradetype = 1 and t.buyorsell = 1 and t.wrtradeorderstatus in(3,10) %v " +
  73. " ) a" +
  74. " where a.cnt = 1" +
  75. " group by a.wrfactortypeid, a.fixedprice)," +
  76. "wrQuote as (" +
  77. " select nvl(k1.wrfactortypeid, k2.wrfactortypeid) wrfactortypeid," +
  78. " k1.buyPrice," +
  79. " k1.buyQty," +
  80. " k2.sellPrice," +
  81. " k2.sellQty" +
  82. " from buyQuote k1" +
  83. " full join sellQuote k2" +
  84. " on k1.wrfactortypeid = k2.wrfactortypeid" +
  85. ")" +
  86. "select k.*," +
  87. " w.wrfactortypename," +
  88. " w.deliverygoodsid," +
  89. " w.wrstandardid," +
  90. " w.warehouseid," +
  91. " dg.deliverygoodsname," +
  92. " dg.deliverygoodscode," +
  93. " h.warehousename," +
  94. " h.warehousecode," +
  95. " wg.wrstandardname," +
  96. " wg.wrstandardcode," +
  97. " wg.wrstandardname || w.wrfactortypename2 as wrgoodsname," +
  98. " e.enumdicname" +
  99. " from wrQuote k" +
  100. " left join WRFactorType w" +
  101. " on k.wrfactortypeid = w.wrfactortypeid" +
  102. " left join deliverygoods dg" +
  103. " on w.deliverygoodsid = dg.deliverygoodsid" +
  104. " left join wrstandard wg" +
  105. " on w.wrstandardid = wg.wrstandardid" +
  106. " left join warehouseinfo h" +
  107. " on w.warehouseid = h.autoid" +
  108. " left join enumdicitem e" +
  109. " on e.enumitemname = wg.unitid" +
  110. " and e.enumdiccode = 'goodsunit'" +
  111. " where 1=1 %v " +
  112. "order by deliverygoodsname"
  113. var param, param2 utils.SQLVal
  114. param.And("t.haswr", r.HasWr)
  115. param.And("t.wrpricetype", r.WrPriceType)
  116. param.AndEx("t.marketid", r.MarketId, r.MarketId > 0)
  117. param2.AndLike("w.wrfactortypename", r.WRSTANDARDNAME)
  118. param2.AndLike("w.wrfactortypename", r.BRANDNAME)
  119. param2.AndEx("w.warehouseid", r.WAREHOUSEID, r.WAREHOUSEID > 0)
  120. param2.AndEx("w.deliverygoodsid", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0)
  121. sqlId.FormatParam(param.String(), param.String(), param2.String())
  122. sqlId.Page(r.Page, r.PageSize)
  123. return sqlId.String()
  124. }
  125. // buildSqlPriceMove 浮动价
  126. func (r *WrOrderQuote) buildSqlPriceMove() string {
  127. var sqlId utils.SQLVal = "with buyQuote as" +
  128. " (select to_char(a.wrfactortypeid) wrfactortypeid," +
  129. " a.pricemove buypricemove," +
  130. " sum(a.orderqty) buyQty," +
  131. " a.goodsid," +
  132. " a.goodscode," +
  133. " a.deliverymonth" +
  134. " from (select t.wrfactortypeid," +
  135. " t.marketid," +
  136. " t.buyorsell," +
  137. " t.orderqty - t.tradeqty as orderqty," +
  138. " t.pricemove," +
  139. " t.wrtradeorderid," +
  140. " t.deliverymonth," +
  141. " c.goodsid," +
  142. " c.goodscode," +
  143. " rank() over(partition by t.wrfactortypeid, nvl(t.deliverymonth,'0'), c.goodsid order by t.pricemove desc) cnt" +
  144. " from wrtrade_orderdetail t" +
  145. " left join WRTrade_GoodsConfig c" +
  146. " on t.wrtradeorderid = c.wrtradeorderid" +
  147. " where t.wrtradetype = 1 and t.wrtradeorderstatus in(3,10)" +
  148. " and t.buyorsell = 0 %v) a" +
  149. " where a.cnt = 1" +
  150. " group by a.wrfactortypeid, a.pricemove, a.goodsid, a.goodscode, a.deliverymonth)," +
  151. "sellQuote as" +
  152. " (select to_char(a.wrfactortypeid) wrfactortypeid," +
  153. " a.pricemove sellpricemove," +
  154. " a.goodsid," +
  155. " a.goodscode," +
  156. " a.deliverymonth," +
  157. " sum(a.orderqty) sellQty" +
  158. " from (select t.wrfactortypeid," +
  159. " t.marketid," +
  160. " t.buyorsell," +
  161. " t.orderqty - t.tradeqty as orderqty," +
  162. " t.pricemove," +
  163. " t.deliverymonth," +
  164. " c.goodsid," +
  165. " c.goodscode," +
  166. " rank() over(partition by t.wrfactortypeid, nvl(t.deliverymonth,'0'), c.goodsid order by t.pricemove asc) cnt" +
  167. " from wrtrade_orderdetail t" +
  168. " left join WRTrade_GoodsConfig c" +
  169. " on t.wrtradeorderid = c.wrtradeorderid" +
  170. " where t.wrtradetype = 1 and t.wrtradeorderstatus in(3,10)" +
  171. " and t.buyorsell = 1 %v) a" +
  172. " where a.cnt = 1" +
  173. " group by a.wrfactortypeid, a.pricemove, a.goodsid, a.goodscode, a.deliverymonth)," +
  174. "wrQuote as" +
  175. " (select nvl(k1.wrfactortypeid, k2.wrfactortypeid) wrfactortypeid," +
  176. " nvl(k1.goodsid, k2.goodsid) goodsid," +
  177. " nvl(k1.goodscode, k2.goodscode) goodscode," +
  178. " nvl(k1.deliverymonth, k2.deliverymonth) deliverymonth," +
  179. " k1.buypricemove," +
  180. " k1.buyQty," +
  181. " k2.sellpricemove," +
  182. " k2.sellQty" +
  183. " from buyQuote k1" +
  184. " full join sellQuote k2" +
  185. " on k1.wrfactortypeid = k2.wrfactortypeid and k1.deliverymonth = k2.deliverymonth)" +
  186. "select k.*," +
  187. " w.wrfactortypename," +
  188. " w.deliverygoodsid," +
  189. " w.wrstandardid," +
  190. " w.warehouseid," +
  191. " dg.deliverygoodsname," +
  192. " dg.deliverygoodscode," +
  193. " h.warehousename," +
  194. " h.warehousecode," +
  195. " wg.wrstandardname," +
  196. " wg.wrstandardcode," +
  197. " wg.wrstandardname || w.wrfactortypename2 as wrgoodsname," +
  198. " e.enumdicname" +
  199. " from wrQuote k" +
  200. " left join WRFactorType w" +
  201. " on k.wrfactortypeid = w.wrfactortypeid" +
  202. " left join deliverygoods dg" +
  203. " on w.deliverygoodsid = dg.deliverygoodsid" +
  204. " left join wrstandard wg" +
  205. " on w.wrstandardid = wg.wrstandardid" +
  206. " left join warehouseinfo h" +
  207. " on w.warehouseid = h.autoid" +
  208. " left join enumdicitem e" +
  209. " on e.enumitemname = wg.unitid" +
  210. " and e.enumdiccode = 'goodsunit'" +
  211. " where 1 = 1 %v" +
  212. " order by deliverygoodsname"
  213. var param, param2 utils.SQLVal
  214. param.And("t.haswr", r.HasWr)
  215. param.And("t.wrpricetype", r.WrPriceType)
  216. param.AndEx("t.marketid", r.MarketId, r.MarketId > 0)
  217. param2.AndLike("w.wrfactortypename", r.WRSTANDARDNAME)
  218. param2.AndLike("w.wrfactortypename", r.BRANDNAME)
  219. param2.AndEx("w.warehouseid", r.WAREHOUSEID, r.WAREHOUSEID > 0)
  220. sqlId.FormatParam(param.String(), param.String(), param2.String())
  221. sqlId.Page(r.Page, r.PageSize)
  222. return sqlId.String()
  223. }
  224. func (r *WrOrderQuote) buildSql() string {
  225. if r.WrPriceType == 1 {
  226. return r.buildSqlFixedPrice()
  227. } else {
  228. return r.buildSqlPriceMove()
  229. }
  230. }
  231. // GetDataByPage 获取买卖大厅行情
  232. func (r *WrOrderQuote) GetDataByPage() (interface{}, error, int, int, int) {
  233. sData := make([]WrOrderQuote, 0)
  234. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  235. total := 0
  236. for i := range sData {
  237. sData[i].calc()
  238. total = sData[i].Total
  239. }
  240. return sData, err, r.Page, r.PageSize, total
  241. }
  242. // WrOrderQuoteDetail 行情大厅明细(买卖大厅)
  243. type WrOrderQuoteDetail struct {
  244. WRTRADEORDERID string `json:"wrtradeorderid" xorm:"WRTRADEORDERID"` // 仓单贸易委托单ID(320+Unix秒时间戳(10位)+xxxxxx)
  245. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL" form:"buyorsell"` // 买卖 - 0:买 1:卖
  246. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 购买方(销售方)用户ID
  247. QTY float64 `json:"orderqty" xorm:"qty"` // 买(卖)量(=委托量-成交量)
  248. PRICE float64 `json:"fixedprice" xorm:"price"` // 买(卖)价
  249. PRICEMOVE float64 `json:"pricemove" xorm:"PRICEMOVE"` // 买(卖)升贴水- 基差
  250. USERNAME string `json:"username" xorm:"'USERNAME'"` // 购买方(销售方)
  251. ENUMDICNAME string `json:"enumdicname" xorm:"'enumdicname'"` // 单位名称
  252. PageEx `xorm:"extends"`
  253. WRFACTORTYPEID int64 `json:"-" form:"wrfactortypeid"` // 仓单要素id
  254. HasWr int32 `json:"-" form:"haswr"` // 是否有仓单 0-没有 1-有
  255. WrPriceType int32 `json:"-" form:"wrpricetype"` // 价格方式 - 1:固定价 2-浮动价 - [挂牌]
  256. MarketId int32 `json:"-" form:"marketid"` // 市场id
  257. GOODSID int32 `json:"-" form:"goodsid"` // 商品id
  258. }
  259. func (r *WrOrderQuoteDetail) calc() {
  260. }
  261. func (r *WrOrderQuoteDetail) buildSql() string {
  262. var sqlId utils.SQLVal = "select to_char(t.wrtradeorderid) wrtradeorderid," +
  263. " to_char(t.wrfactortypeid) wrfactortypeid," +
  264. " t.userid," +
  265. " t.orderqty - t.tradeqty as qty," +
  266. " t.fixedprice as price," +
  267. " t.pricemove," +
  268. " t.wrpricetype," +
  269. " t.buyorsell," +
  270. " u.accountname as username," +
  271. " c.goodsid," +
  272. " c.goodscode," +
  273. " e.enumdicname" +
  274. " from WRTRADE_ORDERDETAIL t" +
  275. " left join WRTRADE_GOODSCONFIG c" +
  276. " on t.wrtradeorderid = c.wrtradeorderid" +
  277. " left join Useraccount u" +
  278. " on t.userid = u.userid" +
  279. " left join wrfactortype w on t.wrfactortypeid=w.wrfactortypeid" +
  280. " left join wrstandard wd on w.wrstandardid=wd.wrstandardid" +
  281. " left join enumdicitem e on wd.unitid=e.enumitemname and e.enumdiccode='goodsunit'" +
  282. " where 1 = 1" +
  283. " and t.wrtradetype = 1" +
  284. " and t.wrtradeorderstatus in (3, 10)"
  285. sqlId.And("t.haswr", r.HasWr)
  286. sqlId.And("t.wrpricetype", r.WrPriceType)
  287. sqlId.And("t.wrfactortypeid", r.WRFACTORTYPEID)
  288. sqlId.AndEx("c.goodsid", r.GOODSID, r.GOODSID > 0)
  289. sqlId.And("t.buyorsell", r.BUYORSELL)
  290. sqlId.AndEx("t.marketid", r.MarketId, r.MarketId > 0)
  291. if r.BUYORSELL == 0 {
  292. if r.WrPriceType == 1 {
  293. sqlId.Join(" order by t.fixedprice desc")
  294. } else {
  295. sqlId.Join(" order by t.pricemove desc")
  296. }
  297. } else {
  298. if r.WrPriceType == 1 {
  299. sqlId.Join(" order by t.fixedprice asc")
  300. } else {
  301. sqlId.Join(" order by t.pricemove asc")
  302. }
  303. }
  304. sqlId.Page(r.Page, r.PageSize)
  305. return sqlId.String()
  306. }
  307. // GetDataByPage 获取行情大厅明细(买卖大厅)
  308. func (r *WrOrderQuoteDetail) GetDataByPage() (interface{}, error, int, int, int) {
  309. sData := make([]WrOrderQuoteDetail, 0)
  310. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  311. total := 0
  312. for i := range sData {
  313. sData[i].calc()
  314. total = sData[i].Total
  315. }
  316. return sData, err, r.Page, r.PageSize, total
  317. }
  318. // Wr2FactorType 仓单要素类型
  319. type Wr2FactorType struct {
  320. WRFACTORTYPEID string `json:"wrfactortypeid" xorm:"WRFACTORTYPEID" form:"wrfactortypeid"` // 仓单要素类型ID(212+Unix秒时间戳(10位)+xxxxxx)
  321. WRFACTORTYPENAME string `json:"wrfactortypename" xorm:"WRFACTORTYPENAME" form:"wrfactortypename"` // 仓单要素类型名称(选择项要素的名称合并显示,逗号分隔)
  322. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID" form:"deliverygoodsid"` // 品种ID
  323. WAREHOUSEID int64 `json:"warehouseid" xorm:"WAREHOUSEID" form:"warehouseid"` // 仓库ID
  324. WRSTANDARDID int64 `json:"wrstandardid" xorm:"WRSTANDARDID" form:"wrstandardid"` // 现货商品ID
  325. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"WRSTANDARDCODE" form:"wrstandardcode"` // 现货商品代码
  326. OPTIONCOMPARE string `json:"optioncompare" xorm:"OPTIONCOMPARE" form:"optioncompare"` // 选择项比较串【{选择项ID}+{冒号}+选择项值 } ,逗号分隔,头尾加逗号】-- 所有选择项拼接,用于比较
  327. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 商品名称
  328. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 品种代码
  329. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 品种名称
  330. ENUMDICNAME string `json:"enumdicname" xorm:"'enumdicname'"` // 单位名称
  331. WAREHOUSENAME string `json:"warehousename" xorm:"'WAREHOUSENAME'"` // 仓库名称
  332. WRTYPENAME string `json:"wrtypename" xorm:"'WRTYPENAME'"` // 商品
  333. }
  334. // Calc
  335. func (r *Wr2FactorType) Calc() {
  336. if r.WRTYPENAME == "" {
  337. if len(r.WRFACTORTYPENAME) > 0 {
  338. r.WRTYPENAME = r.WRSTANDARDNAME + r.WRFACTORTYPENAME
  339. } else {
  340. r.WRTYPENAME = r.WRSTANDARDNAME
  341. }
  342. }
  343. r.WRTYPENAME = strings.ReplaceAll(r.WRTYPENAME, ",", "-")
  344. }
  345. // WrPosition 仓单贸易持仓汇总
  346. type WrPosition struct {
  347. WRPOSITIONID string `json:"wrpositionid" xorm:"WRPOSITIONID" form:"wrpositionid"` // 仓单头寸ID(201+Unix秒时间戳(10位)+xxxxxx)
  348. WRUSERID int64 `json:"wruserid" xorm:"WRUSERID" form:"userid"` // 持有人ID
  349. TOTALQTY float64 `json:"totalqty" xorm:"TOTALQTY" form:"totalqty"` // 总数量(库存数量)
  350. INCREASEQTY float64 `json:"-" xorm:"INCREASEQTY" form:"increaseqty"` // 今日增加数量
  351. DECREASEQTY float64 `json:"-" xorm:"DECREASEQTY" form:"decreaseqty"` // 今日减少数量
  352. FREEZEQTY float64 `json:"freezeqty" xorm:"FREEZEQTY" form:"freezeqty"` // 总冻结数量
  353. RELATEDQTY float64 `json:"-" xorm:"RELATEDQTY" form:"relatedqty"` // 关联数量
  354. MODIFYTIME string `json:"modifytime" xorm:"MODIFYTIME" form:"modifytime"` // 修改时间(过户时间)
  355. MODIFIERID int64 `json:"-" xorm:"MODIFIERID" form:"modifierid"` // 修改人
  356. TRADEWRQTY float64 `json:"-" xorm:"TRADEWRQTY" form:"tradewrqty"` // 订单仓单头寸总数量
  357. ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID" form:"accountid"` // 帐户ID
  358. CREDITTOTALQTY float64 `json:"credittotalqty" xorm:"CREDITTOTALQTY" form:"credittotalqty"` // 授信总数量(预售仓单:预售总量)
  359. CREDITCURQTY float64 `json:"creditcurqty" xorm:"CREDITCURQTY" form:"creditcurqty"` // 授信当前数量(预售仓单:预售当前量)
  360. CREDITFREEZEQTY float64 `json:"creditfreezeqty" xorm:"CREDITFREEZEQTY" form:"creditfreezeqty"` // 授信冻结数量(预售仓单: 当前数量)
  361. CREDITTRADEQTY float64 `json:"credittradeqty" xorm:"CREDITTRADEQTY" form:"credittradeqty"` // 授信成交数量(预售仓单:成交总量)
  362. Wr2FactorType `xorm:"extends"`
  363. ENALBEQTY float64 `json:"enalbeqty" xorm:"'ENALBEQTY'"` // 可用数量
  364. CREDITENABLEQTY float64 `json:"creditenableqty" xorm:"'CREDITENABLEQTY'"` // 授信可用数量(预售仓单: 可用数量)
  365. PLEDGEQTY float64 `json:"pledgeqty" xorm:"'-'"` // 质押数量
  366. BUYEXCUTEQTY float64 `json:"buyexcuteqty"` // 采购履约中数量
  367. SELLEXCUTEQTY float64 `json:"sellexcuteqty"` // 销售履约中数量
  368. WRPOSITIONNO string `json:"wrpositionno"` // 仓单编号
  369. QueryType int32 `json:"querytype" form:"querytype"` // 查询类型 1-现货汇总 2-库存汇总(订单汇总)
  370. HASWR int32 `json:"haswr" form:"haswr"` // 是否有仓单-卖方 - 0:无仓单 1:有仓单
  371. }
  372. func (r *WrPosition) calc() {
  373. r.ENALBEQTY = r.TOTALQTY - r.FREEZEQTY
  374. r.CREDITENABLEQTY = r.CREDITCURQTY - r.CREDITFREEZEQTY
  375. r.WRPOSITIONNO = fmt.Sprintf("%v", r.WRFACTORTYPEID)
  376. r.Wr2FactorType.Calc()
  377. }
  378. // 添加履约中数量
  379. func (r *WrPosition) addPerformancePlanQty(sum WrPerformanPlanSum) {
  380. if r.DELIVERYGOODSID == sum.DELIVERYGOODSID &&
  381. r.WRSTANDARDID == sum.WRSTANDARDID &&
  382. r.WRTYPENAME == sum.WRTYPENAME {
  383. if r.QueryType == 1 || (r.QueryType == 2 && r.WAREHOUSEID == sum.WAREHOUSEID) {
  384. if sum.BUYORSELL == 0 {
  385. r.BUYEXCUTEQTY = sum.QTY
  386. } else {
  387. r.SELLEXCUTEQTY = sum.QTY
  388. }
  389. }
  390. }
  391. }
  392. func (r *WrPosition) buildSql() string {
  393. if r.QueryType == 1 {
  394. // 现货汇总 品种 + 品类 + 其它要素, 根据品种汇总
  395. return r.buildSql1()
  396. } else if r.QueryType == 2 {
  397. // 库存汇总 品种 + 仓库 + 品类 + 其它要素, 即全维度
  398. return r.buildSql2()
  399. } else {
  400. // 现货明细 仓单编号 + 品种 + 仓库 + 仓单要素 即全维度 跟库存汇总一样
  401. return r.buildSql3()
  402. }
  403. }
  404. func (r *WrPosition) buildSql1() string {
  405. var sqlId utils.SQLVal = "with tmp as" +
  406. " (select t.*," +
  407. " w.wrstandardid," +
  408. " w.warehouseid," +
  409. " wd.wrstandardname," +
  410. " wd.wrstandardname || w.wrfactortypename2 as wrtypename" +
  411. " from WRPOSITION t" +
  412. " left join WRFACTORTYPE w" +
  413. " on t.wrfactortypeid = w.wrfactortypeid" +
  414. " left join wrstandard wd" +
  415. " on w.wrstandardid = wd.wrstandardid" +
  416. " where 1=1 %v)," +
  417. "hld as" +
  418. " (select k.deliverygoodsid," +
  419. " k.wrtypename," +
  420. " k.wrstandardid," +
  421. " sum(k.TOTALQTY) TOTALQTY," +
  422. " sum(k.INCREASEQTY) INCREASEQTY," +
  423. " sum(k.DECREASEQTY) DECREASEQTY," +
  424. " sum(k.FREEZEQTY) FREEZEQTY," +
  425. " sum(k.RELATEDQTY) RELATEDQTY," +
  426. " sum(k.TRADEWRQTY) TRADEWRQTY," +
  427. " sum(k.CREDITTOTALQTY) CREDITTOTALQTY," +
  428. " sum(k.CREDITCURQTY) CREDITCURQTY," +
  429. " sum(k.CREDITFREEZEQTY) CREDITFREEZEQTY," +
  430. " sum(k.CREDITTRADEQTY) CREDITTRADEQTY" +
  431. " from tmp k" +
  432. " where 1 = 1" +
  433. " group by k.deliverygoodsid, k.wrstandardname, k.wrtypename, k.wrstandardid)" +
  434. "select h.*, g.deliverygoodsname, g.deliverygoodscode, e.enumdicname" +
  435. " from hld h" +
  436. " left join deliverygoods g" +
  437. " on h.deliverygoodsid = g.deliverygoodsid" +
  438. " left join wrstandard wd" +
  439. " on h.wrstandardid = wd.wrstandardid" +
  440. " left join enumdicitem e" +
  441. " on e.enumitemname = wd.unitid" +
  442. " and e.enumdiccode = 'goodsunit'"
  443. var param utils.SQLVal
  444. param.And("t.wruserid", r.WRUSERID)
  445. if r.HASWR == 0 {
  446. param.Join(" and t.CREDITTOTALQTY > 0")
  447. } else {
  448. param.Join(" and t.TOTALQTY > 0")
  449. }
  450. sqlId.FormatParam(param.String())
  451. return sqlId.String()
  452. }
  453. func (r *WrPosition) buildSql2() string {
  454. return r.buildSql3()
  455. }
  456. func (r *WrPosition) buildSql3() string {
  457. var sqlId utils.SQLVal = "SELECT to_char(t.WRPOSITIONID) WRPOSITIONID," +
  458. " t.WRUSERID," +
  459. " t.TOTALQTY," +
  460. " t.INCREASEQTY," +
  461. " t.DECREASEQTY," +
  462. " t.FREEZEQTY," +
  463. " t.RELATEDQTY," +
  464. " to_char(t.MODIFYTIME, 'yyyy-mm-dd hh24:mi:ss') MODIFYTIME," +
  465. " t.MODIFIERID," +
  466. " t.TRADEWRQTY," +
  467. " t.ACCOUNTID," +
  468. " t.CREDITTOTALQTY," +
  469. " t.CREDITCURQTY," +
  470. " t.CREDITFREEZEQTY," +
  471. " t.CREDITTRADEQTY," +
  472. " to_char(w.WRFACTORTYPEID) WRFACTORTYPEID," +
  473. " w.WRFACTORTYPENAME2 WRFACTORTYPENAME," +
  474. " w.DELIVERYGOODSID," +
  475. " w.WAREHOUSEID," +
  476. " w.WRSTANDARDID," +
  477. " w.WRSTANDARDCODE," +
  478. " w.OPTIONCOMPARE," +
  479. " dg.deliverygoodscode," +
  480. " dg.deliverygoodsname," +
  481. " wd.wrstandardcode," +
  482. " wd.wrstandardname," +
  483. " h.warehousecode," +
  484. " h.warehousename," +
  485. " e.enumdicname" +
  486. " FROM WRPOSITION t" +
  487. " LEFT JOIN WRFACTORTYPE w" +
  488. " on t.wrfactortypeid = w.wrfactortypeid" +
  489. " LEFT JOIN DELIVERYGOODS dg" +
  490. " on t.deliverygoodsid = dg.deliverygoodsid" +
  491. " LEFT JOIN WRSTANDARD wd" +
  492. " on w.wrstandardid = wd.wrstandardid" +
  493. " left join warehouseinfo h on w.warehouseid=h.autoid" +
  494. " left join enumdicitem e" +
  495. " on e.enumitemname = wd.unitid" +
  496. " and e.enumdiccode = 'goodsunit'" +
  497. " WHERE 1 = 1"
  498. sqlId.And("t.WRUSERID", r.WRUSERID)
  499. if r.HASWR == 0 {
  500. sqlId.Join(" and t.CREDITTOTALQTY > 0")
  501. } else {
  502. sqlId.Join(" and t.TOTALQTY > 0")
  503. }
  504. return sqlId.String()
  505. }
  506. // GetDataEx 获取仓单贸易持仓汇总
  507. func (r *WrPosition) GetDataEx() (interface{}, error) {
  508. sData := make([]WrPosition, 0)
  509. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  510. for i := range sData {
  511. sData[i].calc()
  512. sData[i].QueryType = r.QueryType
  513. sData[i].HASWR = r.HASWR
  514. }
  515. // 查履约中的数量
  516. if len(sData) > 0 {
  517. if r.QueryType == 1 || r.QueryType == 2 {
  518. m := WrPerformanPlanSum{QueryType: r.QueryType, USERID: r.WRUSERID}
  519. if d, err := m.GetData(); err == nil {
  520. for i := range sData {
  521. for _, sum := range d {
  522. sData[i].addPerformancePlanQty(sum)
  523. }
  524. }
  525. }
  526. }
  527. }
  528. return sData, err
  529. }
  530. // WrOrderDetail 仓单贸易委托单
  531. type WrOrderDetail struct {
  532. HASWR int32 `json:"haswr" xorm:"HASWR" form:"haswr"` // 是否有仓单-卖方 - 0:无仓单 1:有仓单
  533. WRTRADEORDERID string `json:"wrtradeorderid" xorm:"WRTRADEORDERID"` // 仓单贸易委托单ID(320+Unix秒时间戳(10位)+xxxxxx)
  534. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE" form:"tradedate"` // 交易日(yyyyMMdd)
  535. WRTRADETYPE int32 `json:"wrtradetype" xorm:"WRTRADETYPE" form:"wrtradetype"` // 仓单贸易类型 - 1:挂牌 2:摘牌 3:提货卖(文化中国) 4:提货买(文化中国)
  536. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL" form:"buyorsell"` // 买卖 - 0:买 1:卖(挂牌类型 买为采购 卖为销售)
  537. MARKETID int64 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID
  538. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 用户ID
  539. WRFACTORTYPEID string `json:"wrfactortypeid" xorm:"WRFACTORTYPEID"` // 仓单要素类型ID/商品ID(77)
  540. ORDERQTY float64 `json:"orderqty" xorm:"ORDERQTY" form:"orderqty"` // 委托数量
  541. TRADEQTY float64 `json:"tradeqty" xorm:"TRADEQTY" form:"tradeqty"` // 成交数量
  542. CANCELQTY float64 `json:"cancelqty" xorm:"CANCELQTY" form:"cancelqty"` // 撤销数量
  543. WRPRICETYPE int32 `json:"wrpricetype" xorm:"WRPRICETYPE" form:"wrpricetype"` // 价格方式 - 1:固定价 2-浮动价 - [挂牌]
  544. FIXEDPRICE float64 `json:"fixedprice" xorm:"FIXEDPRICE" form:"fixedprice"` // 固定价格 - [挂牌]
  545. PRICEMOVE float64 `json:"pricemove" xorm:"PRICEMOVE" form:"pricemove"` // 升贴水(浮动价时填写) - [挂牌]
  546. TRADEPRICE float64 `json:"tradeprice" xorm:"TRADEPRICE" form:"tradeprice"` // 成交价格 - [摘牌] (浮动价 ((商品1价格*商品1价格系数+升贴水)* 商品1重量系数 + 商品2价格*商品2价格系数+商品2升贴水)* 商品2重量系数 ...)* 委托单价格系数 + 委托单升贴水)
  547. ORDERTIME string `json:"ordertime" xorm:"ORDERTIME" form:"ordertime"` // 委托时间(挂牌时间)
  548. WRTRADEORDERSTATUS int32 `json:"wrtradeorderstatus" xorm:"WRTRADEORDERSTATUS"` // 委托状态 - 1:委托请求 2:待冻结 3:委托成功 4:委托失败 5:配对成功 6:已撤 7:已成 8:成交失败 9:委托拒绝 10:挂牌部分成交 11:仓单生成失败 12:首付扣款失败 13:履约失败 14:撤单解冻贷款失败 15:部成部撤
  549. GOODSID int32 `json:"goodsid" xorm:"'GOODSID'"` // 期货商品id
  550. GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 期货合约
  551. FUTUPRICEMOVE float64 `json:"futupricemove" xorm:"'FUTUPRICEMOVE'"` // 期货升贴水
  552. DELIVERYMONTH string `json:"deliverymonth" xorm:"'DELIVERYMONTH'"` // 交收月
  553. Wr2FactorType `xorm:"extends"`
  554. PageEx `xorm:"extends"`
  555. FUTUSHOW string `json:"futushow"` // 期货合约/升贴水
  556. }
  557. func (r *WrOrderDetail) calc() {
  558. if r.GOODSCODE == "" {
  559. r.FUTUSHOW = "-"
  560. } else {
  561. r.FUTUSHOW = fmt.Sprintf("%v//%.2f", r.GOODSCODE, r.FUTUPRICEMOVE)
  562. }
  563. r.Wr2FactorType.Calc()
  564. }
  565. func (r *WrOrderDetail) buildSql() string {
  566. var sqlId utils.SQLVal = "with tmp as" +
  567. " (select to_char(t.wrfactortypeid) wrfactortypeid," +
  568. " t.wrfactortypename2 wrfactortypename," +
  569. " t.wrstandardid," +
  570. " t.deliverygoodsid," +
  571. " g.deliverygoodscode," +
  572. " g.deliverygoodsname," +
  573. " w.wrstandardcode," +
  574. " w.wrstandardname," +
  575. " h.warehousecode," +
  576. " h.warehousename," +
  577. " e.enumdicname," +
  578. " w.wrstandardname || t.wrfactortypename2 as wrtypename" +
  579. " from wrfactortype t" +
  580. " left join deliverygoods g" +
  581. " on t.deliverygoodsid = g.deliverygoodsid" +
  582. " left join wrstandard w" +
  583. " on t.wrstandardid = w.wrstandardid" +
  584. " left join warehouseinfo h" +
  585. " on t.warehouseid = h.autoid" +
  586. " left join enumdicitem e on w.unitid = e.enumitemname and e.enumdiccode='goodsunit')" +
  587. "select t.HASWR," +
  588. " to_char(t.WRTRADEORDERID) WRTRADEORDERID," +
  589. " t.TRADEDATE," +
  590. " t.DELIVERYMONTH," +
  591. " t.WRTRADETYPE," +
  592. " t.BUYORSELL," +
  593. " t.MARKETID," +
  594. " t.USERID," +
  595. " t.ORDERQTY," +
  596. " t.TRADEQTY," +
  597. " t.CANCELQTY," +
  598. " t.WRPRICETYPE," +
  599. " t.FIXEDPRICE," +
  600. " t.PRICEMOVE," +
  601. " t.TRADEPRICE," +
  602. " to_char(t.ORDERTIME,'yyyy-mm-dd hh24:mi:ss') ORDERTIME," +
  603. " t.WRTRADEORDERSTATUS," +
  604. " c.GOODSID," +
  605. " c.GOODSCODE," +
  606. " c.pricemove FUTUPRICEMOVE," +
  607. " k.*" +
  608. " from wrtrade_orderdetail t" +
  609. " left join wrtrade_goodsconfig c" +
  610. " on t.wrtradeorderid = c.wrtradeorderid" +
  611. " left join tmp k" +
  612. " on t.wrfactortypeid = k.wrfactortypeid" +
  613. " where t.WRTRADETYPE = 1 and t.isspecified=0"
  614. sqlId.And("t.USERID", r.USERID)
  615. sqlId.And("t.haswr", r.HASWR)
  616. sqlId.AndEx("t.marketid", r.MARKETID, r.MARKETID > 0)
  617. sqlId.Join(" order by t.ORDERTIME desc")
  618. sqlId.Page(r.Page, r.PageSize)
  619. return sqlId.String()
  620. }
  621. // GetDataByPage 获取仓单贸易委托单
  622. func (r *WrOrderDetail) GetDataByPage() (interface{}, error, int, int, int) {
  623. sData := make([]WrOrderDetail, 0)
  624. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  625. total := 0
  626. for i := range sData {
  627. sData[i].calc()
  628. total = sData[i].Total
  629. }
  630. return sData, err, r.Page, r.PageSize, total
  631. }
  632. // WrTradeDetail 仓单贸易成交明细
  633. type WrTradeDetail struct {
  634. HASWR int32 `json:"haswr" xorm:"HASWR" form:"haswr"` // 是否有仓单-卖方 - 0:无仓单 1:有仓单
  635. WRTRADEDETAILID string `json:"wrtradedetailid" xorm:"WRTRADEDETAILID"` // 仓单贸易成交单ID(321+Unix秒时间戳(10位)+xxxxxx)
  636. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE" form:"tradedate"` // 交易日(yyyyMMdd)
  637. WRTRADETYPE int32 `json:"wrtradetype" xorm:"WRTRADETYPE" form:"wrtradetype"` // 仓单贸易类型 - 1:挂牌 2:摘牌 3:提货卖(文化中国) 4:提货买(文化中国)
  638. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL" form:"buyorsell"` // 买卖 - 0:买 1:卖(挂牌类型 买为采购 卖为销售)
  639. MARKETID int64 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID
  640. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 用户ID
  641. WRFACTORTYPEID int64 `json:"wrfactortypeid" xorm:"WRFACTORTYPEID"` // 仓单要素类型ID/商品ID(77)
  642. TRADEQTY float64 `json:"tradeqty" xorm:"TRADEQTY" form:"tradeqty"` // 成交数量
  643. TRADEPRICE float64 `json:"tradeprice" xorm:"TRADEPRICE" form:"tradeprice"` // 成交价格
  644. TRADETIME string `json:"tradetime" xorm:"TRADETIME" form:"tradetime"` // 成交时间
  645. DELIVERYMONTH string `json:"deliverymonth" xorm:"'DELIVERYMONTH'"` // 交收月
  646. ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID"` // 资金账号
  647. MATCHACCOUNTID int64 `json:"matchaccountid" xorm:"MATCHACCOUNTID"` // 对手账号
  648. MATCHUSERNAME string `json:"matchusername" xorm:"'MATCHUSERNAME'"` // 对手方
  649. Wr2FactorType `xorm:"extends"`
  650. PageEx `xorm:"extends"`
  651. }
  652. func (r *WrTradeDetail) calc() {
  653. r.Wr2FactorType.Calc()
  654. }
  655. func (r *WrTradeDetail) buildSql() string {
  656. var sqlId utils.SQLVal = "with tmp as" +
  657. " (select to_char(t.wrfactortypeid) wrfactortypeid," +
  658. " t.wrfactortypename," +
  659. " t.wrstandardid," +
  660. " t.deliverygoodsid," +
  661. " g.deliverygoodscode," +
  662. " g.deliverygoodsname," +
  663. " w.wrstandardcode," +
  664. " w.wrstandardname," +
  665. " h.warehousecode," +
  666. " h.warehousename," +
  667. " e.enumdicname," +
  668. " w.wrstandardname || t.wrfactortypename2 as wrtypename" +
  669. " from wrfactortype t" +
  670. " left join deliverygoods g" +
  671. " on t.deliverygoodsid = g.deliverygoodsid" +
  672. " left join wrstandard w" +
  673. " on t.wrstandardid = w.wrstandardid" +
  674. " left join warehouseinfo h" +
  675. " on t.warehouseid = h.autoid" +
  676. " left join enumdicitem e on w.unitid = e.enumitemname and e.enumdiccode='goodsunit')" +
  677. "select t.HASWR," +
  678. " to_char(t.WRTRADEDETAILID) WRTRADEDETAILID," +
  679. " t.TRADEDATE," +
  680. " t.DELIVERYMONTH," +
  681. " t.WRTRADETYPE," +
  682. " t.BUYORSELL," +
  683. " t.MARKETID," +
  684. " t.TRADEQTY," +
  685. " t.TRADEPRICE," +
  686. " to_char(t.TRADETIME,'yyyy-mm-dd hh24:mi:ss') TRADETIME," +
  687. " u2.accountname matchusername," +
  688. " ta1.userid," +
  689. " k.*" +
  690. " from wrtrade_tradedetail t" +
  691. " left join tmp k" +
  692. " on t.wrfactortypeid = k.wrfactortypeid" +
  693. " left join taaccount ta1 on t.accountid=ta1.accountid" +
  694. " left join taaccount ta2 on t.matchaccountid=ta2.accountid" +
  695. " left join useraccount u2 on ta2.userid=u2.userid" +
  696. " where 1=1"
  697. sqlId.And("ta1.userid", r.USERID)
  698. sqlId.And("t.haswr", r.HASWR)
  699. sqlId.AndEx("t.marketid", r.MARKETID, r.MARKETID > 0)
  700. sqlId.Join(" order by t.tradetime desc")
  701. sqlId.Page(r.Page, r.PageSize)
  702. return sqlId.String()
  703. }
  704. // GetDataByPage 获取仓单贸易成交明细
  705. func (r *WrTradeDetail) GetDataByPage() (interface{}, error, int, int, int) {
  706. sData := make([]WrTradeDetail, 0)
  707. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  708. total := 0
  709. for i := range sData {
  710. sData[i].calc()
  711. total = sData[i].Total
  712. }
  713. return sData, err, r.Page, r.PageSize, total
  714. }
  715. // WrSpecialMatchOrder 指定对手委托
  716. type WrSpecialMatchOrder struct {
  717. HASWR int32 `json:"haswr" xorm:"HASWR" form:"haswr"` // 是否有仓单-卖方 - 0:无仓单 1:有仓单
  718. WRTRADEORDERID string `json:"wrtradeorderid" xorm:"WRTRADEORDERID"` // 仓单贸易委托单ID(320+Unix秒时间戳(10位)+xxxxxx)
  719. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE" form:"tradedate"` // 交易日(yyyyMMdd)
  720. WRTRADETYPE int32 `json:"wrtradetype" xorm:"WRTRADETYPE" form:"wrtradetype"` // 仓单贸易类型 - 1:挂牌 2:摘牌 3:提货卖(文化中国) 4:提货买(文化中国)
  721. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL" form:"buyorsell"` // 买卖 - 0:买 1:卖(挂牌类型 买为采购 卖为销售)
  722. MARKETID int64 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID
  723. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 用户ID
  724. WRFACTORTYPEID int64 `json:"wrfactortypeid" xorm:"WRFACTORTYPEID"` // 仓单要素类型ID/商品ID(77)
  725. ORDERQTY float64 `json:"orderqty" xorm:"ORDERQTY" form:"orderqty"` // 委托数量
  726. TRADEQTY float64 `json:"tradeqty" xorm:"TRADEQTY" form:"tradeqty"` // 成交数量
  727. CANCELQTY float64 `json:"cancelqty" xorm:"CANCELQTY" form:"cancelqty"` // 撤销数量
  728. WRPRICETYPE int32 `json:"wrpricetype" xorm:"WRPRICETYPE" form:"wrpricetype"` // 价格方式 - 1:固定价 2-浮动价 - [挂牌]
  729. FIXEDPRICE float64 `json:"fixedprice" xorm:"FIXEDPRICE" form:"fixedprice"` // 固定价格(价格)
  730. PRICEMOVE float64 `json:"pricemove" xorm:"PRICEMOVE" form:"pricemove"` // 升贴水(浮动价时填写) - [挂牌]
  731. TRADEPRICE float64 `json:"tradeprice" xorm:"TRADEPRICE" form:"tradeprice"` // 成交价格
  732. ORDERTIME string `json:"ordertime" xorm:"ORDERTIME" form:"ordertime"` // 委托时间
  733. WRTRADEORDERSTATUS int32 `json:"wrtradeorderstatus" xorm:"WRTRADEORDERSTATUS"` // 委托状态 - 1:委托请求 2:待冻结 3:委托成功 4:委托失败 5:配对成功 6:已撤 7:已成 8:成交失败 9:委托拒绝 10:挂牌部分成交 11:仓单生成失败 12:首付扣款失败 13:履约失败 14:撤单解冻贷款失败 15:部成部撤
  734. USERNAME string `json:"username" xorm:"'USERNAME'"` // 发起方
  735. MATCHUSERNAME string `json:"matchusername" xorm:"'MATCHUSERNAME'"` // 指定方
  736. MATCHUSERID int64 `json:"matchuserid" xorm:"'MATCHUSERID'"` // 指定方资金账号(字段名为userid,实际存的是accountid by:邓工)
  737. Wr2FactorType `xorm:"extends"`
  738. PageEx `xorm:"extends"`
  739. AMOUNT float64 `json:"amount"` // 金额 = 数量 * 价格
  740. }
  741. func (r *WrSpecialMatchOrder) calc() {
  742. r.AMOUNT = r.FIXEDPRICE * r.ORDERQTY
  743. r.Wr2FactorType.Calc()
  744. }
  745. func (r *WrSpecialMatchOrder) buildSql() string {
  746. var sqlId utils.SQLVal = "with tmp as" +
  747. " (select t.wrfactortypeid," +
  748. " t.wrfactortypename2 wrfactortypename," +
  749. " t.wrstandardid," +
  750. " t.deliverygoodsid," +
  751. " g.deliverygoodscode," +
  752. " g.deliverygoodsname," +
  753. " w.wrstandardcode," +
  754. " w.wrstandardname," +
  755. " h.warehousecode," +
  756. " h.warehousename," +
  757. " e.enumdicname," +
  758. " w.wrstandardname || t.wrfactortypename2 as wrtypename" +
  759. " from wrfactortype t" +
  760. " left join deliverygoods g" +
  761. " on t.deliverygoodsid = g.deliverygoodsid" +
  762. " left join wrstandard w" +
  763. " on t.wrstandardid = w.wrstandardid" +
  764. " left join warehouseinfo h" +
  765. " on t.warehouseid = h.autoid" +
  766. " left join enumdicitem e" +
  767. " on w.unitid = e.enumitemname" +
  768. " and e.enumdiccode = 'goodsunit')" +
  769. "select t.HASWR," +
  770. " to_char(t.WRTRADEORDERID) WRTRADEORDERID," +
  771. " t.WRTRADETYPE," +
  772. " t.BUYORSELL," +
  773. " t.MARKETID," +
  774. " t.USERID," +
  775. " t.ORDERQTY," +
  776. " t.TRADEQTY," +
  777. " t.CANCELQTY," +
  778. " t.WRPRICETYPE," +
  779. " t.FIXEDPRICE," +
  780. " t.PRICEMOVE," +
  781. " t.TRADEPRICE," +
  782. " to_char(t.ORDERTIME, 'yyyy-mm-dd hh24:mi:ss') ORDERTIME," +
  783. " t.WRTRADEORDERSTATUS," +
  784. " m.matchuserid," +
  785. " u1.accountname username," +
  786. " u2.accountname matchusername," +
  787. " k.*" +
  788. " from wrtrade_orderdetail t" +
  789. " left join WRTrade_MatchDetail m on t.wrtradeorderid=m.wrtradeorderid" +
  790. " left join useraccount u1 on t.userid=u1.userid" +
  791. " left join taaccount ta2 on m.matchuserid=ta2.accountid" +
  792. " left join useraccount u2 on ta2.userid=u2.userid" +
  793. " left join tmp k" +
  794. " on t.wrfactortypeid = k.wrfactortypeid" +
  795. " where t.WRTRADETYPE = 1" +
  796. " and t.isspecified = 1" +
  797. " and t.WRTRADEORDERSTATUS = 3"
  798. sqlId.And("t.USERID", r.USERID)
  799. sqlId.And("t.haswr", r.HASWR)
  800. sqlId.AndEx("t.marketid", r.MARKETID, r.MARKETID > 0)
  801. sqlId.Join(" order by t.ORDERTIME desc")
  802. sqlId.Page(r.Page, r.PageSize)
  803. return sqlId.String()
  804. }
  805. // GetDataEx 获取指定对手委托
  806. func (r *WrSpecialMatchOrder) GetDataByPage() (interface{}, error, int, int, int) {
  807. sData := make([]WrSpecialMatchOrder, 0)
  808. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  809. total := 0
  810. for i := range sData {
  811. sData[i].calc()
  812. total = sData[i].Total
  813. }
  814. return sData, err, r.Page, r.PageSize, total
  815. }
  816. // WrFactorTypeInfo 仓单要素选择项
  817. type WrFactorTypeInfo struct {
  818. WRFACTORTYPEID string `json:"wrfactortypeid" xorm:"'WRFACTORTYPEID'" form:"wrfactortypeid"` // 仓单要素ID
  819. DGFACTORYITEMTYPEID int64 `json:"dgfactoryitemtypeid" xorm:"'DGFACTORYITEMTYPEID'"` // 要素选择项ID (1-仓库 2-品牌)
  820. ITEMTYPENAME string `json:"itemtypename" xorm:"'ITEMTYPENAME'"` // 要素项名称
  821. DGFACTORYITEMVALUE string `json:"dgfactoryitemvalue" xorm:"'DGFACTORYITEMVALUE'"` // 要素项值
  822. OPTIONCOMPARE string `json:"optioncompare" xorm:"'OPTIONCOMPARE'"` // 选择比较串
  823. WAREHOUSEID int64 `json:"warehouseid" xorm:"'WAREHOUSEID'"` // 仓库id
  824. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 品种名称
  825. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 品种代码
  826. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品类代码
  827. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称
  828. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 品类id
  829. DGFACTORYITEMID int64 `json:"dgfactoryitemid" xorm:"'DGFACTORYITEMID'"` // 选择项id
  830. WRFACTORTYPENAME string `json:"wrfactortypename" xorm:"'WRFACTORTYPENAME'"` // 要素名称
  831. WRFACTORTYPENAME2 string `json:"wrfactortypename2" xorm:"'WRFACTORTYPENAME2'"` // 要素名称(不含仓库)
  832. }
  833. func (r *WrFactorTypeInfo) calc() {
  834. }
  835. func (r *WrFactorTypeInfo) buildSql() string {
  836. var sqlId utils.SQLVal = "select to_char(t.wrfactortypeid) wrfactortypeid," +
  837. " b.dgfactoryitemtypeid," +
  838. " b.itemtypename," +
  839. " c.dgfactoryitemvalue," +
  840. " t.optioncompare," +
  841. " t.warehouseid," +
  842. " t.wrstandardid," +
  843. " g.deliverygoodsname," +
  844. " g.deliverygoodscode," +
  845. " w.wrstandardcode," +
  846. " w.wrstandardname," +
  847. " c.dgfactoryitemid," +
  848. " t.wrfactortypename," +
  849. " t.wrfactortypename2" +
  850. " from wrfactortype t" +
  851. " inner join wrfactortypeitem a" +
  852. " on t.wrfactortypeid = a.wrfactortypeid" +
  853. " inner join dgfactoryitemtype b" +
  854. " on t.deliverygoodsid = b.deliverygoodsid" +
  855. " and a.dgfactoryitemtypeid = b.dgfactoryitemtypeid" +
  856. " left join dgfactoryitem c" +
  857. " on a.dgfactoryitemid = c.dgfactoryitemid" +
  858. " and b.deliverygoodsid = c.deliverygoodsid" +
  859. " left join deliverygoods g on t.deliverygoodsid=g.deliverygoodsid" +
  860. " left join wrstandard w on t.wrstandardid=w.wrstandardid" +
  861. " where 1 = 1"
  862. sqlId.And("t.wrfactortypeid", r.WRFACTORTYPEID)
  863. return sqlId.String()
  864. }
  865. // GetData 获取仓单要素选择项
  866. func (r *WrFactorTypeInfo) GetData() ([]WrFactorTypeInfo, error) {
  867. sData := make([]WrFactorTypeInfo, 0)
  868. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  869. for i := range sData {
  870. sData[i].calc()
  871. }
  872. return sData, err
  873. }
  874. // GetDataEx 获取仓单要素选择项
  875. func (r *WrFactorTypeInfo) GetDataEx() (interface{}, error) {
  876. return r.GetData()
  877. }
  878. // WrGoodsPerformanceStep 商品履约步骤
  879. type WrGoodsPerformanceStep struct {
  880. AUTOID int64 `json:"autoid" xorm:"AUTOID" form:"autoid"` // AutoID
  881. TEMPLATEID int64 `json:"templateid" xorm:"TEMPLATEID" form:"templateid"` // 履约计划模板ID
  882. STEPINDEX int32 `json:"stepindex" xorm:"STEPINDEX" form:"stepindex"` // 步骤序号
  883. STEPDAYS int32 `json:"stepdays" xorm:"STEPDAYS" form:"stepdays"` // 距离上一步天数
  884. STEPTYPEID int32 `json:"steptypeid" xorm:"STEPTYPEID" form:"steptypeid"` // 履约步骤类型ID - 1:买方支付 2:卖方收款 3:买方自提 4:卖方发货 5:买方确认货 6:卖方发票 7:买方确认票 8:仓单转移 9:释放卖方冻结 10:货款溢短 11:生成合同[中江] 12:运费 90:确认支付 91. 确认放行 92买方支付(直接扣款) 用于-1模板“
  885. STEPVALUE SFLOAT64 `json:"stepvalue" xorm:"STEPVALUE" form:"stepvalue"` // 步骤值
  886. ISAUTO int32 `json:"isauto" xorm:"ISAUTO" form:"isauto"` // 是否自动 - 0:不自动 1:自动
  887. REMARK string `json:"remark" xorm:"REMARK" form:"remark"` // 备注
  888. STEPTYPENAME string `json:"steptypename" xorm:"'STEPTYPENAME'"` // 步骤名称
  889. STEPINFO string `json:"stepinfo"` // 步骤信息(步骤名称+步骤值)
  890. STEPDAYSINFO string `json:"stepdate"` // 天数信息(T+N)
  891. WRSTANDARDID int64 `json:"-" form:"wrstandardid"` // 商品id
  892. MARKETID int64 `json:"-" form:"marketid"` // 市场id
  893. HASWR int32 `json:"-" form:"haswr"` // 是否有仓单-卖方 - 0:无仓单 1:有仓单
  894. }
  895. func (r *WrGoodsPerformanceStep) calc() {
  896. switch r.STEPTYPEID {
  897. case 1, 2:
  898. r.STEPINFO = fmt.Sprintf("%v% v%%", r.STEPTYPENAME, r.STEPVALUE*100)
  899. default:
  900. if r.STEPVALUE == 0 {
  901. r.STEPINFO = r.STEPTYPENAME
  902. } else {
  903. r.STEPINFO = fmt.Sprintf("%v %v", r.STEPTYPENAME, r.STEPVALUE)
  904. }
  905. }
  906. r.STEPDAYSINFO = fmt.Sprintf("T+%v", r.STEPDAYS)
  907. }
  908. func (r *WrGoodsPerformanceStep) buildSql() string {
  909. var sqlId utils.SQLVal = "with tmp as" +
  910. " (select decode(%v, 1, t.performancetempid, t.performancetempid2) tempid" +
  911. " from marketspotgoodsconfig t" +
  912. " where rownum <= 1 %v)" +
  913. "select t.*, s.steptypename" +
  914. " from PerformanceStepTemplate t" +
  915. " inner join PerformanceStepType s" +
  916. " on t.steptypeid = s.steptypeid" +
  917. " inner join tmp" +
  918. " on t.templateid = tmp.tempid" +
  919. " order by t.stepindex"
  920. var param utils.SQLVal
  921. param.And("t.wrstandardid", r.WRSTANDARDID)
  922. param.AndEx("t.marketid", r.MARKETID, r.MARKETID > 0)
  923. sqlId.FormatParam(r.HASWR, param.String())
  924. return sqlId.String()
  925. }
  926. // GetDataEx 获取商品履约步骤
  927. func (r *WrGoodsPerformanceStep) GetData() ([]WrGoodsPerformanceStep, error) {
  928. sData := make([]WrGoodsPerformanceStep, 0)
  929. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  930. for i := range sData {
  931. sData[i].calc()
  932. sData[i].MARKETID = r.MARKETID
  933. sData[i].WRSTANDARDID = r.WRSTANDARDID
  934. }
  935. return sData, err
  936. }
  937. // WrTypeItem 要素项
  938. type WrTypeItem struct {
  939. NAME string `json:"name"` // 名称
  940. VALUE string `json:"value"` // 值
  941. }
  942. // WrGoodsInfo 仓单商品信息(仓单要素列展开+履约计划步骤)
  943. type WrGoodsInfo struct {
  944. WRFACTORTYPEID string `json:"-" form:"wrfactortypeid"` // 仓单要素ID
  945. MARKETID int64 `json:"marketid" form:"marketid"` // 市场id
  946. HASWR int32 `json:"haswr" form:"haswr"` // 0:仓单预售 1:仓单贸易
  947. LstItem []WrTypeItem `json:"lstitem"` // 商品信息项
  948. LstStep []WrGoodsPerformanceStep `json:"lststep"` // 履约规则
  949. }
  950. // GetDataEx 获取仓单商品信息(仓单要素列展开+履约计划步骤)
  951. func (r *WrGoodsInfo) GetDataEx() (interface{}, error) {
  952. sData := make([]WrGoodsInfo, 0)
  953. mWrType := WrFactorTypeInfo{WRFACTORTYPEID: r.WRFACTORTYPEID}
  954. // 获取要素项
  955. if sType, err := mWrType.GetData(); err == nil {
  956. v := WrGoodsInfo{LstItem: make([]WrTypeItem, 0), LstStep: make([]WrGoodsPerformanceStep, 0)}
  957. if len(sType) > 0 {
  958. a := sType[0]
  959. v.LstItem = append(v.LstItem, WrTypeItem{NAME: "品种", VALUE: a.DELIVERYGOODSNAME})
  960. v.LstItem = append(v.LstItem, WrTypeItem{NAME: "品类", VALUE: a.WRSTANDARDNAME})
  961. for _, b := range sType {
  962. v.LstItem = append(v.LstItem, WrTypeItem{NAME: b.ITEMTYPENAME, VALUE: b.DGFACTORYITEMVALUE})
  963. }
  964. // 获取履约规则
  965. mStep := WrGoodsPerformanceStep{MARKETID: r.MARKETID, WRSTANDARDID: a.WRSTANDARDID, HASWR: r.HASWR}
  966. if sStep, err := mStep.GetData(); err == nil && len(sStep) > 0 {
  967. v.LstStep = append(v.LstStep, sStep...)
  968. }
  969. }
  970. v.MARKETID = r.MARKETID
  971. v.HASWR = r.HASWR
  972. v.WRFACTORTYPEID = r.WRFACTORTYPEID
  973. sData = append(sData, v)
  974. }
  975. return sData, nil
  976. }
  977. // WrPerformancePlan 履约信息(履约计划)
  978. type WrPerformancePlan struct {
  979. PERFORMANCEPLANID int64 `json:"performanceplanid" xorm:"PERFORMANCEPLANID" form:"performanceplanid"` // 履约计划ID(130+yyMMddHHmmss+xxxx)
  980. PERFORMANCETYPE int32 `json:"performancetype" xorm:"PERFORMANCETYPE" form:"performancetype"` // 履约类型 - 0:通用 1:交割 2:仓单贸易 3:预售集采 4:竞拍-降价式 (无仓单) 5:挂牌期权 6:竞拍-降价式 7:竞拍-竞价式 8:竞拍-大宗式 9:荷兰式 10:法币C2C 11:报价系统 12:挂牌系统
  981. RELATEDORDERID string `json:"relatedorderid" xorm:"RELATEDORDERID" form:"relatedorderid"` // 关联单号(履约类型的关联单号)
  982. AMOUNT float64 `json:"amount" xorm:"AMOUNT" form:"amount"` // 履约金额(总金额)
  983. PAYMENTTYPE int32 `json:"paymenttype" xorm:"PAYMENTTYPE" form:"paymenttype"` // 付款方式 - 1:冻结 2:扣款
  984. PERFORMANCESTATUS int32 `json:"performancestatus" xorm:"PERFORMANCESTATUS" form:"performancestatus"` // 履约状态 - 1:初始化 2:正常 3:处理错误 4:违约待处理 5:违约处理中 6:完成 7.违约已完成 8:释放冻结失败 9:超时待处理 10:超时关闭
  985. CURSTEPID int64 `json:"curstepid" xorm:"CURSTEPID" form:"curstepid"` // 当前步骤ID
  986. BUYACCOUNTID int64 `json:"buyaccountid" xorm:"BUYACCOUNTID" form:"buyaccountid"` // 买方账号
  987. WRTRANSFERUSERID int64 `json:"wrtransferuserid" xorm:"WRTRANSFERUSERID" form:"wrtransferuserid"` // 仓单受让用户
  988. BUYPAIDAMOUNT float64 `json:"buypaidamount" xorm:"BUYPAIDAMOUNT" form:"buypaidamount"` // 买方已冻/已扣金额 (已付金额)
  989. SELLACCOUNTID int64 `json:"sellaccountid" xorm:"SELLACCOUNTID" form:"sellaccountid"` // 卖方账号
  990. SELLRECEIVEDAMOUNT float64 `json:"sellreceivedamount" xorm:"SELLRECEIVEDAMOUNT"` // 卖方已收金额
  991. CREATETIME string `json:"createtime" xorm:"CREATETIME" form:"createtime"` // 创建时间(开始时间)
  992. CREATORID int64 `json:"creatorid" xorm:"CREATORID" form:"creatorid"` // 创建人
  993. REMARK string `json:"remark" xorm:"REMARK" form:"remark"` // 备注
  994. BUYERFREEZEAMOUNT float64 `json:"buyerfreezeamount" xorm:"BUYERFREEZEAMOUNT"` // 履约冻结(买履约)
  995. BUYERFREEZEAMOUNTREMAIN float64 `json:"buyerfreezeamountremain" xorm:"BUYERFREEZEAMOUNTREMAIN"` // 履约冻结剩余(买履约)
  996. SELLERFREEZEAMOUNT float64 `json:"sellerfreezeamount" xorm:"SELLERFREEZEAMOUNT"` // 履约冻结(卖履约)
  997. SELLERFREEZEAMOUNTREMAIN float64 `json:"sellerfreezeamountremain" xorm:"SELLERFREEZEAMOUNTREMAIN"` // 履约冻结剩余(卖履约)
  998. OVERSHORTAMOUNT float64 `json:"overshortamount" xorm:"OVERSHORTAMOUNT" form:"overshortamount"` // 溢短金额
  999. HASOVERSHORT int32 `json:"hasovershort" xorm:"HASOVERSHORT" form:"hasovershort"` // 是否确认溢短 - 0:没有 1:买方确认 2:卖方确认
  1000. SHIPREMARK string `json:"shipremark" xorm:"SHIPREMARK" form:"shipremark"` // 发货备注[物流单号]
  1001. MIDDLEUSERID int64 `json:"middleuserid" xorm:"MIDDLEUSERID" form:"middleuserid"` // 中间商用户ID
  1002. MIDDLEACCOUNTID int64 `json:"middleaccountid" xorm:"MIDDLEACCOUNTID" form:"middleaccountid"` // 中间商资金账号ID
  1003. HASWR int32 `json:"haswr" xorm:"HASWR" form:"haswr"` // 类型 0-仓单预售 1-仓单贸易
  1004. OVERSHORTQTY float64 `json:"overshortqty" xorm:"OVERSHORTQTY" form:"overshortqty"` // 溢短数量
  1005. MARKETID int32 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID
  1006. EXPRESSFEECONFIRMED int32 `json:"expressfeeconfirmed" xorm:"EXPRESSFEECONFIRMED"` // 是否确认运费 - 0:无 1:买方确认 2:卖方确认
  1007. EXPRESSFEE float64 `json:"expressfee" xorm:"EXPRESSFEE" form:"expressfee"` // 运费
  1008. CONTRACTID int64 `json:"contractid" xorm:"CONTRACTID" form:"contractid"` // 合同ID
  1009. CURSTEPDEADLINE string `json:"curstepdeadline" xorm:"CURSTEPDEADLINE" form:"curstepdeadline"` // 当前步骤到期时间
  1010. QTY float64 `json:"qty" xorm:"QTY" form:"qty"` // 履约数量
  1011. Wr2FactorType `xorm:"extends"`
  1012. CURSTEPNAME string `json:"curstepname" xorm:"'CURSTEPNAME'"` // 当前步骤名称
  1013. BUYUSERNAME string `json:"buyusername" xorm:"'BUYUSERNAME'"` // 买方名字
  1014. SELLUSERNAME string `json:"sellusername" xorm:"'SELLUSERNAME'"` // 卖方名字
  1015. USERID int64 `json:"userid" form:"userid" binding:"required"` // 用户id
  1016. BUYORSELL int32 `json:"buyorsell" form:"buyorsell"` // 买卖方向 0-买 1-卖
  1017. }
  1018. func (r *WrPerformancePlan) calc() {
  1019. r.Wr2FactorType.Calc()
  1020. }
  1021. func (r *WrPerformancePlan) buildSql() string {
  1022. var sqlId utils.SQLVal = "with tmp as" +
  1023. " (select to_char(t.wrfactortypeid) wrfactortypeid," +
  1024. " t.wrfactortypename," +
  1025. " t.wrstandardid," +
  1026. " t.deliverygoodsid," +
  1027. " g.deliverygoodscode," +
  1028. " g.deliverygoodsname," +
  1029. " w.wrstandardcode," +
  1030. " w.wrstandardname," +
  1031. " h.warehousecode," +
  1032. " h.warehousename," +
  1033. " e.enumdicname," +
  1034. " w.wrstandardname || t.wrfactortypename2 as wrtypename" +
  1035. " from wrfactortype t" +
  1036. " left join deliverygoods g" +
  1037. " on t.deliverygoodsid = g.deliverygoodsid" +
  1038. " left join wrstandard w" +
  1039. " on t.wrstandardid = w.wrstandardid" +
  1040. " left join warehouseinfo h" +
  1041. " on t.warehouseid = h.autoid" +
  1042. " left join enumdicitem e" +
  1043. " on w.unitid = e.enumitemname" +
  1044. " and e.enumdiccode = 'goodsunit'" +
  1045. ")" +
  1046. "select to_char(t.PERFORMANCEPLANID) PERFORMANCEPLANID," +
  1047. " t.PERFORMANCETYPE," +
  1048. " to_char(t.RELATEDORDERID) RELATEDORDERID," +
  1049. " t.AMOUNT," +
  1050. " t.PAYMENTTYPE," +
  1051. " t.PERFORMANCESTATUS," +
  1052. " t.CURSTEPID," +
  1053. " t.BUYACCOUNTID," +
  1054. " t.WRTRANSFERUSERID," +
  1055. " t.BUYPAIDAMOUNT," +
  1056. " t.SELLACCOUNTID," +
  1057. " t.SELLRECEIVEDAMOUNT," +
  1058. " t.BUYTODAYAMOUNT," +
  1059. " t.SELLTODAYAMOUNT," +
  1060. " to_char(t.CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
  1061. " t.CREATORID," +
  1062. " t.REMARK," +
  1063. " t.BUYERFREEZEAMOUNT," +
  1064. " t.BUYERFREEZEAMOUNTREMAIN," +
  1065. " t.SELLERFREEZEAMOUNT," +
  1066. " t.SELLERFREEZEAMOUNTREMAIN," +
  1067. " t.OVERSHORTAMOUNT," +
  1068. " t.HASOVERSHORT," +
  1069. " t.SHIPREMARK," +
  1070. " t.MIDDLEUSERID," +
  1071. " t.MIDDLEACCOUNTID," +
  1072. " t.HASWR," +
  1073. " t.BUYERINFO," +
  1074. " t.SELLERINFO," +
  1075. " t.OVERSHORTQTY," +
  1076. " t.MARKETID," +
  1077. " t.EXPRESSFEECONFIRMED," +
  1078. " t.EXPRESSFEE," +
  1079. " t.CONTRACTID," +
  1080. " to_char(t.CURSTEPDEADLINE, 'yyyy-mm-dd hh24:mi:ss') CURSTEPDEADLINE," +
  1081. " t.QTY," +
  1082. " u1.accountname buyusername," +
  1083. " u2.accountname sellusername," +
  1084. " s.steptypename CURSTEPNAME," +
  1085. " tmp.*" +
  1086. " from performanceplan t" +
  1087. " left join taaccount a1" +
  1088. " on t.buyaccountid = a1.accountid" +
  1089. " left join useraccount u1" +
  1090. " on a1.userid = u1.userid" +
  1091. " left join taaccount a2" +
  1092. " on t.sellaccountid = a2.accountid" +
  1093. " left join useraccount u2" +
  1094. " on a2.userid = u2.userid" +
  1095. " left join performancesteptype s" +
  1096. " on t.curstepid = s.steptypeid" +
  1097. " left join performanceplanwr p on t.performanceplanid = p.performanceplanid" +
  1098. " left join warehousereciept f on p.wrid= f.wrid" +
  1099. " left join tmp on f.wrfactortypeid=tmp.wrfactortypeid" +
  1100. " where 1 = 1"
  1101. if r.BUYORSELL == 0 {
  1102. sqlId.And("u1.userid", r.USERID)
  1103. } else {
  1104. sqlId.And("u2.userid", r.USERID)
  1105. }
  1106. sqlId.Join(" order by t.CREATETIME desc")
  1107. return sqlId.String()
  1108. }
  1109. // GetDataEx 获取履约信息(履约计划)
  1110. func (r *WrPerformancePlan) GetDataEx() (interface{}, error) {
  1111. sData := make([]WrPerformancePlan, 0)
  1112. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1113. for i := range sData {
  1114. sData[i].calc()
  1115. }
  1116. return sData, err
  1117. }
  1118. // WrHoldLB 仓单持有记录
  1119. type WrHoldLB struct {
  1120. LADINGBILLID string `json:"ladingbillid" xorm:"LADINGBILLID" form:"ladingbillid"` // 提单ID(208+Unix秒时间戳(10位)+xxxxxx)
  1121. SUBNUM int32 `json:"subnum" xorm:"SUBNUM" form:"subnum"` // 提单子单号
  1122. WRFACTORTYPEID string `json:"wrfactortypeid" xorm:"WRFACTORTYPEID" form:"wrfactortypeid"` // 仓单要素类型ID
  1123. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID" form:"deliverygoodsid"` // 品种ID
  1124. QTY float64 `json:"qty" xorm:"QTY" form:"qty"` // 数量
  1125. FREEZERQTY float64 `json:"freezerqty" xorm:"FREEZERQTY" form:"freezerqty"` // 冻结数量
  1126. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 持有人ID
  1127. ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID" form:"accountid"` // 持有人帐户ID
  1128. CREATETIME string `json:"createtime" xorm:"CREATETIME" form:"createtime"` // 创建时间(过户时间)
  1129. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE" form:"tradedate"` // 交易日(yyyyMMdd)
  1130. WRID string `json:"wrid" xorm:"WRID" form:"wrid"` // 仓单变更ID
  1131. PARENTSUBNUM int32 `json:"parentsubnum" xorm:"PARENTSUBNUM" form:"parentsubnum"` // 拆分父子单号
  1132. PLEDGEQTY float64 `json:"pledgeqty" xorm:"'-'"` // 质押数量
  1133. Wr2FactorType `xorm:"extends"`
  1134. WRHOLDENO string `json:"wrholdeno"` // 仓单编号
  1135. ENABLEQTY float64 `json:"enableqty"` // 可用数量
  1136. }
  1137. func (r *WrHoldLB) calc() {
  1138. r.WRHOLDENO = fmt.Sprintf("%v_%v", r.LADINGBILLID, r.SUBNUM)
  1139. r.ENABLEQTY = r.QTY - r.FREEZERQTY
  1140. r.Wr2FactorType.Calc()
  1141. }
  1142. func (r *WrHoldLB) buildSql() string {
  1143. var sqlId utils.SQLVal = "with tmp as" +
  1144. " (select t.wrfactortypeid," +
  1145. " t.wrfactortypename," +
  1146. " t.wrstandardid," +
  1147. " t.deliverygoodsid," +
  1148. " t.warehouseid," +
  1149. " g.deliverygoodscode," +
  1150. " g.deliverygoodsname," +
  1151. " w.wrstandardcode," +
  1152. " w.wrstandardname," +
  1153. " h.warehousecode," +
  1154. " h.warehousename," +
  1155. " e.enumdicname," +
  1156. " w.wrstandardname || t.wrfactortypename2 as wrtypename" +
  1157. " from wrfactortype t" +
  1158. " left join deliverygoods g" +
  1159. " on t.deliverygoodsid = g.deliverygoodsid" +
  1160. " left join wrstandard w" +
  1161. " on t.wrstandardid = w.wrstandardid" +
  1162. " left join warehouseinfo h" +
  1163. " on t.warehouseid = h.autoid" +
  1164. " left join enumdicitem e" +
  1165. " on w.unitid = e.enumitemname" +
  1166. " and e.enumdiccode = 'goodsunit'" +
  1167. ")" +
  1168. "SELECT to_char(t.LADINGBILLID) LADINGBILLID," +
  1169. " t.SUBNUM," +
  1170. " to_char(t.WRFACTORTYPEID) WRFACTORTYPEID," +
  1171. " t.DELIVERYGOODSID," +
  1172. " t.QTY," +
  1173. " t.FREEZERQTY," +
  1174. " t.USERID," +
  1175. " t.ACCOUNTID," +
  1176. " to_char(t.CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
  1177. " t.TRADEDATE," +
  1178. " t.WRID," +
  1179. " t.PARENTSUBNUM," +
  1180. " tmp.*" +
  1181. " FROM WRHOLDLB t" +
  1182. " LEFT JOIN tmp on t.wrfactortypeid= tmp.wrfactortypeid" +
  1183. " WHERE 1 = 1"
  1184. sqlId.And("t.ACCOUNTID", r.ACCOUNTID)
  1185. sqlId.AndEx("tmp.DELIVERYGOODSID", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0)
  1186. sqlId.AndEx("tmp.WRSTANDARDID", r.WRSTANDARDID, r.WRSTANDARDID > 0)
  1187. sqlId.AndEx("tmp.WAREHOUSEID", r.WAREHOUSEID, r.WAREHOUSEID > 0)
  1188. return sqlId.String()
  1189. }
  1190. // GetDataEx 获取仓单持有记录
  1191. func (r *WrHoldLB) GetDataEx() (interface{}, error) {
  1192. sData := make([]WrHoldLB, 0)
  1193. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1194. for i := range sData {
  1195. sData[i].calc()
  1196. }
  1197. return sData, err
  1198. }
  1199. // WrFilterItem 筛选框列表项
  1200. type WrFilterItem struct {
  1201. ITEMTYPE int32 `json:"itemtype" xorm:"'ITEMTYPE'"` // 类型 1-品种 2-品类(商品) 3-仓库
  1202. ITEMNAME string `json:"itemname" xorm:"'ITEMNAME'"` // 名称
  1203. ITEMCODE string `json:"itemcode" xorm:"'ITEMCODE'"` // 代码
  1204. ITEMID int64 `json:"itemid" xorm:"'ITEMID'"` // 项id
  1205. IType string `json:"-" form:"itype"` // 类型 逗号隔开, 如 1,2
  1206. }
  1207. func (r *WrFilterItem) calc() {
  1208. }
  1209. func (r *WrFilterItem) buildSql() string {
  1210. if r.IType == "" {
  1211. r.IType = "1, 2, 3"
  1212. }
  1213. r.IType = strings.ReplaceAll(r.IType, " ", "")
  1214. sType := strings.Split(r.IType, ",")
  1215. sqls := make([]string, 0)
  1216. for _, v := range sType {
  1217. switch v {
  1218. case "1":
  1219. sqls = append(sqls, "select 1 itemtype, t.deliverygoodsid itemid, t.deliverygoodscode itemcode, to_char(t.deliverygoodsname) itemname from deliverygoods t")
  1220. case "2":
  1221. sqls = append(sqls, "select 2 itemtype, t.wrstandardid itemid, to_char(t.wrstandardcode) itemcode, to_char(t.wrstandardname) itemname from wrstandard t")
  1222. case "3":
  1223. sqls = append(sqls, "select 3 itemtype, t.autoid itemid, t.warehousecode itemcode, to_char(t.warehousename) itemname from warehouseinfo t")
  1224. default:
  1225. }
  1226. }
  1227. var sqlId string
  1228. for _, v := range sqls {
  1229. if len(sqlId) > 0 {
  1230. sqlId += " union all " + v
  1231. } else {
  1232. sqlId = v
  1233. }
  1234. }
  1235. sqlId += " order by itemtype, itemid"
  1236. return sqlId
  1237. }
  1238. // GetDataEx 获取筛选框列表项
  1239. func (r *WrFilterItem) GetDataEx() (interface{}, error) {
  1240. sData := make([]WrFilterItem, 0)
  1241. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1242. for i := range sData {
  1243. sData[i].calc()
  1244. }
  1245. return sData, err
  1246. }
  1247. // WrPerformanPlanSum 履约中数量
  1248. type WrPerformanPlanSum struct {
  1249. USERID int64 `json:"userid" xorm:"'USERID'"` // 用户id
  1250. BUYORSELL int32 `json:"buyorsell" xorm:"'BUYORSELL'"` // 买卖方向
  1251. QTY float64 `json:"qty" xorm:"'QTY'"` // 履约中的数量
  1252. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 品种id
  1253. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 品类id
  1254. WAREHOUSEID int64 `json:"warehouseid" xorm:"'WAREHOUSEID'"` // 仓库id
  1255. WRTYPENAME string `json:"wrtypename" xorm:"'WRTYPENAME'"` // 商品
  1256. QueryType int32 `json:"querytype" form:"querytype"` // 查询类型 1-现货汇总 2-库存汇总
  1257. }
  1258. func (r *WrPerformanPlanSum) calc() {
  1259. if len(r.WRTYPENAME) > 0 {
  1260. r.WRTYPENAME = strings.ReplaceAll(r.WRTYPENAME, ",", "-")
  1261. }
  1262. }
  1263. // buildSql_XHHZ 现货汇总 履约中的数量
  1264. func (r *WrPerformanPlanSum) buildSql_XHHZ() string {
  1265. var sqlId utils.SQLVal = "with tmp as" +
  1266. " (select t.buyaccountid," +
  1267. " t.sellaccountid," +
  1268. " t.qty," +
  1269. " w.wrfactortypeid," +
  1270. " w.deliverygoodsid," +
  1271. " w.wrstandardid," +
  1272. " w.warehouseid," +
  1273. " wd.wrstandardname || w.wrfactortypename2 wrtypename," +
  1274. " u1.userid buyuserid," +
  1275. " u2.userid selluserid" +
  1276. " from performanceplan t" +
  1277. " left join performanceplanwr p" +
  1278. " on t.performanceplanid = p.performanceplanid" +
  1279. " left join warehousereciept f" +
  1280. " on p.wrid = f.wrid" +
  1281. " left join wrfactortype w" +
  1282. " on f.wrfactortypeid = w.wrfactortypeid" +
  1283. " left join wrstandard wd" +
  1284. " on w.wrstandardid = wd.wrstandardid" +
  1285. " left join taaccount ta1" +
  1286. " on t.buyaccountid = ta1.accountid" +
  1287. " left join useraccount u1" +
  1288. " on ta1.userid = u1.userid" +
  1289. " left join taaccount ta2" +
  1290. " on t.sellaccountid = ta2.accountid" +
  1291. " left join useraccount u2" +
  1292. " on ta2.userid = u2.userid" +
  1293. " where t.performancestatus in (2) and %v in(u1.userid, u2.userid))" +
  1294. "select k.buyuserid userid," +
  1295. " 0 as buyorsell," +
  1296. " k.deliverygoodsid," +
  1297. " k.wrstandardid," +
  1298. " k.wrtypename," +
  1299. " sum(k.qty) qty" +
  1300. " from tmp k" +
  1301. " group by k.buyuserid, k.deliverygoodsid, k.wrstandardid, k.wrtypename" +
  1302. "union all" +
  1303. "select k.selluserid userid," +
  1304. " 1 as buyorsell," +
  1305. " k.deliverygoodsid," +
  1306. " k.wrstandardid," +
  1307. " k.wrtypename," +
  1308. " sum(k.qty) qty" +
  1309. " from tmp k" +
  1310. " group by k.selluserid, k.deliverygoodsid, k.wrstandardid, k.wrtypename"
  1311. sqlId.FormatParam(r.USERID)
  1312. return sqlId.String()
  1313. }
  1314. // buildSql_KCHZ 库存汇总 履约中的数量
  1315. func (r *WrPerformanPlanSum) buildSql_KCHZ() string {
  1316. var sqlId utils.SQLVal = "with tmp as" +
  1317. " (select t.buyaccountid," +
  1318. " t.sellaccountid," +
  1319. " t.qty," +
  1320. " w.wrfactortypeid," +
  1321. " w.deliverygoodsid," +
  1322. " w.wrstandardid," +
  1323. " w.warehouseid," +
  1324. " wd.wrstandardname || w.wrfactortypename2 wrtypename," +
  1325. " u1.userid buyuserid," +
  1326. " u2.userid selluserid" +
  1327. " from performanceplan t" +
  1328. " left join performanceplanwr p" +
  1329. " on t.performanceplanid = p.performanceplanid" +
  1330. " left join warehousereciept f" +
  1331. " on p.wrid = f.wrid" +
  1332. " left join wrfactortype w" +
  1333. " on f.wrfactortypeid = w.wrfactortypeid" +
  1334. " left join wrstandard wd" +
  1335. " on w.wrstandardid = wd.wrstandardid" +
  1336. " left join taaccount ta1" +
  1337. " on t.buyaccountid = ta1.accountid" +
  1338. " left join useraccount u1" +
  1339. " on ta1.userid = u1.userid" +
  1340. " left join taaccount ta2" +
  1341. " on t.sellaccountid = ta2.accountid" +
  1342. " left join useraccount u2" +
  1343. " on ta2.userid = u2.userid" +
  1344. " where t.performancestatus in (2) and %v in(u1.userid, u2.userid)" +
  1345. "select k.buyuserid userid," +
  1346. " 0 as buyorsell," +
  1347. " k.deliverygoodsid," +
  1348. " k.wrstandardid," +
  1349. " k.warehouseid," +
  1350. " k.wrtypename," +
  1351. " sum(k.qty) qty" +
  1352. " from tmp k" +
  1353. " group by k.buyuserid, k.deliverygoodsid, k.wrstandardid, k.warehouseid, k.wrtypename" +
  1354. "union all" +
  1355. "select k.selluserid userid," +
  1356. " 1 as buyorsell," +
  1357. " k.deliverygoodsid," +
  1358. " k.wrstandardid," +
  1359. " k.warehouseid," +
  1360. " k.wrtypename," +
  1361. " sum(k.qty) qty" +
  1362. " from tmp k" +
  1363. " group by k.selluserid, k.deliverygoodsid, k.wrstandardid, k.warehouseid, k.wrtypename"
  1364. sqlId.FormatParam(r.USERID, r.USERID)
  1365. return sqlId.String()
  1366. }
  1367. func (r *WrPerformanPlanSum) buildSql() string {
  1368. if r.QueryType == 1 {
  1369. return r.buildSql_XHHZ()
  1370. } else {
  1371. return r.buildSql_KCHZ()
  1372. }
  1373. }
  1374. // GetData 获取履约中数量
  1375. func (r *WrPerformanPlanSum) GetData() ([]WrPerformanPlanSum, error) {
  1376. sData := make([]WrPerformanPlanSum, 0)
  1377. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1378. for i := range sData {
  1379. sData[i].calc()
  1380. }
  1381. return sData, err
  1382. }
  1383. // WrFAProductDetail 融资产品列表
  1384. type WrFAProductDetail struct {
  1385. PRODUCTDETAILID int64 `json:"productdetailid" xorm:"PRODUCTDETAILID"` // 产品组合ID(SEQ_FINANCEAREAPRODUCTDETAIL)
  1386. PRODUCTID int64 `json:"productid" xorm:"PRODUCTID"` // 金融产品ID
  1387. AREAUSERID int64 `json:"areauserid" xorm:"AREAUSERID"` // 金融机构ID
  1388. FINANCINGDAYS int32 `json:"financingdays" xorm:"FINANCINGDAYS"` // 天数(天)
  1389. MARGINRATIO float64 `json:"marginratio" xorm:"MARGINRATIO"` // 保证金比率质押率 - [仓单质押]
  1390. INTERESTRATEMODE int32 `json:"interestratemode" xorm:"INTERESTRATEMODE"` // 利率方式 - 1:年利率 2:日利率
  1391. INTERESTRATE float64 `json:"interestrate" xorm:"INTERESTRATE"` // 利率
  1392. INTERESTMINLEN int32 `json:"interestminlen" xorm:"INTERESTMINLEN"` // 最小起息天数
  1393. INTERESTSETTLEMODE int32 `json:"interestsettlemode" xorm:"INTERESTSETTLEMODE"` // 结息方式 - 1:按日结息 3:按月结息
  1394. INTERESTSETTLEVALUE int32 `json:"interestsettlevalue" xorm:"INTERESTSETTLEVALUE"` // 结息方式值
  1395. UPDATETIME string `json:"updatetime" xorm:"UPDATETIME"` // 更新时间
  1396. ISAUTOLOAN int32 `json:"isautoloan" xorm:"'ISAUTOLOAN'"` // 是否自动放款 0-手动 1-自动 (当为自动放款时,显示"放款快")
  1397. PRODUCTNAME string `json:"productname" xorm:"'PRODUCTNAME'"` // 产品名称
  1398. USERNAME string `json:"username" xorm:"'USERNAME'"` // 融出方
  1399. ACCOUNTID int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 资金账号
  1400. LOANTAG string `json:"-"` // 放款标识: "放款快" 或者为空
  1401. WRSTANDARDID int64 `json:"-"` // 品类(商品)id
  1402. BRANDID int64 `json:"-"` // 品牌id
  1403. WAREHOUSEID int64 `json:"-"` // 仓库id
  1404. WRFACTORTYPEID string `json:"wrfactortypeid" form:"wrfactortypeid"` // 仓单要素ID
  1405. }
  1406. func (r *WrFAProductDetail) calc() {
  1407. r.LOANTAG = IFValue(r.ISAUTOLOAN == 1, "放款快", "").(string)
  1408. }
  1409. func (r *WrFAProductDetail) buildSql() string {
  1410. var sqlId utils.SQLVal = "with tmp as" +
  1411. " (select distinct f.productid, f.isautoloan" +
  1412. " from FinanceAreaProductLimit f" +
  1413. " where 1 = 1" +
  1414. " and f.wrstandardid = %v" +
  1415. " and (f.spotgoodsbrandid like '%%,%v,%%' or f.spotgoodsbrandid like '%%,0,%%')" +
  1416. " and (f.warehouseinfoid like '%%,%v,%%' or f.warehouseinfoid like '%%,0,%%'))" +
  1417. "select t.PRODUCTDETAILID," +
  1418. " t.PRODUCTID," +
  1419. " t.AREAUSERID," +
  1420. " t.FINANCINGDAYS," +
  1421. " t.MARGINRATIO," +
  1422. " t.INTERESTRATEMODE," +
  1423. " t.INTERESTRATE," +
  1424. " t.INTERESTMINLEN," +
  1425. " t.INTERESTSETTLEMODE," +
  1426. " t.INTERESTSETTLEVALUE," +
  1427. " to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," +
  1428. " p.productname," +
  1429. " p.accountid," +
  1430. " u.accountname username," +
  1431. " k.isautoloan" +
  1432. " from FinanceAreaProductDetail t" +
  1433. " left join FinanceAreaProduct p" +
  1434. " on t.productid = p.productid" +
  1435. " left join useraccount u" +
  1436. " on t.areauserid = u.userid" +
  1437. " inner join tmp k" +
  1438. " on t.productid = k.productid"
  1439. sqlId.FormatParam(r.WRSTANDARDID, r.BRANDID, r.WAREHOUSEID)
  1440. return sqlId.String()
  1441. }
  1442. // GetDataEx 获取融资产品列表
  1443. func (r *WrFAProductDetail) GetDataEx() (interface{}, error) {
  1444. sData := make([]WrFAProductDetail, 0)
  1445. m := WrFactorTypeInfo{WRFACTORTYPEID: r.WRFACTORTYPEID}
  1446. if d, err := m.GetData(); err == nil {
  1447. var brandid int64 = 0
  1448. for _, v := range d {
  1449. if v.DGFACTORYITEMTYPEID == 2 {
  1450. brandid = v.DGFACTORYITEMID
  1451. }
  1452. }
  1453. if brandid > 0 && len(d) > 0 {
  1454. r.BRANDID = brandid
  1455. r.WRSTANDARDID = d[0].WRSTANDARDID
  1456. r.WAREHOUSEID = d[0].WAREHOUSEID
  1457. _ = db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1458. for i := range sData {
  1459. sData[i].calc()
  1460. sData[i].WRSTANDARDID = r.WRSTANDARDID
  1461. sData[i].BRANDID = r.BRANDID
  1462. sData[i].WAREHOUSEID = r.WAREHOUSEID
  1463. sData[i].WRFACTORTYPEID = r.WRFACTORTYPEID
  1464. }
  1465. }
  1466. }
  1467. return sData, nil
  1468. }