wrTrade2.go 81 KB

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