RANetwork.m 412 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322
  1. //
  2. // iSalesNetwork.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-6-20.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RANetwork.h"
  9. #import "RAUtils.h"
  10. #import "RASingleton.h"
  11. #import "GoogleAnalyst.h"
  12. #import "ERPUtils.h"
  13. #import "RAConvertor.h"
  14. #import "ActiveViewController.h"
  15. #import "ZipArchive.h"
  16. #import "RADataProvider.h"
  17. NSString *const kScreenName = @"kScreenName";
  18. NSString *const kAction = @"kAction";
  19. NSString *const kExtra = @"kExtra";
  20. NSString *const ScreenCodeLoginView = @"Login Screen";
  21. NSString *const ScreenCodeHomeView = @"Home Screen";
  22. NSString *const ScreenCodeCategory = @"Category Screen";
  23. NSString *const ScreenCodeCart = @"Cart Sceen";
  24. NSString *const ScreenCodeOrderList = @"Order History Screen";
  25. NSString *const ScreenCodeSearch = @"Search Screen";
  26. NSString *const ScreenCodeAccount = @"Account Screen";
  27. NSString *const ScreenCodeWishList = @"Wish List Screen";
  28. NSString *const ScreenCodePortfolio = @"Portfolio Screen";
  29. NSString *const ScreenCodeViewPortfolios = @"View Portfolios Screen";
  30. NSString *const ScreenCodeCamScan = @"Cam Scan Screen";
  31. NSString *const ScreenCodeScannerSetting = @"Scanner Setting Screen";
  32. NSString *const ScreenCodeOfflineSetting = @"Offline Setting Screen";
  33. NSString *const ScreenCodePlaceOrder = @"Place Order Screen";
  34. NSString *const ScreenCodeCustomerInfo = @"Customer Information Screen";
  35. NSString *const ScreenCodeNewCustomer = @"New Customer Screen";
  36. NSString *const ScreenCodeEditCustomer = @"Edit Customer Information Screen";
  37. NSString *const ScreenCodeModelInfo = @"Model Information Screen";
  38. NSString *const ScreenCodeOrderInfo = @"Order Information Screeen";
  39. NSString *const ScreenCodeUserSign = @"User Sign Screen";
  40. NSString *const ScreenCodeNewAddress = @"New Address Screen";
  41. NSString *const ScreenCodeAdvanceSearch = @"Account Advance Search Screen";
  42. NSString *const ScreenCodeCreatePortfolio = @"Create Portfolio Screen";
  43. NSString *const ScreenCodeParticularCategory = @"Particular Category Screen";
  44. NSString *const ScreenCodeEditPortfolio = @"Edit Portfolio Screen";
  45. NSString *const ScreenCodePriceSetting = @"Price Setting Screen";
  46. NSString *const ScreenCodeCategoryPrice = @"Category Price Screen";
  47. NSString *const ScreenCodeSetCatetoryPrice = @"Set Category Price Screen";
  48. NSString *const ScreenCodeUploadImage = @"Upload Image Screen";
  49. NSString *const ScreenCodeOfflineSync = @"Offline Sync Screen";
  50. @implementation RANetwork
  51. +(NSMutableDictionary*) prepare_additional_params:(NSMutableDictionary* ) params
  52. {
  53. AppDelegate *appDelegate = nil;
  54. //some UI methods ej
  55. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  56. // if(appDelegate.user!=nil)
  57. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.user key:@"usai"] forKey:@"user"];
  58. // if(appDelegate.password!=nil)
  59. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.password key:@"usai"] forKey:@"password"];
  60. //
  61. //
  62. //
  63. // if(appDelegate.user!=nil)
  64. // [params setValue:appDelegate.user forKey:@"user"];
  65. //
  66. // if(appDelegate.contact_id!=nil)
  67. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  68. // if(appDelegate.password!=nil)
  69. // [params setValue:appDelegate.password forKey:@"password"];
  70. //
  71. // [params setValue:appDelegate.build forKey:@"app_ver"];
  72. //
  73. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  74. // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  75. // [params setValue:short_version forKey:@"app_short_ver"];
  76. //
  77. //
  78. //
  79. //#if TARGET_IPHONE_SIMULATOR//模拟器
  80. // [params setValue:@"simulator_uuid" forKey:@"deviceid"];
  81. //#elif TARGET_OS_IPHONE//真机
  82. // UIDevice * dev = [UIDevice currentDevice];
  83. // NSUUID* uuid =dev.identifierForVendor;
  84. // [params setValue:uuid.UUIDString forKey:@"deviceid"];
  85. //#endif
  86. if(appDelegate.user!=nil)
  87. [params setValue:appDelegate.user forKey:@"user"];
  88. if(appDelegate.password!=nil)
  89. [params setValue:appDelegate.password forKey:@"password"];
  90. if(appDelegate.ipad_perm!=nil)
  91. [params setValue:appDelegate.ipad_perm forKey:@"ipad_perm"];
  92. [params setValue:appDelegate.build forKey:@"app_ver"];
  93. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  94. NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  95. [params setValue:short_version forKey:@"app_short_ver"];
  96. #if TARGET_IPHONE_SIMULATOR//模拟器
  97. [params setValue:@"simulator_uuid" forKey:@"idfv"];
  98. #elif TARGET_OS_IPHONE//真机
  99. UIDevice * dev = [UIDevice currentDevice];
  100. NSUUID* uuid =dev.identifierForVendor;
  101. [params setValue:uuid.UUIDString forKey:@"idfv"];
  102. #endif
  103. //
  104. // NSString *userAction = [params valueForKey:kAction];
  105. // NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  106. // if ([userAction isEqualToString:@"Login"]) {
  107. // if (!extra) {
  108. // extra = [NSMutableDictionary dictionary];
  109. // }
  110. // [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  111. // }
  112. return params;
  113. }
  114. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString *) file //delegate:(id < NSURLConnectionDelegate >)delegate
  115. {
  116. // NSString* e=[AESCrypt AES128Encrypt:@"密码学中的高级加密标准(Advanced Encryption Standard,AES),又称 高级加密标准Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用。经过五年的甄选流程,高级加密标准由美国国家标准与技术研究院 (NIST)于2001年11月26日发布于FIPS PUB 197,并在2002年5月26日成为有效的标准。2006年,高级加密标准已然成为对称密钥加密中最流行的算法之一。 " key:@"usai2010"];
  117. // DebugLog(e);
  118. // NSString* d=[AESCrypt decrypt:@"VzB4+lENfbzWX7ggHh2Os1P69l5YBzKmM51yqA37AfoKgPY8bJgdK8M4WvF+wDyOsLWP\/o8H5+bHMivQp1u8wM2QV7SYzgzPwV85QKtYWIzEgLe9T0HO69EdutWz7k1rdAT\/mftsRin0Hy5SHk7txTZT\/zPH5X+FQiExCTFm5Zus39HYvp+VxCX4+kYeymn8B63AUd3mRQyscUvDjfgU2olKR\/TP8PV3g+VQMZxpKfol3P1iOtz3XQlHZV0pM6SAf+SwT0sPfrdn6CZFfNQlrKA9QjMrnBdMeSCquSIWXnmLv6okzvnlJnT0SjvJuUeqNdBC5EZ0ACnhI0MrXVZEsq1EuM9al7oPzvU5EZbjZpmx+fSFIkMzTT8bYClTnG1bsL1MCcU4pSODDorUj8zalA==" password:@"usai2010"];
  119. params = [self prepare_additional_params:params];
  120. DebugLog(@"\n++++++++++++++++++++++Request++++++++++++++++++++++\n%@\n++++++++++++++++++++++Params++++++++++++++++++++++\n%@\n",url,[RAConvertor dict2string:params]);
  121. return [super get_json:url parameters:params file:(NSString*)file err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  122. int result=[[jsobj valueForKey:@"result"] intValue];
  123. // UIApplication * app = [UIApplication sharedApplication];
  124. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  125. switch (result) {
  126. case 0:
  127. [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  128. break;
  129. case 1:
  130. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  131. break;
  132. case 2:
  133. [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  134. break;
  135. case 8:
  136. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  137. break;
  138. case 9:
  139. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  140. break;
  141. case 99:
  142. [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  143. break;
  144. default:
  145. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  146. break;
  147. }
  148. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  149. // {
  150. // [jsobj setValue:@"9" forKey:@"result"];
  151. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  152. // }
  153. return jsobj;
  154. } decrypt_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  155. return nil;
  156. // NSString* base64str = jsobj[@"str"];
  157. // NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"usai2010"];
  158. // jsobj=[[RAUtils string2dict:decryptstr] mutableCopy];
  159. // return jsobj;
  160. }];
  161. /*
  162. */
  163. return nil;
  164. }
  165. +(void) LoadImage:(NSString*) url into:(UIImageView*) container
  166. {
  167. DebugLog(@"LoadImage:(NSString*) url in:(UIImageView*) container");
  168. NSString* file_name=[url lastPathComponent];
  169. NSData* img_data = [iSalesDB load_cached_img:file_name loadFrom:url];
  170. if(img_data==nil)
  171. {
  172. DebugLog(@"IMG NOT CACHED %@",file_name);
  173. img_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
  174. [iSalesDB cache_img:img_data filename:file_name saveTo:url];
  175. //load from internet;
  176. }
  177. if(img_data!=nil)
  178. {
  179. UIImage * img =[UIImage imageWithData:img_data];
  180. if(img==nil)
  181. DebugLog(@"UIIMAGE IS NIL! %@",file_name);
  182. else
  183. dispatch_async(dispatch_get_main_queue(), ^{
  184. container.image =img;
  185. });
  186. }
  187. else
  188. {
  189. DebugLog(@"IMG DOWNLOAD FAILED! %@",file_name);
  190. }
  191. }
  192. //+(NSData*)fake_json:(NSString*) url
  193. //{
  194. // NSString* jsonfile = nil;
  195. // if([url isEqualToString:URL_UPDATE_AUTH])
  196. // {
  197. // jsonfile=@"login";
  198. //
  199. // }
  200. // else if([url isEqualToString:URL_REQUEST_CATMENU])
  201. // {
  202. // jsonfile=@"categorymenu";
  203. // }
  204. // else if([url isEqualToString:URL_LOAD_HOME])
  205. // {
  206. // jsonfile=@"homepage";
  207. // }
  208. // else if([url isEqualToString:URL_SEARCH])
  209. // {
  210. // jsonfile=@"search";
  211. // }
  212. // else if([url isEqualToString:URL_CATEGORY_LOADMORE])
  213. // {
  214. // jsonfile=@"category_more";
  215. // }else if([url isEqualToString:URL_ITEM_DETAIL])
  216. // {
  217. // jsonfile=@"detail";
  218. // }else if([url isEqualToString:URL_CART])
  219. // {
  220. // jsonfile=@"cart";
  221. // }else if([url isEqualToString:URL_ORDER_LIST])
  222. // {
  223. // jsonfile=@"orderlist";
  224. // }
  225. //// else if([url isEqualToString:URL_ORDER_INFO])
  226. //// {
  227. //// jsonfile=@"orderinfo";
  228. //// }
  229. //// else if([url isEqualToString:URL_ORDER_INFO])
  230. //// {
  231. //// jsonfile=@"orderinfo2label";
  232. //// }
  233. //
  234. //
  235. //
  236. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:jsonfile ofType:@"json" ]];
  237. // NSMutableString *result = [[NSMutableString alloc] initWithData:json encoding:NSUTF8StringEncoding];
  238. //
  239. // DebugLog(@"result: \n%@",result);
  240. // return json;
  241. //}
  242. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
  243. {
  244. NSString *screenName = [params valueForKey:kScreenName];
  245. NSString *userAction = [params valueForKey:kAction];
  246. NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  247. if ([userAction isEqualToString:@"Login"]) {
  248. if (!extra) {
  249. extra = [NSMutableDictionary dictionary];
  250. }
  251. [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  252. }
  253. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  254. [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  255. #endif
  256. return [self get_json:url parameters:params file:nil];
  257. // {
  258. // int retry = 0;
  259. //
  260. // __block AppDelegate *appDelegate = nil;
  261. //
  262. // dispatch_sync(dispatch_get_main_queue(), ^{
  263. // //some UI methods ej
  264. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  265. // });
  266. // if(appDelegate.user!=nil)
  267. // [params setValue:appDelegate.user forKey:@"user"];
  268. // if(appDelegate.password!=nil)
  269. // [params setValue:appDelegate.password forKey:@"password"];
  270. //
  271. //
  272. // if(appDelegate.ipad_perm!=nil)
  273. // [params setValue:appDelegate.ipad_perm forKey:@"ipad_perm"];
  274. //
  275. // [params setValue:appDelegate.build forKey:@"app_ver"];
  276. //
  277. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  278. // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  279. // [params setValue:short_version forKey:@"app_short_ver"];
  280. //
  281. // UIDevice * dev = [UIDevice currentDevice];
  282. // NSUUID* uuid =dev.identifierForVendor;
  283. //#if TARGET_IPHONE_SIMULATOR//模拟器
  284. // [params setValue:@"simulator_uuid" forKey:@"idfv"];
  285. //#elif TARGET_OS_IPHONE//真机
  286. // [params setValue:uuid.UUIDString forKey:@"idfv"];
  287. //#endif
  288. //
  289. //// NSString *screenName = [params valueForKey:kScreenName];
  290. //// NSString *userAction = [params valueForKey:kAction];
  291. //// NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  292. //// if ([userAction isEqualToString:@"Login"]) {
  293. //// if (!extra) {
  294. //// extra = [NSMutableDictionary dictionary];
  295. //// }
  296. //// [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  297. //// }
  298. //
  299. //repeat:
  300. // {
  301. //
  302. // // return [self fake_json:url];
  303. //
  304. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  305. // //分界线的标识符
  306. // NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
  307. // //根据url初始化request
  308. // NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
  309. // cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
  310. // timeoutInterval:JSON_TIMEOUT];
  311. // //分界线 --AaB03x
  312. // NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
  313. // //结束符 AaB03x--
  314. // NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
  315. // //要上传的图片
  316. // // UIImage *image=[params objectForKey:@"pic"];
  317. // //得到图片的data
  318. // // NSData* data = UIImagePNGRepresentation(image);
  319. // //http body的字符串
  320. // NSMutableString *body=[[NSMutableString alloc]init];
  321. //
  322. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  323. // // [params setValue:@"handset_login" forKey:@"action"];
  324. // // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  325. //
  326. // // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  327. // // [params setValue:password forKey:@"password"];
  328. // // [params setValue:[NSString stringWithFormat:@"%d",ver] forKey:@"auth_ver"];
  329. //
  330. //
  331. //
  332. // // [headers setValue:headQuerlString forKey:@"param"];
  333. //
  334. // //参数的集合的所有key的集合
  335. // NSArray *keys= [params allKeys];
  336. // DebugLog(@"================parms==================");
  337. // //遍历keys
  338. // for(int i=0;i<[keys count];i++)
  339. // {
  340. // //得到当前key
  341. // NSString *key=[keys objectAtIndex:i];
  342. // //如果key不是pic,说明value是字符类型,比如name:Boris
  343. // if(![key isEqualToString:@"pic"])
  344. // {
  345. // //添加分界线,换行
  346. // [body appendFormat:@"%@\r\n",MPboundary];
  347. // //添加字段名称,换2行
  348. // [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
  349. // //添加字段的值
  350. // [body appendFormat:@"%@\r\n",[params objectForKey:key]];
  351. // DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
  352. // }
  353. // }
  354. // DebugLog(@"================parms==================");
  355. // ////添加分界线,换行
  356. // [body appendFormat:@"%@\r\n",MPboundary];
  357. // //声明pic字段,文件名为boris.png
  358. // [body appendFormat:@"Content-Disposition: form-data; name=\"pic\"; filename=\"boris.png\"\r\n"];
  359. // //声明上传文件的格式
  360. // [body appendFormat:@"Content-Type: image/png\r\n\r\n"];
  361. //
  362. // //声明结束符:--AaB03x--
  363. // NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
  364. // //声明myRequestData,用来放入http body
  365. // NSMutableData *myRequestData=[NSMutableData data];
  366. // //将body字符串转化为UTF8格式的二进制
  367. // [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
  368. // //将image的data加入
  369. // // [myRequestData appendData:data];
  370. // //加入结束符--AaB03x--
  371. // [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
  372. //
  373. // //设置HTTPHeader中Content-Type的值
  374. // NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
  375. // //设置HTTPHeader
  376. // [request setValue:content forHTTPHeaderField:@"Content-Type"];
  377. //
  378. // // 关闭keep alive
  379. // [request setValue:@"close" forHTTPHeaderField:@"Connection"];
  380. // //设置Content-Length
  381. // [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[myRequestData length]] forHTTPHeaderField:@"Content-Length"];
  382. // //设置http body
  383. // [request setHTTPBody:myRequestData];
  384. // //http method
  385. // [request setHTTPMethod:@"POST"];
  386. //
  387. //
  388. // NSHTTPURLResponse* urlResponse = nil;
  389. //
  390. // NSError *error = nil;
  391. //
  392. // NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  393. //
  394. //
  395. // DebugLog(@"url: %@",url);
  396. //
  397. // DebugLog(@"response: %@",[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode]);
  398. //
  399. // if (responseData==nil) {
  400. //
  401. //// DebugLog(@"response error:%@", [error localizedDescription]);
  402. //
  403. //
  404. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  405. // //#define RESULT_FALSE 0
  406. // //#define RESULT_TRUE 2
  407. // //#define RESULT_NET_ERROR -3
  408. // //#define RESULT_NET_NOTAVAILABLE -4
  409. // //#define RESULT_ERROR -5
  410. // //#define RESULT_LOCALFILE_ERROR -7
  411. // //#define RESULT_USERAUTH_ERROR -9
  412. // //#define RESULT_UPDATE_USERAUTH_ERROR -11
  413. // //#define RESULT_SESSION_EXPIRED -13
  414. // //#define RESULT_VER_LOW
  415. //
  416. // // NSString * moreinfo = error.description ;
  417. //
  418. // NSString* err_msg = [error localizedDescription];
  419. //
  420. //
  421. // //-----------------retry 3 times for error code -1005------------------------
  422. // if(error.code==-1005&&retry<3)
  423. // {
  424. // retry++;
  425. // goto repeat;
  426. //
  427. // }
  428. // //-----------------end retry 3 times for error code -1005------------------------
  429. //
  430. // NSDictionary* error_json = [RAUtils error_dict:error];
  431. // [ret setObject:error_json forKey:@"err_obj"];
  432. // NSString* resp_msg= nil;
  433. //
  434. // if(err_msg.length==0)
  435. // {
  436. // err_msg =[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode];
  437. // resp_msg = err_msg;
  438. // }
  439. // [ret setValue:[NSString stringWithFormat:@"%d",RESULT_NET_ERROR] forKey:@"result"];
  440. // [ret setValue:err_msg forKey:@"err_msg"];
  441. // [ret setValue:resp_msg forKey:@"resp_msg"];
  442. // [ret setValue:[NSString stringWithFormat:@"%ld",(long)urlResponse.statusCode] forKey:@"resp_code"];
  443. //
  444. //
  445. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ret
  446. // options:0
  447. // error:nil];
  448. // if(![url isEqualToString:URL_ERR_LOG])
  449. // {
  450. // [RANetwork err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:[RAConvertor dict2string:ret]] module:url code:RESULT_NET_ERROR];
  451. // }
  452. //#if defined(BUILD_NPD)// || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  453. // [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  454. //#endif
  455. // return jsonData;
  456. //
  457. // }
  458. // else
  459. // {
  460. // NSString* err_msg = [error localizedDescription];
  461. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  462. //
  463. // DebugLog(@"data string: %@",str);
  464. // NSError *error1 = nil;
  465. //
  466. // NSMutableDictionary* jsobj = [[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error1] mutableCopy];
  467. //
  468. // if(jsobj==nil)// 服务器返回不是json
  469. // {
  470. //
  471. // jsobj=[[NSMutableDictionary alloc] init];
  472. // [jsobj setValue:@"1" forKey:@"result"];
  473. //
  474. // }
  475. //
  476. // int result=[[jsobj valueForKey:@"result"] intValue];
  477. // UIApplication * app = [UIApplication sharedApplication];
  478. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  479. // NSString* mode =[jsobj valueForKey:@"mode"];
  480. // [appDelegate SetMode:mode];
  481. // switch (result) {
  482. // case 0:
  483. // [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  484. // break;
  485. // case 1:
  486. // [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  487. // break;
  488. // case 2:
  489. // [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  490. // break;
  491. // case 8:
  492. // [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  493. // break;
  494. // case 9:
  495. // [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  496. // break;
  497. // case 99:
  498. // [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  499. // break;
  500. // default:
  501. // [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  502. // break;
  503. // }
  504. //
  505. //
  506. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  507. // {
  508. // [jsobj setValue:@"9" forKey:@"result"];
  509. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  510. // }
  511. //
  512. // if(![url isEqualToString:URL_ERR_LOG]&&![url isEqualToString:URL_DOWNLOAD_OFFLINE]/*&&result!=-3*/&&result!=2&&result!=99)
  513. // {
  514. // [RANetwork err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:str] module:url code:result];
  515. // }
  516. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsobj
  517. // options:0
  518. // error:nil];
  519. //#if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  520. // [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  521. //#endif
  522. // return jsonData;
  523. //
  524. // }
  525. //
  526. // return responseData;
  527. // }
  528. //}
  529. }
  530. //+(NSDictionary*)request_Editor:(NSString*) sourceid editor:(NSString*)editor
  531. //{
  532. //
  533. //}
  534. +(NSDictionary*) delete_portfoliolist:(NSString* ) listid
  535. {
  536. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  537. __block AppDelegate *appDelegate = nil;
  538. dispatch_sync(dispatch_get_main_queue(), ^{
  539. //some UI methods ej
  540. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  541. });
  542. if(appDelegate.user!=nil)
  543. [params setValue:appDelegate.user forKey:@"user"];
  544. if(appDelegate.contact_id!=nil)
  545. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  546. if(appDelegate.password!=nil)
  547. [params setValue:appDelegate.password forKey:@"password"];
  548. [params setValue:listid forKey:@"tearsheetsId"];
  549. // [params setValue:editor forKey:@"editor"];
  550. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  551. // [params setValue:@"Delete Portfolio" forKey:kAction];
  552. NSData* json = nil;
  553. if(appDelegate.offline_mode)
  554. {
  555. json = [OLDataProvider offline_removePDF:params];
  556. } else {
  557. if(![self IsNetworkAvailable])
  558. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  559. json=[self get_json:URL_PORTFOLIOLIST_REMOVE parameters:params];
  560. }
  561. if(json!=nil)
  562. {
  563. NSError *error=nil;
  564. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  565. return jsobj;
  566. }
  567. else
  568. return nil;
  569. }
  570. +(NSDictionary*) portfolio_remove:(NSString* ) item_ids
  571. {
  572. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  573. __block AppDelegate *appDelegate = nil;
  574. dispatch_sync(dispatch_get_main_queue(), ^{
  575. //some UI methods ej
  576. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  577. });
  578. if(appDelegate.user!=nil)
  579. [params setValue:appDelegate.user forKey:@"user"];
  580. if(appDelegate.contact_id!=nil)
  581. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  582. if(appDelegate.password!=nil)
  583. [params setValue:appDelegate.password forKey:@"password"];
  584. [params setValue:item_ids forKey:@"portfolioId"];
  585. // [params setValue:editor forKey:@"editor"];
  586. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  587. NSData* json = nil;
  588. if(appDelegate.offline_mode)
  589. {
  590. json = [OLDataProvider offline_removePortfolio:params];
  591. } else {
  592. if(![self IsNetworkAvailable])
  593. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  594. json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  595. }
  596. if(json!=nil)
  597. {
  598. NSError *error=nil;
  599. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  600. int result = [[jsobj valueForKey:@"result"] intValue];
  601. if (result==2)
  602. {
  603. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  604. [appDelegate update_count_mark];
  605. }
  606. return jsobj;
  607. }
  608. else
  609. return nil;
  610. }
  611. //+(NSDictionary*) watchlist_remove:(NSString* ) item_ids
  612. //{
  613. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  614. // __block AppDelegate *appDelegate = nil;
  615. //
  616. // dispatch_sync(dispatch_get_main_queue(), ^{
  617. // //some UI methods ej
  618. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  619. // });
  620. // if(appDelegate.user!=nil)
  621. // [params setValue:appDelegate.user forKey:@"user"];
  622. // if(appDelegate.contact_id!=nil)
  623. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  624. // if(appDelegate.password!=nil)
  625. // [params setValue:appDelegate.password forKey:@"password"];
  626. // [params setValue:item_ids forKey:@"collectId"];
  627. // // [params setValue:editor forKey:@"editor"];
  628. //
  629. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  630. //
  631. // if(appDelegate.offline_mode)
  632. // {
  633. // return [OLDataProvider offline_deletewishlist:params];
  634. // }
  635. // if(![self IsNetworkAvailable])
  636. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  637. //
  638. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  639. // if(json!=nil)
  640. // {
  641. // NSError *error=nil;
  642. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  643. // int result = [[jsobj valueForKey:@"result"] intValue];
  644. //
  645. // if (result==2)
  646. // {
  647. //
  648. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  649. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  650. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  651. //
  652. // [appDelegate update_count_mark];
  653. // }
  654. // return jsobj;
  655. // }
  656. // else
  657. // return nil;
  658. //}
  659. //+(NSDictionary*) move_cart2wish:(NSString* ) item_ids
  660. //{
  661. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  662. // __block AppDelegate *appDelegate = nil;
  663. //
  664. // dispatch_sync(dispatch_get_main_queue(), ^{
  665. // //some UI methods ej
  666. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  667. // });
  668. // if(appDelegate.user!=nil)
  669. // [params setValue:appDelegate.user forKey:@"user"];
  670. // if(appDelegate.contact_id!=nil)
  671. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  672. // if(appDelegate.password!=nil)
  673. // [params setValue:appDelegate.password forKey:@"password"];
  674. // if(appDelegate.order_code!=nil)
  675. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  676. // [params setValue:item_ids forKey:@"cartItemId"];
  677. // // [params setValue:editor forKey:@"editor"];
  678. //
  679. // [params setValue:ScreenCodeCart forKey:kScreenName];
  680. // // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  681. //
  682. // NSData* json = nil;
  683. // if(appDelegate.offline_mode)
  684. // {
  685. // json= [OLDataProvider offline_movecart2wish:params];
  686. // }
  687. // else
  688. // {
  689. // if(![self IsNetworkAvailable])
  690. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  691. //
  692. // json=[self get_json:URL_CART2WISH parameters:params];
  693. // }
  694. // if(json!=nil)
  695. // {
  696. // NSError *error=nil;
  697. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  698. // int result = [[jsobj valueForKey:@"result"] intValue];
  699. //
  700. // if (result==2)
  701. // {
  702. //
  703. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  704. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  705. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  706. //
  707. // [appDelegate update_count_mark];
  708. // }
  709. // return jsobj;
  710. // }
  711. // else
  712. // return nil;
  713. //}
  714. //+(NSDictionary*) move_wish2cart:(NSString* ) item_ids
  715. //{
  716. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  717. // __block AppDelegate *appDelegate = nil;
  718. //
  719. // dispatch_sync(dispatch_get_main_queue(), ^{
  720. // //some UI methods ej
  721. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  722. // });
  723. // if(appDelegate.user!=nil)
  724. // [params setValue:appDelegate.user forKey:@"user"];
  725. // if(appDelegate.contact_id!=nil)
  726. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  727. // if(appDelegate.password!=nil)
  728. // [params setValue:appDelegate.password forKey:@"password"];
  729. // if(appDelegate.order_code!=nil)
  730. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  731. // [params setValue:item_ids forKey:@"collectId"];
  732. // // [params setValue:editor forKey:@"editor"];
  733. //
  734. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  735. // [params setValue:@"Move To Cart" forKey:kAction];
  736. //
  737. // NSData *json = nil;
  738. // if(appDelegate.offline_mode)
  739. // {
  740. // json = [OLDataProvider offline_movewish2cart:params];
  741. // } else {
  742. // if(![self IsNetworkAvailable])
  743. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  744. //
  745. // json=[self get_json:URL_WISH2CART parameters:params];
  746. // }
  747. //
  748. // if(json!=nil)
  749. // {
  750. // NSError *error=nil;
  751. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  752. // int result = [[jsobj valueForKey:@"result"] intValue];
  753. //
  754. // if (result==2)
  755. // {
  756. //
  757. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  758. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  759. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  760. //
  761. // [appDelegate update_count_mark];
  762. // }
  763. // return jsobj;
  764. // }
  765. // else
  766. // return nil;
  767. //}
  768. //+(NSDictionary*) cart_remove:(NSString* ) item_ids
  769. //{
  770. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  771. // __block AppDelegate *appDelegate = nil;
  772. //
  773. // dispatch_sync(dispatch_get_main_queue(), ^{
  774. // //some UI methods ej
  775. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  776. // });
  777. // if(appDelegate.user!=nil)
  778. // [params setValue:appDelegate.user forKey:@"user"];
  779. // if(appDelegate.contact_id!=nil)
  780. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  781. // if(appDelegate.password!=nil)
  782. // [params setValue:appDelegate.password forKey:@"password"];
  783. //
  784. // if(appDelegate.order_code!=nil)
  785. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  786. // [params setValue:item_ids forKey:@"cartItemId"];
  787. // // [params setValue:editor forKey:@"editor"];
  788. //
  789. // [params setValue:ScreenCodeCart forKey:kScreenName];
  790. // // [params setValue:@"" forKey:kAction];
  791. //
  792. // NSData* json=nil;
  793. // if(appDelegate.offline_mode)
  794. // {
  795. // json= [OLDataProvider offline_cartremove:params];
  796. // }
  797. // else
  798. // {
  799. // if(![self IsNetworkAvailable])
  800. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  801. //
  802. // json=[self get_json:URL_CART_REMOVE parameters:params];
  803. // }
  804. // if(json!=nil)
  805. // {
  806. // NSError *error=nil;
  807. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  808. //
  809. // int result = [[jsobj valueForKey:@"result"] intValue];
  810. //
  811. // if (result==2)
  812. // {
  813. //
  814. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  815. //
  816. //
  817. // [appDelegate update_count_mark];
  818. // }
  819. // return jsobj;
  820. // }
  821. // else
  822. // return nil;
  823. //}
  824. //+(NSDictionary*) cart_check:(NSString* ) item_ids
  825. //{
  826. // return nil;
  827. // if(![self IsNetworkAvailable])
  828. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  829. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  830. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  831. // if(appDelegate.user!=nil)
  832. // [params setValue:appDelegate.user forKey:@"user"];
  833. // if(appDelegate.contact_id!=nil)
  834. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  835. // if(appDelegate.password!=nil)
  836. // [params setValue:appDelegate.password forKey:@"password"];
  837. // [params setValue:item_ids forKey:@"cartItemId"];
  838. // // [params setValue:editor forKey:@"editor"];
  839. // if(appDelegate.offline_mode)
  840. // {
  841. // return [OLDataProvider offline_notimpl];
  842. // }
  843. // NSData* json=[self get_json:URL_CART_CHECK parameters:params];
  844. // if(json!=nil)
  845. // {
  846. // NSError *error=nil;
  847. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  848. // return jsobj;
  849. // }
  850. // else
  851. // return nil;
  852. //}
  853. +(NSDictionary*)create_Address:(NSMutableDictionary*)params
  854. {
  855. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  856. __block AppDelegate *appDelegate = nil;
  857. dispatch_sync(dispatch_get_main_queue(), ^{
  858. //some UI methods ej
  859. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  860. });
  861. if(appDelegate.user!=nil)
  862. [params setValue:appDelegate.user forKey:@"user"];
  863. if(appDelegate.contact_id!=nil)
  864. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  865. if(appDelegate.password!=nil)
  866. [params setValue:appDelegate.password forKey:@"password"];
  867. // [params setValue:sourceid forKey:@"sourceid"];
  868. // [params setValue:editor forKey:@"editor"];
  869. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  870. NSData* json=nil;
  871. if(appDelegate.offline_mode)
  872. {
  873. json= [OLDataProvider offline_saveaddr:params];
  874. }
  875. else
  876. {
  877. if(![self IsNetworkAvailable])
  878. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  879. json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  880. }
  881. if(json!=nil)
  882. {
  883. NSError *error=nil;
  884. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  885. return jsobj;
  886. }
  887. else
  888. return nil;
  889. }
  890. +(NSDictionary*)copy_Order:(NSString*) order_code
  891. {
  892. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  893. __block AppDelegate *appDelegate = nil;
  894. dispatch_sync(dispatch_get_main_queue(), ^{
  895. //some UI methods ej
  896. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  897. });
  898. if(appDelegate.user!=nil)
  899. [params setValue:appDelegate.user forKey:@"user"];
  900. if(appDelegate.contact_id!=nil)
  901. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  902. if(appDelegate.password!=nil)
  903. [params setValue:appDelegate.password forKey:@"password"];
  904. // NSString* ssaved = @"false";
  905. // if(saved)
  906. // ssaved=@"true";
  907. // [params setValue:@"true" forKey:@"saved"];
  908. [params setValue:order_code forKey:@"code"];
  909. // [params setValue:sourceid forKey:@"sourceid"];
  910. // [params setValue:editor forKey:@"editor"];
  911. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  912. NSData* json=nil;
  913. if(appDelegate.offline_mode)
  914. {
  915. json= [OLDataProvider offline_copyorder:params];
  916. }
  917. else
  918. {
  919. if(![self IsNetworkAvailable])
  920. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  921. json=[self get_json:URL_COPY_ORDER parameters:params];
  922. }
  923. if(json!=nil)
  924. {
  925. NSError *error=nil;
  926. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  927. return jsobj;
  928. }
  929. else
  930. return nil;
  931. }
  932. +(NSDictionary*)sign_Order:(NSString*) order_code path:(NSString*)path
  933. {
  934. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  935. __block AppDelegate *appDelegate = nil;
  936. dispatch_sync(dispatch_get_main_queue(), ^{
  937. //some UI methods ej
  938. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  939. });
  940. if(appDelegate.user!=nil)
  941. [params setValue:appDelegate.user forKey:@"user"];
  942. if(appDelegate.contact_id!=nil)
  943. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  944. if(appDelegate.password!=nil)
  945. [params setValue:appDelegate.password forKey:@"password"];
  946. // NSString* ssaved = @"false";
  947. // if(saved)
  948. // ssaved=@"true";
  949. // [params setValue:@"true" forKey:@"saved"];
  950. [params setValue:order_code forKey:@"orderCode"];
  951. [params setValue:path forKey:@"picpath"];
  952. // [params setValue:sourceid forKey:@"sourceid"];
  953. // [params setValue:editor forKey:@"editor"];
  954. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  955. NSData* json=nil;
  956. if(appDelegate.offline_mode)
  957. {
  958. json= [OLDataProvider offline_signorder:params];
  959. }
  960. else
  961. {
  962. if(![self IsNetworkAvailable])
  963. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  964. json=[self get_json:URL_SIGN_ORDER parameters:params];
  965. }
  966. if(json!=nil)
  967. {
  968. NSError *error=nil;
  969. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  970. return jsobj;
  971. }
  972. else
  973. return nil;
  974. }
  975. +(NSDictionary*)commit_Order:(NSString*) order_code //saved:(bool) saved
  976. {
  977. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  978. __block AppDelegate *appDelegate = nil;
  979. dispatch_sync(dispatch_get_main_queue(), ^{
  980. //some UI methods ej
  981. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  982. });
  983. if(appDelegate.user!=nil)
  984. [params setValue:appDelegate.user forKey:@"user"];
  985. if(appDelegate.contact_id!=nil)
  986. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  987. if(appDelegate.password!=nil)
  988. [params setValue:appDelegate.password forKey:@"password"];
  989. // NSString* ssaved = @"false";
  990. // if(saved)
  991. // ssaved=@"true";
  992. [params setValue:@"true" forKey:@"saved"];
  993. [params setValue:order_code forKey:@"orderCode"];
  994. // [params setValue:sourceid forKey:@"sourceid"];
  995. // [params setValue:editor forKey:@"editor"];
  996. [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  997. NSData* json = nil;
  998. if(appDelegate.offline_mode)
  999. {
  1000. json= [OLDataProvider offline_submitorder:params];
  1001. }
  1002. else
  1003. {
  1004. if(![self IsNetworkAvailable])
  1005. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1006. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  1007. }
  1008. if(json!=nil)
  1009. {
  1010. NSError *error=nil;
  1011. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1012. return jsobj;
  1013. }
  1014. else
  1015. return nil;
  1016. }
  1017. //+(NSDictionary*)open_Order:(NSString*) order_code
  1018. //{
  1019. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1020. // __block AppDelegate *appDelegate = nil;
  1021. //
  1022. // dispatch_sync(dispatch_get_main_queue(), ^{
  1023. // //some UI methods ej
  1024. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1025. // });
  1026. // if(appDelegate.user!=nil)
  1027. // [params setValue:appDelegate.user forKey:@"user"];
  1028. // // if(appDelegate.contact_id!=nil)
  1029. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1030. // if(appDelegate.password!=nil)
  1031. // [params setValue:appDelegate.password forKey:@"password"];
  1032. //
  1033. // [params setValue:order_code forKey:@"orderCode"];
  1034. // // [params setValue:sourceid forKey:@"sourceid"];
  1035. // // [params setValue:editor forKey:@"editor"];
  1036. //
  1037. // [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  1038. //
  1039. // NSData* json=nil;
  1040. // if(appDelegate.offline_mode)
  1041. // {
  1042. // json=[OLDataProvider offline_editorder:params];
  1043. //
  1044. // }
  1045. // else
  1046. // {
  1047. // if(![self IsNetworkAvailable])
  1048. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1049. //
  1050. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  1051. // }
  1052. // if(json!=nil)
  1053. // {
  1054. // NSError *error=nil;
  1055. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1056. // int result = [[jsobj valueForKey:@"result"] intValue];
  1057. //
  1058. // if (result==2)
  1059. // {
  1060. //
  1061. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1062. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1063. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1064. //
  1065. // [appDelegate update_count_mark];
  1066. //
  1067. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1068. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  1069. // }
  1070. //
  1071. // }
  1072. //
  1073. // return jsobj;
  1074. // }
  1075. // else
  1076. // return nil;
  1077. //}
  1078. +(NSDictionary*)delete_Order:(NSString*) order_id
  1079. {
  1080. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1081. __block AppDelegate *appDelegate = nil;
  1082. dispatch_sync(dispatch_get_main_queue(), ^{
  1083. //some UI methods ej
  1084. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1085. });
  1086. if(appDelegate.user!=nil)
  1087. [params setValue:appDelegate.user forKey:@"user"];
  1088. // if(appDelegate.contact_id!=nil)
  1089. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1090. if(appDelegate.password!=nil)
  1091. [params setValue:appDelegate.password forKey:@"password"];
  1092. [params setValue:order_id forKey:@"orderId"];
  1093. // [params setValue:sourceid forKey:@"sourceid"];
  1094. // [params setValue:editor forKey:@"editor"];
  1095. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  1096. if(appDelegate.offline_mode)
  1097. {
  1098. return [OLDataProvider offline_notimpl];
  1099. }
  1100. if(![self IsNetworkAvailable])
  1101. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1102. NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  1103. if(json!=nil)
  1104. {
  1105. NSError *error=nil;
  1106. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1107. return jsobj;
  1108. }
  1109. else
  1110. return nil;
  1111. }
  1112. +(NSDictionary*)cancel_Order:(NSString*) order_id order_code:(NSString*) order_code
  1113. {
  1114. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1115. __block AppDelegate *appDelegate = nil;
  1116. dispatch_sync(dispatch_get_main_queue(), ^{
  1117. //some UI methods ej
  1118. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1119. });
  1120. if(appDelegate.user!=nil)
  1121. [params setValue:appDelegate.user forKey:@"user"];
  1122. // if(appDelegate.contact_id!=nil)
  1123. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1124. if(appDelegate.password!=nil)
  1125. [params setValue:appDelegate.password forKey:@"password"];
  1126. [params setValue:order_id forKey:@"orderId"];
  1127. [params setValue:order_code forKey:@"orderCode"];
  1128. // [params setValue:sourceid forKey:@"sourceid"];
  1129. // [params setValue:editor forKey:@"editor"];
  1130. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  1131. NSData* json=nil;
  1132. if(appDelegate.offline_mode)
  1133. {
  1134. json=[OLDataProvider offline_cancelorder:params];
  1135. }
  1136. else
  1137. {
  1138. if(![self IsNetworkAvailable])
  1139. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1140. json=[self get_json:URL_CANCEL_ORDER parameters:params];
  1141. }
  1142. if(json!=nil)
  1143. {
  1144. NSError *error=nil;
  1145. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1146. return jsobj;
  1147. }
  1148. else
  1149. return nil;
  1150. }
  1151. +(NSDictionary*)release_Order:(NSString*) order_code withScreen:(NSString *)screenName
  1152. {
  1153. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1154. __block AppDelegate *appDelegate = nil;
  1155. dispatch_sync(dispatch_get_main_queue(), ^{
  1156. //some UI methods ej
  1157. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1158. });
  1159. if(appDelegate.user!=nil)
  1160. [params setValue:appDelegate.user forKey:@"user"];
  1161. // if(appDelegate.contact_id!=nil)
  1162. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1163. if(appDelegate.password!=nil)
  1164. [params setValue:appDelegate.password forKey:@"password"];
  1165. [params setValue:order_code forKey:@"orderCode"];
  1166. // [params setValue:sourceid forKey:@"sourceid"];
  1167. // [params setValue:editor forKey:@"editor"];
  1168. if (screenName) {
  1169. [params setValue:screenName forKey:kScreenName];
  1170. }
  1171. NSData* json=nil;
  1172. if(appDelegate.offline_mode)
  1173. {
  1174. json= [OLDataProvider offline_resetorder:params];
  1175. }
  1176. else
  1177. {
  1178. if(![self IsNetworkAvailable])
  1179. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1180. json=[self get_json:URL_RELEASE_ORDER parameters:params];
  1181. }
  1182. if(json!=nil)
  1183. {
  1184. NSError *error=nil;
  1185. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1186. if([[jsobj valueForKey:@"result"]intValue]==2)
  1187. { [appDelegate SetSo:nil];
  1188. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1189. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1190. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1191. [appDelegate update_count_mark];
  1192. }
  1193. return jsobj;
  1194. }
  1195. else
  1196. return nil;
  1197. }
  1198. +(NSDictionary*)update_OrderCustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info
  1199. {
  1200. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1201. __block AppDelegate *appDelegate = nil;
  1202. dispatch_sync(dispatch_get_main_queue(), ^{
  1203. //some UI methods ej
  1204. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1205. });
  1206. if(appDelegate.user!=nil)
  1207. [info setValue:appDelegate.user forKey:@"user"];
  1208. // if(appDelegate.contact_id!=nil)
  1209. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1210. if(appDelegate.password!=nil)
  1211. [info setValue:appDelegate.password forKey:@"password"];
  1212. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1213. [info setValue:order_code forKey:@"orderCode"];
  1214. // [params setValue:sourceid forKey:@"sourceid"];
  1215. // [params setValue:editor forKey:@"editor"];
  1216. if(appDelegate.offline_mode)
  1217. {
  1218. return [OLDataProvider offline_notimpl];
  1219. }
  1220. if(![self IsNetworkAvailable])
  1221. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1222. NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  1223. if(json!=nil)
  1224. {
  1225. NSError *error=nil;
  1226. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1227. return jsobj;
  1228. }
  1229. else
  1230. return nil;
  1231. }
  1232. //+(NSDictionary*)commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url
  1233. //{
  1234. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1235. // __block AppDelegate *appDelegate = nil;
  1236. //
  1237. // dispatch_sync(dispatch_get_main_queue(), ^{
  1238. // //some UI methods ej
  1239. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1240. // });
  1241. // if(appDelegate.user!=nil)
  1242. // [params setValue:appDelegate.user forKey:@"user"];
  1243. // if(appDelegate.contact_id!=nil)
  1244. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1245. // if(appDelegate.password!=nil)
  1246. // [params setValue:appDelegate.password forKey:@"password"];
  1247. //
  1248. // // if(appDelegate.order_code!=nil)
  1249. // // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1250. //
  1251. // // NSDictionary* customerinfo= appDelegate.customerInfo;
  1252. // //
  1253. // // NSArray* keys=[customerinfo allKeys];
  1254. // // for(int i=0;i<keys.count;i++)
  1255. // // {
  1256. // // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1257. // // }
  1258. // //
  1259. // // [params setValue:sourceid forKey:@"sourceid"];
  1260. // // [params setValue:editor forKey:@"editor"];
  1261. //
  1262. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  1263. //
  1264. // if(appDelegate.offline_mode)
  1265. // {
  1266. // params[@"offline_Command"]=url;
  1267. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  1268. // }
  1269. //
  1270. // if(![self IsNetworkAvailable])
  1271. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1272. //
  1273. // NSData* json=[self get_json:url parameters:params];
  1274. // if(json!=nil)
  1275. // {
  1276. // NSError *error=nil;
  1277. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1278. // if([[jsobj valueForKey:@"result"]intValue]==2)
  1279. // [appDelegate SetSo:nil];
  1280. //
  1281. //
  1282. // return jsobj;
  1283. // }
  1284. // else
  1285. // return nil;
  1286. //}
  1287. +(NSDictionary*)saveandcommit_Order:(NSMutableDictionary*)params
  1288. {
  1289. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1290. __block AppDelegate *appDelegate = nil;
  1291. dispatch_sync(dispatch_get_main_queue(), ^{
  1292. //some UI methods ej
  1293. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1294. });
  1295. if(appDelegate.user!=nil)
  1296. [params setValue:appDelegate.user forKey:@"user"];
  1297. if(appDelegate.contact_id!=nil)
  1298. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1299. if(appDelegate.password!=nil)
  1300. [params setValue:appDelegate.password forKey:@"password"];
  1301. if(appDelegate.order_code!=nil)
  1302. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1303. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1304. //
  1305. // NSArray* keys=[customerinfo allKeys];
  1306. // for(int i=0;i<keys.count;i++)
  1307. // {
  1308. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1309. // }
  1310. //
  1311. // [params setValue:sourceid forKey:@"sourceid"];
  1312. // [params setValue:editor forKey:@"editor"];
  1313. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1314. NSData* json=nil;
  1315. if(appDelegate.offline_mode)
  1316. {
  1317. json=[OLDataProvider offline_submitorder:params];
  1318. }
  1319. else
  1320. {
  1321. if(![self IsNetworkAvailable])
  1322. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1323. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  1324. }
  1325. if(json!=nil)
  1326. {
  1327. NSError *error=nil;
  1328. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1329. if([[jsobj valueForKey:@"result"]intValue]==2)
  1330. [appDelegate SetSo:nil];
  1331. return jsobj;
  1332. }
  1333. else
  1334. return nil;
  1335. }
  1336. +(NSDictionary*)update_Customer:(NSMutableDictionary*)params
  1337. {
  1338. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1339. __block AppDelegate *appDelegate = nil;
  1340. dispatch_sync(dispatch_get_main_queue(), ^{
  1341. //some UI methods ej
  1342. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1343. });
  1344. if(appDelegate.user!=nil)
  1345. [params setValue:appDelegate.user forKey:@"user"];
  1346. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1347. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1348. // else
  1349. if(appDelegate.contact_id!=nil)
  1350. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1351. if(appDelegate.password!=nil)
  1352. [params setValue:appDelegate.password forKey:@"password"];
  1353. // NSDictionary* customerinfo=nil;
  1354. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1355. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1356. // else
  1357. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1358. //
  1359. // appDelegate.customerInfo;
  1360. // NSArray* keys=[customerinfo allKeys];
  1361. // for(int i=0;i<keys.count;i++)
  1362. // {
  1363. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1364. // }
  1365. // [params setValue:sourceid forKey:@"sourceid"];
  1366. // [params setValue:editor forKey:@"editor"];
  1367. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1368. NSData* json=nil;
  1369. if(appDelegate.offline_mode)
  1370. {
  1371. json= [OLDataProvider offline_saveContact:params];
  1372. }
  1373. else
  1374. {
  1375. if(![self IsNetworkAvailable])
  1376. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1377. json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  1378. }
  1379. if(json!=nil)
  1380. {
  1381. NSError *error=nil;
  1382. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1383. return jsobj;
  1384. }
  1385. else
  1386. return nil;
  1387. }
  1388. +(NSDictionary*)save_newCustomer:(NSMutableDictionary*)params
  1389. {
  1390. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1391. __block AppDelegate *appDelegate = nil;
  1392. dispatch_sync(dispatch_get_main_queue(), ^{
  1393. //some UI methods ej
  1394. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1395. });
  1396. if(appDelegate.user!=nil)
  1397. [params setValue:appDelegate.user forKey:@"user"];
  1398. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1399. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1400. // else
  1401. if(appDelegate.contact_id!=nil)
  1402. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1403. if(appDelegate.password!=nil)
  1404. [params setValue:appDelegate.password forKey:@"password"];
  1405. // NSDictionary* customerinfo=nil;
  1406. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1407. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1408. // else
  1409. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1410. //
  1411. // appDelegate.customerInfo;
  1412. // NSArray* keys=[customerinfo allKeys];
  1413. // for(int i=0;i<keys.count;i++)
  1414. // {
  1415. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1416. // }
  1417. // [params setValue:sourceid forKey:@"sourceid"];
  1418. // [params setValue:editor forKey:@"editor"];
  1419. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1420. NSData* json=nil;
  1421. if(appDelegate.offline_mode)
  1422. {
  1423. json= [OLDataProvider offline_saveNewContact:params];
  1424. }
  1425. else
  1426. {
  1427. if(![self IsNetworkAvailable])
  1428. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1429. json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  1430. }
  1431. if(json!=nil)
  1432. {
  1433. NSError *error=nil;
  1434. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1435. return jsobj;
  1436. }
  1437. else
  1438. return nil;
  1439. }
  1440. +(NSDictionary*)save_Order:(NSMutableDictionary*)params
  1441. {
  1442. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1443. __block AppDelegate *appDelegate = nil;
  1444. dispatch_sync(dispatch_get_main_queue(), ^{
  1445. //some UI methods ej
  1446. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1447. });
  1448. if(appDelegate.user!=nil)
  1449. [params setValue:appDelegate.user forKey:@"user"];
  1450. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1451. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1452. // else
  1453. if(appDelegate.contact_id!=nil)
  1454. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1455. if(appDelegate.password!=nil)
  1456. [params setValue:appDelegate.password forKey:@"password"];
  1457. if(appDelegate.order_code!=nil)
  1458. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1459. // NSDictionary* customerinfo=nil;
  1460. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1461. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1462. // else
  1463. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1464. //
  1465. // appDelegate.customerInfo;
  1466. // NSArray* keys=[customerinfo allKeys];
  1467. // for(int i=0;i<keys.count;i++)
  1468. // {
  1469. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1470. // }
  1471. // [params setValue:sourceid forKey:@"sourceid"];
  1472. // [params setValue:editor forKey:@"editor"];
  1473. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1474. NSData* json=nil;
  1475. if(appDelegate.offline_mode)
  1476. {
  1477. json= [OLDataProvider offline_saveorder:params];
  1478. }
  1479. else
  1480. {
  1481. if(![self IsNetworkAvailable])
  1482. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1483. json=[self get_json:URL_SAVE_ORDER parameters:params];
  1484. }
  1485. if(json!=nil)
  1486. {
  1487. NSError *error=nil;
  1488. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1489. NSString *so = [jsobj valueForKey:@"so#"];
  1490. if (so) {
  1491. [appDelegate SetSo:so];
  1492. }
  1493. return jsobj;
  1494. }
  1495. else
  1496. return nil;
  1497. }
  1498. //+(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
  1499. //{
  1500. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1501. // __block AppDelegate *appDelegate = nil;
  1502. //
  1503. // dispatch_sync(dispatch_get_main_queue(), ^{
  1504. // //some UI methods ej
  1505. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1506. // });
  1507. // if(appDelegate.user!=nil)
  1508. // [params setValue:appDelegate.user forKey:@"user"];
  1509. //
  1510. //
  1511. // // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1512. // // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1513. // // else
  1514. //
  1515. // if(appDelegate.contact_id!=nil)
  1516. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1517. // if(appDelegate.password!=nil)
  1518. // [params setValue:appDelegate.password forKey:@"password"];
  1519. //
  1520. // if(appDelegate.order_code!=nil)
  1521. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1522. // // [params setValue:sourceid forKey:@"sourceid"];
  1523. // // [params setValue:editor forKey:@"editor"];
  1524. // DebugLog(@"request editor url:%@",request_url);
  1525. //
  1526. //
  1527. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1528. // {
  1529. // [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1530. // }
  1531. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1532. // {
  1533. // [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1534. // }
  1535. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1536. // {
  1537. // [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  1538. // }
  1539. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1540. // {
  1541. // [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1542. // }
  1543. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1544. // {
  1545. // [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  1546. // }
  1547. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1548. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1549. // }
  1550. //
  1551. // NSData* json = nil;
  1552. // if(appDelegate.offline_mode)
  1553. // {
  1554. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1555. // {
  1556. // json= [OLDataProvider offline_createContact:params];
  1557. // }
  1558. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1559. // {
  1560. // json= [OLDataProvider offline_editContact:params];
  1561. // }
  1562. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1563. // {
  1564. // json= [OLDataProvider offline_contactAdvancedSearch:params];
  1565. // }
  1566. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1567. // {
  1568. // json= [OLDataProvider offline_placeorder:params];
  1569. // }
  1570. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1571. // {
  1572. // json= [OLDataProvider offline_addreditor:params];
  1573. // }
  1574. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1575. // json = [OLDataProvider offline_createTearSheet:params];
  1576. // }
  1577. //
  1578. // else
  1579. // return [OLDataProvider offline_notimpl];
  1580. // }
  1581. // else
  1582. // {
  1583. // if(![self IsNetworkAvailable])
  1584. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1585. //
  1586. // if([request_url isEqualToString:URL_CARTDELIVERY])
  1587. // {
  1588. // NSError *error=nil;
  1589. //
  1590. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1591. // params[@"resultSerial"]=uuid;
  1592. //
  1593. // for(int i=0;i<150;i++)
  1594. // {
  1595. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1596. // // result_params[@"resultSerial"]=uuid;
  1597. // json=[self get_json:request_url parameters:params];
  1598. // if(json!=nil)
  1599. // {
  1600. //
  1601. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1602. // if([jsobj[@"result"] intValue]==2 || [jsobj[@"result"] intValue] == 8)
  1603. // {
  1604. // break;
  1605. // }
  1606. // }
  1607. // sleep(2);
  1608. // }
  1609. // }
  1610. // else
  1611. // json =[self get_json:request_url parameters:params];
  1612. // }
  1613. // if(json!=nil)
  1614. // {
  1615. // NSError *error=nil;
  1616. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1617. // return jsobj;
  1618. // }
  1619. // else
  1620. // return nil;
  1621. //}
  1622. //+(NSDictionary*)request_OrderInfo:(NSString*) orderid
  1623. //{
  1624. // if(![self IsNetworkAvailable])
  1625. // return nil;
  1626. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1627. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1628. // if(appDelegate.user!=nil)
  1629. // [params setValue:appDelegate.user forKey:@"user"];
  1630. // if(appDelegate.password!=nil)
  1631. // [params setValue:appDelegate.password forKey:@"password"];
  1632. // [params setValue:orderid forKey:@"orderid"];
  1633. // NSData* json=[self get_json:URL_ORDER_INFO parameters:params];
  1634. // NSError *error=nil;
  1635. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1636. // return jsobj;
  1637. //}
  1638. +(NSDictionary*)request_OrderList:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged
  1639. {
  1640. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1641. __block AppDelegate *appDelegate = nil;
  1642. dispatch_sync(dispatch_get_main_queue(), ^{
  1643. //some UI methods ej
  1644. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1645. });
  1646. if(appDelegate.user!=nil)
  1647. [params setValue:appDelegate.user forKey:@"user"];
  1648. if(appDelegate.contact_id!=nil)
  1649. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1650. if(appDelegate.password!=nil)
  1651. [params setValue:appDelegate.password forKey:@"password"];
  1652. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1653. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1654. [params setValue:keywords forKey:@"keyWord"];
  1655. [params setValue:customer forKey:@"customer_filter"];
  1656. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  1657. [params setValue:status_code forKey:@"orderStatus"];
  1658. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1659. if (keywords) {
  1660. [params setObject:@"Search" forKey:kAction];
  1661. }
  1662. NSData* json=nil;
  1663. if(appDelegate.offline_mode)
  1664. {
  1665. json= [OLDataProvider offline_orderlist:params];
  1666. }
  1667. else
  1668. {
  1669. if(![self IsNetworkAvailable])
  1670. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1671. json=[self get_json:URL_ORDER_LIST parameters:params];
  1672. }
  1673. if(json==nil)
  1674. return nil;
  1675. NSError *error=nil;
  1676. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1677. return jsobj;
  1678. }
  1679. +(NSDictionary*)request_PDFList:(int ) offset limit:(int)limit keywords:(NSString* ) keywords
  1680. {
  1681. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1682. __block AppDelegate *appDelegate = nil;
  1683. dispatch_sync(dispatch_get_main_queue(), ^{
  1684. //some UI methods ej
  1685. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1686. });
  1687. if(appDelegate.user!=nil)
  1688. [params setValue:appDelegate.user forKey:@"user"];
  1689. if(appDelegate.contact_id!=nil)
  1690. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1691. if(appDelegate.password!=nil)
  1692. [params setValue:appDelegate.password forKey:@"password"];
  1693. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  1694. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  1695. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  1696. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  1697. // [params setValue:filter forKey:@"filter"];
  1698. [params setValue:keywords forKey:@"keyWord"];
  1699. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  1700. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  1701. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  1702. if (keywords) {
  1703. [params setObject:@"Search" forKey:kAction];
  1704. }
  1705. NSData* json = nil;
  1706. if(appDelegate.offline_mode)
  1707. {
  1708. json = [OLDataProvider offline_pdfList:params];
  1709. } else {
  1710. if(![self IsNetworkAvailable])
  1711. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1712. json=[self get_json:URL_DM_LIST parameters:params];
  1713. }
  1714. if(json==nil)
  1715. return nil;
  1716. NSError *error=nil;
  1717. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1718. return jsobj;
  1719. }
  1720. //+(NSString*) create_portfolio:(NSMutableDictionary*)params
  1721. //{
  1722. // __block AppDelegate *appDelegate = nil;
  1723. //
  1724. // dispatch_sync(dispatch_get_main_queue(), ^{
  1725. // //some UI methods ej
  1726. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1727. // });
  1728. // if(appDelegate.offline_mode)
  1729. // {
  1730. //
  1731. //
  1732. // NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  1733. // if(json==nil)
  1734. // return nil;
  1735. // NSError *error=nil;
  1736. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1737. //
  1738. // return jsobj[@"pdf_path"];
  1739. // }
  1740. // else
  1741. // {
  1742. // return nil;
  1743. // }
  1744. //}
  1745. //+(NSDictionary*)direct_save_TearSheet:(NSMutableDictionary*)params//(NSString*) request_url name:(NSString*)name delete:(NSString* )ids note:(NSString* )saveNote modelIds:(NSDictionary *)modelIds
  1746. //{
  1747. // NSMutableDictionary* off_params = [params mutableCopy];;
  1748. //
  1749. // params[@"off_params"]=[RAConvertor dict2string:off_params];;
  1750. // __block AppDelegate *appDelegate = nil;
  1751. //
  1752. // dispatch_sync(dispatch_get_main_queue(), ^{
  1753. // //some UI methods ej
  1754. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1755. // });
  1756. // if(appDelegate.user!=nil)
  1757. // [params setValue:appDelegate.user forKey:@"user"];
  1758. // if(appDelegate.contact_id!=nil)
  1759. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1760. // if(appDelegate.password!=nil)
  1761. // [params setValue:appDelegate.password forKey:@"password"];
  1762. //
  1763. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1764. //
  1765. // /*
  1766. // [params setValue:request_url forKey:@"pdfUrl"];
  1767. // [params setValue:name forKey:@"pdfName"];
  1768. // [params setValue:ids forKey:@"itemIds"];
  1769. // [params setValue:saveNote forKey:@"pdfNote"];
  1770. // [params setValue:[modelIds objectForKey:@"product_ids"] forKey:@"product_ids"];
  1771. // [params setValue:[modelIds objectForKey:@"item_ids"] forKey:@"item_ids"];
  1772. // [params setValue:[modelIds objectForKey:@"remove_item"] forKey:@"remove_item"];
  1773. // */
  1774. // NSData* json= nil;
  1775. //
  1776. // if(appDelegate.offline_mode)
  1777. // {
  1778. // json = [OLDataProvider offline_direct_save_TearSheet:params];
  1779. // }
  1780. // else
  1781. // {
  1782. // if(![self IsNetworkAvailable])
  1783. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1784. //
  1785. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1786. //
  1787. // NSError *error=nil;
  1788. //
  1789. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1790. // params[@"resultSerial"]=uuid;
  1791. //
  1792. // for(int i=0;i<150;i++)
  1793. // {
  1794. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1795. // // result_params[@"resultSerial"]=uuid;
  1796. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1797. // if(json!=nil)
  1798. // {
  1799. //
  1800. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1801. // if([jsobj[@"result"] intValue]==2)
  1802. // {
  1803. // break;
  1804. // }
  1805. // }
  1806. // sleep(5);
  1807. // }
  1808. //
  1809. // }
  1810. // if(json==nil)
  1811. // return nil;
  1812. // NSError *error=nil;
  1813. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1814. // return jsobj;
  1815. //}
  1816. //+(NSDictionary*)request_TearSheet:(NSMutableDictionary*)params//(NSString*) request_url
  1817. //{
  1818. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1819. // __block AppDelegate *appDelegate = nil;
  1820. //
  1821. // dispatch_sync(dispatch_get_main_queue(), ^{
  1822. // //some UI methods ej
  1823. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1824. // });
  1825. // if(appDelegate.user!=nil)
  1826. // [params setValue:appDelegate.user forKey:@"user"];
  1827. // if(appDelegate.contact_id!=nil)
  1828. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1829. // if(appDelegate.password!=nil)
  1830. // [params setValue:appDelegate.password forKey:@"password"];
  1831. //
  1832. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1833. //
  1834. // // [params setValue:request_url forKey:@"pdfUrl"];
  1835. // NSData* json= nil;
  1836. // if(appDelegate.offline_mode)
  1837. // {
  1838. // json= [OLDataProvider offline_request_tearsheet:params];
  1839. // }
  1840. // else
  1841. // {
  1842. // if(![self IsNetworkAvailable])
  1843. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1844. //
  1845. // NSError *error=nil;
  1846. //
  1847. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1848. // params[@"resultSerial"]=uuid;
  1849. //
  1850. // for(int i=0;i<150;i++)
  1851. // {
  1852. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1853. // // result_params[@"resultSerial"]=uuid;
  1854. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1855. // if(json!=nil)
  1856. // {
  1857. //
  1858. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1859. // if([jsobj[@"result"] intValue]==2)
  1860. // {
  1861. // break;
  1862. // }
  1863. // }
  1864. // sleep(5);
  1865. // }
  1866. // }
  1867. // if(json==nil)
  1868. // return nil;
  1869. // NSError *error=nil;
  1870. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1871. // return jsobj;
  1872. //}
  1873. //+(NSDictionary*)save_TearSheet:(NSMutableDictionary *)params//(NSString*) path name:(NSString*)name delete:(NSString* )ids note:(NSString*)note configureParams:(NSString *)configureParams modelIds:(NSDictionary *)modelIds
  1874. //{
  1875. //
  1876. //
  1877. // NSMutableDictionary* off_params = [params mutableCopy];;
  1878. //
  1879. // params[@"off_params"]=[RAConvertor dict2string:off_params];
  1880. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1881. // __block AppDelegate *appDelegate = nil;
  1882. //
  1883. // dispatch_sync(dispatch_get_main_queue(), ^{
  1884. // //some UI methods ej
  1885. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1886. // });
  1887. // if(appDelegate.user!=nil)
  1888. // [params setValue:appDelegate.user forKey:@"user"];
  1889. // if(appDelegate.contact_id!=nil)
  1890. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1891. // if(appDelegate.password!=nil)
  1892. // [params setValue:appDelegate.password forKey:@"password"];
  1893. //
  1894. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1895. //
  1896. // /*
  1897. // [params setValue:path forKey:@"pdfPath"];
  1898. // [params setValue:name forKey:@"pdfName"];
  1899. // [params setValue:note forKey:@"pdfNote"];
  1900. // [params setValue:ids forKey:@"itemIds"];
  1901. // [params setValue:configureParams forKey:@"configureParams"];
  1902. // [params setValue:[modelIds objectForKey:@"product_ids"] forKey:@"product_ids"];
  1903. // [params setValue:[modelIds objectForKey:@"item_ids"] forKey:@"item_ids"];
  1904. // [params setValue:[modelIds objectForKey:@"remove_item"] forKey:@"remove_item"];
  1905. // */
  1906. // NSData* json = nil;
  1907. // if(appDelegate.offline_mode)
  1908. // {
  1909. // json = [OLDataProvider offline_save_TearSheet:params];
  1910. // } else {
  1911. // if(![self IsNetworkAvailable])
  1912. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1913. //
  1914. // json=[self get_json:URL_SAVE_DM parameters:params];
  1915. // }
  1916. // if(json==nil)
  1917. // return nil;
  1918. // NSError *error=nil;
  1919. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1920. // return jsobj;
  1921. //}
  1922. +(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code//device:(NSString*) device
  1923. {
  1924. return nil;
  1925. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1926. __block AppDelegate *appDelegate = nil;
  1927. dispatch_sync(dispatch_get_main_queue(), ^{
  1928. //some UI methods ej
  1929. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1930. });
  1931. if(appDelegate.user!=nil)
  1932. [params setValue:appDelegate.user forKey:@"user"];
  1933. [params setValue:up_params forKey:@"upparam"];
  1934. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  1935. [params setValue:result forKey:@"result"];
  1936. [params setValue:module forKey:@"interfac"];
  1937. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  1938. // [params setValue:module forKey:@"module"];
  1939. // [[UIDevice currentDevice] name];
  1940. // if(appDelegate.offline_mode)
  1941. // {
  1942. // return [OLDataProvider offline_notimpl];
  1943. // }
  1944. if(![self IsNetworkAvailable])
  1945. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1946. NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  1947. if(json==nil)
  1948. return nil;
  1949. NSError *error=nil;
  1950. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1951. return jsobj;
  1952. }
  1953. //+(NSDictionary*)request_ContactList:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams
  1954. //{
  1955. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1956. //
  1957. // if(upparams!=nil)
  1958. // params = [upparams mutableCopy];
  1959. // __block AppDelegate *appDelegate = nil;
  1960. //
  1961. // dispatch_sync(dispatch_get_main_queue(), ^{
  1962. // //some UI methods ej
  1963. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1964. // });
  1965. // if(appDelegate.user!=nil)
  1966. // [params setValue:appDelegate.user forKey:@"user"];
  1967. //
  1968. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1969. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1970. // else
  1971. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1972. //
  1973. // if(appDelegate.password!=nil)
  1974. // [params setValue:appDelegate.password forKey:@"password"];
  1975. //
  1976. // [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1977. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1978. // [params setValue:contact_type forKey:@"contactType"];
  1979. // [params setValue:keywords forKey:@"keyword"];
  1980. //
  1981. // [params setObject:ScreenCodeAccount forKey:kScreenName];
  1982. // if (keywords) {
  1983. // [params setObject:@"Search" forKey:kAction];
  1984. // }
  1985. // if (upparams) {
  1986. // [params setObject:@"Advance Search" forKey:kAction];
  1987. // }
  1988. //
  1989. // NSString* url=nil;
  1990. // if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  1991. // url=URL_SHIPTO_LIST;
  1992. // else
  1993. // url=URL_CONTACT_LIST;
  1994. //
  1995. // if(appDelegate.offline_mode)
  1996. // return [OLDataProvider offline_contactlist:params];
  1997. //
  1998. // if(![self IsNetworkAvailable])
  1999. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2000. //
  2001. // NSData* json=[self get_json:url parameters:params];
  2002. // if(json==nil)
  2003. // return nil;
  2004. // NSError *error=nil;
  2005. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2006. // return jsobj;
  2007. //}
  2008. //+(NSDictionary*)request_OrderDetail:(NSMutableDictionary *) params
  2009. //{
  2010. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2011. // if (params == nil) {
  2012. // params = [[NSMutableDictionary alloc] init];
  2013. // }
  2014. // __block AppDelegate *appDelegate = nil;
  2015. //
  2016. // dispatch_sync(dispatch_get_main_queue(), ^{
  2017. // //some UI methods ej
  2018. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2019. // });
  2020. // if(appDelegate.user!=nil)
  2021. // [params setValue:appDelegate.user forKey:@"user"];
  2022. // if(appDelegate.contact_id!=nil)
  2023. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2024. // if(appDelegate.password!=nil)
  2025. // [params setValue:appDelegate.password forKey:@"password"];
  2026. //
  2027. //
  2028. // // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  2029. //
  2030. // [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  2031. //
  2032. // NSData* json=nil;
  2033. // if(appDelegate.offline_mode)
  2034. // {
  2035. // json= [OLDataProvider offline_orderdetail:params];
  2036. // }
  2037. // else
  2038. // {
  2039. // if(![self IsNetworkAvailable])
  2040. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2041. //
  2042. // NSError *error=nil;
  2043. //
  2044. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2045. // params[@"resultSerial"]=uuid;
  2046. //
  2047. // for(int i=0;i<150;i++)
  2048. // {
  2049. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2050. // // result_params[@"resultSerial"]=uuid;
  2051. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  2052. // if(json!=nil)
  2053. // {
  2054. //
  2055. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2056. // int resultCode = [jsobj[@"result"] intValue];
  2057. // if(resultCode==2 || resultCode == 8)
  2058. // {
  2059. // break;
  2060. // }
  2061. // }
  2062. // sleep(2);
  2063. // }
  2064. //
  2065. //
  2066. // }
  2067. // if(json==nil)
  2068. // return nil;
  2069. // NSError *error=nil;
  2070. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2071. // return jsobj;
  2072. //}
  2073. //+(NSDictionary*) add_toCart:(NSString* ) item_id count:(int) count name:(NSString *)name
  2074. //{
  2075. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2076. // __block AppDelegate *appDelegate = nil;
  2077. //
  2078. // dispatch_sync(dispatch_get_main_queue(), ^{
  2079. // //some UI methods ej
  2080. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2081. // });
  2082. // if(appDelegate.user!=nil)
  2083. // [params setValue:appDelegate.user forKey:@"user"];
  2084. // if(appDelegate.contact_id!=nil)
  2085. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2086. // if(appDelegate.password!=nil)
  2087. // [params setValue:appDelegate.password forKey:@"password"];
  2088. //
  2089. // if(appDelegate.order_code!=nil)
  2090. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2091. // [params setValue:item_id forKey:@"product_id"];
  2092. // [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  2093. //
  2094. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  2095. // [params setObject:@"Add To Cart" forKey:kAction];
  2096. // if (name) {
  2097. // NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  2098. // [params setObject:extra forKey:kExtra];
  2099. // }
  2100. //
  2101. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2102. //
  2103. // NSArray* keys=[customerinfo allKeys];
  2104. // for(int i=0;i<keys.count;i++)
  2105. // {
  2106. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2107. // }
  2108. //
  2109. // NSData* json=nil;
  2110. // if(appDelegate.offline_mode)
  2111. // {
  2112. // json=[OLDataProvider offline_add2cart:params];
  2113. // }
  2114. // else
  2115. // {
  2116. // if(![self IsNetworkAvailable])
  2117. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2118. //
  2119. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  2120. // }
  2121. // if(json==nil)
  2122. // return nil;
  2123. // NSError *error=nil;
  2124. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2125. //
  2126. //
  2127. //
  2128. // int result = [[jsobj valueForKey:@"result"] intValue];
  2129. //
  2130. // if (result==2)
  2131. // {
  2132. //
  2133. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2134. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2135. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2136. //
  2137. // [appDelegate update_count_mark];
  2138. // }
  2139. //
  2140. // return jsobj;
  2141. //}
  2142. //+(NSDictionary*) add_toCart_byName:(NSString* ) model_name withScreen:(NSString *)screenName
  2143. //{
  2144. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2145. // __block AppDelegate *appDelegate = nil;
  2146. //
  2147. // dispatch_sync(dispatch_get_main_queue(), ^{
  2148. // //some UI methods ej
  2149. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2150. // });
  2151. // if(appDelegate.user!=nil)
  2152. // [params setValue:appDelegate.user forKey:@"user"];
  2153. // if(appDelegate.contact_id!=nil)
  2154. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2155. // if(appDelegate.password!=nil)
  2156. // [params setValue:appDelegate.password forKey:@"password"];
  2157. //
  2158. // if(appDelegate.order_code!=nil)
  2159. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2160. // [params setValue:model_name forKey:@"product_name"];
  2161. // [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  2162. //
  2163. // [params setObject:screenName forKey:kScreenName];
  2164. // [params setObject:@"Add To Cart" forKey:kAction];
  2165. // if (!model_name) {
  2166. // model_name = @"";
  2167. // }
  2168. // [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  2169. //
  2170. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2171. //
  2172. // NSArray* keys=[customerinfo allKeys];
  2173. // for(int i=0;i<keys.count;i++)
  2174. // {
  2175. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2176. // }
  2177. // NSData* json=nil;
  2178. // if(appDelegate.offline_mode)
  2179. // {
  2180. // json= [OLDataProvider offline_add2cartbyname:params];
  2181. // }
  2182. // else
  2183. // {
  2184. // if(![self IsNetworkAvailable])
  2185. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2186. //
  2187. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  2188. // }
  2189. // if(json==nil)
  2190. // return nil;
  2191. // NSError *error=nil;
  2192. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2193. //
  2194. //
  2195. //
  2196. // int result = [[jsobj valueForKey:@"result"] intValue];
  2197. //
  2198. // if (result==2||result==8)
  2199. // {
  2200. //
  2201. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2202. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2203. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2204. //
  2205. // [appDelegate update_count_mark];
  2206. // }
  2207. //
  2208. // return jsobj;
  2209. //}
  2210. //+(NSDictionary*) new_Customer
  2211. //{
  2212. // if(![self IsNetworkAvailable])
  2213. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2214. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2215. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2216. // if(appDelegate.user!=nil)
  2217. // [params setValue:appDelegate.user forKey:@"user"];
  2218. //// if(appDelegate.contact_id!=nil)
  2219. //// [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2220. // if(appDelegate.password!=nil)
  2221. // [params setValue:appDelegate.password forKey:@"password"];
  2222. //
  2223. //// if(appDelegate.order_code!=nil)
  2224. //// [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2225. //
  2226. //
  2227. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2228. //
  2229. // NSArray* keys=[customerinfo allKeys];
  2230. // for(int i=0;i<keys.count;i++)
  2231. // {
  2232. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2233. // }
  2234. //
  2235. // NSData* json=[self get_json:URL_CUSTOMER_EDIT parameters:params];
  2236. // if(json==nil)
  2237. // return nil;
  2238. // NSError *error=nil;
  2239. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2240. // return jsobj;
  2241. //}
  2242. //+(NSDictionary*) new_Order
  2243. //{
  2244. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2245. // __block AppDelegate *appDelegate = nil;
  2246. //
  2247. // dispatch_sync(dispatch_get_main_queue(), ^{
  2248. // //some UI methods ej
  2249. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2250. // });
  2251. // if(appDelegate.user!=nil)
  2252. // [params setValue:appDelegate.user forKey:@"user"];
  2253. // if(appDelegate.contact_id!=nil)
  2254. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2255. // if(appDelegate.password!=nil)
  2256. // [params setValue:appDelegate.password forKey:@"password"];
  2257. //
  2258. // if(appDelegate.order_code!=nil)
  2259. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2260. //
  2261. //
  2262. // [params setObject:ScreenCodeOrderList forKey:kScreenName];
  2263. //
  2264. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2265. //
  2266. // NSArray* keys=[customerinfo allKeys];
  2267. // for(int i=0;i<keys.count;i++)
  2268. // {
  2269. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2270. // }
  2271. //
  2272. // NSData* json = nil;
  2273. // if(appDelegate.offline_mode)
  2274. // {
  2275. // json= [OLDataProvider offline_createorder:params];
  2276. // }
  2277. // else
  2278. // {
  2279. // if(![self IsNetworkAvailable])
  2280. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2281. //
  2282. // json=[self get_json:URL_NEW_ORDER parameters:params];
  2283. // }
  2284. // if(json==nil)
  2285. // return nil;
  2286. // NSError *error=nil;
  2287. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2288. // int result = [[jsobj valueForKey:@"result"] intValue];
  2289. //
  2290. // if (result==2)
  2291. // {
  2292. //
  2293. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2294. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2295. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2296. //
  2297. // [appDelegate update_count_mark];
  2298. // }
  2299. //
  2300. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  2301. //
  2302. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  2303. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  2304. // }
  2305. //
  2306. // return jsobj;
  2307. //}
  2308. +(NSDictionary*) add_toPortfolio:(NSString* ) item_id withScreen:(NSString *)screenName
  2309. {
  2310. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2311. __block AppDelegate *appDelegate = nil;
  2312. dispatch_sync(dispatch_get_main_queue(), ^{
  2313. //some UI methods ej
  2314. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2315. });
  2316. if(appDelegate.user!=nil)
  2317. [params setValue:appDelegate.user forKey:@"user"];
  2318. if(appDelegate.contact_id!=nil)
  2319. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2320. if(appDelegate.password!=nil)
  2321. [params setValue:appDelegate.password forKey:@"password"];
  2322. [params setValue:item_id forKey:@"product_id"];
  2323. [params setObject:screenName forKey:kScreenName];
  2324. NSData* json = nil;
  2325. if(appDelegate.offline_mode)
  2326. {
  2327. json = [OLDataProvider offline_add2Portfolio:params];
  2328. } else {
  2329. if(![self IsNetworkAvailable])
  2330. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2331. json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  2332. }
  2333. if(json==nil)
  2334. return nil;
  2335. NSError *error=nil;
  2336. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2337. int result = [[jsobj valueForKey:@"result"] intValue];
  2338. if (result==2)
  2339. {
  2340. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2341. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2342. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2343. [appDelegate update_count_mark];
  2344. }
  2345. return jsobj;
  2346. }
  2347. //+(NSDictionary*) add_toWatchList:(NSString* ) item_id withScreen:(NSString *)screenName
  2348. //{
  2349. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2350. // __block AppDelegate *appDelegate = nil;
  2351. //
  2352. // dispatch_sync(dispatch_get_main_queue(), ^{
  2353. // //some UI methods ej
  2354. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2355. // });
  2356. // if(appDelegate.user!=nil)
  2357. // [params setValue:appDelegate.user forKey:@"user"];
  2358. // if(appDelegate.contact_id!=nil)
  2359. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2360. // if(appDelegate.password!=nil)
  2361. // [params setValue:appDelegate.password forKey:@"password"];
  2362. //
  2363. //
  2364. // [params setValue:item_id forKey:@"product_id"];
  2365. //
  2366. // [params setObject:screenName forKey:kScreenName];
  2367. //
  2368. // if(appDelegate.offline_mode)
  2369. // {
  2370. // return [OLDataProvider offline_add2wishlist:params];
  2371. // }
  2372. // if(![self IsNetworkAvailable])
  2373. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2374. //
  2375. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  2376. // if(json==nil)
  2377. // return nil;
  2378. // NSError *error=nil;
  2379. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2380. // int result = [[jsobj valueForKey:@"result"] intValue];
  2381. //
  2382. // if (result==2)
  2383. // {
  2384. //
  2385. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2386. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2387. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2388. //
  2389. // [appDelegate update_count_mark];
  2390. // }
  2391. // return jsobj;
  2392. //}
  2393. //+(NSDictionary*) cart_setPrice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes
  2394. //{
  2395. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2396. // __block AppDelegate *appDelegate = nil;
  2397. //
  2398. // dispatch_sync(dispatch_get_main_queue(), ^{
  2399. // //some UI methods ej
  2400. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2401. // });
  2402. // if(appDelegate.user!=nil)
  2403. // [params setValue:appDelegate.user forKey:@"user"];
  2404. // if(appDelegate.contact_id!=nil)
  2405. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2406. // if(appDelegate.password!=nil)
  2407. // [params setValue:appDelegate.password forKey:@"password"];
  2408. //
  2409. // [params setValue:cart_id forKey:@"cartitem_id"];
  2410. // [params setValue:notes forKey:@"item_note"];
  2411. //
  2412. // [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  2413. //
  2414. // [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  2415. //
  2416. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2417. //
  2418. // NSData* json= nil;
  2419. // if(appDelegate.offline_mode)
  2420. // {
  2421. // json=[OLDataProvider offline_cartsetprice:params];
  2422. // }
  2423. // else
  2424. // {
  2425. // if(![self IsNetworkAvailable])
  2426. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2427. //
  2428. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2429. // }
  2430. // if(json==nil)
  2431. // return nil;
  2432. // NSError *error=nil;
  2433. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2434. // return jsobj;
  2435. //}
  2436. //+(NSDictionary*) portfolio_setQTY:(NSString*) watchlist_id QTY:(int)qty
  2437. //{
  2438. // if(![self IsNetworkAvailable])
  2439. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2440. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2441. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2442. // if(appDelegate.user!=nil)
  2443. // [params setValue:appDelegate.user forKey:@"user"];
  2444. // if(appDelegate.contact_id!=nil)
  2445. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2446. // if(appDelegate.password!=nil)
  2447. // [params setValue:appDelegate.password forKey:@"password"];
  2448. //
  2449. // [params setValue:watchlist_id forKey:@"item_id"];
  2450. //
  2451. // [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  2452. //
  2453. //
  2454. //
  2455. // NSData* json=[self get_json:URL_DM_SET_QTY parameters:params];
  2456. // if(json==nil)
  2457. // return nil;
  2458. // NSError *error=nil;
  2459. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2460. // return jsobj;
  2461. //}
  2462. +(NSDictionary*) portfolio_setPrice:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes
  2463. {
  2464. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2465. __block AppDelegate *appDelegate = nil;
  2466. dispatch_sync(dispatch_get_main_queue(), ^{
  2467. //some UI methods ej
  2468. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2469. });
  2470. if(appDelegate.user!=nil)
  2471. [params setValue:appDelegate.user forKey:@"user"];
  2472. if(appDelegate.contact_id!=nil)
  2473. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2474. if(appDelegate.password!=nil)
  2475. [params setValue:appDelegate.password forKey:@"password"];
  2476. [params setValue:watchlist_id forKey:@"item_id"];
  2477. // if(notes.length>0)
  2478. // [params setValue:notes forKey:@"notes"];
  2479. if(notes)
  2480. [params setValue:notes forKey:@"notes"];
  2481. if(price != -MAXFLOAT)
  2482. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  2483. if (discount != -MAXFLOAT)
  2484. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  2485. if(qty_p != -MAXFLOAT)
  2486. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  2487. if(qty != -INT32_MAX)
  2488. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  2489. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2490. NSData* json = nil;
  2491. if(appDelegate.offline_mode)
  2492. {
  2493. json = [OLDataProvider offline_editPortfolio:params];
  2494. } else {
  2495. if(![self IsNetworkAvailable])
  2496. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2497. json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  2498. }
  2499. if(json==nil)
  2500. return nil;
  2501. NSError *error=nil;
  2502. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2503. return jsobj;
  2504. }
  2505. //+(NSDictionary*) cart_setGeneralNote:(NSString*) order_code notes:(NSString*) notes
  2506. //{
  2507. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2508. // __block AppDelegate *appDelegate = nil;
  2509. //
  2510. // dispatch_sync(dispatch_get_main_queue(), ^{
  2511. // //some UI methods ej
  2512. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2513. // });
  2514. // if(appDelegate.user!=nil)
  2515. // [params setValue:appDelegate.user forKey:@"user"];
  2516. // if(appDelegate.contact_id!=nil)
  2517. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2518. // if(appDelegate.password!=nil)
  2519. // [params setValue:appDelegate.password forKey:@"password"];
  2520. //
  2521. // [params setValue:order_code forKey:@"orderCode"];
  2522. //
  2523. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2524. //
  2525. // if(notes.length==0)
  2526. // notes=@"";
  2527. //
  2528. //
  2529. // [params setValue:notes forKey:@"comments"];
  2530. // NSData* json=nil;
  2531. // if(appDelegate.offline_mode)
  2532. // {
  2533. // json= [OLDataProvider offline_updategnotes:params];
  2534. // }
  2535. // else
  2536. // {
  2537. // if(![self IsNetworkAvailable])
  2538. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2539. //
  2540. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  2541. // }
  2542. // if(json==nil)
  2543. // return nil;
  2544. // NSError *error=nil;
  2545. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2546. // return jsobj;
  2547. //}
  2548. //+(NSDictionary*) cart_setItemNote:(NSString*) cart_id notes:(NSString*) notes
  2549. //{
  2550. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2551. // __block AppDelegate *appDelegate = nil;
  2552. //
  2553. // dispatch_sync(dispatch_get_main_queue(), ^{
  2554. // //some UI methods ej
  2555. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2556. // });
  2557. // if(appDelegate.user!=nil)
  2558. // [params setValue:appDelegate.user forKey:@"user"];
  2559. // if(appDelegate.contact_id!=nil)
  2560. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2561. // if(appDelegate.password!=nil)
  2562. // [params setValue:appDelegate.password forKey:@"password"];
  2563. //
  2564. // [params setValue:cart_id forKey:@"cartitem_id"];
  2565. //
  2566. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2567. //
  2568. // if(notes.length==0)
  2569. // notes=@"";
  2570. //
  2571. //
  2572. // [params setValue:notes forKey:@"notes"];
  2573. // NSData* json=nil;
  2574. // if(appDelegate.offline_mode)
  2575. // {
  2576. // json= [OLDataProvider offline_cartsetlnotes:params];
  2577. // }
  2578. // else
  2579. // {
  2580. // if(![self IsNetworkAvailable])
  2581. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2582. //
  2583. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  2584. // }
  2585. // if(json==nil)
  2586. // return nil;
  2587. // NSError *error=nil;
  2588. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2589. // return jsobj;
  2590. //}
  2591. //+(NSDictionary*) cart_setFree:(NSString*) cart_id isfree:(bool) isfree
  2592. //{
  2593. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2594. // __block AppDelegate *appDelegate = nil;
  2595. //
  2596. // dispatch_sync(dispatch_get_main_queue(), ^{
  2597. // //some UI methods ej
  2598. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2599. // });
  2600. // if(appDelegate.user!=nil)
  2601. // [params setValue:appDelegate.user forKey:@"user"];
  2602. // if(appDelegate.contact_id!=nil)
  2603. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2604. // if(appDelegate.password!=nil)
  2605. // [params setValue:appDelegate.password forKey:@"password"];
  2606. //
  2607. // [params setValue:cart_id forKey:@"cartitem_id"];
  2608. //
  2609. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2610. //
  2611. // NSString* free=nil;
  2612. //
  2613. // if(isfree)
  2614. // free=@"true";
  2615. // else
  2616. // free=@"false";
  2617. //
  2618. // [params setValue:free forKey:@"free_giveaway"];
  2619. //
  2620. // if(appDelegate.offline_mode)
  2621. // {
  2622. // return [OLDataProvider offline_notimpl];
  2623. // }
  2624. // if(![self IsNetworkAvailable])
  2625. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2626. //
  2627. // NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2628. // if(json==nil)
  2629. // return nil;
  2630. // NSError *error=nil;
  2631. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2632. // return jsobj;
  2633. //}
  2634. //+(NSDictionary*) cart_setQTY:(NSString*) cart_id value:(int) value
  2635. //{
  2636. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2637. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2638. // if(appDelegate.user!=nil)
  2639. // [params setValue:appDelegate.user forKey:@"user"];
  2640. // if(appDelegate.contact_id!=nil)
  2641. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2642. // if(appDelegate.password!=nil)
  2643. // [params setValue:appDelegate.password forKey:@"password"];
  2644. //
  2645. // [params setValue:cart_id forKey:@"cartitem_id"];
  2646. //
  2647. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2648. //
  2649. // [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  2650. //
  2651. // NSData* json=nil;
  2652. // if(appDelegate.offline_mode)
  2653. // {
  2654. // json= [OLDataProvider offline_cartsetqty:params];
  2655. // }
  2656. // else
  2657. // {
  2658. // if(![self IsNetworkAvailable])
  2659. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2660. //
  2661. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2662. // }
  2663. // if(json==nil)
  2664. // return nil;
  2665. // NSError *error=nil;
  2666. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2667. // return jsobj;
  2668. //
  2669. //}
  2670. //+(NSDictionary*) cart_incresement:(NSString*) cart_id increse:(bool) increse
  2671. //{
  2672. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2673. // __block AppDelegate *appDelegate = nil;
  2674. //
  2675. // dispatch_sync(dispatch_get_main_queue(), ^{
  2676. // //some UI methods ej
  2677. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2678. // });
  2679. // if(appDelegate.user!=nil)
  2680. // [params setValue:appDelegate.user forKey:@"user"];
  2681. // if(appDelegate.contact_id!=nil)
  2682. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2683. // if(appDelegate.password!=nil)
  2684. // [params setValue:appDelegate.password forKey:@"password"];
  2685. //
  2686. // [params setValue:cart_id forKey:@"cartitem_id"];
  2687. //
  2688. // if(increse)
  2689. // [params setValue:@"1" forKey:@"incrementType"];
  2690. // else
  2691. // [params setValue:@"0" forKey:@"incrementType"];
  2692. //
  2693. //
  2694. //
  2695. // if(appDelegate.offline_mode)
  2696. // {
  2697. // return [OLDataProvider offline_notimpl];
  2698. // }
  2699. // if(![self IsNetworkAvailable])
  2700. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2701. //
  2702. // NSData* json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2703. // if(json==nil)
  2704. // return nil;
  2705. // NSError *error=nil;
  2706. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2707. // return jsobj;
  2708. //}
  2709. +(NSDictionary*) finish_download_Offline:(NSString* )vid
  2710. {
  2711. if(![self IsNetworkAvailable])
  2712. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2713. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2714. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  2715. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2716. // if(appDelegate.user!=nil)
  2717. // [params setValue:appDelegate.user forKey:@"user"];
  2718. // // if(appDelegate.contact_id!=nil)
  2719. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2720. // if(appDelegate.password!=nil)
  2721. // [params setValue:appDelegate.password forKey:@"password"];
  2722. [params setValue:vid forKey:@"downSerial"];
  2723. NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  2724. if(json==nil)
  2725. return nil;
  2726. NSError *error=nil;
  2727. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2728. // int result = [[jsobj valueForKey:@"result"] intValue];
  2729. //
  2730. // if (result==2)
  2731. // {
  2732. //
  2733. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2734. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2735. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2736. ////
  2737. //// [appDelegate update_count_mark];
  2738. // }
  2739. return jsobj;
  2740. }
  2741. +(NSDictionary*) download_Offline:(NSString* )vid
  2742. {
  2743. if(![self IsNetworkAvailable])
  2744. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2745. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2746. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2747. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2748. // if(appDelegate.user!=nil)
  2749. // [params setValue:appDelegate.user forKey:@"user"];
  2750. // // if(appDelegate.contact_id!=nil)
  2751. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2752. // if(appDelegate.password!=nil)
  2753. // [params setValue:appDelegate.password forKey:@"password"];
  2754. [params setValue:vid forKey:@"downSerial"];
  2755. NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  2756. if(json==nil)
  2757. return nil;
  2758. NSError *error=nil;
  2759. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2760. // int result = [[jsobj valueForKey:@"result"] intValue];
  2761. //
  2762. // if (result==2)
  2763. // {
  2764. //
  2765. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2766. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2767. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2768. ////
  2769. //// [appDelegate update_count_mark];
  2770. // }
  2771. return jsobj;
  2772. }
  2773. +(NSDictionary*) check_Offline:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid
  2774. {
  2775. if(![self IsNetworkAvailable])
  2776. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2777. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2778. __block AppDelegate *appDelegate = nil;
  2779. dispatch_sync(dispatch_get_main_queue(), ^{
  2780. //some UI methods ej
  2781. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2782. });
  2783. if(appDelegate.user!=nil)
  2784. [params setValue:appDelegate.user forKey:@"user"];
  2785. // if(appDelegate.contact_id!=nil)
  2786. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2787. if(appDelegate.password!=nil)
  2788. [params setValue:appDelegate.password forKey:@"password"];
  2789. [params setValue:ver forKey:@"ver"];
  2790. [params setValue:vid forKey:@"vid"];
  2791. if(buseinternaladdress)
  2792. [params setValue:@"true" forKey:@"internal_address"];
  2793. else
  2794. [params setValue:@"false" forKey:@"internal_address"];
  2795. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2796. NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  2797. if(json==nil)
  2798. return nil;
  2799. NSError *error=nil;
  2800. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2801. // int result = [[jsobj valueForKey:@"result"] intValue];
  2802. //
  2803. // if (result==2)
  2804. // {
  2805. //
  2806. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2807. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2808. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2809. ////
  2810. //// [appDelegate update_count_mark];
  2811. // }
  2812. return jsobj;
  2813. }
  2814. //+(NSDictionary*)request_Cart:(int)sort
  2815. //{
  2816. //
  2817. // DebugLog(@"iSalesNetwork::request_Cart");
  2818. //
  2819. //
  2820. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2821. // __block AppDelegate *appDelegate = nil;
  2822. //
  2823. // dispatch_sync(dispatch_get_main_queue(), ^{
  2824. // //some UI methods ej
  2825. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2826. // });
  2827. // if(appDelegate.user!=nil)
  2828. // [params setValue:appDelegate.user forKey:@"user"];
  2829. // // if(appDelegate.contact_id!=nil)
  2830. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2831. // if(appDelegate.password!=nil)
  2832. // [params setValue:appDelegate.password forKey:@"password"];
  2833. //
  2834. // if(appDelegate.order_code!=nil)
  2835. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2836. //
  2837. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2838. //
  2839. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2840. //
  2841. // NSData* json=nil;
  2842. // if(appDelegate.offline_mode)
  2843. // {
  2844. // json= [OLDataProvider offline_requestcart:params];
  2845. // }
  2846. // else
  2847. // {
  2848. // if(![self IsNetworkAvailable])
  2849. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2850. //
  2851. // NSError *error=nil;
  2852. //
  2853. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2854. // params[@"resultSerial"]=uuid;
  2855. //
  2856. // for(int i=0;i<150;i++)
  2857. // {
  2858. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2859. // // result_params[@"resultSerial"]=uuid;
  2860. // json=[self get_json:URL_CART parameters:params];
  2861. // if(json!=nil)
  2862. // {
  2863. //
  2864. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2865. // if([jsobj[@"result"] intValue]==2)
  2866. // {
  2867. // break;
  2868. // }
  2869. // }
  2870. // sleep(2);
  2871. // }
  2872. //
  2873. // }
  2874. // if(json==nil)
  2875. // return nil;
  2876. // NSError *error=nil;
  2877. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2878. // int result = [[jsobj valueForKey:@"result"] intValue];
  2879. //
  2880. // if (result==2)
  2881. // {
  2882. //
  2883. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2884. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2885. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2886. //
  2887. // [appDelegate update_count_mark];
  2888. // }
  2889. // return jsobj;
  2890. //}
  2891. //+(NSDictionary*)request_Portfolio:(int)sort
  2892. //{
  2893. //
  2894. //
  2895. //
  2896. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2897. // __block AppDelegate *appDelegate = nil;
  2898. //
  2899. // dispatch_sync(dispatch_get_main_queue(), ^{
  2900. // //some UI methods ej
  2901. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2902. // });
  2903. // if(appDelegate.user!=nil)
  2904. // [params setValue:appDelegate.user forKey:@"user"];
  2905. // if(appDelegate.contact_id!=nil)
  2906. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2907. // if(appDelegate.password!=nil)
  2908. // [params setValue:appDelegate.password forKey:@"password"];
  2909. //
  2910. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2911. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2912. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2913. //
  2914. // [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2915. //
  2916. // NSData* json = nil;
  2917. // if(appDelegate.offline_mode)
  2918. // {
  2919. // json = [OLDataProvider offline_portfolioList:params];
  2920. // } else {
  2921. // if(![self IsNetworkAvailable])
  2922. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2923. //
  2924. // json = [self get_json:URL_PORTFOLIO parameters:params];
  2925. // }
  2926. //
  2927. //
  2928. // if(json==nil)
  2929. // return nil;
  2930. // NSError *error=nil;
  2931. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2932. // int result = [[jsobj valueForKey:@"result"] intValue];
  2933. //
  2934. // if (result==2)
  2935. // {
  2936. //
  2937. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2938. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2939. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  2940. //
  2941. // [appDelegate update_count_mark];
  2942. // }
  2943. // return jsobj;
  2944. //}
  2945. //+(NSDictionary*)request_WatchList:(int)sort
  2946. //{
  2947. //
  2948. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2949. // __block AppDelegate *appDelegate = nil;
  2950. //
  2951. // dispatch_sync(dispatch_get_main_queue(), ^{
  2952. // //some UI methods ej
  2953. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2954. // });
  2955. // if(appDelegate.user!=nil)
  2956. // [params setValue:appDelegate.user forKey:@"user"];
  2957. // if(appDelegate.contact_id!=nil)
  2958. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2959. // if(appDelegate.password!=nil)
  2960. // [params setValue:appDelegate.password forKey:@"password"];
  2961. //
  2962. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2963. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2964. //
  2965. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2966. //
  2967. // [params setObject:ScreenCodeWishList forKey:kScreenName];
  2968. //
  2969. // if(appDelegate.offline_mode)
  2970. // {
  2971. // return [OLDataProvider offline_wishlist:params];
  2972. // }
  2973. // if(![self IsNetworkAvailable])
  2974. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2975. //
  2976. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  2977. // if(json==nil)
  2978. // return nil;
  2979. // NSError *error=nil;
  2980. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2981. // int result = [[jsobj valueForKey:@"result"] intValue];
  2982. //
  2983. // if (result==2)
  2984. // {
  2985. //
  2986. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2987. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2988. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2989. //
  2990. // [appDelegate update_count_mark];
  2991. // }
  2992. // return jsobj;
  2993. //}
  2994. //+(NSDictionary*)request_ItemDetail: (NSString* ) item_id model_name:(NSString*) model_name category_id:(NSString*) category_id use_name :(bool) use_name groupName:(NSString *)groupName
  2995. //{
  2996. //
  2997. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2998. // __block AppDelegate *appDelegate = nil;
  2999. //
  3000. // dispatch_sync(dispatch_get_main_queue(), ^{
  3001. // //some UI methods ej
  3002. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3003. // });
  3004. // if(appDelegate.user!=nil)
  3005. // [params setValue:appDelegate.user forKey:@"user"];
  3006. // if(appDelegate.contact_id!=nil)
  3007. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3008. // if(appDelegate.password!=nil)
  3009. // [params setValue:appDelegate.password forKey:@"password"];
  3010. // if(appDelegate.order_code!=nil)
  3011. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3012. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3013. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3014. // if(use_name)
  3015. // [params setValue:model_name forKey:@"product_name"];
  3016. // else
  3017. // [params setValue:item_id forKey:@"product_id"];
  3018. //
  3019. //
  3020. // [params setValue:category_id forKey:@"category"];
  3021. //
  3022. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  3023. // [params setObject:@"Open A Model" forKey:kAction];
  3024. // if (model_name) {
  3025. // NSDictionary *extra = @{@"ModelName" : model_name};
  3026. // [params setObject:extra forKey:kExtra];
  3027. // }
  3028. //
  3029. // if (groupName.length > 0) {
  3030. // [params setObject:groupName forKey:@"groupName"];
  3031. // }
  3032. //
  3033. // if(appDelegate.offline_mode)
  3034. // return [OLDataProvider offline_model:params];
  3035. //
  3036. // if(![self IsNetworkAvailable])
  3037. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3038. //
  3039. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  3040. // if(json==nil)
  3041. // return nil;
  3042. // NSError *error=nil;
  3043. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3044. // return jsobj;
  3045. //}
  3046. //+(NSDictionary*)category_LoadMore: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(int)offset
  3047. //{
  3048. // if(![self IsNetworkAvailable])
  3049. // return nil;
  3050. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3051. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3052. // if(appDelegate.user!=nil)
  3053. // [params setValue:appDelegate.user forKey:@"user"];
  3054. // if(appDelegate.contact_id!=nil)
  3055. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3056. // if(appDelegate.password!=nil)
  3057. // [params setValue:appDelegate.password forKey:@"password"];
  3058. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3059. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3060. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3061. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3062. // [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  3063. // [params setValue:filter forKey:@"filter"];
  3064. // [params setValue:keyword forKey:@"keyword"];
  3065. //
  3066. //
  3067. // NSData* json=[self get_json:URL_CATEGORY_LOADMORE parameters:params];
  3068. // if(json==nil)
  3069. // return nil;
  3070. // NSError *error=nil;
  3071. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3072. // return jsobj;
  3073. //
  3074. //}
  3075. //+(NSDictionary*)Category_addall: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  3076. //
  3077. //{
  3078. //
  3079. //
  3080. // __block AppDelegate *appDelegate = nil;
  3081. //
  3082. // dispatch_sync(dispatch_get_main_queue(), ^{
  3083. // //some UI methods ej
  3084. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3085. // });
  3086. //
  3087. //
  3088. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3089. //
  3090. // if(appDelegate.user!=nil)
  3091. // [params setValue:appDelegate.user forKey:@"user"];
  3092. // if(appDelegate.contact_id!=nil)
  3093. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3094. // if(appDelegate.password!=nil)
  3095. // [params setValue:appDelegate.password forKey:@"password"];
  3096. // if(appDelegate.order_code!=nil)
  3097. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3098. //
  3099. // [params setValue:addTo forKey:@"addTo"];
  3100. // [params setValue:orderCode forKey:@"orderCode"];
  3101. // [params setValue:alert forKey:@"alert"];
  3102. // [params setValue:qty forKey:@"sold_by_qty"];
  3103. // [params setValue:available forKey:@"available"];
  3104. // [params setValue:price forKey:@"price"];
  3105. // [params setValue:bestseller forKey:@"bestseller"];
  3106. // [params setValue:modelname forKey:@"modelName"];
  3107. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3108. //
  3109. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3110. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3111. // [params setValue:category forKey:@"category"];
  3112. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3113. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3114. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3115. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3116. // [params setValue:filter forKey:@"filter"];
  3117. // [params setValue:keyword forKey:@"keyword"];
  3118. //
  3119. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  3120. // if ([addTo isEqualToString:@"cart"]) {
  3121. // [params setObject:@"Add To Cart" forKey:kAction];
  3122. // }
  3123. //
  3124. //
  3125. // NSData* json= nil;
  3126. //
  3127. // if(appDelegate.offline_mode)
  3128. // {
  3129. // json= [OLDataProvider offline_categoryaddall:params];
  3130. // }
  3131. // else
  3132. // {
  3133. // if(![self IsNetworkAvailable])
  3134. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3135. //
  3136. //
  3137. // NSError *error=nil;
  3138. //
  3139. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3140. // params[@"resultSerial"]=uuid;
  3141. //
  3142. // for(int i=0;i<150;i++)
  3143. // {
  3144. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3145. // // result_params[@"resultSerial"]=uuid;
  3146. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  3147. // if(json!=nil)
  3148. // {
  3149. //
  3150. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3151. // int resultInt = [jsobj[@"result"] intValue];
  3152. // if(resultInt == 2 || resultInt == 8)
  3153. // {
  3154. // break;
  3155. // }
  3156. // }
  3157. // sleep(2);
  3158. // }
  3159. //
  3160. //
  3161. //
  3162. // }
  3163. // if(json==nil)
  3164. // return nil;
  3165. // NSError *error=nil;
  3166. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3167. // return jsobj;
  3168. //
  3169. //}
  3170. //+(NSDictionary*)category_addall2portfolio: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip
  3171. //{
  3172. //
  3173. //
  3174. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3175. //
  3176. //
  3177. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3178. //
  3179. // if(appDelegate.user!=nil)
  3180. // [params setValue:appDelegate.user forKey:@"user"];
  3181. // if(appDelegate.contact_id!=nil)
  3182. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3183. // if(appDelegate.password!=nil)
  3184. // [params setValue:appDelegate.password forKey:@"password"];
  3185. // if(appDelegate.order_code!=nil)
  3186. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3187. //
  3188. // [params setValue:alert forKey:@"alert"];
  3189. // [params setValue:qty forKey:@"sold_by_qty"];
  3190. // [params setValue:available forKey:@"available"];
  3191. // [params setValue:price forKey:@"price"];
  3192. // [params setValue:bestseller forKey:@"bestseller"];
  3193. // [params setValue:modelname forKey:@"modelName"];
  3194. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3195. //
  3196. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3197. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3198. // [params setValue:category forKey:@"category"];
  3199. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3200. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3201. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3202. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3203. // [params setValue:filter forKey:@"filter"];
  3204. // [params setValue:keyword forKey:@"keyword"];
  3205. //
  3206. //
  3207. //
  3208. // if(appDelegate.offline_mode)
  3209. // return [OLDataProvider offline_category:params];
  3210. // if(![self IsNetworkAvailable])
  3211. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3212. //
  3213. // NSData* json=[self get_json:URL_ADDALL2PORTFOLIO parameters:params];
  3214. // if(json==nil)
  3215. // return nil;
  3216. // NSError *error=nil;
  3217. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3218. // return jsobj;
  3219. //
  3220. //}
  3221. //+(NSDictionary*)category_addall2wish: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip
  3222. //{
  3223. //
  3224. //
  3225. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3226. //
  3227. //
  3228. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3229. //
  3230. // if(appDelegate.user!=nil)
  3231. // [params setValue:appDelegate.user forKey:@"user"];
  3232. // if(appDelegate.contact_id!=nil)
  3233. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3234. // if(appDelegate.password!=nil)
  3235. // [params setValue:appDelegate.password forKey:@"password"];
  3236. // if(appDelegate.order_code!=nil)
  3237. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3238. //
  3239. // [params setValue:alert forKey:@"alert"];
  3240. // [params setValue:qty forKey:@"sold_by_qty"];
  3241. // [params setValue:available forKey:@"available"];
  3242. // [params setValue:price forKey:@"price"];
  3243. // [params setValue:bestseller forKey:@"bestseller"];
  3244. // [params setValue:modelname forKey:@"modelName"];
  3245. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3246. //
  3247. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3248. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3249. // [params setValue:category forKey:@"category"];
  3250. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3251. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3252. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3253. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3254. // [params setValue:filter forKey:@"filter"];
  3255. // [params setValue:keyword forKey:@"keyword"];
  3256. //
  3257. //
  3258. //
  3259. // if(appDelegate.offline_mode)
  3260. // return [OLDataProvider offline_category:params];
  3261. // if(![self IsNetworkAvailable])
  3262. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3263. //
  3264. // NSData* json=[self get_json:URL_ADDALL2WISH parameters:params];
  3265. // if(json==nil)
  3266. // return nil;
  3267. // NSError *error=nil;
  3268. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3269. // return jsobj;
  3270. //
  3271. //}
  3272. //+(NSDictionary*)Category: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip
  3273. //{
  3274. //
  3275. //
  3276. // __block AppDelegate *appDelegate = nil;
  3277. //
  3278. // dispatch_sync(dispatch_get_main_queue(), ^{
  3279. // //some UI methods ej
  3280. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3281. // });
  3282. //
  3283. //
  3284. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3285. //
  3286. // if(appDelegate.user!=nil)
  3287. // [params setValue:appDelegate.user forKey:@"user"];
  3288. // if(appDelegate.contact_id!=nil)
  3289. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3290. // if(appDelegate.password!=nil)
  3291. // [params setValue:appDelegate.password forKey:@"password"];
  3292. // if(appDelegate.order_code!=nil)
  3293. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3294. //
  3295. // [params setValue:alert forKey:@"alert"];
  3296. // [params setValue:qty forKey:@"sold_by_qty"];
  3297. // [params setValue:available forKey:@"available"];
  3298. // [params setValue:price forKey:@"price"];
  3299. // [params setValue:bestseller forKey:@"bestseller"];
  3300. // [params setValue:modelname forKey:@"modelName"];
  3301. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3302. //
  3303. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3304. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3305. // [params setValue:category forKey:@"category"];
  3306. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3307. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3308. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3309. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3310. // [params setValue:filter forKey:@"filter"];
  3311. // [params setValue:keyword forKey:@"keyword"];
  3312. //
  3313. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  3314. // if (alert) {
  3315. // [params setObject:@"Filter" forKey:kAction];
  3316. // }
  3317. // if ([Singleton sharedInstance].homeItemClick) {
  3318. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  3319. // [Singleton sharedInstance].homeItemClick = NO;
  3320. //
  3321. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  3322. // [Singleton sharedInstance].homeClickedItemName = nil;
  3323. // [params setObject:extra forKey:kExtra];
  3324. //
  3325. // }
  3326. //
  3327. //
  3328. // if(appDelegate.offline_mode)
  3329. // return [OLDataProvider offline_category:params];
  3330. // if(![self IsNetworkAvailable])
  3331. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3332. //
  3333. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  3334. // if(json==nil)
  3335. // return nil;
  3336. // NSError *error=nil;
  3337. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3338. // return jsobj;
  3339. //
  3340. //}
  3341. //+(NSDictionary*)Search_addall:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  3342. //{
  3343. //
  3344. //
  3345. //
  3346. //
  3347. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3348. // __block AppDelegate *appDelegate = nil;
  3349. //
  3350. // dispatch_sync(dispatch_get_main_queue(), ^{
  3351. // //some UI methods ej
  3352. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3353. // });
  3354. // if(appDelegate.user!=nil)
  3355. // [params setValue:appDelegate.user forKey:@"user"];
  3356. // if(appDelegate.contact_id!=nil)
  3357. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3358. // if(appDelegate.password!=nil)
  3359. // [params setValue:appDelegate.password forKey:@"password"];
  3360. // if(appDelegate.order_code!=nil)
  3361. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3362. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3363. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3364. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3365. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3366. // // [params setValue:filter forKey:@"filter"];
  3367. // [params setValue:keywords forKey:@"keyword"];
  3368. // [params setValue:addTo forKey:@"addTo"];
  3369. //
  3370. // [params setValue:orderCode forKey:@"orderCode"];
  3371. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3372. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3373. // if(matchfull)
  3374. // [params setValue:@"true" forKey:@"exactMatch"];
  3375. // else
  3376. // [params setValue:@"false" forKey:@"exactMatch"];
  3377. //
  3378. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  3379. // if ([addTo isEqualToString:@"cart"]) {
  3380. // [params setObject:@"Add To Cart" forKey:kAction];
  3381. // }
  3382. //
  3383. // NSData* json=nil;
  3384. // if(appDelegate.offline_mode)
  3385. // {
  3386. // json=[OLDataProvider offline_searchaddall:params];
  3387. // }
  3388. // else
  3389. // {
  3390. // if(![self IsNetworkAvailable])
  3391. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3392. //
  3393. // NSError *error=nil;
  3394. //
  3395. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3396. // params[@"resultSerial"]=uuid;
  3397. //
  3398. // for(int i=0;i<150;i++)
  3399. // {
  3400. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3401. // // result_params[@"resultSerial"]=uuid;
  3402. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  3403. // if(json!=nil)
  3404. // {
  3405. //
  3406. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3407. // if([jsobj[@"result"] intValue]==2)
  3408. // {
  3409. // break;
  3410. // }
  3411. // }
  3412. // sleep(2);
  3413. // }
  3414. // }
  3415. // if(json==nil)
  3416. // return nil;
  3417. // NSError *error=nil;
  3418. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3419. // return jsobj;
  3420. //
  3421. //}
  3422. //+(NSDictionary*)Search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull
  3423. //{
  3424. //
  3425. //
  3426. //
  3427. //
  3428. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3429. // __block AppDelegate *appDelegate = nil;
  3430. //
  3431. // dispatch_sync(dispatch_get_main_queue(), ^{
  3432. // //some UI methods ej
  3433. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3434. // });
  3435. // if(appDelegate.user!=nil)
  3436. // [params setValue:appDelegate.user forKey:@"user"];
  3437. // if(appDelegate.contact_id!=nil)
  3438. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3439. // if(appDelegate.password!=nil)
  3440. // [params setValue:appDelegate.password forKey:@"password"];
  3441. // if(appDelegate.order_code!=nil)
  3442. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3443. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3444. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3445. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3446. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3447. // // [params setValue:filter forKey:@"filter"];
  3448. // [params setValue:keywords forKey:@"keyword"];
  3449. //
  3450. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3451. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3452. // if(matchfull)
  3453. // [params setValue:@"true" forKey:@"exactMatch"];
  3454. // else
  3455. // [params setValue:@"false" forKey:@"exactMatch"];
  3456. //
  3457. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  3458. // if (keywords) {
  3459. // [params setObject:@"Search" forKey:kAction];
  3460. // }
  3461. //
  3462. // if(appDelegate.offline_mode)
  3463. // {
  3464. // return [OLDataProvider offline_search:params];
  3465. // }
  3466. // if(![self IsNetworkAvailable])
  3467. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3468. //
  3469. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3470. // if(json==nil)
  3471. // return nil;
  3472. // NSError *error=nil;
  3473. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3474. // return jsobj;
  3475. //}
  3476. //+(NSDictionary*)ItemSearch_addall:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  3477. //{
  3478. // // for debug
  3479. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3480. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3481. //
  3482. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3483. // __block AppDelegate *appDelegate = nil;
  3484. //
  3485. // dispatch_sync(dispatch_get_main_queue(), ^{
  3486. // //some UI methods ej
  3487. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3488. // });
  3489. // if(appDelegate.user!=nil)
  3490. // [params setValue:appDelegate.user forKey:@"user"];
  3491. // if(appDelegate.contact_id!=nil)
  3492. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3493. // if(appDelegate.password!=nil)
  3494. // [params setValue:appDelegate.password forKey:@"password"];
  3495. // if(appDelegate.order_code!=nil)
  3496. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3497. //
  3498. // [params setValue:addTo forKey:@"addTo"];
  3499. //
  3500. // [params setValue:orderCode forKey:@"orderCode"];
  3501. //
  3502. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3503. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3504. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3505. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3506. // // [params setValue:filter forKey:@"filter"];
  3507. // [params setValue:covertype forKey:@"covertype"];
  3508. // [params setValue:ctgid forKey:@"ctgId"];
  3509. // [params setValue:modelname forKey:@"modelName"];
  3510. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3511. // [params setValue:alert forKey:@"alert"];
  3512. // [params setValue:qty forKey:@"sold_by_qty"];
  3513. // [params setValue:available forKey:@"available"];
  3514. // [params setValue:price forKey:@"price"];
  3515. // [params setValue:bestseller forKey:@"bestseller"];
  3516. //
  3517. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3518. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3519. //
  3520. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3521. // if ([addTo isEqualToString:@"cart"]) {
  3522. // [params setObject:@"Add To Cart" forKey:kAction];
  3523. // }
  3524. //
  3525. // NSData* json = nil;
  3526. //
  3527. // if(appDelegate.offline_mode)
  3528. // {
  3529. // json= [OLDataProvider offline_itemsearchaddall:params];
  3530. // }
  3531. // else
  3532. // {
  3533. // if(![self IsNetworkAvailable])
  3534. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3535. // NSError *error=nil;
  3536. //
  3537. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3538. // params[@"resultSerial"]=uuid;
  3539. //
  3540. // for(int i=0;i<150;i++)
  3541. // {
  3542. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3543. // // result_params[@"resultSerial"]=uuid;
  3544. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  3545. // if(json!=nil)
  3546. // {
  3547. //
  3548. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3549. // if([jsobj[@"result"] intValue]==2)
  3550. // {
  3551. // break;
  3552. // }
  3553. // }
  3554. // sleep(2);
  3555. // }
  3556. // }
  3557. // if(json==nil)
  3558. // return nil;
  3559. // NSError *error=nil;
  3560. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3561. // return jsobj;
  3562. //}
  3563. //+(NSDictionary*)ItemSearch:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller
  3564. //{
  3565. //
  3566. // // for debug
  3567. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3568. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3569. //
  3570. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3571. // __block AppDelegate *appDelegate = nil;
  3572. //
  3573. // dispatch_sync(dispatch_get_main_queue(), ^{
  3574. // //some UI methods ej
  3575. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3576. // });
  3577. // if(appDelegate.user!=nil)
  3578. // [params setValue:appDelegate.user forKey:@"user"];
  3579. // if(appDelegate.contact_id!=nil)
  3580. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3581. // if(appDelegate.password!=nil)
  3582. // [params setValue:appDelegate.password forKey:@"password"];
  3583. // if(appDelegate.order_code!=nil)
  3584. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3585. //
  3586. //
  3587. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3588. // if (alert && qty && available && price && bestseller) {
  3589. // [params setObject:@"Filter" forKey:kAction];
  3590. // }
  3591. // if ([Singleton sharedInstance].homeItemClick) {
  3592. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  3593. // [Singleton sharedInstance].homeItemClick = NO;
  3594. //
  3595. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  3596. // [Singleton sharedInstance].homeClickedItemName = nil;
  3597. // [params setObject:extra forKey:kExtra];
  3598. // }
  3599. //
  3600. //
  3601. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3602. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3603. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3604. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3605. // // [params setValue:filter forKey:@"filter"];
  3606. // [params setValue:covertype forKey:@"covertype"];
  3607. // [params setValue:ctgid forKey:@"ctgId"];
  3608. // [params setValue:modelname forKey:@"modelName"];
  3609. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3610. // [params setValue:alert forKey:@"alert"];
  3611. // [params setValue:qty forKey:@"sold_by_qty"];
  3612. // [params setValue:available forKey:@"available"];
  3613. // [params setValue:price forKey:@"price"];
  3614. // [params setValue:bestseller forKey:@"bestseller"];
  3615. //
  3616. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3617. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3618. //
  3619. // if(appDelegate.offline_mode)
  3620. // {
  3621. // return [OLDataProvider offline_itemsearch:params];
  3622. // }
  3623. // if(![self IsNetworkAvailable])
  3624. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3625. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  3626. // if(json==nil)
  3627. // return nil;
  3628. // NSError *error=nil;
  3629. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3630. // return jsobj;
  3631. //}
  3632. //+(NSDictionary*)Search: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword
  3633. //{
  3634. // if(![self IsNetworkAvailable])
  3635. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3636. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3637. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3638. // if(appDelegate.user!=nil)
  3639. // [params setValue:appDelegate.user forKey:@"user"];
  3640. // if(appDelegate.contact_id!=nil)
  3641. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3642. // if(appDelegate.password!=nil)
  3643. // [params setValue:appDelegate.password forKey:@"password"];
  3644. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3645. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3646. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3647. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3648. // [params setValue:filter forKey:@"filter"];
  3649. // [params setValue:keyword forKey:@"keyword"];
  3650. //
  3651. //
  3652. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3653. // if(json==nil)
  3654. // return nil;
  3655. // NSError *error=nil;
  3656. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3657. // return jsobj;
  3658. //}
  3659. +(NSDictionary*)request_model_qty: (NSString*) fashionId
  3660. {
  3661. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3662. __block AppDelegate *appDelegate = nil;
  3663. dispatch_sync(dispatch_get_main_queue(), ^{
  3664. //some UI methods ej
  3665. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3666. });
  3667. if(appDelegate.user!=nil)
  3668. [params setValue:appDelegate.user forKey:@"user"];
  3669. if(appDelegate.contact_id!=nil)
  3670. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3671. if(appDelegate.password!=nil)
  3672. [params setValue:appDelegate.password forKey:@"password"];
  3673. [params setValue:fashionId forKey:@"fashionId"];
  3674. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  3675. NSData* json = nil;
  3676. if(appDelegate.offline_mode)
  3677. {
  3678. json = [OLDataProvider offline_model_qty:params];
  3679. } else {
  3680. if(![self IsNetworkAvailable])
  3681. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3682. json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  3683. }
  3684. if(json==nil)
  3685. return nil;
  3686. NSError *error=nil;
  3687. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3688. return jsobj;
  3689. }
  3690. +(NSDictionary*)retrieve_password: (NSString*) user email:(NSString*) email
  3691. {
  3692. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3693. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3694. // if(appDelegate.user!=nil)
  3695. // [params setValue:appDelegate.user forKey:@"user"];
  3696. // if(appDelegate.contact_id!=nil)
  3697. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3698. // if(appDelegate.password!=nil)
  3699. // [params setValue:appDelegate.password forKey:@"password"];
  3700. [params setValue:user forKey:@"username"];
  3701. [params setValue:email forKey:@"email"];
  3702. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3703. if(![self IsNetworkAvailable])
  3704. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3705. NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  3706. if(json==nil)
  3707. return nil;
  3708. NSError *error=nil;
  3709. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3710. return jsobj;
  3711. }
  3712. +(NSDictionary*)load_HomePage:(int) price_template customid:(int) customid
  3713. {
  3714. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3715. __block AppDelegate *appDelegate = nil;
  3716. dispatch_sync(dispatch_get_main_queue(), ^{
  3717. //some UI methods ej
  3718. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3719. });
  3720. if(appDelegate.user!=nil)
  3721. [params setValue:appDelegate.user forKey:@"user"];
  3722. if(appDelegate.contact_id!=nil)
  3723. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3724. if(appDelegate.password!=nil)
  3725. [params setValue:appDelegate.password forKey:@"password"];
  3726. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3727. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3728. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  3729. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3730. if(appDelegate.offline_mode)
  3731. {
  3732. //params[@"offline_Command"]=url;
  3733. return [OLDataProvider offline_home];
  3734. }
  3735. if(![self IsNetworkAvailable])
  3736. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3737. NSData* json=[self get_json:URL_LOAD_HOME parameters:params];
  3738. if(json==nil)
  3739. return nil;
  3740. NSError *error=nil;
  3741. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3742. return jsobj;
  3743. }
  3744. //+(NSDictionary*)logout
  3745. //{
  3746. //
  3747. //
  3748. //
  3749. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3750. // __block AppDelegate *appDelegate = nil;
  3751. //
  3752. // dispatch_sync(dispatch_get_main_queue(), ^{
  3753. // //some UI methods ej
  3754. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3755. // });
  3756. // if(appDelegate.user!=nil)
  3757. // [params setValue:appDelegate.user forKey:@"user"];
  3758. //
  3759. //
  3760. // if(appDelegate.password!=nil)
  3761. // [params setValue:appDelegate.password forKey:@"password"];
  3762. //
  3763. //
  3764. // if(appDelegate.offline_mode)
  3765. // {
  3766. // return [OLDataProvider offline_logout:params];
  3767. // }
  3768. // if(![self IsNetworkAvailable])
  3769. // {
  3770. // DebugLog(@"NET ERR");
  3771. //
  3772. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3773. // // return nil;
  3774. // }
  3775. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  3776. // //if(json==nil)
  3777. //
  3778. //
  3779. // if(json==nil)
  3780. // return nil;
  3781. // NSError *error=nil;
  3782. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3783. // int result = [[jsobj valueForKey:@"result"] intValue];
  3784. //
  3785. // if (result==2)
  3786. // {
  3787. //
  3788. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  3789. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  3790. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  3791. //
  3792. // [appDelegate update_count_mark];
  3793. //
  3794. //
  3795. // appDelegate.can_show_price =false;
  3796. // appDelegate.can_see_price =false;
  3797. // appDelegate.can_create_portfolio =false;
  3798. // appDelegate.can_create_order =false;
  3799. //
  3800. //
  3801. // appDelegate.can_cancel_order =false;
  3802. // appDelegate.can_set_cart_price =false;
  3803. // appDelegate.can_delete_order =false;
  3804. // appDelegate.can_submit_order =false;
  3805. // appDelegate.can_set_tearsheet_price =false;
  3806. // appDelegate.can_update_contact_info = false;
  3807. //
  3808. // appDelegate.save_order_logout = false;
  3809. // appDelegate.submit_order_logout = false;
  3810. // appDelegate.alert_sold_in_quantities = false;
  3811. //
  3812. // appDelegate.ipad_perm =nil ;
  3813. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  3814. // appDelegate.OrderFilter= nil;
  3815. // [appDelegate SetSo:nil];
  3816. // [appDelegate set_main_button_panel];
  3817. //#ifdef RA_NOTIFICATION
  3818. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  3819. //#endif
  3820. // }
  3821. // return jsobj;
  3822. //}
  3823. +(NSDictionary*)request_Cagegory
  3824. {
  3825. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  3826. __block AppDelegate *appDelegate = nil;
  3827. dispatch_sync(dispatch_get_main_queue(), ^{
  3828. //some UI methods ej
  3829. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3830. });
  3831. if(appDelegate.offline_mode)
  3832. {
  3833. //params[@"offline_Command"]=url;
  3834. return [OLDataProvider offline_category_menu];
  3835. }
  3836. if(![self IsNetworkAvailable])
  3837. {
  3838. DebugLog(@"NET ERR");
  3839. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3840. // return nil;
  3841. }
  3842. NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  3843. //if(json==nil)
  3844. if(json==nil)
  3845. return nil;
  3846. NSError *error=nil;
  3847. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3848. return jsobj;
  3849. }
  3850. +(int)Authorize : (NSString*) user password:(NSString*) password{
  3851. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  3852. // return RESULT_NET_ERROR;
  3853. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3854. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3855. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3856. __block AppDelegate *appDelegate = nil;
  3857. dispatch_sync(dispatch_get_main_queue(), ^{
  3858. //some UI methods ej
  3859. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3860. });
  3861. if(appDelegate.duid !=nil)
  3862. [params setValue:appDelegate.duid forKey:@"udid"];
  3863. [params setValue:@"handset_login" forKey:@"action"];
  3864. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  3865. [params setValue:user forKey:@"user"];
  3866. [params setValue:password forKey:@"password"];
  3867. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  3868. #ifdef TEST
  3869. [params setValue:@"true" forKey:@"is_debug"];
  3870. #else
  3871. [params setValue:@"false" forKey:@"is_debug"];
  3872. #endif
  3873. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3874. [params setObject:@"Login" forKey:kAction];
  3875. NSData* json= nil;
  3876. if(appDelegate.offline_mode)
  3877. {
  3878. json= [OLDataProvider offline_login:params] ;
  3879. }
  3880. else
  3881. {
  3882. if(![self IsNetworkAvailable])
  3883. return RESULT_NET_NOTAVAILABLE;
  3884. json =[self get_json:URL_UPDATE_AUTH parameters:params];
  3885. }
  3886. if(json==nil)
  3887. return RESULT_NET_ERROR;
  3888. int ret = [self parse_authinfo:json user:user password:password];
  3889. DebugLog(@"parse_authinfo return %d ",ret);
  3890. return ret;
  3891. }
  3892. +(NSDictionary*)update_customer_img: (NSString*) contactid img_url:(NSString*) url
  3893. {
  3894. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3895. __block AppDelegate *appDelegate = nil;
  3896. dispatch_sync(dispatch_get_main_queue(), ^{
  3897. //some UI methods ej
  3898. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3899. });
  3900. if(appDelegate.user!=nil)
  3901. [params setValue:appDelegate.user forKey:@"user"];
  3902. // if(appDelegate.contact_id!=nil)
  3903. if(appDelegate.password!=nil)
  3904. [params setValue:appDelegate.password forKey:@"password"];
  3905. [params setValue:contactid forKey:@"contactId"];
  3906. [params setValue:url forKey:@"business_card"];
  3907. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  3908. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  3909. if(appDelegate.offline_mode)
  3910. {
  3911. return [OLDataProvider offline_notimpl];
  3912. }
  3913. if(![self IsNetworkAvailable])
  3914. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3915. NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  3916. if(json==nil)
  3917. return nil;
  3918. NSError *error=nil;
  3919. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3920. return jsobj;
  3921. }
  3922. +(NSDictionary*)request_PendingOrder:(NSString *)contactid
  3923. {
  3924. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3925. __block AppDelegate *appDelegate = nil;
  3926. dispatch_sync(dispatch_get_main_queue(), ^{
  3927. //some UI methods ej
  3928. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3929. });
  3930. if(appDelegate.user!=nil)
  3931. [params setValue:appDelegate.user forKey:@"user"];
  3932. // if(appDelegate.contact_id!=nil)
  3933. if(appDelegate.password!=nil)
  3934. [params setValue:appDelegate.password forKey:@"password"];
  3935. [params setValue:contactid forKey:@"contactId"];
  3936. if(appDelegate.offline_mode)
  3937. {
  3938. return [OLDataProvider offline_notimpl];
  3939. }
  3940. if(![self IsNetworkAvailable])
  3941. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3942. NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  3943. if(json==nil)
  3944. return nil;
  3945. NSError *error=nil;
  3946. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3947. return jsobj;
  3948. }
  3949. //+(NSDictionary*)request_CustomerInfo:(NSString* ) contactid
  3950. //{
  3951. //
  3952. //
  3953. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3954. // __block AppDelegate *appDelegate = nil;
  3955. //
  3956. // dispatch_sync(dispatch_get_main_queue(), ^{
  3957. // //some UI methods ej
  3958. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3959. // });
  3960. // if(appDelegate.user!=nil)
  3961. // [params setValue:appDelegate.user forKey:@"user"];
  3962. // // if(appDelegate.contact_id!=nil)
  3963. //
  3964. // if(appDelegate.password!=nil)
  3965. // [params setValue:appDelegate.password forKey:@"password"];
  3966. // [params setValue:contactid forKey:@"contactId"];
  3967. //
  3968. // [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  3969. //
  3970. // if(appDelegate.offline_mode)
  3971. // return [OLDataProvider offline_contactinfo:params];
  3972. // if(![self IsNetworkAvailable])
  3973. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3974. //
  3975. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  3976. // if(json==nil)
  3977. // return nil;
  3978. // NSError *error=nil;
  3979. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3980. // return jsobj;
  3981. //
  3982. //}
  3983. +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
  3984. {
  3985. DebugLog(@"parse_authinfo");
  3986. NSError *error=nil;
  3987. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3988. if(jsobj)
  3989. {
  3990. __block AppDelegate *appDelegate = nil;
  3991. dispatch_sync(dispatch_get_main_queue(), ^{
  3992. //some UI methods ej
  3993. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3994. });
  3995. int result = [[jsobj valueForKey:@"result"] intValue];
  3996. if (result<0)
  3997. return result;
  3998. if(result!=AP_USER_AUTH&& result!=9)
  3999. {
  4000. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  4001. // [appDelegate Logout];
  4002. if(result==8)
  4003. {
  4004. return RESULT_LOGIN_DEVICE;
  4005. }
  4006. return RESULT_FALSE;
  4007. }
  4008. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  4009. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  4010. user=[objheader objectForKey:@"username"] ;
  4011. DebugLog(@"required_ver=%@ ",required_ver);
  4012. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  4013. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  4014. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  4015. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  4016. // if([ibadge isEqual:[NSNull null]])
  4017. // strbadge=@"0";
  4018. // if(ibadge==nil)
  4019. // ibadge=@"0";
  4020. // if([strbadge isEqualToString:@"null"])
  4021. // strbadge=@"0";
  4022. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  4023. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  4024. if([appDelegate.build intValue]<[required_ver intValue])
  4025. return RESULT_VER_LOW;
  4026. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  4027. appDelegate.user = user;
  4028. appDelegate.password = password;
  4029. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  4030. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  4031. appDelegate.bLogin = true;
  4032. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  4033. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  4034. {
  4035. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  4036. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  4037. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  4038. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  4039. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  4040. }
  4041. NSString* mode =[jsobj valueForKey:@"mode"] ;
  4042. [appDelegate SetMode:mode];
  4043. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  4044. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  4045. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  4046. [appDelegate update_count_mark];
  4047. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  4048. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  4049. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  4050. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  4051. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  4052. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  4053. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  4054. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  4055. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  4056. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  4057. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  4058. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  4059. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  4060. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  4061. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  4062. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  4063. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  4064. [appDelegate set_main_button_panel];
  4065. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  4066. // shop order status filter
  4067. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  4068. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  4069. // Sales order status filter
  4070. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  4071. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  4072. // specialInstruction
  4073. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  4074. //-价格类型
  4075. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  4076. // 权限
  4077. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  4078. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  4079. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  4080. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  4081. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  4082. [[RASingleton sharedInstance] resetGlobalLock];
  4083. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  4084. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  4085. }
  4086. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  4087. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  4088. // {
  4089. // // no update on the server;
  4090. // return RESULT_TRUE;
  4091. // }
  4092. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  4093. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4094. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4095. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4096. // [defaults synchronize];
  4097. //
  4098. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  4099. // NSArray* keys= [objfuncs allKeys];
  4100. /*
  4101. db.setTransactionSuccessful();
  4102. db.endTransaction();
  4103. */
  4104. return RESULT_TRUE;
  4105. }
  4106. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  4107. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  4108. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  4109. return RESULT_USERAUTH_ERROR;
  4110. }
  4111. //+(bool) IsNetworkAvailable
  4112. //{
  4113. //
  4114. // if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) &&
  4115. // ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable))
  4116. // return false;
  4117. // return true;
  4118. //}
  4119. //+(NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim
  4120. //{
  4121. // NSScanner *theScanner = [NSScanner scannerWithString:html];
  4122. // NSString *text = nil;
  4123. //
  4124. // while ([theScanner isAtEnd] == NO) {
  4125. // // find start of tag
  4126. // [theScanner scanUpToString:@"<" intoString:NULL] ;
  4127. // // find end of tag
  4128. // [theScanner scanUpToString:@">" intoString:&text] ;
  4129. // // replace the found tag with a space
  4130. // //(you can filter multi-spaces out later if you wish)
  4131. // html = [html stringByReplacingOccurrencesOfString:
  4132. // [ NSString stringWithFormat:@"%@>", text]
  4133. // withString:@""];
  4134. // }
  4135. //
  4136. // return trim ? [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : html;
  4137. //}
  4138. //
  4139. //+(NSString *)flattenURL:(NSString *)url trimWhiteSpace:(BOOL)trim
  4140. //{
  4141. // NSScanner *theScanner = [NSScanner scannerWithString:url];
  4142. // NSString *text = nil;
  4143. //
  4144. // while ([theScanner isAtEnd] == NO) {
  4145. // // find start of tag
  4146. // [theScanner scanUpToString:@"/" intoString:NULL] ;
  4147. // // find end of tag
  4148. // [theScanner scanUpToString:@"/" intoString:&text] ;
  4149. // // replace the found tag with a space
  4150. // //(you can filter multi-spaces out later if you wish)
  4151. // url = [url stringByReplacingOccurrencesOfString:
  4152. // [ NSString stringWithFormat:@"%@", text]
  4153. // withString:@""];
  4154. // }
  4155. //
  4156. // return trim ? [url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : url;
  4157. //}
  4158. + (NSDictionary *)set_npd_shop_price_type:(NSInteger)priceType {
  4159. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4160. __block AppDelegate *appDelegate = nil;
  4161. dispatch_sync(dispatch_get_main_queue(), ^{
  4162. //some UI methods ej
  4163. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4164. });
  4165. if(appDelegate.user!=nil)
  4166. [dic setValue:appDelegate.user forKey:@"user"];
  4167. if(appDelegate.password!=nil)
  4168. [dic setValue:appDelegate.password forKey:@"password"];
  4169. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  4170. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  4171. NSData* json=nil;
  4172. if(appDelegate.offline_mode)
  4173. {
  4174. return [OLDataProvider offline_notimpl];
  4175. }
  4176. else
  4177. {
  4178. if(![self IsNetworkAvailable])
  4179. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4180. json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  4181. }
  4182. if(json!=nil)
  4183. {
  4184. NSError *error=nil;
  4185. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4186. return jsobj;
  4187. }
  4188. return nil;
  4189. }
  4190. + (NSDictionary *)get_npd_shop_givenPrice {
  4191. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4192. __block AppDelegate *appDelegate = nil;
  4193. dispatch_sync(dispatch_get_main_queue(), ^{
  4194. //some UI methods ej
  4195. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4196. });
  4197. if(appDelegate.user!=nil)
  4198. [dic setValue:appDelegate.user forKey:@"user"];
  4199. if(appDelegate.password!=nil)
  4200. [dic setValue:appDelegate.password forKey:@"password"];
  4201. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  4202. NSData* json=nil;
  4203. if(appDelegate.offline_mode)
  4204. {
  4205. return [OLDataProvider offline_notimpl];
  4206. }
  4207. else
  4208. {
  4209. if(![self IsNetworkAvailable])
  4210. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4211. json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  4212. }
  4213. if(json!=nil)
  4214. {
  4215. NSError *error=nil;
  4216. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4217. return jsobj;
  4218. }
  4219. return nil;
  4220. }
  4221. + (NSDictionary *)set_npd_shop_givenPrice:(NSMutableDictionary *)params {
  4222. __block AppDelegate *appDelegate = nil;
  4223. dispatch_sync(dispatch_get_main_queue(), ^{
  4224. //some UI methods ej
  4225. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4226. });
  4227. if(appDelegate.user!=nil)
  4228. [params setValue:appDelegate.user forKey:@"user"];
  4229. if(appDelegate.password!=nil)
  4230. [params setValue:appDelegate.password forKey:@"password"];
  4231. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  4232. NSData* json=nil;
  4233. if(appDelegate.offline_mode)
  4234. {
  4235. return [OLDataProvider offline_notimpl];
  4236. }
  4237. else
  4238. {
  4239. if(![self IsNetworkAvailable])
  4240. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4241. json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  4242. }
  4243. if(json!=nil)
  4244. {
  4245. NSError *error=nil;
  4246. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4247. return jsobj;
  4248. }
  4249. return nil;
  4250. }
  4251. + (NSDictionary *)merge_order:(NSMutableDictionary *)params {
  4252. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4253. __block AppDelegate *appDelegate = nil;
  4254. dispatch_sync(dispatch_get_main_queue(), ^{
  4255. //some UI methods ej
  4256. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4257. });
  4258. if(appDelegate.user!=nil)
  4259. [dic setValue:appDelegate.user forKey:@"user"];
  4260. if(appDelegate.password!=nil)
  4261. [dic setValue:appDelegate.password forKey:@"password"];
  4262. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  4263. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  4264. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  4265. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  4266. NSData* json=nil;
  4267. if(appDelegate.offline_mode)
  4268. {
  4269. return [OLDataProvider offline_notimpl];
  4270. }
  4271. else
  4272. {
  4273. if(![self IsNetworkAvailable])
  4274. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4275. json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  4276. }
  4277. if(json!=nil)
  4278. {
  4279. NSError *error=nil;
  4280. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4281. return jsobj;
  4282. }
  4283. else
  4284. return nil;
  4285. }
  4286. //+ (NSDictionary *)lock_order:(NSString *)oderCode
  4287. //{
  4288. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4289. // __block AppDelegate *appDelegate = nil;
  4290. //
  4291. // dispatch_sync(dispatch_get_main_queue(), ^{
  4292. // //some UI methods ej
  4293. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4294. // });
  4295. // if(appDelegate.user!=nil)
  4296. // [params setValue:appDelegate.user forKey:@"user"];
  4297. //
  4298. // if(appDelegate.password!=nil)
  4299. // [params setValue:appDelegate.password forKey:@"password"];
  4300. //
  4301. // [params setValue:oderCode forKey:@"orderCode"];
  4302. //
  4303. // NSData* json=nil;
  4304. // if(appDelegate.offline_mode)
  4305. // {
  4306. // json=[OLDataProvider offline_editorder:params];
  4307. //
  4308. // }
  4309. // else
  4310. // {
  4311. // if(![self IsNetworkAvailable])
  4312. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4313. //
  4314. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  4315. // }
  4316. // if(json!=nil)
  4317. // {
  4318. // NSError *error=nil;
  4319. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4320. //
  4321. // return jsobj;
  4322. // }
  4323. // else
  4324. // return nil;
  4325. //}
  4326. + (NSDictionary *)quoteOrder:(NSString *)so_id emailAddr:(NSString *)addr {
  4327. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4328. __block AppDelegate *appDelegate = nil;
  4329. dispatch_sync(dispatch_get_main_queue(), ^{
  4330. //some UI methods ej
  4331. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4332. });
  4333. if(appDelegate.user!=nil)
  4334. [dic setValue:appDelegate.user forKey:@"user"];
  4335. if(appDelegate.password!=nil)
  4336. [dic setValue:appDelegate.password forKey:@"password"];
  4337. [dic setValue:so_id forKey:@"orderCode"];
  4338. [dic setValue:addr forKey:@"email"];
  4339. [dic setObject:ScreenCodeCart forKey:kScreenName];
  4340. if (appDelegate.customerInfo) {
  4341. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4342. if (customer_cid) {
  4343. [dic setValue:customer_cid forKey:@"contactId"];
  4344. }
  4345. }
  4346. NSData* json=nil;
  4347. if(appDelegate.offline_mode)
  4348. {
  4349. return [OLDataProvider offline_notimpl];
  4350. }
  4351. else
  4352. {
  4353. if(![self IsNetworkAvailable])
  4354. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4355. json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  4356. }
  4357. if(json!=nil)
  4358. {
  4359. NSError *error=nil;
  4360. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4361. return jsobj;
  4362. }
  4363. return @{@"result" : @(RESULT_FALSE)};
  4364. }
  4365. + (NSDictionary *)notifyModel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName{
  4366. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4367. __block AppDelegate *appDelegate = nil;
  4368. dispatch_sync(dispatch_get_main_queue(), ^{
  4369. //some UI methods ej
  4370. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4371. });
  4372. if(appDelegate.user!=nil)
  4373. [dic setValue:appDelegate.user forKey:@"user"];
  4374. if(appDelegate.password!=nil)
  4375. [dic setValue:appDelegate.password forKey:@"password"];
  4376. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  4377. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4378. if (customer_cid) {
  4379. [dic setValue:customer_cid forKey:@"contactId"];
  4380. }
  4381. }
  4382. [dic setObject:screenName forKey:kScreenName];
  4383. [dic setValue:modelID forKey:@"productId"];
  4384. if (addr) { // 弹框输入
  4385. [dic setValue:addr forKey:@"email"];
  4386. } else {
  4387. // employee选择了Contact,并且Contact有Email
  4388. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  4389. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  4390. // if (email) {
  4391. // [dic setValue:email forKey:@"email"];
  4392. // }
  4393. // }
  4394. }
  4395. NSData* json=nil;
  4396. if(appDelegate.offline_mode)
  4397. {
  4398. return [OLDataProvider offline_notimpl];
  4399. }
  4400. else
  4401. {
  4402. if(![self IsNetworkAvailable])
  4403. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4404. json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  4405. }
  4406. if(json!=nil)
  4407. {
  4408. NSError *error=nil;
  4409. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4410. return jsobj;
  4411. }
  4412. return @{@"result" : @(RESULT_FALSE)};
  4413. }
  4414. + (NSDictionary *)quoteWishlist2EmailAddr:(NSString *)addr {
  4415. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4416. __block AppDelegate *appDelegate = nil;
  4417. dispatch_sync(dispatch_get_main_queue(), ^{
  4418. //some UI methods ej
  4419. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4420. });
  4421. if(appDelegate.user!=nil)
  4422. [dic setValue:appDelegate.user forKey:@"user"];
  4423. if(appDelegate.password!=nil)
  4424. [dic setValue:appDelegate.password forKey:@"password"];
  4425. [dic setValue:addr forKey:@"email"];
  4426. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  4427. // if (appDelegate.customerInfo) {
  4428. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4429. // if (customer_cid) {
  4430. // [dic setValue:customer_cid forKey:@"contactId"];
  4431. // }
  4432. // }
  4433. NSData* json=nil;
  4434. if(appDelegate.offline_mode)
  4435. {
  4436. return [OLDataProvider offline_notimpl];
  4437. }
  4438. else
  4439. {
  4440. if(![self IsNetworkAvailable])
  4441. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4442. json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  4443. }
  4444. if(json!=nil)
  4445. {
  4446. NSError *error=nil;
  4447. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4448. return jsobj;
  4449. }
  4450. return @{@"result" : @(RESULT_FALSE)};
  4451. }
  4452. + (NSDictionary *)movetobackorder:(NSString *)cart_item_id {
  4453. if (cart_item_id == nil || cart_item_id.length < 1) {
  4454. return @{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"};
  4455. }
  4456. __block AppDelegate *appDelegate = nil;
  4457. dispatch_sync(dispatch_get_main_queue(), ^{
  4458. //some UI methods ej
  4459. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4460. });
  4461. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4462. if(appDelegate.user!=nil)
  4463. [dic setValue:appDelegate.user forKey:@"user"];
  4464. if(appDelegate.password!=nil)
  4465. [dic setValue:appDelegate.password forKey:@"password"];
  4466. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  4467. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  4468. [dic setObject:ScreenCodeCart forKey:kScreenName];
  4469. if(![self IsNetworkAvailable])
  4470. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4471. NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  4472. if(json!=nil)
  4473. {
  4474. NSError *error=nil;
  4475. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4476. return jsobj;
  4477. }
  4478. return @{@"result" : @(RESULT_FALSE)};
  4479. }
  4480. + (NSDictionary*)request_hangTag:(NSString *)group {
  4481. #ifdef BUILD_UWAVER
  4482. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4483. __block AppDelegate *appDelegate = nil;
  4484. dispatch_sync(dispatch_get_main_queue(), ^{
  4485. //some UI methods ej
  4486. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4487. });
  4488. if(appDelegate.user!=nil)
  4489. [params setValue:appDelegate.user forKey:@"user"];
  4490. if(appDelegate.contact_id!=nil)
  4491. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4492. if(appDelegate.password!=nil)
  4493. [params setValue:appDelegate.password forKey:@"password"];
  4494. if (group) {
  4495. [params setValue:group forKey:@"groupName"];
  4496. }
  4497. NSString * uuid= [[NSUUID UUID] UUIDString];
  4498. params[@"resultSerial"]=uuid;
  4499. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4500. NSData* json = nil;
  4501. if(appDelegate.offline_mode)
  4502. {
  4503. json = [OLDataProvider offline_notimpl];
  4504. } else {
  4505. if(![self IsNetworkAvailable])
  4506. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4507. json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  4508. }
  4509. if(json==nil)
  4510. return nil;
  4511. NSError *error=nil;
  4512. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4513. return jsobj;
  4514. #else
  4515. return nil;
  4516. #endif
  4517. }
  4518. #pragma mark 2020 new interface
  4519. // 新接口逐步替换以前的网络请求,2020
  4520. +(void)request_home:(int) price_template customid:(int) customid completionHandler:(resultHandler)result
  4521. {
  4522. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4523. AppDelegate *appDelegate = nil;
  4524. //some UI methods ej
  4525. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4526. if(appDelegate.user!=nil)
  4527. [params setValue:appDelegate.user forKey:@"user"];
  4528. if(appDelegate.contact_id!=nil)
  4529. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4530. if(appDelegate.password!=nil)
  4531. [params setValue:appDelegate.password forKey:@"password"];
  4532. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4533. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4534. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  4535. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4536. if(appDelegate.offline_mode)
  4537. {
  4538. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4539. NSMutableDictionary* json = [[OLDataProvider offline_home] mutableCopy];
  4540. dispatch_async(dispatch_get_main_queue(), ^{
  4541. result(json);
  4542. });
  4543. });
  4544. return;
  4545. }
  4546. [self request_interface:URL_LOAD_HOME parameters:params err_record_url:nil completionHandler:result retry:0];
  4547. return;
  4548. }
  4549. +(void)request_category:(resultHandler)result
  4550. {
  4551. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  4552. AppDelegate *appDelegate = nil;
  4553. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4554. if(appDelegate.offline_mode)
  4555. {
  4556. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4557. NSMutableDictionary* json = [[OLDataProvider offline_category_menu] mutableCopy];
  4558. dispatch_async(dispatch_get_main_queue(), ^{
  4559. result(json);
  4560. });
  4561. });
  4562. return;
  4563. }
  4564. [self request_interface:URL_REQUEST_CATMENU parameters:[NSMutableDictionary new] err_record_url:nil completionHandler:result retry:0];
  4565. //
  4566. // if(![self IsNetworkAvailable])
  4567. // {
  4568. // DebugLog(@"NET ERR");
  4569. //
  4570. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4571. // // return nil;
  4572. // }
  4573. //
  4574. // NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  4575. // //if(json==nil)
  4576. //
  4577. //
  4578. // if(json==nil)
  4579. // return nil;
  4580. // NSError *error=nil;
  4581. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4582. // return jsobj;
  4583. }
  4584. +(void)request_categorylist: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip completionHandler:(resultHandler)result
  4585. {
  4586. AppDelegate *appDelegate = nil;
  4587. //some UI methods ej
  4588. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4589. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4590. if(appDelegate.user!=nil)
  4591. [params setValue:appDelegate.user forKey:@"user"];
  4592. if(appDelegate.contact_id!=nil)
  4593. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4594. if(appDelegate.password!=nil)
  4595. [params setValue:appDelegate.password forKey:@"password"];
  4596. if(appDelegate.order_code!=nil)
  4597. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4598. [params setValue:alert forKey:@"alert"];
  4599. [params setValue:qty forKey:@"sold_by_qty"];
  4600. [params setValue:available forKey:@"available"];
  4601. [params setValue:price forKey:@"price"];
  4602. [params setValue:bestseller forKey:@"bestseller"];
  4603. [params setValue:modelname forKey:@"modelName"];
  4604. [params setValue:modeldescrip forKey:@"modelDescription"];
  4605. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4606. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4607. [params setValue:category forKey:@"category"];
  4608. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4609. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4610. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4611. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4612. [params setValue:filter forKey:@"filter"];
  4613. [params setValue:keyword forKey:@"keyword"];
  4614. [params setObject:ScreenCodeCategory forKey:kScreenName];
  4615. if (alert) {
  4616. [params setObject:@"Filter" forKey:kAction];
  4617. }
  4618. if ([RASingleton sharedInstance].homeItemClick) {
  4619. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  4620. [RASingleton sharedInstance].homeItemClick = NO;
  4621. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  4622. [RASingleton sharedInstance].homeClickedItemName = nil;
  4623. [params setObject:extra forKey:kExtra];
  4624. }
  4625. if(appDelegate.offline_mode)
  4626. {
  4627. // [OLDataProvider offline_category:params completionHandler:result];
  4628. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4629. NSMutableDictionary* json = [[OLDataProvider offline_category:params] mutableCopy];
  4630. dispatch_async(dispatch_get_main_queue(), ^{
  4631. result(json);
  4632. });
  4633. });
  4634. return;
  4635. }
  4636. [self request_interface:URL_CATEGORY parameters:params err_record_url:nil completionHandler:result retry:0];
  4637. return ;
  4638. //
  4639. // if(![self IsNetworkAvailable])
  4640. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4641. //
  4642. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  4643. // if(json==nil)
  4644. // return nil;
  4645. // NSError *error=nil;
  4646. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4647. // return jsobj;
  4648. //
  4649. }
  4650. +(void)request_modeldetail: (NSString* ) item_id model_name:(NSString*) model_name upc_code:(NSString*) upc_code category_id:(NSString*) category_id use_name :(bool) use_name use_upc :(bool) use_upc groupName:(NSString *)groupName completionHandler:(resultHandler)result
  4651. {
  4652. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4653. AppDelegate *appDelegate = nil;
  4654. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4655. if(appDelegate.user!=nil)
  4656. [params setValue:appDelegate.user forKey:@"user"];
  4657. if(appDelegate.contact_id!=nil)
  4658. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4659. if(appDelegate.password!=nil)
  4660. [params setValue:appDelegate.password forKey:@"password"];
  4661. if(appDelegate.order_code!=nil)
  4662. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4663. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4664. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4665. if(use_name)
  4666. [params setValue:model_name forKey:@"product_name"];
  4667. else
  4668. if(use_upc){
  4669. params[@"search_upc"]=@true;
  4670. [params setValue:upc_code forKey:@"upc_code"];
  4671. }
  4672. else
  4673. [params setValue:item_id forKey:@"product_id"];
  4674. [params setValue:category_id forKey:@"category"];
  4675. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4676. [params setObject:@"Open A Model" forKey:kAction];
  4677. if (model_name) {
  4678. NSDictionary *extra = @{@"ModelName" : model_name};
  4679. [params setObject:extra forKey:kExtra];
  4680. }
  4681. if (groupName.length > 0) {
  4682. [params setObject:groupName forKey:@"groupName"];
  4683. }
  4684. if(appDelegate.offline_mode)
  4685. {
  4686. [OLDataProvider offline_model:params completionHandler:result];
  4687. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4688. // NSMutableDictionary* json = [[OLDataProvider offline_model:params] mutableCopy];
  4689. // dispatch_async(dispatch_get_main_queue(), ^{
  4690. // result(json);
  4691. // });
  4692. // });
  4693. return;
  4694. }
  4695. [self request_interface:URL_ITEM_DETAIL parameters:params err_record_url:nil completionHandler:result retry:0];
  4696. //
  4697. // if(appDelegate.offline_mode)
  4698. // return [OLDataProvider offline_model:params];
  4699. //
  4700. // if(![self IsNetworkAvailable])
  4701. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4702. //
  4703. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  4704. // if(json==nil)
  4705. // return nil;
  4706. // NSError *error=nil;
  4707. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4708. // return jsobj;
  4709. }
  4710. +(void)request_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull completionHandler:(resultHandler)result
  4711. {
  4712. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4713. AppDelegate *appDelegate = nil;
  4714. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4715. if(appDelegate.user!=nil)
  4716. [params setValue:appDelegate.user forKey:@"user"];
  4717. if(appDelegate.contact_id!=nil)
  4718. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4719. if(appDelegate.password!=nil)
  4720. [params setValue:appDelegate.password forKey:@"password"];
  4721. if(appDelegate.order_code!=nil)
  4722. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4723. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4724. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4725. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  4726. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4727. // [params setValue:filter forKey:@"filter"];
  4728. [params setValue:keywords forKey:@"keyword"];
  4729. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4730. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4731. if(matchfull)
  4732. [params setValue:@"true" forKey:@"exactMatch"];
  4733. else
  4734. [params setValue:@"false" forKey:@"exactMatch"];
  4735. [params setObject:ScreenCodeSearch forKey:kScreenName];
  4736. if (keywords) {
  4737. [params setObject:@"Search" forKey:kAction];
  4738. }
  4739. if(appDelegate.offline_mode)
  4740. {
  4741. // [OLDataProvider offline_search:params completionHandler:result];
  4742. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4743. NSMutableDictionary* json = [[OLDataProvider offline_search:params] mutableCopy];
  4744. dispatch_async(dispatch_get_main_queue(), ^{
  4745. result(json);
  4746. });
  4747. });
  4748. return;
  4749. }
  4750. [self request_interface:URL_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  4751. // if(appDelegate.offline_mode)
  4752. // {
  4753. // return [OLDataProvider offline_search:params];
  4754. // }
  4755. // if(![self IsNetworkAvailable])
  4756. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4757. //
  4758. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  4759. // if(json==nil)
  4760. // return nil;
  4761. // NSError *error=nil;
  4762. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4763. // return jsobj;
  4764. }
  4765. +(void)request_login: (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
  4766. {
  4767. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  4768. // return RESULT_NET_ERROR;
  4769. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4770. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4771. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4772. AppDelegate *appDelegate = nil;
  4773. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4774. if(appDelegate.duid !=nil)
  4775. [params setValue:appDelegate.duid forKey:@"udid"];
  4776. [params setValue:@"handset_login" forKey:@"action"];
  4777. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  4778. [params setValue:user forKey:@"user"];
  4779. [params setValue:password forKey:@"password"];
  4780. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  4781. #ifdef TEST
  4782. [params setValue:@"true" forKey:@"is_debug"];
  4783. #else
  4784. [params setValue:@"false" forKey:@"is_debug"];
  4785. #endif
  4786. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  4787. [params setObject:@"Login" forKey:kAction];
  4788. if(appDelegate.offline_mode)
  4789. {
  4790. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4791. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_login:params]] mutableCopy];
  4792. dispatch_async(dispatch_get_main_queue(), ^{
  4793. int ret = [self parse_logininfo:json user:user password:password] ;
  4794. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4795. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4796. result(retjson);
  4797. });
  4798. });
  4799. return;
  4800. }
  4801. NSString* url;
  4802. bool scan_guest = false;
  4803. #ifdef SCANNER_ORDER
  4804. params[@"site_name"]=[RADataProvider getSiteName];
  4805. params[@"_method"]=@"login";
  4806. url = [appDelegate.address stringByAppendingPathComponent:URL_UPDATE_AUTH];
  4807. if([user.uppercaseString isEqualToString:@"GUEST"]&&[password.uppercaseString isEqualToString:@"GUEST"])
  4808. scan_guest = true;
  4809. #else
  4810. url = URL_UPDATE_AUTH;
  4811. #endif
  4812. if(scan_guest)
  4813. {
  4814. [OLDataProvider guestLogin];
  4815. // int ret = [self parse_logininfo:chresult user:user password:password] ;
  4816. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4817. retjson[@"result"]= [NSNumber numberWithInt:RESULT_TRUE];
  4818. result(retjson);
  4819. }
  4820. else
  4821. {
  4822. [self request_interface:url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *chresult) {
  4823. int ret = [self parse_logininfo:chresult user:user password:password] ;
  4824. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4825. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4826. result(retjson);
  4827. } retry:0];
  4828. }
  4829. //
  4830. // NSData* json= nil;
  4831. // if(appDelegate.offline_mode)
  4832. // {
  4833. // json= [OLDataProvider offline_login:params] ;
  4834. //
  4835. // }
  4836. // else
  4837. // {
  4838. // if(![self IsNetworkAvailable])
  4839. // return RESULT_NET_NOTAVAILABLE;
  4840. // json =[self get_json:URL_UPDATE_AUTH parameters:params];
  4841. //
  4842. // }
  4843. //
  4844. // if(json==nil)
  4845. // return RESULT_NET_ERROR;
  4846. //
  4847. // int ret = [self parse_authinfo:json user:user password:password];
  4848. // DebugLog(@"parse_authinfo return %d ",ret);
  4849. //
  4850. //
  4851. // return ret;
  4852. //
  4853. }
  4854. +(int)parse_logininfo : (NSMutableDictionary *) jsobj user:(NSString*) user password:(NSString*) password
  4855. {
  4856. // DebugLog(@"parse_authinfo");
  4857. // NSError *error=nil;
  4858. //
  4859. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4860. if(jsobj)
  4861. {
  4862. AppDelegate *appDelegate = nil;
  4863. //some UI methods ej
  4864. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4865. int result = [[jsobj valueForKey:@"result"] intValue];
  4866. if (result<0)
  4867. return result;
  4868. if(result!=AP_USER_AUTH&& result!=9)
  4869. {
  4870. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  4871. // [appDelegate Logout];
  4872. if(result==8)
  4873. {
  4874. return RESULT_LOGIN_DEVICE;
  4875. }
  4876. return RESULT_FALSE;
  4877. }
  4878. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  4879. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  4880. user=[objheader objectForKey:@"username"] ;
  4881. DebugLog(@"required_ver=%@ ",required_ver);
  4882. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  4883. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  4884. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  4885. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  4886. // if([ibadge isEqual:[NSNull null]])
  4887. // strbadge=@"0";
  4888. // if(ibadge==nil)
  4889. // ibadge=@"0";
  4890. // if([strbadge isEqualToString:@"null"])
  4891. // strbadge=@"0";
  4892. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  4893. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  4894. #ifndef SCANNER_ORDER
  4895. if([appDelegate.build intValue]<[required_ver intValue])
  4896. return RESULT_VER_LOW;
  4897. #endif
  4898. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  4899. appDelegate.user = user;
  4900. appDelegate.password = password;
  4901. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  4902. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  4903. appDelegate.bLogin = true;
  4904. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  4905. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  4906. {
  4907. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  4908. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  4909. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  4910. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  4911. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  4912. }
  4913. NSString* mode =[jsobj valueForKey:@"mode"] ;
  4914. [appDelegate SetMode:mode];
  4915. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  4916. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  4917. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  4918. [appDelegate update_count_mark];
  4919. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  4920. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  4921. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  4922. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  4923. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  4924. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  4925. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  4926. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  4927. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  4928. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  4929. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  4930. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  4931. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  4932. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  4933. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  4934. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  4935. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  4936. [appDelegate set_main_button_panel];
  4937. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  4938. // shop order status filter
  4939. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  4940. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  4941. // Sales order status filter
  4942. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  4943. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  4944. // specialInstruction
  4945. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  4946. //-价格类型
  4947. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  4948. // 权限
  4949. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  4950. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  4951. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  4952. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  4953. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  4954. [[RASingleton sharedInstance] resetGlobalLock];
  4955. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  4956. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  4957. }
  4958. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  4959. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  4960. // {
  4961. // // no update on the server;
  4962. // return RESULT_TRUE;
  4963. // }
  4964. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  4965. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4966. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4967. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4968. // [defaults synchronize];
  4969. //
  4970. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  4971. // NSArray* keys= [objfuncs allKeys];
  4972. /*
  4973. db.setTransactionSuccessful();
  4974. db.endTransaction();
  4975. */
  4976. return RESULT_TRUE;
  4977. }
  4978. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  4979. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  4980. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  4981. return RESULT_USERAUTH_ERROR;
  4982. }
  4983. +(void)request_contactlist:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams completionHandler:(resultHandler)result
  4984. {
  4985. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4986. if(upparams!=nil)
  4987. params = [upparams mutableCopy];
  4988. AppDelegate *appDelegate = nil;
  4989. //some UI methods ej
  4990. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4991. if(appDelegate.user!=nil)
  4992. [params setValue:appDelegate.user forKey:@"user"];
  4993. if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  4994. [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  4995. else
  4996. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4997. if(appDelegate.password!=nil)
  4998. [params setValue:appDelegate.password forKey:@"password"];
  4999. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  5000. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  5001. [params setValue:contact_type forKey:@"contactType"];
  5002. [params setValue:keywords forKey:@"keyword"];
  5003. [params setObject:ScreenCodeAccount forKey:kScreenName];
  5004. if (keywords) {
  5005. [params setObject:@"Search" forKey:kAction];
  5006. }
  5007. if (upparams) {
  5008. [params setObject:@"Advance Search" forKey:kAction];
  5009. }
  5010. NSString* url=nil;
  5011. if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  5012. url=URL_SHIPTO_LIST;
  5013. else
  5014. url=URL_CONTACT_LIST;
  5015. if(appDelegate.offline_mode)
  5016. {
  5017. [OLDataProvider offline_contactlist:params completionHandler:result];
  5018. return;
  5019. }
  5020. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  5021. //
  5022. // if(appDelegate.offline_mode)
  5023. // return [OLDataProvider offline_contactlist:params];
  5024. //
  5025. // if(![self IsNetworkAvailable])
  5026. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5027. //
  5028. // NSData* json=[self get_json:url parameters:params];
  5029. // if(json==nil)
  5030. // return nil;
  5031. // NSError *error=nil;
  5032. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5033. // return jsobj;
  5034. }
  5035. +(void)request_contactinfo:(NSString* ) contactid completionHandler:(resultHandler)result
  5036. {
  5037. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5038. AppDelegate *appDelegate = nil;
  5039. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5040. if(appDelegate.user!=nil)
  5041. [params setValue:appDelegate.user forKey:@"user"];
  5042. // if(appDelegate.contact_id!=nil)
  5043. if(appDelegate.password!=nil)
  5044. [params setValue:appDelegate.password forKey:@"password"];
  5045. [params setValue:contactid forKey:@"contactId"];
  5046. [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  5047. if(appDelegate.offline_mode)
  5048. {
  5049. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5050. // [OLDataProvider offline_contactinfo:params completionHandler:result] ;
  5051. // });
  5052. params[@"mode"]=appDelegate.mode;
  5053. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5054. NSMutableDictionary* json = [[OLDataProvider offline_contactinfo:params] mutableCopy];
  5055. dispatch_async(dispatch_get_main_queue(), ^{
  5056. result(json);
  5057. });
  5058. });
  5059. return;
  5060. }
  5061. [self request_interface:URL_CUSTOMER_INFO parameters:params err_record_url:nil completionHandler:result retry:0];
  5062. // if(appDelegate.offline_mode)
  5063. // return [OLDataProvider offline_contactinfo:params];
  5064. // if(![self IsNetworkAvailable])
  5065. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5066. //
  5067. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  5068. // if(json==nil)
  5069. // return nil;
  5070. // NSError *error=nil;
  5071. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5072. // return jsobj;
  5073. //
  5074. }
  5075. +(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  5076. {
  5077. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5078. AppDelegate *appDelegate = nil;
  5079. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5080. if(appDelegate.user!=nil)
  5081. [params setValue:appDelegate.user forKey:@"user"];
  5082. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  5083. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  5084. // else
  5085. if(appDelegate.contact_id!=nil)
  5086. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5087. if(appDelegate.password!=nil)
  5088. [params setValue:appDelegate.password forKey:@"password"];
  5089. if(appDelegate.order_code!=nil)
  5090. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5091. bool can_create_backorder=appDelegate.can_create_backorder;
  5092. // [params setValue:sourceid forKey:@"sourceid"];
  5093. // [params setValue:editor forKey:@"editor"];
  5094. DebugLog(@"request editor url:%@",request_url);
  5095. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  5096. {
  5097. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  5098. }
  5099. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  5100. {
  5101. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  5102. }
  5103. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  5104. {
  5105. [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  5106. }
  5107. else if([request_url isEqualToString:URL_CARTDELIVERY])
  5108. {
  5109. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  5110. }
  5111. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  5112. {
  5113. [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  5114. }
  5115. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  5116. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  5117. }
  5118. if(appDelegate.offline_mode)
  5119. {
  5120. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5121. NSData* json = nil;
  5122. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  5123. {
  5124. json= [OLDataProvider offline_createContact:params];
  5125. }
  5126. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  5127. {
  5128. json= [OLDataProvider offline_editContact:params];
  5129. }
  5130. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  5131. {
  5132. json= [OLDataProvider offline_contactAdvancedSearch:params];
  5133. }
  5134. else if([request_url isEqualToString:URL_CARTDELIVERY])
  5135. {
  5136. params[@"contact_id"]=params[@"contactId"];
  5137. params[@"can_create_backorder"]=@(can_create_backorder);
  5138. json= [OLDataProvider offline_placeorder:params];
  5139. }
  5140. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  5141. {
  5142. json= [OLDataProvider offline_addreditor:params];
  5143. }
  5144. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  5145. json = [OLDataProvider offline_createTearSheet:params];
  5146. }
  5147. dispatch_async(dispatch_get_main_queue(), ^{
  5148. if(json==nil)
  5149. result( [[OLDataProvider offline_notimpl] mutableCopy]);
  5150. else
  5151. result([[RAConvertor data2dict:json] mutableCopy]);
  5152. });
  5153. });
  5154. return;
  5155. }
  5156. else
  5157. {
  5158. if([request_url isEqualToString:URL_CARTDELIVERY])
  5159. {
  5160. NSString * uuid= [[NSUUID UUID] UUIDString];
  5161. params[@"resultSerial"]=uuid;
  5162. __block bool bbreak = false;
  5163. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5164. for(int i=0;i<150;i++)
  5165. {
  5166. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  5167. // result_params[@"resultSerial"]=uuid;
  5168. //json=[self get_json:request_url parameters:params];
  5169. if(bbreak)
  5170. break;
  5171. dispatch_async(dispatch_get_main_queue(), ^{
  5172. NSLog(@"request cart delivery %d",i);
  5173. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5174. if(resulti!=nil)
  5175. {
  5176. if([resulti[@"result"] intValue]==2 || [resulti[@"result"] intValue] == 8)
  5177. {
  5178. if(!bbreak) //此判断保证result只调用一次。
  5179. {
  5180. result(resulti);
  5181. NSLog(@"result called at %d",i);
  5182. }
  5183. bbreak=true;
  5184. }
  5185. }
  5186. } retry:3];
  5187. });
  5188. // [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  5189. sleep(2);
  5190. }
  5191. });
  5192. }
  5193. else
  5194. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  5195. }
  5196. // if(json!=nil)
  5197. // {
  5198. // NSError *error=nil;
  5199. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5200. // return jsobj;
  5201. // }
  5202. // else
  5203. // return nil;
  5204. }
  5205. +(void)request_wishlist:(int)sort completionHandler:(resultHandler)result
  5206. {
  5207. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5208. AppDelegate *appDelegate = nil;
  5209. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5210. if(appDelegate.user!=nil)
  5211. [params setValue:appDelegate.user forKey:@"user"];
  5212. if(appDelegate.contact_id!=nil)
  5213. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5214. if(appDelegate.password!=nil)
  5215. [params setValue:appDelegate.password forKey:@"password"];
  5216. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  5217. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  5218. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  5219. [params setObject:ScreenCodeWishList forKey:kScreenName];
  5220. if(appDelegate.offline_mode)
  5221. {
  5222. [OLDataProvider offline_wishlist:params completionHandler:^(NSMutableDictionary *resulti) {
  5223. int result_code = [[resulti valueForKey:@"result"] intValue];
  5224. if (result_code==2)
  5225. {
  5226. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  5227. [appDelegate update_count_mark];;
  5228. result(resulti);
  5229. }
  5230. }];
  5231. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5232. // NSMutableDictionary* json = [[OLDataProvider offline_wishlist:params] mutableCopy];
  5233. // dispatch_async(dispatch_get_main_queue(), ^{
  5234. // result(json);
  5235. // });
  5236. // });
  5237. return;
  5238. }
  5239. [self request_interface:URL_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5240. int result_code = [[resulti valueForKey:@"result"] intValue];
  5241. if (result_code==2)
  5242. {
  5243. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  5244. [appDelegate update_count_mark];;
  5245. result(resulti);
  5246. }
  5247. } retry:0];
  5248. // if(appDelegate.offline_mode)
  5249. // {
  5250. // return [OLDataProvider offline_wishlist:params];
  5251. // }
  5252. // if(![self IsNetworkAvailable])
  5253. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5254. //
  5255. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  5256. // if(json==nil)
  5257. // return nil;
  5258. // NSError *error=nil;
  5259. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5260. // int result = [[jsobj valueForKey:@"result"] intValue];
  5261. //
  5262. // if (result==2)
  5263. // {
  5264. //
  5265. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5266. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  5267. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5268. //
  5269. // [appDelegate update_count_mark];
  5270. // }
  5271. // return jsobj;
  5272. }
  5273. +(void)request_portfoliolist:(int)sort completionHandler:(resultHandler)result
  5274. {
  5275. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5276. AppDelegate *appDelegate = nil;
  5277. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5278. if(appDelegate.user!=nil)
  5279. [params setValue:appDelegate.user forKey:@"user"];
  5280. if(appDelegate.contact_id!=nil)
  5281. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5282. if(appDelegate.password!=nil)
  5283. [params setValue:appDelegate.password forKey:@"password"];
  5284. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  5285. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  5286. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  5287. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  5288. if(appDelegate.offline_mode)
  5289. {
  5290. params[@"user"]=appDelegate.user;
  5291. params[@"contact_id"]=appDelegate.contact_id;
  5292. params[@"can_see_price"]=@(appDelegate.can_see_price);
  5293. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5294. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_portfolioList:params]] mutableCopy];
  5295. dispatch_async(dispatch_get_main_queue(), ^{
  5296. if ([json[@"result"] intValue]==2)
  5297. {
  5298. appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  5299. [appDelegate update_count_mark];
  5300. }
  5301. result(json);
  5302. });
  5303. });
  5304. return;
  5305. }
  5306. [self request_interface:URL_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5307. if ([resulti[@"result"] intValue]==2)
  5308. {
  5309. appDelegate.port_count =[[resulti valueForKey:@"count"] intValue];
  5310. [appDelegate update_count_mark];
  5311. }
  5312. result(resulti);
  5313. } retry:0];
  5314. // NSData* json = nil;
  5315. // if(appDelegate.offline_mode)
  5316. // {
  5317. // json = [OLDataProvider offline_portfolioList:params];
  5318. // } else {
  5319. // if(![self IsNetworkAvailable])
  5320. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5321. //
  5322. // json = [self get_json:URL_PORTFOLIO parameters:params];
  5323. // }
  5324. //
  5325. //
  5326. // if(json==nil)
  5327. // return nil;
  5328. // NSError *error=nil;
  5329. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5330. // int result = [[jsobj valueForKey:@"result"] intValue];
  5331. //
  5332. // if (result==2)
  5333. // {
  5334. //
  5335. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5336. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  5337. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  5338. //
  5339. // [appDelegate update_count_mark];
  5340. // }
  5341. // return jsobj;
  5342. }
  5343. +(void)request_portfoliopdf:(int ) offset limit:(int)limit keywords:(NSString* ) keywords completionHandler:(resultHandler)result
  5344. {
  5345. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5346. AppDelegate *appDelegate = nil;
  5347. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5348. if(appDelegate.user!=nil)
  5349. [params setValue:appDelegate.user forKey:@"user"];
  5350. if(appDelegate.contact_id!=nil)
  5351. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5352. if(appDelegate.password!=nil)
  5353. [params setValue:appDelegate.password forKey:@"password"];
  5354. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  5355. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  5356. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  5357. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  5358. // [params setValue:filter forKey:@"filter"];
  5359. [params setValue:keywords forKey:@"keyWord"];
  5360. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  5361. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  5362. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  5363. if (keywords) {
  5364. [params setObject:@"Search" forKey:kAction];
  5365. }
  5366. if(appDelegate.offline_mode)
  5367. {
  5368. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5369. NSData* json = [[OLDataProvider offline_pdfList:params] mutableCopy];
  5370. dispatch_async(dispatch_get_main_queue(), ^{
  5371. result([[RAConvertor data2dict:json] mutableCopy]);
  5372. });
  5373. });
  5374. return;
  5375. }
  5376. [self request_interface:URL_DM_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  5377. return;
  5378. // NSData* json = nil;
  5379. // if(appDelegate.offline_mode)
  5380. // {
  5381. // json = [OLDataProvider offline_pdfList:params];
  5382. // } else {
  5383. // if(![self IsNetworkAvailable])
  5384. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5385. //
  5386. // json=[self get_json:URL_DM_LIST parameters:params];
  5387. // }
  5388. // if(json==nil)
  5389. // return nil;
  5390. // NSError *error=nil;
  5391. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5392. // return jsobj;
  5393. }
  5394. +(void)request_orderlist:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged completionHandler:(resultHandler)result
  5395. {
  5396. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5397. AppDelegate *appDelegate = nil;
  5398. //some UI methods ej
  5399. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5400. if(appDelegate.user!=nil)
  5401. [params setValue:appDelegate.user forKey:@"user"];
  5402. if(appDelegate.contact_id!=nil)
  5403. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5404. if(appDelegate.password!=nil)
  5405. [params setValue:appDelegate.password forKey:@"password"];
  5406. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  5407. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  5408. [params setValue:keywords forKey:@"keyWord"];
  5409. [params setValue:customer forKey:@"customer_filter"];
  5410. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  5411. [params setValue:status_code forKey:@"orderStatus"];
  5412. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  5413. if (keywords) {
  5414. [params setObject:@"Search" forKey:kAction];
  5415. }
  5416. if(appDelegate.offline_mode)
  5417. {
  5418. params[@"user"]=appDelegate.user;
  5419. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5420. NSData* json = [[OLDataProvider offline_orderlist:params] mutableCopy];
  5421. dispatch_async(dispatch_get_main_queue(), ^{
  5422. result([[RAConvertor data2dict:json] mutableCopy]);
  5423. });
  5424. });
  5425. return;
  5426. }
  5427. [self request_interface:URL_ORDER_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  5428. // NSData* json=nil;
  5429. // if(appDelegate.offline_mode)
  5430. // {
  5431. // json= [OLDataProvider offline_orderlist:params];
  5432. // }
  5433. // else
  5434. // {
  5435. // if(![self IsNetworkAvailable])
  5436. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5437. //
  5438. // json=[self get_json:URL_ORDER_LIST parameters:params];
  5439. // }
  5440. // if(json==nil)
  5441. // return nil;
  5442. // NSError *error=nil;
  5443. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5444. // return jsobj;
  5445. }
  5446. +(void)request_logout:(resultHandler)result
  5447. {
  5448. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5449. AppDelegate *appDelegate = nil;
  5450. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5451. if(appDelegate.user!=nil)
  5452. [params setValue:appDelegate.user forKey:@"user"];
  5453. if(appDelegate.password!=nil)
  5454. [params setValue:appDelegate.password forKey:@"password"];
  5455. if(appDelegate.offline_mode)
  5456. {
  5457. [OLDataProvider offline_logout:params completionHandler:result];
  5458. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5459. // NSMutableDictionary* json = [[OLDataProvider offline_logout:params] mutableCopy];
  5460. // dispatch_async(dispatch_get_main_queue(), ^{
  5461. // result(json);
  5462. // });
  5463. // });
  5464. return;
  5465. }
  5466. [self request_interface:URL_LOGOUT parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5467. NSMutableDictionary* jsobj=resulti;
  5468. int result_code = [[jsobj valueForKey:@"result"] intValue];
  5469. if (result_code==2)
  5470. {
  5471. appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  5472. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5473. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5474. [appDelegate update_count_mark];
  5475. appDelegate.can_show_price =false;
  5476. appDelegate.can_see_price =false;
  5477. appDelegate.can_create_portfolio =false;
  5478. appDelegate.can_create_order =false;
  5479. appDelegate.can_cancel_order =false;
  5480. appDelegate.can_set_cart_price =false;
  5481. appDelegate.can_delete_order =false;
  5482. appDelegate.can_submit_order =false;
  5483. appDelegate.can_set_tearsheet_price =false;
  5484. appDelegate.can_update_contact_info = false;
  5485. appDelegate.save_order_logout = false;
  5486. appDelegate.submit_order_logout = false;
  5487. appDelegate.alert_sold_in_quantities = false;
  5488. appDelegate.ipad_perm =nil ;
  5489. appDelegate.user_type = USER_ROLE_UNKNOWN;
  5490. appDelegate.OrderFilter= nil;
  5491. [appDelegate SetSo:nil];
  5492. [appDelegate set_main_button_panel];
  5493. #ifdef RA_NOTIFICATION
  5494. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5495. #endif
  5496. }
  5497. result(resulti);
  5498. } retry:0];
  5499. //
  5500. // if(appDelegate.offline_mode)
  5501. // {
  5502. // return [OLDataProvider offline_logout:params];
  5503. // }
  5504. // if(![self IsNetworkAvailable])
  5505. // {
  5506. // DebugLog(@"NET ERR");
  5507. //
  5508. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5509. // // return nil;
  5510. // }
  5511. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  5512. // //if(json==nil)
  5513. //
  5514. //
  5515. // if(json==nil)
  5516. // return nil;
  5517. // NSError *error=nil;
  5518. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5519. // int result = [[jsobj valueForKey:@"result"] intValue];
  5520. //
  5521. // if (result==2)
  5522. // {
  5523. //
  5524. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  5525. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5526. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5527. //
  5528. // [appDelegate update_count_mark];
  5529. //
  5530. //
  5531. // appDelegate.can_show_price =false;
  5532. // appDelegate.can_see_price =false;
  5533. // appDelegate.can_create_portfolio =false;
  5534. // appDelegate.can_create_order =false;
  5535. //
  5536. //
  5537. // appDelegate.can_cancel_order =false;
  5538. // appDelegate.can_set_cart_price =false;
  5539. // appDelegate.can_delete_order =false;
  5540. // appDelegate.can_submit_order =false;
  5541. // appDelegate.can_set_tearsheet_price =false;
  5542. // appDelegate.can_update_contact_info = false;
  5543. //
  5544. // appDelegate.save_order_logout = false;
  5545. // appDelegate.submit_order_logout = false;
  5546. // appDelegate.alert_sold_in_quantities = false;
  5547. //
  5548. // appDelegate.ipad_perm =nil ;
  5549. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  5550. // appDelegate.OrderFilter= nil;
  5551. // [appDelegate SetSo:nil];
  5552. // [appDelegate set_main_button_panel];
  5553. //#ifdef RA_NOTIFICATION
  5554. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5555. //#endif
  5556. // }
  5557. // return jsobj;
  5558. }
  5559. + (void)request_hangtag:(NSString *)group completionHandler:(resultHandler)result
  5560. {
  5561. #ifdef BUILD_UWAVER
  5562. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5563. AppDelegate *appDelegate = nil;
  5564. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5565. if(appDelegate.user!=nil)
  5566. [params setValue:appDelegate.user forKey:@"user"];
  5567. if(appDelegate.contact_id!=nil)
  5568. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5569. if(appDelegate.password!=nil)
  5570. [params setValue:appDelegate.password forKey:@"password"];
  5571. if (group) {
  5572. [params setValue:group forKey:@"groupName"];
  5573. }
  5574. NSString * uuid= [[NSUUID UUID] UUIDString];
  5575. params[@"resultSerial"]=uuid;
  5576. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  5577. if(appDelegate.offline_mode)
  5578. {
  5579. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5580. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5581. dispatch_async(dispatch_get_main_queue(), ^{
  5582. result(json);
  5583. });
  5584. });
  5585. return;
  5586. }
  5587. [self request_interface:URL_CREATE_HANG_TAG parameters:params err_record_url:nil completionHandler:result retry:0];
  5588. // NSData* json = nil;
  5589. // if(appDelegate.offline_mode)
  5590. // {
  5591. // json = [OLDataProvider offline_portfolioList:params];
  5592. // } else {
  5593. // if(![self IsNetworkAvailable])
  5594. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5595. //
  5596. // json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  5597. // }
  5598. //
  5599. //
  5600. // if(json==nil)
  5601. // return nil;
  5602. // NSError *error=nil;
  5603. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5604. //
  5605. // return jsobj;
  5606. #else
  5607. return result(nil);
  5608. #endif
  5609. }
  5610. + (void)request_movetobackorder:(NSString *)cart_item_id completionHandler:(resultHandler)result
  5611. {
  5612. if (cart_item_id == nil || cart_item_id.length < 1) {
  5613. result([@{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"} mutableCopy]);
  5614. }
  5615. AppDelegate *appDelegate = nil;
  5616. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5617. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5618. if(appDelegate.user!=nil)
  5619. [dic setValue:appDelegate.user forKey:@"user"];
  5620. if(appDelegate.password!=nil)
  5621. [dic setValue:appDelegate.password forKey:@"password"];
  5622. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  5623. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  5624. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5625. if(appDelegate.offline_mode)
  5626. {
  5627. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5628. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5629. dispatch_async(dispatch_get_main_queue(), ^{
  5630. result(json);
  5631. });
  5632. });
  5633. return;
  5634. }
  5635. [self request_interface:URL_MOVE_TO_BACK_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5636. // if(![self IsNetworkAvailable])
  5637. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5638. //
  5639. // NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  5640. //
  5641. // if(json!=nil)
  5642. // {
  5643. // NSError *error=nil;
  5644. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5645. //
  5646. // return jsobj;
  5647. // }
  5648. //
  5649. // return @{@"result" : @(RESULT_FALSE)};
  5650. }
  5651. + (void)request_emailwishlist:(NSString *)addr completionHandler:(resultHandler)result
  5652. {
  5653. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5654. AppDelegate *appDelegate = nil;
  5655. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5656. if(appDelegate.user!=nil)
  5657. [dic setValue:appDelegate.user forKey:@"user"];
  5658. if(appDelegate.password!=nil)
  5659. [dic setValue:appDelegate.password forKey:@"password"];
  5660. [dic setValue:addr forKey:@"email"];
  5661. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  5662. // if (appDelegate.customerInfo) {
  5663. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5664. // if (customer_cid) {
  5665. // [dic setValue:customer_cid forKey:@"contactId"];
  5666. // }
  5667. // }
  5668. if(appDelegate.offline_mode)
  5669. {
  5670. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5671. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5672. dispatch_async(dispatch_get_main_queue(), ^{
  5673. result(json);
  5674. });
  5675. });
  5676. return;
  5677. }
  5678. [self request_interface:URL_EMAIL_WISHLIST parameters:dic err_record_url:nil completionHandler:result retry:0];
  5679. // NSData* json=nil;
  5680. // if(appDelegate.offline_mode)
  5681. // {
  5682. // return [OLDataProvider offline_notimpl];
  5683. // }
  5684. // else
  5685. // {
  5686. // if(![self IsNetworkAvailable])
  5687. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5688. //
  5689. // json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  5690. // }
  5691. // if(json!=nil)
  5692. // {
  5693. // NSError *error=nil;
  5694. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5695. //
  5696. //
  5697. // return jsobj;
  5698. // }
  5699. //
  5700. // return @{@"result" : @(RESULT_FALSE)};
  5701. }
  5702. +(void)request_notifymodel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  5703. {
  5704. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5705. AppDelegate *appDelegate = nil;
  5706. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5707. if(appDelegate.user!=nil)
  5708. [dic setValue:appDelegate.user forKey:@"user"];
  5709. if(appDelegate.password!=nil)
  5710. [dic setValue:appDelegate.password forKey:@"password"];
  5711. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5712. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5713. if (customer_cid) {
  5714. [dic setValue:customer_cid forKey:@"contactId"];
  5715. }
  5716. }
  5717. [dic setObject:screenName forKey:kScreenName];
  5718. [dic setValue:modelID forKey:@"productId"];
  5719. if (addr) { // 弹框输入
  5720. [dic setValue:addr forKey:@"email"];
  5721. } else {
  5722. // employee选择了Contact,并且Contact有Email
  5723. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5724. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  5725. // if (email) {
  5726. // [dic setValue:email forKey:@"email"];
  5727. // }
  5728. // }
  5729. }
  5730. if(appDelegate.offline_mode)
  5731. {
  5732. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5733. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5734. dispatch_async(dispatch_get_main_queue(), ^{
  5735. result(json);
  5736. });
  5737. });
  5738. return;
  5739. }
  5740. [self request_interface:URL_NOTIFY_ME parameters:dic err_record_url:nil completionHandler:result retry:0];
  5741. // NSData* json=nil;
  5742. // if(appDelegate.offline_mode)
  5743. // {
  5744. // return [OLDataProvider offline_notimpl];
  5745. // }
  5746. // else
  5747. // {
  5748. // if(![self IsNetworkAvailable])
  5749. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5750. //
  5751. // json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  5752. // }
  5753. // if(json!=nil)
  5754. // {
  5755. // NSError *error=nil;
  5756. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5757. //
  5758. //
  5759. // return jsobj;
  5760. // }
  5761. //
  5762. // return @{@"result" : @(RESULT_FALSE)};
  5763. }
  5764. + (void)request_qouteorder:(NSString *)so_id emailAddr:(NSString *)addr completionHandler:(resultHandler)result
  5765. {
  5766. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5767. AppDelegate *appDelegate = nil;
  5768. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5769. if(appDelegate.user!=nil)
  5770. [dic setValue:appDelegate.user forKey:@"user"];
  5771. if(appDelegate.password!=nil)
  5772. [dic setValue:appDelegate.password forKey:@"password"];
  5773. [dic setValue:so_id forKey:@"orderCode"];
  5774. [dic setValue:addr forKey:@"email"];
  5775. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5776. if (appDelegate.customerInfo) {
  5777. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5778. if (customer_cid) {
  5779. [dic setValue:customer_cid forKey:@"contactId"];
  5780. }
  5781. }
  5782. if(appDelegate.offline_mode)
  5783. {
  5784. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5785. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5786. dispatch_async(dispatch_get_main_queue(), ^{
  5787. result(json);
  5788. });
  5789. });
  5790. return;
  5791. }
  5792. [self request_interface:URL_EMAIL_CART parameters:dic err_record_url:nil completionHandler:result retry:0];
  5793. // NSData* json=nil;
  5794. // if(appDelegate.offline_mode)
  5795. // {
  5796. // return [OLDataProvider offline_notimpl];
  5797. // }
  5798. // else
  5799. // {
  5800. // if(![self IsNetworkAvailable])
  5801. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5802. //
  5803. // json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  5804. // }
  5805. // if(json!=nil)
  5806. // {
  5807. // NSError *error=nil;
  5808. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5809. //
  5810. //
  5811. // return jsobj;
  5812. // }
  5813. //
  5814. // return @{@"result" : @(RESULT_FALSE)};
  5815. }
  5816. + (void)request_mergeorder:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  5817. {
  5818. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5819. AppDelegate *appDelegate = nil;
  5820. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5821. if(appDelegate.user!=nil)
  5822. [dic setValue:appDelegate.user forKey:@"user"];
  5823. if(appDelegate.password!=nil)
  5824. [dic setValue:appDelegate.password forKey:@"password"];
  5825. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  5826. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  5827. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  5828. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  5829. if(appDelegate.offline_mode)
  5830. {
  5831. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5832. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5833. dispatch_async(dispatch_get_main_queue(), ^{
  5834. result(json);
  5835. });
  5836. });
  5837. return;
  5838. }
  5839. [self request_interface:URL_SET_MERGE_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5840. // NSData* json=nil;
  5841. // if(appDelegate.offline_mode)
  5842. // {
  5843. // return [OLDataProvider offline_notimpl];
  5844. // }
  5845. // else
  5846. // {
  5847. // if(![self IsNetworkAvailable])
  5848. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5849. //
  5850. // json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  5851. // }
  5852. // if(json!=nil)
  5853. // {
  5854. // NSError *error=nil;
  5855. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5856. //
  5857. //
  5858. // return jsobj;
  5859. // }
  5860. // else
  5861. // return nil;
  5862. }
  5863. +(void)request_pendingorder:(NSString *)contactid completionHandler:(resultHandler)result
  5864. {
  5865. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5866. AppDelegate *appDelegate = nil;
  5867. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5868. if(appDelegate.user!=nil)
  5869. [params setValue:appDelegate.user forKey:@"user"];
  5870. // if(appDelegate.contact_id!=nil)
  5871. if(appDelegate.password!=nil)
  5872. [params setValue:appDelegate.password forKey:@"password"];
  5873. [params setValue:contactid forKey:@"contactId"];
  5874. if(appDelegate.offline_mode)
  5875. {
  5876. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5877. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5878. dispatch_async(dispatch_get_main_queue(), ^{
  5879. result(json);
  5880. });
  5881. });
  5882. return;
  5883. }
  5884. [self request_interface:URL_CUSTOMER_PENDINGORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  5885. //
  5886. // if(appDelegate.offline_mode)
  5887. // {
  5888. // return [OLDataProvider offline_notimpl];
  5889. // }
  5890. // if(![self IsNetworkAvailable])
  5891. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5892. //
  5893. // NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  5894. // if(json==nil)
  5895. // return nil;
  5896. // NSError *error=nil;
  5897. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5898. // return jsobj;
  5899. //
  5900. }
  5901. +(void) request_removeportfolio:(NSString* ) item_ids completionHandler:(resultHandler)result
  5902. {
  5903. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5904. AppDelegate *appDelegate = nil;
  5905. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5906. if(appDelegate.user!=nil)
  5907. [params setValue:appDelegate.user forKey:@"user"];
  5908. if(appDelegate.contact_id!=nil)
  5909. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5910. if(appDelegate.password!=nil)
  5911. [params setValue:appDelegate.password forKey:@"password"];
  5912. [params setValue:item_ids forKey:@"portfolioId"];
  5913. // [params setValue:editor forKey:@"editor"];
  5914. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  5915. if(appDelegate.offline_mode)
  5916. {
  5917. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5918. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_removePortfolio:params]] mutableCopy];
  5919. dispatch_async(dispatch_get_main_queue(), ^{
  5920. int result_code = [[resulti valueForKey:@"result"] intValue];
  5921. if (result_code==2)
  5922. {
  5923. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5924. [appDelegate update_count_mark];
  5925. };
  5926. result(resulti);
  5927. });
  5928. });
  5929. return;
  5930. }
  5931. [self request_interface:URL_PORTFOLIO_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5932. int result_code = [[resulti valueForKey:@"result"] intValue];
  5933. if (result_code==2)
  5934. {
  5935. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5936. [appDelegate update_count_mark];
  5937. };
  5938. result(resulti);
  5939. } retry:0];
  5940. // NSData* json = nil;
  5941. // if(appDelegate.offline_mode)
  5942. // {
  5943. // json = [OLDataProvider offline_removePortfolio:params];
  5944. // } else {
  5945. // if(![self IsNetworkAvailable])
  5946. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5947. // json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  5948. // }
  5949. // if(json!=nil)
  5950. // {
  5951. // NSError *error=nil;
  5952. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5953. //
  5954. //
  5955. // int result = [[jsobj valueForKey:@"result"] intValue];
  5956. //
  5957. // if (result==2)
  5958. // {
  5959. //
  5960. //
  5961. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5962. //
  5963. // [appDelegate update_count_mark];
  5964. // }
  5965. // return jsobj;
  5966. // }
  5967. // else
  5968. // return nil;
  5969. }
  5970. +(void) request_removeportfoliopdf:(NSString* ) listid completionHandler:(resultHandler)result
  5971. {
  5972. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5973. AppDelegate *appDelegate = nil;
  5974. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5975. if(appDelegate.user!=nil)
  5976. [params setValue:appDelegate.user forKey:@"user"];
  5977. if(appDelegate.contact_id!=nil)
  5978. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5979. if(appDelegate.password!=nil)
  5980. [params setValue:appDelegate.password forKey:@"password"];
  5981. [params setValue:listid forKey:@"tearsheetsId"];
  5982. // [params setValue:editor forKey:@"editor"];
  5983. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  5984. // [params setValue:@"Delete Portfolio" forKey:kAction];
  5985. if(appDelegate.offline_mode)
  5986. {
  5987. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5988. NSData* json = [[OLDataProvider offline_removePDF:params] mutableCopy];
  5989. dispatch_async(dispatch_get_main_queue(), ^{
  5990. result([[RAConvertor data2dict:json] mutableCopy]);
  5991. });
  5992. });
  5993. return;
  5994. }
  5995. [self request_interface:URL_PORTFOLIOLIST_REMOVE parameters:params err_record_url:nil completionHandler:result retry:0];
  5996. }
  5997. +(void) request_remove_wishlist:(NSString* ) item_ids completionHandler:(resultHandler)result
  5998. {
  5999. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6000. __block AppDelegate *appDelegate = nil;
  6001. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6002. if(appDelegate.user!=nil)
  6003. [params setValue:appDelegate.user forKey:@"user"];
  6004. if(appDelegate.contact_id!=nil)
  6005. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6006. if(appDelegate.password!=nil)
  6007. [params setValue:appDelegate.password forKey:@"password"];
  6008. [params setValue:item_ids forKey:@"collectId"];
  6009. // [params setValue:editor forKey:@"editor"];
  6010. [params setValue:ScreenCodeWishList forKey:kScreenName];
  6011. if(appDelegate.offline_mode)
  6012. {
  6013. // [OLDataProvider offline_deletewishlist:params completionHandler:result];
  6014. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6015. NSMutableDictionary* resulti = [[OLDataProvider offline_deletewishlist:params] mutableCopy];
  6016. dispatch_async(dispatch_get_main_queue(), ^{
  6017. int result_code = [[resulti valueForKey:@"result"] intValue];
  6018. if (result_code==2)
  6019. {
  6020. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6021. [appDelegate update_count_mark];
  6022. };
  6023. result(resulti);
  6024. });
  6025. });
  6026. return;
  6027. }
  6028. [self request_interface:URL_WATCHLIST_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6029. int result_code = [[resulti valueForKey:@"result"] intValue];
  6030. if (result_code==2)
  6031. {
  6032. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6033. [appDelegate update_count_mark];
  6034. };
  6035. result(resulti);
  6036. } retry:0];
  6037. //
  6038. //
  6039. // if(appDelegate.offline_mode)
  6040. // {
  6041. // return [OLDataProvider offline_deletewishlist:params];
  6042. // }
  6043. // if(![self IsNetworkAvailable])
  6044. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6045. //
  6046. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  6047. // if(json!=nil)
  6048. // {
  6049. // NSError *error=nil;
  6050. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6051. // int result = [[jsobj valueForKey:@"result"] intValue];
  6052. //
  6053. // if (result==2)
  6054. // {
  6055. //
  6056. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6057. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6058. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6059. //
  6060. // [appDelegate update_count_mark];
  6061. // }
  6062. // return jsobj;
  6063. // }
  6064. // else
  6065. // return nil;
  6066. }
  6067. +(void) request_remove_cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  6068. {
  6069. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6070. AppDelegate *appDelegate = nil;
  6071. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6072. #ifdef SCANNER_ORDER
  6073. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  6074. {
  6075. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  6076. //
  6077. //
  6078. // [appDelegate update_count_mark];
  6079. NSArray* arr=[RAConvertor string2arr:item_ids separator:@","];
  6080. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  6081. NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  6082. NSMutableDictionary* newsection =[cartTemplate[@"section_0"] mutableCopy];
  6083. int newcount = 0;
  6084. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  6085. int count = [section[@"count"] intValue];
  6086. for(int i=0;i<count;i++)
  6087. {
  6088. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  6089. int index = [arr indexOfObject:item[@"cart_item_id"]] ;
  6090. if(index <0)
  6091. {
  6092. newsection[[NSString stringWithFormat:@"item_%d",newcount]] = item;
  6093. newcount ++;
  6094. }
  6095. }
  6096. newsection[@"count"]=@(newcount);
  6097. RASingleton.sharedInstance.scan_cart[@"section_0"] = newsection;
  6098. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  6099. result(RASingleton.sharedInstance.scan_cart);
  6100. return;
  6101. }
  6102. #endif
  6103. if(appDelegate.user!=nil)
  6104. [params setValue:appDelegate.user forKey:@"user"];
  6105. if(appDelegate.contact_id!=nil)
  6106. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6107. if(appDelegate.password!=nil)
  6108. [params setValue:appDelegate.password forKey:@"password"];
  6109. if(appDelegate.order_code!=nil)
  6110. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6111. [params setValue:item_ids forKey:@"cartItemId"];
  6112. // [params setValue:editor forKey:@"editor"];
  6113. [params setValue:ScreenCodeCart forKey:kScreenName];
  6114. // [params setValue:@"" forKey:kAction];
  6115. if(appDelegate.offline_mode)
  6116. {
  6117. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6118. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_cartremove:params]] mutableCopy];
  6119. dispatch_async(dispatch_get_main_queue(), ^{
  6120. int result_code = [[resulti valueForKey:@"result"] intValue];
  6121. if (result_code==2)
  6122. {
  6123. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6124. [appDelegate update_count_mark];
  6125. };
  6126. result(resulti);
  6127. });
  6128. });
  6129. return;
  6130. }
  6131. [self request_interface:URL_CART_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6132. int result_code = [[resulti valueForKey:@"result"] intValue];
  6133. if (result_code==2)
  6134. {
  6135. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6136. [appDelegate update_count_mark];
  6137. };
  6138. result(resulti);
  6139. } retry:0];
  6140. //
  6141. // NSData* json=nil;
  6142. // if(appDelegate.offline_mode)
  6143. // {
  6144. // json= [OLDataProvider offline_cartremove:params];
  6145. // }
  6146. // else
  6147. // {
  6148. // if(![self IsNetworkAvailable])
  6149. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6150. //
  6151. // json=[self get_json:URL_CART_REMOVE parameters:params];
  6152. // }
  6153. // if(json!=nil)
  6154. // {
  6155. // NSError *error=nil;
  6156. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6157. //
  6158. // int result = [[jsobj valueForKey:@"result"] intValue];
  6159. //
  6160. // if (result==2)
  6161. // {
  6162. //
  6163. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6164. //
  6165. //
  6166. // [appDelegate update_count_mark];
  6167. // }
  6168. // return jsobj;
  6169. // }
  6170. // else
  6171. // return nil;
  6172. }
  6173. +(void)request_delete_account:(resultHandler)result
  6174. {
  6175. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6176. AppDelegate *appDelegate = nil;
  6177. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6178. if(appDelegate.user!=nil)
  6179. [params setValue:appDelegate.user forKey:@"user"];
  6180. if(appDelegate.password!=nil)
  6181. [params setValue:appDelegate.password forKey:@"password"];
  6182. if(appDelegate.offline_mode)
  6183. {
  6184. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6185. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  6186. dispatch_async(dispatch_get_main_queue(), ^{
  6187. result(json);
  6188. });
  6189. });
  6190. return;
  6191. }
  6192. #ifdef SCANNER_ORDER
  6193. params[@"site_name"]=[RADataProvider getSiteName];
  6194. params[@"_method"]=@"cancelOfflineOrderUser";
  6195. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_DELETE_ACCOUNT];
  6196. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  6197. #else
  6198. [self request_interface:URL_DELETE_ACCOUNT parameters:params err_record_url:nil completionHandler:result retry:0];
  6199. #endif
  6200. }
  6201. +(void) request_create_order:(resultHandler)result
  6202. {
  6203. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6204. AppDelegate *appDelegate = nil;
  6205. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6206. if(appDelegate.user!=nil)
  6207. [params setValue:appDelegate.user forKey:@"user"];
  6208. if(appDelegate.contact_id!=nil)
  6209. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6210. if(appDelegate.password!=nil)
  6211. [params setValue:appDelegate.password forKey:@"password"];
  6212. if(appDelegate.order_code!=nil)
  6213. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6214. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  6215. NSDictionary* customerinfo= appDelegate.customerInfo;
  6216. NSArray* keys=[customerinfo allKeys];
  6217. for(int i=0;i<keys.count;i++)
  6218. {
  6219. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  6220. }
  6221. if(appDelegate.offline_mode)
  6222. {
  6223. [OLDataProvider offline_createorder:params completionHandler:^(NSMutableDictionary *resulti) {
  6224. int result_code = [[resulti valueForKey:@"result"] intValue];
  6225. if (result_code==2)
  6226. {
  6227. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6228. [appDelegate update_count_mark];
  6229. };
  6230. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  6231. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6232. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  6233. }
  6234. result(resulti);
  6235. }];
  6236. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6237. // NSData* json = [[OLDataProvider offline_createorder:params] mutableCopy];
  6238. // dispatch_async(dispatch_get_main_queue(), ^{
  6239. // result([[RAConvertor data2dict:json] mutableCopy]);
  6240. // });
  6241. // });
  6242. return;
  6243. }
  6244. [self request_interface:URL_NEW_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6245. int result_code = [[resulti valueForKey:@"result"] intValue];
  6246. if (result_code==2)
  6247. {
  6248. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6249. [appDelegate update_count_mark];
  6250. };
  6251. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  6252. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6253. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  6254. }
  6255. result(resulti);
  6256. } retry:0];
  6257. //
  6258. // NSData* json = nil;
  6259. // if(appDelegate.offline_mode)
  6260. // {
  6261. // json= [OLDataProvider offline_createorder:params];
  6262. // }
  6263. // else
  6264. // {
  6265. // if(![self IsNetworkAvailable])
  6266. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6267. //
  6268. // json=[self get_json:URL_NEW_ORDER parameters:params];
  6269. // }
  6270. // if(json==nil)
  6271. // return nil;
  6272. // NSError *error=nil;
  6273. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6274. // int result = [[jsobj valueForKey:@"result"] intValue];
  6275. //
  6276. // if (result==2)
  6277. // {
  6278. //
  6279. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6280. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6281. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6282. //
  6283. // [appDelegate update_count_mark];
  6284. // }
  6285. //
  6286. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  6287. //
  6288. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6289. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  6290. // }
  6291. //
  6292. // return jsobj;
  6293. }
  6294. +(void)request_open_order:(NSString*) order_code completionHandler:(resultHandler)result
  6295. {
  6296. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6297. AppDelegate *appDelegate = nil;
  6298. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6299. if(appDelegate.user!=nil)
  6300. [params setValue:appDelegate.user forKey:@"user"];
  6301. // if(appDelegate.contact_id!=nil)
  6302. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6303. if(appDelegate.password!=nil)
  6304. [params setValue:appDelegate.password forKey:@"password"];
  6305. [params setValue:order_code forKey:@"orderCode"];
  6306. // [params setValue:sourceid forKey:@"sourceid"];
  6307. // [params setValue:editor forKey:@"editor"];
  6308. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  6309. if(appDelegate.offline_mode)
  6310. {
  6311. params[@"appDelegate.order_code"]=appDelegate.order_code;
  6312. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6313. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_editorder:params]] mutableCopy];
  6314. dispatch_async(dispatch_get_main_queue(), ^{
  6315. int result_code = [[resulti valueForKey:@"result"] intValue];
  6316. if (result_code==2)
  6317. {
  6318. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6319. [appDelegate update_count_mark];
  6320. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6321. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  6322. }
  6323. }
  6324. result(resulti);
  6325. });
  6326. });
  6327. return;
  6328. }
  6329. [self request_interface:URL_OPEN_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6330. int result_code = [[resulti valueForKey:@"result"] intValue];
  6331. if (result_code==2)
  6332. {
  6333. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6334. [appDelegate update_count_mark];
  6335. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6336. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  6337. }
  6338. }
  6339. result(resulti);
  6340. } retry:0];
  6341. //
  6342. // NSData* json=nil;
  6343. // if(appDelegate.offline_mode)
  6344. // {
  6345. // json=[OLDataProvider offline_editorder:params];
  6346. //
  6347. // }
  6348. // else
  6349. // {
  6350. // if(![self IsNetworkAvailable])
  6351. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6352. //
  6353. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  6354. // }
  6355. // if(json!=nil)
  6356. // {
  6357. // NSError *error=nil;
  6358. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6359. // int result = [[jsobj valueForKey:@"result"] intValue];
  6360. //
  6361. // if (result==2)
  6362. // {
  6363. //
  6364. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6365. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6366. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6367. //
  6368. // [appDelegate update_count_mark];
  6369. //
  6370. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6371. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  6372. // }
  6373. //
  6374. // }
  6375. //
  6376. // return jsobj;
  6377. // }
  6378. // else
  6379. // return nil;
  6380. }
  6381. +(void)request_cart:(int)sort completionHandler:(resultHandler)result
  6382. {
  6383. DebugLog(@"iSalesNetwork::request_Cart");
  6384. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6385. AppDelegate *appDelegate = nil;
  6386. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6387. #ifdef SCANNER_ORDER
  6388. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  6389. {
  6390. appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  6391. [appDelegate update_count_mark];
  6392. result(RASingleton.sharedInstance.scan_cart);
  6393. return;
  6394. }
  6395. #endif
  6396. if(appDelegate.user!=nil)
  6397. [params setValue:appDelegate.user forKey:@"user"];
  6398. // if(appDelegate.contact_id!=nil)
  6399. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6400. if(appDelegate.password!=nil)
  6401. [params setValue:appDelegate.password forKey:@"password"];
  6402. if(appDelegate.order_code!=nil)
  6403. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6404. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  6405. [params setObject:ScreenCodeCart forKey:kScreenName];
  6406. if(appDelegate.offline_mode)
  6407. {
  6408. [OLDataProvider offline_requestcart:params completionHandler:^(NSMutableDictionary *resulti) {
  6409. if([resulti[@"result"] intValue]==2)
  6410. {
  6411. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6412. [appDelegate update_count_mark];
  6413. result(resulti);
  6414. }
  6415. }];
  6416. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6417. // NSData* json = [[OLDataProvider offline_requestcart:params] mutableCopy];
  6418. // dispatch_async(dispatch_get_main_queue(), ^{
  6419. // result([[RAConvertor data2dict:json] mutableCopy]);
  6420. // });
  6421. // });
  6422. return;
  6423. }
  6424. NSString * uuid= [[NSUUID UUID] UUIDString];
  6425. params[@"resultSerial"]=uuid;
  6426. __block bool bbreak = false;
  6427. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6428. for(int i=0;i<150;i++)
  6429. {
  6430. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6431. // result_params[@"resultSerial"]=uuid;
  6432. if(bbreak)
  6433. break;
  6434. dispatch_async(dispatch_get_main_queue(), ^{
  6435. [self request_interface:URL_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6436. if([resulti[@"result"] intValue]==2)
  6437. {
  6438. if(!bbreak) //此判断保证result只调用一次。
  6439. {
  6440. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6441. [appDelegate update_count_mark];
  6442. result(resulti);
  6443. }
  6444. bbreak=true;
  6445. }
  6446. } retry:3];
  6447. });
  6448. sleep(2);
  6449. // json=[self get_json:URL_CART parameters:params];
  6450. // if(json!=nil)
  6451. // {
  6452. //
  6453. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6454. // if([jsobj[@"result"] intValue]==2)
  6455. // {
  6456. // break;
  6457. // }
  6458. // }
  6459. }
  6460. });
  6461. //
  6462. //
  6463. //
  6464. // NSData* json=nil;
  6465. // if(appDelegate.offline_mode)
  6466. // {
  6467. // json= [OLDataProvider offline_requestcart:params];
  6468. // }
  6469. // else
  6470. // {
  6471. // if(![self IsNetworkAvailable])
  6472. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6473. //
  6474. // NSError *error=nil;
  6475. //
  6476. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6477. // params[@"resultSerial"]=uuid;
  6478. //
  6479. // for(int i=0;i<150;i++)
  6480. // {
  6481. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6482. // // result_params[@"resultSerial"]=uuid;
  6483. // json=[self get_json:URL_CART parameters:params];
  6484. // if(json!=nil)
  6485. // {
  6486. //
  6487. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6488. // if([jsobj[@"result"] intValue]==2)
  6489. // {
  6490. // break;
  6491. // }
  6492. // }
  6493. // sleep(2);
  6494. // }
  6495. //
  6496. // }
  6497. // if(json==nil)
  6498. // return nil;
  6499. // NSError *error=nil;
  6500. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6501. // int result = [[jsobj valueForKey:@"result"] intValue];
  6502. //
  6503. // if (result==2)
  6504. // {
  6505. //
  6506. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6507. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  6508. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6509. //
  6510. // [appDelegate update_count_mark];
  6511. // }
  6512. // return jsobj;
  6513. }
  6514. +(void) request_move_wish2cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  6515. {
  6516. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6517. AppDelegate *appDelegate = nil;
  6518. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6519. if(appDelegate.user!=nil)
  6520. [params setValue:appDelegate.user forKey:@"user"];
  6521. if(appDelegate.contact_id!=nil)
  6522. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6523. if(appDelegate.password!=nil)
  6524. [params setValue:appDelegate.password forKey:@"password"];
  6525. if(appDelegate.order_code!=nil)
  6526. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6527. [params setValue:item_ids forKey:@"collectId"];
  6528. // [params setValue:editor forKey:@"editor"];
  6529. [params setValue:ScreenCodeWishList forKey:kScreenName];
  6530. [params setValue:@"Move To Cart" forKey:kAction];
  6531. if(appDelegate.offline_mode)
  6532. {
  6533. // [OLDataProvider offline_movewish2cart:params completionHandler:result];
  6534. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6535. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6536. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movewish2cart:params]] mutableCopy];
  6537. dispatch_async(dispatch_get_main_queue(), ^{
  6538. int result_code = [[resulti valueForKey:@"result"] intValue];
  6539. if (result_code==2)
  6540. {
  6541. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6542. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6543. [appDelegate update_count_mark];
  6544. }
  6545. result(resulti);
  6546. });
  6547. });
  6548. return;
  6549. }
  6550. [self request_interface:URL_WISH2CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6551. int result_code = [[resulti valueForKey:@"result"] intValue];
  6552. if (result_code==2)
  6553. {
  6554. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6555. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6556. [appDelegate update_count_mark];
  6557. }
  6558. result(resulti);
  6559. } retry:0];
  6560. //
  6561. // NSData *json = nil;
  6562. // if(appDelegate.offline_mode)
  6563. // {
  6564. // json = [OLDataProvider offline_movewish2cart:params];
  6565. // } else {
  6566. // if(![self IsNetworkAvailable])
  6567. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6568. //
  6569. // json=[self get_json:URL_WISH2CART parameters:params];
  6570. // }
  6571. //
  6572. // if(json!=nil)
  6573. // {
  6574. // NSError *error=nil;
  6575. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6576. // int result = [[jsobj valueForKey:@"result"] intValue];
  6577. //
  6578. // if (result==2)
  6579. // {
  6580. //
  6581. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6582. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6583. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6584. //
  6585. // [appDelegate update_count_mark];
  6586. // }
  6587. // return jsobj;
  6588. // }
  6589. // else
  6590. // return nil;
  6591. }
  6592. +(void) request_move_cart2wish:(NSString* ) item_ids completionHandler:(resultHandler)result
  6593. {
  6594. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6595. AppDelegate *appDelegate = nil;
  6596. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6597. if(appDelegate.user!=nil)
  6598. [params setValue:appDelegate.user forKey:@"user"];
  6599. if(appDelegate.contact_id!=nil)
  6600. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6601. if(appDelegate.password!=nil)
  6602. [params setValue:appDelegate.password forKey:@"password"];
  6603. if(appDelegate.order_code!=nil)
  6604. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6605. [params setValue:item_ids forKey:@"cartItemId"];
  6606. // [params setValue:editor forKey:@"editor"];
  6607. [params setValue:ScreenCodeCart forKey:kScreenName];
  6608. // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  6609. if(appDelegate.offline_mode)
  6610. {
  6611. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6612. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movecart2wish:params]] mutableCopy];
  6613. dispatch_async(dispatch_get_main_queue(), ^{
  6614. int result_code = [[resulti valueForKey:@"result"] intValue];
  6615. if (result_code==2)
  6616. {
  6617. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6618. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6619. [appDelegate update_count_mark];
  6620. }
  6621. result(resulti);
  6622. });
  6623. });
  6624. return;
  6625. }
  6626. [self request_interface:URL_CART2WISH parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6627. int result_code = [[resulti valueForKey:@"result"] intValue];
  6628. if (result_code==2)
  6629. {
  6630. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6631. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6632. [appDelegate update_count_mark];
  6633. }
  6634. result(resulti);
  6635. } retry:0];
  6636. //
  6637. // NSData* json = nil;
  6638. // if(appDelegate.offline_mode)
  6639. // {
  6640. // json= [OLDataProvider offline_movecart2wish:params];
  6641. // }
  6642. // else
  6643. // {
  6644. // if(![self IsNetworkAvailable])
  6645. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6646. //
  6647. // json=[self get_json:URL_CART2WISH parameters:params];
  6648. // }
  6649. // if(json!=nil)
  6650. // {
  6651. // NSError *error=nil;
  6652. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6653. // int result = [[jsobj valueForKey:@"result"] intValue];
  6654. //
  6655. // if (result==2)
  6656. // {
  6657. //
  6658. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6659. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6660. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6661. //
  6662. // [appDelegate update_count_mark];
  6663. // }
  6664. // return jsobj;
  6665. // }
  6666. // else
  6667. // return nil;
  6668. }
  6669. +(void)request_orderdetail:(NSMutableDictionary *) params completionHandler:(resultHandler)result
  6670. {
  6671. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6672. if (params == nil) {
  6673. params = [[NSMutableDictionary alloc] init];
  6674. }
  6675. AppDelegate *appDelegate = nil;
  6676. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6677. if(appDelegate.user!=nil)
  6678. [params setValue:appDelegate.user forKey:@"user"];
  6679. if(appDelegate.contact_id!=nil)
  6680. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6681. if(appDelegate.password!=nil)
  6682. [params setValue:appDelegate.password forKey:@"password"];
  6683. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  6684. [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  6685. if(appDelegate.offline_mode)
  6686. {
  6687. params[@"mode"]=appDelegate.mode;
  6688. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6689. NSData* json = [[OLDataProvider offline_orderdetail:params] mutableCopy];
  6690. dispatch_async(dispatch_get_main_queue(), ^{
  6691. result([[RAConvertor data2dict:json] mutableCopy]);
  6692. });
  6693. });
  6694. return;
  6695. }
  6696. NSString * uuid= [[NSUUID UUID] UUIDString];
  6697. params[@"resultSerial"]=uuid;
  6698. __block bool bbreak = false;
  6699. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6700. for(int i=0;i<150;i++)
  6701. {
  6702. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6703. // result_params[@"resultSerial"]=uuid;
  6704. if(bbreak)
  6705. break;
  6706. dispatch_async(dispatch_get_main_queue(), ^{
  6707. [self request_interface:URL_ORDER_DETAIL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6708. if([resulti[@"result"] intValue]==2||[resulti[@"result"] intValue]==8)
  6709. {
  6710. if(!bbreak)//此判断保证result只调用一次。
  6711. result(resulti);
  6712. bbreak=true;
  6713. }
  6714. } retry:3];
  6715. });
  6716. sleep(2);
  6717. }
  6718. });
  6719. //
  6720. // NSData* json=nil;
  6721. // if(appDelegate.offline_mode)
  6722. // {
  6723. // json= [OLDataProvider offline_orderdetail:params];
  6724. // }
  6725. // else
  6726. // {
  6727. // if(![self IsNetworkAvailable])
  6728. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6729. //
  6730. // NSError *error=nil;
  6731. //
  6732. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6733. // params[@"resultSerial"]=uuid;
  6734. //
  6735. // for(int i=0;i<150;i++)
  6736. // {
  6737. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6738. // // result_params[@"resultSerial"]=uuid;
  6739. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  6740. // if(json!=nil)
  6741. // {
  6742. //
  6743. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6744. // int resultCode = [jsobj[@"result"] intValue];
  6745. // if(resultCode==2 || resultCode == 8)
  6746. // {
  6747. // break;
  6748. // }
  6749. // }
  6750. // sleep(2);
  6751. // }
  6752. //
  6753. //
  6754. // }
  6755. // if(json==nil)
  6756. // return nil;
  6757. // NSError *error=nil;
  6758. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6759. // return jsobj;
  6760. }
  6761. //
  6762. //+(void)request_commit_order:(NSString*) order_code completionHandler:(resultHandler)result
  6763. //{
  6764. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6765. // AppDelegate *appDelegate = nil;
  6766. //
  6767. //
  6768. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6769. //
  6770. // if(appDelegate.user!=nil)
  6771. // [params setValue:appDelegate.user forKey:@"user"];
  6772. // if(appDelegate.contact_id!=nil)
  6773. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6774. // if(appDelegate.password!=nil)
  6775. // [params setValue:appDelegate.password forKey:@"password"];
  6776. // // NSString* ssaved = @"false";
  6777. // // if(saved)
  6778. // // ssaved=@"true";
  6779. // [params setValue:@"true" forKey:@"saved"];
  6780. // [params setValue:order_code forKey:@"orderCode"];
  6781. // // [params setValue:sourceid forKey:@"sourceid"];
  6782. // // [params setValue:editor forKey:@"editor"];
  6783. //
  6784. // [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  6785. //
  6786. //
  6787. // if(appDelegate.offline_mode)
  6788. // {
  6789. //
  6790. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6791. // NSMutableDictionary* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  6792. // dispatch_async(dispatch_get_main_queue(), ^{
  6793. // result(json);
  6794. // });
  6795. // });
  6796. //
  6797. // return;
  6798. // }
  6799. //
  6800. //
  6801. // [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6802. //
  6803. //// NSData* json = nil;
  6804. ////
  6805. //// if(appDelegate.offline_mode)
  6806. //// {
  6807. //// json= [OLDataProvider offline_submitorder:params];
  6808. //// }
  6809. //// else
  6810. //// {
  6811. //// if(![self IsNetworkAvailable])
  6812. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6813. ////
  6814. //// json=[self get_json:URL_COMMIT_ORDER parameters:params];
  6815. //// }
  6816. //// if(json!=nil)
  6817. //// {
  6818. //// NSError *error=nil;
  6819. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6820. //// return jsobj;
  6821. //// }
  6822. //// else
  6823. //// return nil;
  6824. //
  6825. //}
  6826. +(void)request_copy_order:(NSString*) order_code completionHandler:(resultHandler)result
  6827. {
  6828. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6829. AppDelegate *appDelegate = nil;
  6830. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6831. if(appDelegate.user!=nil)
  6832. [params setValue:appDelegate.user forKey:@"user"];
  6833. if(appDelegate.contact_id!=nil)
  6834. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6835. if(appDelegate.password!=nil)
  6836. [params setValue:appDelegate.password forKey:@"password"];
  6837. // NSString* ssaved = @"false";
  6838. // if(saved)
  6839. // ssaved=@"true";
  6840. // [params setValue:@"true" forKey:@"saved"];
  6841. [params setValue:order_code forKey:@"code"];
  6842. // [params setValue:sourceid forKey:@"sourceid"];
  6843. // [params setValue:editor forKey:@"editor"];
  6844. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  6845. if(appDelegate.offline_mode)
  6846. {
  6847. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6848. NSData* json = [[OLDataProvider offline_copyorder:params] mutableCopy];
  6849. dispatch_async(dispatch_get_main_queue(), ^{
  6850. result([[RAConvertor data2dict:json] mutableCopy]);
  6851. });
  6852. });
  6853. return;
  6854. }
  6855. [self request_interface:URL_COPY_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6856. // NSData* json=nil;
  6857. // if(appDelegate.offline_mode)
  6858. // {
  6859. // json= [OLDataProvider offline_copyorder:params];
  6860. // }
  6861. // else
  6862. // {
  6863. // if(![self IsNetworkAvailable])
  6864. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6865. //
  6866. // json=[self get_json:URL_COPY_ORDER parameters:params];
  6867. // }
  6868. // if(json!=nil)
  6869. // {
  6870. // NSError *error=nil;
  6871. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6872. // return jsobj;
  6873. // }
  6874. // else
  6875. // return nil;
  6876. }
  6877. //
  6878. //+ (void)request_fastdownload:(NSMutableDictionary *)params url:(NSString *)url completionHandler:(resultHandler)result
  6879. //{
  6880. //
  6881. // //#ifdef test_server
  6882. // // url=URL_REQUEST_RECORDS;
  6883. // // params[@"prefix"]=URL_REQUEST_RECORDS;
  6884. // //#endif
  6885. //
  6886. // [self request_file_fast:url parameters:params completionHandler:result];
  6887. //
  6888. //}
  6889. +(void) request_addto_portfolio:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6890. {
  6891. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6892. AppDelegate *appDelegate = nil;
  6893. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6894. if(appDelegate.user!=nil)
  6895. [params setValue:appDelegate.user forKey:@"user"];
  6896. if(appDelegate.contact_id!=nil)
  6897. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6898. if(appDelegate.password!=nil)
  6899. [params setValue:appDelegate.password forKey:@"password"];
  6900. [params setValue:item_id forKey:@"product_id"];
  6901. [params setObject:screenName forKey:kScreenName];
  6902. if(appDelegate.offline_mode)
  6903. {
  6904. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6905. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_add2Portfolio:params]] mutableCopy];
  6906. dispatch_async(dispatch_get_main_queue(), ^{
  6907. int result_code = [[resulti valueForKey:@"result"] intValue];
  6908. if (result_code==2)
  6909. {
  6910. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6911. [appDelegate update_count_mark];
  6912. }
  6913. result(resulti);
  6914. });
  6915. });
  6916. return;
  6917. }
  6918. [self request_interface:URL_ADD_TO_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6919. int result_code = [[resulti valueForKey:@"result"] intValue];
  6920. if (result_code==2)
  6921. {
  6922. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6923. [appDelegate update_count_mark];
  6924. }
  6925. result(resulti);
  6926. } retry:0];
  6927. //
  6928. // NSData* json = nil;
  6929. // if(appDelegate.offline_mode)
  6930. // {
  6931. // json = [OLDataProvider offline_add2Portfolio:params];
  6932. // } else {
  6933. // if(![self IsNetworkAvailable])
  6934. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6935. //
  6936. // json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  6937. // }
  6938. //
  6939. // if(json==nil)
  6940. // return nil;
  6941. // NSError *error=nil;
  6942. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6943. // int result = [[jsobj valueForKey:@"result"] intValue];
  6944. //
  6945. // if (result==2)
  6946. // {
  6947. //
  6948. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6949. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6950. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6951. //
  6952. // [appDelegate update_count_mark];
  6953. // }
  6954. // return jsobj;
  6955. }
  6956. +(void)request_addall_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  6957. {
  6958. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6959. AppDelegate *appDelegate = nil;
  6960. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6961. if(appDelegate.user!=nil)
  6962. [params setValue:appDelegate.user forKey:@"user"];
  6963. if(appDelegate.contact_id!=nil)
  6964. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6965. if(appDelegate.password!=nil)
  6966. [params setValue:appDelegate.password forKey:@"password"];
  6967. if(appDelegate.order_code!=nil)
  6968. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6969. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6970. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6971. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  6972. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6973. // [params setValue:filter forKey:@"filter"];
  6974. [params setValue:keywords forKey:@"keyword"];
  6975. [params setValue:addTo forKey:@"addTo"];
  6976. [params setValue:orderCode forKey:@"orderCode"];
  6977. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6978. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6979. if(matchfull)
  6980. [params setValue:@"true" forKey:@"exactMatch"];
  6981. else
  6982. [params setValue:@"false" forKey:@"exactMatch"];
  6983. [params setObject:ScreenCodeSearch forKey:kScreenName];
  6984. if ([addTo isEqualToString:@"cart"]) {
  6985. [params setObject:@"Add To Cart" forKey:kAction];
  6986. }
  6987. if(appDelegate.offline_mode)
  6988. {
  6989. if ([addTo isEqualToString:@"cart"])
  6990. {
  6991. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6992. }
  6993. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6994. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_searchaddall:params]] mutableCopy];
  6995. dispatch_async(dispatch_get_main_queue(), ^{
  6996. int result_code =[json[@"result"] intValue];
  6997. if (result_code==2||result_code==8)
  6998. {
  6999. if(json[@"cart_count"])
  7000. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7001. if(json[@"wish_count"])
  7002. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7003. if(json[@"portfolio_count"])
  7004. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7005. //
  7006. //
  7007. [appDelegate update_count_mark];
  7008. }
  7009. result(json);
  7010. });
  7011. });
  7012. return;
  7013. }
  7014. NSString * uuid= [[NSUUID UUID] UUIDString];
  7015. params[@"resultSerial"]=uuid;
  7016. __block bool bbreak = false;
  7017. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7018. for(int i=0;i<150;i++)
  7019. {
  7020. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7021. // result_params[@"resultSerial"]=uuid;
  7022. if(bbreak)
  7023. break;
  7024. dispatch_async(dispatch_get_main_queue(), ^{
  7025. [self request_interface:URL_SEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7026. if([resulti[@"result"] intValue]==2)
  7027. {
  7028. if(!bbreak)//此判断保证result只调用一次。
  7029. result(resulti);
  7030. bbreak=true;
  7031. }
  7032. } retry:3];
  7033. });
  7034. sleep(2);
  7035. }
  7036. });
  7037. //
  7038. //
  7039. // NSData* json=nil;
  7040. // if(appDelegate.offline_mode)
  7041. // {
  7042. // json=[OLDataProvider offline_searchaddall:params];
  7043. // }
  7044. // else
  7045. // {
  7046. // if(![self IsNetworkAvailable])
  7047. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7048. //
  7049. // NSError *error=nil;
  7050. //
  7051. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7052. // params[@"resultSerial"]=uuid;
  7053. //
  7054. // for(int i=0;i<150;i++)
  7055. // {
  7056. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7057. // // result_params[@"resultSerial"]=uuid;
  7058. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  7059. // if(json!=nil)
  7060. // {
  7061. //
  7062. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7063. // if([jsobj[@"result"] intValue]==2)
  7064. // {
  7065. // break;
  7066. // }
  7067. // }
  7068. // sleep(2);
  7069. // }
  7070. // }
  7071. // if(json==nil)
  7072. // return nil;
  7073. // NSError *error=nil;
  7074. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7075. // return jsobj;
  7076. }
  7077. +(void) request_addto_cart_byupc:(NSString* ) upc_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  7078. {
  7079. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7080. AppDelegate *appDelegate = nil;
  7081. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7082. if(appDelegate.user!=nil)
  7083. [params setValue:appDelegate.user forKey:@"user"];
  7084. if(appDelegate.contact_id!=nil)
  7085. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7086. if(appDelegate.password!=nil)
  7087. [params setValue:appDelegate.password forKey:@"password"];
  7088. if(appDelegate.order_code!=nil)
  7089. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7090. [params setValue:upc_code forKey:@"upc_code"];
  7091. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  7092. [params setObject:screenName forKey:kScreenName];
  7093. [params setObject:@"Add To Cart" forKey:kAction];
  7094. if (!upc_code) {
  7095. upc_code = @"";
  7096. }
  7097. [params setObject:@{@"UPCCode" : upc_code} forKey:kExtra];
  7098. params[@"search_upc"]=@true;
  7099. NSDictionary* customerinfo= appDelegate.customerInfo;
  7100. NSArray* keys=[customerinfo allKeys];
  7101. for(int i=0;i<keys.count;i++)
  7102. {
  7103. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7104. }
  7105. if(appDelegate.offline_mode)
  7106. {
  7107. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7108. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  7109. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7110. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyupc:params]] mutableCopy];
  7111. dispatch_async(dispatch_get_main_queue(), ^{
  7112. int result_code = [[json valueForKey:@"result"] intValue];
  7113. if (result_code==2||result_code==8)
  7114. {
  7115. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7116. [appDelegate update_count_mark];
  7117. }
  7118. result(json);
  7119. });
  7120. });
  7121. return;
  7122. }
  7123. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7124. int result_code = [[resulti valueForKey:@"result"] intValue];
  7125. if (result_code==2||result_code==8)
  7126. {
  7127. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7128. [appDelegate update_count_mark];
  7129. }
  7130. result(resulti);
  7131. } retry:0];
  7132. }
  7133. +(void) request_addto_cart_byname:(NSString* ) model_name withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  7134. {
  7135. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7136. AppDelegate *appDelegate = nil;
  7137. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7138. if(appDelegate.user!=nil)
  7139. [params setValue:appDelegate.user forKey:@"user"];
  7140. if(appDelegate.contact_id!=nil)
  7141. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7142. if(appDelegate.password!=nil)
  7143. [params setValue:appDelegate.password forKey:@"password"];
  7144. if(appDelegate.order_code!=nil)
  7145. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7146. [params setValue:model_name forKey:@"product_name"];
  7147. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  7148. [params setObject:screenName forKey:kScreenName];
  7149. [params setObject:@"Add To Cart" forKey:kAction];
  7150. if (!model_name) {
  7151. model_name = @"";
  7152. }
  7153. [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  7154. NSDictionary* customerinfo= appDelegate.customerInfo;
  7155. NSArray* keys=[customerinfo allKeys];
  7156. for(int i=0;i<keys.count;i++)
  7157. {
  7158. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7159. }
  7160. if(appDelegate.offline_mode)
  7161. {
  7162. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7163. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  7164. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7165. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyname:params]] mutableCopy];
  7166. dispatch_async(dispatch_get_main_queue(), ^{
  7167. int result_code = [[json valueForKey:@"result"] intValue];
  7168. if (result_code==2||result_code==8)
  7169. {
  7170. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7171. [appDelegate update_count_mark];
  7172. }
  7173. result(json);
  7174. });
  7175. });
  7176. return;
  7177. }
  7178. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7179. int result_code = [[resulti valueForKey:@"result"] intValue];
  7180. if (result_code==2||result_code==8)
  7181. {
  7182. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7183. [appDelegate update_count_mark];
  7184. }
  7185. result(resulti);
  7186. } retry:0];
  7187. // NSData* json=nil;
  7188. // if(appDelegate.offline_mode)
  7189. // {
  7190. // json= [OLDataProvider offline_add2cartbyname:params];
  7191. // }
  7192. // else
  7193. // {
  7194. // if(![self IsNetworkAvailable])
  7195. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7196. //
  7197. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  7198. // }
  7199. // if(json==nil)
  7200. // return nil;
  7201. // NSError *error=nil;
  7202. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7203. //
  7204. //
  7205. //
  7206. // int result = [[jsobj valueForKey:@"result"] intValue];
  7207. //
  7208. // if (result==2||result==8)
  7209. // {
  7210. //
  7211. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  7212. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  7213. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  7214. //
  7215. // [appDelegate update_count_mark];
  7216. // }
  7217. //
  7218. // return jsobj;
  7219. }
  7220. +(void) request_addto_wishlist:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  7221. {
  7222. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7223. AppDelegate *appDelegate = nil;
  7224. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7225. if(appDelegate.user!=nil)
  7226. [params setValue:appDelegate.user forKey:@"user"];
  7227. if(appDelegate.contact_id!=nil)
  7228. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7229. if(appDelegate.password!=nil)
  7230. [params setValue:appDelegate.password forKey:@"password"];
  7231. [params setValue:item_id forKey:@"product_id"];
  7232. [params setObject:screenName forKey:kScreenName];
  7233. if(appDelegate.offline_mode)
  7234. {
  7235. // [OLDataProvider offline_add2wishlist:params completionHandler:result];
  7236. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7237. NSMutableDictionary* resulti = [[OLDataProvider offline_add2wishlist:params] mutableCopy];
  7238. dispatch_async(dispatch_get_main_queue(), ^{
  7239. int result_code = [[resulti valueForKey:@"result"] intValue];
  7240. if (result_code==2||result_code==8)
  7241. {
  7242. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7243. [appDelegate update_count_mark];
  7244. }
  7245. result(resulti);
  7246. });
  7247. });
  7248. return;
  7249. }
  7250. [self request_interface:URL_ADD_TO_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7251. int result_code = [[resulti valueForKey:@"result"] intValue];
  7252. if (result_code==2||result_code==8)
  7253. {
  7254. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7255. [appDelegate update_count_mark];
  7256. }
  7257. result(resulti);
  7258. } retry:0];
  7259. // if(appDelegate.offline_mode)
  7260. // {
  7261. // return [OLDataProvider offline_add2wishlist:params];
  7262. // }
  7263. // if(![self IsNetworkAvailable])
  7264. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7265. //
  7266. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  7267. // if(json==nil)
  7268. // return nil;
  7269. // NSError *error=nil;
  7270. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7271. // int result = [[jsobj valueForKey:@"result"] intValue];
  7272. //
  7273. // if (result==2)
  7274. // {
  7275. //
  7276. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  7277. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  7278. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  7279. //
  7280. // [appDelegate update_count_mark];
  7281. // }
  7282. // return jsobj;
  7283. }
  7284. +(void)request_addall_itemsearch:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  7285. {
  7286. // for debug
  7287. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  7288. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7289. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7290. AppDelegate *appDelegate = nil;
  7291. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7292. if(appDelegate.user!=nil)
  7293. [params setValue:appDelegate.user forKey:@"user"];
  7294. if(appDelegate.contact_id!=nil)
  7295. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7296. if(appDelegate.password!=nil)
  7297. [params setValue:appDelegate.password forKey:@"password"];
  7298. if(appDelegate.order_code!=nil)
  7299. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7300. [params setValue:addTo forKey:@"addTo"];
  7301. [params setValue:orderCode forKey:@"orderCode"];
  7302. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7303. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7304. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  7305. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7306. // [params setValue:filter forKey:@"filter"];
  7307. [params setValue:covertype forKey:@"covertype"];
  7308. [params setValue:ctgid forKey:@"ctgId"];
  7309. [params setValue:modelname forKey:@"modelName"];
  7310. [params setValue:modeldescrip forKey:@"modelDescription"];
  7311. [params setValue:alert forKey:@"alert"];
  7312. [params setValue:qty forKey:@"sold_by_qty"];
  7313. [params setValue:available forKey:@"available"];
  7314. [params setValue:price forKey:@"price"];
  7315. [params setValue:bestseller forKey:@"bestseller"];
  7316. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7317. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7318. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  7319. if ([addTo isEqualToString:@"cart"]) {
  7320. [params setObject:@"Add To Cart" forKey:kAction];
  7321. }
  7322. if(appDelegate.offline_mode)
  7323. {
  7324. if ([addTo isEqualToString:@"cart"])
  7325. {
  7326. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7327. }
  7328. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7329. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_itemsearchaddall:params]] mutableCopy];
  7330. dispatch_async(dispatch_get_main_queue(), ^{
  7331. int result_code =[json[@"result"] intValue];
  7332. if (result_code==2||result_code==8)
  7333. {
  7334. if(json[@"cart_count"])
  7335. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7336. if(json[@"wish_count"])
  7337. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7338. if(json[@"portfolio_count"])
  7339. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7340. //
  7341. //
  7342. [appDelegate update_count_mark];
  7343. }
  7344. result(json);
  7345. });
  7346. });
  7347. return;
  7348. }
  7349. NSString * uuid= [[NSUUID UUID] UUIDString];
  7350. params[@"resultSerial"]=uuid;
  7351. __block bool bbreak = false;
  7352. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7353. for(int i=0;i<150;i++)
  7354. {
  7355. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7356. // result_params[@"resultSerial"]=uuid;
  7357. if(bbreak)
  7358. break;
  7359. dispatch_async(dispatch_get_main_queue(), ^{
  7360. [self request_interface:URL_ITEMSEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7361. if([resulti[@"result"] intValue]==2)
  7362. {
  7363. if(!bbreak)//此判断保证result只调用一次。
  7364. result(resulti);
  7365. bbreak=true;
  7366. }
  7367. } retry:3];
  7368. });
  7369. sleep(2);
  7370. }
  7371. });
  7372. //
  7373. // NSData* json = nil;
  7374. //
  7375. // if(appDelegate.offline_mode)
  7376. // {
  7377. // json= [OLDataProvider offline_itemsearchaddall:params];
  7378. // }
  7379. // else
  7380. // {
  7381. // if(![self IsNetworkAvailable])
  7382. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7383. // NSError *error=nil;
  7384. //
  7385. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7386. // params[@"resultSerial"]=uuid;
  7387. //
  7388. // for(int i=0;i<150;i++)
  7389. // {
  7390. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7391. // // result_params[@"resultSerial"]=uuid;
  7392. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  7393. // if(json!=nil)
  7394. // {
  7395. //
  7396. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7397. // if([jsobj[@"result"] intValue]==2)
  7398. // {
  7399. // break;
  7400. // }
  7401. // }
  7402. // sleep(2);
  7403. // }
  7404. // }
  7405. // if(json==nil)
  7406. // return nil;
  7407. // NSError *error=nil;
  7408. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7409. // return jsobj;
  7410. }
  7411. +(void)request_addall_category: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  7412. {
  7413. AppDelegate *appDelegate = nil;
  7414. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7415. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7416. if(appDelegate.user!=nil)
  7417. [params setValue:appDelegate.user forKey:@"user"];
  7418. if(appDelegate.contact_id!=nil)
  7419. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7420. if(appDelegate.password!=nil)
  7421. [params setValue:appDelegate.password forKey:@"password"];
  7422. if(appDelegate.order_code!=nil)
  7423. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7424. [params setValue:addTo forKey:@"addTo"];
  7425. [params setValue:orderCode forKey:@"orderCode"];
  7426. [params setValue:alert forKey:@"alert"];
  7427. [params setValue:qty forKey:@"sold_by_qty"];
  7428. [params setValue:available forKey:@"available"];
  7429. [params setValue:price forKey:@"price"];
  7430. [params setValue:bestseller forKey:@"bestseller"];
  7431. [params setValue:modelname forKey:@"modelName"];
  7432. [params setValue:modeldescrip forKey:@"modelDescription"];
  7433. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7434. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7435. [params setValue:category forKey:@"category"];
  7436. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7437. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7438. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7439. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7440. [params setValue:filter forKey:@"filter"];
  7441. [params setValue:keyword forKey:@"keyword"];
  7442. [params setObject:ScreenCodeCategory forKey:kScreenName];
  7443. if ([addTo isEqualToString:@"cart"]) {
  7444. [params setObject:@"Add To Cart" forKey:kAction];
  7445. }
  7446. if(appDelegate.offline_mode)
  7447. {
  7448. if ([addTo isEqualToString:@"cart"])
  7449. {
  7450. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7451. }
  7452. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7453. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_categoryaddall:params]] mutableCopy];
  7454. dispatch_async(dispatch_get_main_queue(), ^{
  7455. int result_code =[json[@"result"] intValue];
  7456. if (result_code==2||result_code==8)
  7457. {
  7458. if(json[@"cart_count"])
  7459. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7460. if(json[@"wish_count"])
  7461. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7462. if(json[@"portfolio_count"])
  7463. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7464. //
  7465. //
  7466. [appDelegate update_count_mark];
  7467. }
  7468. result(json);
  7469. });
  7470. });
  7471. return;
  7472. }
  7473. NSString * uuid= [[NSUUID UUID] UUIDString];
  7474. params[@"resultSerial"]=uuid;
  7475. __block bool bbreak = false;
  7476. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7477. for(int i=0;i<150;i++)
  7478. {
  7479. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7480. // result_params[@"resultSerial"]=uuid;
  7481. if(bbreak)
  7482. break;
  7483. dispatch_async(dispatch_get_main_queue(), ^{
  7484. [self request_interface:URL_CATEGORYADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7485. if([resulti[@"result"] intValue]==2|| [resulti[@"result"] intValue] == 8)
  7486. {
  7487. if(!bbreak)//此判断保证result只调用一次。
  7488. {
  7489. int result_code =[resulti[@"result"] intValue];
  7490. if (result_code==2||result_code==8)
  7491. {
  7492. if(resulti[@"cart_count"])
  7493. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7494. if(resulti[@"wish_count"])
  7495. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7496. if(resulti[@"portfolio_count"])
  7497. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  7498. //
  7499. //
  7500. [appDelegate update_count_mark];
  7501. }
  7502. result(resulti);
  7503. }
  7504. bbreak=true;
  7505. }
  7506. } retry:3];
  7507. });
  7508. sleep(2);
  7509. }
  7510. });
  7511. //
  7512. // NSData* json= nil;
  7513. //
  7514. // if(appDelegate.offline_mode)
  7515. // {
  7516. // json= [OLDataProvider offline_categoryaddall:params];
  7517. // }
  7518. // else
  7519. // {
  7520. // if(![self IsNetworkAvailable])
  7521. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7522. //
  7523. //
  7524. // NSError *error=nil;
  7525. //
  7526. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7527. // params[@"resultSerial"]=uuid;
  7528. //
  7529. // for(int i=0;i<150;i++)
  7530. // {
  7531. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7532. //// result_params[@"resultSerial"]=uuid;
  7533. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  7534. // if(json!=nil)
  7535. // {
  7536. //
  7537. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7538. // int resultInt = [jsobj[@"result"] intValue];
  7539. // if(resultInt == 2 || resultInt == 8)
  7540. // {
  7541. // break;
  7542. // }
  7543. // }
  7544. // sleep(2);
  7545. // }
  7546. //
  7547. //
  7548. //
  7549. // }
  7550. // if(json==nil)
  7551. // return nil;
  7552. // NSError *error=nil;
  7553. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7554. // return jsobj;
  7555. }
  7556. +(void)request_save_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7557. {
  7558. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7559. AppDelegate *appDelegate = nil;
  7560. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7561. if(appDelegate.user!=nil)
  7562. [params setValue:appDelegate.user forKey:@"user"];
  7563. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  7564. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7565. // else
  7566. if(appDelegate.contact_id!=nil)
  7567. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7568. if(appDelegate.password!=nil)
  7569. [params setValue:appDelegate.password forKey:@"password"];
  7570. if(appDelegate.order_code!=nil)
  7571. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7572. // NSDictionary* customerinfo=nil;
  7573. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  7574. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7575. // else
  7576. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7577. //
  7578. // appDelegate.customerInfo;
  7579. // NSArray* keys=[customerinfo allKeys];
  7580. // for(int i=0;i<keys.count;i++)
  7581. // {
  7582. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7583. // }
  7584. // [params setValue:sourceid forKey:@"sourceid"];
  7585. // [params setValue:editor forKey:@"editor"];
  7586. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  7587. if(appDelegate.offline_mode)
  7588. {
  7589. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7590. NSData* json = [[OLDataProvider offline_saveorder:params] mutableCopy];
  7591. dispatch_async(dispatch_get_main_queue(), ^{
  7592. result([[RAConvertor data2dict:json] mutableCopy]);
  7593. });
  7594. });
  7595. return;
  7596. }
  7597. [self request_interface:URL_SAVE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  7598. //
  7599. // NSData* json=nil;
  7600. //
  7601. // if(appDelegate.offline_mode)
  7602. // {
  7603. // json= [OLDataProvider offline_saveorder:params];
  7604. // }
  7605. // else
  7606. // {
  7607. // if(![self IsNetworkAvailable])
  7608. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7609. //
  7610. // json=[self get_json:URL_SAVE_ORDER parameters:params];
  7611. // }
  7612. // if(json!=nil)
  7613. // {
  7614. // NSError *error=nil;
  7615. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7616. // NSString *so = [jsobj valueForKey:@"so#"];
  7617. // if (so) {
  7618. // [appDelegate SetSo:so];
  7619. // }
  7620. // return jsobj;
  7621. // }
  7622. // else
  7623. // return nil;
  7624. }
  7625. +(void) request_update_cartqty:(NSString*) cart_id value:(int) value completionHandler:(resultHandler)result
  7626. {
  7627. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7628. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  7629. #ifdef SCANNER_ORDER
  7630. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7631. {
  7632. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7633. //
  7634. //
  7635. // [appDelegate update_count_mark];
  7636. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7637. int count = [section[@"count"] intValue];
  7638. for(int i=0;i<count;i++)
  7639. {
  7640. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7641. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7642. {
  7643. item[@"count"] =@(value);
  7644. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7645. break;
  7646. }
  7647. }
  7648. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7649. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7650. result(RASingleton.sharedInstance.scan_cart);
  7651. // [OLDataProvider updateScanOrder:appDelegate.order_code orderitem:nil];
  7652. return;
  7653. }
  7654. #endif
  7655. if(appDelegate.user!=nil)
  7656. [params setValue:appDelegate.user forKey:@"user"];
  7657. if(appDelegate.contact_id!=nil)
  7658. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7659. if(appDelegate.password!=nil)
  7660. [params setValue:appDelegate.password forKey:@"password"];
  7661. [params setValue:cart_id forKey:@"cartitem_id"];
  7662. [params setObject:ScreenCodeCart forKey:kScreenName];
  7663. [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  7664. if(appDelegate.offline_mode)
  7665. {
  7666. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7667. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7668. NSData* json = [[OLDataProvider offline_cartsetqty:params] mutableCopy];
  7669. dispatch_async(dispatch_get_main_queue(), ^{
  7670. result([[RAConvertor data2dict:json] mutableCopy]);
  7671. });
  7672. });
  7673. return;
  7674. }
  7675. [self request_interface:URL_CART_INCRESEMENT parameters:params err_record_url:nil completionHandler:result retry:0];
  7676. //
  7677. // NSData* json=nil;
  7678. // if(appDelegate.offline_mode)
  7679. // {
  7680. // json= [OLDataProvider offline_cartsetqty:params];
  7681. // }
  7682. // else
  7683. // {
  7684. // if(![self IsNetworkAvailable])
  7685. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7686. //
  7687. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  7688. // }
  7689. // if(json==nil)
  7690. // return nil;
  7691. // NSError *error=nil;
  7692. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7693. // return jsobj;
  7694. }
  7695. +(void) request_update_cartgeneralnote:(NSString*) order_code notes:(NSString*) notes completionHandler:(resultHandler)result
  7696. {
  7697. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7698. AppDelegate *appDelegate = nil;
  7699. #ifdef SCANNER_ORDER
  7700. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7701. {
  7702. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7703. //
  7704. //
  7705. // [appDelegate update_count_mark];
  7706. RASingleton.sharedInstance.scan_cart[@"general_note"] = notes;
  7707. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7708. result(RASingleton.sharedInstance.scan_cart);
  7709. return;
  7710. }
  7711. #endif
  7712. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7713. if(appDelegate.user!=nil)
  7714. [params setValue:appDelegate.user forKey:@"user"];
  7715. if(appDelegate.contact_id!=nil)
  7716. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7717. if(appDelegate.password!=nil)
  7718. [params setValue:appDelegate.password forKey:@"password"];
  7719. [params setValue:order_code forKey:@"orderCode"];
  7720. [params setObject:ScreenCodeCart forKey:kScreenName];
  7721. if(notes.length==0)
  7722. notes=@"";
  7723. [params setValue:notes forKey:@"comments"];
  7724. if(appDelegate.offline_mode)
  7725. {
  7726. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7727. NSData* json = [[OLDataProvider offline_updategnotes:params] mutableCopy];
  7728. dispatch_async(dispatch_get_main_queue(), ^{
  7729. result([[RAConvertor data2dict:json] mutableCopy]);
  7730. });
  7731. });
  7732. return;
  7733. }
  7734. [self request_interface:URL_CART_GENERAL_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7735. //
  7736. // NSData* json=nil;
  7737. // if(appDelegate.offline_mode)
  7738. // {
  7739. // json= [OLDataProvider offline_updategnotes:params];
  7740. // }
  7741. // else
  7742. // {
  7743. // if(![self IsNetworkAvailable])
  7744. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7745. //
  7746. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  7747. // }
  7748. // if(json==nil)
  7749. // return nil;
  7750. // NSError *error=nil;
  7751. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7752. // return jsobj;
  7753. }
  7754. +(void) request_update_cartitemnote:(NSString*) cart_id notes:(NSString*) notes completionHandler:(resultHandler)result
  7755. {
  7756. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7757. AppDelegate *appDelegate = nil;
  7758. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7759. #ifdef SCANNER_ORDER
  7760. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7761. {
  7762. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7763. //
  7764. //
  7765. // [appDelegate update_count_mark];
  7766. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7767. int count = [section[@"count"] intValue];
  7768. for(int i=0;i<count;i++)
  7769. {
  7770. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7771. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7772. {
  7773. item[@"note"] =notes;
  7774. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7775. break;
  7776. }
  7777. }
  7778. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7779. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7780. result(RASingleton.sharedInstance.scan_cart);
  7781. return;
  7782. }
  7783. #endif
  7784. if(appDelegate.user!=nil)
  7785. [params setValue:appDelegate.user forKey:@"user"];
  7786. if(appDelegate.contact_id!=nil)
  7787. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7788. if(appDelegate.password!=nil)
  7789. [params setValue:appDelegate.password forKey:@"password"];
  7790. [params setValue:cart_id forKey:@"cartitem_id"];
  7791. [params setObject:ScreenCodeCart forKey:kScreenName];
  7792. if(notes.length==0)
  7793. notes=@"";
  7794. [params setValue:notes forKey:@"notes"];
  7795. if(appDelegate.offline_mode)
  7796. {
  7797. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7798. NSData* json = [[OLDataProvider offline_cartsetlnotes:params] mutableCopy];
  7799. dispatch_async(dispatch_get_main_queue(), ^{
  7800. result([[RAConvertor data2dict:json] mutableCopy]);
  7801. });
  7802. });
  7803. return;
  7804. }
  7805. [self request_interface:URL_CART_ITEM_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7806. //
  7807. // NSData* json=nil;
  7808. // if(appDelegate.offline_mode)
  7809. // {
  7810. // json= [OLDataProvider offline_cartsetlnotes:params];
  7811. // }
  7812. // else
  7813. // {
  7814. // if(![self IsNetworkAvailable])
  7815. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7816. //
  7817. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  7818. // }
  7819. // if(json==nil)
  7820. // return nil;
  7821. // NSError *error=nil;
  7822. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7823. // return jsobj;
  7824. }
  7825. + (void)request_update_npd_shop_price_type:(NSInteger)priceType completionHandler:(resultHandler)result
  7826. {
  7827. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7828. AppDelegate *appDelegate = nil;
  7829. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7830. if(appDelegate.user!=nil)
  7831. [dic setValue:appDelegate.user forKey:@"user"];
  7832. if(appDelegate.password!=nil)
  7833. [dic setValue:appDelegate.password forKey:@"password"];
  7834. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  7835. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  7836. if(appDelegate.offline_mode)
  7837. {
  7838. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7839. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7840. dispatch_async(dispatch_get_main_queue(), ^{
  7841. result(json);
  7842. });
  7843. });
  7844. return;
  7845. }
  7846. [self request_interface:URL_SET_PRICE_TYPE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7847. //
  7848. // NSData* json=nil;
  7849. // if(appDelegate.offline_mode)
  7850. // {
  7851. // return [OLDataProvider offline_notimpl];
  7852. // }
  7853. // else
  7854. // {
  7855. // if(![self IsNetworkAvailable])
  7856. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7857. //
  7858. // json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  7859. // }
  7860. // if(json!=nil)
  7861. // {
  7862. // NSError *error=nil;
  7863. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7864. //
  7865. //
  7866. // return jsobj;
  7867. // }
  7868. //
  7869. //
  7870. // return nil;
  7871. }
  7872. + (void)request_npd_shop_givenprice:(resultHandler)result
  7873. {
  7874. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7875. AppDelegate *appDelegate = nil;
  7876. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7877. if(appDelegate.user!=nil)
  7878. [dic setValue:appDelegate.user forKey:@"user"];
  7879. if(appDelegate.password!=nil)
  7880. [dic setValue:appDelegate.password forKey:@"password"];
  7881. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  7882. if(appDelegate.offline_mode)
  7883. {
  7884. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7885. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7886. dispatch_async(dispatch_get_main_queue(), ^{
  7887. result(json);
  7888. });
  7889. });
  7890. return;
  7891. }
  7892. [self request_interface:URL_GET_CIVEN_PRICE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7893. //
  7894. // NSData* json=nil;
  7895. // if(appDelegate.offline_mode)
  7896. // {
  7897. // return [OLDataProvider offline_notimpl];
  7898. // }
  7899. // else
  7900. // {
  7901. // if(![self IsNetworkAvailable])
  7902. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7903. //
  7904. // json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  7905. // }
  7906. // if(json!=nil)
  7907. // {
  7908. // NSError *error=nil;
  7909. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7910. //
  7911. //
  7912. // return jsobj;
  7913. // }
  7914. //
  7915. //
  7916. // return nil;
  7917. }
  7918. + (void)request_update_npd_shop_givenprice:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  7919. {
  7920. AppDelegate *appDelegate = nil;
  7921. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7922. if(appDelegate.user!=nil)
  7923. [params setValue:appDelegate.user forKey:@"user"];
  7924. if(appDelegate.password!=nil)
  7925. [params setValue:appDelegate.password forKey:@"password"];
  7926. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  7927. if(appDelegate.offline_mode)
  7928. {
  7929. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7930. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7931. dispatch_async(dispatch_get_main_queue(), ^{
  7932. result(json);
  7933. });
  7934. });
  7935. return;
  7936. }
  7937. [self request_interface:URL_SET_GIVEN_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  7938. //
  7939. // NSData* json=nil;
  7940. // if(appDelegate.offline_mode)
  7941. // {
  7942. // return [OLDataProvider offline_notimpl];
  7943. // }
  7944. // else
  7945. // {
  7946. // if(![self IsNetworkAvailable])
  7947. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7948. //
  7949. // json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  7950. // }
  7951. // if(json!=nil)
  7952. // {
  7953. // NSError *error=nil;
  7954. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7955. //
  7956. //
  7957. // return jsobj;
  7958. // }
  7959. //
  7960. //
  7961. // return nil;
  7962. }
  7963. +(void) request_create_portfolio:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7964. {
  7965. AppDelegate *appDelegate = nil;
  7966. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7967. if(appDelegate.offline_mode)
  7968. {
  7969. params[@"contact_id"]=params[@"contactId"];
  7970. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7971. NSData* json = [[OLDataProvider offline_direct_save_TearSheet:params] mutableCopy];
  7972. dispatch_async(dispatch_get_main_queue(), ^{
  7973. result([[RAConvertor data2dict:json] mutableCopy]);
  7974. });
  7975. });
  7976. return;
  7977. }
  7978. //
  7979. // if(appDelegate.offline_mode)
  7980. // {
  7981. //
  7982. //
  7983. // NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  7984. // if(json==nil)
  7985. // return nil;
  7986. // NSError *error=nil;
  7987. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7988. //
  7989. // return jsobj[@"pdf_path"];
  7990. // }
  7991. // else
  7992. // {
  7993. // return nil;
  7994. // }
  7995. }
  7996. +(void)request_save_portfoliodirectly:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7997. {
  7998. NSMutableDictionary* off_params = [params mutableCopy];
  7999. AppDelegate *appDelegate = nil;
  8000. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8001. if(appDelegate.user!=nil)
  8002. [params setValue:appDelegate.user forKey:@"user"];
  8003. if(appDelegate.contact_id!=nil)
  8004. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8005. if(appDelegate.password!=nil)
  8006. params[@"off_params"]=[RAConvertor dict2string:off_params];
  8007. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  8008. [params setValue:appDelegate.password forKey:@"password"];
  8009. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  8010. if(appDelegate.offline_mode)
  8011. {
  8012. params[@"contact_id"]=appDelegate.contact_id;
  8013. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8014. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_direct_save_TearSheet:params]] mutableCopy];
  8015. dispatch_async(dispatch_get_main_queue(), ^{
  8016. result(json);
  8017. });
  8018. });
  8019. return;
  8020. }
  8021. NSString * uuid= [[NSUUID UUID] UUIDString];
  8022. params[@"resultSerial"]=uuid;
  8023. __block bool bbreak = false;
  8024. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8025. for(int i=0;i<150;i++)
  8026. {
  8027. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8028. // result_params[@"resultSerial"]=uuid;
  8029. if(bbreak)
  8030. break;
  8031. dispatch_async(dispatch_get_main_queue(), ^{
  8032. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8033. if([resulti[@"result"] intValue]==2)
  8034. {
  8035. if(!bbreak)//此判断保证result只调用一次。
  8036. result(resulti);
  8037. bbreak=true;
  8038. }
  8039. } retry:3];
  8040. });
  8041. sleep(2);
  8042. }
  8043. });
  8044. //
  8045. //
  8046. // NSData* json= nil;
  8047. //
  8048. // if(appDelegate.offline_mode)
  8049. // {
  8050. // json = [OLDataProvider offline_direct_save_TearSheet:params];
  8051. // }
  8052. // else
  8053. // {
  8054. // if(![self IsNetworkAvailable])
  8055. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8056. //
  8057. // json=[self get_json:URL_REQUEST_DM parameters:params];
  8058. //
  8059. // NSError *error=nil;
  8060. //
  8061. // NSString * uuid= [[NSUUID UUID] UUIDString];
  8062. // params[@"resultSerial"]=uuid;
  8063. //
  8064. // for(int i=0;i<150;i++)
  8065. // {
  8066. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8067. // // result_params[@"resultSerial"]=uuid;
  8068. // json=[self get_json:URL_REQUEST_DM parameters:params];
  8069. // if(json!=nil)
  8070. // {
  8071. //
  8072. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8073. // if([jsobj[@"result"] intValue]==2)
  8074. // {
  8075. // break;
  8076. // }
  8077. // }
  8078. // sleep(5);
  8079. // }
  8080. //
  8081. // }
  8082. // if(json==nil)
  8083. // return nil;
  8084. // NSError *error=nil;
  8085. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8086. // return jsobj;
  8087. }
  8088. +(void)request_save_portfolio:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  8089. {
  8090. AppDelegate *appDelegate = nil;
  8091. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8092. if(appDelegate.user!=nil)
  8093. [params setValue:appDelegate.user forKey:@"user"];
  8094. if(appDelegate.contact_id!=nil)
  8095. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8096. NSMutableDictionary* off_params = [params mutableCopy];;
  8097. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  8098. params[@"off_params"]=[RAConvertor dict2string:off_params];
  8099. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8100. if(appDelegate.password!=nil)
  8101. [params setValue:appDelegate.password forKey:@"password"];
  8102. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  8103. if(appDelegate.offline_mode)
  8104. {
  8105. params[@"contact_id"]=appDelegate.contact_id;
  8106. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8107. NSData* json = [[OLDataProvider offline_save_TearSheet:params] mutableCopy];
  8108. dispatch_async(dispatch_get_main_queue(), ^{
  8109. result([[RAConvertor data2dict:json] mutableCopy]);
  8110. });
  8111. });
  8112. return;
  8113. }
  8114. [self request_interface:URL_SAVE_DM parameters:params err_record_url:nil completionHandler:result retry:0];
  8115. //
  8116. // NSData* json = nil;
  8117. // if(appDelegate.offline_mode)
  8118. // {
  8119. // json = [OLDataProvider offline_save_TearSheet:params];
  8120. // } else {
  8121. // if(![self IsNetworkAvailable])
  8122. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8123. //
  8124. // json=[self get_json:URL_SAVE_DM parameters:params];
  8125. // }
  8126. // if(json==nil)
  8127. // return nil;
  8128. // NSError *error=nil;
  8129. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8130. // return jsobj;
  8131. }
  8132. +(void)request_portfoliopreview:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8133. {
  8134. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8135. AppDelegate *appDelegate = nil;
  8136. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8137. if(appDelegate.user!=nil)
  8138. [params setValue:appDelegate.user forKey:@"user"];
  8139. if(appDelegate.contact_id!=nil)
  8140. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8141. if(appDelegate.password!=nil)
  8142. [params setValue:appDelegate.password forKey:@"password"];
  8143. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  8144. // [params setValue:request_url forKey:@"pdfUrl"];
  8145. if(appDelegate.offline_mode)
  8146. {
  8147. params[@"contact_id"]=params[@"contactId"];
  8148. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8149. NSData* json = [[OLDataProvider offline_request_tearsheet:params] mutableCopy];
  8150. dispatch_async(dispatch_get_main_queue(), ^{
  8151. result([[RAConvertor data2dict:json] mutableCopy]);
  8152. });
  8153. });
  8154. return;
  8155. }
  8156. NSString * uuid= [[NSUUID UUID] UUIDString];
  8157. params[@"resultSerial"]=uuid;
  8158. __block bool bbreak = false;
  8159. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8160. for(int i=0;i<150;i++)
  8161. {
  8162. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8163. // result_params[@"resultSerial"]=uuid;
  8164. if(bbreak)
  8165. break;
  8166. dispatch_async(dispatch_get_main_queue(), ^{
  8167. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8168. if([resulti[@"result"] intValue]==2)
  8169. {
  8170. if(!bbreak)//此判断保证result只调用一次。
  8171. result(resulti);
  8172. bbreak=true;
  8173. }
  8174. } retry:3];
  8175. });
  8176. sleep(5);
  8177. }
  8178. });
  8179. //
  8180. // NSData* json= nil;
  8181. // if(appDelegate.offline_mode)
  8182. // {
  8183. // json= [OLDataProvider offline_request_tearsheet:params];
  8184. // }
  8185. // else
  8186. // {
  8187. // if(![self IsNetworkAvailable])
  8188. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8189. //
  8190. // NSError *error=nil;
  8191. //
  8192. // NSString * uuid= [[NSUUID UUID] UUIDString];
  8193. // params[@"resultSerial"]=uuid;
  8194. //
  8195. // for(int i=0;i<150;i++)
  8196. // {
  8197. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8198. // // result_params[@"resultSerial"]=uuid;
  8199. // json=[self get_json:URL_REQUEST_DM parameters:params];
  8200. // if(json!=nil)
  8201. // {
  8202. //
  8203. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8204. // if([jsobj[@"result"] intValue]==2)
  8205. // {
  8206. // break;
  8207. // }
  8208. // }
  8209. // sleep(5);
  8210. // }
  8211. // }
  8212. // if(json==nil)
  8213. // return nil;
  8214. // NSError *error=nil;
  8215. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8216. // return jsobj;
  8217. }
  8218. +(void)request_itemsearch:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller completionHandler:(resultHandler)result
  8219. {
  8220. // for debug
  8221. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  8222. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8223. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8224. AppDelegate *appDelegate = nil;
  8225. //some UI methods ej
  8226. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8227. if(appDelegate.user!=nil)
  8228. [params setValue:appDelegate.user forKey:@"user"];
  8229. if(appDelegate.contact_id!=nil)
  8230. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8231. if(appDelegate.password!=nil)
  8232. [params setValue:appDelegate.password forKey:@"password"];
  8233. if(appDelegate.order_code!=nil)
  8234. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8235. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  8236. if (alert && qty && available && price && bestseller) {
  8237. [params setObject:@"Filter" forKey:kAction];
  8238. }
  8239. if ([RASingleton sharedInstance].homeItemClick) {
  8240. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  8241. [RASingleton sharedInstance].homeItemClick = NO;
  8242. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  8243. [RASingleton sharedInstance].homeClickedItemName = nil;
  8244. [params setObject:extra forKey:kExtra];
  8245. }
  8246. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  8247. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  8248. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  8249. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  8250. // [params setValue:filter forKey:@"filter"];
  8251. [params setValue:covertype forKey:@"covertype"];
  8252. [params setValue:ctgid forKey:@"ctgId"];
  8253. [params setValue:modelname forKey:@"modelName"];
  8254. [params setValue:modeldescrip forKey:@"modelDescription"];
  8255. [params setValue:alert forKey:@"alert"];
  8256. [params setValue:qty forKey:@"sold_by_qty"];
  8257. [params setValue:available forKey:@"available"];
  8258. [params setValue:price forKey:@"price"];
  8259. [params setValue:bestseller forKey:@"bestseller"];
  8260. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  8261. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  8262. if(appDelegate.offline_mode)
  8263. {
  8264. // [OLDataProvider offline_itemsearch:params completionHandler:result];
  8265. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8266. NSMutableDictionary* json = [[OLDataProvider offline_itemsearch:params] mutableCopy];
  8267. dispatch_async(dispatch_get_main_queue(), ^{
  8268. result(json);
  8269. });
  8270. });
  8271. return;
  8272. }
  8273. [self request_interface:URL_ITEM_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  8274. // if(appDelegate.offline_mode)
  8275. // {
  8276. // return [OLDataProvider offline_itemsearch:params];
  8277. // }
  8278. // if(![self IsNetworkAvailable])
  8279. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8280. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  8281. // if(json==nil)
  8282. // return nil;
  8283. // NSError *error=nil;
  8284. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8285. // return jsobj;
  8286. }
  8287. +(void)request_modelqty: (NSString*) fashionId completionHandler:(resultHandler)result
  8288. {
  8289. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8290. AppDelegate *appDelegate = nil;
  8291. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8292. if(appDelegate.user!=nil)
  8293. [params setValue:appDelegate.user forKey:@"user"];
  8294. if(appDelegate.contact_id!=nil)
  8295. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8296. if(appDelegate.password!=nil)
  8297. [params setValue:appDelegate.password forKey:@"password"];
  8298. [params setValue:fashionId forKey:@"fashionId"];
  8299. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  8300. if(appDelegate.offline_mode)
  8301. {
  8302. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8303. NSData* json = [[OLDataProvider offline_model_qty:params] mutableCopy];
  8304. dispatch_async(dispatch_get_main_queue(), ^{
  8305. result([[RAConvertor data2dict:json] mutableCopy]);
  8306. });
  8307. });
  8308. return;
  8309. }
  8310. [self request_interface:URL_REQUEST_MODEL_QTY parameters:params err_record_url:nil completionHandler:result retry:0];
  8311. // NSData* json = nil;
  8312. // if(appDelegate.offline_mode)
  8313. // {
  8314. // json = [OLDataProvider offline_model_qty:params];
  8315. // } else {
  8316. // if(![self IsNetworkAvailable])
  8317. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8318. //
  8319. // json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  8320. // }
  8321. // if(json==nil)
  8322. // return nil;
  8323. // NSError *error=nil;
  8324. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8325. // return jsobj;
  8326. }
  8327. +(void) request_update_portfolio_price:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes completionHandler:(resultHandler)result
  8328. {
  8329. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8330. AppDelegate *appDelegate = nil;
  8331. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8332. if(appDelegate.user!=nil)
  8333. [params setValue:appDelegate.user forKey:@"user"];
  8334. if(appDelegate.contact_id!=nil)
  8335. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8336. if(appDelegate.password!=nil)
  8337. [params setValue:appDelegate.password forKey:@"password"];
  8338. [params setValue:watchlist_id forKey:@"item_id"];
  8339. // if(notes.length>0)
  8340. // [params setValue:notes forKey:@"notes"];
  8341. if(notes)
  8342. [params setValue:notes forKey:@"notes"];
  8343. if(price != -MAXFLOAT)
  8344. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  8345. if (discount != -MAXFLOAT)
  8346. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  8347. if(qty_p != -MAXFLOAT)
  8348. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  8349. if(qty != -INT32_MAX)
  8350. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  8351. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  8352. // NSData* json = nil;
  8353. if(appDelegate.offline_mode)
  8354. {
  8355. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8356. NSData* json = [[OLDataProvider offline_editPortfolio:params] mutableCopy];
  8357. dispatch_async(dispatch_get_main_queue(), ^{
  8358. result([[RAConvertor data2dict:json] mutableCopy]);
  8359. });
  8360. });
  8361. return;
  8362. }
  8363. [self request_interface:URL_PORTFOLIO_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8364. //
  8365. // if(appDelegate.offline_mode)
  8366. // {
  8367. // json = [OLDataProvider offline_editPortfolio:params];
  8368. // } else {
  8369. // if(![self IsNetworkAvailable])
  8370. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8371. //
  8372. // json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  8373. // }
  8374. // if(json==nil)
  8375. // return nil;
  8376. // NSError *error=nil;
  8377. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8378. // return jsobj;
  8379. }
  8380. +(void)request_add_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8381. {
  8382. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8383. AppDelegate *appDelegate = nil;
  8384. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8385. if(appDelegate.user!=nil)
  8386. [params setValue:appDelegate.user forKey:@"user"];
  8387. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  8388. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8389. // else
  8390. if(appDelegate.contact_id!=nil)
  8391. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8392. if(appDelegate.password!=nil)
  8393. [params setValue:appDelegate.password forKey:@"password"];
  8394. // NSDictionary* customerinfo=nil;
  8395. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  8396. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8397. // else
  8398. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8399. //
  8400. // appDelegate.customerInfo;
  8401. // NSArray* keys=[customerinfo allKeys];
  8402. // for(int i=0;i<keys.count;i++)
  8403. // {
  8404. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8405. // }
  8406. // [params setValue:sourceid forKey:@"sourceid"];
  8407. // [params setValue:editor forKey:@"editor"];
  8408. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  8409. if(appDelegate.offline_mode)
  8410. {
  8411. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8412. NSData* json = [[OLDataProvider offline_saveNewContact:params] mutableCopy];
  8413. dispatch_async(dispatch_get_main_queue(), ^{
  8414. result([[RAConvertor data2dict:json] mutableCopy]);
  8415. });
  8416. });
  8417. return;
  8418. }
  8419. [self request_interface:URL_CUSTOMER_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  8420. //
  8421. // NSData* json=nil;
  8422. // if(appDelegate.offline_mode)
  8423. // {
  8424. // json= [OLDataProvider offline_saveNewContact:params];
  8425. // }
  8426. // else
  8427. // {
  8428. // if(![self IsNetworkAvailable])
  8429. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8430. //
  8431. // json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  8432. // }
  8433. //
  8434. // if(json!=nil)
  8435. // {
  8436. // NSError *error=nil;
  8437. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8438. // return jsobj;
  8439. // }
  8440. // else
  8441. // return nil;
  8442. }
  8443. +(void)request_update_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8444. {
  8445. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8446. AppDelegate *appDelegate = nil;
  8447. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8448. if(appDelegate.user!=nil)
  8449. [params setValue:appDelegate.user forKey:@"user"];
  8450. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  8451. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8452. // else
  8453. if(appDelegate.contact_id!=nil)
  8454. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8455. if(appDelegate.password!=nil)
  8456. [params setValue:appDelegate.password forKey:@"password"];
  8457. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8458. if(appDelegate.offline_mode)
  8459. {
  8460. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8461. NSData* json = [[OLDataProvider offline_saveContact:params] mutableCopy];
  8462. dispatch_async(dispatch_get_main_queue(), ^{
  8463. result([[RAConvertor data2dict:json] mutableCopy]);
  8464. });
  8465. });
  8466. return;
  8467. }
  8468. [self request_interface:URL_CUSTOMER_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  8469. //
  8470. // NSData* json=nil;
  8471. // if(appDelegate.offline_mode)
  8472. // {
  8473. // json= [OLDataProvider offline_saveContact:params];
  8474. // }
  8475. // else
  8476. // {
  8477. // if(![self IsNetworkAvailable])
  8478. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8479. //
  8480. // json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  8481. // }
  8482. //
  8483. // if(json!=nil)
  8484. // {
  8485. // NSError *error=nil;
  8486. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8487. // return jsobj;
  8488. // }
  8489. // else
  8490. // return nil;
  8491. }
  8492. +(void)request_delete_order:(NSString*) order_id completionHandler:(resultHandler)result
  8493. {
  8494. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8495. AppDelegate *appDelegate = nil;
  8496. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8497. if(appDelegate.user!=nil)
  8498. [params setValue:appDelegate.user forKey:@"user"];
  8499. // if(appDelegate.contact_id!=nil)
  8500. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8501. if(appDelegate.password!=nil)
  8502. [params setValue:appDelegate.password forKey:@"password"];
  8503. [params setValue:order_id forKey:@"orderId"];
  8504. // [params setValue:sourceid forKey:@"sourceid"];
  8505. // [params setValue:editor forKey:@"editor"];
  8506. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8507. if(appDelegate.offline_mode)
  8508. {
  8509. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8510. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8511. dispatch_async(dispatch_get_main_queue(), ^{
  8512. result(json);
  8513. });
  8514. });
  8515. return;
  8516. }
  8517. [self request_interface:URL_DELETE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8518. //
  8519. // if(appDelegate.offline_mode)
  8520. // {
  8521. // return [OLDataProvider offline_notimpl];
  8522. // }
  8523. // if(![self IsNetworkAvailable])
  8524. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8525. //
  8526. // NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  8527. // if(json!=nil)
  8528. // {
  8529. // NSError *error=nil;
  8530. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8531. //
  8532. //
  8533. // return jsobj;
  8534. // }
  8535. // else
  8536. // return nil;
  8537. }
  8538. +(void)request_cancel_order:(NSString*) order_id order_code:(NSString*) order_code completionHandler:(resultHandler)result
  8539. {
  8540. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8541. AppDelegate *appDelegate = nil;
  8542. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8543. if(appDelegate.user!=nil)
  8544. [params setValue:appDelegate.user forKey:@"user"];
  8545. // if(appDelegate.contact_id!=nil)
  8546. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8547. if(appDelegate.password!=nil)
  8548. [params setValue:appDelegate.password forKey:@"password"];
  8549. [params setValue:order_id forKey:@"orderId"];
  8550. [params setValue:order_code forKey:@"orderCode"];
  8551. // [params setValue:sourceid forKey:@"sourceid"];
  8552. // [params setValue:editor forKey:@"editor"];
  8553. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8554. if(appDelegate.offline_mode)
  8555. {
  8556. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8557. NSData* json = [[OLDataProvider offline_cancelorder:params] mutableCopy];
  8558. dispatch_async(dispatch_get_main_queue(), ^{
  8559. result([[RAConvertor data2dict:json] mutableCopy]);
  8560. });
  8561. });
  8562. return;
  8563. }
  8564. [self request_interface:URL_CANCEL_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8565. //
  8566. // NSData* json=nil;
  8567. // if(appDelegate.offline_mode)
  8568. // {
  8569. // json=[OLDataProvider offline_cancelorder:params];
  8570. // }
  8571. // else
  8572. // {
  8573. // if(![self IsNetworkAvailable])
  8574. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8575. // json=[self get_json:URL_CANCEL_ORDER parameters:params];
  8576. // }
  8577. // if(json!=nil)
  8578. // {
  8579. // NSError *error=nil;
  8580. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8581. //
  8582. //
  8583. // return jsobj;
  8584. // }
  8585. // else
  8586. // return nil;
  8587. }
  8588. +(void)request_release_order:(NSString*) order_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  8589. {
  8590. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8591. AppDelegate *appDelegate = nil;
  8592. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8593. if(appDelegate.user!=nil)
  8594. [params setValue:appDelegate.user forKey:@"user"];
  8595. // if(appDelegate.contact_id!=nil)
  8596. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8597. if(appDelegate.password!=nil)
  8598. [params setValue:appDelegate.password forKey:@"password"];
  8599. [params setValue:order_code forKey:@"orderCode"];
  8600. // [params setValue:sourceid forKey:@"sourceid"];
  8601. // [params setValue:editor forKey:@"editor"];
  8602. if (screenName) {
  8603. [params setValue:screenName forKey:kScreenName];
  8604. }
  8605. if(appDelegate.offline_mode)
  8606. {
  8607. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8608. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_resetorder:params]] mutableCopy];
  8609. dispatch_async(dispatch_get_main_queue(), ^{
  8610. if([[resulti valueForKey:@"result"]intValue]==2)
  8611. { [appDelegate SetSo:nil];
  8612. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8613. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8614. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8615. [appDelegate update_count_mark];
  8616. dispatch_async(dispatch_get_main_queue(), ^{
  8617. result(resulti);
  8618. });
  8619. }
  8620. });
  8621. });
  8622. return;
  8623. }
  8624. [self request_interface:URL_RELEASE_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8625. if([[resulti valueForKey:@"result"]intValue]==2)
  8626. { [appDelegate SetSo:nil];
  8627. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8628. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8629. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8630. [appDelegate update_count_mark];
  8631. dispatch_async(dispatch_get_main_queue(), ^{
  8632. result(resulti);
  8633. });
  8634. }
  8635. } retry:0];
  8636. //
  8637. // NSData* json=nil;
  8638. // if(appDelegate.offline_mode)
  8639. // {
  8640. // json= [OLDataProvider offline_resetorder:params];
  8641. // }
  8642. // else
  8643. // {
  8644. // if(![self IsNetworkAvailable])
  8645. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8646. //
  8647. // json=[self get_json:URL_RELEASE_ORDER parameters:params];
  8648. // }
  8649. // if(json!=nil)
  8650. // {
  8651. // NSError *error=nil;
  8652. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8653. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8654. // { [appDelegate SetSo:nil];
  8655. //
  8656. //
  8657. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8658. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8659. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8660. //
  8661. // [appDelegate update_count_mark];
  8662. // }
  8663. // return jsobj;
  8664. // }
  8665. // else
  8666. // return nil;
  8667. }
  8668. +(void)request_update_order_signature:(NSString*) order_code path:(NSString*)path completionHandler:(resultHandler)result
  8669. {
  8670. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8671. AppDelegate *appDelegate = nil;
  8672. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8673. if(appDelegate.user!=nil)
  8674. [params setValue:appDelegate.user forKey:@"user"];
  8675. if(appDelegate.contact_id!=nil)
  8676. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8677. if(appDelegate.password!=nil)
  8678. [params setValue:appDelegate.password forKey:@"password"];
  8679. // NSString* ssaved = @"false";
  8680. // if(saved)
  8681. // ssaved=@"true";
  8682. // [params setValue:@"true" forKey:@"saved"];
  8683. [params setValue:order_code forKey:@"orderCode"];
  8684. [params setValue:path forKey:@"picpath"];
  8685. // [params setValue:sourceid forKey:@"sourceid"];
  8686. // [params setValue:editor forKey:@"editor"];
  8687. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  8688. if(appDelegate.offline_mode)
  8689. {
  8690. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8691. NSData* json = [[OLDataProvider offline_signorder:params] mutableCopy];
  8692. dispatch_async(dispatch_get_main_queue(), ^{
  8693. result([[RAConvertor data2dict:json] mutableCopy]);
  8694. });
  8695. });
  8696. return;
  8697. }
  8698. [self request_interface:URL_SIGN_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8699. //
  8700. // NSData* json=nil;
  8701. // if(appDelegate.offline_mode)
  8702. // {
  8703. // json= [OLDataProvider offline_signorder:params];
  8704. // }
  8705. // else
  8706. // {
  8707. // if(![self IsNetworkAvailable])
  8708. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8709. //
  8710. // json=[self get_json:URL_SIGN_ORDER parameters:params];
  8711. // }
  8712. // if(json!=nil)
  8713. // {
  8714. // NSError *error=nil;
  8715. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8716. // return jsobj;
  8717. // }
  8718. // else
  8719. // return nil;
  8720. }
  8721. +(void) request_update_cart_modelprice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8722. {
  8723. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8724. AppDelegate *appDelegate = nil;
  8725. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8726. #ifdef SCANNER_ORDER
  8727. return;
  8728. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  8729. {
  8730. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  8731. //
  8732. //
  8733. // [appDelegate update_count_mark];
  8734. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  8735. int count = [section[@"count"] intValue];
  8736. for(int i=0;i<count;i++)
  8737. {
  8738. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  8739. if([item[@"cart_item_id"] isEqualToString:cart_id])
  8740. {
  8741. int item_count = [item[@"count"] intValue];
  8742. item[@"unit_price"] =@(price);
  8743. item[@"discount"] =@(discount);
  8744. item[@"subtotal_price"] =@(price*item_count);
  8745. item[@"note"] =@"PRICE MODIFIED";
  8746. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  8747. break;
  8748. }
  8749. }
  8750. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  8751. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  8752. result(RASingleton.sharedInstance.scan_cart);
  8753. return;
  8754. }
  8755. #endif
  8756. if(appDelegate.user!=nil)
  8757. [params setValue:appDelegate.user forKey:@"user"];
  8758. if(appDelegate.contact_id!=nil)
  8759. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8760. if(appDelegate.password!=nil)
  8761. [params setValue:appDelegate.password forKey:@"password"];
  8762. [params setValue:cart_id forKey:@"cartitem_id"];
  8763. [params setValue:notes forKey:@"item_note"];
  8764. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  8765. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  8766. [params setObject:ScreenCodeCart forKey:kScreenName];
  8767. if(appDelegate.offline_mode)
  8768. {
  8769. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8770. NSData* json = [[OLDataProvider offline_cartsetprice:params] mutableCopy];
  8771. dispatch_async(dispatch_get_main_queue(), ^{
  8772. result([[RAConvertor data2dict:json] mutableCopy]);
  8773. });
  8774. });
  8775. return;
  8776. }
  8777. [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8778. //
  8779. // NSData* json= nil;
  8780. // if(appDelegate.offline_mode)
  8781. // {
  8782. // json=[OLDataProvider offline_cartsetprice:params];
  8783. // }
  8784. // else
  8785. // {
  8786. // if(![self IsNetworkAvailable])
  8787. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8788. //
  8789. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8790. // }
  8791. // if(json==nil)
  8792. // return nil;
  8793. // NSError *error=nil;
  8794. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8795. // return jsobj;
  8796. }
  8797. +(void) request_addto_cart:(NSString* ) item_id count:(int) count name:(NSString *)name completionHandler:(resultHandler)result
  8798. {
  8799. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8800. AppDelegate *appDelegate = nil;
  8801. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8802. if(appDelegate.user!=nil)
  8803. [params setValue:appDelegate.user forKey:@"user"];
  8804. if(appDelegate.contact_id!=nil)
  8805. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8806. if(appDelegate.password!=nil)
  8807. [params setValue:appDelegate.password forKey:@"password"];
  8808. if(appDelegate.order_code!=nil)
  8809. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8810. [params setValue:item_id forKey:@"product_id"];
  8811. [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  8812. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  8813. [params setObject:@"Add To Cart" forKey:kAction];
  8814. if (name) {
  8815. NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  8816. [params setObject:extra forKey:kExtra];
  8817. }
  8818. NSDictionary* customerinfo= appDelegate.customerInfo;
  8819. NSArray* keys=[customerinfo allKeys];
  8820. for(int i=0;i<keys.count;i++)
  8821. {
  8822. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8823. }
  8824. if(appDelegate.offline_mode)
  8825. {
  8826. // [OLDataProvider offline_add2cart:params completionHandler:^(NSMutableDictionary *resulti) {
  8827. // NSMutableDictionary* json = resulti;
  8828. // if ([json[@"result"] intValue]==2)
  8829. // {
  8830. // appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  8831. //
  8832. // [appDelegate update_count_mark];
  8833. // }
  8834. // result(json);
  8835. // }];
  8836. params[@"can_create_backorder"]= @(appDelegate.can_create_backorder);
  8837. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8838. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cart:params]] mutableCopy];
  8839. dispatch_async(dispatch_get_main_queue(), ^{
  8840. if ([json[@"result"] intValue]==2)
  8841. {
  8842. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  8843. [appDelegate update_count_mark];
  8844. }
  8845. result(json);
  8846. });
  8847. });
  8848. return;
  8849. }
  8850. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8851. if ([resulti[@"result"] intValue]==2)
  8852. {
  8853. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8854. [appDelegate update_count_mark];
  8855. }
  8856. result(resulti);
  8857. } retry:0];
  8858. //
  8859. // NSData* json=nil;
  8860. // if(appDelegate.offline_mode)
  8861. // {
  8862. // json=[OLDataProvider offline_add2cart:params];
  8863. // }
  8864. // else
  8865. // {
  8866. // if(![self IsNetworkAvailable])
  8867. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8868. //
  8869. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  8870. // }
  8871. // if(json==nil)
  8872. // return nil;
  8873. // NSError *error=nil;
  8874. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8875. //
  8876. //
  8877. //
  8878. // int result = [[jsobj valueForKey:@"result"] intValue];
  8879. //
  8880. // if (result==2)
  8881. // {
  8882. //
  8883. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8884. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8885. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8886. //
  8887. // [appDelegate update_count_mark];
  8888. // }
  8889. //
  8890. // return jsobj;
  8891. }
  8892. //+(void) request_update_cart_modelfree:(NSString*) cart_id isfree:(bool) isfree completionHandler:(resultHandler)result
  8893. //{
  8894. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8895. // AppDelegate *appDelegate = nil;
  8896. //
  8897. //
  8898. //
  8899. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8900. //
  8901. // if(appDelegate.user!=nil)
  8902. // [params setValue:appDelegate.user forKey:@"user"];
  8903. // if(appDelegate.contact_id!=nil)
  8904. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8905. // if(appDelegate.password!=nil)
  8906. // [params setValue:appDelegate.password forKey:@"password"];
  8907. //
  8908. // [params setValue:cart_id forKey:@"cartitem_id"];
  8909. //
  8910. // [params setObject:ScreenCodeCart forKey:kScreenName];
  8911. //
  8912. // NSString* free=nil;
  8913. //
  8914. // if(isfree)
  8915. // free=@"true";
  8916. // else
  8917. // free=@"false";
  8918. //
  8919. // [params setValue:free forKey:@"free_giveaway"];
  8920. //
  8921. //
  8922. // if(appDelegate.offline_mode)
  8923. // {
  8924. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8925. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8926. // dispatch_async(dispatch_get_main_queue(), ^{
  8927. // result(json);
  8928. // });
  8929. // });
  8930. //
  8931. // return;
  8932. //
  8933. // }
  8934. // [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8935. //
  8936. ////
  8937. ////
  8938. //// if(appDelegate.offline_mode)
  8939. //// {
  8940. //// return [OLDataProvider offline_notimpl];
  8941. //// }
  8942. //// if(![self IsNetworkAvailable])
  8943. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8944. ////
  8945. //// NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8946. //// if(json==nil)
  8947. //// return nil;
  8948. //// NSError *error=nil;
  8949. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8950. //// return jsobj;
  8951. //}
  8952. +(void)request_retrieve_password: (NSString*) user email:(NSString*) email completionHandler:(resultHandler)result
  8953. {
  8954. AppDelegate *appDelegate = nil;
  8955. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8956. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8957. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8958. // if(appDelegate.user!=nil)
  8959. // [params setValue:appDelegate.user forKey:@"user"];
  8960. // if(appDelegate.contact_id!=nil)
  8961. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8962. // if(appDelegate.password!=nil)
  8963. // [params setValue:appDelegate.password forKey:@"password"];
  8964. [params setValue:user forKey:@"username"];
  8965. [params setValue:email forKey:@"email"];
  8966. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  8967. if(appDelegate.offline_mode)
  8968. {
  8969. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8970. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8971. dispatch_async(dispatch_get_main_queue(), ^{
  8972. result(json);
  8973. });
  8974. });
  8975. return;
  8976. }
  8977. #ifdef SCANNER_ORDER
  8978. params[@"site_name"]=[RADataProvider getSiteName];
  8979. params[@"_method"]=@"forgotPasswordOfflineOrderUser";
  8980. params[@"user"]=user;
  8981. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_RETRIEVE_PASS];
  8982. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  8983. #else
  8984. [self request_interface:URL_RETRIEVE_PASS parameters:params err_record_url:nil completionHandler:result retry:0];
  8985. #endif
  8986. //
  8987. //
  8988. // if(![self IsNetworkAvailable])
  8989. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8990. //
  8991. // NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  8992. // if(json==nil)
  8993. // return nil;
  8994. // NSError *error=nil;
  8995. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8996. // return jsobj;
  8997. }
  8998. +(void)request_update_ordercustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info completionHandler:(resultHandler)result
  8999. {
  9000. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9001. AppDelegate *appDelegate = nil;
  9002. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9003. if(appDelegate.user!=nil)
  9004. [info setValue:appDelegate.user forKey:@"user"];
  9005. // if(appDelegate.contact_id!=nil)
  9006. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9007. if(appDelegate.password!=nil)
  9008. [info setValue:appDelegate.password forKey:@"password"];
  9009. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  9010. [info setValue:order_code forKey:@"orderCode"];
  9011. // [params setValue:sourceid forKey:@"sourceid"];
  9012. // [params setValue:editor forKey:@"editor"];
  9013. if(appDelegate.offline_mode)
  9014. {
  9015. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9016. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9017. dispatch_async(dispatch_get_main_queue(), ^{
  9018. result(json);
  9019. });
  9020. });
  9021. return;
  9022. }
  9023. [self request_interface:URL_UPDATE_ORDERCUSTOMER parameters:info err_record_url:nil completionHandler:result retry:0];
  9024. // if(appDelegate.offline_mode)
  9025. // {
  9026. // return [OLDataProvider offline_notimpl];
  9027. // }
  9028. // if(![self IsNetworkAvailable])
  9029. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9030. //
  9031. // NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  9032. // if(json!=nil)
  9033. // {
  9034. // NSError *error=nil;
  9035. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9036. // return jsobj;
  9037. // }
  9038. // else
  9039. // return nil;
  9040. }
  9041. +(void)request_update_customer_img: (NSString*) contactid img_url:(NSString*) url completionHandler:(resultHandler)result
  9042. {
  9043. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9044. AppDelegate *appDelegate = nil;
  9045. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9046. if(appDelegate.user!=nil)
  9047. [params setValue:appDelegate.user forKey:@"user"];
  9048. // if(appDelegate.contact_id!=nil)
  9049. if(appDelegate.password!=nil)
  9050. [params setValue:appDelegate.password forKey:@"password"];
  9051. [params setValue:contactid forKey:@"contactId"];
  9052. [params setValue:url forKey:@"business_card"];
  9053. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  9054. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  9055. if(appDelegate.offline_mode)
  9056. {
  9057. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9058. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9059. dispatch_async(dispatch_get_main_queue(), ^{
  9060. result(json);
  9061. });
  9062. });
  9063. return;
  9064. }
  9065. [self request_interface:URL_UPDATE_CUSTOMER_BCARD parameters:params err_record_url:nil completionHandler:result retry:0];
  9066. // if(appDelegate.offline_mode)
  9067. // {
  9068. // return [OLDataProvider offline_notimpl];
  9069. // }
  9070. // if(![self IsNetworkAvailable])
  9071. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9072. //
  9073. // NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  9074. // if(json==nil)
  9075. // return nil;
  9076. // NSError *error=nil;
  9077. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9078. // return jsobj;
  9079. }
  9080. +(void)request_commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url completionHandler:(resultHandler)result
  9081. {
  9082. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9083. AppDelegate *appDelegate = nil;
  9084. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9085. if(appDelegate.user!=nil)
  9086. [params setValue:appDelegate.user forKey:@"user"];
  9087. if(appDelegate.contact_id!=nil)
  9088. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9089. if(appDelegate.password!=nil)
  9090. [params setValue:appDelegate.password forKey:@"password"];
  9091. // if(appDelegate.order_code!=nil)
  9092. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  9093. // NSDictionary* customerinfo= appDelegate.customerInfo;
  9094. //
  9095. // NSArray* keys=[customerinfo allKeys];
  9096. // for(int i=0;i<keys.count;i++)
  9097. // {
  9098. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  9099. // }
  9100. //
  9101. // [params setValue:sourceid forKey:@"sourceid"];
  9102. // [params setValue:editor forKey:@"editor"];
  9103. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  9104. if(appDelegate.offline_mode)
  9105. {
  9106. params[@"offline_Command"]=url;
  9107. [OLDataProvider offline_commoneditor_partialrefresh:params completionHandler:result];
  9108. //
  9109. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9110. // NSMutableDictionary* json = [[OLDataProvider offline_commoneditor_partialrefresh:params] mutableCopy];
  9111. // dispatch_async(dispatch_get_main_queue(), ^{
  9112. // result(json);
  9113. // });
  9114. // });
  9115. return;
  9116. }
  9117. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  9118. //
  9119. // if(appDelegate.offline_mode)
  9120. // {
  9121. // params[@"offline_Command"]=url;
  9122. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  9123. // }
  9124. //
  9125. // if(![self IsNetworkAvailable])
  9126. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9127. //
  9128. // NSData* json=[self get_json:url parameters:params];
  9129. // if(json!=nil)
  9130. // {
  9131. // NSError *error=nil;
  9132. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9133. // if([[jsobj valueForKey:@"result"]intValue]==2)
  9134. // [appDelegate SetSo:nil];
  9135. //
  9136. //
  9137. // return jsobj;
  9138. // }
  9139. // else
  9140. // return nil;
  9141. }
  9142. +(void)request_add_address:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  9143. {
  9144. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9145. AppDelegate *appDelegate = nil;
  9146. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9147. if(appDelegate.user!=nil)
  9148. [params setValue:appDelegate.user forKey:@"user"];
  9149. if(appDelegate.contact_id!=nil)
  9150. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9151. if(appDelegate.password!=nil)
  9152. [params setValue:appDelegate.password forKey:@"password"];
  9153. // [params setValue:sourceid forKey:@"sourceid"];
  9154. // [params setValue:editor forKey:@"editor"];
  9155. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  9156. if(appDelegate.offline_mode)
  9157. {
  9158. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9159. NSData* json = [[OLDataProvider offline_saveaddr:params] mutableCopy];
  9160. dispatch_async(dispatch_get_main_queue(), ^{
  9161. result([[RAConvertor data2dict:json] mutableCopy]);
  9162. });
  9163. });
  9164. return;
  9165. }
  9166. [self request_interface:URL_ADDRESS_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  9167. //
  9168. // NSData* json=nil;
  9169. //
  9170. // if(appDelegate.offline_mode)
  9171. // {
  9172. // json= [OLDataProvider offline_saveaddr:params];
  9173. // }
  9174. // else
  9175. // {
  9176. // if(![self IsNetworkAvailable])
  9177. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9178. //
  9179. // json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  9180. // }
  9181. // if(json!=nil)
  9182. // {
  9183. // NSError *error=nil;
  9184. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9185. // return jsobj;
  9186. // }
  9187. // else
  9188. // return nil;
  9189. }
  9190. +(void)request_commit_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  9191. {
  9192. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9193. AppDelegate *appDelegate = nil;
  9194. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9195. if(appDelegate.user!=nil)
  9196. [params setValue:appDelegate.user forKey:@"user"];
  9197. if(appDelegate.contact_id!=nil)
  9198. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9199. if(appDelegate.password!=nil)
  9200. [params setValue:appDelegate.password forKey:@"password"];
  9201. if(appDelegate.order_code!=nil)
  9202. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  9203. // NSDictionary* customerinfo= appDelegate.customerInfo;
  9204. //
  9205. // NSArray* keys=[customerinfo allKeys];
  9206. // for(int i=0;i<keys.count;i++)
  9207. // {
  9208. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  9209. // }
  9210. //
  9211. // [params setValue:sourceid forKey:@"sourceid"];
  9212. // [params setValue:editor forKey:@"editor"];
  9213. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  9214. if(appDelegate.offline_mode)
  9215. {
  9216. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9217. NSData* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  9218. dispatch_async(dispatch_get_main_queue(), ^{
  9219. result([[RAConvertor data2dict:json] mutableCopy]);
  9220. });
  9221. });
  9222. return;
  9223. }
  9224. [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  9225. //
  9226. // NSData* json=nil;
  9227. // if(appDelegate.offline_mode)
  9228. // {
  9229. // json=[OLDataProvider offline_submitorder:params];
  9230. // }
  9231. // else
  9232. // {
  9233. // if(![self IsNetworkAvailable])
  9234. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9235. //
  9236. // json=[self get_json:URL_COMMIT_ORDER parameters:params];
  9237. // }
  9238. // if(json!=nil)
  9239. // {
  9240. // NSError *error=nil;
  9241. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9242. // if([[jsobj valueForKey:@"result"]intValue]==2)
  9243. // [appDelegate SetSo:nil];
  9244. //
  9245. //
  9246. // return jsobj;
  9247. // }
  9248. // else
  9249. // return nil;
  9250. }
  9251. +(void) request_new_offline_ticket:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid completionHandler:(resultHandler)result
  9252. {
  9253. // if(![self IsNetworkAvailable])
  9254. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9255. //
  9256. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9257. AppDelegate *appDelegate = nil;
  9258. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9259. if(appDelegate.user!=nil)
  9260. [params setValue:appDelegate.user forKey:@"user"];
  9261. // if(appDelegate.contact_id!=nil)
  9262. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9263. if(appDelegate.password!=nil)
  9264. [params setValue:appDelegate.password forKey:@"password"];
  9265. [params setValue:ver forKey:@"ver"];
  9266. [params setValue:vid forKey:@"vid"];
  9267. if(buseinternaladdress)
  9268. [params setValue:@"true" forKey:@"internal_address"];
  9269. else
  9270. [params setValue:@"false" forKey:@"internal_address"];
  9271. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  9272. // 无论当前是离线还是在线状态,都可以进行同步;
  9273. // if(appDelegate.offline_mode)
  9274. // {
  9275. //
  9276. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9277. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9278. // dispatch_async(dispatch_get_main_queue(), ^{
  9279. // result(json);
  9280. // });
  9281. // });
  9282. //
  9283. // return;
  9284. //
  9285. // }
  9286. [self request_interface:URL_CHECK_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  9287. //
  9288. // NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  9289. // if(json==nil)
  9290. // return nil;
  9291. // NSError *error=nil;
  9292. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9293. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9294. // //
  9295. // // if (result==2)
  9296. // // {
  9297. // //
  9298. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9299. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9300. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9301. // ////
  9302. // //// [appDelegate update_count_mark];
  9303. // // }
  9304. // return jsobj;
  9305. }
  9306. +(void) request_complete_offline_ticket:(NSString* )vid completionHandler:(resultHandler)result
  9307. {
  9308. AppDelegate *appDelegate = nil;
  9309. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9310. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9311. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  9312. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  9313. // if(appDelegate.user!=nil)
  9314. // [params setValue:appDelegate.user forKey:@"user"];
  9315. // // if(appDelegate.contact_id!=nil)
  9316. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9317. // if(appDelegate.password!=nil)
  9318. // [params setValue:appDelegate.password forKey:@"password"];
  9319. [params setValue:vid forKey:@"downSerial"];
  9320. // 无论当前是离线还是在线状态,都可以进行同步;
  9321. // if(appDelegate.offline_mode)
  9322. // {
  9323. //
  9324. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9325. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9326. // dispatch_async(dispatch_get_main_queue(), ^{
  9327. // result(json);
  9328. // });
  9329. // });
  9330. //
  9331. // return;
  9332. //
  9333. // }
  9334. [self request_interface:URL_FINISH_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  9335. // NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  9336. // if(json==nil)
  9337. // return nil;
  9338. // NSError *error=nil;
  9339. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9340. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9341. // //
  9342. // // if (result==2)
  9343. // // {
  9344. // //
  9345. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9346. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9347. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9348. // ////
  9349. // //// [appDelegate update_count_mark];
  9350. // // }
  9351. // return jsobj;
  9352. }
  9353. +(void) request_download_offline:(NSString* )vid completionHandler:(resultHandler)result
  9354. {
  9355. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9356. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  9357. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  9358. // if(appDelegate.user!=nil)
  9359. // [params setValue:appDelegate.user forKey:@"user"];
  9360. // // if(appDelegate.contact_id!=nil)
  9361. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9362. // if(appDelegate.password!=nil)
  9363. // [params setValue:appDelegate.password forKey:@"password"];
  9364. [params setValue:vid forKey:@"downSerial"];
  9365. // AppDelegate *appDelegate = nil;
  9366. //
  9367. //
  9368. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9369. // if(appDelegate.offline_mode)
  9370. // {
  9371. //
  9372. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9373. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9374. // dispatch_async(dispatch_get_main_queue(), ^{
  9375. // result(json);
  9376. // });
  9377. // });
  9378. //
  9379. // return;
  9380. //
  9381. // }
  9382. __block bool bbreak = false;
  9383. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9384. __block NSMutableDictionary* download_json=nil;
  9385. int count=0;
  9386. // __block bool preparing = true;
  9387. while ([[download_json valueForKey:@"result"] intValue]!=2&&count<REQUEST_DOWNLOAD_RETRY_TIMES) //超过60分钟还没准被好数据就视为服务器出错。
  9388. {
  9389. if(bbreak)
  9390. break;
  9391. dispatch_async(dispatch_get_main_queue(), ^{
  9392. [self request_interface:URL_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  9393. if([resulti[@"result"] intValue]==RESULT_TRUE)
  9394. {
  9395. if(!bbreak) //此判断保证result只调用一次。
  9396. {
  9397. // appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  9398. // [appDelegate update_count_mark];
  9399. resulti[@"request_count"]=[NSNumber numberWithInt:count];
  9400. result(resulti);
  9401. }
  9402. bbreak=true;
  9403. }
  9404. else if([resulti[@"result"] intValue]==RESULT_ERROR)
  9405. {
  9406. result(resulti);
  9407. bbreak=true;
  9408. }
  9409. } retry:3];
  9410. });
  9411. sleep(RETRY_DELAY);
  9412. count++;
  9413. // download_json=[[RANetwork download_Offline:downSerial] mutableCopy];
  9414. //
  9415. // [RANetwork request_download_offline:downSerial completionHandler:^(NSMutableDictionary *result) {
  9416. // download_json=result;
  9417. // }];
  9418. //
  9419. }
  9420. // for(int i=0;i<150;i++)
  9421. // {
  9422. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  9423. // // result_params[@"resultSerial"]=uuid;
  9424. //
  9425. //
  9426. //
  9427. // sleep(2);
  9428. //
  9429. // // json=[self get_json:URL_CART parameters:params];
  9430. // // if(json!=nil)
  9431. // // {
  9432. // //
  9433. // // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9434. // // if([jsobj[@"result"] intValue]==2)
  9435. // // {
  9436. // // break;
  9437. // // }
  9438. // // }
  9439. //
  9440. // }
  9441. });
  9442. //
  9443. // NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  9444. // if(json==nil)
  9445. // return nil;
  9446. // NSError *error=nil;
  9447. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9448. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9449. // //
  9450. // // if (result==2)
  9451. // // {
  9452. // //
  9453. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9454. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9455. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9456. // ////
  9457. // //// [appDelegate update_count_mark];
  9458. // // }
  9459. // return jsobj;
  9460. }
  9461. + (void)request_fastupload:(NSMutableDictionary *)params filename:(NSString*)filename data:(NSData*) data url:(NSString *)url completionHandler:(resultHandler)result
  9462. {
  9463. //#ifdef test_server
  9464. // url=URL_REQUEST_RECORDS;
  9465. // params[@"prefix"]=URL_REQUEST_RECORDS;
  9466. //#endif
  9467. // [self request_file_fast:url parameters:params completionHandler:result];
  9468. #ifdef SCANNER_ORDER
  9469. params[@"site_name"]=[RADataProvider getSiteName];
  9470. #endif
  9471. [self request_upload_fast:data FileName:filename server:url parameters:params completionHandler:result];
  9472. }
  9473. +(void)request_err_log:(NSString*) up_params result:(NSString*)result_str module:(NSString*) module code:(int) code completionHandler:(resultHandler)result
  9474. {
  9475. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9476. AppDelegate *appDelegate = nil;
  9477. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9478. if(appDelegate.user!=nil)
  9479. [params setValue:appDelegate.user forKey:@"user"];
  9480. [params setValue:up_params forKey:@"upparam"];
  9481. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  9482. [params setValue:result_str forKey:@"result"];
  9483. [params setValue:module forKey:@"interfac"];
  9484. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  9485. // [params setValue:module forKey:@"module"];
  9486. // [[UIDevice currentDevice] name];
  9487. // if(appDelegate.offline_mode)
  9488. // {
  9489. // return [OLDataProvider offline_notimpl];
  9490. // }
  9491. if(appDelegate.offline_mode)
  9492. {
  9493. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9494. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9495. dispatch_async(dispatch_get_main_queue(), ^{
  9496. result(json);
  9497. });
  9498. });
  9499. return;
  9500. }
  9501. [self request_interface:URL_ERR_LOG parameters:params err_record_url:nil completionHandler:result retry:0];
  9502. //
  9503. // if(![self IsNetworkAvailable])
  9504. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9505. //
  9506. // NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  9507. // if(json==nil)
  9508. // return nil;
  9509. // NSError *error=nil;
  9510. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9511. // return jsobj;
  9512. }
  9513. @end