RANetwork.m 395 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944
  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(RASingleton.sharedInstance.duid!=nil && params[@"udid"]==nil)
  89. params[@"udid"]=RASingleton.sharedInstance.duid;
  90. #if TARGET_IPHONE_SIMULATOR//模拟器
  91. params[@"udid"]=@"simulator";
  92. #endif
  93. # ifdef DEBUG
  94. [params setValue:@"true" forKey:@"is_debug"];
  95. # endif
  96. if(appDelegate.user!=nil && params[@"user"]==nil)
  97. [params setValue:appDelegate.user forKey:@"user"];
  98. if(appDelegate.password!=nil&& params[@"password"]==nil)
  99. [params setValue:appDelegate.password forKey:@"password"];
  100. if(appDelegate.ipad_perm!=nil)
  101. [params setValue:appDelegate.ipad_perm forKey:@"ipad_perm"];
  102. [params setValue:appDelegate.build forKey:@"app_ver"];
  103. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  104. NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  105. [params setValue:short_version forKey:@"app_short_ver"];
  106. #if TARGET_IPHONE_SIMULATOR//模拟器
  107. [params setValue:@"simulator_uuid" forKey:@"idfv"];
  108. #elif TARGET_OS_IPHONE//真机
  109. UIDevice * dev = [UIDevice currentDevice];
  110. NSUUID* uuid =dev.identifierForVendor;
  111. [params setValue:uuid.UUIDString forKey:@"idfv"];
  112. #endif
  113. //
  114. // NSString *userAction = [params valueForKey:kAction];
  115. // NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  116. // if ([userAction isEqualToString:@"Login"]) {
  117. // if (!extra) {
  118. // extra = [NSMutableDictionary dictionary];
  119. // }
  120. // [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  121. // }
  122. return params;
  123. }
  124. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString *) file //delegate:(id < NSURLConnectionDelegate >)delegate
  125. {
  126. // NSString* e=[AESCrypt AES128Encrypt:@"密码学中的高级加密标准(Advanced Encryption Standard,AES),又称 高级加密标准Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用。经过五年的甄选流程,高级加密标准由美国国家标准与技术研究院 (NIST)于2001年11月26日发布于FIPS PUB 197,并在2002年5月26日成为有效的标准。2006年,高级加密标准已然成为对称密钥加密中最流行的算法之一。 " key:@"usai2010"];
  127. // DebugLog(e);
  128. // NSString* d=[AESCrypt decrypt:@"VzB4+lENfbzWX7ggHh2Os1P69l5YBzKmM51yqA37AfoKgPY8bJgdK8M4WvF+wDyOsLWP\/o8H5+bHMivQp1u8wM2QV7SYzgzPwV85QKtYWIzEgLe9T0HO69EdutWz7k1rdAT\/mftsRin0Hy5SHk7txTZT\/zPH5X+FQiExCTFm5Zus39HYvp+VxCX4+kYeymn8B63AUd3mRQyscUvDjfgU2olKR\/TP8PV3g+VQMZxpKfol3P1iOtz3XQlHZV0pM6SAf+SwT0sPfrdn6CZFfNQlrKA9QjMrnBdMeSCquSIWXnmLv6okzvnlJnT0SjvJuUeqNdBC5EZ0ACnhI0MrXVZEsq1EuM9al7oPzvU5EZbjZpmx+fSFIkMzTT8bYClTnG1bsL1MCcU4pSODDorUj8zalA==" password:@"usai2010"];
  129. params = [self prepare_additional_params:params];
  130. DebugLog(@"\n++++++++++++++++++++++Request++++++++++++++++++++++\n%@\n++++++++++++++++++++++Params++++++++++++++++++++++\n%@\n",url,[RAConvertor dict2string:params]);
  131. return [super get_json:url parameters:params file:(NSString*)file err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  132. int result=[[jsobj valueForKey:@"result"] intValue];
  133. // UIApplication * app = [UIApplication sharedApplication];
  134. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  135. switch (result) {
  136. case 0:
  137. [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  138. break;
  139. case 1:
  140. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  141. break;
  142. case 2:
  143. [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  144. break;
  145. case 8:
  146. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  147. break;
  148. case 9:
  149. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  150. break;
  151. case 99:
  152. [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  153. break;
  154. default:
  155. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  156. break;
  157. }
  158. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  159. // {
  160. // [jsobj setValue:@"9" forKey:@"result"];
  161. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  162. // }
  163. return jsobj;
  164. } decrypt_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  165. return nil;
  166. // NSString* base64str = jsobj[@"str"];
  167. // NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"usai2010"];
  168. // jsobj=[[RAUtils string2dict:decryptstr] mutableCopy];
  169. // return jsobj;
  170. }];
  171. /*
  172. */
  173. return nil;
  174. }
  175. +(void) LoadImage:(NSString*) url into:(UIImageView*) container
  176. {
  177. DebugLog(@"LoadImage:(NSString*) url in:(UIImageView*) container");
  178. NSString* file_name=[url lastPathComponent];
  179. NSData* img_data = [iSalesDB load_cached_img:file_name loadFrom:url];
  180. if(img_data==nil)
  181. {
  182. DebugLog(@"IMG NOT CACHED %@",file_name);
  183. img_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
  184. [iSalesDB cache_img:img_data filename:file_name saveTo:url];
  185. //load from internet;
  186. }
  187. if(img_data!=nil)
  188. {
  189. UIImage * img =[UIImage imageWithData:img_data];
  190. if(img==nil)
  191. DebugLog(@"UIIMAGE IS NIL! %@",file_name);
  192. else
  193. dispatch_async(dispatch_get_main_queue(), ^{
  194. container.image =img;
  195. });
  196. }
  197. else
  198. {
  199. DebugLog(@"IMG DOWNLOAD FAILED! %@",file_name);
  200. }
  201. }
  202. //+(NSData*)fake_json:(NSString*) url
  203. //{
  204. // NSString* jsonfile = nil;
  205. // if([url isEqualToString:URL_UPDATE_AUTH])
  206. // {
  207. // jsonfile=@"login";
  208. //
  209. // }
  210. // else if([url isEqualToString:URL_REQUEST_CATMENU])
  211. // {
  212. // jsonfile=@"categorymenu";
  213. // }
  214. // else if([url isEqualToString:URL_LOAD_HOME])
  215. // {
  216. // jsonfile=@"homepage";
  217. // }
  218. // else if([url isEqualToString:URL_SEARCH])
  219. // {
  220. // jsonfile=@"search";
  221. // }
  222. // else if([url isEqualToString:URL_CATEGORY_LOADMORE])
  223. // {
  224. // jsonfile=@"category_more";
  225. // }else if([url isEqualToString:URL_ITEM_DETAIL])
  226. // {
  227. // jsonfile=@"detail";
  228. // }else if([url isEqualToString:URL_CART])
  229. // {
  230. // jsonfile=@"cart";
  231. // }else if([url isEqualToString:URL_ORDER_LIST])
  232. // {
  233. // jsonfile=@"orderlist";
  234. // }
  235. //// else if([url isEqualToString:URL_ORDER_INFO])
  236. //// {
  237. //// jsonfile=@"orderinfo";
  238. //// }
  239. //// else if([url isEqualToString:URL_ORDER_INFO])
  240. //// {
  241. //// jsonfile=@"orderinfo2label";
  242. //// }
  243. //
  244. //
  245. //
  246. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:jsonfile ofType:@"json" ]];
  247. // NSMutableString *result = [[NSMutableString alloc] initWithData:json encoding:NSUTF8StringEncoding];
  248. //
  249. // DebugLog(@"result: \n%@",result);
  250. // return json;
  251. //}
  252. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
  253. {
  254. NSString *userAction = [params valueForKey:kAction];
  255. NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  256. if ([userAction isEqualToString:@"Login"]) {
  257. if (!extra) {
  258. extra = [NSMutableDictionary dictionary];
  259. }
  260. [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  261. }
  262. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  263. NSString *screenName = [params valueForKey:kScreenName];
  264. [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  265. #endif
  266. return [self get_json:url parameters:params file:nil];
  267. }
  268. //+(NSDictionary*)request_Editor:(NSString*) sourceid editor:(NSString*)editor
  269. //{
  270. //
  271. //}
  272. +(NSDictionary*) delete_portfoliolist:(NSString* ) listid
  273. {
  274. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  275. __block AppDelegate *appDelegate = nil;
  276. dispatch_sync(dispatch_get_main_queue(), ^{
  277. //some UI methods ej
  278. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  279. });
  280. if(appDelegate.user!=nil)
  281. [params setValue:appDelegate.user forKey:@"user"];
  282. if(appDelegate.contact_id!=nil)
  283. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  284. if(appDelegate.password!=nil)
  285. [params setValue:appDelegate.password forKey:@"password"];
  286. [params setValue:listid forKey:@"tearsheetsId"];
  287. // [params setValue:editor forKey:@"editor"];
  288. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  289. // [params setValue:@"Delete Portfolio" forKey:kAction];
  290. NSData* json = nil;
  291. if(appDelegate.offline_mode)
  292. {
  293. json = [OLDataProvider offline_removePDF:params];
  294. } else {
  295. if(![self IsNetworkAvailable])
  296. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  297. json=[self get_json:URL_PORTFOLIOLIST_REMOVE parameters:params];
  298. }
  299. if(json!=nil)
  300. {
  301. NSError *error=nil;
  302. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  303. return jsobj;
  304. }
  305. else
  306. return nil;
  307. }
  308. +(NSDictionary*) portfolio_remove:(NSString* ) item_ids
  309. {
  310. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  311. __block AppDelegate *appDelegate = nil;
  312. dispatch_sync(dispatch_get_main_queue(), ^{
  313. //some UI methods ej
  314. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  315. });
  316. if(appDelegate.user!=nil)
  317. [params setValue:appDelegate.user forKey:@"user"];
  318. if(appDelegate.contact_id!=nil)
  319. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  320. if(appDelegate.password!=nil)
  321. [params setValue:appDelegate.password forKey:@"password"];
  322. [params setValue:item_ids forKey:@"portfolioId"];
  323. // [params setValue:editor forKey:@"editor"];
  324. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  325. NSData* json = nil;
  326. if(appDelegate.offline_mode)
  327. {
  328. json = [OLDataProvider offline_removePortfolio:params];
  329. } else {
  330. if(![self IsNetworkAvailable])
  331. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  332. json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  333. }
  334. if(json!=nil)
  335. {
  336. NSError *error=nil;
  337. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  338. int result = [[jsobj valueForKey:@"result"] intValue];
  339. if (result==2)
  340. {
  341. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  342. [appDelegate update_count_mark];
  343. }
  344. return jsobj;
  345. }
  346. else
  347. return nil;
  348. }
  349. //+(NSDictionary*) watchlist_remove:(NSString* ) item_ids
  350. //{
  351. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  352. // __block AppDelegate *appDelegate = nil;
  353. //
  354. // dispatch_sync(dispatch_get_main_queue(), ^{
  355. // //some UI methods ej
  356. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  357. // });
  358. // if(appDelegate.user!=nil)
  359. // [params setValue:appDelegate.user forKey:@"user"];
  360. // if(appDelegate.contact_id!=nil)
  361. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  362. // if(appDelegate.password!=nil)
  363. // [params setValue:appDelegate.password forKey:@"password"];
  364. // [params setValue:item_ids forKey:@"collectId"];
  365. // // [params setValue:editor forKey:@"editor"];
  366. //
  367. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  368. //
  369. // if(appDelegate.offline_mode)
  370. // {
  371. // return [OLDataProvider offline_deletewishlist:params];
  372. // }
  373. // if(![self IsNetworkAvailable])
  374. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  375. //
  376. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  377. // if(json!=nil)
  378. // {
  379. // NSError *error=nil;
  380. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  381. // int result = [[jsobj valueForKey:@"result"] intValue];
  382. //
  383. // if (result==2)
  384. // {
  385. //
  386. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  387. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  388. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  389. //
  390. // [appDelegate update_count_mark];
  391. // }
  392. // return jsobj;
  393. // }
  394. // else
  395. // return nil;
  396. //}
  397. //+(NSDictionary*) move_cart2wish:(NSString* ) item_ids
  398. //{
  399. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  400. // __block AppDelegate *appDelegate = nil;
  401. //
  402. // dispatch_sync(dispatch_get_main_queue(), ^{
  403. // //some UI methods ej
  404. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  405. // });
  406. // if(appDelegate.user!=nil)
  407. // [params setValue:appDelegate.user forKey:@"user"];
  408. // if(appDelegate.contact_id!=nil)
  409. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  410. // if(appDelegate.password!=nil)
  411. // [params setValue:appDelegate.password forKey:@"password"];
  412. // if(appDelegate.order_code!=nil)
  413. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  414. // [params setValue:item_ids forKey:@"cartItemId"];
  415. // // [params setValue:editor forKey:@"editor"];
  416. //
  417. // [params setValue:ScreenCodeCart forKey:kScreenName];
  418. // // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  419. //
  420. // NSData* json = nil;
  421. // if(appDelegate.offline_mode)
  422. // {
  423. // json= [OLDataProvider offline_movecart2wish:params];
  424. // }
  425. // else
  426. // {
  427. // if(![self IsNetworkAvailable])
  428. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  429. //
  430. // json=[self get_json:URL_CART2WISH parameters:params];
  431. // }
  432. // if(json!=nil)
  433. // {
  434. // NSError *error=nil;
  435. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  436. // int result = [[jsobj valueForKey:@"result"] intValue];
  437. //
  438. // if (result==2)
  439. // {
  440. //
  441. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  442. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  443. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  444. //
  445. // [appDelegate update_count_mark];
  446. // }
  447. // return jsobj;
  448. // }
  449. // else
  450. // return nil;
  451. //}
  452. //+(NSDictionary*) move_wish2cart:(NSString* ) item_ids
  453. //{
  454. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  455. // __block AppDelegate *appDelegate = nil;
  456. //
  457. // dispatch_sync(dispatch_get_main_queue(), ^{
  458. // //some UI methods ej
  459. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  460. // });
  461. // if(appDelegate.user!=nil)
  462. // [params setValue:appDelegate.user forKey:@"user"];
  463. // if(appDelegate.contact_id!=nil)
  464. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  465. // if(appDelegate.password!=nil)
  466. // [params setValue:appDelegate.password forKey:@"password"];
  467. // if(appDelegate.order_code!=nil)
  468. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  469. // [params setValue:item_ids forKey:@"collectId"];
  470. // // [params setValue:editor forKey:@"editor"];
  471. //
  472. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  473. // [params setValue:@"Move To Cart" forKey:kAction];
  474. //
  475. // NSData *json = nil;
  476. // if(appDelegate.offline_mode)
  477. // {
  478. // json = [OLDataProvider offline_movewish2cart:params];
  479. // } else {
  480. // if(![self IsNetworkAvailable])
  481. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  482. //
  483. // json=[self get_json:URL_WISH2CART parameters:params];
  484. // }
  485. //
  486. // if(json!=nil)
  487. // {
  488. // NSError *error=nil;
  489. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  490. // int result = [[jsobj valueForKey:@"result"] intValue];
  491. //
  492. // if (result==2)
  493. // {
  494. //
  495. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  496. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  497. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  498. //
  499. // [appDelegate update_count_mark];
  500. // }
  501. // return jsobj;
  502. // }
  503. // else
  504. // return nil;
  505. //}
  506. //+(NSDictionary*) cart_remove:(NSString* ) item_ids
  507. //{
  508. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  509. // __block AppDelegate *appDelegate = nil;
  510. //
  511. // dispatch_sync(dispatch_get_main_queue(), ^{
  512. // //some UI methods ej
  513. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  514. // });
  515. // if(appDelegate.user!=nil)
  516. // [params setValue:appDelegate.user forKey:@"user"];
  517. // if(appDelegate.contact_id!=nil)
  518. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  519. // if(appDelegate.password!=nil)
  520. // [params setValue:appDelegate.password forKey:@"password"];
  521. //
  522. // if(appDelegate.order_code!=nil)
  523. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  524. // [params setValue:item_ids forKey:@"cartItemId"];
  525. // // [params setValue:editor forKey:@"editor"];
  526. //
  527. // [params setValue:ScreenCodeCart forKey:kScreenName];
  528. // // [params setValue:@"" forKey:kAction];
  529. //
  530. // NSData* json=nil;
  531. // if(appDelegate.offline_mode)
  532. // {
  533. // json= [OLDataProvider offline_cartremove:params];
  534. // }
  535. // else
  536. // {
  537. // if(![self IsNetworkAvailable])
  538. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  539. //
  540. // json=[self get_json:URL_CART_REMOVE parameters:params];
  541. // }
  542. // if(json!=nil)
  543. // {
  544. // NSError *error=nil;
  545. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  546. //
  547. // int result = [[jsobj valueForKey:@"result"] intValue];
  548. //
  549. // if (result==2)
  550. // {
  551. //
  552. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  553. //
  554. //
  555. // [appDelegate update_count_mark];
  556. // }
  557. // return jsobj;
  558. // }
  559. // else
  560. // return nil;
  561. //}
  562. //+(NSDictionary*) cart_check:(NSString* ) item_ids
  563. //{
  564. // return nil;
  565. // if(![self IsNetworkAvailable])
  566. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  567. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  568. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  569. // if(appDelegate.user!=nil)
  570. // [params setValue:appDelegate.user forKey:@"user"];
  571. // if(appDelegate.contact_id!=nil)
  572. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  573. // if(appDelegate.password!=nil)
  574. // [params setValue:appDelegate.password forKey:@"password"];
  575. // [params setValue:item_ids forKey:@"cartItemId"];
  576. // // [params setValue:editor forKey:@"editor"];
  577. // if(appDelegate.offline_mode)
  578. // {
  579. // return [OLDataProvider offline_notimpl];
  580. // }
  581. // NSData* json=[self get_json:URL_CART_CHECK parameters:params];
  582. // if(json!=nil)
  583. // {
  584. // NSError *error=nil;
  585. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  586. // return jsobj;
  587. // }
  588. // else
  589. // return nil;
  590. //}
  591. +(NSDictionary*)create_Address:(NSMutableDictionary*)params
  592. {
  593. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  594. __block AppDelegate *appDelegate = nil;
  595. dispatch_sync(dispatch_get_main_queue(), ^{
  596. //some UI methods ej
  597. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  598. });
  599. if(appDelegate.user!=nil)
  600. [params setValue:appDelegate.user forKey:@"user"];
  601. if(appDelegate.contact_id!=nil)
  602. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  603. if(appDelegate.password!=nil)
  604. [params setValue:appDelegate.password forKey:@"password"];
  605. // [params setValue:sourceid forKey:@"sourceid"];
  606. // [params setValue:editor forKey:@"editor"];
  607. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  608. NSData* json=nil;
  609. if(appDelegate.offline_mode)
  610. {
  611. json= [OLDataProvider offline_saveaddr:params];
  612. }
  613. else
  614. {
  615. if(![self IsNetworkAvailable])
  616. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  617. json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  618. }
  619. if(json!=nil)
  620. {
  621. NSError *error=nil;
  622. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  623. return jsobj;
  624. }
  625. else
  626. return nil;
  627. }
  628. +(NSDictionary*)copy_Order:(NSString*) order_code
  629. {
  630. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  631. __block AppDelegate *appDelegate = nil;
  632. dispatch_sync(dispatch_get_main_queue(), ^{
  633. //some UI methods ej
  634. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  635. });
  636. if(appDelegate.user!=nil)
  637. [params setValue:appDelegate.user forKey:@"user"];
  638. if(appDelegate.contact_id!=nil)
  639. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  640. if(appDelegate.password!=nil)
  641. [params setValue:appDelegate.password forKey:@"password"];
  642. // NSString* ssaved = @"false";
  643. // if(saved)
  644. // ssaved=@"true";
  645. // [params setValue:@"true" forKey:@"saved"];
  646. [params setValue:order_code forKey:@"code"];
  647. // [params setValue:sourceid forKey:@"sourceid"];
  648. // [params setValue:editor forKey:@"editor"];
  649. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  650. NSData* json=nil;
  651. if(appDelegate.offline_mode)
  652. {
  653. json= [OLDataProvider offline_copyorder:params];
  654. }
  655. else
  656. {
  657. if(![self IsNetworkAvailable])
  658. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  659. json=[self get_json:URL_COPY_ORDER parameters:params];
  660. }
  661. if(json!=nil)
  662. {
  663. NSError *error=nil;
  664. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  665. return jsobj;
  666. }
  667. else
  668. return nil;
  669. }
  670. +(NSDictionary*)sign_Order:(NSString*) order_code path:(NSString*)path
  671. {
  672. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  673. __block AppDelegate *appDelegate = nil;
  674. dispatch_sync(dispatch_get_main_queue(), ^{
  675. //some UI methods ej
  676. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  677. });
  678. if(appDelegate.user!=nil)
  679. [params setValue:appDelegate.user forKey:@"user"];
  680. if(appDelegate.contact_id!=nil)
  681. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  682. if(appDelegate.password!=nil)
  683. [params setValue:appDelegate.password forKey:@"password"];
  684. // NSString* ssaved = @"false";
  685. // if(saved)
  686. // ssaved=@"true";
  687. // [params setValue:@"true" forKey:@"saved"];
  688. [params setValue:order_code forKey:@"orderCode"];
  689. [params setValue:path forKey:@"picpath"];
  690. // [params setValue:sourceid forKey:@"sourceid"];
  691. // [params setValue:editor forKey:@"editor"];
  692. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  693. NSData* json=nil;
  694. if(appDelegate.offline_mode)
  695. {
  696. json= [OLDataProvider offline_signorder:params];
  697. }
  698. else
  699. {
  700. if(![self IsNetworkAvailable])
  701. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  702. json=[self get_json:URL_SIGN_ORDER parameters:params];
  703. }
  704. if(json!=nil)
  705. {
  706. NSError *error=nil;
  707. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  708. return jsobj;
  709. }
  710. else
  711. return nil;
  712. }
  713. +(NSDictionary*)commit_Order:(NSString*) order_code //saved:(bool) saved
  714. {
  715. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  716. __block AppDelegate *appDelegate = nil;
  717. dispatch_sync(dispatch_get_main_queue(), ^{
  718. //some UI methods ej
  719. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  720. });
  721. if(appDelegate.user!=nil)
  722. [params setValue:appDelegate.user forKey:@"user"];
  723. if(appDelegate.contact_id!=nil)
  724. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  725. if(appDelegate.password!=nil)
  726. [params setValue:appDelegate.password forKey:@"password"];
  727. // NSString* ssaved = @"false";
  728. // if(saved)
  729. // ssaved=@"true";
  730. [params setValue:@"true" forKey:@"saved"];
  731. [params setValue:order_code forKey:@"orderCode"];
  732. // [params setValue:sourceid forKey:@"sourceid"];
  733. // [params setValue:editor forKey:@"editor"];
  734. [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  735. NSData* json = nil;
  736. if(appDelegate.offline_mode)
  737. {
  738. json= [OLDataProvider offline_submitorder:params];
  739. }
  740. else
  741. {
  742. if(![self IsNetworkAvailable])
  743. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  744. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  745. }
  746. if(json!=nil)
  747. {
  748. NSError *error=nil;
  749. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  750. return jsobj;
  751. }
  752. else
  753. return nil;
  754. }
  755. //+(NSDictionary*)open_Order:(NSString*) order_code
  756. //{
  757. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  758. // __block AppDelegate *appDelegate = nil;
  759. //
  760. // dispatch_sync(dispatch_get_main_queue(), ^{
  761. // //some UI methods ej
  762. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  763. // });
  764. // if(appDelegate.user!=nil)
  765. // [params setValue:appDelegate.user forKey:@"user"];
  766. // // if(appDelegate.contact_id!=nil)
  767. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  768. // if(appDelegate.password!=nil)
  769. // [params setValue:appDelegate.password forKey:@"password"];
  770. //
  771. // [params setValue:order_code forKey:@"orderCode"];
  772. // // [params setValue:sourceid forKey:@"sourceid"];
  773. // // [params setValue:editor forKey:@"editor"];
  774. //
  775. // [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  776. //
  777. // NSData* json=nil;
  778. // if(appDelegate.offline_mode)
  779. // {
  780. // json=[OLDataProvider offline_editorder:params];
  781. //
  782. // }
  783. // else
  784. // {
  785. // if(![self IsNetworkAvailable])
  786. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  787. //
  788. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  789. // }
  790. // if(json!=nil)
  791. // {
  792. // NSError *error=nil;
  793. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  794. // int result = [[jsobj valueForKey:@"result"] intValue];
  795. //
  796. // if (result==2)
  797. // {
  798. //
  799. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  800. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  801. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  802. //
  803. // [appDelegate update_count_mark];
  804. //
  805. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  806. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  807. // }
  808. //
  809. // }
  810. //
  811. // return jsobj;
  812. // }
  813. // else
  814. // return nil;
  815. //}
  816. +(NSDictionary*)delete_Order:(NSString*) order_id
  817. {
  818. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  819. __block AppDelegate *appDelegate = nil;
  820. dispatch_sync(dispatch_get_main_queue(), ^{
  821. //some UI methods ej
  822. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  823. });
  824. if(appDelegate.user!=nil)
  825. [params setValue:appDelegate.user forKey:@"user"];
  826. // if(appDelegate.contact_id!=nil)
  827. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  828. if(appDelegate.password!=nil)
  829. [params setValue:appDelegate.password forKey:@"password"];
  830. [params setValue:order_id forKey:@"orderId"];
  831. // [params setValue:sourceid forKey:@"sourceid"];
  832. // [params setValue:editor forKey:@"editor"];
  833. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  834. if(appDelegate.offline_mode)
  835. {
  836. return [OLDataProvider offline_notimpl];
  837. }
  838. if(![self IsNetworkAvailable])
  839. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  840. NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  841. if(json!=nil)
  842. {
  843. NSError *error=nil;
  844. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  845. return jsobj;
  846. }
  847. else
  848. return nil;
  849. }
  850. +(NSDictionary*)cancel_Order:(NSString*) order_id order_code:(NSString*) order_code
  851. {
  852. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  853. __block AppDelegate *appDelegate = nil;
  854. dispatch_sync(dispatch_get_main_queue(), ^{
  855. //some UI methods ej
  856. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  857. });
  858. if(appDelegate.user!=nil)
  859. [params setValue:appDelegate.user forKey:@"user"];
  860. // if(appDelegate.contact_id!=nil)
  861. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  862. if(appDelegate.password!=nil)
  863. [params setValue:appDelegate.password forKey:@"password"];
  864. [params setValue:order_id forKey:@"orderId"];
  865. [params setValue:order_code forKey:@"orderCode"];
  866. // [params setValue:sourceid forKey:@"sourceid"];
  867. // [params setValue:editor forKey:@"editor"];
  868. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  869. NSData* json=nil;
  870. if(appDelegate.offline_mode)
  871. {
  872. json=[OLDataProvider offline_cancelorder:params];
  873. }
  874. else
  875. {
  876. if(![self IsNetworkAvailable])
  877. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  878. json=[self get_json:URL_CANCEL_ORDER parameters:params];
  879. }
  880. if(json!=nil)
  881. {
  882. NSError *error=nil;
  883. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  884. return jsobj;
  885. }
  886. else
  887. return nil;
  888. }
  889. +(NSDictionary*)release_Order:(NSString*) order_code withScreen:(NSString *)screenName
  890. {
  891. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  892. __block AppDelegate *appDelegate = nil;
  893. dispatch_sync(dispatch_get_main_queue(), ^{
  894. //some UI methods ej
  895. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  896. });
  897. if(appDelegate.user!=nil)
  898. [params setValue:appDelegate.user forKey:@"user"];
  899. // if(appDelegate.contact_id!=nil)
  900. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  901. if(appDelegate.password!=nil)
  902. [params setValue:appDelegate.password forKey:@"password"];
  903. [params setValue:order_code forKey:@"orderCode"];
  904. // [params setValue:sourceid forKey:@"sourceid"];
  905. // [params setValue:editor forKey:@"editor"];
  906. if (screenName) {
  907. [params setValue:screenName forKey:kScreenName];
  908. }
  909. NSData* json=nil;
  910. if(appDelegate.offline_mode)
  911. {
  912. json= [OLDataProvider offline_resetorder:params];
  913. }
  914. else
  915. {
  916. if(![self IsNetworkAvailable])
  917. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  918. json=[self get_json:URL_RELEASE_ORDER parameters:params];
  919. }
  920. if(json!=nil)
  921. {
  922. NSError *error=nil;
  923. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  924. if([[jsobj valueForKey:@"result"]intValue]==2)
  925. { [appDelegate SetSo:nil];
  926. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  927. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  928. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  929. [appDelegate update_count_mark];
  930. }
  931. return jsobj;
  932. }
  933. else
  934. return nil;
  935. }
  936. +(NSDictionary*)update_OrderCustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info
  937. {
  938. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  939. __block AppDelegate *appDelegate = nil;
  940. dispatch_sync(dispatch_get_main_queue(), ^{
  941. //some UI methods ej
  942. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  943. });
  944. if(appDelegate.user!=nil)
  945. [info setValue:appDelegate.user forKey:@"user"];
  946. // if(appDelegate.contact_id!=nil)
  947. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  948. if(appDelegate.password!=nil)
  949. [info setValue:appDelegate.password forKey:@"password"];
  950. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  951. [info setValue:order_code forKey:@"orderCode"];
  952. // [params setValue:sourceid forKey:@"sourceid"];
  953. // [params setValue:editor forKey:@"editor"];
  954. if(appDelegate.offline_mode)
  955. {
  956. return [OLDataProvider offline_notimpl];
  957. }
  958. if(![self IsNetworkAvailable])
  959. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  960. NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  961. if(json!=nil)
  962. {
  963. NSError *error=nil;
  964. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  965. return jsobj;
  966. }
  967. else
  968. return nil;
  969. }
  970. //+(NSDictionary*)commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url
  971. //{
  972. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  973. // __block AppDelegate *appDelegate = nil;
  974. //
  975. // dispatch_sync(dispatch_get_main_queue(), ^{
  976. // //some UI methods ej
  977. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  978. // });
  979. // if(appDelegate.user!=nil)
  980. // [params setValue:appDelegate.user forKey:@"user"];
  981. // if(appDelegate.contact_id!=nil)
  982. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  983. // if(appDelegate.password!=nil)
  984. // [params setValue:appDelegate.password forKey:@"password"];
  985. //
  986. // // if(appDelegate.order_code!=nil)
  987. // // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  988. //
  989. // // NSDictionary* customerinfo= appDelegate.customerInfo;
  990. // //
  991. // // NSArray* keys=[customerinfo allKeys];
  992. // // for(int i=0;i<keys.count;i++)
  993. // // {
  994. // // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  995. // // }
  996. // //
  997. // // [params setValue:sourceid forKey:@"sourceid"];
  998. // // [params setValue:editor forKey:@"editor"];
  999. //
  1000. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  1001. //
  1002. // if(appDelegate.offline_mode)
  1003. // {
  1004. // params[@"offline_Command"]=url;
  1005. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  1006. // }
  1007. //
  1008. // if(![self IsNetworkAvailable])
  1009. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1010. //
  1011. // NSData* json=[self get_json:url parameters:params];
  1012. // if(json!=nil)
  1013. // {
  1014. // NSError *error=nil;
  1015. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1016. // if([[jsobj valueForKey:@"result"]intValue]==2)
  1017. // [appDelegate SetSo:nil];
  1018. //
  1019. //
  1020. // return jsobj;
  1021. // }
  1022. // else
  1023. // return nil;
  1024. //}
  1025. +(NSDictionary*)saveandcommit_Order:(NSMutableDictionary*)params
  1026. {
  1027. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1028. __block AppDelegate *appDelegate = nil;
  1029. dispatch_sync(dispatch_get_main_queue(), ^{
  1030. //some UI methods ej
  1031. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1032. });
  1033. if(appDelegate.user!=nil)
  1034. [params setValue:appDelegate.user forKey:@"user"];
  1035. if(appDelegate.contact_id!=nil)
  1036. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1037. if(appDelegate.password!=nil)
  1038. [params setValue:appDelegate.password forKey:@"password"];
  1039. if(appDelegate.order_code!=nil)
  1040. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1041. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1042. //
  1043. // NSArray* keys=[customerinfo allKeys];
  1044. // for(int i=0;i<keys.count;i++)
  1045. // {
  1046. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1047. // }
  1048. //
  1049. // [params setValue:sourceid forKey:@"sourceid"];
  1050. // [params setValue:editor forKey:@"editor"];
  1051. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1052. NSData* json=nil;
  1053. if(appDelegate.offline_mode)
  1054. {
  1055. json=[OLDataProvider offline_submitorder:params];
  1056. }
  1057. else
  1058. {
  1059. if(![self IsNetworkAvailable])
  1060. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1061. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  1062. }
  1063. if(json!=nil)
  1064. {
  1065. NSError *error=nil;
  1066. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1067. if([[jsobj valueForKey:@"result"]intValue]==2)
  1068. [appDelegate SetSo:nil];
  1069. return jsobj;
  1070. }
  1071. else
  1072. return nil;
  1073. }
  1074. +(NSDictionary*)update_Customer:(NSMutableDictionary*)params
  1075. {
  1076. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1077. __block AppDelegate *appDelegate = nil;
  1078. dispatch_sync(dispatch_get_main_queue(), ^{
  1079. //some UI methods ej
  1080. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1081. });
  1082. if(appDelegate.user!=nil)
  1083. [params setValue:appDelegate.user forKey:@"user"];
  1084. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1085. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1086. // else
  1087. if(appDelegate.contact_id!=nil)
  1088. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1089. if(appDelegate.password!=nil)
  1090. [params setValue:appDelegate.password forKey:@"password"];
  1091. // NSDictionary* customerinfo=nil;
  1092. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1093. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1094. // else
  1095. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1096. //
  1097. // appDelegate.customerInfo;
  1098. // NSArray* keys=[customerinfo allKeys];
  1099. // for(int i=0;i<keys.count;i++)
  1100. // {
  1101. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1102. // }
  1103. // [params setValue:sourceid forKey:@"sourceid"];
  1104. // [params setValue:editor forKey:@"editor"];
  1105. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1106. NSData* json=nil;
  1107. if(appDelegate.offline_mode)
  1108. {
  1109. json= [OLDataProvider offline_saveContact:params];
  1110. }
  1111. else
  1112. {
  1113. if(![self IsNetworkAvailable])
  1114. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1115. json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  1116. }
  1117. if(json!=nil)
  1118. {
  1119. NSError *error=nil;
  1120. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1121. return jsobj;
  1122. }
  1123. else
  1124. return nil;
  1125. }
  1126. +(NSDictionary*)save_newCustomer:(NSMutableDictionary*)params
  1127. {
  1128. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1129. __block AppDelegate *appDelegate = nil;
  1130. dispatch_sync(dispatch_get_main_queue(), ^{
  1131. //some UI methods ej
  1132. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1133. });
  1134. if(appDelegate.user!=nil)
  1135. [params setValue:appDelegate.user forKey:@"user"];
  1136. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1137. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1138. // else
  1139. if(appDelegate.contact_id!=nil)
  1140. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1141. if(appDelegate.password!=nil)
  1142. [params setValue:appDelegate.password forKey:@"password"];
  1143. // NSDictionary* customerinfo=nil;
  1144. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1145. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1146. // else
  1147. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1148. //
  1149. // appDelegate.customerInfo;
  1150. // NSArray* keys=[customerinfo allKeys];
  1151. // for(int i=0;i<keys.count;i++)
  1152. // {
  1153. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1154. // }
  1155. // [params setValue:sourceid forKey:@"sourceid"];
  1156. // [params setValue:editor forKey:@"editor"];
  1157. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1158. NSData* json=nil;
  1159. if(appDelegate.offline_mode)
  1160. {
  1161. json= [OLDataProvider offline_saveNewContact:params];
  1162. }
  1163. else
  1164. {
  1165. if(![self IsNetworkAvailable])
  1166. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1167. json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  1168. }
  1169. if(json!=nil)
  1170. {
  1171. NSError *error=nil;
  1172. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1173. return jsobj;
  1174. }
  1175. else
  1176. return nil;
  1177. }
  1178. +(NSDictionary*)save_Order:(NSMutableDictionary*)params
  1179. {
  1180. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1181. __block AppDelegate *appDelegate = nil;
  1182. dispatch_sync(dispatch_get_main_queue(), ^{
  1183. //some UI methods ej
  1184. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1185. });
  1186. if(appDelegate.user!=nil)
  1187. [params setValue:appDelegate.user forKey:@"user"];
  1188. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1189. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1190. // else
  1191. if(appDelegate.contact_id!=nil)
  1192. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1193. if(appDelegate.password!=nil)
  1194. [params setValue:appDelegate.password forKey:@"password"];
  1195. if(appDelegate.order_code!=nil)
  1196. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1197. // NSDictionary* customerinfo=nil;
  1198. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1199. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1200. // else
  1201. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1202. //
  1203. // appDelegate.customerInfo;
  1204. // NSArray* keys=[customerinfo allKeys];
  1205. // for(int i=0;i<keys.count;i++)
  1206. // {
  1207. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1208. // }
  1209. // [params setValue:sourceid forKey:@"sourceid"];
  1210. // [params setValue:editor forKey:@"editor"];
  1211. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1212. NSData* json=nil;
  1213. if(appDelegate.offline_mode)
  1214. {
  1215. json= [OLDataProvider offline_saveorder:params];
  1216. }
  1217. else
  1218. {
  1219. if(![self IsNetworkAvailable])
  1220. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1221. json=[self get_json:URL_SAVE_ORDER parameters:params];
  1222. }
  1223. if(json!=nil)
  1224. {
  1225. NSError *error=nil;
  1226. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1227. NSString *so = [jsobj valueForKey:@"so#"];
  1228. if (so) {
  1229. [appDelegate SetSo:so];
  1230. }
  1231. return jsobj;
  1232. }
  1233. else
  1234. return nil;
  1235. }
  1236. //+(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
  1237. //{
  1238. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1239. // __block AppDelegate *appDelegate = nil;
  1240. //
  1241. // dispatch_sync(dispatch_get_main_queue(), ^{
  1242. // //some UI methods ej
  1243. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1244. // });
  1245. // if(appDelegate.user!=nil)
  1246. // [params setValue:appDelegate.user forKey:@"user"];
  1247. //
  1248. //
  1249. // // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1250. // // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1251. // // else
  1252. //
  1253. // if(appDelegate.contact_id!=nil)
  1254. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1255. // if(appDelegate.password!=nil)
  1256. // [params setValue:appDelegate.password forKey:@"password"];
  1257. //
  1258. // if(appDelegate.order_code!=nil)
  1259. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1260. // // [params setValue:sourceid forKey:@"sourceid"];
  1261. // // [params setValue:editor forKey:@"editor"];
  1262. // DebugLog(@"request editor url:%@",request_url);
  1263. //
  1264. //
  1265. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1266. // {
  1267. // [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1268. // }
  1269. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1270. // {
  1271. // [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1272. // }
  1273. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1274. // {
  1275. // [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  1276. // }
  1277. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1278. // {
  1279. // [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1280. // }
  1281. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1282. // {
  1283. // [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  1284. // }
  1285. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1286. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1287. // }
  1288. //
  1289. // NSData* json = nil;
  1290. // if(appDelegate.offline_mode)
  1291. // {
  1292. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1293. // {
  1294. // json= [OLDataProvider offline_createContact:params];
  1295. // }
  1296. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1297. // {
  1298. // json= [OLDataProvider offline_editContact:params];
  1299. // }
  1300. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1301. // {
  1302. // json= [OLDataProvider offline_contactAdvancedSearch:params];
  1303. // }
  1304. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1305. // {
  1306. // json= [OLDataProvider offline_placeorder:params];
  1307. // }
  1308. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1309. // {
  1310. // json= [OLDataProvider offline_addreditor:params];
  1311. // }
  1312. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1313. // json = [OLDataProvider offline_createTearSheet:params];
  1314. // }
  1315. //
  1316. // else
  1317. // return [OLDataProvider offline_notimpl];
  1318. // }
  1319. // else
  1320. // {
  1321. // if(![self IsNetworkAvailable])
  1322. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1323. //
  1324. // if([request_url isEqualToString:URL_CARTDELIVERY])
  1325. // {
  1326. // NSError *error=nil;
  1327. //
  1328. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1329. // params[@"resultSerial"]=uuid;
  1330. //
  1331. // for(int i=0;i<150;i++)
  1332. // {
  1333. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1334. // // result_params[@"resultSerial"]=uuid;
  1335. // json=[self get_json:request_url parameters:params];
  1336. // if(json!=nil)
  1337. // {
  1338. //
  1339. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1340. // if([jsobj[@"result"] intValue]==2 || [jsobj[@"result"] intValue] == 8)
  1341. // {
  1342. // break;
  1343. // }
  1344. // }
  1345. // sleep(2);
  1346. // }
  1347. // }
  1348. // else
  1349. // json =[self get_json:request_url parameters:params];
  1350. // }
  1351. // if(json!=nil)
  1352. // {
  1353. // NSError *error=nil;
  1354. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1355. // return jsobj;
  1356. // }
  1357. // else
  1358. // return nil;
  1359. //}
  1360. //+(NSDictionary*)request_OrderInfo:(NSString*) orderid
  1361. //{
  1362. // if(![self IsNetworkAvailable])
  1363. // return nil;
  1364. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1365. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1366. // if(appDelegate.user!=nil)
  1367. // [params setValue:appDelegate.user forKey:@"user"];
  1368. // if(appDelegate.password!=nil)
  1369. // [params setValue:appDelegate.password forKey:@"password"];
  1370. // [params setValue:orderid forKey:@"orderid"];
  1371. // NSData* json=[self get_json:URL_ORDER_INFO parameters:params];
  1372. // NSError *error=nil;
  1373. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1374. // return jsobj;
  1375. //}
  1376. +(NSDictionary*)request_OrderList:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged
  1377. {
  1378. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1379. __block AppDelegate *appDelegate = nil;
  1380. dispatch_sync(dispatch_get_main_queue(), ^{
  1381. //some UI methods ej
  1382. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1383. });
  1384. if(appDelegate.user!=nil)
  1385. [params setValue:appDelegate.user forKey:@"user"];
  1386. if(appDelegate.contact_id!=nil)
  1387. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1388. if(appDelegate.password!=nil)
  1389. [params setValue:appDelegate.password forKey:@"password"];
  1390. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1391. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1392. [params setValue:keywords forKey:@"keyWord"];
  1393. [params setValue:customer forKey:@"customer_filter"];
  1394. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  1395. [params setValue:status_code forKey:@"orderStatus"];
  1396. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1397. if (keywords) {
  1398. [params setObject:@"Search" forKey:kAction];
  1399. }
  1400. NSData* json=nil;
  1401. if(appDelegate.offline_mode)
  1402. {
  1403. json= [OLDataProvider offline_orderlist:params];
  1404. }
  1405. else
  1406. {
  1407. if(![self IsNetworkAvailable])
  1408. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1409. json=[self get_json:URL_ORDER_LIST parameters:params];
  1410. }
  1411. if(json==nil)
  1412. return nil;
  1413. NSError *error=nil;
  1414. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1415. return jsobj;
  1416. }
  1417. +(NSDictionary*)request_PDFList:(int ) offset limit:(int)limit keywords:(NSString* ) keywords
  1418. {
  1419. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1420. __block AppDelegate *appDelegate = nil;
  1421. dispatch_sync(dispatch_get_main_queue(), ^{
  1422. //some UI methods ej
  1423. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1424. });
  1425. if(appDelegate.user!=nil)
  1426. [params setValue:appDelegate.user forKey:@"user"];
  1427. if(appDelegate.contact_id!=nil)
  1428. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1429. if(appDelegate.password!=nil)
  1430. [params setValue:appDelegate.password forKey:@"password"];
  1431. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  1432. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  1433. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  1434. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  1435. // [params setValue:filter forKey:@"filter"];
  1436. [params setValue:keywords forKey:@"keyWord"];
  1437. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  1438. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  1439. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  1440. if (keywords) {
  1441. [params setObject:@"Search" forKey:kAction];
  1442. }
  1443. NSData* json = nil;
  1444. if(appDelegate.offline_mode)
  1445. {
  1446. json = [OLDataProvider offline_pdfList:params];
  1447. } else {
  1448. if(![self IsNetworkAvailable])
  1449. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1450. json=[self get_json:URL_DM_LIST parameters:params];
  1451. }
  1452. if(json==nil)
  1453. return nil;
  1454. NSError *error=nil;
  1455. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1456. return jsobj;
  1457. }
  1458. +(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code//device:(NSString*) device
  1459. {
  1460. #ifdef ERR_LOG
  1461. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1462. __block AppDelegate *appDelegate = nil;
  1463. dispatch_sync(dispatch_get_main_queue(), ^{
  1464. //some UI methods ej
  1465. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1466. });
  1467. if(appDelegate.user!=nil)
  1468. [params setValue:appDelegate.user forKey:@"user"];
  1469. [params setValue:up_params forKey:@"upparam"];
  1470. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  1471. [params setValue:result forKey:@"result"];
  1472. [params setValue:module forKey:@"interfac"];
  1473. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  1474. // [params setValue:module forKey:@"module"];
  1475. // [[UIDevice currentDevice] name];
  1476. // if(appDelegate.offline_mode)
  1477. // {
  1478. // return [OLDataProvider offline_notimpl];
  1479. // }
  1480. if(![self IsNetworkAvailable])
  1481. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1482. NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  1483. if(json==nil)
  1484. return nil;
  1485. NSError *error=nil;
  1486. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1487. return jsobj;
  1488. #else
  1489. return nil;
  1490. #endif
  1491. }
  1492. //+(NSDictionary*)request_ContactList:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams
  1493. //{
  1494. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1495. //
  1496. // if(upparams!=nil)
  1497. // params = [upparams mutableCopy];
  1498. // __block AppDelegate *appDelegate = nil;
  1499. //
  1500. // dispatch_sync(dispatch_get_main_queue(), ^{
  1501. // //some UI methods ej
  1502. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1503. // });
  1504. // if(appDelegate.user!=nil)
  1505. // [params setValue:appDelegate.user forKey:@"user"];
  1506. //
  1507. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1508. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1509. // else
  1510. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1511. //
  1512. // if(appDelegate.password!=nil)
  1513. // [params setValue:appDelegate.password forKey:@"password"];
  1514. //
  1515. // [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1516. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1517. // [params setValue:contact_type forKey:@"contactType"];
  1518. // [params setValue:keywords forKey:@"keyword"];
  1519. //
  1520. // [params setObject:ScreenCodeAccount forKey:kScreenName];
  1521. // if (keywords) {
  1522. // [params setObject:@"Search" forKey:kAction];
  1523. // }
  1524. // if (upparams) {
  1525. // [params setObject:@"Advance Search" forKey:kAction];
  1526. // }
  1527. //
  1528. // NSString* url=nil;
  1529. // if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  1530. // url=URL_SHIPTO_LIST;
  1531. // else
  1532. // url=URL_CONTACT_LIST;
  1533. //
  1534. // if(appDelegate.offline_mode)
  1535. // return [OLDataProvider offline_contactlist:params];
  1536. //
  1537. // if(![self IsNetworkAvailable])
  1538. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1539. //
  1540. // NSData* json=[self get_json:url parameters:params];
  1541. // if(json==nil)
  1542. // return nil;
  1543. // NSError *error=nil;
  1544. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1545. // return jsobj;
  1546. //}
  1547. //+(NSDictionary*)request_OrderDetail:(NSMutableDictionary *) params
  1548. //{
  1549. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1550. // if (params == nil) {
  1551. // params = [[NSMutableDictionary alloc] init];
  1552. // }
  1553. // __block AppDelegate *appDelegate = nil;
  1554. //
  1555. // dispatch_sync(dispatch_get_main_queue(), ^{
  1556. // //some UI methods ej
  1557. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1558. // });
  1559. // if(appDelegate.user!=nil)
  1560. // [params setValue:appDelegate.user forKey:@"user"];
  1561. // if(appDelegate.contact_id!=nil)
  1562. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1563. // if(appDelegate.password!=nil)
  1564. // [params setValue:appDelegate.password forKey:@"password"];
  1565. //
  1566. //
  1567. // // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1568. //
  1569. // [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  1570. //
  1571. // NSData* json=nil;
  1572. // if(appDelegate.offline_mode)
  1573. // {
  1574. // json= [OLDataProvider offline_orderdetail:params];
  1575. // }
  1576. // else
  1577. // {
  1578. // if(![self IsNetworkAvailable])
  1579. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1580. //
  1581. // NSError *error=nil;
  1582. //
  1583. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1584. // params[@"resultSerial"]=uuid;
  1585. //
  1586. // for(int i=0;i<150;i++)
  1587. // {
  1588. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1589. // // result_params[@"resultSerial"]=uuid;
  1590. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  1591. // if(json!=nil)
  1592. // {
  1593. //
  1594. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1595. // int resultCode = [jsobj[@"result"] intValue];
  1596. // if(resultCode==2 || resultCode == 8)
  1597. // {
  1598. // break;
  1599. // }
  1600. // }
  1601. // sleep(2);
  1602. // }
  1603. //
  1604. //
  1605. // }
  1606. // if(json==nil)
  1607. // return nil;
  1608. // NSError *error=nil;
  1609. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1610. // return jsobj;
  1611. //}
  1612. //+(NSDictionary*) add_toCart:(NSString* ) item_id count:(int) count name:(NSString *)name
  1613. //{
  1614. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1615. // __block AppDelegate *appDelegate = nil;
  1616. //
  1617. // dispatch_sync(dispatch_get_main_queue(), ^{
  1618. // //some UI methods ej
  1619. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1620. // });
  1621. // if(appDelegate.user!=nil)
  1622. // [params setValue:appDelegate.user forKey:@"user"];
  1623. // if(appDelegate.contact_id!=nil)
  1624. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1625. // if(appDelegate.password!=nil)
  1626. // [params setValue:appDelegate.password forKey:@"password"];
  1627. //
  1628. // if(appDelegate.order_code!=nil)
  1629. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1630. // [params setValue:item_id forKey:@"product_id"];
  1631. // [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  1632. //
  1633. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  1634. // [params setObject:@"Add To Cart" forKey:kAction];
  1635. // if (name) {
  1636. // NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  1637. // [params setObject:extra forKey:kExtra];
  1638. // }
  1639. //
  1640. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1641. //
  1642. // NSArray* keys=[customerinfo allKeys];
  1643. // for(int i=0;i<keys.count;i++)
  1644. // {
  1645. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1646. // }
  1647. //
  1648. // NSData* json=nil;
  1649. // if(appDelegate.offline_mode)
  1650. // {
  1651. // json=[OLDataProvider offline_add2cart:params];
  1652. // }
  1653. // else
  1654. // {
  1655. // if(![self IsNetworkAvailable])
  1656. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1657. //
  1658. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  1659. // }
  1660. // if(json==nil)
  1661. // return nil;
  1662. // NSError *error=nil;
  1663. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1664. //
  1665. //
  1666. //
  1667. // int result = [[jsobj valueForKey:@"result"] intValue];
  1668. //
  1669. // if (result==2)
  1670. // {
  1671. //
  1672. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1673. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1674. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1675. //
  1676. // [appDelegate update_count_mark];
  1677. // }
  1678. //
  1679. // return jsobj;
  1680. //}
  1681. //+(NSDictionary*) add_toCart_byName:(NSString* ) model_name withScreen:(NSString *)screenName
  1682. //{
  1683. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1684. // __block AppDelegate *appDelegate = nil;
  1685. //
  1686. // dispatch_sync(dispatch_get_main_queue(), ^{
  1687. // //some UI methods ej
  1688. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1689. // });
  1690. // if(appDelegate.user!=nil)
  1691. // [params setValue:appDelegate.user forKey:@"user"];
  1692. // if(appDelegate.contact_id!=nil)
  1693. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1694. // if(appDelegate.password!=nil)
  1695. // [params setValue:appDelegate.password forKey:@"password"];
  1696. //
  1697. // if(appDelegate.order_code!=nil)
  1698. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1699. // [params setValue:model_name forKey:@"product_name"];
  1700. // [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  1701. //
  1702. // [params setObject:screenName forKey:kScreenName];
  1703. // [params setObject:@"Add To Cart" forKey:kAction];
  1704. // if (!model_name) {
  1705. // model_name = @"";
  1706. // }
  1707. // [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  1708. //
  1709. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1710. //
  1711. // NSArray* keys=[customerinfo allKeys];
  1712. // for(int i=0;i<keys.count;i++)
  1713. // {
  1714. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1715. // }
  1716. // NSData* json=nil;
  1717. // if(appDelegate.offline_mode)
  1718. // {
  1719. // json= [OLDataProvider offline_add2cartbyname:params];
  1720. // }
  1721. // else
  1722. // {
  1723. // if(![self IsNetworkAvailable])
  1724. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1725. //
  1726. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  1727. // }
  1728. // if(json==nil)
  1729. // return nil;
  1730. // NSError *error=nil;
  1731. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1732. //
  1733. //
  1734. //
  1735. // int result = [[jsobj valueForKey:@"result"] intValue];
  1736. //
  1737. // if (result==2||result==8)
  1738. // {
  1739. //
  1740. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1741. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1742. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1743. //
  1744. // [appDelegate update_count_mark];
  1745. // }
  1746. //
  1747. // return jsobj;
  1748. //}
  1749. //+(NSDictionary*) new_Customer
  1750. //{
  1751. // if(![self IsNetworkAvailable])
  1752. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1753. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1754. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1755. // if(appDelegate.user!=nil)
  1756. // [params setValue:appDelegate.user forKey:@"user"];
  1757. //// if(appDelegate.contact_id!=nil)
  1758. //// [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1759. // if(appDelegate.password!=nil)
  1760. // [params setValue:appDelegate.password forKey:@"password"];
  1761. //
  1762. //// if(appDelegate.order_code!=nil)
  1763. //// [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1764. //
  1765. //
  1766. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1767. //
  1768. // NSArray* keys=[customerinfo allKeys];
  1769. // for(int i=0;i<keys.count;i++)
  1770. // {
  1771. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1772. // }
  1773. //
  1774. // NSData* json=[self get_json:URL_CUSTOMER_EDIT parameters:params];
  1775. // if(json==nil)
  1776. // return nil;
  1777. // NSError *error=nil;
  1778. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1779. // return jsobj;
  1780. //}
  1781. //+(NSDictionary*) new_Order
  1782. //{
  1783. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1784. // __block AppDelegate *appDelegate = nil;
  1785. //
  1786. // dispatch_sync(dispatch_get_main_queue(), ^{
  1787. // //some UI methods ej
  1788. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1789. // });
  1790. // if(appDelegate.user!=nil)
  1791. // [params setValue:appDelegate.user forKey:@"user"];
  1792. // if(appDelegate.contact_id!=nil)
  1793. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1794. // if(appDelegate.password!=nil)
  1795. // [params setValue:appDelegate.password forKey:@"password"];
  1796. //
  1797. // if(appDelegate.order_code!=nil)
  1798. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1799. //
  1800. //
  1801. // [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1802. //
  1803. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1804. //
  1805. // NSArray* keys=[customerinfo allKeys];
  1806. // for(int i=0;i<keys.count;i++)
  1807. // {
  1808. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1809. // }
  1810. //
  1811. // NSData* json = nil;
  1812. // if(appDelegate.offline_mode)
  1813. // {
  1814. // json= [OLDataProvider offline_createorder:params];
  1815. // }
  1816. // else
  1817. // {
  1818. // if(![self IsNetworkAvailable])
  1819. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1820. //
  1821. // json=[self get_json:URL_NEW_ORDER parameters:params];
  1822. // }
  1823. // if(json==nil)
  1824. // return nil;
  1825. // NSError *error=nil;
  1826. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1827. // int result = [[jsobj valueForKey:@"result"] intValue];
  1828. //
  1829. // if (result==2)
  1830. // {
  1831. //
  1832. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1833. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1834. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1835. //
  1836. // [appDelegate update_count_mark];
  1837. // }
  1838. //
  1839. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  1840. //
  1841. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1842. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  1843. // }
  1844. //
  1845. // return jsobj;
  1846. //}
  1847. +(NSDictionary*) add_toPortfolio:(NSString* ) item_id withScreen:(NSString *)screenName
  1848. {
  1849. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1850. __block AppDelegate *appDelegate = nil;
  1851. dispatch_sync(dispatch_get_main_queue(), ^{
  1852. //some UI methods ej
  1853. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1854. });
  1855. if(appDelegate.user!=nil)
  1856. [params setValue:appDelegate.user forKey:@"user"];
  1857. if(appDelegate.contact_id!=nil)
  1858. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1859. if(appDelegate.password!=nil)
  1860. [params setValue:appDelegate.password forKey:@"password"];
  1861. [params setValue:item_id forKey:@"product_id"];
  1862. [params setObject:screenName forKey:kScreenName];
  1863. NSData* json = nil;
  1864. if(appDelegate.offline_mode)
  1865. {
  1866. json = [OLDataProvider offline_add2Portfolio:params];
  1867. } else {
  1868. if(![self IsNetworkAvailable])
  1869. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1870. json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  1871. }
  1872. if(json==nil)
  1873. return nil;
  1874. NSError *error=nil;
  1875. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1876. int result = [[jsobj valueForKey:@"result"] intValue];
  1877. if (result==2)
  1878. {
  1879. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1880. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1881. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1882. [appDelegate update_count_mark];
  1883. }
  1884. return jsobj;
  1885. }
  1886. //+(NSDictionary*) add_toWatchList:(NSString* ) item_id withScreen:(NSString *)screenName
  1887. //{
  1888. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1889. // __block AppDelegate *appDelegate = nil;
  1890. //
  1891. // dispatch_sync(dispatch_get_main_queue(), ^{
  1892. // //some UI methods ej
  1893. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1894. // });
  1895. // if(appDelegate.user!=nil)
  1896. // [params setValue:appDelegate.user forKey:@"user"];
  1897. // if(appDelegate.contact_id!=nil)
  1898. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1899. // if(appDelegate.password!=nil)
  1900. // [params setValue:appDelegate.password forKey:@"password"];
  1901. //
  1902. //
  1903. // [params setValue:item_id forKey:@"product_id"];
  1904. //
  1905. // [params setObject:screenName forKey:kScreenName];
  1906. //
  1907. // if(appDelegate.offline_mode)
  1908. // {
  1909. // return [OLDataProvider offline_add2wishlist:params];
  1910. // }
  1911. // if(![self IsNetworkAvailable])
  1912. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1913. //
  1914. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  1915. // if(json==nil)
  1916. // return nil;
  1917. // NSError *error=nil;
  1918. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1919. // int result = [[jsobj valueForKey:@"result"] intValue];
  1920. //
  1921. // if (result==2)
  1922. // {
  1923. //
  1924. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1925. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1926. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1927. //
  1928. // [appDelegate update_count_mark];
  1929. // }
  1930. // return jsobj;
  1931. //}
  1932. //+(NSDictionary*) cart_setPrice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes
  1933. //{
  1934. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1935. // __block AppDelegate *appDelegate = nil;
  1936. //
  1937. // dispatch_sync(dispatch_get_main_queue(), ^{
  1938. // //some UI methods ej
  1939. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1940. // });
  1941. // if(appDelegate.user!=nil)
  1942. // [params setValue:appDelegate.user forKey:@"user"];
  1943. // if(appDelegate.contact_id!=nil)
  1944. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1945. // if(appDelegate.password!=nil)
  1946. // [params setValue:appDelegate.password forKey:@"password"];
  1947. //
  1948. // [params setValue:cart_id forKey:@"cartitem_id"];
  1949. // [params setValue:notes forKey:@"item_note"];
  1950. //
  1951. // [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  1952. //
  1953. // [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  1954. //
  1955. // [params setObject:ScreenCodeCart forKey:kScreenName];
  1956. //
  1957. // NSData* json= nil;
  1958. // if(appDelegate.offline_mode)
  1959. // {
  1960. // json=[OLDataProvider offline_cartsetprice:params];
  1961. // }
  1962. // else
  1963. // {
  1964. // if(![self IsNetworkAvailable])
  1965. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1966. //
  1967. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  1968. // }
  1969. // if(json==nil)
  1970. // return nil;
  1971. // NSError *error=nil;
  1972. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1973. // return jsobj;
  1974. //}
  1975. //+(NSDictionary*) portfolio_setQTY:(NSString*) watchlist_id QTY:(int)qty
  1976. //{
  1977. // if(![self IsNetworkAvailable])
  1978. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1979. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1980. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1981. // if(appDelegate.user!=nil)
  1982. // [params setValue:appDelegate.user forKey:@"user"];
  1983. // if(appDelegate.contact_id!=nil)
  1984. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1985. // if(appDelegate.password!=nil)
  1986. // [params setValue:appDelegate.password forKey:@"password"];
  1987. //
  1988. // [params setValue:watchlist_id forKey:@"item_id"];
  1989. //
  1990. // [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  1991. //
  1992. //
  1993. //
  1994. // NSData* json=[self get_json:URL_DM_SET_QTY parameters:params];
  1995. // if(json==nil)
  1996. // return nil;
  1997. // NSError *error=nil;
  1998. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1999. // return jsobj;
  2000. //}
  2001. +(NSDictionary*) portfolio_setPrice:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes
  2002. {
  2003. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2004. __block AppDelegate *appDelegate = nil;
  2005. dispatch_sync(dispatch_get_main_queue(), ^{
  2006. //some UI methods ej
  2007. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2008. });
  2009. if(appDelegate.user!=nil)
  2010. [params setValue:appDelegate.user forKey:@"user"];
  2011. if(appDelegate.contact_id!=nil)
  2012. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2013. if(appDelegate.password!=nil)
  2014. [params setValue:appDelegate.password forKey:@"password"];
  2015. [params setValue:watchlist_id forKey:@"item_id"];
  2016. // if(notes.length>0)
  2017. // [params setValue:notes forKey:@"notes"];
  2018. if(notes)
  2019. [params setValue:notes forKey:@"notes"];
  2020. if(price != -MAXFLOAT)
  2021. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  2022. if (discount != -MAXFLOAT)
  2023. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  2024. if(qty_p != -MAXFLOAT)
  2025. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  2026. if(qty != -INT32_MAX)
  2027. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  2028. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2029. NSData* json = nil;
  2030. if(appDelegate.offline_mode)
  2031. {
  2032. json = [OLDataProvider offline_editPortfolio:params];
  2033. } else {
  2034. if(![self IsNetworkAvailable])
  2035. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2036. json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  2037. }
  2038. if(json==nil)
  2039. return nil;
  2040. NSError *error=nil;
  2041. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2042. return jsobj;
  2043. }
  2044. //+(NSDictionary*) cart_setGeneralNote:(NSString*) order_code notes:(NSString*) notes
  2045. //{
  2046. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2047. // __block AppDelegate *appDelegate = nil;
  2048. //
  2049. // dispatch_sync(dispatch_get_main_queue(), ^{
  2050. // //some UI methods ej
  2051. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2052. // });
  2053. // if(appDelegate.user!=nil)
  2054. // [params setValue:appDelegate.user forKey:@"user"];
  2055. // if(appDelegate.contact_id!=nil)
  2056. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2057. // if(appDelegate.password!=nil)
  2058. // [params setValue:appDelegate.password forKey:@"password"];
  2059. //
  2060. // [params setValue:order_code forKey:@"orderCode"];
  2061. //
  2062. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2063. //
  2064. // if(notes.length==0)
  2065. // notes=@"";
  2066. //
  2067. //
  2068. // [params setValue:notes forKey:@"comments"];
  2069. // NSData* json=nil;
  2070. // if(appDelegate.offline_mode)
  2071. // {
  2072. // json= [OLDataProvider offline_updategnotes:params];
  2073. // }
  2074. // else
  2075. // {
  2076. // if(![self IsNetworkAvailable])
  2077. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2078. //
  2079. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  2080. // }
  2081. // if(json==nil)
  2082. // return nil;
  2083. // NSError *error=nil;
  2084. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2085. // return jsobj;
  2086. //}
  2087. //+(NSDictionary*) cart_setItemNote:(NSString*) cart_id notes:(NSString*) notes
  2088. //{
  2089. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2090. // __block AppDelegate *appDelegate = nil;
  2091. //
  2092. // dispatch_sync(dispatch_get_main_queue(), ^{
  2093. // //some UI methods ej
  2094. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2095. // });
  2096. // if(appDelegate.user!=nil)
  2097. // [params setValue:appDelegate.user forKey:@"user"];
  2098. // if(appDelegate.contact_id!=nil)
  2099. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2100. // if(appDelegate.password!=nil)
  2101. // [params setValue:appDelegate.password forKey:@"password"];
  2102. //
  2103. // [params setValue:cart_id forKey:@"cartitem_id"];
  2104. //
  2105. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2106. //
  2107. // if(notes.length==0)
  2108. // notes=@"";
  2109. //
  2110. //
  2111. // [params setValue:notes forKey:@"notes"];
  2112. // NSData* json=nil;
  2113. // if(appDelegate.offline_mode)
  2114. // {
  2115. // json= [OLDataProvider offline_cartsetlnotes:params];
  2116. // }
  2117. // else
  2118. // {
  2119. // if(![self IsNetworkAvailable])
  2120. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2121. //
  2122. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  2123. // }
  2124. // if(json==nil)
  2125. // return nil;
  2126. // NSError *error=nil;
  2127. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2128. // return jsobj;
  2129. //}
  2130. //+(NSDictionary*) cart_setFree:(NSString*) cart_id isfree:(bool) isfree
  2131. //{
  2132. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2133. // __block AppDelegate *appDelegate = nil;
  2134. //
  2135. // dispatch_sync(dispatch_get_main_queue(), ^{
  2136. // //some UI methods ej
  2137. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2138. // });
  2139. // if(appDelegate.user!=nil)
  2140. // [params setValue:appDelegate.user forKey:@"user"];
  2141. // if(appDelegate.contact_id!=nil)
  2142. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2143. // if(appDelegate.password!=nil)
  2144. // [params setValue:appDelegate.password forKey:@"password"];
  2145. //
  2146. // [params setValue:cart_id forKey:@"cartitem_id"];
  2147. //
  2148. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2149. //
  2150. // NSString* free=nil;
  2151. //
  2152. // if(isfree)
  2153. // free=@"true";
  2154. // else
  2155. // free=@"false";
  2156. //
  2157. // [params setValue:free forKey:@"free_giveaway"];
  2158. //
  2159. // if(appDelegate.offline_mode)
  2160. // {
  2161. // return [OLDataProvider offline_notimpl];
  2162. // }
  2163. // if(![self IsNetworkAvailable])
  2164. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2165. //
  2166. // NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2167. // if(json==nil)
  2168. // return nil;
  2169. // NSError *error=nil;
  2170. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2171. // return jsobj;
  2172. //}
  2173. //+(NSDictionary*) cart_setQTY:(NSString*) cart_id value:(int) value
  2174. //{
  2175. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2176. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2177. // if(appDelegate.user!=nil)
  2178. // [params setValue:appDelegate.user forKey:@"user"];
  2179. // if(appDelegate.contact_id!=nil)
  2180. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2181. // if(appDelegate.password!=nil)
  2182. // [params setValue:appDelegate.password forKey:@"password"];
  2183. //
  2184. // [params setValue:cart_id forKey:@"cartitem_id"];
  2185. //
  2186. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2187. //
  2188. // [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  2189. //
  2190. // NSData* json=nil;
  2191. // if(appDelegate.offline_mode)
  2192. // {
  2193. // json= [OLDataProvider offline_cartsetqty:params];
  2194. // }
  2195. // else
  2196. // {
  2197. // if(![self IsNetworkAvailable])
  2198. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2199. //
  2200. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2201. // }
  2202. // if(json==nil)
  2203. // return nil;
  2204. // NSError *error=nil;
  2205. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2206. // return jsobj;
  2207. //
  2208. //}
  2209. //+(NSDictionary*) cart_incresement:(NSString*) cart_id increse:(bool) increse
  2210. //{
  2211. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2212. // __block AppDelegate *appDelegate = nil;
  2213. //
  2214. // dispatch_sync(dispatch_get_main_queue(), ^{
  2215. // //some UI methods ej
  2216. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2217. // });
  2218. // if(appDelegate.user!=nil)
  2219. // [params setValue:appDelegate.user forKey:@"user"];
  2220. // if(appDelegate.contact_id!=nil)
  2221. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2222. // if(appDelegate.password!=nil)
  2223. // [params setValue:appDelegate.password forKey:@"password"];
  2224. //
  2225. // [params setValue:cart_id forKey:@"cartitem_id"];
  2226. //
  2227. // if(increse)
  2228. // [params setValue:@"1" forKey:@"incrementType"];
  2229. // else
  2230. // [params setValue:@"0" forKey:@"incrementType"];
  2231. //
  2232. //
  2233. //
  2234. // if(appDelegate.offline_mode)
  2235. // {
  2236. // return [OLDataProvider offline_notimpl];
  2237. // }
  2238. // if(![self IsNetworkAvailable])
  2239. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2240. //
  2241. // NSData* json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2242. // if(json==nil)
  2243. // return nil;
  2244. // NSError *error=nil;
  2245. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2246. // return jsobj;
  2247. //}
  2248. +(NSDictionary*) finish_download_Offline:(NSString* )vid
  2249. {
  2250. if(![self IsNetworkAvailable])
  2251. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2252. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2253. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  2254. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2255. // if(appDelegate.user!=nil)
  2256. // [params setValue:appDelegate.user forKey:@"user"];
  2257. // // if(appDelegate.contact_id!=nil)
  2258. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2259. // if(appDelegate.password!=nil)
  2260. // [params setValue:appDelegate.password forKey:@"password"];
  2261. [params setValue:vid forKey:@"downSerial"];
  2262. NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  2263. if(json==nil)
  2264. return nil;
  2265. NSError *error=nil;
  2266. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2267. // int result = [[jsobj valueForKey:@"result"] intValue];
  2268. //
  2269. // if (result==2)
  2270. // {
  2271. //
  2272. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2273. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2274. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2275. ////
  2276. //// [appDelegate update_count_mark];
  2277. // }
  2278. return jsobj;
  2279. }
  2280. +(NSDictionary*) download_Offline:(NSString* )vid
  2281. {
  2282. if(![self IsNetworkAvailable])
  2283. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2284. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2285. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2286. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2287. // if(appDelegate.user!=nil)
  2288. // [params setValue:appDelegate.user forKey:@"user"];
  2289. // // if(appDelegate.contact_id!=nil)
  2290. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2291. // if(appDelegate.password!=nil)
  2292. // [params setValue:appDelegate.password forKey:@"password"];
  2293. [params setValue:vid forKey:@"downSerial"];
  2294. NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  2295. if(json==nil)
  2296. return nil;
  2297. NSError *error=nil;
  2298. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2299. // int result = [[jsobj valueForKey:@"result"] intValue];
  2300. //
  2301. // if (result==2)
  2302. // {
  2303. //
  2304. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2305. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2306. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2307. ////
  2308. //// [appDelegate update_count_mark];
  2309. // }
  2310. return jsobj;
  2311. }
  2312. +(NSDictionary*) check_Offline:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid
  2313. {
  2314. if(![self IsNetworkAvailable])
  2315. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2316. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2317. __block AppDelegate *appDelegate = nil;
  2318. dispatch_sync(dispatch_get_main_queue(), ^{
  2319. //some UI methods ej
  2320. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2321. });
  2322. if(appDelegate.user!=nil)
  2323. [params setValue:appDelegate.user forKey:@"user"];
  2324. // if(appDelegate.contact_id!=nil)
  2325. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2326. if(appDelegate.password!=nil)
  2327. [params setValue:appDelegate.password forKey:@"password"];
  2328. [params setValue:ver forKey:@"ver"];
  2329. [params setValue:vid forKey:@"vid"];
  2330. if(buseinternaladdress)
  2331. [params setValue:@"true" forKey:@"internal_address"];
  2332. else
  2333. [params setValue:@"false" forKey:@"internal_address"];
  2334. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2335. NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  2336. if(json==nil)
  2337. return nil;
  2338. NSError *error=nil;
  2339. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2340. // int result = [[jsobj valueForKey:@"result"] intValue];
  2341. //
  2342. // if (result==2)
  2343. // {
  2344. //
  2345. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2346. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2347. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2348. ////
  2349. //// [appDelegate update_count_mark];
  2350. // }
  2351. return jsobj;
  2352. }
  2353. //+(NSDictionary*)request_Cart:(int)sort
  2354. //{
  2355. //
  2356. // DebugLog(@"iSalesNetwork::request_Cart");
  2357. //
  2358. //
  2359. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2360. // __block AppDelegate *appDelegate = nil;
  2361. //
  2362. // dispatch_sync(dispatch_get_main_queue(), ^{
  2363. // //some UI methods ej
  2364. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2365. // });
  2366. // if(appDelegate.user!=nil)
  2367. // [params setValue:appDelegate.user forKey:@"user"];
  2368. // // if(appDelegate.contact_id!=nil)
  2369. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2370. // if(appDelegate.password!=nil)
  2371. // [params setValue:appDelegate.password forKey:@"password"];
  2372. //
  2373. // if(appDelegate.order_code!=nil)
  2374. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2375. //
  2376. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2377. //
  2378. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2379. //
  2380. // NSData* json=nil;
  2381. // if(appDelegate.offline_mode)
  2382. // {
  2383. // json= [OLDataProvider offline_requestcart:params];
  2384. // }
  2385. // else
  2386. // {
  2387. // if(![self IsNetworkAvailable])
  2388. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2389. //
  2390. // NSError *error=nil;
  2391. //
  2392. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2393. // params[@"resultSerial"]=uuid;
  2394. //
  2395. // for(int i=0;i<150;i++)
  2396. // {
  2397. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2398. // // result_params[@"resultSerial"]=uuid;
  2399. // json=[self get_json:URL_CART parameters:params];
  2400. // if(json!=nil)
  2401. // {
  2402. //
  2403. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2404. // if([jsobj[@"result"] intValue]==2)
  2405. // {
  2406. // break;
  2407. // }
  2408. // }
  2409. // sleep(2);
  2410. // }
  2411. //
  2412. // }
  2413. // if(json==nil)
  2414. // return nil;
  2415. // NSError *error=nil;
  2416. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2417. // int result = [[jsobj valueForKey:@"result"] intValue];
  2418. //
  2419. // if (result==2)
  2420. // {
  2421. //
  2422. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2423. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2424. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2425. //
  2426. // [appDelegate update_count_mark];
  2427. // }
  2428. // return jsobj;
  2429. //}
  2430. //+(NSDictionary*)request_Portfolio:(int)sort
  2431. //{
  2432. //
  2433. //
  2434. //
  2435. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2436. // __block AppDelegate *appDelegate = nil;
  2437. //
  2438. // dispatch_sync(dispatch_get_main_queue(), ^{
  2439. // //some UI methods ej
  2440. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2441. // });
  2442. // if(appDelegate.user!=nil)
  2443. // [params setValue:appDelegate.user forKey:@"user"];
  2444. // if(appDelegate.contact_id!=nil)
  2445. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2446. // if(appDelegate.password!=nil)
  2447. // [params setValue:appDelegate.password forKey:@"password"];
  2448. //
  2449. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2450. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2451. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2452. //
  2453. // [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2454. //
  2455. // NSData* json = nil;
  2456. // if(appDelegate.offline_mode)
  2457. // {
  2458. // json = [OLDataProvider offline_portfolioList:params];
  2459. // } else {
  2460. // if(![self IsNetworkAvailable])
  2461. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2462. //
  2463. // json = [self get_json:URL_PORTFOLIO parameters:params];
  2464. // }
  2465. //
  2466. //
  2467. // if(json==nil)
  2468. // return nil;
  2469. // NSError *error=nil;
  2470. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2471. // int result = [[jsobj valueForKey:@"result"] intValue];
  2472. //
  2473. // if (result==2)
  2474. // {
  2475. //
  2476. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2477. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2478. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  2479. //
  2480. // [appDelegate update_count_mark];
  2481. // }
  2482. // return jsobj;
  2483. //}
  2484. //+(NSDictionary*)request_WatchList:(int)sort
  2485. //{
  2486. //
  2487. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2488. // __block AppDelegate *appDelegate = nil;
  2489. //
  2490. // dispatch_sync(dispatch_get_main_queue(), ^{
  2491. // //some UI methods ej
  2492. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2493. // });
  2494. // if(appDelegate.user!=nil)
  2495. // [params setValue:appDelegate.user forKey:@"user"];
  2496. // if(appDelegate.contact_id!=nil)
  2497. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2498. // if(appDelegate.password!=nil)
  2499. // [params setValue:appDelegate.password forKey:@"password"];
  2500. //
  2501. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2502. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2503. //
  2504. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2505. //
  2506. // [params setObject:ScreenCodeWishList forKey:kScreenName];
  2507. //
  2508. // if(appDelegate.offline_mode)
  2509. // {
  2510. // return [OLDataProvider offline_wishlist:params];
  2511. // }
  2512. // if(![self IsNetworkAvailable])
  2513. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2514. //
  2515. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  2516. // if(json==nil)
  2517. // return nil;
  2518. // NSError *error=nil;
  2519. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2520. // int result = [[jsobj valueForKey:@"result"] intValue];
  2521. //
  2522. // if (result==2)
  2523. // {
  2524. //
  2525. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2526. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2527. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2528. //
  2529. // [appDelegate update_count_mark];
  2530. // }
  2531. // return jsobj;
  2532. //}
  2533. //+(NSDictionary*)request_ItemDetail: (NSString* ) item_id model_name:(NSString*) model_name category_id:(NSString*) category_id use_name :(bool) use_name groupName:(NSString *)groupName
  2534. //{
  2535. //
  2536. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2537. // __block AppDelegate *appDelegate = nil;
  2538. //
  2539. // dispatch_sync(dispatch_get_main_queue(), ^{
  2540. // //some UI methods ej
  2541. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2542. // });
  2543. // if(appDelegate.user!=nil)
  2544. // [params setValue:appDelegate.user forKey:@"user"];
  2545. // if(appDelegate.contact_id!=nil)
  2546. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2547. // if(appDelegate.password!=nil)
  2548. // [params setValue:appDelegate.password forKey:@"password"];
  2549. // if(appDelegate.order_code!=nil)
  2550. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2551. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2552. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2553. // if(use_name)
  2554. // [params setValue:model_name forKey:@"product_name"];
  2555. // else
  2556. // [params setValue:item_id forKey:@"product_id"];
  2557. //
  2558. //
  2559. // [params setValue:category_id forKey:@"category"];
  2560. //
  2561. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  2562. // [params setObject:@"Open A Model" forKey:kAction];
  2563. // if (model_name) {
  2564. // NSDictionary *extra = @{@"ModelName" : model_name};
  2565. // [params setObject:extra forKey:kExtra];
  2566. // }
  2567. //
  2568. // if (groupName.length > 0) {
  2569. // [params setObject:groupName forKey:@"groupName"];
  2570. // }
  2571. //
  2572. // if(appDelegate.offline_mode)
  2573. // return [OLDataProvider offline_model:params];
  2574. //
  2575. // if(![self IsNetworkAvailable])
  2576. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2577. //
  2578. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  2579. // if(json==nil)
  2580. // return nil;
  2581. // NSError *error=nil;
  2582. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2583. // return jsobj;
  2584. //}
  2585. //+(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
  2586. //{
  2587. // if(![self IsNetworkAvailable])
  2588. // return nil;
  2589. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2590. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2591. // if(appDelegate.user!=nil)
  2592. // [params setValue:appDelegate.user forKey:@"user"];
  2593. // if(appDelegate.contact_id!=nil)
  2594. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2595. // if(appDelegate.password!=nil)
  2596. // [params setValue:appDelegate.password forKey:@"password"];
  2597. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2598. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2599. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2600. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2601. // [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  2602. // [params setValue:filter forKey:@"filter"];
  2603. // [params setValue:keyword forKey:@"keyword"];
  2604. //
  2605. //
  2606. // NSData* json=[self get_json:URL_CATEGORY_LOADMORE parameters:params];
  2607. // if(json==nil)
  2608. // return nil;
  2609. // NSError *error=nil;
  2610. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2611. // return jsobj;
  2612. //
  2613. //}
  2614. //+(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
  2615. //
  2616. //{
  2617. //
  2618. //
  2619. // __block AppDelegate *appDelegate = nil;
  2620. //
  2621. // dispatch_sync(dispatch_get_main_queue(), ^{
  2622. // //some UI methods ej
  2623. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2624. // });
  2625. //
  2626. //
  2627. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2628. //
  2629. // if(appDelegate.user!=nil)
  2630. // [params setValue:appDelegate.user forKey:@"user"];
  2631. // if(appDelegate.contact_id!=nil)
  2632. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2633. // if(appDelegate.password!=nil)
  2634. // [params setValue:appDelegate.password forKey:@"password"];
  2635. // if(appDelegate.order_code!=nil)
  2636. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2637. //
  2638. // [params setValue:addTo forKey:@"addTo"];
  2639. // [params setValue:orderCode forKey:@"orderCode"];
  2640. // [params setValue:alert forKey:@"alert"];
  2641. // [params setValue:qty forKey:@"sold_by_qty"];
  2642. // [params setValue:available forKey:@"available"];
  2643. // [params setValue:price forKey:@"price"];
  2644. // [params setValue:bestseller forKey:@"bestseller"];
  2645. // [params setValue:modelname forKey:@"modelName"];
  2646. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2647. //
  2648. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2649. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2650. // [params setValue:category forKey:@"category"];
  2651. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2652. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2653. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2654. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2655. // [params setValue:filter forKey:@"filter"];
  2656. // [params setValue:keyword forKey:@"keyword"];
  2657. //
  2658. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  2659. // if ([addTo isEqualToString:@"cart"]) {
  2660. // [params setObject:@"Add To Cart" forKey:kAction];
  2661. // }
  2662. //
  2663. //
  2664. // NSData* json= nil;
  2665. //
  2666. // if(appDelegate.offline_mode)
  2667. // {
  2668. // json= [OLDataProvider offline_categoryaddall:params];
  2669. // }
  2670. // else
  2671. // {
  2672. // if(![self IsNetworkAvailable])
  2673. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2674. //
  2675. //
  2676. // NSError *error=nil;
  2677. //
  2678. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2679. // params[@"resultSerial"]=uuid;
  2680. //
  2681. // for(int i=0;i<150;i++)
  2682. // {
  2683. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2684. // // result_params[@"resultSerial"]=uuid;
  2685. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  2686. // if(json!=nil)
  2687. // {
  2688. //
  2689. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2690. // int resultInt = [jsobj[@"result"] intValue];
  2691. // if(resultInt == 2 || resultInt == 8)
  2692. // {
  2693. // break;
  2694. // }
  2695. // }
  2696. // sleep(2);
  2697. // }
  2698. //
  2699. //
  2700. //
  2701. // }
  2702. // if(json==nil)
  2703. // return nil;
  2704. // NSError *error=nil;
  2705. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2706. // return jsobj;
  2707. //
  2708. //}
  2709. //+(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
  2710. //{
  2711. //
  2712. //
  2713. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2714. //
  2715. //
  2716. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2717. //
  2718. // if(appDelegate.user!=nil)
  2719. // [params setValue:appDelegate.user forKey:@"user"];
  2720. // if(appDelegate.contact_id!=nil)
  2721. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2722. // if(appDelegate.password!=nil)
  2723. // [params setValue:appDelegate.password forKey:@"password"];
  2724. // if(appDelegate.order_code!=nil)
  2725. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2726. //
  2727. // [params setValue:alert forKey:@"alert"];
  2728. // [params setValue:qty forKey:@"sold_by_qty"];
  2729. // [params setValue:available forKey:@"available"];
  2730. // [params setValue:price forKey:@"price"];
  2731. // [params setValue:bestseller forKey:@"bestseller"];
  2732. // [params setValue:modelname forKey:@"modelName"];
  2733. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2734. //
  2735. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2736. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2737. // [params setValue:category forKey:@"category"];
  2738. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2739. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2740. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2741. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2742. // [params setValue:filter forKey:@"filter"];
  2743. // [params setValue:keyword forKey:@"keyword"];
  2744. //
  2745. //
  2746. //
  2747. // if(appDelegate.offline_mode)
  2748. // return [OLDataProvider offline_category:params];
  2749. // if(![self IsNetworkAvailable])
  2750. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2751. //
  2752. // NSData* json=[self get_json:URL_ADDALL2PORTFOLIO parameters:params];
  2753. // if(json==nil)
  2754. // return nil;
  2755. // NSError *error=nil;
  2756. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2757. // return jsobj;
  2758. //
  2759. //}
  2760. //+(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
  2761. //{
  2762. //
  2763. //
  2764. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2765. //
  2766. //
  2767. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2768. //
  2769. // if(appDelegate.user!=nil)
  2770. // [params setValue:appDelegate.user forKey:@"user"];
  2771. // if(appDelegate.contact_id!=nil)
  2772. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2773. // if(appDelegate.password!=nil)
  2774. // [params setValue:appDelegate.password forKey:@"password"];
  2775. // if(appDelegate.order_code!=nil)
  2776. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2777. //
  2778. // [params setValue:alert forKey:@"alert"];
  2779. // [params setValue:qty forKey:@"sold_by_qty"];
  2780. // [params setValue:available forKey:@"available"];
  2781. // [params setValue:price forKey:@"price"];
  2782. // [params setValue:bestseller forKey:@"bestseller"];
  2783. // [params setValue:modelname forKey:@"modelName"];
  2784. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2785. //
  2786. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2787. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2788. // [params setValue:category forKey:@"category"];
  2789. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2790. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2791. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2792. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2793. // [params setValue:filter forKey:@"filter"];
  2794. // [params setValue:keyword forKey:@"keyword"];
  2795. //
  2796. //
  2797. //
  2798. // if(appDelegate.offline_mode)
  2799. // return [OLDataProvider offline_category:params];
  2800. // if(![self IsNetworkAvailable])
  2801. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2802. //
  2803. // NSData* json=[self get_json:URL_ADDALL2WISH parameters:params];
  2804. // if(json==nil)
  2805. // return nil;
  2806. // NSError *error=nil;
  2807. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2808. // return jsobj;
  2809. //
  2810. //}
  2811. //+(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
  2812. //{
  2813. //
  2814. //
  2815. // __block AppDelegate *appDelegate = nil;
  2816. //
  2817. // dispatch_sync(dispatch_get_main_queue(), ^{
  2818. // //some UI methods ej
  2819. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2820. // });
  2821. //
  2822. //
  2823. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2824. //
  2825. // if(appDelegate.user!=nil)
  2826. // [params setValue:appDelegate.user forKey:@"user"];
  2827. // if(appDelegate.contact_id!=nil)
  2828. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2829. // if(appDelegate.password!=nil)
  2830. // [params setValue:appDelegate.password forKey:@"password"];
  2831. // if(appDelegate.order_code!=nil)
  2832. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2833. //
  2834. // [params setValue:alert forKey:@"alert"];
  2835. // [params setValue:qty forKey:@"sold_by_qty"];
  2836. // [params setValue:available forKey:@"available"];
  2837. // [params setValue:price forKey:@"price"];
  2838. // [params setValue:bestseller forKey:@"bestseller"];
  2839. // [params setValue:modelname forKey:@"modelName"];
  2840. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2841. //
  2842. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2843. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2844. // [params setValue:category forKey:@"category"];
  2845. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2846. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2847. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2848. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2849. // [params setValue:filter forKey:@"filter"];
  2850. // [params setValue:keyword forKey:@"keyword"];
  2851. //
  2852. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  2853. // if (alert) {
  2854. // [params setObject:@"Filter" forKey:kAction];
  2855. // }
  2856. // if ([Singleton sharedInstance].homeItemClick) {
  2857. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  2858. // [Singleton sharedInstance].homeItemClick = NO;
  2859. //
  2860. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  2861. // [Singleton sharedInstance].homeClickedItemName = nil;
  2862. // [params setObject:extra forKey:kExtra];
  2863. //
  2864. // }
  2865. //
  2866. //
  2867. // if(appDelegate.offline_mode)
  2868. // return [OLDataProvider offline_category:params];
  2869. // if(![self IsNetworkAvailable])
  2870. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2871. //
  2872. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  2873. // if(json==nil)
  2874. // return nil;
  2875. // NSError *error=nil;
  2876. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2877. // return jsobj;
  2878. //
  2879. //}
  2880. //+(NSDictionary*)Search_addall:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  2881. //{
  2882. //
  2883. //
  2884. //
  2885. //
  2886. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2887. // __block AppDelegate *appDelegate = nil;
  2888. //
  2889. // dispatch_sync(dispatch_get_main_queue(), ^{
  2890. // //some UI methods ej
  2891. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2892. // });
  2893. // if(appDelegate.user!=nil)
  2894. // [params setValue:appDelegate.user forKey:@"user"];
  2895. // if(appDelegate.contact_id!=nil)
  2896. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2897. // if(appDelegate.password!=nil)
  2898. // [params setValue:appDelegate.password forKey:@"password"];
  2899. // if(appDelegate.order_code!=nil)
  2900. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2901. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2902. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2903. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2904. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2905. // // [params setValue:filter forKey:@"filter"];
  2906. // [params setValue:keywords forKey:@"keyword"];
  2907. // [params setValue:addTo forKey:@"addTo"];
  2908. //
  2909. // [params setValue:orderCode forKey:@"orderCode"];
  2910. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2911. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2912. // if(matchfull)
  2913. // [params setValue:@"true" forKey:@"exactMatch"];
  2914. // else
  2915. // [params setValue:@"false" forKey:@"exactMatch"];
  2916. //
  2917. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  2918. // if ([addTo isEqualToString:@"cart"]) {
  2919. // [params setObject:@"Add To Cart" forKey:kAction];
  2920. // }
  2921. //
  2922. // NSData* json=nil;
  2923. // if(appDelegate.offline_mode)
  2924. // {
  2925. // json=[OLDataProvider offline_searchaddall:params];
  2926. // }
  2927. // else
  2928. // {
  2929. // if(![self IsNetworkAvailable])
  2930. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2931. //
  2932. // NSError *error=nil;
  2933. //
  2934. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2935. // params[@"resultSerial"]=uuid;
  2936. //
  2937. // for(int i=0;i<150;i++)
  2938. // {
  2939. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2940. // // result_params[@"resultSerial"]=uuid;
  2941. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  2942. // if(json!=nil)
  2943. // {
  2944. //
  2945. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2946. // if([jsobj[@"result"] intValue]==2)
  2947. // {
  2948. // break;
  2949. // }
  2950. // }
  2951. // sleep(2);
  2952. // }
  2953. // }
  2954. // if(json==nil)
  2955. // return nil;
  2956. // NSError *error=nil;
  2957. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2958. // return jsobj;
  2959. //
  2960. //}
  2961. //+(NSDictionary*)Search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull
  2962. //{
  2963. //
  2964. //
  2965. //
  2966. //
  2967. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2968. // __block AppDelegate *appDelegate = nil;
  2969. //
  2970. // dispatch_sync(dispatch_get_main_queue(), ^{
  2971. // //some UI methods ej
  2972. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2973. // });
  2974. // if(appDelegate.user!=nil)
  2975. // [params setValue:appDelegate.user forKey:@"user"];
  2976. // if(appDelegate.contact_id!=nil)
  2977. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2978. // if(appDelegate.password!=nil)
  2979. // [params setValue:appDelegate.password forKey:@"password"];
  2980. // if(appDelegate.order_code!=nil)
  2981. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2982. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2983. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2984. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2985. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2986. // // [params setValue:filter forKey:@"filter"];
  2987. // [params setValue:keywords forKey:@"keyword"];
  2988. //
  2989. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2990. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2991. // if(matchfull)
  2992. // [params setValue:@"true" forKey:@"exactMatch"];
  2993. // else
  2994. // [params setValue:@"false" forKey:@"exactMatch"];
  2995. //
  2996. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  2997. // if (keywords) {
  2998. // [params setObject:@"Search" forKey:kAction];
  2999. // }
  3000. //
  3001. // if(appDelegate.offline_mode)
  3002. // {
  3003. // return [OLDataProvider offline_search:params];
  3004. // }
  3005. // if(![self IsNetworkAvailable])
  3006. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3007. //
  3008. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3009. // if(json==nil)
  3010. // return nil;
  3011. // NSError *error=nil;
  3012. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3013. // return jsobj;
  3014. //}
  3015. //+(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
  3016. //{
  3017. // // for debug
  3018. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3019. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3020. //
  3021. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3022. // __block AppDelegate *appDelegate = nil;
  3023. //
  3024. // dispatch_sync(dispatch_get_main_queue(), ^{
  3025. // //some UI methods ej
  3026. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3027. // });
  3028. // if(appDelegate.user!=nil)
  3029. // [params setValue:appDelegate.user forKey:@"user"];
  3030. // if(appDelegate.contact_id!=nil)
  3031. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3032. // if(appDelegate.password!=nil)
  3033. // [params setValue:appDelegate.password forKey:@"password"];
  3034. // if(appDelegate.order_code!=nil)
  3035. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3036. //
  3037. // [params setValue:addTo forKey:@"addTo"];
  3038. //
  3039. // [params setValue:orderCode forKey:@"orderCode"];
  3040. //
  3041. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3042. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3043. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3044. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3045. // // [params setValue:filter forKey:@"filter"];
  3046. // [params setValue:covertype forKey:@"covertype"];
  3047. // [params setValue:ctgid forKey:@"ctgId"];
  3048. // [params setValue:modelname forKey:@"modelName"];
  3049. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3050. // [params setValue:alert forKey:@"alert"];
  3051. // [params setValue:qty forKey:@"sold_by_qty"];
  3052. // [params setValue:available forKey:@"available"];
  3053. // [params setValue:price forKey:@"price"];
  3054. // [params setValue:bestseller forKey:@"bestseller"];
  3055. //
  3056. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3057. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3058. //
  3059. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3060. // if ([addTo isEqualToString:@"cart"]) {
  3061. // [params setObject:@"Add To Cart" forKey:kAction];
  3062. // }
  3063. //
  3064. // NSData* json = nil;
  3065. //
  3066. // if(appDelegate.offline_mode)
  3067. // {
  3068. // json= [OLDataProvider offline_itemsearchaddall:params];
  3069. // }
  3070. // else
  3071. // {
  3072. // if(![self IsNetworkAvailable])
  3073. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3074. // NSError *error=nil;
  3075. //
  3076. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3077. // params[@"resultSerial"]=uuid;
  3078. //
  3079. // for(int i=0;i<150;i++)
  3080. // {
  3081. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3082. // // result_params[@"resultSerial"]=uuid;
  3083. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  3084. // if(json!=nil)
  3085. // {
  3086. //
  3087. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3088. // if([jsobj[@"result"] intValue]==2)
  3089. // {
  3090. // break;
  3091. // }
  3092. // }
  3093. // sleep(2);
  3094. // }
  3095. // }
  3096. // if(json==nil)
  3097. // return nil;
  3098. // NSError *error=nil;
  3099. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3100. // return jsobj;
  3101. //}
  3102. //+(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
  3103. //{
  3104. //
  3105. // // for debug
  3106. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3107. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3108. //
  3109. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3110. // __block AppDelegate *appDelegate = nil;
  3111. //
  3112. // dispatch_sync(dispatch_get_main_queue(), ^{
  3113. // //some UI methods ej
  3114. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3115. // });
  3116. // if(appDelegate.user!=nil)
  3117. // [params setValue:appDelegate.user forKey:@"user"];
  3118. // if(appDelegate.contact_id!=nil)
  3119. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3120. // if(appDelegate.password!=nil)
  3121. // [params setValue:appDelegate.password forKey:@"password"];
  3122. // if(appDelegate.order_code!=nil)
  3123. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3124. //
  3125. //
  3126. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3127. // if (alert && qty && available && price && bestseller) {
  3128. // [params setObject:@"Filter" forKey:kAction];
  3129. // }
  3130. // if ([Singleton sharedInstance].homeItemClick) {
  3131. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  3132. // [Singleton sharedInstance].homeItemClick = NO;
  3133. //
  3134. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  3135. // [Singleton sharedInstance].homeClickedItemName = nil;
  3136. // [params setObject:extra forKey:kExtra];
  3137. // }
  3138. //
  3139. //
  3140. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3141. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3142. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3143. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3144. // // [params setValue:filter forKey:@"filter"];
  3145. // [params setValue:covertype forKey:@"covertype"];
  3146. // [params setValue:ctgid forKey:@"ctgId"];
  3147. // [params setValue:modelname forKey:@"modelName"];
  3148. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3149. // [params setValue:alert forKey:@"alert"];
  3150. // [params setValue:qty forKey:@"sold_by_qty"];
  3151. // [params setValue:available forKey:@"available"];
  3152. // [params setValue:price forKey:@"price"];
  3153. // [params setValue:bestseller forKey:@"bestseller"];
  3154. //
  3155. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3156. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3157. //
  3158. // if(appDelegate.offline_mode)
  3159. // {
  3160. // return [OLDataProvider offline_itemsearch:params];
  3161. // }
  3162. // if(![self IsNetworkAvailable])
  3163. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3164. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  3165. // if(json==nil)
  3166. // return nil;
  3167. // NSError *error=nil;
  3168. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3169. // return jsobj;
  3170. //}
  3171. //+(NSDictionary*)Search: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword
  3172. //{
  3173. // if(![self IsNetworkAvailable])
  3174. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3175. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3176. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3177. // if(appDelegate.user!=nil)
  3178. // [params setValue:appDelegate.user forKey:@"user"];
  3179. // if(appDelegate.contact_id!=nil)
  3180. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3181. // if(appDelegate.password!=nil)
  3182. // [params setValue:appDelegate.password forKey:@"password"];
  3183. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3184. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3185. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3186. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3187. // [params setValue:filter forKey:@"filter"];
  3188. // [params setValue:keyword forKey:@"keyword"];
  3189. //
  3190. //
  3191. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3192. // if(json==nil)
  3193. // return nil;
  3194. // NSError *error=nil;
  3195. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3196. // return jsobj;
  3197. //}
  3198. +(NSDictionary*)request_model_qty: (NSString*) fashionId
  3199. {
  3200. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3201. __block AppDelegate *appDelegate = nil;
  3202. dispatch_sync(dispatch_get_main_queue(), ^{
  3203. //some UI methods ej
  3204. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3205. });
  3206. if(appDelegate.user!=nil)
  3207. [params setValue:appDelegate.user forKey:@"user"];
  3208. if(appDelegate.contact_id!=nil)
  3209. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3210. if(appDelegate.password!=nil)
  3211. [params setValue:appDelegate.password forKey:@"password"];
  3212. [params setValue:fashionId forKey:@"fashionId"];
  3213. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  3214. NSData* json = nil;
  3215. if(appDelegate.offline_mode)
  3216. {
  3217. json = [OLDataProvider offline_model_qty:params];
  3218. } else {
  3219. if(![self IsNetworkAvailable])
  3220. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3221. json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  3222. }
  3223. if(json==nil)
  3224. return nil;
  3225. NSError *error=nil;
  3226. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3227. return jsobj;
  3228. }
  3229. +(NSDictionary*)retrieve_password: (NSString*) user email:(NSString*) email
  3230. {
  3231. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3232. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3233. // if(appDelegate.user!=nil)
  3234. // [params setValue:appDelegate.user forKey:@"user"];
  3235. // if(appDelegate.contact_id!=nil)
  3236. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3237. // if(appDelegate.password!=nil)
  3238. // [params setValue:appDelegate.password forKey:@"password"];
  3239. [params setValue:user forKey:@"username"];
  3240. [params setValue:email forKey:@"email"];
  3241. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3242. if(![self IsNetworkAvailable])
  3243. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3244. NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  3245. if(json==nil)
  3246. return nil;
  3247. NSError *error=nil;
  3248. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3249. return jsobj;
  3250. }
  3251. +(NSDictionary*)load_HomePage:(int) price_template customid:(int) customid
  3252. {
  3253. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3254. __block AppDelegate *appDelegate = nil;
  3255. dispatch_sync(dispatch_get_main_queue(), ^{
  3256. //some UI methods ej
  3257. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3258. });
  3259. if(appDelegate.user!=nil)
  3260. [params setValue:appDelegate.user forKey:@"user"];
  3261. if(appDelegate.contact_id!=nil)
  3262. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3263. if(appDelegate.password!=nil)
  3264. [params setValue:appDelegate.password forKey:@"password"];
  3265. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3266. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3267. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  3268. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3269. if(appDelegate.offline_mode)
  3270. {
  3271. //params[@"offline_Command"]=url;
  3272. return [OLDataProvider offline_home];
  3273. }
  3274. if(![self IsNetworkAvailable])
  3275. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3276. NSData* json=[self get_json:URL_LOAD_HOME parameters:params];
  3277. if(json==nil)
  3278. return nil;
  3279. NSError *error=nil;
  3280. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3281. return jsobj;
  3282. }
  3283. //+(NSDictionary*)logout
  3284. //{
  3285. //
  3286. //
  3287. //
  3288. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3289. // __block AppDelegate *appDelegate = nil;
  3290. //
  3291. // dispatch_sync(dispatch_get_main_queue(), ^{
  3292. // //some UI methods ej
  3293. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3294. // });
  3295. // if(appDelegate.user!=nil)
  3296. // [params setValue:appDelegate.user forKey:@"user"];
  3297. //
  3298. //
  3299. // if(appDelegate.password!=nil)
  3300. // [params setValue:appDelegate.password forKey:@"password"];
  3301. //
  3302. //
  3303. // if(appDelegate.offline_mode)
  3304. // {
  3305. // return [OLDataProvider offline_logout:params];
  3306. // }
  3307. // if(![self IsNetworkAvailable])
  3308. // {
  3309. // DebugLog(@"NET ERR");
  3310. //
  3311. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3312. // // return nil;
  3313. // }
  3314. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  3315. // //if(json==nil)
  3316. //
  3317. //
  3318. // if(json==nil)
  3319. // return nil;
  3320. // NSError *error=nil;
  3321. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3322. // int result = [[jsobj valueForKey:@"result"] intValue];
  3323. //
  3324. // if (result==2)
  3325. // {
  3326. //
  3327. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  3328. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  3329. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  3330. //
  3331. // [appDelegate update_count_mark];
  3332. //
  3333. //
  3334. // appDelegate.can_show_price =false;
  3335. // appDelegate.can_see_price =false;
  3336. // appDelegate.can_create_portfolio =false;
  3337. // appDelegate.can_create_order =false;
  3338. //
  3339. //
  3340. // appDelegate.can_cancel_order =false;
  3341. // appDelegate.can_set_cart_price =false;
  3342. // appDelegate.can_delete_order =false;
  3343. // appDelegate.can_submit_order =false;
  3344. // appDelegate.can_set_tearsheet_price =false;
  3345. // appDelegate.can_update_contact_info = false;
  3346. //
  3347. // appDelegate.save_order_logout = false;
  3348. // appDelegate.submit_order_logout = false;
  3349. // appDelegate.alert_sold_in_quantities = false;
  3350. //
  3351. // appDelegate.ipad_perm =nil ;
  3352. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  3353. // appDelegate.OrderFilter= nil;
  3354. // [appDelegate SetSo:nil];
  3355. // [appDelegate set_main_button_panel];
  3356. //#ifdef RA_NOTIFICATION
  3357. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  3358. //#endif
  3359. // }
  3360. // return jsobj;
  3361. //}
  3362. +(NSDictionary*)request_Cagegory
  3363. {
  3364. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  3365. __block AppDelegate *appDelegate = nil;
  3366. dispatch_sync(dispatch_get_main_queue(), ^{
  3367. //some UI methods ej
  3368. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3369. });
  3370. if(appDelegate.offline_mode)
  3371. {
  3372. //params[@"offline_Command"]=url;
  3373. return [OLDataProvider offline_category_menu];
  3374. }
  3375. if(![self IsNetworkAvailable])
  3376. {
  3377. DebugLog(@"NET ERR");
  3378. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3379. // return nil;
  3380. }
  3381. NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  3382. //if(json==nil)
  3383. if(json==nil)
  3384. return nil;
  3385. NSError *error=nil;
  3386. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3387. return jsobj;
  3388. }
  3389. +(int)Authorize : (NSString*) user password:(NSString*) password{
  3390. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  3391. // return RESULT_NET_ERROR;
  3392. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3393. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3394. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3395. __block AppDelegate *appDelegate = nil;
  3396. dispatch_sync(dispatch_get_main_queue(), ^{
  3397. //some UI methods ej
  3398. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3399. });
  3400. if(RASingleton.sharedInstance.duid !=nil)
  3401. [params setValue:RASingleton.sharedInstance.duid forKey:@"udid"];
  3402. [params setValue:@"handset_login" forKey:@"action"];
  3403. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  3404. [params setValue:user forKey:@"user"];
  3405. [params setValue:password forKey:@"password"];
  3406. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  3407. #ifdef TEST
  3408. [params setValue:@"true" forKey:@"is_debug"];
  3409. #else
  3410. [params setValue:@"false" forKey:@"is_debug"];
  3411. #endif
  3412. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3413. [params setObject:@"Login" forKey:kAction];
  3414. NSData* json= nil;
  3415. if(appDelegate.offline_mode)
  3416. {
  3417. json= [OLDataProvider offline_login:params] ;
  3418. }
  3419. else
  3420. {
  3421. if(![self IsNetworkAvailable])
  3422. return RESULT_NET_NOTAVAILABLE;
  3423. json =[self get_json:URL_UPDATE_AUTH parameters:params];
  3424. }
  3425. if(json==nil)
  3426. return RESULT_NET_ERROR;
  3427. int ret = [self parse_authinfo:json user:user password:password];
  3428. DebugLog(@"parse_authinfo return %d ",ret);
  3429. return ret;
  3430. }
  3431. +(NSDictionary*)update_customer_img: (NSString*) contactid img_url:(NSString*) url
  3432. {
  3433. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3434. __block AppDelegate *appDelegate = nil;
  3435. dispatch_sync(dispatch_get_main_queue(), ^{
  3436. //some UI methods ej
  3437. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3438. });
  3439. if(appDelegate.user!=nil)
  3440. [params setValue:appDelegate.user forKey:@"user"];
  3441. // if(appDelegate.contact_id!=nil)
  3442. if(appDelegate.password!=nil)
  3443. [params setValue:appDelegate.password forKey:@"password"];
  3444. [params setValue:contactid forKey:@"contactId"];
  3445. [params setValue:url forKey:@"business_card"];
  3446. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  3447. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  3448. if(appDelegate.offline_mode)
  3449. {
  3450. return [OLDataProvider offline_notimpl];
  3451. }
  3452. if(![self IsNetworkAvailable])
  3453. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3454. NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  3455. if(json==nil)
  3456. return nil;
  3457. NSError *error=nil;
  3458. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3459. return jsobj;
  3460. }
  3461. +(NSDictionary*)request_PendingOrder:(NSString *)contactid
  3462. {
  3463. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3464. __block AppDelegate *appDelegate = nil;
  3465. dispatch_sync(dispatch_get_main_queue(), ^{
  3466. //some UI methods ej
  3467. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3468. });
  3469. if(appDelegate.user!=nil)
  3470. [params setValue:appDelegate.user forKey:@"user"];
  3471. // if(appDelegate.contact_id!=nil)
  3472. if(appDelegate.password!=nil)
  3473. [params setValue:appDelegate.password forKey:@"password"];
  3474. [params setValue:contactid forKey:@"contactId"];
  3475. if(appDelegate.offline_mode)
  3476. {
  3477. return [OLDataProvider offline_notimpl];
  3478. }
  3479. if(![self IsNetworkAvailable])
  3480. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3481. NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  3482. if(json==nil)
  3483. return nil;
  3484. NSError *error=nil;
  3485. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3486. return jsobj;
  3487. }
  3488. //+(NSDictionary*)request_CustomerInfo:(NSString* ) contactid
  3489. //{
  3490. //
  3491. //
  3492. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3493. // __block AppDelegate *appDelegate = nil;
  3494. //
  3495. // dispatch_sync(dispatch_get_main_queue(), ^{
  3496. // //some UI methods ej
  3497. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3498. // });
  3499. // if(appDelegate.user!=nil)
  3500. // [params setValue:appDelegate.user forKey:@"user"];
  3501. // // if(appDelegate.contact_id!=nil)
  3502. //
  3503. // if(appDelegate.password!=nil)
  3504. // [params setValue:appDelegate.password forKey:@"password"];
  3505. // [params setValue:contactid forKey:@"contactId"];
  3506. //
  3507. // [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  3508. //
  3509. // if(appDelegate.offline_mode)
  3510. // return [OLDataProvider offline_contactinfo:params];
  3511. // if(![self IsNetworkAvailable])
  3512. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3513. //
  3514. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  3515. // if(json==nil)
  3516. // return nil;
  3517. // NSError *error=nil;
  3518. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3519. // return jsobj;
  3520. //
  3521. //}
  3522. +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
  3523. {
  3524. DebugLog(@"parse_authinfo");
  3525. NSError *error=nil;
  3526. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3527. if(jsobj)
  3528. {
  3529. __block AppDelegate *appDelegate = nil;
  3530. dispatch_sync(dispatch_get_main_queue(), ^{
  3531. //some UI methods ej
  3532. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3533. });
  3534. int result = [[jsobj valueForKey:@"result"] intValue];
  3535. if (result<0)
  3536. return result;
  3537. if(result!=AP_USER_AUTH&& result!=9)
  3538. {
  3539. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  3540. // [appDelegate Logout];
  3541. if(result==8)
  3542. {
  3543. return RESULT_LOGIN_DEVICE;
  3544. }
  3545. return RESULT_FALSE;
  3546. }
  3547. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  3548. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  3549. user=[objheader objectForKey:@"username"] ;
  3550. DebugLog(@"required_ver=%@ ",required_ver);
  3551. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  3552. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  3553. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  3554. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  3555. // if([ibadge isEqual:[NSNull null]])
  3556. // strbadge=@"0";
  3557. // if(ibadge==nil)
  3558. // ibadge=@"0";
  3559. // if([strbadge isEqualToString:@"null"])
  3560. // strbadge=@"0";
  3561. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  3562. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  3563. if([appDelegate.build intValue]<[required_ver intValue])
  3564. return RESULT_VER_LOW;
  3565. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  3566. appDelegate.user = user;
  3567. appDelegate.password = password;
  3568. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  3569. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  3570. appDelegate.bLogin = true;
  3571. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  3572. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  3573. {
  3574. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  3575. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  3576. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  3577. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  3578. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  3579. }
  3580. NSString* mode =[jsobj valueForKey:@"mode"] ;
  3581. [appDelegate SetMode:mode];
  3582. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  3583. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  3584. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  3585. [appDelegate update_count_mark];
  3586. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  3587. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  3588. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  3589. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  3590. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  3591. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  3592. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  3593. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  3594. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  3595. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  3596. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  3597. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  3598. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  3599. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  3600. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  3601. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  3602. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  3603. [appDelegate set_main_button_panel];
  3604. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  3605. // shop order status filter
  3606. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  3607. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  3608. // Sales order status filter
  3609. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  3610. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  3611. // specialInstruction
  3612. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  3613. //-价格类型
  3614. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  3615. // 权限
  3616. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  3617. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  3618. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  3619. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  3620. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  3621. [[RASingleton sharedInstance] resetGlobalLock];
  3622. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  3623. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  3624. }
  3625. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  3626. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  3627. // {
  3628. // // no update on the server;
  3629. // return RESULT_TRUE;
  3630. // }
  3631. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  3632. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3633. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3634. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3635. // [defaults synchronize];
  3636. //
  3637. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  3638. // NSArray* keys= [objfuncs allKeys];
  3639. /*
  3640. db.setTransactionSuccessful();
  3641. db.endTransaction();
  3642. */
  3643. return RESULT_TRUE;
  3644. }
  3645. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  3646. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  3647. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  3648. return RESULT_USERAUTH_ERROR;
  3649. }
  3650. //+(bool) IsNetworkAvailable
  3651. //{
  3652. //
  3653. // if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) &&
  3654. // ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable))
  3655. // return false;
  3656. // return true;
  3657. //}
  3658. //+(NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim
  3659. //{
  3660. // NSScanner *theScanner = [NSScanner scannerWithString:html];
  3661. // NSString *text = nil;
  3662. //
  3663. // while ([theScanner isAtEnd] == NO) {
  3664. // // find start of tag
  3665. // [theScanner scanUpToString:@"<" intoString:NULL] ;
  3666. // // find end of tag
  3667. // [theScanner scanUpToString:@">" intoString:&text] ;
  3668. // // replace the found tag with a space
  3669. // //(you can filter multi-spaces out later if you wish)
  3670. // html = [html stringByReplacingOccurrencesOfString:
  3671. // [ NSString stringWithFormat:@"%@>", text]
  3672. // withString:@""];
  3673. // }
  3674. //
  3675. // return trim ? [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : html;
  3676. //}
  3677. //
  3678. //+(NSString *)flattenURL:(NSString *)url trimWhiteSpace:(BOOL)trim
  3679. //{
  3680. // NSScanner *theScanner = [NSScanner scannerWithString:url];
  3681. // NSString *text = nil;
  3682. //
  3683. // while ([theScanner isAtEnd] == NO) {
  3684. // // find start of tag
  3685. // [theScanner scanUpToString:@"/" intoString:NULL] ;
  3686. // // find end of tag
  3687. // [theScanner scanUpToString:@"/" intoString:&text] ;
  3688. // // replace the found tag with a space
  3689. // //(you can filter multi-spaces out later if you wish)
  3690. // url = [url stringByReplacingOccurrencesOfString:
  3691. // [ NSString stringWithFormat:@"%@", text]
  3692. // withString:@""];
  3693. // }
  3694. //
  3695. // return trim ? [url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : url;
  3696. //}
  3697. + (NSDictionary *)set_npd_shop_price_type:(NSInteger)priceType {
  3698. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3699. __block AppDelegate *appDelegate = nil;
  3700. dispatch_sync(dispatch_get_main_queue(), ^{
  3701. //some UI methods ej
  3702. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3703. });
  3704. if(appDelegate.user!=nil)
  3705. [dic setValue:appDelegate.user forKey:@"user"];
  3706. if(appDelegate.password!=nil)
  3707. [dic setValue:appDelegate.password forKey:@"password"];
  3708. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  3709. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  3710. NSData* json=nil;
  3711. if(appDelegate.offline_mode)
  3712. {
  3713. return [OLDataProvider offline_notimpl];
  3714. }
  3715. else
  3716. {
  3717. if(![self IsNetworkAvailable])
  3718. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3719. json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  3720. }
  3721. if(json!=nil)
  3722. {
  3723. NSError *error=nil;
  3724. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3725. return jsobj;
  3726. }
  3727. return nil;
  3728. }
  3729. + (NSDictionary *)get_npd_shop_givenPrice {
  3730. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3731. __block AppDelegate *appDelegate = nil;
  3732. dispatch_sync(dispatch_get_main_queue(), ^{
  3733. //some UI methods ej
  3734. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3735. });
  3736. if(appDelegate.user!=nil)
  3737. [dic setValue:appDelegate.user forKey:@"user"];
  3738. if(appDelegate.password!=nil)
  3739. [dic setValue:appDelegate.password forKey:@"password"];
  3740. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  3741. NSData* json=nil;
  3742. if(appDelegate.offline_mode)
  3743. {
  3744. return [OLDataProvider offline_notimpl];
  3745. }
  3746. else
  3747. {
  3748. if(![self IsNetworkAvailable])
  3749. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3750. json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  3751. }
  3752. if(json!=nil)
  3753. {
  3754. NSError *error=nil;
  3755. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3756. return jsobj;
  3757. }
  3758. return nil;
  3759. }
  3760. + (NSDictionary *)set_npd_shop_givenPrice:(NSMutableDictionary *)params {
  3761. __block AppDelegate *appDelegate = nil;
  3762. dispatch_sync(dispatch_get_main_queue(), ^{
  3763. //some UI methods ej
  3764. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3765. });
  3766. if(appDelegate.user!=nil)
  3767. [params setValue:appDelegate.user forKey:@"user"];
  3768. if(appDelegate.password!=nil)
  3769. [params setValue:appDelegate.password forKey:@"password"];
  3770. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  3771. NSData* json=nil;
  3772. if(appDelegate.offline_mode)
  3773. {
  3774. return [OLDataProvider offline_notimpl];
  3775. }
  3776. else
  3777. {
  3778. if(![self IsNetworkAvailable])
  3779. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3780. json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  3781. }
  3782. if(json!=nil)
  3783. {
  3784. NSError *error=nil;
  3785. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3786. return jsobj;
  3787. }
  3788. return nil;
  3789. }
  3790. + (NSDictionary *)merge_order:(NSMutableDictionary *)params {
  3791. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3792. __block AppDelegate *appDelegate = nil;
  3793. dispatch_sync(dispatch_get_main_queue(), ^{
  3794. //some UI methods ej
  3795. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3796. });
  3797. if(appDelegate.user!=nil)
  3798. [dic setValue:appDelegate.user forKey:@"user"];
  3799. if(appDelegate.password!=nil)
  3800. [dic setValue:appDelegate.password forKey:@"password"];
  3801. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  3802. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  3803. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  3804. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  3805. NSData* json=nil;
  3806. if(appDelegate.offline_mode)
  3807. {
  3808. return [OLDataProvider offline_notimpl];
  3809. }
  3810. else
  3811. {
  3812. if(![self IsNetworkAvailable])
  3813. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3814. json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  3815. }
  3816. if(json!=nil)
  3817. {
  3818. NSError *error=nil;
  3819. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3820. return jsobj;
  3821. }
  3822. else
  3823. return nil;
  3824. }
  3825. //+ (NSDictionary *)lock_order:(NSString *)oderCode
  3826. //{
  3827. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3828. // __block AppDelegate *appDelegate = nil;
  3829. //
  3830. // dispatch_sync(dispatch_get_main_queue(), ^{
  3831. // //some UI methods ej
  3832. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3833. // });
  3834. // if(appDelegate.user!=nil)
  3835. // [params setValue:appDelegate.user forKey:@"user"];
  3836. //
  3837. // if(appDelegate.password!=nil)
  3838. // [params setValue:appDelegate.password forKey:@"password"];
  3839. //
  3840. // [params setValue:oderCode forKey:@"orderCode"];
  3841. //
  3842. // NSData* json=nil;
  3843. // if(appDelegate.offline_mode)
  3844. // {
  3845. // json=[OLDataProvider offline_editorder:params];
  3846. //
  3847. // }
  3848. // else
  3849. // {
  3850. // if(![self IsNetworkAvailable])
  3851. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3852. //
  3853. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  3854. // }
  3855. // if(json!=nil)
  3856. // {
  3857. // NSError *error=nil;
  3858. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3859. //
  3860. // return jsobj;
  3861. // }
  3862. // else
  3863. // return nil;
  3864. //}
  3865. + (NSDictionary *)quoteOrder:(NSString *)so_id emailAddr:(NSString *)addr {
  3866. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3867. __block AppDelegate *appDelegate = nil;
  3868. dispatch_sync(dispatch_get_main_queue(), ^{
  3869. //some UI methods ej
  3870. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3871. });
  3872. if(appDelegate.user!=nil)
  3873. [dic setValue:appDelegate.user forKey:@"user"];
  3874. if(appDelegate.password!=nil)
  3875. [dic setValue:appDelegate.password forKey:@"password"];
  3876. [dic setValue:so_id forKey:@"orderCode"];
  3877. [dic setValue:addr forKey:@"email"];
  3878. [dic setObject:ScreenCodeCart forKey:kScreenName];
  3879. if (appDelegate.customerInfo) {
  3880. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  3881. if (customer_cid) {
  3882. [dic setValue:customer_cid forKey:@"contactId"];
  3883. }
  3884. }
  3885. NSData* json=nil;
  3886. if(appDelegate.offline_mode)
  3887. {
  3888. return [OLDataProvider offline_notimpl];
  3889. }
  3890. else
  3891. {
  3892. if(![self IsNetworkAvailable])
  3893. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3894. json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  3895. }
  3896. if(json!=nil)
  3897. {
  3898. NSError *error=nil;
  3899. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3900. return jsobj;
  3901. }
  3902. return @{@"result" : @(RESULT_FALSE)};
  3903. }
  3904. + (NSDictionary *)notifyModel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName{
  3905. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3906. __block AppDelegate *appDelegate = nil;
  3907. dispatch_sync(dispatch_get_main_queue(), ^{
  3908. //some UI methods ej
  3909. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3910. });
  3911. if(appDelegate.user!=nil)
  3912. [dic setValue:appDelegate.user forKey:@"user"];
  3913. if(appDelegate.password!=nil)
  3914. [dic setValue:appDelegate.password forKey:@"password"];
  3915. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  3916. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  3917. if (customer_cid) {
  3918. [dic setValue:customer_cid forKey:@"contactId"];
  3919. }
  3920. }
  3921. [dic setObject:screenName forKey:kScreenName];
  3922. [dic setValue:modelID forKey:@"productId"];
  3923. if (addr) { // 弹框输入
  3924. [dic setValue:addr forKey:@"email"];
  3925. } else {
  3926. // employee选择了Contact,并且Contact有Email
  3927. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  3928. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  3929. // if (email) {
  3930. // [dic setValue:email forKey:@"email"];
  3931. // }
  3932. // }
  3933. }
  3934. NSData* json=nil;
  3935. if(appDelegate.offline_mode)
  3936. {
  3937. return [OLDataProvider offline_notimpl];
  3938. }
  3939. else
  3940. {
  3941. if(![self IsNetworkAvailable])
  3942. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3943. json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  3944. }
  3945. if(json!=nil)
  3946. {
  3947. NSError *error=nil;
  3948. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3949. return jsobj;
  3950. }
  3951. return @{@"result" : @(RESULT_FALSE)};
  3952. }
  3953. + (NSDictionary *)quoteWishlist2EmailAddr:(NSString *)addr {
  3954. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3955. __block AppDelegate *appDelegate = nil;
  3956. dispatch_sync(dispatch_get_main_queue(), ^{
  3957. //some UI methods ej
  3958. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3959. });
  3960. if(appDelegate.user!=nil)
  3961. [dic setValue:appDelegate.user forKey:@"user"];
  3962. if(appDelegate.password!=nil)
  3963. [dic setValue:appDelegate.password forKey:@"password"];
  3964. [dic setValue:addr forKey:@"email"];
  3965. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  3966. // if (appDelegate.customerInfo) {
  3967. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  3968. // if (customer_cid) {
  3969. // [dic setValue:customer_cid forKey:@"contactId"];
  3970. // }
  3971. // }
  3972. NSData* json=nil;
  3973. if(appDelegate.offline_mode)
  3974. {
  3975. return [OLDataProvider offline_notimpl];
  3976. }
  3977. else
  3978. {
  3979. if(![self IsNetworkAvailable])
  3980. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3981. json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  3982. }
  3983. if(json!=nil)
  3984. {
  3985. NSError *error=nil;
  3986. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3987. return jsobj;
  3988. }
  3989. return @{@"result" : @(RESULT_FALSE)};
  3990. }
  3991. + (NSDictionary *)movetobackorder:(NSString *)cart_item_id {
  3992. if (cart_item_id == nil || cart_item_id.length < 1) {
  3993. return @{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"};
  3994. }
  3995. __block AppDelegate *appDelegate = nil;
  3996. dispatch_sync(dispatch_get_main_queue(), ^{
  3997. //some UI methods ej
  3998. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3999. });
  4000. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4001. if(appDelegate.user!=nil)
  4002. [dic setValue:appDelegate.user forKey:@"user"];
  4003. if(appDelegate.password!=nil)
  4004. [dic setValue:appDelegate.password forKey:@"password"];
  4005. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  4006. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  4007. [dic setObject:ScreenCodeCart forKey:kScreenName];
  4008. if(![self IsNetworkAvailable])
  4009. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4010. NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  4011. if(json!=nil)
  4012. {
  4013. NSError *error=nil;
  4014. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4015. return jsobj;
  4016. }
  4017. return @{@"result" : @(RESULT_FALSE)};
  4018. }
  4019. + (NSDictionary*)request_hangTag:(NSString *)group {
  4020. #ifdef BUILD_UWAVER
  4021. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4022. __block AppDelegate *appDelegate = nil;
  4023. dispatch_sync(dispatch_get_main_queue(), ^{
  4024. //some UI methods ej
  4025. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4026. });
  4027. if(appDelegate.user!=nil)
  4028. [params setValue:appDelegate.user forKey:@"user"];
  4029. if(appDelegate.contact_id!=nil)
  4030. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4031. if(appDelegate.password!=nil)
  4032. [params setValue:appDelegate.password forKey:@"password"];
  4033. if (group) {
  4034. [params setValue:group forKey:@"groupName"];
  4035. }
  4036. NSString * uuid= [[NSUUID UUID] UUIDString];
  4037. params[@"resultSerial"]=uuid;
  4038. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4039. NSData* json = nil;
  4040. if(appDelegate.offline_mode)
  4041. {
  4042. return [OLDataProvider offline_notimpl];
  4043. } else {
  4044. if(![self IsNetworkAvailable])
  4045. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4046. json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  4047. }
  4048. if(json==nil)
  4049. return nil;
  4050. NSError *error=nil;
  4051. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4052. return jsobj;
  4053. #else
  4054. return nil;
  4055. #endif
  4056. }
  4057. #pragma mark 2020 new interface
  4058. // 新接口逐步替换以前的网络请求,2020
  4059. +(void)request_home:(int) price_template customid:(int) customid completionHandler:(resultHandler)result
  4060. {
  4061. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4062. AppDelegate *appDelegate = nil;
  4063. //some UI methods ej
  4064. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4065. if(appDelegate.user!=nil)
  4066. [params setValue:appDelegate.user forKey:@"user"];
  4067. if(appDelegate.contact_id!=nil)
  4068. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4069. if(appDelegate.password!=nil)
  4070. [params setValue:appDelegate.password forKey:@"password"];
  4071. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4072. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4073. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  4074. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4075. if(appDelegate.offline_mode)
  4076. {
  4077. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4078. NSMutableDictionary* json = [[OLDataProvider offline_home] mutableCopy];
  4079. dispatch_async(dispatch_get_main_queue(), ^{
  4080. result(json);
  4081. });
  4082. });
  4083. return;
  4084. }
  4085. [self request_interface:URL_LOAD_HOME parameters:params err_record_url:nil completionHandler:result retry:0];
  4086. return;
  4087. }
  4088. +(void)request_category:(resultHandler)result
  4089. {
  4090. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  4091. AppDelegate *appDelegate = nil;
  4092. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4093. if(appDelegate.offline_mode)
  4094. {
  4095. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4096. NSMutableDictionary* json = [[OLDataProvider offline_category_menu] mutableCopy];
  4097. dispatch_async(dispatch_get_main_queue(), ^{
  4098. result(json);
  4099. });
  4100. });
  4101. return;
  4102. }
  4103. [self request_interface:URL_REQUEST_CATMENU parameters:[NSMutableDictionary new] err_record_url:nil completionHandler:result retry:0];
  4104. //
  4105. // if(![self IsNetworkAvailable])
  4106. // {
  4107. // DebugLog(@"NET ERR");
  4108. //
  4109. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4110. // // return nil;
  4111. // }
  4112. //
  4113. // NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  4114. // //if(json==nil)
  4115. //
  4116. //
  4117. // if(json==nil)
  4118. // return nil;
  4119. // NSError *error=nil;
  4120. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4121. // return jsobj;
  4122. }
  4123. +(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
  4124. {
  4125. AppDelegate *appDelegate = nil;
  4126. //some UI methods ej
  4127. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4128. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4129. if(appDelegate.user!=nil)
  4130. [params setValue:appDelegate.user forKey:@"user"];
  4131. if(appDelegate.contact_id!=nil)
  4132. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4133. if(appDelegate.password!=nil)
  4134. [params setValue:appDelegate.password forKey:@"password"];
  4135. if(appDelegate.order_code!=nil)
  4136. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4137. [params setValue:alert forKey:@"alert"];
  4138. [params setValue:qty forKey:@"sold_by_qty"];
  4139. [params setValue:available forKey:@"available"];
  4140. [params setValue:price forKey:@"price"];
  4141. [params setValue:bestseller forKey:@"bestseller"];
  4142. [params setValue:modelname forKey:@"modelName"];
  4143. [params setValue:modeldescrip forKey:@"modelDescription"];
  4144. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4145. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4146. [params setValue:category forKey:@"category"];
  4147. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4148. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4149. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4150. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4151. [params setValue:filter forKey:@"filter"];
  4152. [params setValue:keyword forKey:@"keyword"];
  4153. [params setObject:ScreenCodeCategory forKey:kScreenName];
  4154. if (alert) {
  4155. [params setObject:@"Filter" forKey:kAction];
  4156. }
  4157. if ([RASingleton sharedInstance].homeItemClick) {
  4158. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  4159. [RASingleton sharedInstance].homeItemClick = NO;
  4160. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  4161. [RASingleton sharedInstance].homeClickedItemName = nil;
  4162. [params setObject:extra forKey:kExtra];
  4163. }
  4164. if(appDelegate.offline_mode)
  4165. {
  4166. // [OLDataProvider offline_category:params completionHandler:result];
  4167. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4168. NSMutableDictionary* json = [[OLDataProvider offline_category:params] mutableCopy];
  4169. dispatch_async(dispatch_get_main_queue(), ^{
  4170. result(json);
  4171. });
  4172. });
  4173. return;
  4174. }
  4175. [self request_interface:URL_CATEGORY parameters:params err_record_url:nil completionHandler:result retry:0];
  4176. return ;
  4177. //
  4178. // if(![self IsNetworkAvailable])
  4179. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4180. //
  4181. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  4182. // if(json==nil)
  4183. // return nil;
  4184. // NSError *error=nil;
  4185. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4186. // return jsobj;
  4187. //
  4188. }
  4189. +(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
  4190. {
  4191. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4192. AppDelegate *appDelegate = nil;
  4193. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4194. if(appDelegate.user!=nil)
  4195. [params setValue:appDelegate.user forKey:@"user"];
  4196. if(appDelegate.contact_id!=nil)
  4197. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4198. if(appDelegate.password!=nil)
  4199. [params setValue:appDelegate.password forKey:@"password"];
  4200. if(appDelegate.order_code!=nil)
  4201. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4202. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4203. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4204. if(use_name)
  4205. [params setValue:model_name forKey:@"product_name"];
  4206. else
  4207. if(use_upc){
  4208. params[@"search_upc"]=@true;
  4209. [params setValue:upc_code forKey:@"upc_code"];
  4210. }
  4211. else
  4212. [params setValue:item_id forKey:@"product_id"];
  4213. [params setValue:category_id forKey:@"category"];
  4214. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4215. [params setObject:@"Open A Model" forKey:kAction];
  4216. if (model_name) {
  4217. NSDictionary *extra = @{@"ModelName" : model_name};
  4218. [params setObject:extra forKey:kExtra];
  4219. }
  4220. if (groupName.length > 0) {
  4221. [params setObject:groupName forKey:@"groupName"];
  4222. }
  4223. if(appDelegate.offline_mode)
  4224. {
  4225. [OLDataProvider offline_model:params completionHandler:result];
  4226. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4227. // NSMutableDictionary* json = [[OLDataProvider offline_model:params] mutableCopy];
  4228. // dispatch_async(dispatch_get_main_queue(), ^{
  4229. // result(json);
  4230. // });
  4231. // });
  4232. return;
  4233. }
  4234. [self request_interface:URL_ITEM_DETAIL parameters:params err_record_url:nil completionHandler:result retry:0];
  4235. //
  4236. // if(appDelegate.offline_mode)
  4237. // return [OLDataProvider offline_model:params];
  4238. //
  4239. // if(![self IsNetworkAvailable])
  4240. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4241. //
  4242. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  4243. // if(json==nil)
  4244. // return nil;
  4245. // NSError *error=nil;
  4246. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4247. // return jsobj;
  4248. }
  4249. +(void)request_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull completionHandler:(resultHandler)result
  4250. {
  4251. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4252. AppDelegate *appDelegate = nil;
  4253. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4254. if(appDelegate.user!=nil)
  4255. [params setValue:appDelegate.user forKey:@"user"];
  4256. if(appDelegate.contact_id!=nil)
  4257. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4258. if(appDelegate.password!=nil)
  4259. [params setValue:appDelegate.password forKey:@"password"];
  4260. if(appDelegate.order_code!=nil)
  4261. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4262. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4263. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4264. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  4265. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4266. // [params setValue:filter forKey:@"filter"];
  4267. [params setValue:keywords forKey:@"keyword"];
  4268. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4269. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4270. if(matchfull)
  4271. [params setValue:@"true" forKey:@"exactMatch"];
  4272. else
  4273. [params setValue:@"false" forKey:@"exactMatch"];
  4274. [params setObject:ScreenCodeSearch forKey:kScreenName];
  4275. if (keywords) {
  4276. [params setObject:@"Search" forKey:kAction];
  4277. }
  4278. if(appDelegate.offline_mode)
  4279. {
  4280. // [OLDataProvider offline_search:params completionHandler:result];
  4281. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4282. NSMutableDictionary* json = [[OLDataProvider offline_search:params] mutableCopy];
  4283. dispatch_async(dispatch_get_main_queue(), ^{
  4284. result(json);
  4285. });
  4286. });
  4287. return;
  4288. }
  4289. [self request_interface:URL_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  4290. // if(appDelegate.offline_mode)
  4291. // {
  4292. // return [OLDataProvider offline_search:params];
  4293. // }
  4294. // if(![self IsNetworkAvailable])
  4295. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4296. //
  4297. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  4298. // if(json==nil)
  4299. // return nil;
  4300. // NSError *error=nil;
  4301. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4302. // return jsobj;
  4303. }
  4304. +(void)request_login: (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
  4305. {
  4306. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  4307. // return RESULT_NET_ERROR;
  4308. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4309. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4310. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4311. AppDelegate *appDelegate = nil;
  4312. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4313. if(RASingleton.sharedInstance.duid !=nil)
  4314. [params setValue:RASingleton.sharedInstance.duid forKey:@"udid"];
  4315. [params setValue:@"handset_login" forKey:@"action"];
  4316. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  4317. [params setValue:user forKey:@"user"];
  4318. [params setValue:password forKey:@"password"];
  4319. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  4320. #ifdef TEST
  4321. [params setValue:@"true" forKey:@"is_debug"];
  4322. #else
  4323. [params setValue:@"false" forKey:@"is_debug"];
  4324. #endif
  4325. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  4326. [params setObject:@"Login" forKey:kAction];
  4327. if(appDelegate.offline_mode)
  4328. {
  4329. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4330. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_login:params]] mutableCopy];
  4331. dispatch_async(dispatch_get_main_queue(), ^{
  4332. int ret = [self parse_logininfo:json user:user password:password] ;
  4333. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4334. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4335. result(retjson);
  4336. });
  4337. });
  4338. return;
  4339. }
  4340. NSString* url;
  4341. bool scan_guest = false;
  4342. #ifdef SCANNER_ORDER
  4343. params[@"site_name"]=[RADataProvider getSiteName];
  4344. params[@"_method"]=@"login";
  4345. url = [appDelegate.address stringByAppendingPathComponent:URL_UPDATE_AUTH];
  4346. if([user.uppercaseString isEqualToString:@"GUEST"]&&[password.uppercaseString isEqualToString:@"GUEST"])
  4347. scan_guest = true;
  4348. #else
  4349. url = URL_UPDATE_AUTH;
  4350. #endif
  4351. if(scan_guest)
  4352. {
  4353. [OLDataProvider realguestLogin];
  4354. // int ret = [self parse_logininfo:chresult user:user password:password] ;
  4355. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4356. retjson[@"result"]= [NSNumber numberWithInt:RESULT_TRUE];
  4357. result(retjson);
  4358. }
  4359. else
  4360. {
  4361. [self request_interface:url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *chresult) {
  4362. int ret = [self parse_logininfo:chresult user:user password:password] ;
  4363. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4364. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4365. result(retjson);
  4366. } retry:0];
  4367. }
  4368. //
  4369. // NSData* json= nil;
  4370. // if(appDelegate.offline_mode)
  4371. // {
  4372. // json= [OLDataProvider offline_login:params] ;
  4373. //
  4374. // }
  4375. // else
  4376. // {
  4377. // if(![self IsNetworkAvailable])
  4378. // return RESULT_NET_NOTAVAILABLE;
  4379. // json =[self get_json:URL_UPDATE_AUTH parameters:params];
  4380. //
  4381. // }
  4382. //
  4383. // if(json==nil)
  4384. // return RESULT_NET_ERROR;
  4385. //
  4386. // int ret = [self parse_authinfo:json user:user password:password];
  4387. // DebugLog(@"parse_authinfo return %d ",ret);
  4388. //
  4389. //
  4390. // return ret;
  4391. //
  4392. }
  4393. +(int)parse_logininfo : (NSMutableDictionary *) jsobj user:(NSString*) user password:(NSString*) password
  4394. {
  4395. // DebugLog(@"parse_authinfo");
  4396. // NSError *error=nil;
  4397. //
  4398. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4399. if(jsobj)
  4400. {
  4401. AppDelegate *appDelegate = nil;
  4402. //some UI methods ej
  4403. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4404. int result = [[jsobj valueForKey:@"result"] intValue];
  4405. if (result<0)
  4406. return result;
  4407. if(result!=AP_USER_AUTH&& result!=9)
  4408. {
  4409. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  4410. // [appDelegate Logout];
  4411. if(result==8)
  4412. {
  4413. return RESULT_LOGIN_DEVICE;
  4414. }
  4415. return RESULT_FALSE;
  4416. }
  4417. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  4418. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  4419. user=[objheader objectForKey:@"username"] ;
  4420. DebugLog(@"required_ver=%@ ",required_ver);
  4421. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  4422. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  4423. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  4424. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  4425. // if([ibadge isEqual:[NSNull null]])
  4426. // strbadge=@"0";
  4427. // if(ibadge==nil)
  4428. // ibadge=@"0";
  4429. // if([strbadge isEqualToString:@"null"])
  4430. // strbadge=@"0";
  4431. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  4432. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  4433. #ifndef SCANNER_ORDER
  4434. if([appDelegate.build intValue]<[required_ver intValue])
  4435. return RESULT_VER_LOW;
  4436. #endif
  4437. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  4438. appDelegate.user = user;
  4439. appDelegate.password = password;
  4440. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  4441. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  4442. appDelegate.bLogin = true;
  4443. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  4444. #ifdef SCANNER_ORDER
  4445. appDelegate.available_price_group = objheader[@"price_group"];
  4446. [RADataProvider default_price_group];
  4447. #endif
  4448. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  4449. {
  4450. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  4451. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  4452. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  4453. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  4454. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  4455. }
  4456. NSString* mode =[jsobj valueForKey:@"mode"] ;
  4457. [appDelegate SetMode:mode];
  4458. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  4459. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  4460. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  4461. [appDelegate update_count_mark];
  4462. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  4463. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  4464. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  4465. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  4466. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  4467. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  4468. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  4469. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  4470. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  4471. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  4472. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  4473. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  4474. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  4475. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  4476. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  4477. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  4478. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  4479. [appDelegate set_main_button_panel];
  4480. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  4481. // shop order status filter
  4482. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  4483. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  4484. // Sales order status filter
  4485. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  4486. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  4487. // specialInstruction
  4488. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  4489. //-价格类型
  4490. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  4491. // 权限
  4492. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  4493. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  4494. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  4495. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  4496. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  4497. [[RASingleton sharedInstance] resetGlobalLock];
  4498. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  4499. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  4500. }
  4501. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  4502. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  4503. // {
  4504. // // no update on the server;
  4505. // return RESULT_TRUE;
  4506. // }
  4507. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  4508. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4509. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4510. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4511. // [defaults synchronize];
  4512. //
  4513. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  4514. // NSArray* keys= [objfuncs allKeys];
  4515. /*
  4516. db.setTransactionSuccessful();
  4517. db.endTransaction();
  4518. */
  4519. return RESULT_TRUE;
  4520. }
  4521. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  4522. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  4523. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  4524. return RESULT_USERAUTH_ERROR;
  4525. }
  4526. +(void)request_contactlist:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams completionHandler:(resultHandler)result
  4527. {
  4528. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4529. if(upparams!=nil)
  4530. params = [upparams mutableCopy];
  4531. AppDelegate *appDelegate = nil;
  4532. //some UI methods ej
  4533. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4534. if(appDelegate.user!=nil)
  4535. [params setValue:appDelegate.user forKey:@"user"];
  4536. if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  4537. [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  4538. else
  4539. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4540. if(appDelegate.password!=nil)
  4541. [params setValue:appDelegate.password forKey:@"password"];
  4542. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  4543. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  4544. [params setValue:contact_type forKey:@"contactType"];
  4545. [params setValue:keywords forKey:@"keyword"];
  4546. [params setObject:ScreenCodeAccount forKey:kScreenName];
  4547. if (keywords) {
  4548. [params setObject:@"Search" forKey:kAction];
  4549. }
  4550. if (upparams) {
  4551. [params setObject:@"Advance Search" forKey:kAction];
  4552. }
  4553. NSString* url=nil;
  4554. if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  4555. url=URL_SHIPTO_LIST;
  4556. else
  4557. url=URL_CONTACT_LIST;
  4558. if(appDelegate.offline_mode)
  4559. {
  4560. [OLDataProvider offline_contactlist:params completionHandler:result];
  4561. return;
  4562. }
  4563. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  4564. //
  4565. // if(appDelegate.offline_mode)
  4566. // return [OLDataProvider offline_contactlist:params];
  4567. //
  4568. // if(![self IsNetworkAvailable])
  4569. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4570. //
  4571. // NSData* json=[self get_json:url parameters:params];
  4572. // if(json==nil)
  4573. // return nil;
  4574. // NSError *error=nil;
  4575. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4576. // return jsobj;
  4577. }
  4578. +(void)request_contactinfo:(NSString* ) contactid completionHandler:(resultHandler)result
  4579. {
  4580. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4581. AppDelegate *appDelegate = nil;
  4582. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4583. if(appDelegate.user!=nil)
  4584. [params setValue:appDelegate.user forKey:@"user"];
  4585. // if(appDelegate.contact_id!=nil)
  4586. if(appDelegate.password!=nil)
  4587. [params setValue:appDelegate.password forKey:@"password"];
  4588. [params setValue:contactid forKey:@"contactId"];
  4589. [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  4590. if(appDelegate.offline_mode)
  4591. {
  4592. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4593. // [OLDataProvider offline_contactinfo:params completionHandler:result] ;
  4594. // });
  4595. params[@"mode"]=appDelegate.mode;
  4596. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4597. NSMutableDictionary* json = [[OLDataProvider offline_contactinfo:params] mutableCopy];
  4598. dispatch_async(dispatch_get_main_queue(), ^{
  4599. result(json);
  4600. });
  4601. });
  4602. return;
  4603. }
  4604. [self request_interface:URL_CUSTOMER_INFO parameters:params err_record_url:nil completionHandler:result retry:0];
  4605. // if(appDelegate.offline_mode)
  4606. // return [OLDataProvider offline_contactinfo:params];
  4607. // if(![self IsNetworkAvailable])
  4608. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4609. //
  4610. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  4611. // if(json==nil)
  4612. // return nil;
  4613. // NSError *error=nil;
  4614. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4615. // return jsobj;
  4616. //
  4617. }
  4618. +(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  4619. {
  4620. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4621. AppDelegate *appDelegate = nil;
  4622. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4623. if(appDelegate.user!=nil)
  4624. [params setValue:appDelegate.user forKey:@"user"];
  4625. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  4626. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  4627. // else
  4628. if(appDelegate.contact_id!=nil)
  4629. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4630. if(appDelegate.password!=nil)
  4631. [params setValue:appDelegate.password forKey:@"password"];
  4632. if(appDelegate.order_code!=nil)
  4633. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4634. bool can_create_backorder=appDelegate.can_create_backorder;
  4635. // [params setValue:sourceid forKey:@"sourceid"];
  4636. // [params setValue:editor forKey:@"editor"];
  4637. DebugLog(@"request editor url:%@",request_url);
  4638. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  4639. {
  4640. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  4641. }
  4642. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  4643. {
  4644. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  4645. }
  4646. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  4647. {
  4648. [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  4649. }
  4650. else if([request_url isEqualToString:URL_CARTDELIVERY])
  4651. {
  4652. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  4653. }
  4654. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  4655. {
  4656. [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  4657. }
  4658. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  4659. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  4660. }
  4661. if(appDelegate.offline_mode)
  4662. {
  4663. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4664. NSData* json = nil;
  4665. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  4666. {
  4667. json= [OLDataProvider offline_createContact:params];
  4668. }
  4669. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  4670. {
  4671. json= [OLDataProvider offline_editContact:params];
  4672. }
  4673. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  4674. {
  4675. json= [OLDataProvider offline_contactAdvancedSearch:params];
  4676. }
  4677. else if([request_url isEqualToString:URL_CARTDELIVERY])
  4678. {
  4679. params[@"contact_id"]=params[@"contactId"];
  4680. params[@"can_create_backorder"]=@(can_create_backorder);
  4681. json= [OLDataProvider offline_placeorder:params];
  4682. }
  4683. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  4684. {
  4685. json= [OLDataProvider offline_addreditor:params];
  4686. }
  4687. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  4688. json = [OLDataProvider offline_createTearSheet:params];
  4689. }
  4690. dispatch_async(dispatch_get_main_queue(), ^{
  4691. if(json==nil)
  4692. result( [[OLDataProvider offline_notimpl] mutableCopy]);
  4693. else
  4694. result([[RAConvertor data2dict:json] mutableCopy]);
  4695. });
  4696. });
  4697. return;
  4698. }
  4699. else
  4700. {
  4701. if([request_url isEqualToString:URL_CARTDELIVERY])
  4702. {
  4703. NSString * uuid= [[NSUUID UUID] UUIDString];
  4704. params[@"resultSerial"]=uuid;
  4705. __block bool bbreak = false;
  4706. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4707. for(int i=0;i<150;i++)
  4708. {
  4709. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  4710. // result_params[@"resultSerial"]=uuid;
  4711. //json=[self get_json:request_url parameters:params];
  4712. if(bbreak)
  4713. break;
  4714. dispatch_async(dispatch_get_main_queue(), ^{
  4715. DebugLog(@"request cart delivery %d",i);
  4716. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  4717. if(resulti!=nil)
  4718. {
  4719. if([resulti[@"result"] intValue]==2 || [resulti[@"result"] intValue] == 8)
  4720. {
  4721. if(!bbreak) //此判断保证result只调用一次。
  4722. {
  4723. result(resulti);
  4724. DebugLog(@"result called at %d",i);
  4725. }
  4726. bbreak=true;
  4727. }
  4728. }
  4729. } retry:3];
  4730. });
  4731. // [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  4732. sleep(2);
  4733. }
  4734. });
  4735. }
  4736. else
  4737. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  4738. }
  4739. // if(json!=nil)
  4740. // {
  4741. // NSError *error=nil;
  4742. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4743. // return jsobj;
  4744. // }
  4745. // else
  4746. // return nil;
  4747. }
  4748. +(void)request_wishlist:(int)sort completionHandler:(resultHandler)result
  4749. {
  4750. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4751. AppDelegate *appDelegate = nil;
  4752. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4753. if(appDelegate.user!=nil)
  4754. [params setValue:appDelegate.user forKey:@"user"];
  4755. if(appDelegate.contact_id!=nil)
  4756. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4757. if(appDelegate.password!=nil)
  4758. [params setValue:appDelegate.password forKey:@"password"];
  4759. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  4760. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  4761. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  4762. [params setObject:ScreenCodeWishList forKey:kScreenName];
  4763. if(appDelegate.offline_mode)
  4764. {
  4765. [OLDataProvider offline_wishlist:params completionHandler:^(NSMutableDictionary *resulti) {
  4766. int result_code = [[resulti valueForKey:@"result"] intValue];
  4767. if (result_code==2)
  4768. {
  4769. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  4770. [appDelegate update_count_mark];;
  4771. result(resulti);
  4772. }
  4773. }];
  4774. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4775. // NSMutableDictionary* json = [[OLDataProvider offline_wishlist:params] mutableCopy];
  4776. // dispatch_async(dispatch_get_main_queue(), ^{
  4777. // result(json);
  4778. // });
  4779. // });
  4780. return;
  4781. }
  4782. [self request_interface:URL_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  4783. int result_code = [[resulti valueForKey:@"result"] intValue];
  4784. if (result_code==2)
  4785. {
  4786. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  4787. [appDelegate update_count_mark];;
  4788. result(resulti);
  4789. }
  4790. } retry:0];
  4791. // if(appDelegate.offline_mode)
  4792. // {
  4793. // return [OLDataProvider offline_wishlist:params];
  4794. // }
  4795. // if(![self IsNetworkAvailable])
  4796. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4797. //
  4798. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  4799. // if(json==nil)
  4800. // return nil;
  4801. // NSError *error=nil;
  4802. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4803. // int result = [[jsobj valueForKey:@"result"] intValue];
  4804. //
  4805. // if (result==2)
  4806. // {
  4807. //
  4808. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  4809. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  4810. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  4811. //
  4812. // [appDelegate update_count_mark];
  4813. // }
  4814. // return jsobj;
  4815. }
  4816. +(void)request_portfoliolist:(int)sort completionHandler:(resultHandler)result
  4817. {
  4818. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4819. AppDelegate *appDelegate = nil;
  4820. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4821. if(appDelegate.user!=nil)
  4822. [params setValue:appDelegate.user forKey:@"user"];
  4823. if(appDelegate.contact_id!=nil)
  4824. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4825. if(appDelegate.password!=nil)
  4826. [params setValue:appDelegate.password forKey:@"password"];
  4827. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  4828. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  4829. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  4830. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  4831. if(appDelegate.offline_mode)
  4832. {
  4833. params[@"user"]=appDelegate.user;
  4834. params[@"contact_id"]=appDelegate.contact_id;
  4835. params[@"can_see_price"]=@(appDelegate.can_see_price);
  4836. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4837. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_portfolioList:params]] mutableCopy];
  4838. dispatch_async(dispatch_get_main_queue(), ^{
  4839. if ([json[@"result"] intValue]==2)
  4840. {
  4841. appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  4842. [appDelegate update_count_mark];
  4843. }
  4844. result(json);
  4845. });
  4846. });
  4847. return;
  4848. }
  4849. [self request_interface:URL_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  4850. if ([resulti[@"result"] intValue]==2)
  4851. {
  4852. appDelegate.port_count =[[resulti valueForKey:@"count"] intValue];
  4853. [appDelegate update_count_mark];
  4854. }
  4855. result(resulti);
  4856. } retry:0];
  4857. // NSData* json = nil;
  4858. // if(appDelegate.offline_mode)
  4859. // {
  4860. // json = [OLDataProvider offline_portfolioList:params];
  4861. // } else {
  4862. // if(![self IsNetworkAvailable])
  4863. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4864. //
  4865. // json = [self get_json:URL_PORTFOLIO parameters:params];
  4866. // }
  4867. //
  4868. //
  4869. // if(json==nil)
  4870. // return nil;
  4871. // NSError *error=nil;
  4872. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4873. // int result = [[jsobj valueForKey:@"result"] intValue];
  4874. //
  4875. // if (result==2)
  4876. // {
  4877. //
  4878. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  4879. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  4880. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  4881. //
  4882. // [appDelegate update_count_mark];
  4883. // }
  4884. // return jsobj;
  4885. }
  4886. +(void)request_portfoliopdf:(int ) offset limit:(int)limit keywords:(NSString* ) keywords completionHandler:(resultHandler)result
  4887. {
  4888. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4889. AppDelegate *appDelegate = nil;
  4890. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4891. if(appDelegate.user!=nil)
  4892. [params setValue:appDelegate.user forKey:@"user"];
  4893. if(appDelegate.contact_id!=nil)
  4894. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4895. if(appDelegate.password!=nil)
  4896. [params setValue:appDelegate.password forKey:@"password"];
  4897. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4898. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4899. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  4900. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4901. // [params setValue:filter forKey:@"filter"];
  4902. [params setValue:keywords forKey:@"keyWord"];
  4903. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  4904. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  4905. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  4906. if (keywords) {
  4907. [params setObject:@"Search" forKey:kAction];
  4908. }
  4909. if(appDelegate.offline_mode)
  4910. {
  4911. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4912. NSData* json = [[OLDataProvider offline_pdfList:params] mutableCopy];
  4913. dispatch_async(dispatch_get_main_queue(), ^{
  4914. result([[RAConvertor data2dict:json] mutableCopy]);
  4915. });
  4916. });
  4917. return;
  4918. }
  4919. [self request_interface:URL_DM_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  4920. return;
  4921. // NSData* json = nil;
  4922. // if(appDelegate.offline_mode)
  4923. // {
  4924. // json = [OLDataProvider offline_pdfList:params];
  4925. // } else {
  4926. // if(![self IsNetworkAvailable])
  4927. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4928. //
  4929. // json=[self get_json:URL_DM_LIST parameters:params];
  4930. // }
  4931. // if(json==nil)
  4932. // return nil;
  4933. // NSError *error=nil;
  4934. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4935. // return jsobj;
  4936. }
  4937. +(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
  4938. {
  4939. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4940. AppDelegate *appDelegate = nil;
  4941. //some UI methods ej
  4942. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4943. if(appDelegate.user!=nil)
  4944. [params setValue:appDelegate.user forKey:@"user"];
  4945. if(appDelegate.contact_id!=nil)
  4946. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4947. if(appDelegate.password!=nil)
  4948. [params setValue:appDelegate.password forKey:@"password"];
  4949. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  4950. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  4951. [params setValue:keywords forKey:@"keyWord"];
  4952. [params setValue:customer forKey:@"customer_filter"];
  4953. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  4954. [params setValue:status_code forKey:@"orderStatus"];
  4955. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  4956. if (keywords) {
  4957. [params setObject:@"Search" forKey:kAction];
  4958. }
  4959. if(appDelegate.offline_mode)
  4960. {
  4961. params[@"user"]=appDelegate.user;
  4962. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4963. NSData* json = [[OLDataProvider offline_orderlist:params] mutableCopy];
  4964. dispatch_async(dispatch_get_main_queue(), ^{
  4965. result([[RAConvertor data2dict:json] mutableCopy]);
  4966. });
  4967. });
  4968. return;
  4969. }
  4970. [self request_interface:URL_ORDER_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  4971. // NSData* json=nil;
  4972. // if(appDelegate.offline_mode)
  4973. // {
  4974. // json= [OLDataProvider offline_orderlist:params];
  4975. // }
  4976. // else
  4977. // {
  4978. // if(![self IsNetworkAvailable])
  4979. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4980. //
  4981. // json=[self get_json:URL_ORDER_LIST parameters:params];
  4982. // }
  4983. // if(json==nil)
  4984. // return nil;
  4985. // NSError *error=nil;
  4986. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4987. // return jsobj;
  4988. }
  4989. +(void)request_logout:(resultHandler)result
  4990. {
  4991. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4992. AppDelegate *appDelegate = nil;
  4993. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4994. if(appDelegate.user!=nil)
  4995. [params setValue:appDelegate.user forKey:@"user"];
  4996. if(appDelegate.password!=nil)
  4997. [params setValue:appDelegate.password forKey:@"password"];
  4998. if(appDelegate.offline_mode)
  4999. {
  5000. [OLDataProvider offline_logout:params completionHandler:result];
  5001. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5002. // NSMutableDictionary* json = [[OLDataProvider offline_logout:params] mutableCopy];
  5003. // dispatch_async(dispatch_get_main_queue(), ^{
  5004. // result(json);
  5005. // });
  5006. // });
  5007. return;
  5008. }
  5009. [self request_interface:URL_LOGOUT parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5010. NSMutableDictionary* jsobj=resulti;
  5011. int result_code = [[jsobj valueForKey:@"result"] intValue];
  5012. if (result_code==2)
  5013. {
  5014. appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  5015. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5016. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5017. [appDelegate update_count_mark];
  5018. appDelegate.can_show_price =false;
  5019. appDelegate.can_see_price =false;
  5020. appDelegate.can_create_portfolio =false;
  5021. appDelegate.can_create_order =false;
  5022. appDelegate.can_cancel_order =false;
  5023. appDelegate.can_set_cart_price =false;
  5024. appDelegate.can_delete_order =false;
  5025. appDelegate.can_submit_order =false;
  5026. appDelegate.can_set_tearsheet_price =false;
  5027. appDelegate.can_update_contact_info = false;
  5028. appDelegate.save_order_logout = false;
  5029. appDelegate.submit_order_logout = false;
  5030. appDelegate.alert_sold_in_quantities = false;
  5031. appDelegate.ipad_perm =nil ;
  5032. appDelegate.user_type = USER_ROLE_UNKNOWN;
  5033. appDelegate.OrderFilter= nil;
  5034. [appDelegate SetSo:nil];
  5035. [appDelegate set_main_button_panel];
  5036. #ifdef RA_NOTIFICATION
  5037. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5038. #endif
  5039. }
  5040. result(resulti);
  5041. } retry:0];
  5042. //
  5043. // if(appDelegate.offline_mode)
  5044. // {
  5045. // return [OLDataProvider offline_logout:params];
  5046. // }
  5047. // if(![self IsNetworkAvailable])
  5048. // {
  5049. // DebugLog(@"NET ERR");
  5050. //
  5051. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5052. // // return nil;
  5053. // }
  5054. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  5055. // //if(json==nil)
  5056. //
  5057. //
  5058. // if(json==nil)
  5059. // return nil;
  5060. // NSError *error=nil;
  5061. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5062. // int result = [[jsobj valueForKey:@"result"] intValue];
  5063. //
  5064. // if (result==2)
  5065. // {
  5066. //
  5067. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  5068. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5069. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5070. //
  5071. // [appDelegate update_count_mark];
  5072. //
  5073. //
  5074. // appDelegate.can_show_price =false;
  5075. // appDelegate.can_see_price =false;
  5076. // appDelegate.can_create_portfolio =false;
  5077. // appDelegate.can_create_order =false;
  5078. //
  5079. //
  5080. // appDelegate.can_cancel_order =false;
  5081. // appDelegate.can_set_cart_price =false;
  5082. // appDelegate.can_delete_order =false;
  5083. // appDelegate.can_submit_order =false;
  5084. // appDelegate.can_set_tearsheet_price =false;
  5085. // appDelegate.can_update_contact_info = false;
  5086. //
  5087. // appDelegate.save_order_logout = false;
  5088. // appDelegate.submit_order_logout = false;
  5089. // appDelegate.alert_sold_in_quantities = false;
  5090. //
  5091. // appDelegate.ipad_perm =nil ;
  5092. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  5093. // appDelegate.OrderFilter= nil;
  5094. // [appDelegate SetSo:nil];
  5095. // [appDelegate set_main_button_panel];
  5096. //#ifdef RA_NOTIFICATION
  5097. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5098. //#endif
  5099. // }
  5100. // return jsobj;
  5101. }
  5102. + (void)request_hangtag:(NSString *)group completionHandler:(resultHandler)result
  5103. {
  5104. #ifdef BUILD_UWAVER
  5105. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5106. AppDelegate *appDelegate = nil;
  5107. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5108. if(appDelegate.user!=nil)
  5109. [params setValue:appDelegate.user forKey:@"user"];
  5110. if(appDelegate.contact_id!=nil)
  5111. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5112. if(appDelegate.password!=nil)
  5113. [params setValue:appDelegate.password forKey:@"password"];
  5114. if (group) {
  5115. [params setValue:group forKey:@"groupName"];
  5116. }
  5117. NSString * uuid= [[NSUUID UUID] UUIDString];
  5118. params[@"resultSerial"]=uuid;
  5119. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  5120. if(appDelegate.offline_mode)
  5121. {
  5122. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5123. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5124. dispatch_async(dispatch_get_main_queue(), ^{
  5125. result(json);
  5126. });
  5127. });
  5128. return;
  5129. }
  5130. [self request_interface:URL_CREATE_HANG_TAG parameters:params err_record_url:nil completionHandler:result retry:0];
  5131. // NSData* json = nil;
  5132. // if(appDelegate.offline_mode)
  5133. // {
  5134. // json = [OLDataProvider offline_portfolioList:params];
  5135. // } else {
  5136. // if(![self IsNetworkAvailable])
  5137. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5138. //
  5139. // json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  5140. // }
  5141. //
  5142. //
  5143. // if(json==nil)
  5144. // return nil;
  5145. // NSError *error=nil;
  5146. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5147. //
  5148. // return jsobj;
  5149. #else
  5150. return result(nil);
  5151. #endif
  5152. }
  5153. + (void)request_movetobackorder:(NSString *)cart_item_id completionHandler:(resultHandler)result
  5154. {
  5155. if (cart_item_id == nil || cart_item_id.length < 1) {
  5156. result([@{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"} mutableCopy]);
  5157. }
  5158. AppDelegate *appDelegate = nil;
  5159. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5160. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5161. if(appDelegate.user!=nil)
  5162. [dic setValue:appDelegate.user forKey:@"user"];
  5163. if(appDelegate.password!=nil)
  5164. [dic setValue:appDelegate.password forKey:@"password"];
  5165. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  5166. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  5167. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5168. if(appDelegate.offline_mode)
  5169. {
  5170. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5171. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5172. dispatch_async(dispatch_get_main_queue(), ^{
  5173. result(json);
  5174. });
  5175. });
  5176. return;
  5177. }
  5178. [self request_interface:URL_MOVE_TO_BACK_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5179. // if(![self IsNetworkAvailable])
  5180. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5181. //
  5182. // NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  5183. //
  5184. // if(json!=nil)
  5185. // {
  5186. // NSError *error=nil;
  5187. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5188. //
  5189. // return jsobj;
  5190. // }
  5191. //
  5192. // return @{@"result" : @(RESULT_FALSE)};
  5193. }
  5194. + (void)request_emailwishlist:(NSString *)addr completionHandler:(resultHandler)result
  5195. {
  5196. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5197. AppDelegate *appDelegate = nil;
  5198. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5199. if(appDelegate.user!=nil)
  5200. [dic setValue:appDelegate.user forKey:@"user"];
  5201. if(appDelegate.password!=nil)
  5202. [dic setValue:appDelegate.password forKey:@"password"];
  5203. [dic setValue:addr forKey:@"email"];
  5204. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  5205. // if (appDelegate.customerInfo) {
  5206. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5207. // if (customer_cid) {
  5208. // [dic setValue:customer_cid forKey:@"contactId"];
  5209. // }
  5210. // }
  5211. if(appDelegate.offline_mode)
  5212. {
  5213. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5214. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5215. dispatch_async(dispatch_get_main_queue(), ^{
  5216. result(json);
  5217. });
  5218. });
  5219. return;
  5220. }
  5221. [self request_interface:URL_EMAIL_WISHLIST parameters:dic err_record_url:nil completionHandler:result retry:0];
  5222. // NSData* json=nil;
  5223. // if(appDelegate.offline_mode)
  5224. // {
  5225. // return [OLDataProvider offline_notimpl];
  5226. // }
  5227. // else
  5228. // {
  5229. // if(![self IsNetworkAvailable])
  5230. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5231. //
  5232. // json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  5233. // }
  5234. // if(json!=nil)
  5235. // {
  5236. // NSError *error=nil;
  5237. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5238. //
  5239. //
  5240. // return jsobj;
  5241. // }
  5242. //
  5243. // return @{@"result" : @(RESULT_FALSE)};
  5244. }
  5245. +(void)request_notifymodel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  5246. {
  5247. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5248. AppDelegate *appDelegate = nil;
  5249. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5250. if(appDelegate.user!=nil)
  5251. [dic setValue:appDelegate.user forKey:@"user"];
  5252. if(appDelegate.password!=nil)
  5253. [dic setValue:appDelegate.password forKey:@"password"];
  5254. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5255. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5256. if (customer_cid) {
  5257. [dic setValue:customer_cid forKey:@"contactId"];
  5258. }
  5259. }
  5260. [dic setObject:screenName forKey:kScreenName];
  5261. [dic setValue:modelID forKey:@"productId"];
  5262. if (addr) { // 弹框输入
  5263. [dic setValue:addr forKey:@"email"];
  5264. } else {
  5265. // employee选择了Contact,并且Contact有Email
  5266. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5267. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  5268. // if (email) {
  5269. // [dic setValue:email forKey:@"email"];
  5270. // }
  5271. // }
  5272. }
  5273. if(appDelegate.offline_mode)
  5274. {
  5275. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5276. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5277. dispatch_async(dispatch_get_main_queue(), ^{
  5278. result(json);
  5279. });
  5280. });
  5281. return;
  5282. }
  5283. [self request_interface:URL_NOTIFY_ME parameters:dic err_record_url:nil completionHandler:result retry:0];
  5284. // NSData* json=nil;
  5285. // if(appDelegate.offline_mode)
  5286. // {
  5287. // return [OLDataProvider offline_notimpl];
  5288. // }
  5289. // else
  5290. // {
  5291. // if(![self IsNetworkAvailable])
  5292. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5293. //
  5294. // json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  5295. // }
  5296. // if(json!=nil)
  5297. // {
  5298. // NSError *error=nil;
  5299. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5300. //
  5301. //
  5302. // return jsobj;
  5303. // }
  5304. //
  5305. // return @{@"result" : @(RESULT_FALSE)};
  5306. }
  5307. + (void)request_qouteorder:(NSString *)so_id emailAddr:(NSString *)addr completionHandler:(resultHandler)result
  5308. {
  5309. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5310. AppDelegate *appDelegate = nil;
  5311. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5312. if(appDelegate.user!=nil)
  5313. [dic setValue:appDelegate.user forKey:@"user"];
  5314. if(appDelegate.password!=nil)
  5315. [dic setValue:appDelegate.password forKey:@"password"];
  5316. [dic setValue:so_id forKey:@"orderCode"];
  5317. [dic setValue:addr forKey:@"email"];
  5318. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5319. if (appDelegate.customerInfo) {
  5320. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5321. if (customer_cid) {
  5322. [dic setValue:customer_cid forKey:@"contactId"];
  5323. }
  5324. }
  5325. if(appDelegate.offline_mode)
  5326. {
  5327. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5328. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5329. dispatch_async(dispatch_get_main_queue(), ^{
  5330. result(json);
  5331. });
  5332. });
  5333. return;
  5334. }
  5335. [self request_interface:URL_EMAIL_CART parameters:dic err_record_url:nil completionHandler:result retry:0];
  5336. // NSData* json=nil;
  5337. // if(appDelegate.offline_mode)
  5338. // {
  5339. // return [OLDataProvider offline_notimpl];
  5340. // }
  5341. // else
  5342. // {
  5343. // if(![self IsNetworkAvailable])
  5344. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5345. //
  5346. // json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  5347. // }
  5348. // if(json!=nil)
  5349. // {
  5350. // NSError *error=nil;
  5351. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5352. //
  5353. //
  5354. // return jsobj;
  5355. // }
  5356. //
  5357. // return @{@"result" : @(RESULT_FALSE)};
  5358. }
  5359. + (void)request_mergeorder:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  5360. {
  5361. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5362. AppDelegate *appDelegate = nil;
  5363. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5364. if(appDelegate.user!=nil)
  5365. [dic setValue:appDelegate.user forKey:@"user"];
  5366. if(appDelegate.password!=nil)
  5367. [dic setValue:appDelegate.password forKey:@"password"];
  5368. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  5369. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  5370. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  5371. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  5372. if(appDelegate.offline_mode)
  5373. {
  5374. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5375. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5376. dispatch_async(dispatch_get_main_queue(), ^{
  5377. result(json);
  5378. });
  5379. });
  5380. return;
  5381. }
  5382. [self request_interface:URL_SET_MERGE_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5383. // NSData* json=nil;
  5384. // if(appDelegate.offline_mode)
  5385. // {
  5386. // return [OLDataProvider offline_notimpl];
  5387. // }
  5388. // else
  5389. // {
  5390. // if(![self IsNetworkAvailable])
  5391. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5392. //
  5393. // json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  5394. // }
  5395. // if(json!=nil)
  5396. // {
  5397. // NSError *error=nil;
  5398. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5399. //
  5400. //
  5401. // return jsobj;
  5402. // }
  5403. // else
  5404. // return nil;
  5405. }
  5406. +(void)request_pendingorder:(NSString *)contactid completionHandler:(resultHandler)result
  5407. {
  5408. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5409. AppDelegate *appDelegate = nil;
  5410. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5411. if(appDelegate.user!=nil)
  5412. [params setValue:appDelegate.user forKey:@"user"];
  5413. // if(appDelegate.contact_id!=nil)
  5414. if(appDelegate.password!=nil)
  5415. [params setValue:appDelegate.password forKey:@"password"];
  5416. [params setValue:contactid forKey:@"contactId"];
  5417. if(appDelegate.offline_mode)
  5418. {
  5419. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5420. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5421. dispatch_async(dispatch_get_main_queue(), ^{
  5422. result(json);
  5423. });
  5424. });
  5425. return;
  5426. }
  5427. [self request_interface:URL_CUSTOMER_PENDINGORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  5428. //
  5429. // if(appDelegate.offline_mode)
  5430. // {
  5431. // return [OLDataProvider offline_notimpl];
  5432. // }
  5433. // if(![self IsNetworkAvailable])
  5434. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5435. //
  5436. // NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  5437. // if(json==nil)
  5438. // return nil;
  5439. // NSError *error=nil;
  5440. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5441. // return jsobj;
  5442. //
  5443. }
  5444. +(void) request_removeportfolio:(NSString* ) item_ids completionHandler:(resultHandler)result
  5445. {
  5446. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5447. AppDelegate *appDelegate = nil;
  5448. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5449. if(appDelegate.user!=nil)
  5450. [params setValue:appDelegate.user forKey:@"user"];
  5451. if(appDelegate.contact_id!=nil)
  5452. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5453. if(appDelegate.password!=nil)
  5454. [params setValue:appDelegate.password forKey:@"password"];
  5455. [params setValue:item_ids forKey:@"portfolioId"];
  5456. // [params setValue:editor forKey:@"editor"];
  5457. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  5458. if(appDelegate.offline_mode)
  5459. {
  5460. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5461. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_removePortfolio:params]] mutableCopy];
  5462. dispatch_async(dispatch_get_main_queue(), ^{
  5463. int result_code = [[resulti valueForKey:@"result"] intValue];
  5464. if (result_code==2)
  5465. {
  5466. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5467. [appDelegate update_count_mark];
  5468. };
  5469. result(resulti);
  5470. });
  5471. });
  5472. return;
  5473. }
  5474. [self request_interface:URL_PORTFOLIO_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5475. int result_code = [[resulti valueForKey:@"result"] intValue];
  5476. if (result_code==2)
  5477. {
  5478. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5479. [appDelegate update_count_mark];
  5480. };
  5481. result(resulti);
  5482. } retry:0];
  5483. // NSData* json = nil;
  5484. // if(appDelegate.offline_mode)
  5485. // {
  5486. // json = [OLDataProvider offline_removePortfolio:params];
  5487. // } else {
  5488. // if(![self IsNetworkAvailable])
  5489. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5490. // json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  5491. // }
  5492. // if(json!=nil)
  5493. // {
  5494. // NSError *error=nil;
  5495. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5496. //
  5497. //
  5498. // int result = [[jsobj valueForKey:@"result"] intValue];
  5499. //
  5500. // if (result==2)
  5501. // {
  5502. //
  5503. //
  5504. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5505. //
  5506. // [appDelegate update_count_mark];
  5507. // }
  5508. // return jsobj;
  5509. // }
  5510. // else
  5511. // return nil;
  5512. }
  5513. +(void) request_removeportfoliopdf:(NSString* ) listid completionHandler:(resultHandler)result
  5514. {
  5515. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5516. AppDelegate *appDelegate = nil;
  5517. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5518. if(appDelegate.user!=nil)
  5519. [params setValue:appDelegate.user forKey:@"user"];
  5520. if(appDelegate.contact_id!=nil)
  5521. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5522. if(appDelegate.password!=nil)
  5523. [params setValue:appDelegate.password forKey:@"password"];
  5524. [params setValue:listid forKey:@"tearsheetsId"];
  5525. // [params setValue:editor forKey:@"editor"];
  5526. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  5527. // [params setValue:@"Delete Portfolio" forKey:kAction];
  5528. if(appDelegate.offline_mode)
  5529. {
  5530. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5531. NSData* json = [[OLDataProvider offline_removePDF:params] mutableCopy];
  5532. dispatch_async(dispatch_get_main_queue(), ^{
  5533. result([[RAConvertor data2dict:json] mutableCopy]);
  5534. });
  5535. });
  5536. return;
  5537. }
  5538. [self request_interface:URL_PORTFOLIOLIST_REMOVE parameters:params err_record_url:nil completionHandler:result retry:0];
  5539. }
  5540. +(void) request_remove_wishlist:(NSString* ) item_ids completionHandler:(resultHandler)result
  5541. {
  5542. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5543. __block AppDelegate *appDelegate = nil;
  5544. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5545. if(appDelegate.user!=nil)
  5546. [params setValue:appDelegate.user forKey:@"user"];
  5547. if(appDelegate.contact_id!=nil)
  5548. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5549. if(appDelegate.password!=nil)
  5550. [params setValue:appDelegate.password forKey:@"password"];
  5551. [params setValue:item_ids forKey:@"collectId"];
  5552. // [params setValue:editor forKey:@"editor"];
  5553. [params setValue:ScreenCodeWishList forKey:kScreenName];
  5554. if(appDelegate.offline_mode)
  5555. {
  5556. // [OLDataProvider offline_deletewishlist:params completionHandler:result];
  5557. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5558. NSMutableDictionary* resulti = [[OLDataProvider offline_deletewishlist:params] mutableCopy];
  5559. dispatch_async(dispatch_get_main_queue(), ^{
  5560. int result_code = [[resulti valueForKey:@"result"] intValue];
  5561. if (result_code==2)
  5562. {
  5563. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  5564. [appDelegate update_count_mark];
  5565. };
  5566. result(resulti);
  5567. });
  5568. });
  5569. return;
  5570. }
  5571. [self request_interface:URL_WATCHLIST_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5572. int result_code = [[resulti valueForKey:@"result"] intValue];
  5573. if (result_code==2)
  5574. {
  5575. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  5576. [appDelegate update_count_mark];
  5577. };
  5578. result(resulti);
  5579. } retry:0];
  5580. //
  5581. //
  5582. // if(appDelegate.offline_mode)
  5583. // {
  5584. // return [OLDataProvider offline_deletewishlist:params];
  5585. // }
  5586. // if(![self IsNetworkAvailable])
  5587. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5588. //
  5589. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  5590. // if(json!=nil)
  5591. // {
  5592. // NSError *error=nil;
  5593. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5594. // int result = [[jsobj valueForKey:@"result"] intValue];
  5595. //
  5596. // if (result==2)
  5597. // {
  5598. //
  5599. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5600. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  5601. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5602. //
  5603. // [appDelegate update_count_mark];
  5604. // }
  5605. // return jsobj;
  5606. // }
  5607. // else
  5608. // return nil;
  5609. }
  5610. +(void) request_remove_cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  5611. {
  5612. #ifdef SCANNER_ORDER
  5613. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  5614. {
  5615. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  5616. //
  5617. //
  5618. // [appDelegate update_count_mark];
  5619. NSArray* arr=[RAConvertor string2arr:item_ids separator:@","];
  5620. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  5621. NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  5622. NSMutableDictionary* newsection =[cartTemplate[@"section_0"] mutableCopy];
  5623. int newcount = 0;
  5624. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  5625. int count = [section[@"count"] intValue];
  5626. for(int i=0;i<count;i++)
  5627. {
  5628. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  5629. long index = [arr indexOfObject:item[@"cart_item_id"]] ;
  5630. if(index ==NSNotFound)
  5631. {
  5632. newsection[[NSString stringWithFormat:@"item_%d",newcount]] = item;
  5633. newcount ++;
  5634. }
  5635. }
  5636. newsection[@"count"]=@(newcount);
  5637. RASingleton.sharedInstance.scan_cart[@"section_0"] = newsection;
  5638. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  5639. result(RASingleton.sharedInstance.scan_cart);
  5640. return;
  5641. }
  5642. #else
  5643. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5644. AppDelegate *appDelegate = nil;
  5645. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5646. if(appDelegate.user!=nil)
  5647. [params setValue:appDelegate.user forKey:@"user"];
  5648. if(appDelegate.contact_id!=nil)
  5649. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5650. if(appDelegate.password!=nil)
  5651. [params setValue:appDelegate.password forKey:@"password"];
  5652. if(appDelegate.order_code!=nil)
  5653. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5654. [params setValue:item_ids forKey:@"cartItemId"];
  5655. // [params setValue:editor forKey:@"editor"];
  5656. [params setValue:ScreenCodeCart forKey:kScreenName];
  5657. // [params setValue:@"" forKey:kAction];
  5658. if(appDelegate.offline_mode)
  5659. {
  5660. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5661. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_cartremove:params]] mutableCopy];
  5662. dispatch_async(dispatch_get_main_queue(), ^{
  5663. int result_code = [[resulti valueForKey:@"result"] intValue];
  5664. if (result_code==2)
  5665. {
  5666. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5667. [appDelegate update_count_mark];
  5668. };
  5669. result(resulti);
  5670. });
  5671. });
  5672. return;
  5673. }
  5674. [self request_interface:URL_CART_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5675. int result_code = [[resulti valueForKey:@"result"] intValue];
  5676. if (result_code==2)
  5677. {
  5678. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5679. [appDelegate update_count_mark];
  5680. };
  5681. result(resulti);
  5682. } retry:0];
  5683. #endif
  5684. }
  5685. +(void)request_delete_account:(resultHandler)result
  5686. {
  5687. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5688. AppDelegate *appDelegate = nil;
  5689. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5690. if(appDelegate.user!=nil)
  5691. [params setValue:appDelegate.user forKey:@"user"];
  5692. if(appDelegate.password!=nil)
  5693. [params setValue:appDelegate.password forKey:@"password"];
  5694. if(appDelegate.offline_mode)
  5695. {
  5696. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5697. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5698. dispatch_async(dispatch_get_main_queue(), ^{
  5699. result(json);
  5700. });
  5701. });
  5702. return;
  5703. }
  5704. #ifdef SCANNER_ORDER
  5705. params[@"site_name"]=[RADataProvider getSiteName];
  5706. params[@"_method"]=@"cancelOfflineOrderUser";
  5707. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_DELETE_ACCOUNT];
  5708. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  5709. #else
  5710. [self request_interface:URL_DELETE_ACCOUNT parameters:params err_record_url:nil completionHandler:result retry:0];
  5711. #endif
  5712. }
  5713. +(void) request_create_order:(resultHandler)result
  5714. {
  5715. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5716. AppDelegate *appDelegate = nil;
  5717. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5718. if(appDelegate.user!=nil)
  5719. [params setValue:appDelegate.user forKey:@"user"];
  5720. if(appDelegate.contact_id!=nil)
  5721. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5722. if(appDelegate.password!=nil)
  5723. [params setValue:appDelegate.password forKey:@"password"];
  5724. if(appDelegate.order_code!=nil)
  5725. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5726. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  5727. NSDictionary* customerinfo= appDelegate.customerInfo;
  5728. NSArray* keys=[customerinfo allKeys];
  5729. for(int i=0;i<keys.count;i++)
  5730. {
  5731. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  5732. }
  5733. if(appDelegate.offline_mode)
  5734. {
  5735. [OLDataProvider offline_createorder:params completionHandler:^(NSMutableDictionary *resulti) {
  5736. int result_code = [[resulti valueForKey:@"result"] intValue];
  5737. if (result_code==2)
  5738. {
  5739. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5740. [appDelegate update_count_mark];
  5741. };
  5742. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  5743. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5744. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  5745. }
  5746. result(resulti);
  5747. }];
  5748. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5749. // NSData* json = [[OLDataProvider offline_createorder:params] mutableCopy];
  5750. // dispatch_async(dispatch_get_main_queue(), ^{
  5751. // result([[RAConvertor data2dict:json] mutableCopy]);
  5752. // });
  5753. // });
  5754. return;
  5755. }
  5756. [self request_interface:URL_NEW_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5757. int result_code = [[resulti valueForKey:@"result"] intValue];
  5758. if (result_code==2)
  5759. {
  5760. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5761. [appDelegate update_count_mark];
  5762. };
  5763. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  5764. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5765. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  5766. }
  5767. result(resulti);
  5768. } retry:0];
  5769. //
  5770. // NSData* json = nil;
  5771. // if(appDelegate.offline_mode)
  5772. // {
  5773. // json= [OLDataProvider offline_createorder:params];
  5774. // }
  5775. // else
  5776. // {
  5777. // if(![self IsNetworkAvailable])
  5778. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5779. //
  5780. // json=[self get_json:URL_NEW_ORDER parameters:params];
  5781. // }
  5782. // if(json==nil)
  5783. // return nil;
  5784. // NSError *error=nil;
  5785. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5786. // int result = [[jsobj valueForKey:@"result"] intValue];
  5787. //
  5788. // if (result==2)
  5789. // {
  5790. //
  5791. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5792. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  5793. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5794. //
  5795. // [appDelegate update_count_mark];
  5796. // }
  5797. //
  5798. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  5799. //
  5800. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5801. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  5802. // }
  5803. //
  5804. // return jsobj;
  5805. }
  5806. +(void)request_open_order:(NSString*) order_code completionHandler:(resultHandler)result
  5807. {
  5808. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5809. AppDelegate *appDelegate = nil;
  5810. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5811. if(appDelegate.user!=nil)
  5812. [params setValue:appDelegate.user forKey:@"user"];
  5813. // if(appDelegate.contact_id!=nil)
  5814. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5815. if(appDelegate.password!=nil)
  5816. [params setValue:appDelegate.password forKey:@"password"];
  5817. [params setValue:order_code forKey:@"orderCode"];
  5818. // [params setValue:sourceid forKey:@"sourceid"];
  5819. // [params setValue:editor forKey:@"editor"];
  5820. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  5821. if(appDelegate.offline_mode)
  5822. {
  5823. params[@"appDelegate.order_code"]=appDelegate.order_code;
  5824. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5825. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_editorder:params]] mutableCopy];
  5826. dispatch_async(dispatch_get_main_queue(), ^{
  5827. int result_code = [[resulti valueForKey:@"result"] intValue];
  5828. if (result_code==2)
  5829. {
  5830. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5831. [appDelegate update_count_mark];
  5832. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5833. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  5834. }
  5835. }
  5836. result(resulti);
  5837. });
  5838. });
  5839. return;
  5840. }
  5841. [self request_interface:URL_OPEN_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5842. int result_code = [[resulti valueForKey:@"result"] intValue];
  5843. if (result_code==2)
  5844. {
  5845. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5846. [appDelegate update_count_mark];
  5847. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5848. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  5849. }
  5850. }
  5851. result(resulti);
  5852. } retry:0];
  5853. //
  5854. // NSData* json=nil;
  5855. // if(appDelegate.offline_mode)
  5856. // {
  5857. // json=[OLDataProvider offline_editorder:params];
  5858. //
  5859. // }
  5860. // else
  5861. // {
  5862. // if(![self IsNetworkAvailable])
  5863. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5864. //
  5865. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  5866. // }
  5867. // if(json!=nil)
  5868. // {
  5869. // NSError *error=nil;
  5870. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5871. // int result = [[jsobj valueForKey:@"result"] intValue];
  5872. //
  5873. // if (result==2)
  5874. // {
  5875. //
  5876. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5877. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  5878. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5879. //
  5880. // [appDelegate update_count_mark];
  5881. //
  5882. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5883. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  5884. // }
  5885. //
  5886. // }
  5887. //
  5888. // return jsobj;
  5889. // }
  5890. // else
  5891. // return nil;
  5892. }
  5893. +(void)request_order_discount:(double)discount completionHandler:(resultHandler)result
  5894. {
  5895. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5896. AppDelegate *appDelegate = nil;
  5897. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5898. if(appDelegate.user!=nil)
  5899. [params setValue:appDelegate.user forKey:@"user"];
  5900. // if(appDelegate.contact_id!=nil)
  5901. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5902. if(appDelegate.password!=nil)
  5903. [params setValue:appDelegate.password forKey:@"password"];
  5904. if(appDelegate.order_code!=nil)
  5905. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5906. [params setValue:@(discount) forKey:@"app_discount"];
  5907. if(appDelegate.offline_mode)
  5908. {
  5909. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5910. NSMutableDictionary* json = [[OLDataProvider offline_setorderdiscount:params] mutableCopy];
  5911. dispatch_async(dispatch_get_main_queue(), ^{
  5912. result(json);
  5913. });
  5914. });
  5915. return;
  5916. //
  5917. //
  5918. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5919. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5920. // dispatch_async(dispatch_get_main_queue(), ^{
  5921. // result(json);
  5922. // });
  5923. // });
  5924. //
  5925. // return;
  5926. }
  5927. [self request_interface:URL_ORDER_DISCOUNT parameters:params err_record_url:nil completionHandler:result retry:0];
  5928. }
  5929. +(void)request_cart:(int)sort completionHandler:(resultHandler)result
  5930. {
  5931. DebugLog(@"iSalesNetwork::request_Cart");
  5932. AppDelegate *appDelegate = nil;
  5933. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5934. #ifdef SCANNER_ORDER
  5935. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  5936. {
  5937. appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  5938. [appDelegate update_count_mark];
  5939. result(RASingleton.sharedInstance.scan_cart);
  5940. return;
  5941. }
  5942. #else
  5943. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5944. if(appDelegate.user!=nil)
  5945. [params setValue:appDelegate.user forKey:@"user"];
  5946. // if(appDelegate.contact_id!=nil)
  5947. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5948. if(appDelegate.password!=nil)
  5949. [params setValue:appDelegate.password forKey:@"password"];
  5950. if(appDelegate.order_code!=nil)
  5951. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5952. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  5953. [params setObject:ScreenCodeCart forKey:kScreenName];
  5954. if(appDelegate.offline_mode)
  5955. {
  5956. [OLDataProvider offline_requestcart:params completionHandler:^(NSMutableDictionary *resulti) {
  5957. if([resulti[@"result"] intValue]==2)
  5958. {
  5959. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5960. [appDelegate update_count_mark];
  5961. result(resulti);
  5962. }
  5963. }];
  5964. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5965. // NSData* json = [[OLDataProvider offline_requestcart:params] mutableCopy];
  5966. // dispatch_async(dispatch_get_main_queue(), ^{
  5967. // result([[RAConvertor data2dict:json] mutableCopy]);
  5968. // });
  5969. // });
  5970. return;
  5971. }
  5972. NSString * uuid= [[NSUUID UUID] UUIDString];
  5973. params[@"resultSerial"]=uuid;
  5974. __block bool bbreak = false;
  5975. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5976. for(int i=0;i<150;i++)
  5977. {
  5978. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  5979. // result_params[@"resultSerial"]=uuid;
  5980. if(bbreak)
  5981. break;
  5982. dispatch_async(dispatch_get_main_queue(), ^{
  5983. [self request_interface:URL_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5984. if([resulti[@"result"] intValue]==2)
  5985. {
  5986. if(!bbreak) //此判断保证result只调用一次。
  5987. {
  5988. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5989. [appDelegate update_count_mark];
  5990. result(resulti);
  5991. }
  5992. bbreak=true;
  5993. }
  5994. } retry:3];
  5995. });
  5996. sleep(2);
  5997. // json=[self get_json:URL_CART parameters:params];
  5998. // if(json!=nil)
  5999. // {
  6000. //
  6001. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6002. // if([jsobj[@"result"] intValue]==2)
  6003. // {
  6004. // break;
  6005. // }
  6006. // }
  6007. }
  6008. });
  6009. //
  6010. //
  6011. //
  6012. // NSData* json=nil;
  6013. // if(appDelegate.offline_mode)
  6014. // {
  6015. // json= [OLDataProvider offline_requestcart:params];
  6016. // }
  6017. // else
  6018. // {
  6019. // if(![self IsNetworkAvailable])
  6020. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6021. //
  6022. // NSError *error=nil;
  6023. //
  6024. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6025. // params[@"resultSerial"]=uuid;
  6026. //
  6027. // for(int i=0;i<150;i++)
  6028. // {
  6029. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6030. // // result_params[@"resultSerial"]=uuid;
  6031. // json=[self get_json:URL_CART parameters:params];
  6032. // if(json!=nil)
  6033. // {
  6034. //
  6035. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6036. // if([jsobj[@"result"] intValue]==2)
  6037. // {
  6038. // break;
  6039. // }
  6040. // }
  6041. // sleep(2);
  6042. // }
  6043. //
  6044. // }
  6045. // if(json==nil)
  6046. // return nil;
  6047. // NSError *error=nil;
  6048. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6049. // int result = [[jsobj valueForKey:@"result"] intValue];
  6050. //
  6051. // if (result==2)
  6052. // {
  6053. //
  6054. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6055. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  6056. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6057. //
  6058. // [appDelegate update_count_mark];
  6059. // }
  6060. // return jsobj;
  6061. #endif
  6062. }
  6063. +(void) request_move_wish2cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  6064. {
  6065. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6066. AppDelegate *appDelegate = nil;
  6067. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6068. if(appDelegate.user!=nil)
  6069. [params setValue:appDelegate.user forKey:@"user"];
  6070. if(appDelegate.contact_id!=nil)
  6071. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6072. if(appDelegate.password!=nil)
  6073. [params setValue:appDelegate.password forKey:@"password"];
  6074. if(appDelegate.order_code!=nil)
  6075. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6076. [params setValue:item_ids forKey:@"collectId"];
  6077. // [params setValue:editor forKey:@"editor"];
  6078. [params setValue:ScreenCodeWishList forKey:kScreenName];
  6079. [params setValue:@"Move To Cart" forKey:kAction];
  6080. if(appDelegate.offline_mode)
  6081. {
  6082. // [OLDataProvider offline_movewish2cart:params completionHandler:result];
  6083. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6084. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6085. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movewish2cart:params]] mutableCopy];
  6086. dispatch_async(dispatch_get_main_queue(), ^{
  6087. int result_code = [[resulti valueForKey:@"result"] intValue];
  6088. if (result_code==2)
  6089. {
  6090. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6091. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6092. [appDelegate update_count_mark];
  6093. }
  6094. result(resulti);
  6095. });
  6096. });
  6097. return;
  6098. }
  6099. [self request_interface:URL_WISH2CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6100. int result_code = [[resulti valueForKey:@"result"] intValue];
  6101. if (result_code==2)
  6102. {
  6103. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6104. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6105. [appDelegate update_count_mark];
  6106. }
  6107. result(resulti);
  6108. } retry:0];
  6109. //
  6110. // NSData *json = nil;
  6111. // if(appDelegate.offline_mode)
  6112. // {
  6113. // json = [OLDataProvider offline_movewish2cart:params];
  6114. // } else {
  6115. // if(![self IsNetworkAvailable])
  6116. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6117. //
  6118. // json=[self get_json:URL_WISH2CART parameters:params];
  6119. // }
  6120. //
  6121. // if(json!=nil)
  6122. // {
  6123. // NSError *error=nil;
  6124. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6125. // int result = [[jsobj valueForKey:@"result"] intValue];
  6126. //
  6127. // if (result==2)
  6128. // {
  6129. //
  6130. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6131. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6132. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6133. //
  6134. // [appDelegate update_count_mark];
  6135. // }
  6136. // return jsobj;
  6137. // }
  6138. // else
  6139. // return nil;
  6140. }
  6141. +(void) request_move_cart2wish:(NSString* ) item_ids completionHandler:(resultHandler)result
  6142. {
  6143. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6144. AppDelegate *appDelegate = nil;
  6145. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6146. if(appDelegate.user!=nil)
  6147. [params setValue:appDelegate.user forKey:@"user"];
  6148. if(appDelegate.contact_id!=nil)
  6149. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6150. if(appDelegate.password!=nil)
  6151. [params setValue:appDelegate.password forKey:@"password"];
  6152. if(appDelegate.order_code!=nil)
  6153. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6154. [params setValue:item_ids forKey:@"cartItemId"];
  6155. // [params setValue:editor forKey:@"editor"];
  6156. [params setValue:ScreenCodeCart forKey:kScreenName];
  6157. // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  6158. if(appDelegate.offline_mode)
  6159. {
  6160. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6161. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movecart2wish:params]] mutableCopy];
  6162. dispatch_async(dispatch_get_main_queue(), ^{
  6163. int result_code = [[resulti valueForKey:@"result"] intValue];
  6164. if (result_code==2)
  6165. {
  6166. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6167. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6168. [appDelegate update_count_mark];
  6169. }
  6170. result(resulti);
  6171. });
  6172. });
  6173. return;
  6174. }
  6175. [self request_interface:URL_CART2WISH parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6176. int result_code = [[resulti valueForKey:@"result"] intValue];
  6177. if (result_code==2)
  6178. {
  6179. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6180. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6181. [appDelegate update_count_mark];
  6182. }
  6183. result(resulti);
  6184. } retry:0];
  6185. //
  6186. // NSData* json = nil;
  6187. // if(appDelegate.offline_mode)
  6188. // {
  6189. // json= [OLDataProvider offline_movecart2wish:params];
  6190. // }
  6191. // else
  6192. // {
  6193. // if(![self IsNetworkAvailable])
  6194. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6195. //
  6196. // json=[self get_json:URL_CART2WISH parameters:params];
  6197. // }
  6198. // if(json!=nil)
  6199. // {
  6200. // NSError *error=nil;
  6201. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6202. // int result = [[jsobj valueForKey:@"result"] intValue];
  6203. //
  6204. // if (result==2)
  6205. // {
  6206. //
  6207. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6208. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6209. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6210. //
  6211. // [appDelegate update_count_mark];
  6212. // }
  6213. // return jsobj;
  6214. // }
  6215. // else
  6216. // return nil;
  6217. }
  6218. +(void)request_orderdetail:(NSMutableDictionary *) params completionHandler:(resultHandler)result
  6219. {
  6220. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6221. if (params == nil) {
  6222. params = [[NSMutableDictionary alloc] init];
  6223. }
  6224. AppDelegate *appDelegate = nil;
  6225. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6226. if(appDelegate.user!=nil)
  6227. [params setValue:appDelegate.user forKey:@"user"];
  6228. if(appDelegate.contact_id!=nil)
  6229. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6230. if(appDelegate.password!=nil)
  6231. [params setValue:appDelegate.password forKey:@"password"];
  6232. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  6233. [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  6234. if(appDelegate.offline_mode)
  6235. {
  6236. params[@"mode"]=appDelegate.mode;
  6237. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6238. NSData* json = [[OLDataProvider offline_orderdetail:params] mutableCopy];
  6239. dispatch_async(dispatch_get_main_queue(), ^{
  6240. result([[RAConvertor data2dict:json] mutableCopy]);
  6241. });
  6242. });
  6243. return;
  6244. }
  6245. NSString * uuid= [[NSUUID UUID] UUIDString];
  6246. params[@"resultSerial"]=uuid;
  6247. __block bool bbreak = false;
  6248. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6249. for(int i=0;i<150;i++)
  6250. {
  6251. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6252. // result_params[@"resultSerial"]=uuid;
  6253. if(bbreak)
  6254. break;
  6255. dispatch_async(dispatch_get_main_queue(), ^{
  6256. [self request_interface:URL_ORDER_DETAIL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6257. if([resulti[@"result"] intValue]==2||[resulti[@"result"] intValue]==8)
  6258. {
  6259. if(!bbreak)//此判断保证result只调用一次。
  6260. result(resulti);
  6261. bbreak=true;
  6262. }
  6263. } retry:3];
  6264. });
  6265. sleep(2);
  6266. }
  6267. });
  6268. //
  6269. // NSData* json=nil;
  6270. // if(appDelegate.offline_mode)
  6271. // {
  6272. // json= [OLDataProvider offline_orderdetail:params];
  6273. // }
  6274. // else
  6275. // {
  6276. // if(![self IsNetworkAvailable])
  6277. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6278. //
  6279. // NSError *error=nil;
  6280. //
  6281. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6282. // params[@"resultSerial"]=uuid;
  6283. //
  6284. // for(int i=0;i<150;i++)
  6285. // {
  6286. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6287. // // result_params[@"resultSerial"]=uuid;
  6288. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  6289. // if(json!=nil)
  6290. // {
  6291. //
  6292. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6293. // int resultCode = [jsobj[@"result"] intValue];
  6294. // if(resultCode==2 || resultCode == 8)
  6295. // {
  6296. // break;
  6297. // }
  6298. // }
  6299. // sleep(2);
  6300. // }
  6301. //
  6302. //
  6303. // }
  6304. // if(json==nil)
  6305. // return nil;
  6306. // NSError *error=nil;
  6307. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6308. // return jsobj;
  6309. }
  6310. //
  6311. //+(void)request_commit_order:(NSString*) order_code completionHandler:(resultHandler)result
  6312. //{
  6313. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6314. // AppDelegate *appDelegate = nil;
  6315. //
  6316. //
  6317. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6318. //
  6319. // if(appDelegate.user!=nil)
  6320. // [params setValue:appDelegate.user forKey:@"user"];
  6321. // if(appDelegate.contact_id!=nil)
  6322. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6323. // if(appDelegate.password!=nil)
  6324. // [params setValue:appDelegate.password forKey:@"password"];
  6325. // // NSString* ssaved = @"false";
  6326. // // if(saved)
  6327. // // ssaved=@"true";
  6328. // [params setValue:@"true" forKey:@"saved"];
  6329. // [params setValue:order_code forKey:@"orderCode"];
  6330. // // [params setValue:sourceid forKey:@"sourceid"];
  6331. // // [params setValue:editor forKey:@"editor"];
  6332. //
  6333. // [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  6334. //
  6335. //
  6336. // if(appDelegate.offline_mode)
  6337. // {
  6338. //
  6339. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6340. // NSMutableDictionary* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  6341. // dispatch_async(dispatch_get_main_queue(), ^{
  6342. // result(json);
  6343. // });
  6344. // });
  6345. //
  6346. // return;
  6347. // }
  6348. //
  6349. //
  6350. // [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6351. //
  6352. //// NSData* json = nil;
  6353. ////
  6354. //// if(appDelegate.offline_mode)
  6355. //// {
  6356. //// json= [OLDataProvider offline_submitorder:params];
  6357. //// }
  6358. //// else
  6359. //// {
  6360. //// if(![self IsNetworkAvailable])
  6361. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6362. ////
  6363. //// json=[self get_json:URL_COMMIT_ORDER parameters:params];
  6364. //// }
  6365. //// if(json!=nil)
  6366. //// {
  6367. //// NSError *error=nil;
  6368. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6369. //// return jsobj;
  6370. //// }
  6371. //// else
  6372. //// return nil;
  6373. //
  6374. //}
  6375. +(void)request_copy_order:(NSString*) order_code completionHandler:(resultHandler)result
  6376. {
  6377. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6378. AppDelegate *appDelegate = nil;
  6379. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6380. if(appDelegate.user!=nil)
  6381. [params setValue:appDelegate.user forKey:@"user"];
  6382. if(appDelegate.contact_id!=nil)
  6383. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6384. if(appDelegate.password!=nil)
  6385. [params setValue:appDelegate.password forKey:@"password"];
  6386. // NSString* ssaved = @"false";
  6387. // if(saved)
  6388. // ssaved=@"true";
  6389. // [params setValue:@"true" forKey:@"saved"];
  6390. [params setValue:order_code forKey:@"code"];
  6391. // [params setValue:sourceid forKey:@"sourceid"];
  6392. // [params setValue:editor forKey:@"editor"];
  6393. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  6394. if(appDelegate.offline_mode)
  6395. {
  6396. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6397. NSData* json = [[OLDataProvider offline_copyorder:params] mutableCopy];
  6398. dispatch_async(dispatch_get_main_queue(), ^{
  6399. result([[RAConvertor data2dict:json] mutableCopy]);
  6400. });
  6401. });
  6402. return;
  6403. }
  6404. [self request_interface:URL_COPY_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6405. // NSData* json=nil;
  6406. // if(appDelegate.offline_mode)
  6407. // {
  6408. // json= [OLDataProvider offline_copyorder:params];
  6409. // }
  6410. // else
  6411. // {
  6412. // if(![self IsNetworkAvailable])
  6413. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6414. //
  6415. // json=[self get_json:URL_COPY_ORDER parameters:params];
  6416. // }
  6417. // if(json!=nil)
  6418. // {
  6419. // NSError *error=nil;
  6420. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6421. // return jsobj;
  6422. // }
  6423. // else
  6424. // return nil;
  6425. }
  6426. //
  6427. //+ (void)request_fastdownload:(NSMutableDictionary *)params url:(NSString *)url completionHandler:(resultHandler)result
  6428. //{
  6429. //
  6430. // //#ifdef test_server
  6431. // // url=URL_REQUEST_RECORDS;
  6432. // // params[@"prefix"]=URL_REQUEST_RECORDS;
  6433. // //#endif
  6434. //
  6435. // [self request_file_fast:url parameters:params completionHandler:result];
  6436. //
  6437. //}
  6438. +(void) request_addto_portfolio:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6439. {
  6440. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6441. AppDelegate *appDelegate = nil;
  6442. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6443. if(appDelegate.user!=nil)
  6444. [params setValue:appDelegate.user forKey:@"user"];
  6445. if(appDelegate.contact_id!=nil)
  6446. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6447. if(appDelegate.password!=nil)
  6448. [params setValue:appDelegate.password forKey:@"password"];
  6449. [params setValue:item_id forKey:@"product_id"];
  6450. [params setObject:screenName forKey:kScreenName];
  6451. if(appDelegate.offline_mode)
  6452. {
  6453. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6454. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_add2Portfolio:params]] mutableCopy];
  6455. dispatch_async(dispatch_get_main_queue(), ^{
  6456. int result_code = [[resulti valueForKey:@"result"] intValue];
  6457. if (result_code==2)
  6458. {
  6459. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6460. [appDelegate update_count_mark];
  6461. }
  6462. result(resulti);
  6463. });
  6464. });
  6465. return;
  6466. }
  6467. [self request_interface:URL_ADD_TO_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6468. int result_code = [[resulti valueForKey:@"result"] intValue];
  6469. if (result_code==2)
  6470. {
  6471. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6472. [appDelegate update_count_mark];
  6473. }
  6474. result(resulti);
  6475. } retry:0];
  6476. //
  6477. // NSData* json = nil;
  6478. // if(appDelegate.offline_mode)
  6479. // {
  6480. // json = [OLDataProvider offline_add2Portfolio:params];
  6481. // } else {
  6482. // if(![self IsNetworkAvailable])
  6483. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6484. //
  6485. // json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  6486. // }
  6487. //
  6488. // if(json==nil)
  6489. // return nil;
  6490. // NSError *error=nil;
  6491. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6492. // int result = [[jsobj valueForKey:@"result"] intValue];
  6493. //
  6494. // if (result==2)
  6495. // {
  6496. //
  6497. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6498. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6499. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6500. //
  6501. // [appDelegate update_count_mark];
  6502. // }
  6503. // return jsobj;
  6504. }
  6505. +(void)request_addall_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  6506. {
  6507. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6508. AppDelegate *appDelegate = nil;
  6509. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6510. if(appDelegate.user!=nil)
  6511. [params setValue:appDelegate.user forKey:@"user"];
  6512. if(appDelegate.contact_id!=nil)
  6513. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6514. if(appDelegate.password!=nil)
  6515. [params setValue:appDelegate.password forKey:@"password"];
  6516. if(appDelegate.order_code!=nil)
  6517. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6518. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6519. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6520. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  6521. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6522. // [params setValue:filter forKey:@"filter"];
  6523. [params setValue:keywords forKey:@"keyword"];
  6524. [params setValue:addTo forKey:@"addTo"];
  6525. [params setValue:orderCode forKey:@"orderCode"];
  6526. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6527. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6528. if(matchfull)
  6529. [params setValue:@"true" forKey:@"exactMatch"];
  6530. else
  6531. [params setValue:@"false" forKey:@"exactMatch"];
  6532. [params setObject:ScreenCodeSearch forKey:kScreenName];
  6533. if ([addTo isEqualToString:@"cart"]) {
  6534. [params setObject:@"Add To Cart" forKey:kAction];
  6535. }
  6536. if(appDelegate.offline_mode)
  6537. {
  6538. if ([addTo isEqualToString:@"cart"])
  6539. {
  6540. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6541. }
  6542. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6543. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_searchaddall:params]] mutableCopy];
  6544. dispatch_async(dispatch_get_main_queue(), ^{
  6545. int result_code =[json[@"result"] intValue];
  6546. if (result_code==2||result_code==8)
  6547. {
  6548. if(json[@"cart_count"])
  6549. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6550. if(json[@"wish_count"])
  6551. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  6552. if(json[@"portfolio_count"])
  6553. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  6554. //
  6555. //
  6556. [appDelegate update_count_mark];
  6557. }
  6558. result(json);
  6559. });
  6560. });
  6561. return;
  6562. }
  6563. NSString * uuid= [[NSUUID UUID] UUIDString];
  6564. params[@"resultSerial"]=uuid;
  6565. __block bool bbreak = false;
  6566. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6567. for(int i=0;i<150;i++)
  6568. {
  6569. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6570. // result_params[@"resultSerial"]=uuid;
  6571. if(bbreak)
  6572. break;
  6573. dispatch_async(dispatch_get_main_queue(), ^{
  6574. [self request_interface:URL_SEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6575. if([resulti[@"result"] intValue]==2)
  6576. {
  6577. if(!bbreak)//此判断保证result只调用一次。
  6578. result(resulti);
  6579. bbreak=true;
  6580. }
  6581. } retry:3];
  6582. });
  6583. sleep(2);
  6584. }
  6585. });
  6586. //
  6587. //
  6588. // NSData* json=nil;
  6589. // if(appDelegate.offline_mode)
  6590. // {
  6591. // json=[OLDataProvider offline_searchaddall:params];
  6592. // }
  6593. // else
  6594. // {
  6595. // if(![self IsNetworkAvailable])
  6596. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6597. //
  6598. // NSError *error=nil;
  6599. //
  6600. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6601. // params[@"resultSerial"]=uuid;
  6602. //
  6603. // for(int i=0;i<150;i++)
  6604. // {
  6605. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6606. // // result_params[@"resultSerial"]=uuid;
  6607. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  6608. // if(json!=nil)
  6609. // {
  6610. //
  6611. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6612. // if([jsobj[@"result"] intValue]==2)
  6613. // {
  6614. // break;
  6615. // }
  6616. // }
  6617. // sleep(2);
  6618. // }
  6619. // }
  6620. // if(json==nil)
  6621. // return nil;
  6622. // NSError *error=nil;
  6623. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6624. // return jsobj;
  6625. }
  6626. +(void) request_addto_cart_byupc:(NSString* ) upc_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6627. {
  6628. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6629. AppDelegate *appDelegate = nil;
  6630. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6631. if(appDelegate.user!=nil)
  6632. [params setValue:appDelegate.user forKey:@"user"];
  6633. if(appDelegate.contact_id!=nil)
  6634. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6635. if(appDelegate.password!=nil)
  6636. [params setValue:appDelegate.password forKey:@"password"];
  6637. if(appDelegate.order_code!=nil)
  6638. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6639. [params setValue:upc_code forKey:@"upc_code"];
  6640. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  6641. [params setObject:screenName forKey:kScreenName];
  6642. [params setObject:@"Add To Cart" forKey:kAction];
  6643. if (!upc_code) {
  6644. upc_code = @"";
  6645. }
  6646. [params setObject:@{@"UPCCode" : upc_code} forKey:kExtra];
  6647. params[@"search_upc"]=@true;
  6648. NSDictionary* customerinfo= appDelegate.customerInfo;
  6649. NSArray* keys=[customerinfo allKeys];
  6650. for(int i=0;i<keys.count;i++)
  6651. {
  6652. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  6653. }
  6654. if(appDelegate.offline_mode)
  6655. {
  6656. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6657. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  6658. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6659. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyupc:params]] mutableCopy];
  6660. dispatch_async(dispatch_get_main_queue(), ^{
  6661. int result_code = [[json valueForKey:@"result"] intValue];
  6662. if (result_code==2||result_code==8)
  6663. {
  6664. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6665. [appDelegate update_count_mark];
  6666. }
  6667. result(json);
  6668. });
  6669. });
  6670. return;
  6671. }
  6672. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6673. int result_code = [[resulti valueForKey:@"result"] intValue];
  6674. if (result_code==2||result_code==8)
  6675. {
  6676. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6677. [appDelegate update_count_mark];
  6678. }
  6679. result(resulti);
  6680. } retry:0];
  6681. }
  6682. +(void) request_addto_cart_byname:(NSString* ) model_name withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6683. {
  6684. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6685. AppDelegate *appDelegate = nil;
  6686. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6687. if(appDelegate.user!=nil)
  6688. [params setValue:appDelegate.user forKey:@"user"];
  6689. if(appDelegate.contact_id!=nil)
  6690. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6691. if(appDelegate.password!=nil)
  6692. [params setValue:appDelegate.password forKey:@"password"];
  6693. if(appDelegate.order_code!=nil)
  6694. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6695. [params setValue:model_name forKey:@"product_name"];
  6696. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  6697. [params setObject:screenName forKey:kScreenName];
  6698. [params setObject:@"Add To Cart" forKey:kAction];
  6699. if (!model_name) {
  6700. model_name = @"";
  6701. }
  6702. [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  6703. NSDictionary* customerinfo= appDelegate.customerInfo;
  6704. NSArray* keys=[customerinfo allKeys];
  6705. for(int i=0;i<keys.count;i++)
  6706. {
  6707. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  6708. }
  6709. if(appDelegate.offline_mode)
  6710. {
  6711. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6712. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  6713. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6714. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyname:params]] mutableCopy];
  6715. dispatch_async(dispatch_get_main_queue(), ^{
  6716. int result_code = [[json valueForKey:@"result"] intValue];
  6717. if (result_code==2||result_code==8)
  6718. {
  6719. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6720. [appDelegate update_count_mark];
  6721. }
  6722. result(json);
  6723. });
  6724. });
  6725. return;
  6726. }
  6727. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6728. int result_code = [[resulti valueForKey:@"result"] intValue];
  6729. if (result_code==2||result_code==8)
  6730. {
  6731. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6732. [appDelegate update_count_mark];
  6733. }
  6734. result(resulti);
  6735. } retry:0];
  6736. // NSData* json=nil;
  6737. // if(appDelegate.offline_mode)
  6738. // {
  6739. // json= [OLDataProvider offline_add2cartbyname:params];
  6740. // }
  6741. // else
  6742. // {
  6743. // if(![self IsNetworkAvailable])
  6744. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6745. //
  6746. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  6747. // }
  6748. // if(json==nil)
  6749. // return nil;
  6750. // NSError *error=nil;
  6751. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6752. //
  6753. //
  6754. //
  6755. // int result = [[jsobj valueForKey:@"result"] intValue];
  6756. //
  6757. // if (result==2||result==8)
  6758. // {
  6759. //
  6760. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6761. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6762. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6763. //
  6764. // [appDelegate update_count_mark];
  6765. // }
  6766. //
  6767. // return jsobj;
  6768. }
  6769. +(void) request_addto_wishlist:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6770. {
  6771. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6772. AppDelegate *appDelegate = nil;
  6773. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6774. if(appDelegate.user!=nil)
  6775. [params setValue:appDelegate.user forKey:@"user"];
  6776. if(appDelegate.contact_id!=nil)
  6777. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6778. if(appDelegate.password!=nil)
  6779. [params setValue:appDelegate.password forKey:@"password"];
  6780. [params setValue:item_id forKey:@"product_id"];
  6781. [params setObject:screenName forKey:kScreenName];
  6782. if(appDelegate.offline_mode)
  6783. {
  6784. // [OLDataProvider offline_add2wishlist:params completionHandler:result];
  6785. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6786. NSMutableDictionary* resulti = [[OLDataProvider offline_add2wishlist:params] mutableCopy];
  6787. dispatch_async(dispatch_get_main_queue(), ^{
  6788. int result_code = [[resulti valueForKey:@"result"] intValue];
  6789. if (result_code==2||result_code==8)
  6790. {
  6791. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6792. [appDelegate update_count_mark];
  6793. }
  6794. result(resulti);
  6795. });
  6796. });
  6797. return;
  6798. }
  6799. [self request_interface:URL_ADD_TO_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6800. int result_code = [[resulti valueForKey:@"result"] intValue];
  6801. if (result_code==2||result_code==8)
  6802. {
  6803. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6804. [appDelegate update_count_mark];
  6805. }
  6806. result(resulti);
  6807. } retry:0];
  6808. // if(appDelegate.offline_mode)
  6809. // {
  6810. // return [OLDataProvider offline_add2wishlist:params];
  6811. // }
  6812. // if(![self IsNetworkAvailable])
  6813. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6814. //
  6815. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  6816. // if(json==nil)
  6817. // return nil;
  6818. // NSError *error=nil;
  6819. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6820. // int result = [[jsobj valueForKey:@"result"] intValue];
  6821. //
  6822. // if (result==2)
  6823. // {
  6824. //
  6825. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6826. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6827. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6828. //
  6829. // [appDelegate update_count_mark];
  6830. // }
  6831. // return jsobj;
  6832. }
  6833. +(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
  6834. {
  6835. // for debug
  6836. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  6837. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6838. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6839. AppDelegate *appDelegate = nil;
  6840. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6841. if(appDelegate.user!=nil)
  6842. [params setValue:appDelegate.user forKey:@"user"];
  6843. if(appDelegate.contact_id!=nil)
  6844. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6845. if(appDelegate.password!=nil)
  6846. [params setValue:appDelegate.password forKey:@"password"];
  6847. if(appDelegate.order_code!=nil)
  6848. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6849. [params setValue:addTo forKey:@"addTo"];
  6850. [params setValue:orderCode forKey:@"orderCode"];
  6851. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6852. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6853. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  6854. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6855. // [params setValue:filter forKey:@"filter"];
  6856. [params setValue:covertype forKey:@"covertype"];
  6857. [params setValue:ctgid forKey:@"ctgId"];
  6858. [params setValue:modelname forKey:@"modelName"];
  6859. [params setValue:modeldescrip forKey:@"modelDescription"];
  6860. [params setValue:alert forKey:@"alert"];
  6861. [params setValue:qty forKey:@"sold_by_qty"];
  6862. [params setValue:available forKey:@"available"];
  6863. [params setValue:price forKey:@"price"];
  6864. [params setValue:bestseller forKey:@"bestseller"];
  6865. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6866. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6867. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  6868. if ([addTo isEqualToString:@"cart"]) {
  6869. [params setObject:@"Add To Cart" forKey:kAction];
  6870. }
  6871. if(appDelegate.offline_mode)
  6872. {
  6873. if ([addTo isEqualToString:@"cart"])
  6874. {
  6875. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6876. }
  6877. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6878. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_itemsearchaddall:params]] mutableCopy];
  6879. dispatch_async(dispatch_get_main_queue(), ^{
  6880. int result_code =[json[@"result"] intValue];
  6881. if (result_code==2||result_code==8)
  6882. {
  6883. if(json[@"cart_count"])
  6884. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6885. if(json[@"wish_count"])
  6886. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  6887. if(json[@"portfolio_count"])
  6888. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  6889. //
  6890. //
  6891. [appDelegate update_count_mark];
  6892. }
  6893. result(json);
  6894. });
  6895. });
  6896. return;
  6897. }
  6898. NSString * uuid= [[NSUUID UUID] UUIDString];
  6899. params[@"resultSerial"]=uuid;
  6900. __block bool bbreak = false;
  6901. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6902. for(int i=0;i<150;i++)
  6903. {
  6904. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6905. // result_params[@"resultSerial"]=uuid;
  6906. if(bbreak)
  6907. break;
  6908. dispatch_async(dispatch_get_main_queue(), ^{
  6909. [self request_interface:URL_ITEMSEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6910. if([resulti[@"result"] intValue]==2)
  6911. {
  6912. if(!bbreak)//此判断保证result只调用一次。
  6913. result(resulti);
  6914. bbreak=true;
  6915. }
  6916. } retry:3];
  6917. });
  6918. sleep(2);
  6919. }
  6920. });
  6921. //
  6922. // NSData* json = nil;
  6923. //
  6924. // if(appDelegate.offline_mode)
  6925. // {
  6926. // json= [OLDataProvider offline_itemsearchaddall:params];
  6927. // }
  6928. // else
  6929. // {
  6930. // if(![self IsNetworkAvailable])
  6931. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6932. // NSError *error=nil;
  6933. //
  6934. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6935. // params[@"resultSerial"]=uuid;
  6936. //
  6937. // for(int i=0;i<150;i++)
  6938. // {
  6939. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6940. // // result_params[@"resultSerial"]=uuid;
  6941. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  6942. // if(json!=nil)
  6943. // {
  6944. //
  6945. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6946. // if([jsobj[@"result"] intValue]==2)
  6947. // {
  6948. // break;
  6949. // }
  6950. // }
  6951. // sleep(2);
  6952. // }
  6953. // }
  6954. // if(json==nil)
  6955. // return nil;
  6956. // NSError *error=nil;
  6957. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6958. // return jsobj;
  6959. }
  6960. +(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
  6961. {
  6962. AppDelegate *appDelegate = nil;
  6963. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6964. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6965. if(appDelegate.user!=nil)
  6966. [params setValue:appDelegate.user forKey:@"user"];
  6967. if(appDelegate.contact_id!=nil)
  6968. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6969. if(appDelegate.password!=nil)
  6970. [params setValue:appDelegate.password forKey:@"password"];
  6971. if(appDelegate.order_code!=nil)
  6972. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6973. [params setValue:addTo forKey:@"addTo"];
  6974. [params setValue:orderCode forKey:@"orderCode"];
  6975. [params setValue:alert forKey:@"alert"];
  6976. [params setValue:qty forKey:@"sold_by_qty"];
  6977. [params setValue:available forKey:@"available"];
  6978. [params setValue:price forKey:@"price"];
  6979. [params setValue:bestseller forKey:@"bestseller"];
  6980. [params setValue:modelname forKey:@"modelName"];
  6981. [params setValue:modeldescrip forKey:@"modelDescription"];
  6982. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6983. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6984. [params setValue:category forKey:@"category"];
  6985. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6986. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6987. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6988. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6989. [params setValue:filter forKey:@"filter"];
  6990. [params setValue:keyword forKey:@"keyword"];
  6991. [params setObject:ScreenCodeCategory forKey:kScreenName];
  6992. if ([addTo isEqualToString:@"cart"]) {
  6993. [params setObject:@"Add To Cart" forKey:kAction];
  6994. }
  6995. if(appDelegate.offline_mode)
  6996. {
  6997. if ([addTo isEqualToString:@"cart"])
  6998. {
  6999. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7000. }
  7001. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7002. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_categoryaddall:params]] mutableCopy];
  7003. dispatch_async(dispatch_get_main_queue(), ^{
  7004. int result_code =[json[@"result"] intValue];
  7005. if (result_code==2||result_code==8)
  7006. {
  7007. if(json[@"cart_count"])
  7008. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7009. if(json[@"wish_count"])
  7010. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7011. if(json[@"portfolio_count"])
  7012. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7013. //
  7014. //
  7015. [appDelegate update_count_mark];
  7016. }
  7017. result(json);
  7018. });
  7019. });
  7020. return;
  7021. }
  7022. NSString * uuid= [[NSUUID UUID] UUIDString];
  7023. params[@"resultSerial"]=uuid;
  7024. __block bool bbreak = false;
  7025. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7026. for(int i=0;i<150;i++)
  7027. {
  7028. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7029. // result_params[@"resultSerial"]=uuid;
  7030. if(bbreak)
  7031. break;
  7032. dispatch_async(dispatch_get_main_queue(), ^{
  7033. [self request_interface:URL_CATEGORYADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7034. if([resulti[@"result"] intValue]==2|| [resulti[@"result"] intValue] == 8)
  7035. {
  7036. if(!bbreak)//此判断保证result只调用一次。
  7037. {
  7038. int result_code =[resulti[@"result"] intValue];
  7039. if (result_code==2||result_code==8)
  7040. {
  7041. if(resulti[@"cart_count"])
  7042. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7043. if(resulti[@"wish_count"])
  7044. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7045. if(resulti[@"portfolio_count"])
  7046. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  7047. //
  7048. //
  7049. [appDelegate update_count_mark];
  7050. }
  7051. result(resulti);
  7052. }
  7053. bbreak=true;
  7054. }
  7055. } retry:3];
  7056. });
  7057. sleep(2);
  7058. }
  7059. });
  7060. //
  7061. // NSData* json= nil;
  7062. //
  7063. // if(appDelegate.offline_mode)
  7064. // {
  7065. // json= [OLDataProvider offline_categoryaddall:params];
  7066. // }
  7067. // else
  7068. // {
  7069. // if(![self IsNetworkAvailable])
  7070. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7071. //
  7072. //
  7073. // NSError *error=nil;
  7074. //
  7075. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7076. // params[@"resultSerial"]=uuid;
  7077. //
  7078. // for(int i=0;i<150;i++)
  7079. // {
  7080. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7081. //// result_params[@"resultSerial"]=uuid;
  7082. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  7083. // if(json!=nil)
  7084. // {
  7085. //
  7086. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7087. // int resultInt = [jsobj[@"result"] intValue];
  7088. // if(resultInt == 2 || resultInt == 8)
  7089. // {
  7090. // break;
  7091. // }
  7092. // }
  7093. // sleep(2);
  7094. // }
  7095. //
  7096. //
  7097. //
  7098. // }
  7099. // if(json==nil)
  7100. // return nil;
  7101. // NSError *error=nil;
  7102. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7103. // return jsobj;
  7104. }
  7105. +(void)request_save_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7106. {
  7107. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7108. AppDelegate *appDelegate = nil;
  7109. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7110. if(appDelegate.user!=nil)
  7111. [params setValue:appDelegate.user forKey:@"user"];
  7112. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  7113. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7114. // else
  7115. if(appDelegate.contact_id!=nil)
  7116. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7117. if(appDelegate.password!=nil)
  7118. [params setValue:appDelegate.password forKey:@"password"];
  7119. if(appDelegate.order_code!=nil)
  7120. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7121. // NSDictionary* customerinfo=nil;
  7122. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  7123. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7124. // else
  7125. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7126. //
  7127. // appDelegate.customerInfo;
  7128. // NSArray* keys=[customerinfo allKeys];
  7129. // for(int i=0;i<keys.count;i++)
  7130. // {
  7131. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7132. // }
  7133. // [params setValue:sourceid forKey:@"sourceid"];
  7134. // [params setValue:editor forKey:@"editor"];
  7135. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  7136. if(appDelegate.offline_mode)
  7137. {
  7138. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7139. NSData* json = [[OLDataProvider offline_saveorder:params] mutableCopy];
  7140. dispatch_async(dispatch_get_main_queue(), ^{
  7141. result([[RAConvertor data2dict:json] mutableCopy]);
  7142. });
  7143. });
  7144. return;
  7145. }
  7146. [self request_interface:URL_SAVE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  7147. //
  7148. // NSData* json=nil;
  7149. //
  7150. // if(appDelegate.offline_mode)
  7151. // {
  7152. // json= [OLDataProvider offline_saveorder:params];
  7153. // }
  7154. // else
  7155. // {
  7156. // if(![self IsNetworkAvailable])
  7157. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7158. //
  7159. // json=[self get_json:URL_SAVE_ORDER parameters:params];
  7160. // }
  7161. // if(json!=nil)
  7162. // {
  7163. // NSError *error=nil;
  7164. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7165. // NSString *so = [jsobj valueForKey:@"so#"];
  7166. // if (so) {
  7167. // [appDelegate SetSo:so];
  7168. // }
  7169. // return jsobj;
  7170. // }
  7171. // else
  7172. // return nil;
  7173. }
  7174. +(void) request_update_cartqty:(NSString*) cart_id value:(int) value completionHandler:(resultHandler)result
  7175. {
  7176. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  7177. #ifdef SCANNER_ORDER
  7178. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7179. {
  7180. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7181. //
  7182. //
  7183. // [appDelegate update_count_mark];
  7184. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7185. int count = [section[@"count"] intValue];
  7186. for(int i=0;i<count;i++)
  7187. {
  7188. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7189. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7190. {
  7191. item[@"count"] =@(value);
  7192. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7193. break;
  7194. }
  7195. }
  7196. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7197. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7198. result(RASingleton.sharedInstance.scan_cart);
  7199. [OLDataProvider updateScanOrder:appDelegate.order_code];
  7200. return;
  7201. }
  7202. #else
  7203. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7204. if(appDelegate.user!=nil)
  7205. [params setValue:appDelegate.user forKey:@"user"];
  7206. if(appDelegate.contact_id!=nil)
  7207. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7208. if(appDelegate.password!=nil)
  7209. [params setValue:appDelegate.password forKey:@"password"];
  7210. [params setValue:cart_id forKey:@"cartitem_id"];
  7211. [params setObject:ScreenCodeCart forKey:kScreenName];
  7212. [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  7213. if(appDelegate.offline_mode)
  7214. {
  7215. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7216. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7217. NSData* json = [[OLDataProvider offline_cartsetqty:params] mutableCopy];
  7218. dispatch_async(dispatch_get_main_queue(), ^{
  7219. result([[RAConvertor data2dict:json] mutableCopy]);
  7220. });
  7221. });
  7222. return;
  7223. }
  7224. [self request_interface:URL_CART_INCRESEMENT parameters:params err_record_url:nil completionHandler:result retry:0];
  7225. //
  7226. // NSData* json=nil;
  7227. // if(appDelegate.offline_mode)
  7228. // {
  7229. // json= [OLDataProvider offline_cartsetqty:params];
  7230. // }
  7231. // else
  7232. // {
  7233. // if(![self IsNetworkAvailable])
  7234. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7235. //
  7236. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  7237. // }
  7238. // if(json==nil)
  7239. // return nil;
  7240. // NSError *error=nil;
  7241. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7242. // return jsobj;
  7243. #endif
  7244. }
  7245. +(void) request_update_cartgeneralnote:(NSString*) order_code notes:(NSString*) notes completionHandler:(resultHandler)result
  7246. {
  7247. #ifdef SCANNER_ORDER
  7248. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7249. {
  7250. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7251. //
  7252. //
  7253. // [appDelegate update_count_mark];
  7254. RASingleton.sharedInstance.scan_cart[@"general_note"] = notes;
  7255. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7256. result(RASingleton.sharedInstance.scan_cart);
  7257. return;
  7258. }
  7259. #else
  7260. AppDelegate *appDelegate = nil;
  7261. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7262. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7263. if(appDelegate.user!=nil)
  7264. [params setValue:appDelegate.user forKey:@"user"];
  7265. if(appDelegate.contact_id!=nil)
  7266. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7267. if(appDelegate.password!=nil)
  7268. [params setValue:appDelegate.password forKey:@"password"];
  7269. [params setValue:order_code forKey:@"orderCode"];
  7270. [params setObject:ScreenCodeCart forKey:kScreenName];
  7271. if(notes.length==0)
  7272. notes=@"";
  7273. [params setValue:notes forKey:@"comments"];
  7274. if(appDelegate.offline_mode)
  7275. {
  7276. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7277. NSData* json = [[OLDataProvider offline_updategnotes:params] mutableCopy];
  7278. dispatch_async(dispatch_get_main_queue(), ^{
  7279. result([[RAConvertor data2dict:json] mutableCopy]);
  7280. });
  7281. });
  7282. return;
  7283. }
  7284. [self request_interface:URL_CART_GENERAL_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7285. //
  7286. // NSData* json=nil;
  7287. // if(appDelegate.offline_mode)
  7288. // {
  7289. // json= [OLDataProvider offline_updategnotes:params];
  7290. // }
  7291. // else
  7292. // {
  7293. // if(![self IsNetworkAvailable])
  7294. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7295. //
  7296. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  7297. // }
  7298. // if(json==nil)
  7299. // return nil;
  7300. // NSError *error=nil;
  7301. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7302. // return jsobj;
  7303. #endif
  7304. }
  7305. +(void) request_update_cartitemnote:(NSString*) cart_id notes:(NSString*) notes completionHandler:(resultHandler)result
  7306. {
  7307. AppDelegate *appDelegate = nil;
  7308. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7309. #ifdef SCANNER_ORDER
  7310. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7311. {
  7312. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7313. //
  7314. //
  7315. // [appDelegate update_count_mark];
  7316. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7317. int count = [section[@"count"] intValue];
  7318. for(int i=0;i<count;i++)
  7319. {
  7320. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7321. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7322. {
  7323. item[@"note"] =notes;
  7324. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7325. break;
  7326. }
  7327. }
  7328. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7329. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7330. result(RASingleton.sharedInstance.scan_cart);
  7331. return;
  7332. }
  7333. #else
  7334. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7335. if(appDelegate.user!=nil)
  7336. [params setValue:appDelegate.user forKey:@"user"];
  7337. if(appDelegate.contact_id!=nil)
  7338. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7339. if(appDelegate.password!=nil)
  7340. [params setValue:appDelegate.password forKey:@"password"];
  7341. [params setValue:cart_id forKey:@"cartitem_id"];
  7342. [params setObject:ScreenCodeCart forKey:kScreenName];
  7343. if(notes.length==0)
  7344. notes=@"";
  7345. [params setValue:notes forKey:@"notes"];
  7346. if(appDelegate.offline_mode)
  7347. {
  7348. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7349. NSData* json = [[OLDataProvider offline_cartsetlnotes:params] mutableCopy];
  7350. dispatch_async(dispatch_get_main_queue(), ^{
  7351. result([[RAConvertor data2dict:json] mutableCopy]);
  7352. });
  7353. });
  7354. return;
  7355. }
  7356. [self request_interface:URL_CART_ITEM_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7357. //
  7358. // NSData* json=nil;
  7359. // if(appDelegate.offline_mode)
  7360. // {
  7361. // json= [OLDataProvider offline_cartsetlnotes:params];
  7362. // }
  7363. // else
  7364. // {
  7365. // if(![self IsNetworkAvailable])
  7366. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7367. //
  7368. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  7369. // }
  7370. // if(json==nil)
  7371. // return nil;
  7372. // NSError *error=nil;
  7373. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7374. // return jsobj;
  7375. #endif
  7376. }
  7377. + (void)request_update_npd_shop_price_type:(NSInteger)priceType completionHandler:(resultHandler)result
  7378. {
  7379. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7380. AppDelegate *appDelegate = nil;
  7381. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7382. if(appDelegate.user!=nil)
  7383. [dic setValue:appDelegate.user forKey:@"user"];
  7384. if(appDelegate.password!=nil)
  7385. [dic setValue:appDelegate.password forKey:@"password"];
  7386. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  7387. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  7388. if(appDelegate.offline_mode)
  7389. {
  7390. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7391. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7392. dispatch_async(dispatch_get_main_queue(), ^{
  7393. result(json);
  7394. });
  7395. });
  7396. return;
  7397. }
  7398. [self request_interface:URL_SET_PRICE_TYPE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7399. //
  7400. // NSData* json=nil;
  7401. // if(appDelegate.offline_mode)
  7402. // {
  7403. // return [OLDataProvider offline_notimpl];
  7404. // }
  7405. // else
  7406. // {
  7407. // if(![self IsNetworkAvailable])
  7408. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7409. //
  7410. // json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  7411. // }
  7412. // if(json!=nil)
  7413. // {
  7414. // NSError *error=nil;
  7415. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7416. //
  7417. //
  7418. // return jsobj;
  7419. // }
  7420. //
  7421. //
  7422. // return nil;
  7423. }
  7424. + (void)request_npd_shop_givenprice:(resultHandler)result
  7425. {
  7426. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7427. AppDelegate *appDelegate = nil;
  7428. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7429. if(appDelegate.user!=nil)
  7430. [dic setValue:appDelegate.user forKey:@"user"];
  7431. if(appDelegate.password!=nil)
  7432. [dic setValue:appDelegate.password forKey:@"password"];
  7433. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  7434. if(appDelegate.offline_mode)
  7435. {
  7436. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7437. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7438. dispatch_async(dispatch_get_main_queue(), ^{
  7439. result(json);
  7440. });
  7441. });
  7442. return;
  7443. }
  7444. [self request_interface:URL_GET_CIVEN_PRICE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7445. //
  7446. // NSData* json=nil;
  7447. // if(appDelegate.offline_mode)
  7448. // {
  7449. // return [OLDataProvider offline_notimpl];
  7450. // }
  7451. // else
  7452. // {
  7453. // if(![self IsNetworkAvailable])
  7454. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7455. //
  7456. // json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  7457. // }
  7458. // if(json!=nil)
  7459. // {
  7460. // NSError *error=nil;
  7461. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7462. //
  7463. //
  7464. // return jsobj;
  7465. // }
  7466. //
  7467. //
  7468. // return nil;
  7469. }
  7470. + (void)request_update_npd_shop_givenprice:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  7471. {
  7472. AppDelegate *appDelegate = nil;
  7473. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7474. if(appDelegate.user!=nil)
  7475. [params setValue:appDelegate.user forKey:@"user"];
  7476. if(appDelegate.password!=nil)
  7477. [params setValue:appDelegate.password forKey:@"password"];
  7478. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  7479. if(appDelegate.offline_mode)
  7480. {
  7481. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7482. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7483. dispatch_async(dispatch_get_main_queue(), ^{
  7484. result(json);
  7485. });
  7486. });
  7487. return;
  7488. }
  7489. [self request_interface:URL_SET_GIVEN_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  7490. //
  7491. // NSData* json=nil;
  7492. // if(appDelegate.offline_mode)
  7493. // {
  7494. // return [OLDataProvider offline_notimpl];
  7495. // }
  7496. // else
  7497. // {
  7498. // if(![self IsNetworkAvailable])
  7499. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7500. //
  7501. // json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  7502. // }
  7503. // if(json!=nil)
  7504. // {
  7505. // NSError *error=nil;
  7506. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7507. //
  7508. //
  7509. // return jsobj;
  7510. // }
  7511. //
  7512. //
  7513. // return nil;
  7514. }
  7515. +(void) request_create_portfolio:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7516. {
  7517. AppDelegate *appDelegate = nil;
  7518. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7519. if(appDelegate.offline_mode)
  7520. {
  7521. params[@"contact_id"]=params[@"contactId"];
  7522. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7523. NSData* json = [[OLDataProvider offline_direct_save_TearSheet:params] mutableCopy];
  7524. dispatch_async(dispatch_get_main_queue(), ^{
  7525. result([[RAConvertor data2dict:json] mutableCopy]);
  7526. });
  7527. });
  7528. return;
  7529. }
  7530. //
  7531. // if(appDelegate.offline_mode)
  7532. // {
  7533. //
  7534. //
  7535. // NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  7536. // if(json==nil)
  7537. // return nil;
  7538. // NSError *error=nil;
  7539. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7540. //
  7541. // return jsobj[@"pdf_path"];
  7542. // }
  7543. // else
  7544. // {
  7545. // return nil;
  7546. // }
  7547. }
  7548. +(void)request_save_portfoliodirectly:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7549. {
  7550. NSMutableDictionary* off_params = [params mutableCopy];
  7551. AppDelegate *appDelegate = nil;
  7552. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7553. if(appDelegate.user!=nil)
  7554. [params setValue:appDelegate.user forKey:@"user"];
  7555. if(appDelegate.contact_id!=nil)
  7556. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7557. if(appDelegate.password!=nil)
  7558. params[@"off_params"]=[RAConvertor dict2string:off_params];
  7559. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  7560. [params setValue:appDelegate.password forKey:@"password"];
  7561. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7562. if(appDelegate.offline_mode)
  7563. {
  7564. params[@"contact_id"]=appDelegate.contact_id;
  7565. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7566. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_direct_save_TearSheet:params]] mutableCopy];
  7567. dispatch_async(dispatch_get_main_queue(), ^{
  7568. result(json);
  7569. });
  7570. });
  7571. return;
  7572. }
  7573. NSString * uuid= [[NSUUID UUID] UUIDString];
  7574. params[@"resultSerial"]=uuid;
  7575. __block bool bbreak = false;
  7576. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7577. for(int i=0;i<150;i++)
  7578. {
  7579. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7580. // result_params[@"resultSerial"]=uuid;
  7581. if(bbreak)
  7582. break;
  7583. dispatch_async(dispatch_get_main_queue(), ^{
  7584. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7585. if([resulti[@"result"] intValue]==2)
  7586. {
  7587. if(!bbreak)//此判断保证result只调用一次。
  7588. result(resulti);
  7589. bbreak=true;
  7590. }
  7591. } retry:3];
  7592. });
  7593. sleep(2);
  7594. }
  7595. });
  7596. //
  7597. //
  7598. // NSData* json= nil;
  7599. //
  7600. // if(appDelegate.offline_mode)
  7601. // {
  7602. // json = [OLDataProvider offline_direct_save_TearSheet:params];
  7603. // }
  7604. // else
  7605. // {
  7606. // if(![self IsNetworkAvailable])
  7607. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7608. //
  7609. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7610. //
  7611. // NSError *error=nil;
  7612. //
  7613. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7614. // params[@"resultSerial"]=uuid;
  7615. //
  7616. // for(int i=0;i<150;i++)
  7617. // {
  7618. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7619. // // result_params[@"resultSerial"]=uuid;
  7620. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7621. // if(json!=nil)
  7622. // {
  7623. //
  7624. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7625. // if([jsobj[@"result"] intValue]==2)
  7626. // {
  7627. // break;
  7628. // }
  7629. // }
  7630. // sleep(5);
  7631. // }
  7632. //
  7633. // }
  7634. // if(json==nil)
  7635. // return nil;
  7636. // NSError *error=nil;
  7637. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7638. // return jsobj;
  7639. }
  7640. +(void)request_save_portfolio:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  7641. {
  7642. AppDelegate *appDelegate = nil;
  7643. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7644. if(appDelegate.user!=nil)
  7645. [params setValue:appDelegate.user forKey:@"user"];
  7646. if(appDelegate.contact_id!=nil)
  7647. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7648. NSMutableDictionary* off_params = [params mutableCopy];;
  7649. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  7650. params[@"off_params"]=[RAConvertor dict2string:off_params];
  7651. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7652. if(appDelegate.password!=nil)
  7653. [params setValue:appDelegate.password forKey:@"password"];
  7654. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7655. if(appDelegate.offline_mode)
  7656. {
  7657. params[@"contact_id"]=appDelegate.contact_id;
  7658. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7659. NSData* json = [[OLDataProvider offline_save_TearSheet:params] mutableCopy];
  7660. dispatch_async(dispatch_get_main_queue(), ^{
  7661. result([[RAConvertor data2dict:json] mutableCopy]);
  7662. });
  7663. });
  7664. return;
  7665. }
  7666. [self request_interface:URL_SAVE_DM parameters:params err_record_url:nil completionHandler:result retry:0];
  7667. //
  7668. // NSData* json = nil;
  7669. // if(appDelegate.offline_mode)
  7670. // {
  7671. // json = [OLDataProvider offline_save_TearSheet:params];
  7672. // } else {
  7673. // if(![self IsNetworkAvailable])
  7674. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7675. //
  7676. // json=[self get_json:URL_SAVE_DM parameters:params];
  7677. // }
  7678. // if(json==nil)
  7679. // return nil;
  7680. // NSError *error=nil;
  7681. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7682. // return jsobj;
  7683. }
  7684. +(void)request_portfoliopreview:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7685. {
  7686. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7687. AppDelegate *appDelegate = nil;
  7688. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7689. if(appDelegate.user!=nil)
  7690. [params setValue:appDelegate.user forKey:@"user"];
  7691. if(appDelegate.contact_id!=nil)
  7692. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7693. if(appDelegate.password!=nil)
  7694. [params setValue:appDelegate.password forKey:@"password"];
  7695. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7696. // [params setValue:request_url forKey:@"pdfUrl"];
  7697. if(appDelegate.offline_mode)
  7698. {
  7699. params[@"contact_id"]=params[@"contactId"];
  7700. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7701. NSData* json = [[OLDataProvider offline_request_tearsheet:params] mutableCopy];
  7702. dispatch_async(dispatch_get_main_queue(), ^{
  7703. result([[RAConvertor data2dict:json] mutableCopy]);
  7704. });
  7705. });
  7706. return;
  7707. }
  7708. NSString * uuid= [[NSUUID UUID] UUIDString];
  7709. params[@"resultSerial"]=uuid;
  7710. __block bool bbreak = false;
  7711. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7712. for(int i=0;i<150;i++)
  7713. {
  7714. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7715. // result_params[@"resultSerial"]=uuid;
  7716. if(bbreak)
  7717. break;
  7718. dispatch_async(dispatch_get_main_queue(), ^{
  7719. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7720. if([resulti[@"result"] intValue]==2)
  7721. {
  7722. if(!bbreak)//此判断保证result只调用一次。
  7723. result(resulti);
  7724. bbreak=true;
  7725. }
  7726. } retry:3];
  7727. });
  7728. sleep(5);
  7729. }
  7730. });
  7731. //
  7732. // NSData* json= nil;
  7733. // if(appDelegate.offline_mode)
  7734. // {
  7735. // json= [OLDataProvider offline_request_tearsheet:params];
  7736. // }
  7737. // else
  7738. // {
  7739. // if(![self IsNetworkAvailable])
  7740. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7741. //
  7742. // NSError *error=nil;
  7743. //
  7744. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7745. // params[@"resultSerial"]=uuid;
  7746. //
  7747. // for(int i=0;i<150;i++)
  7748. // {
  7749. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7750. // // result_params[@"resultSerial"]=uuid;
  7751. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7752. // if(json!=nil)
  7753. // {
  7754. //
  7755. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7756. // if([jsobj[@"result"] intValue]==2)
  7757. // {
  7758. // break;
  7759. // }
  7760. // }
  7761. // sleep(5);
  7762. // }
  7763. // }
  7764. // if(json==nil)
  7765. // return nil;
  7766. // NSError *error=nil;
  7767. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7768. // return jsobj;
  7769. }
  7770. +(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
  7771. {
  7772. // for debug
  7773. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  7774. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7775. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7776. AppDelegate *appDelegate = nil;
  7777. //some UI methods ej
  7778. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7779. if(appDelegate.user!=nil)
  7780. [params setValue:appDelegate.user forKey:@"user"];
  7781. if(appDelegate.contact_id!=nil)
  7782. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7783. if(appDelegate.password!=nil)
  7784. [params setValue:appDelegate.password forKey:@"password"];
  7785. if(appDelegate.order_code!=nil)
  7786. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7787. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  7788. if (alert && qty && available && price && bestseller) {
  7789. [params setObject:@"Filter" forKey:kAction];
  7790. }
  7791. if ([RASingleton sharedInstance].homeItemClick) {
  7792. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  7793. [RASingleton sharedInstance].homeItemClick = NO;
  7794. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  7795. [RASingleton sharedInstance].homeClickedItemName = nil;
  7796. [params setObject:extra forKey:kExtra];
  7797. }
  7798. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7799. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7800. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  7801. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7802. // [params setValue:filter forKey:@"filter"];
  7803. [params setValue:covertype forKey:@"covertype"];
  7804. [params setValue:ctgid forKey:@"ctgId"];
  7805. [params setValue:modelname forKey:@"modelName"];
  7806. [params setValue:modeldescrip forKey:@"modelDescription"];
  7807. [params setValue:alert forKey:@"alert"];
  7808. [params setValue:qty forKey:@"sold_by_qty"];
  7809. [params setValue:available forKey:@"available"];
  7810. [params setValue:price forKey:@"price"];
  7811. [params setValue:bestseller forKey:@"bestseller"];
  7812. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7813. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7814. if(appDelegate.offline_mode)
  7815. {
  7816. // [OLDataProvider offline_itemsearch:params completionHandler:result];
  7817. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7818. NSMutableDictionary* json = [[OLDataProvider offline_itemsearch:params] mutableCopy];
  7819. dispatch_async(dispatch_get_main_queue(), ^{
  7820. result(json);
  7821. });
  7822. });
  7823. return;
  7824. }
  7825. [self request_interface:URL_ITEM_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  7826. // if(appDelegate.offline_mode)
  7827. // {
  7828. // return [OLDataProvider offline_itemsearch:params];
  7829. // }
  7830. // if(![self IsNetworkAvailable])
  7831. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7832. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  7833. // if(json==nil)
  7834. // return nil;
  7835. // NSError *error=nil;
  7836. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7837. // return jsobj;
  7838. }
  7839. +(void)request_modelqty: (NSString*) fashionId completionHandler:(resultHandler)result
  7840. {
  7841. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7842. AppDelegate *appDelegate = nil;
  7843. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7844. if(appDelegate.user!=nil)
  7845. [params setValue:appDelegate.user forKey:@"user"];
  7846. if(appDelegate.contact_id!=nil)
  7847. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7848. if(appDelegate.password!=nil)
  7849. [params setValue:appDelegate.password forKey:@"password"];
  7850. [params setValue:fashionId forKey:@"fashionId"];
  7851. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  7852. if(appDelegate.offline_mode)
  7853. {
  7854. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7855. NSData* json = [[OLDataProvider offline_model_qty:params] mutableCopy];
  7856. dispatch_async(dispatch_get_main_queue(), ^{
  7857. result([[RAConvertor data2dict:json] mutableCopy]);
  7858. });
  7859. });
  7860. return;
  7861. }
  7862. [self request_interface:URL_REQUEST_MODEL_QTY parameters:params err_record_url:nil completionHandler:result retry:0];
  7863. // NSData* json = nil;
  7864. // if(appDelegate.offline_mode)
  7865. // {
  7866. // json = [OLDataProvider offline_model_qty:params];
  7867. // } else {
  7868. // if(![self IsNetworkAvailable])
  7869. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7870. //
  7871. // json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  7872. // }
  7873. // if(json==nil)
  7874. // return nil;
  7875. // NSError *error=nil;
  7876. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7877. // return jsobj;
  7878. }
  7879. +(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
  7880. {
  7881. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7882. AppDelegate *appDelegate = nil;
  7883. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7884. if(appDelegate.user!=nil)
  7885. [params setValue:appDelegate.user forKey:@"user"];
  7886. if(appDelegate.contact_id!=nil)
  7887. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7888. if(appDelegate.password!=nil)
  7889. [params setValue:appDelegate.password forKey:@"password"];
  7890. [params setValue:watchlist_id forKey:@"item_id"];
  7891. // if(notes.length>0)
  7892. // [params setValue:notes forKey:@"notes"];
  7893. if(notes)
  7894. [params setValue:notes forKey:@"notes"];
  7895. if(price != -MAXFLOAT)
  7896. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  7897. if (discount != -MAXFLOAT)
  7898. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  7899. if(qty_p != -MAXFLOAT)
  7900. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  7901. if(qty != -INT32_MAX)
  7902. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  7903. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  7904. // NSData* json = nil;
  7905. if(appDelegate.offline_mode)
  7906. {
  7907. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7908. NSData* json = [[OLDataProvider offline_editPortfolio:params] mutableCopy];
  7909. dispatch_async(dispatch_get_main_queue(), ^{
  7910. result([[RAConvertor data2dict:json] mutableCopy]);
  7911. });
  7912. });
  7913. return;
  7914. }
  7915. [self request_interface:URL_PORTFOLIO_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  7916. //
  7917. // if(appDelegate.offline_mode)
  7918. // {
  7919. // json = [OLDataProvider offline_editPortfolio:params];
  7920. // } else {
  7921. // if(![self IsNetworkAvailable])
  7922. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7923. //
  7924. // json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  7925. // }
  7926. // if(json==nil)
  7927. // return nil;
  7928. // NSError *error=nil;
  7929. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7930. // return jsobj;
  7931. }
  7932. +(void)request_add_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7933. {
  7934. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7935. AppDelegate *appDelegate = nil;
  7936. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7937. if(appDelegate.user!=nil)
  7938. [params setValue:appDelegate.user forKey:@"user"];
  7939. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  7940. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7941. // else
  7942. if(appDelegate.contact_id!=nil)
  7943. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7944. if(appDelegate.password!=nil)
  7945. [params setValue:appDelegate.password forKey:@"password"];
  7946. // NSDictionary* customerinfo=nil;
  7947. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  7948. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7949. // else
  7950. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7951. //
  7952. // appDelegate.customerInfo;
  7953. // NSArray* keys=[customerinfo allKeys];
  7954. // for(int i=0;i<keys.count;i++)
  7955. // {
  7956. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7957. // }
  7958. // [params setValue:sourceid forKey:@"sourceid"];
  7959. // [params setValue:editor forKey:@"editor"];
  7960. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  7961. if(appDelegate.offline_mode)
  7962. {
  7963. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7964. NSData* json = [[OLDataProvider offline_saveNewContact:params] mutableCopy];
  7965. dispatch_async(dispatch_get_main_queue(), ^{
  7966. result([[RAConvertor data2dict:json] mutableCopy]);
  7967. });
  7968. });
  7969. return;
  7970. }
  7971. [self request_interface:URL_CUSTOMER_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  7972. //
  7973. // NSData* json=nil;
  7974. // if(appDelegate.offline_mode)
  7975. // {
  7976. // json= [OLDataProvider offline_saveNewContact:params];
  7977. // }
  7978. // else
  7979. // {
  7980. // if(![self IsNetworkAvailable])
  7981. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7982. //
  7983. // json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  7984. // }
  7985. //
  7986. // if(json!=nil)
  7987. // {
  7988. // NSError *error=nil;
  7989. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7990. // return jsobj;
  7991. // }
  7992. // else
  7993. // return nil;
  7994. }
  7995. +(void)request_update_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7996. {
  7997. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7998. AppDelegate *appDelegate = nil;
  7999. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8000. if(appDelegate.user!=nil)
  8001. [params setValue:appDelegate.user forKey:@"user"];
  8002. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  8003. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8004. // else
  8005. if(appDelegate.contact_id!=nil)
  8006. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8007. if(appDelegate.password!=nil)
  8008. [params setValue:appDelegate.password forKey:@"password"];
  8009. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8010. if(appDelegate.offline_mode)
  8011. {
  8012. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8013. NSData* json = [[OLDataProvider offline_saveContact:params] mutableCopy];
  8014. dispatch_async(dispatch_get_main_queue(), ^{
  8015. result([[RAConvertor data2dict:json] mutableCopy]);
  8016. });
  8017. });
  8018. return;
  8019. }
  8020. [self request_interface:URL_CUSTOMER_UPDATE parameters:params err_record_url:nil completionHandler:result retry:0];
  8021. //
  8022. // NSData* json=nil;
  8023. // if(appDelegate.offline_mode)
  8024. // {
  8025. // json= [OLDataProvider offline_saveContact:params];
  8026. // }
  8027. // else
  8028. // {
  8029. // if(![self IsNetworkAvailable])
  8030. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8031. //
  8032. // json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  8033. // }
  8034. //
  8035. // if(json!=nil)
  8036. // {
  8037. // NSError *error=nil;
  8038. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8039. // return jsobj;
  8040. // }
  8041. // else
  8042. // return nil;
  8043. }
  8044. +(void)request_delete_order:(NSString*) order_id completionHandler:(resultHandler)result
  8045. {
  8046. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8047. AppDelegate *appDelegate = nil;
  8048. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8049. if(appDelegate.user!=nil)
  8050. [params setValue:appDelegate.user forKey:@"user"];
  8051. // if(appDelegate.contact_id!=nil)
  8052. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8053. if(appDelegate.password!=nil)
  8054. [params setValue:appDelegate.password forKey:@"password"];
  8055. [params setValue:order_id forKey:@"orderId"];
  8056. // [params setValue:sourceid forKey:@"sourceid"];
  8057. // [params setValue:editor forKey:@"editor"];
  8058. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8059. if(appDelegate.offline_mode)
  8060. {
  8061. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8062. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8063. dispatch_async(dispatch_get_main_queue(), ^{
  8064. result(json);
  8065. });
  8066. });
  8067. return;
  8068. }
  8069. [self request_interface:URL_DELETE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8070. //
  8071. // if(appDelegate.offline_mode)
  8072. // {
  8073. // return [OLDataProvider offline_notimpl];
  8074. // }
  8075. // if(![self IsNetworkAvailable])
  8076. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8077. //
  8078. // NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  8079. // if(json!=nil)
  8080. // {
  8081. // NSError *error=nil;
  8082. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8083. //
  8084. //
  8085. // return jsobj;
  8086. // }
  8087. // else
  8088. // return nil;
  8089. }
  8090. +(void)request_cancel_order:(NSString*) order_id order_code:(NSString*) order_code completionHandler:(resultHandler)result
  8091. {
  8092. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8093. AppDelegate *appDelegate = nil;
  8094. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8095. if(appDelegate.user!=nil)
  8096. [params setValue:appDelegate.user forKey:@"user"];
  8097. // if(appDelegate.contact_id!=nil)
  8098. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8099. if(appDelegate.password!=nil)
  8100. [params setValue:appDelegate.password forKey:@"password"];
  8101. [params setValue:order_id forKey:@"orderId"];
  8102. [params setValue:order_code forKey:@"orderCode"];
  8103. // [params setValue:sourceid forKey:@"sourceid"];
  8104. // [params setValue:editor forKey:@"editor"];
  8105. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8106. if(appDelegate.offline_mode)
  8107. {
  8108. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8109. NSData* json = [[OLDataProvider offline_cancelorder:params] mutableCopy];
  8110. dispatch_async(dispatch_get_main_queue(), ^{
  8111. result([[RAConvertor data2dict:json] mutableCopy]);
  8112. });
  8113. });
  8114. return;
  8115. }
  8116. [self request_interface:URL_CANCEL_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8117. //
  8118. // NSData* json=nil;
  8119. // if(appDelegate.offline_mode)
  8120. // {
  8121. // json=[OLDataProvider offline_cancelorder:params];
  8122. // }
  8123. // else
  8124. // {
  8125. // if(![self IsNetworkAvailable])
  8126. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8127. // json=[self get_json:URL_CANCEL_ORDER parameters:params];
  8128. // }
  8129. // if(json!=nil)
  8130. // {
  8131. // NSError *error=nil;
  8132. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8133. //
  8134. //
  8135. // return jsobj;
  8136. // }
  8137. // else
  8138. // return nil;
  8139. }
  8140. +(void)request_release_order:(NSString*) order_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  8141. {
  8142. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8143. AppDelegate *appDelegate = nil;
  8144. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8145. if(appDelegate.user!=nil)
  8146. [params setValue:appDelegate.user forKey:@"user"];
  8147. // if(appDelegate.contact_id!=nil)
  8148. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8149. if(appDelegate.password!=nil)
  8150. [params setValue:appDelegate.password forKey:@"password"];
  8151. [params setValue:order_code forKey:@"orderCode"];
  8152. // [params setValue:sourceid forKey:@"sourceid"];
  8153. // [params setValue:editor forKey:@"editor"];
  8154. if (screenName) {
  8155. [params setValue:screenName forKey:kScreenName];
  8156. }
  8157. if(appDelegate.offline_mode)
  8158. {
  8159. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8160. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_resetorder:params]] mutableCopy];
  8161. dispatch_async(dispatch_get_main_queue(), ^{
  8162. if([[resulti valueForKey:@"result"]intValue]==2)
  8163. { [appDelegate SetSo:nil];
  8164. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8165. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8166. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8167. [appDelegate update_count_mark];
  8168. dispatch_async(dispatch_get_main_queue(), ^{
  8169. result(resulti);
  8170. });
  8171. }
  8172. });
  8173. });
  8174. return;
  8175. }
  8176. [self request_interface:URL_RELEASE_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8177. if([[resulti valueForKey:@"result"]intValue]==2)
  8178. { [appDelegate SetSo:nil];
  8179. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8180. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8181. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8182. [appDelegate update_count_mark];
  8183. dispatch_async(dispatch_get_main_queue(), ^{
  8184. result(resulti);
  8185. });
  8186. }
  8187. } retry:0];
  8188. //
  8189. // NSData* json=nil;
  8190. // if(appDelegate.offline_mode)
  8191. // {
  8192. // json= [OLDataProvider offline_resetorder:params];
  8193. // }
  8194. // else
  8195. // {
  8196. // if(![self IsNetworkAvailable])
  8197. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8198. //
  8199. // json=[self get_json:URL_RELEASE_ORDER parameters:params];
  8200. // }
  8201. // if(json!=nil)
  8202. // {
  8203. // NSError *error=nil;
  8204. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8205. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8206. // { [appDelegate SetSo:nil];
  8207. //
  8208. //
  8209. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8210. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8211. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8212. //
  8213. // [appDelegate update_count_mark];
  8214. // }
  8215. // return jsobj;
  8216. // }
  8217. // else
  8218. // return nil;
  8219. }
  8220. +(void)request_update_order_signature:(NSString*) order_code path:(NSString*)path completionHandler:(resultHandler)result
  8221. {
  8222. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8223. AppDelegate *appDelegate = nil;
  8224. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8225. if(appDelegate.user!=nil)
  8226. [params setValue:appDelegate.user forKey:@"user"];
  8227. if(appDelegate.contact_id!=nil)
  8228. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8229. if(appDelegate.password!=nil)
  8230. [params setValue:appDelegate.password forKey:@"password"];
  8231. // NSString* ssaved = @"false";
  8232. // if(saved)
  8233. // ssaved=@"true";
  8234. // [params setValue:@"true" forKey:@"saved"];
  8235. [params setValue:order_code forKey:@"orderCode"];
  8236. [params setValue:path forKey:@"picpath"];
  8237. // [params setValue:sourceid forKey:@"sourceid"];
  8238. // [params setValue:editor forKey:@"editor"];
  8239. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  8240. if(appDelegate.offline_mode)
  8241. {
  8242. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8243. NSData* json = [[OLDataProvider offline_signorder:params] mutableCopy];
  8244. dispatch_async(dispatch_get_main_queue(), ^{
  8245. result([[RAConvertor data2dict:json] mutableCopy]);
  8246. });
  8247. });
  8248. return;
  8249. }
  8250. [self request_interface:URL_SIGN_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8251. //
  8252. // NSData* json=nil;
  8253. // if(appDelegate.offline_mode)
  8254. // {
  8255. // json= [OLDataProvider offline_signorder:params];
  8256. // }
  8257. // else
  8258. // {
  8259. // if(![self IsNetworkAvailable])
  8260. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8261. //
  8262. // json=[self get_json:URL_SIGN_ORDER parameters:params];
  8263. // }
  8264. // if(json!=nil)
  8265. // {
  8266. // NSError *error=nil;
  8267. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8268. // return jsobj;
  8269. // }
  8270. // else
  8271. // return nil;
  8272. }
  8273. #ifdef SCANNER_ORDER
  8274. +(void) request_scan_bulkdiscount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8275. {
  8276. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  8277. //
  8278. //
  8279. // [appDelegate update_count_mark];
  8280. if(RASingleton.sharedInstance.price_type==0)
  8281. {
  8282. result(RASingleton.sharedInstance.scan_cart);
  8283. return;
  8284. }
  8285. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  8286. int count = [section[@"count"] intValue];
  8287. for(int i=0;i<count;i++)
  8288. {
  8289. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  8290. if ([item[@"special_price"] boolValue]||[item[@"net_price"] boolValue])
  8291. continue;
  8292. int item_count = [item[@"count"] intValue];
  8293. float price=[item[@"unit_price"] floatValue] ;
  8294. item[@"discount"] =@(discount);
  8295. // item[@"subtotal_price"] =@(price*item_count);
  8296. item[@"subtotal_price"]= [NSString stringWithFormat:@"%f",price*item_count*(1-discount/100.0)];
  8297. if(discount>0)
  8298. item[@"note"] =[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  8299. else
  8300. item[@"note"] =@"";
  8301. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  8302. }
  8303. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  8304. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  8305. result(RASingleton.sharedInstance.scan_cart);
  8306. AppDelegate *appDelegate = nil;
  8307. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8308. [OLDataProvider updateScanOrder:appDelegate.order_code];
  8309. return;
  8310. }
  8311. #endif
  8312. +(void) request_update_cart_modelprice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8313. {
  8314. AppDelegate *appDelegate = nil;
  8315. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8316. #ifdef SCANNER_ORDER
  8317. // return;
  8318. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  8319. {
  8320. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  8321. //
  8322. //
  8323. // [appDelegate update_count_mark];
  8324. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  8325. int count = [section[@"count"] intValue];
  8326. for(int i=0;i<count;i++)
  8327. {
  8328. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  8329. if([item[@"cart_item_id"] isEqualToString:cart_id])
  8330. {
  8331. int item_count = [item[@"count"] intValue];
  8332. item[@"unit_price"] =@(price);
  8333. item[@"discount"] =@(discount);
  8334. // item[@"subtotal_price"] =@(price*item_count);
  8335. item[@"subtotal_price"]= [NSString stringWithFormat:@"%f",price*item_count*(1-discount/100.0)];
  8336. if(discount>0)
  8337. item[@"note"] =[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  8338. else
  8339. item[@"note"] =@"";
  8340. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  8341. break;
  8342. }
  8343. }
  8344. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  8345. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  8346. result(RASingleton.sharedInstance.scan_cart);
  8347. [OLDataProvider updateScanOrder:appDelegate.order_code];
  8348. return;
  8349. }
  8350. #else
  8351. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8352. if(appDelegate.user!=nil)
  8353. [params setValue:appDelegate.user forKey:@"user"];
  8354. if(appDelegate.contact_id!=nil)
  8355. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8356. if(appDelegate.password!=nil)
  8357. [params setValue:appDelegate.password forKey:@"password"];
  8358. [params setValue:cart_id forKey:@"cartitem_id"];
  8359. [params setValue:notes forKey:@"item_note"];
  8360. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  8361. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  8362. [params setObject:ScreenCodeCart forKey:kScreenName];
  8363. if(appDelegate.offline_mode)
  8364. {
  8365. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8366. NSData* json = [[OLDataProvider offline_cartsetprice:params] mutableCopy];
  8367. dispatch_async(dispatch_get_main_queue(), ^{
  8368. result([[RAConvertor data2dict:json] mutableCopy]);
  8369. });
  8370. });
  8371. return;
  8372. }
  8373. [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8374. //
  8375. // NSData* json= nil;
  8376. // if(appDelegate.offline_mode)
  8377. // {
  8378. // json=[OLDataProvider offline_cartsetprice:params];
  8379. // }
  8380. // else
  8381. // {
  8382. // if(![self IsNetworkAvailable])
  8383. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8384. //
  8385. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8386. // }
  8387. // if(json==nil)
  8388. // return nil;
  8389. // NSError *error=nil;
  8390. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8391. // return jsobj;
  8392. #endif
  8393. }
  8394. +(void) request_addto_cart:(NSString* ) item_id count:(int) count name:(NSString *)name completionHandler:(resultHandler)result
  8395. {
  8396. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8397. AppDelegate *appDelegate = nil;
  8398. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8399. if(appDelegate.user!=nil)
  8400. [params setValue:appDelegate.user forKey:@"user"];
  8401. if(appDelegate.contact_id!=nil)
  8402. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8403. if(appDelegate.password!=nil)
  8404. [params setValue:appDelegate.password forKey:@"password"];
  8405. if(appDelegate.order_code!=nil)
  8406. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8407. [params setValue:item_id forKey:@"product_id"];
  8408. [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  8409. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  8410. [params setObject:@"Add To Cart" forKey:kAction];
  8411. if (name) {
  8412. NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  8413. [params setObject:extra forKey:kExtra];
  8414. }
  8415. NSDictionary* customerinfo= appDelegate.customerInfo;
  8416. NSArray* keys=[customerinfo allKeys];
  8417. for(int i=0;i<keys.count;i++)
  8418. {
  8419. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8420. }
  8421. if(appDelegate.offline_mode)
  8422. {
  8423. // [OLDataProvider offline_add2cart:params completionHandler:^(NSMutableDictionary *resulti) {
  8424. // NSMutableDictionary* json = resulti;
  8425. // if ([json[@"result"] intValue]==2)
  8426. // {
  8427. // appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  8428. //
  8429. // [appDelegate update_count_mark];
  8430. // }
  8431. // result(json);
  8432. // }];
  8433. params[@"can_create_backorder"]= @(appDelegate.can_create_backorder);
  8434. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8435. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cart:params]] mutableCopy];
  8436. dispatch_async(dispatch_get_main_queue(), ^{
  8437. if ([json[@"result"] intValue]==2)
  8438. {
  8439. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  8440. [appDelegate update_count_mark];
  8441. }
  8442. result(json);
  8443. });
  8444. });
  8445. return;
  8446. }
  8447. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8448. if ([resulti[@"result"] intValue]==2)
  8449. {
  8450. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8451. [appDelegate update_count_mark];
  8452. }
  8453. result(resulti);
  8454. } retry:0];
  8455. //
  8456. // NSData* json=nil;
  8457. // if(appDelegate.offline_mode)
  8458. // {
  8459. // json=[OLDataProvider offline_add2cart:params];
  8460. // }
  8461. // else
  8462. // {
  8463. // if(![self IsNetworkAvailable])
  8464. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8465. //
  8466. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  8467. // }
  8468. // if(json==nil)
  8469. // return nil;
  8470. // NSError *error=nil;
  8471. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8472. //
  8473. //
  8474. //
  8475. // int result = [[jsobj valueForKey:@"result"] intValue];
  8476. //
  8477. // if (result==2)
  8478. // {
  8479. //
  8480. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8481. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8482. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8483. //
  8484. // [appDelegate update_count_mark];
  8485. // }
  8486. //
  8487. // return jsobj;
  8488. }
  8489. //+(void) request_update_cart_modelfree:(NSString*) cart_id isfree:(bool) isfree completionHandler:(resultHandler)result
  8490. //{
  8491. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8492. // AppDelegate *appDelegate = nil;
  8493. //
  8494. //
  8495. //
  8496. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8497. //
  8498. // if(appDelegate.user!=nil)
  8499. // [params setValue:appDelegate.user forKey:@"user"];
  8500. // if(appDelegate.contact_id!=nil)
  8501. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8502. // if(appDelegate.password!=nil)
  8503. // [params setValue:appDelegate.password forKey:@"password"];
  8504. //
  8505. // [params setValue:cart_id forKey:@"cartitem_id"];
  8506. //
  8507. // [params setObject:ScreenCodeCart forKey:kScreenName];
  8508. //
  8509. // NSString* free=nil;
  8510. //
  8511. // if(isfree)
  8512. // free=@"true";
  8513. // else
  8514. // free=@"false";
  8515. //
  8516. // [params setValue:free forKey:@"free_giveaway"];
  8517. //
  8518. //
  8519. // if(appDelegate.offline_mode)
  8520. // {
  8521. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8522. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8523. // dispatch_async(dispatch_get_main_queue(), ^{
  8524. // result(json);
  8525. // });
  8526. // });
  8527. //
  8528. // return;
  8529. //
  8530. // }
  8531. // [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8532. //
  8533. ////
  8534. ////
  8535. //// if(appDelegate.offline_mode)
  8536. //// {
  8537. //// return [OLDataProvider offline_notimpl];
  8538. //// }
  8539. //// if(![self IsNetworkAvailable])
  8540. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8541. ////
  8542. //// NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8543. //// if(json==nil)
  8544. //// return nil;
  8545. //// NSError *error=nil;
  8546. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8547. //// return jsobj;
  8548. //}
  8549. +(void)request_retrieve_password: (NSString*) user email:(NSString*) email completionHandler:(resultHandler)result
  8550. {
  8551. AppDelegate *appDelegate = nil;
  8552. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8553. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8554. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8555. // if(appDelegate.user!=nil)
  8556. // [params setValue:appDelegate.user forKey:@"user"];
  8557. // if(appDelegate.contact_id!=nil)
  8558. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8559. // if(appDelegate.password!=nil)
  8560. // [params setValue:appDelegate.password forKey:@"password"];
  8561. [params setValue:user forKey:@"username"];
  8562. [params setValue:email forKey:@"email"];
  8563. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  8564. if(appDelegate.offline_mode)
  8565. {
  8566. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8567. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8568. dispatch_async(dispatch_get_main_queue(), ^{
  8569. result(json);
  8570. });
  8571. });
  8572. return;
  8573. }
  8574. #ifdef SCANNER_ORDER
  8575. params[@"site_name"]=[RADataProvider getSiteName];
  8576. params[@"_method"]=@"forgotPasswordOfflineOrderUser";
  8577. params[@"user"]=user;
  8578. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_RETRIEVE_PASS];
  8579. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  8580. #else
  8581. [self request_interface:URL_RETRIEVE_PASS parameters:params err_record_url:nil completionHandler:result retry:0];
  8582. #endif
  8583. //
  8584. //
  8585. // if(![self IsNetworkAvailable])
  8586. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8587. //
  8588. // NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  8589. // if(json==nil)
  8590. // return nil;
  8591. // NSError *error=nil;
  8592. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8593. // return jsobj;
  8594. }
  8595. +(void)request_update_ordercustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info completionHandler:(resultHandler)result
  8596. {
  8597. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8598. AppDelegate *appDelegate = nil;
  8599. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8600. if(appDelegate.user!=nil)
  8601. [info setValue:appDelegate.user forKey:@"user"];
  8602. // if(appDelegate.contact_id!=nil)
  8603. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8604. if(appDelegate.password!=nil)
  8605. [info setValue:appDelegate.password forKey:@"password"];
  8606. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8607. [info setValue:order_code forKey:@"orderCode"];
  8608. // [params setValue:sourceid forKey:@"sourceid"];
  8609. // [params setValue:editor forKey:@"editor"];
  8610. if(appDelegate.offline_mode)
  8611. {
  8612. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8613. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8614. dispatch_async(dispatch_get_main_queue(), ^{
  8615. result(json);
  8616. });
  8617. });
  8618. return;
  8619. }
  8620. [self request_interface:URL_UPDATE_ORDERCUSTOMER parameters:info err_record_url:nil completionHandler:result retry:0];
  8621. // if(appDelegate.offline_mode)
  8622. // {
  8623. // return [OLDataProvider offline_notimpl];
  8624. // }
  8625. // if(![self IsNetworkAvailable])
  8626. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8627. //
  8628. // NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  8629. // if(json!=nil)
  8630. // {
  8631. // NSError *error=nil;
  8632. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8633. // return jsobj;
  8634. // }
  8635. // else
  8636. // return nil;
  8637. }
  8638. +(void)request_update_customer_img: (NSString*) contactid img_url:(NSString*) url completionHandler:(resultHandler)result
  8639. {
  8640. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8641. AppDelegate *appDelegate = nil;
  8642. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8643. if(appDelegate.user!=nil)
  8644. [params setValue:appDelegate.user forKey:@"user"];
  8645. // if(appDelegate.contact_id!=nil)
  8646. if(appDelegate.password!=nil)
  8647. [params setValue:appDelegate.password forKey:@"password"];
  8648. [params setValue:contactid forKey:@"contactId"];
  8649. [params setValue:url forKey:@"business_card"];
  8650. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  8651. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8652. if(appDelegate.offline_mode)
  8653. {
  8654. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8655. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8656. dispatch_async(dispatch_get_main_queue(), ^{
  8657. result(json);
  8658. });
  8659. });
  8660. return;
  8661. }
  8662. [self request_interface:URL_UPDATE_CUSTOMER_BCARD parameters:params err_record_url:nil completionHandler:result retry:0];
  8663. // if(appDelegate.offline_mode)
  8664. // {
  8665. // return [OLDataProvider offline_notimpl];
  8666. // }
  8667. // if(![self IsNetworkAvailable])
  8668. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8669. //
  8670. // NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  8671. // if(json==nil)
  8672. // return nil;
  8673. // NSError *error=nil;
  8674. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8675. // return jsobj;
  8676. }
  8677. +(void)request_commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url completionHandler:(resultHandler)result
  8678. {
  8679. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8680. AppDelegate *appDelegate = nil;
  8681. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8682. if(appDelegate.user!=nil)
  8683. [params setValue:appDelegate.user forKey:@"user"];
  8684. if(appDelegate.contact_id!=nil)
  8685. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8686. if(appDelegate.password!=nil)
  8687. [params setValue:appDelegate.password forKey:@"password"];
  8688. // if(appDelegate.order_code!=nil)
  8689. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8690. // NSDictionary* customerinfo= appDelegate.customerInfo;
  8691. //
  8692. // NSArray* keys=[customerinfo allKeys];
  8693. // for(int i=0;i<keys.count;i++)
  8694. // {
  8695. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8696. // }
  8697. //
  8698. // [params setValue:sourceid forKey:@"sourceid"];
  8699. // [params setValue:editor forKey:@"editor"];
  8700. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  8701. if(appDelegate.offline_mode)
  8702. {
  8703. params[@"offline_Command"]=url;
  8704. [OLDataProvider offline_commoneditor_partialrefresh:params completionHandler:result];
  8705. //
  8706. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8707. // NSMutableDictionary* json = [[OLDataProvider offline_commoneditor_partialrefresh:params] mutableCopy];
  8708. // dispatch_async(dispatch_get_main_queue(), ^{
  8709. // result(json);
  8710. // });
  8711. // });
  8712. return;
  8713. }
  8714. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  8715. //
  8716. // if(appDelegate.offline_mode)
  8717. // {
  8718. // params[@"offline_Command"]=url;
  8719. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  8720. // }
  8721. //
  8722. // if(![self IsNetworkAvailable])
  8723. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8724. //
  8725. // NSData* json=[self get_json:url parameters:params];
  8726. // if(json!=nil)
  8727. // {
  8728. // NSError *error=nil;
  8729. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8730. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8731. // [appDelegate SetSo:nil];
  8732. //
  8733. //
  8734. // return jsobj;
  8735. // }
  8736. // else
  8737. // return nil;
  8738. }
  8739. +(void)request_add_address:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8740. {
  8741. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8742. AppDelegate *appDelegate = nil;
  8743. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8744. if(appDelegate.user!=nil)
  8745. [params setValue:appDelegate.user forKey:@"user"];
  8746. if(appDelegate.contact_id!=nil)
  8747. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8748. if(appDelegate.password!=nil)
  8749. [params setValue:appDelegate.password forKey:@"password"];
  8750. // [params setValue:sourceid forKey:@"sourceid"];
  8751. // [params setValue:editor forKey:@"editor"];
  8752. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  8753. if(appDelegate.offline_mode)
  8754. {
  8755. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8756. NSData* json = [[OLDataProvider offline_saveaddr:params] mutableCopy];
  8757. dispatch_async(dispatch_get_main_queue(), ^{
  8758. result([[RAConvertor data2dict:json] mutableCopy]);
  8759. });
  8760. });
  8761. return;
  8762. }
  8763. [self request_interface:URL_ADDRESS_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  8764. //
  8765. // NSData* json=nil;
  8766. //
  8767. // if(appDelegate.offline_mode)
  8768. // {
  8769. // json= [OLDataProvider offline_saveaddr:params];
  8770. // }
  8771. // else
  8772. // {
  8773. // if(![self IsNetworkAvailable])
  8774. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8775. //
  8776. // json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  8777. // }
  8778. // if(json!=nil)
  8779. // {
  8780. // NSError *error=nil;
  8781. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8782. // return jsobj;
  8783. // }
  8784. // else
  8785. // return nil;
  8786. }
  8787. +(void)request_commit_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8788. {
  8789. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8790. AppDelegate *appDelegate = nil;
  8791. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8792. if(appDelegate.user!=nil)
  8793. [params setValue:appDelegate.user forKey:@"user"];
  8794. if(appDelegate.contact_id!=nil)
  8795. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8796. if(appDelegate.password!=nil)
  8797. [params setValue:appDelegate.password forKey:@"password"];
  8798. if(appDelegate.order_code!=nil)
  8799. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8800. // NSDictionary* customerinfo= appDelegate.customerInfo;
  8801. //
  8802. // NSArray* keys=[customerinfo allKeys];
  8803. // for(int i=0;i<keys.count;i++)
  8804. // {
  8805. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8806. // }
  8807. //
  8808. // [params setValue:sourceid forKey:@"sourceid"];
  8809. // [params setValue:editor forKey:@"editor"];
  8810. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  8811. if(appDelegate.offline_mode)
  8812. {
  8813. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8814. NSData* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  8815. dispatch_async(dispatch_get_main_queue(), ^{
  8816. result([[RAConvertor data2dict:json] mutableCopy]);
  8817. });
  8818. });
  8819. return;
  8820. }
  8821. [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8822. //
  8823. // NSData* json=nil;
  8824. // if(appDelegate.offline_mode)
  8825. // {
  8826. // json=[OLDataProvider offline_submitorder:params];
  8827. // }
  8828. // else
  8829. // {
  8830. // if(![self IsNetworkAvailable])
  8831. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8832. //
  8833. // json=[self get_json:URL_COMMIT_ORDER parameters:params];
  8834. // }
  8835. // if(json!=nil)
  8836. // {
  8837. // NSError *error=nil;
  8838. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8839. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8840. // [appDelegate SetSo:nil];
  8841. //
  8842. //
  8843. // return jsobj;
  8844. // }
  8845. // else
  8846. // return nil;
  8847. }
  8848. +(void) request_new_offline_ticket:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid completionHandler:(resultHandler)result
  8849. {
  8850. // if(![self IsNetworkAvailable])
  8851. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8852. //
  8853. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8854. AppDelegate *appDelegate = nil;
  8855. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8856. if(appDelegate.user!=nil)
  8857. [params setValue:appDelegate.user forKey:@"user"];
  8858. // if(appDelegate.contact_id!=nil)
  8859. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8860. if(appDelegate.password!=nil)
  8861. [params setValue:appDelegate.password forKey:@"password"];
  8862. [params setValue:ver forKey:@"ver"];
  8863. [params setValue:vid forKey:@"vid"];
  8864. if(buseinternaladdress)
  8865. [params setValue:@"true" forKey:@"internal_address"];
  8866. else
  8867. [params setValue:@"false" forKey:@"internal_address"];
  8868. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  8869. // 无论当前是离线还是在线状态,都可以进行同步;
  8870. // if(appDelegate.offline_mode)
  8871. // {
  8872. //
  8873. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8874. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8875. // dispatch_async(dispatch_get_main_queue(), ^{
  8876. // result(json);
  8877. // });
  8878. // });
  8879. //
  8880. // return;
  8881. //
  8882. // }
  8883. [self request_interface:URL_CHECK_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  8884. //
  8885. // NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  8886. // if(json==nil)
  8887. // return nil;
  8888. // NSError *error=nil;
  8889. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8890. // // int result = [[jsobj valueForKey:@"result"] intValue];
  8891. // //
  8892. // // if (result==2)
  8893. // // {
  8894. // //
  8895. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8896. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  8897. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8898. // ////
  8899. // //// [appDelegate update_count_mark];
  8900. // // }
  8901. // return jsobj;
  8902. }
  8903. +(void) request_complete_offline_ticket:(NSString* )vid completionHandler:(resultHandler)result
  8904. {
  8905. // AppDelegate *appDelegate = nil;
  8906. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8907. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8908. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  8909. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8910. // if(appDelegate.user!=nil)
  8911. // [params setValue:appDelegate.user forKey:@"user"];
  8912. // // if(appDelegate.contact_id!=nil)
  8913. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8914. // if(appDelegate.password!=nil)
  8915. // [params setValue:appDelegate.password forKey:@"password"];
  8916. [params setValue:vid forKey:@"downSerial"];
  8917. // 无论当前是离线还是在线状态,都可以进行同步;
  8918. // if(appDelegate.offline_mode)
  8919. // {
  8920. //
  8921. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8922. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8923. // dispatch_async(dispatch_get_main_queue(), ^{
  8924. // result(json);
  8925. // });
  8926. // });
  8927. //
  8928. // return;
  8929. //
  8930. // }
  8931. [self request_interface:URL_FINISH_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  8932. // NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  8933. // if(json==nil)
  8934. // return nil;
  8935. // NSError *error=nil;
  8936. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8937. // // int result = [[jsobj valueForKey:@"result"] intValue];
  8938. // //
  8939. // // if (result==2)
  8940. // // {
  8941. // //
  8942. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8943. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  8944. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8945. // ////
  8946. // //// [appDelegate update_count_mark];
  8947. // // }
  8948. // return jsobj;
  8949. }
  8950. +(void) request_download_offline:(NSString* )vid completionHandler:(resultHandler)result
  8951. {
  8952. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8953. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  8954. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8955. // if(appDelegate.user!=nil)
  8956. // [params setValue:appDelegate.user forKey:@"user"];
  8957. // // if(appDelegate.contact_id!=nil)
  8958. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8959. // if(appDelegate.password!=nil)
  8960. // [params setValue:appDelegate.password forKey:@"password"];
  8961. [params setValue:vid forKey:@"downSerial"];
  8962. // AppDelegate *appDelegate = nil;
  8963. //
  8964. //
  8965. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8966. // if(appDelegate.offline_mode)
  8967. // {
  8968. //
  8969. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8970. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8971. // dispatch_async(dispatch_get_main_queue(), ^{
  8972. // result(json);
  8973. // });
  8974. // });
  8975. //
  8976. // return;
  8977. //
  8978. // }
  8979. __block bool bbreak = false;
  8980. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8981. __block NSMutableDictionary* download_json=nil;
  8982. int count=0;
  8983. // __block bool preparing = true;
  8984. while ([[download_json valueForKey:@"result"] intValue]!=2&&count<REQUEST_DOWNLOAD_RETRY_TIMES) //超过60分钟还没准被好数据就视为服务器出错。
  8985. {
  8986. if(bbreak)
  8987. break;
  8988. dispatch_async(dispatch_get_main_queue(), ^{
  8989. [self request_interface:URL_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8990. if([resulti[@"result"] intValue]==RESULT_TRUE)
  8991. {
  8992. if(!bbreak) //此判断保证result只调用一次。
  8993. {
  8994. // appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8995. // [appDelegate update_count_mark];
  8996. resulti[@"request_count"]=[NSNumber numberWithInt:count];
  8997. result(resulti);
  8998. }
  8999. bbreak=true;
  9000. }
  9001. else if([resulti[@"result"] intValue]==RESULT_ERROR)
  9002. {
  9003. result(resulti);
  9004. bbreak=true;
  9005. }
  9006. } retry:3];
  9007. });
  9008. sleep(RETRY_DELAY);
  9009. count++;
  9010. // download_json=[[RANetwork download_Offline:downSerial] mutableCopy];
  9011. //
  9012. // [RANetwork request_download_offline:downSerial completionHandler:^(NSMutableDictionary *result) {
  9013. // download_json=result;
  9014. // }];
  9015. //
  9016. }
  9017. // for(int i=0;i<150;i++)
  9018. // {
  9019. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  9020. // // result_params[@"resultSerial"]=uuid;
  9021. //
  9022. //
  9023. //
  9024. // sleep(2);
  9025. //
  9026. // // json=[self get_json:URL_CART parameters:params];
  9027. // // if(json!=nil)
  9028. // // {
  9029. // //
  9030. // // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9031. // // if([jsobj[@"result"] intValue]==2)
  9032. // // {
  9033. // // break;
  9034. // // }
  9035. // // }
  9036. //
  9037. // }
  9038. });
  9039. //
  9040. // NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  9041. // if(json==nil)
  9042. // return nil;
  9043. // NSError *error=nil;
  9044. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9045. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9046. // //
  9047. // // if (result==2)
  9048. // // {
  9049. // //
  9050. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9051. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9052. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9053. // ////
  9054. // //// [appDelegate update_count_mark];
  9055. // // }
  9056. // return jsobj;
  9057. }
  9058. + (void)request_fastupload:(NSMutableDictionary *)params filename:(NSString*)filename data:(NSData*) data url:(NSString *)url completionHandler:(resultHandler)result
  9059. {
  9060. //#ifdef test_server
  9061. // url=URL_REQUEST_RECORDS;
  9062. // params[@"prefix"]=URL_REQUEST_RECORDS;
  9063. //#endif
  9064. // [self request_file_fast:url parameters:params completionHandler:result];
  9065. #ifdef SCANNER_ORDER
  9066. params[@"site_name"]=[RADataProvider getSiteName];
  9067. #endif
  9068. [self request_upload_fast:data FileName:filename server:url parameters:params completionHandler:result];
  9069. }
  9070. +(void)request_err_log:(NSString*) up_params result:(NSString*)result_str module:(NSString*) module code:(int) code completionHandler:(resultHandler)result
  9071. {
  9072. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9073. AppDelegate *appDelegate = nil;
  9074. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9075. if(appDelegate.user!=nil)
  9076. [params setValue:appDelegate.user forKey:@"user"];
  9077. [params setValue:up_params forKey:@"upparam"];
  9078. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  9079. [params setValue:result_str forKey:@"result"];
  9080. [params setValue:module forKey:@"interfac"];
  9081. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  9082. // [params setValue:module forKey:@"module"];
  9083. // [[UIDevice currentDevice] name];
  9084. // if(appDelegate.offline_mode)
  9085. // {
  9086. // return [OLDataProvider offline_notimpl];
  9087. // }
  9088. if(appDelegate.offline_mode)
  9089. {
  9090. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9091. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9092. dispatch_async(dispatch_get_main_queue(), ^{
  9093. result(json);
  9094. });
  9095. });
  9096. return;
  9097. }
  9098. [self request_interface:URL_ERR_LOG parameters:params err_record_url:nil completionHandler:result retry:0];
  9099. //
  9100. // if(![self IsNetworkAvailable])
  9101. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9102. //
  9103. // NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  9104. // if(json==nil)
  9105. // return nil;
  9106. // NSError *error=nil;
  9107. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9108. // return jsobj;
  9109. }
  9110. @end