wrTrade2.go 226 KB

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