wrTrade2.go 240 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292
  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. "errors"
  9. "fmt"
  10. "mtp2_if/db"
  11. "mtp2_if/mtpcache"
  12. "mtp2_if/utils"
  13. "sort"
  14. "strconv"
  15. "strings"
  16. "time"
  17. )
  18. // WrOrderQuote 买卖大厅行情
  19. type WrOrderQuote struct {
  20. WRFACTORTYPEID string `json:"wrfactortypeid" xorm:"'WRFACTORTYPEID'" form:"wrfactortypeid"` // 仓单要素id
  21. BUYPRICE float64 `json:"buyprice" xorm:"'BUYPRICE'"` // 买价
  22. BUYQTY float64 `json:"buyqty" xorm:"'BUYQTY'"` // 买量
  23. SELLPRICE float64 `json:"sellprice" xorm:"'SELLPRICE'"` // 卖价
  24. SELLQTY float64 `json:"sellqty" xorm:"'SELLQTY'"` // 卖量
  25. WRFACTORTYPENAME string `json:"wrfactortypename" xorm:"'WRFACTORTYPENAME'"` // 仓单要素类型名称(选择项要素的名称合并显示,逗号分隔)
  26. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 品种id
  27. WRSTANDARDID int32 `json:"wrstandardid" xorm:"'WRSTANDARDID'" form:"wrstandardid"` // 商品id
  28. WAREHOUSEID int32 `json:"warehouseid" xorm:"'WAREHOUSEID'" form:"warehouseid"` // 仓库id
  29. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 品种名称
  30. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 品种代码
  31. WAREHOUSENAME string `json:"warehousename" xorm:"'WAREHOUSENAME'"` // 仓库名称
  32. WAREHOUSECODE string `json:"warehousecode" xorm:"'WAREHOUSECODE'"` // 仓库代码
  33. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'" form:"wrstandardname"` // 商品名称
  34. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 商品代码
  35. WRGOODSNAME string `json:"wrgoodsname" xorm:"'WRGOODSNAME'"` // 商品(商品名称+仓库要素名称 拼接)
  36. THUMURLS string `json:"thumurls" xorm:"THUMURLS"` // 缩略图片(1:1)(逗号分隔)
  37. PICTUREURLS string `json:"pictureurls" xorm:"PICTUREURLS"` // 详情图片(逗号分隔)
  38. BANNERPICURL string `json:"bannerpicurl" xorm:"BANNERPICURL"` // Banner图
  39. BUYPRICEMOVE float64 `json:"buypricemove" xorm:"'BUYPRICEMOVE'"` // 买升贴水(基差)
  40. SELLPRICEMOVE float64 `json:"sellpricemove" xorm:"'SELLPRICEMOVE'"` // 卖升贴水(基差)
  41. GOODSID int32 `json:"goodsid" xorm:"'GOODSID'"` // 商品id(浮动价列表才有)
  42. GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品合约(浮动价列表才有)
  43. DELIVERYMONTH string `json:"deliverymonth" xorm:"'DELIVERYMONTH'" form:"deliverymonth"` // 交收月
  44. ENUMDICNAME string `json:"enumdicname" xorm:"'enumdicname'"` // 单位名称
  45. MINIVALUE int32 `json:"minivalue" xorm:"'MINIVALUE'"` // 现货商品最小变动值
  46. PageEx `xorm:"extends"` // 页码信息
  47. HasWr int32 `json:"-" form:"haswr"` // 是否有仓单 0-没有 1-有
  48. WrPriceType int32 `json:"-" form:"wrpricetype"` // 价格方式 - 1:固定价 2-浮动价 - [挂牌]
  49. MarketId int32 `json:"-" form:"marketid"` // 市场id
  50. BRANDNAME string `json:"-" form:"brandname"` // 品牌名称
  51. DGITEMNAME string `json:"-" form:"dgitemname"` // 筛选项
  52. BrandId int `json:"-" form:"brandid"` // 品牌id
  53. YearsId int `json:"-" form:"yearsid"` // 年份id
  54. }
  55. func (r *WrOrderQuote) calc() {
  56. r.WRGOODSNAME = strings.ReplaceAll(r.WRGOODSNAME, ",", "-")
  57. }
  58. func (r *WrOrderQuote) ftItemName() ([]string, bool) {
  59. if len(r.DGITEMNAME) < 2 {
  60. return nil, false
  61. }
  62. sItem := strings.Split(r.DGITEMNAME, ",")
  63. if len(sItem) > 0 {
  64. return sItem, true
  65. }
  66. return nil, false
  67. }
  68. // buildSqlFixedPrice 一口价
  69. func (r *WrOrderQuote) buildSqlFixedPrice() string {
  70. var sqlId utils.SQLVal = "with buyQuote as" +
  71. " (" +
  72. " select to_char(a.wrfactortypeid) wrfactortypeid, a.fixedprice buyPrice, sum(a.orderqty) buyQty, a.deliverymonth" +
  73. " from (select t.wrfactortypeid," +
  74. " t.marketid," +
  75. " t.buyorsell," +
  76. " t.orderqty - t.tradeqty as orderqty," +
  77. " t.fixedprice," +
  78. " nvl(t.deliverymonth,'0') deliverymonth," +
  79. " rank() over(partition by t.wrfactortypeid, nvl(t.deliverymonth,'0') order by t.fixedprice desc) cnt" +
  80. " from wrtrade_orderdetail t" +
  81. " where t.wrtradetype = 1 and t.isspecified=0 and t.buyorsell = 0 and t.wrtradeorderstatus in(3,7) %v" +
  82. " ) a" +
  83. " where a.cnt = 1" +
  84. " group by a.wrfactortypeid, a.fixedprice, a.deliverymonth)," +
  85. "sellQuote as" +
  86. " (" +
  87. " select to_char(a.wrfactortypeid) wrfactortypeid, a.fixedprice sellPrice, sum(a.orderqty) sellQty, a.deliverymonth" +
  88. " from (select t.wrfactortypeid," +
  89. " t.marketid," +
  90. " t.buyorsell," +
  91. " t.orderqty - t.tradeqty as orderqty," +
  92. " t.fixedprice," +
  93. " nvl(t.deliverymonth,'0') deliverymonth," +
  94. " rank() over(partition by t.wrfactortypeid, nvl(t.deliverymonth,'0') order by t.fixedprice asc) cnt" +
  95. " from wrtrade_orderdetail t" +
  96. " where t.wrtradetype = 1 and t.isspecified=0 and t.buyorsell = 1 and t.wrtradeorderstatus in(3,7) %v " +
  97. " ) a" +
  98. " where a.cnt = 1" +
  99. " group by a.wrfactortypeid, a.fixedprice, a.deliverymonth)," +
  100. "wrQuote as (" +
  101. " select nvl(k1.wrfactortypeid, k2.wrfactortypeid) wrfactortypeid," +
  102. " nvl(k1.deliverymonth, k2.deliverymonth) deliverymonth," +
  103. " k1.buyPrice," +
  104. " k1.buyQty," +
  105. " k2.sellPrice," +
  106. " k2.sellQty" +
  107. " from buyQuote k1" +
  108. " full join sellQuote k2" +
  109. " on k1.wrfactortypeid = k2.wrfactortypeid and k1.deliverymonth = k2.deliverymonth" +
  110. ")" +
  111. "select k.*," +
  112. " w.wrfactortypename," +
  113. " w.deliverygoodsid," +
  114. " w.wrstandardid," +
  115. " w.warehouseid," +
  116. " dg.deliverygoodsname," +
  117. " dg.deliverygoodscode," +
  118. " h.warehousename," +
  119. " h.warehousecode," +
  120. " wg.wrstandardname," +
  121. " wg.wrstandardcode," +
  122. " wg.minivalue," +
  123. " wg.wrstandardname || w.wrfactortypename2 as wrgoodsname," +
  124. " wg.bannerpicurl," +
  125. " wg.pictureurls," +
  126. " wg.thumurls," +
  127. " e.enumdicname" +
  128. " from wrQuote k" +
  129. " left join WRFactorType w" +
  130. " on k.wrfactortypeid = w.wrfactortypeid" +
  131. " left join deliverygoods dg" +
  132. " on w.deliverygoodsid = dg.deliverygoodsid" +
  133. " left join wrstandard wg" +
  134. " on w.wrstandardid = wg.wrstandardid" +
  135. " left join warehouseinfo h" +
  136. " on w.warehouseid = h.autoid" +
  137. " left join enumdicitem e" +
  138. " on e.enumitemname = wg.unitid" +
  139. " and e.enumdiccode = 'goodsunit'" +
  140. " where 1=1 %v " +
  141. "order by deliverygoodsname"
  142. var param, param2 utils.SQLVal
  143. param.AndEx("t.haswr", r.HasWr, r.HasWr >= 0)
  144. param.And("t.wrpricetype", r.WrPriceType)
  145. param.AndEx("t.marketid", r.MarketId, r.MarketId > 0)
  146. param.AndEx("t.wrfactortypeid", r.WRFACTORTYPEID, len(r.WRFACTORTYPEID) > 0)
  147. param.AndEx("t.deliverymonth", r.DELIVERYMONTH, len(r.DELIVERYMONTH) > 1)
  148. if d, ok := r.ftItemName(); ok {
  149. param2.AndLikes2("w.wrfactortypename", "w.wrfactortypename2", d...)
  150. }
  151. //指定品类id
  152. if r.WRSTANDARDID > 0 {
  153. param2.AndEx("w.wrstandardid", r.WRSTANDARDID, r.WRSTANDARDID > 0)
  154. } else {
  155. //品牌过滤
  156. if r.BrandId > 0 {
  157. param2.JoinFormat(" and w.WRSTANDARDID in(select WRSTANDARDID from WRStandardFactoryItem t "+
  158. "where dgfactoryitemtypeid = 100 and t.dgfactoryitemid=%d)", r.BrandId)
  159. }
  160. //年份过滤
  161. if r.YearsId > 0 {
  162. param2.JoinFormat(" and w.WRSTANDARDID in(select WRSTANDARDID from WRStandardFactoryItem t "+
  163. "where dgfactoryitemtypeid = 101 and t.dgfactoryitemid=%d)", r.YearsId)
  164. }
  165. }
  166. param2.AndEx("w.warehouseid", r.WAREHOUSEID, r.WAREHOUSEID > 0)
  167. param2.AndEx("w.deliverygoodsid", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0)
  168. sqlId.FormatParam(param.String(), param.String(), param2.String())
  169. sqlId.Page(r.Page, r.PageSize)
  170. return sqlId.String()
  171. }
  172. // buildSqlPriceMove 浮动价
  173. func (r *WrOrderQuote) buildSqlPriceMove() string {
  174. var sqlId utils.SQLVal = "with buyQuote as" +
  175. " (select to_char(a.wrfactortypeid) wrfactortypeid," +
  176. " a.pricemove buypricemove," +
  177. " sum(a.orderqty) buyQty," +
  178. " a.goodsid," +
  179. " a.goodscode," +
  180. " a.deliverymonth" +
  181. " from (select t.wrfactortypeid," +
  182. " t.marketid," +
  183. " t.buyorsell," +
  184. " t.orderqty - t.tradeqty as orderqty," +
  185. " t.pricemove," +
  186. " t.wrtradeorderid," +
  187. " nvl(t.deliverymonth,'0') deliverymonth," +
  188. " c.goodsid," +
  189. " c.goodscode," +
  190. " rank() over(partition by t.wrfactortypeid, nvl(t.deliverymonth,'0'), c.goodsid order by t.pricemove desc) cnt" +
  191. " from wrtrade_orderdetail t" +
  192. " left join WRTrade_GoodsConfig c" +
  193. " on t.wrtradeorderid = c.wrtradeorderid" +
  194. " where t.wrtradetype = 1 and t.isspecified=0 and t.wrtradeorderstatus in(3, 7)" +
  195. " and t.buyorsell = 0 %v) a" +
  196. " where a.cnt = 1" +
  197. " group by a.wrfactortypeid, a.pricemove, a.goodsid, a.goodscode, a.deliverymonth)," +
  198. "sellQuote as" +
  199. " (select to_char(a.wrfactortypeid) wrfactortypeid," +
  200. " a.pricemove sellpricemove," +
  201. " a.goodsid," +
  202. " a.goodscode," +
  203. " a.deliverymonth," +
  204. " sum(a.orderqty) sellQty" +
  205. " from (select t.wrfactortypeid," +
  206. " t.marketid," +
  207. " t.buyorsell," +
  208. " t.orderqty - t.tradeqty as orderqty," +
  209. " t.pricemove," +
  210. " nvl(t.deliverymonth,'0') deliverymonth," +
  211. " c.goodsid," +
  212. " c.goodscode," +
  213. " rank() over(partition by t.wrfactortypeid, nvl(t.deliverymonth,'0'), c.goodsid order by t.pricemove asc) cnt" +
  214. " from wrtrade_orderdetail t" +
  215. " left join WRTrade_GoodsConfig c" +
  216. " on t.wrtradeorderid = c.wrtradeorderid" +
  217. " where t.wrtradetype = 1 and t.isspecified=0 and t.wrtradeorderstatus in(3, 7)" +
  218. " and t.buyorsell = 1 %v) a" +
  219. " where a.cnt = 1" +
  220. " group by a.wrfactortypeid, a.pricemove, a.goodsid, a.goodscode, a.deliverymonth)," +
  221. "wrQuote as" +
  222. " (select nvl(k1.wrfactortypeid, k2.wrfactortypeid) wrfactortypeid," +
  223. " nvl(k1.goodsid, k2.goodsid) goodsid," +
  224. " nvl(k1.goodscode, k2.goodscode) goodscode," +
  225. " nvl(k1.deliverymonth, k2.deliverymonth) deliverymonth," +
  226. " k1.buypricemove," +
  227. " k1.buyQty," +
  228. " k2.sellpricemove," +
  229. " k2.sellQty" +
  230. " from buyQuote k1" +
  231. " full join sellQuote k2" +
  232. " on k1.wrfactortypeid = k2.wrfactortypeid and nvl(k1.deliverymonth,0) = nvl(k2.deliverymonth,0))" +
  233. "select k.*," +
  234. " w.wrfactortypename," +
  235. " w.deliverygoodsid," +
  236. " w.wrstandardid," +
  237. " w.warehouseid," +
  238. " dg.deliverygoodsname," +
  239. " dg.deliverygoodscode," +
  240. " h.warehousename," +
  241. " h.warehousecode," +
  242. " wg.wrstandardname," +
  243. " wg.wrstandardcode," +
  244. " wg.minivalue," +
  245. " wg.wrstandardname || w.wrfactortypename2 as wrgoodsname," +
  246. " wg.bannerpicurl," +
  247. " wg.pictureurls," +
  248. " wg.thumurls," +
  249. " e.enumdicname" +
  250. " from wrQuote k" +
  251. " left join WRFactorType w" +
  252. " on k.wrfactortypeid = w.wrfactortypeid" +
  253. " left join deliverygoods dg" +
  254. " on w.deliverygoodsid = dg.deliverygoodsid" +
  255. " left join wrstandard wg" +
  256. " on w.wrstandardid = wg.wrstandardid" +
  257. " left join warehouseinfo h" +
  258. " on w.warehouseid = h.autoid" +
  259. " left join enumdicitem e" +
  260. " on e.enumitemname = wg.unitid" +
  261. " and e.enumdiccode = 'goodsunit'" +
  262. " where 1 = 1 %v" +
  263. " order by deliverygoodsname"
  264. var param, param2 utils.SQLVal
  265. param.AndEx("t.haswr", r.HasWr, r.HasWr >= 0)
  266. param.And("t.wrpricetype", r.WrPriceType)
  267. param.AndEx("t.marketid", r.MarketId, r.MarketId > 0)
  268. param.AndEx("t.wrfactortypeid", r.WRFACTORTYPEID, len(r.WRFACTORTYPEID) > 0)
  269. param.AndEx("t.deliverymonth", r.DELIVERYMONTH, len(r.DELIVERYMONTH) > 1)
  270. if d, ok := r.ftItemName(); ok {
  271. param2.AndLikes("w.wrfactortypename", d...)
  272. }
  273. //指定品类id
  274. if r.WRSTANDARDID > 0 {
  275. param2.AndEx("w.wrstandardid", r.WRSTANDARDID, r.WRSTANDARDID > 0)
  276. } else {
  277. //品牌过滤
  278. if r.BrandId > 0 {
  279. param2.JoinFormat(" and w.WRSTANDARDID in(select WRSTANDARDID from WRStandardFactoryItem t "+
  280. "where dgfactoryitemtypeid = 100 and t.dgfactoryitemid=%d)", r.BrandId)
  281. }
  282. //年份过滤
  283. if r.YearsId > 0 {
  284. param2.JoinFormat(" and w.WRSTANDARDID in(select WRSTANDARDID from WRStandardFactoryItem t "+
  285. "where dgfactoryitemtypeid = 101 and t.dgfactoryitemid=%d)", r.YearsId)
  286. }
  287. }
  288. param2.AndEx("w.warehouseid", r.WAREHOUSEID, r.WAREHOUSEID > 0)
  289. param2.AndEx("w.deliverygoodsid", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0)
  290. sqlId.FormatParam(param.String(), param.String(), param2.String())
  291. sqlId.Page(r.Page, r.PageSize)
  292. return sqlId.String()
  293. }
  294. func (r *WrOrderQuote) buildSql() string {
  295. if r.WrPriceType == 1 {
  296. return r.buildSqlFixedPrice()
  297. } else {
  298. return r.buildSqlPriceMove()
  299. }
  300. }
  301. // GetDataByPage 获取买卖大厅行情
  302. func (r *WrOrderQuote) GetDataByPage() (interface{}, error, int, int, int) {
  303. sData := make([]WrOrderQuote, 0)
  304. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  305. total := 0
  306. for i := range sData {
  307. sData[i].calc()
  308. total = sData[i].Total
  309. }
  310. return sData, err, r.Page, r.PageSize, total
  311. }
  312. // WrOrderQuoteDetail 行情大厅明细(买卖大厅)
  313. type WrOrderQuoteDetail struct {
  314. WRTRADEORDERID string `json:"wrtradeorderid" xorm:"WRTRADEORDERID"` // 仓单贸易委托单ID(320+Unix秒时间戳(10位)+xxxxxx)
  315. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL" form:"buyorsell"` // 买卖 - 0:买 1:卖
  316. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 购买方(销售方)用户ID
  317. QTY float64 `json:"orderqty" xorm:"qty"` // 买(卖)量(=委托量-成交量)
  318. PRICE float64 `json:"fixedprice" xorm:"price"` // 买(卖)价
  319. PRICEMOVE float64 `json:"pricemove" xorm:"PRICEMOVE"` // 买(卖)升贴水- 基差
  320. USERNAME string `json:"username" xorm:"'USERNAME'"` // 购买方(销售方)
  321. ENUMDICNAME string `json:"enumdicname" xorm:"'enumdicname'"` // 单位名称
  322. MINIVALUE int32 `json:"minivalue" xorm:"'MINIVALUE'"` // 现货商品最小变动值
  323. DELIVERYMONTH string `json:"deliverymonth" xorm:"'DELIVERYMONTH'" form:"deliverymonth"` // 交收月
  324. ORDERTIME string `json:"ordertime" xorm:"'ORDERTIME'"` // 委托时间
  325. DELISTMINQTY SFLOAT64 `json:"delistminqty" xorm:"'DELISTMINQTY'"` // 起摘数量
  326. MarketId int32 `json:"marketid" xorm:"'MARKETID'" form:"marketid"` // 市场id
  327. PageEx `xorm:"extends"`
  328. WRFACTORTYPEID int64 `json:"-" form:"wrfactortypeid"` // 仓单要素id
  329. HasWr int32 `json:"-" form:"haswr"` // 是否有仓单 0-没有 1-有
  330. WrPriceType int32 `json:"-" form:"wrpricetype"` // 价格方式 - 1:固定价 2-浮动价 - [挂牌]
  331. GOODSID int32 `json:"-" form:"goodsid"` // 商品id
  332. }
  333. func (r *WrOrderQuoteDetail) calc() {
  334. r.USERNAME = EncryptByStar2(r.USERNAME)
  335. }
  336. func (r *WrOrderQuoteDetail) buildSql() string {
  337. var sqlId utils.SQLVal = "select to_char(t.wrtradeorderid) wrtradeorderid," +
  338. " to_char(t.wrfactortypeid) wrfactortypeid," +
  339. " t.userid," +
  340. " t.orderqty - t.tradeqty as qty," +
  341. " t.fixedprice as price," +
  342. " t.pricemove," +
  343. " t.wrpricetype," +
  344. " t.buyorsell," +
  345. " t.deliverymonth," +
  346. " t.delistminqty," +
  347. " t.marketid," +
  348. " to_char(t.ordertime, 'yyyy-mm-dd hh24:mi:ss') ordertime," +
  349. " u.accountname as username," +
  350. " c.goodsid," +
  351. " c.goodscode," +
  352. " wd.minivalue," +
  353. " e.enumdicname" +
  354. " from WRTRADE_ORDERDETAIL t" +
  355. " left join WRTRADE_GOODSCONFIG c" +
  356. " on t.wrtradeorderid = c.wrtradeorderid" +
  357. " left join Useraccount u" +
  358. " on t.userid = u.userid" +
  359. " left join wrfactortype w on t.wrfactortypeid=w.wrfactortypeid" +
  360. " left join wrstandard wd on w.wrstandardid=wd.wrstandardid" +
  361. " left join enumdicitem e on wd.unitid=e.enumitemname and e.enumdiccode='goodsunit'" +
  362. " where 1 = 1" +
  363. " and t.wrtradetype = 1" +
  364. " and t.isspecified = 0" +
  365. " and t.wrtradeorderstatus in (3, 7)"
  366. sqlId.And("t.haswr", r.HasWr)
  367. sqlId.And("t.wrpricetype", r.WrPriceType)
  368. sqlId.And("t.wrfactortypeid", r.WRFACTORTYPEID)
  369. sqlId.AndEx("c.goodsid", r.GOODSID, r.GOODSID > 0)
  370. sqlId.And("t.buyorsell", r.BUYORSELL)
  371. sqlId.AndEx("t.marketid", r.MarketId, r.MarketId > 0)
  372. sqlId.AndEx("t.deliverymonth", r.DELIVERYMONTH, len(r.DELIVERYMONTH) > 0)
  373. if r.BUYORSELL == 0 {
  374. if r.WrPriceType == 1 {
  375. sqlId.Join(" order by t.fixedprice desc, t.ordertime")
  376. } else {
  377. sqlId.Join(" order by t.pricemove desc, t.ordertime")
  378. }
  379. } else {
  380. if r.WrPriceType == 1 {
  381. sqlId.Join(" order by t.fixedprice asc, t.ordertime")
  382. } else {
  383. sqlId.Join(" order by t.pricemove asc, t.ordertime")
  384. }
  385. }
  386. sqlId.Page(r.Page, r.PageSize)
  387. return sqlId.String()
  388. }
  389. // GetDataByPage 获取行情大厅明细(买卖大厅)
  390. func (r *WrOrderQuoteDetail) GetDataByPage() (interface{}, error, int, int, int) {
  391. sData := make([]WrOrderQuoteDetail, 0)
  392. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  393. total := 0
  394. for i := range sData {
  395. sData[i].calc()
  396. total = sData[i].Total
  397. }
  398. return sData, err, r.Page, r.PageSize, total
  399. }
  400. // Wr2FactorType 仓单要素类型
  401. type Wr2FactorType struct {
  402. WRFACTORTYPEID string `json:"wrfactortypeid" xorm:"WRFACTORTYPEID" form:"wrfactortypeid"` // 仓单要素类型ID(212+Unix秒时间戳(10位)+xxxxxx)
  403. WRFACTORTYPENAME string `json:"wrfactortypename" xorm:"WRFACTORTYPENAME" form:"wrfactortypename"` // 仓单要素类型名称(选择项要素的名称合并显示,逗号分隔)
  404. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID" form:"deliverygoodsid"` // 品种ID
  405. WAREHOUSEID int64 `json:"warehouseid" xorm:"WAREHOUSEID" form:"warehouseid"` // 仓库ID
  406. WRSTANDARDID int64 `json:"wrstandardid" xorm:"WRSTANDARDID" form:"wrstandardid"` // 现货商品ID
  407. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"WRSTANDARDCODE" form:"wrstandardcode"` // 现货商品代码
  408. OPTIONCOMPARE string `json:"optioncompare" xorm:"OPTIONCOMPARE" form:"optioncompare"` // 选择项比较串【{选择项ID}+{冒号}+选择项值 } ,逗号分隔,头尾加逗号】-- 所有选择项拼接,用于比较
  409. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 商品名称
  410. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 品种代码
  411. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 品种名称
  412. ENUMDICNAME string `json:"enumdicname" xorm:"'enumdicname'"` // 单位名称
  413. WAREHOUSENAME string `json:"warehousename" xorm:"'WAREHOUSENAME'"` // 仓库名称
  414. MINIVALUE int32 `json:"minivalue" xorm:"'MINIVALUE'"` // 现货商品最小变动值
  415. WRTYPENAME string `json:"wrtypename" xorm:"'WRTYPENAME'"` // 商品
  416. }
  417. // Calc 计算
  418. func (r *Wr2FactorType) Calc() {
  419. if r.WRTYPENAME == "" {
  420. if len(r.WRFACTORTYPENAME) > 0 {
  421. r.WRTYPENAME = r.WRSTANDARDNAME + r.WRFACTORTYPENAME
  422. } else {
  423. r.WRTYPENAME = r.WRSTANDARDNAME
  424. }
  425. }
  426. r.WRTYPENAME = strings.ReplaceAll(r.WRTYPENAME, ",", "-")
  427. }
  428. // WrPosition 仓单贸易持仓汇总
  429. type WrPosition struct {
  430. WRPOSITIONID string `json:"wrpositionid" xorm:"WRPOSITIONID" form:"wrpositionid"` // 仓单头寸ID(201+Unix秒时间戳(10位)+xxxxxx)
  431. WRUSERID int64 `json:"wruserid" xorm:"WRUSERID" form:"userid"` // 持有人ID
  432. TOTALQTY float64 `json:"totalqty" xorm:"TOTALQTY" form:"totalqty"` // 总数量(库存数量)
  433. INCREASEQTY float64 `json:"-" xorm:"INCREASEQTY" form:"increaseqty"` // 今日增加数量
  434. DECREASEQTY float64 `json:"-" xorm:"DECREASEQTY" form:"decreaseqty"` // 今日减少数量
  435. FREEZEQTY float64 `json:"freezeqty" xorm:"FREEZEQTY" form:"freezeqty"` // 总冻结数量
  436. RELATEDQTY float64 `json:"-" xorm:"RELATEDQTY" form:"relatedqty"` // 关联数量
  437. MODIFYTIME string `json:"modifytime" xorm:"MODIFYTIME" form:"modifytime"` // 修改时间(过户时间)
  438. MODIFIERID int64 `json:"-" xorm:"MODIFIERID" form:"modifierid"` // 修改人
  439. TRADEWRQTY float64 `json:"-" xorm:"TRADEWRQTY" form:"tradewrqty"` // 订单仓单头寸总数量
  440. ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID" form:"accountid"` // 帐户ID
  441. CREDITTOTALQTY float64 `json:"credittotalqty" xorm:"CREDITTOTALQTY" form:"credittotalqty"` // 授信总数量(预售仓单:预售总量)
  442. CREDITCURQTY float64 `json:"creditcurqty" xorm:"CREDITCURQTY" form:"creditcurqty"` // 授信当前数量(预售仓单:预售当前量)
  443. CREDITFREEZEQTY float64 `json:"creditfreezeqty" xorm:"CREDITFREEZEQTY" form:"creditfreezeqty"` // 授信冻结数量(预售仓单: 当前数量)
  444. CREDITTRADEQTY float64 `json:"credittradeqty" xorm:"CREDITTRADEQTY" form:"credittradeqty"` // 授信成交数量(预售仓单:成交总量)
  445. Wr2FactorType `xorm:"extends"`
  446. ENALBEQTY float64 `json:"enalbeqty" xorm:"'ENALBEQTY'"` // 可用数量
  447. CREDITENABLEQTY float64 `json:"creditenableqty" xorm:"'CREDITENABLEQTY'"` // 授信可用数量(预售仓单: 可用数量)
  448. PLEDGEQTY float64 `json:"pledgeqty" xorm:"'-'"` // 质押数量
  449. BUYEXCUTEQTY float64 `json:"buyexcuteqty"` // 采购履约中数量
  450. SELLEXCUTEQTY float64 `json:"sellexcuteqty"` // 销售履约中数量
  451. WRPOSITIONNO string `json:"wrpositionno"` // 仓单编号
  452. QueryType int32 `json:"querytype" form:"querytype"` // 查询类型 1-现货汇总 2-库存汇总(订单汇总)
  453. HASWR int32 `json:"haswr" form:"haswr"` // 是否有仓单-卖方 - 0:无仓单 1:有仓单
  454. DGITEMNAME string `json:"-" form:"dgitemname"` // 筛选项
  455. }
  456. func (r *WrPosition) calc() {
  457. r.ENALBEQTY = r.TOTALQTY - r.FREEZEQTY
  458. r.CREDITENABLEQTY = r.CREDITCURQTY - r.CREDITFREEZEQTY
  459. r.WRPOSITIONNO = fmt.Sprintf("%v", r.WRFACTORTYPEID)
  460. r.Wr2FactorType.Calc()
  461. }
  462. // 添加履约中数量
  463. func (r *WrPosition) addPerformancePlanQty(sum WrPerformanPlanSum) {
  464. if r.DELIVERYGOODSID == sum.DELIVERYGOODSID &&
  465. r.WRSTANDARDID == sum.WRSTANDARDID &&
  466. r.WRTYPENAME == sum.WRTYPENAME {
  467. if r.QueryType == 1 || (r.QueryType == 2 && r.WAREHOUSEID == sum.WAREHOUSEID) {
  468. if sum.BUYORSELL == 0 {
  469. r.BUYEXCUTEQTY = sum.QTY
  470. } else {
  471. r.SELLEXCUTEQTY = sum.QTY
  472. }
  473. }
  474. }
  475. }
  476. func (r *WrPosition) buildSql() string {
  477. if r.QueryType == 1 {
  478. // 现货汇总 品种 + 品类 + 其它要素, 根据品种汇总
  479. return r.buildSql1()
  480. } else if r.QueryType == 2 {
  481. // 库存汇总 品种 + 仓库 + 品类 + 其它要素, 即全维度
  482. return r.buildSql2()
  483. } else {
  484. // 现货明细 仓单编号 + 品种 + 仓库 + 仓单要素 即全维度 跟库存汇总一样
  485. return r.buildSql3()
  486. }
  487. }
  488. func (r *WrPosition) buildSql1() string {
  489. var sqlId utils.SQLVal = "with tmp as" +
  490. " (select t.*," +
  491. " w.wrstandardid," +
  492. " w.warehouseid," +
  493. " wd.wrstandardname," +
  494. " wd.wrstandardname || w.wrfactortypename2 as wrtypename" +
  495. " from WRPOSITION t" +
  496. " left join WRFACTORTYPE w" +
  497. " on t.wrfactortypeid = w.wrfactortypeid" +
  498. " left join wrstandard wd" +
  499. " on w.wrstandardid = wd.wrstandardid" +
  500. " where 1=1 %v)," +
  501. "hld as" +
  502. " (select k.deliverygoodsid," +
  503. " k.wrtypename," +
  504. " k.wrstandardid," +
  505. " sum(k.TOTALQTY) TOTALQTY," +
  506. " sum(k.INCREASEQTY) INCREASEQTY," +
  507. " sum(k.DECREASEQTY) DECREASEQTY," +
  508. " sum(k.FREEZEQTY) FREEZEQTY," +
  509. " sum(k.RELATEDQTY) RELATEDQTY," +
  510. " sum(k.TRADEWRQTY) TRADEWRQTY," +
  511. " sum(k.CREDITTOTALQTY) CREDITTOTALQTY," +
  512. " sum(k.CREDITCURQTY) CREDITCURQTY," +
  513. " sum(k.CREDITFREEZEQTY) CREDITFREEZEQTY," +
  514. " sum(k.CREDITTRADEQTY) CREDITTRADEQTY" +
  515. " from tmp k" +
  516. " where 1 = 1" +
  517. " group by k.deliverygoodsid, k.wrstandardname, k.wrtypename, k.wrstandardid)" +
  518. "select h.*, g.deliverygoodsname, g.deliverygoodscode, e.enumdicname, wd.minivalue" +
  519. " from hld h" +
  520. " left join deliverygoods g" +
  521. " on h.deliverygoodsid = g.deliverygoodsid" +
  522. " left join wrstandard wd" +
  523. " on h.wrstandardid = wd.wrstandardid" +
  524. " left join enumdicitem e" +
  525. " on e.enumitemname = wd.unitid" +
  526. " and e.enumdiccode = 'goodsunit'"
  527. var param utils.SQLVal
  528. param.And("t.wruserid", r.WRUSERID)
  529. param.AndEx("w.wrstandardid", r.WRSTANDARDID, r.WRSTANDARDID > 0)
  530. param.AndEx("w.warehouseid", r.WAREHOUSEID, r.WAREHOUSEID > 0)
  531. param.AndEx("w.deliverygoodsid", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0)
  532. if d, ok := FtItemName(r.DGITEMNAME); ok {
  533. param.AndLikes("w.wrfactortypename", d...)
  534. }
  535. if r.HASWR == 0 {
  536. param.Join(" and t.CREDITTOTALQTY > 0")
  537. } else {
  538. param.Join(" and t.TOTALQTY > 0")
  539. }
  540. sqlId.FormatParam(param.String())
  541. return sqlId.String()
  542. }
  543. func (r *WrPosition) buildSql2() string {
  544. return r.buildSql3()
  545. }
  546. func (r *WrPosition) buildSql3() string {
  547. var sqlId utils.SQLVal = "SELECT to_char(t.WRPOSITIONID) WRPOSITIONID," +
  548. " t.WRUSERID," +
  549. " t.TOTALQTY," +
  550. " t.INCREASEQTY," +
  551. " t.DECREASEQTY," +
  552. " t.FREEZEQTY," +
  553. " t.RELATEDQTY," +
  554. " to_char(t.MODIFYTIME, 'yyyy-mm-dd hh24:mi:ss') MODIFYTIME," +
  555. " t.MODIFIERID," +
  556. " t.TRADEWRQTY," +
  557. " t.ACCOUNTID," +
  558. " t.CREDITTOTALQTY," +
  559. " t.CREDITCURQTY," +
  560. " t.CREDITFREEZEQTY," +
  561. " t.CREDITTRADEQTY," +
  562. " to_char(w.WRFACTORTYPEID) WRFACTORTYPEID," +
  563. " w.WRFACTORTYPENAME2 WRFACTORTYPENAME," +
  564. " w.DELIVERYGOODSID," +
  565. " w.WAREHOUSEID," +
  566. " w.WRSTANDARDID," +
  567. " w.WRSTANDARDCODE," +
  568. " w.OPTIONCOMPARE," +
  569. " dg.deliverygoodscode," +
  570. " dg.deliverygoodsname," +
  571. " wd.wrstandardcode," +
  572. " wd.wrstandardname," +
  573. " wd.minivalue," +
  574. " h.warehousecode," +
  575. " h.warehousename," +
  576. " e.enumdicname" +
  577. " FROM WRPOSITION t" +
  578. " LEFT JOIN WRFACTORTYPE w" +
  579. " on t.wrfactortypeid = w.wrfactortypeid" +
  580. " LEFT JOIN DELIVERYGOODS dg" +
  581. " on t.deliverygoodsid = dg.deliverygoodsid" +
  582. " LEFT JOIN WRSTANDARD wd" +
  583. " on w.wrstandardid = wd.wrstandardid" +
  584. " left join warehouseinfo h on w.warehouseid=h.autoid" +
  585. " left join enumdicitem e" +
  586. " on e.enumitemname = wd.unitid" +
  587. " and e.enumdiccode = 'goodsunit'" +
  588. " WHERE 1 = 1"
  589. sqlId.And("t.WRUSERID", r.WRUSERID)
  590. if r.HASWR == 0 {
  591. sqlId.Join(" and t.CREDITTOTALQTY > 0")
  592. } else {
  593. sqlId.Join(" and t.TOTALQTY > 0")
  594. }
  595. sqlId.AndEx("w.wrstandardid", r.WRSTANDARDID, r.WRSTANDARDID > 0)
  596. sqlId.AndEx("w.warehouseid", r.WAREHOUSEID, r.WAREHOUSEID > 0)
  597. sqlId.AndEx("w.deliverygoodsid", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0)
  598. if d, ok := FtItemName(r.DGITEMNAME); ok {
  599. sqlId.AndLikes("w.wrfactortypename", d...)
  600. }
  601. return sqlId.String()
  602. }
  603. // GetDataEx 获取仓单贸易持仓汇总
  604. func (r *WrPosition) GetDataEx() (interface{}, error) {
  605. sData := make([]WrPosition, 0)
  606. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  607. for i := range sData {
  608. sData[i].calc()
  609. sData[i].QueryType = r.QueryType
  610. sData[i].HASWR = r.HASWR
  611. }
  612. // 查履约中的数量
  613. if len(sData) > 0 {
  614. if r.QueryType == 1 || r.QueryType == 2 {
  615. m := WrPerformanPlanSum{QueryType: r.QueryType, USERID: r.WRUSERID}
  616. if d, err := m.GetData(); err == nil {
  617. for i := range sData {
  618. for _, sum := range d {
  619. sData[i].addPerformancePlanQty(sum)
  620. }
  621. }
  622. }
  623. }
  624. }
  625. return sData, err
  626. }
  627. // WrOrderDetail 仓单贸易委托单
  628. type WrOrderDetail struct {
  629. HASWR int32 `json:"haswr" xorm:"HASWR" form:"haswr"` // 是否有仓单-卖方 - 0:无仓单 1:有仓单
  630. WRTRADEORDERID string `json:"wrtradeorderid" xorm:"WRTRADEORDERID"` // 仓单贸易委托单ID(320+Unix秒时间戳(10位)+xxxxxx)
  631. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE" form:"tradedate"` // 交易日(yyyyMMdd)
  632. WRTRADETYPE int32 `json:"wrtradetype" xorm:"WRTRADETYPE" form:"wrtradetype"` // 仓单贸易类型 - 1:挂牌 2:摘牌 3:提货卖(文化中国) 4:提货买(文化中国)
  633. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL" form:"buyorsell"` // 买卖 - 0:买 1:卖(挂牌类型 买为采购 卖为销售)
  634. MARKETID int64 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID
  635. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 用户ID
  636. WRFACTORTYPEID string `json:"wrfactortypeid" xorm:"WRFACTORTYPEID"` // 仓单要素类型ID/商品ID(77)
  637. ORDERQTY float64 `json:"orderqty" xorm:"ORDERQTY" form:"orderqty"` // 委托数量
  638. TRADEQTY float64 `json:"tradeqty" xorm:"TRADEQTY" form:"tradeqty"` // 成交数量
  639. CANCELQTY float64 `json:"cancelqty" xorm:"CANCELQTY" form:"cancelqty"` // 撤销数量
  640. WRPRICETYPE int32 `json:"wrpricetype" xorm:"WRPRICETYPE" form:"wrpricetype"` // 价格方式 - 1:固定价 2-浮动价 - [挂牌]
  641. FIXEDPRICE float64 `json:"fixedprice" xorm:"FIXEDPRICE" form:"fixedprice"` // 固定价格 - [挂牌]
  642. PRICEMOVE float64 `json:"pricemove" xorm:"PRICEMOVE" form:"pricemove"` // 升贴水(浮动价时填写) - [挂牌]
  643. TRADEPRICE float64 `json:"tradeprice" xorm:"TRADEPRICE" form:"tradeprice"` // 成交价格 - [摘牌] (浮动价 ((商品1价格*商品1价格系数+升贴水)* 商品1重量系数 + 商品2价格*商品2价格系数+商品2升贴水)* 商品2重量系数 ...)* 委托单价格系数 + 委托单升贴水)
  644. ORDERTIME string `json:"ordertime" xorm:"ORDERTIME" form:"ordertime"` // 委托时间(挂牌时间)
  645. WRTRADEORDERSTATUS int32 `json:"wrtradeorderstatus" xorm:"WRTRADEORDERSTATUS"` // 委托状态 - 1:委托请求 2:待冻结 3:委托成功 4:委托失败 5:配对成功 6:已撤 7:部成 8:已成 9:部成部撤 10:成交失败 11:委托拒绝 12:经过摘牌(先摘后挂专用) 13:冻结成功(通道交易专用) 14:通道已撤 15:通道部成部撤 16:成交失败违约(荷兰式竞拍专用) 17:冻结PD成功 18:冻结PD失败 19:冻结能量成功 20:冻结能量失败 21:预约已报价 22:过期未付 23:优惠券处理中 24:仓单生成失败 25:首付扣款失败 26:履约失败 27:撤单解冻贷款失败
  646. GOODSID int32 `json:"goodsid" xorm:"'GOODSID'"` // 期货商品id
  647. GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 期货合约
  648. GOODSNAME string `json:"goodsname" xorm:"'GOODSNAME'"` // 商品名称
  649. FUTUPRICEMOVE float64 `json:"futupricemove" xorm:"'FUTUPRICEMOVE'"` // 期货升贴水
  650. DELIVERYMONTH string `json:"deliverymonth" xorm:"'DELIVERYMONTH'"` // 交收月
  651. MARGINVALUE SFLOAT64 `json:"marginvalue" xorm:"'MARGINVALUE'"` // 保证金设置值(履约保证金)
  652. FREEZEMARGIN SFLOAT64 `json:"freezemargin" xorm:"'FREEZEMARGIN'"` // 冻结保证金(保证金)
  653. FREEZECHARGE SFLOAT64 `json:"freezecharge" xorm:"'FREEZECHARGE'"` // 冻结手续费
  654. DELISTMINQTY int64 `json:"delistminqty" xorm:"'DELISTMINQTY'"` // 起摘数量
  655. CANBARGAIN int32 `json:"canbargain" xorm:"'CANBARGAIN'"` // 是否可议价 - 0:不可 1:可
  656. CANPART int32 `json:"canpart" xorm:"'CANPART'"` // 是否允许部份摘牌 - 0:不允许(要求整单) 1:允许(可以不整单)
  657. ALLFRIENDSFLAG int32 `json:"allfriendsflag" xorm:"'ALLFRIENDSFLAG'"` // 是否全好友可见 - 0:否 1:是
  658. ISSPECIFIED int32 `json:"isspecified" xorm:"'ISSPECIFIED'"` // 是否指定对手 - 0:不指定 1:指定 - [挂牌]
  659. ACCOUNTID int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 交易账号(资金账号)
  660. MATCHUSERID int64 `json:"-" xorm:"'MATCHUSERID'"` // 对手方id- 作废 可能存在多个对方id
  661. MATCHUSERNAME string `json:"matchusername" xorm:"'MATCHUSERNAME'"` // 对手方名称(当ISSPECIFIED=1时,有值,指定朋友的名称)
  662. VALIDTYPE int32 `json:"validtype" xorm:"'VALIDTYPE'"` // 有效类型 - 1当日有效 2本周有效 3指定日期有效 4一直有效
  663. VALIDTIME string `json:"validtime" xorm:"'VALIDTIME'"` // 挂牌有效期
  664. TANAME string `json:"taname" xorm:"'TANAME'"` // 交易用户名称(资金账号名称)
  665. PERFORMANCETEMPLATEID int64 `json:"performancetemplateid" xorm:"'PERFORMANCETEMPLATEID'"` // 履约模板id
  666. LADINGBILLID string `json:"ladingbillid" xorm:"LADINGBILLID" form:"ladingbillid"` // 提单ID(208+Unix秒时间戳(10位)+xxxxxx)
  667. SUBNUM int32 `json:"-" xorm:"SUBNUM" form:"subnum"` // 提单子单号
  668. BANNERPICURL string `json:"bannerpicurl" xorm:"BANNERPICURL"` // Banner图
  669. THUMURLS string `json:"thumurls" xorm:"thumurls"` // 缩略图
  670. UNITID int32 `json:"unitid" xorm:"UNITID"` // 现货商品单位ID
  671. Wr2FactorType `xorm:"extends"`
  672. PageEx `xorm:"extends"`
  673. FUTUSHOW string `json:"futushow"` // 期货合约/升贴水
  674. AMOUNT SFLOAT64 `json:"amount"` // 挂牌金额 = 委托数量 * 固定价或升贴水
  675. BEGINDATE string `json:"begindate" form:"begindate"` // 开始交易日(yyyymmdd)
  676. ENDDATE string `json:"enddate" form:"enddate"` // 结束交易日(yyyymmdd)
  677. BCancel int32 `json:"-" form:"bcancel"` // 是否仅查可撤单据 1:可撤 注:此参数仅对当前记录有效, 且不含47模式市场
  678. }
  679. func (r *WrOrderDetail) calc() {
  680. if r.GOODSCODE == "" {
  681. r.FUTUSHOW = "-"
  682. } else {
  683. r.FUTUSHOW = fmt.Sprintf("%v/%.2f", r.GOODSNAME, r.PRICEMOVE)
  684. }
  685. r.Wr2FactorType.Calc()
  686. if r.WRPRICETYPE == 1 {
  687. r.AMOUNT.Set(r.ORDERQTY * r.FIXEDPRICE)
  688. } else {
  689. r.AMOUNT.Set(r.ORDERQTY * r.PRICEMOVE)
  690. }
  691. // 对手名字脱敏
  692. if len(r.MATCHUSERNAME) > 0 {
  693. var newStr string
  694. str := strings.Split(r.MATCHUSERNAME, ",")
  695. for i := range str {
  696. sItem := strings.Split(str[i], " ")
  697. if len(sItem) == 2 {
  698. sItem[1] = EncryptByStar(sItem[1])
  699. if len(newStr) > 0 {
  700. newStr += "、 "
  701. }
  702. newStr += sItem[0] + " " + sItem[1]
  703. }
  704. }
  705. r.MATCHUSERNAME = newStr
  706. }
  707. if r.SUBNUM > 0 {
  708. r.LADINGBILLID += fmt.Sprintf("-%v", r.SUBNUM)
  709. }
  710. }
  711. func (r *WrOrderDetail) buildSql() string {
  712. var sqlId utils.SQLVal = `
  713. with tmp as
  714. (select to_char(t.wrfactortypeid) wrfactortypeid,
  715. t.wrfactortypename2 wrfactortypename,
  716. t.wrstandardid,
  717. t.deliverygoodsid,
  718. g.deliverygoodscode,
  719. g.deliverygoodsname,
  720. w.wrstandardcode,
  721. w.wrstandardname,
  722. w.bannerpicurl,
  723. w.thumurls,
  724. h.warehousecode,
  725. h.warehousename,
  726. e.enumdicname,
  727. w.wrstandardname || t.wrfactortypename2 as wrtypename,
  728. w.unitid
  729. from wrfactortype t
  730. left join deliverygoods g
  731. on t.deliverygoodsid = g.deliverygoodsid
  732. left join wrstandard w
  733. on t.wrstandardid = w.wrstandardid
  734. left join warehouseinfo h
  735. on t.warehouseid = h.autoid
  736. left join enumdicitem e
  737. on w.unitid = e.enumitemname
  738. and e.enumdiccode = 'goodsunit'),
  739. mr as (
  740. select q.wrtradeorderid, wm_concat(u.userid||' '||u.accountname) matchusername from wrtrade_matchdetail q
  741. left join useraccount u on q.matchuserid=u.userid
  742. group by q.wrtradeorderid
  743. )
  744. select t.HASWR,
  745. t.validtype,
  746. to_char(t.validtime,'yyyy-mm-dd hh24:mi:ss') validtime,
  747. to_char(t.WRTRADEORDERID) WRTRADEORDERID,
  748. t.TRADEDATE,
  749. t.DELIVERYMONTH,
  750. t.WRTRADETYPE,
  751. t.BUYORSELL,
  752. t.MARKETID,
  753. t.USERID,
  754. t.ORDERQTY,
  755. t.TRADEQTY,
  756. t.CANCELQTY,
  757. t.WRPRICETYPE,
  758. t.FIXEDPRICE,
  759. t.PRICEMOVE,
  760. t.TRADEPRICE,
  761. to_char(t.ORDERTIME, 'yyyy-mm-dd hh24:mi:ss') ORDERTIME,
  762. t.WRTRADEORDERSTATUS,
  763. t.marginvalue,
  764. t.freezemargin,
  765. t.freezecharge,
  766. t.delistminqty,
  767. t.canbargain,
  768. t.canpart,
  769. t.allfriendsflag,
  770. t.isspecified,
  771. t.accountid,
  772. t.performancetemplateid,
  773. c.GOODSID,
  774. c.GOODSCODE,
  775. c.pricemove FUTUPRICEMOVE,
  776. g.goodsname,
  777. mr.matchusername,
  778. ta.accountname taname,
  779. to_char(b.ladingbillid) ladingbillid,
  780. b.subnum,
  781. k.*
  782. from wrtrade_orderdetail t
  783. left join wrtrade_goodsconfig c
  784. on t.wrtradeorderid = c.wrtradeorderid
  785. left join wrtrade_orderdetaillb b on t.wrtradeorderid=b.wrtradeorderid
  786. left join goods g
  787. on c.goodsid = g.goodsid
  788. left join tmp k
  789. on t.wrfactortypeid = k.wrfactortypeid
  790. left join mr
  791. on t.wrtradeorderid = mr.wrtradeorderid
  792. left join taaccount ta
  793. on t.accountid = ta.accountid
  794. where t.WRTRADEORDERSTATUS not in(2)
  795. `
  796. sqlId.And("t.USERID", r.USERID)
  797. sqlId.And("t.haswr", r.HASWR)
  798. sqlId.AndEx("t.marketid", r.MARKETID, r.MARKETID > 0)
  799. sqlId.AndEx("t.wrtradetype", r.WRTRADETYPE, r.WRTRADETYPE > 0)
  800. if r.BCancel == 1 {
  801. // 只查委托状态=3 委托成功的单, 且不含47模式的
  802. sqlId.Join(" and t.WRTRADEORDERSTATUS=3 and t.marketid not in(select marketid from market where trademode = 47)")
  803. }
  804. sqlId.Join(" order by t.ORDERTIME desc")
  805. sqlId.Page(r.Page, r.PageSize)
  806. return sqlId.String()
  807. }
  808. func (r *WrOrderDetail) buildSqlHis() string {
  809. var sqlId utils.SQLVal = `
  810. with tmp as
  811. (select to_char(t.wrfactortypeid) wrfactortypeid,
  812. t.wrfactortypename2 wrfactortypename,
  813. t.wrstandardid,
  814. t.deliverygoodsid,
  815. g.deliverygoodscode,
  816. g.deliverygoodsname,
  817. w.wrstandardcode,
  818. w.wrstandardname,
  819. h.warehousecode,
  820. h.warehousename,
  821. e.enumdicname,
  822. w.wrstandardname || t.wrfactortypename2 as wrtypename
  823. from wrfactortype t
  824. left join deliverygoods g
  825. on t.deliverygoodsid = g.deliverygoodsid
  826. left join wrstandard w
  827. on t.wrstandardid = w.wrstandardid
  828. left join warehouseinfo h
  829. on t.warehouseid = h.autoid
  830. left join enumdicitem e
  831. on w.unitid = e.enumitemname
  832. and e.enumdiccode = 'goodsunit'),
  833. mr as (
  834. select q.wrtradeorderid, wm_concat(u.userid||' '||u.accountname) matchusername from wrtrade_matchdetail q
  835. left join useraccount u on q.matchuserid=u.userid
  836. group by q.wrtradeorderid
  837. )
  838. select t.HASWR,
  839. to_char(t.validtime,'yyyy-mm-dd hh24:mi:ss') validtime,
  840. to_char(t.WRTRADEORDERID) WRTRADEORDERID,
  841. t.TRADEDATE,
  842. t.DELIVERYMONTH,
  843. t.WRTRADETYPE,
  844. t.BUYORSELL,
  845. t.MARKETID,
  846. t.USERID,
  847. t.ORDERQTY,
  848. t.TRADEQTY,
  849. t.CANCELQTY,
  850. t.WRPRICETYPE,
  851. t.FIXEDPRICE,
  852. t.PRICEMOVE,
  853. t.TRADEPRICE,
  854. to_char(t.ORDERTIME, 'yyyy-mm-dd hh24:mi:ss') ORDERTIME,
  855. t.WRTRADEORDERSTATUS,
  856. t.marginvalue,
  857. t.freezemargin,
  858. t.delistminqty,
  859. t.canbargain,
  860. t.canpart,
  861. t.allfriendsflag,
  862. t.isspecified,
  863. t.accountid,
  864. t.performancetemplateid,
  865. c.GOODSID,
  866. c.GOODSCODE,
  867. c.pricemove FUTUPRICEMOVE,
  868. g.goodsname,
  869. mr.matchusername,
  870. ta.accountname taname,
  871. to_char(b.ladingbillid) ladingbillid,
  872. b.subnum,
  873. k.*
  874. from his_wrtrade_orderdetail t
  875. left join wrtrade_goodsconfig c
  876. on t.wrtradeorderid = c.wrtradeorderid
  877. left join wrtrade_orderdetaillb b on t.wrtradeorderid=b.wrtradeorderid
  878. left join goods g
  879. on c.goodsid = g.goodsid
  880. left join tmp k
  881. on t.wrfactortypeid = k.wrfactortypeid
  882. left join mr
  883. on t.wrtradeorderid = mr.wrtradeorderid
  884. left join taaccount ta
  885. on t.accountid = ta.accountid
  886. where t.WRTRADETYPE = 1 and t.WRTRADEORDERSTATUS not in(2) and t.isvaliddata=1
  887. `
  888. sqlId.And("t.USERID", r.USERID)
  889. sqlId.And("t.haswr", r.HASWR)
  890. sqlId.AndEx("t.marketid", r.MARKETID, r.MARKETID > 0)
  891. // 格式 yyyymmdd
  892. if len(r.BEGINDATE) > 0 {
  893. sqlId.JoinFormat(" and t.TRADEDATE >= '%v'", r.BEGINDATE)
  894. }
  895. if len(r.ENDDATE) > 0 {
  896. sqlId.JoinFormat(" and t.TRADEDATE <= '%v'", r.ENDDATE)
  897. }
  898. sqlId.Join(" order by t.ORDERTIME desc")
  899. sqlId.Page(r.Page, r.PageSize)
  900. return sqlId.String()
  901. }
  902. // GetDataByPage 获取仓单贸易委托单
  903. func (r *WrOrderDetail) GetDataByPage() (interface{}, error, int, int, int) {
  904. var sqlId string
  905. // 如果指定了开始日期或结束日期, 刚查历史
  906. if r.BEGINDATE != "" || r.ENDDATE != "" {
  907. sqlId = r.buildSqlHis()
  908. } else {
  909. sqlId = r.buildSql()
  910. }
  911. sData := make([]WrOrderDetail, 0)
  912. err := db.GetEngine().SQL(sqlId).Find(&sData)
  913. total := 0
  914. for i := range sData {
  915. sData[i].calc()
  916. total = sData[i].Total
  917. }
  918. return sData, err, r.Page, r.PageSize, total
  919. }
  920. // WrTradeDetail 仓单贸易成交明细
  921. type WrTradeDetail struct {
  922. HASWR int32 `json:"haswr" xorm:"HASWR" form:"haswr"` // 是否有仓单-卖方 - 0:无仓单 1:有仓单
  923. WRTRADEDETAILID string `json:"wrtradedetailid" xorm:"WRTRADEDETAILID"` // 仓单贸易成交单ID(321+Unix秒时间戳(10位)+xxxxxx)
  924. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE" form:"tradedate"` // 交易日(yyyyMMdd)
  925. WRTRADETYPE int32 `json:"wrtradetype" xorm:"WRTRADETYPE" form:"wrtradetype"` // 仓单贸易类型 - 1:挂牌 2:摘牌 3:提货卖(文化中国) 4:提货买(文化中国)
  926. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL" form:"buyorsell"` // 买卖 - 0:买 1:卖(挂牌类型 买为采购 卖为销售)
  927. MARKETID int64 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID
  928. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 用户ID
  929. WRFACTORTYPEID int64 `json:"wrfactortypeid" xorm:"WRFACTORTYPEID"` // 仓单要素类型ID/商品ID(77)
  930. TRADEQTY float64 `json:"tradeqty" xorm:"TRADEQTY" form:"tradeqty"` // 成交数量
  931. TRADEPRICE float64 `json:"tradeprice" xorm:"TRADEPRICE" form:"tradeprice"` // 成交价格
  932. CHARGEVALUE float64 `json:"chargevalue" xorm:"'CHARGEVALUE'"` // 手续费
  933. TRADETIME string `json:"tradetime" xorm:"TRADETIME" form:"tradetime"` // 成交时间
  934. DELIVERYMONTH string `json:"deliverymonth" xorm:"'DELIVERYMONTH'"` // 交收月
  935. ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID"` // 资金账号
  936. MATCHACCOUNTID int64 `json:"matchaccountid" xorm:"MATCHACCOUNTID"` // 对手账号
  937. MATCHUSERNAME string `json:"matchusername" xorm:"'MATCHUSERNAME'"` // 对手方
  938. BANNERPICURL string `json:"bannerpicurl" xorm:"BANNERPICURL"` // Banner图
  939. THUMURLS string `json:"thumurls" xorm:"thumurls"` // 缩略图
  940. Wr2FactorType `xorm:"extends"`
  941. PageEx `xorm:"extends"`
  942. BEGINDATE string `json:"begindate" form:"begindate"` // 开始交易日(yyyymmdd)
  943. ENDDATE string `json:"enddate" form:"enddate"` // 结束交易日(yyyymmdd)
  944. UNITID int32 `json:"unitid" xorm:"UNITID"` // 现货商品单位ID
  945. }
  946. func (r *WrTradeDetail) calc() {
  947. r.Wr2FactorType.Calc()
  948. r.MATCHUSERNAME = EncryptByStar(r.MATCHUSERNAME)
  949. }
  950. func (r *WrTradeDetail) buildSql() string {
  951. var sqlId utils.SQLVal = "with tmp as" +
  952. " (select to_char(t.wrfactortypeid) wrfactortypeid," +
  953. " t.wrfactortypename," +
  954. " t.wrstandardid," +
  955. " t.deliverygoodsid," +
  956. " g.deliverygoodscode," +
  957. " g.deliverygoodsname," +
  958. " w.wrstandardcode," +
  959. " w.wrstandardname," +
  960. " w.bannerpicurl," +
  961. " w.thumurls," +
  962. " h.warehousecode," +
  963. " h.warehousename," +
  964. " e.enumdicname," +
  965. " w.wrstandardname || t.wrfactortypename2 as wrtypename," +
  966. " w.unitid" +
  967. " from wrfactortype t" +
  968. " left join deliverygoods g" +
  969. " on t.deliverygoodsid = g.deliverygoodsid" +
  970. " left join wrstandard w" +
  971. " on t.wrstandardid = w.wrstandardid" +
  972. " left join warehouseinfo h" +
  973. " on t.warehouseid = h.autoid" +
  974. " left join enumdicitem e on w.unitid = e.enumitemname and e.enumdiccode='goodsunit')" +
  975. "select t.HASWR," +
  976. " to_char(t.WRTRADEDETAILID) WRTRADEDETAILID," +
  977. " t.TRADEDATE," +
  978. " t.DELIVERYMONTH," +
  979. " t.WRTRADETYPE," +
  980. " t.BUYORSELL," +
  981. " t.MARKETID," +
  982. " t.TRADEQTY," +
  983. " t.TRADEPRICE," +
  984. " t.CHARGEVALUE," +
  985. " to_char(t.TRADETIME,'yyyy-mm-dd hh24:mi:ss') TRADETIME," +
  986. " u2.accountname matchusername," +
  987. " ta1.userid," +
  988. " k.*" +
  989. " from wrtrade_tradedetail t" +
  990. " left join tmp k" +
  991. " on t.wrfactortypeid = k.wrfactortypeid" +
  992. " left join taaccount ta1 on t.accountid=ta1.accountid" +
  993. " left join taaccount ta2 on t.matchaccountid=ta2.accountid" +
  994. " left join useraccount u2 on ta2.userid=u2.userid" +
  995. " where 1=1"
  996. sqlId.And("ta1.userid", r.USERID)
  997. sqlId.And("t.haswr", r.HASWR)
  998. sqlId.AndEx("t.marketid", r.MARKETID, r.MARKETID > 0)
  999. sqlId.Join(" order by t.tradetime desc")
  1000. sqlId.Page(r.Page, r.PageSize)
  1001. return sqlId.String()
  1002. }
  1003. func (r *WrTradeDetail) buildSqlHis() string {
  1004. var sqlId utils.SQLVal = "with tmp as" +
  1005. " (select to_char(t.wrfactortypeid) wrfactortypeid," +
  1006. " t.wrfactortypename," +
  1007. " t.wrstandardid," +
  1008. " t.deliverygoodsid," +
  1009. " g.deliverygoodscode," +
  1010. " g.deliverygoodsname," +
  1011. " w.wrstandardcode," +
  1012. " w.wrstandardname," +
  1013. " h.warehousecode," +
  1014. " h.warehousename," +
  1015. " e.enumdicname," +
  1016. " w.wrstandardname || t.wrfactortypename2 as wrtypename," +
  1017. " w.unitid" +
  1018. " from wrfactortype t" +
  1019. " left join deliverygoods g" +
  1020. " on t.deliverygoodsid = g.deliverygoodsid" +
  1021. " left join wrstandard w" +
  1022. " on t.wrstandardid = w.wrstandardid" +
  1023. " left join warehouseinfo h" +
  1024. " on t.warehouseid = h.autoid" +
  1025. " left join enumdicitem e on w.unitid = e.enumitemname and e.enumdiccode='goodsunit')" +
  1026. "select t.HASWR," +
  1027. " to_char(t.WRTRADEDETAILID) WRTRADEDETAILID," +
  1028. " t.TRADEDATE," +
  1029. " t.DELIVERYMONTH," +
  1030. " t.WRTRADETYPE," +
  1031. " t.BUYORSELL," +
  1032. " t.MARKETID," +
  1033. " t.TRADEQTY," +
  1034. " t.TRADEPRICE," +
  1035. " t.CHARGEVALUE," +
  1036. " to_char(t.TRADETIME,'yyyy-mm-dd hh24:mi:ss') TRADETIME," +
  1037. " u2.accountname matchusername," +
  1038. " ta1.userid," +
  1039. " k.*" +
  1040. " from his_wrtrade_tradedetail t" +
  1041. " left join tmp k" +
  1042. " on t.wrfactortypeid = k.wrfactortypeid" +
  1043. " left join taaccount ta1 on t.accountid=ta1.accountid" +
  1044. " left join taaccount ta2 on t.matchaccountid=ta2.accountid" +
  1045. " left join useraccount u2 on ta2.userid=u2.userid" +
  1046. " where 1=1 and t.isvaliddata=1"
  1047. sqlId.And("ta1.userid", r.USERID)
  1048. sqlId.And("t.haswr", r.HASWR)
  1049. sqlId.AndEx("t.marketid", r.MARKETID, r.MARKETID > 0)
  1050. // 格式 yyyymmdd
  1051. if len(r.BEGINDATE) > 0 {
  1052. sqlId.JoinFormat(" and t.TRADEDATE >= '%v'", r.BEGINDATE)
  1053. }
  1054. if len(r.ENDDATE) > 0 {
  1055. sqlId.JoinFormat(" and t.TRADEDATE <= '%v'", r.ENDDATE)
  1056. }
  1057. sqlId.Join(" order by t.tradetime desc")
  1058. sqlId.Page(r.Page, r.PageSize)
  1059. return sqlId.String()
  1060. }
  1061. // GetDataByPage 获取仓单贸易成交明细
  1062. func (r *WrTradeDetail) GetDataByPage() (interface{}, error, int, int, int) {
  1063. var sqlId string
  1064. // 如果指定了开始日期或结束日期, 刚查历史
  1065. if r.BEGINDATE != "" || r.ENDDATE != "" {
  1066. sqlId = r.buildSqlHis()
  1067. } else {
  1068. sqlId = r.buildSql()
  1069. }
  1070. sData := make([]WrTradeDetail, 0)
  1071. err := db.GetEngine().SQL(sqlId).Find(&sData)
  1072. total := 0
  1073. for i := range sData {
  1074. sData[i].calc()
  1075. total = sData[i].Total
  1076. }
  1077. return sData, err, r.Page, r.PageSize, total
  1078. }
  1079. // WrSpecialMatchOrder 指定对手委托
  1080. type WrSpecialMatchOrder struct {
  1081. HASWR int32 `json:"haswr" xorm:"HASWR" form:"haswr"` // 是否有仓单-卖方 - 0:无仓单 1:有仓单
  1082. WRTRADEORDERID string `json:"wrtradeorderid" xorm:"WRTRADEORDERID"` // 仓单贸易委托单ID(320+Unix秒时间戳(10位)+xxxxxx)
  1083. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE" form:"tradedate"` // 交易日(yyyyMMdd)
  1084. WRTRADETYPE int32 `json:"wrtradetype" xorm:"WRTRADETYPE" form:"wrtradetype"` // 仓单贸易类型 - 1:挂牌 2:摘牌 3:提货卖(文化中国) 4:提货买(文化中国)
  1085. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL" form:"buyorsell"` // 买卖 - 0:买 1:卖(挂牌类型 买为采购 卖为销售)
  1086. MARKETID int64 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID
  1087. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 用户ID
  1088. WRFACTORTYPEID int64 `json:"wrfactortypeid" xorm:"WRFACTORTYPEID"` // 仓单要素类型ID/商品ID(77)
  1089. ORDERQTY float64 `json:"orderqty" xorm:"ORDERQTY" form:"orderqty"` // 委托数量
  1090. TRADEQTY float64 `json:"tradeqty" xorm:"TRADEQTY" form:"tradeqty"` // 成交数量
  1091. CANCELQTY float64 `json:"cancelqty" xorm:"CANCELQTY" form:"cancelqty"` // 撤销数量
  1092. WRPRICETYPE int32 `json:"wrpricetype" xorm:"WRPRICETYPE" form:"wrpricetype"` // 价格方式 - 1:固定价 2-浮动价 - [挂牌]
  1093. FIXEDPRICE float64 `json:"fixedprice" xorm:"FIXEDPRICE" form:"fixedprice"` // 固定价格(价格)
  1094. PRICEMOVE float64 `json:"pricemove" xorm:"PRICEMOVE" form:"pricemove"` // 升贴水(浮动价时填写) - [挂牌]
  1095. TRADEPRICE float64 `json:"tradeprice" xorm:"TRADEPRICE" form:"tradeprice"` // 成交价格
  1096. ORDERTIME string `json:"ordertime" xorm:"ORDERTIME" form:"ordertime"` // 委托时间
  1097. WRTRADEORDERSTATUS int32 `json:"wrtradeorderstatus" xorm:"WRTRADEORDERSTATUS"` // 委托状态 - 1:委托请求 2:待冻结 3:委托成功 4:委托失败 5:配对成功 6:已撤 7:已成 8:成交失败 9:委托拒绝 10:挂牌部分成交 11:仓单生成失败 12:首付扣款失败 13:履约失败 14:撤单解冻贷款失败 15:部成部撤
  1098. USERNAME string `json:"username" xorm:"'USERNAME'"` // 发起方
  1099. MATCHUSERNAME string `json:"matchusername" xorm:"'MATCHUSERNAME'"` // 指定方
  1100. MATCHUSERID int64 `json:"matchuserid" xorm:"'MATCHUSERID'"` // 指定方资金账号(字段名为userid,实际存的是accountid by:邓工)
  1101. ISSPECIFIED int32 `json:"isspecified" xorm:"'ISSPECIFIED'" form:"isspecified"` // 是否指定对手 - 0:不指定 1:指定好友(贸易圈) 2:指定对手 - [挂牌]
  1102. Wr2FactorType `xorm:"extends"`
  1103. PageEx `xorm:"extends"`
  1104. AMOUNT float64 `json:"amount"` // 金额 = 数量 * 价格
  1105. }
  1106. func (r *WrSpecialMatchOrder) calc() {
  1107. r.AMOUNT = r.FIXEDPRICE * r.ORDERQTY
  1108. r.Wr2FactorType.Calc()
  1109. }
  1110. func (r *WrSpecialMatchOrder) buildSql() string {
  1111. var sqlId utils.SQLVal = "with tmp as" +
  1112. " (select t.wrfactortypeid," +
  1113. " t.wrfactortypename2 wrfactortypename," +
  1114. " t.wrstandardid," +
  1115. " t.deliverygoodsid," +
  1116. " g.deliverygoodscode," +
  1117. " g.deliverygoodsname," +
  1118. " w.wrstandardcode," +
  1119. " w.wrstandardname," +
  1120. " h.warehousecode," +
  1121. " h.warehousename," +
  1122. " e.enumdicname," +
  1123. " w.wrstandardname || t.wrfactortypename2 as wrtypename" +
  1124. " from wrfactortype t" +
  1125. " left join deliverygoods g" +
  1126. " on t.deliverygoodsid = g.deliverygoodsid" +
  1127. " left join wrstandard w" +
  1128. " on t.wrstandardid = w.wrstandardid" +
  1129. " left join warehouseinfo h" +
  1130. " on t.warehouseid = h.autoid" +
  1131. " left join enumdicitem e" +
  1132. " on w.unitid = e.enumitemname" +
  1133. " and e.enumdiccode = 'goodsunit')" +
  1134. "select t.HASWR," +
  1135. " to_char(t.WRTRADEORDERID) WRTRADEORDERID," +
  1136. " t.WRTRADETYPE," +
  1137. " t.ISSPECIFIED," +
  1138. " t.BUYORSELL," +
  1139. " t.MARKETID," +
  1140. " t.USERID," +
  1141. " t.ORDERQTY," +
  1142. " t.TRADEQTY," +
  1143. " t.CANCELQTY," +
  1144. " t.WRPRICETYPE," +
  1145. " t.FIXEDPRICE," +
  1146. " t.PRICEMOVE," +
  1147. " t.TRADEPRICE," +
  1148. " to_char(t.ORDERTIME, 'yyyy-mm-dd hh24:mi:ss') ORDERTIME," +
  1149. " t.WRTRADEORDERSTATUS," +
  1150. " m.matchuserid," +
  1151. " u1.accountname username," +
  1152. " u2.accountname matchusername," +
  1153. " k.*" +
  1154. " from wrtrade_orderdetail t" +
  1155. " left join WRTrade_MatchDetail m on t.wrtradeorderid=m.wrtradeorderid" +
  1156. " left join useraccount u1 on t.userid=u1.userid" +
  1157. " left join taaccount ta2 on m.matchuserid=ta2.accountid" +
  1158. " left join useraccount u2 on ta2.userid=u2.userid" +
  1159. " left join tmp k" +
  1160. " on t.wrfactortypeid = k.wrfactortypeid" +
  1161. " where t.WRTRADETYPE = 1" +
  1162. " and t.isspecified in (1,2)" +
  1163. " and t.WRTRADEORDERSTATUS = 3"
  1164. if r.ISSPECIFIED > 0 {
  1165. sqlId.And("t.isspecified", r.ISSPECIFIED)
  1166. } else {
  1167. sqlId.Join(" and t.isspecified in (1,2)")
  1168. }
  1169. sqlId.And("t.USERID", r.USERID)
  1170. sqlId.And("t.haswr", r.HASWR)
  1171. sqlId.AndEx("t.marketid", r.MARKETID, r.MARKETID > 0)
  1172. sqlId.Join(" order by t.ORDERTIME desc")
  1173. sqlId.Page(r.Page, r.PageSize)
  1174. return sqlId.String()
  1175. }
  1176. // GetDataByPage 获取指定对手委托
  1177. func (r *WrSpecialMatchOrder) GetDataByPage() (interface{}, error, int, int, int) {
  1178. sData := make([]WrSpecialMatchOrder, 0)
  1179. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1180. total := 0
  1181. for i := range sData {
  1182. sData[i].calc()
  1183. total = sData[i].Total
  1184. }
  1185. return sData, err, r.Page, r.PageSize, total
  1186. }
  1187. // WrFactorTypeInfo 仓单要素选择项
  1188. type WrFactorTypeInfo struct {
  1189. WRFACTORTYPEID string `json:"wrfactortypeid" xorm:"'WRFACTORTYPEID'" form:"wrfactortypeid"` // 仓单要素ID
  1190. DGFACTORYITEMTYPEID int64 `json:"dgfactoryitemtypeid" xorm:"'DGFACTORYITEMTYPEID'"` // 要素选择项ID (1-仓库 2-品牌)
  1191. ITEMTYPENAME string `json:"itemtypename" xorm:"'ITEMTYPENAME'"` // 要素项名称
  1192. DGFACTORYITEMVALUE string `json:"dgfactoryitemvalue" xorm:"'DGFACTORYITEMVALUE'"` // 要素项值
  1193. OPTIONCOMPARE string `json:"optioncompare" xorm:"'OPTIONCOMPARE'"` // 选择比较串
  1194. WAREHOUSEID int64 `json:"warehouseid" xorm:"'WAREHOUSEID'"` // 仓库id
  1195. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 品种名称
  1196. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 品种代码
  1197. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品类代码
  1198. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称
  1199. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 品类id
  1200. DGFACTORYITEMID int64 `json:"dgfactoryitemid" xorm:"'DGFACTORYITEMID'"` // 选择项id
  1201. WRFACTORTYPENAME string `json:"wrfactortypename" xorm:"'WRFACTORTYPENAME'"` // 要素名称
  1202. WRFACTORTYPENAME2 string `json:"wrfactortypename2" xorm:"'WRFACTORTYPENAME2'"` // 要素名称(不含仓库)
  1203. }
  1204. func (r *WrFactorTypeInfo) calc() {
  1205. }
  1206. func (r *WrFactorTypeInfo) buildSql() string {
  1207. var sqlId utils.SQLVal = "select to_char(t.wrfactortypeid) wrfactortypeid," +
  1208. " b.dgfactoryitemtypeid," +
  1209. " b.itemtypename," +
  1210. " c.dgfactoryitemvalue," +
  1211. " t.optioncompare," +
  1212. " t.warehouseid," +
  1213. " t.wrstandardid," +
  1214. " g.deliverygoodsname," +
  1215. " g.deliverygoodscode," +
  1216. " w.wrstandardcode," +
  1217. " w.wrstandardname," +
  1218. " c.dgfactoryitemid," +
  1219. " t.wrfactortypename," +
  1220. " t.wrfactortypename2" +
  1221. " from wrfactortype t" +
  1222. " inner join wrfactortypeitem a" +
  1223. " on t.wrfactortypeid = a.wrfactortypeid" +
  1224. " inner join dgfactoryitemtype b" +
  1225. " on t.deliverygoodsid = b.deliverygoodsid" +
  1226. " and a.dgfactoryitemtypeid = b.dgfactoryitemtypeid" +
  1227. " left join dgfactoryitem c" +
  1228. " on a.dgfactoryitemid = c.dgfactoryitemid" +
  1229. " and b.deliverygoodsid = c.deliverygoodsid" +
  1230. " left join deliverygoods g on t.deliverygoodsid=g.deliverygoodsid" +
  1231. " left join wrstandard w on t.wrstandardid=w.wrstandardid" +
  1232. " where 1 = 1"
  1233. sqlId.And("t.wrfactortypeid", r.WRFACTORTYPEID)
  1234. return sqlId.String()
  1235. }
  1236. // GetData 获取仓单要素选择项
  1237. func (r *WrFactorTypeInfo) GetData() ([]WrFactorTypeInfo, error) {
  1238. sData := make([]WrFactorTypeInfo, 0)
  1239. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1240. for i := range sData {
  1241. sData[i].calc()
  1242. }
  1243. return sData, err
  1244. }
  1245. // GetDataEx 获取仓单要素选择项
  1246. func (r *WrFactorTypeInfo) GetDataEx() (interface{}, error) {
  1247. return r.GetData()
  1248. }
  1249. // GetItemList 获取要素项列表
  1250. func (r WrFactorTypeInfo) GetItemList() ([]WrTypeItem, error) {
  1251. d, err := r.GetData()
  1252. return r.buildItemList(d), err
  1253. }
  1254. func (r *WrFactorTypeInfo) buildItemList(lst []WrFactorTypeInfo) []WrTypeItem {
  1255. lstItem := make([]WrTypeItem, 0)
  1256. if len(lst) > 0 {
  1257. a := lst[0]
  1258. lstItem = append(lstItem, WrTypeItem{NAME: "品种", VALUE: a.DELIVERYGOODSNAME})
  1259. lstItem = append(lstItem, WrTypeItem{NAME: "商品", VALUE: a.WRSTANDARDNAME})
  1260. for _, b := range lst {
  1261. lstItem = append(lstItem, WrTypeItem{NAME: b.ITEMTYPENAME, VALUE: b.DGFACTORYITEMVALUE})
  1262. }
  1263. }
  1264. return lstItem
  1265. }
  1266. // WrFactorTypeInfoEx 类型id
  1267. type WrFactorTypeInfoEx struct {
  1268. WRFACTORTYPEID string `json:"wrfactortypeid" xorm:"'WRFACTORTYPEID'" form:"wrfactortypeid"`
  1269. }
  1270. // GetDataEx 获取仓单要素选择项
  1271. func (r *WrFactorTypeInfoEx) GetDataEx() (interface{}, error) {
  1272. m := WrFactorTypeInfo{WRFACTORTYPEID: r.WRFACTORTYPEID}
  1273. return m.GetItemList()
  1274. }
  1275. // WrGoodsPerformanceStep 商品履约步骤
  1276. type WrGoodsPerformanceStep struct {
  1277. AUTOID int64 `json:"autoid" xorm:"AUTOID" form:"autoid"` // AutoID
  1278. TEMPLATEID int64 `json:"templateid" xorm:"TEMPLATEID" form:"templateid"` // 履约计划模板ID
  1279. STEPINDEX int32 `json:"stepindex" xorm:"STEPINDEX" form:"stepindex"` // 步骤序号
  1280. STEPDAYS int32 `json:"stepdays" xorm:"STEPDAYS" form:"stepdays"` // 距离上一步天数
  1281. 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模板“
  1282. STEPVALUE SFLOAT64 `json:"stepvalue" xorm:"STEPVALUE" form:"stepvalue"` // 步骤值
  1283. ISAUTO int32 `json:"isauto" xorm:"ISAUTO" form:"isauto"` // 是否自动 - 0:不自动 1:自动
  1284. REMARK string `json:"remark" xorm:"REMARK" form:"remark"` // 备注
  1285. STEPTYPENAME string `json:"steptypename" xorm:"'STEPTYPENAME'"` // 步骤名称
  1286. STEPINFO string `json:"stepinfo"` // 步骤信息(步骤名称+步骤值)
  1287. STEPDAYSINFO string `json:"stepdate"` // 天数信息(T+N)
  1288. WRSTANDARDID int64 `json:"-" form:"wrstandardid"` // 商品id
  1289. MARKETID int64 `json:"-" form:"marketid"` // 市场id
  1290. HASWR int32 `json:"-" form:"haswr"` // 是否有仓单-卖方 - 0:无仓单 1:有仓单
  1291. }
  1292. func (r *WrGoodsPerformanceStep) calc() {
  1293. switch r.STEPTYPEID {
  1294. case 1, 2, 98:
  1295. v := r.STEPVALUE * 100
  1296. v.Round(8) // fix bug: 0.56 * 100 之后变为 0.560000000001, 把后面多余的1去掉
  1297. r.STEPINFO = fmt.Sprintf("%v %v%%", r.STEPTYPENAME, v.string())
  1298. case 92:
  1299. r.STEPINFO = r.STEPTYPENAME
  1300. default:
  1301. if r.STEPVALUE == 0 {
  1302. r.STEPINFO = r.STEPTYPENAME
  1303. } else {
  1304. r.STEPINFO = fmt.Sprintf("%v %v", r.STEPTYPENAME, r.STEPVALUE)
  1305. }
  1306. }
  1307. r.STEPDAYSINFO = fmt.Sprintf("T+%v", r.STEPDAYS)
  1308. }
  1309. func (r *WrGoodsPerformanceStep) buildSqlByWrstandard() string {
  1310. var sqlId utils.SQLVal = "with tmp as" +
  1311. " (select decode(%v, 1, t.performancetempid, t.performancetempid2) tempid" +
  1312. " from marketspotgoodsconfig t" +
  1313. " where rownum <= 1 %v)" +
  1314. "select t.*, s.steptypename" +
  1315. " from PerformanceStepTemplate t" +
  1316. " inner join PerformanceStepType s" +
  1317. " on t.steptypeid = s.steptypeid" +
  1318. " inner join tmp" +
  1319. " on t.templateid = tmp.tempid" +
  1320. " order by t.stepindex"
  1321. var param utils.SQLVal
  1322. param.And("t.wrstandardid", r.WRSTANDARDID)
  1323. param.AndEx("t.marketid", r.MARKETID, r.MARKETID > 0)
  1324. sqlId.FormatParam(r.HASWR, param.String())
  1325. return sqlId.String()
  1326. }
  1327. func (r WrGoodsPerformanceStep) buildSqlByTmpId() string {
  1328. var sqlId utils.SQLVal = "select t.*, s.steptypename" +
  1329. " from PerformanceStepTemplate t" +
  1330. " inner join PerformanceStepType s" +
  1331. " on t.steptypeid = s.steptypeid" +
  1332. " where t.templateid=%v" +
  1333. " order by t.stepindex"
  1334. sqlId.FormatParam(r.TEMPLATEID)
  1335. return sqlId.String()
  1336. }
  1337. func (r WrGoodsPerformanceStep) buildSqlAll() string {
  1338. var sqlId utils.SQLVal = "select t.*, s.steptypename" +
  1339. " from PerformanceStepTemplate t" +
  1340. " inner join PerformanceStepType s" +
  1341. " on t.steptypeid = s.steptypeid" +
  1342. " where 1=1" +
  1343. " order by t.templateid, t.stepindex"
  1344. return sqlId.String()
  1345. }
  1346. func (r *WrGoodsPerformanceStep) buildSql() string {
  1347. if r.TEMPLATEID != 0 {
  1348. return r.buildSqlByTmpId()
  1349. } else if r.WRSTANDARDID > 0 {
  1350. return r.buildSqlByWrstandard()
  1351. } else {
  1352. return r.buildSqlAll()
  1353. }
  1354. }
  1355. // GetData 获取商品履约步骤
  1356. func (r *WrGoodsPerformanceStep) GetData() ([]WrGoodsPerformanceStep, error) {
  1357. sData := make([]WrGoodsPerformanceStep, 0)
  1358. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1359. for i := range sData {
  1360. sData[i].calc()
  1361. sData[i].MARKETID = r.MARKETID
  1362. sData[i].WRSTANDARDID = r.WRSTANDARDID
  1363. }
  1364. return sData, err
  1365. }
  1366. // WrTypeItem 要素项
  1367. type WrTypeItem struct {
  1368. NAME string `json:"name"` // 名称
  1369. VALUE string `json:"value"` // 值
  1370. }
  1371. // WrGoodsInfo 仓单商品信息(仓单要素列展开+履约计划步骤)
  1372. type WrGoodsInfo struct {
  1373. WRFACTORTYPEID string `json:"-" form:"wrfactortypeid"` // 仓单要素ID
  1374. MARKETID int64 `json:"marketid" form:"marketid"` // 市场id
  1375. HASWR int32 `json:"haswr" form:"haswr"` // 0:仓单预售 1:仓单贸易
  1376. LstItem []WrTypeItem `json:"lstitem"` // 商品信息项
  1377. LstStep []WrGoodsPerformanceStep `json:"lststep"` // 履约规则
  1378. TMPLATEID int64 `json:"-" form:"tmplateid"` // 履约模板id
  1379. }
  1380. // GetDataEx 获取仓单商品信息(仓单要素列展开+履约计划步骤)
  1381. func (r *WrGoodsInfo) GetDataEx() (interface{}, error) {
  1382. sData := make([]WrGoodsInfo, 0)
  1383. mWrType := WrFactorTypeInfo{WRFACTORTYPEID: r.WRFACTORTYPEID}
  1384. // 获取要素项
  1385. if sType, err := mWrType.GetData(); err == nil {
  1386. v := WrGoodsInfo{LstItem: make([]WrTypeItem, 0), LstStep: make([]WrGoodsPerformanceStep, 0)}
  1387. if len(sType) > 0 {
  1388. v.LstItem = mWrType.buildItemList(sType)
  1389. a := sType[0]
  1390. // 获取履约规则
  1391. mStep := WrGoodsPerformanceStep{}
  1392. // 如果指定了履约模板id(-1是特殊的模板id:立即执行)
  1393. if r.TMPLATEID > 0 || r.TMPLATEID == -1 {
  1394. mStep.TEMPLATEID = r.TMPLATEID
  1395. } else {
  1396. mStep.MARKETID, mStep.WRSTANDARDID, mStep.HASWR = r.MARKETID, a.WRSTANDARDID, r.HASWR
  1397. }
  1398. if sStep, err := mStep.GetData(); err == nil && len(sStep) > 0 {
  1399. v.LstStep = append(v.LstStep, sStep...)
  1400. }
  1401. }
  1402. v.MARKETID = r.MARKETID
  1403. v.HASWR = r.HASWR
  1404. v.WRFACTORTYPEID = r.WRFACTORTYPEID
  1405. sData = append(sData, v)
  1406. }
  1407. return sData, nil
  1408. }
  1409. // WrPerformancePlan 履约信息(履约计划)
  1410. type WrPerformancePlan struct {
  1411. PERFORMANCEPLANID string `json:"performanceplanid" xorm:"PERFORMANCEPLANID" form:"performanceplanid"` // 履约计划ID(130+yyMMddHHmmss+xxxx)
  1412. PERFORMANCETYPE int32 `json:"performancetype" xorm:"PERFORMANCETYPE" form:"performancetype"` // 履约类型 - 0:通用 1:交割 2:仓单贸易 3:预售集采 4:竞拍-降价式 (无仓单) 5:挂牌期权 6:竞拍-降价式 7:竞拍-竞价式 8:竞拍-大宗式 9:荷兰式 10:法币C2C 11:报价系统 12:挂牌系统
  1413. RELATEDORDERID string `json:"relatedorderid" xorm:"RELATEDORDERID" form:"relatedorderid"` // 关联单号(履约类型的关联单号)
  1414. AMOUNT float64 `json:"amount" xorm:"AMOUNT" form:"amount"` // 履约金额(总金额)
  1415. PAYMENTTYPE int32 `json:"paymenttype" xorm:"PAYMENTTYPE" form:"paymenttype"` // 付款方式 - 1:冻结 2:扣款
  1416. PERFORMANCESTATUS int32 `json:"performancestatus" xorm:"PERFORMANCESTATUS" form:"performancestatus"` // 履约状态 - 1:初始化 2:正常 3:处理错误 4:违约待处理 5:违约处理中 6:完成 7.违约已完成 8:释放冻结失败 9:超时待处理 10:超时关闭
  1417. CURSTEPID string `json:"curstepid" xorm:"CURSTEPID" form:"curstepid"` // 当前步骤ID
  1418. BUYACCOUNTID int64 `json:"buyaccountid" xorm:"BUYACCOUNTID" form:"buyaccountid"` // 买方账号
  1419. WRTRANSFERUSERID int64 `json:"wrtransferuserid" xorm:"WRTRANSFERUSERID" form:"wrtransferuserid"` // 仓单受让用户
  1420. BUYPAIDAMOUNT float64 `json:"buypaidamount" xorm:"BUYPAIDAMOUNT" form:"buypaidamount"` // 买方已冻/已扣金额 (已付金额)
  1421. SELLACCOUNTID int64 `json:"sellaccountid" xorm:"SELLACCOUNTID" form:"sellaccountid"` // 卖方账号
  1422. SELLRECEIVEDAMOUNT float64 `json:"sellreceivedamount" xorm:"SELLRECEIVEDAMOUNT"` // 卖方已收金额
  1423. CREATETIME string `json:"createtime" xorm:"CREATETIME" form:"createtime"` // 创建时间
  1424. CREATORID int64 `json:"creatorid" xorm:"CREATORID" form:"creatorid"` // 创建人
  1425. REMARK string `json:"remark" xorm:"REMARK" form:"remark"` // 备注
  1426. BUYERFREEZEAMOUNT float64 `json:"buyerfreezeamount" xorm:"BUYERFREEZEAMOUNT"` // 履约冻结(买履约)
  1427. BUYERFREEZEAMOUNTREMAIN float64 `json:"buyerfreezeamountremain" xorm:"BUYERFREEZEAMOUNTREMAIN"` // 履约冻结剩余(买履约)
  1428. SELLERFREEZEAMOUNT float64 `json:"sellerfreezeamount" xorm:"SELLERFREEZEAMOUNT"` // 履约冻结(卖履约)
  1429. SELLERFREEZEAMOUNTREMAIN float64 `json:"sellerfreezeamountremain" xorm:"SELLERFREEZEAMOUNTREMAIN"` // 履约冻结剩余(卖履约)
  1430. OVERSHORTAMOUNT float64 `json:"overshortamount" xorm:"OVERSHORTAMOUNT" form:"overshortamount"` // 溢短金额
  1431. HASOVERSHORT int32 `json:"hasovershort" xorm:"HASOVERSHORT" form:"hasovershort"` // 是否确认溢短 - 0:没有 1:买方确认 2:卖方确认
  1432. SHIPREMARK string `json:"shipremark" xorm:"SHIPREMARK" form:"shipremark"` // 发货备注[物流单号]
  1433. MIDDLEUSERID int64 `json:"middleuserid" xorm:"MIDDLEUSERID" form:"middleuserid"` // 中间商用户ID
  1434. MIDDLEACCOUNTID int64 `json:"middleaccountid" xorm:"MIDDLEACCOUNTID" form:"middleaccountid"` // 中间商资金账号ID
  1435. HASWR int32 `json:"haswr" xorm:"HASWR" form:"haswr"` // 类型 0-仓单预售 1-仓单贸易
  1436. OVERSHORTQTY float64 `json:"overshortqty" xorm:"OVERSHORTQTY" form:"overshortqty"` // 溢短数量
  1437. MARKETID int32 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID
  1438. EXPRESSFEECONFIRMED int32 `json:"expressfeeconfirmed" xorm:"EXPRESSFEECONFIRMED"` // 是否确认运费 - 0:无 1:买方确认 2:卖方确认
  1439. EXPRESSFEE float64 `json:"expressfee" xorm:"EXPRESSFEE" form:"expressfee"` // 运费
  1440. CONTRACTID int64 `json:"contractid" xorm:"CONTRACTID" form:"contractid"` // 合同ID
  1441. CURSTEPDEADLINE string `json:"curstepdeadline" xorm:"CURSTEPDEADLINE" form:"curstepdeadline"` // 当前步骤到期时间
  1442. STARTTIME string `json:"starttime" xorm:"'STARTTIME'"` // 开始时间
  1443. QTY float64 `json:"qty" xorm:"QTY" form:"qty"` // 履约数量
  1444. 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模板“
  1445. ACTIVATEMONTH string `json:"activatemonth" xorm:"'ACTIVATEMONTH'"` // 履约激活月 [无仓单的交易收月](yyyy-MM)
  1446. Wr2FactorType `xorm:"extends"`
  1447. CURSTEPNAME string `json:"curstepname" xorm:"'CURSTEPNAME'"` // 当前步骤名称
  1448. BUYUSERNAME string `json:"buyusername" xorm:"'BUYUSERNAME'"` // 买方名字
  1449. SELLUSERNAME string `json:"sellusername" xorm:"'SELLUSERNAME'"` // 卖方名字
  1450. TYPENAME string `json:"typename" xorm:"'TYPENAME'"` // 履约类型 名称
  1451. USERID int64 `json:"userid" form:"userid" binding:"required"` // 用户id
  1452. BUYORSELL int32 `json:"buyorsell" form:"buyorsell"` // 买卖方向 0-买 1-卖
  1453. STATUS string `json:"-" form:"status"` // 状态筛选
  1454. UNPAIDAMOUNT SFLOAT64 `json:"unpaidamount" xorm:"'UNPAIDAMOUNT'"` // 剩余款(待支付金额)
  1455. BEGINDATE string `json:"begindate" form:"begindate"` // 开始交易日(yyyymmdd)
  1456. ENDDATE string `json:"enddate" form:"enddate"` // 结束交易日(yyyymmdd)
  1457. }
  1458. func (r *WrPerformancePlan) calc() {
  1459. r.Wr2FactorType.Calc()
  1460. r.UNPAIDAMOUNT = SFLOAT64(r.AMOUNT - r.BUYPAIDAMOUNT)
  1461. r.SELLUSERNAME = EncryptByStar(r.SELLUSERNAME)
  1462. r.BUYUSERNAME = EncryptByStar(r.BUYUSERNAME)
  1463. }
  1464. func (r *WrPerformancePlan) buildSql() string {
  1465. var sqlId utils.SQLVal = `
  1466. with tmp as
  1467. (select to_char(t.wrfactortypeid) wrfactortypeid,
  1468. t.wrfactortypename,
  1469. t.wrstandardid,
  1470. t.deliverygoodsid,
  1471. g.deliverygoodscode,
  1472. g.deliverygoodsname,
  1473. w.wrstandardcode,
  1474. w.wrstandardname,
  1475. h.warehousecode,
  1476. h.warehousename,
  1477. e.enumdicname,
  1478. w.wrstandardname || t.wrfactortypename2 as wrtypename
  1479. from wrfactortype t
  1480. left join deliverygoods g
  1481. on t.deliverygoodsid = g.deliverygoodsid
  1482. left join wrstandard w
  1483. on t.wrstandardid = w.wrstandardid
  1484. left join warehouseinfo h
  1485. on t.warehouseid = h.autoid
  1486. left join enumdicitem e
  1487. on w.unitid = e.enumitemname
  1488. and e.enumdiccode = 'goodsunit')
  1489. select to_char(t.PERFORMANCEPLANID) PERFORMANCEPLANID,
  1490. t.PERFORMANCETYPE,
  1491. to_char(t.RELATEDORDERID) RELATEDORDERID,
  1492. t.AMOUNT,
  1493. t.PAYMENTTYPE,
  1494. t.PERFORMANCESTATUS,
  1495. to_char(t.CURSTEPID) CURSTEPID,
  1496. t.BUYACCOUNTID,
  1497. t.WRTRANSFERUSERID,
  1498. t.BUYPAIDAMOUNT,
  1499. t.SELLACCOUNTID,
  1500. t.SELLRECEIVEDAMOUNT,
  1501. t.BUYTODAYAMOUNT,
  1502. t.SELLTODAYAMOUNT,
  1503. to_char(t.CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME,
  1504. t.CREATORID,
  1505. t.REMARK,
  1506. t.BUYERFREEZEAMOUNT,
  1507. t.BUYERFREEZEAMOUNTREMAIN,
  1508. t.SELLERFREEZEAMOUNT,
  1509. t.SELLERFREEZEAMOUNTREMAIN,
  1510. t.OVERSHORTAMOUNT,
  1511. t.HASOVERSHORT,
  1512. t.SHIPREMARK,
  1513. t.MIDDLEUSERID,
  1514. t.MIDDLEACCOUNTID,
  1515. t.HASWR,
  1516. t.BUYERINFO,
  1517. t.SELLERINFO,
  1518. t.OVERSHORTQTY,
  1519. t.MARKETID,
  1520. t.EXPRESSFEECONFIRMED,
  1521. t.EXPRESSFEE,
  1522. t.CONTRACTID,
  1523. to_char(t.CURSTEPDEADLINE, 'yyyy-mm-dd hh24:mi:ss') CURSTEPDEADLINE,
  1524. t.QTY,
  1525. t.activatemonth,
  1526. u1.accountname buyusername,
  1527. u2.accountname sellusername,
  1528. s.steptypename CURSTEPNAME,
  1529. s.steptypeid,
  1530. to_char(k.starttime, 'yyyy-mm-dd hh24:mi:ss') starttime,
  1531. tmp.*,
  1532. case when m.trademode=17 and t.haswr=1 then '仓单贸易'
  1533. when m.trademode=17 and t.haswr=0 then '仓单预售' else
  1534. m.marketname end as typename
  1535. from performanceplan t
  1536. left join taaccount a1
  1537. on t.buyaccountid = a1.accountid
  1538. left join useraccount u1
  1539. on a1.userid = u1.userid
  1540. left join taaccount a2
  1541. on t.sellaccountid = a2.accountid
  1542. left join useraccount u2
  1543. on a2.userid = u2.userid
  1544. left join performancestep k
  1545. on t.curstepid = k.performancestepid
  1546. left join performancesteptype s
  1547. on k.steptypeid = s.steptypeid
  1548. left join performanceplanwr f
  1549. on t.performanceplanid = f.performanceplanid
  1550. left join tmp
  1551. on f.wrfactortypeid = tmp.wrfactortypeid
  1552. left join market m on t.marketid=m.marketid
  1553. where 1 = 1
  1554. `
  1555. if r.BUYORSELL == 0 {
  1556. sqlId.And("u1.userid", r.USERID)
  1557. } else {
  1558. sqlId.And("u2.userid", r.USERID)
  1559. }
  1560. sqlId.JoinEx(r.STATUS != "", fmt.Sprintf(" and t.PERFORMANCESTATUS in(%v)", r.STATUS))
  1561. sqlId.Join(" order by t.CREATETIME desc")
  1562. return sqlId.String()
  1563. }
  1564. func (r *WrPerformancePlan) buildSqlHis() string {
  1565. var sqlId utils.SQLVal = `
  1566. with tmp as
  1567. (select to_char(t.wrfactortypeid) wrfactortypeid,
  1568. t.wrfactortypename,
  1569. t.wrstandardid,
  1570. t.deliverygoodsid,
  1571. g.deliverygoodscode,
  1572. g.deliverygoodsname,
  1573. w.wrstandardcode,
  1574. w.wrstandardname,
  1575. h.warehousecode,
  1576. h.warehousename,
  1577. e.enumdicname,
  1578. w.wrstandardname || t.wrfactortypename2 as wrtypename
  1579. from wrfactortype t
  1580. left join deliverygoods g
  1581. on t.deliverygoodsid = g.deliverygoodsid
  1582. left join wrstandard w
  1583. on t.wrstandardid = w.wrstandardid
  1584. left join warehouseinfo h
  1585. on t.warehouseid = h.autoid
  1586. left join enumdicitem e
  1587. on w.unitid = e.enumitemname
  1588. and e.enumdiccode = 'goodsunit')
  1589. select to_char(t.PERFORMANCEPLANID) PERFORMANCEPLANID,
  1590. t.PERFORMANCETYPE,
  1591. to_char(t.RELATEDORDERID) RELATEDORDERID,
  1592. t.AMOUNT,
  1593. t.PAYMENTTYPE,
  1594. t.PERFORMANCESTATUS,
  1595. to_char(t.CURSTEPID) CURSTEPID,
  1596. t.BUYACCOUNTID,
  1597. t.WRTRANSFERUSERID,
  1598. t.BUYPAIDAMOUNT,
  1599. t.SELLACCOUNTID,
  1600. t.SELLRECEIVEDAMOUNT,
  1601. t.BUYTODAYAMOUNT,
  1602. t.SELLTODAYAMOUNT,
  1603. to_char(t.CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME,
  1604. t.CREATORID,
  1605. t.REMARK,
  1606. t.BUYERFREEZEAMOUNT,
  1607. t.BUYERFREEZEAMOUNTREMAIN,
  1608. t.SELLERFREEZEAMOUNT,
  1609. t.SELLERFREEZEAMOUNTREMAIN,
  1610. t.OVERSHORTAMOUNT,
  1611. t.HASOVERSHORT,
  1612. t.SHIPREMARK,
  1613. t.MIDDLEUSERID,
  1614. t.MIDDLEACCOUNTID,
  1615. t.HASWR,
  1616. t.BUYERINFO,
  1617. t.SELLERINFO,
  1618. t.OVERSHORTQTY,
  1619. t.MARKETID,
  1620. t.EXPRESSFEECONFIRMED,
  1621. t.EXPRESSFEE,
  1622. t.CONTRACTID,
  1623. to_char(t.CURSTEPDEADLINE, 'yyyy-mm-dd hh24:mi:ss') CURSTEPDEADLINE,
  1624. t.QTY,
  1625. t.activatemonth,
  1626. u1.accountname buyusername,
  1627. u2.accountname sellusername,
  1628. s.steptypename CURSTEPNAME,
  1629. s.steptypeid,
  1630. to_char(k.starttime, 'yyyy-mm-dd hh24:mi:ss') starttime,
  1631. tmp.*,
  1632. case when m.trademode=17 and t.haswr=1 then '仓单贸易'
  1633. when m.trademode=17 and t.haswr=0 then '仓单预售' else
  1634. m.marketname end as typename
  1635. from his_performanceplan t
  1636. left join taaccount a1
  1637. on t.buyaccountid = a1.accountid
  1638. left join useraccount u1
  1639. on a1.userid = u1.userid
  1640. left join taaccount a2
  1641. on t.sellaccountid = a2.accountid
  1642. left join useraccount u2
  1643. on a2.userid = u2.userid
  1644. left join (select * from his_performancestep where isvaliddata=1) k
  1645. on t.curstepid = k.performancestepid
  1646. left join performancesteptype s
  1647. on k.steptypeid = s.steptypeid
  1648. left join performanceplanwr f
  1649. on t.performanceplanid = f.performanceplanid
  1650. left join tmp
  1651. on f.wrfactortypeid = tmp.wrfactortypeid
  1652. left join market m on t.marketid=m.marketid
  1653. where 1 = 1 and t.isvaliddata=1
  1654. `
  1655. if r.BUYORSELL == 0 {
  1656. sqlId.And("u1.userid", r.USERID)
  1657. } else {
  1658. sqlId.And("u2.userid", r.USERID)
  1659. }
  1660. sqlId.JoinEx(r.STATUS != "", fmt.Sprintf(" and t.PERFORMANCESTATUS in(%v)", r.STATUS))
  1661. // 格式 yyyymmdd
  1662. if len(r.BEGINDATE) > 0 {
  1663. sqlId.JoinFormat(" and t.HISTRADEDATE >= '%v'", r.BEGINDATE)
  1664. }
  1665. if len(r.ENDDATE) > 0 {
  1666. sqlId.JoinFormat(" and t.HISTRADEDATE <= '%v'", r.ENDDATE)
  1667. }
  1668. sqlId.Join(" order by t.CREATETIME desc")
  1669. return sqlId.String()
  1670. }
  1671. // GetDataEx 获取履约信息(履约计划)
  1672. func (r *WrPerformancePlan) GetDataEx() (interface{}, error) {
  1673. var sqlId string
  1674. // 如果指定了开始日期或结束日期, 刚查历史
  1675. if r.BEGINDATE != "" || r.ENDDATE != "" {
  1676. sqlId = r.buildSqlHis()
  1677. } else {
  1678. sqlId = r.buildSql()
  1679. }
  1680. sData := make([]WrPerformancePlan, 0)
  1681. err := db.GetEngine().SQL(sqlId).Find(&sData)
  1682. for i := range sData {
  1683. sData[i].calc()
  1684. sData[i].BEGINDATE = r.BEGINDATE
  1685. sData[i].ENDDATE = r.ENDDATE
  1686. }
  1687. return sData, err
  1688. }
  1689. // WrHoldLB 仓单持有记录
  1690. type WrHoldLB struct {
  1691. LADINGBILLID string `json:"ladingbillid" xorm:"LADINGBILLID" form:"ladingbillid"` // 提单ID(208+Unix秒时间戳(10位)+xxxxxx)
  1692. SUBNUM int32 `json:"subnum" xorm:"SUBNUM" form:"subnum"` // 提单子单号
  1693. WRFACTORTYPEID string `json:"wrfactortypeid" xorm:"WRFACTORTYPEID" form:"wrfactortypeid"` // 仓单要素类型ID
  1694. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID" form:"deliverygoodsid"` // 品种ID
  1695. QTY float64 `json:"qty" xorm:"QTY" form:"qty"` // 数量
  1696. FREEZERQTY float64 `json:"freezerqty" xorm:"FREEZERQTY" form:"freezerqty"` // 冻结数量
  1697. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 持有人ID
  1698. ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID" form:"accountid"` // 持有人帐户ID
  1699. CREATETIME string `json:"createtime" xorm:"CREATETIME" form:"createtime"` // 创建时间(过户时间)
  1700. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE" form:"tradedate"` // 交易日(yyyyMMdd)
  1701. WRID string `json:"wrid" xorm:"WRID" form:"wrid"` // 仓单变更ID
  1702. PARENTSUBNUM int32 `json:"parentsubnum" xorm:"PARENTSUBNUM" form:"parentsubnum"` // 拆分父子单号
  1703. PLEDGEQTY float64 `json:"pledgeqty" xorm:"'-'"` // 质押数量
  1704. BANNERPICURL string `json:"bannerpicurl" xorm:"BANNERPICURL"` // Banner图
  1705. THUMURLS string `json:"thumurls" xorm:"thumurls"` // 缩略图
  1706. Wr2FactorType `xorm:"extends"`
  1707. WRHOLDENO string `json:"wrholdeno"` // 仓单编号
  1708. ENABLEQTY float64 `json:"enableqty"` // 可用数量
  1709. DGITEMNAME string `json:"-" form:"dgitemname"`
  1710. }
  1711. func (r *WrHoldLB) calc() {
  1712. r.WRHOLDENO = fmt.Sprintf("%v_%v", r.LADINGBILLID, r.SUBNUM)
  1713. r.ENABLEQTY = r.QTY - r.FREEZERQTY
  1714. r.Wr2FactorType.Calc()
  1715. }
  1716. func (r *WrHoldLB) buildSql() string {
  1717. var sqlId utils.SQLVal = "with tmp as" +
  1718. " (select t.wrfactortypeid," +
  1719. " t.wrfactortypename," +
  1720. " t.wrstandardid," +
  1721. " t.deliverygoodsid," +
  1722. " t.warehouseid," +
  1723. " g.deliverygoodscode," +
  1724. " g.deliverygoodsname," +
  1725. " w.wrstandardcode," +
  1726. " w.wrstandardname," +
  1727. " w.bannerpicurl," +
  1728. " w.thumurls," +
  1729. " w.minivalue," +
  1730. " h.warehousecode," +
  1731. " h.warehousename," +
  1732. " e.enumdicname," +
  1733. " w.wrstandardname || t.wrfactortypename2 as wrtypename" +
  1734. " from wrfactortype t" +
  1735. " left join deliverygoods g" +
  1736. " on t.deliverygoodsid = g.deliverygoodsid" +
  1737. " left join wrstandard w" +
  1738. " on t.wrstandardid = w.wrstandardid" +
  1739. " left join warehouseinfo h" +
  1740. " on t.warehouseid = h.autoid" +
  1741. " left join enumdicitem e" +
  1742. " on w.unitid = e.enumitemname" +
  1743. " and e.enumdiccode = 'goodsunit'" +
  1744. ")" +
  1745. "SELECT to_char(t.LADINGBILLID) LADINGBILLID," +
  1746. " t.SUBNUM," +
  1747. " to_char(t.WRFACTORTYPEID) WRFACTORTYPEID," +
  1748. " t.DELIVERYGOODSID," +
  1749. " t.QTY," +
  1750. " t.FREEZERQTY," +
  1751. " t.USERID," +
  1752. " t.ACCOUNTID," +
  1753. " to_char(t.CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
  1754. " t.TRADEDATE," +
  1755. " t.WRID," +
  1756. " t.PARENTSUBNUM," +
  1757. " tmp.*" +
  1758. " FROM WRHOLDLB t" +
  1759. " LEFT JOIN tmp on t.wrfactortypeid= tmp.wrfactortypeid" +
  1760. " WHERE 1 = 1"
  1761. sqlId.And("t.ACCOUNTID", r.ACCOUNTID)
  1762. sqlId.AndEx("tmp.DELIVERYGOODSID", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0)
  1763. sqlId.AndEx("tmp.WRSTANDARDID", r.WRSTANDARDID, r.WRSTANDARDID > 0)
  1764. sqlId.AndEx("tmp.WAREHOUSEID", r.WAREHOUSEID, r.WAREHOUSEID > 0)
  1765. sqlId.AndInterEx("t.wrfactortypeid", r.WRFACTORTYPEID, r.WRFACTORTYPEID != "")
  1766. if d, ok := FtItemName(r.DGITEMNAME); ok {
  1767. sqlId.AndLikes("tmp.wrfactortypename", d...)
  1768. }
  1769. return sqlId.String()
  1770. }
  1771. // GetDataEx 获取仓单持有记录
  1772. func (r *WrHoldLB) GetDataEx() (interface{}, error) {
  1773. sData := make([]WrHoldLB, 0)
  1774. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1775. for i := range sData {
  1776. sData[i].calc()
  1777. }
  1778. return sData, err
  1779. }
  1780. // WrFilterItem 筛选框列表项
  1781. type WrFilterItem struct {
  1782. ITEMTYPE int32 `json:"itemtype" xorm:"'ITEMTYPE'"` // 类型 1-品种 2-品类(商品) 3-仓库
  1783. ITEMNAME string `json:"itemname" xorm:"'ITEMNAME'"` // 名称
  1784. ITEMCODE string `json:"itemcode" xorm:"'ITEMCODE'"` // 代码
  1785. ITEMID int64 `json:"itemid" xorm:"'ITEMID'"` // 项id
  1786. IType string `json:"-" form:"itype"` // 类型 逗号隔开, 如 1,2
  1787. }
  1788. func (r *WrFilterItem) calc() {
  1789. }
  1790. func (r *WrFilterItem) buildSql() string {
  1791. if r.IType == "" {
  1792. r.IType = "1, 2, 3"
  1793. }
  1794. r.IType = strings.ReplaceAll(r.IType, " ", "")
  1795. sType := strings.Split(r.IType, ",")
  1796. sqls := make([]string, 0)
  1797. for _, v := range sType {
  1798. switch v {
  1799. case "1":
  1800. sqls = append(sqls, "select 1 itemtype, t.deliverygoodsid itemid, t.deliverygoodscode itemcode, to_char(t.deliverygoodsname) itemname from deliverygoods t")
  1801. case "2":
  1802. sqls = append(sqls, "select 2 itemtype, t.wrstandardid itemid, to_char(t.wrstandardcode) itemcode, to_char(t.wrstandardname) itemname from wrstandard t")
  1803. case "3":
  1804. sqls = append(sqls, "select 3 itemtype, t.autoid itemid, t.warehousecode itemcode, to_char(t.warehousename) itemname from warehouseinfo t")
  1805. default:
  1806. }
  1807. }
  1808. var sqlId string
  1809. for _, v := range sqls {
  1810. if len(sqlId) > 0 {
  1811. sqlId += " union all " + v
  1812. } else {
  1813. sqlId = v
  1814. }
  1815. }
  1816. sqlId += " order by itemtype, itemid"
  1817. return sqlId
  1818. }
  1819. // GetDataEx 获取筛选框列表项
  1820. func (r *WrFilterItem) GetDataEx() (interface{}, error) {
  1821. sData := make([]WrFilterItem, 0)
  1822. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1823. for i := range sData {
  1824. sData[i].calc()
  1825. }
  1826. return sData, err
  1827. }
  1828. // WrPerformanPlanSum 履约中数量
  1829. type WrPerformanPlanSum struct {
  1830. USERID int64 `json:"userid" xorm:"'USERID'"` // 用户id
  1831. BUYORSELL int32 `json:"buyorsell" xorm:"'BUYORSELL'"` // 买卖方向
  1832. QTY float64 `json:"qty" xorm:"'QTY'"` // 履约中的数量
  1833. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 品种id
  1834. WRSTANDARDID int64 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 品类id
  1835. WAREHOUSEID int64 `json:"warehouseid" xorm:"'WAREHOUSEID'"` // 仓库id
  1836. WRTYPENAME string `json:"wrtypename" xorm:"'WRTYPENAME'"` // 商品
  1837. QueryType int32 `json:"querytype" form:"querytype"` // 查询类型 1-现货汇总 2-库存汇总
  1838. }
  1839. func (r *WrPerformanPlanSum) calc() {
  1840. if len(r.WRTYPENAME) > 0 {
  1841. r.WRTYPENAME = strings.ReplaceAll(r.WRTYPENAME, ",", "-")
  1842. }
  1843. }
  1844. // buildSql_XHHZ 现货汇总 履约中的数量
  1845. func (r *WrPerformanPlanSum) buildSql_XHHZ() string {
  1846. var sqlId utils.SQLVal = `
  1847. with tmp as
  1848. (select t.buyaccountid,
  1849. t.sellaccountid,
  1850. t.qty,
  1851. w.wrfactortypeid,
  1852. w.deliverygoodsid,
  1853. w.wrstandardid,
  1854. w.warehouseid,
  1855. wd.wrstandardname || w.wrfactortypename2 wrtypename,
  1856. u1.userid buyuserid,
  1857. u2.userid selluserid
  1858. from performanceplan t
  1859. left join performanceplanwr p
  1860. on t.performanceplanid = p.performanceplanid
  1861. left join warehousereciept f
  1862. on p.wrid = f.wrid
  1863. left join wrfactortype w
  1864. on f.wrfactortypeid = w.wrfactortypeid
  1865. left join wrstandard wd
  1866. on w.wrstandardid = wd.wrstandardid
  1867. left join taaccount ta1
  1868. on t.buyaccountid = ta1.accountid
  1869. left join useraccount u1
  1870. on ta1.userid = u1.userid
  1871. left join taaccount ta2
  1872. on t.sellaccountid = ta2.accountid
  1873. left join useraccount u2
  1874. on ta2.userid = u2.userid
  1875. where t.performancestatus in (2)
  1876. and %v in (u1.userid, u2.userid))
  1877. select k.buyuserid userid,
  1878. 0 as buyorsell,
  1879. k.deliverygoodsid,
  1880. k.wrstandardid,
  1881. k.wrtypename,
  1882. sum(k.qty) qty
  1883. from tmp k
  1884. group by k.buyuserid, k.deliverygoodsid, k.wrstandardid, k.wrtypename
  1885. union all
  1886. select k.selluserid userid,
  1887. 1 as buyorsell,
  1888. k.deliverygoodsid,
  1889. k.wrstandardid,
  1890. k.wrtypename,
  1891. sum(k.qty) qty
  1892. from tmp k
  1893. group by k.selluserid, k.deliverygoodsid, k.wrstandardid, k.wrtypename
  1894. `
  1895. sqlId.FormatParam(r.USERID)
  1896. return sqlId.String()
  1897. }
  1898. // buildSql_KCHZ 库存汇总 履约中的数量
  1899. func (r *WrPerformanPlanSum) buildSql_KCHZ() string {
  1900. // 跟buildSql_XHHZ()相比, group by 多了warehouseid字段
  1901. var sqlId utils.SQLVal = `
  1902. with tmp as
  1903. (select t.buyaccountid,
  1904. t.sellaccountid,
  1905. t.qty,
  1906. w.wrfactortypeid,
  1907. w.deliverygoodsid,
  1908. w.wrstandardid,
  1909. w.warehouseid,
  1910. wd.wrstandardname || w.wrfactortypename2 wrtypename,
  1911. u1.userid buyuserid,
  1912. u2.userid selluserid
  1913. from performanceplan t
  1914. left join performanceplanwr p
  1915. on t.performanceplanid = p.performanceplanid
  1916. left join warehousereciept f
  1917. on p.wrid = f.wrid
  1918. left join wrfactortype w
  1919. on f.wrfactortypeid = w.wrfactortypeid
  1920. left join wrstandard wd
  1921. on w.wrstandardid = wd.wrstandardid
  1922. left join taaccount ta1
  1923. on t.buyaccountid = ta1.accountid
  1924. left join useraccount u1
  1925. on ta1.userid = u1.userid
  1926. left join taaccount ta2
  1927. on t.sellaccountid = ta2.accountid
  1928. left join useraccount u2
  1929. on ta2.userid = u2.userid
  1930. where t.performancestatus in (2)
  1931. and %v in (u1.userid, u2.userid))
  1932. select k.buyuserid userid,
  1933. 0 as buyorsell,
  1934. k.deliverygoodsid,
  1935. k.wrstandardid,
  1936. k.warehouseid,
  1937. k.wrtypename,
  1938. sum(k.qty) qty
  1939. from tmp k
  1940. group by k.buyuserid,
  1941. k.deliverygoodsid,
  1942. k.wrstandardid,
  1943. k.warehouseid,
  1944. k.wrtypename
  1945. union all
  1946. select k.selluserid userid,
  1947. 1 as buyorsell,
  1948. k.deliverygoodsid,
  1949. k.wrstandardid,
  1950. k.warehouseid,
  1951. k.wrtypename,
  1952. sum(k.qty) qty
  1953. from tmp k
  1954. group by k.selluserid,
  1955. k.deliverygoodsid,
  1956. k.wrstandardid,
  1957. k.warehouseid,
  1958. k.wrtypename
  1959. `
  1960. sqlId.FormatParam(r.USERID)
  1961. return sqlId.String()
  1962. }
  1963. func (r *WrPerformanPlanSum) buildSql() string {
  1964. if r.QueryType == 1 {
  1965. return r.buildSql_XHHZ()
  1966. } else {
  1967. return r.buildSql_KCHZ()
  1968. }
  1969. }
  1970. // GetData 获取履约中数量
  1971. func (r *WrPerformanPlanSum) GetData() ([]WrPerformanPlanSum, error) {
  1972. sData := make([]WrPerformanPlanSum, 0)
  1973. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  1974. for i := range sData {
  1975. sData[i].calc()
  1976. }
  1977. return sData, err
  1978. }
  1979. // WrFAProductDetail 融资产品列表
  1980. type WrFAProductDetail struct {
  1981. PRODUCTDETAILID int64 `json:"productdetailid" xorm:"PRODUCTDETAILID" form:"productdetailid"` // 产品组合ID(SEQ_FINANCEAREAPRODUCTDETAIL)
  1982. PRODUCTID int64 `json:"productid" xorm:"PRODUCTID"` // 金融产品ID
  1983. AREAUSERID int64 `json:"areauserid" xorm:"AREAUSERID"` // 金融机构ID
  1984. FINANCINGDAYS int32 `json:"financingdays" xorm:"FINANCINGDAYS"` // 天数(天)
  1985. MARGINRATIO float64 `json:"marginratio" xorm:"MARGINRATIO"` // 保证金比率质押率 - [仓单质押]
  1986. INTERESTRATEMODE int32 `json:"interestratemode" xorm:"INTERESTRATEMODE"` // 利率方式 - 1:年利率 2:日利率 3:日固定值
  1987. INTERESTRATE float64 `json:"interestrate" xorm:"INTERESTRATE"` // 利率
  1988. INTERESTMINLEN int32 `json:"interestminlen" xorm:"INTERESTMINLEN"` // 最小起息天数
  1989. INTERESTSETTLEMODE int32 `json:"interestsettlemode" xorm:"INTERESTSETTLEMODE"` // 结息方式 - 1:按日结息 3:按月结息
  1990. INTERESTSETTLEVALUE int32 `json:"interestsettlevalue" xorm:"INTERESTSETTLEVALUE"` // 结息方式值
  1991. UPDATETIME string `json:"updatetime" xorm:"UPDATETIME"` // 更新时间
  1992. ISAUTOLOAN int32 `json:"isautoloan" xorm:"'ISAUTOLOAN'"` // 是否自动放款 0-手动 1-自动 (当为自动放款时,显示"放款快")
  1993. PRODUCTNAME string `json:"productname" xorm:"'PRODUCTNAME'"` // 产品名称
  1994. USERNAME string `json:"username" xorm:"'USERNAME'"` // 融出方
  1995. ACCOUNTID int64 `json:"accountid" xorm:"'ACCOUNTID'"` // 资金账号
  1996. LOANTAG string `json:"loantag"` // 放款标识: "放款快" 或者为空
  1997. WRSTANDARDID int64 `json:"-"` // 品类(商品)id
  1998. BRANDID int64 `json:"-"` // 品牌id
  1999. WAREHOUSEID int64 `json:"-"` // 仓库id
  2000. WRFACTORTYPEID string `json:"-" form:"wrfactortypeid"` // 仓单要素ID
  2001. }
  2002. func (r *WrFAProductDetail) calc() {
  2003. r.LOANTAG = IFValue(r.ISAUTOLOAN == 1, "放款快", "").(string)
  2004. r.USERNAME = EncryptByStar(r.USERNAME)
  2005. }
  2006. func (r *WrFAProductDetail) buildSqlByWrFactorTypeId() string {
  2007. var sqlId utils.SQLVal = "with tmp as" +
  2008. " (select distinct f.productid, f.isautoloan" +
  2009. " from FinanceAreaProductLimit f" +
  2010. " where 1 = 1" +
  2011. " and f.wrstandardid = %v" +
  2012. " and (f.spotgoodsbrandid like '%%,%v,%%' or f.spotgoodsbrandid like '%%,0,%%')" +
  2013. " and (f.warehouseinfoid like '%%,%v,%%' or f.warehouseinfoid like '%%,0,%%'))" +
  2014. "select t.PRODUCTDETAILID," +
  2015. " t.PRODUCTID," +
  2016. " t.AREAUSERID," +
  2017. " t.FINANCINGDAYS," +
  2018. " t.MARGINRATIO," +
  2019. " t.INTERESTRATEMODE," +
  2020. " t.INTERESTRATE," +
  2021. " t.INTERESTMINLEN," +
  2022. " t.INTERESTSETTLEMODE," +
  2023. " t.INTERESTSETTLEVALUE," +
  2024. " to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," +
  2025. " p.productname," +
  2026. " p.accountid," +
  2027. " u.accountname username," +
  2028. " k.isautoloan" +
  2029. " from FinanceAreaProductDetail t" +
  2030. " left join FinanceAreaProduct p" +
  2031. " on t.productid = p.productid" +
  2032. " left join useraccount u" +
  2033. " on t.areauserid = u.userid" +
  2034. " inner join tmp k" +
  2035. " on t.productid = k.productid"
  2036. sqlId.FormatParam(r.WRSTANDARDID, r.BRANDID, r.WAREHOUSEID)
  2037. return sqlId.String()
  2038. }
  2039. func (r *WrFAProductDetail) buildSqlByProductDetailId() string {
  2040. var sqlId utils.SQLVal = "select t.PRODUCTDETAILID," +
  2041. " t.PRODUCTID," +
  2042. " t.AREAUSERID," +
  2043. " t.FINANCINGDAYS," +
  2044. " t.MARGINRATIO," +
  2045. " t.INTERESTRATEMODE," +
  2046. " t.INTERESTRATE," +
  2047. " t.INTERESTMINLEN," +
  2048. " t.INTERESTSETTLEMODE," +
  2049. " t.INTERESTSETTLEVALUE," +
  2050. " to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," +
  2051. " p.productname," +
  2052. " p.accountid," +
  2053. " u.accountname username" +
  2054. " from FinanceAreaProductDetail t" +
  2055. " left join FinanceAreaProduct p" +
  2056. " on t.productid = p.productid" +
  2057. " left join useraccount u" +
  2058. " on t.areauserid = u.userid" +
  2059. " where 1=1"
  2060. sqlId.And("t.PRODUCTDETAILID", r.PRODUCTDETAILID)
  2061. return sqlId.String()
  2062. }
  2063. func (r *WrFAProductDetail) buildSql() string {
  2064. if r.PRODUCTDETAILID > 0 {
  2065. return r.buildSqlByProductDetailId()
  2066. } else {
  2067. return r.buildSqlByWrFactorTypeId()
  2068. }
  2069. }
  2070. // GetDataEx 获取融资产品列表
  2071. func (r *WrFAProductDetail) GetDataEx() (interface{}, error) {
  2072. sData := make([]WrFAProductDetail, 0)
  2073. m := WrFactorTypeInfo{WRFACTORTYPEID: r.WRFACTORTYPEID}
  2074. if d, err := m.GetData(); err == nil {
  2075. var brandid int64 = 0
  2076. for _, v := range d {
  2077. if v.DGFACTORYITEMTYPEID == 2 {
  2078. brandid = v.DGFACTORYITEMID
  2079. }
  2080. }
  2081. if brandid > 0 && len(d) > 0 {
  2082. r.BRANDID = brandid
  2083. r.WRSTANDARDID = d[0].WRSTANDARDID
  2084. r.WAREHOUSEID = d[0].WAREHOUSEID
  2085. _ = db.GetEngine().SQL(r.buildSql()).Find(&sData)
  2086. for i := range sData {
  2087. sData[i].calc()
  2088. sData[i].WRSTANDARDID = r.WRSTANDARDID
  2089. sData[i].BRANDID = r.BRANDID
  2090. sData[i].WAREHOUSEID = r.WAREHOUSEID
  2091. sData[i].WRFACTORTYPEID = r.WRFACTORTYPEID
  2092. }
  2093. }
  2094. }
  2095. return sData, nil
  2096. }
  2097. // WrMarketTradeConfig 市场交易参数配置
  2098. type WrMarketTradeConfig struct {
  2099. MARKETID int32 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID-仓单贸易、竞拍、预售
  2100. BUYMARGINALGORITHM int32 `json:"buymarginalgorithm" xorm:"BUYMARGINALGORITHM" form:"buymarginalgorithm"` // 买方保证金方式 - 1:比率 2:固定
  2101. BUYMARGINVALUE float64 `json:"buymarginvalue" xorm:"BUYMARGINVALUE" form:"buymarginvalue"` // 买方保证金设置值
  2102. SELLMARGINALGORITHM int32 `json:"sellmarginalgorithm" xorm:"SELLMARGINALGORITHM" form:"sellmarginalgorithm"` // 卖方保证金方式 - 1:比率 2:固定
  2103. SELLMARGINVALUE float64 `json:"sellmarginvalue" xorm:"SELLMARGINVALUE" form:"sellmarginvalue"` // 卖方保证金设置值
  2104. SELLMARGINVALUE2 float64 `json:"sellmarginvalue2" xorm:"SELLMARGINVALUE2" form:"sellmarginvalue2"` // 卖方保证金设置值(无仓单)
  2105. BUYCHARGEALGORITHM int32 `json:"buychargealgorithm" xorm:"BUYCHARGEALGORITHM" form:"buychargealgorithm"` // 买方手续费收取方式 1:比率 2:固定
  2106. BUYCHARGEALGORITHMVALUE float64 `json:"buychargealgorithmvalue" xorm:"BUYCHARGEALGORITHMVALUE" form:"buychargealgorithmvalue"` // 买方手续费设置值(交易所部分)
  2107. BUYCHARGEALGORITHMVALUE2 float64 `json:"buychargealgorithmvalue2" xorm:"BUYCHARGEALGORITHMVALUE2" form:"buychargealgorithmvalue2"` // 买方手续费设置值(会员部分)
  2108. SELLCHARGEALGORITHM int32 `json:"sellchargealgorithm" xorm:"SELLCHARGEALGORITHM" form:"sellchargealgorithm"` // 卖方手续费收取方式 1:比率 2:固定
  2109. SELLCHARGEALGORITHMVALUE float64 `json:"sellchargealgorithmvalue" xorm:"SELLCHARGEALGORITHMVALUE" form:"sellchargealgorithmvalue"` // 卖方手续费设置值(交易所部分)
  2110. SELLCHARGEALGORITHMVALUE2 float64 `json:"sellchargealgorithmvalue2" xorm:"SELLCHARGEALGORITHMVALUE2" form:"sellchargealgorithmvalue2"` // 卖方手续费设置值(会员部分)
  2111. FAILEDCHARGEALGORITHM int32 `json:"failedchargealgorithm" xorm:"FAILEDCHARGEALGORITHM" form:"failedchargealgorithm"` // 流拍手续费收取方式 1:比率 2:固定
  2112. FAILEDCHARGEVALUE float64 `json:"failedchargevalue" xorm:"FAILEDCHARGEVALUE" form:"failedchargevalue"` // 流拍手续费设置值
  2113. FAILEDCHARGEVALUE2 float64 `json:"failedchargevalue2" xorm:"FAILEDCHARGEVALUE2" form:"failedchargevalue2"` // 流拍卖方手续费设置值
  2114. BUYFIRSTMARGINALGORITHM int32 `json:"buyfirstmarginalgorithm" xorm:"BUYFIRSTMARGINALGORITHM" form:"buyfirstmarginalgorithm"` // 买方出价保证金方式 - 1:比率 2:固定 - [竞拍]
  2115. BUYFIRSTMARGINVALUE float64 `json:"buyfirstmarginvalue" xorm:"BUYFIRSTMARGINVALUE" form:"buyfirstmarginvalue"` // 买方出价保证金设置值 - [竞拍]
  2116. PERFORMANCEWAY int32 `json:"performanceway" xorm:"PERFORMANCEWAY" form:"performanceway"` // 交货模式 - 1:履约计划 2:分步履约 3:分步提货[文昌]
  2117. PERFORMANCETEMPID int64 `json:"performancetempid" xorm:"PERFORMANCETEMPID" form:"performancetempid"` // 履约计划模板ID(有仓单) - 根据交货模式:1:履约 - 履约计划模板2:分步履约 - 履约计划模板3:分步提货 - 履约方式: 立即执行(-1)
  2118. PERFORMANCETEMPID2 int64 `json:"performancetempid2" xorm:"PERFORMANCETEMPID2" form:"performancetempid2"` // 履约计划模板ID(无仓单) - 根据交货模式:1:履约 - 履约计划模板2:分步履约 - 履约计划模板3:分步提货 - 履约方式: 立即执行
  2119. BUYRELEASERATIO float64 `json:"buyreleaseratio" xorm:"BUYRELEASERATIO" form:"buyreleaseratio"` // 买方释放比率[2:分步履约]
  2120. SELLRELEASERATIO float64 `json:"sellreleaseratio" xorm:"SELLRELEASERATIO" form:"sellreleaseratio"` // 卖方释放比率[2:分步履约]
  2121. EXECUTEMODE int32 `json:"executemode" xorm:"EXECUTEMODE" form:"executemode"` // 执行方式[2:分步履约] - 1:顺序执行 2:交叉执行
  2122. EXECUTESIDE int32 `json:"executeside" xorm:"EXECUTESIDE" form:"executeside"` // 执行方[2:分步履约] - 1:买方 2:卖方
  2123. MINQTY float64 `json:"minqty" xorm:"MINQTY" form:"minqty"` // 最小执行量[2:分步履约]
  2124. HOLDDAYS int32 `json:"holddays" xorm:"HOLDDAYS" form:"holddays"` // 合同期限[2:分步履约]
  2125. MODIFIERID int64 `json:"modifierid" xorm:"MODIFIERID" form:"modifierid"` // 修改人
  2126. UPDATETIME string `json:"updatetime" xorm:"UPDATETIME" form:"updatetime"` // 更新时间
  2127. BUYCHARGEALGORITHM2 int32 `json:"buychargealgorithm2" xorm:"BUYCHARGEALGORITHM2" form:"buychargealgorithm2"` // 回购买方手续费收取方式 1:比率 2:固定 --77:现货商城
  2128. BUYCHARGEALGORITHMVALUE3 float64 `json:"buychargealgorithmvalue3" xorm:"BUYCHARGEALGORITHMVALUE3" form:"buychargealgorithmvalue3"` // 回购买方手续费设置值(交易所部分) --77:现货商城
  2129. BUYCHARGEALGORITHMVALUE4 float64 `json:"buychargealgorithmvalue4" xorm:"BUYCHARGEALGORITHMVALUE4" form:"buychargealgorithmvalue4"` // 回购买方手续费设置值(会员部分) --77:现货商城
  2130. SELLCHARGEALGORITHM2 int32 `json:"sellchargealgorithm2" xorm:"SELLCHARGEALGORITHM2" form:"sellchargealgorithm2"` // 回购卖方手续费收取方式 1:比率 2:固定 --77:现货商城
  2131. SELLCHARGEALGORITHMVALUE3 float64 `json:"sellchargealgorithmvalue3" xorm:"SELLCHARGEALGORITHMVALUE3" form:"sellchargealgorithmvalue3"` // 回购卖方手续费设置值(交易所部分) --77:现货商城
  2132. SELLCHARGEALGORITHMVALUE4 float64 `json:"sellchargealgorithmvalue4" xorm:"SELLCHARGEALGORITHMVALUE4" form:"sellchargealgorithmvalue4"` // 回购卖方手续费设置值(会员部分) --77:现货商城
  2133. BASISUPRATIO float64 `json:"basisupratio" xorm:"'BASISUPRATIO'"` // 浮动价基差上限比例(仓单贸易)
  2134. BASISDOWNRATIO float64 `json:"basisdownratio" xorm:"'BASISDOWNRATIO'"` // 浮动价基差下限比例(仓单贸易)
  2135. PERFORMANCETEMPIDS string `json:"performancetempids" xorm:"PERFORMANCETEMPIDS"` // 履约计划模板IDs(有仓单)- 根据交货模式, 多个逗号分隔:1:履约 - 履约计划模板2:分步履约 - 履约计划模板3:分步提货 - 履约方式: 立即执行(-1)
  2136. PERFORMANCETEMPID2S string `json:"performancetempid2s" xorm:"PERFORMANCETEMPID2S"` // 履约计划模板IDs(无仓单) - 根据交货模式, 多个逗号分隔:1:履约 - 履约计划模板2:分步履约 - 履约计划模板3:分步提货 - 履约方式: 立即执行
  2137. NOWRQUOTAFLAG int `json:"nowrquotaflag" xorm:"'NOWRQUOTAFLAG'"` // 是否校验无仓单额度(仓单贸易) - 0:否 1:是
  2138. LISTINGMODE int `json:"listingmode" xorm:"'LISTINGMODE'"` // 挂牌方式 - 1:一口价 2:浮动价 3:贸易圈 4:协议指定
  2139. }
  2140. func (r *WrMarketTradeConfig) calc() {
  2141. r.PERFORMANCETEMPIDS = strings.Trim(r.PERFORMANCETEMPIDS, ",")
  2142. r.PERFORMANCETEMPID2S = strings.Trim(r.PERFORMANCETEMPID2S, ",")
  2143. }
  2144. func (r *WrMarketTradeConfig) buildSql() string {
  2145. var sqlId utils.SQLVal = "select * from markettradeconfig t where 1=1"
  2146. sqlId.AndEx("t.MARKETID", r.MARKETID, r.MARKETID > 0)
  2147. return sqlId.String()
  2148. }
  2149. // GetDataEx 获取市场交易参数配置
  2150. func (r *WrMarketTradeConfig) GetDataEx() (interface{}, error) {
  2151. sData := make([]WrMarketTradeConfig, 0)
  2152. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  2153. for i := range sData {
  2154. sData[i].calc()
  2155. }
  2156. return sData, err
  2157. }
  2158. // WrFtWrstandard 品类筛选列表
  2159. type WrFtWrstandard struct {
  2160. WRSTANDARDID int64 `json:"wrstandardid"` // 现货商品ID
  2161. WRSTANDARDCODE string `json:"wrstandardcode"` // 现货商品代码
  2162. WRSTANDARDNAME string `json:"wrstandardname"` // 商品名称
  2163. MINIVALUE int32 `json:"minivalue"` // 最小变动值
  2164. EnumdicName string `json:"enumdicname"` // 单位名称
  2165. }
  2166. // WrFtDeliveryGoods 品种筛选列表
  2167. type WrFtDeliveryGoods struct {
  2168. DELIVERYGOODSID int32 `json:"deliverygoodsid"` // 品种ID
  2169. DELIVERYGOODSCODE string `json:"deliverygoodscode"` // 品种代码
  2170. DELIVERYGOODSNAME string `json:"deliverygoodsname"` // 品种名称
  2171. WDLST []WrFtWrstandard `json:"wdlst"` // 商品列表
  2172. }
  2173. // GetDataEx 获取品种商品筛选列表
  2174. func (r *WrFtDeliveryGoods) GetDataEx() (interface{}, error) {
  2175. sData := make([]WrFtDeliveryGoods, 0)
  2176. mg := ErmcpDeliveryGoods{}
  2177. sMgData, err := mg.GetData()
  2178. if err == nil {
  2179. mWd := Ermcp3Wrstandard{}
  2180. if d, er := mWd.GetDataEx(); er == nil {
  2181. if sMd, ok := d.([]Ermcp3Wrstandard); ok {
  2182. for _, v := range sMgData {
  2183. item := WrFtDeliveryGoods{
  2184. DELIVERYGOODSID: v.DELIVERYGOODSID,
  2185. DELIVERYGOODSCODE: v.DELIVERYGOODSCODE,
  2186. DELIVERYGOODSNAME: v.DELIVERYGOODSNAME,
  2187. WDLST: make([]WrFtWrstandard, 0),
  2188. }
  2189. for _, a := range sMd {
  2190. if a.DELIVERYGOODSID == item.DELIVERYGOODSID && a.CANTRADE == 1 {
  2191. val := WrFtWrstandard{
  2192. WRSTANDARDID: a.WRSTANDARDID,
  2193. WRSTANDARDNAME: a.WRSTANDARDNAME,
  2194. WRSTANDARDCODE: a.WRSTANDARDCODE,
  2195. MINIVALUE: a.MINIVALUE,
  2196. EnumdicName: a.EnumdicName,
  2197. }
  2198. item.WDLST = append(item.WDLST, val)
  2199. }
  2200. }
  2201. // 有品类的品种才要, 终端不显示无品类的品种
  2202. if len(item.WDLST) > 0 {
  2203. sData = append(sData, item)
  2204. }
  2205. }
  2206. }
  2207. }
  2208. }
  2209. return sData, err
  2210. }
  2211. // WrStandardFactoryItem 现货商品要素定义项
  2212. type WrStandardFactoryItem struct {
  2213. WRSTANDARDID int64 `json:"-" xorm:"'WRSTANDARDID'" form:"wrstandardid"` // 品类
  2214. DGFACTORYITEMTYPEID int64 `json:"-" xorm:"'DGFACTORYITEMTYPEID'"` // 要素项类型id(1-999:预留为特殊类型 1:仓库 2:品牌)
  2215. ITEMTYPENAME string `json:"-" xorm:"'ITEMTYPENAME'"` // 要素项类型名称
  2216. DGFACTORYITEMID int64 `json:"dgfactoryitemid" xorm:"'DGFACTORYITEMID'"` // 选择项id
  2217. DGFACTORYITEMVALUE string `json:"dgfactoryitemvalue" xorm:"'DGFACTORYITEMVALUE'"` // 要素项值
  2218. WAREHOUSEID int64 `json:"warehouseid" xorm:"'WAREHOUSEID'"` // 仓库id
  2219. WMCATFLAG int `json:"-"` // 合同相同项(如有多个仓库, 逗号隔开, 仓库1, 仓库2, 仓库3 ) 1-合并
  2220. }
  2221. func (r *WrStandardFactoryItem) calc() {
  2222. }
  2223. func (r *WrStandardFactoryItem) buildSql() string {
  2224. var sqlId utils.SQLVal = "select t.wrstandardid," +
  2225. " dp.dgfactoryitemtypeid," +
  2226. " dp.itemtypename," +
  2227. " di.dgfactoryitemid," +
  2228. " di.warehouseid," +
  2229. " di.dgfactoryitemvalue" +
  2230. " from wrstandardfactoryitem t" +
  2231. " inner join wrstandard w" +
  2232. " on t.wrstandardid = w.wrstandardid" +
  2233. " inner join dgfactoryitemtype dp" +
  2234. " on t.dgfactoryitemtypeid = dp.dgfactoryitemtypeid" +
  2235. " and dp.deliverygoodsid = w.deliverygoodsid" +
  2236. " inner join dgfactoryitem di" +
  2237. " on t.dgfactoryitemid = di.dgfactoryitemid" +
  2238. " and di.deliverygoodsid = w.deliverygoodsid" +
  2239. " where dp.isvalid = 1" +
  2240. " and di.isvalid = 1"
  2241. sqlId.And("t.WRSTANDARDID", r.WRSTANDARDID)
  2242. sqlId.Join(" order by t.dgfactoryitemtypeid, di.orderindex")
  2243. // 合并同类项名称
  2244. if r.WMCATFLAG == 1 {
  2245. sqlId = `
  2246. select t.wrstandardid,
  2247. dp.dgfactoryitemtypeid,
  2248. dp.itemtypename,
  2249. wm_concat(di.dgfactoryitemvalue) dgfactoryitemvalue
  2250. from wrstandardfactoryitem t
  2251. inner join wrstandard w
  2252. on t.wrstandardid = w.wrstandardid
  2253. inner join dgfactoryitemtype dp
  2254. on t.dgfactoryitemtypeid = dp.dgfactoryitemtypeid
  2255. and dp.deliverygoodsid = w.deliverygoodsid
  2256. inner join dgfactoryitem di
  2257. on t.dgfactoryitemid = di.dgfactoryitemid
  2258. and di.deliverygoodsid = w.deliverygoodsid
  2259. where dp.isvalid = 1
  2260. and di.isvalid = 1
  2261. and t.wrstandardid = %v
  2262. group by t.wrstandardid, dp.dgfactoryitemtypeid, dp.itemtypename
  2263. `
  2264. sqlId.FormatParam(r.WRSTANDARDID)
  2265. }
  2266. return sqlId.String()
  2267. }
  2268. // GetDataEx 获取现货商品要素定义项
  2269. func (r *WrStandardFactoryItem) GetDataEx() (interface{}, error) {
  2270. sData := make([]WrStandardFactoryItem, 0)
  2271. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  2272. for i := range sData {
  2273. sData[i].calc()
  2274. }
  2275. return sData, err
  2276. }
  2277. // WrStandardFactoryItemEx 现货商品要素定义项列表
  2278. type WrStandardFactoryItemEx struct {
  2279. WRSTANDARDID int64 `json:"wrstandardid" form:"wrstandardid"` // 品类
  2280. DGFACTORYITEMTYPEID int64 `json:"dgfactoryitemtypeid"` // 要素项类型id(1-999:预留为特殊类型 1:仓库 2:品牌)
  2281. ITEMTYPENAME string `json:"itemtypename"` // 要素项类型名称
  2282. ItemLst []WrStandardFactoryItem `json:"itemlst"` // 要素项列表
  2283. }
  2284. // GetDataEx 获取现货商品要素定义项列表
  2285. func (r *WrStandardFactoryItemEx) GetDataEx() (interface{}, error) {
  2286. sData := make([]WrStandardFactoryItemEx, 0)
  2287. m := WrStandardFactoryItem{WRSTANDARDID: r.WRSTANDARDID}
  2288. if d, err := m.GetDataEx(); err == nil {
  2289. if lst, ok := d.([]WrStandardFactoryItem); ok {
  2290. mapLst := map[int64]WrStandardFactoryItemEx{}
  2291. for _, v := range lst {
  2292. if a, ok := mapLst[v.DGFACTORYITEMTYPEID]; ok {
  2293. a.ItemLst = append(a.ItemLst, v)
  2294. mapLst[v.DGFACTORYITEMTYPEID] = a
  2295. } else {
  2296. val := WrStandardFactoryItemEx{
  2297. WRSTANDARDID: v.WRSTANDARDID,
  2298. DGFACTORYITEMTYPEID: v.DGFACTORYITEMTYPEID,
  2299. ITEMTYPENAME: v.ITEMTYPENAME,
  2300. ItemLst: make([]WrStandardFactoryItem, 0),
  2301. }
  2302. val.ItemLst = append(val.ItemLst, v)
  2303. mapLst[v.DGFACTORYITEMTYPEID] = val
  2304. }
  2305. }
  2306. for _, ex := range mapLst {
  2307. sData = append(sData, ex)
  2308. }
  2309. sort.Slice(sData, func(i, j int) bool {
  2310. return sData[i].DGFACTORYITEMTYPEID < sData[j].DGFACTORYITEMTYPEID
  2311. })
  2312. }
  2313. }
  2314. return sData, nil
  2315. }
  2316. // WrPerformancePlanStep 履约计划详情
  2317. type WrPerformancePlanStep struct {
  2318. PERFORMANCESTEPID string `json:"performancestepid" xorm:"PERFORMANCESTEPID" form:"curstepid"` // 履约步骤ID(131+Unix秒时间戳(10位)+xxxxxx)
  2319. PLANID string `json:"planid" xorm:"PLANID" form:"planid"` // 所属履约计划ID
  2320. STEPINDEX int32 `json:"stepindex" xorm:"STEPINDEX" form:"stepindex"` // 步骤序号
  2321. STEPDAYS int32 `json:"stepdays" xorm:"STEPDAYS" form:"stepdays"` // 距离上一步天数(分钟)
  2322. 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模板“
  2323. STEPVALUE float64 `json:"stepvalue" xorm:"STEPVALUE" form:"stepvalue"` // 步骤值
  2324. STEPAMOUNT float64 `json:"stepamount" xorm:"STEPAMOUNT" form:"stepamount"` // 步骤金额
  2325. REALAMOUNT float64 `json:"realamount" xorm:"REALAMOUNT" form:"realamount"` // 实际完成金额
  2326. REMAINDAYS int32 `json:"remaindays" xorm:"REMAINDAYS" form:"remaindays"` // 剩余天数
  2327. DELAYDAYS int32 `json:"delaydays" xorm:"DELAYDAYS" form:"delaydays"` // 延期申请天数
  2328. ISAUTO int32 `json:"isauto" xorm:"ISAUTO" form:"isauto"` // 是否自动 - 0:不自动 1:自动
  2329. ISLASTRECEIVESTEP int32 `json:"islastreceivestep" xorm:"ISLASTRECEIVESTEP"` // 是否最后收款步骤 - 0:不是 1:是 (暂时不用,由服务自己判断是否为最后一步付款或收款)
  2330. STEPSTATUS int32 `json:"stepstatus" xorm:"STEPSTATUS" form:"stepstatus"` // 步骤状态 - 1:待开始 2:进行中 3:已完成 4:延期(进行中) 5:失败 6:自动完成 7:超时关闭
  2331. HANDLESTATUS int32 `json:"handlestatus" xorm:"HANDLESTATUS" form:"handlestatus"` // 处理状态 - 1:开始 2:结束 3:冻结请求 4:冻结返回成功 5:冻结返回失败 6:扣款请求 7:扣款返回成功 8:扣款返回失败 9:仓单转移请求 10:仓单转移返回成功 11:仓单转移返回失败 12:加钱请求 13:加钱返回成功 14:加钱返回失败 15:解冻仓单头寸请求 16:解冻仓单头寸返回成功 17:解冻仓单头寸返回失败 18:解冻库位请求 19:解冻库位返回成功 20:解冻库位返回失败
  2332. STEPLANCHTYPE int32 `json:"steplanchtype" xorm:"STEPLANCHTYPE" form:"steplanchtype"` // 步骤启动类型 - 1:系统自动 2:手动
  2333. EXECUTESIDE int32 `json:"executeside" xorm:"EXECUTESIDE" form:"executeside"` // 步骤执行方 - 1:买方 2:卖方
  2334. STARTTIME string `json:"starttime" xorm:"STARTTIME" form:"starttime"` // 开始日期
  2335. ENDTIME string `json:"endtime" xorm:"ENDTIME" form:"endtime"` // 结束日期
  2336. REMARK string `json:"remark" xorm:"REMARK" form:"remark"` // 错误备注
  2337. STEPREMARK string `json:"stepremark" xorm:"STEPREMARK" form:"stepremark"` // 步骤备注
  2338. STEPTYPENAME string `json:"steptypename" xorm:"'STEPTYPENAME'"` // 步骤名称
  2339. RELATEDORDERID string `json:"relatedorderid" xorm:"'RELATEDORDERID'"` // 关联单号
  2340. OVERDAYS int32 `json:"overdays" xorm:"'OVERDAYS'"` // 超期天数 = 当前时间(数据库时间) - 结束日期
  2341. Wr2FactorType `xorm:"extends"`
  2342. }
  2343. func (r *WrPerformancePlanStep) calc() {
  2344. r.Wr2FactorType.Calc()
  2345. }
  2346. func (r *WrPerformancePlanStep) buildSql() string {
  2347. var sqlId utils.SQLVal = "with tmp as" +
  2348. " (select to_char(t.wrfactortypeid) wrfactortypeid," +
  2349. " t.wrfactortypename2 wrfactortypename," +
  2350. " t.wrstandardid," +
  2351. " t.deliverygoodsid," +
  2352. " g.deliverygoodscode," +
  2353. " g.deliverygoodsname," +
  2354. " w.wrstandardcode," +
  2355. " w.wrstandardname," +
  2356. " h.warehousecode," +
  2357. " h.warehousename," +
  2358. " e.enumdicname," +
  2359. " w.wrstandardname || t.wrfactortypename2 as wrtypename" +
  2360. " from wrfactortype t" +
  2361. " left join deliverygoods g" +
  2362. " on t.deliverygoodsid = g.deliverygoodsid" +
  2363. " left join wrstandard w" +
  2364. " on t.wrstandardid = w.wrstandardid" +
  2365. " left join warehouseinfo h" +
  2366. " on t.warehouseid = h.autoid" +
  2367. " left join enumdicitem e" +
  2368. " on w.unitid = e.enumitemname" +
  2369. " and e.enumdiccode = 'goodsunit')" +
  2370. "SELECT to_char(t.PERFORMANCESTEPID) PERFORMANCESTEPID," +
  2371. " to_char(t.PLANID) PLANID," +
  2372. " t.STEPINDEX," +
  2373. " t.STEPDAYS," +
  2374. " t.STEPTYPEID," +
  2375. " t.STEPVALUE," +
  2376. " t.STEPAMOUNT," +
  2377. " t.REALAMOUNT," +
  2378. " t.REMAINDAYS," +
  2379. " t.DELAYDAYS," +
  2380. " t.ISAUTO," +
  2381. " t.ISLASTRECEIVESTEP," +
  2382. " t.STEPSTATUS," +
  2383. " t.HANDLESTATUS," +
  2384. " t.STEPLANCHTYPE," +
  2385. " t.EXECUTESIDE," +
  2386. " to_char(t.STARTTIME, 'yyyy-mm-dd hh24:mi:ss') STARTTIME," +
  2387. " to_char(t.ENDTIME, 'yyyy-mm-dd hh24:mi:ss') ENDTIME," +
  2388. " nvl(trunc(sysdate) - trunc(t.endtime), 0) overdays," +
  2389. " t.REMARK," +
  2390. " t.STEPREMARK," +
  2391. " s.steptypename," +
  2392. " to_char(p.relatedorderid) relatedorderid," +
  2393. " k.*" +
  2394. " FROM PERFORMANCESTEP t" +
  2395. " LEFT JOIN PERFORMANCESTEPTYPE s on t.steptypeid=s.steptypeid" +
  2396. " LEFT JOIN PERFORMANCEPLAN p on t.planid=p.performanceplanid" +
  2397. " LEFT JOIN PERFORMANCEPLANWR pr on p.performanceplanid=pr.performanceplanid" +
  2398. " LEFT JOIN tmp k on pr.wrfactortypeid=k.wrfactortypeid" +
  2399. " WHERE 1 = 1"
  2400. sqlId.And("t.PLANID", r.PLANID)
  2401. sqlId.AndEx("t.PERFORMANCESTEPID", r.PERFORMANCESTEPID, r.PERFORMANCESTEPID != "")
  2402. sqlId.Join(" order by t.stepindex")
  2403. return sqlId.String()
  2404. }
  2405. // GetDataEx 获取履约计划详情
  2406. func (r *WrPerformancePlanStep) GetDataEx() (interface{}, error) {
  2407. sData := make([]WrPerformancePlanStep, 0)
  2408. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  2409. for i := range sData {
  2410. sData[i].calc()
  2411. }
  2412. return sData, err
  2413. }
  2414. // WrFinanceBuyApply 融资购买申请表
  2415. type WrFinanceBuyApply struct {
  2416. FINANCEAPPLYID string `json:"financeapplyid" xorm:"FINANCEAPPLYID" form:"financeapplyid"` // 融资申请单ID(320+Unix秒时间戳(10位)+xxxxxx)
  2417. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE" form:"tradedate"` // 交易日(yyyyMMdd)
  2418. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL" form:"buyorsell"` // 买卖 - 0:买 1:卖
  2419. MARKETID int64 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID
  2420. BUYUSERID int64 `json:"buyuserid" xorm:"BUYUSERID" form:"userid"` // 买方用户ID
  2421. BUYACCOUNTID int64 `json:"buyaccountid" xorm:"BUYACCOUNTID" form:"buyaccountid"` // 买方资金账号
  2422. SELLWRTRADEORDERID string `json:"sellwrtradeorderid" xorm:"SELLWRTRADEORDERID" form:"sellwrtradeorderid"` // 卖方委托单ID
  2423. WRFACTORTYPEID string `json:"wrfactortypeid" xorm:"WRFACTORTYPEID" form:"wrfactortypeid"` // 仓单要素类型ID
  2424. ORDERQTY float64 `json:"orderqty" xorm:"ORDERQTY" form:"orderqty"` // 委托数量(商品数量)
  2425. SELLUSERID int64 `json:"selluserid" xorm:"SELLUSERID" form:"selluserid"` // 卖方用户ID
  2426. SELLACCOUNTID int64 `json:"sellaccountid" xorm:"SELLACCOUNTID" form:"sellaccountid"` // 卖方资金账号
  2427. FINANCEACCOUNTID int64 `json:"financeaccountid" xorm:"FINANCEACCOUNTID" form:"financeaccountid"` // 融资方资金帐户ID
  2428. FINANCEAREAUSERID string `json:"financeareauserid" xorm:"FINANCEAREAUSERID" form:"financeareauserid"` // 融资方用户ID
  2429. ISAUTOLOAN int32 `json:"isautoloan" xorm:"ISAUTOLOAN" form:"isautoloan"` // 是否自动放款 - 0:手动 1:自动
  2430. REMARK string `json:"remark" xorm:"REMARK" form:"remark"` // 备注
  2431. APPLYSTATUS int32 `json:"applystatus" xorm:"APPLYSTATUS" form:"applystatus"` // 申请状态 - 1:待审核 2.审核中 3:审核通过 4:审核拒绝 5:审核失败 6:已撤销 7:自动审核 8:融资失败
  2432. APPLYUSERID int64 `json:"applyuserid" xorm:"APPLYUSERID" form:"applyuserid"` // 申请人
  2433. APPLYDATE string `json:"applydate" xorm:"APPLYDATE" form:"applydate"` // 申请时间
  2434. AUDITUSERID int64 `json:"audituserid" xorm:"AUDITUSERID" form:"audituserid"` // 审核人
  2435. AUDITDATE string `json:"auditdate" xorm:"AUDITDATE" form:"auditdate"` // 审核时间
  2436. AUDITREMARK string `json:"auditremark" xorm:"AUDITREMARK" form:"auditremark"` // 审核备注
  2437. HANDLESTATUS int32 `json:"handlestatus" xorm:"HANDLESTATUS" form:"handlestatus"` // 处理状态
  2438. HANDLEREMARK string `json:"handleremark" xorm:"HANDLEREMARK" form:"handleremark"` // 处理备注
  2439. BUYWRTRADEORDERID string `json:"buywrtradeorderid" xorm:"BUYWRTRADEORDERID" form:"buywrtradeorderid"` // 融资方买委托单ID
  2440. SCFCONTRACTID string `json:"scfcontractid" xorm:"SCFCONTRACTID" form:"scfcontractid"` // 仓单回购合同ID
  2441. FREEZEBUYMARGIN float64 `json:"freezebuymargin" xorm:"FREEZEBUYMARGIN" form:"freezebuymargin"` // 冻结融资保证金(买方)
  2442. WRPRICETYPE int32 `json:"wrpricetype" xorm:"WRPRICETYPE" form:"wrpricetype"` // 价格方式 - 1:固定价 2-浮动价 - [挂牌单]
  2443. TRADEPRICE float64 `json:"tradeprice" xorm:"TRADEPRICE" form:"tradeprice"` // 成交价格
  2444. TRADEAMOUNT float64 `json:"tradeamount" xorm:"TRADEAMOUNT" form:"tradeamount"` // 成交金额(借款金额)
  2445. DELIVERYMONTH string `json:"deliverymonth" xorm:"DELIVERYMONTH" form:"deliverymonth"` // 交收月(yyyy-MM) [无仓单HasWR =0]
  2446. BUYUSERNAME string `json:"buyusername" xorm:"'BUYUSERNAME'"` // 买方名称
  2447. FINANCENAME string `json:"financename" xorm:"'FINANCENAME'"` // 融出方名称
  2448. FINANCETYPE int32 `json:"financetype" xorm:"'FINANCETYPE'"` // 融资类型 1-融资回购
  2449. PRODUCTDETAILID int64 `json:"productdetailid" xorm:"PRODUCTDETAILID" form:"productdetailid"` // 产品组合ID
  2450. PRODUCTID int64 `json:"productid" xorm:"PRODUCTID"` // 金融产品ID
  2451. PRODUCTNAME string `json:"productname" xorm:"'PRODUCTNAME'"` // 产品名称
  2452. FINANCINGDAYS int32 `json:"financingdays" xorm:"FINANCINGDAYS"` // 天数(天)
  2453. MARGINRATIO float64 `json:"marginratio" xorm:"MARGINRATIO"` // 保证金比率质押率 - [仓单质押]
  2454. INTERESTRATEMODE int32 `json:"interestratemode" xorm:"INTERESTRATEMODE"` // 利率方式 - 1:年利率 2:日利率 3:日固定值
  2455. INTERESTRATE float64 `json:"interestrate" xorm:"INTERESTRATE"` // 利率
  2456. INTERESTMINLEN int32 `json:"interestminlen" xorm:"INTERESTMINLEN"` // 最小起息天数
  2457. INTERESTSETTLEMODE int32 `json:"interestsettlemode" xorm:"INTERESTSETTLEMODE"` // 结息方式 - 1:按日结息 3:按月结息
  2458. INTERESTSETTLEVALUE int32 `json:"interestsettlevalue" xorm:"INTERESTSETTLEVALUE"` // 结息方式值
  2459. Wr2FactorType `xorm:"extends"`
  2460. }
  2461. func (r *WrFinanceBuyApply) calc() {
  2462. r.FINANCENAME = EncryptByStar(r.FINANCENAME)
  2463. }
  2464. func (r *WrFinanceBuyApply) buildSql() string {
  2465. var sqlId utils.SQLVal = "with tmp as" +
  2466. " (select to_char(t.wrfactortypeid) wrfactortypeid," +
  2467. " t.wrfactortypename2 wrfactortypename," +
  2468. " t.wrstandardid," +
  2469. " t.deliverygoodsid," +
  2470. " g.deliverygoodscode," +
  2471. " g.deliverygoodsname," +
  2472. " w.wrstandardcode," +
  2473. " w.wrstandardname," +
  2474. " h.warehousecode," +
  2475. " h.warehousename," +
  2476. " e.enumdicname," +
  2477. " w.wrstandardname || t.wrfactortypename2 as wrtypename" +
  2478. " from wrfactortype t" +
  2479. " left join deliverygoods g" +
  2480. " on t.deliverygoodsid = g.deliverygoodsid" +
  2481. " left join wrstandard w" +
  2482. " on t.wrstandardid = w.wrstandardid" +
  2483. " left join warehouseinfo h" +
  2484. " on t.warehouseid = h.autoid" +
  2485. " left join enumdicitem e" +
  2486. " on w.unitid = e.enumitemname" +
  2487. " and e.enumdiccode = 'goodsunit')" +
  2488. "SELECT to_char(t.FINANCEAPPLYID) FINANCEAPPLYID," +
  2489. " t.TRADEDATE," +
  2490. " t.BUYORSELL," +
  2491. " t.MARKETID," +
  2492. " t.BUYUSERID," +
  2493. " t.BUYACCOUNTID," +
  2494. " to_char(t.SELLWRTRADEORDERID) SELLWRTRADEORDERID," +
  2495. " t.ORDERQTY," +
  2496. " t.SELLUSERID," +
  2497. " t.SELLACCOUNTID," +
  2498. " t.PRODUCTDETAILID," +
  2499. " t.FINANCEACCOUNTID," +
  2500. " t.FINANCEAREAUSERID," +
  2501. " t.ISAUTOLOAN," +
  2502. " t.REMARK," +
  2503. " t.APPLYSTATUS," +
  2504. " t.APPLYUSERID," +
  2505. " to_char(t.APPLYDATE, 'yyyy-mm-dd hh24:mi:ss') APPLYDATE," +
  2506. " t.AUDITUSERID," +
  2507. " to_char(t.AUDITDATE, 'yyyy-mm-dd hh24:mi:ss') AUDITDATE," +
  2508. " t.AUDITREMARK," +
  2509. " t.HANDLESTATUS," +
  2510. " t.HANDLEREMARK," +
  2511. " to_char(t.BUYWRTRADEORDERID) BUYWRTRADEORDERID," +
  2512. " t.SCFCONTRACTID," +
  2513. " t.FREEZEBUYMARGIN," +
  2514. " t.WRPRICETYPE," +
  2515. " t.TRADEPRICE," +
  2516. " t.TRADEAMOUNT," +
  2517. " t.DELIVERYMONTH," +
  2518. " t.FINANCETYPE," +
  2519. " f.PRODUCTNAME," +
  2520. " t.FINANCINGDAYS," +
  2521. " t.MARGINRATIO," +
  2522. " t.INTERESTRATEMODE," +
  2523. " t.INTERESTRATE," +
  2524. " t.INTERESTMINLEN," +
  2525. " t.INTERESTSETTLEMODE," +
  2526. " t.INTERESTSETTLEVALUE," +
  2527. " u1.accountname BUYUSERNAME," +
  2528. " u2.accountname FINANCENAME," +
  2529. " tmp.*" +
  2530. " FROM WRTRADE_FINANCEBUYAPPLY t" +
  2531. " LEFT JOIN FINANCEAREAPRODUCTDETAIL p on t.productdetailid = p.productdetailid" +
  2532. " LEFT JOIN FinanceAreaProduct f on p.productid = f.productid" +
  2533. " LEFT JOIN tmp on t.wrfactortypeid=tmp.wrfactortypeid" +
  2534. " LEFT JOIN USERACCOUNT u1 on t.BUYUSERID = u1.userid" +
  2535. " LEFT JOIN USERACCOUNT u2 on t.FINANCEAREAUSERID = u2.userid" +
  2536. " WHERE 1 = 1"
  2537. sqlId.AndEx("t.BUYUSERID", r.BUYUSERID, r.BUYUSERID > 0)
  2538. sqlId.AndEx("t.FINANCEAPPLYID", r.FINANCEAPPLYID, r.FINANCEAPPLYID != "")
  2539. return sqlId.String()
  2540. }
  2541. // GetDataEx 获取融资购买申请表
  2542. func (r *WrFinanceBuyApply) GetDataEx() (interface{}, error) {
  2543. sData := make([]WrFinanceBuyApply, 0)
  2544. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  2545. for i := range sData {
  2546. sData[i].calc()
  2547. }
  2548. return sData, err
  2549. }
  2550. // WrScfContract 仓单贸易融资合同
  2551. type WrScfContract struct {
  2552. DEADLINE string `json:"deadline" xorm:"DEADLINE"` // 截止日期(yyyyMMdd) -> 借款到期时间
  2553. MARKETID int64 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID - 拆成三个独立模式后,根据市场ID处理
  2554. SCFCONTRACTID string `json:"scfcontractid" xorm:"SCFCONTRACTID" form:"scfcontractid"` // SCF合同ID(310+Unix秒时间戳(10位)+xxxxxx)
  2555. SCFCONTRACTTYPE int32 `json:"scfcontracttype" xorm:"SCFCONTRACTTYPE" form:"scfcontracttype"` // 合同类型 - 1:仓单回购 2:仓单质押 3:合作套保 4:资金贷款 5:融资单 6:融资回购
  2556. LENDERUSERID int64 `json:"lenderuserid" xorm:"LENDERUSERID" form:"lenderuserid"` // 贷款方用户ID -> 融出方用户ID
  2557. BORROWERUSERID int64 `json:"borroweruserid" xorm:"BORROWERUSERID" form:"userid"` // 借款用户ID
  2558. LENDERAMOUNT float64 `json:"lenderamount" xorm:"LENDERAMOUNT"` // 贷款金额 -> 借款金额
  2559. WRFACTORTYPEID int64 `json:"wrfactortypeid" xorm:"WRFACTORTYPEID" form:"wrfactortypeid"` // 仓单要素类型ID - [仓单回购\仓单质押]
  2560. WRQTY float64 `json:"wrqty" xorm:"WRQTY"` // 仓单数量 - [仓单回购\仓单质押] -> 数量
  2561. ISAUTOLOAN int32 `json:"isautoloan" xorm:"ISAUTOLOAN"` // 是否自动放款 - 0:手动 1:自动 - [仓单质押]
  2562. REMAINAMOUNT float64 `json:"remainamount" xorm:"REMAINAMOUNT"` // 合同剩余金额 -> 剩余金额
  2563. INITMARGIN float64 `json:"initmargin" xorm:"INITMARGIN"` // 保证金 - [仓单回购]
  2564. REMAINWRPOSITIONQTY float64 `json:"remainwrpositionqty" xorm:"REMAINWRPOSITIONQTY"` // 剩余仓单头寸数量 - [仓单回购\仓单质押] -> 剩余数量(待回购数量)
  2565. BUYBACKWRPOSITIONQTY float64 `json:"buybackwrpositionqty" xorm:"BUYBACKWRPOSITIONQTY"` // 已回购仓单头寸数量 - [仓单回购\仓单质押] -> 已回购数量
  2566. INTERESTAMOUNT float64 `json:"interestamount" xorm:"INTERESTAMOUNT"` // 计息金额=合同剩余金额 - 初始保证金 - 追缴保证金 \ 合同剩余金额
  2567. TOTALINTEREST float64 `json:"totalinterest" xorm:"TOTALINTEREST"` // 已计利息 -> 已计费用
  2568. CLOSEINTEREST float64 `json:"closeinterest" xorm:"CLOSEINTEREST"` // 已结利息 -> 已结费用
  2569. INTERESTDEBT float64 `json:"interestdebt" xorm:"INTERESTDEBT"` // 利息欠款(记录负数) -> 费用欠款
  2570. STARTINTERESTDAY string `json:"startinterestday" xorm:"STARTINTERESTDAY"` // 计息开始日(yyyyMMdd) -> 开始计费日期
  2571. LASTCLOSEINTERESTDAY string `json:"lastcloseinterestday" xorm:"LASTCLOSEINTERESTDAY"` // 最近结息日(yyyyMMdd)
  2572. SCFCONTRACTSTATUS int32 `json:"scfcontractstatus" xorm:"SCFCONTRACTSTATUS"` // 合同状态 - 1:待确认 2:已确认 3:确认拒绝 4:已支付保证金 5:已激活 6:已违约 7:到期结束 8:延期结束 9:违约结束 10:已注销 11:已关闭 99:未提交
  2573. UPDATETIME string `json:"updatetime" xorm:"UPDATETIME"` // 更新时间
  2574. REMARK string `json:"remark" xorm:"REMARK"` // 备注
  2575. PRICEMOVE float64 `json:"pricemove" xorm:"PRICEMOVE"` // 估值升贴水值
  2576. CURRISKLEVEL int32 `json:"currisklevel" xorm:"CURRISKLEVEL"` // 风险级别 - 1:正常 2:追加货款 3:支付尾款
  2577. PRODUCTDETAILID int64 `json:"productdetailid" xorm:"PRODUCTDETAILID" form:"productdetailid"` // 产品组合ID
  2578. PRODUCTID int64 `json:"productid" xorm:"PRODUCTID"` // 金融产品ID
  2579. PRODUCTNAME string `json:"productname" xorm:"'PRODUCTNAME'"` // 产品名称
  2580. FINANCINGDAYS int32 `json:"financingdays" xorm:"FINANCINGDAYS"` // 天数(天)
  2581. MARGINRATIO float64 `json:"marginratio" xorm:"MARGINRATIO"` // 保证金比率质押率 - [仓单质押]
  2582. INTERESTRATEMODE int32 `json:"interestratemode" xorm:"INTERESTRATEMODE"` // 利率方式 - 1:年利率 2:日利率 3:日固定值
  2583. INTERESTRATE float64 `json:"interestrate" xorm:"INTERESTRATE"` // 利率
  2584. INTERESTMINLEN int32 `json:"interestminlen" xorm:"INTERESTMINLEN"` // 最小起息天数
  2585. INTERESTSETTLEMODE int32 `json:"interestsettlemode" xorm:"INTERESTSETTLEMODE"` // 结息方式 - 1:按日结息 3:按月结息
  2586. INTERESTSETTLEVALUE int32 `json:"interestsettlevalue" xorm:"INTERESTSETTLEVALUE"` // 结息方式值
  2587. Wr2FactorType `xorm:"extends"`
  2588. UNPAIDINTEREST SFLOAT64 `json:"unpaidinterest"` // 未结费用
  2589. LENDERUSERNAME string `json:"lenderusername"` // 融出方
  2590. }
  2591. func (r *WrScfContract) calc() {
  2592. r.LENDERUSERNAME = mtpcache.GetUserNameByUserId(r.LENDERUSERID)
  2593. r.LENDERUSERNAME = EncryptByStar(r.LENDERUSERNAME)
  2594. r.UNPAIDINTEREST.Set(r.TOTALINTEREST - r.CLOSEINTEREST)
  2595. r.UNPAIDINTEREST.Round(2)
  2596. }
  2597. func (r *WrScfContract) buildSql() string {
  2598. var sqlId utils.SQLVal = "with tmp as" +
  2599. " (select to_char(t.wrfactortypeid) wrfactortypeid," +
  2600. " t.wrfactortypename," +
  2601. " t.wrstandardid," +
  2602. " t.deliverygoodsid," +
  2603. " g.deliverygoodscode," +
  2604. " g.deliverygoodsname," +
  2605. " w.wrstandardcode," +
  2606. " w.wrstandardname," +
  2607. " h.warehousecode," +
  2608. " h.warehousename," +
  2609. " e.enumdicname," +
  2610. " w.wrstandardname || t.wrfactortypename2 as wrtypename" +
  2611. " from wrfactortype t" +
  2612. " left join deliverygoods g" +
  2613. " on t.deliverygoodsid = g.deliverygoodsid" +
  2614. " left join wrstandard w" +
  2615. " on t.wrstandardid = w.wrstandardid" +
  2616. " left join warehouseinfo h" +
  2617. " on t.warehouseid = h.autoid" +
  2618. " left join enumdicitem e" +
  2619. " on w.unitid = e.enumitemname" +
  2620. " and e.enumdiccode = 'goodsunit')" +
  2621. "select to_char(t.scfcontractid) scfcontractid," +
  2622. " t.scfcontracttype," +
  2623. " t.marketid," +
  2624. " t.lenderuserid," +
  2625. " t.lenderamount," +
  2626. " s.remainamount," +
  2627. " s.initmargin," +
  2628. " t.wrqty," +
  2629. " s.buybackwrpositionqty," +
  2630. " s.remainwrpositionqty," +
  2631. " s.closeinterest," +
  2632. " s.totalinterest," +
  2633. " s.interestdebt," +
  2634. " s.startinterestday," +
  2635. " s.lastcloseinterestday," +
  2636. " t.deadline," +
  2637. " s.scfcontractstatus," +
  2638. " p.productdetailid," +
  2639. " p.productid," +
  2640. " f.productname," +
  2641. " p.FINANCINGDAYS," +
  2642. " p.MARGINRATIO," +
  2643. " p.INTERESTRATEMODE," +
  2644. " p.INTERESTRATE," +
  2645. " p.INTERESTMINLEN," +
  2646. " p.INTERESTSETTLEMODE," +
  2647. " p.INTERESTSETTLEVALUE," +
  2648. " tmp.*" +
  2649. " from scf_contract t" +
  2650. " left join scf_contractinfo s" +
  2651. " on t.scfcontractid = s.scfcontractid" +
  2652. " left join WRTrade_FinanceBuyApply a" +
  2653. " on t.scfcontractid = a.scfcontractid" +
  2654. " left join FINANCEAREAPRODUCTDETAIL p" +
  2655. " on a.productdetailid = p.productdetailid" +
  2656. " left join FINANCEAREAPRODUCT f" +
  2657. " on p.productid = f.productid" +
  2658. " left join tmp" +
  2659. " on t.wrfactortypeid = tmp.wrfactortypeid" +
  2660. " where 1 = 1"
  2661. sqlId.And("t.borroweruserid", r.BORROWERUSERID)
  2662. sqlId.AndEx("t.scfcontractid", r.SCFCONTRACTID, r.SCFCONTRACTID != "")
  2663. return sqlId.String()
  2664. }
  2665. // GetDataEx 获取仓单贸易融资合同
  2666. func (r *WrScfContract) GetDataEx() (interface{}, error) {
  2667. sData := make([]WrScfContract, 0)
  2668. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  2669. for i := range sData {
  2670. sData[i].calc()
  2671. }
  2672. return sData, err
  2673. }
  2674. // WrBuybackDetail 仓单回购明细
  2675. type WrBuybackDetail struct {
  2676. SCFWRBUYBACKID int64 `json:"scfwrbuybackid" xorm:"SCFWRBUYBACKID" form:"scfwrbuybackid"` // SCF仓单回购明细ID(312+Unix秒时间戳(10位)+xxxxxx)
  2677. SCFCONTRACTID string `json:"scfcontractid" xorm:"SCFCONTRACTID" form:"scfcontractid"` // SCF合同ID
  2678. BUYBACKQTY float64 `json:"buybackqty" xorm:"BUYBACKQTY"` // 回购数量
  2679. BUYBACKAMOUNT float64 `json:"buybackamount" xorm:"BUYBACKAMOUNT"` // 回购金额
  2680. BUYBACKRELEASEMARGIN float64 `json:"buybackreleasemargin" xorm:"BUYBACKRELEASEMARGIN"` // 回购释放保证金
  2681. BUYBACKTIME string `json:"buybacktime" xorm:"BUYBACKTIME"` // 回购时间
  2682. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE" form:"tradedate"` // 交易日(yyyyMMdd)
  2683. RELATEDWRID int64 `json:"relatedwrid" xorm:"RELATEDWRID" form:"relatedwrid"` // 关联仓单ID
  2684. HANDLESTATUS int32 `json:"handlestatus" xorm:"HANDLESTATUS"` // 处理 - 1:待处理 2:处理成功 3:处理失败
  2685. ERRORDESC string `json:"errordesc" xorm:"ERRORDESC"` // 错误描述
  2686. }
  2687. func (r *WrBuybackDetail) calc() {
  2688. }
  2689. func (r *WrBuybackDetail) buildSql() string {
  2690. var sqlId utils.SQLVal = "SELECT t.SCFWRBUYBACKID," +
  2691. " t.SCFCONTRACTID," +
  2692. " t.BUYBACKQTY," +
  2693. " t.BUYBACKAMOUNT," +
  2694. " t.BUYBACKRELEASEMARGIN," +
  2695. " to_char(t.BUYBACKTIME, 'yyyy-mm-dd hh24:mi:ss') BUYBACKTIME," +
  2696. " t.TRADEDATE," +
  2697. " t.RELATEDWRID," +
  2698. " t.HANDLESTATUS," +
  2699. " t.ERRORDESC" +
  2700. " FROM SCF_WRBUYBACKDETAIL t" +
  2701. " WHERE 1 = 1" +
  2702. " AND t.handlestatus = 2"
  2703. sqlId.AndEx("scfcontractid", r.SCFCONTRACTID, r.SCFCONTRACTID != "")
  2704. return sqlId.String()
  2705. }
  2706. // GetDataEx 获取仓单回购明细
  2707. func (r *WrBuybackDetail) GetDataEx() (interface{}, error) {
  2708. sData := make([]WrBuybackDetail, 0)
  2709. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  2710. for i := range sData {
  2711. sData[i].calc()
  2712. }
  2713. return sData, err
  2714. }
  2715. // WrScfContractInterest 合同计息表(费用明细)
  2716. type WrScfContractInterest struct {
  2717. SCFCONTRACTINTERESTID int64 `json:"scfcontractinterestid" xorm:"SCFCONTRACTINTERESTID"` // SCF合同计息ID(313+Unix秒时间戳(10位)+xxxxxx)
  2718. SCFCONTRACTID string `json:"scfcontractid" xorm:"SCFCONTRACTID" form:"scfcontractid"` // SCF合同ID
  2719. INTERESTDAY string `json:"interestday" xorm:"INTERESTDAY"` // 计息日(yyyyMMdd)
  2720. INTEREST float64 `json:"interest" xorm:"INTEREST"` // 利息
  2721. CLOSEINTEREST float64 `json:"closeinterest" xorm:"CLOSEINTEREST"` // 已结利息
  2722. CLOSEINTERESTSTATUS int32 `json:"closeintereststatus" xorm:"CLOSEINTERESTSTATUS"` // 结息状态 - 1:未结 2:已结
  2723. UPDATETIME string `json:"updatetime" xorm:"UPDATETIME"` // 更新时间
  2724. CREATORID int64 `json:"creatorid" xorm:"CREATORID" form:"creatorid"` // 操作人ID
  2725. CLOSETIME string `json:"closetime" xorm:"CLOSETIME"` // 结息时间
  2726. CLOSETRADEDATE string `json:"closetradedate" xorm:"CLOSETRADEDATE" form:"closetradedate"` // 结息交易日
  2727. INTERESTAMOUNT float64 `json:"interestamount" xorm:"INTERESTAMOUNT"` // 计息金额
  2728. DAYRATE float64 `json:"dayrate" xorm:"DAYRATE"` // 日利率(根据利率配置计算出的日利率值,年利率则除以360,保留5位小数)
  2729. }
  2730. func (r *WrScfContractInterest) calc() {
  2731. }
  2732. func (r *WrScfContractInterest) buildSql() string {
  2733. var sqlId utils.SQLVal = "SELECT t.SCFCONTRACTINTERESTID," +
  2734. " t.SCFCONTRACTID," +
  2735. " t.INTERESTDAY," +
  2736. " t.INTEREST," +
  2737. " t.CLOSEINTEREST," +
  2738. " t.CLOSEINTERESTSTATUS," +
  2739. " to_char(t.UPDATETIME, 'yyyy-mm-dd hh24:mi:ss') UPDATETIME," +
  2740. " t.CREATORID," +
  2741. " to_char(t.CLOSETIME, 'yyyy-mm-dd hh24:mi:ss') CLOSETIME," +
  2742. " t.CLOSETRADEDATE," +
  2743. " t.INTERESTAMOUNT," +
  2744. " t.DAYRATE" +
  2745. " FROM SCF_CONTRACTINTEREST t" +
  2746. " WHERE 1 = 1"
  2747. sqlId.AndEx("scfcontractid", r.SCFCONTRACTID, r.SCFCONTRACTID != "")
  2748. return sqlId.String()
  2749. }
  2750. // GetDataEx 获取描述
  2751. func (r *WrScfContractInterest) GetDataEx() (interface{}, error) {
  2752. sData := make([]WrScfContractInterest, 0)
  2753. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  2754. for i := range sData {
  2755. sData[i].calc()
  2756. }
  2757. return sData, err
  2758. }
  2759. // WrOutInApply 出入库申请(提货)
  2760. type WrOutInApply struct {
  2761. APPLYID string `json:"applyid" xorm:"'APPLYID'"` // 申请单id
  2762. APPLYTYPE int32 `json:"applytype" xorm:"'APPLYTYPE'"` // 申请类型 - 1:预约入库 2:预约出库 3:入库注册 4:出库注销
  2763. USERID int64 `json:"userid" xorm:"'USERID'" form:"userid"` // 用户id
  2764. APPLYTIME string `json:"applytime" xorm:"'APPLYTIME'"` // 申请时间
  2765. APPLYSTATUS int32 `json:"applystatus" xorm:"'APPLYSTATUS'"` // 申请状态 - 0:预约成功 1:待初审 2:初审通过 3:初审拒绝 4:初审失败 5复审通过 6:复审拒绝 7:复审失败 8:已撤销
  2766. QTY int64 `json:"qty" xorm:"'QTY'"` // 数量
  2767. EXPRESSNUM string `json:"expressnum" xorm:"'EXPRESSNUM'"` // 物流单号
  2768. EXPRESSCOMPANY string `json:"expresscompany" xorm:"'EXPRESSCOMPANY'"` // 物流公司
  2769. BANNERPICURL string `json:"bannerpicurl" xorm:"BANNERPICURL"` // Banner图
  2770. Wr2FactorType `xorm:"extends"`
  2771. BEGINDATE string `json:"begindate" form:"begindate"` // 开始交易日(yyyymmdd)
  2772. ENDDATE string `json:"enddate" form:"enddate"` // 结束交易日(yyyymmdd)
  2773. APPOINTMENTMODEL int32 `json:"appointmentmodel" xorm:"'APPOINTMENTMODEL'"` // 预约方式 - 1:物流 2:自送 3:自提
  2774. APPOINTMENTMODELDISPLAY string `json:"appointmentmodeldisplay" xorm:"'APPOINTMENTMODELDISPLAY'"` // 预约方式(显示枚举)
  2775. CONTACTNAME string `json:"contactname" xorm:"'CONTACTNAME'"` // 联系人
  2776. CONTACTNUM string `json:"contactnum" xorm:"'CONTACTNUM'"` // 联系方式
  2777. ADDRESS string `json:"address" xorm:"ADDRESS"` // 详细地址
  2778. APPOINTMENTREMARK string `json:"appointmentremark" xorm:"'APPOINTMENTREMARK'"` // 申请备注
  2779. PageEx `xorm:"extends"` // 页码信息
  2780. }
  2781. func (r *WrOutInApply) calc() {
  2782. r.Wr2FactorType.Calc()
  2783. }
  2784. func (r *WrOutInApply) buildSql() string {
  2785. var sqlId utils.SQLVal = "with tmp as" +
  2786. " (select to_char(t.wrfactortypeid) wrfactortypeid," +
  2787. " t.wrfactortypename2 wrfactortypename," +
  2788. " t.wrstandardid," +
  2789. " t.deliverygoodsid," +
  2790. " g.deliverygoodscode," +
  2791. " g.deliverygoodsname," +
  2792. " w.wrstandardcode," +
  2793. " w.wrstandardname," +
  2794. " w.bannerpicurl," +
  2795. " w.minivalue," +
  2796. " h.warehousecode," +
  2797. " h.warehousename," +
  2798. " e.enumdicname," +
  2799. " w.wrstandardname || t.wrfactortypename2 as wrtypename" +
  2800. " from wrfactortype t" +
  2801. " left join deliverygoods g" +
  2802. " on t.deliverygoodsid = g.deliverygoodsid" +
  2803. " left join wrstandard w" +
  2804. " on t.wrstandardid = w.wrstandardid" +
  2805. " left join warehouseinfo h" +
  2806. " on t.warehouseid = h.autoid" +
  2807. " left join enumdicitem e" +
  2808. " on w.unitid = e.enumitemname" +
  2809. " and e.enumdiccode = 'goodsunit')" +
  2810. "select to_char(t.applyid) applyid," +
  2811. " t.applytype," +
  2812. " t.userid," +
  2813. " to_char(t.applytime, 'yyyy-mm-dd hh24:mi:ss') applytime," +
  2814. " decode(t.applytype, 2, t.applystatus, 4, t.applystatus2) applystatus," +
  2815. " decode(t.applytype, 2, t.inqty, 4, t.inrealqty) qty," +
  2816. " e.expressnum," +
  2817. " e.expresscompany," +
  2818. " t.appointmentmodel," +
  2819. " en1.enumdicname appointmentmodeldisplay," +
  2820. " t.contactname," +
  2821. " t.contactnum," +
  2822. " t.address," +
  2823. " t.appointmentremark," +
  2824. " k.*" +
  2825. " from WROutInApply t" +
  2826. " left join wroutindetail d" +
  2827. " on t.applyid = d.applyid" +
  2828. " left join wroutinexpress e" +
  2829. " on t.applyid = e.applyid" +
  2830. " left join tmp k" +
  2831. " on d.wrfactortypeid = k.wrfactortypeid" +
  2832. " left join enumdicitem en1" +
  2833. " on t.appointmentmodel = en1.enumitemname and en1.enumdiccode='appointmentModel'" +
  2834. " where t.applytype in (2, 4)"
  2835. sqlId.AndEx("t.USERID", r.USERID, r.USERID > 0)
  2836. // 格式 yyyymmdd
  2837. if len(r.BEGINDATE) > 0 {
  2838. sqlId.JoinFormat(" and t.TRADEDATE >= '%v'", r.BEGINDATE)
  2839. }
  2840. if len(r.ENDDATE) > 0 {
  2841. sqlId.JoinFormat(" and t.TRADEDATE <= '%v'", r.ENDDATE)
  2842. }
  2843. sqlId.Join(" order by t.applytime desc")
  2844. sqlId.Page(r.Page, r.PageSize)
  2845. return sqlId.String()
  2846. }
  2847. // GetDataEx 获取出入库申请(提货)
  2848. func (r *WrOutInApply) GetDataEx() (interface{}, error) {
  2849. sData := make([]WrOutInApply, 0)
  2850. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  2851. for i := range sData {
  2852. sData[i].calc()
  2853. }
  2854. return sData, err
  2855. }
  2856. // GetDataEx 获取出入库申请(提货) - 分页
  2857. func (r *WrOutInApply) GetDataByPage() (interface{}, error, int, int, int) {
  2858. sData := make([]WrOutInApply, 0)
  2859. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  2860. total := 0
  2861. for i := range sData {
  2862. sData[i].calc()
  2863. total = sData[i].Total
  2864. }
  2865. return sData, err, r.Page, r.PageSize, total
  2866. }
  2867. // WrDeliveryDetail 交收
  2868. type WrDeliveryDetail struct {
  2869. DELIVERYID string `json:"deliveryid" xorm:"'DELIVERYID'"` //交割单号(121+Unix秒时间戳(10位)+xxxxxx)
  2870. DELIVERYQTY float64 `json:"deliveryqty" xorm:"DELIVERYQTY"` // 交收数量(点选数量)
  2871. XDELIVERYCLOSEQTY float64 `json:"xdeliverycloseqty" xorm:"'XDELIVERYCLOSEQTY'"` // 合约数量
  2872. PDELIVERYCLOSEQTY float64 `json:"pdeliverycloseqty" xorm:"'PDELIVERYCLOSEQTY'"` // p合约平仓数量
  2873. DELIVERYTIME string `json:"deliverytime" xorm:"DELIVERYTIME"` // 交割时间
  2874. DELIVERYAMOUNT float64 `json:"deliveryamount" xorm:"DELIVERYAMOUNT"` // 货款金额(X总货款+P总货款)
  2875. DELIVERYPRICEMOVE float64 `json:"deliverypricemove" xorm:"DELIVERYPRICEMOVE"` // 升贴水(升贴水总额)
  2876. DELIVERYTOTALAMOUNT float64 `json:"deliverytotalamount" xorm:"DELIVERYTOTALAMOUNT"` // 交收金额
  2877. P1GOODSREMAINAMOUNT float64 `json:"p1goodsremainamount" xorm:"P1GOODSREMAINAMOUNT"` // 点价货款 ps:当PPRICEMODE=2时, 界面需显示"-"
  2878. WRFACTORTYPEID string `json:"wrfactortypeid" xorm:"WRFACTORTYPEID"` // 仓单要素类型ID
  2879. DELIVERYSTATUS int32 `json:"deliverystatus" xorm:"DELIVERYSTATUS"` // 状态 - 1:待成交 2:已成交 3:成交失败 4:履约完成
  2880. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL"` // 方向 - 0:买 1:卖
  2881. DELIVERYORDERID string `json:"deliveryorderid" xorm:"DELIVERYORDERID"` // 申报单号
  2882. ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID" form:"accountid"` // 账号ID
  2883. MATCHACCOUNTID int64 `json:"matchaccountid" xorm:"MATCHACCOUNTID"` // 对手账号ID
  2884. XGOODSID int32 `json:"xgoodsid" xorm:"XGOODSID" form:"xgoodsid"` // x交易合约ID
  2885. PGOODSID int32 `json:"pgoodsid" xorm:"'PGOODSID'"` // p点选合约id
  2886. PPRICEMODE int32 `json:"ppricemode" xorm:"PPRICEMODE"` // 点价价格方式 - 1:商品价 2:固定值
  2887. PDELIVERYPRICE float64 `json:"pdeliveryprice" xorm:"PDELIVERYPRICE"` // 点价价格 ps:当PPRICEMODE=2时, 界面需显示"-"
  2888. XGOODSCODE string `json:"xgoodscode" xorm:"'XGOODSCODE'"` // 商品代码
  2889. XGOODSNAME string `json:"xgoodsname" xorm:"'XGOODSNAME'"` // 商品名称
  2890. PGOODSCODE string `json:"pgoodscode" xorm:"'PGOODSCODE'"` // 商品代码
  2891. PGOODSNAME string `json:"pgoodsname" xorm:"'PGOODSNAME'"` // 商品名称
  2892. USERID int64 `json:"userid" xorm:"'USERID'" form:"userid"` // 用户id
  2893. USERNAME string `json:"username" xorm:"'USERNAME'"` // 用户名称
  2894. MATCHUSERNAME string `json:"matchusername" xorm:"'MATCHUSERNAME'"` // 对手方名称(仓单持有人)
  2895. TRADEDATE string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日(yyyymmdd)
  2896. WRTYPENAME string `json:"wrtypename" xorm:"'WRTYPENAME'"` // 商品
  2897. WAREHOUSENAME string `json:"warehousename" xorm:"'WAREHOUSENAME'"` // 仓库名称
  2898. ENUMDICNAME string `json:"enumdicname" xorm:"'ENUMDICNAME'"` // 单位名称
  2899. XGOODSAMOUNT SFLOAT64 `json:"xgoodsamount"` // 合约金额 = 货款金额(DELIVERYAMOUNT) - 点价货款(P1GOODSREMAINAMOUNT)
  2900. AVERAGEPRICE SFLOAT64 `json:"averageprice"` // 交割均价 = 交割金额 / 交割数量
  2901. BEGINDATE string `json:"begindate" form:"begindate"` // 开始交易日(yyyymmdd)
  2902. ENDDATE string `json:"enddate" form:"enddate"` // 结束交易日(yyyymmdd)
  2903. }
  2904. func (r *WrDeliveryDetail) calc() {
  2905. r.MATCHUSERNAME = EncryptByStar(r.MATCHUSERNAME)
  2906. if r.WRTYPENAME != "" {
  2907. r.WRTYPENAME = strings.ReplaceAll(r.WRTYPENAME, ",", "-")
  2908. }
  2909. r.XGOODSAMOUNT.Set(r.DELIVERYAMOUNT - r.P1GOODSREMAINAMOUNT)
  2910. if r.DELIVERYQTY > 1e-8 {
  2911. r.AVERAGEPRICE.Set(r.DELIVERYTOTALAMOUNT / r.DELIVERYQTY)
  2912. r.AVERAGEPRICE.Round(3)
  2913. }
  2914. }
  2915. func (r *WrDeliveryDetail) buildSql() string {
  2916. var sqlId utils.SQLVal = `
  2917. select t.xgoodsid,
  2918. t.buyorsell,
  2919. to_char(t.deliveryid) deliveryid,
  2920. t.deliveryqty,
  2921. t.xdeliverycloseqty,
  2922. t.pdeliverycloseqty,
  2923. t.deliveryamount,
  2924. t.pdeliveryprice,
  2925. t.p1goodsremainamount,
  2926. t.deliverypricemove,
  2927. t.deliverytotalamount,
  2928. to_char(t.deliverytime, 'yyyy-mm-dd hh24:mi:ss') deliverytime,
  2929. t.deliverystatus,
  2930. t.accountid,
  2931. t.matchaccountid,
  2932. t.tradedate,
  2933. to_char(t.wrfactortypeid) wrfactortypeid,
  2934. to_char(t.deliveryorderid) deliveryorderid,
  2935. g.goodscode xgoodscode,
  2936. g.goodsname xgoodsname,
  2937. t.pgoodsid,
  2938. g2.goodscode pgoodscode,
  2939. g2.goodsname pgoodsname,
  2940. ta.accountname taaccountname,
  2941. u.userid,
  2942. u.accountname username,
  2943. u2.accountname matchusername,
  2944. wd.wrstandardname || w.wrfactortypename2 as WRTYPENAME,
  2945. h.warehousename,
  2946. e.enumdicname
  2947. from deliverydetail t
  2948. left join goods g
  2949. on t.xgoodsid = g.goodsid
  2950. left join goods g2
  2951. on t.pgoodsid = g2.goodsid
  2952. left join taaccount ta
  2953. on t.accountid = ta.accountid
  2954. left join useraccount u
  2955. on ta.userid = u.userid
  2956. left join taaccount ta2
  2957. on t.accountid = ta2.accountid
  2958. left join useraccount u2
  2959. on ta2.userid = u2.userid
  2960. left join wrfactortype w
  2961. on t.wrfactortypeid = w.wrfactortypeid
  2962. left join wrstandard wd
  2963. on w.wrstandardid = wd.wrstandardid
  2964. left join warehouseinfo h on w.warehouseid=h.autoid
  2965. left join enumdicitem e on wd.unitid=e.enumitemname and e.enumdiccode='goodsunit'
  2966. where 1 = 1
  2967. `
  2968. sqlId.AndEx("u.userid", r.USERID, r.USERID > 0)
  2969. sqlId.AndEx("t.accountid", r.ACCOUNTID, r.ACCOUNTID > 0)
  2970. return sqlId.String()
  2971. }
  2972. func (r *WrDeliveryDetail) buildSqlHis() string {
  2973. var sqlId utils.SQLVal = `
  2974. select t.xgoodsid,
  2975. t.buyorsell,
  2976. to_char(t.deliveryid) deliveryid,
  2977. t.deliveryqty,
  2978. t.xdeliverycloseqty,
  2979. t.pdeliverycloseqty,
  2980. t.deliveryamount,
  2981. t.pdeliveryprice,
  2982. t.p1goodsremainamount,
  2983. t.deliverypricemove,
  2984. t.deliverytotalamount,
  2985. to_char(t.deliverytime, 'yyyy-mm-dd hh24:mi:ss') deliverytime,
  2986. t.deliverystatus,
  2987. t.accountid,
  2988. t.matchaccountid,
  2989. t.tradedate,
  2990. to_char(t.wrfactortypeid) wrfactortypeid,
  2991. to_char(t.deliveryorderid) deliveryorderid,
  2992. g.goodscode xgoodscode,
  2993. g.goodsname xgoodsname,
  2994. t.pgoodsid,
  2995. g2.goodscode pgoodscode,
  2996. g2.goodsname pgoodsname,
  2997. ta.accountname taaccountname,
  2998. u.userid,
  2999. u.accountname username,
  3000. u2.accountname matchusername,
  3001. wd.wrstandardname || w.wrfactortypename2 as WRTYPENAME,
  3002. h.warehousename,
  3003. e.enumdicname
  3004. from his_deliverydetail t
  3005. left join goods g
  3006. on t.xgoodsid = g.goodsid
  3007. left join goods g2
  3008. on t.pgoodsid = g2.goodsid
  3009. left join taaccount ta
  3010. on t.accountid = ta.accountid
  3011. left join useraccount u
  3012. on ta.userid = u.userid
  3013. left join taaccount ta2
  3014. on t.accountid = ta2.accountid
  3015. left join useraccount u2
  3016. on ta2.userid = u2.userid
  3017. left join wrfactortype w
  3018. on t.wrfactortypeid = w.wrfactortypeid
  3019. left join wrstandard wd
  3020. on w.wrstandardid = wd.wrstandardid
  3021. left join warehouseinfo h on w.warehouseid=h.autoid
  3022. left join enumdicitem e on wd.unitid=e.enumitemname and e.enumdiccode='goodsunit'
  3023. where 1 = 1 and t.isvaliddata = 1
  3024. `
  3025. sqlId.AndEx("u.userid", r.USERID, r.USERID > 0)
  3026. sqlId.AndEx("t.accountid", r.ACCOUNTID, r.ACCOUNTID > 0)
  3027. // 格式 yyyymmdd
  3028. if len(r.BEGINDATE) > 0 {
  3029. sqlId.JoinFormat(" and t.TRADEDATE >= '%v'", r.BEGINDATE)
  3030. }
  3031. if len(r.ENDDATE) > 0 {
  3032. sqlId.JoinFormat(" and t.TRADEDATE <= '%v'", r.ENDDATE)
  3033. }
  3034. return sqlId.String()
  3035. }
  3036. // GetDataEx 获取交收
  3037. func (r *WrDeliveryDetail) GetDataEx() (interface{}, error) {
  3038. var sqlId string
  3039. // 如果指定了开始日期或结束日期, 刚查历史
  3040. if r.BEGINDATE != "" || r.ENDDATE != "" {
  3041. sqlId = r.buildSqlHis()
  3042. } else {
  3043. sqlId = r.buildSql()
  3044. }
  3045. sData := make([]WrDeliveryDetail, 0)
  3046. err := db.GetEngine().SQL(sqlId).Find(&sData)
  3047. for i := range sData {
  3048. sData[i].calc()
  3049. }
  3050. return sData, err
  3051. }
  3052. // WrBsGoodsInfo 合约交易买卖大厅详情
  3053. type WrBsGoodsInfo struct {
  3054. GOODSID int32 `json:"goodsid" xorm:"GOODSID" form:"goodsid"` // 交易合约ID
  3055. LstItem []WrTypeItem `json:"lstitem"` // 商品信息项
  3056. LstStep []WrGoodsPerformanceStep `json:"lststep"` // 履约规则
  3057. BUYORSELL int32 `json:"buyorsell" form:"buyorsell"` // 买卖方向 0-买 1-卖
  3058. }
  3059. // GetDataEx 获取描述
  3060. func (r *WrBsGoodsInfo) GetDataEx() (interface{}, error) {
  3061. sData := make([]WrBsGoodsInfo, 0)
  3062. // 履约关系
  3063. mRelation := DeliveryRelation{GOODSID: r.GOODSID}
  3064. if d, err := mRelation.GetDataEx(); err == nil {
  3065. if sRelation, ok := d.([]DeliveryRelation); ok {
  3066. val := WrBsGoodsInfo{GOODSID: r.GOODSID,
  3067. LstItem: make([]WrTypeItem, 0),
  3068. LstStep: make([]WrGoodsPerformanceStep, 0)}
  3069. if len(sRelation) > 0 {
  3070. vR := sRelation[0]
  3071. val.LstItem = append(val.LstItem, WrTypeItem{NAME: "品种", VALUE: vR.DELIVERYGOODSNAME})
  3072. val.LstItem = append(val.LstItem, WrTypeItem{NAME: "商品", VALUE: vR.WRSTANDARDNAME})
  3073. mItem := WrStandardFactoryItem{WRSTANDARDID: int64(vR.WRSTANDARDID), WMCATFLAG: 1}
  3074. if d2, err := mItem.GetDataEx(); err == nil {
  3075. if lst, ok := d2.([]WrStandardFactoryItem); ok {
  3076. for i := range lst {
  3077. val.LstItem = append(val.LstItem,
  3078. WrTypeItem{NAME: lst[i].ITEMTYPENAME, VALUE: lst[i].DGFACTORYITEMVALUE})
  3079. }
  3080. }
  3081. }
  3082. // 履约计划模板步骤
  3083. tmpId := IFValue(r.BUYORSELL == 0, vR.BUYTEMPLATEID, vR.SELLTEMPLATEID).(int64)
  3084. mStep := WrGoodsPerformanceStep{TEMPLATEID: tmpId}
  3085. if d3, err := mStep.GetData(); err == nil {
  3086. val.LstStep = d3
  3087. }
  3088. }
  3089. sData = append(sData, val)
  3090. }
  3091. }
  3092. return sData, nil
  3093. }
  3094. // WrTradeOrderDetail 合约交易买卖大厅
  3095. type WrTradeOrderDetail struct {
  3096. ORDERID string `json:"orderid" xorm:"'ORDERID'"` // 委托单号
  3097. GOODSID int32 `json:"goodsid" xorm:"'GOODSID'" form:"goodsid"` // 商品id
  3098. BUYORSELL int32 `json:"buyorsell" xorm:"'BUYORSELL'" form:"buyorsell"` // 买卖方向 0-买 1-卖
  3099. ORDERPRICE SFLOAT64 `json:"orderprice" xorm:"'ORDERPRICE'"` // 委托价格
  3100. ORDERQTY int64 `json:"orderqty" xorm:"'ORDERQTY'"` // 委托数量
  3101. USERID int64 `json:"userid" xorm:"'USERID'"` // 用户id
  3102. USERNAME string `json:"username" xorm:"'USERNAME'"` // 用户名称(已脱敏)
  3103. PageEx `xorm:"extends"`
  3104. }
  3105. func (r *WrTradeOrderDetail) calc() {
  3106. r.USERNAME = EncryptByStar(r.USERNAME)
  3107. }
  3108. func (r *WrTradeOrderDetail) buildSql() string {
  3109. var sqlId utils.SQLVal = "select to_char(t.orderid) orderid," +
  3110. " t.buyorsell," +
  3111. " t.goodsid," +
  3112. " t.orderprice," +
  3113. " t.orderqty - t.tradeqty orderqty," +
  3114. " u.userid," +
  3115. " u.accountname username," +
  3116. " t.orderstatus" +
  3117. " from trade_orderdetail t" +
  3118. " left join taaccount ta" +
  3119. " on t.accountid = ta.accountid" +
  3120. " left join useraccount u" +
  3121. " on ta.relateduserid = u.userid" +
  3122. " where 1 = 1" +
  3123. " and t.orderstatus in(3,7)"
  3124. sqlId.And("t.GOODSID", r.GOODSID)
  3125. sqlId.And("t.BUYORSELL", r.BUYORSELL)
  3126. if r.BUYORSELL == 0 {
  3127. sqlId.Join(" order by t.orderprice desc, t.ordertime desc")
  3128. } else {
  3129. sqlId.Join(" order by t.orderprice, t.ordertime desc")
  3130. }
  3131. sqlId.Page(r.Page, r.PageSize)
  3132. return sqlId.String()
  3133. }
  3134. // GetDataByPage 获取合约交易买卖大厅
  3135. func (r *WrTradeOrderDetail) GetDataByPage() (interface{}, error, int, int, int) {
  3136. sData := make([]WrTradeOrderDetail, 0)
  3137. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  3138. for i := range sData {
  3139. sData[i].calc()
  3140. }
  3141. if len(sData) > 0 {
  3142. r.Total = sData[0].Total
  3143. }
  3144. return sData, err, r.Page, r.PageSize, r.Total
  3145. }
  3146. // WrAverageTradePrice 成交均价(历史走势)
  3147. type WrAverageTradePrice struct {
  3148. TRADEDATE string `json:"tradedate" xorm:"'TRADEDATE'"` // 交易日yyyymm
  3149. TRADEAMOUNT SFLOAT64 `json:"-" xorm:"'TRADEAMOUNT'"` // 总成交额
  3150. TRADEQTY SFLOAT64 `json:"-" xorm:"'TRADEQTY'"` // 总成交量
  3151. AVERAGEPRICE SFLOAT64 `json:"averageprice" xorm:"'AVERAGEPRICE'"` // 成交均价
  3152. PageEx `xorm:"extends"`
  3153. WRFACTORTYPEID int64 `json:"-" form:"wrfactortypeid"` // 仓单要素id
  3154. HASWR int32 `json:"-" form:"haswr"` // 0-仓单预售 1-仓单贸易
  3155. }
  3156. func (r *WrAverageTradePrice) calc() {
  3157. }
  3158. func (r *WrAverageTradePrice) buildSql() string {
  3159. var sqlId utils.SQLVal = "select t.tradedate," +
  3160. " sum(t.tradeamount) tradeamount," +
  3161. " sum(t.tradeqty) tradeqty," +
  3162. " round(sum(t.tradeamount) / sum(t.tradeqty), 2) as averagePrice" +
  3163. " from his_wrtrade_tradedetail t" +
  3164. " where t.wrtradetype in (1, 2)" +
  3165. " and t.haswr = %v" +
  3166. " and t.wrfactortypeid = %v" +
  3167. " group by t.tradedate" +
  3168. " order by t.tradedate desc"
  3169. sqlId.FormatParam(r.HASWR, r.WRFACTORTYPEID)
  3170. sqlId.Page(r.Page, r.PageSize)
  3171. return sqlId.String()
  3172. }
  3173. // GetDataByPage 获取成交均价(历史走势)
  3174. func (r *WrAverageTradePrice) GetDataByPage() (interface{}, error, int, int, int) {
  3175. sData := make([]WrAverageTradePrice, 0)
  3176. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  3177. for i := range sData {
  3178. sData[i].calc()
  3179. }
  3180. // 进行反序, sql是日期倒序查的, 反序后变为日期从小到大
  3181. if nLen := len(sData); nLen >= 2 {
  3182. i, j := 0, nLen-1
  3183. for i < j {
  3184. sData[i], sData[j] = sData[j], sData[i]
  3185. i++
  3186. j--
  3187. }
  3188. }
  3189. if len(sData) > 0 {
  3190. r.Total = sData[0].Total
  3191. }
  3192. return sData, err, r.Page, r.PageSize, r.Total
  3193. }
  3194. // WrQuoteOrderMyq 贸易圈大厅
  3195. type WrQuoteOrderMyq struct {
  3196. WRTRADEORDERID string `json:"wrtradeorderid" xorm:"WRTRADEORDERID"` // 仓单贸易委托单ID(320+Unix秒时间戳(10位)+xxxxxx)
  3197. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL" form:"buyorsell"` // 买卖 - 0:买 1:卖
  3198. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 购买方(销售方)用户ID
  3199. QTY float64 `json:"orderqty" xorm:"qty"` // 买(卖)量(=委托量-成交量)
  3200. PRICE float64 `json:"fixedprice" xorm:"price"` // 买(卖)价
  3201. PRICEMOVE float64 `json:"pricemove" xorm:"PRICEMOVE"` // 买(卖)升贴水- 基差
  3202. USERNAME string `json:"username" xorm:"'USERNAME'"` // 购买方(销售方)
  3203. ENUMDICNAME string `json:"enumdicname" xorm:"'enumdicname'"` // 单位名称
  3204. MINIVALUE int32 `json:"minivalue" xorm:"'MINIVALUE'"` // 现货商品最小变动值
  3205. DELIVERYMONTH string `json:"deliverymonth" xorm:"'DELIVERYMONTH'" form:"deliverymonth"` // 交收月
  3206. ORDERTIME string `json:"ordertime" xorm:"'ORDERTIME'"` // 委托时间
  3207. DELISTMINQTY SFLOAT64 `json:"delistminqty" xorm:"'DELISTMINQTY'"` // 起摘数量
  3208. CANBARGAIN int32 `json:"canbargain" xorm:"'CANBARGAIN'"` // 是否可议价 - 0:不可 1:可
  3209. CANPART int32 `json:"canpart" xorm:"'CANPART'"` // 是否允许部份摘牌 - 0:不允许 1:允许
  3210. MARGINFLAG int32 `json:"marginflag" xorm:"'MARGINFLAG'"` // 挂牌是否指定保证金 - 0:未指定 1:指定
  3211. MARGINVALUE float64 `json:"marginvalue" xorm:"'MARGINVALUE'"` // 保证金设置值
  3212. VALIDTYPE int32 `json:"validtype" xorm:"'VALIDTYPE'"` // 有效类型 - 1当日有效 2本周有效 3指定日期有效 4一直有效
  3213. VALIDTIME string `json:"validtime" xorm:"'VALIDTIME'"` // 有效期限
  3214. PERFORMANCETEMPLATEID int64 `json:"performancetemplateid" xorm:"'PERFORMANCETEMPLATEID'"` // 履约模板id
  3215. GOODSCODE string `json:"goodscode" xorm:"'GOODSCODE'"` // 商品合约代码
  3216. TEMPLATENAME string `json:"templatename" xorm:"'TEMPLATENAME'"` // 履约模板名称
  3217. WAREHOUSENAME string `json:"warehousename" xorm:"'WAREHOUSENAME'"` // 仓库名称
  3218. WRTYPENAME string `json:"wrtypename" xorm:"'WRTYPENAME'"` // 商品
  3219. WRSTANDARDID int64 `json:"wrstandardid" xorm:"WRSTANDARDID" form:"wrstandardid"` // 现货商品ID
  3220. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID" form:"deliverygoodsid"` // 品种ID
  3221. WRFACTORTYPEID string `json:"wrfactortypeid" xorm:"'WRFACTORTYPEID'"` // 仓单要素id
  3222. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 商品名称
  3223. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"WRSTANDARDCODE" form:"wrstandardcode"` // 现货商品代码
  3224. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 品种代码
  3225. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 品种名称
  3226. PageEx `xorm:"extends"`
  3227. HasWr int32 `json:"-" form:"haswr"` // 是否有仓单 0-没有 1-有
  3228. WrPriceType int32 `json:"-" form:"wrpricetype"` // 价格方式 - 1:固定价 2-浮动价 - [挂牌]
  3229. MarketId int32 `json:"-" form:"marketid"` // 市场id
  3230. GOODSID int32 `json:"-" form:"goodsid"` // 商品id
  3231. DGITEMNAME string `json:"-" form:"dgitemname"` // 筛选项
  3232. }
  3233. func (r *WrQuoteOrderMyq) calc() {
  3234. r.WRTYPENAME = strings.ReplaceAll(r.WRTYPENAME, ",", "-")
  3235. r.USERNAME = EncryptByStar(r.USERNAME)
  3236. }
  3237. func (r *WrQuoteOrderMyq) buildSql() string {
  3238. var sqlId utils.SQLVal = `
  3239. select to_char(t.wrtradeorderid) wrtradeorderid,
  3240. to_char(t.wrfactortypeid) wrfactortypeid,
  3241. t.userid,
  3242. t.orderqty - t.tradeqty as qty,
  3243. t.fixedprice as price,
  3244. t.pricemove,
  3245. t.wrpricetype,
  3246. t.buyorsell,
  3247. t.deliverymonth,
  3248. t.delistminqty,
  3249. t.haswr,
  3250. t.canbargain,
  3251. t.canpart,
  3252. t.marginflag,
  3253. t.marginvalue,
  3254. t.validtype,
  3255. to_char(t.validtime, 'yyyy-mm-dd hh24:mi:ss') validtime,
  3256. t.performancetemplateid,
  3257. to_char(t.ordertime, 'yyyy-mm-dd hh24:mi:ss') ordertime,
  3258. u.accountname as username,
  3259. c.goodsid,
  3260. c.goodscode,
  3261. wd.minivalue,
  3262. wd.wrstandardname,
  3263. wd.wrstandardcode,
  3264. g.deliverygoodscode,
  3265. g.deliverygoodsname,
  3266. e.enumdicname,
  3267. wd.wrstandardname || w.wrfactortypename2 WRTYPENAME,
  3268. w.wrstandardid,
  3269. w.deliverygoodsid,
  3270. s.templatename,
  3271. h.warehousename
  3272. from WRTRADE_ORDERDETAIL t
  3273. left join WRTRADE_GOODSCONFIG c
  3274. on t.wrtradeorderid = c.wrtradeorderid
  3275. left join Useraccount u
  3276. on t.userid = u.userid
  3277. left join wrfactortype w
  3278. on t.wrfactortypeid = w.wrfactortypeid
  3279. left join wrstandard wd
  3280. on w.wrstandardid = wd.wrstandardid
  3281. left join performanceplantemplate s
  3282. on t.performancetemplateid = s.autoid
  3283. left join warehouseinfo h
  3284. on w.warehouseid = h.autoid
  3285. left join deliverygoods g on w.deliverygoodsid=g.deliverygoodsid
  3286. left join enumdicitem e
  3287. on wd.unitid = e.enumitemname
  3288. and e.enumdiccode = 'goodsunit'
  3289. where 1 = 1
  3290. and t.wrtradetype = 1
  3291. and t.isspecified=1
  3292. and t.wrtradeorderstatus in (3, 7)
  3293. and (t.userid=%v or
  3294. (t.allfriendsflag=1 and t.userid in(select userid from userfriend where frienduserid=%v))
  3295. or (t.allfriendsflag=0 and %v in(select k.matchuserid from wrtrade_matchdetail k where k.wrtradeorderid=t.wrtradeorderid))
  3296. )
  3297. `
  3298. sqlId.FormatParam(r.USERID, r.USERID, r.USERID)
  3299. sqlId.AndEx("t.haswr", r.HasWr, r.HasWr >= 0)
  3300. r.WrPriceType = 1 // 查固定价
  3301. sqlId.And("t.wrpricetype", r.WrPriceType)
  3302. sqlId.AndEx("t.wrfactortypeid", r.WRFACTORTYPEID, r.WRFACTORTYPEID != "")
  3303. sqlId.AndEx("c.goodsid", r.GOODSID, r.GOODSID > 0)
  3304. sqlId.And("t.buyorsell", r.BUYORSELL)
  3305. sqlId.AndEx("t.marketid", r.MarketId, r.MarketId > 0)
  3306. sqlId.AndEx("t.deliverymonth", r.DELIVERYMONTH, len(r.DELIVERYMONTH) > 0)
  3307. sqlId.AndEx("w.wrstandardid", r.WRSTANDARDID, r.WRSTANDARDID > 0)
  3308. sqlId.AndEx("w.deliverygoodsid", r.DELIVERYGOODSID, r.DELIVERYGOODSID > 0)
  3309. if d, ok := FtItemName(r.DGITEMNAME); ok {
  3310. sqlId.AndLikes("w.wrfactortypename", d...)
  3311. }
  3312. if r.BUYORSELL == 0 {
  3313. if r.WrPriceType == 1 {
  3314. sqlId.Join(" order by t.fixedprice desc, t.ordertime")
  3315. } else {
  3316. sqlId.Join(" order by t.pricemove desc, t.ordertime")
  3317. }
  3318. } else {
  3319. if r.WrPriceType == 1 {
  3320. sqlId.Join(" order by t.fixedprice asc, t.ordertime")
  3321. } else {
  3322. sqlId.Join(" order by t.pricemove asc, t.ordertime")
  3323. }
  3324. }
  3325. sqlId.Page(r.Page, r.PageSize)
  3326. return sqlId.String()
  3327. }
  3328. // GetDataByPage 获取贸易圈大厅
  3329. func (r *WrQuoteOrderMyq) GetDataByPage() (interface{}, error, int, int, int) {
  3330. sData := make([]WrQuoteOrderMyq, 0)
  3331. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  3332. total := 0
  3333. for i := range sData {
  3334. sData[i].calc()
  3335. total = sData[i].Total
  3336. }
  3337. return sData, err, r.Page, r.PageSize, total
  3338. }
  3339. // WrDeliveryAvalidHoldLB 合约交收可点选仓单
  3340. type WrDeliveryAvalidHoldLB struct {
  3341. ACCOUNTID int64 `json:"accountid" xorm:"'ACCOUNTID'" form:"accountid"` // 资金账号
  3342. GOODSID int32 `json:"goodsid" xorm:"'GOODSID'" form:"goodsid"` // x合约商品id
  3343. WRSTANDARDID int32 `json:"wrstandardid" xorm:"'WRSTANDARDID'"` // 品类d
  3344. UQTY float64 `json:"-" xorm:"'UQTY'"` // 用户持有数量
  3345. QTY float64 `json:"-" xorm:"'QTY'"` // 用户仓单数量
  3346. WRFACTORTYPEID string `json:"wrfactortypeid" xorm:"'WRFACTORTYPEID'"` // 仓单要素id
  3347. LADINGBILLID string `json:"ladingbillid" xorm:"'LADINGBILLID'"` // 提单id
  3348. SUBNUM int64 `json:"subnum" xorm:"'SUBNUM'"` // 提单子id
  3349. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 品种id
  3350. USERID int64 `json:"userid" xorm:"'USERID'"` // 用户id
  3351. WRFACTORTYPENAME2 string `json:"-" xorm:"'WRFACTORTYPENAME2'"` // 仓单要素名称(不含仓库)
  3352. WAREHOUSEID int32 `json:"warehouseid" xorm:"'WAREHOUSEID'"` // 仓库id
  3353. AVALIDQTY float64 `json:"avalidqty" xorm:"'AVALIDQTY'"` // 数量(可点选数量)
  3354. WRSTANDARDNAME string `json:"wrstandardname" xorm:"'WRSTANDARDNAME'"` // 品类名称
  3355. WRSTANDARDCODE string `json:"wrstandardcode" xorm:"'WRSTANDARDCODE'"` // 品代码
  3356. WAREHOUSECODE string `json:"warehousecode" xorm:"'WAREHOUSECODE'"` // 仓库代码
  3357. WAREHOUSENAME string `json:"warehousename" xorm:"'WAREHOUSENAME'"` // 仓库名称
  3358. XGOODSCODE string `json:"xgoodscode" xorm:"'XGOODSCODE'"` // x合约代码
  3359. XGOODSNAME string `json:"xgoodsname" xorm:"'XGOODSNAME'"` // x合约名称
  3360. PGOODSID int32 `json:"pgoodsid" xorm:"'PGOODSID'"` // p商品id(点价合约)
  3361. PGOODSCODE string `json:"pgoodscode" xorm:"'PGOODSCODE'"` // p商品代码(点价合约)
  3362. PGOODSNAME string `json:"pgoodsname" xorm:"'PGOODSNAME'"` // p商品名称(点价合约)
  3363. USERNAME string `json:"username" xorm:"'USERNAME'"` // 仓单持有人
  3364. PRICEMOVE float64 `json:"pricemove" xorm:"'PRICEMOVE'"` // 升贴水
  3365. WRTYPENAME string `json:"wrtypename"` // 商品
  3366. UNITID int32 `json:"-" xorm:"'UNITID'"` // 品类单位id
  3367. ENUMDICNAME string `json:"enumdicname"` // 单位名称
  3368. }
  3369. func (r *WrDeliveryAvalidHoldLB) calc() {
  3370. r.USERNAME = EncryptByStar(r.USERNAME)
  3371. if r.WRTYPENAME == "" {
  3372. if len(r.WRFACTORTYPENAME2) > 0 {
  3373. r.WRTYPENAME = r.WRSTANDARDNAME + r.WRFACTORTYPENAME2
  3374. } else {
  3375. r.WRTYPENAME = r.WRSTANDARDNAME
  3376. }
  3377. }
  3378. r.WRTYPENAME = strings.ReplaceAll(r.WRTYPENAME, ",", "-")
  3379. r.ENUMDICNAME = mtpcache.GetEnumDicitemName(r.UNITID)
  3380. }
  3381. func (r *WrDeliveryAvalidHoldLB) buildSql() string {
  3382. var sqlId utils.SQLVal = `
  3383. with tmp as
  3384. (select k.wrfactortypeid, k.goodsid, sum(k.pricemove) pricemove
  3385. from (select to_char(t.wrfactortypeid) wrfactortypeid,
  3386. b.dgfactoryitemtypeid,
  3387. b.itemtypename,
  3388. c.dgfactoryitemvalue,
  3389. t.optioncompare,
  3390. t.warehouseid,
  3391. t.wrstandardid,
  3392. c.dgfactoryitemid,
  3393. t.wrfactortypename,
  3394. t.wrfactortypename2,
  3395. r.goodsid,
  3396. nvl(r.premiumvalue, 0) pricemove
  3397. from wrfactortype t
  3398. inner join wrfactortypeitem a
  3399. on t.wrfactortypeid = a.wrfactortypeid
  3400. inner join dgfactoryitemtype b
  3401. on t.deliverygoodsid = b.deliverygoodsid
  3402. and a.dgfactoryitemtypeid = b.dgfactoryitemtypeid
  3403. left join dgfactoryitem c
  3404. on a.dgfactoryitemid = c.dgfactoryitemid
  3405. and b.deliverygoodsid = c.deliverygoodsid
  3406. left join deliveryrelationdetail r
  3407. on c.dgfactoryitemid = r.dgfactoryitemid
  3408. and b.dgfactoryitemtypeid = r.dgfactoryitemtypeid
  3409. where 1 = 1) k
  3410. group by k.wrfactortypeid, k.goodsid)
  3411. select a.*,
  3412. case
  3413. when a.uqty * g1.agreeunit * r.mindeliveryqty * (r.rratio2/nvl(r.rratio1,1)) < a.qty then
  3414. a.uqty * g1.agreeunit * r.mindeliveryqty * (r.rratio2/nvl(r.rratio1,1))
  3415. else
  3416. a.qty
  3417. end as avalidqty,
  3418. wd.wrstandardname,
  3419. wd.wrstandardcode,
  3420. wd.unitid,
  3421. h.warehousecode,
  3422. h.warehousename,
  3423. g1.goodscode xgoodscode,
  3424. g1.goodsname xgoodsname,
  3425. r.pgoodsid,
  3426. g2.goodscode pgoodscode,
  3427. g2.goodsname pgoodsname,
  3428. u.accountname username,
  3429. tmp.pricemove
  3430. from (select t.accountid,
  3431. t.goodsid,
  3432. t.wrstandardid,
  3433. t.inqty - t.cancelqty - t.deliveryqty - p.buycurpositionqty as uqty,
  3434. hl.qty - hl.freezerqty qty,
  3435. to_char(hl.wrfactortypeid) wrfactortypeid,
  3436. to_char(hl.ladingbillid) ladingbillid,
  3437. hl.subnum,
  3438. hl.deliverygoodsid,
  3439. hl.userid,
  3440. w.wrfactortypename2,
  3441. w.warehouseid
  3442. from cptrade_usergoodsdata t
  3443. inner join wrholdlb hl
  3444. on t.accountid = hl.accountid
  3445. inner join wrfactortype w
  3446. on t.wrstandardid = w.wrstandardid
  3447. and hl.wrfactortypeid = w.wrfactortypeid
  3448. left join tradeposition p on t.accountid=p.accountid and t.goodsid=p.goodsid
  3449. ) a
  3450. left join wrstandard wd
  3451. on a.wrstandardid = wd.wrstandardid
  3452. left join warehouseinfo h
  3453. on a.warehouseid = h.autoid
  3454. inner join deliveryrelation r
  3455. on a.goodsid = r.goodsid
  3456. and a.wrstandardid = r.wrstandardid
  3457. left join goods g1
  3458. on a.goodsid = g1.goodsid
  3459. left join goods g2
  3460. on r.pgoodsid = g2.goodsid
  3461. left join useraccount u
  3462. on a.userid = u.userid
  3463. left join tmp
  3464. on a.wrfactortypeid = tmp.wrfactortypeid
  3465. and a.goodsid = tmp.goodsid
  3466. where a.uqty > 0
  3467. and a.qty > 0
  3468. `
  3469. // 过滤掉自己的仓单 and a.accountid !=
  3470. sqlId.Join(fmt.Sprintf(" and a.accountid != %v", r.ACCOUNTID))
  3471. sqlId.And("a.goodsid", r.GOODSID)
  3472. return sqlId.String()
  3473. }
  3474. // GetDataEx 获取合约交收可点选仓单
  3475. func (r *WrDeliveryAvalidHoldLB) GetDataEx() (interface{}, error) {
  3476. sData := make([]WrDeliveryAvalidHoldLB, 0)
  3477. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  3478. for i := range sData {
  3479. sData[i].calc()
  3480. }
  3481. return sData, err
  3482. }
  3483. // WrUserFriend 我的朋友
  3484. type WrUserFriend struct {
  3485. USERID int64 `json:"userid" xorm:"'USERID'" form:"userid"` // 用户id
  3486. FRIENDUSERID int64 `json:"frienduserid" xorm:"'FRIENDUSERID'"` // 朋友id
  3487. FRIENDNAME string `json:"friendname" xorm:"'FRIENDNAME'"` // 朋友名称(已脱敏)
  3488. ISFRIEND int32 `json:"isfriend" xorm:"'ISFRIEND'"` // 是否好友 0-不是 1-是
  3489. NEWUSERID int64 `json:"-" form:"newuserid"` // 新朋友id
  3490. }
  3491. func (r *WrUserFriend) calc() {
  3492. r.FRIENDNAME = EncryptByStar(r.FRIENDNAME)
  3493. }
  3494. func (r *WrUserFriend) buildSql() string {
  3495. var sqlId utils.SQLVal
  3496. if r.NEWUSERID > 0 {
  3497. sqlId =
  3498. "select t.userid frienduserid, t.accountname friendname, nvl(f.userid-f.userid+1,0) isfriend" +
  3499. " from useraccount t" +
  3500. " left join userfriend f on t.userid=f.frienduserid and f.userid=%v" +
  3501. " where 1 = 1" +
  3502. " and t.userid = %v"
  3503. sqlId.FormatParam(r.USERID, r.NEWUSERID)
  3504. } else {
  3505. sqlId = "select t.userid, t.frienduserid, u.accountname friendname, 1 as isfriend" +
  3506. " from UserFriend t" +
  3507. " left join useraccount u" +
  3508. " on t.frienduserid = u.userid" +
  3509. " where 1 = 1"
  3510. sqlId.And("t.userid", r.USERID)
  3511. }
  3512. return sqlId.String()
  3513. }
  3514. // GetDataEx 获取我的朋友
  3515. func (r *WrUserFriend) GetDataEx() (interface{}, error) {
  3516. sData := make([]WrUserFriend, 0)
  3517. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  3518. for i := range sData {
  3519. sData[i].calc()
  3520. }
  3521. return sData, err
  3522. }
  3523. // WrFriendApply 好友申请
  3524. type WrFriendApply struct {
  3525. FRIENDAPPLYID string `json:"friendapplyid" xorm:"FRIENDAPPLYID" form:"friendapplyid"` // 申请ID(SEQ_FRIENDAPPLY)
  3526. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 申请人用户ID
  3527. FRIENDUSERID string `json:"frienduserid" xorm:"FRIENDUSERID" form:"frienduserid"` // 好友用户ID
  3528. APPLYSRC int32 `json:"applysrc" xorm:"APPLYSRC"` // 申请来源 - 1:管理端 2:终端
  3529. APPLICANTID int64 `json:"applicantid" xorm:"APPLICANTID" form:"applicantid"` // 申请人
  3530. REMARK string `json:"remark" xorm:"REMARK"` // 备注
  3531. APPLYTIME string `json:"applytime" xorm:"APPLYTIME"` // 申请时间
  3532. APPLYSTATUS int32 `json:"applystatus" xorm:"APPLYSTATUS"` // 申请状态 - 1:待审核 2:审核通过 3:审核拒绝 4:处理失败 5:已撤回
  3533. AUDITORID int64 `json:"auditorid" xorm:"AUDITORID" form:"auditorid"` // 审核人
  3534. AUDITSRC int32 `json:"auditsrc" xorm:"AUDITSRC"` // 审核来源 - 1:管理端 2:终端
  3535. AUDITTIME string `json:"audittime" xorm:"AUDITTIME"` // 审核时间
  3536. AUDITREMARK string `json:"auditremark" xorm:"AUDITREMARK"` // 审核备注
  3537. FRIENDNAME string `json:"friendname" xorm:"'FRIENDNAME'"` // 好友名字(已脱敏)
  3538. APPLYNAME string `json:"applyname" xorm:"'APPLYNAME'"` // 申请人名称
  3539. AUDITNAME string `json:"auditname" xorm:"'AUDITNAME'"` // 审核人名称
  3540. }
  3541. func (r *WrFriendApply) calc() {
  3542. r.FRIENDNAME = EncryptByStar(r.FRIENDNAME)
  3543. }
  3544. func (r *WrFriendApply) buildSql() string {
  3545. var sqlId utils.SQLVal = "with tmp as" +
  3546. " (select 2 as src," +
  3547. " loginid as usid," +
  3548. " nvl(to_char(accountname), to_char(logincode)) username" +
  3549. " from loginaccount" +
  3550. " union all" +
  3551. " select 1 as src, autoid as usid, rolename" +
  3552. " from systemmanagerrole)" +
  3553. "select t.friendapplyid," +
  3554. " t.userid," +
  3555. " t.frienduserid," +
  3556. " t.applysrc," +
  3557. " t.applicantid," +
  3558. " t.remark," +
  3559. " to_char(t.applytime, 'yyyy-mm-dd hh24:mi:ss') applytime," +
  3560. " t.applystatus," +
  3561. " t.auditorid," +
  3562. " t.auditsrc," +
  3563. " to_char(t.audittime, 'yyyy-mm-dd hh24:mi:ss') audittime," +
  3564. " t.auditremark," +
  3565. " u.accountname friendname," +
  3566. " k1.username as applyname," +
  3567. " k2.username as auditname" +
  3568. " from FriendApply t" +
  3569. " left join useraccount u" +
  3570. " on t.frienduserid = u.userid" +
  3571. " left join tmp k1" +
  3572. " on t.applicantid = k1.usid" +
  3573. " and t.applysrc = k1.src" +
  3574. " left join tmp k2" +
  3575. " on t.auditorid = k2.usid" +
  3576. " and t.auditsrc = k2.src" +
  3577. " where 1=1"
  3578. sqlId.And("t.userid", r.USERID)
  3579. return sqlId.String()
  3580. }
  3581. // GetDataEx 获取好友申请
  3582. func (r *WrFriendApply) GetDataEx() (interface{}, error) {
  3583. sData := make([]WrFriendApply, 0)
  3584. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  3585. for i := range sData {
  3586. sData[i].calc()
  3587. }
  3588. return sData, err
  3589. }
  3590. // WrPerformanceTemplate 履约模板
  3591. type WrPerformanceTemplate struct {
  3592. AUTOID int64 `json:"autoid" xorm:"AUTOID" form:"autoid"` // AutoID 模板id
  3593. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 所属用户
  3594. TEMPLATENAME string `json:"templatename" xorm:"TEMPLATENAME"` // 模板名称
  3595. PAYMENTTYPE int32 `json:"paymenttype" xorm:"PAYMENTTYPE"` // 支付方式 - 1:冻结 2:扣款
  3596. CREATETIME string `json:"createtime" xorm:"CREATETIME"` // 创建时间
  3597. CREATORID int64 `json:"creatorid" xorm:"CREATORID" form:"creatorid"` // 创建人
  3598. TEMPLATETYPE int32 `json:"templatetype" xorm:"TEMPLATETYPE"` // 模板类型 - 0:通用 1:交割 2:仓单贸易 3:预售集采 7:竞拍-竞价式 8:竞拍-大宗式 9:荷兰式--失效枚举:4:竞拍-降价式 (无仓单) 5:挂牌期权 6:竞拍-降价式
  3599. TAKEMODE int32 `json:"takemode" xorm:"TAKEMODE"` // 提货方式 - 1:无 2:买方自提 3:卖方发货
  3600. FTTMPTYPE string `json:"-" form:"tmptype"` // 模板类型筛选
  3601. INCLUDEPUB int32 `json:"-" form:"includepub"` // 是否包含公共模板
  3602. MARKETID int32 `json:"-" form:"marketid"` // 市场ID-从市场配置表中指定的模板id查
  3603. }
  3604. func (r *WrPerformanceTemplate) calc() {
  3605. }
  3606. func (r *WrPerformanceTemplate) buildSql() string {
  3607. var sqlId utils.SQLVal = "SELECT t.USERID," +
  3608. " t.AUTOID," +
  3609. " t.TEMPLATENAME," +
  3610. " t.PAYMENTTYPE," +
  3611. " to_char(t.CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME," +
  3612. " t.CREATORID," +
  3613. " t.TEMPLATETYPE," +
  3614. " t.TAKEMODE" +
  3615. " FROM PERFORMANCEPLANTEMPLATE t" +
  3616. " WHERE 1 = 1"
  3617. if r.USERID > 0 {
  3618. if r.INCLUDEPUB == 1 {
  3619. // t.userid is null 意思是查公共模板
  3620. sqlId.JoinFormat(" and (t.userid is null or t.userid = %v)", r.USERID)
  3621. } else {
  3622. sqlId.And("t.userid", r.USERID)
  3623. }
  3624. }
  3625. sqlId.AndEx("t.autoid", r.AUTOID, r.AUTOID > 0)
  3626. if r.FTTMPTYPE != "" {
  3627. sqlId.JoinFormat(" and t.TEMPLATETYPE in(%v)", r.FTTMPTYPE)
  3628. }
  3629. if r.MARKETID > 0 {
  3630. // 指定了市场, 从市场交易配置表中取履约模板id
  3631. m := WrMarketTradeConfig{MARKETID: r.MARKETID}
  3632. if d, err := m.GetDataEx(); err == nil {
  3633. if v, ok := d.([]WrMarketTradeConfig); ok {
  3634. a := v[0]
  3635. var inStr string
  3636. // 有仓单用 PERFORMANCETEMPIDS, 无仓单用PERFORMANCETEMPID2S,
  3637. // 这2个只会有一个有值, 所以只需取其中一个有值的即可
  3638. if len(a.PERFORMANCETEMPIDS) > 0 {
  3639. inStr = a.PERFORMANCETEMPIDS
  3640. } else if len(a.PERFORMANCETEMPID2S) > 0 {
  3641. inStr = a.PERFORMANCETEMPID2S
  3642. }
  3643. if len(v) > 0 {
  3644. sqlId.JoinFormat(" and t.autoid in(%v)", inStr)
  3645. }
  3646. }
  3647. }
  3648. }
  3649. sqlId.Join(" order by t.AUTOID")
  3650. return sqlId.String()
  3651. }
  3652. // GetDataEx 获取履约模板
  3653. func (r *WrPerformanceTemplate) GetDataEx() (interface{}, error) {
  3654. sData := make([]WrPerformanceTemplate, 0)
  3655. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  3656. for i := range sData {
  3657. sData[i].calc()
  3658. }
  3659. return sData, err
  3660. }
  3661. // WrPerformanceTemplateEx 履约模板(含步骤信息)
  3662. type WrPerformanceTemplateEx struct {
  3663. WrPerformanceTemplate `form:"extends"`
  3664. LstStep []WrGoodsPerformanceStep // 步骤信息列表
  3665. }
  3666. func (r *WrPerformanceTemplateEx) addStep(lst []WrGoodsPerformanceStep) {
  3667. for i := range lst {
  3668. if lst[i].TEMPLATEID == r.AUTOID {
  3669. r.LstStep = append(r.LstStep, lst[i])
  3670. }
  3671. }
  3672. }
  3673. func (r *WrPerformanceTemplateEx) GetDataEx() (interface{}, error) {
  3674. sData := make([]WrPerformanceTemplateEx, 0)
  3675. if d, err := r.WrPerformanceTemplate.GetDataEx(); err == nil {
  3676. if sTmplate, ok := d.([]WrPerformanceTemplate); ok {
  3677. if len(sTmplate) > 0 {
  3678. // 查履约步骤
  3679. ms := WrGoodsPerformanceStep{}
  3680. if d2, err := ms.GetData(); err == nil {
  3681. for i := range sTmplate {
  3682. val := WrPerformanceTemplateEx{}
  3683. val.WrPerformanceTemplate = sTmplate[i]
  3684. val.LstStep = make([]WrGoodsPerformanceStep, 0)
  3685. val.addStep(d2)
  3686. sData = append(sData, val)
  3687. }
  3688. }
  3689. }
  3690. }
  3691. }
  3692. return sData, nil
  3693. }
  3694. // WRTradeBargainApply 议价单
  3695. type WRTradeBargainApply struct {
  3696. WRBARGAINID string `json:"wrbargainid" xorm:"WRBARGAINID" form:"wrbargainid"` // 议价申请单ID(327+Unix秒时间戳(10位)+xxxxxx)
  3697. WRTRADEORDERID string `json:"wrtradeorderid" xorm:"WRTRADEORDERID" form:"wrtradeorderid"` // 关联委托单ID
  3698. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE" form:"tradedate"` // 交易日(yyyyMMdd)
  3699. MARKETID int64 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID
  3700. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 摘牌人用户ID(议价人ID)
  3701. ACCOUNTID int64 `json:"accountid" xorm:"ACCOUNTID" form:"accountid"` // 摘牌资金账号
  3702. BUYORSELL int32 `json:"buyorsell" xorm:"BUYORSELL"` // 买卖(挂牌类型) - 0:买 1:卖
  3703. APPLYQTY float64 `json:"applyqty" xorm:"APPLYQTY"` // 摘牌数量(议价数量)
  3704. APPLYPRICE string `json:"applyprice" xorm:"APPLYPRICE"` // 申请价格(议价价格)
  3705. APPLYSTATUS int32 `json:"applystatus" xorm:"APPLYSTATUS"` // 申请状态(议价状态) - 1:待确认 2:已确认 3:已拒绝 4:已撤销 5:系统撤销 6:处理失败 7:确认中
  3706. HANDLESTATUS int32 `json:"handlestatus" xorm:"HANDLESTATUS"` // 处理状态
  3707. APPLYTIME string `json:"applytime" xorm:"APPLYTIME"` // 申请时间(议价时间)
  3708. APPLYREMARK string `json:"applyremark" xorm:"APPLYREMARK"` // 申请备注
  3709. CONFIRMUSERID int64 `json:"confirmuserid" xorm:"CONFIRMUSERID" form:"confirmuserid"` // 确认人
  3710. CONFIRMTIME string `json:"confirmtime" xorm:"CONFIRMTIME"` // 确认时间
  3711. CONFIRMREMARK string `json:"confirmremark" xorm:"CONFIRMREMARK"` // 确认备注
  3712. REFPRICE string `json:"refprice" xorm:"REFPRICE"` // 参考价格
  3713. RETCODE int32 `json:"retcode" xorm:"RETCODE"` // 委托返回代码
  3714. USERNAME string `json:"username" xorm:"'USERNAME'"` // 议价人名字(已脱敏)
  3715. MATCHUSERID int64 `json:"matchuserid" xorm:"'MATCHUSERID'" form:"matchuserid"` // 挂牌方用户id
  3716. MATCHACCOUNTID int64 `json:"matchaccountid" xorm:"'MATCHACCOUNTID'"` // 挂牌方资金账号
  3717. MATCHUSERNAME string `json:"matchusername" xorm:"'MATCHUSERNAME'"` // 挂牌方用户名称(已脱敏)
  3718. ORDERQTY int64 `json:"orderqty" xorm:"'ORDERQTY'"` // 挂牌数量
  3719. FIXEDPRICE SFLOAT64 `json:"fixedprice" xorm:"'FIXEDPRICE'"` // 挂牌价格
  3720. DELIVERYMONTH string `json:"deliverymonth" xorm:"'DELIVERYMONTH'"` // 交收月
  3721. MARGINVALUE SFLOAT64 `json:"marginvalue" xorm:"'MARGINVALUE'"` // 履约保证金比例
  3722. VALIDTIME string `json:"validtime" xorm:"'VALIDTIME'"` // 有效期限
  3723. TEMPLATENAME string `json:"templatename" xorm:"'TEMPLATENAME'"` // 履约方式(履约模板名称)
  3724. Wr2FactorType `xorm:"extends"`
  3725. HASWR int32 `json:"-" form:"haswr"` // 0-仓单预售 1-仓单贸易
  3726. BEGINDATE string `json:"begindate" form:"begindate"` // 开始交易日(yyyymmdd)
  3727. ENDDATE string `json:"enddate" form:"enddate"` // 结束交易日(yyyymmdd)
  3728. }
  3729. func (r *WRTradeBargainApply) calc() {
  3730. r.USERNAME = EncryptByStar(r.USERNAME)
  3731. r.MATCHUSERNAME = EncryptByStar(r.MATCHUSERNAME)
  3732. }
  3733. func (r *WRTradeBargainApply) buildSql() string {
  3734. var sqlId utils.SQLVal = `
  3735. with tmp as
  3736. (select to_char(t.wrfactortypeid) wrfactortypeid,
  3737. t.wrfactortypename2 wrfactortypename,
  3738. t.wrstandardid,
  3739. t.deliverygoodsid,
  3740. g.deliverygoodscode,
  3741. g.deliverygoodsname,
  3742. w.wrstandardcode,
  3743. w.wrstandardname,
  3744. h.warehousecode,
  3745. h.warehousename,
  3746. e.enumdicname,
  3747. w.wrstandardname || t.wrfactortypename2 as wrtypename
  3748. from wrfactortype t
  3749. left join deliverygoods g
  3750. on t.deliverygoodsid = g.deliverygoodsid
  3751. left join wrstandard w
  3752. on t.wrstandardid = w.wrstandardid
  3753. left join warehouseinfo h
  3754. on t.warehouseid = h.autoid
  3755. left join enumdicitem e
  3756. on w.unitid = e.enumitemname
  3757. and e.enumdiccode = 'goodsunit')
  3758. SELECT to_char(t.WRBARGAINID) WRBARGAINID,
  3759. to_char(t.WRTRADEORDERID) WRTRADEORDERID,
  3760. t.TRADEDATE,
  3761. t.MARKETID,
  3762. t.USERID,
  3763. t.ACCOUNTID,
  3764. t.BUYORSELL,
  3765. t.APPLYQTY,
  3766. t.APPLYPRICE,
  3767. t.APPLYSTATUS,
  3768. t.HANDLESTATUS,
  3769. to_char(t.APPLYTIME, 'yyyy-mm-dd hh24:mi:ss') APPLYTIME,
  3770. t.APPLYREMARK,
  3771. t.CONFIRMUSERID,
  3772. to_char(t.CONFIRMTIME, 'yyyy-mm-dd hh24:mi:ss') CONFIRMTIME,
  3773. t.CONFIRMREMARK,
  3774. t.REFPRICE,
  3775. t.RETCODE,
  3776. t.matchuserid,
  3777. t.matchaccountid,
  3778. u.accountname USERNAME,
  3779. u2.accountname matchusername,
  3780. o.orderqty,
  3781. o.fixedprice,
  3782. o.deliverymonth,
  3783. o.marginvalue,
  3784. to_char(o.validtime, 'yyyy-mm-dd hh24:mi:ss') validtime,
  3785. p.templatename,
  3786. tmp.*
  3787. FROM WRTRADE_BARGAINAPPLY t
  3788. LEFT JOIN USERACCOUNT u on t.userid=u.userid
  3789. LEFT JOIN USERACCOUNT u2 on t.matchuserid=u2.userid
  3790. LEFT JOIN WRTRADE_ORDERDETAIL o on t.wrtradeorderid=o.wrtradeorderid
  3791. LEFT JOIN tmp on o.wrfactortypeid=tmp.wrfactortypeid
  3792. LEFT JOIN PERFORMANCEPLANTEMPLATE p on o.performancetemplateid=p.autoid
  3793. WHERE 1 = 1
  3794. `
  3795. if r.USERID > 0 {
  3796. if r.WRTRADEORDERID != "" {
  3797. sqlId.And("t.userid", r.USERID)
  3798. sqlId.AndInterEx("t.wrtradeorderid", r.WRTRADEORDERID, true)
  3799. } else {
  3800. sqlId.And("t.userid", r.USERID)
  3801. sqlId.Join(" and t.APPLYTIME = (select max(APPLYTIME) from WRTRADE_BARGAINAPPLY where wrtradeorderid=t.wrtradeorderid)")
  3802. }
  3803. } else {
  3804. sqlId.AndEx("t.WRTRADEORDERID", r.WRTRADEORDERID, r.WRTRADEORDERID != "")
  3805. }
  3806. sqlId.AndEx("t.matchuserid", r.MATCHUSERID, r.MATCHUSERID > 0)
  3807. sqlId.And("o.haswr", r.HASWR)
  3808. return sqlId.String()
  3809. }
  3810. // buildSqlHis 查历史
  3811. func (r *WRTradeBargainApply) buildSqlHis() string {
  3812. var sqlId utils.SQLVal = `
  3813. with tmp as
  3814. (select to_char(t.wrfactortypeid) wrfactortypeid,
  3815. t.wrfactortypename2 wrfactortypename,
  3816. t.wrstandardid,
  3817. t.deliverygoodsid,
  3818. g.deliverygoodscode,
  3819. g.deliverygoodsname,
  3820. w.wrstandardcode,
  3821. w.wrstandardname,
  3822. h.warehousecode,
  3823. h.warehousename,
  3824. e.enumdicname,
  3825. w.wrstandardname || t.wrfactortypename2 as wrtypename
  3826. from wrfactortype t
  3827. left join deliverygoods g
  3828. on t.deliverygoodsid = g.deliverygoodsid
  3829. left join wrstandard w
  3830. on t.wrstandardid = w.wrstandardid
  3831. left join warehouseinfo h
  3832. on t.warehouseid = h.autoid
  3833. left join enumdicitem e
  3834. on w.unitid = e.enumitemname
  3835. and e.enumdiccode = 'goodsunit')
  3836. SELECT to_char(t.WRBARGAINID) WRBARGAINID,
  3837. to_char(t.WRTRADEORDERID) WRTRADEORDERID,
  3838. t.TRADEDATE,
  3839. t.MARKETID,
  3840. t.USERID,
  3841. t.ACCOUNTID,
  3842. t.BUYORSELL,
  3843. t.APPLYQTY,
  3844. t.APPLYPRICE,
  3845. t.APPLYSTATUS,
  3846. t.HANDLESTATUS,
  3847. to_char(t.APPLYTIME, 'yyyy-mm-dd hh24:mi:ss') APPLYTIME,
  3848. t.APPLYREMARK,
  3849. t.CONFIRMUSERID,
  3850. to_char(t.CONFIRMTIME, 'yyyy-mm-dd hh24:mi:ss') CONFIRMTIME,
  3851. t.CONFIRMREMARK,
  3852. t.REFPRICE,
  3853. t.RETCODE,
  3854. t.matchuserid,
  3855. t.matchaccountid,
  3856. u.accountname USERNAME,
  3857. u2.accountname matchusername,
  3858. o.orderqty,
  3859. o.fixedprice,
  3860. o.deliverymonth,
  3861. o.marginvalue,
  3862. to_char(o.validtime, 'yyyy-mm-dd hh24:mi:ss') validtime,
  3863. p.templatename,
  3864. tmp.*
  3865. FROM HIS_WRTRADE_BARGAINAPPLY t
  3866. LEFT JOIN USERACCOUNT u on t.userid=u.userid
  3867. LEFT JOIN USERACCOUNT u2 on t.matchuserid=u2.userid
  3868. LEFT JOIN HIS_WRTRADE_ORDERDETAIL o on t.wrtradeorderid=o.wrtradeorderid
  3869. LEFT JOIN tmp on o.wrfactortypeid=tmp.wrfactortypeid
  3870. LEFT JOIN PERFORMANCEPLANTEMPLATE p on o.performancetemplateid=p.autoid
  3871. WHERE 1 = 1 and t.isvaliddata = 1
  3872. `
  3873. sqlId.AndEx("t.userid", r.USERID, r.USERID > 0)
  3874. sqlId.AndEx("t.matchuserid", r.MATCHUSERID, r.MATCHUSERID > 0)
  3875. sqlId.AndEx("t.WRTRADEORDERID", r.WRTRADEORDERID, r.WRTRADEORDERID != "")
  3876. sqlId.And("o.haswr", r.HASWR)
  3877. // 格式 yyyymmdd
  3878. if len(r.BEGINDATE) > 0 {
  3879. sqlId.JoinFormat(" and t.TRADEDATE >= '%v'", r.BEGINDATE)
  3880. }
  3881. if len(r.ENDDATE) > 0 {
  3882. sqlId.JoinFormat(" and t.TRADEDATE <= '%v'", r.ENDDATE)
  3883. }
  3884. return sqlId.String()
  3885. }
  3886. // GetDataEx 获取议价单
  3887. func (r *WRTradeBargainApply) GetDataEx() (interface{}, error) {
  3888. var sqlId string
  3889. // 如果指定了开始日期或结束日期, 刚查历史
  3890. if r.BEGINDATE != "" || r.ENDDATE != "" {
  3891. sqlId = r.buildSqlHis()
  3892. } else {
  3893. sqlId = r.buildSql()
  3894. }
  3895. sData := make([]WRTradeBargainApply, 0)
  3896. err := db.GetEngine().SQL(sqlId).Find(&sData)
  3897. for i := range sData {
  3898. sData[i].calc()
  3899. }
  3900. return sData, err
  3901. }
  3902. // WrPerformanceStepType 履约步骤枚举
  3903. type WrPerformanceStepType struct {
  3904. STEPTYPEID int32 `json:"steptypeid" xorm:"STEPTYPEID" form:"steptypeid"` // 步骤类型ID - 1:买方支付 2:卖方收款 3:买方自提 4:卖方发货 5:买方确认货 6:卖方发票 7:买方确认票 8:仓单转移
  3905. STEPTYPENAME string `json:"steptypename" xorm:"STEPTYPENAME"` // 步骤类型名称
  3906. CANAUTO int32 `json:"canauto" xorm:"CANAUTO"` // 能否自动确认 - 0:不可自动确认 1:可自动确认 (可设置自动确认步骤: 1:买方支付 3:买方自提 5:买方确认货 7:买方确认票)
  3907. }
  3908. func (r *WrPerformanceStepType) calc() {
  3909. }
  3910. func (r *WrPerformanceStepType) buildSql() string {
  3911. // id 90以上的不可选
  3912. var sqlId utils.SQLVal = `
  3913. select t.* from PERFORMANCESTEPTYPE t where t.STEPTYPEID < 90 order by t.STEPTYPEID
  3914. `
  3915. return sqlId.String()
  3916. }
  3917. // GetDataEx 获取履约步骤枚举
  3918. func (r *WrPerformanceStepType) GetDataEx() (interface{}, error) {
  3919. sData := make([]WrPerformanceStepType, 0)
  3920. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  3921. for i := range sData {
  3922. sData[i].calc()
  3923. }
  3924. return sData, err
  3925. }
  3926. // WrUserReceiptInfo 发票信息
  3927. type WrUserReceiptInfo struct {
  3928. AUTOID int64 `json:"autoid" xorm:"AUTOID" form:"autoid"` // AutoID
  3929. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 用户ID
  3930. RECEIPTTYPE int32 `json:"receipttype" xorm:"RECEIPTTYPE" form:"receipttype"` // 发票类型 - 1:个人 2:企业
  3931. USERNAME string `json:"username" xorm:"USERNAME"` // 户名(个人姓名或企业名称)
  3932. TAXPAYERID string `json:"taxpayerid" xorm:"TAXPAYERID" form:"taxpayerid"` // 纳税人识别号
  3933. CONTACTINFO string `json:"contactinfo" xorm:"CONTACTINFO"` // 联系方式
  3934. RECEIPTBANK string `json:"receiptbank" xorm:"RECEIPTBANK"` // 发票开户行[发票类型:企业]
  3935. RECEIPTACCOUNT string `json:"receiptaccount" xorm:"RECEIPTACCOUNT"` // 发票帐号[发票类型:企业]
  3936. ADDRESS string `json:"address" xorm:"ADDRESS"` // 地址[发票类型:企业]
  3937. IDNUM string `json:"idnum" xorm:"IDNUM"` // 身份证号码[发票类型:个人]
  3938. ISDEFAULT int32 `json:"isdefault" xorm:"'ISDEFAULT'"` // 是否默认地址 - 0:否 1:是
  3939. EMAIL string `json:"email" xorm:"EMAIL"` // 收件邮箱
  3940. }
  3941. func (r *WrUserReceiptInfo) calc() {
  3942. }
  3943. func (r *WrUserReceiptInfo) buildSql() string {
  3944. var sqlId utils.SQLVal = `
  3945. SELECT t.AUTOID,
  3946. t.USERID,
  3947. t.RECEIPTTYPE,
  3948. t.USERNAME,
  3949. t.TAXPAYERID,
  3950. t.CONTACTINFO,
  3951. t.RECEIPTBANK,
  3952. t.RECEIPTACCOUNT,
  3953. t.ADDRESS,
  3954. t.IDNUM,
  3955. t.EMAIL
  3956. FROM USERRECEIPTINFO t
  3957. WHERE 1 = 1
  3958. `
  3959. sqlId.AndEx("t.USERID", r.USERID, r.USERID > 0)
  3960. sqlId.AndEx("t.USERID", r.RECEIPTTYPE, r.RECEIPTTYPE > 0)
  3961. return sqlId.String()
  3962. }
  3963. // GetDataEx 获取发票信息
  3964. func (r *WrUserReceiptInfo) GetDataEx() (interface{}, error) {
  3965. sData := make([]WrUserReceiptInfo, 0)
  3966. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  3967. for i := range sData {
  3968. sData[i].calc()
  3969. }
  3970. return sData, err
  3971. }
  3972. // WrSiteColumnDetail 资讯
  3973. type WrSiteColumnDetail struct {
  3974. ID int64 `json:"id" xorm:"ID" form:"id"` // ID(SEQ_SITE_COLUMNDETAIL)
  3975. COLUMNID int64 `json:"-" xorm:"COLUMNID" form:"columnid"` // 所属栏目
  3976. USERID int64 `json:"-" xorm:"USERID" form:"userid"` // 用户ID(默认为0, 核心为为机构用户ID)
  3977. TITLE string `json:"title" xorm:"TITLE"` // 标题
  3978. COVERIMAGE string `json:"coverimage" xorm:"COVERIMAGE"` // 封面图片
  3979. AUTHOR string `json:"author" xorm:"AUTHOR"` // 作者
  3980. BRIEF string `json:"brief" xorm:"BRIEF"` // 简介
  3981. CONTEXT string `json:"context" xorm:"CONTEXT"` // 内容
  3982. STATUS int32 `json:"-" xorm:"STATUS"` // 状态 - 1:暂存 10:待审核 20:审核通过 30:审核拒绝
  3983. ISTOP int32 `json:"istop" xorm:"ISTOP"` // 是否置顶 - 0:不置 1:置顶
  3984. HITS int64 `json:"-" xorm:"HITS"` // 点击数
  3985. PUBLISHDATE string `json:"publishdate" xorm:"PUBLISHDATE" form:"publishdate"` // 发布日期
  3986. CREAEDATE string `json:"creaedate" xorm:"CREAEDATE" form:"creaedate"` // 创建时间
  3987. CREATORID int64 `json:"-" xorm:"CREATORID" form:"creatorid"` // 创建人
  3988. UPDATEDATE string `json:"updatedate" xorm:"UPDATEDATE" form:"updatedate"` // 修改时间
  3989. MODIFIERID int64 `json:"-" xorm:"MODIFIERID" form:"modifierid"` // 操作人
  3990. ISSHOW int32 `json:"-" xorm:"ISSHOW"` // 是否展示 - 0:不展示 1:展示
  3991. PageEx `xorm:"extends"` // 页码信息
  3992. }
  3993. func (r *WrSiteColumnDetail) calc() {
  3994. }
  3995. func (r *WrSiteColumnDetail) buildSql() string {
  3996. var sqlId utils.SQLVal = `
  3997. SELECT t.ID,
  3998. t.COLUMNID,
  3999. t.USERID,
  4000. t.TITLE,
  4001. t.COVERIMAGE,
  4002. t.AUTHOR,
  4003. t.BRIEF,
  4004. t.CONTEXT,
  4005. t.STATUS,
  4006. t.ISTOP,
  4007. t.HITS,
  4008. to_char(t.PUBLISHDATE, 'yyyy-mm-dd hh24:mi:ss') PUBLISHDATE,
  4009. to_char(t.CREAEDATE, 'yyyy-mm-dd hh24:mi:ss') CREAEDATE,
  4010. t.CREATORID,
  4011. to_char(t.UPDATEDATE, 'yyyy-mm-dd hh24:mi:ss') UPDATEDATE,
  4012. t.MODIFIERID,
  4013. t.ISSHOW
  4014. FROM SITE_COLUMNDETAIL t
  4015. WHERE 1 = 1 and t.isshow = 1 and t.status = 20 and %v
  4016. order by t.istop desc, t.updatedate desc
  4017. `
  4018. // sqlId.AndEx("t.COLUMNID", r.COLUMNID, r.COLUMNID > 0)
  4019. param := "1=1"
  4020. if r.COLUMNID > 0 {
  4021. param = fmt.Sprintf("t.COLUMNID = %v", r.COLUMNID)
  4022. }
  4023. sqlId.FormatParam(param)
  4024. sqlId.Page(r.Page, r.PageSize)
  4025. return sqlId.String()
  4026. }
  4027. // GetDataByPage 获取资讯
  4028. func (r *WrSiteColumnDetail) GetDataByPage() (interface{}, error, int, int, int) {
  4029. sData := make([]WrSiteColumnDetail, 0)
  4030. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  4031. for i := range sData {
  4032. sData[i].calc()
  4033. }
  4034. if len(sData) > 0 {
  4035. r.Total = sData[0].Total
  4036. }
  4037. return sData, err, r.Page, r.PageSize, r.Total
  4038. }
  4039. // Sitecolumnconfig 栏目配置表 - 前999预留,序列从1000开始
  4040. type Sitecolumnconfig struct {
  4041. ID int64 `json:"id" xorm:"ID"` // ID(SEQ_SITE_COLUMNCONFIG)
  4042. COLUMNTYPE int32 `json:"columntype" xorm:"COLUMNTYPE" form:"columntype"` // 栏目类型 - 1:行情资讯 10:会员服务 30:关于我们 100:核心企业栏目-百色
  4043. COLUMNNAME string `json:"columnname" xorm:"COLUMNNAME"` // 栏目名称
  4044. SORT int64 `json:"sort" xorm:"SORT"` // 排序
  4045. ISSHOW int32 `json:"isshow" xorm:"ISSHOW"` // 是否展示 - 0:不展示 1:展示
  4046. CREAEDATE time.Time `json:"creaedate" xorm:"CREAEDATE"` // 创建时间
  4047. CREATORID int64 `json:"creatorid" xorm:"CREATORID"` // 创建人
  4048. UPDATEDATE time.Time `json:"updatedate" xorm:"UPDATEDATE"` // 修改时间
  4049. MODIFIERID int64 `json:"modifierid" xorm:"MODIFIERID"` // 操作人
  4050. PageEx `xorm:"extends"` // 页码信息
  4051. }
  4052. func (r *Sitecolumnconfig) calc() {
  4053. }
  4054. func (r *Sitecolumnconfig) buildSql() string {
  4055. var sqlId utils.SQLVal = `
  4056. select
  4057. t.ID ,
  4058. t.COLUMNTYPE,
  4059. t.COLUMNNAME,
  4060. t.SORT ,
  4061. t.ISSHOW ,
  4062. t.CREAEDATE ,
  4063. t.CREATORID ,
  4064. t.UPDATEDATE,
  4065. t.MODIFIERID
  4066. from SITE_COLUMNCONFIG t
  4067. where %v
  4068. order by t.SORT
  4069. `
  4070. param := "1=1"
  4071. if r.COLUMNTYPE > 0 {
  4072. param = fmt.Sprintf("t.COLUMNTYPE = %v", r.COLUMNTYPE)
  4073. }
  4074. sqlId.FormatParam(param)
  4075. sqlId.Page(r.Page, r.PageSize)
  4076. return sqlId.String()
  4077. }
  4078. func (r *Sitecolumnconfig) GetDataByPage() (interface{}, error, int, int, int) {
  4079. sData := make([]Sitecolumnconfig, 0)
  4080. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  4081. for i := range sData {
  4082. sData[i].calc()
  4083. }
  4084. if len(sData) > 0 {
  4085. r.Total = sData[0].Total
  4086. }
  4087. return sData, err, r.Page, r.PageSize, r.Total
  4088. }
  4089. // WrDeliveryGoodsSection 走势 (分类)
  4090. type WrDeliveryGoodsSection struct {
  4091. SECTIONID int64 `json:"sectionid" xorm:"SECTIONID" form:"sectionid"` // 版块ID (SEQ_DELIVERYGOODSSECTION) - 自增100开始, 前面ID预留给SectionType = 1的版块1 - 云融指数
  4092. SECTIONTYPE int32 `json:"sectiontype" xorm:"SECTIONTYPE"` // 版块类型 - 1:指数版块 2:普通版块
  4093. SECTIONNAME string `json:"sectionname" xorm:"SECTIONNAME"` // 版块名称
  4094. ORDERINDEX int32 `json:"orderindex" xorm:"ORDERINDEX"` // 排序
  4095. SHOWFLAG int32 `json:"-" xorm:"SHOWFLAG"` // 是否展示 - 0:不展示 1:展示
  4096. CREATORSRC int32 `json:"-" xorm:"CREATORSRC"` // 申请来源 - 1:管理端 2:终端 3:交易
  4097. CREATORID int64 `json:"-" xorm:"CREATORID" form:"creatorid"` // 创建人
  4098. CREATETIME string `json:"-" xorm:"CREATETIME"` // 创建时间
  4099. IMAGEPATH string `json:"imagepath" xorm:"IMAGEPATH"` // 图片地址
  4100. DGLst []WrDeliveryGoodsSectionConfig `json:"dglst"` // 板块商品列表
  4101. }
  4102. func (r *WrDeliveryGoodsSection) calc() {
  4103. r.DGLst = make([]WrDeliveryGoodsSectionConfig, 0)
  4104. }
  4105. func (r *WrDeliveryGoodsSection) buildSql() string {
  4106. var sqlId utils.SQLVal = `
  4107. select t.sectionid,
  4108. t.sectiontype,
  4109. t.sectionname,
  4110. t.orderindex,
  4111. t.showflag,
  4112. t.creatorsrc,
  4113. t.creatorid,
  4114. to_char(t.createtime,'yyyy-mm-dd hh24:mi:ss') createtime,
  4115. t.imagepath
  4116. from DeliveryGoodsSection t
  4117. where t.sectiontype = 2
  4118. and t.showflag = 1
  4119. order by t.orderindex
  4120. `
  4121. return sqlId.String()
  4122. }
  4123. // GetDataEx 获取板块(分类)
  4124. func (r *WrDeliveryGoodsSection) GetDataEx() (interface{}, error) {
  4125. sData := make([]WrDeliveryGoodsSection, 0)
  4126. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  4127. for i := range sData {
  4128. sData[i].calc()
  4129. }
  4130. // 获取商品
  4131. m := WrDeliveryGoodsSectionConfig{}
  4132. if d, err := m.GetDataEx(); err == nil {
  4133. lst := d.([]WrDeliveryGoodsSectionConfig)
  4134. for i := range sData {
  4135. for _, v := range lst {
  4136. if sData[i].SECTIONID == v.SECTIONID {
  4137. sData[i].DGLst = append(sData[i].DGLst, v)
  4138. }
  4139. }
  4140. }
  4141. }
  4142. return sData, err
  4143. }
  4144. // WrDeliveryGoodsSectionConfig 板块商品
  4145. type WrDeliveryGoodsSectionConfig struct {
  4146. SECTIONID int64 `json:"-" xorm:"'SECTIONID'"` // 版块ID (SEQ_DELIVERYGOODSSECTION)
  4147. DELIVERYGOODSID int64 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种ID(SEQ_DELIVERYGOODS)
  4148. ORDERINDEX int32 `json:"orderindex" xorm:"'ORDERINDEX'"` // 排序
  4149. CREATORSRC int32 `json:"-" xorm:"'CREATORSRC'"` // 申请来源 - 1:管理端 2:终端 3:交易
  4150. CREATORID int32 `json:"-" xorm:"'CREATORID'"` // 创建人
  4151. CREATEDATE string `json:"-" xorm:"'CREATEDATE'"` // 创建时间
  4152. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货商品代码
  4153. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货商品名称
  4154. }
  4155. func (r *WrDeliveryGoodsSectionConfig) calc() {
  4156. }
  4157. func (r *WrDeliveryGoodsSectionConfig) buildSql() string {
  4158. var sqlId utils.SQLVal = `
  4159. select t.sectionid,
  4160. t.deliverygoodsid,
  4161. t.orderindex,
  4162. t.creatorsrc,
  4163. t.creatorid,
  4164. to_char(t.createdate, 'yyyy-mm-dd hh24:mi:ss') createdate,
  4165. g.deliverygoodscode,
  4166. g.deliverygoodsname
  4167. from DeliveryGoodsSectionConfig t
  4168. inner join deliverygoods g
  4169. on t.deliverygoodsid = g.deliverygoodsid
  4170. inner join Deliverygoodssection s
  4171. on t.sectionid = s.sectionid
  4172. where 1 = 1
  4173. and t.showflag = 1
  4174. and s.showflag = 1
  4175. and s.sectiontype = 2
  4176. order by t.sectionid, t.orderindex
  4177. `
  4178. return sqlId.String()
  4179. }
  4180. // GetDataEx 获取板块商品
  4181. func (r *WrDeliveryGoodsSectionConfig) GetDataEx() (interface{}, error) {
  4182. sData := make([]WrDeliveryGoodsSectionConfig, 0)
  4183. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  4184. for i := range sData {
  4185. sData[i].calc()
  4186. }
  4187. return sData, err
  4188. }
  4189. // WrSpotGroupTradeSum 指数
  4190. type WrSpotGroupTradeSum struct {
  4191. RECKONDATE string `json:"reckondate" xorm:"'RECKONDATE'"` // 上个交易日(前1天交易日)
  4192. LASTRECKONDATE string `json:"lastreckondate" xorm:"'LASTRECKONDATE'"` // 上上个交易日(前2天交易日)
  4193. MARKETID int64 `json:"-" xorm:"'MARKETID'" form:"marketid"` // 市场id
  4194. TRADEQTY float64 `json:"-" xorm:"'TRADEQTY'"` // 成交量
  4195. TRADEAMOUNT float64 `json:"-" xorm:"'TRADEAMOUNT'"` // 成交额
  4196. LASTAVGPRICE SFLOAT64 `json:"-" xorm:"'LASTAVGPRICE'"` // 上上个交易日价格(前2天价格)
  4197. TODAYAVGPRICE SFLOAT64 `json:"-" xorm:"'TODAYAVGPRICE'"` // 上个交易日价格(前1天价格)
  4198. DELIVERYGOODSID int64 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'"` // 现货品种ID(SEQ_DELIVERYGOODS)
  4199. DELIVERYGOODSCODE string `json:"deliverygoodscode" xorm:"'DELIVERYGOODSCODE'"` // 现货品种代码
  4200. DELIVERYGOODSNAME string `json:"deliverygoodsname" xorm:"'DELIVERYGOODSNAME'"` // 现货品种名称
  4201. SECTIONID int64 `json:"-" xorm:"'SECTIONID'"` // 版块ID (SEQ_DELIVERYGOODSSECTION)
  4202. PRETRADEDATE string `json:"-" xorm:"'PRETRADEDATE'"` // 上个交易日(从marketid=0表中取的, 系统)
  4203. LASTAVGPRICE2 string `json:"lastavgprice"` // 上上个交易日价格(前2天价格)
  4204. TODAYAVGPRICE2 string `json:"todayavgprice"` // 上个交易日价格(前1天价格)
  4205. UPDOWN string `json:"updown"` // 涨跌
  4206. UPDOWNRATIO string `json:"updownratio"` // 涨幅(已格式化, 直接显示即可)
  4207. }
  4208. func (r *WrSpotGroupTradeSum) calc() {
  4209. if r.TODAYAVGPRICE < 1e-8 {
  4210. // 如果今日为0, 则取上日的作为今日价
  4211. r.TODAYAVGPRICE = r.LASTAVGPRICE
  4212. }
  4213. if r.LASTAVGPRICE < 1e-8 {
  4214. r.LASTAVGPRICE2 = "-"
  4215. } else {
  4216. r.LASTAVGPRICE2 = r.LASTAVGPRICE.string()
  4217. }
  4218. if r.TODAYAVGPRICE < 1e-8 {
  4219. r.TODAYAVGPRICE2 = "-"
  4220. } else {
  4221. r.TODAYAVGPRICE2 = r.TODAYAVGPRICE.string()
  4222. }
  4223. if r.TODAYAVGPRICE > 1e-8 && r.LASTAVGPRICE > 1e-8 {
  4224. r.LASTAVGPRICE2 = r.LASTAVGPRICE.string()
  4225. r.TODAYAVGPRICE2 = r.TODAYAVGPRICE.string()
  4226. // 涨跌
  4227. var diff SFLOAT64
  4228. diff = r.TODAYAVGPRICE - r.LASTAVGPRICE
  4229. r.UPDOWN = diff.Round(2).string()
  4230. // 涨幅
  4231. var k SFLOAT64
  4232. k = diff * 100 / r.TODAYAVGPRICE
  4233. k.Round(2)
  4234. if k.Float64() > 1e-8 {
  4235. r.UPDOWNRATIO = "+" + k.string() + `%`
  4236. } else {
  4237. r.UPDOWNRATIO = k.string() + `%`
  4238. }
  4239. } else {
  4240. r.UPDOWN = "-"
  4241. r.UPDOWNRATIO = "-"
  4242. }
  4243. }
  4244. func (r *WrSpotGroupTradeSum) buildSql() string {
  4245. var sqlId utils.SQLVal = `
  4246. with tmp as
  4247. (select k.reckondate,
  4248. k.marketid,
  4249. k.tradeqty,
  4250. k.tradeamount,
  4251. k.lastreckondate,
  4252. k.lastavgprice,
  4253. k.todayavgprice,
  4254. k.deliverygoodsid deliverygoodsid1
  4255. from reckon_spotgrouptradesum k
  4256. inner join marketrun m
  4257. on k.reckondate = m.pretradedate
  4258. and m.marketid = 0)
  4259. select tmp.*,
  4260. t.sectionid,
  4261. g.deliverygoodsid,
  4262. g.deliverygoodscode,
  4263. g.deliverygoodsname
  4264. from DeliveryGoodsSectionConfig t
  4265. left join tmp
  4266. on t.deliverygoodsid = tmp.deliverygoodsid1
  4267. left join deliverygoods g
  4268. on t.deliverygoodsid = g.deliverygoodsid
  4269. where t.sectionid = 1
  4270. and t.showflag = 1
  4271. order by t.orderindex
  4272. `
  4273. return sqlId.String()
  4274. }
  4275. // GetDataEx 获取指数
  4276. func (r *WrSpotGroupTradeSum) GetDataEx() (interface{}, error) {
  4277. sData := make([]WrSpotGroupTradeSum, 0)
  4278. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  4279. for i := range sData {
  4280. sData[i].calc()
  4281. }
  4282. return sData, err
  4283. }
  4284. // WrSpotGroupTradeSumEx 指数(层级)
  4285. type WrSpotGroupTradeSumEx struct {
  4286. RECKONDATE string `json:"reckondate" xorm:"'RECKONDATE'"` // 上个交易日(yyyymmdd)
  4287. PRERECKONDATE string `json:"prereckondate" xorm:"'PRERECKONDATE'"` // 上上个交易日(yyymmdd)
  4288. LST []WrSpotGroupTradeSum `json:"lst"` // 指数列表
  4289. }
  4290. func (r *WrSpotGroupTradeSumEx) calc() {
  4291. r.LST = make([]WrSpotGroupTradeSum, 0)
  4292. }
  4293. func (r *WrSpotGroupTradeSumEx) buildSql() string {
  4294. var sqlId utils.SQLVal = `
  4295. select t.pretradedate RECKONDATE,
  4296. (select max(k.lastreckondate)
  4297. from reckon_spotgrouptradesum k
  4298. where k.reckondate = t.pretradedate) PRERECKONDATE
  4299. from marketrun t
  4300. where t.marketid = 0
  4301. `
  4302. return sqlId.String()
  4303. }
  4304. // GetDataEx 获取指数(层级)
  4305. func (r *WrSpotGroupTradeSumEx) GetDataEx() (interface{}, error) {
  4306. sData := make([]WrSpotGroupTradeSumEx, 0)
  4307. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  4308. for i := range sData {
  4309. sData[i].calc()
  4310. }
  4311. if err == nil && len(sData) > 0 {
  4312. m := WrSpotGroupTradeSum{}
  4313. if d, err := m.GetDataEx(); err == nil {
  4314. sData[0].LST = d.([]WrSpotGroupTradeSum)
  4315. }
  4316. }
  4317. return sData, err
  4318. }
  4319. // WrSpotGroupTradeSumDetail 折线图价格走势
  4320. type WrSpotGroupTradeSumDetail struct {
  4321. RECKONDATE string `json:"reckondate" xorm:"'RECKONDATE'"` // 日期(yyymmdd, 如:20211031)
  4322. DELIVERYGOODSID int64 `json:"deliverygoodsid" xorm:"'DELIVERYGOODSID'" form:"deliverygoodsid"` // 现货商品id
  4323. PRICE float64 `json:"price" xorm:"'PRICE'"` // 价格
  4324. LASTNUM int32 `json:"-" form:"lastnum"` // 最新多少条
  4325. }
  4326. func (r *WrSpotGroupTradeSumDetail) calc() {
  4327. }
  4328. func (r *WrSpotGroupTradeSumDetail) buildSql() string {
  4329. var sqlId utils.SQLVal = `
  4330. select a.*
  4331. from (select t.reckondate, t.deliverygoodsid, t.todayavgprice price, rownum cnt
  4332. from reckon_spotgrouptradesum t
  4333. where 1 = 1 and t.todayavgprice > 0
  4334. and t.deliverygoodsid = %v
  4335. order by t.reckondate desc) a
  4336. where a.cnt <= %v
  4337. order by a.reckondate
  4338. `
  4339. if r.LASTNUM == 0 {
  4340. r.LASTNUM = 30 // 如果没传值, 默认查最近30条
  4341. }
  4342. sqlId.FormatParam(r.DELIVERYGOODSID, r.LASTNUM)
  4343. return sqlId.String()
  4344. }
  4345. // GetDataEx 获取折线图价格走势
  4346. func (r *WrSpotGroupTradeSumDetail) GetDataEx() (interface{}, error) {
  4347. sData := make([]WrSpotGroupTradeSumDetail, 0)
  4348. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  4349. for i := range sData {
  4350. sData[i].calc()
  4351. }
  4352. return sData, err
  4353. }
  4354. // WrPreSaleInfo 新品发布
  4355. type WrPreSaleInfo struct {
  4356. PRESALEAPPLYID int64 `json:"presaleapplyid,string" xorm:"PRESALEAPPLYID" form:"presaleapplyid"` // 预售申请ID(184+Unix秒时间戳(10位)+xxxxxx)
  4357. SELLUSERID int64 `json:"selluserid" xorm:"SELLUSERID" form:"selluserid"` // 发行方用户ID
  4358. SELLACCOUNTID int64 `json:"sellaccountid" xorm:"SELLACCOUNTID" form:"sellaccountid"` // 发行方资金账户ID
  4359. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID" form:"deliverygoodsid"` // 现货品种ID
  4360. WAREHOUSEID int64 `json:"warehouseid" xorm:"WAREHOUSEID" form:"warehouseid"` // 仓库ID
  4361. WRSTANDARDID int64 `json:"wrstandardid" xorm:"WRSTANDARDID" form:"wrstandardid"` // 现货商品ID
  4362. WRFACTORTYPEID int64 `json:"wrfactortypeid,string" xorm:"WRFACTORTYPEID" form:"wrfactortypeid"` // 仓单要素类型ID - 根据现货商品\仓库生成
  4363. WRSTANDARDNAME string `json:"wrstandardname" xorm:"WRSTANDARDNAME"` // 现货商品名称
  4364. UNITID int32 `json:"unitid" xorm:"UNITID" form:"unitid"` // 单位ID
  4365. UNITPRICE float64 `json:"unitprice" xorm:"UNITPRICE"` // 商品单价
  4366. PRESALEQTY float64 `json:"presaleqty" xorm:"PRESALEQTY"` // 预售总量
  4367. BASEQTY float64 `json:"baseqty" xorm:"BASEQTY"` // 中签基数
  4368. MAXBUYQTY float64 `json:"maxbuyqty" xorm:"MAXBUYQTY"` // 单人最大申购量
  4369. MAXLUCKYQTY float64 `json:"maxluckyqty" xorm:"MAXLUCKYQTY"` // 单人最大中签量
  4370. STARTDATE string `json:"startdate" xorm:"STARTDATE" form:"startdate"` // 预售开始日期
  4371. ENDDATE string `json:"enddate" xorm:"ENDDATE" form:"enddate"` // 预售结束日期
  4372. TAKESTARTDATE string `json:"takestartdate" xorm:"TAKESTARTDATE" form:"takestartdate"` // 提货开始日期
  4373. THUMURLS string `json:"thumurls" xorm:"THUMURLS"` // 缩略图片(1:1)(逗号分隔)
  4374. PICTUREURLS string `json:"pictureurls" xorm:"PICTUREURLS"` // 详情图片(逗号分隔)
  4375. BANNERPICURL string `json:"bannerpicurl" xorm:"BANNERPICURL"` // Banner图
  4376. PRESALESTATUS int32 `json:"presalestatus" xorm:"PRESALESTATUS"` // 预售状态 - 1:未开始 2:进行中 3:已结束 4:已关闭
  4377. LOTTERYFLAG int32 `json:"lotteryflag" xorm:"LOTTERYFLAG" form:"lotteryflag"` // 摇号标识 - 0:未摇号 1:已摇号
  4378. LOTTERYQTY float64 `json:"lotteryqty" xorm:"LOTTERYQTY"` // 摇号总量
  4379. LUCKYQTY float64 `json:"luckyqty" xorm:"LUCKYQTY"` // 已中签量
  4380. PLACEQTY float64 `json:"placeqty" xorm:"PLACEQTY"` // 已配售量
  4381. MARKETID int32 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID
  4382. SELLWRTRADEORDERID string `json:"sellwrtradeorderid" xorm:"SELLWRTRADEORDERID"` // 发行方卖委托单ID
  4383. CREATETIME string `json:"createtime" xorm:"CREATETIME"` // 创建时间
  4384. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE" form:"tradedate"` // 交易日
  4385. WAREHOUSECODE string `json:"warehousecode" xorm:"'WAREHOUSECODE'"` // 仓库代码(仓库简称)
  4386. WAREHOUSENAME string `json:"warehousename" xorm:"'WAREHOUSENAME'"` // 仓库名称
  4387. USERNAME string `json:"username" xorm:"'USERNAME'"` // 发行方用户名称
  4388. ENUMDICNAME string `json:"enumdicname" xorm:"'ENUMDICNAME'"` // 单位名称
  4389. LastNum int `json:"-" form:"lastnum"` // 最近多少条记录
  4390. FilterStatus string `json:"-" form:"presalestatus"` // 预售状态(逗号隔开,如1,2,3) 1:未开始 2:进行中 3:已结束 4:已关闭
  4391. }
  4392. func (r *WrPreSaleInfo) calc() {
  4393. }
  4394. func (r *WrPreSaleInfo) buildSql() string {
  4395. var sqlId utils.SQLVal = `
  4396. SELECT to_char(t.PRESALEAPPLYID) PRESALEAPPLYID,
  4397. t.SELLUSERID,
  4398. t.SELLACCOUNTID,
  4399. t.DELIVERYGOODSID,
  4400. t.WAREHOUSEID,
  4401. t.WRSTANDARDID,
  4402. to_char(t.WRFACTORTYPEID) WRFACTORTYPEID,
  4403. t.WRSTANDARDNAME,
  4404. t.UNITID,
  4405. t.UNITPRICE,
  4406. t.PRESALEQTY,
  4407. t.BASEQTY,
  4408. t.MAXBUYQTY,
  4409. t.MAXLUCKYQTY,
  4410. to_char(t.STARTDATE, 'yyyy-mm-dd hh24:mi:ss') STARTDATE,
  4411. to_char(t.ENDDATE, 'yyyy-mm-dd hh24:mi:ss') ENDDATE,
  4412. to_char(t.TAKESTARTDATE, 'yyyy-mm-dd hh24:mi:ss') TAKESTARTDATE,
  4413. t.THUMURLS,
  4414. t.PICTUREURLS,
  4415. t.BANNERPICURL,
  4416. t.PRESALESTATUS,
  4417. t.LOTTERYFLAG,
  4418. t.LOTTERYQTY,
  4419. t.LUCKYQTY,
  4420. t.PLACEQTY,
  4421. t.MARKETID,
  4422. to_char(t.SELLWRTRADEORDERID) SELLWRTRADEORDERID,
  4423. to_char(t.CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME,
  4424. t.TRADEDATE,
  4425. h.warehousecode,
  4426. h.warehousename,
  4427. u.accountname username,
  4428. e.enumdicname
  4429. FROM WR_PRESALEINFO t
  4430. LEFT JOIN WAREHOUSEINFO h on t.warehouseid=h.autoid
  4431. LEFT JOIN USERACCOUNT u on t.selluserid=u.userid
  4432. LEFT JOIN ENUMDICITEM e on t.unitid=e.enumitemname and e.enumdiccode='goodsunit'
  4433. WHERE 1 = 1
  4434. `
  4435. sqlId.AndEx("t.MARKETID", r.MARKETID, r.MARKETID > 0)
  4436. sqlId.AndEx("t.LOTTERYFLAG", r.LOTTERYFLAG, r.LOTTERYFLAG >= 0)
  4437. sqlId.JoinEx(r.FilterStatus != "", fmt.Sprintf(" and t.PRESALESTATUS in(%s)", r.FilterStatus))
  4438. sqlId.Join(" order by t.createtime desc")
  4439. if r.LastNum > 0 {
  4440. sqlId.Page(1, r.LastNum)
  4441. }
  4442. return sqlId.String()
  4443. }
  4444. // GetDataEx 获取新品发布
  4445. func (r *WrPreSaleInfo) GetDataEx() (interface{}, error) {
  4446. sData := make([]WrPreSaleInfo, 0)
  4447. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  4448. for i := range sData {
  4449. sData[i].calc()
  4450. }
  4451. return sData, err
  4452. }
  4453. // WrReckonSpotGoodsTradeSum 价格走势
  4454. type WrReckonSpotGoodsTradeSum struct {
  4455. RECKONDATE string `json:"reckondate" xorm:"'RECKONDATE'"` // 日期 格式 yyyymmdd
  4456. MARKETID int `json:"marketid" xorm:"'MARKETID'" form:"marketid"` // 市场ID
  4457. WRSTANDARDID int `json:"wrstandardid" xorm:"'WRSTANDARDID'" form:"wrstandardid"` // 现货商品ID
  4458. TRADEQTY SFLOAT64 `json:"tradeqty" xorm:"'TRADEQTY'"` // 日成交数量(当日单方向成交数量)
  4459. TRADEAMOUNT SFLOAT64 `json:"tradeamount" xorm:"'TRADEAMOUNT'"` // 日成交金额(当日单方向成交金额)
  4460. PRICE string `json:"price"` // 价格 = 日成交金额 / 日成交数量
  4461. BEGINDATE string `json:"begindate" form:"begindate"` // 开始日期(结果含开始日期) yyyymmdd
  4462. ENDDATE string `json:"enddate" form:"enddate"` // 结束日期(结果含结束日期) yyyymmdd
  4463. LastNum int `json:"-" form:"lastnum"` // 最近多少条记录
  4464. ISTODAY bool `json:"istoday" form:"istoday"` // 是否当日
  4465. }
  4466. func (r *WrReckonSpotGoodsTradeSum) calc() {
  4467. if r.TRADEQTY > 1e-10 {
  4468. d := r.TRADEAMOUNT / r.TRADEQTY
  4469. r.PRICE = d.Round(2).string()
  4470. }
  4471. }
  4472. func (r *WrReckonSpotGoodsTradeSum) buildSql() string {
  4473. var sqlId utils.SQLVal = `
  4474. select t.reckondate,
  4475. t.marketid,
  4476. t.wrstandardid,
  4477. sum(t.tradeqty) tradeqty,
  4478. sum(t.tradeamount) tradeamount
  4479. from reckon_spotgoodstradesum t
  4480. where 1 = 1 %v
  4481. group by t.reckondate, t.marketid, t.wrstandardid
  4482. order by t.reckondate desc
  4483. `
  4484. var sqlParam utils.SQLVal
  4485. sqlParam.And("t.marketid", r.MARKETID)
  4486. sqlParam.And("t.wrstandardid", r.WRSTANDARDID)
  4487. // 格式 yyyymmdd
  4488. if len(r.BEGINDATE) > 0 {
  4489. sqlParam.JoinFormat(" and t.reckondate >= '%v'", r.BEGINDATE)
  4490. }
  4491. if len(r.ENDDATE) > 0 {
  4492. sqlParam.JoinFormat(" and t.reckondate <= '%v'", r.ENDDATE)
  4493. }
  4494. sqlId.FormatParam(sqlParam.String())
  4495. sqlId.Page(1, r.LastNum)
  4496. return sqlId.String()
  4497. }
  4498. // buildSqlByToday 今日走势数据
  4499. func (r *WrReckonSpotGoodsTradeSum) buildSqlByToday(today string) string {
  4500. var sqlId utils.SQLVal = utils.SQLVal(fmt.Sprintf(`
  4501. with tmp as
  4502. (select
  4503. to_char(t.TradeTime, 'HH24:MI:SS') RECKONDATE,
  4504. to_char(t.TradeTime, 'yyyymmdd') TRADEDATE,
  4505. t.marketid,
  4506. w.wrstandardid,
  4507. t.tradeqty,
  4508. t.tradeamount
  4509. from WRTrade_TradeDetail t
  4510. left join WRFactorType w on w.WRFactorTypeID = t.WRFactorTypeID
  4511. where t.marketid = %v and w.wrstandardid = %v
  4512. order by t.WRTradeDetailID desc)
  4513. select distinct
  4514. t.RECKONDATE,
  4515. t.marketid,
  4516. t.wrstandardid,
  4517. t.tradeqty,
  4518. t.tradeamount
  4519. from tmp t where t.TRADEDATE = '%v'
  4520. `, r.MARKETID, r.WRSTANDARDID, today))
  4521. sqlId.Page(1, r.LastNum)
  4522. return sqlId.String()
  4523. }
  4524. // GetDataEx 获取价格走势
  4525. func (r *WrReckonSpotGoodsTradeSum) GetDataEx() (interface{}, error) {
  4526. sql := r.buildSql()
  4527. // 判断是否获取今日走势
  4528. if r.MARKETID > 0 && r.ISTODAY {
  4529. if marketRun, err := GetMarketRun(r.MARKETID); err == nil {
  4530. sql = r.buildSqlByToday(marketRun.Tradedate)
  4531. } else {
  4532. return nil, errors.New("数据异常")
  4533. }
  4534. }
  4535. sData := make([]WrReckonSpotGoodsTradeSum, 0)
  4536. err := db.GetEngine().SQL(sql).Find(&sData)
  4537. for i := range sData {
  4538. sData[i].calc()
  4539. sData[i].BEGINDATE = r.BEGINDATE
  4540. sData[i].ENDDATE = r.ENDDATE
  4541. sData[i].ISTODAY = r.ISTODAY
  4542. }
  4543. return sData, err
  4544. }
  4545. // WrSearchUser 搜索用户
  4546. type WrSearchUser struct {
  4547. USERNAME string `json:"username" xorm:"'USERNAME'" form:"username" binding:"required"` // 用户名称(已脱敏)
  4548. USERID int64 `json:"userid" xorm:"'USERID'"` // 用户ID
  4549. USERNAME2 string `json:"username2" xorm:"'-'"` // 用户名称(未脱敏)
  4550. USERTYPE int `json:"usertype" xorm:"'USERTYPE'"` // 账户类型 - 1:交易所 2:机构 3:会员子机构 4:经纪人 5:投资者 6:客户 7:企业成员(云平台)
  4551. }
  4552. func (r *WrSearchUser) calc() {
  4553. r.USERNAME2 = r.USERNAME
  4554. r.USERNAME = EncryptByStar(r.USERNAME)
  4555. }
  4556. func (r *WrSearchUser) buildSql() string {
  4557. var sqlId utils.SQLVal = `
  4558. select t.userid, t.usertype, t.accountname username from useraccount t
  4559. where t.usertype in(2,6) and t.accountname like '%%%v%%'
  4560. `
  4561. sqlId.FormatParam(r.USERNAME)
  4562. return sqlId.String()
  4563. }
  4564. // GetDataEx 获取搜索用户
  4565. func (r *WrSearchUser) GetDataEx() (interface{}, error) {
  4566. sData := make([]WrSearchUser, 0)
  4567. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  4568. for i := range sData {
  4569. sData[i].calc()
  4570. }
  4571. return sData, err
  4572. }
  4573. // WrDraftUserInfo 实名认证信息
  4574. type WrDraftUserInfo struct {
  4575. USERID int64 `json:"userid" xorm:"USERID" form:"userid"` // 用户ID
  4576. USERINFOTYPE int32 `json:"userinfotype" xorm:"USERINFOTYPE"` // 用户信息类型 - 1:个人 2:企业
  4577. CUSTOMERNAME string `json:"customername" xorm:"CUSTOMERNAME"` // 客户名称(企业名称)
  4578. USERSTATUS int32 `json:"userstatus" xorm:"USERSTATUS" form:"userstatus"` // 用户状态 - 1:正常 2:注销
  4579. USERTYPE int32 `json:"usertype" xorm:"USERTYPE"` // 账户类型 - 1:交易所 2:机构 3:会员子机构 4:经纪人 5:投资者
  4580. OPENMODE int32 `json:"openmode" xorm:"OPENMODE"` // 开户方式 - 1:管理端开户 2 :网上开户注册(会员官网) 3:微信开户 4:网页交易端注册 5:安卓手机端注册 6:苹果手机端注册 7:PC交易端注册
  4581. CARDTYPEID int32 `json:"cardtypeid" xorm:"CARDTYPEID" form:"cardtypeid"` // 证件类型ID
  4582. CARDNUM string `json:"cardnum" xorm:"CARDNUM"` // 证件号码(加密存储)
  4583. HALFBODYPHOTOURL string `json:"halfbodyphotourl" xorm:"HALFBODYPHOTOURL"` // 半身照地址
  4584. CARDFRONTPHOTOURL string `json:"cardfrontphotourl" xorm:"CARDFRONTPHOTOURL"` // 证件正面图片地址
  4585. CARDBACKPHOTOURL string `json:"cardbackphotourl" xorm:"CARDBACKPHOTOURL"` // 证件背面图片地址
  4586. BIZNATURE int32 `json:"biznature" xorm:"BIZNATURE"` // 企业性质( 企业) - 1:国有控股企业 2:集体控股企业 3:私人控股企业 4:港澳台商控股企业 5:外商控股企业 6:其它
  4587. BIZSCOPE string `json:"bizscope" xorm:"BIZSCOPE"` // 企业经营范围(企业)
  4588. LEGALPERSONNAME string `json:"legalpersonname" xorm:"LEGALPERSONNAME"` // 法人姓名(企业)
  4589. CONTACTNAME string `json:"contactname" xorm:"CONTACTNAME"` // 联系人
  4590. SEX int32 `json:"sex" xorm:"SEX"` // 用户性别 0: 女 1: 男
  4591. TELPHONE string `json:"telphone" xorm:"TELPHONE"` // 联系电话(加密存储)
  4592. MOBILE string `json:"mobile" xorm:"MOBILE"` // 手机号码(加密存储)
  4593. FAX string `json:"fax" xorm:"FAX"` // 传真(加密存储)
  4594. EMAIL string `json:"email" xorm:"EMAIL"` // 邮件(加密存储)
  4595. QQ string `json:"qq" xorm:"QQ"` // QQ(加密存储
  4596. WECHAT string `json:"wechat" xorm:"WECHAT"` // 微信(加密存储)
  4597. COUNTRYID int32 `json:"countryid" xorm:"COUNTRYID" form:"countryid"` // 国家
  4598. PROVINCEID int32 `json:"provinceid" xorm:"PROVINCEID" form:"provinceid"` // 省
  4599. CITYID int32 `json:"cityid" xorm:"CITYID" form:"cityid"` // 市
  4600. DISTRICTID int32 `json:"districtid" xorm:"DISTRICTID" form:"districtid"` // 地区
  4601. COMPANY string `json:"company" xorm:"COMPANY"` // 公司(个人)
  4602. ADDRESS string `json:"address" xorm:"ADDRESS"` // 地址
  4603. POSTALCODE string `json:"postalcode" xorm:"POSTALCODE"` // 邮政编码
  4604. CREATETIME string `json:"createtime" xorm:"CREATETIME2"` // 创建时间
  4605. CREATORID int64 `json:"creatorid" xorm:"CREATORID" form:"creatorid"` // 创建人
  4606. MODIFIERTIME string `json:"modifiertime" xorm:"MODIFIERTIME2"` // 修改时间
  4607. MODIFIERID int64 `json:"modifierid" xorm:"MODIFIERID" form:"modifierid"` // 修改人
  4608. REMARK string `json:"remark" xorm:"REMARK"` // 备注
  4609. WSKHINFO string `json:"wskhinfo" xorm:"WSKHINFO"` // 开户申请信息(JSON)
  4610. SIGNPDFURL string `json:"signpdfurl" xorm:"SIGNPDFURL"` // 签约pdf文件
  4611. LEGALCARDFRONTPHOTOURL string `json:"legalcardfrontphotourl" xorm:"LEGALCARDFRONTPHOTOURL"` // 法人身份证正面照地址
  4612. LEGALCARDBACKPHOTOURL string `json:"legalcardbackphotourl" xorm:"LEGALCARDBACKPHOTOURL"` // 法人身份证背面照地址
  4613. OTHERURL string `json:"otherurl" xorm:"OTHERURL"` // 其它图片地址[使用分号分隔]
  4614. HASENCRYPT int32 `json:"hasencrypt" xorm:"HASENCRYPT"` // 数据是否已加密 - 0:未加密 1:已加密
  4615. BANKNAME string `json:"bankname" xorm:"BANKNAME"` // 银行名称
  4616. BANKACCOUNT string `json:"bankaccount" xorm:"BANKACCOUNT"` // 银行帐号 (加密存储)
  4617. BANKCARDFRONTPHOTOURL string `json:"bankcardfrontphotourl" xorm:"BANKCARDFRONTPHOTOURL"` // 银行卡正面照地址
  4618. NEEDINVOICE int32 `json:"needinvoice" xorm:"NEEDINVOICE"` // 是否需要发票 - 0:不需要 1:需要
  4619. BANKID string `json:"bankid" xorm:"BANKID" form:"bankid"` // 银行编码
  4620. ATTACHMENT1 string `json:"attachment1" xorm:"ATTACHMENT1"` // 附件1
  4621. ATTACHMENT2 string `json:"attachment2" xorm:"ATTACHMENT2"` // 附件2
  4622. BANKACCOUNTNAME string `json:"bankaccountname" xorm:"BANKACCOUNTNAME"` // 收款人名称
  4623. HEADURL string `json:"headurl" xorm:"HEADURL"` // 头像地址
  4624. NICKNAME string `json:"nickname" xorm:"NICKNAME"` // 昵称:默认为名称脱敏(张**) 或 手机号脱敏(139****9999)
  4625. MOBILE2 string `json:"mobile2" xorm:"MOBILE2"` // 手机号码[明文-尚志]
  4626. BIZTYPE int32 `json:"biztype" xorm:"BIZTYPE"` // 企业类型 - 1:进口/生产 2:销售 3:零售 4:运输 5:仓储
  4627. PROXYSTATEMENTURL string `json:"proxystatementurl" xorm:"PROXYSTATEMENTURL"` // 授权委托书
  4628. CONTACTCARDFRONTPHOTOURL string `json:"contactcardfrontphotourl" xorm:"CONTACTCARDFRONTPHOTOURL"` // 联系人证件正面图片地址
  4629. CONTACTCARDBACKPHOTOURL string `json:"contactcardbackphotourl" xorm:"CONTACTCARDBACKPHOTOURL"` // 联系人证件背面图片地址
  4630. ATTACHMENT3 string `json:"attachment3" xorm:"ATTACHMENT3"` // 附件3
  4631. ATTACHMENT4 string `json:"attachment4" xorm:"ATTACHMENT4"` // 附件4
  4632. ATTACHMENT5 string `json:"attachment5" xorm:"ATTACHMENT5"` // 附件5
  4633. TAXPAYERNUM string `json:"taxpayernum" xorm:"TAXPAYERNUM"` // 纳税人识别号
  4634. BIRTHDAY string `json:"birthday" xorm:"BIRTHDAY2"` // 生日(个人:年月日)
  4635. CREDITQUOTA float64 `json:"creditquota" xorm:"CREDITQUOTA"` // 授信额度(金瑞)
  4636. }
  4637. func (r *WrDraftUserInfo) calc() {
  4638. r.CARDNUM = DecryptField(r.CARDNUM)
  4639. r.TELPHONE = DecryptField(r.TELPHONE) // 联系电话(加密存储)
  4640. r.MOBILE = DecryptField(r.MOBILE) // 手机号码(加密存储)
  4641. r.FAX = DecryptField(r.FAX) // 传真(加密存储)
  4642. r.EMAIL = DecryptField(r.EMAIL) // 邮件(加密存储)
  4643. r.QQ = DecryptField(r.QQ) // QQ(加密存储
  4644. r.WECHAT = DecryptField(r.WECHAT) // 微信(加密存储)
  4645. r.BANKACCOUNT = DecryptField(r.BANKACCOUNT) // 银行帐号 (加密存储)
  4646. }
  4647. func (r *WrDraftUserInfo) buildSql() string {
  4648. var sqlId utils.SQLVal = `
  4649. SELECT to_char(t.BIRTHDAY, 'yyyy-mm-dd hh24:mi:ss') BIRTHDAY2,
  4650. to_char(t.CREATETIME, 'yyyy-mm-dd hh24:mi:ss') CREATETIME2,
  4651. to_char(t.MODIFIERTIME, 'yyyy-mm-dd hh24:mi:ss') MODIFIERTIME2,
  4652. t.*
  4653. FROM DRAFT_USERINFO t
  4654. WHERE 1 = 1
  4655. `
  4656. sqlId.And("t.userid", r.USERID)
  4657. sqlId.AndEx("t.userstatus", r.USERSTATUS, r.USERSTATUS != 0)
  4658. return sqlId.String()
  4659. }
  4660. // GetDataEx 获取实名认证信息
  4661. func (r *WrDraftUserInfo) GetDataEx() (interface{}, error) {
  4662. sData := make([]WrDraftUserInfo, 0)
  4663. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  4664. for i := range sData {
  4665. sData[i].calc()
  4666. }
  4667. return sData, err
  4668. }
  4669. // DgFactoryItem 查询品牌和年份
  4670. type DgFactoryItem struct {
  4671. DGFACTORYITEMID int64 `json:"dgfactoryitemid" xorm:"DGFACTORYITEMID"` // 选择项ID(SEQ_DGFACTORYITEM)
  4672. DGFACTORYITEMTYPEID int64 `json:"dgfactoryitemtypeid" xorm:"DGFACTORYITEMTYPEID"` // 要素项类型
  4673. DGFACTORYITEMVALUE string `json:"dgfactoryitemvalue" xorm:"DGFACTORYITEMVALUE"` // 要素项值(类型为仓库时填写仓库名称)
  4674. ORDERINDEX int32 `json:"orderindex" xorm:"ORDERINDEX"` // 顺序
  4675. }
  4676. func (r *DgFactoryItem) buildSql() string {
  4677. var sqlId utils.SQLVal = `
  4678. select t.*
  4679. from DGFactoryItem t
  4680. where t.dgfactoryitemtypeid = %v
  4681. and t.deliverygoodsid = 0
  4682. and t.isvalid = 1
  4683. order by t.orderindex
  4684. `
  4685. sqlId.FormatParam(r.DGFACTORYITEMTYPEID)
  4686. return sqlId.String()
  4687. }
  4688. // GetDataEx 获取查询品牌和年份
  4689. func (r *DgFactoryItem) GetDataEx() ([]DgFactoryItem, error) {
  4690. sData := make([]DgFactoryItem, 0)
  4691. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  4692. return sData, err
  4693. }
  4694. // WrBrandAndYears 查询品牌和年份
  4695. type WrBrandAndYears struct {
  4696. BrandLst []DgFactoryItem `json:"brandlst"` // 品牌列表
  4697. YearsLst []DgFactoryItem `json:"yearslst"` // 年份列表
  4698. }
  4699. // GetDataEx 获取查询品牌和年份
  4700. func (r *WrBrandAndYears) GetDataEx() (interface{}, error) {
  4701. sData := make([]WrBrandAndYears, 0)
  4702. v := DgFactoryItem{DGFACTORYITEMTYPEID: 100}
  4703. brand, err := v.GetDataEx()
  4704. if err != nil {
  4705. return nil, err
  4706. }
  4707. v.DGFACTORYITEMTYPEID = 101
  4708. years, err2 := v.GetDataEx()
  4709. if err2 != nil {
  4710. return nil, err
  4711. }
  4712. d := WrBrandAndYears{
  4713. BrandLst: brand,
  4714. YearsLst: years,
  4715. }
  4716. sData = append(sData, d)
  4717. return sData, nil
  4718. }
  4719. // WrClientAdSpaceConfig 查询固定广告配置
  4720. type WrClientAdSpaceConfig struct {
  4721. ADSPACEID int32 `json:"adspaceid" xorm:"ADSPACEID"` // 广告位ID
  4722. ADSPACETYPE int32 `json:"adspacetype" xorm:"ADSPACETYPE"` // 广告位类型 - 1:固定广告位
  4723. ADSPACENAME string `json:"adspacename" xorm:"ADSPACENAME"` // 广告位名称
  4724. RECSIZE string `json:"recsize" xorm:"RECSIZE"` // 推荐尺寸
  4725. IMAGEPATH string `json:"imagepath" xorm:"IMAGEPATH"` // 图片
  4726. TITLE string `json:"title" xorm:"TITLE"` // 标题
  4727. URLTYPE int32 `json:"urltype" xorm:"URLTYPE"` // 链接类型 - 0:无 1:直接地址 2:商品ID 3:图片详情 4:App功能 5:微信小程序
  4728. URLCONTENT string `json:"urlcontent" xorm:"URLCONTENT"` // 链接(地址\商品ID\功能菜单Key\appid)
  4729. CREATEDATE string `json:"createdate" xorm:"CREATEDATE"` // 创建时间
  4730. UPDATEDATE string `json:"updatedate" xorm:"UPDATEDATE"` // 更新时间
  4731. MODIFIERID int64 `json:"modifierid" xorm:"MODIFIERID"` // 操作人
  4732. AREAUSERID int64 `json:"areauserid" xorm:"AREAUSERID"` // 所属机构ID
  4733. }
  4734. func (r *WrClientAdSpaceConfig) calc() {
  4735. }
  4736. func (r *WrClientAdSpaceConfig) buildSql() string {
  4737. var sqlId utils.SQLVal = `
  4738. SELECT t.ADSPACEID,
  4739. t.ADSPACETYPE,
  4740. t.ADSPACENAME,
  4741. t.RECSIZE,
  4742. t.IMAGEPATH,
  4743. t.TITLE,
  4744. t.URLTYPE,
  4745. t.URLCONTENT,
  4746. to_char(t.CREATEDATE, 'yyyy-mm-dd hh24:mi:ss') CREATEDATE,
  4747. to_char(t.UPDATEDATE, 'yyyy-mm-dd hh24:mi:ss') UPDATEDATE,
  4748. t.MODIFIERID,
  4749. t.AREAUSERID
  4750. FROM CLIENT_ADSPACECONFIG t
  4751. WHERE t.adspacetype=1
  4752. order by t.updatedate desc
  4753. `
  4754. return sqlId.String()
  4755. }
  4756. // GetDataEx 获取查询固定广告配置
  4757. func (r *WrClientAdSpaceConfig) GetDataEx() (interface{}, error) {
  4758. sData := make([]WrClientAdSpaceConfig, 0)
  4759. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  4760. for i := range sData {
  4761. sData[i].calc()
  4762. }
  4763. return sData, err
  4764. }
  4765. // Xhcpsellbackapply 回收鉴别申请表
  4766. type Xhcpsellbackapply struct {
  4767. SELLBACKAPPLYID string `json:"sellbackapplyid" xorm:"SELLBACKAPPLYID"` // 回收申请ID - SEQ_XHCP_SELLBACKAPPLY
  4768. PHONENUM string `json:"phonenum" xorm:"PHONENUM"` // 联系电话
  4769. GOODSSPEC int32 `json:"goodsspec" xorm:"GOODSSPEC"` // 商品规格 - 1:整件 2;整提 3:单罐 4:单盒
  4770. EXPIRYTYPE int32 `json:"expirytype" xorm:"EXPIRYTYPE"` // 寄售有效期 - 1:3天 2:7天 3:15天 4:长期
  4771. ISUNOPENED int32 `json:"isunopened" xorm:"ISUNOPENED"` // 是否原封 - 1:否 2:是
  4772. ZPFLAG int32 `json:"zpflag" xorm:"ZPFLAG"` // 皱皮类型[原封] - 1:无皱皮 2:小皱皮 3:皱皮
  4773. MPFLAG int32 `json:"mpflag" xorm:"MPFLAG"` // 磨皮类型[原封] - 1:无磨皮 2:小磨皮 3:磨皮
  4774. HOLEFLAG int32 `json:"holeflag" xorm:"HOLEFLAG"` // 是否破洞[原封] - 1:无破洞 2:破洞
  4775. OPENFLAG int32 `json:"openflag" xorm:"OPENFLAG"` // 是否非原封 - 1:无 2:皮张大、片张完整,无杂质、虫蛀、霉变、病变、烧皮。 3:片张较大、皮张基本完整,少量断片,少量病变、轻微虫蛀和烧皮。 4:皮张小、片张不完整,断片、碎片较多,有一定量杂质、病斑、虫蛀和烧皮。
  4776. APPLYREMARK string `json:"applyremark" xorm:"APPLYREMARK"` // 申请备注
  4777. APPLYSRC int32 `json:"applysrc" xorm:"APPLYSRC"` // 申请来源 - 1:管理端 2:终端
  4778. APPLYID int64 `json:"applyid" xorm:"APPLYID"` // 申请人
  4779. APPLYTIME time.Time `json:"applytime" xorm:"APPLYTIME"` // 申请时间
  4780. APPLYSTATUS int32 `json:"applystatus" xorm:"APPLYSTATUS"` // 申请状态 - 1:待确认 2:已处理
  4781. AUDITREMARK string `json:"auditremark" xorm:"AUDITREMARK"` // 审核备注
  4782. AUDITSRC int32 `json:"auditsrc" xorm:"AUDITSRC"` // 审核来源 - 1:管理端 2:终端
  4783. AUDITID int64 `json:"-" xorm:"AUDITID"` // 审核人
  4784. AUDITTIME time.Time `json:"-" xorm:"AUDITTIME"` // 审核时间
  4785. USERID int64 `json:"userid" xorm:"USERID" form:"userid" binding:"required"` // 所属用户ID
  4786. }
  4787. // TableName is XHCP_SELLBACKAPPLY
  4788. func (r *Xhcpsellbackapply) TableName() string {
  4789. return "XHCP_SELLBACKAPPLY"
  4790. }
  4791. func (r *Xhcpsellbackapply) calc() {
  4792. }
  4793. func (r *Xhcpsellbackapply) buildSql() string {
  4794. var sqlId utils.SQLVal = `
  4795. SELECT
  4796. to_char(t.SELLBACKAPPLYID) SELLBACKAPPLYID,
  4797. t.PHONENUM,
  4798. t.GOODSSPEC,
  4799. t.EXPIRYTYPE,
  4800. t.ISUNOPENED,
  4801. t.ZPFLAG,
  4802. t.MPFLAG,
  4803. t.HOLEFLAG,
  4804. t.OPENFLAG,
  4805. t.APPLYREMARK,
  4806. t.APPLYID,
  4807. to_char(t.APPLYTIME, 'yyyy-mm-dd hh24:mi:ss') APPLYTIME,
  4808. t.APPLYSTATUS,
  4809. t.APPLYSTATUS,
  4810. t.AUDITREMARK,
  4811. t.AUDITSRC,
  4812. t.AUDITID,
  4813. t.USERID
  4814. FROM XHCP_SELLBACKAPPLY t
  4815. WHERE 1 = 1
  4816. `
  4817. sqlId.And("t.userid", r.USERID)
  4818. return sqlId.String()
  4819. }
  4820. func (r *Xhcpsellbackapply) GetDataEx() (interface{}, error) {
  4821. sData := make([]Xhcpsellbackapply, 0)
  4822. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  4823. for i := range sData {
  4824. sData[i].calc()
  4825. }
  4826. return sData, err
  4827. }
  4828. // XhcpSellBackApplyEx 回收鉴别申请表
  4829. type XhcpSellBackApplyEx struct {
  4830. SELLBACKAPPLYID int64 `json:"-" xorm:"SELLBACKAPPLYID"` // 回收申请ID - SEQ_XHCP_SELLBACKAPPLY
  4831. PHONENUM string `json:"phonenum" xorm:"PHONENUM"` // 联系电话
  4832. GOODSSPEC int32 `json:"goodsspec" xorm:"GOODSSPEC"` // 商品规格 - 1:整件 2;整提 3:单罐 4:单盒
  4833. EXPIRYTYPE int32 `json:"expirytype" xorm:"EXPIRYTYPE"` // 寄售有效期 - 1:3天 2:7天 3:15天 4:长期
  4834. ISUNOPENED int32 `json:"isunopened" xorm:"ISUNOPENED"` // 是否原封 - 1:否 2:是
  4835. ZPFLAG int32 `json:"zpflag" xorm:"ZPFLAG"` // 皱皮类型[原封] - 1:无皱皮 2:小皱皮 3:皱皮
  4836. MPFLAG int32 `json:"mpflag" xorm:"MPFLAG"` // 磨皮类型[原封] - 1:无磨皮 2:小磨皮 3:磨皮
  4837. HOLEFLAG int32 `json:"holeflag" xorm:"HOLEFLAG"` // 是否破洞[原封] - 1:无破洞 2:破洞
  4838. OPENFLAG int32 `json:"openflag" xorm:"OPENFLAG"` // 是否非原封 - 1:无 2:皮张大、片张完整,无杂质、虫蛀、霉变、病变、烧皮。 3:片张较大、皮张基本完整,少量断片,少量病变、轻微虫蛀和烧皮。 4:皮张小、片张不完整,断片、碎片较多,有一定量杂质、病斑、虫蛀和烧皮。
  4839. APPLYREMARK string `json:"applyremark" xorm:"APPLYREMARK"` // 申请备注
  4840. APPLYSRC int32 `json:"-" xorm:"APPLYSRC"` // 申请来源 - 1:管理端 2:终端
  4841. APPLYID int64 `json:"-" xorm:"APPLYID"` // 申请人
  4842. // APPLYTIME time.Time `json:"-" xorm:"APPLYTIME default(sysdate)"` // 申请时间
  4843. APPLYSTATUS int32 `json:"-" xorm:"APPLYSTATUS"` // 申请状态 - 1:待确认 2:已处理
  4844. AUDITREMARK string `json:"-" xorm:"AUDITREMARK"` // 审核备注
  4845. AUDITSRC int32 `json:"-" xorm:"AUDITSRC"` // 审核来源 - 1:管理端 2:终端
  4846. USERID int64 `json:"userid" xorm:"USERID" form:"userid" binding:"required"` // 所属用户ID
  4847. }
  4848. // TableName is XHCP_SELLBACKAPPLY
  4849. func (r *XhcpSellBackApplyEx) TableName() string {
  4850. return "XHCP_SELLBACKAPPLY"
  4851. }
  4852. func (r *XhcpSellBackApplyEx) Insert() error {
  4853. engine := db.GetEngine()
  4854. session := engine.NewSession()
  4855. defer session.Close()
  4856. // add Begin() before any action
  4857. if err := session.Begin(); err != nil {
  4858. return err
  4859. }
  4860. // 自增ID
  4861. seqMap, err := session.QueryString("SELECT SEQ_XHCP_SELLBACKAPPLY.nextval SEQID FROM dual")
  4862. if err != nil {
  4863. return err
  4864. }
  4865. if len(seqMap) <= 0 {
  4866. return errors.New("获取自增ID错误")
  4867. }
  4868. seqID, _ := strconv.Atoi(seqMap[0]["SEQID"])
  4869. r.SELLBACKAPPLYID = int64(seqID)
  4870. r.APPLYSRC = 2
  4871. r.APPLYSTATUS = 1
  4872. // 关于oracle的问题还是要处理的
  4873. // r.APPLYTIME = time.Now()
  4874. // 插入数据
  4875. if _, err = session.Insert(r); err != nil {
  4876. return err
  4877. }
  4878. // add Commit() after all actions
  4879. return session.Commit()
  4880. }
  4881. // Wrtradetradequote 仓单贸易成交行情表
  4882. type Wrtradetradequote1 struct {
  4883. WRTRADEDETAILID string `json:"wrtradedetailid" xorm:"WRTRADEDETAILID"` // 仓单贸易成交单ID(321+Unix秒时间戳(10位)+xxxxxx)
  4884. TRADEDATE string `json:"tradedate" xorm:"TRADEDATE"` // 交易日(yyyyMMdd)
  4885. MARKETID int32 `json:"marketid" xorm:"MARKETID" form:"marketid"` // 市场ID
  4886. WRFACTORTYPEID int64 `json:"wrfactortypeid" xorm:"WRFACTORTYPEID"` // 仓单要素类型ID
  4887. DELIVERYGOODSID int32 `json:"deliverygoodsid" xorm:"DELIVERYGOODSID"` // 现货品种ID
  4888. WRSTANDARDID int32 `json:"wrstandardid" xorm:"WRSTANDARDID" form:"wrstandardid"` // 现货商品ID
  4889. BUYUSERID int64 `json:"buyuserid" xorm:"BUYUSERID"` // 买方用户ID
  4890. BUYACCOUNTID int64 `json:"buyaccountid" xorm:"BUYACCOUNTID"` // 买方账号ID
  4891. SELLUSERID int64 `json:"selluserid" xorm:"SELLUSERID"` // 卖方用户ID
  4892. SELLACCOUNTID int64 `json:"sellaccountid" xorm:"SELLACCOUNTID"` // 卖方账号ID
  4893. TRADETIME time.Time `json:"tradetime" xorm:"TRADETIME"` // 成交时间
  4894. TRADEPRICE float64 `json:"tradeprice" xorm:"TRADEPRICE"` // 成交价格
  4895. TRADEQTY int64 `json:"tradeqty" xorm:"TRADEQTY"` // 成交数量
  4896. TRADEAMOUNT float64 `json:"tradeamount" xorm:"TRADEAMOUNT"` // 成交金额
  4897. BEGINDATE string `json:"begindate" form:"begindate"` // 开始日期(结果含开始日期) yyyymmdd
  4898. ENDDATE string `json:"enddate" form:"enddate"` // 结束日期(结果含结束日期) yyyymmdd
  4899. }
  4900. // TableName is WRTRADE_TRADEQUOTE
  4901. func (r *Wrtradetradequote1) TableName() string {
  4902. return "WRTRADE_TRADEQUOTE"
  4903. }
  4904. func (r *Wrtradetradequote1) calc() {
  4905. }
  4906. func (r *Wrtradetradequote1) buildSql() string {
  4907. var sqlId utils.SQLVal = `
  4908. SELECT
  4909. to_char(t.WRTRADEDETAILID) WRTRADEDETAILID,
  4910. t.TRADEDATE,
  4911. t.MARKETID,
  4912. t.WRFACTORTYPEID,
  4913. t.DELIVERYGOODSID,
  4914. t.WRSTANDARDID,
  4915. t.BUYUSERID,
  4916. t.BUYACCOUNTID,
  4917. t.SELLUSERID,
  4918. t.SELLACCOUNTID,
  4919. t.TRADETIME,
  4920. t.TRADEPRICE,
  4921. t.TRADEQTY,
  4922. t.TRADEAMOUNT
  4923. FROM WRTRADE_TRADEQUOTE t
  4924. WHERE
  4925. t.WRSTANDARDID = %v
  4926. AND
  4927. t.TRADETIME BETWEEN TO_DATE('%v' || ' 000000', 'yyyymmdd hh24:mi:ss') and TO_DATE('%v' || ' 235959', 'yyyymmdd hh24:mi:ss')
  4928. `
  4929. sqlId.FormatParam(r.WRSTANDARDID, r.BEGINDATE, r.ENDDATE)
  4930. sqlId.AndEx("t.MARKETID", r.MARKETID, r.MARKETID > 0)
  4931. return sqlId.String()
  4932. }
  4933. func (r *Wrtradetradequote1) GetDataEx() (interface{}, error) {
  4934. sData := make([]Wrtradetradequote1, 0)
  4935. err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
  4936. for i := range sData {
  4937. sData[i].calc()
  4938. }
  4939. return sData, err
  4940. }