RANetwork.m 395 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947
  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. #ifdef GOOGLE_ANALYTICS
  12. #import "GoogleAnalyst.h"
  13. #endif
  14. #import "ERPUtils.h"
  15. #import "RAConvertor.h"
  16. #import "ActiveViewController.h"
  17. #import "ZipArchive.h"
  18. #import "RADataProvider.h"
  19. NSString *const kScreenName = @"kScreenName";
  20. NSString *const kAction = @"kAction";
  21. NSString *const kExtra = @"kExtra";
  22. NSString *const ScreenCodeLoginView = @"Login Screen";
  23. NSString *const ScreenCodeHomeView = @"Home Screen";
  24. NSString *const ScreenCodeCategory = @"Category Screen";
  25. NSString *const ScreenCodeCart = @"Cart Sceen";
  26. NSString *const ScreenCodeOrderList = @"Order History Screen";
  27. NSString *const ScreenCodeSearch = @"Search Screen";
  28. NSString *const ScreenCodeAccount = @"Account Screen";
  29. NSString *const ScreenCodeWishList = @"Wish List Screen";
  30. NSString *const ScreenCodePortfolio = @"Portfolio Screen";
  31. NSString *const ScreenCodeViewPortfolios = @"View Portfolios Screen";
  32. NSString *const ScreenCodeCamScan = @"Cam Scan Screen";
  33. NSString *const ScreenCodeScannerSetting = @"Scanner Setting Screen";
  34. NSString *const ScreenCodeOfflineSetting = @"Offline Setting Screen";
  35. NSString *const ScreenCodePlaceOrder = @"Place Order Screen";
  36. NSString *const ScreenCodeCustomerInfo = @"Customer Information Screen";
  37. NSString *const ScreenCodeNewCustomer = @"New Customer Screen";
  38. NSString *const ScreenCodeEditCustomer = @"Edit Customer Information Screen";
  39. NSString *const ScreenCodeModelInfo = @"Model Information Screen";
  40. NSString *const ScreenCodeOrderInfo = @"Order Information Screeen";
  41. NSString *const ScreenCodeUserSign = @"User Sign Screen";
  42. NSString *const ScreenCodeNewAddress = @"New Address Screen";
  43. NSString *const ScreenCodeAdvanceSearch = @"Account Advance Search Screen";
  44. NSString *const ScreenCodeCreatePortfolio = @"Create Portfolio Screen";
  45. NSString *const ScreenCodeParticularCategory = @"Particular Category Screen";
  46. NSString *const ScreenCodeEditPortfolio = @"Edit Portfolio Screen";
  47. NSString *const ScreenCodePriceSetting = @"Price Setting Screen";
  48. NSString *const ScreenCodeCategoryPrice = @"Category Price Screen";
  49. NSString *const ScreenCodeSetCatetoryPrice = @"Set Category Price Screen";
  50. NSString *const ScreenCodeUploadImage = @"Upload Image Screen";
  51. NSString *const ScreenCodeOfflineSync = @"Offline Sync Screen";
  52. @implementation RANetwork
  53. +(NSMutableDictionary*) prepare_additional_params:(NSMutableDictionary* ) params
  54. {
  55. AppDelegate *appDelegate = nil;
  56. //some UI methods ej
  57. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  58. // if(appDelegate.user!=nil)
  59. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.user key:@"usai"] forKey:@"user"];
  60. // if(appDelegate.password!=nil)
  61. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.password key:@"usai"] forKey:@"password"];
  62. //
  63. //
  64. //
  65. // if(appDelegate.user!=nil)
  66. // [params setValue:appDelegate.user forKey:@"user"];
  67. //
  68. // if(appDelegate.contact_id!=nil)
  69. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  70. // if(appDelegate.password!=nil)
  71. // [params setValue:appDelegate.password forKey:@"password"];
  72. //
  73. // [params setValue:appDelegate.build forKey:@"app_ver"];
  74. //
  75. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  76. // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  77. // [params setValue:short_version forKey:@"app_short_ver"];
  78. //
  79. //
  80. //
  81. //#if TARGET_IPHONE_SIMULATOR//模拟器
  82. // [params setValue:@"simulator_uuid" forKey:@"deviceid"];
  83. //#elif TARGET_OS_IPHONE//真机
  84. // UIDevice * dev = [UIDevice currentDevice];
  85. // NSUUID* uuid =dev.identifierForVendor;
  86. // [params setValue:uuid.UUIDString forKey:@"deviceid"];
  87. //#endif
  88. if(appDelegate.user!=nil && params[@"user"]==nil)
  89. [params setValue:appDelegate.user forKey:@"user"];
  90. if(appDelegate.password!=nil&& params[@"password"]==nil)
  91. [params setValue:appDelegate.password forKey:@"password"];
  92. if(appDelegate.ipad_perm!=nil)
  93. [params setValue:appDelegate.ipad_perm forKey:@"ipad_perm"];
  94. [params setValue:appDelegate.build forKey:@"app_ver"];
  95. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  96. NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  97. [params setValue:short_version forKey:@"app_short_ver"];
  98. #if TARGET_IPHONE_SIMULATOR//模拟器
  99. [params setValue:@"simulator_uuid" forKey:@"idfv"];
  100. #elif TARGET_OS_IPHONE//真机
  101. UIDevice * dev = [UIDevice currentDevice];
  102. NSUUID* uuid =dev.identifierForVendor;
  103. [params setValue:uuid.UUIDString forKey:@"idfv"];
  104. #endif
  105. //
  106. // NSString *userAction = [params valueForKey:kAction];
  107. // NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  108. // if ([userAction isEqualToString:@"Login"]) {
  109. // if (!extra) {
  110. // extra = [NSMutableDictionary dictionary];
  111. // }
  112. // [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  113. // }
  114. return params;
  115. }
  116. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString *) file //delegate:(id < NSURLConnectionDelegate >)delegate
  117. {
  118. // NSString* e=[AESCrypt AES128Encrypt:@"密码学中的高级加密标准(Advanced Encryption Standard,AES),又称 高级加密标准Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用。经过五年的甄选流程,高级加密标准由美国国家标准与技术研究院 (NIST)于2001年11月26日发布于FIPS PUB 197,并在2002年5月26日成为有效的标准。2006年,高级加密标准已然成为对称密钥加密中最流行的算法之一。 " key:@"usai2010"];
  119. // DebugLog(e);
  120. // NSString* d=[AESCrypt decrypt:@"VzB4+lENfbzWX7ggHh2Os1P69l5YBzKmM51yqA37AfoKgPY8bJgdK8M4WvF+wDyOsLWP\/o8H5+bHMivQp1u8wM2QV7SYzgzPwV85QKtYWIzEgLe9T0HO69EdutWz7k1rdAT\/mftsRin0Hy5SHk7txTZT\/zPH5X+FQiExCTFm5Zus39HYvp+VxCX4+kYeymn8B63AUd3mRQyscUvDjfgU2olKR\/TP8PV3g+VQMZxpKfol3P1iOtz3XQlHZV0pM6SAf+SwT0sPfrdn6CZFfNQlrKA9QjMrnBdMeSCquSIWXnmLv6okzvnlJnT0SjvJuUeqNdBC5EZ0ACnhI0MrXVZEsq1EuM9al7oPzvU5EZbjZpmx+fSFIkMzTT8bYClTnG1bsL1MCcU4pSODDorUj8zalA==" password:@"usai2010"];
  121. params = [self prepare_additional_params:params];
  122. DebugLog(@"\n++++++++++++++++++++++Request++++++++++++++++++++++\n%@\n++++++++++++++++++++++Params++++++++++++++++++++++\n%@\n",url,[RAConvertor dict2string:params]);
  123. return [super get_json:url parameters:params file:(NSString*)file err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  124. int result=[[jsobj valueForKey:@"result"] intValue];
  125. // UIApplication * app = [UIApplication sharedApplication];
  126. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  127. switch (result) {
  128. case 0:
  129. [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  130. break;
  131. case 1:
  132. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  133. break;
  134. case 2:
  135. [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  136. break;
  137. case 8:
  138. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  139. break;
  140. case 9:
  141. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  142. break;
  143. case 99:
  144. [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  145. break;
  146. default:
  147. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  148. break;
  149. }
  150. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  151. // {
  152. // [jsobj setValue:@"9" forKey:@"result"];
  153. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  154. // }
  155. return jsobj;
  156. } decrypt_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  157. return nil;
  158. // NSString* base64str = jsobj[@"str"];
  159. // NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"usai2010"];
  160. // jsobj=[[RAUtils string2dict:decryptstr] mutableCopy];
  161. // return jsobj;
  162. }];
  163. /*
  164. */
  165. return nil;
  166. }
  167. +(void) LoadImage:(NSString*) url into:(UIImageView*) container
  168. {
  169. DebugLog(@"LoadImage:(NSString*) url in:(UIImageView*) container");
  170. NSString* file_name=[url lastPathComponent];
  171. NSData* img_data = [iSalesDB load_cached_img:file_name loadFrom:url];
  172. if(img_data==nil)
  173. {
  174. DebugLog(@"IMG NOT CACHED %@",file_name);
  175. img_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
  176. [iSalesDB cache_img:img_data filename:file_name saveTo:url];
  177. //load from internet;
  178. }
  179. if(img_data!=nil)
  180. {
  181. UIImage * img =[UIImage imageWithData:img_data];
  182. if(img==nil)
  183. DebugLog(@"UIIMAGE IS NIL! %@",file_name);
  184. else
  185. dispatch_async(dispatch_get_main_queue(), ^{
  186. container.image =img;
  187. });
  188. }
  189. else
  190. {
  191. DebugLog(@"IMG DOWNLOAD FAILED! %@",file_name);
  192. }
  193. }
  194. //+(NSData*)fake_json:(NSString*) url
  195. //{
  196. // NSString* jsonfile = nil;
  197. // if([url isEqualToString:URL_UPDATE_AUTH])
  198. // {
  199. // jsonfile=@"login";
  200. //
  201. // }
  202. // else if([url isEqualToString:URL_REQUEST_CATMENU])
  203. // {
  204. // jsonfile=@"categorymenu";
  205. // }
  206. // else if([url isEqualToString:URL_LOAD_HOME])
  207. // {
  208. // jsonfile=@"homepage";
  209. // }
  210. // else if([url isEqualToString:URL_SEARCH])
  211. // {
  212. // jsonfile=@"search";
  213. // }
  214. // else if([url isEqualToString:URL_CATEGORY_LOADMORE])
  215. // {
  216. // jsonfile=@"category_more";
  217. // }else if([url isEqualToString:URL_ITEM_DETAIL])
  218. // {
  219. // jsonfile=@"detail";
  220. // }else if([url isEqualToString:URL_CART])
  221. // {
  222. // jsonfile=@"cart";
  223. // }else if([url isEqualToString:URL_ORDER_LIST])
  224. // {
  225. // jsonfile=@"orderlist";
  226. // }
  227. //// else if([url isEqualToString:URL_ORDER_INFO])
  228. //// {
  229. //// jsonfile=@"orderinfo";
  230. //// }
  231. //// else if([url isEqualToString:URL_ORDER_INFO])
  232. //// {
  233. //// jsonfile=@"orderinfo2label";
  234. //// }
  235. //
  236. //
  237. //
  238. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:jsonfile ofType:@"json" ]];
  239. // NSMutableString *result = [[NSMutableString alloc] initWithData:json encoding:NSUTF8StringEncoding];
  240. //
  241. // DebugLog(@"result: \n%@",result);
  242. // return json;
  243. //}
  244. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
  245. {
  246. NSString *userAction = [params valueForKey:kAction];
  247. NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  248. if ([userAction isEqualToString:@"Login"]) {
  249. if (!extra) {
  250. extra = [NSMutableDictionary dictionary];
  251. }
  252. [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  253. }
  254. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  255. NSString *screenName = [params valueForKey:kScreenName];
  256. [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  257. #endif
  258. return [self get_json:url parameters:params file:nil];
  259. }
  260. //+(NSDictionary*)request_Editor:(NSString*) sourceid editor:(NSString*)editor
  261. //{
  262. //
  263. //}
  264. +(NSDictionary*) delete_portfoliolist:(NSString* ) listid
  265. {
  266. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  267. __block AppDelegate *appDelegate = nil;
  268. dispatch_sync(dispatch_get_main_queue(), ^{
  269. //some UI methods ej
  270. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  271. });
  272. if(appDelegate.user!=nil)
  273. [params setValue:appDelegate.user forKey:@"user"];
  274. if(appDelegate.contact_id!=nil)
  275. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  276. if(appDelegate.password!=nil)
  277. [params setValue:appDelegate.password forKey:@"password"];
  278. [params setValue:listid forKey:@"tearsheetsId"];
  279. // [params setValue:editor forKey:@"editor"];
  280. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  281. // [params setValue:@"Delete Portfolio" forKey:kAction];
  282. NSData* json = nil;
  283. if(appDelegate.offline_mode)
  284. {
  285. json = [OLDataProvider offline_removePDF:params];
  286. } else {
  287. if(![self IsNetworkAvailable])
  288. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  289. json=[self get_json:URL_PORTFOLIOLIST_REMOVE parameters:params];
  290. }
  291. if(json!=nil)
  292. {
  293. NSError *error=nil;
  294. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  295. return jsobj;
  296. }
  297. else
  298. return nil;
  299. }
  300. +(NSDictionary*) portfolio_remove:(NSString* ) item_ids
  301. {
  302. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  303. __block AppDelegate *appDelegate = nil;
  304. dispatch_sync(dispatch_get_main_queue(), ^{
  305. //some UI methods ej
  306. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  307. });
  308. if(appDelegate.user!=nil)
  309. [params setValue:appDelegate.user forKey:@"user"];
  310. if(appDelegate.contact_id!=nil)
  311. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  312. if(appDelegate.password!=nil)
  313. [params setValue:appDelegate.password forKey:@"password"];
  314. [params setValue:item_ids forKey:@"portfolioId"];
  315. // [params setValue:editor forKey:@"editor"];
  316. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  317. NSData* json = nil;
  318. if(appDelegate.offline_mode)
  319. {
  320. json = [OLDataProvider offline_removePortfolio:params];
  321. } else {
  322. if(![self IsNetworkAvailable])
  323. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  324. json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  325. }
  326. if(json!=nil)
  327. {
  328. NSError *error=nil;
  329. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  330. int result = [[jsobj valueForKey:@"result"] intValue];
  331. if (result==2)
  332. {
  333. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  334. [appDelegate update_count_mark];
  335. }
  336. return jsobj;
  337. }
  338. else
  339. return nil;
  340. }
  341. //+(NSDictionary*) watchlist_remove:(NSString* ) item_ids
  342. //{
  343. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  344. // __block AppDelegate *appDelegate = nil;
  345. //
  346. // dispatch_sync(dispatch_get_main_queue(), ^{
  347. // //some UI methods ej
  348. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  349. // });
  350. // if(appDelegate.user!=nil)
  351. // [params setValue:appDelegate.user forKey:@"user"];
  352. // if(appDelegate.contact_id!=nil)
  353. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  354. // if(appDelegate.password!=nil)
  355. // [params setValue:appDelegate.password forKey:@"password"];
  356. // [params setValue:item_ids forKey:@"collectId"];
  357. // // [params setValue:editor forKey:@"editor"];
  358. //
  359. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  360. //
  361. // if(appDelegate.offline_mode)
  362. // {
  363. // return [OLDataProvider offline_deletewishlist:params];
  364. // }
  365. // if(![self IsNetworkAvailable])
  366. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  367. //
  368. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  369. // if(json!=nil)
  370. // {
  371. // NSError *error=nil;
  372. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  373. // int result = [[jsobj valueForKey:@"result"] intValue];
  374. //
  375. // if (result==2)
  376. // {
  377. //
  378. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  379. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  380. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  381. //
  382. // [appDelegate update_count_mark];
  383. // }
  384. // return jsobj;
  385. // }
  386. // else
  387. // return nil;
  388. //}
  389. //+(NSDictionary*) move_cart2wish:(NSString* ) item_ids
  390. //{
  391. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  392. // __block AppDelegate *appDelegate = nil;
  393. //
  394. // dispatch_sync(dispatch_get_main_queue(), ^{
  395. // //some UI methods ej
  396. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  397. // });
  398. // if(appDelegate.user!=nil)
  399. // [params setValue:appDelegate.user forKey:@"user"];
  400. // if(appDelegate.contact_id!=nil)
  401. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  402. // if(appDelegate.password!=nil)
  403. // [params setValue:appDelegate.password forKey:@"password"];
  404. // if(appDelegate.order_code!=nil)
  405. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  406. // [params setValue:item_ids forKey:@"cartItemId"];
  407. // // [params setValue:editor forKey:@"editor"];
  408. //
  409. // [params setValue:ScreenCodeCart forKey:kScreenName];
  410. // // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  411. //
  412. // NSData* json = nil;
  413. // if(appDelegate.offline_mode)
  414. // {
  415. // json= [OLDataProvider offline_movecart2wish:params];
  416. // }
  417. // else
  418. // {
  419. // if(![self IsNetworkAvailable])
  420. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  421. //
  422. // json=[self get_json:URL_CART2WISH parameters:params];
  423. // }
  424. // if(json!=nil)
  425. // {
  426. // NSError *error=nil;
  427. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  428. // int result = [[jsobj valueForKey:@"result"] intValue];
  429. //
  430. // if (result==2)
  431. // {
  432. //
  433. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  434. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  435. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  436. //
  437. // [appDelegate update_count_mark];
  438. // }
  439. // return jsobj;
  440. // }
  441. // else
  442. // return nil;
  443. //}
  444. //+(NSDictionary*) move_wish2cart:(NSString* ) item_ids
  445. //{
  446. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  447. // __block AppDelegate *appDelegate = nil;
  448. //
  449. // dispatch_sync(dispatch_get_main_queue(), ^{
  450. // //some UI methods ej
  451. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  452. // });
  453. // if(appDelegate.user!=nil)
  454. // [params setValue:appDelegate.user forKey:@"user"];
  455. // if(appDelegate.contact_id!=nil)
  456. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  457. // if(appDelegate.password!=nil)
  458. // [params setValue:appDelegate.password forKey:@"password"];
  459. // if(appDelegate.order_code!=nil)
  460. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  461. // [params setValue:item_ids forKey:@"collectId"];
  462. // // [params setValue:editor forKey:@"editor"];
  463. //
  464. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  465. // [params setValue:@"Move To Cart" forKey:kAction];
  466. //
  467. // NSData *json = nil;
  468. // if(appDelegate.offline_mode)
  469. // {
  470. // json = [OLDataProvider offline_movewish2cart:params];
  471. // } else {
  472. // if(![self IsNetworkAvailable])
  473. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  474. //
  475. // json=[self get_json:URL_WISH2CART parameters:params];
  476. // }
  477. //
  478. // if(json!=nil)
  479. // {
  480. // NSError *error=nil;
  481. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  482. // int result = [[jsobj valueForKey:@"result"] intValue];
  483. //
  484. // if (result==2)
  485. // {
  486. //
  487. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  488. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  489. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  490. //
  491. // [appDelegate update_count_mark];
  492. // }
  493. // return jsobj;
  494. // }
  495. // else
  496. // return nil;
  497. //}
  498. //+(NSDictionary*) cart_remove:(NSString* ) item_ids
  499. //{
  500. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  501. // __block AppDelegate *appDelegate = nil;
  502. //
  503. // dispatch_sync(dispatch_get_main_queue(), ^{
  504. // //some UI methods ej
  505. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  506. // });
  507. // if(appDelegate.user!=nil)
  508. // [params setValue:appDelegate.user forKey:@"user"];
  509. // if(appDelegate.contact_id!=nil)
  510. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  511. // if(appDelegate.password!=nil)
  512. // [params setValue:appDelegate.password forKey:@"password"];
  513. //
  514. // if(appDelegate.order_code!=nil)
  515. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  516. // [params setValue:item_ids forKey:@"cartItemId"];
  517. // // [params setValue:editor forKey:@"editor"];
  518. //
  519. // [params setValue:ScreenCodeCart forKey:kScreenName];
  520. // // [params setValue:@"" forKey:kAction];
  521. //
  522. // NSData* json=nil;
  523. // if(appDelegate.offline_mode)
  524. // {
  525. // json= [OLDataProvider offline_cartremove:params];
  526. // }
  527. // else
  528. // {
  529. // if(![self IsNetworkAvailable])
  530. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  531. //
  532. // json=[self get_json:URL_CART_REMOVE parameters:params];
  533. // }
  534. // if(json!=nil)
  535. // {
  536. // NSError *error=nil;
  537. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  538. //
  539. // int result = [[jsobj valueForKey:@"result"] intValue];
  540. //
  541. // if (result==2)
  542. // {
  543. //
  544. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  545. //
  546. //
  547. // [appDelegate update_count_mark];
  548. // }
  549. // return jsobj;
  550. // }
  551. // else
  552. // return nil;
  553. //}
  554. //+(NSDictionary*) cart_check:(NSString* ) item_ids
  555. //{
  556. // return nil;
  557. // if(![self IsNetworkAvailable])
  558. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  559. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  560. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  561. // if(appDelegate.user!=nil)
  562. // [params setValue:appDelegate.user forKey:@"user"];
  563. // if(appDelegate.contact_id!=nil)
  564. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  565. // if(appDelegate.password!=nil)
  566. // [params setValue:appDelegate.password forKey:@"password"];
  567. // [params setValue:item_ids forKey:@"cartItemId"];
  568. // // [params setValue:editor forKey:@"editor"];
  569. // if(appDelegate.offline_mode)
  570. // {
  571. // return [OLDataProvider offline_notimpl];
  572. // }
  573. // NSData* json=[self get_json:URL_CART_CHECK parameters:params];
  574. // if(json!=nil)
  575. // {
  576. // NSError *error=nil;
  577. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  578. // return jsobj;
  579. // }
  580. // else
  581. // return nil;
  582. //}
  583. +(NSDictionary*)create_Address:(NSMutableDictionary*)params
  584. {
  585. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  586. __block AppDelegate *appDelegate = nil;
  587. dispatch_sync(dispatch_get_main_queue(), ^{
  588. //some UI methods ej
  589. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  590. });
  591. if(appDelegate.user!=nil)
  592. [params setValue:appDelegate.user forKey:@"user"];
  593. if(appDelegate.contact_id!=nil)
  594. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  595. if(appDelegate.password!=nil)
  596. [params setValue:appDelegate.password forKey:@"password"];
  597. // [params setValue:sourceid forKey:@"sourceid"];
  598. // [params setValue:editor forKey:@"editor"];
  599. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  600. NSData* json=nil;
  601. if(appDelegate.offline_mode)
  602. {
  603. json= [OLDataProvider offline_saveaddr:params];
  604. }
  605. else
  606. {
  607. if(![self IsNetworkAvailable])
  608. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  609. json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  610. }
  611. if(json!=nil)
  612. {
  613. NSError *error=nil;
  614. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  615. return jsobj;
  616. }
  617. else
  618. return nil;
  619. }
  620. +(NSDictionary*)copy_Order:(NSString*) order_code
  621. {
  622. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  623. __block AppDelegate *appDelegate = nil;
  624. dispatch_sync(dispatch_get_main_queue(), ^{
  625. //some UI methods ej
  626. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  627. });
  628. if(appDelegate.user!=nil)
  629. [params setValue:appDelegate.user forKey:@"user"];
  630. if(appDelegate.contact_id!=nil)
  631. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  632. if(appDelegate.password!=nil)
  633. [params setValue:appDelegate.password forKey:@"password"];
  634. // NSString* ssaved = @"false";
  635. // if(saved)
  636. // ssaved=@"true";
  637. // [params setValue:@"true" forKey:@"saved"];
  638. [params setValue:order_code forKey:@"code"];
  639. // [params setValue:sourceid forKey:@"sourceid"];
  640. // [params setValue:editor forKey:@"editor"];
  641. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  642. NSData* json=nil;
  643. if(appDelegate.offline_mode)
  644. {
  645. json= [OLDataProvider offline_copyorder:params];
  646. }
  647. else
  648. {
  649. if(![self IsNetworkAvailable])
  650. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  651. json=[self get_json:URL_COPY_ORDER parameters:params];
  652. }
  653. if(json!=nil)
  654. {
  655. NSError *error=nil;
  656. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  657. return jsobj;
  658. }
  659. else
  660. return nil;
  661. }
  662. +(NSDictionary*)sign_Order:(NSString*) order_code path:(NSString*)path
  663. {
  664. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  665. __block AppDelegate *appDelegate = nil;
  666. dispatch_sync(dispatch_get_main_queue(), ^{
  667. //some UI methods ej
  668. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  669. });
  670. if(appDelegate.user!=nil)
  671. [params setValue:appDelegate.user forKey:@"user"];
  672. if(appDelegate.contact_id!=nil)
  673. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  674. if(appDelegate.password!=nil)
  675. [params setValue:appDelegate.password forKey:@"password"];
  676. // NSString* ssaved = @"false";
  677. // if(saved)
  678. // ssaved=@"true";
  679. // [params setValue:@"true" forKey:@"saved"];
  680. [params setValue:order_code forKey:@"orderCode"];
  681. [params setValue:path forKey:@"picpath"];
  682. // [params setValue:sourceid forKey:@"sourceid"];
  683. // [params setValue:editor forKey:@"editor"];
  684. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  685. NSData* json=nil;
  686. if(appDelegate.offline_mode)
  687. {
  688. json= [OLDataProvider offline_signorder:params];
  689. }
  690. else
  691. {
  692. if(![self IsNetworkAvailable])
  693. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  694. json=[self get_json:URL_SIGN_ORDER parameters:params];
  695. }
  696. if(json!=nil)
  697. {
  698. NSError *error=nil;
  699. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  700. return jsobj;
  701. }
  702. else
  703. return nil;
  704. }
  705. +(NSDictionary*)commit_Order:(NSString*) order_code //saved:(bool) saved
  706. {
  707. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  708. __block AppDelegate *appDelegate = nil;
  709. dispatch_sync(dispatch_get_main_queue(), ^{
  710. //some UI methods ej
  711. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  712. });
  713. if(appDelegate.user!=nil)
  714. [params setValue:appDelegate.user forKey:@"user"];
  715. if(appDelegate.contact_id!=nil)
  716. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  717. if(appDelegate.password!=nil)
  718. [params setValue:appDelegate.password forKey:@"password"];
  719. // NSString* ssaved = @"false";
  720. // if(saved)
  721. // ssaved=@"true";
  722. [params setValue:@"true" forKey:@"saved"];
  723. [params setValue:order_code forKey:@"orderCode"];
  724. // [params setValue:sourceid forKey:@"sourceid"];
  725. // [params setValue:editor forKey:@"editor"];
  726. [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  727. NSData* json = nil;
  728. if(appDelegate.offline_mode)
  729. {
  730. json= [OLDataProvider offline_submitorder:params];
  731. }
  732. else
  733. {
  734. if(![self IsNetworkAvailable])
  735. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  736. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  737. }
  738. if(json!=nil)
  739. {
  740. NSError *error=nil;
  741. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  742. return jsobj;
  743. }
  744. else
  745. return nil;
  746. }
  747. //+(NSDictionary*)open_Order:(NSString*) order_code
  748. //{
  749. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  750. // __block AppDelegate *appDelegate = nil;
  751. //
  752. // dispatch_sync(dispatch_get_main_queue(), ^{
  753. // //some UI methods ej
  754. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  755. // });
  756. // if(appDelegate.user!=nil)
  757. // [params setValue:appDelegate.user forKey:@"user"];
  758. // // if(appDelegate.contact_id!=nil)
  759. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  760. // if(appDelegate.password!=nil)
  761. // [params setValue:appDelegate.password forKey:@"password"];
  762. //
  763. // [params setValue:order_code forKey:@"orderCode"];
  764. // // [params setValue:sourceid forKey:@"sourceid"];
  765. // // [params setValue:editor forKey:@"editor"];
  766. //
  767. // [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  768. //
  769. // NSData* json=nil;
  770. // if(appDelegate.offline_mode)
  771. // {
  772. // json=[OLDataProvider offline_editorder:params];
  773. //
  774. // }
  775. // else
  776. // {
  777. // if(![self IsNetworkAvailable])
  778. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  779. //
  780. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  781. // }
  782. // if(json!=nil)
  783. // {
  784. // NSError *error=nil;
  785. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  786. // int result = [[jsobj valueForKey:@"result"] intValue];
  787. //
  788. // if (result==2)
  789. // {
  790. //
  791. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  792. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  793. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  794. //
  795. // [appDelegate update_count_mark];
  796. //
  797. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  798. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  799. // }
  800. //
  801. // }
  802. //
  803. // return jsobj;
  804. // }
  805. // else
  806. // return nil;
  807. //}
  808. +(NSDictionary*)delete_Order:(NSString*) order_id
  809. {
  810. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  811. __block AppDelegate *appDelegate = nil;
  812. dispatch_sync(dispatch_get_main_queue(), ^{
  813. //some UI methods ej
  814. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  815. });
  816. if(appDelegate.user!=nil)
  817. [params setValue:appDelegate.user forKey:@"user"];
  818. // if(appDelegate.contact_id!=nil)
  819. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  820. if(appDelegate.password!=nil)
  821. [params setValue:appDelegate.password forKey:@"password"];
  822. [params setValue:order_id forKey:@"orderId"];
  823. // [params setValue:sourceid forKey:@"sourceid"];
  824. // [params setValue:editor forKey:@"editor"];
  825. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  826. if(appDelegate.offline_mode)
  827. {
  828. return [OLDataProvider offline_notimpl];
  829. }
  830. if(![self IsNetworkAvailable])
  831. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  832. NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  833. if(json!=nil)
  834. {
  835. NSError *error=nil;
  836. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  837. return jsobj;
  838. }
  839. else
  840. return nil;
  841. }
  842. +(NSDictionary*)cancel_Order:(NSString*) order_id order_code:(NSString*) order_code
  843. {
  844. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  845. __block AppDelegate *appDelegate = nil;
  846. dispatch_sync(dispatch_get_main_queue(), ^{
  847. //some UI methods ej
  848. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  849. });
  850. if(appDelegate.user!=nil)
  851. [params setValue:appDelegate.user forKey:@"user"];
  852. // if(appDelegate.contact_id!=nil)
  853. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  854. if(appDelegate.password!=nil)
  855. [params setValue:appDelegate.password forKey:@"password"];
  856. [params setValue:order_id forKey:@"orderId"];
  857. [params setValue:order_code forKey:@"orderCode"];
  858. // [params setValue:sourceid forKey:@"sourceid"];
  859. // [params setValue:editor forKey:@"editor"];
  860. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  861. NSData* json=nil;
  862. if(appDelegate.offline_mode)
  863. {
  864. json=[OLDataProvider offline_cancelorder:params];
  865. }
  866. else
  867. {
  868. if(![self IsNetworkAvailable])
  869. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  870. json=[self get_json:URL_CANCEL_ORDER parameters:params];
  871. }
  872. if(json!=nil)
  873. {
  874. NSError *error=nil;
  875. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  876. return jsobj;
  877. }
  878. else
  879. return nil;
  880. }
  881. +(NSDictionary*)release_Order:(NSString*) order_code withScreen:(NSString *)screenName
  882. {
  883. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  884. __block AppDelegate *appDelegate = nil;
  885. dispatch_sync(dispatch_get_main_queue(), ^{
  886. //some UI methods ej
  887. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  888. });
  889. if(appDelegate.user!=nil)
  890. [params setValue:appDelegate.user forKey:@"user"];
  891. // if(appDelegate.contact_id!=nil)
  892. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  893. if(appDelegate.password!=nil)
  894. [params setValue:appDelegate.password forKey:@"password"];
  895. [params setValue:order_code forKey:@"orderCode"];
  896. // [params setValue:sourceid forKey:@"sourceid"];
  897. // [params setValue:editor forKey:@"editor"];
  898. if (screenName) {
  899. [params setValue:screenName forKey:kScreenName];
  900. }
  901. NSData* json=nil;
  902. if(appDelegate.offline_mode)
  903. {
  904. json= [OLDataProvider offline_resetorder:params];
  905. }
  906. else
  907. {
  908. if(![self IsNetworkAvailable])
  909. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  910. json=[self get_json:URL_RELEASE_ORDER parameters:params];
  911. }
  912. if(json!=nil)
  913. {
  914. NSError *error=nil;
  915. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  916. if([[jsobj valueForKey:@"result"]intValue]==2)
  917. { [appDelegate SetSo:nil];
  918. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  919. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  920. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  921. [appDelegate update_count_mark];
  922. }
  923. return jsobj;
  924. }
  925. else
  926. return nil;
  927. }
  928. +(NSDictionary*)update_OrderCustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info
  929. {
  930. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  931. __block AppDelegate *appDelegate = nil;
  932. dispatch_sync(dispatch_get_main_queue(), ^{
  933. //some UI methods ej
  934. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  935. });
  936. if(appDelegate.user!=nil)
  937. [info setValue:appDelegate.user forKey:@"user"];
  938. // if(appDelegate.contact_id!=nil)
  939. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  940. if(appDelegate.password!=nil)
  941. [info setValue:appDelegate.password forKey:@"password"];
  942. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  943. [info setValue:order_code forKey:@"orderCode"];
  944. // [params setValue:sourceid forKey:@"sourceid"];
  945. // [params setValue:editor forKey:@"editor"];
  946. if(appDelegate.offline_mode)
  947. {
  948. return [OLDataProvider offline_notimpl];
  949. }
  950. if(![self IsNetworkAvailable])
  951. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  952. NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  953. if(json!=nil)
  954. {
  955. NSError *error=nil;
  956. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  957. return jsobj;
  958. }
  959. else
  960. return nil;
  961. }
  962. //+(NSDictionary*)commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url
  963. //{
  964. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  965. // __block AppDelegate *appDelegate = nil;
  966. //
  967. // dispatch_sync(dispatch_get_main_queue(), ^{
  968. // //some UI methods ej
  969. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  970. // });
  971. // if(appDelegate.user!=nil)
  972. // [params setValue:appDelegate.user forKey:@"user"];
  973. // if(appDelegate.contact_id!=nil)
  974. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  975. // if(appDelegate.password!=nil)
  976. // [params setValue:appDelegate.password forKey:@"password"];
  977. //
  978. // // if(appDelegate.order_code!=nil)
  979. // // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  980. //
  981. // // NSDictionary* customerinfo= appDelegate.customerInfo;
  982. // //
  983. // // NSArray* keys=[customerinfo allKeys];
  984. // // for(int i=0;i<keys.count;i++)
  985. // // {
  986. // // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  987. // // }
  988. // //
  989. // // [params setValue:sourceid forKey:@"sourceid"];
  990. // // [params setValue:editor forKey:@"editor"];
  991. //
  992. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  993. //
  994. // if(appDelegate.offline_mode)
  995. // {
  996. // params[@"offline_Command"]=url;
  997. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  998. // }
  999. //
  1000. // if(![self IsNetworkAvailable])
  1001. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1002. //
  1003. // NSData* json=[self get_json:url parameters:params];
  1004. // if(json!=nil)
  1005. // {
  1006. // NSError *error=nil;
  1007. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1008. // if([[jsobj valueForKey:@"result"]intValue]==2)
  1009. // [appDelegate SetSo:nil];
  1010. //
  1011. //
  1012. // return jsobj;
  1013. // }
  1014. // else
  1015. // return nil;
  1016. //}
  1017. +(NSDictionary*)saveandcommit_Order:(NSMutableDictionary*)params
  1018. {
  1019. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1020. __block AppDelegate *appDelegate = nil;
  1021. dispatch_sync(dispatch_get_main_queue(), ^{
  1022. //some UI methods ej
  1023. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1024. });
  1025. if(appDelegate.user!=nil)
  1026. [params setValue:appDelegate.user forKey:@"user"];
  1027. if(appDelegate.contact_id!=nil)
  1028. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1029. if(appDelegate.password!=nil)
  1030. [params setValue:appDelegate.password forKey:@"password"];
  1031. if(appDelegate.order_code!=nil)
  1032. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1033. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1034. //
  1035. // NSArray* keys=[customerinfo allKeys];
  1036. // for(int i=0;i<keys.count;i++)
  1037. // {
  1038. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1039. // }
  1040. //
  1041. // [params setValue:sourceid forKey:@"sourceid"];
  1042. // [params setValue:editor forKey:@"editor"];
  1043. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1044. NSData* json=nil;
  1045. if(appDelegate.offline_mode)
  1046. {
  1047. json=[OLDataProvider offline_submitorder:params];
  1048. }
  1049. else
  1050. {
  1051. if(![self IsNetworkAvailable])
  1052. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1053. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  1054. }
  1055. if(json!=nil)
  1056. {
  1057. NSError *error=nil;
  1058. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1059. if([[jsobj valueForKey:@"result"]intValue]==2)
  1060. [appDelegate SetSo:nil];
  1061. return jsobj;
  1062. }
  1063. else
  1064. return nil;
  1065. }
  1066. +(NSDictionary*)update_Customer:(NSMutableDictionary*)params
  1067. {
  1068. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1069. __block AppDelegate *appDelegate = nil;
  1070. dispatch_sync(dispatch_get_main_queue(), ^{
  1071. //some UI methods ej
  1072. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1073. });
  1074. if(appDelegate.user!=nil)
  1075. [params setValue:appDelegate.user forKey:@"user"];
  1076. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1077. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1078. // else
  1079. if(appDelegate.contact_id!=nil)
  1080. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1081. if(appDelegate.password!=nil)
  1082. [params setValue:appDelegate.password forKey:@"password"];
  1083. // NSDictionary* customerinfo=nil;
  1084. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1085. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1086. // else
  1087. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1088. //
  1089. // appDelegate.customerInfo;
  1090. // NSArray* keys=[customerinfo allKeys];
  1091. // for(int i=0;i<keys.count;i++)
  1092. // {
  1093. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1094. // }
  1095. // [params setValue:sourceid forKey:@"sourceid"];
  1096. // [params setValue:editor forKey:@"editor"];
  1097. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1098. NSData* json=nil;
  1099. if(appDelegate.offline_mode)
  1100. {
  1101. json= [OLDataProvider offline_saveContact:params];
  1102. }
  1103. else
  1104. {
  1105. if(![self IsNetworkAvailable])
  1106. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1107. json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  1108. }
  1109. if(json!=nil)
  1110. {
  1111. NSError *error=nil;
  1112. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1113. return jsobj;
  1114. }
  1115. else
  1116. return nil;
  1117. }
  1118. +(NSDictionary*)save_newCustomer:(NSMutableDictionary*)params
  1119. {
  1120. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1121. __block AppDelegate *appDelegate = nil;
  1122. dispatch_sync(dispatch_get_main_queue(), ^{
  1123. //some UI methods ej
  1124. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1125. });
  1126. if(appDelegate.user!=nil)
  1127. [params setValue:appDelegate.user forKey:@"user"];
  1128. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1129. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1130. // else
  1131. if(appDelegate.contact_id!=nil)
  1132. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1133. if(appDelegate.password!=nil)
  1134. [params setValue:appDelegate.password forKey:@"password"];
  1135. // NSDictionary* customerinfo=nil;
  1136. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1137. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1138. // else
  1139. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1140. //
  1141. // appDelegate.customerInfo;
  1142. // NSArray* keys=[customerinfo allKeys];
  1143. // for(int i=0;i<keys.count;i++)
  1144. // {
  1145. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1146. // }
  1147. // [params setValue:sourceid forKey:@"sourceid"];
  1148. // [params setValue:editor forKey:@"editor"];
  1149. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1150. NSData* json=nil;
  1151. if(appDelegate.offline_mode)
  1152. {
  1153. json= [OLDataProvider offline_saveNewContact:params];
  1154. }
  1155. else
  1156. {
  1157. if(![self IsNetworkAvailable])
  1158. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1159. json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  1160. }
  1161. if(json!=nil)
  1162. {
  1163. NSError *error=nil;
  1164. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1165. return jsobj;
  1166. }
  1167. else
  1168. return nil;
  1169. }
  1170. +(NSDictionary*)save_Order:(NSMutableDictionary*)params
  1171. {
  1172. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1173. __block AppDelegate *appDelegate = nil;
  1174. dispatch_sync(dispatch_get_main_queue(), ^{
  1175. //some UI methods ej
  1176. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1177. });
  1178. if(appDelegate.user!=nil)
  1179. [params setValue:appDelegate.user forKey:@"user"];
  1180. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1181. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1182. // else
  1183. if(appDelegate.contact_id!=nil)
  1184. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1185. if(appDelegate.password!=nil)
  1186. [params setValue:appDelegate.password forKey:@"password"];
  1187. if(appDelegate.order_code!=nil)
  1188. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1189. // NSDictionary* customerinfo=nil;
  1190. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1191. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1192. // else
  1193. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1194. //
  1195. // appDelegate.customerInfo;
  1196. // NSArray* keys=[customerinfo allKeys];
  1197. // for(int i=0;i<keys.count;i++)
  1198. // {
  1199. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1200. // }
  1201. // [params setValue:sourceid forKey:@"sourceid"];
  1202. // [params setValue:editor forKey:@"editor"];
  1203. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1204. NSData* json=nil;
  1205. if(appDelegate.offline_mode)
  1206. {
  1207. json= [OLDataProvider offline_saveorder:params];
  1208. }
  1209. else
  1210. {
  1211. if(![self IsNetworkAvailable])
  1212. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1213. json=[self get_json:URL_SAVE_ORDER parameters:params];
  1214. }
  1215. if(json!=nil)
  1216. {
  1217. NSError *error=nil;
  1218. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1219. NSString *so = [jsobj valueForKey:@"so#"];
  1220. if (so) {
  1221. [appDelegate SetSo:so];
  1222. }
  1223. return jsobj;
  1224. }
  1225. else
  1226. return nil;
  1227. }
  1228. //+(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
  1229. //{
  1230. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1231. // __block AppDelegate *appDelegate = nil;
  1232. //
  1233. // dispatch_sync(dispatch_get_main_queue(), ^{
  1234. // //some UI methods ej
  1235. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1236. // });
  1237. // if(appDelegate.user!=nil)
  1238. // [params setValue:appDelegate.user forKey:@"user"];
  1239. //
  1240. //
  1241. // // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1242. // // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1243. // // else
  1244. //
  1245. // if(appDelegate.contact_id!=nil)
  1246. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1247. // if(appDelegate.password!=nil)
  1248. // [params setValue:appDelegate.password forKey:@"password"];
  1249. //
  1250. // if(appDelegate.order_code!=nil)
  1251. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1252. // // [params setValue:sourceid forKey:@"sourceid"];
  1253. // // [params setValue:editor forKey:@"editor"];
  1254. // DebugLog(@"request editor url:%@",request_url);
  1255. //
  1256. //
  1257. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1258. // {
  1259. // [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1260. // }
  1261. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1262. // {
  1263. // [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1264. // }
  1265. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1266. // {
  1267. // [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  1268. // }
  1269. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1270. // {
  1271. // [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1272. // }
  1273. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1274. // {
  1275. // [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  1276. // }
  1277. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1278. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1279. // }
  1280. //
  1281. // NSData* json = nil;
  1282. // if(appDelegate.offline_mode)
  1283. // {
  1284. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1285. // {
  1286. // json= [OLDataProvider offline_createContact:params];
  1287. // }
  1288. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1289. // {
  1290. // json= [OLDataProvider offline_editContact:params];
  1291. // }
  1292. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1293. // {
  1294. // json= [OLDataProvider offline_contactAdvancedSearch:params];
  1295. // }
  1296. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1297. // {
  1298. // json= [OLDataProvider offline_placeorder:params];
  1299. // }
  1300. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1301. // {
  1302. // json= [OLDataProvider offline_addreditor:params];
  1303. // }
  1304. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1305. // json = [OLDataProvider offline_createTearSheet:params];
  1306. // }
  1307. //
  1308. // else
  1309. // return [OLDataProvider offline_notimpl];
  1310. // }
  1311. // else
  1312. // {
  1313. // if(![self IsNetworkAvailable])
  1314. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1315. //
  1316. // if([request_url isEqualToString:URL_CARTDELIVERY])
  1317. // {
  1318. // NSError *error=nil;
  1319. //
  1320. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1321. // params[@"resultSerial"]=uuid;
  1322. //
  1323. // for(int i=0;i<150;i++)
  1324. // {
  1325. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1326. // // result_params[@"resultSerial"]=uuid;
  1327. // json=[self get_json:request_url parameters:params];
  1328. // if(json!=nil)
  1329. // {
  1330. //
  1331. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1332. // if([jsobj[@"result"] intValue]==2 || [jsobj[@"result"] intValue] == 8)
  1333. // {
  1334. // break;
  1335. // }
  1336. // }
  1337. // sleep(2);
  1338. // }
  1339. // }
  1340. // else
  1341. // json =[self get_json:request_url parameters:params];
  1342. // }
  1343. // if(json!=nil)
  1344. // {
  1345. // NSError *error=nil;
  1346. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1347. // return jsobj;
  1348. // }
  1349. // else
  1350. // return nil;
  1351. //}
  1352. //+(NSDictionary*)request_OrderInfo:(NSString*) orderid
  1353. //{
  1354. // if(![self IsNetworkAvailable])
  1355. // return nil;
  1356. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1357. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1358. // if(appDelegate.user!=nil)
  1359. // [params setValue:appDelegate.user forKey:@"user"];
  1360. // if(appDelegate.password!=nil)
  1361. // [params setValue:appDelegate.password forKey:@"password"];
  1362. // [params setValue:orderid forKey:@"orderid"];
  1363. // NSData* json=[self get_json:URL_ORDER_INFO parameters:params];
  1364. // NSError *error=nil;
  1365. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1366. // return jsobj;
  1367. //}
  1368. +(NSDictionary*)request_OrderList:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged
  1369. {
  1370. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1371. __block AppDelegate *appDelegate = nil;
  1372. dispatch_sync(dispatch_get_main_queue(), ^{
  1373. //some UI methods ej
  1374. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1375. });
  1376. if(appDelegate.user!=nil)
  1377. [params setValue:appDelegate.user forKey:@"user"];
  1378. if(appDelegate.contact_id!=nil)
  1379. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1380. if(appDelegate.password!=nil)
  1381. [params setValue:appDelegate.password forKey:@"password"];
  1382. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1383. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1384. [params setValue:keywords forKey:@"keyWord"];
  1385. [params setValue:customer forKey:@"customer_filter"];
  1386. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  1387. [params setValue:status_code forKey:@"orderStatus"];
  1388. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1389. if (keywords) {
  1390. [params setObject:@"Search" forKey:kAction];
  1391. }
  1392. NSData* json=nil;
  1393. if(appDelegate.offline_mode)
  1394. {
  1395. json= [OLDataProvider offline_orderlist:params];
  1396. }
  1397. else
  1398. {
  1399. if(![self IsNetworkAvailable])
  1400. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1401. json=[self get_json:URL_ORDER_LIST parameters:params];
  1402. }
  1403. if(json==nil)
  1404. return nil;
  1405. NSError *error=nil;
  1406. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1407. return jsobj;
  1408. }
  1409. +(NSDictionary*)request_PDFList:(int ) offset limit:(int)limit keywords:(NSString* ) keywords
  1410. {
  1411. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1412. __block AppDelegate *appDelegate = nil;
  1413. dispatch_sync(dispatch_get_main_queue(), ^{
  1414. //some UI methods ej
  1415. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1416. });
  1417. if(appDelegate.user!=nil)
  1418. [params setValue:appDelegate.user forKey:@"user"];
  1419. if(appDelegate.contact_id!=nil)
  1420. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1421. if(appDelegate.password!=nil)
  1422. [params setValue:appDelegate.password forKey:@"password"];
  1423. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  1424. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  1425. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  1426. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  1427. // [params setValue:filter forKey:@"filter"];
  1428. [params setValue:keywords forKey:@"keyWord"];
  1429. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  1430. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  1431. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  1432. if (keywords) {
  1433. [params setObject:@"Search" forKey:kAction];
  1434. }
  1435. NSData* json = nil;
  1436. if(appDelegate.offline_mode)
  1437. {
  1438. json = [OLDataProvider offline_pdfList:params];
  1439. } else {
  1440. if(![self IsNetworkAvailable])
  1441. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1442. json=[self get_json:URL_DM_LIST parameters:params];
  1443. }
  1444. if(json==nil)
  1445. return nil;
  1446. NSError *error=nil;
  1447. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1448. return jsobj;
  1449. }
  1450. +(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code//device:(NSString*) device
  1451. {
  1452. return nil;
  1453. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1454. __block AppDelegate *appDelegate = nil;
  1455. dispatch_sync(dispatch_get_main_queue(), ^{
  1456. //some UI methods ej
  1457. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1458. });
  1459. if(appDelegate.user!=nil)
  1460. [params setValue:appDelegate.user forKey:@"user"];
  1461. [params setValue:up_params forKey:@"upparam"];
  1462. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  1463. [params setValue:result forKey:@"result"];
  1464. [params setValue:module forKey:@"interfac"];
  1465. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  1466. // [params setValue:module forKey:@"module"];
  1467. // [[UIDevice currentDevice] name];
  1468. // if(appDelegate.offline_mode)
  1469. // {
  1470. // return [OLDataProvider offline_notimpl];
  1471. // }
  1472. if(![self IsNetworkAvailable])
  1473. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1474. NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  1475. if(json==nil)
  1476. return nil;
  1477. NSError *error=nil;
  1478. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1479. return jsobj;
  1480. }
  1481. //+(NSDictionary*)request_ContactList:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams
  1482. //{
  1483. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1484. //
  1485. // if(upparams!=nil)
  1486. // params = [upparams mutableCopy];
  1487. // __block AppDelegate *appDelegate = nil;
  1488. //
  1489. // dispatch_sync(dispatch_get_main_queue(), ^{
  1490. // //some UI methods ej
  1491. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1492. // });
  1493. // if(appDelegate.user!=nil)
  1494. // [params setValue:appDelegate.user forKey:@"user"];
  1495. //
  1496. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1497. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1498. // else
  1499. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1500. //
  1501. // if(appDelegate.password!=nil)
  1502. // [params setValue:appDelegate.password forKey:@"password"];
  1503. //
  1504. // [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1505. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1506. // [params setValue:contact_type forKey:@"contactType"];
  1507. // [params setValue:keywords forKey:@"keyword"];
  1508. //
  1509. // [params setObject:ScreenCodeAccount forKey:kScreenName];
  1510. // if (keywords) {
  1511. // [params setObject:@"Search" forKey:kAction];
  1512. // }
  1513. // if (upparams) {
  1514. // [params setObject:@"Advance Search" forKey:kAction];
  1515. // }
  1516. //
  1517. // NSString* url=nil;
  1518. // if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  1519. // url=URL_SHIPTO_LIST;
  1520. // else
  1521. // url=URL_CONTACT_LIST;
  1522. //
  1523. // if(appDelegate.offline_mode)
  1524. // return [OLDataProvider offline_contactlist:params];
  1525. //
  1526. // if(![self IsNetworkAvailable])
  1527. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1528. //
  1529. // NSData* json=[self get_json:url parameters:params];
  1530. // if(json==nil)
  1531. // return nil;
  1532. // NSError *error=nil;
  1533. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1534. // return jsobj;
  1535. //}
  1536. //+(NSDictionary*)request_OrderDetail:(NSMutableDictionary *) params
  1537. //{
  1538. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1539. // if (params == nil) {
  1540. // params = [[NSMutableDictionary alloc] init];
  1541. // }
  1542. // __block AppDelegate *appDelegate = nil;
  1543. //
  1544. // dispatch_sync(dispatch_get_main_queue(), ^{
  1545. // //some UI methods ej
  1546. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1547. // });
  1548. // if(appDelegate.user!=nil)
  1549. // [params setValue:appDelegate.user forKey:@"user"];
  1550. // if(appDelegate.contact_id!=nil)
  1551. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1552. // if(appDelegate.password!=nil)
  1553. // [params setValue:appDelegate.password forKey:@"password"];
  1554. //
  1555. //
  1556. // // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1557. //
  1558. // [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  1559. //
  1560. // NSData* json=nil;
  1561. // if(appDelegate.offline_mode)
  1562. // {
  1563. // json= [OLDataProvider offline_orderdetail:params];
  1564. // }
  1565. // else
  1566. // {
  1567. // if(![self IsNetworkAvailable])
  1568. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1569. //
  1570. // NSError *error=nil;
  1571. //
  1572. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1573. // params[@"resultSerial"]=uuid;
  1574. //
  1575. // for(int i=0;i<150;i++)
  1576. // {
  1577. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1578. // // result_params[@"resultSerial"]=uuid;
  1579. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  1580. // if(json!=nil)
  1581. // {
  1582. //
  1583. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1584. // int resultCode = [jsobj[@"result"] intValue];
  1585. // if(resultCode==2 || resultCode == 8)
  1586. // {
  1587. // break;
  1588. // }
  1589. // }
  1590. // sleep(2);
  1591. // }
  1592. //
  1593. //
  1594. // }
  1595. // if(json==nil)
  1596. // return nil;
  1597. // NSError *error=nil;
  1598. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1599. // return jsobj;
  1600. //}
  1601. //+(NSDictionary*) add_toCart:(NSString* ) item_id count:(int) count name:(NSString *)name
  1602. //{
  1603. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1604. // __block AppDelegate *appDelegate = nil;
  1605. //
  1606. // dispatch_sync(dispatch_get_main_queue(), ^{
  1607. // //some UI methods ej
  1608. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1609. // });
  1610. // if(appDelegate.user!=nil)
  1611. // [params setValue:appDelegate.user forKey:@"user"];
  1612. // if(appDelegate.contact_id!=nil)
  1613. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1614. // if(appDelegate.password!=nil)
  1615. // [params setValue:appDelegate.password forKey:@"password"];
  1616. //
  1617. // if(appDelegate.order_code!=nil)
  1618. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1619. // [params setValue:item_id forKey:@"product_id"];
  1620. // [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  1621. //
  1622. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  1623. // [params setObject:@"Add To Cart" forKey:kAction];
  1624. // if (name) {
  1625. // NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  1626. // [params setObject:extra forKey:kExtra];
  1627. // }
  1628. //
  1629. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1630. //
  1631. // NSArray* keys=[customerinfo allKeys];
  1632. // for(int i=0;i<keys.count;i++)
  1633. // {
  1634. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1635. // }
  1636. //
  1637. // NSData* json=nil;
  1638. // if(appDelegate.offline_mode)
  1639. // {
  1640. // json=[OLDataProvider offline_add2cart:params];
  1641. // }
  1642. // else
  1643. // {
  1644. // if(![self IsNetworkAvailable])
  1645. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1646. //
  1647. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  1648. // }
  1649. // if(json==nil)
  1650. // return nil;
  1651. // NSError *error=nil;
  1652. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1653. //
  1654. //
  1655. //
  1656. // int result = [[jsobj valueForKey:@"result"] intValue];
  1657. //
  1658. // if (result==2)
  1659. // {
  1660. //
  1661. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1662. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1663. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1664. //
  1665. // [appDelegate update_count_mark];
  1666. // }
  1667. //
  1668. // return jsobj;
  1669. //}
  1670. //+(NSDictionary*) add_toCart_byName:(NSString* ) model_name withScreen:(NSString *)screenName
  1671. //{
  1672. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1673. // __block AppDelegate *appDelegate = nil;
  1674. //
  1675. // dispatch_sync(dispatch_get_main_queue(), ^{
  1676. // //some UI methods ej
  1677. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1678. // });
  1679. // if(appDelegate.user!=nil)
  1680. // [params setValue:appDelegate.user forKey:@"user"];
  1681. // if(appDelegate.contact_id!=nil)
  1682. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1683. // if(appDelegate.password!=nil)
  1684. // [params setValue:appDelegate.password forKey:@"password"];
  1685. //
  1686. // if(appDelegate.order_code!=nil)
  1687. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1688. // [params setValue:model_name forKey:@"product_name"];
  1689. // [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  1690. //
  1691. // [params setObject:screenName forKey:kScreenName];
  1692. // [params setObject:@"Add To Cart" forKey:kAction];
  1693. // if (!model_name) {
  1694. // model_name = @"";
  1695. // }
  1696. // [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  1697. //
  1698. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1699. //
  1700. // NSArray* keys=[customerinfo allKeys];
  1701. // for(int i=0;i<keys.count;i++)
  1702. // {
  1703. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1704. // }
  1705. // NSData* json=nil;
  1706. // if(appDelegate.offline_mode)
  1707. // {
  1708. // json= [OLDataProvider offline_add2cartbyname:params];
  1709. // }
  1710. // else
  1711. // {
  1712. // if(![self IsNetworkAvailable])
  1713. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1714. //
  1715. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  1716. // }
  1717. // if(json==nil)
  1718. // return nil;
  1719. // NSError *error=nil;
  1720. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1721. //
  1722. //
  1723. //
  1724. // int result = [[jsobj valueForKey:@"result"] intValue];
  1725. //
  1726. // if (result==2||result==8)
  1727. // {
  1728. //
  1729. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1730. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1731. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1732. //
  1733. // [appDelegate update_count_mark];
  1734. // }
  1735. //
  1736. // return jsobj;
  1737. //}
  1738. //+(NSDictionary*) new_Customer
  1739. //{
  1740. // if(![self IsNetworkAvailable])
  1741. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1742. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1743. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1744. // if(appDelegate.user!=nil)
  1745. // [params setValue:appDelegate.user forKey:@"user"];
  1746. //// if(appDelegate.contact_id!=nil)
  1747. //// [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1748. // if(appDelegate.password!=nil)
  1749. // [params setValue:appDelegate.password forKey:@"password"];
  1750. //
  1751. //// if(appDelegate.order_code!=nil)
  1752. //// [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1753. //
  1754. //
  1755. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1756. //
  1757. // NSArray* keys=[customerinfo allKeys];
  1758. // for(int i=0;i<keys.count;i++)
  1759. // {
  1760. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1761. // }
  1762. //
  1763. // NSData* json=[self get_json:URL_CUSTOMER_EDIT parameters:params];
  1764. // if(json==nil)
  1765. // return nil;
  1766. // NSError *error=nil;
  1767. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1768. // return jsobj;
  1769. //}
  1770. //+(NSDictionary*) new_Order
  1771. //{
  1772. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1773. // __block AppDelegate *appDelegate = nil;
  1774. //
  1775. // dispatch_sync(dispatch_get_main_queue(), ^{
  1776. // //some UI methods ej
  1777. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1778. // });
  1779. // if(appDelegate.user!=nil)
  1780. // [params setValue:appDelegate.user forKey:@"user"];
  1781. // if(appDelegate.contact_id!=nil)
  1782. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1783. // if(appDelegate.password!=nil)
  1784. // [params setValue:appDelegate.password forKey:@"password"];
  1785. //
  1786. // if(appDelegate.order_code!=nil)
  1787. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1788. //
  1789. //
  1790. // [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1791. //
  1792. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1793. //
  1794. // NSArray* keys=[customerinfo allKeys];
  1795. // for(int i=0;i<keys.count;i++)
  1796. // {
  1797. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1798. // }
  1799. //
  1800. // NSData* json = nil;
  1801. // if(appDelegate.offline_mode)
  1802. // {
  1803. // json= [OLDataProvider offline_createorder:params];
  1804. // }
  1805. // else
  1806. // {
  1807. // if(![self IsNetworkAvailable])
  1808. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1809. //
  1810. // json=[self get_json:URL_NEW_ORDER parameters:params];
  1811. // }
  1812. // if(json==nil)
  1813. // return nil;
  1814. // NSError *error=nil;
  1815. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1816. // int result = [[jsobj valueForKey:@"result"] intValue];
  1817. //
  1818. // if (result==2)
  1819. // {
  1820. //
  1821. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1822. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1823. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1824. //
  1825. // [appDelegate update_count_mark];
  1826. // }
  1827. //
  1828. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  1829. //
  1830. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1831. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  1832. // }
  1833. //
  1834. // return jsobj;
  1835. //}
  1836. +(NSDictionary*) add_toPortfolio:(NSString* ) item_id withScreen:(NSString *)screenName
  1837. {
  1838. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1839. __block AppDelegate *appDelegate = nil;
  1840. dispatch_sync(dispatch_get_main_queue(), ^{
  1841. //some UI methods ej
  1842. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1843. });
  1844. if(appDelegate.user!=nil)
  1845. [params setValue:appDelegate.user forKey:@"user"];
  1846. if(appDelegate.contact_id!=nil)
  1847. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1848. if(appDelegate.password!=nil)
  1849. [params setValue:appDelegate.password forKey:@"password"];
  1850. [params setValue:item_id forKey:@"product_id"];
  1851. [params setObject:screenName forKey:kScreenName];
  1852. NSData* json = nil;
  1853. if(appDelegate.offline_mode)
  1854. {
  1855. json = [OLDataProvider offline_add2Portfolio:params];
  1856. } else {
  1857. if(![self IsNetworkAvailable])
  1858. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1859. json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  1860. }
  1861. if(json==nil)
  1862. return nil;
  1863. NSError *error=nil;
  1864. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1865. int result = [[jsobj valueForKey:@"result"] intValue];
  1866. if (result==2)
  1867. {
  1868. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1869. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1870. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1871. [appDelegate update_count_mark];
  1872. }
  1873. return jsobj;
  1874. }
  1875. //+(NSDictionary*) add_toWatchList:(NSString* ) item_id withScreen:(NSString *)screenName
  1876. //{
  1877. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1878. // __block AppDelegate *appDelegate = nil;
  1879. //
  1880. // dispatch_sync(dispatch_get_main_queue(), ^{
  1881. // //some UI methods ej
  1882. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1883. // });
  1884. // if(appDelegate.user!=nil)
  1885. // [params setValue:appDelegate.user forKey:@"user"];
  1886. // if(appDelegate.contact_id!=nil)
  1887. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1888. // if(appDelegate.password!=nil)
  1889. // [params setValue:appDelegate.password forKey:@"password"];
  1890. //
  1891. //
  1892. // [params setValue:item_id forKey:@"product_id"];
  1893. //
  1894. // [params setObject:screenName forKey:kScreenName];
  1895. //
  1896. // if(appDelegate.offline_mode)
  1897. // {
  1898. // return [OLDataProvider offline_add2wishlist:params];
  1899. // }
  1900. // if(![self IsNetworkAvailable])
  1901. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1902. //
  1903. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  1904. // if(json==nil)
  1905. // return nil;
  1906. // NSError *error=nil;
  1907. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1908. // int result = [[jsobj valueForKey:@"result"] intValue];
  1909. //
  1910. // if (result==2)
  1911. // {
  1912. //
  1913. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1914. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1915. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1916. //
  1917. // [appDelegate update_count_mark];
  1918. // }
  1919. // return jsobj;
  1920. //}
  1921. //+(NSDictionary*) cart_setPrice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes
  1922. //{
  1923. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1924. // __block AppDelegate *appDelegate = nil;
  1925. //
  1926. // dispatch_sync(dispatch_get_main_queue(), ^{
  1927. // //some UI methods ej
  1928. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1929. // });
  1930. // if(appDelegate.user!=nil)
  1931. // [params setValue:appDelegate.user forKey:@"user"];
  1932. // if(appDelegate.contact_id!=nil)
  1933. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1934. // if(appDelegate.password!=nil)
  1935. // [params setValue:appDelegate.password forKey:@"password"];
  1936. //
  1937. // [params setValue:cart_id forKey:@"cartitem_id"];
  1938. // [params setValue:notes forKey:@"item_note"];
  1939. //
  1940. // [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  1941. //
  1942. // [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  1943. //
  1944. // [params setObject:ScreenCodeCart forKey:kScreenName];
  1945. //
  1946. // NSData* json= nil;
  1947. // if(appDelegate.offline_mode)
  1948. // {
  1949. // json=[OLDataProvider offline_cartsetprice:params];
  1950. // }
  1951. // else
  1952. // {
  1953. // if(![self IsNetworkAvailable])
  1954. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1955. //
  1956. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  1957. // }
  1958. // if(json==nil)
  1959. // return nil;
  1960. // NSError *error=nil;
  1961. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1962. // return jsobj;
  1963. //}
  1964. //+(NSDictionary*) portfolio_setQTY:(NSString*) watchlist_id QTY:(int)qty
  1965. //{
  1966. // if(![self IsNetworkAvailable])
  1967. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1968. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1969. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1970. // if(appDelegate.user!=nil)
  1971. // [params setValue:appDelegate.user forKey:@"user"];
  1972. // if(appDelegate.contact_id!=nil)
  1973. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1974. // if(appDelegate.password!=nil)
  1975. // [params setValue:appDelegate.password forKey:@"password"];
  1976. //
  1977. // [params setValue:watchlist_id forKey:@"item_id"];
  1978. //
  1979. // [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  1980. //
  1981. //
  1982. //
  1983. // NSData* json=[self get_json:URL_DM_SET_QTY parameters:params];
  1984. // if(json==nil)
  1985. // return nil;
  1986. // NSError *error=nil;
  1987. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1988. // return jsobj;
  1989. //}
  1990. +(NSDictionary*) portfolio_setPrice:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes
  1991. {
  1992. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1993. __block AppDelegate *appDelegate = nil;
  1994. dispatch_sync(dispatch_get_main_queue(), ^{
  1995. //some UI methods ej
  1996. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1997. });
  1998. if(appDelegate.user!=nil)
  1999. [params setValue:appDelegate.user forKey:@"user"];
  2000. if(appDelegate.contact_id!=nil)
  2001. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2002. if(appDelegate.password!=nil)
  2003. [params setValue:appDelegate.password forKey:@"password"];
  2004. [params setValue:watchlist_id forKey:@"item_id"];
  2005. // if(notes.length>0)
  2006. // [params setValue:notes forKey:@"notes"];
  2007. if(notes)
  2008. [params setValue:notes forKey:@"notes"];
  2009. if(price != -MAXFLOAT)
  2010. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  2011. if (discount != -MAXFLOAT)
  2012. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  2013. if(qty_p != -MAXFLOAT)
  2014. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  2015. if(qty != -INT32_MAX)
  2016. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  2017. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2018. NSData* json = nil;
  2019. if(appDelegate.offline_mode)
  2020. {
  2021. json = [OLDataProvider offline_editPortfolio:params];
  2022. } else {
  2023. if(![self IsNetworkAvailable])
  2024. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2025. json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  2026. }
  2027. if(json==nil)
  2028. return nil;
  2029. NSError *error=nil;
  2030. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2031. return jsobj;
  2032. }
  2033. //+(NSDictionary*) cart_setGeneralNote:(NSString*) order_code notes:(NSString*) notes
  2034. //{
  2035. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2036. // __block AppDelegate *appDelegate = nil;
  2037. //
  2038. // dispatch_sync(dispatch_get_main_queue(), ^{
  2039. // //some UI methods ej
  2040. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2041. // });
  2042. // if(appDelegate.user!=nil)
  2043. // [params setValue:appDelegate.user forKey:@"user"];
  2044. // if(appDelegate.contact_id!=nil)
  2045. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2046. // if(appDelegate.password!=nil)
  2047. // [params setValue:appDelegate.password forKey:@"password"];
  2048. //
  2049. // [params setValue:order_code forKey:@"orderCode"];
  2050. //
  2051. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2052. //
  2053. // if(notes.length==0)
  2054. // notes=@"";
  2055. //
  2056. //
  2057. // [params setValue:notes forKey:@"comments"];
  2058. // NSData* json=nil;
  2059. // if(appDelegate.offline_mode)
  2060. // {
  2061. // json= [OLDataProvider offline_updategnotes:params];
  2062. // }
  2063. // else
  2064. // {
  2065. // if(![self IsNetworkAvailable])
  2066. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2067. //
  2068. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  2069. // }
  2070. // if(json==nil)
  2071. // return nil;
  2072. // NSError *error=nil;
  2073. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2074. // return jsobj;
  2075. //}
  2076. //+(NSDictionary*) cart_setItemNote:(NSString*) cart_id notes:(NSString*) notes
  2077. //{
  2078. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2079. // __block AppDelegate *appDelegate = nil;
  2080. //
  2081. // dispatch_sync(dispatch_get_main_queue(), ^{
  2082. // //some UI methods ej
  2083. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2084. // });
  2085. // if(appDelegate.user!=nil)
  2086. // [params setValue:appDelegate.user forKey:@"user"];
  2087. // if(appDelegate.contact_id!=nil)
  2088. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2089. // if(appDelegate.password!=nil)
  2090. // [params setValue:appDelegate.password forKey:@"password"];
  2091. //
  2092. // [params setValue:cart_id forKey:@"cartitem_id"];
  2093. //
  2094. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2095. //
  2096. // if(notes.length==0)
  2097. // notes=@"";
  2098. //
  2099. //
  2100. // [params setValue:notes forKey:@"notes"];
  2101. // NSData* json=nil;
  2102. // if(appDelegate.offline_mode)
  2103. // {
  2104. // json= [OLDataProvider offline_cartsetlnotes:params];
  2105. // }
  2106. // else
  2107. // {
  2108. // if(![self IsNetworkAvailable])
  2109. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2110. //
  2111. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  2112. // }
  2113. // if(json==nil)
  2114. // return nil;
  2115. // NSError *error=nil;
  2116. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2117. // return jsobj;
  2118. //}
  2119. //+(NSDictionary*) cart_setFree:(NSString*) cart_id isfree:(bool) isfree
  2120. //{
  2121. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2122. // __block AppDelegate *appDelegate = nil;
  2123. //
  2124. // dispatch_sync(dispatch_get_main_queue(), ^{
  2125. // //some UI methods ej
  2126. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2127. // });
  2128. // if(appDelegate.user!=nil)
  2129. // [params setValue:appDelegate.user forKey:@"user"];
  2130. // if(appDelegate.contact_id!=nil)
  2131. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2132. // if(appDelegate.password!=nil)
  2133. // [params setValue:appDelegate.password forKey:@"password"];
  2134. //
  2135. // [params setValue:cart_id forKey:@"cartitem_id"];
  2136. //
  2137. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2138. //
  2139. // NSString* free=nil;
  2140. //
  2141. // if(isfree)
  2142. // free=@"true";
  2143. // else
  2144. // free=@"false";
  2145. //
  2146. // [params setValue:free forKey:@"free_giveaway"];
  2147. //
  2148. // if(appDelegate.offline_mode)
  2149. // {
  2150. // return [OLDataProvider offline_notimpl];
  2151. // }
  2152. // if(![self IsNetworkAvailable])
  2153. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2154. //
  2155. // NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2156. // if(json==nil)
  2157. // return nil;
  2158. // NSError *error=nil;
  2159. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2160. // return jsobj;
  2161. //}
  2162. //+(NSDictionary*) cart_setQTY:(NSString*) cart_id value:(int) value
  2163. //{
  2164. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2165. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2166. // if(appDelegate.user!=nil)
  2167. // [params setValue:appDelegate.user forKey:@"user"];
  2168. // if(appDelegate.contact_id!=nil)
  2169. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2170. // if(appDelegate.password!=nil)
  2171. // [params setValue:appDelegate.password forKey:@"password"];
  2172. //
  2173. // [params setValue:cart_id forKey:@"cartitem_id"];
  2174. //
  2175. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2176. //
  2177. // [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  2178. //
  2179. // NSData* json=nil;
  2180. // if(appDelegate.offline_mode)
  2181. // {
  2182. // json= [OLDataProvider offline_cartsetqty:params];
  2183. // }
  2184. // else
  2185. // {
  2186. // if(![self IsNetworkAvailable])
  2187. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2188. //
  2189. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2190. // }
  2191. // if(json==nil)
  2192. // return nil;
  2193. // NSError *error=nil;
  2194. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2195. // return jsobj;
  2196. //
  2197. //}
  2198. //+(NSDictionary*) cart_incresement:(NSString*) cart_id increse:(bool) increse
  2199. //{
  2200. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2201. // __block AppDelegate *appDelegate = nil;
  2202. //
  2203. // dispatch_sync(dispatch_get_main_queue(), ^{
  2204. // //some UI methods ej
  2205. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2206. // });
  2207. // if(appDelegate.user!=nil)
  2208. // [params setValue:appDelegate.user forKey:@"user"];
  2209. // if(appDelegate.contact_id!=nil)
  2210. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2211. // if(appDelegate.password!=nil)
  2212. // [params setValue:appDelegate.password forKey:@"password"];
  2213. //
  2214. // [params setValue:cart_id forKey:@"cartitem_id"];
  2215. //
  2216. // if(increse)
  2217. // [params setValue:@"1" forKey:@"incrementType"];
  2218. // else
  2219. // [params setValue:@"0" forKey:@"incrementType"];
  2220. //
  2221. //
  2222. //
  2223. // if(appDelegate.offline_mode)
  2224. // {
  2225. // return [OLDataProvider offline_notimpl];
  2226. // }
  2227. // if(![self IsNetworkAvailable])
  2228. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2229. //
  2230. // NSData* json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2231. // if(json==nil)
  2232. // return nil;
  2233. // NSError *error=nil;
  2234. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2235. // return jsobj;
  2236. //}
  2237. +(NSDictionary*) finish_download_Offline:(NSString* )vid
  2238. {
  2239. if(![self IsNetworkAvailable])
  2240. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2241. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2242. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  2243. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2244. // if(appDelegate.user!=nil)
  2245. // [params setValue:appDelegate.user forKey:@"user"];
  2246. // // if(appDelegate.contact_id!=nil)
  2247. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2248. // if(appDelegate.password!=nil)
  2249. // [params setValue:appDelegate.password forKey:@"password"];
  2250. [params setValue:vid forKey:@"downSerial"];
  2251. NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  2252. if(json==nil)
  2253. return nil;
  2254. NSError *error=nil;
  2255. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2256. // int result = [[jsobj valueForKey:@"result"] intValue];
  2257. //
  2258. // if (result==2)
  2259. // {
  2260. //
  2261. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2262. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2263. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2264. ////
  2265. //// [appDelegate update_count_mark];
  2266. // }
  2267. return jsobj;
  2268. }
  2269. +(NSDictionary*) download_Offline:(NSString* )vid
  2270. {
  2271. if(![self IsNetworkAvailable])
  2272. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2273. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2274. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2275. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2276. // if(appDelegate.user!=nil)
  2277. // [params setValue:appDelegate.user forKey:@"user"];
  2278. // // if(appDelegate.contact_id!=nil)
  2279. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2280. // if(appDelegate.password!=nil)
  2281. // [params setValue:appDelegate.password forKey:@"password"];
  2282. [params setValue:vid forKey:@"downSerial"];
  2283. NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  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:@"count"] intValue];
  2295. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2296. ////
  2297. //// [appDelegate update_count_mark];
  2298. // }
  2299. return jsobj;
  2300. }
  2301. +(NSDictionary*) check_Offline:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid
  2302. {
  2303. if(![self IsNetworkAvailable])
  2304. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2305. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2306. __block AppDelegate *appDelegate = nil;
  2307. dispatch_sync(dispatch_get_main_queue(), ^{
  2308. //some UI methods ej
  2309. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2310. });
  2311. if(appDelegate.user!=nil)
  2312. [params setValue:appDelegate.user forKey:@"user"];
  2313. // if(appDelegate.contact_id!=nil)
  2314. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2315. if(appDelegate.password!=nil)
  2316. [params setValue:appDelegate.password forKey:@"password"];
  2317. [params setValue:ver forKey:@"ver"];
  2318. [params setValue:vid forKey:@"vid"];
  2319. if(buseinternaladdress)
  2320. [params setValue:@"true" forKey:@"internal_address"];
  2321. else
  2322. [params setValue:@"false" forKey:@"internal_address"];
  2323. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2324. NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  2325. if(json==nil)
  2326. return nil;
  2327. NSError *error=nil;
  2328. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2329. // int result = [[jsobj valueForKey:@"result"] intValue];
  2330. //
  2331. // if (result==2)
  2332. // {
  2333. //
  2334. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2335. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2336. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2337. ////
  2338. //// [appDelegate update_count_mark];
  2339. // }
  2340. return jsobj;
  2341. }
  2342. //+(NSDictionary*)request_Cart:(int)sort
  2343. //{
  2344. //
  2345. // DebugLog(@"iSalesNetwork::request_Cart");
  2346. //
  2347. //
  2348. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2349. // __block AppDelegate *appDelegate = nil;
  2350. //
  2351. // dispatch_sync(dispatch_get_main_queue(), ^{
  2352. // //some UI methods ej
  2353. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2354. // });
  2355. // if(appDelegate.user!=nil)
  2356. // [params setValue:appDelegate.user forKey:@"user"];
  2357. // // if(appDelegate.contact_id!=nil)
  2358. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2359. // if(appDelegate.password!=nil)
  2360. // [params setValue:appDelegate.password forKey:@"password"];
  2361. //
  2362. // if(appDelegate.order_code!=nil)
  2363. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2364. //
  2365. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2366. //
  2367. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2368. //
  2369. // NSData* json=nil;
  2370. // if(appDelegate.offline_mode)
  2371. // {
  2372. // json= [OLDataProvider offline_requestcart:params];
  2373. // }
  2374. // else
  2375. // {
  2376. // if(![self IsNetworkAvailable])
  2377. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2378. //
  2379. // NSError *error=nil;
  2380. //
  2381. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2382. // params[@"resultSerial"]=uuid;
  2383. //
  2384. // for(int i=0;i<150;i++)
  2385. // {
  2386. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2387. // // result_params[@"resultSerial"]=uuid;
  2388. // json=[self get_json:URL_CART parameters:params];
  2389. // if(json!=nil)
  2390. // {
  2391. //
  2392. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2393. // if([jsobj[@"result"] intValue]==2)
  2394. // {
  2395. // break;
  2396. // }
  2397. // }
  2398. // sleep(2);
  2399. // }
  2400. //
  2401. // }
  2402. // if(json==nil)
  2403. // return nil;
  2404. // NSError *error=nil;
  2405. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2406. // int result = [[jsobj valueForKey:@"result"] intValue];
  2407. //
  2408. // if (result==2)
  2409. // {
  2410. //
  2411. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2412. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2413. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2414. //
  2415. // [appDelegate update_count_mark];
  2416. // }
  2417. // return jsobj;
  2418. //}
  2419. //+(NSDictionary*)request_Portfolio:(int)sort
  2420. //{
  2421. //
  2422. //
  2423. //
  2424. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2425. // __block AppDelegate *appDelegate = nil;
  2426. //
  2427. // dispatch_sync(dispatch_get_main_queue(), ^{
  2428. // //some UI methods ej
  2429. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2430. // });
  2431. // if(appDelegate.user!=nil)
  2432. // [params setValue:appDelegate.user forKey:@"user"];
  2433. // if(appDelegate.contact_id!=nil)
  2434. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2435. // if(appDelegate.password!=nil)
  2436. // [params setValue:appDelegate.password forKey:@"password"];
  2437. //
  2438. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2439. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2440. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2441. //
  2442. // [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2443. //
  2444. // NSData* json = nil;
  2445. // if(appDelegate.offline_mode)
  2446. // {
  2447. // json = [OLDataProvider offline_portfolioList:params];
  2448. // } else {
  2449. // if(![self IsNetworkAvailable])
  2450. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2451. //
  2452. // json = [self get_json:URL_PORTFOLIO parameters:params];
  2453. // }
  2454. //
  2455. //
  2456. // if(json==nil)
  2457. // return nil;
  2458. // NSError *error=nil;
  2459. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2460. // int result = [[jsobj valueForKey:@"result"] intValue];
  2461. //
  2462. // if (result==2)
  2463. // {
  2464. //
  2465. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2466. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2467. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  2468. //
  2469. // [appDelegate update_count_mark];
  2470. // }
  2471. // return jsobj;
  2472. //}
  2473. //+(NSDictionary*)request_WatchList:(int)sort
  2474. //{
  2475. //
  2476. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2477. // __block AppDelegate *appDelegate = nil;
  2478. //
  2479. // dispatch_sync(dispatch_get_main_queue(), ^{
  2480. // //some UI methods ej
  2481. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2482. // });
  2483. // if(appDelegate.user!=nil)
  2484. // [params setValue:appDelegate.user forKey:@"user"];
  2485. // if(appDelegate.contact_id!=nil)
  2486. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2487. // if(appDelegate.password!=nil)
  2488. // [params setValue:appDelegate.password forKey:@"password"];
  2489. //
  2490. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2491. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2492. //
  2493. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2494. //
  2495. // [params setObject:ScreenCodeWishList forKey:kScreenName];
  2496. //
  2497. // if(appDelegate.offline_mode)
  2498. // {
  2499. // return [OLDataProvider offline_wishlist:params];
  2500. // }
  2501. // if(![self IsNetworkAvailable])
  2502. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2503. //
  2504. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  2505. // if(json==nil)
  2506. // return nil;
  2507. // NSError *error=nil;
  2508. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2509. // int result = [[jsobj valueForKey:@"result"] intValue];
  2510. //
  2511. // if (result==2)
  2512. // {
  2513. //
  2514. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2515. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2516. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2517. //
  2518. // [appDelegate update_count_mark];
  2519. // }
  2520. // return jsobj;
  2521. //}
  2522. //+(NSDictionary*)request_ItemDetail: (NSString* ) item_id model_name:(NSString*) model_name category_id:(NSString*) category_id use_name :(bool) use_name groupName:(NSString *)groupName
  2523. //{
  2524. //
  2525. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2526. // __block AppDelegate *appDelegate = nil;
  2527. //
  2528. // dispatch_sync(dispatch_get_main_queue(), ^{
  2529. // //some UI methods ej
  2530. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2531. // });
  2532. // if(appDelegate.user!=nil)
  2533. // [params setValue:appDelegate.user forKey:@"user"];
  2534. // if(appDelegate.contact_id!=nil)
  2535. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2536. // if(appDelegate.password!=nil)
  2537. // [params setValue:appDelegate.password forKey:@"password"];
  2538. // if(appDelegate.order_code!=nil)
  2539. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2540. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2541. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2542. // if(use_name)
  2543. // [params setValue:model_name forKey:@"product_name"];
  2544. // else
  2545. // [params setValue:item_id forKey:@"product_id"];
  2546. //
  2547. //
  2548. // [params setValue:category_id forKey:@"category"];
  2549. //
  2550. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  2551. // [params setObject:@"Open A Model" forKey:kAction];
  2552. // if (model_name) {
  2553. // NSDictionary *extra = @{@"ModelName" : model_name};
  2554. // [params setObject:extra forKey:kExtra];
  2555. // }
  2556. //
  2557. // if (groupName.length > 0) {
  2558. // [params setObject:groupName forKey:@"groupName"];
  2559. // }
  2560. //
  2561. // if(appDelegate.offline_mode)
  2562. // return [OLDataProvider offline_model:params];
  2563. //
  2564. // if(![self IsNetworkAvailable])
  2565. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2566. //
  2567. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  2568. // if(json==nil)
  2569. // return nil;
  2570. // NSError *error=nil;
  2571. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2572. // return jsobj;
  2573. //}
  2574. //+(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
  2575. //{
  2576. // if(![self IsNetworkAvailable])
  2577. // return nil;
  2578. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2579. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2580. // if(appDelegate.user!=nil)
  2581. // [params setValue:appDelegate.user forKey:@"user"];
  2582. // if(appDelegate.contact_id!=nil)
  2583. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2584. // if(appDelegate.password!=nil)
  2585. // [params setValue:appDelegate.password forKey:@"password"];
  2586. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2587. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2588. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2589. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2590. // [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  2591. // [params setValue:filter forKey:@"filter"];
  2592. // [params setValue:keyword forKey:@"keyword"];
  2593. //
  2594. //
  2595. // NSData* json=[self get_json:URL_CATEGORY_LOADMORE parameters:params];
  2596. // if(json==nil)
  2597. // return nil;
  2598. // NSError *error=nil;
  2599. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2600. // return jsobj;
  2601. //
  2602. //}
  2603. //+(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
  2604. //
  2605. //{
  2606. //
  2607. //
  2608. // __block AppDelegate *appDelegate = nil;
  2609. //
  2610. // dispatch_sync(dispatch_get_main_queue(), ^{
  2611. // //some UI methods ej
  2612. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2613. // });
  2614. //
  2615. //
  2616. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2617. //
  2618. // if(appDelegate.user!=nil)
  2619. // [params setValue:appDelegate.user forKey:@"user"];
  2620. // if(appDelegate.contact_id!=nil)
  2621. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2622. // if(appDelegate.password!=nil)
  2623. // [params setValue:appDelegate.password forKey:@"password"];
  2624. // if(appDelegate.order_code!=nil)
  2625. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2626. //
  2627. // [params setValue:addTo forKey:@"addTo"];
  2628. // [params setValue:orderCode forKey:@"orderCode"];
  2629. // [params setValue:alert forKey:@"alert"];
  2630. // [params setValue:qty forKey:@"sold_by_qty"];
  2631. // [params setValue:available forKey:@"available"];
  2632. // [params setValue:price forKey:@"price"];
  2633. // [params setValue:bestseller forKey:@"bestseller"];
  2634. // [params setValue:modelname forKey:@"modelName"];
  2635. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2636. //
  2637. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2638. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2639. // [params setValue:category forKey:@"category"];
  2640. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2641. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2642. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2643. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2644. // [params setValue:filter forKey:@"filter"];
  2645. // [params setValue:keyword forKey:@"keyword"];
  2646. //
  2647. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  2648. // if ([addTo isEqualToString:@"cart"]) {
  2649. // [params setObject:@"Add To Cart" forKey:kAction];
  2650. // }
  2651. //
  2652. //
  2653. // NSData* json= nil;
  2654. //
  2655. // if(appDelegate.offline_mode)
  2656. // {
  2657. // json= [OLDataProvider offline_categoryaddall:params];
  2658. // }
  2659. // else
  2660. // {
  2661. // if(![self IsNetworkAvailable])
  2662. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2663. //
  2664. //
  2665. // NSError *error=nil;
  2666. //
  2667. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2668. // params[@"resultSerial"]=uuid;
  2669. //
  2670. // for(int i=0;i<150;i++)
  2671. // {
  2672. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2673. // // result_params[@"resultSerial"]=uuid;
  2674. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  2675. // if(json!=nil)
  2676. // {
  2677. //
  2678. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2679. // int resultInt = [jsobj[@"result"] intValue];
  2680. // if(resultInt == 2 || resultInt == 8)
  2681. // {
  2682. // break;
  2683. // }
  2684. // }
  2685. // sleep(2);
  2686. // }
  2687. //
  2688. //
  2689. //
  2690. // }
  2691. // if(json==nil)
  2692. // return nil;
  2693. // NSError *error=nil;
  2694. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2695. // return jsobj;
  2696. //
  2697. //}
  2698. //+(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
  2699. //{
  2700. //
  2701. //
  2702. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2703. //
  2704. //
  2705. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2706. //
  2707. // if(appDelegate.user!=nil)
  2708. // [params setValue:appDelegate.user forKey:@"user"];
  2709. // if(appDelegate.contact_id!=nil)
  2710. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2711. // if(appDelegate.password!=nil)
  2712. // [params setValue:appDelegate.password forKey:@"password"];
  2713. // if(appDelegate.order_code!=nil)
  2714. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2715. //
  2716. // [params setValue:alert forKey:@"alert"];
  2717. // [params setValue:qty forKey:@"sold_by_qty"];
  2718. // [params setValue:available forKey:@"available"];
  2719. // [params setValue:price forKey:@"price"];
  2720. // [params setValue:bestseller forKey:@"bestseller"];
  2721. // [params setValue:modelname forKey:@"modelName"];
  2722. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2723. //
  2724. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2725. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2726. // [params setValue:category forKey:@"category"];
  2727. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2728. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2729. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2730. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2731. // [params setValue:filter forKey:@"filter"];
  2732. // [params setValue:keyword forKey:@"keyword"];
  2733. //
  2734. //
  2735. //
  2736. // if(appDelegate.offline_mode)
  2737. // return [OLDataProvider offline_category:params];
  2738. // if(![self IsNetworkAvailable])
  2739. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2740. //
  2741. // NSData* json=[self get_json:URL_ADDALL2PORTFOLIO parameters:params];
  2742. // if(json==nil)
  2743. // return nil;
  2744. // NSError *error=nil;
  2745. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2746. // return jsobj;
  2747. //
  2748. //}
  2749. //+(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
  2750. //{
  2751. //
  2752. //
  2753. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2754. //
  2755. //
  2756. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2757. //
  2758. // if(appDelegate.user!=nil)
  2759. // [params setValue:appDelegate.user forKey:@"user"];
  2760. // if(appDelegate.contact_id!=nil)
  2761. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2762. // if(appDelegate.password!=nil)
  2763. // [params setValue:appDelegate.password forKey:@"password"];
  2764. // if(appDelegate.order_code!=nil)
  2765. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2766. //
  2767. // [params setValue:alert forKey:@"alert"];
  2768. // [params setValue:qty forKey:@"sold_by_qty"];
  2769. // [params setValue:available forKey:@"available"];
  2770. // [params setValue:price forKey:@"price"];
  2771. // [params setValue:bestseller forKey:@"bestseller"];
  2772. // [params setValue:modelname forKey:@"modelName"];
  2773. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2774. //
  2775. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2776. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2777. // [params setValue:category forKey:@"category"];
  2778. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2779. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2780. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2781. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2782. // [params setValue:filter forKey:@"filter"];
  2783. // [params setValue:keyword forKey:@"keyword"];
  2784. //
  2785. //
  2786. //
  2787. // if(appDelegate.offline_mode)
  2788. // return [OLDataProvider offline_category:params];
  2789. // if(![self IsNetworkAvailable])
  2790. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2791. //
  2792. // NSData* json=[self get_json:URL_ADDALL2WISH parameters:params];
  2793. // if(json==nil)
  2794. // return nil;
  2795. // NSError *error=nil;
  2796. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2797. // return jsobj;
  2798. //
  2799. //}
  2800. //+(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
  2801. //{
  2802. //
  2803. //
  2804. // __block AppDelegate *appDelegate = nil;
  2805. //
  2806. // dispatch_sync(dispatch_get_main_queue(), ^{
  2807. // //some UI methods ej
  2808. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2809. // });
  2810. //
  2811. //
  2812. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2813. //
  2814. // if(appDelegate.user!=nil)
  2815. // [params setValue:appDelegate.user forKey:@"user"];
  2816. // if(appDelegate.contact_id!=nil)
  2817. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2818. // if(appDelegate.password!=nil)
  2819. // [params setValue:appDelegate.password forKey:@"password"];
  2820. // if(appDelegate.order_code!=nil)
  2821. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2822. //
  2823. // [params setValue:alert forKey:@"alert"];
  2824. // [params setValue:qty forKey:@"sold_by_qty"];
  2825. // [params setValue:available forKey:@"available"];
  2826. // [params setValue:price forKey:@"price"];
  2827. // [params setValue:bestseller forKey:@"bestseller"];
  2828. // [params setValue:modelname forKey:@"modelName"];
  2829. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2830. //
  2831. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2832. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2833. // [params setValue:category forKey:@"category"];
  2834. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2835. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2836. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2837. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2838. // [params setValue:filter forKey:@"filter"];
  2839. // [params setValue:keyword forKey:@"keyword"];
  2840. //
  2841. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  2842. // if (alert) {
  2843. // [params setObject:@"Filter" forKey:kAction];
  2844. // }
  2845. // if ([Singleton sharedInstance].homeItemClick) {
  2846. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  2847. // [Singleton sharedInstance].homeItemClick = NO;
  2848. //
  2849. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  2850. // [Singleton sharedInstance].homeClickedItemName = nil;
  2851. // [params setObject:extra forKey:kExtra];
  2852. //
  2853. // }
  2854. //
  2855. //
  2856. // if(appDelegate.offline_mode)
  2857. // return [OLDataProvider offline_category:params];
  2858. // if(![self IsNetworkAvailable])
  2859. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2860. //
  2861. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  2862. // if(json==nil)
  2863. // return nil;
  2864. // NSError *error=nil;
  2865. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2866. // return jsobj;
  2867. //
  2868. //}
  2869. //+(NSDictionary*)Search_addall:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  2870. //{
  2871. //
  2872. //
  2873. //
  2874. //
  2875. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2876. // __block AppDelegate *appDelegate = nil;
  2877. //
  2878. // dispatch_sync(dispatch_get_main_queue(), ^{
  2879. // //some UI methods ej
  2880. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2881. // });
  2882. // if(appDelegate.user!=nil)
  2883. // [params setValue:appDelegate.user forKey:@"user"];
  2884. // if(appDelegate.contact_id!=nil)
  2885. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2886. // if(appDelegate.password!=nil)
  2887. // [params setValue:appDelegate.password forKey:@"password"];
  2888. // if(appDelegate.order_code!=nil)
  2889. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2890. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2891. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2892. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2893. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2894. // // [params setValue:filter forKey:@"filter"];
  2895. // [params setValue:keywords forKey:@"keyword"];
  2896. // [params setValue:addTo forKey:@"addTo"];
  2897. //
  2898. // [params setValue:orderCode forKey:@"orderCode"];
  2899. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2900. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2901. // if(matchfull)
  2902. // [params setValue:@"true" forKey:@"exactMatch"];
  2903. // else
  2904. // [params setValue:@"false" forKey:@"exactMatch"];
  2905. //
  2906. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  2907. // if ([addTo isEqualToString:@"cart"]) {
  2908. // [params setObject:@"Add To Cart" forKey:kAction];
  2909. // }
  2910. //
  2911. // NSData* json=nil;
  2912. // if(appDelegate.offline_mode)
  2913. // {
  2914. // json=[OLDataProvider offline_searchaddall:params];
  2915. // }
  2916. // else
  2917. // {
  2918. // if(![self IsNetworkAvailable])
  2919. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2920. //
  2921. // NSError *error=nil;
  2922. //
  2923. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2924. // params[@"resultSerial"]=uuid;
  2925. //
  2926. // for(int i=0;i<150;i++)
  2927. // {
  2928. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2929. // // result_params[@"resultSerial"]=uuid;
  2930. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  2931. // if(json!=nil)
  2932. // {
  2933. //
  2934. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2935. // if([jsobj[@"result"] intValue]==2)
  2936. // {
  2937. // break;
  2938. // }
  2939. // }
  2940. // sleep(2);
  2941. // }
  2942. // }
  2943. // if(json==nil)
  2944. // return nil;
  2945. // NSError *error=nil;
  2946. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2947. // return jsobj;
  2948. //
  2949. //}
  2950. //+(NSDictionary*)Search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull
  2951. //{
  2952. //
  2953. //
  2954. //
  2955. //
  2956. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2957. // __block AppDelegate *appDelegate = nil;
  2958. //
  2959. // dispatch_sync(dispatch_get_main_queue(), ^{
  2960. // //some UI methods ej
  2961. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2962. // });
  2963. // if(appDelegate.user!=nil)
  2964. // [params setValue:appDelegate.user forKey:@"user"];
  2965. // if(appDelegate.contact_id!=nil)
  2966. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2967. // if(appDelegate.password!=nil)
  2968. // [params setValue:appDelegate.password forKey:@"password"];
  2969. // if(appDelegate.order_code!=nil)
  2970. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2971. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2972. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2973. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2974. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2975. // // [params setValue:filter forKey:@"filter"];
  2976. // [params setValue:keywords forKey:@"keyword"];
  2977. //
  2978. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2979. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2980. // if(matchfull)
  2981. // [params setValue:@"true" forKey:@"exactMatch"];
  2982. // else
  2983. // [params setValue:@"false" forKey:@"exactMatch"];
  2984. //
  2985. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  2986. // if (keywords) {
  2987. // [params setObject:@"Search" forKey:kAction];
  2988. // }
  2989. //
  2990. // if(appDelegate.offline_mode)
  2991. // {
  2992. // return [OLDataProvider offline_search:params];
  2993. // }
  2994. // if(![self IsNetworkAvailable])
  2995. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2996. //
  2997. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  2998. // if(json==nil)
  2999. // return nil;
  3000. // NSError *error=nil;
  3001. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3002. // return jsobj;
  3003. //}
  3004. //+(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
  3005. //{
  3006. // // for debug
  3007. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3008. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3009. //
  3010. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3011. // __block AppDelegate *appDelegate = nil;
  3012. //
  3013. // dispatch_sync(dispatch_get_main_queue(), ^{
  3014. // //some UI methods ej
  3015. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3016. // });
  3017. // if(appDelegate.user!=nil)
  3018. // [params setValue:appDelegate.user forKey:@"user"];
  3019. // if(appDelegate.contact_id!=nil)
  3020. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3021. // if(appDelegate.password!=nil)
  3022. // [params setValue:appDelegate.password forKey:@"password"];
  3023. // if(appDelegate.order_code!=nil)
  3024. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3025. //
  3026. // [params setValue:addTo forKey:@"addTo"];
  3027. //
  3028. // [params setValue:orderCode forKey:@"orderCode"];
  3029. //
  3030. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3031. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3032. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3033. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3034. // // [params setValue:filter forKey:@"filter"];
  3035. // [params setValue:covertype forKey:@"covertype"];
  3036. // [params setValue:ctgid forKey:@"ctgId"];
  3037. // [params setValue:modelname forKey:@"modelName"];
  3038. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3039. // [params setValue:alert forKey:@"alert"];
  3040. // [params setValue:qty forKey:@"sold_by_qty"];
  3041. // [params setValue:available forKey:@"available"];
  3042. // [params setValue:price forKey:@"price"];
  3043. // [params setValue:bestseller forKey:@"bestseller"];
  3044. //
  3045. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3046. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3047. //
  3048. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3049. // if ([addTo isEqualToString:@"cart"]) {
  3050. // [params setObject:@"Add To Cart" forKey:kAction];
  3051. // }
  3052. //
  3053. // NSData* json = nil;
  3054. //
  3055. // if(appDelegate.offline_mode)
  3056. // {
  3057. // json= [OLDataProvider offline_itemsearchaddall:params];
  3058. // }
  3059. // else
  3060. // {
  3061. // if(![self IsNetworkAvailable])
  3062. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3063. // NSError *error=nil;
  3064. //
  3065. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3066. // params[@"resultSerial"]=uuid;
  3067. //
  3068. // for(int i=0;i<150;i++)
  3069. // {
  3070. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3071. // // result_params[@"resultSerial"]=uuid;
  3072. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  3073. // if(json!=nil)
  3074. // {
  3075. //
  3076. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3077. // if([jsobj[@"result"] intValue]==2)
  3078. // {
  3079. // break;
  3080. // }
  3081. // }
  3082. // sleep(2);
  3083. // }
  3084. // }
  3085. // if(json==nil)
  3086. // return nil;
  3087. // NSError *error=nil;
  3088. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3089. // return jsobj;
  3090. //}
  3091. //+(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
  3092. //{
  3093. //
  3094. // // for debug
  3095. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3096. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3097. //
  3098. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3099. // __block AppDelegate *appDelegate = nil;
  3100. //
  3101. // dispatch_sync(dispatch_get_main_queue(), ^{
  3102. // //some UI methods ej
  3103. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3104. // });
  3105. // if(appDelegate.user!=nil)
  3106. // [params setValue:appDelegate.user forKey:@"user"];
  3107. // if(appDelegate.contact_id!=nil)
  3108. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3109. // if(appDelegate.password!=nil)
  3110. // [params setValue:appDelegate.password forKey:@"password"];
  3111. // if(appDelegate.order_code!=nil)
  3112. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3113. //
  3114. //
  3115. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3116. // if (alert && qty && available && price && bestseller) {
  3117. // [params setObject:@"Filter" forKey:kAction];
  3118. // }
  3119. // if ([Singleton sharedInstance].homeItemClick) {
  3120. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  3121. // [Singleton sharedInstance].homeItemClick = NO;
  3122. //
  3123. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  3124. // [Singleton sharedInstance].homeClickedItemName = nil;
  3125. // [params setObject:extra forKey:kExtra];
  3126. // }
  3127. //
  3128. //
  3129. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3130. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3131. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3132. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3133. // // [params setValue:filter forKey:@"filter"];
  3134. // [params setValue:covertype forKey:@"covertype"];
  3135. // [params setValue:ctgid forKey:@"ctgId"];
  3136. // [params setValue:modelname forKey:@"modelName"];
  3137. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3138. // [params setValue:alert forKey:@"alert"];
  3139. // [params setValue:qty forKey:@"sold_by_qty"];
  3140. // [params setValue:available forKey:@"available"];
  3141. // [params setValue:price forKey:@"price"];
  3142. // [params setValue:bestseller forKey:@"bestseller"];
  3143. //
  3144. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3145. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3146. //
  3147. // if(appDelegate.offline_mode)
  3148. // {
  3149. // return [OLDataProvider offline_itemsearch:params];
  3150. // }
  3151. // if(![self IsNetworkAvailable])
  3152. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3153. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  3154. // if(json==nil)
  3155. // return nil;
  3156. // NSError *error=nil;
  3157. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3158. // return jsobj;
  3159. //}
  3160. //+(NSDictionary*)Search: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword
  3161. //{
  3162. // if(![self IsNetworkAvailable])
  3163. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3164. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3165. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3166. // if(appDelegate.user!=nil)
  3167. // [params setValue:appDelegate.user forKey:@"user"];
  3168. // if(appDelegate.contact_id!=nil)
  3169. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3170. // if(appDelegate.password!=nil)
  3171. // [params setValue:appDelegate.password forKey:@"password"];
  3172. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3173. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3174. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3175. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3176. // [params setValue:filter forKey:@"filter"];
  3177. // [params setValue:keyword forKey:@"keyword"];
  3178. //
  3179. //
  3180. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3181. // if(json==nil)
  3182. // return nil;
  3183. // NSError *error=nil;
  3184. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3185. // return jsobj;
  3186. //}
  3187. +(NSDictionary*)request_model_qty: (NSString*) fashionId
  3188. {
  3189. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3190. __block AppDelegate *appDelegate = nil;
  3191. dispatch_sync(dispatch_get_main_queue(), ^{
  3192. //some UI methods ej
  3193. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3194. });
  3195. if(appDelegate.user!=nil)
  3196. [params setValue:appDelegate.user forKey:@"user"];
  3197. if(appDelegate.contact_id!=nil)
  3198. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3199. if(appDelegate.password!=nil)
  3200. [params setValue:appDelegate.password forKey:@"password"];
  3201. [params setValue:fashionId forKey:@"fashionId"];
  3202. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  3203. NSData* json = nil;
  3204. if(appDelegate.offline_mode)
  3205. {
  3206. json = [OLDataProvider offline_model_qty:params];
  3207. } else {
  3208. if(![self IsNetworkAvailable])
  3209. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3210. json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  3211. }
  3212. if(json==nil)
  3213. return nil;
  3214. NSError *error=nil;
  3215. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3216. return jsobj;
  3217. }
  3218. +(NSDictionary*)retrieve_password: (NSString*) user email:(NSString*) email
  3219. {
  3220. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3221. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3222. // if(appDelegate.user!=nil)
  3223. // [params setValue:appDelegate.user forKey:@"user"];
  3224. // if(appDelegate.contact_id!=nil)
  3225. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3226. // if(appDelegate.password!=nil)
  3227. // [params setValue:appDelegate.password forKey:@"password"];
  3228. [params setValue:user forKey:@"username"];
  3229. [params setValue:email forKey:@"email"];
  3230. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3231. if(![self IsNetworkAvailable])
  3232. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3233. NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  3234. if(json==nil)
  3235. return nil;
  3236. NSError *error=nil;
  3237. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3238. return jsobj;
  3239. }
  3240. +(NSDictionary*)load_HomePage:(int) price_template customid:(int) customid
  3241. {
  3242. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3243. __block AppDelegate *appDelegate = nil;
  3244. dispatch_sync(dispatch_get_main_queue(), ^{
  3245. //some UI methods ej
  3246. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3247. });
  3248. if(appDelegate.user!=nil)
  3249. [params setValue:appDelegate.user forKey:@"user"];
  3250. if(appDelegate.contact_id!=nil)
  3251. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3252. if(appDelegate.password!=nil)
  3253. [params setValue:appDelegate.password forKey:@"password"];
  3254. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3255. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3256. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  3257. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3258. if(appDelegate.offline_mode)
  3259. {
  3260. //params[@"offline_Command"]=url;
  3261. return [OLDataProvider offline_home];
  3262. }
  3263. if(![self IsNetworkAvailable])
  3264. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3265. NSData* json=[self get_json:URL_LOAD_HOME parameters:params];
  3266. if(json==nil)
  3267. return nil;
  3268. NSError *error=nil;
  3269. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3270. return jsobj;
  3271. }
  3272. //+(NSDictionary*)logout
  3273. //{
  3274. //
  3275. //
  3276. //
  3277. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3278. // __block AppDelegate *appDelegate = nil;
  3279. //
  3280. // dispatch_sync(dispatch_get_main_queue(), ^{
  3281. // //some UI methods ej
  3282. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3283. // });
  3284. // if(appDelegate.user!=nil)
  3285. // [params setValue:appDelegate.user forKey:@"user"];
  3286. //
  3287. //
  3288. // if(appDelegate.password!=nil)
  3289. // [params setValue:appDelegate.password forKey:@"password"];
  3290. //
  3291. //
  3292. // if(appDelegate.offline_mode)
  3293. // {
  3294. // return [OLDataProvider offline_logout:params];
  3295. // }
  3296. // if(![self IsNetworkAvailable])
  3297. // {
  3298. // DebugLog(@"NET ERR");
  3299. //
  3300. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3301. // // return nil;
  3302. // }
  3303. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  3304. // //if(json==nil)
  3305. //
  3306. //
  3307. // if(json==nil)
  3308. // return nil;
  3309. // NSError *error=nil;
  3310. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3311. // int result = [[jsobj valueForKey:@"result"] intValue];
  3312. //
  3313. // if (result==2)
  3314. // {
  3315. //
  3316. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  3317. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  3318. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  3319. //
  3320. // [appDelegate update_count_mark];
  3321. //
  3322. //
  3323. // appDelegate.can_show_price =false;
  3324. // appDelegate.can_see_price =false;
  3325. // appDelegate.can_create_portfolio =false;
  3326. // appDelegate.can_create_order =false;
  3327. //
  3328. //
  3329. // appDelegate.can_cancel_order =false;
  3330. // appDelegate.can_set_cart_price =false;
  3331. // appDelegate.can_delete_order =false;
  3332. // appDelegate.can_submit_order =false;
  3333. // appDelegate.can_set_tearsheet_price =false;
  3334. // appDelegate.can_update_contact_info = false;
  3335. //
  3336. // appDelegate.save_order_logout = false;
  3337. // appDelegate.submit_order_logout = false;
  3338. // appDelegate.alert_sold_in_quantities = false;
  3339. //
  3340. // appDelegate.ipad_perm =nil ;
  3341. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  3342. // appDelegate.OrderFilter= nil;
  3343. // [appDelegate SetSo:nil];
  3344. // [appDelegate set_main_button_panel];
  3345. //#ifdef RA_NOTIFICATION
  3346. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  3347. //#endif
  3348. // }
  3349. // return jsobj;
  3350. //}
  3351. +(NSDictionary*)request_Cagegory
  3352. {
  3353. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  3354. __block AppDelegate *appDelegate = nil;
  3355. dispatch_sync(dispatch_get_main_queue(), ^{
  3356. //some UI methods ej
  3357. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3358. });
  3359. if(appDelegate.offline_mode)
  3360. {
  3361. //params[@"offline_Command"]=url;
  3362. return [OLDataProvider offline_category_menu];
  3363. }
  3364. if(![self IsNetworkAvailable])
  3365. {
  3366. DebugLog(@"NET ERR");
  3367. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3368. // return nil;
  3369. }
  3370. NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  3371. //if(json==nil)
  3372. if(json==nil)
  3373. return nil;
  3374. NSError *error=nil;
  3375. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3376. return jsobj;
  3377. }
  3378. +(int)Authorize : (NSString*) user password:(NSString*) password{
  3379. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  3380. // return RESULT_NET_ERROR;
  3381. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3382. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3383. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3384. __block AppDelegate *appDelegate = nil;
  3385. dispatch_sync(dispatch_get_main_queue(), ^{
  3386. //some UI methods ej
  3387. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3388. });
  3389. if(appDelegate.duid !=nil)
  3390. [params setValue:appDelegate.duid forKey:@"udid"];
  3391. [params setValue:@"handset_login" forKey:@"action"];
  3392. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  3393. [params setValue:user forKey:@"user"];
  3394. [params setValue:password forKey:@"password"];
  3395. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  3396. #ifdef TEST
  3397. [params setValue:@"true" forKey:@"is_debug"];
  3398. #else
  3399. [params setValue:@"false" forKey:@"is_debug"];
  3400. #endif
  3401. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3402. [params setObject:@"Login" forKey:kAction];
  3403. NSData* json= nil;
  3404. if(appDelegate.offline_mode)
  3405. {
  3406. json= [OLDataProvider offline_login:params] ;
  3407. }
  3408. else
  3409. {
  3410. if(![self IsNetworkAvailable])
  3411. return RESULT_NET_NOTAVAILABLE;
  3412. json =[self get_json:URL_UPDATE_AUTH parameters:params];
  3413. }
  3414. if(json==nil)
  3415. return RESULT_NET_ERROR;
  3416. int ret = [self parse_authinfo:json user:user password:password];
  3417. DebugLog(@"parse_authinfo return %d ",ret);
  3418. return ret;
  3419. }
  3420. +(NSDictionary*)update_customer_img: (NSString*) contactid img_url:(NSString*) url
  3421. {
  3422. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3423. __block AppDelegate *appDelegate = nil;
  3424. dispatch_sync(dispatch_get_main_queue(), ^{
  3425. //some UI methods ej
  3426. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3427. });
  3428. if(appDelegate.user!=nil)
  3429. [params setValue:appDelegate.user forKey:@"user"];
  3430. // if(appDelegate.contact_id!=nil)
  3431. if(appDelegate.password!=nil)
  3432. [params setValue:appDelegate.password forKey:@"password"];
  3433. [params setValue:contactid forKey:@"contactId"];
  3434. [params setValue:url forKey:@"business_card"];
  3435. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  3436. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  3437. if(appDelegate.offline_mode)
  3438. {
  3439. return [OLDataProvider offline_notimpl];
  3440. }
  3441. if(![self IsNetworkAvailable])
  3442. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3443. NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  3444. if(json==nil)
  3445. return nil;
  3446. NSError *error=nil;
  3447. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3448. return jsobj;
  3449. }
  3450. +(NSDictionary*)request_PendingOrder:(NSString *)contactid
  3451. {
  3452. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3453. __block AppDelegate *appDelegate = nil;
  3454. dispatch_sync(dispatch_get_main_queue(), ^{
  3455. //some UI methods ej
  3456. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3457. });
  3458. if(appDelegate.user!=nil)
  3459. [params setValue:appDelegate.user forKey:@"user"];
  3460. // if(appDelegate.contact_id!=nil)
  3461. if(appDelegate.password!=nil)
  3462. [params setValue:appDelegate.password forKey:@"password"];
  3463. [params setValue:contactid forKey:@"contactId"];
  3464. if(appDelegate.offline_mode)
  3465. {
  3466. return [OLDataProvider offline_notimpl];
  3467. }
  3468. if(![self IsNetworkAvailable])
  3469. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3470. NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  3471. if(json==nil)
  3472. return nil;
  3473. NSError *error=nil;
  3474. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3475. return jsobj;
  3476. }
  3477. //+(NSDictionary*)request_CustomerInfo:(NSString* ) contactid
  3478. //{
  3479. //
  3480. //
  3481. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3482. // __block AppDelegate *appDelegate = nil;
  3483. //
  3484. // dispatch_sync(dispatch_get_main_queue(), ^{
  3485. // //some UI methods ej
  3486. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3487. // });
  3488. // if(appDelegate.user!=nil)
  3489. // [params setValue:appDelegate.user forKey:@"user"];
  3490. // // if(appDelegate.contact_id!=nil)
  3491. //
  3492. // if(appDelegate.password!=nil)
  3493. // [params setValue:appDelegate.password forKey:@"password"];
  3494. // [params setValue:contactid forKey:@"contactId"];
  3495. //
  3496. // [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  3497. //
  3498. // if(appDelegate.offline_mode)
  3499. // return [OLDataProvider offline_contactinfo:params];
  3500. // if(![self IsNetworkAvailable])
  3501. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3502. //
  3503. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  3504. // if(json==nil)
  3505. // return nil;
  3506. // NSError *error=nil;
  3507. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3508. // return jsobj;
  3509. //
  3510. //}
  3511. +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
  3512. {
  3513. DebugLog(@"parse_authinfo");
  3514. NSError *error=nil;
  3515. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3516. if(jsobj)
  3517. {
  3518. __block AppDelegate *appDelegate = nil;
  3519. dispatch_sync(dispatch_get_main_queue(), ^{
  3520. //some UI methods ej
  3521. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3522. });
  3523. int result = [[jsobj valueForKey:@"result"] intValue];
  3524. if (result<0)
  3525. return result;
  3526. if(result!=AP_USER_AUTH&& result!=9)
  3527. {
  3528. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  3529. // [appDelegate Logout];
  3530. if(result==8)
  3531. {
  3532. return RESULT_LOGIN_DEVICE;
  3533. }
  3534. return RESULT_FALSE;
  3535. }
  3536. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  3537. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  3538. user=[objheader objectForKey:@"username"] ;
  3539. DebugLog(@"required_ver=%@ ",required_ver);
  3540. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  3541. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  3542. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  3543. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  3544. // if([ibadge isEqual:[NSNull null]])
  3545. // strbadge=@"0";
  3546. // if(ibadge==nil)
  3547. // ibadge=@"0";
  3548. // if([strbadge isEqualToString:@"null"])
  3549. // strbadge=@"0";
  3550. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  3551. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  3552. if([appDelegate.build intValue]<[required_ver intValue])
  3553. return RESULT_VER_LOW;
  3554. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  3555. appDelegate.user = user;
  3556. appDelegate.password = password;
  3557. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  3558. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  3559. appDelegate.bLogin = true;
  3560. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  3561. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  3562. {
  3563. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  3564. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  3565. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  3566. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  3567. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  3568. }
  3569. NSString* mode =[jsobj valueForKey:@"mode"] ;
  3570. [appDelegate SetMode:mode];
  3571. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  3572. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  3573. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  3574. [appDelegate update_count_mark];
  3575. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  3576. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  3577. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  3578. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  3579. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  3580. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  3581. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  3582. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  3583. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  3584. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  3585. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  3586. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  3587. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  3588. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  3589. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  3590. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  3591. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  3592. [appDelegate set_main_button_panel];
  3593. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  3594. // shop order status filter
  3595. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  3596. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  3597. // Sales order status filter
  3598. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  3599. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  3600. // specialInstruction
  3601. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  3602. //-价格类型
  3603. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  3604. // 权限
  3605. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  3606. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  3607. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  3608. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  3609. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  3610. [[RASingleton sharedInstance] resetGlobalLock];
  3611. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  3612. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  3613. }
  3614. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  3615. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  3616. // {
  3617. // // no update on the server;
  3618. // return RESULT_TRUE;
  3619. // }
  3620. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  3621. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3622. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3623. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3624. // [defaults synchronize];
  3625. //
  3626. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  3627. // NSArray* keys= [objfuncs allKeys];
  3628. /*
  3629. db.setTransactionSuccessful();
  3630. db.endTransaction();
  3631. */
  3632. return RESULT_TRUE;
  3633. }
  3634. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  3635. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  3636. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  3637. return RESULT_USERAUTH_ERROR;
  3638. }
  3639. //+(bool) IsNetworkAvailable
  3640. //{
  3641. //
  3642. // if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) &&
  3643. // ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable))
  3644. // return false;
  3645. // return true;
  3646. //}
  3647. //+(NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim
  3648. //{
  3649. // NSScanner *theScanner = [NSScanner scannerWithString:html];
  3650. // NSString *text = nil;
  3651. //
  3652. // while ([theScanner isAtEnd] == NO) {
  3653. // // find start of tag
  3654. // [theScanner scanUpToString:@"<" intoString:NULL] ;
  3655. // // find end of tag
  3656. // [theScanner scanUpToString:@">" intoString:&text] ;
  3657. // // replace the found tag with a space
  3658. // //(you can filter multi-spaces out later if you wish)
  3659. // html = [html stringByReplacingOccurrencesOfString:
  3660. // [ NSString stringWithFormat:@"%@>", text]
  3661. // withString:@""];
  3662. // }
  3663. //
  3664. // return trim ? [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : html;
  3665. //}
  3666. //
  3667. //+(NSString *)flattenURL:(NSString *)url trimWhiteSpace:(BOOL)trim
  3668. //{
  3669. // NSScanner *theScanner = [NSScanner scannerWithString:url];
  3670. // NSString *text = nil;
  3671. //
  3672. // while ([theScanner isAtEnd] == NO) {
  3673. // // find start of tag
  3674. // [theScanner scanUpToString:@"/" intoString:NULL] ;
  3675. // // find end of tag
  3676. // [theScanner scanUpToString:@"/" intoString:&text] ;
  3677. // // replace the found tag with a space
  3678. // //(you can filter multi-spaces out later if you wish)
  3679. // url = [url stringByReplacingOccurrencesOfString:
  3680. // [ NSString stringWithFormat:@"%@", text]
  3681. // withString:@""];
  3682. // }
  3683. //
  3684. // return trim ? [url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : url;
  3685. //}
  3686. + (NSDictionary *)set_npd_shop_price_type:(NSInteger)priceType {
  3687. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3688. __block AppDelegate *appDelegate = nil;
  3689. dispatch_sync(dispatch_get_main_queue(), ^{
  3690. //some UI methods ej
  3691. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3692. });
  3693. if(appDelegate.user!=nil)
  3694. [dic setValue:appDelegate.user forKey:@"user"];
  3695. if(appDelegate.password!=nil)
  3696. [dic setValue:appDelegate.password forKey:@"password"];
  3697. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  3698. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  3699. NSData* json=nil;
  3700. if(appDelegate.offline_mode)
  3701. {
  3702. return [OLDataProvider offline_notimpl];
  3703. }
  3704. else
  3705. {
  3706. if(![self IsNetworkAvailable])
  3707. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3708. json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  3709. }
  3710. if(json!=nil)
  3711. {
  3712. NSError *error=nil;
  3713. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3714. return jsobj;
  3715. }
  3716. return nil;
  3717. }
  3718. + (NSDictionary *)get_npd_shop_givenPrice {
  3719. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3720. __block AppDelegate *appDelegate = nil;
  3721. dispatch_sync(dispatch_get_main_queue(), ^{
  3722. //some UI methods ej
  3723. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3724. });
  3725. if(appDelegate.user!=nil)
  3726. [dic setValue:appDelegate.user forKey:@"user"];
  3727. if(appDelegate.password!=nil)
  3728. [dic setValue:appDelegate.password forKey:@"password"];
  3729. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  3730. NSData* json=nil;
  3731. if(appDelegate.offline_mode)
  3732. {
  3733. return [OLDataProvider offline_notimpl];
  3734. }
  3735. else
  3736. {
  3737. if(![self IsNetworkAvailable])
  3738. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3739. json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  3740. }
  3741. if(json!=nil)
  3742. {
  3743. NSError *error=nil;
  3744. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3745. return jsobj;
  3746. }
  3747. return nil;
  3748. }
  3749. + (NSDictionary *)set_npd_shop_givenPrice:(NSMutableDictionary *)params {
  3750. __block AppDelegate *appDelegate = nil;
  3751. dispatch_sync(dispatch_get_main_queue(), ^{
  3752. //some UI methods ej
  3753. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3754. });
  3755. if(appDelegate.user!=nil)
  3756. [params setValue:appDelegate.user forKey:@"user"];
  3757. if(appDelegate.password!=nil)
  3758. [params setValue:appDelegate.password forKey:@"password"];
  3759. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  3760. NSData* json=nil;
  3761. if(appDelegate.offline_mode)
  3762. {
  3763. return [OLDataProvider offline_notimpl];
  3764. }
  3765. else
  3766. {
  3767. if(![self IsNetworkAvailable])
  3768. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3769. json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  3770. }
  3771. if(json!=nil)
  3772. {
  3773. NSError *error=nil;
  3774. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3775. return jsobj;
  3776. }
  3777. return nil;
  3778. }
  3779. + (NSDictionary *)merge_order:(NSMutableDictionary *)params {
  3780. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3781. __block AppDelegate *appDelegate = nil;
  3782. dispatch_sync(dispatch_get_main_queue(), ^{
  3783. //some UI methods ej
  3784. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3785. });
  3786. if(appDelegate.user!=nil)
  3787. [dic setValue:appDelegate.user forKey:@"user"];
  3788. if(appDelegate.password!=nil)
  3789. [dic setValue:appDelegate.password forKey:@"password"];
  3790. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  3791. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  3792. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  3793. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  3794. NSData* json=nil;
  3795. if(appDelegate.offline_mode)
  3796. {
  3797. return [OLDataProvider offline_notimpl];
  3798. }
  3799. else
  3800. {
  3801. if(![self IsNetworkAvailable])
  3802. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3803. json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  3804. }
  3805. if(json!=nil)
  3806. {
  3807. NSError *error=nil;
  3808. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3809. return jsobj;
  3810. }
  3811. else
  3812. return nil;
  3813. }
  3814. //+ (NSDictionary *)lock_order:(NSString *)oderCode
  3815. //{
  3816. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3817. // __block AppDelegate *appDelegate = nil;
  3818. //
  3819. // dispatch_sync(dispatch_get_main_queue(), ^{
  3820. // //some UI methods ej
  3821. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3822. // });
  3823. // if(appDelegate.user!=nil)
  3824. // [params setValue:appDelegate.user forKey:@"user"];
  3825. //
  3826. // if(appDelegate.password!=nil)
  3827. // [params setValue:appDelegate.password forKey:@"password"];
  3828. //
  3829. // [params setValue:oderCode forKey:@"orderCode"];
  3830. //
  3831. // NSData* json=nil;
  3832. // if(appDelegate.offline_mode)
  3833. // {
  3834. // json=[OLDataProvider offline_editorder:params];
  3835. //
  3836. // }
  3837. // else
  3838. // {
  3839. // if(![self IsNetworkAvailable])
  3840. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3841. //
  3842. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  3843. // }
  3844. // if(json!=nil)
  3845. // {
  3846. // NSError *error=nil;
  3847. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3848. //
  3849. // return jsobj;
  3850. // }
  3851. // else
  3852. // return nil;
  3853. //}
  3854. + (NSDictionary *)quoteOrder:(NSString *)so_id emailAddr:(NSString *)addr {
  3855. NSMutableDictionary* dic = [[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.user!=nil)
  3862. [dic setValue:appDelegate.user forKey:@"user"];
  3863. if(appDelegate.password!=nil)
  3864. [dic setValue:appDelegate.password forKey:@"password"];
  3865. [dic setValue:so_id forKey:@"orderCode"];
  3866. [dic setValue:addr forKey:@"email"];
  3867. [dic setObject:ScreenCodeCart forKey:kScreenName];
  3868. if (appDelegate.customerInfo) {
  3869. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  3870. if (customer_cid) {
  3871. [dic setValue:customer_cid forKey:@"contactId"];
  3872. }
  3873. }
  3874. NSData* json=nil;
  3875. if(appDelegate.offline_mode)
  3876. {
  3877. return [OLDataProvider offline_notimpl];
  3878. }
  3879. else
  3880. {
  3881. if(![self IsNetworkAvailable])
  3882. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3883. json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  3884. }
  3885. if(json!=nil)
  3886. {
  3887. NSError *error=nil;
  3888. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3889. return jsobj;
  3890. }
  3891. return @{@"result" : @(RESULT_FALSE)};
  3892. }
  3893. + (NSDictionary *)notifyModel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName{
  3894. NSMutableDictionary* dic = [[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. [dic setValue:appDelegate.user forKey:@"user"];
  3902. if(appDelegate.password!=nil)
  3903. [dic setValue:appDelegate.password forKey:@"password"];
  3904. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  3905. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  3906. if (customer_cid) {
  3907. [dic setValue:customer_cid forKey:@"contactId"];
  3908. }
  3909. }
  3910. [dic setObject:screenName forKey:kScreenName];
  3911. [dic setValue:modelID forKey:@"productId"];
  3912. if (addr) { // 弹框输入
  3913. [dic setValue:addr forKey:@"email"];
  3914. } else {
  3915. // employee选择了Contact,并且Contact有Email
  3916. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  3917. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  3918. // if (email) {
  3919. // [dic setValue:email forKey:@"email"];
  3920. // }
  3921. // }
  3922. }
  3923. NSData* json=nil;
  3924. if(appDelegate.offline_mode)
  3925. {
  3926. return [OLDataProvider offline_notimpl];
  3927. }
  3928. else
  3929. {
  3930. if(![self IsNetworkAvailable])
  3931. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3932. json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  3933. }
  3934. if(json!=nil)
  3935. {
  3936. NSError *error=nil;
  3937. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3938. return jsobj;
  3939. }
  3940. return @{@"result" : @(RESULT_FALSE)};
  3941. }
  3942. + (NSDictionary *)quoteWishlist2EmailAddr:(NSString *)addr {
  3943. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3944. __block AppDelegate *appDelegate = nil;
  3945. dispatch_sync(dispatch_get_main_queue(), ^{
  3946. //some UI methods ej
  3947. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3948. });
  3949. if(appDelegate.user!=nil)
  3950. [dic setValue:appDelegate.user forKey:@"user"];
  3951. if(appDelegate.password!=nil)
  3952. [dic setValue:appDelegate.password forKey:@"password"];
  3953. [dic setValue:addr forKey:@"email"];
  3954. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  3955. // if (appDelegate.customerInfo) {
  3956. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  3957. // if (customer_cid) {
  3958. // [dic setValue:customer_cid forKey:@"contactId"];
  3959. // }
  3960. // }
  3961. NSData* json=nil;
  3962. if(appDelegate.offline_mode)
  3963. {
  3964. return [OLDataProvider offline_notimpl];
  3965. }
  3966. else
  3967. {
  3968. if(![self IsNetworkAvailable])
  3969. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3970. json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  3971. }
  3972. if(json!=nil)
  3973. {
  3974. NSError *error=nil;
  3975. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3976. return jsobj;
  3977. }
  3978. return @{@"result" : @(RESULT_FALSE)};
  3979. }
  3980. + (NSDictionary *)movetobackorder:(NSString *)cart_item_id {
  3981. if (cart_item_id == nil || cart_item_id.length < 1) {
  3982. return @{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"};
  3983. }
  3984. __block AppDelegate *appDelegate = nil;
  3985. dispatch_sync(dispatch_get_main_queue(), ^{
  3986. //some UI methods ej
  3987. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3988. });
  3989. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3990. if(appDelegate.user!=nil)
  3991. [dic setValue:appDelegate.user forKey:@"user"];
  3992. if(appDelegate.password!=nil)
  3993. [dic setValue:appDelegate.password forKey:@"password"];
  3994. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  3995. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  3996. [dic setObject:ScreenCodeCart forKey:kScreenName];
  3997. if(![self IsNetworkAvailable])
  3998. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3999. NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  4000. if(json!=nil)
  4001. {
  4002. NSError *error=nil;
  4003. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4004. return jsobj;
  4005. }
  4006. return @{@"result" : @(RESULT_FALSE)};
  4007. }
  4008. + (NSDictionary*)request_hangTag:(NSString *)group {
  4009. #ifdef BUILD_UWAVER
  4010. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4011. __block AppDelegate *appDelegate = nil;
  4012. dispatch_sync(dispatch_get_main_queue(), ^{
  4013. //some UI methods ej
  4014. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4015. });
  4016. if(appDelegate.user!=nil)
  4017. [params setValue:appDelegate.user forKey:@"user"];
  4018. if(appDelegate.contact_id!=nil)
  4019. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4020. if(appDelegate.password!=nil)
  4021. [params setValue:appDelegate.password forKey:@"password"];
  4022. if (group) {
  4023. [params setValue:group forKey:@"groupName"];
  4024. }
  4025. NSString * uuid= [[NSUUID UUID] UUIDString];
  4026. params[@"resultSerial"]=uuid;
  4027. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4028. NSData* json = nil;
  4029. if(appDelegate.offline_mode)
  4030. {
  4031. json = [OLDataProvider offline_notimpl];
  4032. } else {
  4033. if(![self IsNetworkAvailable])
  4034. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4035. json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  4036. }
  4037. if(json==nil)
  4038. return nil;
  4039. NSError *error=nil;
  4040. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4041. return jsobj;
  4042. #else
  4043. return nil;
  4044. #endif
  4045. }
  4046. #pragma mark 2020 new interface
  4047. // 新接口逐步替换以前的网络请求,2020
  4048. +(void)request_home:(int) price_template customid:(int) customid completionHandler:(resultHandler)result
  4049. {
  4050. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4051. AppDelegate *appDelegate = nil;
  4052. //some UI methods ej
  4053. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4054. if(appDelegate.user!=nil)
  4055. [params setValue:appDelegate.user forKey:@"user"];
  4056. if(appDelegate.contact_id!=nil)
  4057. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4058. if(appDelegate.password!=nil)
  4059. [params setValue:appDelegate.password forKey:@"password"];
  4060. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4061. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4062. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  4063. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4064. if(appDelegate.offline_mode)
  4065. {
  4066. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4067. NSMutableDictionary* json = [[OLDataProvider offline_home] mutableCopy];
  4068. dispatch_async(dispatch_get_main_queue(), ^{
  4069. result(json);
  4070. });
  4071. });
  4072. return;
  4073. }
  4074. [self request_interface:URL_LOAD_HOME parameters:params err_record_url:nil completionHandler:result retry:0];
  4075. return;
  4076. }
  4077. +(void)request_category:(resultHandler)result
  4078. {
  4079. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  4080. AppDelegate *appDelegate = nil;
  4081. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4082. if(appDelegate.offline_mode)
  4083. {
  4084. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4085. NSMutableDictionary* json = [[OLDataProvider offline_category_menu] mutableCopy];
  4086. dispatch_async(dispatch_get_main_queue(), ^{
  4087. result(json);
  4088. });
  4089. });
  4090. return;
  4091. }
  4092. [self request_interface:URL_REQUEST_CATMENU parameters:[NSMutableDictionary new] err_record_url:nil completionHandler:result retry:0];
  4093. //
  4094. // if(![self IsNetworkAvailable])
  4095. // {
  4096. // DebugLog(@"NET ERR");
  4097. //
  4098. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4099. // // return nil;
  4100. // }
  4101. //
  4102. // NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  4103. // //if(json==nil)
  4104. //
  4105. //
  4106. // if(json==nil)
  4107. // return nil;
  4108. // NSError *error=nil;
  4109. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4110. // return jsobj;
  4111. }
  4112. +(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
  4113. {
  4114. AppDelegate *appDelegate = nil;
  4115. //some UI methods ej
  4116. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4117. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4118. if(appDelegate.user!=nil)
  4119. [params setValue:appDelegate.user forKey:@"user"];
  4120. if(appDelegate.contact_id!=nil)
  4121. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4122. if(appDelegate.password!=nil)
  4123. [params setValue:appDelegate.password forKey:@"password"];
  4124. if(appDelegate.order_code!=nil)
  4125. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4126. [params setValue:alert forKey:@"alert"];
  4127. [params setValue:qty forKey:@"sold_by_qty"];
  4128. [params setValue:available forKey:@"available"];
  4129. [params setValue:price forKey:@"price"];
  4130. [params setValue:bestseller forKey:@"bestseller"];
  4131. [params setValue:modelname forKey:@"modelName"];
  4132. [params setValue:modeldescrip forKey:@"modelDescription"];
  4133. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4134. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4135. [params setValue:category forKey:@"category"];
  4136. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4137. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4138. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4139. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4140. [params setValue:filter forKey:@"filter"];
  4141. [params setValue:keyword forKey:@"keyword"];
  4142. [params setObject:ScreenCodeCategory forKey:kScreenName];
  4143. if (alert) {
  4144. [params setObject:@"Filter" forKey:kAction];
  4145. }
  4146. if ([RASingleton sharedInstance].homeItemClick) {
  4147. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  4148. [RASingleton sharedInstance].homeItemClick = NO;
  4149. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  4150. [RASingleton sharedInstance].homeClickedItemName = nil;
  4151. [params setObject:extra forKey:kExtra];
  4152. }
  4153. if(appDelegate.offline_mode)
  4154. {
  4155. // [OLDataProvider offline_category:params completionHandler:result];
  4156. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4157. NSMutableDictionary* json = [[OLDataProvider offline_category:params] mutableCopy];
  4158. dispatch_async(dispatch_get_main_queue(), ^{
  4159. result(json);
  4160. });
  4161. });
  4162. return;
  4163. }
  4164. [self request_interface:URL_CATEGORY parameters:params err_record_url:nil completionHandler:result retry:0];
  4165. return ;
  4166. //
  4167. // if(![self IsNetworkAvailable])
  4168. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4169. //
  4170. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  4171. // if(json==nil)
  4172. // return nil;
  4173. // NSError *error=nil;
  4174. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4175. // return jsobj;
  4176. //
  4177. }
  4178. +(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
  4179. {
  4180. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4181. AppDelegate *appDelegate = nil;
  4182. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4183. if(appDelegate.user!=nil)
  4184. [params setValue:appDelegate.user forKey:@"user"];
  4185. if(appDelegate.contact_id!=nil)
  4186. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4187. if(appDelegate.password!=nil)
  4188. [params setValue:appDelegate.password forKey:@"password"];
  4189. if(appDelegate.order_code!=nil)
  4190. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4191. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4192. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4193. if(use_name)
  4194. [params setValue:model_name forKey:@"product_name"];
  4195. else
  4196. if(use_upc){
  4197. params[@"search_upc"]=@true;
  4198. [params setValue:upc_code forKey:@"upc_code"];
  4199. }
  4200. else
  4201. [params setValue:item_id forKey:@"product_id"];
  4202. [params setValue:category_id forKey:@"category"];
  4203. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4204. [params setObject:@"Open A Model" forKey:kAction];
  4205. if (model_name) {
  4206. NSDictionary *extra = @{@"ModelName" : model_name};
  4207. [params setObject:extra forKey:kExtra];
  4208. }
  4209. if (groupName.length > 0) {
  4210. [params setObject:groupName forKey:@"groupName"];
  4211. }
  4212. if(appDelegate.offline_mode)
  4213. {
  4214. [OLDataProvider offline_model:params completionHandler:result];
  4215. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4216. // NSMutableDictionary* json = [[OLDataProvider offline_model:params] mutableCopy];
  4217. // dispatch_async(dispatch_get_main_queue(), ^{
  4218. // result(json);
  4219. // });
  4220. // });
  4221. return;
  4222. }
  4223. [self request_interface:URL_ITEM_DETAIL parameters:params err_record_url:nil completionHandler:result retry:0];
  4224. //
  4225. // if(appDelegate.offline_mode)
  4226. // return [OLDataProvider offline_model:params];
  4227. //
  4228. // if(![self IsNetworkAvailable])
  4229. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4230. //
  4231. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  4232. // if(json==nil)
  4233. // return nil;
  4234. // NSError *error=nil;
  4235. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4236. // return jsobj;
  4237. }
  4238. +(void)request_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull completionHandler:(resultHandler)result
  4239. {
  4240. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4241. AppDelegate *appDelegate = nil;
  4242. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4243. if(appDelegate.user!=nil)
  4244. [params setValue:appDelegate.user forKey:@"user"];
  4245. if(appDelegate.contact_id!=nil)
  4246. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4247. if(appDelegate.password!=nil)
  4248. [params setValue:appDelegate.password forKey:@"password"];
  4249. if(appDelegate.order_code!=nil)
  4250. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4251. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4252. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4253. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  4254. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4255. // [params setValue:filter forKey:@"filter"];
  4256. [params setValue:keywords forKey:@"keyword"];
  4257. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4258. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4259. if(matchfull)
  4260. [params setValue:@"true" forKey:@"exactMatch"];
  4261. else
  4262. [params setValue:@"false" forKey:@"exactMatch"];
  4263. [params setObject:ScreenCodeSearch forKey:kScreenName];
  4264. if (keywords) {
  4265. [params setObject:@"Search" forKey:kAction];
  4266. }
  4267. if(appDelegate.offline_mode)
  4268. {
  4269. // [OLDataProvider offline_search:params completionHandler:result];
  4270. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4271. NSMutableDictionary* json = [[OLDataProvider offline_search:params] mutableCopy];
  4272. dispatch_async(dispatch_get_main_queue(), ^{
  4273. result(json);
  4274. });
  4275. });
  4276. return;
  4277. }
  4278. [self request_interface:URL_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  4279. // if(appDelegate.offline_mode)
  4280. // {
  4281. // return [OLDataProvider offline_search:params];
  4282. // }
  4283. // if(![self IsNetworkAvailable])
  4284. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4285. //
  4286. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  4287. // if(json==nil)
  4288. // return nil;
  4289. // NSError *error=nil;
  4290. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4291. // return jsobj;
  4292. }
  4293. +(void)request_login: (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
  4294. {
  4295. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  4296. // return RESULT_NET_ERROR;
  4297. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4298. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4299. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4300. AppDelegate *appDelegate = nil;
  4301. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4302. if(appDelegate.duid !=nil)
  4303. [params setValue:appDelegate.duid forKey:@"udid"];
  4304. [params setValue:@"handset_login" forKey:@"action"];
  4305. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  4306. [params setValue:user forKey:@"user"];
  4307. [params setValue:password forKey:@"password"];
  4308. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  4309. #ifdef TEST
  4310. [params setValue:@"true" forKey:@"is_debug"];
  4311. #else
  4312. [params setValue:@"false" forKey:@"is_debug"];
  4313. #endif
  4314. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  4315. [params setObject:@"Login" forKey:kAction];
  4316. if(appDelegate.offline_mode)
  4317. {
  4318. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4319. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_login:params]] mutableCopy];
  4320. dispatch_async(dispatch_get_main_queue(), ^{
  4321. int ret = [self parse_logininfo:json user:user password:password] ;
  4322. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4323. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4324. result(retjson);
  4325. });
  4326. });
  4327. return;
  4328. }
  4329. NSString* url;
  4330. bool scan_guest = false;
  4331. #ifdef SCANNER_ORDER
  4332. params[@"site_name"]=[RADataProvider getSiteName];
  4333. params[@"_method"]=@"login";
  4334. url = [appDelegate.address stringByAppendingPathComponent:URL_UPDATE_AUTH];
  4335. if([user.uppercaseString isEqualToString:@"GUEST"]&&[password.uppercaseString isEqualToString:@"GUEST"])
  4336. scan_guest = true;
  4337. #else
  4338. url = URL_UPDATE_AUTH;
  4339. #endif
  4340. if(scan_guest)
  4341. {
  4342. [OLDataProvider realguestLogin];
  4343. // int ret = [self parse_logininfo:chresult user:user password:password] ;
  4344. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4345. retjson[@"result"]= [NSNumber numberWithInt:RESULT_TRUE];
  4346. result(retjson);
  4347. }
  4348. else
  4349. {
  4350. [self request_interface:url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *chresult) {
  4351. int ret = [self parse_logininfo:chresult user:user password:password] ;
  4352. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4353. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4354. result(retjson);
  4355. } retry:0];
  4356. }
  4357. //
  4358. // NSData* json= nil;
  4359. // if(appDelegate.offline_mode)
  4360. // {
  4361. // json= [OLDataProvider offline_login:params] ;
  4362. //
  4363. // }
  4364. // else
  4365. // {
  4366. // if(![self IsNetworkAvailable])
  4367. // return RESULT_NET_NOTAVAILABLE;
  4368. // json =[self get_json:URL_UPDATE_AUTH parameters:params];
  4369. //
  4370. // }
  4371. //
  4372. // if(json==nil)
  4373. // return RESULT_NET_ERROR;
  4374. //
  4375. // int ret = [self parse_authinfo:json user:user password:password];
  4376. // DebugLog(@"parse_authinfo return %d ",ret);
  4377. //
  4378. //
  4379. // return ret;
  4380. //
  4381. }
  4382. +(int)parse_logininfo : (NSMutableDictionary *) jsobj user:(NSString*) user password:(NSString*) password
  4383. {
  4384. // DebugLog(@"parse_authinfo");
  4385. // NSError *error=nil;
  4386. //
  4387. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4388. if(jsobj)
  4389. {
  4390. AppDelegate *appDelegate = nil;
  4391. //some UI methods ej
  4392. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4393. int result = [[jsobj valueForKey:@"result"] intValue];
  4394. if (result<0)
  4395. return result;
  4396. if(result!=AP_USER_AUTH&& result!=9)
  4397. {
  4398. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  4399. // [appDelegate Logout];
  4400. if(result==8)
  4401. {
  4402. return RESULT_LOGIN_DEVICE;
  4403. }
  4404. return RESULT_FALSE;
  4405. }
  4406. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  4407. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  4408. user=[objheader objectForKey:@"username"] ;
  4409. DebugLog(@"required_ver=%@ ",required_ver);
  4410. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  4411. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  4412. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  4413. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  4414. // if([ibadge isEqual:[NSNull null]])
  4415. // strbadge=@"0";
  4416. // if(ibadge==nil)
  4417. // ibadge=@"0";
  4418. // if([strbadge isEqualToString:@"null"])
  4419. // strbadge=@"0";
  4420. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  4421. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  4422. #ifndef SCANNER_ORDER
  4423. if([appDelegate.build intValue]<[required_ver intValue])
  4424. return RESULT_VER_LOW;
  4425. #endif
  4426. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  4427. appDelegate.user = user;
  4428. appDelegate.password = password;
  4429. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  4430. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  4431. appDelegate.bLogin = true;
  4432. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  4433. #ifdef SCANNER_ORDER
  4434. appDelegate.available_price_group = objheader[@"price_group"];
  4435. [RADataProvider default_price_group];
  4436. #endif
  4437. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  4438. {
  4439. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  4440. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  4441. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  4442. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  4443. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  4444. }
  4445. NSString* mode =[jsobj valueForKey:@"mode"] ;
  4446. [appDelegate SetMode:mode];
  4447. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  4448. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  4449. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  4450. [appDelegate update_count_mark];
  4451. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  4452. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  4453. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  4454. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  4455. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  4456. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  4457. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  4458. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  4459. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  4460. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  4461. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  4462. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  4463. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  4464. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  4465. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  4466. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  4467. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  4468. [appDelegate set_main_button_panel];
  4469. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  4470. // shop order status filter
  4471. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  4472. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  4473. // Sales order status filter
  4474. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  4475. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  4476. // specialInstruction
  4477. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  4478. //-价格类型
  4479. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  4480. // 权限
  4481. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  4482. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  4483. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  4484. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  4485. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  4486. [[RASingleton sharedInstance] resetGlobalLock];
  4487. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  4488. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  4489. }
  4490. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  4491. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  4492. // {
  4493. // // no update on the server;
  4494. // return RESULT_TRUE;
  4495. // }
  4496. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  4497. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4498. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4499. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4500. // [defaults synchronize];
  4501. //
  4502. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  4503. // NSArray* keys= [objfuncs allKeys];
  4504. /*
  4505. db.setTransactionSuccessful();
  4506. db.endTransaction();
  4507. */
  4508. return RESULT_TRUE;
  4509. }
  4510. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  4511. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  4512. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  4513. return RESULT_USERAUTH_ERROR;
  4514. }
  4515. +(void)request_contactlist:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams completionHandler:(resultHandler)result
  4516. {
  4517. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4518. if(upparams!=nil)
  4519. params = [upparams mutableCopy];
  4520. AppDelegate *appDelegate = nil;
  4521. //some UI methods ej
  4522. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4523. if(appDelegate.user!=nil)
  4524. [params setValue:appDelegate.user forKey:@"user"];
  4525. if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  4526. [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  4527. else
  4528. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4529. if(appDelegate.password!=nil)
  4530. [params setValue:appDelegate.password forKey:@"password"];
  4531. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  4532. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  4533. [params setValue:contact_type forKey:@"contactType"];
  4534. [params setValue:keywords forKey:@"keyword"];
  4535. [params setObject:ScreenCodeAccount forKey:kScreenName];
  4536. if (keywords) {
  4537. [params setObject:@"Search" forKey:kAction];
  4538. }
  4539. if (upparams) {
  4540. [params setObject:@"Advance Search" forKey:kAction];
  4541. }
  4542. NSString* url=nil;
  4543. if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  4544. url=URL_SHIPTO_LIST;
  4545. else
  4546. url=URL_CONTACT_LIST;
  4547. if(appDelegate.offline_mode)
  4548. {
  4549. [OLDataProvider offline_contactlist:params completionHandler:result];
  4550. return;
  4551. }
  4552. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  4553. //
  4554. // if(appDelegate.offline_mode)
  4555. // return [OLDataProvider offline_contactlist:params];
  4556. //
  4557. // if(![self IsNetworkAvailable])
  4558. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4559. //
  4560. // NSData* json=[self get_json:url parameters:params];
  4561. // if(json==nil)
  4562. // return nil;
  4563. // NSError *error=nil;
  4564. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4565. // return jsobj;
  4566. }
  4567. +(void)request_contactinfo:(NSString* ) contactid completionHandler:(resultHandler)result
  4568. {
  4569. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4570. AppDelegate *appDelegate = nil;
  4571. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4572. if(appDelegate.user!=nil)
  4573. [params setValue:appDelegate.user forKey:@"user"];
  4574. // if(appDelegate.contact_id!=nil)
  4575. if(appDelegate.password!=nil)
  4576. [params setValue:appDelegate.password forKey:@"password"];
  4577. [params setValue:contactid forKey:@"contactId"];
  4578. [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  4579. if(appDelegate.offline_mode)
  4580. {
  4581. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4582. // [OLDataProvider offline_contactinfo:params completionHandler:result] ;
  4583. // });
  4584. params[@"mode"]=appDelegate.mode;
  4585. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4586. NSMutableDictionary* json = [[OLDataProvider offline_contactinfo:params] mutableCopy];
  4587. dispatch_async(dispatch_get_main_queue(), ^{
  4588. result(json);
  4589. });
  4590. });
  4591. return;
  4592. }
  4593. [self request_interface:URL_CUSTOMER_INFO parameters:params err_record_url:nil completionHandler:result retry:0];
  4594. // if(appDelegate.offline_mode)
  4595. // return [OLDataProvider offline_contactinfo:params];
  4596. // if(![self IsNetworkAvailable])
  4597. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4598. //
  4599. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  4600. // if(json==nil)
  4601. // return nil;
  4602. // NSError *error=nil;
  4603. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4604. // return jsobj;
  4605. //
  4606. }
  4607. +(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  4608. {
  4609. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4610. AppDelegate *appDelegate = nil;
  4611. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4612. if(appDelegate.user!=nil)
  4613. [params setValue:appDelegate.user forKey:@"user"];
  4614. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  4615. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  4616. // else
  4617. if(appDelegate.contact_id!=nil)
  4618. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4619. if(appDelegate.password!=nil)
  4620. [params setValue:appDelegate.password forKey:@"password"];
  4621. if(appDelegate.order_code!=nil)
  4622. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4623. bool can_create_backorder=appDelegate.can_create_backorder;
  4624. // [params setValue:sourceid forKey:@"sourceid"];
  4625. // [params setValue:editor forKey:@"editor"];
  4626. DebugLog(@"request editor url:%@",request_url);
  4627. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  4628. {
  4629. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  4630. }
  4631. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  4632. {
  4633. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  4634. }
  4635. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  4636. {
  4637. [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  4638. }
  4639. else if([request_url isEqualToString:URL_CARTDELIVERY])
  4640. {
  4641. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  4642. }
  4643. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  4644. {
  4645. [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  4646. }
  4647. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  4648. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  4649. }
  4650. if(appDelegate.offline_mode)
  4651. {
  4652. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4653. NSData* json = nil;
  4654. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  4655. {
  4656. json= [OLDataProvider offline_createContact:params];
  4657. }
  4658. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  4659. {
  4660. json= [OLDataProvider offline_editContact:params];
  4661. }
  4662. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  4663. {
  4664. json= [OLDataProvider offline_contactAdvancedSearch:params];
  4665. }
  4666. else if([request_url isEqualToString:URL_CARTDELIVERY])
  4667. {
  4668. params[@"contact_id"]=params[@"contactId"];
  4669. params[@"can_create_backorder"]=@(can_create_backorder);
  4670. json= [OLDataProvider offline_placeorder:params];
  4671. }
  4672. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  4673. {
  4674. json= [OLDataProvider offline_addreditor:params];
  4675. }
  4676. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  4677. json = [OLDataProvider offline_createTearSheet:params];
  4678. }
  4679. dispatch_async(dispatch_get_main_queue(), ^{
  4680. if(json==nil)
  4681. result( [[OLDataProvider offline_notimpl] mutableCopy]);
  4682. else
  4683. result([[RAConvertor data2dict:json] mutableCopy]);
  4684. });
  4685. });
  4686. return;
  4687. }
  4688. else
  4689. {
  4690. if([request_url isEqualToString:URL_CARTDELIVERY])
  4691. {
  4692. NSString * uuid= [[NSUUID UUID] UUIDString];
  4693. params[@"resultSerial"]=uuid;
  4694. __block bool bbreak = false;
  4695. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4696. for(int i=0;i<150;i++)
  4697. {
  4698. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  4699. // result_params[@"resultSerial"]=uuid;
  4700. //json=[self get_json:request_url parameters:params];
  4701. if(bbreak)
  4702. break;
  4703. dispatch_async(dispatch_get_main_queue(), ^{
  4704. DebugLog(@"request cart delivery %d",i);
  4705. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  4706. if(resulti!=nil)
  4707. {
  4708. if([resulti[@"result"] intValue]==2 || [resulti[@"result"] intValue] == 8)
  4709. {
  4710. if(!bbreak) //此判断保证result只调用一次。
  4711. {
  4712. result(resulti);
  4713. DebugLog(@"result called at %d",i);
  4714. }
  4715. bbreak=true;
  4716. }
  4717. }
  4718. } retry:3];
  4719. });
  4720. // [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  4721. sleep(2);
  4722. }
  4723. });
  4724. }
  4725. else
  4726. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  4727. }
  4728. // if(json!=nil)
  4729. // {
  4730. // NSError *error=nil;
  4731. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4732. // return jsobj;
  4733. // }
  4734. // else
  4735. // return nil;
  4736. }
  4737. +(void)request_wishlist:(int)sort completionHandler:(resultHandler)result
  4738. {
  4739. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4740. AppDelegate *appDelegate = nil;
  4741. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4742. if(appDelegate.user!=nil)
  4743. [params setValue:appDelegate.user forKey:@"user"];
  4744. if(appDelegate.contact_id!=nil)
  4745. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4746. if(appDelegate.password!=nil)
  4747. [params setValue:appDelegate.password forKey:@"password"];
  4748. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  4749. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  4750. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  4751. [params setObject:ScreenCodeWishList forKey:kScreenName];
  4752. if(appDelegate.offline_mode)
  4753. {
  4754. [OLDataProvider offline_wishlist:params completionHandler:^(NSMutableDictionary *resulti) {
  4755. int result_code = [[resulti valueForKey:@"result"] intValue];
  4756. if (result_code==2)
  4757. {
  4758. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  4759. [appDelegate update_count_mark];;
  4760. result(resulti);
  4761. }
  4762. }];
  4763. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4764. // NSMutableDictionary* json = [[OLDataProvider offline_wishlist:params] mutableCopy];
  4765. // dispatch_async(dispatch_get_main_queue(), ^{
  4766. // result(json);
  4767. // });
  4768. // });
  4769. return;
  4770. }
  4771. [self request_interface:URL_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  4772. int result_code = [[resulti valueForKey:@"result"] intValue];
  4773. if (result_code==2)
  4774. {
  4775. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  4776. [appDelegate update_count_mark];;
  4777. result(resulti);
  4778. }
  4779. } retry:0];
  4780. // if(appDelegate.offline_mode)
  4781. // {
  4782. // return [OLDataProvider offline_wishlist:params];
  4783. // }
  4784. // if(![self IsNetworkAvailable])
  4785. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4786. //
  4787. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  4788. // if(json==nil)
  4789. // return nil;
  4790. // NSError *error=nil;
  4791. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4792. // int result = [[jsobj valueForKey:@"result"] intValue];
  4793. //
  4794. // if (result==2)
  4795. // {
  4796. //
  4797. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  4798. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  4799. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  4800. //
  4801. // [appDelegate update_count_mark];
  4802. // }
  4803. // return jsobj;
  4804. }
  4805. +(void)request_portfoliolist:(int)sort completionHandler:(resultHandler)result
  4806. {
  4807. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4808. AppDelegate *appDelegate = nil;
  4809. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4810. if(appDelegate.user!=nil)
  4811. [params setValue:appDelegate.user forKey:@"user"];
  4812. if(appDelegate.contact_id!=nil)
  4813. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4814. if(appDelegate.password!=nil)
  4815. [params setValue:appDelegate.password forKey:@"password"];
  4816. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  4817. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  4818. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  4819. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  4820. if(appDelegate.offline_mode)
  4821. {
  4822. params[@"user"]=appDelegate.user;
  4823. params[@"contact_id"]=appDelegate.contact_id;
  4824. params[@"can_see_price"]=@(appDelegate.can_see_price);
  4825. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4826. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_portfolioList:params]] mutableCopy];
  4827. dispatch_async(dispatch_get_main_queue(), ^{
  4828. if ([json[@"result"] intValue]==2)
  4829. {
  4830. appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  4831. [appDelegate update_count_mark];
  4832. }
  4833. result(json);
  4834. });
  4835. });
  4836. return;
  4837. }
  4838. [self request_interface:URL_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  4839. if ([resulti[@"result"] intValue]==2)
  4840. {
  4841. appDelegate.port_count =[[resulti valueForKey:@"count"] intValue];
  4842. [appDelegate update_count_mark];
  4843. }
  4844. result(resulti);
  4845. } retry:0];
  4846. // NSData* json = nil;
  4847. // if(appDelegate.offline_mode)
  4848. // {
  4849. // json = [OLDataProvider offline_portfolioList:params];
  4850. // } else {
  4851. // if(![self IsNetworkAvailable])
  4852. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4853. //
  4854. // json = [self get_json:URL_PORTFOLIO parameters:params];
  4855. // }
  4856. //
  4857. //
  4858. // if(json==nil)
  4859. // return nil;
  4860. // NSError *error=nil;
  4861. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4862. // int result = [[jsobj valueForKey:@"result"] intValue];
  4863. //
  4864. // if (result==2)
  4865. // {
  4866. //
  4867. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  4868. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  4869. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  4870. //
  4871. // [appDelegate update_count_mark];
  4872. // }
  4873. // return jsobj;
  4874. }
  4875. +(void)request_portfoliopdf:(int ) offset limit:(int)limit keywords:(NSString* ) keywords completionHandler:(resultHandler)result
  4876. {
  4877. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4878. AppDelegate *appDelegate = nil;
  4879. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4880. if(appDelegate.user!=nil)
  4881. [params setValue:appDelegate.user forKey:@"user"];
  4882. if(appDelegate.contact_id!=nil)
  4883. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4884. if(appDelegate.password!=nil)
  4885. [params setValue:appDelegate.password forKey:@"password"];
  4886. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4887. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4888. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  4889. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4890. // [params setValue:filter forKey:@"filter"];
  4891. [params setValue:keywords forKey:@"keyWord"];
  4892. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  4893. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  4894. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  4895. if (keywords) {
  4896. [params setObject:@"Search" forKey:kAction];
  4897. }
  4898. if(appDelegate.offline_mode)
  4899. {
  4900. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4901. NSData* json = [[OLDataProvider offline_pdfList:params] mutableCopy];
  4902. dispatch_async(dispatch_get_main_queue(), ^{
  4903. result([[RAConvertor data2dict:json] mutableCopy]);
  4904. });
  4905. });
  4906. return;
  4907. }
  4908. [self request_interface:URL_DM_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  4909. return;
  4910. // NSData* json = nil;
  4911. // if(appDelegate.offline_mode)
  4912. // {
  4913. // json = [OLDataProvider offline_pdfList:params];
  4914. // } else {
  4915. // if(![self IsNetworkAvailable])
  4916. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4917. //
  4918. // json=[self get_json:URL_DM_LIST parameters:params];
  4919. // }
  4920. // if(json==nil)
  4921. // return nil;
  4922. // NSError *error=nil;
  4923. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4924. // return jsobj;
  4925. }
  4926. +(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
  4927. {
  4928. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4929. AppDelegate *appDelegate = nil;
  4930. //some UI methods ej
  4931. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4932. if(appDelegate.user!=nil)
  4933. [params setValue:appDelegate.user forKey:@"user"];
  4934. if(appDelegate.contact_id!=nil)
  4935. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4936. if(appDelegate.password!=nil)
  4937. [params setValue:appDelegate.password forKey:@"password"];
  4938. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  4939. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  4940. [params setValue:keywords forKey:@"keyWord"];
  4941. [params setValue:customer forKey:@"customer_filter"];
  4942. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  4943. [params setValue:status_code forKey:@"orderStatus"];
  4944. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  4945. if (keywords) {
  4946. [params setObject:@"Search" forKey:kAction];
  4947. }
  4948. if(appDelegate.offline_mode)
  4949. {
  4950. params[@"user"]=appDelegate.user;
  4951. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4952. NSData* json = [[OLDataProvider offline_orderlist:params] mutableCopy];
  4953. dispatch_async(dispatch_get_main_queue(), ^{
  4954. result([[RAConvertor data2dict:json] mutableCopy]);
  4955. });
  4956. });
  4957. return;
  4958. }
  4959. [self request_interface:URL_ORDER_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  4960. // NSData* json=nil;
  4961. // if(appDelegate.offline_mode)
  4962. // {
  4963. // json= [OLDataProvider offline_orderlist:params];
  4964. // }
  4965. // else
  4966. // {
  4967. // if(![self IsNetworkAvailable])
  4968. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4969. //
  4970. // json=[self get_json:URL_ORDER_LIST parameters:params];
  4971. // }
  4972. // if(json==nil)
  4973. // return nil;
  4974. // NSError *error=nil;
  4975. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4976. // return jsobj;
  4977. }
  4978. +(void)request_logout:(resultHandler)result
  4979. {
  4980. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4981. AppDelegate *appDelegate = nil;
  4982. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4983. if(appDelegate.user!=nil)
  4984. [params setValue:appDelegate.user forKey:@"user"];
  4985. if(appDelegate.password!=nil)
  4986. [params setValue:appDelegate.password forKey:@"password"];
  4987. if(appDelegate.offline_mode)
  4988. {
  4989. [OLDataProvider offline_logout:params completionHandler:result];
  4990. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4991. // NSMutableDictionary* json = [[OLDataProvider offline_logout:params] mutableCopy];
  4992. // dispatch_async(dispatch_get_main_queue(), ^{
  4993. // result(json);
  4994. // });
  4995. // });
  4996. return;
  4997. }
  4998. [self request_interface:URL_LOGOUT parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  4999. NSMutableDictionary* jsobj=resulti;
  5000. int result_code = [[jsobj valueForKey:@"result"] intValue];
  5001. if (result_code==2)
  5002. {
  5003. appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  5004. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5005. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5006. [appDelegate update_count_mark];
  5007. appDelegate.can_show_price =false;
  5008. appDelegate.can_see_price =false;
  5009. appDelegate.can_create_portfolio =false;
  5010. appDelegate.can_create_order =false;
  5011. appDelegate.can_cancel_order =false;
  5012. appDelegate.can_set_cart_price =false;
  5013. appDelegate.can_delete_order =false;
  5014. appDelegate.can_submit_order =false;
  5015. appDelegate.can_set_tearsheet_price =false;
  5016. appDelegate.can_update_contact_info = false;
  5017. appDelegate.save_order_logout = false;
  5018. appDelegate.submit_order_logout = false;
  5019. appDelegate.alert_sold_in_quantities = false;
  5020. appDelegate.ipad_perm =nil ;
  5021. appDelegate.user_type = USER_ROLE_UNKNOWN;
  5022. appDelegate.OrderFilter= nil;
  5023. [appDelegate SetSo:nil];
  5024. [appDelegate set_main_button_panel];
  5025. #ifdef RA_NOTIFICATION
  5026. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5027. #endif
  5028. }
  5029. result(resulti);
  5030. } retry:0];
  5031. //
  5032. // if(appDelegate.offline_mode)
  5033. // {
  5034. // return [OLDataProvider offline_logout:params];
  5035. // }
  5036. // if(![self IsNetworkAvailable])
  5037. // {
  5038. // DebugLog(@"NET ERR");
  5039. //
  5040. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5041. // // return nil;
  5042. // }
  5043. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  5044. // //if(json==nil)
  5045. //
  5046. //
  5047. // if(json==nil)
  5048. // return nil;
  5049. // NSError *error=nil;
  5050. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5051. // int result = [[jsobj valueForKey:@"result"] intValue];
  5052. //
  5053. // if (result==2)
  5054. // {
  5055. //
  5056. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  5057. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5058. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5059. //
  5060. // [appDelegate update_count_mark];
  5061. //
  5062. //
  5063. // appDelegate.can_show_price =false;
  5064. // appDelegate.can_see_price =false;
  5065. // appDelegate.can_create_portfolio =false;
  5066. // appDelegate.can_create_order =false;
  5067. //
  5068. //
  5069. // appDelegate.can_cancel_order =false;
  5070. // appDelegate.can_set_cart_price =false;
  5071. // appDelegate.can_delete_order =false;
  5072. // appDelegate.can_submit_order =false;
  5073. // appDelegate.can_set_tearsheet_price =false;
  5074. // appDelegate.can_update_contact_info = false;
  5075. //
  5076. // appDelegate.save_order_logout = false;
  5077. // appDelegate.submit_order_logout = false;
  5078. // appDelegate.alert_sold_in_quantities = false;
  5079. //
  5080. // appDelegate.ipad_perm =nil ;
  5081. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  5082. // appDelegate.OrderFilter= nil;
  5083. // [appDelegate SetSo:nil];
  5084. // [appDelegate set_main_button_panel];
  5085. //#ifdef RA_NOTIFICATION
  5086. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5087. //#endif
  5088. // }
  5089. // return jsobj;
  5090. }
  5091. + (void)request_hangtag:(NSString *)group completionHandler:(resultHandler)result
  5092. {
  5093. #ifdef BUILD_UWAVER
  5094. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5095. AppDelegate *appDelegate = nil;
  5096. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5097. if(appDelegate.user!=nil)
  5098. [params setValue:appDelegate.user forKey:@"user"];
  5099. if(appDelegate.contact_id!=nil)
  5100. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5101. if(appDelegate.password!=nil)
  5102. [params setValue:appDelegate.password forKey:@"password"];
  5103. if (group) {
  5104. [params setValue:group forKey:@"groupName"];
  5105. }
  5106. NSString * uuid= [[NSUUID UUID] UUIDString];
  5107. params[@"resultSerial"]=uuid;
  5108. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  5109. if(appDelegate.offline_mode)
  5110. {
  5111. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5112. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5113. dispatch_async(dispatch_get_main_queue(), ^{
  5114. result(json);
  5115. });
  5116. });
  5117. return;
  5118. }
  5119. [self request_interface:URL_CREATE_HANG_TAG parameters:params err_record_url:nil completionHandler:result retry:0];
  5120. // NSData* json = nil;
  5121. // if(appDelegate.offline_mode)
  5122. // {
  5123. // json = [OLDataProvider offline_portfolioList:params];
  5124. // } else {
  5125. // if(![self IsNetworkAvailable])
  5126. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5127. //
  5128. // json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  5129. // }
  5130. //
  5131. //
  5132. // if(json==nil)
  5133. // return nil;
  5134. // NSError *error=nil;
  5135. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5136. //
  5137. // return jsobj;
  5138. #else
  5139. return result(nil);
  5140. #endif
  5141. }
  5142. + (void)request_movetobackorder:(NSString *)cart_item_id completionHandler:(resultHandler)result
  5143. {
  5144. if (cart_item_id == nil || cart_item_id.length < 1) {
  5145. result([@{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"} mutableCopy]);
  5146. }
  5147. AppDelegate *appDelegate = nil;
  5148. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5149. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5150. if(appDelegate.user!=nil)
  5151. [dic setValue:appDelegate.user forKey:@"user"];
  5152. if(appDelegate.password!=nil)
  5153. [dic setValue:appDelegate.password forKey:@"password"];
  5154. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  5155. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  5156. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5157. if(appDelegate.offline_mode)
  5158. {
  5159. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5160. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5161. dispatch_async(dispatch_get_main_queue(), ^{
  5162. result(json);
  5163. });
  5164. });
  5165. return;
  5166. }
  5167. [self request_interface:URL_MOVE_TO_BACK_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5168. // if(![self IsNetworkAvailable])
  5169. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5170. //
  5171. // NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  5172. //
  5173. // if(json!=nil)
  5174. // {
  5175. // NSError *error=nil;
  5176. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5177. //
  5178. // return jsobj;
  5179. // }
  5180. //
  5181. // return @{@"result" : @(RESULT_FALSE)};
  5182. }
  5183. + (void)request_emailwishlist:(NSString *)addr completionHandler:(resultHandler)result
  5184. {
  5185. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5186. AppDelegate *appDelegate = nil;
  5187. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5188. if(appDelegate.user!=nil)
  5189. [dic setValue:appDelegate.user forKey:@"user"];
  5190. if(appDelegate.password!=nil)
  5191. [dic setValue:appDelegate.password forKey:@"password"];
  5192. [dic setValue:addr forKey:@"email"];
  5193. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  5194. // if (appDelegate.customerInfo) {
  5195. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5196. // if (customer_cid) {
  5197. // [dic setValue:customer_cid forKey:@"contactId"];
  5198. // }
  5199. // }
  5200. if(appDelegate.offline_mode)
  5201. {
  5202. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5203. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5204. dispatch_async(dispatch_get_main_queue(), ^{
  5205. result(json);
  5206. });
  5207. });
  5208. return;
  5209. }
  5210. [self request_interface:URL_EMAIL_WISHLIST parameters:dic err_record_url:nil completionHandler:result retry:0];
  5211. // NSData* json=nil;
  5212. // if(appDelegate.offline_mode)
  5213. // {
  5214. // return [OLDataProvider offline_notimpl];
  5215. // }
  5216. // else
  5217. // {
  5218. // if(![self IsNetworkAvailable])
  5219. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5220. //
  5221. // json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  5222. // }
  5223. // if(json!=nil)
  5224. // {
  5225. // NSError *error=nil;
  5226. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5227. //
  5228. //
  5229. // return jsobj;
  5230. // }
  5231. //
  5232. // return @{@"result" : @(RESULT_FALSE)};
  5233. }
  5234. +(void)request_notifymodel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  5235. {
  5236. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5237. AppDelegate *appDelegate = nil;
  5238. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5239. if(appDelegate.user!=nil)
  5240. [dic setValue:appDelegate.user forKey:@"user"];
  5241. if(appDelegate.password!=nil)
  5242. [dic setValue:appDelegate.password forKey:@"password"];
  5243. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5244. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5245. if (customer_cid) {
  5246. [dic setValue:customer_cid forKey:@"contactId"];
  5247. }
  5248. }
  5249. [dic setObject:screenName forKey:kScreenName];
  5250. [dic setValue:modelID forKey:@"productId"];
  5251. if (addr) { // 弹框输入
  5252. [dic setValue:addr forKey:@"email"];
  5253. } else {
  5254. // employee选择了Contact,并且Contact有Email
  5255. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5256. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  5257. // if (email) {
  5258. // [dic setValue:email forKey:@"email"];
  5259. // }
  5260. // }
  5261. }
  5262. if(appDelegate.offline_mode)
  5263. {
  5264. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5265. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5266. dispatch_async(dispatch_get_main_queue(), ^{
  5267. result(json);
  5268. });
  5269. });
  5270. return;
  5271. }
  5272. [self request_interface:URL_NOTIFY_ME parameters:dic err_record_url:nil completionHandler:result retry:0];
  5273. // NSData* json=nil;
  5274. // if(appDelegate.offline_mode)
  5275. // {
  5276. // return [OLDataProvider offline_notimpl];
  5277. // }
  5278. // else
  5279. // {
  5280. // if(![self IsNetworkAvailable])
  5281. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5282. //
  5283. // json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  5284. // }
  5285. // if(json!=nil)
  5286. // {
  5287. // NSError *error=nil;
  5288. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5289. //
  5290. //
  5291. // return jsobj;
  5292. // }
  5293. //
  5294. // return @{@"result" : @(RESULT_FALSE)};
  5295. }
  5296. + (void)request_qouteorder:(NSString *)so_id emailAddr:(NSString *)addr completionHandler:(resultHandler)result
  5297. {
  5298. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5299. AppDelegate *appDelegate = nil;
  5300. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5301. if(appDelegate.user!=nil)
  5302. [dic setValue:appDelegate.user forKey:@"user"];
  5303. if(appDelegate.password!=nil)
  5304. [dic setValue:appDelegate.password forKey:@"password"];
  5305. [dic setValue:so_id forKey:@"orderCode"];
  5306. [dic setValue:addr forKey:@"email"];
  5307. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5308. if (appDelegate.customerInfo) {
  5309. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5310. if (customer_cid) {
  5311. [dic setValue:customer_cid forKey:@"contactId"];
  5312. }
  5313. }
  5314. if(appDelegate.offline_mode)
  5315. {
  5316. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5317. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5318. dispatch_async(dispatch_get_main_queue(), ^{
  5319. result(json);
  5320. });
  5321. });
  5322. return;
  5323. }
  5324. [self request_interface:URL_EMAIL_CART parameters:dic err_record_url:nil completionHandler:result retry:0];
  5325. // NSData* json=nil;
  5326. // if(appDelegate.offline_mode)
  5327. // {
  5328. // return [OLDataProvider offline_notimpl];
  5329. // }
  5330. // else
  5331. // {
  5332. // if(![self IsNetworkAvailable])
  5333. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5334. //
  5335. // json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  5336. // }
  5337. // if(json!=nil)
  5338. // {
  5339. // NSError *error=nil;
  5340. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5341. //
  5342. //
  5343. // return jsobj;
  5344. // }
  5345. //
  5346. // return @{@"result" : @(RESULT_FALSE)};
  5347. }
  5348. + (void)request_mergeorder:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  5349. {
  5350. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5351. AppDelegate *appDelegate = nil;
  5352. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5353. if(appDelegate.user!=nil)
  5354. [dic setValue:appDelegate.user forKey:@"user"];
  5355. if(appDelegate.password!=nil)
  5356. [dic setValue:appDelegate.password forKey:@"password"];
  5357. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  5358. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  5359. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  5360. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  5361. if(appDelegate.offline_mode)
  5362. {
  5363. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5364. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5365. dispatch_async(dispatch_get_main_queue(), ^{
  5366. result(json);
  5367. });
  5368. });
  5369. return;
  5370. }
  5371. [self request_interface:URL_SET_MERGE_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5372. // NSData* json=nil;
  5373. // if(appDelegate.offline_mode)
  5374. // {
  5375. // return [OLDataProvider offline_notimpl];
  5376. // }
  5377. // else
  5378. // {
  5379. // if(![self IsNetworkAvailable])
  5380. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5381. //
  5382. // json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  5383. // }
  5384. // if(json!=nil)
  5385. // {
  5386. // NSError *error=nil;
  5387. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5388. //
  5389. //
  5390. // return jsobj;
  5391. // }
  5392. // else
  5393. // return nil;
  5394. }
  5395. +(void)request_pendingorder:(NSString *)contactid completionHandler:(resultHandler)result
  5396. {
  5397. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5398. AppDelegate *appDelegate = nil;
  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. if(appDelegate.password!=nil)
  5404. [params setValue:appDelegate.password forKey:@"password"];
  5405. [params setValue:contactid forKey:@"contactId"];
  5406. if(appDelegate.offline_mode)
  5407. {
  5408. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5409. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5410. dispatch_async(dispatch_get_main_queue(), ^{
  5411. result(json);
  5412. });
  5413. });
  5414. return;
  5415. }
  5416. [self request_interface:URL_CUSTOMER_PENDINGORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  5417. //
  5418. // if(appDelegate.offline_mode)
  5419. // {
  5420. // return [OLDataProvider offline_notimpl];
  5421. // }
  5422. // if(![self IsNetworkAvailable])
  5423. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5424. //
  5425. // NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  5426. // if(json==nil)
  5427. // return nil;
  5428. // NSError *error=nil;
  5429. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5430. // return jsobj;
  5431. //
  5432. }
  5433. +(void) request_removeportfolio:(NSString* ) item_ids completionHandler:(resultHandler)result
  5434. {
  5435. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5436. AppDelegate *appDelegate = nil;
  5437. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5438. if(appDelegate.user!=nil)
  5439. [params setValue:appDelegate.user forKey:@"user"];
  5440. if(appDelegate.contact_id!=nil)
  5441. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5442. if(appDelegate.password!=nil)
  5443. [params setValue:appDelegate.password forKey:@"password"];
  5444. [params setValue:item_ids forKey:@"portfolioId"];
  5445. // [params setValue:editor forKey:@"editor"];
  5446. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  5447. if(appDelegate.offline_mode)
  5448. {
  5449. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5450. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_removePortfolio:params]] mutableCopy];
  5451. dispatch_async(dispatch_get_main_queue(), ^{
  5452. int result_code = [[resulti valueForKey:@"result"] intValue];
  5453. if (result_code==2)
  5454. {
  5455. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5456. [appDelegate update_count_mark];
  5457. };
  5458. result(resulti);
  5459. });
  5460. });
  5461. return;
  5462. }
  5463. [self request_interface:URL_PORTFOLIO_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5464. int result_code = [[resulti valueForKey:@"result"] intValue];
  5465. if (result_code==2)
  5466. {
  5467. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5468. [appDelegate update_count_mark];
  5469. };
  5470. result(resulti);
  5471. } retry:0];
  5472. // NSData* json = nil;
  5473. // if(appDelegate.offline_mode)
  5474. // {
  5475. // json = [OLDataProvider offline_removePortfolio:params];
  5476. // } else {
  5477. // if(![self IsNetworkAvailable])
  5478. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5479. // json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  5480. // }
  5481. // if(json!=nil)
  5482. // {
  5483. // NSError *error=nil;
  5484. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5485. //
  5486. //
  5487. // int result = [[jsobj valueForKey:@"result"] intValue];
  5488. //
  5489. // if (result==2)
  5490. // {
  5491. //
  5492. //
  5493. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5494. //
  5495. // [appDelegate update_count_mark];
  5496. // }
  5497. // return jsobj;
  5498. // }
  5499. // else
  5500. // return nil;
  5501. }
  5502. +(void) request_removeportfoliopdf:(NSString* ) listid completionHandler:(resultHandler)result
  5503. {
  5504. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5505. AppDelegate *appDelegate = nil;
  5506. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5507. if(appDelegate.user!=nil)
  5508. [params setValue:appDelegate.user forKey:@"user"];
  5509. if(appDelegate.contact_id!=nil)
  5510. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5511. if(appDelegate.password!=nil)
  5512. [params setValue:appDelegate.password forKey:@"password"];
  5513. [params setValue:listid forKey:@"tearsheetsId"];
  5514. // [params setValue:editor forKey:@"editor"];
  5515. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  5516. // [params setValue:@"Delete Portfolio" forKey:kAction];
  5517. if(appDelegate.offline_mode)
  5518. {
  5519. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5520. NSData* json = [[OLDataProvider offline_removePDF:params] mutableCopy];
  5521. dispatch_async(dispatch_get_main_queue(), ^{
  5522. result([[RAConvertor data2dict:json] mutableCopy]);
  5523. });
  5524. });
  5525. return;
  5526. }
  5527. [self request_interface:URL_PORTFOLIOLIST_REMOVE parameters:params err_record_url:nil completionHandler:result retry:0];
  5528. }
  5529. +(void) request_remove_wishlist:(NSString* ) item_ids completionHandler:(resultHandler)result
  5530. {
  5531. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5532. __block AppDelegate *appDelegate = nil;
  5533. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5534. if(appDelegate.user!=nil)
  5535. [params setValue:appDelegate.user forKey:@"user"];
  5536. if(appDelegate.contact_id!=nil)
  5537. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5538. if(appDelegate.password!=nil)
  5539. [params setValue:appDelegate.password forKey:@"password"];
  5540. [params setValue:item_ids forKey:@"collectId"];
  5541. // [params setValue:editor forKey:@"editor"];
  5542. [params setValue:ScreenCodeWishList forKey:kScreenName];
  5543. if(appDelegate.offline_mode)
  5544. {
  5545. // [OLDataProvider offline_deletewishlist:params completionHandler:result];
  5546. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5547. NSMutableDictionary* resulti = [[OLDataProvider offline_deletewishlist:params] mutableCopy];
  5548. dispatch_async(dispatch_get_main_queue(), ^{
  5549. int result_code = [[resulti valueForKey:@"result"] intValue];
  5550. if (result_code==2)
  5551. {
  5552. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  5553. [appDelegate update_count_mark];
  5554. };
  5555. result(resulti);
  5556. });
  5557. });
  5558. return;
  5559. }
  5560. [self request_interface:URL_WATCHLIST_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5561. int result_code = [[resulti valueForKey:@"result"] intValue];
  5562. if (result_code==2)
  5563. {
  5564. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  5565. [appDelegate update_count_mark];
  5566. };
  5567. result(resulti);
  5568. } retry:0];
  5569. //
  5570. //
  5571. // if(appDelegate.offline_mode)
  5572. // {
  5573. // return [OLDataProvider offline_deletewishlist:params];
  5574. // }
  5575. // if(![self IsNetworkAvailable])
  5576. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5577. //
  5578. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  5579. // if(json!=nil)
  5580. // {
  5581. // NSError *error=nil;
  5582. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5583. // int result = [[jsobj valueForKey:@"result"] intValue];
  5584. //
  5585. // if (result==2)
  5586. // {
  5587. //
  5588. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5589. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  5590. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5591. //
  5592. // [appDelegate update_count_mark];
  5593. // }
  5594. // return jsobj;
  5595. // }
  5596. // else
  5597. // return nil;
  5598. }
  5599. +(void) request_remove_cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  5600. {
  5601. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5602. AppDelegate *appDelegate = nil;
  5603. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5604. #ifdef SCANNER_ORDER
  5605. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  5606. {
  5607. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  5608. //
  5609. //
  5610. // [appDelegate update_count_mark];
  5611. NSArray* arr=[RAConvertor string2arr:item_ids separator:@","];
  5612. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  5613. NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  5614. NSMutableDictionary* newsection =[cartTemplate[@"section_0"] mutableCopy];
  5615. int newcount = 0;
  5616. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  5617. int count = [section[@"count"] intValue];
  5618. for(int i=0;i<count;i++)
  5619. {
  5620. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  5621. int index = [arr indexOfObject:item[@"cart_item_id"]] ;
  5622. if(index <0)
  5623. {
  5624. newsection[[NSString stringWithFormat:@"item_%d",newcount]] = item;
  5625. newcount ++;
  5626. }
  5627. }
  5628. newsection[@"count"]=@(newcount);
  5629. RASingleton.sharedInstance.scan_cart[@"section_0"] = newsection;
  5630. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  5631. result(RASingleton.sharedInstance.scan_cart);
  5632. return;
  5633. }
  5634. #endif
  5635. if(appDelegate.user!=nil)
  5636. [params setValue:appDelegate.user forKey:@"user"];
  5637. if(appDelegate.contact_id!=nil)
  5638. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5639. if(appDelegate.password!=nil)
  5640. [params setValue:appDelegate.password forKey:@"password"];
  5641. if(appDelegate.order_code!=nil)
  5642. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5643. [params setValue:item_ids forKey:@"cartItemId"];
  5644. // [params setValue:editor forKey:@"editor"];
  5645. [params setValue:ScreenCodeCart forKey:kScreenName];
  5646. // [params setValue:@"" forKey:kAction];
  5647. if(appDelegate.offline_mode)
  5648. {
  5649. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5650. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_cartremove:params]] mutableCopy];
  5651. dispatch_async(dispatch_get_main_queue(), ^{
  5652. int result_code = [[resulti valueForKey:@"result"] intValue];
  5653. if (result_code==2)
  5654. {
  5655. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5656. [appDelegate update_count_mark];
  5657. };
  5658. result(resulti);
  5659. });
  5660. });
  5661. return;
  5662. }
  5663. [self request_interface:URL_CART_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5664. int result_code = [[resulti valueForKey:@"result"] intValue];
  5665. if (result_code==2)
  5666. {
  5667. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5668. [appDelegate update_count_mark];
  5669. };
  5670. result(resulti);
  5671. } retry:0];
  5672. //
  5673. // NSData* json=nil;
  5674. // if(appDelegate.offline_mode)
  5675. // {
  5676. // json= [OLDataProvider offline_cartremove:params];
  5677. // }
  5678. // else
  5679. // {
  5680. // if(![self IsNetworkAvailable])
  5681. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5682. //
  5683. // json=[self get_json:URL_CART_REMOVE parameters:params];
  5684. // }
  5685. // if(json!=nil)
  5686. // {
  5687. // NSError *error=nil;
  5688. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5689. //
  5690. // int result = [[jsobj valueForKey:@"result"] intValue];
  5691. //
  5692. // if (result==2)
  5693. // {
  5694. //
  5695. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5696. //
  5697. //
  5698. // [appDelegate update_count_mark];
  5699. // }
  5700. // return jsobj;
  5701. // }
  5702. // else
  5703. // return nil;
  5704. }
  5705. +(void)request_delete_account:(resultHandler)result
  5706. {
  5707. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5708. AppDelegate *appDelegate = nil;
  5709. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5710. if(appDelegate.user!=nil)
  5711. [params setValue:appDelegate.user forKey:@"user"];
  5712. if(appDelegate.password!=nil)
  5713. [params setValue:appDelegate.password forKey:@"password"];
  5714. if(appDelegate.offline_mode)
  5715. {
  5716. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5717. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5718. dispatch_async(dispatch_get_main_queue(), ^{
  5719. result(json);
  5720. });
  5721. });
  5722. return;
  5723. }
  5724. #ifdef SCANNER_ORDER
  5725. params[@"site_name"]=[RADataProvider getSiteName];
  5726. params[@"_method"]=@"cancelOfflineOrderUser";
  5727. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_DELETE_ACCOUNT];
  5728. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  5729. #else
  5730. [self request_interface:URL_DELETE_ACCOUNT parameters:params err_record_url:nil completionHandler:result retry:0];
  5731. #endif
  5732. }
  5733. +(void) request_create_order:(resultHandler)result
  5734. {
  5735. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5736. AppDelegate *appDelegate = nil;
  5737. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5738. if(appDelegate.user!=nil)
  5739. [params setValue:appDelegate.user forKey:@"user"];
  5740. if(appDelegate.contact_id!=nil)
  5741. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5742. if(appDelegate.password!=nil)
  5743. [params setValue:appDelegate.password forKey:@"password"];
  5744. if(appDelegate.order_code!=nil)
  5745. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5746. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  5747. NSDictionary* customerinfo= appDelegate.customerInfo;
  5748. NSArray* keys=[customerinfo allKeys];
  5749. for(int i=0;i<keys.count;i++)
  5750. {
  5751. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  5752. }
  5753. if(appDelegate.offline_mode)
  5754. {
  5755. [OLDataProvider offline_createorder:params completionHandler:^(NSMutableDictionary *resulti) {
  5756. int result_code = [[resulti valueForKey:@"result"] intValue];
  5757. if (result_code==2)
  5758. {
  5759. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5760. [appDelegate update_count_mark];
  5761. };
  5762. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  5763. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5764. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  5765. }
  5766. result(resulti);
  5767. }];
  5768. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5769. // NSData* json = [[OLDataProvider offline_createorder:params] mutableCopy];
  5770. // dispatch_async(dispatch_get_main_queue(), ^{
  5771. // result([[RAConvertor data2dict:json] mutableCopy]);
  5772. // });
  5773. // });
  5774. return;
  5775. }
  5776. [self request_interface:URL_NEW_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5777. int result_code = [[resulti valueForKey:@"result"] intValue];
  5778. if (result_code==2)
  5779. {
  5780. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5781. [appDelegate update_count_mark];
  5782. };
  5783. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  5784. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5785. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  5786. }
  5787. result(resulti);
  5788. } retry:0];
  5789. //
  5790. // NSData* json = nil;
  5791. // if(appDelegate.offline_mode)
  5792. // {
  5793. // json= [OLDataProvider offline_createorder:params];
  5794. // }
  5795. // else
  5796. // {
  5797. // if(![self IsNetworkAvailable])
  5798. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5799. //
  5800. // json=[self get_json:URL_NEW_ORDER parameters:params];
  5801. // }
  5802. // if(json==nil)
  5803. // return nil;
  5804. // NSError *error=nil;
  5805. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5806. // int result = [[jsobj valueForKey:@"result"] intValue];
  5807. //
  5808. // if (result==2)
  5809. // {
  5810. //
  5811. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5812. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  5813. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5814. //
  5815. // [appDelegate update_count_mark];
  5816. // }
  5817. //
  5818. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  5819. //
  5820. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5821. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  5822. // }
  5823. //
  5824. // return jsobj;
  5825. }
  5826. +(void)request_open_order:(NSString*) order_code completionHandler:(resultHandler)result
  5827. {
  5828. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5829. AppDelegate *appDelegate = nil;
  5830. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5831. if(appDelegate.user!=nil)
  5832. [params setValue:appDelegate.user forKey:@"user"];
  5833. // if(appDelegate.contact_id!=nil)
  5834. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5835. if(appDelegate.password!=nil)
  5836. [params setValue:appDelegate.password forKey:@"password"];
  5837. [params setValue:order_code forKey:@"orderCode"];
  5838. // [params setValue:sourceid forKey:@"sourceid"];
  5839. // [params setValue:editor forKey:@"editor"];
  5840. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  5841. if(appDelegate.offline_mode)
  5842. {
  5843. params[@"appDelegate.order_code"]=appDelegate.order_code;
  5844. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5845. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_editorder:params]] mutableCopy];
  5846. dispatch_async(dispatch_get_main_queue(), ^{
  5847. int result_code = [[resulti valueForKey:@"result"] intValue];
  5848. if (result_code==2)
  5849. {
  5850. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5851. [appDelegate update_count_mark];
  5852. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5853. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  5854. }
  5855. }
  5856. result(resulti);
  5857. });
  5858. });
  5859. return;
  5860. }
  5861. [self request_interface:URL_OPEN_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5862. int result_code = [[resulti valueForKey:@"result"] intValue];
  5863. if (result_code==2)
  5864. {
  5865. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5866. [appDelegate update_count_mark];
  5867. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5868. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  5869. }
  5870. }
  5871. result(resulti);
  5872. } retry:0];
  5873. //
  5874. // NSData* json=nil;
  5875. // if(appDelegate.offline_mode)
  5876. // {
  5877. // json=[OLDataProvider offline_editorder:params];
  5878. //
  5879. // }
  5880. // else
  5881. // {
  5882. // if(![self IsNetworkAvailable])
  5883. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5884. //
  5885. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  5886. // }
  5887. // if(json!=nil)
  5888. // {
  5889. // NSError *error=nil;
  5890. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5891. // int result = [[jsobj valueForKey:@"result"] intValue];
  5892. //
  5893. // if (result==2)
  5894. // {
  5895. //
  5896. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5897. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  5898. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5899. //
  5900. // [appDelegate update_count_mark];
  5901. //
  5902. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5903. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  5904. // }
  5905. //
  5906. // }
  5907. //
  5908. // return jsobj;
  5909. // }
  5910. // else
  5911. // return nil;
  5912. }
  5913. +(void)request_order_discount:(double)discount completionHandler:(resultHandler)result
  5914. {
  5915. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5916. AppDelegate *appDelegate = nil;
  5917. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5918. if(appDelegate.user!=nil)
  5919. [params setValue:appDelegate.user forKey:@"user"];
  5920. // if(appDelegate.contact_id!=nil)
  5921. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5922. if(appDelegate.password!=nil)
  5923. [params setValue:appDelegate.password forKey:@"password"];
  5924. if(appDelegate.order_code!=nil)
  5925. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5926. [params setValue:@(discount) forKey:@"app_discount"];
  5927. if(appDelegate.offline_mode)
  5928. {
  5929. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5930. NSMutableDictionary* json = [[OLDataProvider offline_setorderdiscount:params] mutableCopy];
  5931. dispatch_async(dispatch_get_main_queue(), ^{
  5932. result(json);
  5933. });
  5934. });
  5935. return;
  5936. //
  5937. //
  5938. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5939. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5940. // dispatch_async(dispatch_get_main_queue(), ^{
  5941. // result(json);
  5942. // });
  5943. // });
  5944. //
  5945. // return;
  5946. }
  5947. [self request_interface:URL_ORDER_DISCOUNT parameters:params err_record_url:nil completionHandler:result retry:0];
  5948. }
  5949. +(void)request_cart:(int)sort completionHandler:(resultHandler)result
  5950. {
  5951. DebugLog(@"iSalesNetwork::request_Cart");
  5952. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5953. AppDelegate *appDelegate = nil;
  5954. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5955. #ifdef SCANNER_ORDER
  5956. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  5957. {
  5958. appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  5959. [appDelegate update_count_mark];
  5960. result(RASingleton.sharedInstance.scan_cart);
  5961. return;
  5962. }
  5963. #endif
  5964. if(appDelegate.user!=nil)
  5965. [params setValue:appDelegate.user forKey:@"user"];
  5966. // if(appDelegate.contact_id!=nil)
  5967. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5968. if(appDelegate.password!=nil)
  5969. [params setValue:appDelegate.password forKey:@"password"];
  5970. if(appDelegate.order_code!=nil)
  5971. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5972. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  5973. [params setObject:ScreenCodeCart forKey:kScreenName];
  5974. if(appDelegate.offline_mode)
  5975. {
  5976. [OLDataProvider offline_requestcart:params completionHandler:^(NSMutableDictionary *resulti) {
  5977. if([resulti[@"result"] intValue]==2)
  5978. {
  5979. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5980. [appDelegate update_count_mark];
  5981. result(resulti);
  5982. }
  5983. }];
  5984. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5985. // NSData* json = [[OLDataProvider offline_requestcart:params] mutableCopy];
  5986. // dispatch_async(dispatch_get_main_queue(), ^{
  5987. // result([[RAConvertor data2dict:json] mutableCopy]);
  5988. // });
  5989. // });
  5990. return;
  5991. }
  5992. NSString * uuid= [[NSUUID UUID] UUIDString];
  5993. params[@"resultSerial"]=uuid;
  5994. __block bool bbreak = false;
  5995. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5996. for(int i=0;i<150;i++)
  5997. {
  5998. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  5999. // result_params[@"resultSerial"]=uuid;
  6000. if(bbreak)
  6001. break;
  6002. dispatch_async(dispatch_get_main_queue(), ^{
  6003. [self request_interface:URL_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6004. if([resulti[@"result"] intValue]==2)
  6005. {
  6006. if(!bbreak) //此判断保证result只调用一次。
  6007. {
  6008. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6009. [appDelegate update_count_mark];
  6010. result(resulti);
  6011. }
  6012. bbreak=true;
  6013. }
  6014. } retry:3];
  6015. });
  6016. sleep(2);
  6017. // json=[self get_json:URL_CART parameters:params];
  6018. // if(json!=nil)
  6019. // {
  6020. //
  6021. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6022. // if([jsobj[@"result"] intValue]==2)
  6023. // {
  6024. // break;
  6025. // }
  6026. // }
  6027. }
  6028. });
  6029. //
  6030. //
  6031. //
  6032. // NSData* json=nil;
  6033. // if(appDelegate.offline_mode)
  6034. // {
  6035. // json= [OLDataProvider offline_requestcart:params];
  6036. // }
  6037. // else
  6038. // {
  6039. // if(![self IsNetworkAvailable])
  6040. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6041. //
  6042. // NSError *error=nil;
  6043. //
  6044. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6045. // params[@"resultSerial"]=uuid;
  6046. //
  6047. // for(int i=0;i<150;i++)
  6048. // {
  6049. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6050. // // result_params[@"resultSerial"]=uuid;
  6051. // json=[self get_json:URL_CART parameters:params];
  6052. // if(json!=nil)
  6053. // {
  6054. //
  6055. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6056. // if([jsobj[@"result"] intValue]==2)
  6057. // {
  6058. // break;
  6059. // }
  6060. // }
  6061. // sleep(2);
  6062. // }
  6063. //
  6064. // }
  6065. // if(json==nil)
  6066. // return nil;
  6067. // NSError *error=nil;
  6068. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6069. // int result = [[jsobj valueForKey:@"result"] intValue];
  6070. //
  6071. // if (result==2)
  6072. // {
  6073. //
  6074. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6075. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  6076. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6077. //
  6078. // [appDelegate update_count_mark];
  6079. // }
  6080. // return jsobj;
  6081. }
  6082. +(void) request_move_wish2cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  6083. {
  6084. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6085. AppDelegate *appDelegate = nil;
  6086. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6087. if(appDelegate.user!=nil)
  6088. [params setValue:appDelegate.user forKey:@"user"];
  6089. if(appDelegate.contact_id!=nil)
  6090. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6091. if(appDelegate.password!=nil)
  6092. [params setValue:appDelegate.password forKey:@"password"];
  6093. if(appDelegate.order_code!=nil)
  6094. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6095. [params setValue:item_ids forKey:@"collectId"];
  6096. // [params setValue:editor forKey:@"editor"];
  6097. [params setValue:ScreenCodeWishList forKey:kScreenName];
  6098. [params setValue:@"Move To Cart" forKey:kAction];
  6099. if(appDelegate.offline_mode)
  6100. {
  6101. // [OLDataProvider offline_movewish2cart:params completionHandler:result];
  6102. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6103. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6104. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movewish2cart:params]] mutableCopy];
  6105. dispatch_async(dispatch_get_main_queue(), ^{
  6106. int result_code = [[resulti valueForKey:@"result"] intValue];
  6107. if (result_code==2)
  6108. {
  6109. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6110. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6111. [appDelegate update_count_mark];
  6112. }
  6113. result(resulti);
  6114. });
  6115. });
  6116. return;
  6117. }
  6118. [self request_interface:URL_WISH2CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6119. int result_code = [[resulti valueForKey:@"result"] intValue];
  6120. if (result_code==2)
  6121. {
  6122. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6123. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6124. [appDelegate update_count_mark];
  6125. }
  6126. result(resulti);
  6127. } retry:0];
  6128. //
  6129. // NSData *json = nil;
  6130. // if(appDelegate.offline_mode)
  6131. // {
  6132. // json = [OLDataProvider offline_movewish2cart:params];
  6133. // } else {
  6134. // if(![self IsNetworkAvailable])
  6135. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6136. //
  6137. // json=[self get_json:URL_WISH2CART parameters:params];
  6138. // }
  6139. //
  6140. // if(json!=nil)
  6141. // {
  6142. // NSError *error=nil;
  6143. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6144. // int result = [[jsobj valueForKey:@"result"] intValue];
  6145. //
  6146. // if (result==2)
  6147. // {
  6148. //
  6149. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6150. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6151. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6152. //
  6153. // [appDelegate update_count_mark];
  6154. // }
  6155. // return jsobj;
  6156. // }
  6157. // else
  6158. // return nil;
  6159. }
  6160. +(void) request_move_cart2wish:(NSString* ) item_ids completionHandler:(resultHandler)result
  6161. {
  6162. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6163. AppDelegate *appDelegate = nil;
  6164. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6165. if(appDelegate.user!=nil)
  6166. [params setValue:appDelegate.user forKey:@"user"];
  6167. if(appDelegate.contact_id!=nil)
  6168. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6169. if(appDelegate.password!=nil)
  6170. [params setValue:appDelegate.password forKey:@"password"];
  6171. if(appDelegate.order_code!=nil)
  6172. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6173. [params setValue:item_ids forKey:@"cartItemId"];
  6174. // [params setValue:editor forKey:@"editor"];
  6175. [params setValue:ScreenCodeCart forKey:kScreenName];
  6176. // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  6177. if(appDelegate.offline_mode)
  6178. {
  6179. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6180. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movecart2wish:params]] mutableCopy];
  6181. dispatch_async(dispatch_get_main_queue(), ^{
  6182. int result_code = [[resulti valueForKey:@"result"] intValue];
  6183. if (result_code==2)
  6184. {
  6185. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6186. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6187. [appDelegate update_count_mark];
  6188. }
  6189. result(resulti);
  6190. });
  6191. });
  6192. return;
  6193. }
  6194. [self request_interface:URL_CART2WISH parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6195. int result_code = [[resulti valueForKey:@"result"] intValue];
  6196. if (result_code==2)
  6197. {
  6198. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6199. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6200. [appDelegate update_count_mark];
  6201. }
  6202. result(resulti);
  6203. } retry:0];
  6204. //
  6205. // NSData* json = nil;
  6206. // if(appDelegate.offline_mode)
  6207. // {
  6208. // json= [OLDataProvider offline_movecart2wish:params];
  6209. // }
  6210. // else
  6211. // {
  6212. // if(![self IsNetworkAvailable])
  6213. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6214. //
  6215. // json=[self get_json:URL_CART2WISH parameters:params];
  6216. // }
  6217. // if(json!=nil)
  6218. // {
  6219. // NSError *error=nil;
  6220. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6221. // int result = [[jsobj valueForKey:@"result"] intValue];
  6222. //
  6223. // if (result==2)
  6224. // {
  6225. //
  6226. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6227. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6228. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6229. //
  6230. // [appDelegate update_count_mark];
  6231. // }
  6232. // return jsobj;
  6233. // }
  6234. // else
  6235. // return nil;
  6236. }
  6237. +(void)request_orderdetail:(NSMutableDictionary *) params completionHandler:(resultHandler)result
  6238. {
  6239. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6240. if (params == nil) {
  6241. params = [[NSMutableDictionary alloc] init];
  6242. }
  6243. AppDelegate *appDelegate = nil;
  6244. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6245. if(appDelegate.user!=nil)
  6246. [params setValue:appDelegate.user forKey:@"user"];
  6247. if(appDelegate.contact_id!=nil)
  6248. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6249. if(appDelegate.password!=nil)
  6250. [params setValue:appDelegate.password forKey:@"password"];
  6251. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  6252. [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  6253. if(appDelegate.offline_mode)
  6254. {
  6255. params[@"mode"]=appDelegate.mode;
  6256. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6257. NSData* json = [[OLDataProvider offline_orderdetail:params] mutableCopy];
  6258. dispatch_async(dispatch_get_main_queue(), ^{
  6259. result([[RAConvertor data2dict:json] mutableCopy]);
  6260. });
  6261. });
  6262. return;
  6263. }
  6264. NSString * uuid= [[NSUUID UUID] UUIDString];
  6265. params[@"resultSerial"]=uuid;
  6266. __block bool bbreak = false;
  6267. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6268. for(int i=0;i<150;i++)
  6269. {
  6270. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6271. // result_params[@"resultSerial"]=uuid;
  6272. if(bbreak)
  6273. break;
  6274. dispatch_async(dispatch_get_main_queue(), ^{
  6275. [self request_interface:URL_ORDER_DETAIL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6276. if([resulti[@"result"] intValue]==2||[resulti[@"result"] intValue]==8)
  6277. {
  6278. if(!bbreak)//此判断保证result只调用一次。
  6279. result(resulti);
  6280. bbreak=true;
  6281. }
  6282. } retry:3];
  6283. });
  6284. sleep(2);
  6285. }
  6286. });
  6287. //
  6288. // NSData* json=nil;
  6289. // if(appDelegate.offline_mode)
  6290. // {
  6291. // json= [OLDataProvider offline_orderdetail:params];
  6292. // }
  6293. // else
  6294. // {
  6295. // if(![self IsNetworkAvailable])
  6296. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6297. //
  6298. // NSError *error=nil;
  6299. //
  6300. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6301. // params[@"resultSerial"]=uuid;
  6302. //
  6303. // for(int i=0;i<150;i++)
  6304. // {
  6305. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6306. // // result_params[@"resultSerial"]=uuid;
  6307. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  6308. // if(json!=nil)
  6309. // {
  6310. //
  6311. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6312. // int resultCode = [jsobj[@"result"] intValue];
  6313. // if(resultCode==2 || resultCode == 8)
  6314. // {
  6315. // break;
  6316. // }
  6317. // }
  6318. // sleep(2);
  6319. // }
  6320. //
  6321. //
  6322. // }
  6323. // if(json==nil)
  6324. // return nil;
  6325. // NSError *error=nil;
  6326. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6327. // return jsobj;
  6328. }
  6329. //
  6330. //+(void)request_commit_order:(NSString*) order_code completionHandler:(resultHandler)result
  6331. //{
  6332. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6333. // AppDelegate *appDelegate = nil;
  6334. //
  6335. //
  6336. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6337. //
  6338. // if(appDelegate.user!=nil)
  6339. // [params setValue:appDelegate.user forKey:@"user"];
  6340. // if(appDelegate.contact_id!=nil)
  6341. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6342. // if(appDelegate.password!=nil)
  6343. // [params setValue:appDelegate.password forKey:@"password"];
  6344. // // NSString* ssaved = @"false";
  6345. // // if(saved)
  6346. // // ssaved=@"true";
  6347. // [params setValue:@"true" forKey:@"saved"];
  6348. // [params setValue:order_code forKey:@"orderCode"];
  6349. // // [params setValue:sourceid forKey:@"sourceid"];
  6350. // // [params setValue:editor forKey:@"editor"];
  6351. //
  6352. // [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  6353. //
  6354. //
  6355. // if(appDelegate.offline_mode)
  6356. // {
  6357. //
  6358. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6359. // NSMutableDictionary* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  6360. // dispatch_async(dispatch_get_main_queue(), ^{
  6361. // result(json);
  6362. // });
  6363. // });
  6364. //
  6365. // return;
  6366. // }
  6367. //
  6368. //
  6369. // [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6370. //
  6371. //// NSData* json = nil;
  6372. ////
  6373. //// if(appDelegate.offline_mode)
  6374. //// {
  6375. //// json= [OLDataProvider offline_submitorder:params];
  6376. //// }
  6377. //// else
  6378. //// {
  6379. //// if(![self IsNetworkAvailable])
  6380. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6381. ////
  6382. //// json=[self get_json:URL_COMMIT_ORDER parameters:params];
  6383. //// }
  6384. //// if(json!=nil)
  6385. //// {
  6386. //// NSError *error=nil;
  6387. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6388. //// return jsobj;
  6389. //// }
  6390. //// else
  6391. //// return nil;
  6392. //
  6393. //}
  6394. +(void)request_copy_order:(NSString*) order_code completionHandler:(resultHandler)result
  6395. {
  6396. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6397. AppDelegate *appDelegate = nil;
  6398. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6399. if(appDelegate.user!=nil)
  6400. [params setValue:appDelegate.user forKey:@"user"];
  6401. if(appDelegate.contact_id!=nil)
  6402. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6403. if(appDelegate.password!=nil)
  6404. [params setValue:appDelegate.password forKey:@"password"];
  6405. // NSString* ssaved = @"false";
  6406. // if(saved)
  6407. // ssaved=@"true";
  6408. // [params setValue:@"true" forKey:@"saved"];
  6409. [params setValue:order_code forKey:@"code"];
  6410. // [params setValue:sourceid forKey:@"sourceid"];
  6411. // [params setValue:editor forKey:@"editor"];
  6412. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  6413. if(appDelegate.offline_mode)
  6414. {
  6415. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6416. NSData* json = [[OLDataProvider offline_copyorder:params] mutableCopy];
  6417. dispatch_async(dispatch_get_main_queue(), ^{
  6418. result([[RAConvertor data2dict:json] mutableCopy]);
  6419. });
  6420. });
  6421. return;
  6422. }
  6423. [self request_interface:URL_COPY_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6424. // NSData* json=nil;
  6425. // if(appDelegate.offline_mode)
  6426. // {
  6427. // json= [OLDataProvider offline_copyorder:params];
  6428. // }
  6429. // else
  6430. // {
  6431. // if(![self IsNetworkAvailable])
  6432. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6433. //
  6434. // json=[self get_json:URL_COPY_ORDER parameters:params];
  6435. // }
  6436. // if(json!=nil)
  6437. // {
  6438. // NSError *error=nil;
  6439. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6440. // return jsobj;
  6441. // }
  6442. // else
  6443. // return nil;
  6444. }
  6445. //
  6446. //+ (void)request_fastdownload:(NSMutableDictionary *)params url:(NSString *)url completionHandler:(resultHandler)result
  6447. //{
  6448. //
  6449. // //#ifdef test_server
  6450. // // url=URL_REQUEST_RECORDS;
  6451. // // params[@"prefix"]=URL_REQUEST_RECORDS;
  6452. // //#endif
  6453. //
  6454. // [self request_file_fast:url parameters:params completionHandler:result];
  6455. //
  6456. //}
  6457. +(void) request_addto_portfolio:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6458. {
  6459. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6460. AppDelegate *appDelegate = nil;
  6461. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6462. if(appDelegate.user!=nil)
  6463. [params setValue:appDelegate.user forKey:@"user"];
  6464. if(appDelegate.contact_id!=nil)
  6465. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6466. if(appDelegate.password!=nil)
  6467. [params setValue:appDelegate.password forKey:@"password"];
  6468. [params setValue:item_id forKey:@"product_id"];
  6469. [params setObject:screenName forKey:kScreenName];
  6470. if(appDelegate.offline_mode)
  6471. {
  6472. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6473. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_add2Portfolio:params]] mutableCopy];
  6474. dispatch_async(dispatch_get_main_queue(), ^{
  6475. int result_code = [[resulti valueForKey:@"result"] intValue];
  6476. if (result_code==2)
  6477. {
  6478. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6479. [appDelegate update_count_mark];
  6480. }
  6481. result(resulti);
  6482. });
  6483. });
  6484. return;
  6485. }
  6486. [self request_interface:URL_ADD_TO_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6487. int result_code = [[resulti valueForKey:@"result"] intValue];
  6488. if (result_code==2)
  6489. {
  6490. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6491. [appDelegate update_count_mark];
  6492. }
  6493. result(resulti);
  6494. } retry:0];
  6495. //
  6496. // NSData* json = nil;
  6497. // if(appDelegate.offline_mode)
  6498. // {
  6499. // json = [OLDataProvider offline_add2Portfolio:params];
  6500. // } else {
  6501. // if(![self IsNetworkAvailable])
  6502. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6503. //
  6504. // json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  6505. // }
  6506. //
  6507. // if(json==nil)
  6508. // return nil;
  6509. // NSError *error=nil;
  6510. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6511. // int result = [[jsobj valueForKey:@"result"] intValue];
  6512. //
  6513. // if (result==2)
  6514. // {
  6515. //
  6516. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6517. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6518. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6519. //
  6520. // [appDelegate update_count_mark];
  6521. // }
  6522. // return jsobj;
  6523. }
  6524. +(void)request_addall_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  6525. {
  6526. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6527. AppDelegate *appDelegate = nil;
  6528. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6529. if(appDelegate.user!=nil)
  6530. [params setValue:appDelegate.user forKey:@"user"];
  6531. if(appDelegate.contact_id!=nil)
  6532. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6533. if(appDelegate.password!=nil)
  6534. [params setValue:appDelegate.password forKey:@"password"];
  6535. if(appDelegate.order_code!=nil)
  6536. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6537. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6538. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6539. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  6540. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6541. // [params setValue:filter forKey:@"filter"];
  6542. [params setValue:keywords forKey:@"keyword"];
  6543. [params setValue:addTo forKey:@"addTo"];
  6544. [params setValue:orderCode forKey:@"orderCode"];
  6545. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6546. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6547. if(matchfull)
  6548. [params setValue:@"true" forKey:@"exactMatch"];
  6549. else
  6550. [params setValue:@"false" forKey:@"exactMatch"];
  6551. [params setObject:ScreenCodeSearch forKey:kScreenName];
  6552. if ([addTo isEqualToString:@"cart"]) {
  6553. [params setObject:@"Add To Cart" forKey:kAction];
  6554. }
  6555. if(appDelegate.offline_mode)
  6556. {
  6557. if ([addTo isEqualToString:@"cart"])
  6558. {
  6559. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6560. }
  6561. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6562. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_searchaddall:params]] mutableCopy];
  6563. dispatch_async(dispatch_get_main_queue(), ^{
  6564. int result_code =[json[@"result"] intValue];
  6565. if (result_code==2||result_code==8)
  6566. {
  6567. if(json[@"cart_count"])
  6568. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6569. if(json[@"wish_count"])
  6570. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  6571. if(json[@"portfolio_count"])
  6572. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  6573. //
  6574. //
  6575. [appDelegate update_count_mark];
  6576. }
  6577. result(json);
  6578. });
  6579. });
  6580. return;
  6581. }
  6582. NSString * uuid= [[NSUUID UUID] UUIDString];
  6583. params[@"resultSerial"]=uuid;
  6584. __block bool bbreak = false;
  6585. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6586. for(int i=0;i<150;i++)
  6587. {
  6588. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6589. // result_params[@"resultSerial"]=uuid;
  6590. if(bbreak)
  6591. break;
  6592. dispatch_async(dispatch_get_main_queue(), ^{
  6593. [self request_interface:URL_SEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6594. if([resulti[@"result"] intValue]==2)
  6595. {
  6596. if(!bbreak)//此判断保证result只调用一次。
  6597. result(resulti);
  6598. bbreak=true;
  6599. }
  6600. } retry:3];
  6601. });
  6602. sleep(2);
  6603. }
  6604. });
  6605. //
  6606. //
  6607. // NSData* json=nil;
  6608. // if(appDelegate.offline_mode)
  6609. // {
  6610. // json=[OLDataProvider offline_searchaddall:params];
  6611. // }
  6612. // else
  6613. // {
  6614. // if(![self IsNetworkAvailable])
  6615. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6616. //
  6617. // NSError *error=nil;
  6618. //
  6619. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6620. // params[@"resultSerial"]=uuid;
  6621. //
  6622. // for(int i=0;i<150;i++)
  6623. // {
  6624. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6625. // // result_params[@"resultSerial"]=uuid;
  6626. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  6627. // if(json!=nil)
  6628. // {
  6629. //
  6630. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6631. // if([jsobj[@"result"] intValue]==2)
  6632. // {
  6633. // break;
  6634. // }
  6635. // }
  6636. // sleep(2);
  6637. // }
  6638. // }
  6639. // if(json==nil)
  6640. // return nil;
  6641. // NSError *error=nil;
  6642. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6643. // return jsobj;
  6644. }
  6645. +(void) request_addto_cart_byupc:(NSString* ) upc_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6646. {
  6647. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6648. AppDelegate *appDelegate = nil;
  6649. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6650. if(appDelegate.user!=nil)
  6651. [params setValue:appDelegate.user forKey:@"user"];
  6652. if(appDelegate.contact_id!=nil)
  6653. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6654. if(appDelegate.password!=nil)
  6655. [params setValue:appDelegate.password forKey:@"password"];
  6656. if(appDelegate.order_code!=nil)
  6657. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6658. [params setValue:upc_code forKey:@"upc_code"];
  6659. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  6660. [params setObject:screenName forKey:kScreenName];
  6661. [params setObject:@"Add To Cart" forKey:kAction];
  6662. if (!upc_code) {
  6663. upc_code = @"";
  6664. }
  6665. [params setObject:@{@"UPCCode" : upc_code} forKey:kExtra];
  6666. params[@"search_upc"]=@true;
  6667. NSDictionary* customerinfo= appDelegate.customerInfo;
  6668. NSArray* keys=[customerinfo allKeys];
  6669. for(int i=0;i<keys.count;i++)
  6670. {
  6671. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  6672. }
  6673. if(appDelegate.offline_mode)
  6674. {
  6675. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6676. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  6677. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6678. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyupc:params]] mutableCopy];
  6679. dispatch_async(dispatch_get_main_queue(), ^{
  6680. int result_code = [[json valueForKey:@"result"] intValue];
  6681. if (result_code==2||result_code==8)
  6682. {
  6683. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6684. [appDelegate update_count_mark];
  6685. }
  6686. result(json);
  6687. });
  6688. });
  6689. return;
  6690. }
  6691. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6692. int result_code = [[resulti valueForKey:@"result"] intValue];
  6693. if (result_code==2||result_code==8)
  6694. {
  6695. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6696. [appDelegate update_count_mark];
  6697. }
  6698. result(resulti);
  6699. } retry:0];
  6700. }
  6701. +(void) request_addto_cart_byname:(NSString* ) model_name withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6702. {
  6703. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6704. AppDelegate *appDelegate = nil;
  6705. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6706. if(appDelegate.user!=nil)
  6707. [params setValue:appDelegate.user forKey:@"user"];
  6708. if(appDelegate.contact_id!=nil)
  6709. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6710. if(appDelegate.password!=nil)
  6711. [params setValue:appDelegate.password forKey:@"password"];
  6712. if(appDelegate.order_code!=nil)
  6713. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6714. [params setValue:model_name forKey:@"product_name"];
  6715. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  6716. [params setObject:screenName forKey:kScreenName];
  6717. [params setObject:@"Add To Cart" forKey:kAction];
  6718. if (!model_name) {
  6719. model_name = @"";
  6720. }
  6721. [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  6722. NSDictionary* customerinfo= appDelegate.customerInfo;
  6723. NSArray* keys=[customerinfo allKeys];
  6724. for(int i=0;i<keys.count;i++)
  6725. {
  6726. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  6727. }
  6728. if(appDelegate.offline_mode)
  6729. {
  6730. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6731. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  6732. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6733. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyname:params]] mutableCopy];
  6734. dispatch_async(dispatch_get_main_queue(), ^{
  6735. int result_code = [[json valueForKey:@"result"] intValue];
  6736. if (result_code==2||result_code==8)
  6737. {
  6738. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6739. [appDelegate update_count_mark];
  6740. }
  6741. result(json);
  6742. });
  6743. });
  6744. return;
  6745. }
  6746. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6747. int result_code = [[resulti valueForKey:@"result"] intValue];
  6748. if (result_code==2||result_code==8)
  6749. {
  6750. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6751. [appDelegate update_count_mark];
  6752. }
  6753. result(resulti);
  6754. } retry:0];
  6755. // NSData* json=nil;
  6756. // if(appDelegate.offline_mode)
  6757. // {
  6758. // json= [OLDataProvider offline_add2cartbyname:params];
  6759. // }
  6760. // else
  6761. // {
  6762. // if(![self IsNetworkAvailable])
  6763. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6764. //
  6765. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  6766. // }
  6767. // if(json==nil)
  6768. // return nil;
  6769. // NSError *error=nil;
  6770. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6771. //
  6772. //
  6773. //
  6774. // int result = [[jsobj valueForKey:@"result"] intValue];
  6775. //
  6776. // if (result==2||result==8)
  6777. // {
  6778. //
  6779. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6780. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6781. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6782. //
  6783. // [appDelegate update_count_mark];
  6784. // }
  6785. //
  6786. // return jsobj;
  6787. }
  6788. +(void) request_addto_wishlist:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6789. {
  6790. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6791. AppDelegate *appDelegate = nil;
  6792. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6793. if(appDelegate.user!=nil)
  6794. [params setValue:appDelegate.user forKey:@"user"];
  6795. if(appDelegate.contact_id!=nil)
  6796. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6797. if(appDelegate.password!=nil)
  6798. [params setValue:appDelegate.password forKey:@"password"];
  6799. [params setValue:item_id forKey:@"product_id"];
  6800. [params setObject:screenName forKey:kScreenName];
  6801. if(appDelegate.offline_mode)
  6802. {
  6803. // [OLDataProvider offline_add2wishlist:params completionHandler:result];
  6804. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6805. NSMutableDictionary* resulti = [[OLDataProvider offline_add2wishlist:params] mutableCopy];
  6806. dispatch_async(dispatch_get_main_queue(), ^{
  6807. int result_code = [[resulti valueForKey:@"result"] intValue];
  6808. if (result_code==2||result_code==8)
  6809. {
  6810. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6811. [appDelegate update_count_mark];
  6812. }
  6813. result(resulti);
  6814. });
  6815. });
  6816. return;
  6817. }
  6818. [self request_interface:URL_ADD_TO_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6819. int result_code = [[resulti valueForKey:@"result"] intValue];
  6820. if (result_code==2||result_code==8)
  6821. {
  6822. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6823. [appDelegate update_count_mark];
  6824. }
  6825. result(resulti);
  6826. } retry:0];
  6827. // if(appDelegate.offline_mode)
  6828. // {
  6829. // return [OLDataProvider offline_add2wishlist:params];
  6830. // }
  6831. // if(![self IsNetworkAvailable])
  6832. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6833. //
  6834. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  6835. // if(json==nil)
  6836. // return nil;
  6837. // NSError *error=nil;
  6838. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6839. // int result = [[jsobj valueForKey:@"result"] intValue];
  6840. //
  6841. // if (result==2)
  6842. // {
  6843. //
  6844. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6845. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6846. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6847. //
  6848. // [appDelegate update_count_mark];
  6849. // }
  6850. // return jsobj;
  6851. }
  6852. +(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
  6853. {
  6854. // for debug
  6855. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  6856. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6857. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6858. AppDelegate *appDelegate = nil;
  6859. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6860. if(appDelegate.user!=nil)
  6861. [params setValue:appDelegate.user forKey:@"user"];
  6862. if(appDelegate.contact_id!=nil)
  6863. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6864. if(appDelegate.password!=nil)
  6865. [params setValue:appDelegate.password forKey:@"password"];
  6866. if(appDelegate.order_code!=nil)
  6867. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6868. [params setValue:addTo forKey:@"addTo"];
  6869. [params setValue:orderCode forKey:@"orderCode"];
  6870. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6871. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6872. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  6873. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6874. // [params setValue:filter forKey:@"filter"];
  6875. [params setValue:covertype forKey:@"covertype"];
  6876. [params setValue:ctgid forKey:@"ctgId"];
  6877. [params setValue:modelname forKey:@"modelName"];
  6878. [params setValue:modeldescrip forKey:@"modelDescription"];
  6879. [params setValue:alert forKey:@"alert"];
  6880. [params setValue:qty forKey:@"sold_by_qty"];
  6881. [params setValue:available forKey:@"available"];
  6882. [params setValue:price forKey:@"price"];
  6883. [params setValue:bestseller forKey:@"bestseller"];
  6884. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6885. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6886. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  6887. if ([addTo isEqualToString:@"cart"]) {
  6888. [params setObject:@"Add To Cart" forKey:kAction];
  6889. }
  6890. if(appDelegate.offline_mode)
  6891. {
  6892. if ([addTo isEqualToString:@"cart"])
  6893. {
  6894. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6895. }
  6896. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6897. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_itemsearchaddall:params]] mutableCopy];
  6898. dispatch_async(dispatch_get_main_queue(), ^{
  6899. int result_code =[json[@"result"] intValue];
  6900. if (result_code==2||result_code==8)
  6901. {
  6902. if(json[@"cart_count"])
  6903. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6904. if(json[@"wish_count"])
  6905. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  6906. if(json[@"portfolio_count"])
  6907. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  6908. //
  6909. //
  6910. [appDelegate update_count_mark];
  6911. }
  6912. result(json);
  6913. });
  6914. });
  6915. return;
  6916. }
  6917. NSString * uuid= [[NSUUID UUID] UUIDString];
  6918. params[@"resultSerial"]=uuid;
  6919. __block bool bbreak = false;
  6920. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6921. for(int i=0;i<150;i++)
  6922. {
  6923. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6924. // result_params[@"resultSerial"]=uuid;
  6925. if(bbreak)
  6926. break;
  6927. dispatch_async(dispatch_get_main_queue(), ^{
  6928. [self request_interface:URL_ITEMSEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6929. if([resulti[@"result"] intValue]==2)
  6930. {
  6931. if(!bbreak)//此判断保证result只调用一次。
  6932. result(resulti);
  6933. bbreak=true;
  6934. }
  6935. } retry:3];
  6936. });
  6937. sleep(2);
  6938. }
  6939. });
  6940. //
  6941. // NSData* json = nil;
  6942. //
  6943. // if(appDelegate.offline_mode)
  6944. // {
  6945. // json= [OLDataProvider offline_itemsearchaddall:params];
  6946. // }
  6947. // else
  6948. // {
  6949. // if(![self IsNetworkAvailable])
  6950. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6951. // NSError *error=nil;
  6952. //
  6953. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6954. // params[@"resultSerial"]=uuid;
  6955. //
  6956. // for(int i=0;i<150;i++)
  6957. // {
  6958. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6959. // // result_params[@"resultSerial"]=uuid;
  6960. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  6961. // if(json!=nil)
  6962. // {
  6963. //
  6964. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6965. // if([jsobj[@"result"] intValue]==2)
  6966. // {
  6967. // break;
  6968. // }
  6969. // }
  6970. // sleep(2);
  6971. // }
  6972. // }
  6973. // if(json==nil)
  6974. // return nil;
  6975. // NSError *error=nil;
  6976. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6977. // return jsobj;
  6978. }
  6979. +(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
  6980. {
  6981. AppDelegate *appDelegate = nil;
  6982. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6983. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6984. if(appDelegate.user!=nil)
  6985. [params setValue:appDelegate.user forKey:@"user"];
  6986. if(appDelegate.contact_id!=nil)
  6987. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6988. if(appDelegate.password!=nil)
  6989. [params setValue:appDelegate.password forKey:@"password"];
  6990. if(appDelegate.order_code!=nil)
  6991. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6992. [params setValue:addTo forKey:@"addTo"];
  6993. [params setValue:orderCode forKey:@"orderCode"];
  6994. [params setValue:alert forKey:@"alert"];
  6995. [params setValue:qty forKey:@"sold_by_qty"];
  6996. [params setValue:available forKey:@"available"];
  6997. [params setValue:price forKey:@"price"];
  6998. [params setValue:bestseller forKey:@"bestseller"];
  6999. [params setValue:modelname forKey:@"modelName"];
  7000. [params setValue:modeldescrip forKey:@"modelDescription"];
  7001. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7002. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7003. [params setValue:category forKey:@"category"];
  7004. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7005. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7006. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7007. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7008. [params setValue:filter forKey:@"filter"];
  7009. [params setValue:keyword forKey:@"keyword"];
  7010. [params setObject:ScreenCodeCategory forKey:kScreenName];
  7011. if ([addTo isEqualToString:@"cart"]) {
  7012. [params setObject:@"Add To Cart" forKey:kAction];
  7013. }
  7014. if(appDelegate.offline_mode)
  7015. {
  7016. if ([addTo isEqualToString:@"cart"])
  7017. {
  7018. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7019. }
  7020. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7021. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_categoryaddall:params]] mutableCopy];
  7022. dispatch_async(dispatch_get_main_queue(), ^{
  7023. int result_code =[json[@"result"] intValue];
  7024. if (result_code==2||result_code==8)
  7025. {
  7026. if(json[@"cart_count"])
  7027. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7028. if(json[@"wish_count"])
  7029. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7030. if(json[@"portfolio_count"])
  7031. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7032. //
  7033. //
  7034. [appDelegate update_count_mark];
  7035. }
  7036. result(json);
  7037. });
  7038. });
  7039. return;
  7040. }
  7041. NSString * uuid= [[NSUUID UUID] UUIDString];
  7042. params[@"resultSerial"]=uuid;
  7043. __block bool bbreak = false;
  7044. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7045. for(int i=0;i<150;i++)
  7046. {
  7047. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7048. // result_params[@"resultSerial"]=uuid;
  7049. if(bbreak)
  7050. break;
  7051. dispatch_async(dispatch_get_main_queue(), ^{
  7052. [self request_interface:URL_CATEGORYADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7053. if([resulti[@"result"] intValue]==2|| [resulti[@"result"] intValue] == 8)
  7054. {
  7055. if(!bbreak)//此判断保证result只调用一次。
  7056. {
  7057. int result_code =[resulti[@"result"] intValue];
  7058. if (result_code==2||result_code==8)
  7059. {
  7060. if(resulti[@"cart_count"])
  7061. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7062. if(resulti[@"wish_count"])
  7063. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7064. if(resulti[@"portfolio_count"])
  7065. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  7066. //
  7067. //
  7068. [appDelegate update_count_mark];
  7069. }
  7070. result(resulti);
  7071. }
  7072. bbreak=true;
  7073. }
  7074. } retry:3];
  7075. });
  7076. sleep(2);
  7077. }
  7078. });
  7079. //
  7080. // NSData* json= nil;
  7081. //
  7082. // if(appDelegate.offline_mode)
  7083. // {
  7084. // json= [OLDataProvider offline_categoryaddall:params];
  7085. // }
  7086. // else
  7087. // {
  7088. // if(![self IsNetworkAvailable])
  7089. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7090. //
  7091. //
  7092. // NSError *error=nil;
  7093. //
  7094. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7095. // params[@"resultSerial"]=uuid;
  7096. //
  7097. // for(int i=0;i<150;i++)
  7098. // {
  7099. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7100. //// result_params[@"resultSerial"]=uuid;
  7101. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  7102. // if(json!=nil)
  7103. // {
  7104. //
  7105. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7106. // int resultInt = [jsobj[@"result"] intValue];
  7107. // if(resultInt == 2 || resultInt == 8)
  7108. // {
  7109. // break;
  7110. // }
  7111. // }
  7112. // sleep(2);
  7113. // }
  7114. //
  7115. //
  7116. //
  7117. // }
  7118. // if(json==nil)
  7119. // return nil;
  7120. // NSError *error=nil;
  7121. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7122. // return jsobj;
  7123. }
  7124. +(void)request_save_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7125. {
  7126. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7127. AppDelegate *appDelegate = nil;
  7128. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7129. if(appDelegate.user!=nil)
  7130. [params setValue:appDelegate.user forKey:@"user"];
  7131. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  7132. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7133. // else
  7134. if(appDelegate.contact_id!=nil)
  7135. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7136. if(appDelegate.password!=nil)
  7137. [params setValue:appDelegate.password forKey:@"password"];
  7138. if(appDelegate.order_code!=nil)
  7139. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7140. // NSDictionary* customerinfo=nil;
  7141. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  7142. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7143. // else
  7144. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7145. //
  7146. // appDelegate.customerInfo;
  7147. // NSArray* keys=[customerinfo allKeys];
  7148. // for(int i=0;i<keys.count;i++)
  7149. // {
  7150. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7151. // }
  7152. // [params setValue:sourceid forKey:@"sourceid"];
  7153. // [params setValue:editor forKey:@"editor"];
  7154. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  7155. if(appDelegate.offline_mode)
  7156. {
  7157. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7158. NSData* json = [[OLDataProvider offline_saveorder:params] mutableCopy];
  7159. dispatch_async(dispatch_get_main_queue(), ^{
  7160. result([[RAConvertor data2dict:json] mutableCopy]);
  7161. });
  7162. });
  7163. return;
  7164. }
  7165. [self request_interface:URL_SAVE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  7166. //
  7167. // NSData* json=nil;
  7168. //
  7169. // if(appDelegate.offline_mode)
  7170. // {
  7171. // json= [OLDataProvider offline_saveorder:params];
  7172. // }
  7173. // else
  7174. // {
  7175. // if(![self IsNetworkAvailable])
  7176. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7177. //
  7178. // json=[self get_json:URL_SAVE_ORDER parameters:params];
  7179. // }
  7180. // if(json!=nil)
  7181. // {
  7182. // NSError *error=nil;
  7183. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7184. // NSString *so = [jsobj valueForKey:@"so#"];
  7185. // if (so) {
  7186. // [appDelegate SetSo:so];
  7187. // }
  7188. // return jsobj;
  7189. // }
  7190. // else
  7191. // return nil;
  7192. }
  7193. +(void) request_update_cartqty:(NSString*) cart_id value:(int) value completionHandler:(resultHandler)result
  7194. {
  7195. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7196. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  7197. #ifdef SCANNER_ORDER
  7198. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7199. {
  7200. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7201. //
  7202. //
  7203. // [appDelegate update_count_mark];
  7204. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7205. int count = [section[@"count"] intValue];
  7206. for(int i=0;i<count;i++)
  7207. {
  7208. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7209. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7210. {
  7211. item[@"count"] =@(value);
  7212. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7213. break;
  7214. }
  7215. }
  7216. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7217. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7218. result(RASingleton.sharedInstance.scan_cart);
  7219. [OLDataProvider updateScanOrder:appDelegate.order_code];
  7220. return;
  7221. }
  7222. #endif
  7223. if(appDelegate.user!=nil)
  7224. [params setValue:appDelegate.user forKey:@"user"];
  7225. if(appDelegate.contact_id!=nil)
  7226. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7227. if(appDelegate.password!=nil)
  7228. [params setValue:appDelegate.password forKey:@"password"];
  7229. [params setValue:cart_id forKey:@"cartitem_id"];
  7230. [params setObject:ScreenCodeCart forKey:kScreenName];
  7231. [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  7232. if(appDelegate.offline_mode)
  7233. {
  7234. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7235. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7236. NSData* json = [[OLDataProvider offline_cartsetqty:params] mutableCopy];
  7237. dispatch_async(dispatch_get_main_queue(), ^{
  7238. result([[RAConvertor data2dict:json] mutableCopy]);
  7239. });
  7240. });
  7241. return;
  7242. }
  7243. [self request_interface:URL_CART_INCRESEMENT parameters:params err_record_url:nil completionHandler:result retry:0];
  7244. //
  7245. // NSData* json=nil;
  7246. // if(appDelegate.offline_mode)
  7247. // {
  7248. // json= [OLDataProvider offline_cartsetqty:params];
  7249. // }
  7250. // else
  7251. // {
  7252. // if(![self IsNetworkAvailable])
  7253. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7254. //
  7255. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  7256. // }
  7257. // if(json==nil)
  7258. // return nil;
  7259. // NSError *error=nil;
  7260. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7261. // return jsobj;
  7262. }
  7263. +(void) request_update_cartgeneralnote:(NSString*) order_code notes:(NSString*) notes completionHandler:(resultHandler)result
  7264. {
  7265. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7266. AppDelegate *appDelegate = nil;
  7267. #ifdef SCANNER_ORDER
  7268. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7269. {
  7270. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7271. //
  7272. //
  7273. // [appDelegate update_count_mark];
  7274. RASingleton.sharedInstance.scan_cart[@"general_note"] = notes;
  7275. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7276. result(RASingleton.sharedInstance.scan_cart);
  7277. return;
  7278. }
  7279. #endif
  7280. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7281. if(appDelegate.user!=nil)
  7282. [params setValue:appDelegate.user forKey:@"user"];
  7283. if(appDelegate.contact_id!=nil)
  7284. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7285. if(appDelegate.password!=nil)
  7286. [params setValue:appDelegate.password forKey:@"password"];
  7287. [params setValue:order_code forKey:@"orderCode"];
  7288. [params setObject:ScreenCodeCart forKey:kScreenName];
  7289. if(notes.length==0)
  7290. notes=@"";
  7291. [params setValue:notes forKey:@"comments"];
  7292. if(appDelegate.offline_mode)
  7293. {
  7294. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7295. NSData* json = [[OLDataProvider offline_updategnotes:params] mutableCopy];
  7296. dispatch_async(dispatch_get_main_queue(), ^{
  7297. result([[RAConvertor data2dict:json] mutableCopy]);
  7298. });
  7299. });
  7300. return;
  7301. }
  7302. [self request_interface:URL_CART_GENERAL_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7303. //
  7304. // NSData* json=nil;
  7305. // if(appDelegate.offline_mode)
  7306. // {
  7307. // json= [OLDataProvider offline_updategnotes:params];
  7308. // }
  7309. // else
  7310. // {
  7311. // if(![self IsNetworkAvailable])
  7312. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7313. //
  7314. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  7315. // }
  7316. // if(json==nil)
  7317. // return nil;
  7318. // NSError *error=nil;
  7319. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7320. // return jsobj;
  7321. }
  7322. +(void) request_update_cartitemnote:(NSString*) cart_id notes:(NSString*) notes completionHandler:(resultHandler)result
  7323. {
  7324. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7325. AppDelegate *appDelegate = nil;
  7326. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7327. #ifdef SCANNER_ORDER
  7328. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7329. {
  7330. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7331. //
  7332. //
  7333. // [appDelegate update_count_mark];
  7334. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7335. int count = [section[@"count"] intValue];
  7336. for(int i=0;i<count;i++)
  7337. {
  7338. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7339. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7340. {
  7341. item[@"note"] =notes;
  7342. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7343. break;
  7344. }
  7345. }
  7346. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7347. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7348. result(RASingleton.sharedInstance.scan_cart);
  7349. return;
  7350. }
  7351. #endif
  7352. if(appDelegate.user!=nil)
  7353. [params setValue:appDelegate.user forKey:@"user"];
  7354. if(appDelegate.contact_id!=nil)
  7355. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7356. if(appDelegate.password!=nil)
  7357. [params setValue:appDelegate.password forKey:@"password"];
  7358. [params setValue:cart_id forKey:@"cartitem_id"];
  7359. [params setObject:ScreenCodeCart forKey:kScreenName];
  7360. if(notes.length==0)
  7361. notes=@"";
  7362. [params setValue:notes forKey:@"notes"];
  7363. if(appDelegate.offline_mode)
  7364. {
  7365. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7366. NSData* json = [[OLDataProvider offline_cartsetlnotes:params] mutableCopy];
  7367. dispatch_async(dispatch_get_main_queue(), ^{
  7368. result([[RAConvertor data2dict:json] mutableCopy]);
  7369. });
  7370. });
  7371. return;
  7372. }
  7373. [self request_interface:URL_CART_ITEM_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7374. //
  7375. // NSData* json=nil;
  7376. // if(appDelegate.offline_mode)
  7377. // {
  7378. // json= [OLDataProvider offline_cartsetlnotes:params];
  7379. // }
  7380. // else
  7381. // {
  7382. // if(![self IsNetworkAvailable])
  7383. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7384. //
  7385. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  7386. // }
  7387. // if(json==nil)
  7388. // return nil;
  7389. // NSError *error=nil;
  7390. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7391. // return jsobj;
  7392. }
  7393. + (void)request_update_npd_shop_price_type:(NSInteger)priceType completionHandler:(resultHandler)result
  7394. {
  7395. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7396. AppDelegate *appDelegate = nil;
  7397. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7398. if(appDelegate.user!=nil)
  7399. [dic setValue:appDelegate.user forKey:@"user"];
  7400. if(appDelegate.password!=nil)
  7401. [dic setValue:appDelegate.password forKey:@"password"];
  7402. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  7403. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  7404. if(appDelegate.offline_mode)
  7405. {
  7406. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7407. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7408. dispatch_async(dispatch_get_main_queue(), ^{
  7409. result(json);
  7410. });
  7411. });
  7412. return;
  7413. }
  7414. [self request_interface:URL_SET_PRICE_TYPE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7415. //
  7416. // NSData* json=nil;
  7417. // if(appDelegate.offline_mode)
  7418. // {
  7419. // return [OLDataProvider offline_notimpl];
  7420. // }
  7421. // else
  7422. // {
  7423. // if(![self IsNetworkAvailable])
  7424. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7425. //
  7426. // json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  7427. // }
  7428. // if(json!=nil)
  7429. // {
  7430. // NSError *error=nil;
  7431. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7432. //
  7433. //
  7434. // return jsobj;
  7435. // }
  7436. //
  7437. //
  7438. // return nil;
  7439. }
  7440. + (void)request_npd_shop_givenprice:(resultHandler)result
  7441. {
  7442. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7443. AppDelegate *appDelegate = nil;
  7444. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7445. if(appDelegate.user!=nil)
  7446. [dic setValue:appDelegate.user forKey:@"user"];
  7447. if(appDelegate.password!=nil)
  7448. [dic setValue:appDelegate.password forKey:@"password"];
  7449. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  7450. if(appDelegate.offline_mode)
  7451. {
  7452. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7453. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7454. dispatch_async(dispatch_get_main_queue(), ^{
  7455. result(json);
  7456. });
  7457. });
  7458. return;
  7459. }
  7460. [self request_interface:URL_GET_CIVEN_PRICE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7461. //
  7462. // NSData* json=nil;
  7463. // if(appDelegate.offline_mode)
  7464. // {
  7465. // return [OLDataProvider offline_notimpl];
  7466. // }
  7467. // else
  7468. // {
  7469. // if(![self IsNetworkAvailable])
  7470. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7471. //
  7472. // json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  7473. // }
  7474. // if(json!=nil)
  7475. // {
  7476. // NSError *error=nil;
  7477. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7478. //
  7479. //
  7480. // return jsobj;
  7481. // }
  7482. //
  7483. //
  7484. // return nil;
  7485. }
  7486. + (void)request_update_npd_shop_givenprice:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  7487. {
  7488. AppDelegate *appDelegate = nil;
  7489. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7490. if(appDelegate.user!=nil)
  7491. [params setValue:appDelegate.user forKey:@"user"];
  7492. if(appDelegate.password!=nil)
  7493. [params setValue:appDelegate.password forKey:@"password"];
  7494. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  7495. if(appDelegate.offline_mode)
  7496. {
  7497. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7498. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7499. dispatch_async(dispatch_get_main_queue(), ^{
  7500. result(json);
  7501. });
  7502. });
  7503. return;
  7504. }
  7505. [self request_interface:URL_SET_GIVEN_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  7506. //
  7507. // NSData* json=nil;
  7508. // if(appDelegate.offline_mode)
  7509. // {
  7510. // return [OLDataProvider offline_notimpl];
  7511. // }
  7512. // else
  7513. // {
  7514. // if(![self IsNetworkAvailable])
  7515. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7516. //
  7517. // json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  7518. // }
  7519. // if(json!=nil)
  7520. // {
  7521. // NSError *error=nil;
  7522. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7523. //
  7524. //
  7525. // return jsobj;
  7526. // }
  7527. //
  7528. //
  7529. // return nil;
  7530. }
  7531. +(void) request_create_portfolio:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7532. {
  7533. AppDelegate *appDelegate = nil;
  7534. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7535. if(appDelegate.offline_mode)
  7536. {
  7537. params[@"contact_id"]=params[@"contactId"];
  7538. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7539. NSData* json = [[OLDataProvider offline_direct_save_TearSheet:params] mutableCopy];
  7540. dispatch_async(dispatch_get_main_queue(), ^{
  7541. result([[RAConvertor data2dict:json] mutableCopy]);
  7542. });
  7543. });
  7544. return;
  7545. }
  7546. //
  7547. // if(appDelegate.offline_mode)
  7548. // {
  7549. //
  7550. //
  7551. // NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  7552. // if(json==nil)
  7553. // return nil;
  7554. // NSError *error=nil;
  7555. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7556. //
  7557. // return jsobj[@"pdf_path"];
  7558. // }
  7559. // else
  7560. // {
  7561. // return nil;
  7562. // }
  7563. }
  7564. +(void)request_save_portfoliodirectly:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7565. {
  7566. NSMutableDictionary* off_params = [params mutableCopy];
  7567. AppDelegate *appDelegate = nil;
  7568. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7569. if(appDelegate.user!=nil)
  7570. [params setValue:appDelegate.user forKey:@"user"];
  7571. if(appDelegate.contact_id!=nil)
  7572. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7573. if(appDelegate.password!=nil)
  7574. params[@"off_params"]=[RAConvertor dict2string:off_params];
  7575. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  7576. [params setValue:appDelegate.password forKey:@"password"];
  7577. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7578. if(appDelegate.offline_mode)
  7579. {
  7580. params[@"contact_id"]=appDelegate.contact_id;
  7581. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7582. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_direct_save_TearSheet:params]] mutableCopy];
  7583. dispatch_async(dispatch_get_main_queue(), ^{
  7584. result(json);
  7585. });
  7586. });
  7587. return;
  7588. }
  7589. NSString * uuid= [[NSUUID UUID] UUIDString];
  7590. params[@"resultSerial"]=uuid;
  7591. __block bool bbreak = false;
  7592. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7593. for(int i=0;i<150;i++)
  7594. {
  7595. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7596. // result_params[@"resultSerial"]=uuid;
  7597. if(bbreak)
  7598. break;
  7599. dispatch_async(dispatch_get_main_queue(), ^{
  7600. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7601. if([resulti[@"result"] intValue]==2)
  7602. {
  7603. if(!bbreak)//此判断保证result只调用一次。
  7604. result(resulti);
  7605. bbreak=true;
  7606. }
  7607. } retry:3];
  7608. });
  7609. sleep(2);
  7610. }
  7611. });
  7612. //
  7613. //
  7614. // NSData* json= nil;
  7615. //
  7616. // if(appDelegate.offline_mode)
  7617. // {
  7618. // json = [OLDataProvider offline_direct_save_TearSheet:params];
  7619. // }
  7620. // else
  7621. // {
  7622. // if(![self IsNetworkAvailable])
  7623. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7624. //
  7625. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7626. //
  7627. // NSError *error=nil;
  7628. //
  7629. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7630. // params[@"resultSerial"]=uuid;
  7631. //
  7632. // for(int i=0;i<150;i++)
  7633. // {
  7634. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7635. // // result_params[@"resultSerial"]=uuid;
  7636. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7637. // if(json!=nil)
  7638. // {
  7639. //
  7640. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7641. // if([jsobj[@"result"] intValue]==2)
  7642. // {
  7643. // break;
  7644. // }
  7645. // }
  7646. // sleep(5);
  7647. // }
  7648. //
  7649. // }
  7650. // if(json==nil)
  7651. // return nil;
  7652. // NSError *error=nil;
  7653. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7654. // return jsobj;
  7655. }
  7656. +(void)request_save_portfolio:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  7657. {
  7658. AppDelegate *appDelegate = nil;
  7659. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7660. if(appDelegate.user!=nil)
  7661. [params setValue:appDelegate.user forKey:@"user"];
  7662. if(appDelegate.contact_id!=nil)
  7663. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7664. NSMutableDictionary* off_params = [params mutableCopy];;
  7665. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  7666. params[@"off_params"]=[RAConvertor dict2string:off_params];
  7667. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7668. if(appDelegate.password!=nil)
  7669. [params setValue:appDelegate.password forKey:@"password"];
  7670. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7671. if(appDelegate.offline_mode)
  7672. {
  7673. params[@"contact_id"]=appDelegate.contact_id;
  7674. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7675. NSData* json = [[OLDataProvider offline_save_TearSheet:params] mutableCopy];
  7676. dispatch_async(dispatch_get_main_queue(), ^{
  7677. result([[RAConvertor data2dict:json] mutableCopy]);
  7678. });
  7679. });
  7680. return;
  7681. }
  7682. [self request_interface:URL_SAVE_DM parameters:params err_record_url:nil completionHandler:result retry:0];
  7683. //
  7684. // NSData* json = nil;
  7685. // if(appDelegate.offline_mode)
  7686. // {
  7687. // json = [OLDataProvider offline_save_TearSheet:params];
  7688. // } else {
  7689. // if(![self IsNetworkAvailable])
  7690. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7691. //
  7692. // json=[self get_json:URL_SAVE_DM parameters:params];
  7693. // }
  7694. // if(json==nil)
  7695. // return nil;
  7696. // NSError *error=nil;
  7697. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7698. // return jsobj;
  7699. }
  7700. +(void)request_portfoliopreview:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7701. {
  7702. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7703. AppDelegate *appDelegate = nil;
  7704. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7705. if(appDelegate.user!=nil)
  7706. [params setValue:appDelegate.user forKey:@"user"];
  7707. if(appDelegate.contact_id!=nil)
  7708. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7709. if(appDelegate.password!=nil)
  7710. [params setValue:appDelegate.password forKey:@"password"];
  7711. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7712. // [params setValue:request_url forKey:@"pdfUrl"];
  7713. if(appDelegate.offline_mode)
  7714. {
  7715. params[@"contact_id"]=params[@"contactId"];
  7716. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7717. NSData* json = [[OLDataProvider offline_request_tearsheet:params] mutableCopy];
  7718. dispatch_async(dispatch_get_main_queue(), ^{
  7719. result([[RAConvertor data2dict:json] mutableCopy]);
  7720. });
  7721. });
  7722. return;
  7723. }
  7724. NSString * uuid= [[NSUUID UUID] UUIDString];
  7725. params[@"resultSerial"]=uuid;
  7726. __block bool bbreak = false;
  7727. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7728. for(int i=0;i<150;i++)
  7729. {
  7730. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7731. // result_params[@"resultSerial"]=uuid;
  7732. if(bbreak)
  7733. break;
  7734. dispatch_async(dispatch_get_main_queue(), ^{
  7735. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7736. if([resulti[@"result"] intValue]==2)
  7737. {
  7738. if(!bbreak)//此判断保证result只调用一次。
  7739. result(resulti);
  7740. bbreak=true;
  7741. }
  7742. } retry:3];
  7743. });
  7744. sleep(5);
  7745. }
  7746. });
  7747. //
  7748. // NSData* json= nil;
  7749. // if(appDelegate.offline_mode)
  7750. // {
  7751. // json= [OLDataProvider offline_request_tearsheet:params];
  7752. // }
  7753. // else
  7754. // {
  7755. // if(![self IsNetworkAvailable])
  7756. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7757. //
  7758. // NSError *error=nil;
  7759. //
  7760. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7761. // params[@"resultSerial"]=uuid;
  7762. //
  7763. // for(int i=0;i<150;i++)
  7764. // {
  7765. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7766. // // result_params[@"resultSerial"]=uuid;
  7767. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7768. // if(json!=nil)
  7769. // {
  7770. //
  7771. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7772. // if([jsobj[@"result"] intValue]==2)
  7773. // {
  7774. // break;
  7775. // }
  7776. // }
  7777. // sleep(5);
  7778. // }
  7779. // }
  7780. // if(json==nil)
  7781. // return nil;
  7782. // NSError *error=nil;
  7783. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7784. // return jsobj;
  7785. }
  7786. +(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
  7787. {
  7788. // for debug
  7789. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  7790. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7791. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7792. AppDelegate *appDelegate = nil;
  7793. //some UI methods ej
  7794. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7795. if(appDelegate.user!=nil)
  7796. [params setValue:appDelegate.user forKey:@"user"];
  7797. if(appDelegate.contact_id!=nil)
  7798. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7799. if(appDelegate.password!=nil)
  7800. [params setValue:appDelegate.password forKey:@"password"];
  7801. if(appDelegate.order_code!=nil)
  7802. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7803. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  7804. if (alert && qty && available && price && bestseller) {
  7805. [params setObject:@"Filter" forKey:kAction];
  7806. }
  7807. if ([RASingleton sharedInstance].homeItemClick) {
  7808. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  7809. [RASingleton sharedInstance].homeItemClick = NO;
  7810. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  7811. [RASingleton sharedInstance].homeClickedItemName = nil;
  7812. [params setObject:extra forKey:kExtra];
  7813. }
  7814. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7815. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7816. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  7817. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7818. // [params setValue:filter forKey:@"filter"];
  7819. [params setValue:covertype forKey:@"covertype"];
  7820. [params setValue:ctgid forKey:@"ctgId"];
  7821. [params setValue:modelname forKey:@"modelName"];
  7822. [params setValue:modeldescrip forKey:@"modelDescription"];
  7823. [params setValue:alert forKey:@"alert"];
  7824. [params setValue:qty forKey:@"sold_by_qty"];
  7825. [params setValue:available forKey:@"available"];
  7826. [params setValue:price forKey:@"price"];
  7827. [params setValue:bestseller forKey:@"bestseller"];
  7828. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7829. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7830. if(appDelegate.offline_mode)
  7831. {
  7832. // [OLDataProvider offline_itemsearch:params completionHandler:result];
  7833. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7834. NSMutableDictionary* json = [[OLDataProvider offline_itemsearch:params] mutableCopy];
  7835. dispatch_async(dispatch_get_main_queue(), ^{
  7836. result(json);
  7837. });
  7838. });
  7839. return;
  7840. }
  7841. [self request_interface:URL_ITEM_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  7842. // if(appDelegate.offline_mode)
  7843. // {
  7844. // return [OLDataProvider offline_itemsearch:params];
  7845. // }
  7846. // if(![self IsNetworkAvailable])
  7847. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7848. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  7849. // if(json==nil)
  7850. // return nil;
  7851. // NSError *error=nil;
  7852. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7853. // return jsobj;
  7854. }
  7855. +(void)request_modelqty: (NSString*) fashionId completionHandler:(resultHandler)result
  7856. {
  7857. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7858. AppDelegate *appDelegate = nil;
  7859. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7860. if(appDelegate.user!=nil)
  7861. [params setValue:appDelegate.user forKey:@"user"];
  7862. if(appDelegate.contact_id!=nil)
  7863. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7864. if(appDelegate.password!=nil)
  7865. [params setValue:appDelegate.password forKey:@"password"];
  7866. [params setValue:fashionId forKey:@"fashionId"];
  7867. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  7868. if(appDelegate.offline_mode)
  7869. {
  7870. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7871. NSData* json = [[OLDataProvider offline_model_qty:params] mutableCopy];
  7872. dispatch_async(dispatch_get_main_queue(), ^{
  7873. result([[RAConvertor data2dict:json] mutableCopy]);
  7874. });
  7875. });
  7876. return;
  7877. }
  7878. [self request_interface:URL_REQUEST_MODEL_QTY parameters:params err_record_url:nil completionHandler:result retry:0];
  7879. // NSData* json = nil;
  7880. // if(appDelegate.offline_mode)
  7881. // {
  7882. // json = [OLDataProvider offline_model_qty:params];
  7883. // } else {
  7884. // if(![self IsNetworkAvailable])
  7885. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7886. //
  7887. // json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  7888. // }
  7889. // if(json==nil)
  7890. // return nil;
  7891. // NSError *error=nil;
  7892. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7893. // return jsobj;
  7894. }
  7895. +(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
  7896. {
  7897. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7898. AppDelegate *appDelegate = nil;
  7899. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7900. if(appDelegate.user!=nil)
  7901. [params setValue:appDelegate.user forKey:@"user"];
  7902. if(appDelegate.contact_id!=nil)
  7903. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7904. if(appDelegate.password!=nil)
  7905. [params setValue:appDelegate.password forKey:@"password"];
  7906. [params setValue:watchlist_id forKey:@"item_id"];
  7907. // if(notes.length>0)
  7908. // [params setValue:notes forKey:@"notes"];
  7909. if(notes)
  7910. [params setValue:notes forKey:@"notes"];
  7911. if(price != -MAXFLOAT)
  7912. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  7913. if (discount != -MAXFLOAT)
  7914. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  7915. if(qty_p != -MAXFLOAT)
  7916. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  7917. if(qty != -INT32_MAX)
  7918. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  7919. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  7920. // NSData* json = nil;
  7921. if(appDelegate.offline_mode)
  7922. {
  7923. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7924. NSData* json = [[OLDataProvider offline_editPortfolio:params] mutableCopy];
  7925. dispatch_async(dispatch_get_main_queue(), ^{
  7926. result([[RAConvertor data2dict:json] mutableCopy]);
  7927. });
  7928. });
  7929. return;
  7930. }
  7931. [self request_interface:URL_PORTFOLIO_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  7932. //
  7933. // if(appDelegate.offline_mode)
  7934. // {
  7935. // json = [OLDataProvider offline_editPortfolio:params];
  7936. // } else {
  7937. // if(![self IsNetworkAvailable])
  7938. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7939. //
  7940. // json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  7941. // }
  7942. // if(json==nil)
  7943. // return nil;
  7944. // NSError *error=nil;
  7945. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7946. // return jsobj;
  7947. }
  7948. +(void)request_add_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7949. {
  7950. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7951. AppDelegate *appDelegate = nil;
  7952. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7953. if(appDelegate.user!=nil)
  7954. [params setValue:appDelegate.user forKey:@"user"];
  7955. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  7956. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7957. // else
  7958. if(appDelegate.contact_id!=nil)
  7959. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7960. if(appDelegate.password!=nil)
  7961. [params setValue:appDelegate.password forKey:@"password"];
  7962. // NSDictionary* customerinfo=nil;
  7963. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  7964. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7965. // else
  7966. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7967. //
  7968. // appDelegate.customerInfo;
  7969. // NSArray* keys=[customerinfo allKeys];
  7970. // for(int i=0;i<keys.count;i++)
  7971. // {
  7972. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7973. // }
  7974. // [params setValue:sourceid forKey:@"sourceid"];
  7975. // [params setValue:editor forKey:@"editor"];
  7976. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  7977. if(appDelegate.offline_mode)
  7978. {
  7979. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7980. NSData* json = [[OLDataProvider offline_saveNewContact:params] mutableCopy];
  7981. dispatch_async(dispatch_get_main_queue(), ^{
  7982. result([[RAConvertor data2dict:json] mutableCopy]);
  7983. });
  7984. });
  7985. return;
  7986. }
  7987. [self request_interface:URL_CUSTOMER_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  7988. //
  7989. // NSData* json=nil;
  7990. // if(appDelegate.offline_mode)
  7991. // {
  7992. // json= [OLDataProvider offline_saveNewContact:params];
  7993. // }
  7994. // else
  7995. // {
  7996. // if(![self IsNetworkAvailable])
  7997. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7998. //
  7999. // json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  8000. // }
  8001. //
  8002. // if(json!=nil)
  8003. // {
  8004. // NSError *error=nil;
  8005. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8006. // return jsobj;
  8007. // }
  8008. // else
  8009. // return nil;
  8010. }
  8011. +(void)request_update_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8012. {
  8013. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8014. AppDelegate *appDelegate = nil;
  8015. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8016. if(appDelegate.user!=nil)
  8017. [params setValue:appDelegate.user forKey:@"user"];
  8018. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  8019. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8020. // else
  8021. if(appDelegate.contact_id!=nil)
  8022. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8023. if(appDelegate.password!=nil)
  8024. [params setValue:appDelegate.password forKey:@"password"];
  8025. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8026. if(appDelegate.offline_mode)
  8027. {
  8028. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8029. NSData* json = [[OLDataProvider offline_saveContact:params] mutableCopy];
  8030. dispatch_async(dispatch_get_main_queue(), ^{
  8031. result([[RAConvertor data2dict:json] mutableCopy]);
  8032. });
  8033. });
  8034. return;
  8035. }
  8036. [self request_interface:URL_CUSTOMER_UPDATE parameters:params err_record_url:nil completionHandler:result retry:0];
  8037. //
  8038. // NSData* json=nil;
  8039. // if(appDelegate.offline_mode)
  8040. // {
  8041. // json= [OLDataProvider offline_saveContact:params];
  8042. // }
  8043. // else
  8044. // {
  8045. // if(![self IsNetworkAvailable])
  8046. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8047. //
  8048. // json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  8049. // }
  8050. //
  8051. // if(json!=nil)
  8052. // {
  8053. // NSError *error=nil;
  8054. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8055. // return jsobj;
  8056. // }
  8057. // else
  8058. // return nil;
  8059. }
  8060. +(void)request_delete_order:(NSString*) order_id completionHandler:(resultHandler)result
  8061. {
  8062. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8063. AppDelegate *appDelegate = nil;
  8064. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8065. if(appDelegate.user!=nil)
  8066. [params setValue:appDelegate.user forKey:@"user"];
  8067. // if(appDelegate.contact_id!=nil)
  8068. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8069. if(appDelegate.password!=nil)
  8070. [params setValue:appDelegate.password forKey:@"password"];
  8071. [params setValue:order_id forKey:@"orderId"];
  8072. // [params setValue:sourceid forKey:@"sourceid"];
  8073. // [params setValue:editor forKey:@"editor"];
  8074. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8075. if(appDelegate.offline_mode)
  8076. {
  8077. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8078. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8079. dispatch_async(dispatch_get_main_queue(), ^{
  8080. result(json);
  8081. });
  8082. });
  8083. return;
  8084. }
  8085. [self request_interface:URL_DELETE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8086. //
  8087. // if(appDelegate.offline_mode)
  8088. // {
  8089. // return [OLDataProvider offline_notimpl];
  8090. // }
  8091. // if(![self IsNetworkAvailable])
  8092. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8093. //
  8094. // NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  8095. // if(json!=nil)
  8096. // {
  8097. // NSError *error=nil;
  8098. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8099. //
  8100. //
  8101. // return jsobj;
  8102. // }
  8103. // else
  8104. // return nil;
  8105. }
  8106. +(void)request_cancel_order:(NSString*) order_id order_code:(NSString*) order_code completionHandler:(resultHandler)result
  8107. {
  8108. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8109. AppDelegate *appDelegate = nil;
  8110. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8111. if(appDelegate.user!=nil)
  8112. [params setValue:appDelegate.user forKey:@"user"];
  8113. // if(appDelegate.contact_id!=nil)
  8114. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8115. if(appDelegate.password!=nil)
  8116. [params setValue:appDelegate.password forKey:@"password"];
  8117. [params setValue:order_id forKey:@"orderId"];
  8118. [params setValue:order_code forKey:@"orderCode"];
  8119. // [params setValue:sourceid forKey:@"sourceid"];
  8120. // [params setValue:editor forKey:@"editor"];
  8121. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8122. if(appDelegate.offline_mode)
  8123. {
  8124. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8125. NSData* json = [[OLDataProvider offline_cancelorder:params] mutableCopy];
  8126. dispatch_async(dispatch_get_main_queue(), ^{
  8127. result([[RAConvertor data2dict:json] mutableCopy]);
  8128. });
  8129. });
  8130. return;
  8131. }
  8132. [self request_interface:URL_CANCEL_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8133. //
  8134. // NSData* json=nil;
  8135. // if(appDelegate.offline_mode)
  8136. // {
  8137. // json=[OLDataProvider offline_cancelorder:params];
  8138. // }
  8139. // else
  8140. // {
  8141. // if(![self IsNetworkAvailable])
  8142. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8143. // json=[self get_json:URL_CANCEL_ORDER parameters:params];
  8144. // }
  8145. // if(json!=nil)
  8146. // {
  8147. // NSError *error=nil;
  8148. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8149. //
  8150. //
  8151. // return jsobj;
  8152. // }
  8153. // else
  8154. // return nil;
  8155. }
  8156. +(void)request_release_order:(NSString*) order_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  8157. {
  8158. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8159. AppDelegate *appDelegate = nil;
  8160. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8161. if(appDelegate.user!=nil)
  8162. [params setValue:appDelegate.user forKey:@"user"];
  8163. // if(appDelegate.contact_id!=nil)
  8164. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8165. if(appDelegate.password!=nil)
  8166. [params setValue:appDelegate.password forKey:@"password"];
  8167. [params setValue:order_code forKey:@"orderCode"];
  8168. // [params setValue:sourceid forKey:@"sourceid"];
  8169. // [params setValue:editor forKey:@"editor"];
  8170. if (screenName) {
  8171. [params setValue:screenName forKey:kScreenName];
  8172. }
  8173. if(appDelegate.offline_mode)
  8174. {
  8175. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8176. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_resetorder:params]] mutableCopy];
  8177. dispatch_async(dispatch_get_main_queue(), ^{
  8178. if([[resulti valueForKey:@"result"]intValue]==2)
  8179. { [appDelegate SetSo:nil];
  8180. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8181. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8182. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8183. [appDelegate update_count_mark];
  8184. dispatch_async(dispatch_get_main_queue(), ^{
  8185. result(resulti);
  8186. });
  8187. }
  8188. });
  8189. });
  8190. return;
  8191. }
  8192. [self request_interface:URL_RELEASE_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8193. if([[resulti valueForKey:@"result"]intValue]==2)
  8194. { [appDelegate SetSo:nil];
  8195. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8196. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8197. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8198. [appDelegate update_count_mark];
  8199. dispatch_async(dispatch_get_main_queue(), ^{
  8200. result(resulti);
  8201. });
  8202. }
  8203. } retry:0];
  8204. //
  8205. // NSData* json=nil;
  8206. // if(appDelegate.offline_mode)
  8207. // {
  8208. // json= [OLDataProvider offline_resetorder:params];
  8209. // }
  8210. // else
  8211. // {
  8212. // if(![self IsNetworkAvailable])
  8213. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8214. //
  8215. // json=[self get_json:URL_RELEASE_ORDER parameters:params];
  8216. // }
  8217. // if(json!=nil)
  8218. // {
  8219. // NSError *error=nil;
  8220. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8221. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8222. // { [appDelegate SetSo:nil];
  8223. //
  8224. //
  8225. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8226. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8227. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8228. //
  8229. // [appDelegate update_count_mark];
  8230. // }
  8231. // return jsobj;
  8232. // }
  8233. // else
  8234. // return nil;
  8235. }
  8236. +(void)request_update_order_signature:(NSString*) order_code path:(NSString*)path completionHandler:(resultHandler)result
  8237. {
  8238. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8239. AppDelegate *appDelegate = nil;
  8240. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8241. if(appDelegate.user!=nil)
  8242. [params setValue:appDelegate.user forKey:@"user"];
  8243. if(appDelegate.contact_id!=nil)
  8244. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8245. if(appDelegate.password!=nil)
  8246. [params setValue:appDelegate.password forKey:@"password"];
  8247. // NSString* ssaved = @"false";
  8248. // if(saved)
  8249. // ssaved=@"true";
  8250. // [params setValue:@"true" forKey:@"saved"];
  8251. [params setValue:order_code forKey:@"orderCode"];
  8252. [params setValue:path forKey:@"picpath"];
  8253. // [params setValue:sourceid forKey:@"sourceid"];
  8254. // [params setValue:editor forKey:@"editor"];
  8255. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  8256. if(appDelegate.offline_mode)
  8257. {
  8258. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8259. NSData* json = [[OLDataProvider offline_signorder:params] mutableCopy];
  8260. dispatch_async(dispatch_get_main_queue(), ^{
  8261. result([[RAConvertor data2dict:json] mutableCopy]);
  8262. });
  8263. });
  8264. return;
  8265. }
  8266. [self request_interface:URL_SIGN_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8267. //
  8268. // NSData* json=nil;
  8269. // if(appDelegate.offline_mode)
  8270. // {
  8271. // json= [OLDataProvider offline_signorder:params];
  8272. // }
  8273. // else
  8274. // {
  8275. // if(![self IsNetworkAvailable])
  8276. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8277. //
  8278. // json=[self get_json:URL_SIGN_ORDER parameters:params];
  8279. // }
  8280. // if(json!=nil)
  8281. // {
  8282. // NSError *error=nil;
  8283. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8284. // return jsobj;
  8285. // }
  8286. // else
  8287. // return nil;
  8288. }
  8289. #ifdef SCANNER_ORDER
  8290. +(void) request_scan_bulkdiscount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8291. {
  8292. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  8293. //
  8294. //
  8295. // [appDelegate update_count_mark];
  8296. if(RASingleton.sharedInstance.price_type==0)
  8297. {
  8298. result(RASingleton.sharedInstance.scan_cart);
  8299. return;
  8300. }
  8301. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  8302. int count = [section[@"count"] intValue];
  8303. for(int i=0;i<count;i++)
  8304. {
  8305. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  8306. if ([item[@"special_price"] boolValue]||[item[@"net_price"] boolValue])
  8307. continue;
  8308. int item_count = [item[@"count"] intValue];
  8309. float price=[item[@"unit_price"] floatValue] ;
  8310. item[@"discount"] =@(discount);
  8311. item[@"subtotal_price"] =@(price*item_count);
  8312. if(discount>0)
  8313. item[@"note"] =[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  8314. else
  8315. item[@"note"] =@"";
  8316. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  8317. }
  8318. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  8319. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  8320. result(RASingleton.sharedInstance.scan_cart);
  8321. AppDelegate *appDelegate = nil;
  8322. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8323. [OLDataProvider updateScanOrder:appDelegate.order_code];
  8324. return;
  8325. }
  8326. #endif
  8327. +(void) request_update_cart_modelprice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8328. {
  8329. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8330. AppDelegate *appDelegate = nil;
  8331. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8332. #ifdef SCANNER_ORDER
  8333. // return;
  8334. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  8335. {
  8336. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  8337. //
  8338. //
  8339. // [appDelegate update_count_mark];
  8340. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  8341. int count = [section[@"count"] intValue];
  8342. for(int i=0;i<count;i++)
  8343. {
  8344. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  8345. if([item[@"cart_item_id"] isEqualToString:cart_id])
  8346. {
  8347. int item_count = [item[@"count"] intValue];
  8348. item[@"unit_price"] =@(price);
  8349. item[@"discount"] =@(discount);
  8350. item[@"subtotal_price"] =@(price*item_count);
  8351. if(discount>0)
  8352. item[@"note"] =[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  8353. else
  8354. item[@"note"] =@"";
  8355. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  8356. break;
  8357. }
  8358. }
  8359. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  8360. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  8361. result(RASingleton.sharedInstance.scan_cart);
  8362. [OLDataProvider updateScanOrder:appDelegate.order_code];
  8363. return;
  8364. }
  8365. #endif
  8366. if(appDelegate.user!=nil)
  8367. [params setValue:appDelegate.user forKey:@"user"];
  8368. if(appDelegate.contact_id!=nil)
  8369. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8370. if(appDelegate.password!=nil)
  8371. [params setValue:appDelegate.password forKey:@"password"];
  8372. [params setValue:cart_id forKey:@"cartitem_id"];
  8373. [params setValue:notes forKey:@"item_note"];
  8374. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  8375. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  8376. [params setObject:ScreenCodeCart forKey:kScreenName];
  8377. if(appDelegate.offline_mode)
  8378. {
  8379. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8380. NSData* json = [[OLDataProvider offline_cartsetprice:params] mutableCopy];
  8381. dispatch_async(dispatch_get_main_queue(), ^{
  8382. result([[RAConvertor data2dict:json] mutableCopy]);
  8383. });
  8384. });
  8385. return;
  8386. }
  8387. [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8388. //
  8389. // NSData* json= nil;
  8390. // if(appDelegate.offline_mode)
  8391. // {
  8392. // json=[OLDataProvider offline_cartsetprice:params];
  8393. // }
  8394. // else
  8395. // {
  8396. // if(![self IsNetworkAvailable])
  8397. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8398. //
  8399. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8400. // }
  8401. // if(json==nil)
  8402. // return nil;
  8403. // NSError *error=nil;
  8404. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8405. // return jsobj;
  8406. }
  8407. +(void) request_addto_cart:(NSString* ) item_id count:(int) count name:(NSString *)name completionHandler:(resultHandler)result
  8408. {
  8409. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8410. AppDelegate *appDelegate = nil;
  8411. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8412. if(appDelegate.user!=nil)
  8413. [params setValue:appDelegate.user forKey:@"user"];
  8414. if(appDelegate.contact_id!=nil)
  8415. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8416. if(appDelegate.password!=nil)
  8417. [params setValue:appDelegate.password forKey:@"password"];
  8418. if(appDelegate.order_code!=nil)
  8419. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8420. [params setValue:item_id forKey:@"product_id"];
  8421. [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  8422. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  8423. [params setObject:@"Add To Cart" forKey:kAction];
  8424. if (name) {
  8425. NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  8426. [params setObject:extra forKey:kExtra];
  8427. }
  8428. NSDictionary* customerinfo= appDelegate.customerInfo;
  8429. NSArray* keys=[customerinfo allKeys];
  8430. for(int i=0;i<keys.count;i++)
  8431. {
  8432. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8433. }
  8434. if(appDelegate.offline_mode)
  8435. {
  8436. // [OLDataProvider offline_add2cart:params completionHandler:^(NSMutableDictionary *resulti) {
  8437. // NSMutableDictionary* json = resulti;
  8438. // if ([json[@"result"] intValue]==2)
  8439. // {
  8440. // appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  8441. //
  8442. // [appDelegate update_count_mark];
  8443. // }
  8444. // result(json);
  8445. // }];
  8446. params[@"can_create_backorder"]= @(appDelegate.can_create_backorder);
  8447. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8448. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cart:params]] mutableCopy];
  8449. dispatch_async(dispatch_get_main_queue(), ^{
  8450. if ([json[@"result"] intValue]==2)
  8451. {
  8452. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  8453. [appDelegate update_count_mark];
  8454. }
  8455. result(json);
  8456. });
  8457. });
  8458. return;
  8459. }
  8460. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8461. if ([resulti[@"result"] intValue]==2)
  8462. {
  8463. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8464. [appDelegate update_count_mark];
  8465. }
  8466. result(resulti);
  8467. } retry:0];
  8468. //
  8469. // NSData* json=nil;
  8470. // if(appDelegate.offline_mode)
  8471. // {
  8472. // json=[OLDataProvider offline_add2cart:params];
  8473. // }
  8474. // else
  8475. // {
  8476. // if(![self IsNetworkAvailable])
  8477. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8478. //
  8479. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  8480. // }
  8481. // if(json==nil)
  8482. // return nil;
  8483. // NSError *error=nil;
  8484. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8485. //
  8486. //
  8487. //
  8488. // int result = [[jsobj valueForKey:@"result"] intValue];
  8489. //
  8490. // if (result==2)
  8491. // {
  8492. //
  8493. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8494. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8495. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8496. //
  8497. // [appDelegate update_count_mark];
  8498. // }
  8499. //
  8500. // return jsobj;
  8501. }
  8502. //+(void) request_update_cart_modelfree:(NSString*) cart_id isfree:(bool) isfree completionHandler:(resultHandler)result
  8503. //{
  8504. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8505. // AppDelegate *appDelegate = nil;
  8506. //
  8507. //
  8508. //
  8509. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8510. //
  8511. // if(appDelegate.user!=nil)
  8512. // [params setValue:appDelegate.user forKey:@"user"];
  8513. // if(appDelegate.contact_id!=nil)
  8514. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8515. // if(appDelegate.password!=nil)
  8516. // [params setValue:appDelegate.password forKey:@"password"];
  8517. //
  8518. // [params setValue:cart_id forKey:@"cartitem_id"];
  8519. //
  8520. // [params setObject:ScreenCodeCart forKey:kScreenName];
  8521. //
  8522. // NSString* free=nil;
  8523. //
  8524. // if(isfree)
  8525. // free=@"true";
  8526. // else
  8527. // free=@"false";
  8528. //
  8529. // [params setValue:free forKey:@"free_giveaway"];
  8530. //
  8531. //
  8532. // if(appDelegate.offline_mode)
  8533. // {
  8534. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8535. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8536. // dispatch_async(dispatch_get_main_queue(), ^{
  8537. // result(json);
  8538. // });
  8539. // });
  8540. //
  8541. // return;
  8542. //
  8543. // }
  8544. // [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8545. //
  8546. ////
  8547. ////
  8548. //// if(appDelegate.offline_mode)
  8549. //// {
  8550. //// return [OLDataProvider offline_notimpl];
  8551. //// }
  8552. //// if(![self IsNetworkAvailable])
  8553. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8554. ////
  8555. //// NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8556. //// if(json==nil)
  8557. //// return nil;
  8558. //// NSError *error=nil;
  8559. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8560. //// return jsobj;
  8561. //}
  8562. +(void)request_retrieve_password: (NSString*) user email:(NSString*) email completionHandler:(resultHandler)result
  8563. {
  8564. AppDelegate *appDelegate = nil;
  8565. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8566. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8567. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8568. // if(appDelegate.user!=nil)
  8569. // [params setValue:appDelegate.user forKey:@"user"];
  8570. // if(appDelegate.contact_id!=nil)
  8571. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8572. // if(appDelegate.password!=nil)
  8573. // [params setValue:appDelegate.password forKey:@"password"];
  8574. [params setValue:user forKey:@"username"];
  8575. [params setValue:email forKey:@"email"];
  8576. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  8577. if(appDelegate.offline_mode)
  8578. {
  8579. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8580. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8581. dispatch_async(dispatch_get_main_queue(), ^{
  8582. result(json);
  8583. });
  8584. });
  8585. return;
  8586. }
  8587. #ifdef SCANNER_ORDER
  8588. params[@"site_name"]=[RADataProvider getSiteName];
  8589. params[@"_method"]=@"forgotPasswordOfflineOrderUser";
  8590. params[@"user"]=user;
  8591. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_RETRIEVE_PASS];
  8592. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  8593. #else
  8594. [self request_interface:URL_RETRIEVE_PASS parameters:params err_record_url:nil completionHandler:result retry:0];
  8595. #endif
  8596. //
  8597. //
  8598. // if(![self IsNetworkAvailable])
  8599. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8600. //
  8601. // NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  8602. // if(json==nil)
  8603. // return nil;
  8604. // NSError *error=nil;
  8605. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8606. // return jsobj;
  8607. }
  8608. +(void)request_update_ordercustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info completionHandler:(resultHandler)result
  8609. {
  8610. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8611. AppDelegate *appDelegate = nil;
  8612. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8613. if(appDelegate.user!=nil)
  8614. [info setValue:appDelegate.user forKey:@"user"];
  8615. // if(appDelegate.contact_id!=nil)
  8616. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8617. if(appDelegate.password!=nil)
  8618. [info setValue:appDelegate.password forKey:@"password"];
  8619. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8620. [info setValue:order_code forKey:@"orderCode"];
  8621. // [params setValue:sourceid forKey:@"sourceid"];
  8622. // [params setValue:editor forKey:@"editor"];
  8623. if(appDelegate.offline_mode)
  8624. {
  8625. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8626. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8627. dispatch_async(dispatch_get_main_queue(), ^{
  8628. result(json);
  8629. });
  8630. });
  8631. return;
  8632. }
  8633. [self request_interface:URL_UPDATE_ORDERCUSTOMER parameters:info err_record_url:nil completionHandler:result retry:0];
  8634. // if(appDelegate.offline_mode)
  8635. // {
  8636. // return [OLDataProvider offline_notimpl];
  8637. // }
  8638. // if(![self IsNetworkAvailable])
  8639. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8640. //
  8641. // NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  8642. // if(json!=nil)
  8643. // {
  8644. // NSError *error=nil;
  8645. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8646. // return jsobj;
  8647. // }
  8648. // else
  8649. // return nil;
  8650. }
  8651. +(void)request_update_customer_img: (NSString*) contactid img_url:(NSString*) url completionHandler:(resultHandler)result
  8652. {
  8653. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8654. AppDelegate *appDelegate = nil;
  8655. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8656. if(appDelegate.user!=nil)
  8657. [params setValue:appDelegate.user forKey:@"user"];
  8658. // if(appDelegate.contact_id!=nil)
  8659. if(appDelegate.password!=nil)
  8660. [params setValue:appDelegate.password forKey:@"password"];
  8661. [params setValue:contactid forKey:@"contactId"];
  8662. [params setValue:url forKey:@"business_card"];
  8663. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  8664. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8665. if(appDelegate.offline_mode)
  8666. {
  8667. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8668. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8669. dispatch_async(dispatch_get_main_queue(), ^{
  8670. result(json);
  8671. });
  8672. });
  8673. return;
  8674. }
  8675. [self request_interface:URL_UPDATE_CUSTOMER_BCARD parameters:params err_record_url:nil completionHandler:result retry:0];
  8676. // if(appDelegate.offline_mode)
  8677. // {
  8678. // return [OLDataProvider offline_notimpl];
  8679. // }
  8680. // if(![self IsNetworkAvailable])
  8681. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8682. //
  8683. // NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  8684. // if(json==nil)
  8685. // return nil;
  8686. // NSError *error=nil;
  8687. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8688. // return jsobj;
  8689. }
  8690. +(void)request_commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url completionHandler:(resultHandler)result
  8691. {
  8692. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8693. AppDelegate *appDelegate = nil;
  8694. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8695. if(appDelegate.user!=nil)
  8696. [params setValue:appDelegate.user forKey:@"user"];
  8697. if(appDelegate.contact_id!=nil)
  8698. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8699. if(appDelegate.password!=nil)
  8700. [params setValue:appDelegate.password forKey:@"password"];
  8701. // if(appDelegate.order_code!=nil)
  8702. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8703. // NSDictionary* customerinfo= appDelegate.customerInfo;
  8704. //
  8705. // NSArray* keys=[customerinfo allKeys];
  8706. // for(int i=0;i<keys.count;i++)
  8707. // {
  8708. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8709. // }
  8710. //
  8711. // [params setValue:sourceid forKey:@"sourceid"];
  8712. // [params setValue:editor forKey:@"editor"];
  8713. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  8714. if(appDelegate.offline_mode)
  8715. {
  8716. params[@"offline_Command"]=url;
  8717. [OLDataProvider offline_commoneditor_partialrefresh:params completionHandler:result];
  8718. //
  8719. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8720. // NSMutableDictionary* json = [[OLDataProvider offline_commoneditor_partialrefresh:params] mutableCopy];
  8721. // dispatch_async(dispatch_get_main_queue(), ^{
  8722. // result(json);
  8723. // });
  8724. // });
  8725. return;
  8726. }
  8727. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  8728. //
  8729. // if(appDelegate.offline_mode)
  8730. // {
  8731. // params[@"offline_Command"]=url;
  8732. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  8733. // }
  8734. //
  8735. // if(![self IsNetworkAvailable])
  8736. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8737. //
  8738. // NSData* json=[self get_json:url parameters:params];
  8739. // if(json!=nil)
  8740. // {
  8741. // NSError *error=nil;
  8742. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8743. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8744. // [appDelegate SetSo:nil];
  8745. //
  8746. //
  8747. // return jsobj;
  8748. // }
  8749. // else
  8750. // return nil;
  8751. }
  8752. +(void)request_add_address:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8753. {
  8754. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8755. AppDelegate *appDelegate = nil;
  8756. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8757. if(appDelegate.user!=nil)
  8758. [params setValue:appDelegate.user forKey:@"user"];
  8759. if(appDelegate.contact_id!=nil)
  8760. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8761. if(appDelegate.password!=nil)
  8762. [params setValue:appDelegate.password forKey:@"password"];
  8763. // [params setValue:sourceid forKey:@"sourceid"];
  8764. // [params setValue:editor forKey:@"editor"];
  8765. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  8766. if(appDelegate.offline_mode)
  8767. {
  8768. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8769. NSData* json = [[OLDataProvider offline_saveaddr:params] mutableCopy];
  8770. dispatch_async(dispatch_get_main_queue(), ^{
  8771. result([[RAConvertor data2dict:json] mutableCopy]);
  8772. });
  8773. });
  8774. return;
  8775. }
  8776. [self request_interface:URL_ADDRESS_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  8777. //
  8778. // NSData* json=nil;
  8779. //
  8780. // if(appDelegate.offline_mode)
  8781. // {
  8782. // json= [OLDataProvider offline_saveaddr: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_ADDRESS_SAVE parameters:params];
  8790. // }
  8791. // if(json!=nil)
  8792. // {
  8793. // NSError *error=nil;
  8794. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8795. // return jsobj;
  8796. // }
  8797. // else
  8798. // return nil;
  8799. }
  8800. +(void)request_commit_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8801. {
  8802. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8803. AppDelegate *appDelegate = nil;
  8804. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8805. if(appDelegate.user!=nil)
  8806. [params setValue:appDelegate.user forKey:@"user"];
  8807. if(appDelegate.contact_id!=nil)
  8808. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8809. if(appDelegate.password!=nil)
  8810. [params setValue:appDelegate.password forKey:@"password"];
  8811. if(appDelegate.order_code!=nil)
  8812. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8813. // NSDictionary* customerinfo= appDelegate.customerInfo;
  8814. //
  8815. // NSArray* keys=[customerinfo allKeys];
  8816. // for(int i=0;i<keys.count;i++)
  8817. // {
  8818. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8819. // }
  8820. //
  8821. // [params setValue:sourceid forKey:@"sourceid"];
  8822. // [params setValue:editor forKey:@"editor"];
  8823. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  8824. if(appDelegate.offline_mode)
  8825. {
  8826. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8827. NSData* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  8828. dispatch_async(dispatch_get_main_queue(), ^{
  8829. result([[RAConvertor data2dict:json] mutableCopy]);
  8830. });
  8831. });
  8832. return;
  8833. }
  8834. [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8835. //
  8836. // NSData* json=nil;
  8837. // if(appDelegate.offline_mode)
  8838. // {
  8839. // json=[OLDataProvider offline_submitorder:params];
  8840. // }
  8841. // else
  8842. // {
  8843. // if(![self IsNetworkAvailable])
  8844. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8845. //
  8846. // json=[self get_json:URL_COMMIT_ORDER parameters:params];
  8847. // }
  8848. // if(json!=nil)
  8849. // {
  8850. // NSError *error=nil;
  8851. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8852. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8853. // [appDelegate SetSo:nil];
  8854. //
  8855. //
  8856. // return jsobj;
  8857. // }
  8858. // else
  8859. // return nil;
  8860. }
  8861. +(void) request_new_offline_ticket:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid completionHandler:(resultHandler)result
  8862. {
  8863. // if(![self IsNetworkAvailable])
  8864. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8865. //
  8866. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8867. AppDelegate *appDelegate = nil;
  8868. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8869. if(appDelegate.user!=nil)
  8870. [params setValue:appDelegate.user forKey:@"user"];
  8871. // if(appDelegate.contact_id!=nil)
  8872. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8873. if(appDelegate.password!=nil)
  8874. [params setValue:appDelegate.password forKey:@"password"];
  8875. [params setValue:ver forKey:@"ver"];
  8876. [params setValue:vid forKey:@"vid"];
  8877. if(buseinternaladdress)
  8878. [params setValue:@"true" forKey:@"internal_address"];
  8879. else
  8880. [params setValue:@"false" forKey:@"internal_address"];
  8881. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  8882. // 无论当前是离线还是在线状态,都可以进行同步;
  8883. // if(appDelegate.offline_mode)
  8884. // {
  8885. //
  8886. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8887. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8888. // dispatch_async(dispatch_get_main_queue(), ^{
  8889. // result(json);
  8890. // });
  8891. // });
  8892. //
  8893. // return;
  8894. //
  8895. // }
  8896. [self request_interface:URL_CHECK_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  8897. //
  8898. // NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  8899. // if(json==nil)
  8900. // return nil;
  8901. // NSError *error=nil;
  8902. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8903. // // int result = [[jsobj valueForKey:@"result"] intValue];
  8904. // //
  8905. // // if (result==2)
  8906. // // {
  8907. // //
  8908. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8909. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  8910. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8911. // ////
  8912. // //// [appDelegate update_count_mark];
  8913. // // }
  8914. // return jsobj;
  8915. }
  8916. +(void) request_complete_offline_ticket:(NSString* )vid completionHandler:(resultHandler)result
  8917. {
  8918. AppDelegate *appDelegate = nil;
  8919. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8920. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8921. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  8922. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8923. // if(appDelegate.user!=nil)
  8924. // [params setValue:appDelegate.user forKey:@"user"];
  8925. // // if(appDelegate.contact_id!=nil)
  8926. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8927. // if(appDelegate.password!=nil)
  8928. // [params setValue:appDelegate.password forKey:@"password"];
  8929. [params setValue:vid forKey:@"downSerial"];
  8930. // 无论当前是离线还是在线状态,都可以进行同步;
  8931. // if(appDelegate.offline_mode)
  8932. // {
  8933. //
  8934. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8935. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8936. // dispatch_async(dispatch_get_main_queue(), ^{
  8937. // result(json);
  8938. // });
  8939. // });
  8940. //
  8941. // return;
  8942. //
  8943. // }
  8944. [self request_interface:URL_FINISH_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  8945. // NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  8946. // if(json==nil)
  8947. // return nil;
  8948. // NSError *error=nil;
  8949. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8950. // // int result = [[jsobj valueForKey:@"result"] intValue];
  8951. // //
  8952. // // if (result==2)
  8953. // // {
  8954. // //
  8955. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8956. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  8957. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8958. // ////
  8959. // //// [appDelegate update_count_mark];
  8960. // // }
  8961. // return jsobj;
  8962. }
  8963. +(void) request_download_offline:(NSString* )vid completionHandler:(resultHandler)result
  8964. {
  8965. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8966. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  8967. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8968. // if(appDelegate.user!=nil)
  8969. // [params setValue:appDelegate.user forKey:@"user"];
  8970. // // if(appDelegate.contact_id!=nil)
  8971. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8972. // if(appDelegate.password!=nil)
  8973. // [params setValue:appDelegate.password forKey:@"password"];
  8974. [params setValue:vid forKey:@"downSerial"];
  8975. // AppDelegate *appDelegate = nil;
  8976. //
  8977. //
  8978. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8979. // if(appDelegate.offline_mode)
  8980. // {
  8981. //
  8982. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8983. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8984. // dispatch_async(dispatch_get_main_queue(), ^{
  8985. // result(json);
  8986. // });
  8987. // });
  8988. //
  8989. // return;
  8990. //
  8991. // }
  8992. __block bool bbreak = false;
  8993. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8994. __block NSMutableDictionary* download_json=nil;
  8995. int count=0;
  8996. // __block bool preparing = true;
  8997. while ([[download_json valueForKey:@"result"] intValue]!=2&&count<REQUEST_DOWNLOAD_RETRY_TIMES) //超过60分钟还没准被好数据就视为服务器出错。
  8998. {
  8999. if(bbreak)
  9000. break;
  9001. dispatch_async(dispatch_get_main_queue(), ^{
  9002. [self request_interface:URL_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  9003. if([resulti[@"result"] intValue]==RESULT_TRUE)
  9004. {
  9005. if(!bbreak) //此判断保证result只调用一次。
  9006. {
  9007. // appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  9008. // [appDelegate update_count_mark];
  9009. resulti[@"request_count"]=[NSNumber numberWithInt:count];
  9010. result(resulti);
  9011. }
  9012. bbreak=true;
  9013. }
  9014. else if([resulti[@"result"] intValue]==RESULT_ERROR)
  9015. {
  9016. result(resulti);
  9017. bbreak=true;
  9018. }
  9019. } retry:3];
  9020. });
  9021. sleep(RETRY_DELAY);
  9022. count++;
  9023. // download_json=[[RANetwork download_Offline:downSerial] mutableCopy];
  9024. //
  9025. // [RANetwork request_download_offline:downSerial completionHandler:^(NSMutableDictionary *result) {
  9026. // download_json=result;
  9027. // }];
  9028. //
  9029. }
  9030. // for(int i=0;i<150;i++)
  9031. // {
  9032. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  9033. // // result_params[@"resultSerial"]=uuid;
  9034. //
  9035. //
  9036. //
  9037. // sleep(2);
  9038. //
  9039. // // json=[self get_json:URL_CART parameters:params];
  9040. // // if(json!=nil)
  9041. // // {
  9042. // //
  9043. // // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9044. // // if([jsobj[@"result"] intValue]==2)
  9045. // // {
  9046. // // break;
  9047. // // }
  9048. // // }
  9049. //
  9050. // }
  9051. });
  9052. //
  9053. // NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  9054. // if(json==nil)
  9055. // return nil;
  9056. // NSError *error=nil;
  9057. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9058. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9059. // //
  9060. // // if (result==2)
  9061. // // {
  9062. // //
  9063. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9064. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9065. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9066. // ////
  9067. // //// [appDelegate update_count_mark];
  9068. // // }
  9069. // return jsobj;
  9070. }
  9071. + (void)request_fastupload:(NSMutableDictionary *)params filename:(NSString*)filename data:(NSData*) data url:(NSString *)url completionHandler:(resultHandler)result
  9072. {
  9073. //#ifdef test_server
  9074. // url=URL_REQUEST_RECORDS;
  9075. // params[@"prefix"]=URL_REQUEST_RECORDS;
  9076. //#endif
  9077. // [self request_file_fast:url parameters:params completionHandler:result];
  9078. #ifdef SCANNER_ORDER
  9079. params[@"site_name"]=[RADataProvider getSiteName];
  9080. #endif
  9081. [self request_upload_fast:data FileName:filename server:url parameters:params completionHandler:result];
  9082. }
  9083. +(void)request_err_log:(NSString*) up_params result:(NSString*)result_str module:(NSString*) module code:(int) code completionHandler:(resultHandler)result
  9084. {
  9085. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9086. AppDelegate *appDelegate = nil;
  9087. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9088. if(appDelegate.user!=nil)
  9089. [params setValue:appDelegate.user forKey:@"user"];
  9090. [params setValue:up_params forKey:@"upparam"];
  9091. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  9092. [params setValue:result_str forKey:@"result"];
  9093. [params setValue:module forKey:@"interfac"];
  9094. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  9095. // [params setValue:module forKey:@"module"];
  9096. // [[UIDevice currentDevice] name];
  9097. // if(appDelegate.offline_mode)
  9098. // {
  9099. // return [OLDataProvider offline_notimpl];
  9100. // }
  9101. if(appDelegate.offline_mode)
  9102. {
  9103. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9104. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9105. dispatch_async(dispatch_get_main_queue(), ^{
  9106. result(json);
  9107. });
  9108. });
  9109. return;
  9110. }
  9111. [self request_interface:URL_ERR_LOG parameters:params err_record_url:nil completionHandler:result retry:0];
  9112. //
  9113. // if(![self IsNetworkAvailable])
  9114. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9115. //
  9116. // NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  9117. // if(json==nil)
  9118. // return nil;
  9119. // NSError *error=nil;
  9120. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9121. // return jsobj;
  9122. }
  9123. @end