RANetwork.m 416 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415
  1. //
  2. // iSalesNetwork.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-6-20.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RANetwork.h"
  9. #import "RAUtils.h"
  10. #import "RASingleton.h"
  11. #ifdef GOOGLE_ANALYTICS
  12. #import "GoogleAnalyst.h"
  13. #endif
  14. #import "ERPUtils.h"
  15. #import "RAConvertor.h"
  16. #import "ActiveViewController.h"
  17. #import "ZipArchive.h"
  18. #import "RADataProvider.h"
  19. NSString *const kScreenName = @"kScreenName";
  20. NSString *const kAction = @"kAction";
  21. NSString *const kExtra = @"kExtra";
  22. NSString *const ScreenCodeLoginView = @"Login Screen";
  23. NSString *const ScreenCodeHomeView = @"Home Screen";
  24. NSString *const ScreenCodeCategory = @"Category Screen";
  25. NSString *const ScreenCodeCart = @"Cart Sceen";
  26. NSString *const ScreenCodeOrderList = @"Order History Screen";
  27. NSString *const ScreenCodeSearch = @"Search Screen";
  28. NSString *const ScreenCodeAccount = @"Account Screen";
  29. NSString *const ScreenCodeWishList = @"Wish List Screen";
  30. NSString *const ScreenCodePortfolio = @"Portfolio Screen";
  31. NSString *const ScreenCodeViewPortfolios = @"View Portfolios Screen";
  32. NSString *const ScreenCodeCamScan = @"Cam Scan Screen";
  33. NSString *const ScreenCodeScannerSetting = @"Scanner Setting Screen";
  34. NSString *const ScreenCodeOfflineSetting = @"Offline Setting Screen";
  35. NSString *const ScreenCodePlaceOrder = @"Place Order Screen";
  36. NSString *const ScreenCodeCustomerInfo = @"Customer Information Screen";
  37. NSString *const ScreenCodeNewCustomer = @"New Customer Screen";
  38. NSString *const ScreenCodeEditCustomer = @"Edit Customer Information Screen";
  39. NSString *const ScreenCodeModelInfo = @"Model Information Screen";
  40. NSString *const ScreenCodeOrderInfo = @"Order Information Screeen";
  41. NSString *const ScreenCodeUserSign = @"User Sign Screen";
  42. NSString *const ScreenCodeNewAddress = @"New Address Screen";
  43. NSString *const ScreenCodeAdvanceSearch = @"Account Advance Search Screen";
  44. NSString *const ScreenCodeCreatePortfolio = @"Create Portfolio Screen";
  45. NSString *const ScreenCodeParticularCategory = @"Particular Category Screen";
  46. NSString *const ScreenCodeEditPortfolio = @"Edit Portfolio Screen";
  47. NSString *const ScreenCodePriceSetting = @"Price Setting Screen";
  48. NSString *const ScreenCodeCategoryPrice = @"Category Price Screen";
  49. NSString *const ScreenCodeSetCatetoryPrice = @"Set Category Price Screen";
  50. NSString *const ScreenCodeUploadImage = @"Upload Image Screen";
  51. NSString *const ScreenCodeOfflineSync = @"Offline Sync Screen";
  52. @implementation RANetwork
  53. +(NSMutableDictionary*) prepare_additional_params:(NSMutableDictionary* ) params
  54. {
  55. AppDelegate *appDelegate = nil;
  56. //some UI methods ej
  57. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  58. // if(appDelegate.user!=nil)
  59. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.user key:@"usai"] forKey:@"user"];
  60. // if(appDelegate.password!=nil)
  61. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.password key:@"usai"] forKey:@"password"];
  62. //
  63. //
  64. //
  65. // if(appDelegate.user!=nil)
  66. // [params setValue:appDelegate.user forKey:@"user"];
  67. //
  68. // if(appDelegate.contact_id!=nil)
  69. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  70. // if(appDelegate.password!=nil)
  71. // [params setValue:appDelegate.password forKey:@"password"];
  72. //
  73. // [params setValue:appDelegate.build forKey:@"app_ver"];
  74. //
  75. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  76. // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  77. // [params setValue:short_version forKey:@"app_short_ver"];
  78. //
  79. //
  80. //
  81. //#if TARGET_IPHONE_SIMULATOR//模拟器
  82. // [params setValue:@"simulator_uuid" forKey:@"deviceid"];
  83. //#elif TARGET_OS_IPHONE//真机
  84. // UIDevice * dev = [UIDevice currentDevice];
  85. // NSUUID* uuid =dev.identifierForVendor;
  86. // [params setValue:uuid.UUIDString forKey:@"deviceid"];
  87. //#endif
  88. if(appDelegate.user!=nil && params[@"user"]==nil)
  89. [params setValue:appDelegate.user forKey:@"user"];
  90. if(appDelegate.password!=nil&& params[@"password"]==nil)
  91. [params setValue:appDelegate.password forKey:@"password"];
  92. if(appDelegate.ipad_perm!=nil)
  93. [params setValue:appDelegate.ipad_perm forKey:@"ipad_perm"];
  94. [params setValue:appDelegate.build forKey:@"app_ver"];
  95. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  96. NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  97. [params setValue:short_version forKey:@"app_short_ver"];
  98. #if TARGET_IPHONE_SIMULATOR//模拟器
  99. [params setValue:@"simulator_uuid" forKey:@"idfv"];
  100. #elif TARGET_OS_IPHONE//真机
  101. UIDevice * dev = [UIDevice currentDevice];
  102. NSUUID* uuid =dev.identifierForVendor;
  103. [params setValue:uuid.UUIDString forKey:@"idfv"];
  104. #endif
  105. //
  106. // NSString *userAction = [params valueForKey:kAction];
  107. // NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  108. // if ([userAction isEqualToString:@"Login"]) {
  109. // if (!extra) {
  110. // extra = [NSMutableDictionary dictionary];
  111. // }
  112. // [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  113. // }
  114. return params;
  115. }
  116. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString *) file //delegate:(id < NSURLConnectionDelegate >)delegate
  117. {
  118. // NSString* e=[AESCrypt AES128Encrypt:@"密码学中的高级加密标准(Advanced Encryption Standard,AES),又称 高级加密标准Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用。经过五年的甄选流程,高级加密标准由美国国家标准与技术研究院 (NIST)于2001年11月26日发布于FIPS PUB 197,并在2002年5月26日成为有效的标准。2006年,高级加密标准已然成为对称密钥加密中最流行的算法之一。 " key:@"usai2010"];
  119. // DebugLog(e);
  120. // NSString* d=[AESCrypt decrypt:@"VzB4+lENfbzWX7ggHh2Os1P69l5YBzKmM51yqA37AfoKgPY8bJgdK8M4WvF+wDyOsLWP\/o8H5+bHMivQp1u8wM2QV7SYzgzPwV85QKtYWIzEgLe9T0HO69EdutWz7k1rdAT\/mftsRin0Hy5SHk7txTZT\/zPH5X+FQiExCTFm5Zus39HYvp+VxCX4+kYeymn8B63AUd3mRQyscUvDjfgU2olKR\/TP8PV3g+VQMZxpKfol3P1iOtz3XQlHZV0pM6SAf+SwT0sPfrdn6CZFfNQlrKA9QjMrnBdMeSCquSIWXnmLv6okzvnlJnT0SjvJuUeqNdBC5EZ0ACnhI0MrXVZEsq1EuM9al7oPzvU5EZbjZpmx+fSFIkMzTT8bYClTnG1bsL1MCcU4pSODDorUj8zalA==" password:@"usai2010"];
  121. params = [self prepare_additional_params:params];
  122. DebugLog(@"\n++++++++++++++++++++++Request++++++++++++++++++++++\n%@\n++++++++++++++++++++++Params++++++++++++++++++++++\n%@\n",url,[RAConvertor dict2string:params]);
  123. return [super get_json:url parameters:params file:(NSString*)file err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  124. int result=[[jsobj valueForKey:@"result"] intValue];
  125. // UIApplication * app = [UIApplication sharedApplication];
  126. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  127. switch (result) {
  128. case 0:
  129. [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  130. break;
  131. case 1:
  132. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  133. break;
  134. case 2:
  135. [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  136. break;
  137. case 8:
  138. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  139. break;
  140. case 9:
  141. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  142. break;
  143. case 99:
  144. [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  145. break;
  146. default:
  147. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  148. break;
  149. }
  150. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  151. // {
  152. // [jsobj setValue:@"9" forKey:@"result"];
  153. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  154. // }
  155. return jsobj;
  156. } decrypt_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  157. return nil;
  158. // NSString* base64str = jsobj[@"str"];
  159. // NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"usai2010"];
  160. // jsobj=[[RAUtils string2dict:decryptstr] mutableCopy];
  161. // return jsobj;
  162. }];
  163. /*
  164. */
  165. return nil;
  166. }
  167. +(void) LoadImage:(NSString*) url into:(UIImageView*) container
  168. {
  169. DebugLog(@"LoadImage:(NSString*) url in:(UIImageView*) container");
  170. NSString* file_name=[url lastPathComponent];
  171. NSData* img_data = [iSalesDB load_cached_img:file_name loadFrom:url];
  172. if(img_data==nil)
  173. {
  174. DebugLog(@"IMG NOT CACHED %@",file_name);
  175. img_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
  176. [iSalesDB cache_img:img_data filename:file_name saveTo:url];
  177. //load from internet;
  178. }
  179. if(img_data!=nil)
  180. {
  181. UIImage * img =[UIImage imageWithData:img_data];
  182. if(img==nil)
  183. DebugLog(@"UIIMAGE IS NIL! %@",file_name);
  184. else
  185. dispatch_async(dispatch_get_main_queue(), ^{
  186. container.image =img;
  187. });
  188. }
  189. else
  190. {
  191. DebugLog(@"IMG DOWNLOAD FAILED! %@",file_name);
  192. }
  193. }
  194. //+(NSData*)fake_json:(NSString*) url
  195. //{
  196. // NSString* jsonfile = nil;
  197. // if([url isEqualToString:URL_UPDATE_AUTH])
  198. // {
  199. // jsonfile=@"login";
  200. //
  201. // }
  202. // else if([url isEqualToString:URL_REQUEST_CATMENU])
  203. // {
  204. // jsonfile=@"categorymenu";
  205. // }
  206. // else if([url isEqualToString:URL_LOAD_HOME])
  207. // {
  208. // jsonfile=@"homepage";
  209. // }
  210. // else if([url isEqualToString:URL_SEARCH])
  211. // {
  212. // jsonfile=@"search";
  213. // }
  214. // else if([url isEqualToString:URL_CATEGORY_LOADMORE])
  215. // {
  216. // jsonfile=@"category_more";
  217. // }else if([url isEqualToString:URL_ITEM_DETAIL])
  218. // {
  219. // jsonfile=@"detail";
  220. // }else if([url isEqualToString:URL_CART])
  221. // {
  222. // jsonfile=@"cart";
  223. // }else if([url isEqualToString:URL_ORDER_LIST])
  224. // {
  225. // jsonfile=@"orderlist";
  226. // }
  227. //// else if([url isEqualToString:URL_ORDER_INFO])
  228. //// {
  229. //// jsonfile=@"orderinfo";
  230. //// }
  231. //// else if([url isEqualToString:URL_ORDER_INFO])
  232. //// {
  233. //// jsonfile=@"orderinfo2label";
  234. //// }
  235. //
  236. //
  237. //
  238. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:jsonfile ofType:@"json" ]];
  239. // NSMutableString *result = [[NSMutableString alloc] initWithData:json encoding:NSUTF8StringEncoding];
  240. //
  241. // DebugLog(@"result: \n%@",result);
  242. // return json;
  243. //}
  244. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
  245. {
  246. NSString *screenName = [params valueForKey:kScreenName];
  247. NSString *userAction = [params valueForKey:kAction];
  248. NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  249. if ([userAction isEqualToString:@"Login"]) {
  250. if (!extra) {
  251. extra = [NSMutableDictionary dictionary];
  252. }
  253. [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  254. }
  255. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  256. [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  257. #endif
  258. return [self get_json:url parameters:params file:nil];
  259. // {
  260. // int retry = 0;
  261. //
  262. // __block AppDelegate *appDelegate = nil;
  263. //
  264. // dispatch_sync(dispatch_get_main_queue(), ^{
  265. // //some UI methods ej
  266. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  267. // });
  268. // if(appDelegate.user!=nil)
  269. // [params setValue:appDelegate.user forKey:@"user"];
  270. // if(appDelegate.password!=nil)
  271. // [params setValue:appDelegate.password forKey:@"password"];
  272. //
  273. //
  274. // if(appDelegate.ipad_perm!=nil)
  275. // [params setValue:appDelegate.ipad_perm forKey:@"ipad_perm"];
  276. //
  277. // [params setValue:appDelegate.build forKey:@"app_ver"];
  278. //
  279. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  280. // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  281. // [params setValue:short_version forKey:@"app_short_ver"];
  282. //
  283. // UIDevice * dev = [UIDevice currentDevice];
  284. // NSUUID* uuid =dev.identifierForVendor;
  285. //#if TARGET_IPHONE_SIMULATOR//模拟器
  286. // [params setValue:@"simulator_uuid" forKey:@"idfv"];
  287. //#elif TARGET_OS_IPHONE//真机
  288. // [params setValue:uuid.UUIDString forKey:@"idfv"];
  289. //#endif
  290. //
  291. //// NSString *screenName = [params valueForKey:kScreenName];
  292. //// NSString *userAction = [params valueForKey:kAction];
  293. //// NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  294. //// if ([userAction isEqualToString:@"Login"]) {
  295. //// if (!extra) {
  296. //// extra = [NSMutableDictionary dictionary];
  297. //// }
  298. //// [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  299. //// }
  300. //
  301. //repeat:
  302. // {
  303. //
  304. // // return [self fake_json:url];
  305. //
  306. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  307. // //分界线的标识符
  308. // NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
  309. // //根据url初始化request
  310. // NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
  311. // cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
  312. // timeoutInterval:JSON_TIMEOUT];
  313. // //分界线 --AaB03x
  314. // NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
  315. // //结束符 AaB03x--
  316. // NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
  317. // //要上传的图片
  318. // // UIImage *image=[params objectForKey:@"pic"];
  319. // //得到图片的data
  320. // // NSData* data = UIImagePNGRepresentation(image);
  321. // //http body的字符串
  322. // NSMutableString *body=[[NSMutableString alloc]init];
  323. //
  324. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  325. // // [params setValue:@"handset_login" forKey:@"action"];
  326. // // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  327. //
  328. // // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  329. // // [params setValue:password forKey:@"password"];
  330. // // [params setValue:[NSString stringWithFormat:@"%d",ver] forKey:@"auth_ver"];
  331. //
  332. //
  333. //
  334. // // [headers setValue:headQuerlString forKey:@"param"];
  335. //
  336. // //参数的集合的所有key的集合
  337. // NSArray *keys= [params allKeys];
  338. // DebugLog(@"================parms==================");
  339. // //遍历keys
  340. // for(int i=0;i<[keys count];i++)
  341. // {
  342. // //得到当前key
  343. // NSString *key=[keys objectAtIndex:i];
  344. // //如果key不是pic,说明value是字符类型,比如name:Boris
  345. // if(![key isEqualToString:@"pic"])
  346. // {
  347. // //添加分界线,换行
  348. // [body appendFormat:@"%@\r\n",MPboundary];
  349. // //添加字段名称,换2行
  350. // [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
  351. // //添加字段的值
  352. // [body appendFormat:@"%@\r\n",[params objectForKey:key]];
  353. // DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
  354. // }
  355. // }
  356. // DebugLog(@"================parms==================");
  357. // ////添加分界线,换行
  358. // [body appendFormat:@"%@\r\n",MPboundary];
  359. // //声明pic字段,文件名为boris.png
  360. // [body appendFormat:@"Content-Disposition: form-data; name=\"pic\"; filename=\"boris.png\"\r\n"];
  361. // //声明上传文件的格式
  362. // [body appendFormat:@"Content-Type: image/png\r\n\r\n"];
  363. //
  364. // //声明结束符:--AaB03x--
  365. // NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
  366. // //声明myRequestData,用来放入http body
  367. // NSMutableData *myRequestData=[NSMutableData data];
  368. // //将body字符串转化为UTF8格式的二进制
  369. // [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
  370. // //将image的data加入
  371. // // [myRequestData appendData:data];
  372. // //加入结束符--AaB03x--
  373. // [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
  374. //
  375. // //设置HTTPHeader中Content-Type的值
  376. // NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
  377. // //设置HTTPHeader
  378. // [request setValue:content forHTTPHeaderField:@"Content-Type"];
  379. //
  380. // // 关闭keep alive
  381. // [request setValue:@"close" forHTTPHeaderField:@"Connection"];
  382. // //设置Content-Length
  383. // [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[myRequestData length]] forHTTPHeaderField:@"Content-Length"];
  384. // //设置http body
  385. // [request setHTTPBody:myRequestData];
  386. // //http method
  387. // [request setHTTPMethod:@"POST"];
  388. //
  389. //
  390. // NSHTTPURLResponse* urlResponse = nil;
  391. //
  392. // NSError *error = nil;
  393. //
  394. // NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  395. //
  396. //
  397. // DebugLog(@"url: %@",url);
  398. //
  399. // DebugLog(@"response: %@",[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode]);
  400. //
  401. // if (responseData==nil) {
  402. //
  403. //// DebugLog(@"response error:%@", [error localizedDescription]);
  404. //
  405. //
  406. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  407. // //#define RESULT_FALSE 0
  408. // //#define RESULT_TRUE 2
  409. // //#define RESULT_NET_ERROR -3
  410. // //#define RESULT_NET_NOTAVAILABLE -4
  411. // //#define RESULT_ERROR -5
  412. // //#define RESULT_LOCALFILE_ERROR -7
  413. // //#define RESULT_USERAUTH_ERROR -9
  414. // //#define RESULT_UPDATE_USERAUTH_ERROR -11
  415. // //#define RESULT_SESSION_EXPIRED -13
  416. // //#define RESULT_VER_LOW
  417. //
  418. // // NSString * moreinfo = error.description ;
  419. //
  420. // NSString* err_msg = [error localizedDescription];
  421. //
  422. //
  423. // //-----------------retry 3 times for error code -1005------------------------
  424. // if(error.code==-1005&&retry<3)
  425. // {
  426. // retry++;
  427. // goto repeat;
  428. //
  429. // }
  430. // //-----------------end retry 3 times for error code -1005------------------------
  431. //
  432. // NSDictionary* error_json = [RAUtils error_dict:error];
  433. // [ret setObject:error_json forKey:@"err_obj"];
  434. // NSString* resp_msg= nil;
  435. //
  436. // if(err_msg.length==0)
  437. // {
  438. // err_msg =[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode];
  439. // resp_msg = err_msg;
  440. // }
  441. // [ret setValue:[NSString stringWithFormat:@"%d",RESULT_NET_ERROR] forKey:@"result"];
  442. // [ret setValue:err_msg forKey:@"err_msg"];
  443. // [ret setValue:resp_msg forKey:@"resp_msg"];
  444. // [ret setValue:[NSString stringWithFormat:@"%ld",(long)urlResponse.statusCode] forKey:@"resp_code"];
  445. //
  446. //
  447. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ret
  448. // options:0
  449. // error:nil];
  450. // if(![url isEqualToString:URL_ERR_LOG])
  451. // {
  452. // [RANetwork err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:[RAConvertor dict2string:ret]] module:url code:RESULT_NET_ERROR];
  453. // }
  454. //#if defined(BUILD_NPD)// || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  455. // [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  456. //#endif
  457. // return jsonData;
  458. //
  459. // }
  460. // else
  461. // {
  462. // NSString* err_msg = [error localizedDescription];
  463. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  464. //
  465. // DebugLog(@"data string: %@",str);
  466. // NSError *error1 = nil;
  467. //
  468. // NSMutableDictionary* jsobj = [[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error1] mutableCopy];
  469. //
  470. // if(jsobj==nil)// 服务器返回不是json
  471. // {
  472. //
  473. // jsobj=[[NSMutableDictionary alloc] init];
  474. // [jsobj setValue:@"1" forKey:@"result"];
  475. //
  476. // }
  477. //
  478. // int result=[[jsobj valueForKey:@"result"] intValue];
  479. // UIApplication * app = [UIApplication sharedApplication];
  480. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  481. // NSString* mode =[jsobj valueForKey:@"mode"];
  482. // [appDelegate SetMode:mode];
  483. // switch (result) {
  484. // case 0:
  485. // [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  486. // break;
  487. // case 1:
  488. // [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  489. // break;
  490. // case 2:
  491. // [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  492. // break;
  493. // case 8:
  494. // [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  495. // break;
  496. // case 9:
  497. // [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  498. // break;
  499. // case 99:
  500. // [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  501. // break;
  502. // default:
  503. // [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  504. // break;
  505. // }
  506. //
  507. //
  508. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  509. // {
  510. // [jsobj setValue:@"9" forKey:@"result"];
  511. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  512. // }
  513. //
  514. // if(![url isEqualToString:URL_ERR_LOG]&&![url isEqualToString:URL_DOWNLOAD_OFFLINE]/*&&result!=-3*/&&result!=2&&result!=99)
  515. // {
  516. // [RANetwork err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:str] module:url code:result];
  517. // }
  518. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsobj
  519. // options:0
  520. // error:nil];
  521. //#if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  522. // [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  523. //#endif
  524. // return jsonData;
  525. //
  526. // }
  527. //
  528. // return responseData;
  529. // }
  530. //}
  531. }
  532. //+(NSDictionary*)request_Editor:(NSString*) sourceid editor:(NSString*)editor
  533. //{
  534. //
  535. //}
  536. +(NSDictionary*) delete_portfoliolist:(NSString* ) listid
  537. {
  538. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  539. __block AppDelegate *appDelegate = nil;
  540. dispatch_sync(dispatch_get_main_queue(), ^{
  541. //some UI methods ej
  542. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  543. });
  544. if(appDelegate.user!=nil)
  545. [params setValue:appDelegate.user forKey:@"user"];
  546. if(appDelegate.contact_id!=nil)
  547. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  548. if(appDelegate.password!=nil)
  549. [params setValue:appDelegate.password forKey:@"password"];
  550. [params setValue:listid forKey:@"tearsheetsId"];
  551. // [params setValue:editor forKey:@"editor"];
  552. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  553. // [params setValue:@"Delete Portfolio" forKey:kAction];
  554. NSData* json = nil;
  555. if(appDelegate.offline_mode)
  556. {
  557. json = [OLDataProvider offline_removePDF:params];
  558. } else {
  559. if(![self IsNetworkAvailable])
  560. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  561. json=[self get_json:URL_PORTFOLIOLIST_REMOVE parameters:params];
  562. }
  563. if(json!=nil)
  564. {
  565. NSError *error=nil;
  566. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  567. return jsobj;
  568. }
  569. else
  570. return nil;
  571. }
  572. +(NSDictionary*) portfolio_remove:(NSString* ) item_ids
  573. {
  574. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  575. __block AppDelegate *appDelegate = nil;
  576. dispatch_sync(dispatch_get_main_queue(), ^{
  577. //some UI methods ej
  578. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  579. });
  580. if(appDelegate.user!=nil)
  581. [params setValue:appDelegate.user forKey:@"user"];
  582. if(appDelegate.contact_id!=nil)
  583. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  584. if(appDelegate.password!=nil)
  585. [params setValue:appDelegate.password forKey:@"password"];
  586. [params setValue:item_ids forKey:@"portfolioId"];
  587. // [params setValue:editor forKey:@"editor"];
  588. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  589. NSData* json = nil;
  590. if(appDelegate.offline_mode)
  591. {
  592. json = [OLDataProvider offline_removePortfolio:params];
  593. } else {
  594. if(![self IsNetworkAvailable])
  595. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  596. json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  597. }
  598. if(json!=nil)
  599. {
  600. NSError *error=nil;
  601. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  602. int result = [[jsobj valueForKey:@"result"] intValue];
  603. if (result==2)
  604. {
  605. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  606. [appDelegate update_count_mark];
  607. }
  608. return jsobj;
  609. }
  610. else
  611. return nil;
  612. }
  613. //+(NSDictionary*) watchlist_remove:(NSString* ) item_ids
  614. //{
  615. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  616. // __block AppDelegate *appDelegate = nil;
  617. //
  618. // dispatch_sync(dispatch_get_main_queue(), ^{
  619. // //some UI methods ej
  620. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  621. // });
  622. // if(appDelegate.user!=nil)
  623. // [params setValue:appDelegate.user forKey:@"user"];
  624. // if(appDelegate.contact_id!=nil)
  625. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  626. // if(appDelegate.password!=nil)
  627. // [params setValue:appDelegate.password forKey:@"password"];
  628. // [params setValue:item_ids forKey:@"collectId"];
  629. // // [params setValue:editor forKey:@"editor"];
  630. //
  631. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  632. //
  633. // if(appDelegate.offline_mode)
  634. // {
  635. // return [OLDataProvider offline_deletewishlist:params];
  636. // }
  637. // if(![self IsNetworkAvailable])
  638. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  639. //
  640. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  641. // if(json!=nil)
  642. // {
  643. // NSError *error=nil;
  644. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  645. // int result = [[jsobj valueForKey:@"result"] intValue];
  646. //
  647. // if (result==2)
  648. // {
  649. //
  650. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  651. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  652. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  653. //
  654. // [appDelegate update_count_mark];
  655. // }
  656. // return jsobj;
  657. // }
  658. // else
  659. // return nil;
  660. //}
  661. //+(NSDictionary*) move_cart2wish:(NSString* ) item_ids
  662. //{
  663. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  664. // __block AppDelegate *appDelegate = nil;
  665. //
  666. // dispatch_sync(dispatch_get_main_queue(), ^{
  667. // //some UI methods ej
  668. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  669. // });
  670. // if(appDelegate.user!=nil)
  671. // [params setValue:appDelegate.user forKey:@"user"];
  672. // if(appDelegate.contact_id!=nil)
  673. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  674. // if(appDelegate.password!=nil)
  675. // [params setValue:appDelegate.password forKey:@"password"];
  676. // if(appDelegate.order_code!=nil)
  677. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  678. // [params setValue:item_ids forKey:@"cartItemId"];
  679. // // [params setValue:editor forKey:@"editor"];
  680. //
  681. // [params setValue:ScreenCodeCart forKey:kScreenName];
  682. // // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  683. //
  684. // NSData* json = nil;
  685. // if(appDelegate.offline_mode)
  686. // {
  687. // json= [OLDataProvider offline_movecart2wish:params];
  688. // }
  689. // else
  690. // {
  691. // if(![self IsNetworkAvailable])
  692. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  693. //
  694. // json=[self get_json:URL_CART2WISH parameters:params];
  695. // }
  696. // if(json!=nil)
  697. // {
  698. // NSError *error=nil;
  699. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  700. // int result = [[jsobj valueForKey:@"result"] intValue];
  701. //
  702. // if (result==2)
  703. // {
  704. //
  705. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  706. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  707. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  708. //
  709. // [appDelegate update_count_mark];
  710. // }
  711. // return jsobj;
  712. // }
  713. // else
  714. // return nil;
  715. //}
  716. //+(NSDictionary*) move_wish2cart:(NSString* ) item_ids
  717. //{
  718. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  719. // __block AppDelegate *appDelegate = nil;
  720. //
  721. // dispatch_sync(dispatch_get_main_queue(), ^{
  722. // //some UI methods ej
  723. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  724. // });
  725. // if(appDelegate.user!=nil)
  726. // [params setValue:appDelegate.user forKey:@"user"];
  727. // if(appDelegate.contact_id!=nil)
  728. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  729. // if(appDelegate.password!=nil)
  730. // [params setValue:appDelegate.password forKey:@"password"];
  731. // if(appDelegate.order_code!=nil)
  732. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  733. // [params setValue:item_ids forKey:@"collectId"];
  734. // // [params setValue:editor forKey:@"editor"];
  735. //
  736. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  737. // [params setValue:@"Move To Cart" forKey:kAction];
  738. //
  739. // NSData *json = nil;
  740. // if(appDelegate.offline_mode)
  741. // {
  742. // json = [OLDataProvider offline_movewish2cart:params];
  743. // } else {
  744. // if(![self IsNetworkAvailable])
  745. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  746. //
  747. // json=[self get_json:URL_WISH2CART parameters:params];
  748. // }
  749. //
  750. // if(json!=nil)
  751. // {
  752. // NSError *error=nil;
  753. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  754. // int result = [[jsobj valueForKey:@"result"] intValue];
  755. //
  756. // if (result==2)
  757. // {
  758. //
  759. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  760. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  761. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  762. //
  763. // [appDelegate update_count_mark];
  764. // }
  765. // return jsobj;
  766. // }
  767. // else
  768. // return nil;
  769. //}
  770. //+(NSDictionary*) cart_remove:(NSString* ) item_ids
  771. //{
  772. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  773. // __block AppDelegate *appDelegate = nil;
  774. //
  775. // dispatch_sync(dispatch_get_main_queue(), ^{
  776. // //some UI methods ej
  777. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  778. // });
  779. // if(appDelegate.user!=nil)
  780. // [params setValue:appDelegate.user forKey:@"user"];
  781. // if(appDelegate.contact_id!=nil)
  782. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  783. // if(appDelegate.password!=nil)
  784. // [params setValue:appDelegate.password forKey:@"password"];
  785. //
  786. // if(appDelegate.order_code!=nil)
  787. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  788. // [params setValue:item_ids forKey:@"cartItemId"];
  789. // // [params setValue:editor forKey:@"editor"];
  790. //
  791. // [params setValue:ScreenCodeCart forKey:kScreenName];
  792. // // [params setValue:@"" forKey:kAction];
  793. //
  794. // NSData* json=nil;
  795. // if(appDelegate.offline_mode)
  796. // {
  797. // json= [OLDataProvider offline_cartremove:params];
  798. // }
  799. // else
  800. // {
  801. // if(![self IsNetworkAvailable])
  802. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  803. //
  804. // json=[self get_json:URL_CART_REMOVE parameters:params];
  805. // }
  806. // if(json!=nil)
  807. // {
  808. // NSError *error=nil;
  809. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  810. //
  811. // int result = [[jsobj valueForKey:@"result"] intValue];
  812. //
  813. // if (result==2)
  814. // {
  815. //
  816. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  817. //
  818. //
  819. // [appDelegate update_count_mark];
  820. // }
  821. // return jsobj;
  822. // }
  823. // else
  824. // return nil;
  825. //}
  826. //+(NSDictionary*) cart_check:(NSString* ) item_ids
  827. //{
  828. // return nil;
  829. // if(![self IsNetworkAvailable])
  830. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  831. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  832. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  833. // if(appDelegate.user!=nil)
  834. // [params setValue:appDelegate.user forKey:@"user"];
  835. // if(appDelegate.contact_id!=nil)
  836. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  837. // if(appDelegate.password!=nil)
  838. // [params setValue:appDelegate.password forKey:@"password"];
  839. // [params setValue:item_ids forKey:@"cartItemId"];
  840. // // [params setValue:editor forKey:@"editor"];
  841. // if(appDelegate.offline_mode)
  842. // {
  843. // return [OLDataProvider offline_notimpl];
  844. // }
  845. // NSData* json=[self get_json:URL_CART_CHECK parameters:params];
  846. // if(json!=nil)
  847. // {
  848. // NSError *error=nil;
  849. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  850. // return jsobj;
  851. // }
  852. // else
  853. // return nil;
  854. //}
  855. +(NSDictionary*)create_Address:(NSMutableDictionary*)params
  856. {
  857. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  858. __block AppDelegate *appDelegate = nil;
  859. dispatch_sync(dispatch_get_main_queue(), ^{
  860. //some UI methods ej
  861. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  862. });
  863. if(appDelegate.user!=nil)
  864. [params setValue:appDelegate.user forKey:@"user"];
  865. if(appDelegate.contact_id!=nil)
  866. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  867. if(appDelegate.password!=nil)
  868. [params setValue:appDelegate.password forKey:@"password"];
  869. // [params setValue:sourceid forKey:@"sourceid"];
  870. // [params setValue:editor forKey:@"editor"];
  871. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  872. NSData* json=nil;
  873. if(appDelegate.offline_mode)
  874. {
  875. json= [OLDataProvider offline_saveaddr:params];
  876. }
  877. else
  878. {
  879. if(![self IsNetworkAvailable])
  880. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  881. json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  882. }
  883. if(json!=nil)
  884. {
  885. NSError *error=nil;
  886. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  887. return jsobj;
  888. }
  889. else
  890. return nil;
  891. }
  892. +(NSDictionary*)copy_Order:(NSString*) order_code
  893. {
  894. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  895. __block AppDelegate *appDelegate = nil;
  896. dispatch_sync(dispatch_get_main_queue(), ^{
  897. //some UI methods ej
  898. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  899. });
  900. if(appDelegate.user!=nil)
  901. [params setValue:appDelegate.user forKey:@"user"];
  902. if(appDelegate.contact_id!=nil)
  903. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  904. if(appDelegate.password!=nil)
  905. [params setValue:appDelegate.password forKey:@"password"];
  906. // NSString* ssaved = @"false";
  907. // if(saved)
  908. // ssaved=@"true";
  909. // [params setValue:@"true" forKey:@"saved"];
  910. [params setValue:order_code forKey:@"code"];
  911. // [params setValue:sourceid forKey:@"sourceid"];
  912. // [params setValue:editor forKey:@"editor"];
  913. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  914. NSData* json=nil;
  915. if(appDelegate.offline_mode)
  916. {
  917. json= [OLDataProvider offline_copyorder:params];
  918. }
  919. else
  920. {
  921. if(![self IsNetworkAvailable])
  922. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  923. json=[self get_json:URL_COPY_ORDER parameters:params];
  924. }
  925. if(json!=nil)
  926. {
  927. NSError *error=nil;
  928. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  929. return jsobj;
  930. }
  931. else
  932. return nil;
  933. }
  934. +(NSDictionary*)sign_Order:(NSString*) order_code path:(NSString*)path
  935. {
  936. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  937. __block AppDelegate *appDelegate = nil;
  938. dispatch_sync(dispatch_get_main_queue(), ^{
  939. //some UI methods ej
  940. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  941. });
  942. if(appDelegate.user!=nil)
  943. [params setValue:appDelegate.user forKey:@"user"];
  944. if(appDelegate.contact_id!=nil)
  945. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  946. if(appDelegate.password!=nil)
  947. [params setValue:appDelegate.password forKey:@"password"];
  948. // NSString* ssaved = @"false";
  949. // if(saved)
  950. // ssaved=@"true";
  951. // [params setValue:@"true" forKey:@"saved"];
  952. [params setValue:order_code forKey:@"orderCode"];
  953. [params setValue:path forKey:@"picpath"];
  954. // [params setValue:sourceid forKey:@"sourceid"];
  955. // [params setValue:editor forKey:@"editor"];
  956. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  957. NSData* json=nil;
  958. if(appDelegate.offline_mode)
  959. {
  960. json= [OLDataProvider offline_signorder:params];
  961. }
  962. else
  963. {
  964. if(![self IsNetworkAvailable])
  965. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  966. json=[self get_json:URL_SIGN_ORDER parameters:params];
  967. }
  968. if(json!=nil)
  969. {
  970. NSError *error=nil;
  971. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  972. return jsobj;
  973. }
  974. else
  975. return nil;
  976. }
  977. +(NSDictionary*)commit_Order:(NSString*) order_code //saved:(bool) saved
  978. {
  979. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  980. __block AppDelegate *appDelegate = nil;
  981. dispatch_sync(dispatch_get_main_queue(), ^{
  982. //some UI methods ej
  983. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  984. });
  985. if(appDelegate.user!=nil)
  986. [params setValue:appDelegate.user forKey:@"user"];
  987. if(appDelegate.contact_id!=nil)
  988. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  989. if(appDelegate.password!=nil)
  990. [params setValue:appDelegate.password forKey:@"password"];
  991. // NSString* ssaved = @"false";
  992. // if(saved)
  993. // ssaved=@"true";
  994. [params setValue:@"true" forKey:@"saved"];
  995. [params setValue:order_code forKey:@"orderCode"];
  996. // [params setValue:sourceid forKey:@"sourceid"];
  997. // [params setValue:editor forKey:@"editor"];
  998. [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  999. NSData* json = nil;
  1000. if(appDelegate.offline_mode)
  1001. {
  1002. json= [OLDataProvider offline_submitorder:params];
  1003. }
  1004. else
  1005. {
  1006. if(![self IsNetworkAvailable])
  1007. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1008. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  1009. }
  1010. if(json!=nil)
  1011. {
  1012. NSError *error=nil;
  1013. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1014. return jsobj;
  1015. }
  1016. else
  1017. return nil;
  1018. }
  1019. //+(NSDictionary*)open_Order:(NSString*) order_code
  1020. //{
  1021. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1022. // __block AppDelegate *appDelegate = nil;
  1023. //
  1024. // dispatch_sync(dispatch_get_main_queue(), ^{
  1025. // //some UI methods ej
  1026. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1027. // });
  1028. // if(appDelegate.user!=nil)
  1029. // [params setValue:appDelegate.user forKey:@"user"];
  1030. // // if(appDelegate.contact_id!=nil)
  1031. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1032. // if(appDelegate.password!=nil)
  1033. // [params setValue:appDelegate.password forKey:@"password"];
  1034. //
  1035. // [params setValue:order_code forKey:@"orderCode"];
  1036. // // [params setValue:sourceid forKey:@"sourceid"];
  1037. // // [params setValue:editor forKey:@"editor"];
  1038. //
  1039. // [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  1040. //
  1041. // NSData* json=nil;
  1042. // if(appDelegate.offline_mode)
  1043. // {
  1044. // json=[OLDataProvider offline_editorder:params];
  1045. //
  1046. // }
  1047. // else
  1048. // {
  1049. // if(![self IsNetworkAvailable])
  1050. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1051. //
  1052. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  1053. // }
  1054. // if(json!=nil)
  1055. // {
  1056. // NSError *error=nil;
  1057. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1058. // int result = [[jsobj valueForKey:@"result"] intValue];
  1059. //
  1060. // if (result==2)
  1061. // {
  1062. //
  1063. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1064. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1065. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1066. //
  1067. // [appDelegate update_count_mark];
  1068. //
  1069. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1070. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  1071. // }
  1072. //
  1073. // }
  1074. //
  1075. // return jsobj;
  1076. // }
  1077. // else
  1078. // return nil;
  1079. //}
  1080. +(NSDictionary*)delete_Order:(NSString*) order_id
  1081. {
  1082. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1083. __block AppDelegate *appDelegate = nil;
  1084. dispatch_sync(dispatch_get_main_queue(), ^{
  1085. //some UI methods ej
  1086. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1087. });
  1088. if(appDelegate.user!=nil)
  1089. [params setValue:appDelegate.user forKey:@"user"];
  1090. // if(appDelegate.contact_id!=nil)
  1091. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1092. if(appDelegate.password!=nil)
  1093. [params setValue:appDelegate.password forKey:@"password"];
  1094. [params setValue:order_id forKey:@"orderId"];
  1095. // [params setValue:sourceid forKey:@"sourceid"];
  1096. // [params setValue:editor forKey:@"editor"];
  1097. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  1098. if(appDelegate.offline_mode)
  1099. {
  1100. return [OLDataProvider offline_notimpl];
  1101. }
  1102. if(![self IsNetworkAvailable])
  1103. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1104. NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  1105. if(json!=nil)
  1106. {
  1107. NSError *error=nil;
  1108. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1109. return jsobj;
  1110. }
  1111. else
  1112. return nil;
  1113. }
  1114. +(NSDictionary*)cancel_Order:(NSString*) order_id order_code:(NSString*) order_code
  1115. {
  1116. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1117. __block AppDelegate *appDelegate = nil;
  1118. dispatch_sync(dispatch_get_main_queue(), ^{
  1119. //some UI methods ej
  1120. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1121. });
  1122. if(appDelegate.user!=nil)
  1123. [params setValue:appDelegate.user forKey:@"user"];
  1124. // if(appDelegate.contact_id!=nil)
  1125. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1126. if(appDelegate.password!=nil)
  1127. [params setValue:appDelegate.password forKey:@"password"];
  1128. [params setValue:order_id forKey:@"orderId"];
  1129. [params setValue:order_code forKey:@"orderCode"];
  1130. // [params setValue:sourceid forKey:@"sourceid"];
  1131. // [params setValue:editor forKey:@"editor"];
  1132. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  1133. NSData* json=nil;
  1134. if(appDelegate.offline_mode)
  1135. {
  1136. json=[OLDataProvider offline_cancelorder:params];
  1137. }
  1138. else
  1139. {
  1140. if(![self IsNetworkAvailable])
  1141. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1142. json=[self get_json:URL_CANCEL_ORDER parameters:params];
  1143. }
  1144. if(json!=nil)
  1145. {
  1146. NSError *error=nil;
  1147. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1148. return jsobj;
  1149. }
  1150. else
  1151. return nil;
  1152. }
  1153. +(NSDictionary*)release_Order:(NSString*) order_code withScreen:(NSString *)screenName
  1154. {
  1155. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1156. __block AppDelegate *appDelegate = nil;
  1157. dispatch_sync(dispatch_get_main_queue(), ^{
  1158. //some UI methods ej
  1159. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1160. });
  1161. if(appDelegate.user!=nil)
  1162. [params setValue:appDelegate.user forKey:@"user"];
  1163. // if(appDelegate.contact_id!=nil)
  1164. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1165. if(appDelegate.password!=nil)
  1166. [params setValue:appDelegate.password forKey:@"password"];
  1167. [params setValue:order_code forKey:@"orderCode"];
  1168. // [params setValue:sourceid forKey:@"sourceid"];
  1169. // [params setValue:editor forKey:@"editor"];
  1170. if (screenName) {
  1171. [params setValue:screenName forKey:kScreenName];
  1172. }
  1173. NSData* json=nil;
  1174. if(appDelegate.offline_mode)
  1175. {
  1176. json= [OLDataProvider offline_resetorder:params];
  1177. }
  1178. else
  1179. {
  1180. if(![self IsNetworkAvailable])
  1181. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1182. json=[self get_json:URL_RELEASE_ORDER parameters:params];
  1183. }
  1184. if(json!=nil)
  1185. {
  1186. NSError *error=nil;
  1187. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1188. if([[jsobj valueForKey:@"result"]intValue]==2)
  1189. { [appDelegate SetSo:nil];
  1190. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1191. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1192. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1193. [appDelegate update_count_mark];
  1194. }
  1195. return jsobj;
  1196. }
  1197. else
  1198. return nil;
  1199. }
  1200. +(NSDictionary*)update_OrderCustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info
  1201. {
  1202. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1203. __block AppDelegate *appDelegate = nil;
  1204. dispatch_sync(dispatch_get_main_queue(), ^{
  1205. //some UI methods ej
  1206. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1207. });
  1208. if(appDelegate.user!=nil)
  1209. [info setValue:appDelegate.user forKey:@"user"];
  1210. // if(appDelegate.contact_id!=nil)
  1211. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1212. if(appDelegate.password!=nil)
  1213. [info setValue:appDelegate.password forKey:@"password"];
  1214. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1215. [info setValue:order_code forKey:@"orderCode"];
  1216. // [params setValue:sourceid forKey:@"sourceid"];
  1217. // [params setValue:editor forKey:@"editor"];
  1218. if(appDelegate.offline_mode)
  1219. {
  1220. return [OLDataProvider offline_notimpl];
  1221. }
  1222. if(![self IsNetworkAvailable])
  1223. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1224. NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  1225. if(json!=nil)
  1226. {
  1227. NSError *error=nil;
  1228. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1229. return jsobj;
  1230. }
  1231. else
  1232. return nil;
  1233. }
  1234. //+(NSDictionary*)commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url
  1235. //{
  1236. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1237. // __block AppDelegate *appDelegate = nil;
  1238. //
  1239. // dispatch_sync(dispatch_get_main_queue(), ^{
  1240. // //some UI methods ej
  1241. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1242. // });
  1243. // if(appDelegate.user!=nil)
  1244. // [params setValue:appDelegate.user forKey:@"user"];
  1245. // if(appDelegate.contact_id!=nil)
  1246. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1247. // if(appDelegate.password!=nil)
  1248. // [params setValue:appDelegate.password forKey:@"password"];
  1249. //
  1250. // // if(appDelegate.order_code!=nil)
  1251. // // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1252. //
  1253. // // NSDictionary* customerinfo= appDelegate.customerInfo;
  1254. // //
  1255. // // NSArray* keys=[customerinfo allKeys];
  1256. // // for(int i=0;i<keys.count;i++)
  1257. // // {
  1258. // // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1259. // // }
  1260. // //
  1261. // // [params setValue:sourceid forKey:@"sourceid"];
  1262. // // [params setValue:editor forKey:@"editor"];
  1263. //
  1264. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  1265. //
  1266. // if(appDelegate.offline_mode)
  1267. // {
  1268. // params[@"offline_Command"]=url;
  1269. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  1270. // }
  1271. //
  1272. // if(![self IsNetworkAvailable])
  1273. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1274. //
  1275. // NSData* json=[self get_json:url parameters:params];
  1276. // if(json!=nil)
  1277. // {
  1278. // NSError *error=nil;
  1279. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1280. // if([[jsobj valueForKey:@"result"]intValue]==2)
  1281. // [appDelegate SetSo:nil];
  1282. //
  1283. //
  1284. // return jsobj;
  1285. // }
  1286. // else
  1287. // return nil;
  1288. //}
  1289. +(NSDictionary*)saveandcommit_Order:(NSMutableDictionary*)params
  1290. {
  1291. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1292. __block AppDelegate *appDelegate = nil;
  1293. dispatch_sync(dispatch_get_main_queue(), ^{
  1294. //some UI methods ej
  1295. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1296. });
  1297. if(appDelegate.user!=nil)
  1298. [params setValue:appDelegate.user forKey:@"user"];
  1299. if(appDelegate.contact_id!=nil)
  1300. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1301. if(appDelegate.password!=nil)
  1302. [params setValue:appDelegate.password forKey:@"password"];
  1303. if(appDelegate.order_code!=nil)
  1304. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1305. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1306. //
  1307. // NSArray* keys=[customerinfo allKeys];
  1308. // for(int i=0;i<keys.count;i++)
  1309. // {
  1310. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1311. // }
  1312. //
  1313. // [params setValue:sourceid forKey:@"sourceid"];
  1314. // [params setValue:editor forKey:@"editor"];
  1315. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1316. NSData* json=nil;
  1317. if(appDelegate.offline_mode)
  1318. {
  1319. json=[OLDataProvider offline_submitorder:params];
  1320. }
  1321. else
  1322. {
  1323. if(![self IsNetworkAvailable])
  1324. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1325. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  1326. }
  1327. if(json!=nil)
  1328. {
  1329. NSError *error=nil;
  1330. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1331. if([[jsobj valueForKey:@"result"]intValue]==2)
  1332. [appDelegate SetSo:nil];
  1333. return jsobj;
  1334. }
  1335. else
  1336. return nil;
  1337. }
  1338. +(NSDictionary*)update_Customer:(NSMutableDictionary*)params
  1339. {
  1340. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1341. __block AppDelegate *appDelegate = nil;
  1342. dispatch_sync(dispatch_get_main_queue(), ^{
  1343. //some UI methods ej
  1344. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1345. });
  1346. if(appDelegate.user!=nil)
  1347. [params setValue:appDelegate.user forKey:@"user"];
  1348. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1349. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1350. // else
  1351. if(appDelegate.contact_id!=nil)
  1352. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1353. if(appDelegate.password!=nil)
  1354. [params setValue:appDelegate.password forKey:@"password"];
  1355. // NSDictionary* customerinfo=nil;
  1356. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1357. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1358. // else
  1359. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1360. //
  1361. // appDelegate.customerInfo;
  1362. // NSArray* keys=[customerinfo allKeys];
  1363. // for(int i=0;i<keys.count;i++)
  1364. // {
  1365. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1366. // }
  1367. // [params setValue:sourceid forKey:@"sourceid"];
  1368. // [params setValue:editor forKey:@"editor"];
  1369. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1370. NSData* json=nil;
  1371. if(appDelegate.offline_mode)
  1372. {
  1373. json= [OLDataProvider offline_saveContact:params];
  1374. }
  1375. else
  1376. {
  1377. if(![self IsNetworkAvailable])
  1378. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1379. json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  1380. }
  1381. if(json!=nil)
  1382. {
  1383. NSError *error=nil;
  1384. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1385. return jsobj;
  1386. }
  1387. else
  1388. return nil;
  1389. }
  1390. +(NSDictionary*)save_newCustomer:(NSMutableDictionary*)params
  1391. {
  1392. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1393. __block AppDelegate *appDelegate = nil;
  1394. dispatch_sync(dispatch_get_main_queue(), ^{
  1395. //some UI methods ej
  1396. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1397. });
  1398. if(appDelegate.user!=nil)
  1399. [params setValue:appDelegate.user forKey:@"user"];
  1400. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1401. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1402. // else
  1403. if(appDelegate.contact_id!=nil)
  1404. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1405. if(appDelegate.password!=nil)
  1406. [params setValue:appDelegate.password forKey:@"password"];
  1407. // NSDictionary* customerinfo=nil;
  1408. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1409. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1410. // else
  1411. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1412. //
  1413. // appDelegate.customerInfo;
  1414. // NSArray* keys=[customerinfo allKeys];
  1415. // for(int i=0;i<keys.count;i++)
  1416. // {
  1417. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1418. // }
  1419. // [params setValue:sourceid forKey:@"sourceid"];
  1420. // [params setValue:editor forKey:@"editor"];
  1421. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1422. NSData* json=nil;
  1423. if(appDelegate.offline_mode)
  1424. {
  1425. json= [OLDataProvider offline_saveNewContact:params];
  1426. }
  1427. else
  1428. {
  1429. if(![self IsNetworkAvailable])
  1430. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1431. json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  1432. }
  1433. if(json!=nil)
  1434. {
  1435. NSError *error=nil;
  1436. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1437. return jsobj;
  1438. }
  1439. else
  1440. return nil;
  1441. }
  1442. +(NSDictionary*)save_Order:(NSMutableDictionary*)params
  1443. {
  1444. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1445. __block AppDelegate *appDelegate = nil;
  1446. dispatch_sync(dispatch_get_main_queue(), ^{
  1447. //some UI methods ej
  1448. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1449. });
  1450. if(appDelegate.user!=nil)
  1451. [params setValue:appDelegate.user forKey:@"user"];
  1452. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1453. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1454. // else
  1455. if(appDelegate.contact_id!=nil)
  1456. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1457. if(appDelegate.password!=nil)
  1458. [params setValue:appDelegate.password forKey:@"password"];
  1459. if(appDelegate.order_code!=nil)
  1460. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1461. // NSDictionary* customerinfo=nil;
  1462. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1463. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1464. // else
  1465. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1466. //
  1467. // appDelegate.customerInfo;
  1468. // NSArray* keys=[customerinfo allKeys];
  1469. // for(int i=0;i<keys.count;i++)
  1470. // {
  1471. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1472. // }
  1473. // [params setValue:sourceid forKey:@"sourceid"];
  1474. // [params setValue:editor forKey:@"editor"];
  1475. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1476. NSData* json=nil;
  1477. if(appDelegate.offline_mode)
  1478. {
  1479. json= [OLDataProvider offline_saveorder:params];
  1480. }
  1481. else
  1482. {
  1483. if(![self IsNetworkAvailable])
  1484. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1485. json=[self get_json:URL_SAVE_ORDER parameters:params];
  1486. }
  1487. if(json!=nil)
  1488. {
  1489. NSError *error=nil;
  1490. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1491. NSString *so = [jsobj valueForKey:@"so#"];
  1492. if (so) {
  1493. [appDelegate SetSo:so];
  1494. }
  1495. return jsobj;
  1496. }
  1497. else
  1498. return nil;
  1499. }
  1500. //+(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
  1501. //{
  1502. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1503. // __block AppDelegate *appDelegate = nil;
  1504. //
  1505. // dispatch_sync(dispatch_get_main_queue(), ^{
  1506. // //some UI methods ej
  1507. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1508. // });
  1509. // if(appDelegate.user!=nil)
  1510. // [params setValue:appDelegate.user forKey:@"user"];
  1511. //
  1512. //
  1513. // // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1514. // // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1515. // // else
  1516. //
  1517. // if(appDelegate.contact_id!=nil)
  1518. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1519. // if(appDelegate.password!=nil)
  1520. // [params setValue:appDelegate.password forKey:@"password"];
  1521. //
  1522. // if(appDelegate.order_code!=nil)
  1523. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1524. // // [params setValue:sourceid forKey:@"sourceid"];
  1525. // // [params setValue:editor forKey:@"editor"];
  1526. // DebugLog(@"request editor url:%@",request_url);
  1527. //
  1528. //
  1529. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1530. // {
  1531. // [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1532. // }
  1533. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1534. // {
  1535. // [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1536. // }
  1537. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1538. // {
  1539. // [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  1540. // }
  1541. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1542. // {
  1543. // [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1544. // }
  1545. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1546. // {
  1547. // [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  1548. // }
  1549. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1550. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1551. // }
  1552. //
  1553. // NSData* json = nil;
  1554. // if(appDelegate.offline_mode)
  1555. // {
  1556. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1557. // {
  1558. // json= [OLDataProvider offline_createContact:params];
  1559. // }
  1560. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1561. // {
  1562. // json= [OLDataProvider offline_editContact:params];
  1563. // }
  1564. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1565. // {
  1566. // json= [OLDataProvider offline_contactAdvancedSearch:params];
  1567. // }
  1568. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1569. // {
  1570. // json= [OLDataProvider offline_placeorder:params];
  1571. // }
  1572. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1573. // {
  1574. // json= [OLDataProvider offline_addreditor:params];
  1575. // }
  1576. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1577. // json = [OLDataProvider offline_createTearSheet:params];
  1578. // }
  1579. //
  1580. // else
  1581. // return [OLDataProvider offline_notimpl];
  1582. // }
  1583. // else
  1584. // {
  1585. // if(![self IsNetworkAvailable])
  1586. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1587. //
  1588. // if([request_url isEqualToString:URL_CARTDELIVERY])
  1589. // {
  1590. // NSError *error=nil;
  1591. //
  1592. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1593. // params[@"resultSerial"]=uuid;
  1594. //
  1595. // for(int i=0;i<150;i++)
  1596. // {
  1597. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1598. // // result_params[@"resultSerial"]=uuid;
  1599. // json=[self get_json:request_url parameters:params];
  1600. // if(json!=nil)
  1601. // {
  1602. //
  1603. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1604. // if([jsobj[@"result"] intValue]==2 || [jsobj[@"result"] intValue] == 8)
  1605. // {
  1606. // break;
  1607. // }
  1608. // }
  1609. // sleep(2);
  1610. // }
  1611. // }
  1612. // else
  1613. // json =[self get_json:request_url parameters:params];
  1614. // }
  1615. // if(json!=nil)
  1616. // {
  1617. // NSError *error=nil;
  1618. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1619. // return jsobj;
  1620. // }
  1621. // else
  1622. // return nil;
  1623. //}
  1624. //+(NSDictionary*)request_OrderInfo:(NSString*) orderid
  1625. //{
  1626. // if(![self IsNetworkAvailable])
  1627. // return nil;
  1628. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1629. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1630. // if(appDelegate.user!=nil)
  1631. // [params setValue:appDelegate.user forKey:@"user"];
  1632. // if(appDelegate.password!=nil)
  1633. // [params setValue:appDelegate.password forKey:@"password"];
  1634. // [params setValue:orderid forKey:@"orderid"];
  1635. // NSData* json=[self get_json:URL_ORDER_INFO parameters:params];
  1636. // NSError *error=nil;
  1637. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1638. // return jsobj;
  1639. //}
  1640. +(NSDictionary*)request_OrderList:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged
  1641. {
  1642. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1643. __block AppDelegate *appDelegate = nil;
  1644. dispatch_sync(dispatch_get_main_queue(), ^{
  1645. //some UI methods ej
  1646. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1647. });
  1648. if(appDelegate.user!=nil)
  1649. [params setValue:appDelegate.user forKey:@"user"];
  1650. if(appDelegate.contact_id!=nil)
  1651. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1652. if(appDelegate.password!=nil)
  1653. [params setValue:appDelegate.password forKey:@"password"];
  1654. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1655. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1656. [params setValue:keywords forKey:@"keyWord"];
  1657. [params setValue:customer forKey:@"customer_filter"];
  1658. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  1659. [params setValue:status_code forKey:@"orderStatus"];
  1660. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1661. if (keywords) {
  1662. [params setObject:@"Search" forKey:kAction];
  1663. }
  1664. NSData* json=nil;
  1665. if(appDelegate.offline_mode)
  1666. {
  1667. json= [OLDataProvider offline_orderlist:params];
  1668. }
  1669. else
  1670. {
  1671. if(![self IsNetworkAvailable])
  1672. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1673. json=[self get_json:URL_ORDER_LIST parameters:params];
  1674. }
  1675. if(json==nil)
  1676. return nil;
  1677. NSError *error=nil;
  1678. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1679. return jsobj;
  1680. }
  1681. +(NSDictionary*)request_PDFList:(int ) offset limit:(int)limit keywords:(NSString* ) keywords
  1682. {
  1683. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1684. __block AppDelegate *appDelegate = nil;
  1685. dispatch_sync(dispatch_get_main_queue(), ^{
  1686. //some UI methods ej
  1687. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1688. });
  1689. if(appDelegate.user!=nil)
  1690. [params setValue:appDelegate.user forKey:@"user"];
  1691. if(appDelegate.contact_id!=nil)
  1692. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1693. if(appDelegate.password!=nil)
  1694. [params setValue:appDelegate.password forKey:@"password"];
  1695. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  1696. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  1697. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  1698. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  1699. // [params setValue:filter forKey:@"filter"];
  1700. [params setValue:keywords forKey:@"keyWord"];
  1701. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  1702. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  1703. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  1704. if (keywords) {
  1705. [params setObject:@"Search" forKey:kAction];
  1706. }
  1707. NSData* json = nil;
  1708. if(appDelegate.offline_mode)
  1709. {
  1710. json = [OLDataProvider offline_pdfList:params];
  1711. } else {
  1712. if(![self IsNetworkAvailable])
  1713. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1714. json=[self get_json:URL_DM_LIST parameters:params];
  1715. }
  1716. if(json==nil)
  1717. return nil;
  1718. NSError *error=nil;
  1719. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1720. return jsobj;
  1721. }
  1722. //+(NSString*) create_portfolio:(NSMutableDictionary*)params
  1723. //{
  1724. // __block AppDelegate *appDelegate = nil;
  1725. //
  1726. // dispatch_sync(dispatch_get_main_queue(), ^{
  1727. // //some UI methods ej
  1728. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1729. // });
  1730. // if(appDelegate.offline_mode)
  1731. // {
  1732. //
  1733. //
  1734. // NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  1735. // if(json==nil)
  1736. // return nil;
  1737. // NSError *error=nil;
  1738. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1739. //
  1740. // return jsobj[@"pdf_path"];
  1741. // }
  1742. // else
  1743. // {
  1744. // return nil;
  1745. // }
  1746. //}
  1747. //+(NSDictionary*)direct_save_TearSheet:(NSMutableDictionary*)params//(NSString*) request_url name:(NSString*)name delete:(NSString* )ids note:(NSString* )saveNote modelIds:(NSDictionary *)modelIds
  1748. //{
  1749. // NSMutableDictionary* off_params = [params mutableCopy];;
  1750. //
  1751. // params[@"off_params"]=[RAConvertor dict2string:off_params];;
  1752. // __block AppDelegate *appDelegate = nil;
  1753. //
  1754. // dispatch_sync(dispatch_get_main_queue(), ^{
  1755. // //some UI methods ej
  1756. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1757. // });
  1758. // if(appDelegate.user!=nil)
  1759. // [params setValue:appDelegate.user forKey:@"user"];
  1760. // if(appDelegate.contact_id!=nil)
  1761. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1762. // if(appDelegate.password!=nil)
  1763. // [params setValue:appDelegate.password forKey:@"password"];
  1764. //
  1765. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1766. //
  1767. // /*
  1768. // [params setValue:request_url forKey:@"pdfUrl"];
  1769. // [params setValue:name forKey:@"pdfName"];
  1770. // [params setValue:ids forKey:@"itemIds"];
  1771. // [params setValue:saveNote forKey:@"pdfNote"];
  1772. // [params setValue:[modelIds objectForKey:@"product_ids"] forKey:@"product_ids"];
  1773. // [params setValue:[modelIds objectForKey:@"item_ids"] forKey:@"item_ids"];
  1774. // [params setValue:[modelIds objectForKey:@"remove_item"] forKey:@"remove_item"];
  1775. // */
  1776. // NSData* json= nil;
  1777. //
  1778. // if(appDelegate.offline_mode)
  1779. // {
  1780. // json = [OLDataProvider offline_direct_save_TearSheet:params];
  1781. // }
  1782. // else
  1783. // {
  1784. // if(![self IsNetworkAvailable])
  1785. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1786. //
  1787. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1788. //
  1789. // NSError *error=nil;
  1790. //
  1791. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1792. // params[@"resultSerial"]=uuid;
  1793. //
  1794. // for(int i=0;i<150;i++)
  1795. // {
  1796. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1797. // // result_params[@"resultSerial"]=uuid;
  1798. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1799. // if(json!=nil)
  1800. // {
  1801. //
  1802. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1803. // if([jsobj[@"result"] intValue]==2)
  1804. // {
  1805. // break;
  1806. // }
  1807. // }
  1808. // sleep(5);
  1809. // }
  1810. //
  1811. // }
  1812. // if(json==nil)
  1813. // return nil;
  1814. // NSError *error=nil;
  1815. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1816. // return jsobj;
  1817. //}
  1818. //+(NSDictionary*)request_TearSheet:(NSMutableDictionary*)params//(NSString*) request_url
  1819. //{
  1820. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1821. // __block AppDelegate *appDelegate = nil;
  1822. //
  1823. // dispatch_sync(dispatch_get_main_queue(), ^{
  1824. // //some UI methods ej
  1825. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1826. // });
  1827. // if(appDelegate.user!=nil)
  1828. // [params setValue:appDelegate.user forKey:@"user"];
  1829. // if(appDelegate.contact_id!=nil)
  1830. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1831. // if(appDelegate.password!=nil)
  1832. // [params setValue:appDelegate.password forKey:@"password"];
  1833. //
  1834. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1835. //
  1836. // // [params setValue:request_url forKey:@"pdfUrl"];
  1837. // NSData* json= nil;
  1838. // if(appDelegate.offline_mode)
  1839. // {
  1840. // json= [OLDataProvider offline_request_tearsheet:params];
  1841. // }
  1842. // else
  1843. // {
  1844. // if(![self IsNetworkAvailable])
  1845. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1846. //
  1847. // NSError *error=nil;
  1848. //
  1849. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1850. // params[@"resultSerial"]=uuid;
  1851. //
  1852. // for(int i=0;i<150;i++)
  1853. // {
  1854. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1855. // // result_params[@"resultSerial"]=uuid;
  1856. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1857. // if(json!=nil)
  1858. // {
  1859. //
  1860. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1861. // if([jsobj[@"result"] intValue]==2)
  1862. // {
  1863. // break;
  1864. // }
  1865. // }
  1866. // sleep(5);
  1867. // }
  1868. // }
  1869. // if(json==nil)
  1870. // return nil;
  1871. // NSError *error=nil;
  1872. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1873. // return jsobj;
  1874. //}
  1875. //+(NSDictionary*)save_TearSheet:(NSMutableDictionary *)params//(NSString*) path name:(NSString*)name delete:(NSString* )ids note:(NSString*)note configureParams:(NSString *)configureParams modelIds:(NSDictionary *)modelIds
  1876. //{
  1877. //
  1878. //
  1879. // NSMutableDictionary* off_params = [params mutableCopy];;
  1880. //
  1881. // params[@"off_params"]=[RAConvertor dict2string:off_params];
  1882. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1883. // __block AppDelegate *appDelegate = nil;
  1884. //
  1885. // dispatch_sync(dispatch_get_main_queue(), ^{
  1886. // //some UI methods ej
  1887. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1888. // });
  1889. // if(appDelegate.user!=nil)
  1890. // [params setValue:appDelegate.user forKey:@"user"];
  1891. // if(appDelegate.contact_id!=nil)
  1892. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1893. // if(appDelegate.password!=nil)
  1894. // [params setValue:appDelegate.password forKey:@"password"];
  1895. //
  1896. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1897. //
  1898. // /*
  1899. // [params setValue:path forKey:@"pdfPath"];
  1900. // [params setValue:name forKey:@"pdfName"];
  1901. // [params setValue:note forKey:@"pdfNote"];
  1902. // [params setValue:ids forKey:@"itemIds"];
  1903. // [params setValue:configureParams forKey:@"configureParams"];
  1904. // [params setValue:[modelIds objectForKey:@"product_ids"] forKey:@"product_ids"];
  1905. // [params setValue:[modelIds objectForKey:@"item_ids"] forKey:@"item_ids"];
  1906. // [params setValue:[modelIds objectForKey:@"remove_item"] forKey:@"remove_item"];
  1907. // */
  1908. // NSData* json = nil;
  1909. // if(appDelegate.offline_mode)
  1910. // {
  1911. // json = [OLDataProvider offline_save_TearSheet:params];
  1912. // } else {
  1913. // if(![self IsNetworkAvailable])
  1914. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1915. //
  1916. // json=[self get_json:URL_SAVE_DM parameters:params];
  1917. // }
  1918. // if(json==nil)
  1919. // return nil;
  1920. // NSError *error=nil;
  1921. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1922. // return jsobj;
  1923. //}
  1924. +(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code//device:(NSString*) device
  1925. {
  1926. return nil;
  1927. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1928. __block AppDelegate *appDelegate = nil;
  1929. dispatch_sync(dispatch_get_main_queue(), ^{
  1930. //some UI methods ej
  1931. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1932. });
  1933. if(appDelegate.user!=nil)
  1934. [params setValue:appDelegate.user forKey:@"user"];
  1935. [params setValue:up_params forKey:@"upparam"];
  1936. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  1937. [params setValue:result forKey:@"result"];
  1938. [params setValue:module forKey:@"interfac"];
  1939. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  1940. // [params setValue:module forKey:@"module"];
  1941. // [[UIDevice currentDevice] name];
  1942. // if(appDelegate.offline_mode)
  1943. // {
  1944. // return [OLDataProvider offline_notimpl];
  1945. // }
  1946. if(![self IsNetworkAvailable])
  1947. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1948. NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  1949. if(json==nil)
  1950. return nil;
  1951. NSError *error=nil;
  1952. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1953. return jsobj;
  1954. }
  1955. //+(NSDictionary*)request_ContactList:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams
  1956. //{
  1957. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1958. //
  1959. // if(upparams!=nil)
  1960. // params = [upparams mutableCopy];
  1961. // __block AppDelegate *appDelegate = nil;
  1962. //
  1963. // dispatch_sync(dispatch_get_main_queue(), ^{
  1964. // //some UI methods ej
  1965. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1966. // });
  1967. // if(appDelegate.user!=nil)
  1968. // [params setValue:appDelegate.user forKey:@"user"];
  1969. //
  1970. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1971. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1972. // else
  1973. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1974. //
  1975. // if(appDelegate.password!=nil)
  1976. // [params setValue:appDelegate.password forKey:@"password"];
  1977. //
  1978. // [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1979. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1980. // [params setValue:contact_type forKey:@"contactType"];
  1981. // [params setValue:keywords forKey:@"keyword"];
  1982. //
  1983. // [params setObject:ScreenCodeAccount forKey:kScreenName];
  1984. // if (keywords) {
  1985. // [params setObject:@"Search" forKey:kAction];
  1986. // }
  1987. // if (upparams) {
  1988. // [params setObject:@"Advance Search" forKey:kAction];
  1989. // }
  1990. //
  1991. // NSString* url=nil;
  1992. // if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  1993. // url=URL_SHIPTO_LIST;
  1994. // else
  1995. // url=URL_CONTACT_LIST;
  1996. //
  1997. // if(appDelegate.offline_mode)
  1998. // return [OLDataProvider offline_contactlist:params];
  1999. //
  2000. // if(![self IsNetworkAvailable])
  2001. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2002. //
  2003. // NSData* json=[self get_json:url parameters:params];
  2004. // if(json==nil)
  2005. // return nil;
  2006. // NSError *error=nil;
  2007. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2008. // return jsobj;
  2009. //}
  2010. //+(NSDictionary*)request_OrderDetail:(NSMutableDictionary *) params
  2011. //{
  2012. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2013. // if (params == nil) {
  2014. // params = [[NSMutableDictionary alloc] init];
  2015. // }
  2016. // __block AppDelegate *appDelegate = nil;
  2017. //
  2018. // dispatch_sync(dispatch_get_main_queue(), ^{
  2019. // //some UI methods ej
  2020. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2021. // });
  2022. // if(appDelegate.user!=nil)
  2023. // [params setValue:appDelegate.user forKey:@"user"];
  2024. // if(appDelegate.contact_id!=nil)
  2025. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2026. // if(appDelegate.password!=nil)
  2027. // [params setValue:appDelegate.password forKey:@"password"];
  2028. //
  2029. //
  2030. // // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  2031. //
  2032. // [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  2033. //
  2034. // NSData* json=nil;
  2035. // if(appDelegate.offline_mode)
  2036. // {
  2037. // json= [OLDataProvider offline_orderdetail:params];
  2038. // }
  2039. // else
  2040. // {
  2041. // if(![self IsNetworkAvailable])
  2042. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2043. //
  2044. // NSError *error=nil;
  2045. //
  2046. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2047. // params[@"resultSerial"]=uuid;
  2048. //
  2049. // for(int i=0;i<150;i++)
  2050. // {
  2051. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2052. // // result_params[@"resultSerial"]=uuid;
  2053. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  2054. // if(json!=nil)
  2055. // {
  2056. //
  2057. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2058. // int resultCode = [jsobj[@"result"] intValue];
  2059. // if(resultCode==2 || resultCode == 8)
  2060. // {
  2061. // break;
  2062. // }
  2063. // }
  2064. // sleep(2);
  2065. // }
  2066. //
  2067. //
  2068. // }
  2069. // if(json==nil)
  2070. // return nil;
  2071. // NSError *error=nil;
  2072. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2073. // return jsobj;
  2074. //}
  2075. //+(NSDictionary*) add_toCart:(NSString* ) item_id count:(int) count name:(NSString *)name
  2076. //{
  2077. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2078. // __block AppDelegate *appDelegate = nil;
  2079. //
  2080. // dispatch_sync(dispatch_get_main_queue(), ^{
  2081. // //some UI methods ej
  2082. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2083. // });
  2084. // if(appDelegate.user!=nil)
  2085. // [params setValue:appDelegate.user forKey:@"user"];
  2086. // if(appDelegate.contact_id!=nil)
  2087. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2088. // if(appDelegate.password!=nil)
  2089. // [params setValue:appDelegate.password forKey:@"password"];
  2090. //
  2091. // if(appDelegate.order_code!=nil)
  2092. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2093. // [params setValue:item_id forKey:@"product_id"];
  2094. // [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  2095. //
  2096. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  2097. // [params setObject:@"Add To Cart" forKey:kAction];
  2098. // if (name) {
  2099. // NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  2100. // [params setObject:extra forKey:kExtra];
  2101. // }
  2102. //
  2103. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2104. //
  2105. // NSArray* keys=[customerinfo allKeys];
  2106. // for(int i=0;i<keys.count;i++)
  2107. // {
  2108. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2109. // }
  2110. //
  2111. // NSData* json=nil;
  2112. // if(appDelegate.offline_mode)
  2113. // {
  2114. // json=[OLDataProvider offline_add2cart:params];
  2115. // }
  2116. // else
  2117. // {
  2118. // if(![self IsNetworkAvailable])
  2119. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2120. //
  2121. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  2122. // }
  2123. // if(json==nil)
  2124. // return nil;
  2125. // NSError *error=nil;
  2126. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2127. //
  2128. //
  2129. //
  2130. // int result = [[jsobj valueForKey:@"result"] intValue];
  2131. //
  2132. // if (result==2)
  2133. // {
  2134. //
  2135. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2136. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2137. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2138. //
  2139. // [appDelegate update_count_mark];
  2140. // }
  2141. //
  2142. // return jsobj;
  2143. //}
  2144. //+(NSDictionary*) add_toCart_byName:(NSString* ) model_name withScreen:(NSString *)screenName
  2145. //{
  2146. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2147. // __block AppDelegate *appDelegate = nil;
  2148. //
  2149. // dispatch_sync(dispatch_get_main_queue(), ^{
  2150. // //some UI methods ej
  2151. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2152. // });
  2153. // if(appDelegate.user!=nil)
  2154. // [params setValue:appDelegate.user forKey:@"user"];
  2155. // if(appDelegate.contact_id!=nil)
  2156. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2157. // if(appDelegate.password!=nil)
  2158. // [params setValue:appDelegate.password forKey:@"password"];
  2159. //
  2160. // if(appDelegate.order_code!=nil)
  2161. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2162. // [params setValue:model_name forKey:@"product_name"];
  2163. // [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  2164. //
  2165. // [params setObject:screenName forKey:kScreenName];
  2166. // [params setObject:@"Add To Cart" forKey:kAction];
  2167. // if (!model_name) {
  2168. // model_name = @"";
  2169. // }
  2170. // [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  2171. //
  2172. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2173. //
  2174. // NSArray* keys=[customerinfo allKeys];
  2175. // for(int i=0;i<keys.count;i++)
  2176. // {
  2177. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2178. // }
  2179. // NSData* json=nil;
  2180. // if(appDelegate.offline_mode)
  2181. // {
  2182. // json= [OLDataProvider offline_add2cartbyname:params];
  2183. // }
  2184. // else
  2185. // {
  2186. // if(![self IsNetworkAvailable])
  2187. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2188. //
  2189. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  2190. // }
  2191. // if(json==nil)
  2192. // return nil;
  2193. // NSError *error=nil;
  2194. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2195. //
  2196. //
  2197. //
  2198. // int result = [[jsobj valueForKey:@"result"] intValue];
  2199. //
  2200. // if (result==2||result==8)
  2201. // {
  2202. //
  2203. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2204. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2205. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2206. //
  2207. // [appDelegate update_count_mark];
  2208. // }
  2209. //
  2210. // return jsobj;
  2211. //}
  2212. //+(NSDictionary*) new_Customer
  2213. //{
  2214. // if(![self IsNetworkAvailable])
  2215. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2216. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2217. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  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. //// if(appDelegate.order_code!=nil)
  2226. //// [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2227. //
  2228. //
  2229. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2230. //
  2231. // NSArray* keys=[customerinfo allKeys];
  2232. // for(int i=0;i<keys.count;i++)
  2233. // {
  2234. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2235. // }
  2236. //
  2237. // NSData* json=[self get_json:URL_CUSTOMER_EDIT parameters:params];
  2238. // if(json==nil)
  2239. // return nil;
  2240. // NSError *error=nil;
  2241. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2242. // return jsobj;
  2243. //}
  2244. //+(NSDictionary*) new_Order
  2245. //{
  2246. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2247. // __block AppDelegate *appDelegate = nil;
  2248. //
  2249. // dispatch_sync(dispatch_get_main_queue(), ^{
  2250. // //some UI methods ej
  2251. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2252. // });
  2253. // if(appDelegate.user!=nil)
  2254. // [params setValue:appDelegate.user forKey:@"user"];
  2255. // if(appDelegate.contact_id!=nil)
  2256. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2257. // if(appDelegate.password!=nil)
  2258. // [params setValue:appDelegate.password forKey:@"password"];
  2259. //
  2260. // if(appDelegate.order_code!=nil)
  2261. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2262. //
  2263. //
  2264. // [params setObject:ScreenCodeOrderList forKey:kScreenName];
  2265. //
  2266. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2267. //
  2268. // NSArray* keys=[customerinfo allKeys];
  2269. // for(int i=0;i<keys.count;i++)
  2270. // {
  2271. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2272. // }
  2273. //
  2274. // NSData* json = nil;
  2275. // if(appDelegate.offline_mode)
  2276. // {
  2277. // json= [OLDataProvider offline_createorder:params];
  2278. // }
  2279. // else
  2280. // {
  2281. // if(![self IsNetworkAvailable])
  2282. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2283. //
  2284. // json=[self get_json:URL_NEW_ORDER parameters:params];
  2285. // }
  2286. // if(json==nil)
  2287. // return nil;
  2288. // NSError *error=nil;
  2289. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2290. // int result = [[jsobj valueForKey:@"result"] intValue];
  2291. //
  2292. // if (result==2)
  2293. // {
  2294. //
  2295. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2296. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2297. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2298. //
  2299. // [appDelegate update_count_mark];
  2300. // }
  2301. //
  2302. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  2303. //
  2304. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  2305. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  2306. // }
  2307. //
  2308. // return jsobj;
  2309. //}
  2310. +(NSDictionary*) add_toPortfolio:(NSString* ) item_id withScreen:(NSString *)screenName
  2311. {
  2312. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2313. __block AppDelegate *appDelegate = nil;
  2314. dispatch_sync(dispatch_get_main_queue(), ^{
  2315. //some UI methods ej
  2316. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2317. });
  2318. if(appDelegate.user!=nil)
  2319. [params setValue:appDelegate.user forKey:@"user"];
  2320. if(appDelegate.contact_id!=nil)
  2321. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2322. if(appDelegate.password!=nil)
  2323. [params setValue:appDelegate.password forKey:@"password"];
  2324. [params setValue:item_id forKey:@"product_id"];
  2325. [params setObject:screenName forKey:kScreenName];
  2326. NSData* json = nil;
  2327. if(appDelegate.offline_mode)
  2328. {
  2329. json = [OLDataProvider offline_add2Portfolio:params];
  2330. } else {
  2331. if(![self IsNetworkAvailable])
  2332. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2333. json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  2334. }
  2335. if(json==nil)
  2336. return nil;
  2337. NSError *error=nil;
  2338. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2339. int result = [[jsobj valueForKey:@"result"] intValue];
  2340. if (result==2)
  2341. {
  2342. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2343. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2344. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2345. [appDelegate update_count_mark];
  2346. }
  2347. return jsobj;
  2348. }
  2349. //+(NSDictionary*) add_toWatchList:(NSString* ) item_id withScreen:(NSString *)screenName
  2350. //{
  2351. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2352. // __block AppDelegate *appDelegate = nil;
  2353. //
  2354. // dispatch_sync(dispatch_get_main_queue(), ^{
  2355. // //some UI methods ej
  2356. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2357. // });
  2358. // if(appDelegate.user!=nil)
  2359. // [params setValue:appDelegate.user forKey:@"user"];
  2360. // if(appDelegate.contact_id!=nil)
  2361. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2362. // if(appDelegate.password!=nil)
  2363. // [params setValue:appDelegate.password forKey:@"password"];
  2364. //
  2365. //
  2366. // [params setValue:item_id forKey:@"product_id"];
  2367. //
  2368. // [params setObject:screenName forKey:kScreenName];
  2369. //
  2370. // if(appDelegate.offline_mode)
  2371. // {
  2372. // return [OLDataProvider offline_add2wishlist:params];
  2373. // }
  2374. // if(![self IsNetworkAvailable])
  2375. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2376. //
  2377. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  2378. // if(json==nil)
  2379. // return nil;
  2380. // NSError *error=nil;
  2381. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2382. // int result = [[jsobj valueForKey:@"result"] intValue];
  2383. //
  2384. // if (result==2)
  2385. // {
  2386. //
  2387. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2388. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2389. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2390. //
  2391. // [appDelegate update_count_mark];
  2392. // }
  2393. // return jsobj;
  2394. //}
  2395. //+(NSDictionary*) cart_setPrice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes
  2396. //{
  2397. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2398. // __block AppDelegate *appDelegate = nil;
  2399. //
  2400. // dispatch_sync(dispatch_get_main_queue(), ^{
  2401. // //some UI methods ej
  2402. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2403. // });
  2404. // if(appDelegate.user!=nil)
  2405. // [params setValue:appDelegate.user forKey:@"user"];
  2406. // if(appDelegate.contact_id!=nil)
  2407. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2408. // if(appDelegate.password!=nil)
  2409. // [params setValue:appDelegate.password forKey:@"password"];
  2410. //
  2411. // [params setValue:cart_id forKey:@"cartitem_id"];
  2412. // [params setValue:notes forKey:@"item_note"];
  2413. //
  2414. // [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  2415. //
  2416. // [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  2417. //
  2418. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2419. //
  2420. // NSData* json= nil;
  2421. // if(appDelegate.offline_mode)
  2422. // {
  2423. // json=[OLDataProvider offline_cartsetprice:params];
  2424. // }
  2425. // else
  2426. // {
  2427. // if(![self IsNetworkAvailable])
  2428. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2429. //
  2430. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2431. // }
  2432. // if(json==nil)
  2433. // return nil;
  2434. // NSError *error=nil;
  2435. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2436. // return jsobj;
  2437. //}
  2438. //+(NSDictionary*) portfolio_setQTY:(NSString*) watchlist_id QTY:(int)qty
  2439. //{
  2440. // if(![self IsNetworkAvailable])
  2441. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2442. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2443. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2444. // if(appDelegate.user!=nil)
  2445. // [params setValue:appDelegate.user forKey:@"user"];
  2446. // if(appDelegate.contact_id!=nil)
  2447. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2448. // if(appDelegate.password!=nil)
  2449. // [params setValue:appDelegate.password forKey:@"password"];
  2450. //
  2451. // [params setValue:watchlist_id forKey:@"item_id"];
  2452. //
  2453. // [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  2454. //
  2455. //
  2456. //
  2457. // NSData* json=[self get_json:URL_DM_SET_QTY parameters:params];
  2458. // if(json==nil)
  2459. // return nil;
  2460. // NSError *error=nil;
  2461. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2462. // return jsobj;
  2463. //}
  2464. +(NSDictionary*) portfolio_setPrice:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes
  2465. {
  2466. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2467. __block AppDelegate *appDelegate = nil;
  2468. dispatch_sync(dispatch_get_main_queue(), ^{
  2469. //some UI methods ej
  2470. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2471. });
  2472. if(appDelegate.user!=nil)
  2473. [params setValue:appDelegate.user forKey:@"user"];
  2474. if(appDelegate.contact_id!=nil)
  2475. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2476. if(appDelegate.password!=nil)
  2477. [params setValue:appDelegate.password forKey:@"password"];
  2478. [params setValue:watchlist_id forKey:@"item_id"];
  2479. // if(notes.length>0)
  2480. // [params setValue:notes forKey:@"notes"];
  2481. if(notes)
  2482. [params setValue:notes forKey:@"notes"];
  2483. if(price != -MAXFLOAT)
  2484. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  2485. if (discount != -MAXFLOAT)
  2486. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  2487. if(qty_p != -MAXFLOAT)
  2488. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  2489. if(qty != -INT32_MAX)
  2490. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  2491. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2492. NSData* json = nil;
  2493. if(appDelegate.offline_mode)
  2494. {
  2495. json = [OLDataProvider offline_editPortfolio:params];
  2496. } else {
  2497. if(![self IsNetworkAvailable])
  2498. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2499. json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  2500. }
  2501. if(json==nil)
  2502. return nil;
  2503. NSError *error=nil;
  2504. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2505. return jsobj;
  2506. }
  2507. //+(NSDictionary*) cart_setGeneralNote:(NSString*) order_code notes:(NSString*) notes
  2508. //{
  2509. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2510. // __block AppDelegate *appDelegate = nil;
  2511. //
  2512. // dispatch_sync(dispatch_get_main_queue(), ^{
  2513. // //some UI methods ej
  2514. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2515. // });
  2516. // if(appDelegate.user!=nil)
  2517. // [params setValue:appDelegate.user forKey:@"user"];
  2518. // if(appDelegate.contact_id!=nil)
  2519. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2520. // if(appDelegate.password!=nil)
  2521. // [params setValue:appDelegate.password forKey:@"password"];
  2522. //
  2523. // [params setValue:order_code forKey:@"orderCode"];
  2524. //
  2525. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2526. //
  2527. // if(notes.length==0)
  2528. // notes=@"";
  2529. //
  2530. //
  2531. // [params setValue:notes forKey:@"comments"];
  2532. // NSData* json=nil;
  2533. // if(appDelegate.offline_mode)
  2534. // {
  2535. // json= [OLDataProvider offline_updategnotes:params];
  2536. // }
  2537. // else
  2538. // {
  2539. // if(![self IsNetworkAvailable])
  2540. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2541. //
  2542. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  2543. // }
  2544. // if(json==nil)
  2545. // return nil;
  2546. // NSError *error=nil;
  2547. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2548. // return jsobj;
  2549. //}
  2550. //+(NSDictionary*) cart_setItemNote:(NSString*) cart_id notes:(NSString*) notes
  2551. //{
  2552. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2553. // __block AppDelegate *appDelegate = nil;
  2554. //
  2555. // dispatch_sync(dispatch_get_main_queue(), ^{
  2556. // //some UI methods ej
  2557. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2558. // });
  2559. // if(appDelegate.user!=nil)
  2560. // [params setValue:appDelegate.user forKey:@"user"];
  2561. // if(appDelegate.contact_id!=nil)
  2562. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2563. // if(appDelegate.password!=nil)
  2564. // [params setValue:appDelegate.password forKey:@"password"];
  2565. //
  2566. // [params setValue:cart_id forKey:@"cartitem_id"];
  2567. //
  2568. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2569. //
  2570. // if(notes.length==0)
  2571. // notes=@"";
  2572. //
  2573. //
  2574. // [params setValue:notes forKey:@"notes"];
  2575. // NSData* json=nil;
  2576. // if(appDelegate.offline_mode)
  2577. // {
  2578. // json= [OLDataProvider offline_cartsetlnotes:params];
  2579. // }
  2580. // else
  2581. // {
  2582. // if(![self IsNetworkAvailable])
  2583. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2584. //
  2585. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  2586. // }
  2587. // if(json==nil)
  2588. // return nil;
  2589. // NSError *error=nil;
  2590. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2591. // return jsobj;
  2592. //}
  2593. //+(NSDictionary*) cart_setFree:(NSString*) cart_id isfree:(bool) isfree
  2594. //{
  2595. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2596. // __block AppDelegate *appDelegate = nil;
  2597. //
  2598. // dispatch_sync(dispatch_get_main_queue(), ^{
  2599. // //some UI methods ej
  2600. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2601. // });
  2602. // if(appDelegate.user!=nil)
  2603. // [params setValue:appDelegate.user forKey:@"user"];
  2604. // if(appDelegate.contact_id!=nil)
  2605. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2606. // if(appDelegate.password!=nil)
  2607. // [params setValue:appDelegate.password forKey:@"password"];
  2608. //
  2609. // [params setValue:cart_id forKey:@"cartitem_id"];
  2610. //
  2611. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2612. //
  2613. // NSString* free=nil;
  2614. //
  2615. // if(isfree)
  2616. // free=@"true";
  2617. // else
  2618. // free=@"false";
  2619. //
  2620. // [params setValue:free forKey:@"free_giveaway"];
  2621. //
  2622. // if(appDelegate.offline_mode)
  2623. // {
  2624. // return [OLDataProvider offline_notimpl];
  2625. // }
  2626. // if(![self IsNetworkAvailable])
  2627. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2628. //
  2629. // NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2630. // if(json==nil)
  2631. // return nil;
  2632. // NSError *error=nil;
  2633. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2634. // return jsobj;
  2635. //}
  2636. //+(NSDictionary*) cart_setQTY:(NSString*) cart_id value:(int) value
  2637. //{
  2638. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2639. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2640. // if(appDelegate.user!=nil)
  2641. // [params setValue:appDelegate.user forKey:@"user"];
  2642. // if(appDelegate.contact_id!=nil)
  2643. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2644. // if(appDelegate.password!=nil)
  2645. // [params setValue:appDelegate.password forKey:@"password"];
  2646. //
  2647. // [params setValue:cart_id forKey:@"cartitem_id"];
  2648. //
  2649. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2650. //
  2651. // [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  2652. //
  2653. // NSData* json=nil;
  2654. // if(appDelegate.offline_mode)
  2655. // {
  2656. // json= [OLDataProvider offline_cartsetqty:params];
  2657. // }
  2658. // else
  2659. // {
  2660. // if(![self IsNetworkAvailable])
  2661. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2662. //
  2663. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2664. // }
  2665. // if(json==nil)
  2666. // return nil;
  2667. // NSError *error=nil;
  2668. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2669. // return jsobj;
  2670. //
  2671. //}
  2672. //+(NSDictionary*) cart_incresement:(NSString*) cart_id increse:(bool) increse
  2673. //{
  2674. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2675. // __block AppDelegate *appDelegate = nil;
  2676. //
  2677. // dispatch_sync(dispatch_get_main_queue(), ^{
  2678. // //some UI methods ej
  2679. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2680. // });
  2681. // if(appDelegate.user!=nil)
  2682. // [params setValue:appDelegate.user forKey:@"user"];
  2683. // if(appDelegate.contact_id!=nil)
  2684. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2685. // if(appDelegate.password!=nil)
  2686. // [params setValue:appDelegate.password forKey:@"password"];
  2687. //
  2688. // [params setValue:cart_id forKey:@"cartitem_id"];
  2689. //
  2690. // if(increse)
  2691. // [params setValue:@"1" forKey:@"incrementType"];
  2692. // else
  2693. // [params setValue:@"0" forKey:@"incrementType"];
  2694. //
  2695. //
  2696. //
  2697. // if(appDelegate.offline_mode)
  2698. // {
  2699. // return [OLDataProvider offline_notimpl];
  2700. // }
  2701. // if(![self IsNetworkAvailable])
  2702. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2703. //
  2704. // NSData* json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2705. // if(json==nil)
  2706. // return nil;
  2707. // NSError *error=nil;
  2708. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2709. // return jsobj;
  2710. //}
  2711. +(NSDictionary*) finish_download_Offline:(NSString* )vid
  2712. {
  2713. if(![self IsNetworkAvailable])
  2714. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2715. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2716. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  2717. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  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. [params setValue:vid forKey:@"downSerial"];
  2725. NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  2726. if(json==nil)
  2727. return nil;
  2728. NSError *error=nil;
  2729. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2730. // int result = [[jsobj valueForKey:@"result"] intValue];
  2731. //
  2732. // if (result==2)
  2733. // {
  2734. //
  2735. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2736. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2737. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2738. ////
  2739. //// [appDelegate update_count_mark];
  2740. // }
  2741. return jsobj;
  2742. }
  2743. +(NSDictionary*) download_Offline:(NSString* )vid
  2744. {
  2745. if(![self IsNetworkAvailable])
  2746. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2747. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2748. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2749. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2750. // if(appDelegate.user!=nil)
  2751. // [params setValue:appDelegate.user forKey:@"user"];
  2752. // // if(appDelegate.contact_id!=nil)
  2753. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2754. // if(appDelegate.password!=nil)
  2755. // [params setValue:appDelegate.password forKey:@"password"];
  2756. [params setValue:vid forKey:@"downSerial"];
  2757. NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  2758. if(json==nil)
  2759. return nil;
  2760. NSError *error=nil;
  2761. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2762. // int result = [[jsobj valueForKey:@"result"] intValue];
  2763. //
  2764. // if (result==2)
  2765. // {
  2766. //
  2767. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2768. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2769. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2770. ////
  2771. //// [appDelegate update_count_mark];
  2772. // }
  2773. return jsobj;
  2774. }
  2775. +(NSDictionary*) check_Offline:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid
  2776. {
  2777. if(![self IsNetworkAvailable])
  2778. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2779. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2780. __block AppDelegate *appDelegate = nil;
  2781. dispatch_sync(dispatch_get_main_queue(), ^{
  2782. //some UI methods ej
  2783. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2784. });
  2785. if(appDelegate.user!=nil)
  2786. [params setValue:appDelegate.user forKey:@"user"];
  2787. // if(appDelegate.contact_id!=nil)
  2788. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2789. if(appDelegate.password!=nil)
  2790. [params setValue:appDelegate.password forKey:@"password"];
  2791. [params setValue:ver forKey:@"ver"];
  2792. [params setValue:vid forKey:@"vid"];
  2793. if(buseinternaladdress)
  2794. [params setValue:@"true" forKey:@"internal_address"];
  2795. else
  2796. [params setValue:@"false" forKey:@"internal_address"];
  2797. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2798. NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  2799. if(json==nil)
  2800. return nil;
  2801. NSError *error=nil;
  2802. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2803. // int result = [[jsobj valueForKey:@"result"] intValue];
  2804. //
  2805. // if (result==2)
  2806. // {
  2807. //
  2808. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2809. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2810. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2811. ////
  2812. //// [appDelegate update_count_mark];
  2813. // }
  2814. return jsobj;
  2815. }
  2816. //+(NSDictionary*)request_Cart:(int)sort
  2817. //{
  2818. //
  2819. // DebugLog(@"iSalesNetwork::request_Cart");
  2820. //
  2821. //
  2822. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2823. // __block AppDelegate *appDelegate = nil;
  2824. //
  2825. // dispatch_sync(dispatch_get_main_queue(), ^{
  2826. // //some UI methods ej
  2827. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2828. // });
  2829. // if(appDelegate.user!=nil)
  2830. // [params setValue:appDelegate.user forKey:@"user"];
  2831. // // if(appDelegate.contact_id!=nil)
  2832. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2833. // if(appDelegate.password!=nil)
  2834. // [params setValue:appDelegate.password forKey:@"password"];
  2835. //
  2836. // if(appDelegate.order_code!=nil)
  2837. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2838. //
  2839. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2840. //
  2841. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2842. //
  2843. // NSData* json=nil;
  2844. // if(appDelegate.offline_mode)
  2845. // {
  2846. // json= [OLDataProvider offline_requestcart:params];
  2847. // }
  2848. // else
  2849. // {
  2850. // if(![self IsNetworkAvailable])
  2851. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2852. //
  2853. // NSError *error=nil;
  2854. //
  2855. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2856. // params[@"resultSerial"]=uuid;
  2857. //
  2858. // for(int i=0;i<150;i++)
  2859. // {
  2860. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2861. // // result_params[@"resultSerial"]=uuid;
  2862. // json=[self get_json:URL_CART parameters:params];
  2863. // if(json!=nil)
  2864. // {
  2865. //
  2866. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2867. // if([jsobj[@"result"] intValue]==2)
  2868. // {
  2869. // break;
  2870. // }
  2871. // }
  2872. // sleep(2);
  2873. // }
  2874. //
  2875. // }
  2876. // if(json==nil)
  2877. // return nil;
  2878. // NSError *error=nil;
  2879. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2880. // int result = [[jsobj valueForKey:@"result"] intValue];
  2881. //
  2882. // if (result==2)
  2883. // {
  2884. //
  2885. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2886. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2887. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2888. //
  2889. // [appDelegate update_count_mark];
  2890. // }
  2891. // return jsobj;
  2892. //}
  2893. //+(NSDictionary*)request_Portfolio:(int)sort
  2894. //{
  2895. //
  2896. //
  2897. //
  2898. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2899. // __block AppDelegate *appDelegate = nil;
  2900. //
  2901. // dispatch_sync(dispatch_get_main_queue(), ^{
  2902. // //some UI methods ej
  2903. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2904. // });
  2905. // if(appDelegate.user!=nil)
  2906. // [params setValue:appDelegate.user forKey:@"user"];
  2907. // if(appDelegate.contact_id!=nil)
  2908. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2909. // if(appDelegate.password!=nil)
  2910. // [params setValue:appDelegate.password forKey:@"password"];
  2911. //
  2912. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2913. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2914. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2915. //
  2916. // [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2917. //
  2918. // NSData* json = nil;
  2919. // if(appDelegate.offline_mode)
  2920. // {
  2921. // json = [OLDataProvider offline_portfolioList:params];
  2922. // } else {
  2923. // if(![self IsNetworkAvailable])
  2924. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2925. //
  2926. // json = [self get_json:URL_PORTFOLIO parameters:params];
  2927. // }
  2928. //
  2929. //
  2930. // if(json==nil)
  2931. // return nil;
  2932. // NSError *error=nil;
  2933. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2934. // int result = [[jsobj valueForKey:@"result"] intValue];
  2935. //
  2936. // if (result==2)
  2937. // {
  2938. //
  2939. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2940. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2941. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  2942. //
  2943. // [appDelegate update_count_mark];
  2944. // }
  2945. // return jsobj;
  2946. //}
  2947. //+(NSDictionary*)request_WatchList:(int)sort
  2948. //{
  2949. //
  2950. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2951. // __block AppDelegate *appDelegate = nil;
  2952. //
  2953. // dispatch_sync(dispatch_get_main_queue(), ^{
  2954. // //some UI methods ej
  2955. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2956. // });
  2957. // if(appDelegate.user!=nil)
  2958. // [params setValue:appDelegate.user forKey:@"user"];
  2959. // if(appDelegate.contact_id!=nil)
  2960. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2961. // if(appDelegate.password!=nil)
  2962. // [params setValue:appDelegate.password forKey:@"password"];
  2963. //
  2964. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2965. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2966. //
  2967. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2968. //
  2969. // [params setObject:ScreenCodeWishList forKey:kScreenName];
  2970. //
  2971. // if(appDelegate.offline_mode)
  2972. // {
  2973. // return [OLDataProvider offline_wishlist:params];
  2974. // }
  2975. // if(![self IsNetworkAvailable])
  2976. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2977. //
  2978. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  2979. // if(json==nil)
  2980. // return nil;
  2981. // NSError *error=nil;
  2982. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2983. // int result = [[jsobj valueForKey:@"result"] intValue];
  2984. //
  2985. // if (result==2)
  2986. // {
  2987. //
  2988. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2989. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2990. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2991. //
  2992. // [appDelegate update_count_mark];
  2993. // }
  2994. // return jsobj;
  2995. //}
  2996. //+(NSDictionary*)request_ItemDetail: (NSString* ) item_id model_name:(NSString*) model_name category_id:(NSString*) category_id use_name :(bool) use_name groupName:(NSString *)groupName
  2997. //{
  2998. //
  2999. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3000. // __block AppDelegate *appDelegate = nil;
  3001. //
  3002. // dispatch_sync(dispatch_get_main_queue(), ^{
  3003. // //some UI methods ej
  3004. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3005. // });
  3006. // if(appDelegate.user!=nil)
  3007. // [params setValue:appDelegate.user forKey:@"user"];
  3008. // if(appDelegate.contact_id!=nil)
  3009. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3010. // if(appDelegate.password!=nil)
  3011. // [params setValue:appDelegate.password forKey:@"password"];
  3012. // if(appDelegate.order_code!=nil)
  3013. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3014. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3015. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3016. // if(use_name)
  3017. // [params setValue:model_name forKey:@"product_name"];
  3018. // else
  3019. // [params setValue:item_id forKey:@"product_id"];
  3020. //
  3021. //
  3022. // [params setValue:category_id forKey:@"category"];
  3023. //
  3024. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  3025. // [params setObject:@"Open A Model" forKey:kAction];
  3026. // if (model_name) {
  3027. // NSDictionary *extra = @{@"ModelName" : model_name};
  3028. // [params setObject:extra forKey:kExtra];
  3029. // }
  3030. //
  3031. // if (groupName.length > 0) {
  3032. // [params setObject:groupName forKey:@"groupName"];
  3033. // }
  3034. //
  3035. // if(appDelegate.offline_mode)
  3036. // return [OLDataProvider offline_model:params];
  3037. //
  3038. // if(![self IsNetworkAvailable])
  3039. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3040. //
  3041. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  3042. // if(json==nil)
  3043. // return nil;
  3044. // NSError *error=nil;
  3045. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3046. // return jsobj;
  3047. //}
  3048. //+(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
  3049. //{
  3050. // if(![self IsNetworkAvailable])
  3051. // return nil;
  3052. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3053. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3054. // if(appDelegate.user!=nil)
  3055. // [params setValue:appDelegate.user forKey:@"user"];
  3056. // if(appDelegate.contact_id!=nil)
  3057. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3058. // if(appDelegate.password!=nil)
  3059. // [params setValue:appDelegate.password forKey:@"password"];
  3060. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3061. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3062. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3063. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3064. // [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  3065. // [params setValue:filter forKey:@"filter"];
  3066. // [params setValue:keyword forKey:@"keyword"];
  3067. //
  3068. //
  3069. // NSData* json=[self get_json:URL_CATEGORY_LOADMORE parameters:params];
  3070. // if(json==nil)
  3071. // return nil;
  3072. // NSError *error=nil;
  3073. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3074. // return jsobj;
  3075. //
  3076. //}
  3077. //+(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
  3078. //
  3079. //{
  3080. //
  3081. //
  3082. // __block AppDelegate *appDelegate = nil;
  3083. //
  3084. // dispatch_sync(dispatch_get_main_queue(), ^{
  3085. // //some UI methods ej
  3086. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3087. // });
  3088. //
  3089. //
  3090. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3091. //
  3092. // if(appDelegate.user!=nil)
  3093. // [params setValue:appDelegate.user forKey:@"user"];
  3094. // if(appDelegate.contact_id!=nil)
  3095. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3096. // if(appDelegate.password!=nil)
  3097. // [params setValue:appDelegate.password forKey:@"password"];
  3098. // if(appDelegate.order_code!=nil)
  3099. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3100. //
  3101. // [params setValue:addTo forKey:@"addTo"];
  3102. // [params setValue:orderCode forKey:@"orderCode"];
  3103. // [params setValue:alert forKey:@"alert"];
  3104. // [params setValue:qty forKey:@"sold_by_qty"];
  3105. // [params setValue:available forKey:@"available"];
  3106. // [params setValue:price forKey:@"price"];
  3107. // [params setValue:bestseller forKey:@"bestseller"];
  3108. // [params setValue:modelname forKey:@"modelName"];
  3109. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3110. //
  3111. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3112. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3113. // [params setValue:category forKey:@"category"];
  3114. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3115. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3116. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3117. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3118. // [params setValue:filter forKey:@"filter"];
  3119. // [params setValue:keyword forKey:@"keyword"];
  3120. //
  3121. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  3122. // if ([addTo isEqualToString:@"cart"]) {
  3123. // [params setObject:@"Add To Cart" forKey:kAction];
  3124. // }
  3125. //
  3126. //
  3127. // NSData* json= nil;
  3128. //
  3129. // if(appDelegate.offline_mode)
  3130. // {
  3131. // json= [OLDataProvider offline_categoryaddall:params];
  3132. // }
  3133. // else
  3134. // {
  3135. // if(![self IsNetworkAvailable])
  3136. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3137. //
  3138. //
  3139. // NSError *error=nil;
  3140. //
  3141. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3142. // params[@"resultSerial"]=uuid;
  3143. //
  3144. // for(int i=0;i<150;i++)
  3145. // {
  3146. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3147. // // result_params[@"resultSerial"]=uuid;
  3148. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  3149. // if(json!=nil)
  3150. // {
  3151. //
  3152. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3153. // int resultInt = [jsobj[@"result"] intValue];
  3154. // if(resultInt == 2 || resultInt == 8)
  3155. // {
  3156. // break;
  3157. // }
  3158. // }
  3159. // sleep(2);
  3160. // }
  3161. //
  3162. //
  3163. //
  3164. // }
  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. //}
  3172. //+(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
  3173. //{
  3174. //
  3175. //
  3176. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3177. //
  3178. //
  3179. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3180. //
  3181. // if(appDelegate.user!=nil)
  3182. // [params setValue:appDelegate.user forKey:@"user"];
  3183. // if(appDelegate.contact_id!=nil)
  3184. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3185. // if(appDelegate.password!=nil)
  3186. // [params setValue:appDelegate.password forKey:@"password"];
  3187. // if(appDelegate.order_code!=nil)
  3188. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3189. //
  3190. // [params setValue:alert forKey:@"alert"];
  3191. // [params setValue:qty forKey:@"sold_by_qty"];
  3192. // [params setValue:available forKey:@"available"];
  3193. // [params setValue:price forKey:@"price"];
  3194. // [params setValue:bestseller forKey:@"bestseller"];
  3195. // [params setValue:modelname forKey:@"modelName"];
  3196. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3197. //
  3198. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3199. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3200. // [params setValue:category forKey:@"category"];
  3201. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3202. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3203. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3204. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3205. // [params setValue:filter forKey:@"filter"];
  3206. // [params setValue:keyword forKey:@"keyword"];
  3207. //
  3208. //
  3209. //
  3210. // if(appDelegate.offline_mode)
  3211. // return [OLDataProvider offline_category:params];
  3212. // if(![self IsNetworkAvailable])
  3213. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3214. //
  3215. // NSData* json=[self get_json:URL_ADDALL2PORTFOLIO parameters:params];
  3216. // if(json==nil)
  3217. // return nil;
  3218. // NSError *error=nil;
  3219. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3220. // return jsobj;
  3221. //
  3222. //}
  3223. //+(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
  3224. //{
  3225. //
  3226. //
  3227. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3228. //
  3229. //
  3230. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3231. //
  3232. // if(appDelegate.user!=nil)
  3233. // [params setValue:appDelegate.user forKey:@"user"];
  3234. // if(appDelegate.contact_id!=nil)
  3235. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3236. // if(appDelegate.password!=nil)
  3237. // [params setValue:appDelegate.password forKey:@"password"];
  3238. // if(appDelegate.order_code!=nil)
  3239. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3240. //
  3241. // [params setValue:alert forKey:@"alert"];
  3242. // [params setValue:qty forKey:@"sold_by_qty"];
  3243. // [params setValue:available forKey:@"available"];
  3244. // [params setValue:price forKey:@"price"];
  3245. // [params setValue:bestseller forKey:@"bestseller"];
  3246. // [params setValue:modelname forKey:@"modelName"];
  3247. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3248. //
  3249. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3250. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3251. // [params setValue:category forKey:@"category"];
  3252. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3253. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3254. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3255. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3256. // [params setValue:filter forKey:@"filter"];
  3257. // [params setValue:keyword forKey:@"keyword"];
  3258. //
  3259. //
  3260. //
  3261. // if(appDelegate.offline_mode)
  3262. // return [OLDataProvider offline_category:params];
  3263. // if(![self IsNetworkAvailable])
  3264. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3265. //
  3266. // NSData* json=[self get_json:URL_ADDALL2WISH parameters:params];
  3267. // if(json==nil)
  3268. // return nil;
  3269. // NSError *error=nil;
  3270. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3271. // return jsobj;
  3272. //
  3273. //}
  3274. //+(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
  3275. //{
  3276. //
  3277. //
  3278. // __block AppDelegate *appDelegate = nil;
  3279. //
  3280. // dispatch_sync(dispatch_get_main_queue(), ^{
  3281. // //some UI methods ej
  3282. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3283. // });
  3284. //
  3285. //
  3286. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3287. //
  3288. // if(appDelegate.user!=nil)
  3289. // [params setValue:appDelegate.user forKey:@"user"];
  3290. // if(appDelegate.contact_id!=nil)
  3291. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3292. // if(appDelegate.password!=nil)
  3293. // [params setValue:appDelegate.password forKey:@"password"];
  3294. // if(appDelegate.order_code!=nil)
  3295. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3296. //
  3297. // [params setValue:alert forKey:@"alert"];
  3298. // [params setValue:qty forKey:@"sold_by_qty"];
  3299. // [params setValue:available forKey:@"available"];
  3300. // [params setValue:price forKey:@"price"];
  3301. // [params setValue:bestseller forKey:@"bestseller"];
  3302. // [params setValue:modelname forKey:@"modelName"];
  3303. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3304. //
  3305. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3306. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3307. // [params setValue:category forKey:@"category"];
  3308. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3309. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3310. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3311. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3312. // [params setValue:filter forKey:@"filter"];
  3313. // [params setValue:keyword forKey:@"keyword"];
  3314. //
  3315. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  3316. // if (alert) {
  3317. // [params setObject:@"Filter" forKey:kAction];
  3318. // }
  3319. // if ([Singleton sharedInstance].homeItemClick) {
  3320. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  3321. // [Singleton sharedInstance].homeItemClick = NO;
  3322. //
  3323. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  3324. // [Singleton sharedInstance].homeClickedItemName = nil;
  3325. // [params setObject:extra forKey:kExtra];
  3326. //
  3327. // }
  3328. //
  3329. //
  3330. // if(appDelegate.offline_mode)
  3331. // return [OLDataProvider offline_category:params];
  3332. // if(![self IsNetworkAvailable])
  3333. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3334. //
  3335. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  3336. // if(json==nil)
  3337. // return nil;
  3338. // NSError *error=nil;
  3339. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3340. // return jsobj;
  3341. //
  3342. //}
  3343. //+(NSDictionary*)Search_addall:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  3344. //{
  3345. //
  3346. //
  3347. //
  3348. //
  3349. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3350. // __block AppDelegate *appDelegate = nil;
  3351. //
  3352. // dispatch_sync(dispatch_get_main_queue(), ^{
  3353. // //some UI methods ej
  3354. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3355. // });
  3356. // if(appDelegate.user!=nil)
  3357. // [params setValue:appDelegate.user forKey:@"user"];
  3358. // if(appDelegate.contact_id!=nil)
  3359. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3360. // if(appDelegate.password!=nil)
  3361. // [params setValue:appDelegate.password forKey:@"password"];
  3362. // if(appDelegate.order_code!=nil)
  3363. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3364. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3365. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3366. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3367. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3368. // // [params setValue:filter forKey:@"filter"];
  3369. // [params setValue:keywords forKey:@"keyword"];
  3370. // [params setValue:addTo forKey:@"addTo"];
  3371. //
  3372. // [params setValue:orderCode forKey:@"orderCode"];
  3373. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3374. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3375. // if(matchfull)
  3376. // [params setValue:@"true" forKey:@"exactMatch"];
  3377. // else
  3378. // [params setValue:@"false" forKey:@"exactMatch"];
  3379. //
  3380. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  3381. // if ([addTo isEqualToString:@"cart"]) {
  3382. // [params setObject:@"Add To Cart" forKey:kAction];
  3383. // }
  3384. //
  3385. // NSData* json=nil;
  3386. // if(appDelegate.offline_mode)
  3387. // {
  3388. // json=[OLDataProvider offline_searchaddall:params];
  3389. // }
  3390. // else
  3391. // {
  3392. // if(![self IsNetworkAvailable])
  3393. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3394. //
  3395. // NSError *error=nil;
  3396. //
  3397. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3398. // params[@"resultSerial"]=uuid;
  3399. //
  3400. // for(int i=0;i<150;i++)
  3401. // {
  3402. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3403. // // result_params[@"resultSerial"]=uuid;
  3404. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  3405. // if(json!=nil)
  3406. // {
  3407. //
  3408. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3409. // if([jsobj[@"result"] intValue]==2)
  3410. // {
  3411. // break;
  3412. // }
  3413. // }
  3414. // sleep(2);
  3415. // }
  3416. // }
  3417. // if(json==nil)
  3418. // return nil;
  3419. // NSError *error=nil;
  3420. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3421. // return jsobj;
  3422. //
  3423. //}
  3424. //+(NSDictionary*)Search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull
  3425. //{
  3426. //
  3427. //
  3428. //
  3429. //
  3430. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3431. // __block AppDelegate *appDelegate = nil;
  3432. //
  3433. // dispatch_sync(dispatch_get_main_queue(), ^{
  3434. // //some UI methods ej
  3435. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3436. // });
  3437. // if(appDelegate.user!=nil)
  3438. // [params setValue:appDelegate.user forKey:@"user"];
  3439. // if(appDelegate.contact_id!=nil)
  3440. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3441. // if(appDelegate.password!=nil)
  3442. // [params setValue:appDelegate.password forKey:@"password"];
  3443. // if(appDelegate.order_code!=nil)
  3444. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3445. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3446. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3447. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3448. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3449. // // [params setValue:filter forKey:@"filter"];
  3450. // [params setValue:keywords forKey:@"keyword"];
  3451. //
  3452. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3453. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3454. // if(matchfull)
  3455. // [params setValue:@"true" forKey:@"exactMatch"];
  3456. // else
  3457. // [params setValue:@"false" forKey:@"exactMatch"];
  3458. //
  3459. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  3460. // if (keywords) {
  3461. // [params setObject:@"Search" forKey:kAction];
  3462. // }
  3463. //
  3464. // if(appDelegate.offline_mode)
  3465. // {
  3466. // return [OLDataProvider offline_search:params];
  3467. // }
  3468. // if(![self IsNetworkAvailable])
  3469. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3470. //
  3471. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3472. // if(json==nil)
  3473. // return nil;
  3474. // NSError *error=nil;
  3475. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3476. // return jsobj;
  3477. //}
  3478. //+(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
  3479. //{
  3480. // // for debug
  3481. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3482. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3483. //
  3484. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3485. // __block AppDelegate *appDelegate = nil;
  3486. //
  3487. // dispatch_sync(dispatch_get_main_queue(), ^{
  3488. // //some UI methods ej
  3489. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3490. // });
  3491. // if(appDelegate.user!=nil)
  3492. // [params setValue:appDelegate.user forKey:@"user"];
  3493. // if(appDelegate.contact_id!=nil)
  3494. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3495. // if(appDelegate.password!=nil)
  3496. // [params setValue:appDelegate.password forKey:@"password"];
  3497. // if(appDelegate.order_code!=nil)
  3498. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3499. //
  3500. // [params setValue:addTo forKey:@"addTo"];
  3501. //
  3502. // [params setValue:orderCode forKey:@"orderCode"];
  3503. //
  3504. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3505. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3506. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3507. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3508. // // [params setValue:filter forKey:@"filter"];
  3509. // [params setValue:covertype forKey:@"covertype"];
  3510. // [params setValue:ctgid forKey:@"ctgId"];
  3511. // [params setValue:modelname forKey:@"modelName"];
  3512. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3513. // [params setValue:alert forKey:@"alert"];
  3514. // [params setValue:qty forKey:@"sold_by_qty"];
  3515. // [params setValue:available forKey:@"available"];
  3516. // [params setValue:price forKey:@"price"];
  3517. // [params setValue:bestseller forKey:@"bestseller"];
  3518. //
  3519. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3520. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3521. //
  3522. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3523. // if ([addTo isEqualToString:@"cart"]) {
  3524. // [params setObject:@"Add To Cart" forKey:kAction];
  3525. // }
  3526. //
  3527. // NSData* json = nil;
  3528. //
  3529. // if(appDelegate.offline_mode)
  3530. // {
  3531. // json= [OLDataProvider offline_itemsearchaddall:params];
  3532. // }
  3533. // else
  3534. // {
  3535. // if(![self IsNetworkAvailable])
  3536. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3537. // NSError *error=nil;
  3538. //
  3539. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3540. // params[@"resultSerial"]=uuid;
  3541. //
  3542. // for(int i=0;i<150;i++)
  3543. // {
  3544. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3545. // // result_params[@"resultSerial"]=uuid;
  3546. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  3547. // if(json!=nil)
  3548. // {
  3549. //
  3550. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3551. // if([jsobj[@"result"] intValue]==2)
  3552. // {
  3553. // break;
  3554. // }
  3555. // }
  3556. // sleep(2);
  3557. // }
  3558. // }
  3559. // if(json==nil)
  3560. // return nil;
  3561. // NSError *error=nil;
  3562. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3563. // return jsobj;
  3564. //}
  3565. //+(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
  3566. //{
  3567. //
  3568. // // for debug
  3569. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3570. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3571. //
  3572. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3573. // __block AppDelegate *appDelegate = nil;
  3574. //
  3575. // dispatch_sync(dispatch_get_main_queue(), ^{
  3576. // //some UI methods ej
  3577. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3578. // });
  3579. // if(appDelegate.user!=nil)
  3580. // [params setValue:appDelegate.user forKey:@"user"];
  3581. // if(appDelegate.contact_id!=nil)
  3582. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3583. // if(appDelegate.password!=nil)
  3584. // [params setValue:appDelegate.password forKey:@"password"];
  3585. // if(appDelegate.order_code!=nil)
  3586. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3587. //
  3588. //
  3589. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3590. // if (alert && qty && available && price && bestseller) {
  3591. // [params setObject:@"Filter" forKey:kAction];
  3592. // }
  3593. // if ([Singleton sharedInstance].homeItemClick) {
  3594. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  3595. // [Singleton sharedInstance].homeItemClick = NO;
  3596. //
  3597. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  3598. // [Singleton sharedInstance].homeClickedItemName = nil;
  3599. // [params setObject:extra forKey:kExtra];
  3600. // }
  3601. //
  3602. //
  3603. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3604. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3605. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3606. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3607. // // [params setValue:filter forKey:@"filter"];
  3608. // [params setValue:covertype forKey:@"covertype"];
  3609. // [params setValue:ctgid forKey:@"ctgId"];
  3610. // [params setValue:modelname forKey:@"modelName"];
  3611. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3612. // [params setValue:alert forKey:@"alert"];
  3613. // [params setValue:qty forKey:@"sold_by_qty"];
  3614. // [params setValue:available forKey:@"available"];
  3615. // [params setValue:price forKey:@"price"];
  3616. // [params setValue:bestseller forKey:@"bestseller"];
  3617. //
  3618. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3619. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3620. //
  3621. // if(appDelegate.offline_mode)
  3622. // {
  3623. // return [OLDataProvider offline_itemsearch:params];
  3624. // }
  3625. // if(![self IsNetworkAvailable])
  3626. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3627. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  3628. // if(json==nil)
  3629. // return nil;
  3630. // NSError *error=nil;
  3631. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3632. // return jsobj;
  3633. //}
  3634. //+(NSDictionary*)Search: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword
  3635. //{
  3636. // if(![self IsNetworkAvailable])
  3637. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3638. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3639. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3640. // if(appDelegate.user!=nil)
  3641. // [params setValue:appDelegate.user forKey:@"user"];
  3642. // if(appDelegate.contact_id!=nil)
  3643. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3644. // if(appDelegate.password!=nil)
  3645. // [params setValue:appDelegate.password forKey:@"password"];
  3646. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3647. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3648. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3649. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3650. // [params setValue:filter forKey:@"filter"];
  3651. // [params setValue:keyword forKey:@"keyword"];
  3652. //
  3653. //
  3654. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3655. // if(json==nil)
  3656. // return nil;
  3657. // NSError *error=nil;
  3658. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3659. // return jsobj;
  3660. //}
  3661. +(NSDictionary*)request_model_qty: (NSString*) fashionId
  3662. {
  3663. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3664. __block AppDelegate *appDelegate = nil;
  3665. dispatch_sync(dispatch_get_main_queue(), ^{
  3666. //some UI methods ej
  3667. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3668. });
  3669. if(appDelegate.user!=nil)
  3670. [params setValue:appDelegate.user forKey:@"user"];
  3671. if(appDelegate.contact_id!=nil)
  3672. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3673. if(appDelegate.password!=nil)
  3674. [params setValue:appDelegate.password forKey:@"password"];
  3675. [params setValue:fashionId forKey:@"fashionId"];
  3676. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  3677. NSData* json = nil;
  3678. if(appDelegate.offline_mode)
  3679. {
  3680. json = [OLDataProvider offline_model_qty:params];
  3681. } else {
  3682. if(![self IsNetworkAvailable])
  3683. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3684. json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  3685. }
  3686. if(json==nil)
  3687. return nil;
  3688. NSError *error=nil;
  3689. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3690. return jsobj;
  3691. }
  3692. +(NSDictionary*)retrieve_password: (NSString*) user email:(NSString*) email
  3693. {
  3694. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3695. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3696. // if(appDelegate.user!=nil)
  3697. // [params setValue:appDelegate.user forKey:@"user"];
  3698. // if(appDelegate.contact_id!=nil)
  3699. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3700. // if(appDelegate.password!=nil)
  3701. // [params setValue:appDelegate.password forKey:@"password"];
  3702. [params setValue:user forKey:@"username"];
  3703. [params setValue:email forKey:@"email"];
  3704. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3705. if(![self IsNetworkAvailable])
  3706. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3707. NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  3708. if(json==nil)
  3709. return nil;
  3710. NSError *error=nil;
  3711. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3712. return jsobj;
  3713. }
  3714. +(NSDictionary*)load_HomePage:(int) price_template customid:(int) customid
  3715. {
  3716. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3717. __block AppDelegate *appDelegate = nil;
  3718. dispatch_sync(dispatch_get_main_queue(), ^{
  3719. //some UI methods ej
  3720. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3721. });
  3722. if(appDelegate.user!=nil)
  3723. [params setValue:appDelegate.user forKey:@"user"];
  3724. if(appDelegate.contact_id!=nil)
  3725. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3726. if(appDelegate.password!=nil)
  3727. [params setValue:appDelegate.password forKey:@"password"];
  3728. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3729. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3730. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  3731. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3732. if(appDelegate.offline_mode)
  3733. {
  3734. //params[@"offline_Command"]=url;
  3735. return [OLDataProvider offline_home];
  3736. }
  3737. if(![self IsNetworkAvailable])
  3738. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3739. NSData* json=[self get_json:URL_LOAD_HOME parameters:params];
  3740. if(json==nil)
  3741. return nil;
  3742. NSError *error=nil;
  3743. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3744. return jsobj;
  3745. }
  3746. //+(NSDictionary*)logout
  3747. //{
  3748. //
  3749. //
  3750. //
  3751. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3752. // __block AppDelegate *appDelegate = nil;
  3753. //
  3754. // dispatch_sync(dispatch_get_main_queue(), ^{
  3755. // //some UI methods ej
  3756. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3757. // });
  3758. // if(appDelegate.user!=nil)
  3759. // [params setValue:appDelegate.user forKey:@"user"];
  3760. //
  3761. //
  3762. // if(appDelegate.password!=nil)
  3763. // [params setValue:appDelegate.password forKey:@"password"];
  3764. //
  3765. //
  3766. // if(appDelegate.offline_mode)
  3767. // {
  3768. // return [OLDataProvider offline_logout:params];
  3769. // }
  3770. // if(![self IsNetworkAvailable])
  3771. // {
  3772. // DebugLog(@"NET ERR");
  3773. //
  3774. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3775. // // return nil;
  3776. // }
  3777. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  3778. // //if(json==nil)
  3779. //
  3780. //
  3781. // if(json==nil)
  3782. // return nil;
  3783. // NSError *error=nil;
  3784. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3785. // int result = [[jsobj valueForKey:@"result"] intValue];
  3786. //
  3787. // if (result==2)
  3788. // {
  3789. //
  3790. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  3791. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  3792. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  3793. //
  3794. // [appDelegate update_count_mark];
  3795. //
  3796. //
  3797. // appDelegate.can_show_price =false;
  3798. // appDelegate.can_see_price =false;
  3799. // appDelegate.can_create_portfolio =false;
  3800. // appDelegate.can_create_order =false;
  3801. //
  3802. //
  3803. // appDelegate.can_cancel_order =false;
  3804. // appDelegate.can_set_cart_price =false;
  3805. // appDelegate.can_delete_order =false;
  3806. // appDelegate.can_submit_order =false;
  3807. // appDelegate.can_set_tearsheet_price =false;
  3808. // appDelegate.can_update_contact_info = false;
  3809. //
  3810. // appDelegate.save_order_logout = false;
  3811. // appDelegate.submit_order_logout = false;
  3812. // appDelegate.alert_sold_in_quantities = false;
  3813. //
  3814. // appDelegate.ipad_perm =nil ;
  3815. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  3816. // appDelegate.OrderFilter= nil;
  3817. // [appDelegate SetSo:nil];
  3818. // [appDelegate set_main_button_panel];
  3819. //#ifdef RA_NOTIFICATION
  3820. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  3821. //#endif
  3822. // }
  3823. // return jsobj;
  3824. //}
  3825. +(NSDictionary*)request_Cagegory
  3826. {
  3827. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  3828. __block AppDelegate *appDelegate = nil;
  3829. dispatch_sync(dispatch_get_main_queue(), ^{
  3830. //some UI methods ej
  3831. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3832. });
  3833. if(appDelegate.offline_mode)
  3834. {
  3835. //params[@"offline_Command"]=url;
  3836. return [OLDataProvider offline_category_menu];
  3837. }
  3838. if(![self IsNetworkAvailable])
  3839. {
  3840. DebugLog(@"NET ERR");
  3841. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3842. // return nil;
  3843. }
  3844. NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  3845. //if(json==nil)
  3846. if(json==nil)
  3847. return nil;
  3848. NSError *error=nil;
  3849. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3850. return jsobj;
  3851. }
  3852. +(int)Authorize : (NSString*) user password:(NSString*) password{
  3853. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  3854. // return RESULT_NET_ERROR;
  3855. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3856. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3857. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3858. __block AppDelegate *appDelegate = nil;
  3859. dispatch_sync(dispatch_get_main_queue(), ^{
  3860. //some UI methods ej
  3861. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3862. });
  3863. if(appDelegate.duid !=nil)
  3864. [params setValue:appDelegate.duid forKey:@"udid"];
  3865. [params setValue:@"handset_login" forKey:@"action"];
  3866. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  3867. [params setValue:user forKey:@"user"];
  3868. [params setValue:password forKey:@"password"];
  3869. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  3870. #ifdef TEST
  3871. [params setValue:@"true" forKey:@"is_debug"];
  3872. #else
  3873. [params setValue:@"false" forKey:@"is_debug"];
  3874. #endif
  3875. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3876. [params setObject:@"Login" forKey:kAction];
  3877. NSData* json= nil;
  3878. if(appDelegate.offline_mode)
  3879. {
  3880. json= [OLDataProvider offline_login:params] ;
  3881. }
  3882. else
  3883. {
  3884. if(![self IsNetworkAvailable])
  3885. return RESULT_NET_NOTAVAILABLE;
  3886. json =[self get_json:URL_UPDATE_AUTH parameters:params];
  3887. }
  3888. if(json==nil)
  3889. return RESULT_NET_ERROR;
  3890. int ret = [self parse_authinfo:json user:user password:password];
  3891. DebugLog(@"parse_authinfo return %d ",ret);
  3892. return ret;
  3893. }
  3894. +(NSDictionary*)update_customer_img: (NSString*) contactid img_url:(NSString*) url
  3895. {
  3896. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3897. __block AppDelegate *appDelegate = nil;
  3898. dispatch_sync(dispatch_get_main_queue(), ^{
  3899. //some UI methods ej
  3900. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3901. });
  3902. if(appDelegate.user!=nil)
  3903. [params setValue:appDelegate.user forKey:@"user"];
  3904. // if(appDelegate.contact_id!=nil)
  3905. if(appDelegate.password!=nil)
  3906. [params setValue:appDelegate.password forKey:@"password"];
  3907. [params setValue:contactid forKey:@"contactId"];
  3908. [params setValue:url forKey:@"business_card"];
  3909. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  3910. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  3911. if(appDelegate.offline_mode)
  3912. {
  3913. return [OLDataProvider offline_notimpl];
  3914. }
  3915. if(![self IsNetworkAvailable])
  3916. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3917. NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  3918. if(json==nil)
  3919. return nil;
  3920. NSError *error=nil;
  3921. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3922. return jsobj;
  3923. }
  3924. +(NSDictionary*)request_PendingOrder:(NSString *)contactid
  3925. {
  3926. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3927. __block AppDelegate *appDelegate = nil;
  3928. dispatch_sync(dispatch_get_main_queue(), ^{
  3929. //some UI methods ej
  3930. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3931. });
  3932. if(appDelegate.user!=nil)
  3933. [params setValue:appDelegate.user forKey:@"user"];
  3934. // if(appDelegate.contact_id!=nil)
  3935. if(appDelegate.password!=nil)
  3936. [params setValue:appDelegate.password forKey:@"password"];
  3937. [params setValue:contactid forKey:@"contactId"];
  3938. if(appDelegate.offline_mode)
  3939. {
  3940. return [OLDataProvider offline_notimpl];
  3941. }
  3942. if(![self IsNetworkAvailable])
  3943. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3944. NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  3945. if(json==nil)
  3946. return nil;
  3947. NSError *error=nil;
  3948. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3949. return jsobj;
  3950. }
  3951. //+(NSDictionary*)request_CustomerInfo:(NSString* ) contactid
  3952. //{
  3953. //
  3954. //
  3955. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3956. // __block AppDelegate *appDelegate = nil;
  3957. //
  3958. // dispatch_sync(dispatch_get_main_queue(), ^{
  3959. // //some UI methods ej
  3960. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3961. // });
  3962. // if(appDelegate.user!=nil)
  3963. // [params setValue:appDelegate.user forKey:@"user"];
  3964. // // if(appDelegate.contact_id!=nil)
  3965. //
  3966. // if(appDelegate.password!=nil)
  3967. // [params setValue:appDelegate.password forKey:@"password"];
  3968. // [params setValue:contactid forKey:@"contactId"];
  3969. //
  3970. // [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  3971. //
  3972. // if(appDelegate.offline_mode)
  3973. // return [OLDataProvider offline_contactinfo:params];
  3974. // if(![self IsNetworkAvailable])
  3975. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3976. //
  3977. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  3978. // if(json==nil)
  3979. // return nil;
  3980. // NSError *error=nil;
  3981. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3982. // return jsobj;
  3983. //
  3984. //}
  3985. +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
  3986. {
  3987. DebugLog(@"parse_authinfo");
  3988. NSError *error=nil;
  3989. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3990. if(jsobj)
  3991. {
  3992. __block AppDelegate *appDelegate = nil;
  3993. dispatch_sync(dispatch_get_main_queue(), ^{
  3994. //some UI methods ej
  3995. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3996. });
  3997. int result = [[jsobj valueForKey:@"result"] intValue];
  3998. if (result<0)
  3999. return result;
  4000. if(result!=AP_USER_AUTH&& result!=9)
  4001. {
  4002. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  4003. // [appDelegate Logout];
  4004. if(result==8)
  4005. {
  4006. return RESULT_LOGIN_DEVICE;
  4007. }
  4008. return RESULT_FALSE;
  4009. }
  4010. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  4011. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  4012. user=[objheader objectForKey:@"username"] ;
  4013. DebugLog(@"required_ver=%@ ",required_ver);
  4014. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  4015. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  4016. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  4017. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  4018. // if([ibadge isEqual:[NSNull null]])
  4019. // strbadge=@"0";
  4020. // if(ibadge==nil)
  4021. // ibadge=@"0";
  4022. // if([strbadge isEqualToString:@"null"])
  4023. // strbadge=@"0";
  4024. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  4025. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  4026. if([appDelegate.build intValue]<[required_ver intValue])
  4027. return RESULT_VER_LOW;
  4028. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  4029. appDelegate.user = user;
  4030. appDelegate.password = password;
  4031. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  4032. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  4033. appDelegate.bLogin = true;
  4034. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  4035. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  4036. {
  4037. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  4038. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  4039. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  4040. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  4041. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  4042. }
  4043. NSString* mode =[jsobj valueForKey:@"mode"] ;
  4044. [appDelegate SetMode:mode];
  4045. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  4046. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  4047. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  4048. [appDelegate update_count_mark];
  4049. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  4050. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  4051. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  4052. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  4053. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  4054. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  4055. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  4056. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  4057. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  4058. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  4059. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  4060. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  4061. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  4062. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  4063. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  4064. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  4065. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  4066. [appDelegate set_main_button_panel];
  4067. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  4068. // shop order status filter
  4069. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  4070. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  4071. // Sales order status filter
  4072. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  4073. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  4074. // specialInstruction
  4075. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  4076. //-价格类型
  4077. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  4078. // 权限
  4079. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  4080. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  4081. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  4082. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  4083. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  4084. [[RASingleton sharedInstance] resetGlobalLock];
  4085. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  4086. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  4087. }
  4088. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  4089. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  4090. // {
  4091. // // no update on the server;
  4092. // return RESULT_TRUE;
  4093. // }
  4094. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  4095. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4096. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4097. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4098. // [defaults synchronize];
  4099. //
  4100. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  4101. // NSArray* keys= [objfuncs allKeys];
  4102. /*
  4103. db.setTransactionSuccessful();
  4104. db.endTransaction();
  4105. */
  4106. return RESULT_TRUE;
  4107. }
  4108. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  4109. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  4110. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  4111. return RESULT_USERAUTH_ERROR;
  4112. }
  4113. //+(bool) IsNetworkAvailable
  4114. //{
  4115. //
  4116. // if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) &&
  4117. // ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable))
  4118. // return false;
  4119. // return true;
  4120. //}
  4121. //+(NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim
  4122. //{
  4123. // NSScanner *theScanner = [NSScanner scannerWithString:html];
  4124. // NSString *text = nil;
  4125. //
  4126. // while ([theScanner isAtEnd] == NO) {
  4127. // // find start of tag
  4128. // [theScanner scanUpToString:@"<" intoString:NULL] ;
  4129. // // find end of tag
  4130. // [theScanner scanUpToString:@">" intoString:&text] ;
  4131. // // replace the found tag with a space
  4132. // //(you can filter multi-spaces out later if you wish)
  4133. // html = [html stringByReplacingOccurrencesOfString:
  4134. // [ NSString stringWithFormat:@"%@>", text]
  4135. // withString:@""];
  4136. // }
  4137. //
  4138. // return trim ? [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : html;
  4139. //}
  4140. //
  4141. //+(NSString *)flattenURL:(NSString *)url trimWhiteSpace:(BOOL)trim
  4142. //{
  4143. // NSScanner *theScanner = [NSScanner scannerWithString:url];
  4144. // NSString *text = nil;
  4145. //
  4146. // while ([theScanner isAtEnd] == NO) {
  4147. // // find start of tag
  4148. // [theScanner scanUpToString:@"/" intoString:NULL] ;
  4149. // // find end of tag
  4150. // [theScanner scanUpToString:@"/" intoString:&text] ;
  4151. // // replace the found tag with a space
  4152. // //(you can filter multi-spaces out later if you wish)
  4153. // url = [url stringByReplacingOccurrencesOfString:
  4154. // [ NSString stringWithFormat:@"%@", text]
  4155. // withString:@""];
  4156. // }
  4157. //
  4158. // return trim ? [url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : url;
  4159. //}
  4160. + (NSDictionary *)set_npd_shop_price_type:(NSInteger)priceType {
  4161. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4162. __block AppDelegate *appDelegate = nil;
  4163. dispatch_sync(dispatch_get_main_queue(), ^{
  4164. //some UI methods ej
  4165. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4166. });
  4167. if(appDelegate.user!=nil)
  4168. [dic setValue:appDelegate.user forKey:@"user"];
  4169. if(appDelegate.password!=nil)
  4170. [dic setValue:appDelegate.password forKey:@"password"];
  4171. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  4172. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  4173. NSData* json=nil;
  4174. if(appDelegate.offline_mode)
  4175. {
  4176. return [OLDataProvider offline_notimpl];
  4177. }
  4178. else
  4179. {
  4180. if(![self IsNetworkAvailable])
  4181. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4182. json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  4183. }
  4184. if(json!=nil)
  4185. {
  4186. NSError *error=nil;
  4187. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4188. return jsobj;
  4189. }
  4190. return nil;
  4191. }
  4192. + (NSDictionary *)get_npd_shop_givenPrice {
  4193. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4194. __block AppDelegate *appDelegate = nil;
  4195. dispatch_sync(dispatch_get_main_queue(), ^{
  4196. //some UI methods ej
  4197. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4198. });
  4199. if(appDelegate.user!=nil)
  4200. [dic setValue:appDelegate.user forKey:@"user"];
  4201. if(appDelegate.password!=nil)
  4202. [dic setValue:appDelegate.password forKey:@"password"];
  4203. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  4204. NSData* json=nil;
  4205. if(appDelegate.offline_mode)
  4206. {
  4207. return [OLDataProvider offline_notimpl];
  4208. }
  4209. else
  4210. {
  4211. if(![self IsNetworkAvailable])
  4212. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4213. json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  4214. }
  4215. if(json!=nil)
  4216. {
  4217. NSError *error=nil;
  4218. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4219. return jsobj;
  4220. }
  4221. return nil;
  4222. }
  4223. + (NSDictionary *)set_npd_shop_givenPrice:(NSMutableDictionary *)params {
  4224. __block AppDelegate *appDelegate = nil;
  4225. dispatch_sync(dispatch_get_main_queue(), ^{
  4226. //some UI methods ej
  4227. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4228. });
  4229. if(appDelegate.user!=nil)
  4230. [params setValue:appDelegate.user forKey:@"user"];
  4231. if(appDelegate.password!=nil)
  4232. [params setValue:appDelegate.password forKey:@"password"];
  4233. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  4234. NSData* json=nil;
  4235. if(appDelegate.offline_mode)
  4236. {
  4237. return [OLDataProvider offline_notimpl];
  4238. }
  4239. else
  4240. {
  4241. if(![self IsNetworkAvailable])
  4242. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4243. json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  4244. }
  4245. if(json!=nil)
  4246. {
  4247. NSError *error=nil;
  4248. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4249. return jsobj;
  4250. }
  4251. return nil;
  4252. }
  4253. + (NSDictionary *)merge_order:(NSMutableDictionary *)params {
  4254. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4255. __block AppDelegate *appDelegate = nil;
  4256. dispatch_sync(dispatch_get_main_queue(), ^{
  4257. //some UI methods ej
  4258. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4259. });
  4260. if(appDelegate.user!=nil)
  4261. [dic setValue:appDelegate.user forKey:@"user"];
  4262. if(appDelegate.password!=nil)
  4263. [dic setValue:appDelegate.password forKey:@"password"];
  4264. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  4265. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  4266. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  4267. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  4268. NSData* json=nil;
  4269. if(appDelegate.offline_mode)
  4270. {
  4271. return [OLDataProvider offline_notimpl];
  4272. }
  4273. else
  4274. {
  4275. if(![self IsNetworkAvailable])
  4276. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4277. json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  4278. }
  4279. if(json!=nil)
  4280. {
  4281. NSError *error=nil;
  4282. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4283. return jsobj;
  4284. }
  4285. else
  4286. return nil;
  4287. }
  4288. //+ (NSDictionary *)lock_order:(NSString *)oderCode
  4289. //{
  4290. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4291. // __block AppDelegate *appDelegate = nil;
  4292. //
  4293. // dispatch_sync(dispatch_get_main_queue(), ^{
  4294. // //some UI methods ej
  4295. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4296. // });
  4297. // if(appDelegate.user!=nil)
  4298. // [params setValue:appDelegate.user forKey:@"user"];
  4299. //
  4300. // if(appDelegate.password!=nil)
  4301. // [params setValue:appDelegate.password forKey:@"password"];
  4302. //
  4303. // [params setValue:oderCode forKey:@"orderCode"];
  4304. //
  4305. // NSData* json=nil;
  4306. // if(appDelegate.offline_mode)
  4307. // {
  4308. // json=[OLDataProvider offline_editorder:params];
  4309. //
  4310. // }
  4311. // else
  4312. // {
  4313. // if(![self IsNetworkAvailable])
  4314. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4315. //
  4316. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  4317. // }
  4318. // if(json!=nil)
  4319. // {
  4320. // NSError *error=nil;
  4321. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4322. //
  4323. // return jsobj;
  4324. // }
  4325. // else
  4326. // return nil;
  4327. //}
  4328. + (NSDictionary *)quoteOrder:(NSString *)so_id emailAddr:(NSString *)addr {
  4329. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4330. __block AppDelegate *appDelegate = nil;
  4331. dispatch_sync(dispatch_get_main_queue(), ^{
  4332. //some UI methods ej
  4333. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4334. });
  4335. if(appDelegate.user!=nil)
  4336. [dic setValue:appDelegate.user forKey:@"user"];
  4337. if(appDelegate.password!=nil)
  4338. [dic setValue:appDelegate.password forKey:@"password"];
  4339. [dic setValue:so_id forKey:@"orderCode"];
  4340. [dic setValue:addr forKey:@"email"];
  4341. [dic setObject:ScreenCodeCart forKey:kScreenName];
  4342. if (appDelegate.customerInfo) {
  4343. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4344. if (customer_cid) {
  4345. [dic setValue:customer_cid forKey:@"contactId"];
  4346. }
  4347. }
  4348. NSData* json=nil;
  4349. if(appDelegate.offline_mode)
  4350. {
  4351. return [OLDataProvider offline_notimpl];
  4352. }
  4353. else
  4354. {
  4355. if(![self IsNetworkAvailable])
  4356. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4357. json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  4358. }
  4359. if(json!=nil)
  4360. {
  4361. NSError *error=nil;
  4362. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4363. return jsobj;
  4364. }
  4365. return @{@"result" : @(RESULT_FALSE)};
  4366. }
  4367. + (NSDictionary *)notifyModel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName{
  4368. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4369. __block AppDelegate *appDelegate = nil;
  4370. dispatch_sync(dispatch_get_main_queue(), ^{
  4371. //some UI methods ej
  4372. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4373. });
  4374. if(appDelegate.user!=nil)
  4375. [dic setValue:appDelegate.user forKey:@"user"];
  4376. if(appDelegate.password!=nil)
  4377. [dic setValue:appDelegate.password forKey:@"password"];
  4378. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  4379. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4380. if (customer_cid) {
  4381. [dic setValue:customer_cid forKey:@"contactId"];
  4382. }
  4383. }
  4384. [dic setObject:screenName forKey:kScreenName];
  4385. [dic setValue:modelID forKey:@"productId"];
  4386. if (addr) { // 弹框输入
  4387. [dic setValue:addr forKey:@"email"];
  4388. } else {
  4389. // employee选择了Contact,并且Contact有Email
  4390. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  4391. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  4392. // if (email) {
  4393. // [dic setValue:email forKey:@"email"];
  4394. // }
  4395. // }
  4396. }
  4397. NSData* json=nil;
  4398. if(appDelegate.offline_mode)
  4399. {
  4400. return [OLDataProvider offline_notimpl];
  4401. }
  4402. else
  4403. {
  4404. if(![self IsNetworkAvailable])
  4405. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4406. json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  4407. }
  4408. if(json!=nil)
  4409. {
  4410. NSError *error=nil;
  4411. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4412. return jsobj;
  4413. }
  4414. return @{@"result" : @(RESULT_FALSE)};
  4415. }
  4416. + (NSDictionary *)quoteWishlist2EmailAddr:(NSString *)addr {
  4417. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4418. __block AppDelegate *appDelegate = nil;
  4419. dispatch_sync(dispatch_get_main_queue(), ^{
  4420. //some UI methods ej
  4421. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4422. });
  4423. if(appDelegate.user!=nil)
  4424. [dic setValue:appDelegate.user forKey:@"user"];
  4425. if(appDelegate.password!=nil)
  4426. [dic setValue:appDelegate.password forKey:@"password"];
  4427. [dic setValue:addr forKey:@"email"];
  4428. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  4429. // if (appDelegate.customerInfo) {
  4430. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4431. // if (customer_cid) {
  4432. // [dic setValue:customer_cid forKey:@"contactId"];
  4433. // }
  4434. // }
  4435. NSData* json=nil;
  4436. if(appDelegate.offline_mode)
  4437. {
  4438. return [OLDataProvider offline_notimpl];
  4439. }
  4440. else
  4441. {
  4442. if(![self IsNetworkAvailable])
  4443. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4444. json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  4445. }
  4446. if(json!=nil)
  4447. {
  4448. NSError *error=nil;
  4449. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4450. return jsobj;
  4451. }
  4452. return @{@"result" : @(RESULT_FALSE)};
  4453. }
  4454. + (NSDictionary *)movetobackorder:(NSString *)cart_item_id {
  4455. if (cart_item_id == nil || cart_item_id.length < 1) {
  4456. return @{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"};
  4457. }
  4458. __block AppDelegate *appDelegate = nil;
  4459. dispatch_sync(dispatch_get_main_queue(), ^{
  4460. //some UI methods ej
  4461. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4462. });
  4463. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4464. if(appDelegate.user!=nil)
  4465. [dic setValue:appDelegate.user forKey:@"user"];
  4466. if(appDelegate.password!=nil)
  4467. [dic setValue:appDelegate.password forKey:@"password"];
  4468. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  4469. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  4470. [dic setObject:ScreenCodeCart forKey:kScreenName];
  4471. if(![self IsNetworkAvailable])
  4472. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4473. NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  4474. if(json!=nil)
  4475. {
  4476. NSError *error=nil;
  4477. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4478. return jsobj;
  4479. }
  4480. return @{@"result" : @(RESULT_FALSE)};
  4481. }
  4482. + (NSDictionary*)request_hangTag:(NSString *)group {
  4483. #ifdef BUILD_UWAVER
  4484. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4485. __block AppDelegate *appDelegate = nil;
  4486. dispatch_sync(dispatch_get_main_queue(), ^{
  4487. //some UI methods ej
  4488. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4489. });
  4490. if(appDelegate.user!=nil)
  4491. [params setValue:appDelegate.user forKey:@"user"];
  4492. if(appDelegate.contact_id!=nil)
  4493. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4494. if(appDelegate.password!=nil)
  4495. [params setValue:appDelegate.password forKey:@"password"];
  4496. if (group) {
  4497. [params setValue:group forKey:@"groupName"];
  4498. }
  4499. NSString * uuid= [[NSUUID UUID] UUIDString];
  4500. params[@"resultSerial"]=uuid;
  4501. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4502. NSData* json = nil;
  4503. if(appDelegate.offline_mode)
  4504. {
  4505. json = [OLDataProvider offline_notimpl];
  4506. } else {
  4507. if(![self IsNetworkAvailable])
  4508. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4509. json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  4510. }
  4511. if(json==nil)
  4512. return nil;
  4513. NSError *error=nil;
  4514. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4515. return jsobj;
  4516. #else
  4517. return nil;
  4518. #endif
  4519. }
  4520. #pragma mark 2020 new interface
  4521. // 新接口逐步替换以前的网络请求,2020
  4522. +(void)request_home:(int) price_template customid:(int) customid completionHandler:(resultHandler)result
  4523. {
  4524. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4525. AppDelegate *appDelegate = nil;
  4526. //some UI methods ej
  4527. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4528. if(appDelegate.user!=nil)
  4529. [params setValue:appDelegate.user forKey:@"user"];
  4530. if(appDelegate.contact_id!=nil)
  4531. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4532. if(appDelegate.password!=nil)
  4533. [params setValue:appDelegate.password forKey:@"password"];
  4534. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4535. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4536. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  4537. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4538. if(appDelegate.offline_mode)
  4539. {
  4540. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4541. NSMutableDictionary* json = [[OLDataProvider offline_home] mutableCopy];
  4542. dispatch_async(dispatch_get_main_queue(), ^{
  4543. result(json);
  4544. });
  4545. });
  4546. return;
  4547. }
  4548. [self request_interface:URL_LOAD_HOME parameters:params err_record_url:nil completionHandler:result retry:0];
  4549. return;
  4550. }
  4551. +(void)request_category:(resultHandler)result
  4552. {
  4553. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  4554. AppDelegate *appDelegate = nil;
  4555. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4556. if(appDelegate.offline_mode)
  4557. {
  4558. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4559. NSMutableDictionary* json = [[OLDataProvider offline_category_menu] mutableCopy];
  4560. dispatch_async(dispatch_get_main_queue(), ^{
  4561. result(json);
  4562. });
  4563. });
  4564. return;
  4565. }
  4566. [self request_interface:URL_REQUEST_CATMENU parameters:[NSMutableDictionary new] err_record_url:nil completionHandler:result retry:0];
  4567. //
  4568. // if(![self IsNetworkAvailable])
  4569. // {
  4570. // DebugLog(@"NET ERR");
  4571. //
  4572. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4573. // // return nil;
  4574. // }
  4575. //
  4576. // NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  4577. // //if(json==nil)
  4578. //
  4579. //
  4580. // if(json==nil)
  4581. // return nil;
  4582. // NSError *error=nil;
  4583. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4584. // return jsobj;
  4585. }
  4586. +(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
  4587. {
  4588. AppDelegate *appDelegate = nil;
  4589. //some UI methods ej
  4590. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4591. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4592. if(appDelegate.user!=nil)
  4593. [params setValue:appDelegate.user forKey:@"user"];
  4594. if(appDelegate.contact_id!=nil)
  4595. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4596. if(appDelegate.password!=nil)
  4597. [params setValue:appDelegate.password forKey:@"password"];
  4598. if(appDelegate.order_code!=nil)
  4599. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4600. [params setValue:alert forKey:@"alert"];
  4601. [params setValue:qty forKey:@"sold_by_qty"];
  4602. [params setValue:available forKey:@"available"];
  4603. [params setValue:price forKey:@"price"];
  4604. [params setValue:bestseller forKey:@"bestseller"];
  4605. [params setValue:modelname forKey:@"modelName"];
  4606. [params setValue:modeldescrip forKey:@"modelDescription"];
  4607. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4608. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4609. [params setValue:category forKey:@"category"];
  4610. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4611. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4612. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4613. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4614. [params setValue:filter forKey:@"filter"];
  4615. [params setValue:keyword forKey:@"keyword"];
  4616. [params setObject:ScreenCodeCategory forKey:kScreenName];
  4617. if (alert) {
  4618. [params setObject:@"Filter" forKey:kAction];
  4619. }
  4620. if ([RASingleton sharedInstance].homeItemClick) {
  4621. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  4622. [RASingleton sharedInstance].homeItemClick = NO;
  4623. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  4624. [RASingleton sharedInstance].homeClickedItemName = nil;
  4625. [params setObject:extra forKey:kExtra];
  4626. }
  4627. if(appDelegate.offline_mode)
  4628. {
  4629. // [OLDataProvider offline_category:params completionHandler:result];
  4630. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4631. NSMutableDictionary* json = [[OLDataProvider offline_category:params] mutableCopy];
  4632. dispatch_async(dispatch_get_main_queue(), ^{
  4633. result(json);
  4634. });
  4635. });
  4636. return;
  4637. }
  4638. [self request_interface:URL_CATEGORY parameters:params err_record_url:nil completionHandler:result retry:0];
  4639. return ;
  4640. //
  4641. // if(![self IsNetworkAvailable])
  4642. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4643. //
  4644. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  4645. // if(json==nil)
  4646. // return nil;
  4647. // NSError *error=nil;
  4648. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4649. // return jsobj;
  4650. //
  4651. }
  4652. +(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
  4653. {
  4654. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4655. AppDelegate *appDelegate = nil;
  4656. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4657. if(appDelegate.user!=nil)
  4658. [params setValue:appDelegate.user forKey:@"user"];
  4659. if(appDelegate.contact_id!=nil)
  4660. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4661. if(appDelegate.password!=nil)
  4662. [params setValue:appDelegate.password forKey:@"password"];
  4663. if(appDelegate.order_code!=nil)
  4664. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4665. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4666. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4667. if(use_name)
  4668. [params setValue:model_name forKey:@"product_name"];
  4669. else
  4670. if(use_upc){
  4671. params[@"search_upc"]=@true;
  4672. [params setValue:upc_code forKey:@"upc_code"];
  4673. }
  4674. else
  4675. [params setValue:item_id forKey:@"product_id"];
  4676. [params setValue:category_id forKey:@"category"];
  4677. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4678. [params setObject:@"Open A Model" forKey:kAction];
  4679. if (model_name) {
  4680. NSDictionary *extra = @{@"ModelName" : model_name};
  4681. [params setObject:extra forKey:kExtra];
  4682. }
  4683. if (groupName.length > 0) {
  4684. [params setObject:groupName forKey:@"groupName"];
  4685. }
  4686. if(appDelegate.offline_mode)
  4687. {
  4688. [OLDataProvider offline_model:params completionHandler:result];
  4689. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4690. // NSMutableDictionary* json = [[OLDataProvider offline_model:params] mutableCopy];
  4691. // dispatch_async(dispatch_get_main_queue(), ^{
  4692. // result(json);
  4693. // });
  4694. // });
  4695. return;
  4696. }
  4697. [self request_interface:URL_ITEM_DETAIL parameters:params err_record_url:nil completionHandler:result retry:0];
  4698. //
  4699. // if(appDelegate.offline_mode)
  4700. // return [OLDataProvider offline_model:params];
  4701. //
  4702. // if(![self IsNetworkAvailable])
  4703. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4704. //
  4705. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  4706. // if(json==nil)
  4707. // return nil;
  4708. // NSError *error=nil;
  4709. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4710. // return jsobj;
  4711. }
  4712. +(void)request_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull completionHandler:(resultHandler)result
  4713. {
  4714. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4715. AppDelegate *appDelegate = nil;
  4716. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4717. if(appDelegate.user!=nil)
  4718. [params setValue:appDelegate.user forKey:@"user"];
  4719. if(appDelegate.contact_id!=nil)
  4720. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4721. if(appDelegate.password!=nil)
  4722. [params setValue:appDelegate.password forKey:@"password"];
  4723. if(appDelegate.order_code!=nil)
  4724. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4725. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4726. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4727. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  4728. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4729. // [params setValue:filter forKey:@"filter"];
  4730. [params setValue:keywords forKey:@"keyword"];
  4731. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4732. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4733. if(matchfull)
  4734. [params setValue:@"true" forKey:@"exactMatch"];
  4735. else
  4736. [params setValue:@"false" forKey:@"exactMatch"];
  4737. [params setObject:ScreenCodeSearch forKey:kScreenName];
  4738. if (keywords) {
  4739. [params setObject:@"Search" forKey:kAction];
  4740. }
  4741. if(appDelegate.offline_mode)
  4742. {
  4743. // [OLDataProvider offline_search:params completionHandler:result];
  4744. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4745. NSMutableDictionary* json = [[OLDataProvider offline_search:params] mutableCopy];
  4746. dispatch_async(dispatch_get_main_queue(), ^{
  4747. result(json);
  4748. });
  4749. });
  4750. return;
  4751. }
  4752. [self request_interface:URL_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  4753. // if(appDelegate.offline_mode)
  4754. // {
  4755. // return [OLDataProvider offline_search:params];
  4756. // }
  4757. // if(![self IsNetworkAvailable])
  4758. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4759. //
  4760. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  4761. // if(json==nil)
  4762. // return nil;
  4763. // NSError *error=nil;
  4764. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4765. // return jsobj;
  4766. }
  4767. +(void)request_login: (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
  4768. {
  4769. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  4770. // return RESULT_NET_ERROR;
  4771. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4772. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4773. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4774. AppDelegate *appDelegate = nil;
  4775. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4776. if(appDelegate.duid !=nil)
  4777. [params setValue:appDelegate.duid forKey:@"udid"];
  4778. [params setValue:@"handset_login" forKey:@"action"];
  4779. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  4780. [params setValue:user forKey:@"user"];
  4781. [params setValue:password forKey:@"password"];
  4782. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  4783. #ifdef TEST
  4784. [params setValue:@"true" forKey:@"is_debug"];
  4785. #else
  4786. [params setValue:@"false" forKey:@"is_debug"];
  4787. #endif
  4788. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  4789. [params setObject:@"Login" forKey:kAction];
  4790. if(appDelegate.offline_mode)
  4791. {
  4792. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4793. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_login:params]] mutableCopy];
  4794. dispatch_async(dispatch_get_main_queue(), ^{
  4795. int ret = [self parse_logininfo:json user:user password:password] ;
  4796. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4797. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4798. result(retjson);
  4799. });
  4800. });
  4801. return;
  4802. }
  4803. NSString* url;
  4804. bool scan_guest = false;
  4805. #ifdef SCANNER_ORDER
  4806. params[@"site_name"]=[RADataProvider getSiteName];
  4807. params[@"_method"]=@"login";
  4808. url = [appDelegate.address stringByAppendingPathComponent:URL_UPDATE_AUTH];
  4809. if([user.uppercaseString isEqualToString:@"GUEST"]&&[password.uppercaseString isEqualToString:@"GUEST"])
  4810. scan_guest = true;
  4811. #else
  4812. url = URL_UPDATE_AUTH;
  4813. #endif
  4814. if(scan_guest)
  4815. {
  4816. [OLDataProvider realguestLogin];
  4817. // int ret = [self parse_logininfo:chresult user:user password:password] ;
  4818. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4819. retjson[@"result"]= [NSNumber numberWithInt:RESULT_TRUE];
  4820. result(retjson);
  4821. }
  4822. else
  4823. {
  4824. [self request_interface:url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *chresult) {
  4825. int ret = [self parse_logininfo:chresult user:user password:password] ;
  4826. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4827. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4828. result(retjson);
  4829. } retry:0];
  4830. }
  4831. //
  4832. // NSData* json= nil;
  4833. // if(appDelegate.offline_mode)
  4834. // {
  4835. // json= [OLDataProvider offline_login:params] ;
  4836. //
  4837. // }
  4838. // else
  4839. // {
  4840. // if(![self IsNetworkAvailable])
  4841. // return RESULT_NET_NOTAVAILABLE;
  4842. // json =[self get_json:URL_UPDATE_AUTH parameters:params];
  4843. //
  4844. // }
  4845. //
  4846. // if(json==nil)
  4847. // return RESULT_NET_ERROR;
  4848. //
  4849. // int ret = [self parse_authinfo:json user:user password:password];
  4850. // DebugLog(@"parse_authinfo return %d ",ret);
  4851. //
  4852. //
  4853. // return ret;
  4854. //
  4855. }
  4856. +(int)parse_logininfo : (NSMutableDictionary *) jsobj user:(NSString*) user password:(NSString*) password
  4857. {
  4858. // DebugLog(@"parse_authinfo");
  4859. // NSError *error=nil;
  4860. //
  4861. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4862. if(jsobj)
  4863. {
  4864. AppDelegate *appDelegate = nil;
  4865. //some UI methods ej
  4866. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4867. int result = [[jsobj valueForKey:@"result"] intValue];
  4868. if (result<0)
  4869. return result;
  4870. if(result!=AP_USER_AUTH&& result!=9)
  4871. {
  4872. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  4873. // [appDelegate Logout];
  4874. if(result==8)
  4875. {
  4876. return RESULT_LOGIN_DEVICE;
  4877. }
  4878. return RESULT_FALSE;
  4879. }
  4880. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  4881. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  4882. user=[objheader objectForKey:@"username"] ;
  4883. DebugLog(@"required_ver=%@ ",required_ver);
  4884. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  4885. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  4886. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  4887. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  4888. // if([ibadge isEqual:[NSNull null]])
  4889. // strbadge=@"0";
  4890. // if(ibadge==nil)
  4891. // ibadge=@"0";
  4892. // if([strbadge isEqualToString:@"null"])
  4893. // strbadge=@"0";
  4894. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  4895. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  4896. #ifndef SCANNER_ORDER
  4897. if([appDelegate.build intValue]<[required_ver intValue])
  4898. return RESULT_VER_LOW;
  4899. #endif
  4900. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  4901. appDelegate.user = user;
  4902. appDelegate.password = password;
  4903. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  4904. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  4905. appDelegate.bLogin = true;
  4906. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  4907. #ifdef SCANNER_ORDER
  4908. appDelegate.available_price_group = objheader[@"price_group"];
  4909. [RADataProvider default_price_group];
  4910. #endif
  4911. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  4912. {
  4913. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  4914. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  4915. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  4916. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  4917. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  4918. }
  4919. NSString* mode =[jsobj valueForKey:@"mode"] ;
  4920. [appDelegate SetMode:mode];
  4921. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  4922. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  4923. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  4924. [appDelegate update_count_mark];
  4925. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  4926. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  4927. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  4928. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  4929. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  4930. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  4931. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  4932. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  4933. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  4934. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  4935. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  4936. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  4937. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  4938. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  4939. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  4940. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  4941. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  4942. [appDelegate set_main_button_panel];
  4943. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  4944. // shop order status filter
  4945. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  4946. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  4947. // Sales order status filter
  4948. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  4949. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  4950. // specialInstruction
  4951. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  4952. //-价格类型
  4953. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  4954. // 权限
  4955. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  4956. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  4957. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  4958. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  4959. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  4960. [[RASingleton sharedInstance] resetGlobalLock];
  4961. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  4962. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  4963. }
  4964. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  4965. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  4966. // {
  4967. // // no update on the server;
  4968. // return RESULT_TRUE;
  4969. // }
  4970. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  4971. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4972. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4973. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4974. // [defaults synchronize];
  4975. //
  4976. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  4977. // NSArray* keys= [objfuncs allKeys];
  4978. /*
  4979. db.setTransactionSuccessful();
  4980. db.endTransaction();
  4981. */
  4982. return RESULT_TRUE;
  4983. }
  4984. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  4985. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  4986. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  4987. return RESULT_USERAUTH_ERROR;
  4988. }
  4989. +(void)request_contactlist:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams completionHandler:(resultHandler)result
  4990. {
  4991. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4992. if(upparams!=nil)
  4993. params = [upparams mutableCopy];
  4994. AppDelegate *appDelegate = nil;
  4995. //some UI methods ej
  4996. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4997. if(appDelegate.user!=nil)
  4998. [params setValue:appDelegate.user forKey:@"user"];
  4999. if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  5000. [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  5001. else
  5002. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5003. if(appDelegate.password!=nil)
  5004. [params setValue:appDelegate.password forKey:@"password"];
  5005. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  5006. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  5007. [params setValue:contact_type forKey:@"contactType"];
  5008. [params setValue:keywords forKey:@"keyword"];
  5009. [params setObject:ScreenCodeAccount forKey:kScreenName];
  5010. if (keywords) {
  5011. [params setObject:@"Search" forKey:kAction];
  5012. }
  5013. if (upparams) {
  5014. [params setObject:@"Advance Search" forKey:kAction];
  5015. }
  5016. NSString* url=nil;
  5017. if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  5018. url=URL_SHIPTO_LIST;
  5019. else
  5020. url=URL_CONTACT_LIST;
  5021. if(appDelegate.offline_mode)
  5022. {
  5023. [OLDataProvider offline_contactlist:params completionHandler:result];
  5024. return;
  5025. }
  5026. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  5027. //
  5028. // if(appDelegate.offline_mode)
  5029. // return [OLDataProvider offline_contactlist:params];
  5030. //
  5031. // if(![self IsNetworkAvailable])
  5032. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5033. //
  5034. // NSData* json=[self get_json:url parameters:params];
  5035. // if(json==nil)
  5036. // return nil;
  5037. // NSError *error=nil;
  5038. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5039. // return jsobj;
  5040. }
  5041. +(void)request_contactinfo:(NSString* ) contactid completionHandler:(resultHandler)result
  5042. {
  5043. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5044. AppDelegate *appDelegate = nil;
  5045. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5046. if(appDelegate.user!=nil)
  5047. [params setValue:appDelegate.user forKey:@"user"];
  5048. // if(appDelegate.contact_id!=nil)
  5049. if(appDelegate.password!=nil)
  5050. [params setValue:appDelegate.password forKey:@"password"];
  5051. [params setValue:contactid forKey:@"contactId"];
  5052. [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  5053. if(appDelegate.offline_mode)
  5054. {
  5055. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5056. // [OLDataProvider offline_contactinfo:params completionHandler:result] ;
  5057. // });
  5058. params[@"mode"]=appDelegate.mode;
  5059. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5060. NSMutableDictionary* json = [[OLDataProvider offline_contactinfo:params] mutableCopy];
  5061. dispatch_async(dispatch_get_main_queue(), ^{
  5062. result(json);
  5063. });
  5064. });
  5065. return;
  5066. }
  5067. [self request_interface:URL_CUSTOMER_INFO parameters:params err_record_url:nil completionHandler:result retry:0];
  5068. // if(appDelegate.offline_mode)
  5069. // return [OLDataProvider offline_contactinfo:params];
  5070. // if(![self IsNetworkAvailable])
  5071. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5072. //
  5073. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  5074. // if(json==nil)
  5075. // return nil;
  5076. // NSError *error=nil;
  5077. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5078. // return jsobj;
  5079. //
  5080. }
  5081. +(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  5082. {
  5083. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5084. AppDelegate *appDelegate = nil;
  5085. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5086. if(appDelegate.user!=nil)
  5087. [params setValue:appDelegate.user forKey:@"user"];
  5088. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  5089. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  5090. // else
  5091. if(appDelegate.contact_id!=nil)
  5092. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5093. if(appDelegate.password!=nil)
  5094. [params setValue:appDelegate.password forKey:@"password"];
  5095. if(appDelegate.order_code!=nil)
  5096. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5097. bool can_create_backorder=appDelegate.can_create_backorder;
  5098. // [params setValue:sourceid forKey:@"sourceid"];
  5099. // [params setValue:editor forKey:@"editor"];
  5100. DebugLog(@"request editor url:%@",request_url);
  5101. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  5102. {
  5103. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  5104. }
  5105. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  5106. {
  5107. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  5108. }
  5109. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  5110. {
  5111. [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  5112. }
  5113. else if([request_url isEqualToString:URL_CARTDELIVERY])
  5114. {
  5115. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  5116. }
  5117. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  5118. {
  5119. [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  5120. }
  5121. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  5122. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  5123. }
  5124. if(appDelegate.offline_mode)
  5125. {
  5126. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5127. NSData* json = nil;
  5128. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  5129. {
  5130. json= [OLDataProvider offline_createContact:params];
  5131. }
  5132. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  5133. {
  5134. json= [OLDataProvider offline_editContact:params];
  5135. }
  5136. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  5137. {
  5138. json= [OLDataProvider offline_contactAdvancedSearch:params];
  5139. }
  5140. else if([request_url isEqualToString:URL_CARTDELIVERY])
  5141. {
  5142. params[@"contact_id"]=params[@"contactId"];
  5143. params[@"can_create_backorder"]=@(can_create_backorder);
  5144. json= [OLDataProvider offline_placeorder:params];
  5145. }
  5146. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  5147. {
  5148. json= [OLDataProvider offline_addreditor:params];
  5149. }
  5150. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  5151. json = [OLDataProvider offline_createTearSheet:params];
  5152. }
  5153. dispatch_async(dispatch_get_main_queue(), ^{
  5154. if(json==nil)
  5155. result( [[OLDataProvider offline_notimpl] mutableCopy]);
  5156. else
  5157. result([[RAConvertor data2dict:json] mutableCopy]);
  5158. });
  5159. });
  5160. return;
  5161. }
  5162. else
  5163. {
  5164. if([request_url isEqualToString:URL_CARTDELIVERY])
  5165. {
  5166. NSString * uuid= [[NSUUID UUID] UUIDString];
  5167. params[@"resultSerial"]=uuid;
  5168. __block bool bbreak = false;
  5169. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5170. for(int i=0;i<150;i++)
  5171. {
  5172. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  5173. // result_params[@"resultSerial"]=uuid;
  5174. //json=[self get_json:request_url parameters:params];
  5175. if(bbreak)
  5176. break;
  5177. dispatch_async(dispatch_get_main_queue(), ^{
  5178. NSLog(@"request cart delivery %d",i);
  5179. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5180. if(resulti!=nil)
  5181. {
  5182. if([resulti[@"result"] intValue]==2 || [resulti[@"result"] intValue] == 8)
  5183. {
  5184. if(!bbreak) //此判断保证result只调用一次。
  5185. {
  5186. result(resulti);
  5187. NSLog(@"result called at %d",i);
  5188. }
  5189. bbreak=true;
  5190. }
  5191. }
  5192. } retry:3];
  5193. });
  5194. // [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  5195. sleep(2);
  5196. }
  5197. });
  5198. }
  5199. else
  5200. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  5201. }
  5202. // if(json!=nil)
  5203. // {
  5204. // NSError *error=nil;
  5205. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5206. // return jsobj;
  5207. // }
  5208. // else
  5209. // return nil;
  5210. }
  5211. +(void)request_wishlist:(int)sort completionHandler:(resultHandler)result
  5212. {
  5213. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5214. AppDelegate *appDelegate = nil;
  5215. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5216. if(appDelegate.user!=nil)
  5217. [params setValue:appDelegate.user forKey:@"user"];
  5218. if(appDelegate.contact_id!=nil)
  5219. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5220. if(appDelegate.password!=nil)
  5221. [params setValue:appDelegate.password forKey:@"password"];
  5222. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  5223. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  5224. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  5225. [params setObject:ScreenCodeWishList forKey:kScreenName];
  5226. if(appDelegate.offline_mode)
  5227. {
  5228. [OLDataProvider offline_wishlist:params completionHandler:^(NSMutableDictionary *resulti) {
  5229. int result_code = [[resulti valueForKey:@"result"] intValue];
  5230. if (result_code==2)
  5231. {
  5232. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  5233. [appDelegate update_count_mark];;
  5234. result(resulti);
  5235. }
  5236. }];
  5237. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5238. // NSMutableDictionary* json = [[OLDataProvider offline_wishlist:params] mutableCopy];
  5239. // dispatch_async(dispatch_get_main_queue(), ^{
  5240. // result(json);
  5241. // });
  5242. // });
  5243. return;
  5244. }
  5245. [self request_interface:URL_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5246. int result_code = [[resulti valueForKey:@"result"] intValue];
  5247. if (result_code==2)
  5248. {
  5249. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  5250. [appDelegate update_count_mark];;
  5251. result(resulti);
  5252. }
  5253. } retry:0];
  5254. // if(appDelegate.offline_mode)
  5255. // {
  5256. // return [OLDataProvider offline_wishlist:params];
  5257. // }
  5258. // if(![self IsNetworkAvailable])
  5259. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5260. //
  5261. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  5262. // if(json==nil)
  5263. // return nil;
  5264. // NSError *error=nil;
  5265. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5266. // int result = [[jsobj valueForKey:@"result"] intValue];
  5267. //
  5268. // if (result==2)
  5269. // {
  5270. //
  5271. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5272. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  5273. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5274. //
  5275. // [appDelegate update_count_mark];
  5276. // }
  5277. // return jsobj;
  5278. }
  5279. +(void)request_portfoliolist:(int)sort completionHandler:(resultHandler)result
  5280. {
  5281. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5282. AppDelegate *appDelegate = nil;
  5283. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5284. if(appDelegate.user!=nil)
  5285. [params setValue:appDelegate.user forKey:@"user"];
  5286. if(appDelegate.contact_id!=nil)
  5287. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5288. if(appDelegate.password!=nil)
  5289. [params setValue:appDelegate.password forKey:@"password"];
  5290. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  5291. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  5292. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  5293. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  5294. if(appDelegate.offline_mode)
  5295. {
  5296. params[@"user"]=appDelegate.user;
  5297. params[@"contact_id"]=appDelegate.contact_id;
  5298. params[@"can_see_price"]=@(appDelegate.can_see_price);
  5299. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5300. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_portfolioList:params]] mutableCopy];
  5301. dispatch_async(dispatch_get_main_queue(), ^{
  5302. if ([json[@"result"] intValue]==2)
  5303. {
  5304. appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  5305. [appDelegate update_count_mark];
  5306. }
  5307. result(json);
  5308. });
  5309. });
  5310. return;
  5311. }
  5312. [self request_interface:URL_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5313. if ([resulti[@"result"] intValue]==2)
  5314. {
  5315. appDelegate.port_count =[[resulti valueForKey:@"count"] intValue];
  5316. [appDelegate update_count_mark];
  5317. }
  5318. result(resulti);
  5319. } retry:0];
  5320. // NSData* json = nil;
  5321. // if(appDelegate.offline_mode)
  5322. // {
  5323. // json = [OLDataProvider offline_portfolioList:params];
  5324. // } else {
  5325. // if(![self IsNetworkAvailable])
  5326. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5327. //
  5328. // json = [self get_json:URL_PORTFOLIO parameters:params];
  5329. // }
  5330. //
  5331. //
  5332. // if(json==nil)
  5333. // return nil;
  5334. // NSError *error=nil;
  5335. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5336. // int result = [[jsobj valueForKey:@"result"] intValue];
  5337. //
  5338. // if (result==2)
  5339. // {
  5340. //
  5341. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5342. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  5343. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  5344. //
  5345. // [appDelegate update_count_mark];
  5346. // }
  5347. // return jsobj;
  5348. }
  5349. +(void)request_portfoliopdf:(int ) offset limit:(int)limit keywords:(NSString* ) keywords completionHandler:(resultHandler)result
  5350. {
  5351. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5352. AppDelegate *appDelegate = nil;
  5353. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5354. if(appDelegate.user!=nil)
  5355. [params setValue:appDelegate.user forKey:@"user"];
  5356. if(appDelegate.contact_id!=nil)
  5357. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5358. if(appDelegate.password!=nil)
  5359. [params setValue:appDelegate.password forKey:@"password"];
  5360. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  5361. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  5362. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  5363. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  5364. // [params setValue:filter forKey:@"filter"];
  5365. [params setValue:keywords forKey:@"keyWord"];
  5366. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  5367. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  5368. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  5369. if (keywords) {
  5370. [params setObject:@"Search" forKey:kAction];
  5371. }
  5372. if(appDelegate.offline_mode)
  5373. {
  5374. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5375. NSData* json = [[OLDataProvider offline_pdfList:params] mutableCopy];
  5376. dispatch_async(dispatch_get_main_queue(), ^{
  5377. result([[RAConvertor data2dict:json] mutableCopy]);
  5378. });
  5379. });
  5380. return;
  5381. }
  5382. [self request_interface:URL_DM_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  5383. return;
  5384. // NSData* json = nil;
  5385. // if(appDelegate.offline_mode)
  5386. // {
  5387. // json = [OLDataProvider offline_pdfList:params];
  5388. // } else {
  5389. // if(![self IsNetworkAvailable])
  5390. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5391. //
  5392. // json=[self get_json:URL_DM_LIST parameters:params];
  5393. // }
  5394. // if(json==nil)
  5395. // return nil;
  5396. // NSError *error=nil;
  5397. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5398. // return jsobj;
  5399. }
  5400. +(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
  5401. {
  5402. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5403. AppDelegate *appDelegate = nil;
  5404. //some UI methods ej
  5405. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5406. if(appDelegate.user!=nil)
  5407. [params setValue:appDelegate.user forKey:@"user"];
  5408. if(appDelegate.contact_id!=nil)
  5409. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5410. if(appDelegate.password!=nil)
  5411. [params setValue:appDelegate.password forKey:@"password"];
  5412. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  5413. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  5414. [params setValue:keywords forKey:@"keyWord"];
  5415. [params setValue:customer forKey:@"customer_filter"];
  5416. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  5417. [params setValue:status_code forKey:@"orderStatus"];
  5418. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  5419. if (keywords) {
  5420. [params setObject:@"Search" forKey:kAction];
  5421. }
  5422. if(appDelegate.offline_mode)
  5423. {
  5424. params[@"user"]=appDelegate.user;
  5425. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5426. NSData* json = [[OLDataProvider offline_orderlist:params] mutableCopy];
  5427. dispatch_async(dispatch_get_main_queue(), ^{
  5428. result([[RAConvertor data2dict:json] mutableCopy]);
  5429. });
  5430. });
  5431. return;
  5432. }
  5433. [self request_interface:URL_ORDER_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  5434. // NSData* json=nil;
  5435. // if(appDelegate.offline_mode)
  5436. // {
  5437. // json= [OLDataProvider offline_orderlist:params];
  5438. // }
  5439. // else
  5440. // {
  5441. // if(![self IsNetworkAvailable])
  5442. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5443. //
  5444. // json=[self get_json:URL_ORDER_LIST parameters:params];
  5445. // }
  5446. // if(json==nil)
  5447. // return nil;
  5448. // NSError *error=nil;
  5449. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5450. // return jsobj;
  5451. }
  5452. +(void)request_logout:(resultHandler)result
  5453. {
  5454. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5455. AppDelegate *appDelegate = nil;
  5456. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5457. if(appDelegate.user!=nil)
  5458. [params setValue:appDelegate.user forKey:@"user"];
  5459. if(appDelegate.password!=nil)
  5460. [params setValue:appDelegate.password forKey:@"password"];
  5461. if(appDelegate.offline_mode)
  5462. {
  5463. [OLDataProvider offline_logout:params completionHandler:result];
  5464. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5465. // NSMutableDictionary* json = [[OLDataProvider offline_logout:params] mutableCopy];
  5466. // dispatch_async(dispatch_get_main_queue(), ^{
  5467. // result(json);
  5468. // });
  5469. // });
  5470. return;
  5471. }
  5472. [self request_interface:URL_LOGOUT parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5473. NSMutableDictionary* jsobj=resulti;
  5474. int result_code = [[jsobj valueForKey:@"result"] intValue];
  5475. if (result_code==2)
  5476. {
  5477. appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  5478. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5479. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5480. [appDelegate update_count_mark];
  5481. appDelegate.can_show_price =false;
  5482. appDelegate.can_see_price =false;
  5483. appDelegate.can_create_portfolio =false;
  5484. appDelegate.can_create_order =false;
  5485. appDelegate.can_cancel_order =false;
  5486. appDelegate.can_set_cart_price =false;
  5487. appDelegate.can_delete_order =false;
  5488. appDelegate.can_submit_order =false;
  5489. appDelegate.can_set_tearsheet_price =false;
  5490. appDelegate.can_update_contact_info = false;
  5491. appDelegate.save_order_logout = false;
  5492. appDelegate.submit_order_logout = false;
  5493. appDelegate.alert_sold_in_quantities = false;
  5494. appDelegate.ipad_perm =nil ;
  5495. appDelegate.user_type = USER_ROLE_UNKNOWN;
  5496. appDelegate.OrderFilter= nil;
  5497. [appDelegate SetSo:nil];
  5498. [appDelegate set_main_button_panel];
  5499. #ifdef RA_NOTIFICATION
  5500. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5501. #endif
  5502. }
  5503. result(resulti);
  5504. } retry:0];
  5505. //
  5506. // if(appDelegate.offline_mode)
  5507. // {
  5508. // return [OLDataProvider offline_logout:params];
  5509. // }
  5510. // if(![self IsNetworkAvailable])
  5511. // {
  5512. // DebugLog(@"NET ERR");
  5513. //
  5514. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5515. // // return nil;
  5516. // }
  5517. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  5518. // //if(json==nil)
  5519. //
  5520. //
  5521. // if(json==nil)
  5522. // return nil;
  5523. // NSError *error=nil;
  5524. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5525. // int result = [[jsobj valueForKey:@"result"] intValue];
  5526. //
  5527. // if (result==2)
  5528. // {
  5529. //
  5530. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  5531. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5532. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5533. //
  5534. // [appDelegate update_count_mark];
  5535. //
  5536. //
  5537. // appDelegate.can_show_price =false;
  5538. // appDelegate.can_see_price =false;
  5539. // appDelegate.can_create_portfolio =false;
  5540. // appDelegate.can_create_order =false;
  5541. //
  5542. //
  5543. // appDelegate.can_cancel_order =false;
  5544. // appDelegate.can_set_cart_price =false;
  5545. // appDelegate.can_delete_order =false;
  5546. // appDelegate.can_submit_order =false;
  5547. // appDelegate.can_set_tearsheet_price =false;
  5548. // appDelegate.can_update_contact_info = false;
  5549. //
  5550. // appDelegate.save_order_logout = false;
  5551. // appDelegate.submit_order_logout = false;
  5552. // appDelegate.alert_sold_in_quantities = false;
  5553. //
  5554. // appDelegate.ipad_perm =nil ;
  5555. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  5556. // appDelegate.OrderFilter= nil;
  5557. // [appDelegate SetSo:nil];
  5558. // [appDelegate set_main_button_panel];
  5559. //#ifdef RA_NOTIFICATION
  5560. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5561. //#endif
  5562. // }
  5563. // return jsobj;
  5564. }
  5565. + (void)request_hangtag:(NSString *)group completionHandler:(resultHandler)result
  5566. {
  5567. #ifdef BUILD_UWAVER
  5568. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5569. AppDelegate *appDelegate = nil;
  5570. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5571. if(appDelegate.user!=nil)
  5572. [params setValue:appDelegate.user forKey:@"user"];
  5573. if(appDelegate.contact_id!=nil)
  5574. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5575. if(appDelegate.password!=nil)
  5576. [params setValue:appDelegate.password forKey:@"password"];
  5577. if (group) {
  5578. [params setValue:group forKey:@"groupName"];
  5579. }
  5580. NSString * uuid= [[NSUUID UUID] UUIDString];
  5581. params[@"resultSerial"]=uuid;
  5582. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  5583. if(appDelegate.offline_mode)
  5584. {
  5585. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5586. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5587. dispatch_async(dispatch_get_main_queue(), ^{
  5588. result(json);
  5589. });
  5590. });
  5591. return;
  5592. }
  5593. [self request_interface:URL_CREATE_HANG_TAG parameters:params err_record_url:nil completionHandler:result retry:0];
  5594. // NSData* json = nil;
  5595. // if(appDelegate.offline_mode)
  5596. // {
  5597. // json = [OLDataProvider offline_portfolioList:params];
  5598. // } else {
  5599. // if(![self IsNetworkAvailable])
  5600. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5601. //
  5602. // json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  5603. // }
  5604. //
  5605. //
  5606. // if(json==nil)
  5607. // return nil;
  5608. // NSError *error=nil;
  5609. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5610. //
  5611. // return jsobj;
  5612. #else
  5613. return result(nil);
  5614. #endif
  5615. }
  5616. + (void)request_movetobackorder:(NSString *)cart_item_id completionHandler:(resultHandler)result
  5617. {
  5618. if (cart_item_id == nil || cart_item_id.length < 1) {
  5619. result([@{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"} mutableCopy]);
  5620. }
  5621. AppDelegate *appDelegate = nil;
  5622. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5623. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5624. if(appDelegate.user!=nil)
  5625. [dic setValue:appDelegate.user forKey:@"user"];
  5626. if(appDelegate.password!=nil)
  5627. [dic setValue:appDelegate.password forKey:@"password"];
  5628. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  5629. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  5630. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5631. if(appDelegate.offline_mode)
  5632. {
  5633. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5634. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5635. dispatch_async(dispatch_get_main_queue(), ^{
  5636. result(json);
  5637. });
  5638. });
  5639. return;
  5640. }
  5641. [self request_interface:URL_MOVE_TO_BACK_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5642. // if(![self IsNetworkAvailable])
  5643. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5644. //
  5645. // NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  5646. //
  5647. // if(json!=nil)
  5648. // {
  5649. // NSError *error=nil;
  5650. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5651. //
  5652. // return jsobj;
  5653. // }
  5654. //
  5655. // return @{@"result" : @(RESULT_FALSE)};
  5656. }
  5657. + (void)request_emailwishlist:(NSString *)addr completionHandler:(resultHandler)result
  5658. {
  5659. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5660. AppDelegate *appDelegate = nil;
  5661. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5662. if(appDelegate.user!=nil)
  5663. [dic setValue:appDelegate.user forKey:@"user"];
  5664. if(appDelegate.password!=nil)
  5665. [dic setValue:appDelegate.password forKey:@"password"];
  5666. [dic setValue:addr forKey:@"email"];
  5667. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  5668. // if (appDelegate.customerInfo) {
  5669. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5670. // if (customer_cid) {
  5671. // [dic setValue:customer_cid forKey:@"contactId"];
  5672. // }
  5673. // }
  5674. if(appDelegate.offline_mode)
  5675. {
  5676. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5677. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5678. dispatch_async(dispatch_get_main_queue(), ^{
  5679. result(json);
  5680. });
  5681. });
  5682. return;
  5683. }
  5684. [self request_interface:URL_EMAIL_WISHLIST parameters:dic err_record_url:nil completionHandler:result retry:0];
  5685. // NSData* json=nil;
  5686. // if(appDelegate.offline_mode)
  5687. // {
  5688. // return [OLDataProvider offline_notimpl];
  5689. // }
  5690. // else
  5691. // {
  5692. // if(![self IsNetworkAvailable])
  5693. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5694. //
  5695. // json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  5696. // }
  5697. // if(json!=nil)
  5698. // {
  5699. // NSError *error=nil;
  5700. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5701. //
  5702. //
  5703. // return jsobj;
  5704. // }
  5705. //
  5706. // return @{@"result" : @(RESULT_FALSE)};
  5707. }
  5708. +(void)request_notifymodel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  5709. {
  5710. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5711. AppDelegate *appDelegate = nil;
  5712. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5713. if(appDelegate.user!=nil)
  5714. [dic setValue:appDelegate.user forKey:@"user"];
  5715. if(appDelegate.password!=nil)
  5716. [dic setValue:appDelegate.password forKey:@"password"];
  5717. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5718. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5719. if (customer_cid) {
  5720. [dic setValue:customer_cid forKey:@"contactId"];
  5721. }
  5722. }
  5723. [dic setObject:screenName forKey:kScreenName];
  5724. [dic setValue:modelID forKey:@"productId"];
  5725. if (addr) { // 弹框输入
  5726. [dic setValue:addr forKey:@"email"];
  5727. } else {
  5728. // employee选择了Contact,并且Contact有Email
  5729. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5730. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  5731. // if (email) {
  5732. // [dic setValue:email forKey:@"email"];
  5733. // }
  5734. // }
  5735. }
  5736. if(appDelegate.offline_mode)
  5737. {
  5738. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5739. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5740. dispatch_async(dispatch_get_main_queue(), ^{
  5741. result(json);
  5742. });
  5743. });
  5744. return;
  5745. }
  5746. [self request_interface:URL_NOTIFY_ME parameters:dic err_record_url:nil completionHandler:result retry:0];
  5747. // NSData* json=nil;
  5748. // if(appDelegate.offline_mode)
  5749. // {
  5750. // return [OLDataProvider offline_notimpl];
  5751. // }
  5752. // else
  5753. // {
  5754. // if(![self IsNetworkAvailable])
  5755. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5756. //
  5757. // json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  5758. // }
  5759. // if(json!=nil)
  5760. // {
  5761. // NSError *error=nil;
  5762. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5763. //
  5764. //
  5765. // return jsobj;
  5766. // }
  5767. //
  5768. // return @{@"result" : @(RESULT_FALSE)};
  5769. }
  5770. + (void)request_qouteorder:(NSString *)so_id emailAddr:(NSString *)addr completionHandler:(resultHandler)result
  5771. {
  5772. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5773. AppDelegate *appDelegate = nil;
  5774. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5775. if(appDelegate.user!=nil)
  5776. [dic setValue:appDelegate.user forKey:@"user"];
  5777. if(appDelegate.password!=nil)
  5778. [dic setValue:appDelegate.password forKey:@"password"];
  5779. [dic setValue:so_id forKey:@"orderCode"];
  5780. [dic setValue:addr forKey:@"email"];
  5781. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5782. if (appDelegate.customerInfo) {
  5783. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5784. if (customer_cid) {
  5785. [dic setValue:customer_cid forKey:@"contactId"];
  5786. }
  5787. }
  5788. if(appDelegate.offline_mode)
  5789. {
  5790. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5791. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5792. dispatch_async(dispatch_get_main_queue(), ^{
  5793. result(json);
  5794. });
  5795. });
  5796. return;
  5797. }
  5798. [self request_interface:URL_EMAIL_CART parameters:dic err_record_url:nil completionHandler:result retry:0];
  5799. // NSData* json=nil;
  5800. // if(appDelegate.offline_mode)
  5801. // {
  5802. // return [OLDataProvider offline_notimpl];
  5803. // }
  5804. // else
  5805. // {
  5806. // if(![self IsNetworkAvailable])
  5807. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5808. //
  5809. // json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  5810. // }
  5811. // if(json!=nil)
  5812. // {
  5813. // NSError *error=nil;
  5814. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5815. //
  5816. //
  5817. // return jsobj;
  5818. // }
  5819. //
  5820. // return @{@"result" : @(RESULT_FALSE)};
  5821. }
  5822. + (void)request_mergeorder:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  5823. {
  5824. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5825. AppDelegate *appDelegate = nil;
  5826. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5827. if(appDelegate.user!=nil)
  5828. [dic setValue:appDelegate.user forKey:@"user"];
  5829. if(appDelegate.password!=nil)
  5830. [dic setValue:appDelegate.password forKey:@"password"];
  5831. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  5832. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  5833. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  5834. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  5835. if(appDelegate.offline_mode)
  5836. {
  5837. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5838. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5839. dispatch_async(dispatch_get_main_queue(), ^{
  5840. result(json);
  5841. });
  5842. });
  5843. return;
  5844. }
  5845. [self request_interface:URL_SET_MERGE_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5846. // NSData* json=nil;
  5847. // if(appDelegate.offline_mode)
  5848. // {
  5849. // return [OLDataProvider offline_notimpl];
  5850. // }
  5851. // else
  5852. // {
  5853. // if(![self IsNetworkAvailable])
  5854. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5855. //
  5856. // json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  5857. // }
  5858. // if(json!=nil)
  5859. // {
  5860. // NSError *error=nil;
  5861. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5862. //
  5863. //
  5864. // return jsobj;
  5865. // }
  5866. // else
  5867. // return nil;
  5868. }
  5869. +(void)request_pendingorder:(NSString *)contactid completionHandler:(resultHandler)result
  5870. {
  5871. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5872. AppDelegate *appDelegate = nil;
  5873. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5874. if(appDelegate.user!=nil)
  5875. [params setValue:appDelegate.user forKey:@"user"];
  5876. // if(appDelegate.contact_id!=nil)
  5877. if(appDelegate.password!=nil)
  5878. [params setValue:appDelegate.password forKey:@"password"];
  5879. [params setValue:contactid forKey:@"contactId"];
  5880. if(appDelegate.offline_mode)
  5881. {
  5882. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5883. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5884. dispatch_async(dispatch_get_main_queue(), ^{
  5885. result(json);
  5886. });
  5887. });
  5888. return;
  5889. }
  5890. [self request_interface:URL_CUSTOMER_PENDINGORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  5891. //
  5892. // if(appDelegate.offline_mode)
  5893. // {
  5894. // return [OLDataProvider offline_notimpl];
  5895. // }
  5896. // if(![self IsNetworkAvailable])
  5897. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5898. //
  5899. // NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  5900. // if(json==nil)
  5901. // return nil;
  5902. // NSError *error=nil;
  5903. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5904. // return jsobj;
  5905. //
  5906. }
  5907. +(void) request_removeportfolio:(NSString* ) item_ids completionHandler:(resultHandler)result
  5908. {
  5909. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5910. AppDelegate *appDelegate = nil;
  5911. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5912. if(appDelegate.user!=nil)
  5913. [params setValue:appDelegate.user forKey:@"user"];
  5914. if(appDelegate.contact_id!=nil)
  5915. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5916. if(appDelegate.password!=nil)
  5917. [params setValue:appDelegate.password forKey:@"password"];
  5918. [params setValue:item_ids forKey:@"portfolioId"];
  5919. // [params setValue:editor forKey:@"editor"];
  5920. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  5921. if(appDelegate.offline_mode)
  5922. {
  5923. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5924. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_removePortfolio:params]] mutableCopy];
  5925. dispatch_async(dispatch_get_main_queue(), ^{
  5926. int result_code = [[resulti valueForKey:@"result"] intValue];
  5927. if (result_code==2)
  5928. {
  5929. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5930. [appDelegate update_count_mark];
  5931. };
  5932. result(resulti);
  5933. });
  5934. });
  5935. return;
  5936. }
  5937. [self request_interface:URL_PORTFOLIO_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5938. int result_code = [[resulti valueForKey:@"result"] intValue];
  5939. if (result_code==2)
  5940. {
  5941. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5942. [appDelegate update_count_mark];
  5943. };
  5944. result(resulti);
  5945. } retry:0];
  5946. // NSData* json = nil;
  5947. // if(appDelegate.offline_mode)
  5948. // {
  5949. // json = [OLDataProvider offline_removePortfolio:params];
  5950. // } else {
  5951. // if(![self IsNetworkAvailable])
  5952. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5953. // json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  5954. // }
  5955. // if(json!=nil)
  5956. // {
  5957. // NSError *error=nil;
  5958. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5959. //
  5960. //
  5961. // int result = [[jsobj valueForKey:@"result"] intValue];
  5962. //
  5963. // if (result==2)
  5964. // {
  5965. //
  5966. //
  5967. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5968. //
  5969. // [appDelegate update_count_mark];
  5970. // }
  5971. // return jsobj;
  5972. // }
  5973. // else
  5974. // return nil;
  5975. }
  5976. +(void) request_removeportfoliopdf:(NSString* ) listid completionHandler:(resultHandler)result
  5977. {
  5978. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5979. AppDelegate *appDelegate = nil;
  5980. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5981. if(appDelegate.user!=nil)
  5982. [params setValue:appDelegate.user forKey:@"user"];
  5983. if(appDelegate.contact_id!=nil)
  5984. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5985. if(appDelegate.password!=nil)
  5986. [params setValue:appDelegate.password forKey:@"password"];
  5987. [params setValue:listid forKey:@"tearsheetsId"];
  5988. // [params setValue:editor forKey:@"editor"];
  5989. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  5990. // [params setValue:@"Delete Portfolio" forKey:kAction];
  5991. if(appDelegate.offline_mode)
  5992. {
  5993. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5994. NSData* json = [[OLDataProvider offline_removePDF:params] mutableCopy];
  5995. dispatch_async(dispatch_get_main_queue(), ^{
  5996. result([[RAConvertor data2dict:json] mutableCopy]);
  5997. });
  5998. });
  5999. return;
  6000. }
  6001. [self request_interface:URL_PORTFOLIOLIST_REMOVE parameters:params err_record_url:nil completionHandler:result retry:0];
  6002. }
  6003. +(void) request_remove_wishlist:(NSString* ) item_ids completionHandler:(resultHandler)result
  6004. {
  6005. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6006. __block AppDelegate *appDelegate = nil;
  6007. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6008. if(appDelegate.user!=nil)
  6009. [params setValue:appDelegate.user forKey:@"user"];
  6010. if(appDelegate.contact_id!=nil)
  6011. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6012. if(appDelegate.password!=nil)
  6013. [params setValue:appDelegate.password forKey:@"password"];
  6014. [params setValue:item_ids forKey:@"collectId"];
  6015. // [params setValue:editor forKey:@"editor"];
  6016. [params setValue:ScreenCodeWishList forKey:kScreenName];
  6017. if(appDelegate.offline_mode)
  6018. {
  6019. // [OLDataProvider offline_deletewishlist:params completionHandler:result];
  6020. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6021. NSMutableDictionary* resulti = [[OLDataProvider offline_deletewishlist:params] mutableCopy];
  6022. dispatch_async(dispatch_get_main_queue(), ^{
  6023. int result_code = [[resulti valueForKey:@"result"] intValue];
  6024. if (result_code==2)
  6025. {
  6026. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6027. [appDelegate update_count_mark];
  6028. };
  6029. result(resulti);
  6030. });
  6031. });
  6032. return;
  6033. }
  6034. [self request_interface:URL_WATCHLIST_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6035. int result_code = [[resulti valueForKey:@"result"] intValue];
  6036. if (result_code==2)
  6037. {
  6038. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6039. [appDelegate update_count_mark];
  6040. };
  6041. result(resulti);
  6042. } retry:0];
  6043. //
  6044. //
  6045. // if(appDelegate.offline_mode)
  6046. // {
  6047. // return [OLDataProvider offline_deletewishlist:params];
  6048. // }
  6049. // if(![self IsNetworkAvailable])
  6050. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6051. //
  6052. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  6053. // if(json!=nil)
  6054. // {
  6055. // NSError *error=nil;
  6056. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6057. // int result = [[jsobj valueForKey:@"result"] intValue];
  6058. //
  6059. // if (result==2)
  6060. // {
  6061. //
  6062. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6063. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6064. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6065. //
  6066. // [appDelegate update_count_mark];
  6067. // }
  6068. // return jsobj;
  6069. // }
  6070. // else
  6071. // return nil;
  6072. }
  6073. +(void) request_remove_cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  6074. {
  6075. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6076. AppDelegate *appDelegate = nil;
  6077. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6078. #ifdef SCANNER_ORDER
  6079. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  6080. {
  6081. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  6082. //
  6083. //
  6084. // [appDelegate update_count_mark];
  6085. NSArray* arr=[RAConvertor string2arr:item_ids separator:@","];
  6086. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  6087. NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  6088. NSMutableDictionary* newsection =[cartTemplate[@"section_0"] mutableCopy];
  6089. int newcount = 0;
  6090. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  6091. int count = [section[@"count"] intValue];
  6092. for(int i=0;i<count;i++)
  6093. {
  6094. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  6095. int index = [arr indexOfObject:item[@"cart_item_id"]] ;
  6096. if(index <0)
  6097. {
  6098. newsection[[NSString stringWithFormat:@"item_%d",newcount]] = item;
  6099. newcount ++;
  6100. }
  6101. }
  6102. newsection[@"count"]=@(newcount);
  6103. RASingleton.sharedInstance.scan_cart[@"section_0"] = newsection;
  6104. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  6105. result(RASingleton.sharedInstance.scan_cart);
  6106. return;
  6107. }
  6108. #endif
  6109. if(appDelegate.user!=nil)
  6110. [params setValue:appDelegate.user forKey:@"user"];
  6111. if(appDelegate.contact_id!=nil)
  6112. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6113. if(appDelegate.password!=nil)
  6114. [params setValue:appDelegate.password forKey:@"password"];
  6115. if(appDelegate.order_code!=nil)
  6116. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6117. [params setValue:item_ids forKey:@"cartItemId"];
  6118. // [params setValue:editor forKey:@"editor"];
  6119. [params setValue:ScreenCodeCart forKey:kScreenName];
  6120. // [params setValue:@"" forKey:kAction];
  6121. if(appDelegate.offline_mode)
  6122. {
  6123. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6124. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_cartremove:params]] mutableCopy];
  6125. dispatch_async(dispatch_get_main_queue(), ^{
  6126. int result_code = [[resulti valueForKey:@"result"] intValue];
  6127. if (result_code==2)
  6128. {
  6129. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6130. [appDelegate update_count_mark];
  6131. };
  6132. result(resulti);
  6133. });
  6134. });
  6135. return;
  6136. }
  6137. [self request_interface:URL_CART_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6138. int result_code = [[resulti valueForKey:@"result"] intValue];
  6139. if (result_code==2)
  6140. {
  6141. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6142. [appDelegate update_count_mark];
  6143. };
  6144. result(resulti);
  6145. } retry:0];
  6146. //
  6147. // NSData* json=nil;
  6148. // if(appDelegate.offline_mode)
  6149. // {
  6150. // json= [OLDataProvider offline_cartremove:params];
  6151. // }
  6152. // else
  6153. // {
  6154. // if(![self IsNetworkAvailable])
  6155. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6156. //
  6157. // json=[self get_json:URL_CART_REMOVE parameters:params];
  6158. // }
  6159. // if(json!=nil)
  6160. // {
  6161. // NSError *error=nil;
  6162. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6163. //
  6164. // int result = [[jsobj valueForKey:@"result"] intValue];
  6165. //
  6166. // if (result==2)
  6167. // {
  6168. //
  6169. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6170. //
  6171. //
  6172. // [appDelegate update_count_mark];
  6173. // }
  6174. // return jsobj;
  6175. // }
  6176. // else
  6177. // return nil;
  6178. }
  6179. +(void)request_delete_account:(resultHandler)result
  6180. {
  6181. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6182. AppDelegate *appDelegate = nil;
  6183. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6184. if(appDelegate.user!=nil)
  6185. [params setValue:appDelegate.user forKey:@"user"];
  6186. if(appDelegate.password!=nil)
  6187. [params setValue:appDelegate.password forKey:@"password"];
  6188. if(appDelegate.offline_mode)
  6189. {
  6190. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6191. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  6192. dispatch_async(dispatch_get_main_queue(), ^{
  6193. result(json);
  6194. });
  6195. });
  6196. return;
  6197. }
  6198. #ifdef SCANNER_ORDER
  6199. params[@"site_name"]=[RADataProvider getSiteName];
  6200. params[@"_method"]=@"cancelOfflineOrderUser";
  6201. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_DELETE_ACCOUNT];
  6202. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  6203. #else
  6204. [self request_interface:URL_DELETE_ACCOUNT parameters:params err_record_url:nil completionHandler:result retry:0];
  6205. #endif
  6206. }
  6207. +(void) request_create_order:(resultHandler)result
  6208. {
  6209. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6210. AppDelegate *appDelegate = nil;
  6211. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6212. if(appDelegate.user!=nil)
  6213. [params setValue:appDelegate.user forKey:@"user"];
  6214. if(appDelegate.contact_id!=nil)
  6215. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6216. if(appDelegate.password!=nil)
  6217. [params setValue:appDelegate.password forKey:@"password"];
  6218. if(appDelegate.order_code!=nil)
  6219. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6220. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  6221. NSDictionary* customerinfo= appDelegate.customerInfo;
  6222. NSArray* keys=[customerinfo allKeys];
  6223. for(int i=0;i<keys.count;i++)
  6224. {
  6225. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  6226. }
  6227. if(appDelegate.offline_mode)
  6228. {
  6229. [OLDataProvider offline_createorder:params completionHandler:^(NSMutableDictionary *resulti) {
  6230. int result_code = [[resulti valueForKey:@"result"] intValue];
  6231. if (result_code==2)
  6232. {
  6233. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6234. [appDelegate update_count_mark];
  6235. };
  6236. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  6237. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6238. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  6239. }
  6240. result(resulti);
  6241. }];
  6242. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6243. // NSData* json = [[OLDataProvider offline_createorder:params] mutableCopy];
  6244. // dispatch_async(dispatch_get_main_queue(), ^{
  6245. // result([[RAConvertor data2dict:json] mutableCopy]);
  6246. // });
  6247. // });
  6248. return;
  6249. }
  6250. [self request_interface:URL_NEW_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6251. int result_code = [[resulti valueForKey:@"result"] intValue];
  6252. if (result_code==2)
  6253. {
  6254. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6255. [appDelegate update_count_mark];
  6256. };
  6257. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  6258. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6259. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  6260. }
  6261. result(resulti);
  6262. } retry:0];
  6263. //
  6264. // NSData* json = nil;
  6265. // if(appDelegate.offline_mode)
  6266. // {
  6267. // json= [OLDataProvider offline_createorder:params];
  6268. // }
  6269. // else
  6270. // {
  6271. // if(![self IsNetworkAvailable])
  6272. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6273. //
  6274. // json=[self get_json:URL_NEW_ORDER parameters:params];
  6275. // }
  6276. // if(json==nil)
  6277. // return nil;
  6278. // NSError *error=nil;
  6279. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6280. // int result = [[jsobj valueForKey:@"result"] intValue];
  6281. //
  6282. // if (result==2)
  6283. // {
  6284. //
  6285. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6286. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6287. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6288. //
  6289. // [appDelegate update_count_mark];
  6290. // }
  6291. //
  6292. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  6293. //
  6294. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6295. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  6296. // }
  6297. //
  6298. // return jsobj;
  6299. }
  6300. +(void)request_open_order:(NSString*) order_code completionHandler:(resultHandler)result
  6301. {
  6302. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6303. AppDelegate *appDelegate = nil;
  6304. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6305. if(appDelegate.user!=nil)
  6306. [params setValue:appDelegate.user forKey:@"user"];
  6307. // if(appDelegate.contact_id!=nil)
  6308. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6309. if(appDelegate.password!=nil)
  6310. [params setValue:appDelegate.password forKey:@"password"];
  6311. [params setValue:order_code forKey:@"orderCode"];
  6312. // [params setValue:sourceid forKey:@"sourceid"];
  6313. // [params setValue:editor forKey:@"editor"];
  6314. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  6315. if(appDelegate.offline_mode)
  6316. {
  6317. params[@"appDelegate.order_code"]=appDelegate.order_code;
  6318. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6319. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_editorder:params]] mutableCopy];
  6320. dispatch_async(dispatch_get_main_queue(), ^{
  6321. int result_code = [[resulti valueForKey:@"result"] intValue];
  6322. if (result_code==2)
  6323. {
  6324. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6325. [appDelegate update_count_mark];
  6326. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6327. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  6328. }
  6329. }
  6330. result(resulti);
  6331. });
  6332. });
  6333. return;
  6334. }
  6335. [self request_interface:URL_OPEN_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6336. int result_code = [[resulti valueForKey:@"result"] intValue];
  6337. if (result_code==2)
  6338. {
  6339. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6340. [appDelegate update_count_mark];
  6341. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6342. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  6343. }
  6344. }
  6345. result(resulti);
  6346. } retry:0];
  6347. //
  6348. // NSData* json=nil;
  6349. // if(appDelegate.offline_mode)
  6350. // {
  6351. // json=[OLDataProvider offline_editorder:params];
  6352. //
  6353. // }
  6354. // else
  6355. // {
  6356. // if(![self IsNetworkAvailable])
  6357. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6358. //
  6359. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  6360. // }
  6361. // if(json!=nil)
  6362. // {
  6363. // NSError *error=nil;
  6364. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6365. // int result = [[jsobj valueForKey:@"result"] intValue];
  6366. //
  6367. // if (result==2)
  6368. // {
  6369. //
  6370. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6371. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6372. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6373. //
  6374. // [appDelegate update_count_mark];
  6375. //
  6376. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6377. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  6378. // }
  6379. //
  6380. // }
  6381. //
  6382. // return jsobj;
  6383. // }
  6384. // else
  6385. // return nil;
  6386. }
  6387. +(void)request_order_discount:(double)discount completionHandler:(resultHandler)result
  6388. {
  6389. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6390. AppDelegate *appDelegate = nil;
  6391. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6392. if(appDelegate.user!=nil)
  6393. [params setValue:appDelegate.user forKey:@"user"];
  6394. // if(appDelegate.contact_id!=nil)
  6395. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6396. if(appDelegate.password!=nil)
  6397. [params setValue:appDelegate.password forKey:@"password"];
  6398. if(appDelegate.order_code!=nil)
  6399. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6400. [params setValue:@(discount) forKey:@"app_discount"];
  6401. if(appDelegate.offline_mode)
  6402. {
  6403. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6404. NSMutableDictionary* json = [[OLDataProvider offline_cartsetallprice:params] mutableCopy];
  6405. dispatch_async(dispatch_get_main_queue(), ^{
  6406. result(json);
  6407. });
  6408. });
  6409. return;
  6410. //
  6411. //
  6412. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6413. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  6414. // dispatch_async(dispatch_get_main_queue(), ^{
  6415. // result(json);
  6416. // });
  6417. // });
  6418. //
  6419. // return;
  6420. }
  6421. [self request_interface:URL_ORDER_DISCOUNT parameters:params err_record_url:nil completionHandler:result retry:0];
  6422. }
  6423. +(void)request_cart:(int)sort completionHandler:(resultHandler)result
  6424. {
  6425. DebugLog(@"iSalesNetwork::request_Cart");
  6426. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6427. AppDelegate *appDelegate = nil;
  6428. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6429. #ifdef SCANNER_ORDER
  6430. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  6431. {
  6432. appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  6433. [appDelegate update_count_mark];
  6434. result(RASingleton.sharedInstance.scan_cart);
  6435. return;
  6436. }
  6437. #endif
  6438. if(appDelegate.user!=nil)
  6439. [params setValue:appDelegate.user forKey:@"user"];
  6440. // if(appDelegate.contact_id!=nil)
  6441. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6442. if(appDelegate.password!=nil)
  6443. [params setValue:appDelegate.password forKey:@"password"];
  6444. if(appDelegate.order_code!=nil)
  6445. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6446. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  6447. [params setObject:ScreenCodeCart forKey:kScreenName];
  6448. if(appDelegate.offline_mode)
  6449. {
  6450. [OLDataProvider offline_requestcart:params completionHandler:^(NSMutableDictionary *resulti) {
  6451. if([resulti[@"result"] intValue]==2)
  6452. {
  6453. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6454. [appDelegate update_count_mark];
  6455. result(resulti);
  6456. }
  6457. }];
  6458. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6459. // NSData* json = [[OLDataProvider offline_requestcart:params] mutableCopy];
  6460. // dispatch_async(dispatch_get_main_queue(), ^{
  6461. // result([[RAConvertor data2dict:json] mutableCopy]);
  6462. // });
  6463. // });
  6464. return;
  6465. }
  6466. NSString * uuid= [[NSUUID UUID] UUIDString];
  6467. params[@"resultSerial"]=uuid;
  6468. __block bool bbreak = false;
  6469. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6470. for(int i=0;i<150;i++)
  6471. {
  6472. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6473. // result_params[@"resultSerial"]=uuid;
  6474. if(bbreak)
  6475. break;
  6476. dispatch_async(dispatch_get_main_queue(), ^{
  6477. [self request_interface:URL_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6478. if([resulti[@"result"] intValue]==2)
  6479. {
  6480. if(!bbreak) //此判断保证result只调用一次。
  6481. {
  6482. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6483. [appDelegate update_count_mark];
  6484. result(resulti);
  6485. }
  6486. bbreak=true;
  6487. }
  6488. } retry:3];
  6489. });
  6490. sleep(2);
  6491. // json=[self get_json:URL_CART parameters:params];
  6492. // if(json!=nil)
  6493. // {
  6494. //
  6495. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6496. // if([jsobj[@"result"] intValue]==2)
  6497. // {
  6498. // break;
  6499. // }
  6500. // }
  6501. }
  6502. });
  6503. //
  6504. //
  6505. //
  6506. // NSData* json=nil;
  6507. // if(appDelegate.offline_mode)
  6508. // {
  6509. // json= [OLDataProvider offline_requestcart:params];
  6510. // }
  6511. // else
  6512. // {
  6513. // if(![self IsNetworkAvailable])
  6514. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6515. //
  6516. // NSError *error=nil;
  6517. //
  6518. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6519. // params[@"resultSerial"]=uuid;
  6520. //
  6521. // for(int i=0;i<150;i++)
  6522. // {
  6523. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6524. // // result_params[@"resultSerial"]=uuid;
  6525. // json=[self get_json:URL_CART parameters:params];
  6526. // if(json!=nil)
  6527. // {
  6528. //
  6529. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6530. // if([jsobj[@"result"] intValue]==2)
  6531. // {
  6532. // break;
  6533. // }
  6534. // }
  6535. // sleep(2);
  6536. // }
  6537. //
  6538. // }
  6539. // if(json==nil)
  6540. // return nil;
  6541. // NSError *error=nil;
  6542. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6543. // int result = [[jsobj valueForKey:@"result"] intValue];
  6544. //
  6545. // if (result==2)
  6546. // {
  6547. //
  6548. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6549. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  6550. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6551. //
  6552. // [appDelegate update_count_mark];
  6553. // }
  6554. // return jsobj;
  6555. }
  6556. +(void) request_move_wish2cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  6557. {
  6558. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6559. AppDelegate *appDelegate = nil;
  6560. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6561. if(appDelegate.user!=nil)
  6562. [params setValue:appDelegate.user forKey:@"user"];
  6563. if(appDelegate.contact_id!=nil)
  6564. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6565. if(appDelegate.password!=nil)
  6566. [params setValue:appDelegate.password forKey:@"password"];
  6567. if(appDelegate.order_code!=nil)
  6568. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6569. [params setValue:item_ids forKey:@"collectId"];
  6570. // [params setValue:editor forKey:@"editor"];
  6571. [params setValue:ScreenCodeWishList forKey:kScreenName];
  6572. [params setValue:@"Move To Cart" forKey:kAction];
  6573. if(appDelegate.offline_mode)
  6574. {
  6575. // [OLDataProvider offline_movewish2cart:params completionHandler:result];
  6576. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6577. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6578. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movewish2cart:params]] mutableCopy];
  6579. dispatch_async(dispatch_get_main_queue(), ^{
  6580. int result_code = [[resulti valueForKey:@"result"] intValue];
  6581. if (result_code==2)
  6582. {
  6583. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6584. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6585. [appDelegate update_count_mark];
  6586. }
  6587. result(resulti);
  6588. });
  6589. });
  6590. return;
  6591. }
  6592. [self request_interface:URL_WISH2CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6593. int result_code = [[resulti valueForKey:@"result"] intValue];
  6594. if (result_code==2)
  6595. {
  6596. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6597. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6598. [appDelegate update_count_mark];
  6599. }
  6600. result(resulti);
  6601. } retry:0];
  6602. //
  6603. // NSData *json = nil;
  6604. // if(appDelegate.offline_mode)
  6605. // {
  6606. // json = [OLDataProvider offline_movewish2cart:params];
  6607. // } else {
  6608. // if(![self IsNetworkAvailable])
  6609. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6610. //
  6611. // json=[self get_json:URL_WISH2CART parameters:params];
  6612. // }
  6613. //
  6614. // if(json!=nil)
  6615. // {
  6616. // NSError *error=nil;
  6617. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6618. // int result = [[jsobj valueForKey:@"result"] intValue];
  6619. //
  6620. // if (result==2)
  6621. // {
  6622. //
  6623. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6624. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6625. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6626. //
  6627. // [appDelegate update_count_mark];
  6628. // }
  6629. // return jsobj;
  6630. // }
  6631. // else
  6632. // return nil;
  6633. }
  6634. +(void) request_move_cart2wish:(NSString* ) item_ids completionHandler:(resultHandler)result
  6635. {
  6636. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6637. AppDelegate *appDelegate = nil;
  6638. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6639. if(appDelegate.user!=nil)
  6640. [params setValue:appDelegate.user forKey:@"user"];
  6641. if(appDelegate.contact_id!=nil)
  6642. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6643. if(appDelegate.password!=nil)
  6644. [params setValue:appDelegate.password forKey:@"password"];
  6645. if(appDelegate.order_code!=nil)
  6646. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6647. [params setValue:item_ids forKey:@"cartItemId"];
  6648. // [params setValue:editor forKey:@"editor"];
  6649. [params setValue:ScreenCodeCart forKey:kScreenName];
  6650. // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  6651. if(appDelegate.offline_mode)
  6652. {
  6653. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6654. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movecart2wish:params]] mutableCopy];
  6655. dispatch_async(dispatch_get_main_queue(), ^{
  6656. int result_code = [[resulti valueForKey:@"result"] intValue];
  6657. if (result_code==2)
  6658. {
  6659. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6660. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6661. [appDelegate update_count_mark];
  6662. }
  6663. result(resulti);
  6664. });
  6665. });
  6666. return;
  6667. }
  6668. [self request_interface:URL_CART2WISH parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6669. int result_code = [[resulti valueForKey:@"result"] intValue];
  6670. if (result_code==2)
  6671. {
  6672. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6673. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6674. [appDelegate update_count_mark];
  6675. }
  6676. result(resulti);
  6677. } retry:0];
  6678. //
  6679. // NSData* json = nil;
  6680. // if(appDelegate.offline_mode)
  6681. // {
  6682. // json= [OLDataProvider offline_movecart2wish:params];
  6683. // }
  6684. // else
  6685. // {
  6686. // if(![self IsNetworkAvailable])
  6687. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6688. //
  6689. // json=[self get_json:URL_CART2WISH parameters:params];
  6690. // }
  6691. // if(json!=nil)
  6692. // {
  6693. // NSError *error=nil;
  6694. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6695. // int result = [[jsobj valueForKey:@"result"] intValue];
  6696. //
  6697. // if (result==2)
  6698. // {
  6699. //
  6700. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6701. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6702. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6703. //
  6704. // [appDelegate update_count_mark];
  6705. // }
  6706. // return jsobj;
  6707. // }
  6708. // else
  6709. // return nil;
  6710. }
  6711. +(void)request_orderdetail:(NSMutableDictionary *) params completionHandler:(resultHandler)result
  6712. {
  6713. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6714. if (params == nil) {
  6715. params = [[NSMutableDictionary alloc] init];
  6716. }
  6717. AppDelegate *appDelegate = nil;
  6718. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6719. if(appDelegate.user!=nil)
  6720. [params setValue:appDelegate.user forKey:@"user"];
  6721. if(appDelegate.contact_id!=nil)
  6722. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6723. if(appDelegate.password!=nil)
  6724. [params setValue:appDelegate.password forKey:@"password"];
  6725. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  6726. [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  6727. if(appDelegate.offline_mode)
  6728. {
  6729. params[@"mode"]=appDelegate.mode;
  6730. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6731. NSData* json = [[OLDataProvider offline_orderdetail:params] mutableCopy];
  6732. dispatch_async(dispatch_get_main_queue(), ^{
  6733. result([[RAConvertor data2dict:json] mutableCopy]);
  6734. });
  6735. });
  6736. return;
  6737. }
  6738. NSString * uuid= [[NSUUID UUID] UUIDString];
  6739. params[@"resultSerial"]=uuid;
  6740. __block bool bbreak = false;
  6741. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6742. for(int i=0;i<150;i++)
  6743. {
  6744. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6745. // result_params[@"resultSerial"]=uuid;
  6746. if(bbreak)
  6747. break;
  6748. dispatch_async(dispatch_get_main_queue(), ^{
  6749. [self request_interface:URL_ORDER_DETAIL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6750. if([resulti[@"result"] intValue]==2||[resulti[@"result"] intValue]==8)
  6751. {
  6752. if(!bbreak)//此判断保证result只调用一次。
  6753. result(resulti);
  6754. bbreak=true;
  6755. }
  6756. } retry:3];
  6757. });
  6758. sleep(2);
  6759. }
  6760. });
  6761. //
  6762. // NSData* json=nil;
  6763. // if(appDelegate.offline_mode)
  6764. // {
  6765. // json= [OLDataProvider offline_orderdetail:params];
  6766. // }
  6767. // else
  6768. // {
  6769. // if(![self IsNetworkAvailable])
  6770. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6771. //
  6772. // NSError *error=nil;
  6773. //
  6774. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6775. // params[@"resultSerial"]=uuid;
  6776. //
  6777. // for(int i=0;i<150;i++)
  6778. // {
  6779. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6780. // // result_params[@"resultSerial"]=uuid;
  6781. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  6782. // if(json!=nil)
  6783. // {
  6784. //
  6785. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6786. // int resultCode = [jsobj[@"result"] intValue];
  6787. // if(resultCode==2 || resultCode == 8)
  6788. // {
  6789. // break;
  6790. // }
  6791. // }
  6792. // sleep(2);
  6793. // }
  6794. //
  6795. //
  6796. // }
  6797. // if(json==nil)
  6798. // return nil;
  6799. // NSError *error=nil;
  6800. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6801. // return jsobj;
  6802. }
  6803. //
  6804. //+(void)request_commit_order:(NSString*) order_code completionHandler:(resultHandler)result
  6805. //{
  6806. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6807. // AppDelegate *appDelegate = nil;
  6808. //
  6809. //
  6810. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6811. //
  6812. // if(appDelegate.user!=nil)
  6813. // [params setValue:appDelegate.user forKey:@"user"];
  6814. // if(appDelegate.contact_id!=nil)
  6815. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6816. // if(appDelegate.password!=nil)
  6817. // [params setValue:appDelegate.password forKey:@"password"];
  6818. // // NSString* ssaved = @"false";
  6819. // // if(saved)
  6820. // // ssaved=@"true";
  6821. // [params setValue:@"true" forKey:@"saved"];
  6822. // [params setValue:order_code forKey:@"orderCode"];
  6823. // // [params setValue:sourceid forKey:@"sourceid"];
  6824. // // [params setValue:editor forKey:@"editor"];
  6825. //
  6826. // [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  6827. //
  6828. //
  6829. // if(appDelegate.offline_mode)
  6830. // {
  6831. //
  6832. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6833. // NSMutableDictionary* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  6834. // dispatch_async(dispatch_get_main_queue(), ^{
  6835. // result(json);
  6836. // });
  6837. // });
  6838. //
  6839. // return;
  6840. // }
  6841. //
  6842. //
  6843. // [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6844. //
  6845. //// NSData* json = nil;
  6846. ////
  6847. //// if(appDelegate.offline_mode)
  6848. //// {
  6849. //// json= [OLDataProvider offline_submitorder:params];
  6850. //// }
  6851. //// else
  6852. //// {
  6853. //// if(![self IsNetworkAvailable])
  6854. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6855. ////
  6856. //// json=[self get_json:URL_COMMIT_ORDER parameters:params];
  6857. //// }
  6858. //// if(json!=nil)
  6859. //// {
  6860. //// NSError *error=nil;
  6861. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6862. //// return jsobj;
  6863. //// }
  6864. //// else
  6865. //// return nil;
  6866. //
  6867. //}
  6868. +(void)request_copy_order:(NSString*) order_code completionHandler:(resultHandler)result
  6869. {
  6870. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6871. AppDelegate *appDelegate = nil;
  6872. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6873. if(appDelegate.user!=nil)
  6874. [params setValue:appDelegate.user forKey:@"user"];
  6875. if(appDelegate.contact_id!=nil)
  6876. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6877. if(appDelegate.password!=nil)
  6878. [params setValue:appDelegate.password forKey:@"password"];
  6879. // NSString* ssaved = @"false";
  6880. // if(saved)
  6881. // ssaved=@"true";
  6882. // [params setValue:@"true" forKey:@"saved"];
  6883. [params setValue:order_code forKey:@"code"];
  6884. // [params setValue:sourceid forKey:@"sourceid"];
  6885. // [params setValue:editor forKey:@"editor"];
  6886. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  6887. if(appDelegate.offline_mode)
  6888. {
  6889. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6890. NSData* json = [[OLDataProvider offline_copyorder:params] mutableCopy];
  6891. dispatch_async(dispatch_get_main_queue(), ^{
  6892. result([[RAConvertor data2dict:json] mutableCopy]);
  6893. });
  6894. });
  6895. return;
  6896. }
  6897. [self request_interface:URL_COPY_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6898. // NSData* json=nil;
  6899. // if(appDelegate.offline_mode)
  6900. // {
  6901. // json= [OLDataProvider offline_copyorder:params];
  6902. // }
  6903. // else
  6904. // {
  6905. // if(![self IsNetworkAvailable])
  6906. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6907. //
  6908. // json=[self get_json:URL_COPY_ORDER parameters:params];
  6909. // }
  6910. // if(json!=nil)
  6911. // {
  6912. // NSError *error=nil;
  6913. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6914. // return jsobj;
  6915. // }
  6916. // else
  6917. // return nil;
  6918. }
  6919. //
  6920. //+ (void)request_fastdownload:(NSMutableDictionary *)params url:(NSString *)url completionHandler:(resultHandler)result
  6921. //{
  6922. //
  6923. // //#ifdef test_server
  6924. // // url=URL_REQUEST_RECORDS;
  6925. // // params[@"prefix"]=URL_REQUEST_RECORDS;
  6926. // //#endif
  6927. //
  6928. // [self request_file_fast:url parameters:params completionHandler:result];
  6929. //
  6930. //}
  6931. +(void) request_addto_portfolio:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6932. {
  6933. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6934. AppDelegate *appDelegate = nil;
  6935. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6936. if(appDelegate.user!=nil)
  6937. [params setValue:appDelegate.user forKey:@"user"];
  6938. if(appDelegate.contact_id!=nil)
  6939. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6940. if(appDelegate.password!=nil)
  6941. [params setValue:appDelegate.password forKey:@"password"];
  6942. [params setValue:item_id forKey:@"product_id"];
  6943. [params setObject:screenName forKey:kScreenName];
  6944. if(appDelegate.offline_mode)
  6945. {
  6946. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6947. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_add2Portfolio:params]] mutableCopy];
  6948. dispatch_async(dispatch_get_main_queue(), ^{
  6949. int result_code = [[resulti valueForKey:@"result"] intValue];
  6950. if (result_code==2)
  6951. {
  6952. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6953. [appDelegate update_count_mark];
  6954. }
  6955. result(resulti);
  6956. });
  6957. });
  6958. return;
  6959. }
  6960. [self request_interface:URL_ADD_TO_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6961. int result_code = [[resulti valueForKey:@"result"] intValue];
  6962. if (result_code==2)
  6963. {
  6964. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6965. [appDelegate update_count_mark];
  6966. }
  6967. result(resulti);
  6968. } retry:0];
  6969. //
  6970. // NSData* json = nil;
  6971. // if(appDelegate.offline_mode)
  6972. // {
  6973. // json = [OLDataProvider offline_add2Portfolio:params];
  6974. // } else {
  6975. // if(![self IsNetworkAvailable])
  6976. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6977. //
  6978. // json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  6979. // }
  6980. //
  6981. // if(json==nil)
  6982. // return nil;
  6983. // NSError *error=nil;
  6984. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6985. // int result = [[jsobj valueForKey:@"result"] intValue];
  6986. //
  6987. // if (result==2)
  6988. // {
  6989. //
  6990. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6991. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6992. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6993. //
  6994. // [appDelegate update_count_mark];
  6995. // }
  6996. // return jsobj;
  6997. }
  6998. +(void)request_addall_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  6999. {
  7000. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7001. AppDelegate *appDelegate = nil;
  7002. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7003. if(appDelegate.user!=nil)
  7004. [params setValue:appDelegate.user forKey:@"user"];
  7005. if(appDelegate.contact_id!=nil)
  7006. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7007. if(appDelegate.password!=nil)
  7008. [params setValue:appDelegate.password forKey:@"password"];
  7009. if(appDelegate.order_code!=nil)
  7010. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7011. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7012. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7013. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  7014. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7015. // [params setValue:filter forKey:@"filter"];
  7016. [params setValue:keywords forKey:@"keyword"];
  7017. [params setValue:addTo forKey:@"addTo"];
  7018. [params setValue:orderCode forKey:@"orderCode"];
  7019. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7020. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7021. if(matchfull)
  7022. [params setValue:@"true" forKey:@"exactMatch"];
  7023. else
  7024. [params setValue:@"false" forKey:@"exactMatch"];
  7025. [params setObject:ScreenCodeSearch forKey:kScreenName];
  7026. if ([addTo isEqualToString:@"cart"]) {
  7027. [params setObject:@"Add To Cart" forKey:kAction];
  7028. }
  7029. if(appDelegate.offline_mode)
  7030. {
  7031. if ([addTo isEqualToString:@"cart"])
  7032. {
  7033. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7034. }
  7035. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7036. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_searchaddall:params]] mutableCopy];
  7037. dispatch_async(dispatch_get_main_queue(), ^{
  7038. int result_code =[json[@"result"] intValue];
  7039. if (result_code==2||result_code==8)
  7040. {
  7041. if(json[@"cart_count"])
  7042. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7043. if(json[@"wish_count"])
  7044. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7045. if(json[@"portfolio_count"])
  7046. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7047. //
  7048. //
  7049. [appDelegate update_count_mark];
  7050. }
  7051. result(json);
  7052. });
  7053. });
  7054. return;
  7055. }
  7056. NSString * uuid= [[NSUUID UUID] UUIDString];
  7057. params[@"resultSerial"]=uuid;
  7058. __block bool bbreak = false;
  7059. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7060. for(int i=0;i<150;i++)
  7061. {
  7062. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7063. // result_params[@"resultSerial"]=uuid;
  7064. if(bbreak)
  7065. break;
  7066. dispatch_async(dispatch_get_main_queue(), ^{
  7067. [self request_interface:URL_SEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7068. if([resulti[@"result"] intValue]==2)
  7069. {
  7070. if(!bbreak)//此判断保证result只调用一次。
  7071. result(resulti);
  7072. bbreak=true;
  7073. }
  7074. } retry:3];
  7075. });
  7076. sleep(2);
  7077. }
  7078. });
  7079. //
  7080. //
  7081. // NSData* json=nil;
  7082. // if(appDelegate.offline_mode)
  7083. // {
  7084. // json=[OLDataProvider offline_searchaddall:params];
  7085. // }
  7086. // else
  7087. // {
  7088. // if(![self IsNetworkAvailable])
  7089. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7090. //
  7091. // NSError *error=nil;
  7092. //
  7093. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7094. // params[@"resultSerial"]=uuid;
  7095. //
  7096. // for(int i=0;i<150;i++)
  7097. // {
  7098. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7099. // // result_params[@"resultSerial"]=uuid;
  7100. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  7101. // if(json!=nil)
  7102. // {
  7103. //
  7104. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7105. // if([jsobj[@"result"] intValue]==2)
  7106. // {
  7107. // break;
  7108. // }
  7109. // }
  7110. // sleep(2);
  7111. // }
  7112. // }
  7113. // if(json==nil)
  7114. // return nil;
  7115. // NSError *error=nil;
  7116. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7117. // return jsobj;
  7118. }
  7119. +(void) request_addto_cart_byupc:(NSString* ) upc_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  7120. {
  7121. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7122. AppDelegate *appDelegate = nil;
  7123. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7124. if(appDelegate.user!=nil)
  7125. [params setValue:appDelegate.user forKey:@"user"];
  7126. if(appDelegate.contact_id!=nil)
  7127. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7128. if(appDelegate.password!=nil)
  7129. [params setValue:appDelegate.password forKey:@"password"];
  7130. if(appDelegate.order_code!=nil)
  7131. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7132. [params setValue:upc_code forKey:@"upc_code"];
  7133. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  7134. [params setObject:screenName forKey:kScreenName];
  7135. [params setObject:@"Add To Cart" forKey:kAction];
  7136. if (!upc_code) {
  7137. upc_code = @"";
  7138. }
  7139. [params setObject:@{@"UPCCode" : upc_code} forKey:kExtra];
  7140. params[@"search_upc"]=@true;
  7141. NSDictionary* customerinfo= appDelegate.customerInfo;
  7142. NSArray* keys=[customerinfo allKeys];
  7143. for(int i=0;i<keys.count;i++)
  7144. {
  7145. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7146. }
  7147. if(appDelegate.offline_mode)
  7148. {
  7149. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7150. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  7151. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7152. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyupc:params]] mutableCopy];
  7153. dispatch_async(dispatch_get_main_queue(), ^{
  7154. int result_code = [[json valueForKey:@"result"] intValue];
  7155. if (result_code==2||result_code==8)
  7156. {
  7157. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7158. [appDelegate update_count_mark];
  7159. }
  7160. result(json);
  7161. });
  7162. });
  7163. return;
  7164. }
  7165. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7166. int result_code = [[resulti valueForKey:@"result"] intValue];
  7167. if (result_code==2||result_code==8)
  7168. {
  7169. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7170. [appDelegate update_count_mark];
  7171. }
  7172. result(resulti);
  7173. } retry:0];
  7174. }
  7175. +(void) request_addto_cart_byname:(NSString* ) model_name withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  7176. {
  7177. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7178. AppDelegate *appDelegate = nil;
  7179. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7180. if(appDelegate.user!=nil)
  7181. [params setValue:appDelegate.user forKey:@"user"];
  7182. if(appDelegate.contact_id!=nil)
  7183. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7184. if(appDelegate.password!=nil)
  7185. [params setValue:appDelegate.password forKey:@"password"];
  7186. if(appDelegate.order_code!=nil)
  7187. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7188. [params setValue:model_name forKey:@"product_name"];
  7189. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  7190. [params setObject:screenName forKey:kScreenName];
  7191. [params setObject:@"Add To Cart" forKey:kAction];
  7192. if (!model_name) {
  7193. model_name = @"";
  7194. }
  7195. [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  7196. NSDictionary* customerinfo= appDelegate.customerInfo;
  7197. NSArray* keys=[customerinfo allKeys];
  7198. for(int i=0;i<keys.count;i++)
  7199. {
  7200. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7201. }
  7202. if(appDelegate.offline_mode)
  7203. {
  7204. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7205. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  7206. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7207. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyname:params]] mutableCopy];
  7208. dispatch_async(dispatch_get_main_queue(), ^{
  7209. int result_code = [[json valueForKey:@"result"] intValue];
  7210. if (result_code==2||result_code==8)
  7211. {
  7212. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7213. [appDelegate update_count_mark];
  7214. }
  7215. result(json);
  7216. });
  7217. });
  7218. return;
  7219. }
  7220. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7221. int result_code = [[resulti valueForKey:@"result"] intValue];
  7222. if (result_code==2||result_code==8)
  7223. {
  7224. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7225. [appDelegate update_count_mark];
  7226. }
  7227. result(resulti);
  7228. } retry:0];
  7229. // NSData* json=nil;
  7230. // if(appDelegate.offline_mode)
  7231. // {
  7232. // json= [OLDataProvider offline_add2cartbyname:params];
  7233. // }
  7234. // else
  7235. // {
  7236. // if(![self IsNetworkAvailable])
  7237. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7238. //
  7239. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  7240. // }
  7241. // if(json==nil)
  7242. // return nil;
  7243. // NSError *error=nil;
  7244. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7245. //
  7246. //
  7247. //
  7248. // int result = [[jsobj valueForKey:@"result"] intValue];
  7249. //
  7250. // if (result==2||result==8)
  7251. // {
  7252. //
  7253. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  7254. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  7255. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  7256. //
  7257. // [appDelegate update_count_mark];
  7258. // }
  7259. //
  7260. // return jsobj;
  7261. }
  7262. +(void) request_addto_wishlist:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  7263. {
  7264. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7265. AppDelegate *appDelegate = nil;
  7266. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7267. if(appDelegate.user!=nil)
  7268. [params setValue:appDelegate.user forKey:@"user"];
  7269. if(appDelegate.contact_id!=nil)
  7270. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7271. if(appDelegate.password!=nil)
  7272. [params setValue:appDelegate.password forKey:@"password"];
  7273. [params setValue:item_id forKey:@"product_id"];
  7274. [params setObject:screenName forKey:kScreenName];
  7275. if(appDelegate.offline_mode)
  7276. {
  7277. // [OLDataProvider offline_add2wishlist:params completionHandler:result];
  7278. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7279. NSMutableDictionary* resulti = [[OLDataProvider offline_add2wishlist:params] mutableCopy];
  7280. dispatch_async(dispatch_get_main_queue(), ^{
  7281. int result_code = [[resulti valueForKey:@"result"] intValue];
  7282. if (result_code==2||result_code==8)
  7283. {
  7284. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7285. [appDelegate update_count_mark];
  7286. }
  7287. result(resulti);
  7288. });
  7289. });
  7290. return;
  7291. }
  7292. [self request_interface:URL_ADD_TO_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7293. int result_code = [[resulti valueForKey:@"result"] intValue];
  7294. if (result_code==2||result_code==8)
  7295. {
  7296. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7297. [appDelegate update_count_mark];
  7298. }
  7299. result(resulti);
  7300. } retry:0];
  7301. // if(appDelegate.offline_mode)
  7302. // {
  7303. // return [OLDataProvider offline_add2wishlist:params];
  7304. // }
  7305. // if(![self IsNetworkAvailable])
  7306. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7307. //
  7308. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  7309. // if(json==nil)
  7310. // return nil;
  7311. // NSError *error=nil;
  7312. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7313. // int result = [[jsobj valueForKey:@"result"] intValue];
  7314. //
  7315. // if (result==2)
  7316. // {
  7317. //
  7318. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  7319. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  7320. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  7321. //
  7322. // [appDelegate update_count_mark];
  7323. // }
  7324. // return jsobj;
  7325. }
  7326. +(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
  7327. {
  7328. // for debug
  7329. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  7330. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7331. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7332. AppDelegate *appDelegate = nil;
  7333. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7334. if(appDelegate.user!=nil)
  7335. [params setValue:appDelegate.user forKey:@"user"];
  7336. if(appDelegate.contact_id!=nil)
  7337. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7338. if(appDelegate.password!=nil)
  7339. [params setValue:appDelegate.password forKey:@"password"];
  7340. if(appDelegate.order_code!=nil)
  7341. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7342. [params setValue:addTo forKey:@"addTo"];
  7343. [params setValue:orderCode forKey:@"orderCode"];
  7344. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7345. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7346. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  7347. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7348. // [params setValue:filter forKey:@"filter"];
  7349. [params setValue:covertype forKey:@"covertype"];
  7350. [params setValue:ctgid forKey:@"ctgId"];
  7351. [params setValue:modelname forKey:@"modelName"];
  7352. [params setValue:modeldescrip forKey:@"modelDescription"];
  7353. [params setValue:alert forKey:@"alert"];
  7354. [params setValue:qty forKey:@"sold_by_qty"];
  7355. [params setValue:available forKey:@"available"];
  7356. [params setValue:price forKey:@"price"];
  7357. [params setValue:bestseller forKey:@"bestseller"];
  7358. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7359. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7360. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  7361. if ([addTo isEqualToString:@"cart"]) {
  7362. [params setObject:@"Add To Cart" forKey:kAction];
  7363. }
  7364. if(appDelegate.offline_mode)
  7365. {
  7366. if ([addTo isEqualToString:@"cart"])
  7367. {
  7368. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7369. }
  7370. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7371. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_itemsearchaddall:params]] mutableCopy];
  7372. dispatch_async(dispatch_get_main_queue(), ^{
  7373. int result_code =[json[@"result"] intValue];
  7374. if (result_code==2||result_code==8)
  7375. {
  7376. if(json[@"cart_count"])
  7377. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7378. if(json[@"wish_count"])
  7379. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7380. if(json[@"portfolio_count"])
  7381. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7382. //
  7383. //
  7384. [appDelegate update_count_mark];
  7385. }
  7386. result(json);
  7387. });
  7388. });
  7389. return;
  7390. }
  7391. NSString * uuid= [[NSUUID UUID] UUIDString];
  7392. params[@"resultSerial"]=uuid;
  7393. __block bool bbreak = false;
  7394. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7395. for(int i=0;i<150;i++)
  7396. {
  7397. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7398. // result_params[@"resultSerial"]=uuid;
  7399. if(bbreak)
  7400. break;
  7401. dispatch_async(dispatch_get_main_queue(), ^{
  7402. [self request_interface:URL_ITEMSEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7403. if([resulti[@"result"] intValue]==2)
  7404. {
  7405. if(!bbreak)//此判断保证result只调用一次。
  7406. result(resulti);
  7407. bbreak=true;
  7408. }
  7409. } retry:3];
  7410. });
  7411. sleep(2);
  7412. }
  7413. });
  7414. //
  7415. // NSData* json = nil;
  7416. //
  7417. // if(appDelegate.offline_mode)
  7418. // {
  7419. // json= [OLDataProvider offline_itemsearchaddall:params];
  7420. // }
  7421. // else
  7422. // {
  7423. // if(![self IsNetworkAvailable])
  7424. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7425. // NSError *error=nil;
  7426. //
  7427. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7428. // params[@"resultSerial"]=uuid;
  7429. //
  7430. // for(int i=0;i<150;i++)
  7431. // {
  7432. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7433. // // result_params[@"resultSerial"]=uuid;
  7434. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  7435. // if(json!=nil)
  7436. // {
  7437. //
  7438. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7439. // if([jsobj[@"result"] intValue]==2)
  7440. // {
  7441. // break;
  7442. // }
  7443. // }
  7444. // sleep(2);
  7445. // }
  7446. // }
  7447. // if(json==nil)
  7448. // return nil;
  7449. // NSError *error=nil;
  7450. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7451. // return jsobj;
  7452. }
  7453. +(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
  7454. {
  7455. AppDelegate *appDelegate = nil;
  7456. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7457. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7458. if(appDelegate.user!=nil)
  7459. [params setValue:appDelegate.user forKey:@"user"];
  7460. if(appDelegate.contact_id!=nil)
  7461. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7462. if(appDelegate.password!=nil)
  7463. [params setValue:appDelegate.password forKey:@"password"];
  7464. if(appDelegate.order_code!=nil)
  7465. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7466. [params setValue:addTo forKey:@"addTo"];
  7467. [params setValue:orderCode forKey:@"orderCode"];
  7468. [params setValue:alert forKey:@"alert"];
  7469. [params setValue:qty forKey:@"sold_by_qty"];
  7470. [params setValue:available forKey:@"available"];
  7471. [params setValue:price forKey:@"price"];
  7472. [params setValue:bestseller forKey:@"bestseller"];
  7473. [params setValue:modelname forKey:@"modelName"];
  7474. [params setValue:modeldescrip forKey:@"modelDescription"];
  7475. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7476. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7477. [params setValue:category forKey:@"category"];
  7478. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7479. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7480. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7481. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7482. [params setValue:filter forKey:@"filter"];
  7483. [params setValue:keyword forKey:@"keyword"];
  7484. [params setObject:ScreenCodeCategory forKey:kScreenName];
  7485. if ([addTo isEqualToString:@"cart"]) {
  7486. [params setObject:@"Add To Cart" forKey:kAction];
  7487. }
  7488. if(appDelegate.offline_mode)
  7489. {
  7490. if ([addTo isEqualToString:@"cart"])
  7491. {
  7492. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7493. }
  7494. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7495. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_categoryaddall:params]] mutableCopy];
  7496. dispatch_async(dispatch_get_main_queue(), ^{
  7497. int result_code =[json[@"result"] intValue];
  7498. if (result_code==2||result_code==8)
  7499. {
  7500. if(json[@"cart_count"])
  7501. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7502. if(json[@"wish_count"])
  7503. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7504. if(json[@"portfolio_count"])
  7505. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7506. //
  7507. //
  7508. [appDelegate update_count_mark];
  7509. }
  7510. result(json);
  7511. });
  7512. });
  7513. return;
  7514. }
  7515. NSString * uuid= [[NSUUID UUID] UUIDString];
  7516. params[@"resultSerial"]=uuid;
  7517. __block bool bbreak = false;
  7518. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7519. for(int i=0;i<150;i++)
  7520. {
  7521. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7522. // result_params[@"resultSerial"]=uuid;
  7523. if(bbreak)
  7524. break;
  7525. dispatch_async(dispatch_get_main_queue(), ^{
  7526. [self request_interface:URL_CATEGORYADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7527. if([resulti[@"result"] intValue]==2|| [resulti[@"result"] intValue] == 8)
  7528. {
  7529. if(!bbreak)//此判断保证result只调用一次。
  7530. {
  7531. int result_code =[resulti[@"result"] intValue];
  7532. if (result_code==2||result_code==8)
  7533. {
  7534. if(resulti[@"cart_count"])
  7535. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7536. if(resulti[@"wish_count"])
  7537. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7538. if(resulti[@"portfolio_count"])
  7539. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  7540. //
  7541. //
  7542. [appDelegate update_count_mark];
  7543. }
  7544. result(resulti);
  7545. }
  7546. bbreak=true;
  7547. }
  7548. } retry:3];
  7549. });
  7550. sleep(2);
  7551. }
  7552. });
  7553. //
  7554. // NSData* json= nil;
  7555. //
  7556. // if(appDelegate.offline_mode)
  7557. // {
  7558. // json= [OLDataProvider offline_categoryaddall:params];
  7559. // }
  7560. // else
  7561. // {
  7562. // if(![self IsNetworkAvailable])
  7563. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7564. //
  7565. //
  7566. // NSError *error=nil;
  7567. //
  7568. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7569. // params[@"resultSerial"]=uuid;
  7570. //
  7571. // for(int i=0;i<150;i++)
  7572. // {
  7573. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7574. //// result_params[@"resultSerial"]=uuid;
  7575. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  7576. // if(json!=nil)
  7577. // {
  7578. //
  7579. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7580. // int resultInt = [jsobj[@"result"] intValue];
  7581. // if(resultInt == 2 || resultInt == 8)
  7582. // {
  7583. // break;
  7584. // }
  7585. // }
  7586. // sleep(2);
  7587. // }
  7588. //
  7589. //
  7590. //
  7591. // }
  7592. // if(json==nil)
  7593. // return nil;
  7594. // NSError *error=nil;
  7595. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7596. // return jsobj;
  7597. }
  7598. +(void)request_save_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7599. {
  7600. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7601. AppDelegate *appDelegate = nil;
  7602. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7603. if(appDelegate.user!=nil)
  7604. [params setValue:appDelegate.user forKey:@"user"];
  7605. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  7606. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7607. // else
  7608. if(appDelegate.contact_id!=nil)
  7609. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7610. if(appDelegate.password!=nil)
  7611. [params setValue:appDelegate.password forKey:@"password"];
  7612. if(appDelegate.order_code!=nil)
  7613. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7614. // NSDictionary* customerinfo=nil;
  7615. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  7616. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7617. // else
  7618. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7619. //
  7620. // appDelegate.customerInfo;
  7621. // NSArray* keys=[customerinfo allKeys];
  7622. // for(int i=0;i<keys.count;i++)
  7623. // {
  7624. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7625. // }
  7626. // [params setValue:sourceid forKey:@"sourceid"];
  7627. // [params setValue:editor forKey:@"editor"];
  7628. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  7629. if(appDelegate.offline_mode)
  7630. {
  7631. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7632. NSData* json = [[OLDataProvider offline_saveorder:params] mutableCopy];
  7633. dispatch_async(dispatch_get_main_queue(), ^{
  7634. result([[RAConvertor data2dict:json] mutableCopy]);
  7635. });
  7636. });
  7637. return;
  7638. }
  7639. [self request_interface:URL_SAVE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  7640. //
  7641. // NSData* json=nil;
  7642. //
  7643. // if(appDelegate.offline_mode)
  7644. // {
  7645. // json= [OLDataProvider offline_saveorder:params];
  7646. // }
  7647. // else
  7648. // {
  7649. // if(![self IsNetworkAvailable])
  7650. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7651. //
  7652. // json=[self get_json:URL_SAVE_ORDER parameters:params];
  7653. // }
  7654. // if(json!=nil)
  7655. // {
  7656. // NSError *error=nil;
  7657. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7658. // NSString *so = [jsobj valueForKey:@"so#"];
  7659. // if (so) {
  7660. // [appDelegate SetSo:so];
  7661. // }
  7662. // return jsobj;
  7663. // }
  7664. // else
  7665. // return nil;
  7666. }
  7667. +(void) request_update_cartqty:(NSString*) cart_id value:(int) value completionHandler:(resultHandler)result
  7668. {
  7669. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7670. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  7671. #ifdef SCANNER_ORDER
  7672. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7673. {
  7674. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7675. //
  7676. //
  7677. // [appDelegate update_count_mark];
  7678. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7679. int count = [section[@"count"] intValue];
  7680. for(int i=0;i<count;i++)
  7681. {
  7682. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7683. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7684. {
  7685. item[@"count"] =@(value);
  7686. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7687. break;
  7688. }
  7689. }
  7690. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7691. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7692. result(RASingleton.sharedInstance.scan_cart);
  7693. [OLDataProvider updateScanOrder:appDelegate.order_code];
  7694. return;
  7695. }
  7696. #endif
  7697. if(appDelegate.user!=nil)
  7698. [params setValue:appDelegate.user forKey:@"user"];
  7699. if(appDelegate.contact_id!=nil)
  7700. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7701. if(appDelegate.password!=nil)
  7702. [params setValue:appDelegate.password forKey:@"password"];
  7703. [params setValue:cart_id forKey:@"cartitem_id"];
  7704. [params setObject:ScreenCodeCart forKey:kScreenName];
  7705. [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  7706. if(appDelegate.offline_mode)
  7707. {
  7708. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7709. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7710. NSData* json = [[OLDataProvider offline_cartsetqty:params] mutableCopy];
  7711. dispatch_async(dispatch_get_main_queue(), ^{
  7712. result([[RAConvertor data2dict:json] mutableCopy]);
  7713. });
  7714. });
  7715. return;
  7716. }
  7717. [self request_interface:URL_CART_INCRESEMENT parameters:params err_record_url:nil completionHandler:result retry:0];
  7718. //
  7719. // NSData* json=nil;
  7720. // if(appDelegate.offline_mode)
  7721. // {
  7722. // json= [OLDataProvider offline_cartsetqty:params];
  7723. // }
  7724. // else
  7725. // {
  7726. // if(![self IsNetworkAvailable])
  7727. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7728. //
  7729. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  7730. // }
  7731. // if(json==nil)
  7732. // return nil;
  7733. // NSError *error=nil;
  7734. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7735. // return jsobj;
  7736. }
  7737. +(void) request_update_cartgeneralnote:(NSString*) order_code notes:(NSString*) notes completionHandler:(resultHandler)result
  7738. {
  7739. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7740. AppDelegate *appDelegate = nil;
  7741. #ifdef SCANNER_ORDER
  7742. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7743. {
  7744. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7745. //
  7746. //
  7747. // [appDelegate update_count_mark];
  7748. RASingleton.sharedInstance.scan_cart[@"general_note"] = notes;
  7749. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7750. result(RASingleton.sharedInstance.scan_cart);
  7751. return;
  7752. }
  7753. #endif
  7754. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7755. if(appDelegate.user!=nil)
  7756. [params setValue:appDelegate.user forKey:@"user"];
  7757. if(appDelegate.contact_id!=nil)
  7758. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7759. if(appDelegate.password!=nil)
  7760. [params setValue:appDelegate.password forKey:@"password"];
  7761. [params setValue:order_code forKey:@"orderCode"];
  7762. [params setObject:ScreenCodeCart forKey:kScreenName];
  7763. if(notes.length==0)
  7764. notes=@"";
  7765. [params setValue:notes forKey:@"comments"];
  7766. if(appDelegate.offline_mode)
  7767. {
  7768. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7769. NSData* json = [[OLDataProvider offline_updategnotes:params] mutableCopy];
  7770. dispatch_async(dispatch_get_main_queue(), ^{
  7771. result([[RAConvertor data2dict:json] mutableCopy]);
  7772. });
  7773. });
  7774. return;
  7775. }
  7776. [self request_interface:URL_CART_GENERAL_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7777. //
  7778. // NSData* json=nil;
  7779. // if(appDelegate.offline_mode)
  7780. // {
  7781. // json= [OLDataProvider offline_updategnotes:params];
  7782. // }
  7783. // else
  7784. // {
  7785. // if(![self IsNetworkAvailable])
  7786. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7787. //
  7788. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  7789. // }
  7790. // if(json==nil)
  7791. // return nil;
  7792. // NSError *error=nil;
  7793. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7794. // return jsobj;
  7795. }
  7796. +(void) request_update_cartitemnote:(NSString*) cart_id notes:(NSString*) notes completionHandler:(resultHandler)result
  7797. {
  7798. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7799. AppDelegate *appDelegate = nil;
  7800. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7801. #ifdef SCANNER_ORDER
  7802. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7803. {
  7804. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7805. //
  7806. //
  7807. // [appDelegate update_count_mark];
  7808. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7809. int count = [section[@"count"] intValue];
  7810. for(int i=0;i<count;i++)
  7811. {
  7812. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7813. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7814. {
  7815. item[@"note"] =notes;
  7816. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7817. break;
  7818. }
  7819. }
  7820. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7821. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7822. result(RASingleton.sharedInstance.scan_cart);
  7823. return;
  7824. }
  7825. #endif
  7826. if(appDelegate.user!=nil)
  7827. [params setValue:appDelegate.user forKey:@"user"];
  7828. if(appDelegate.contact_id!=nil)
  7829. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7830. if(appDelegate.password!=nil)
  7831. [params setValue:appDelegate.password forKey:@"password"];
  7832. [params setValue:cart_id forKey:@"cartitem_id"];
  7833. [params setObject:ScreenCodeCart forKey:kScreenName];
  7834. if(notes.length==0)
  7835. notes=@"";
  7836. [params setValue:notes forKey:@"notes"];
  7837. if(appDelegate.offline_mode)
  7838. {
  7839. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7840. NSData* json = [[OLDataProvider offline_cartsetlnotes:params] mutableCopy];
  7841. dispatch_async(dispatch_get_main_queue(), ^{
  7842. result([[RAConvertor data2dict:json] mutableCopy]);
  7843. });
  7844. });
  7845. return;
  7846. }
  7847. [self request_interface:URL_CART_ITEM_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7848. //
  7849. // NSData* json=nil;
  7850. // if(appDelegate.offline_mode)
  7851. // {
  7852. // json= [OLDataProvider offline_cartsetlnotes:params];
  7853. // }
  7854. // else
  7855. // {
  7856. // if(![self IsNetworkAvailable])
  7857. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7858. //
  7859. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  7860. // }
  7861. // if(json==nil)
  7862. // return nil;
  7863. // NSError *error=nil;
  7864. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7865. // return jsobj;
  7866. }
  7867. + (void)request_update_npd_shop_price_type:(NSInteger)priceType completionHandler:(resultHandler)result
  7868. {
  7869. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7870. AppDelegate *appDelegate = nil;
  7871. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7872. if(appDelegate.user!=nil)
  7873. [dic setValue:appDelegate.user forKey:@"user"];
  7874. if(appDelegate.password!=nil)
  7875. [dic setValue:appDelegate.password forKey:@"password"];
  7876. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  7877. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  7878. if(appDelegate.offline_mode)
  7879. {
  7880. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7881. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7882. dispatch_async(dispatch_get_main_queue(), ^{
  7883. result(json);
  7884. });
  7885. });
  7886. return;
  7887. }
  7888. [self request_interface:URL_SET_PRICE_TYPE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7889. //
  7890. // NSData* json=nil;
  7891. // if(appDelegate.offline_mode)
  7892. // {
  7893. // return [OLDataProvider offline_notimpl];
  7894. // }
  7895. // else
  7896. // {
  7897. // if(![self IsNetworkAvailable])
  7898. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7899. //
  7900. // json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  7901. // }
  7902. // if(json!=nil)
  7903. // {
  7904. // NSError *error=nil;
  7905. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7906. //
  7907. //
  7908. // return jsobj;
  7909. // }
  7910. //
  7911. //
  7912. // return nil;
  7913. }
  7914. + (void)request_npd_shop_givenprice:(resultHandler)result
  7915. {
  7916. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7917. AppDelegate *appDelegate = nil;
  7918. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7919. if(appDelegate.user!=nil)
  7920. [dic setValue:appDelegate.user forKey:@"user"];
  7921. if(appDelegate.password!=nil)
  7922. [dic setValue:appDelegate.password forKey:@"password"];
  7923. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  7924. if(appDelegate.offline_mode)
  7925. {
  7926. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7927. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7928. dispatch_async(dispatch_get_main_queue(), ^{
  7929. result(json);
  7930. });
  7931. });
  7932. return;
  7933. }
  7934. [self request_interface:URL_GET_CIVEN_PRICE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7935. //
  7936. // NSData* json=nil;
  7937. // if(appDelegate.offline_mode)
  7938. // {
  7939. // return [OLDataProvider offline_notimpl];
  7940. // }
  7941. // else
  7942. // {
  7943. // if(![self IsNetworkAvailable])
  7944. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7945. //
  7946. // json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  7947. // }
  7948. // if(json!=nil)
  7949. // {
  7950. // NSError *error=nil;
  7951. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7952. //
  7953. //
  7954. // return jsobj;
  7955. // }
  7956. //
  7957. //
  7958. // return nil;
  7959. }
  7960. + (void)request_update_npd_shop_givenprice:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  7961. {
  7962. AppDelegate *appDelegate = nil;
  7963. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7964. if(appDelegate.user!=nil)
  7965. [params setValue:appDelegate.user forKey:@"user"];
  7966. if(appDelegate.password!=nil)
  7967. [params setValue:appDelegate.password forKey:@"password"];
  7968. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  7969. if(appDelegate.offline_mode)
  7970. {
  7971. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7972. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7973. dispatch_async(dispatch_get_main_queue(), ^{
  7974. result(json);
  7975. });
  7976. });
  7977. return;
  7978. }
  7979. [self request_interface:URL_SET_GIVEN_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  7980. //
  7981. // NSData* json=nil;
  7982. // if(appDelegate.offline_mode)
  7983. // {
  7984. // return [OLDataProvider offline_notimpl];
  7985. // }
  7986. // else
  7987. // {
  7988. // if(![self IsNetworkAvailable])
  7989. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7990. //
  7991. // json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  7992. // }
  7993. // if(json!=nil)
  7994. // {
  7995. // NSError *error=nil;
  7996. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7997. //
  7998. //
  7999. // return jsobj;
  8000. // }
  8001. //
  8002. //
  8003. // return nil;
  8004. }
  8005. +(void) request_create_portfolio:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8006. {
  8007. AppDelegate *appDelegate = nil;
  8008. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8009. if(appDelegate.offline_mode)
  8010. {
  8011. params[@"contact_id"]=params[@"contactId"];
  8012. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8013. NSData* json = [[OLDataProvider offline_direct_save_TearSheet:params] mutableCopy];
  8014. dispatch_async(dispatch_get_main_queue(), ^{
  8015. result([[RAConvertor data2dict:json] mutableCopy]);
  8016. });
  8017. });
  8018. return;
  8019. }
  8020. //
  8021. // if(appDelegate.offline_mode)
  8022. // {
  8023. //
  8024. //
  8025. // NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  8026. // if(json==nil)
  8027. // return nil;
  8028. // NSError *error=nil;
  8029. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8030. //
  8031. // return jsobj[@"pdf_path"];
  8032. // }
  8033. // else
  8034. // {
  8035. // return nil;
  8036. // }
  8037. }
  8038. +(void)request_save_portfoliodirectly:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8039. {
  8040. NSMutableDictionary* off_params = [params mutableCopy];
  8041. AppDelegate *appDelegate = nil;
  8042. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8043. if(appDelegate.user!=nil)
  8044. [params setValue:appDelegate.user forKey:@"user"];
  8045. if(appDelegate.contact_id!=nil)
  8046. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8047. if(appDelegate.password!=nil)
  8048. params[@"off_params"]=[RAConvertor dict2string:off_params];
  8049. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  8050. [params setValue:appDelegate.password forKey:@"password"];
  8051. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  8052. if(appDelegate.offline_mode)
  8053. {
  8054. params[@"contact_id"]=appDelegate.contact_id;
  8055. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8056. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_direct_save_TearSheet:params]] mutableCopy];
  8057. dispatch_async(dispatch_get_main_queue(), ^{
  8058. result(json);
  8059. });
  8060. });
  8061. return;
  8062. }
  8063. NSString * uuid= [[NSUUID UUID] UUIDString];
  8064. params[@"resultSerial"]=uuid;
  8065. __block bool bbreak = false;
  8066. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8067. for(int i=0;i<150;i++)
  8068. {
  8069. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8070. // result_params[@"resultSerial"]=uuid;
  8071. if(bbreak)
  8072. break;
  8073. dispatch_async(dispatch_get_main_queue(), ^{
  8074. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8075. if([resulti[@"result"] intValue]==2)
  8076. {
  8077. if(!bbreak)//此判断保证result只调用一次。
  8078. result(resulti);
  8079. bbreak=true;
  8080. }
  8081. } retry:3];
  8082. });
  8083. sleep(2);
  8084. }
  8085. });
  8086. //
  8087. //
  8088. // NSData* json= nil;
  8089. //
  8090. // if(appDelegate.offline_mode)
  8091. // {
  8092. // json = [OLDataProvider offline_direct_save_TearSheet:params];
  8093. // }
  8094. // else
  8095. // {
  8096. // if(![self IsNetworkAvailable])
  8097. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8098. //
  8099. // json=[self get_json:URL_REQUEST_DM parameters:params];
  8100. //
  8101. // NSError *error=nil;
  8102. //
  8103. // NSString * uuid= [[NSUUID UUID] UUIDString];
  8104. // params[@"resultSerial"]=uuid;
  8105. //
  8106. // for(int i=0;i<150;i++)
  8107. // {
  8108. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8109. // // result_params[@"resultSerial"]=uuid;
  8110. // json=[self get_json:URL_REQUEST_DM parameters:params];
  8111. // if(json!=nil)
  8112. // {
  8113. //
  8114. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8115. // if([jsobj[@"result"] intValue]==2)
  8116. // {
  8117. // break;
  8118. // }
  8119. // }
  8120. // sleep(5);
  8121. // }
  8122. //
  8123. // }
  8124. // if(json==nil)
  8125. // return nil;
  8126. // NSError *error=nil;
  8127. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8128. // return jsobj;
  8129. }
  8130. +(void)request_save_portfolio:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  8131. {
  8132. AppDelegate *appDelegate = nil;
  8133. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8134. if(appDelegate.user!=nil)
  8135. [params setValue:appDelegate.user forKey:@"user"];
  8136. if(appDelegate.contact_id!=nil)
  8137. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8138. NSMutableDictionary* off_params = [params mutableCopy];;
  8139. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  8140. params[@"off_params"]=[RAConvertor dict2string:off_params];
  8141. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8142. if(appDelegate.password!=nil)
  8143. [params setValue:appDelegate.password forKey:@"password"];
  8144. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  8145. if(appDelegate.offline_mode)
  8146. {
  8147. params[@"contact_id"]=appDelegate.contact_id;
  8148. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8149. NSData* json = [[OLDataProvider offline_save_TearSheet:params] mutableCopy];
  8150. dispatch_async(dispatch_get_main_queue(), ^{
  8151. result([[RAConvertor data2dict:json] mutableCopy]);
  8152. });
  8153. });
  8154. return;
  8155. }
  8156. [self request_interface:URL_SAVE_DM parameters:params err_record_url:nil completionHandler:result retry:0];
  8157. //
  8158. // NSData* json = nil;
  8159. // if(appDelegate.offline_mode)
  8160. // {
  8161. // json = [OLDataProvider offline_save_TearSheet:params];
  8162. // } else {
  8163. // if(![self IsNetworkAvailable])
  8164. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8165. //
  8166. // json=[self get_json:URL_SAVE_DM parameters:params];
  8167. // }
  8168. // if(json==nil)
  8169. // return nil;
  8170. // NSError *error=nil;
  8171. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8172. // return jsobj;
  8173. }
  8174. +(void)request_portfoliopreview:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8175. {
  8176. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8177. AppDelegate *appDelegate = nil;
  8178. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8179. if(appDelegate.user!=nil)
  8180. [params setValue:appDelegate.user forKey:@"user"];
  8181. if(appDelegate.contact_id!=nil)
  8182. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8183. if(appDelegate.password!=nil)
  8184. [params setValue:appDelegate.password forKey:@"password"];
  8185. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  8186. // [params setValue:request_url forKey:@"pdfUrl"];
  8187. if(appDelegate.offline_mode)
  8188. {
  8189. params[@"contact_id"]=params[@"contactId"];
  8190. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8191. NSData* json = [[OLDataProvider offline_request_tearsheet:params] mutableCopy];
  8192. dispatch_async(dispatch_get_main_queue(), ^{
  8193. result([[RAConvertor data2dict:json] mutableCopy]);
  8194. });
  8195. });
  8196. return;
  8197. }
  8198. NSString * uuid= [[NSUUID UUID] UUIDString];
  8199. params[@"resultSerial"]=uuid;
  8200. __block bool bbreak = false;
  8201. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8202. for(int i=0;i<150;i++)
  8203. {
  8204. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8205. // result_params[@"resultSerial"]=uuid;
  8206. if(bbreak)
  8207. break;
  8208. dispatch_async(dispatch_get_main_queue(), ^{
  8209. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8210. if([resulti[@"result"] intValue]==2)
  8211. {
  8212. if(!bbreak)//此判断保证result只调用一次。
  8213. result(resulti);
  8214. bbreak=true;
  8215. }
  8216. } retry:3];
  8217. });
  8218. sleep(5);
  8219. }
  8220. });
  8221. //
  8222. // NSData* json= nil;
  8223. // if(appDelegate.offline_mode)
  8224. // {
  8225. // json= [OLDataProvider offline_request_tearsheet:params];
  8226. // }
  8227. // else
  8228. // {
  8229. // if(![self IsNetworkAvailable])
  8230. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8231. //
  8232. // NSError *error=nil;
  8233. //
  8234. // NSString * uuid= [[NSUUID UUID] UUIDString];
  8235. // params[@"resultSerial"]=uuid;
  8236. //
  8237. // for(int i=0;i<150;i++)
  8238. // {
  8239. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8240. // // result_params[@"resultSerial"]=uuid;
  8241. // json=[self get_json:URL_REQUEST_DM parameters:params];
  8242. // if(json!=nil)
  8243. // {
  8244. //
  8245. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8246. // if([jsobj[@"result"] intValue]==2)
  8247. // {
  8248. // break;
  8249. // }
  8250. // }
  8251. // sleep(5);
  8252. // }
  8253. // }
  8254. // if(json==nil)
  8255. // return nil;
  8256. // NSError *error=nil;
  8257. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8258. // return jsobj;
  8259. }
  8260. +(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
  8261. {
  8262. // for debug
  8263. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  8264. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8265. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8266. AppDelegate *appDelegate = nil;
  8267. //some UI methods ej
  8268. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8269. if(appDelegate.user!=nil)
  8270. [params setValue:appDelegate.user forKey:@"user"];
  8271. if(appDelegate.contact_id!=nil)
  8272. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8273. if(appDelegate.password!=nil)
  8274. [params setValue:appDelegate.password forKey:@"password"];
  8275. if(appDelegate.order_code!=nil)
  8276. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8277. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  8278. if (alert && qty && available && price && bestseller) {
  8279. [params setObject:@"Filter" forKey:kAction];
  8280. }
  8281. if ([RASingleton sharedInstance].homeItemClick) {
  8282. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  8283. [RASingleton sharedInstance].homeItemClick = NO;
  8284. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  8285. [RASingleton sharedInstance].homeClickedItemName = nil;
  8286. [params setObject:extra forKey:kExtra];
  8287. }
  8288. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  8289. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  8290. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  8291. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  8292. // [params setValue:filter forKey:@"filter"];
  8293. [params setValue:covertype forKey:@"covertype"];
  8294. [params setValue:ctgid forKey:@"ctgId"];
  8295. [params setValue:modelname forKey:@"modelName"];
  8296. [params setValue:modeldescrip forKey:@"modelDescription"];
  8297. [params setValue:alert forKey:@"alert"];
  8298. [params setValue:qty forKey:@"sold_by_qty"];
  8299. [params setValue:available forKey:@"available"];
  8300. [params setValue:price forKey:@"price"];
  8301. [params setValue:bestseller forKey:@"bestseller"];
  8302. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  8303. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  8304. if(appDelegate.offline_mode)
  8305. {
  8306. // [OLDataProvider offline_itemsearch:params completionHandler:result];
  8307. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8308. NSMutableDictionary* json = [[OLDataProvider offline_itemsearch:params] mutableCopy];
  8309. dispatch_async(dispatch_get_main_queue(), ^{
  8310. result(json);
  8311. });
  8312. });
  8313. return;
  8314. }
  8315. [self request_interface:URL_ITEM_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  8316. // if(appDelegate.offline_mode)
  8317. // {
  8318. // return [OLDataProvider offline_itemsearch:params];
  8319. // }
  8320. // if(![self IsNetworkAvailable])
  8321. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8322. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  8323. // if(json==nil)
  8324. // return nil;
  8325. // NSError *error=nil;
  8326. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8327. // return jsobj;
  8328. }
  8329. +(void)request_modelqty: (NSString*) fashionId completionHandler:(resultHandler)result
  8330. {
  8331. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8332. AppDelegate *appDelegate = nil;
  8333. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8334. if(appDelegate.user!=nil)
  8335. [params setValue:appDelegate.user forKey:@"user"];
  8336. if(appDelegate.contact_id!=nil)
  8337. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8338. if(appDelegate.password!=nil)
  8339. [params setValue:appDelegate.password forKey:@"password"];
  8340. [params setValue:fashionId forKey:@"fashionId"];
  8341. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  8342. if(appDelegate.offline_mode)
  8343. {
  8344. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8345. NSData* json = [[OLDataProvider offline_model_qty:params] mutableCopy];
  8346. dispatch_async(dispatch_get_main_queue(), ^{
  8347. result([[RAConvertor data2dict:json] mutableCopy]);
  8348. });
  8349. });
  8350. return;
  8351. }
  8352. [self request_interface:URL_REQUEST_MODEL_QTY parameters:params err_record_url:nil completionHandler:result retry:0];
  8353. // NSData* json = nil;
  8354. // if(appDelegate.offline_mode)
  8355. // {
  8356. // json = [OLDataProvider offline_model_qty:params];
  8357. // } else {
  8358. // if(![self IsNetworkAvailable])
  8359. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8360. //
  8361. // json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  8362. // }
  8363. // if(json==nil)
  8364. // return nil;
  8365. // NSError *error=nil;
  8366. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8367. // return jsobj;
  8368. }
  8369. +(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
  8370. {
  8371. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8372. AppDelegate *appDelegate = nil;
  8373. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8374. if(appDelegate.user!=nil)
  8375. [params setValue:appDelegate.user forKey:@"user"];
  8376. if(appDelegate.contact_id!=nil)
  8377. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8378. if(appDelegate.password!=nil)
  8379. [params setValue:appDelegate.password forKey:@"password"];
  8380. [params setValue:watchlist_id forKey:@"item_id"];
  8381. // if(notes.length>0)
  8382. // [params setValue:notes forKey:@"notes"];
  8383. if(notes)
  8384. [params setValue:notes forKey:@"notes"];
  8385. if(price != -MAXFLOAT)
  8386. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  8387. if (discount != -MAXFLOAT)
  8388. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  8389. if(qty_p != -MAXFLOAT)
  8390. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  8391. if(qty != -INT32_MAX)
  8392. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  8393. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  8394. // NSData* json = nil;
  8395. if(appDelegate.offline_mode)
  8396. {
  8397. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8398. NSData* json = [[OLDataProvider offline_editPortfolio:params] mutableCopy];
  8399. dispatch_async(dispatch_get_main_queue(), ^{
  8400. result([[RAConvertor data2dict:json] mutableCopy]);
  8401. });
  8402. });
  8403. return;
  8404. }
  8405. [self request_interface:URL_PORTFOLIO_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8406. //
  8407. // if(appDelegate.offline_mode)
  8408. // {
  8409. // json = [OLDataProvider offline_editPortfolio:params];
  8410. // } else {
  8411. // if(![self IsNetworkAvailable])
  8412. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8413. //
  8414. // json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  8415. // }
  8416. // if(json==nil)
  8417. // return nil;
  8418. // NSError *error=nil;
  8419. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8420. // return jsobj;
  8421. }
  8422. +(void)request_add_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8423. {
  8424. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8425. AppDelegate *appDelegate = nil;
  8426. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8427. if(appDelegate.user!=nil)
  8428. [params setValue:appDelegate.user forKey:@"user"];
  8429. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  8430. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8431. // else
  8432. if(appDelegate.contact_id!=nil)
  8433. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8434. if(appDelegate.password!=nil)
  8435. [params setValue:appDelegate.password forKey:@"password"];
  8436. // NSDictionary* customerinfo=nil;
  8437. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  8438. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8439. // else
  8440. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8441. //
  8442. // appDelegate.customerInfo;
  8443. // NSArray* keys=[customerinfo allKeys];
  8444. // for(int i=0;i<keys.count;i++)
  8445. // {
  8446. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8447. // }
  8448. // [params setValue:sourceid forKey:@"sourceid"];
  8449. // [params setValue:editor forKey:@"editor"];
  8450. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  8451. if(appDelegate.offline_mode)
  8452. {
  8453. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8454. NSData* json = [[OLDataProvider offline_saveNewContact:params] mutableCopy];
  8455. dispatch_async(dispatch_get_main_queue(), ^{
  8456. result([[RAConvertor data2dict:json] mutableCopy]);
  8457. });
  8458. });
  8459. return;
  8460. }
  8461. [self request_interface:URL_CUSTOMER_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  8462. //
  8463. // NSData* json=nil;
  8464. // if(appDelegate.offline_mode)
  8465. // {
  8466. // json= [OLDataProvider offline_saveNewContact:params];
  8467. // }
  8468. // else
  8469. // {
  8470. // if(![self IsNetworkAvailable])
  8471. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8472. //
  8473. // json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  8474. // }
  8475. //
  8476. // if(json!=nil)
  8477. // {
  8478. // NSError *error=nil;
  8479. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8480. // return jsobj;
  8481. // }
  8482. // else
  8483. // return nil;
  8484. }
  8485. +(void)request_update_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8486. {
  8487. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8488. AppDelegate *appDelegate = nil;
  8489. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8490. if(appDelegate.user!=nil)
  8491. [params setValue:appDelegate.user forKey:@"user"];
  8492. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  8493. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8494. // else
  8495. if(appDelegate.contact_id!=nil)
  8496. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8497. if(appDelegate.password!=nil)
  8498. [params setValue:appDelegate.password forKey:@"password"];
  8499. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8500. if(appDelegate.offline_mode)
  8501. {
  8502. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8503. NSData* json = [[OLDataProvider offline_saveContact:params] mutableCopy];
  8504. dispatch_async(dispatch_get_main_queue(), ^{
  8505. result([[RAConvertor data2dict:json] mutableCopy]);
  8506. });
  8507. });
  8508. return;
  8509. }
  8510. [self request_interface:URL_CUSTOMER_UPDATE parameters:params err_record_url:nil completionHandler:result retry:0];
  8511. //
  8512. // NSData* json=nil;
  8513. // if(appDelegate.offline_mode)
  8514. // {
  8515. // json= [OLDataProvider offline_saveContact:params];
  8516. // }
  8517. // else
  8518. // {
  8519. // if(![self IsNetworkAvailable])
  8520. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8521. //
  8522. // json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  8523. // }
  8524. //
  8525. // if(json!=nil)
  8526. // {
  8527. // NSError *error=nil;
  8528. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8529. // return jsobj;
  8530. // }
  8531. // else
  8532. // return nil;
  8533. }
  8534. +(void)request_delete_order:(NSString*) order_id completionHandler:(resultHandler)result
  8535. {
  8536. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8537. AppDelegate *appDelegate = nil;
  8538. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8539. if(appDelegate.user!=nil)
  8540. [params setValue:appDelegate.user forKey:@"user"];
  8541. // if(appDelegate.contact_id!=nil)
  8542. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8543. if(appDelegate.password!=nil)
  8544. [params setValue:appDelegate.password forKey:@"password"];
  8545. [params setValue:order_id forKey:@"orderId"];
  8546. // [params setValue:sourceid forKey:@"sourceid"];
  8547. // [params setValue:editor forKey:@"editor"];
  8548. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8549. if(appDelegate.offline_mode)
  8550. {
  8551. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8552. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8553. dispatch_async(dispatch_get_main_queue(), ^{
  8554. result(json);
  8555. });
  8556. });
  8557. return;
  8558. }
  8559. [self request_interface:URL_DELETE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8560. //
  8561. // if(appDelegate.offline_mode)
  8562. // {
  8563. // return [OLDataProvider offline_notimpl];
  8564. // }
  8565. // if(![self IsNetworkAvailable])
  8566. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8567. //
  8568. // NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  8569. // if(json!=nil)
  8570. // {
  8571. // NSError *error=nil;
  8572. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8573. //
  8574. //
  8575. // return jsobj;
  8576. // }
  8577. // else
  8578. // return nil;
  8579. }
  8580. +(void)request_cancel_order:(NSString*) order_id order_code:(NSString*) order_code completionHandler:(resultHandler)result
  8581. {
  8582. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8583. AppDelegate *appDelegate = nil;
  8584. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8585. if(appDelegate.user!=nil)
  8586. [params setValue:appDelegate.user forKey:@"user"];
  8587. // if(appDelegate.contact_id!=nil)
  8588. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8589. if(appDelegate.password!=nil)
  8590. [params setValue:appDelegate.password forKey:@"password"];
  8591. [params setValue:order_id forKey:@"orderId"];
  8592. [params setValue:order_code forKey:@"orderCode"];
  8593. // [params setValue:sourceid forKey:@"sourceid"];
  8594. // [params setValue:editor forKey:@"editor"];
  8595. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8596. if(appDelegate.offline_mode)
  8597. {
  8598. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8599. NSData* json = [[OLDataProvider offline_cancelorder:params] mutableCopy];
  8600. dispatch_async(dispatch_get_main_queue(), ^{
  8601. result([[RAConvertor data2dict:json] mutableCopy]);
  8602. });
  8603. });
  8604. return;
  8605. }
  8606. [self request_interface:URL_CANCEL_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8607. //
  8608. // NSData* json=nil;
  8609. // if(appDelegate.offline_mode)
  8610. // {
  8611. // json=[OLDataProvider offline_cancelorder:params];
  8612. // }
  8613. // else
  8614. // {
  8615. // if(![self IsNetworkAvailable])
  8616. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8617. // json=[self get_json:URL_CANCEL_ORDER parameters:params];
  8618. // }
  8619. // if(json!=nil)
  8620. // {
  8621. // NSError *error=nil;
  8622. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8623. //
  8624. //
  8625. // return jsobj;
  8626. // }
  8627. // else
  8628. // return nil;
  8629. }
  8630. +(void)request_release_order:(NSString*) order_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  8631. {
  8632. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8633. AppDelegate *appDelegate = nil;
  8634. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8635. if(appDelegate.user!=nil)
  8636. [params setValue:appDelegate.user forKey:@"user"];
  8637. // if(appDelegate.contact_id!=nil)
  8638. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8639. if(appDelegate.password!=nil)
  8640. [params setValue:appDelegate.password forKey:@"password"];
  8641. [params setValue:order_code forKey:@"orderCode"];
  8642. // [params setValue:sourceid forKey:@"sourceid"];
  8643. // [params setValue:editor forKey:@"editor"];
  8644. if (screenName) {
  8645. [params setValue:screenName forKey:kScreenName];
  8646. }
  8647. if(appDelegate.offline_mode)
  8648. {
  8649. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8650. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_resetorder:params]] mutableCopy];
  8651. dispatch_async(dispatch_get_main_queue(), ^{
  8652. if([[resulti valueForKey:@"result"]intValue]==2)
  8653. { [appDelegate SetSo:nil];
  8654. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8655. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8656. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8657. [appDelegate update_count_mark];
  8658. dispatch_async(dispatch_get_main_queue(), ^{
  8659. result(resulti);
  8660. });
  8661. }
  8662. });
  8663. });
  8664. return;
  8665. }
  8666. [self request_interface:URL_RELEASE_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8667. if([[resulti valueForKey:@"result"]intValue]==2)
  8668. { [appDelegate SetSo:nil];
  8669. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8670. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8671. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8672. [appDelegate update_count_mark];
  8673. dispatch_async(dispatch_get_main_queue(), ^{
  8674. result(resulti);
  8675. });
  8676. }
  8677. } retry:0];
  8678. //
  8679. // NSData* json=nil;
  8680. // if(appDelegate.offline_mode)
  8681. // {
  8682. // json= [OLDataProvider offline_resetorder:params];
  8683. // }
  8684. // else
  8685. // {
  8686. // if(![self IsNetworkAvailable])
  8687. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8688. //
  8689. // json=[self get_json:URL_RELEASE_ORDER parameters:params];
  8690. // }
  8691. // if(json!=nil)
  8692. // {
  8693. // NSError *error=nil;
  8694. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8695. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8696. // { [appDelegate SetSo:nil];
  8697. //
  8698. //
  8699. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8700. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8701. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8702. //
  8703. // [appDelegate update_count_mark];
  8704. // }
  8705. // return jsobj;
  8706. // }
  8707. // else
  8708. // return nil;
  8709. }
  8710. +(void)request_update_order_signature:(NSString*) order_code path:(NSString*)path completionHandler:(resultHandler)result
  8711. {
  8712. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8713. AppDelegate *appDelegate = nil;
  8714. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8715. if(appDelegate.user!=nil)
  8716. [params setValue:appDelegate.user forKey:@"user"];
  8717. if(appDelegate.contact_id!=nil)
  8718. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8719. if(appDelegate.password!=nil)
  8720. [params setValue:appDelegate.password forKey:@"password"];
  8721. // NSString* ssaved = @"false";
  8722. // if(saved)
  8723. // ssaved=@"true";
  8724. // [params setValue:@"true" forKey:@"saved"];
  8725. [params setValue:order_code forKey:@"orderCode"];
  8726. [params setValue:path forKey:@"picpath"];
  8727. // [params setValue:sourceid forKey:@"sourceid"];
  8728. // [params setValue:editor forKey:@"editor"];
  8729. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  8730. if(appDelegate.offline_mode)
  8731. {
  8732. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8733. NSData* json = [[OLDataProvider offline_signorder:params] mutableCopy];
  8734. dispatch_async(dispatch_get_main_queue(), ^{
  8735. result([[RAConvertor data2dict:json] mutableCopy]);
  8736. });
  8737. });
  8738. return;
  8739. }
  8740. [self request_interface:URL_SIGN_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8741. //
  8742. // NSData* json=nil;
  8743. // if(appDelegate.offline_mode)
  8744. // {
  8745. // json= [OLDataProvider offline_signorder:params];
  8746. // }
  8747. // else
  8748. // {
  8749. // if(![self IsNetworkAvailable])
  8750. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8751. //
  8752. // json=[self get_json:URL_SIGN_ORDER parameters:params];
  8753. // }
  8754. // if(json!=nil)
  8755. // {
  8756. // NSError *error=nil;
  8757. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8758. // return jsobj;
  8759. // }
  8760. // else
  8761. // return nil;
  8762. }
  8763. +(void) request_scan_bulkdiscount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8764. {
  8765. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  8766. //
  8767. //
  8768. // [appDelegate update_count_mark];
  8769. if(RASingleton.sharedInstance.price_type==0)
  8770. {
  8771. result(RASingleton.sharedInstance.scan_cart);
  8772. return;
  8773. }
  8774. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  8775. int count = [section[@"count"] intValue];
  8776. for(int i=0;i<count;i++)
  8777. {
  8778. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  8779. if ([item[@"special_price"] boolValue]||[item[@"net_price"] boolValue])
  8780. continue;
  8781. int item_count = [item[@"count"] intValue];
  8782. float price=[item[@"unit_price"] floatValue] ;
  8783. item[@"discount"] =@(discount);
  8784. item[@"subtotal_price"] =@(price*item_count);
  8785. if(discount>0)
  8786. item[@"note"] =[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  8787. else
  8788. item[@"note"] =@"";
  8789. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  8790. }
  8791. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  8792. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  8793. result(RASingleton.sharedInstance.scan_cart);
  8794. AppDelegate *appDelegate = nil;
  8795. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8796. [OLDataProvider updateScanOrder:appDelegate.order_code];
  8797. return;
  8798. }
  8799. +(void) request_update_cart_modelprice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8800. {
  8801. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8802. AppDelegate *appDelegate = nil;
  8803. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8804. #ifdef SCANNER_ORDER
  8805. // return;
  8806. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  8807. {
  8808. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  8809. //
  8810. //
  8811. // [appDelegate update_count_mark];
  8812. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  8813. int count = [section[@"count"] intValue];
  8814. for(int i=0;i<count;i++)
  8815. {
  8816. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  8817. if([item[@"cart_item_id"] isEqualToString:cart_id])
  8818. {
  8819. int item_count = [item[@"count"] intValue];
  8820. item[@"unit_price"] =@(price);
  8821. item[@"discount"] =@(discount);
  8822. item[@"subtotal_price"] =@(price*item_count);
  8823. if(discount>0)
  8824. item[@"note"] =[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  8825. else
  8826. item[@"note"] =@"";
  8827. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  8828. break;
  8829. }
  8830. }
  8831. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  8832. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  8833. result(RASingleton.sharedInstance.scan_cart);
  8834. [OLDataProvider updateScanOrder:appDelegate.order_code];
  8835. return;
  8836. }
  8837. #endif
  8838. if(appDelegate.user!=nil)
  8839. [params setValue:appDelegate.user forKey:@"user"];
  8840. if(appDelegate.contact_id!=nil)
  8841. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8842. if(appDelegate.password!=nil)
  8843. [params setValue:appDelegate.password forKey:@"password"];
  8844. [params setValue:cart_id forKey:@"cartitem_id"];
  8845. [params setValue:notes forKey:@"item_note"];
  8846. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  8847. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  8848. [params setObject:ScreenCodeCart forKey:kScreenName];
  8849. if(appDelegate.offline_mode)
  8850. {
  8851. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8852. NSData* json = [[OLDataProvider offline_cartsetprice:params] mutableCopy];
  8853. dispatch_async(dispatch_get_main_queue(), ^{
  8854. result([[RAConvertor data2dict:json] mutableCopy]);
  8855. });
  8856. });
  8857. return;
  8858. }
  8859. [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8860. //
  8861. // NSData* json= nil;
  8862. // if(appDelegate.offline_mode)
  8863. // {
  8864. // json=[OLDataProvider offline_cartsetprice:params];
  8865. // }
  8866. // else
  8867. // {
  8868. // if(![self IsNetworkAvailable])
  8869. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8870. //
  8871. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8872. // }
  8873. // if(json==nil)
  8874. // return nil;
  8875. // NSError *error=nil;
  8876. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8877. // return jsobj;
  8878. }
  8879. +(void) request_addto_cart:(NSString* ) item_id count:(int) count name:(NSString *)name completionHandler:(resultHandler)result
  8880. {
  8881. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8882. AppDelegate *appDelegate = nil;
  8883. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8884. if(appDelegate.user!=nil)
  8885. [params setValue:appDelegate.user forKey:@"user"];
  8886. if(appDelegate.contact_id!=nil)
  8887. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8888. if(appDelegate.password!=nil)
  8889. [params setValue:appDelegate.password forKey:@"password"];
  8890. if(appDelegate.order_code!=nil)
  8891. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8892. [params setValue:item_id forKey:@"product_id"];
  8893. [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  8894. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  8895. [params setObject:@"Add To Cart" forKey:kAction];
  8896. if (name) {
  8897. NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  8898. [params setObject:extra forKey:kExtra];
  8899. }
  8900. NSDictionary* customerinfo= appDelegate.customerInfo;
  8901. NSArray* keys=[customerinfo allKeys];
  8902. for(int i=0;i<keys.count;i++)
  8903. {
  8904. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8905. }
  8906. if(appDelegate.offline_mode)
  8907. {
  8908. // [OLDataProvider offline_add2cart:params completionHandler:^(NSMutableDictionary *resulti) {
  8909. // NSMutableDictionary* json = resulti;
  8910. // if ([json[@"result"] intValue]==2)
  8911. // {
  8912. // appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  8913. //
  8914. // [appDelegate update_count_mark];
  8915. // }
  8916. // result(json);
  8917. // }];
  8918. params[@"can_create_backorder"]= @(appDelegate.can_create_backorder);
  8919. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8920. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cart:params]] mutableCopy];
  8921. dispatch_async(dispatch_get_main_queue(), ^{
  8922. if ([json[@"result"] intValue]==2)
  8923. {
  8924. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  8925. [appDelegate update_count_mark];
  8926. }
  8927. result(json);
  8928. });
  8929. });
  8930. return;
  8931. }
  8932. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8933. if ([resulti[@"result"] intValue]==2)
  8934. {
  8935. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8936. [appDelegate update_count_mark];
  8937. }
  8938. result(resulti);
  8939. } retry:0];
  8940. //
  8941. // NSData* json=nil;
  8942. // if(appDelegate.offline_mode)
  8943. // {
  8944. // json=[OLDataProvider offline_add2cart:params];
  8945. // }
  8946. // else
  8947. // {
  8948. // if(![self IsNetworkAvailable])
  8949. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8950. //
  8951. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  8952. // }
  8953. // if(json==nil)
  8954. // return nil;
  8955. // NSError *error=nil;
  8956. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8957. //
  8958. //
  8959. //
  8960. // int result = [[jsobj valueForKey:@"result"] intValue];
  8961. //
  8962. // if (result==2)
  8963. // {
  8964. //
  8965. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8966. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8967. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8968. //
  8969. // [appDelegate update_count_mark];
  8970. // }
  8971. //
  8972. // return jsobj;
  8973. }
  8974. //+(void) request_update_cart_modelfree:(NSString*) cart_id isfree:(bool) isfree completionHandler:(resultHandler)result
  8975. //{
  8976. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8977. // AppDelegate *appDelegate = nil;
  8978. //
  8979. //
  8980. //
  8981. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8982. //
  8983. // if(appDelegate.user!=nil)
  8984. // [params setValue:appDelegate.user forKey:@"user"];
  8985. // if(appDelegate.contact_id!=nil)
  8986. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8987. // if(appDelegate.password!=nil)
  8988. // [params setValue:appDelegate.password forKey:@"password"];
  8989. //
  8990. // [params setValue:cart_id forKey:@"cartitem_id"];
  8991. //
  8992. // [params setObject:ScreenCodeCart forKey:kScreenName];
  8993. //
  8994. // NSString* free=nil;
  8995. //
  8996. // if(isfree)
  8997. // free=@"true";
  8998. // else
  8999. // free=@"false";
  9000. //
  9001. // [params setValue:free forKey:@"free_giveaway"];
  9002. //
  9003. //
  9004. // if(appDelegate.offline_mode)
  9005. // {
  9006. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9007. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9008. // dispatch_async(dispatch_get_main_queue(), ^{
  9009. // result(json);
  9010. // });
  9011. // });
  9012. //
  9013. // return;
  9014. //
  9015. // }
  9016. // [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  9017. //
  9018. ////
  9019. ////
  9020. //// if(appDelegate.offline_mode)
  9021. //// {
  9022. //// return [OLDataProvider offline_notimpl];
  9023. //// }
  9024. //// if(![self IsNetworkAvailable])
  9025. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9026. ////
  9027. //// NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  9028. //// if(json==nil)
  9029. //// return nil;
  9030. //// NSError *error=nil;
  9031. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9032. //// return jsobj;
  9033. //}
  9034. +(void)request_retrieve_password: (NSString*) user email:(NSString*) email completionHandler:(resultHandler)result
  9035. {
  9036. AppDelegate *appDelegate = nil;
  9037. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9038. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9039. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  9040. // if(appDelegate.user!=nil)
  9041. // [params setValue:appDelegate.user forKey:@"user"];
  9042. // if(appDelegate.contact_id!=nil)
  9043. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9044. // if(appDelegate.password!=nil)
  9045. // [params setValue:appDelegate.password forKey:@"password"];
  9046. [params setValue:user forKey:@"username"];
  9047. [params setValue:email forKey:@"email"];
  9048. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  9049. if(appDelegate.offline_mode)
  9050. {
  9051. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9052. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9053. dispatch_async(dispatch_get_main_queue(), ^{
  9054. result(json);
  9055. });
  9056. });
  9057. return;
  9058. }
  9059. #ifdef SCANNER_ORDER
  9060. params[@"site_name"]=[RADataProvider getSiteName];
  9061. params[@"_method"]=@"forgotPasswordOfflineOrderUser";
  9062. params[@"user"]=user;
  9063. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_RETRIEVE_PASS];
  9064. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  9065. #else
  9066. [self request_interface:URL_RETRIEVE_PASS parameters:params err_record_url:nil completionHandler:result retry:0];
  9067. #endif
  9068. //
  9069. //
  9070. // if(![self IsNetworkAvailable])
  9071. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9072. //
  9073. // NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  9074. // if(json==nil)
  9075. // return nil;
  9076. // NSError *error=nil;
  9077. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9078. // return jsobj;
  9079. }
  9080. +(void)request_update_ordercustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info completionHandler:(resultHandler)result
  9081. {
  9082. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9083. AppDelegate *appDelegate = nil;
  9084. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9085. if(appDelegate.user!=nil)
  9086. [info setValue:appDelegate.user forKey:@"user"];
  9087. // if(appDelegate.contact_id!=nil)
  9088. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9089. if(appDelegate.password!=nil)
  9090. [info setValue:appDelegate.password forKey:@"password"];
  9091. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  9092. [info setValue:order_code forKey:@"orderCode"];
  9093. // [params setValue:sourceid forKey:@"sourceid"];
  9094. // [params setValue:editor forKey:@"editor"];
  9095. if(appDelegate.offline_mode)
  9096. {
  9097. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9098. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9099. dispatch_async(dispatch_get_main_queue(), ^{
  9100. result(json);
  9101. });
  9102. });
  9103. return;
  9104. }
  9105. [self request_interface:URL_UPDATE_ORDERCUSTOMER parameters:info err_record_url:nil completionHandler:result retry:0];
  9106. // if(appDelegate.offline_mode)
  9107. // {
  9108. // return [OLDataProvider offline_notimpl];
  9109. // }
  9110. // if(![self IsNetworkAvailable])
  9111. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9112. //
  9113. // NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  9114. // if(json!=nil)
  9115. // {
  9116. // NSError *error=nil;
  9117. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9118. // return jsobj;
  9119. // }
  9120. // else
  9121. // return nil;
  9122. }
  9123. +(void)request_update_customer_img: (NSString*) contactid img_url:(NSString*) url completionHandler:(resultHandler)result
  9124. {
  9125. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9126. AppDelegate *appDelegate = nil;
  9127. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9128. if(appDelegate.user!=nil)
  9129. [params setValue:appDelegate.user forKey:@"user"];
  9130. // if(appDelegate.contact_id!=nil)
  9131. if(appDelegate.password!=nil)
  9132. [params setValue:appDelegate.password forKey:@"password"];
  9133. [params setValue:contactid forKey:@"contactId"];
  9134. [params setValue:url forKey:@"business_card"];
  9135. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  9136. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  9137. if(appDelegate.offline_mode)
  9138. {
  9139. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9140. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9141. dispatch_async(dispatch_get_main_queue(), ^{
  9142. result(json);
  9143. });
  9144. });
  9145. return;
  9146. }
  9147. [self request_interface:URL_UPDATE_CUSTOMER_BCARD parameters:params err_record_url:nil completionHandler:result retry:0];
  9148. // if(appDelegate.offline_mode)
  9149. // {
  9150. // return [OLDataProvider offline_notimpl];
  9151. // }
  9152. // if(![self IsNetworkAvailable])
  9153. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9154. //
  9155. // NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  9156. // if(json==nil)
  9157. // return nil;
  9158. // NSError *error=nil;
  9159. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9160. // return jsobj;
  9161. }
  9162. +(void)request_commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url completionHandler:(resultHandler)result
  9163. {
  9164. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9165. AppDelegate *appDelegate = nil;
  9166. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9167. if(appDelegate.user!=nil)
  9168. [params setValue:appDelegate.user forKey:@"user"];
  9169. if(appDelegate.contact_id!=nil)
  9170. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9171. if(appDelegate.password!=nil)
  9172. [params setValue:appDelegate.password forKey:@"password"];
  9173. // if(appDelegate.order_code!=nil)
  9174. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  9175. // NSDictionary* customerinfo= appDelegate.customerInfo;
  9176. //
  9177. // NSArray* keys=[customerinfo allKeys];
  9178. // for(int i=0;i<keys.count;i++)
  9179. // {
  9180. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  9181. // }
  9182. //
  9183. // [params setValue:sourceid forKey:@"sourceid"];
  9184. // [params setValue:editor forKey:@"editor"];
  9185. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  9186. if(appDelegate.offline_mode)
  9187. {
  9188. params[@"offline_Command"]=url;
  9189. [OLDataProvider offline_commoneditor_partialrefresh:params completionHandler:result];
  9190. //
  9191. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9192. // NSMutableDictionary* json = [[OLDataProvider offline_commoneditor_partialrefresh:params] mutableCopy];
  9193. // dispatch_async(dispatch_get_main_queue(), ^{
  9194. // result(json);
  9195. // });
  9196. // });
  9197. return;
  9198. }
  9199. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  9200. //
  9201. // if(appDelegate.offline_mode)
  9202. // {
  9203. // params[@"offline_Command"]=url;
  9204. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  9205. // }
  9206. //
  9207. // if(![self IsNetworkAvailable])
  9208. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9209. //
  9210. // NSData* json=[self get_json:url parameters:params];
  9211. // if(json!=nil)
  9212. // {
  9213. // NSError *error=nil;
  9214. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9215. // if([[jsobj valueForKey:@"result"]intValue]==2)
  9216. // [appDelegate SetSo:nil];
  9217. //
  9218. //
  9219. // return jsobj;
  9220. // }
  9221. // else
  9222. // return nil;
  9223. }
  9224. +(void)request_add_address:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  9225. {
  9226. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9227. AppDelegate *appDelegate = nil;
  9228. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9229. if(appDelegate.user!=nil)
  9230. [params setValue:appDelegate.user forKey:@"user"];
  9231. if(appDelegate.contact_id!=nil)
  9232. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9233. if(appDelegate.password!=nil)
  9234. [params setValue:appDelegate.password forKey:@"password"];
  9235. // [params setValue:sourceid forKey:@"sourceid"];
  9236. // [params setValue:editor forKey:@"editor"];
  9237. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  9238. if(appDelegate.offline_mode)
  9239. {
  9240. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9241. NSData* json = [[OLDataProvider offline_saveaddr:params] mutableCopy];
  9242. dispatch_async(dispatch_get_main_queue(), ^{
  9243. result([[RAConvertor data2dict:json] mutableCopy]);
  9244. });
  9245. });
  9246. return;
  9247. }
  9248. [self request_interface:URL_ADDRESS_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  9249. //
  9250. // NSData* json=nil;
  9251. //
  9252. // if(appDelegate.offline_mode)
  9253. // {
  9254. // json= [OLDataProvider offline_saveaddr:params];
  9255. // }
  9256. // else
  9257. // {
  9258. // if(![self IsNetworkAvailable])
  9259. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9260. //
  9261. // json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  9262. // }
  9263. // if(json!=nil)
  9264. // {
  9265. // NSError *error=nil;
  9266. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9267. // return jsobj;
  9268. // }
  9269. // else
  9270. // return nil;
  9271. }
  9272. +(void)request_commit_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  9273. {
  9274. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9275. AppDelegate *appDelegate = nil;
  9276. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9277. if(appDelegate.user!=nil)
  9278. [params setValue:appDelegate.user forKey:@"user"];
  9279. if(appDelegate.contact_id!=nil)
  9280. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9281. if(appDelegate.password!=nil)
  9282. [params setValue:appDelegate.password forKey:@"password"];
  9283. if(appDelegate.order_code!=nil)
  9284. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  9285. // NSDictionary* customerinfo= appDelegate.customerInfo;
  9286. //
  9287. // NSArray* keys=[customerinfo allKeys];
  9288. // for(int i=0;i<keys.count;i++)
  9289. // {
  9290. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  9291. // }
  9292. //
  9293. // [params setValue:sourceid forKey:@"sourceid"];
  9294. // [params setValue:editor forKey:@"editor"];
  9295. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  9296. if(appDelegate.offline_mode)
  9297. {
  9298. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9299. NSData* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  9300. dispatch_async(dispatch_get_main_queue(), ^{
  9301. result([[RAConvertor data2dict:json] mutableCopy]);
  9302. });
  9303. });
  9304. return;
  9305. }
  9306. [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  9307. //
  9308. // NSData* json=nil;
  9309. // if(appDelegate.offline_mode)
  9310. // {
  9311. // json=[OLDataProvider offline_submitorder:params];
  9312. // }
  9313. // else
  9314. // {
  9315. // if(![self IsNetworkAvailable])
  9316. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9317. //
  9318. // json=[self get_json:URL_COMMIT_ORDER parameters:params];
  9319. // }
  9320. // if(json!=nil)
  9321. // {
  9322. // NSError *error=nil;
  9323. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9324. // if([[jsobj valueForKey:@"result"]intValue]==2)
  9325. // [appDelegate SetSo:nil];
  9326. //
  9327. //
  9328. // return jsobj;
  9329. // }
  9330. // else
  9331. // return nil;
  9332. }
  9333. +(void) request_new_offline_ticket:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid completionHandler:(resultHandler)result
  9334. {
  9335. // if(![self IsNetworkAvailable])
  9336. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9337. //
  9338. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9339. AppDelegate *appDelegate = nil;
  9340. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9341. if(appDelegate.user!=nil)
  9342. [params setValue:appDelegate.user forKey:@"user"];
  9343. // if(appDelegate.contact_id!=nil)
  9344. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9345. if(appDelegate.password!=nil)
  9346. [params setValue:appDelegate.password forKey:@"password"];
  9347. [params setValue:ver forKey:@"ver"];
  9348. [params setValue:vid forKey:@"vid"];
  9349. if(buseinternaladdress)
  9350. [params setValue:@"true" forKey:@"internal_address"];
  9351. else
  9352. [params setValue:@"false" forKey:@"internal_address"];
  9353. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  9354. // 无论当前是离线还是在线状态,都可以进行同步;
  9355. // if(appDelegate.offline_mode)
  9356. // {
  9357. //
  9358. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9359. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9360. // dispatch_async(dispatch_get_main_queue(), ^{
  9361. // result(json);
  9362. // });
  9363. // });
  9364. //
  9365. // return;
  9366. //
  9367. // }
  9368. [self request_interface:URL_CHECK_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  9369. //
  9370. // NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  9371. // if(json==nil)
  9372. // return nil;
  9373. // NSError *error=nil;
  9374. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9375. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9376. // //
  9377. // // if (result==2)
  9378. // // {
  9379. // //
  9380. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9381. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9382. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9383. // ////
  9384. // //// [appDelegate update_count_mark];
  9385. // // }
  9386. // return jsobj;
  9387. }
  9388. +(void) request_complete_offline_ticket:(NSString* )vid completionHandler:(resultHandler)result
  9389. {
  9390. AppDelegate *appDelegate = nil;
  9391. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9392. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9393. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  9394. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  9395. // if(appDelegate.user!=nil)
  9396. // [params setValue:appDelegate.user forKey:@"user"];
  9397. // // if(appDelegate.contact_id!=nil)
  9398. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9399. // if(appDelegate.password!=nil)
  9400. // [params setValue:appDelegate.password forKey:@"password"];
  9401. [params setValue:vid forKey:@"downSerial"];
  9402. // 无论当前是离线还是在线状态,都可以进行同步;
  9403. // if(appDelegate.offline_mode)
  9404. // {
  9405. //
  9406. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9407. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9408. // dispatch_async(dispatch_get_main_queue(), ^{
  9409. // result(json);
  9410. // });
  9411. // });
  9412. //
  9413. // return;
  9414. //
  9415. // }
  9416. [self request_interface:URL_FINISH_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  9417. // NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  9418. // if(json==nil)
  9419. // return nil;
  9420. // NSError *error=nil;
  9421. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9422. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9423. // //
  9424. // // if (result==2)
  9425. // // {
  9426. // //
  9427. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9428. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9429. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9430. // ////
  9431. // //// [appDelegate update_count_mark];
  9432. // // }
  9433. // return jsobj;
  9434. }
  9435. +(void) request_download_offline:(NSString* )vid completionHandler:(resultHandler)result
  9436. {
  9437. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9438. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  9439. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  9440. // if(appDelegate.user!=nil)
  9441. // [params setValue:appDelegate.user forKey:@"user"];
  9442. // // if(appDelegate.contact_id!=nil)
  9443. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9444. // if(appDelegate.password!=nil)
  9445. // [params setValue:appDelegate.password forKey:@"password"];
  9446. [params setValue:vid forKey:@"downSerial"];
  9447. // AppDelegate *appDelegate = nil;
  9448. //
  9449. //
  9450. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9451. // if(appDelegate.offline_mode)
  9452. // {
  9453. //
  9454. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9455. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9456. // dispatch_async(dispatch_get_main_queue(), ^{
  9457. // result(json);
  9458. // });
  9459. // });
  9460. //
  9461. // return;
  9462. //
  9463. // }
  9464. __block bool bbreak = false;
  9465. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9466. __block NSMutableDictionary* download_json=nil;
  9467. int count=0;
  9468. // __block bool preparing = true;
  9469. while ([[download_json valueForKey:@"result"] intValue]!=2&&count<REQUEST_DOWNLOAD_RETRY_TIMES) //超过60分钟还没准被好数据就视为服务器出错。
  9470. {
  9471. if(bbreak)
  9472. break;
  9473. dispatch_async(dispatch_get_main_queue(), ^{
  9474. [self request_interface:URL_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  9475. if([resulti[@"result"] intValue]==RESULT_TRUE)
  9476. {
  9477. if(!bbreak) //此判断保证result只调用一次。
  9478. {
  9479. // appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  9480. // [appDelegate update_count_mark];
  9481. resulti[@"request_count"]=[NSNumber numberWithInt:count];
  9482. result(resulti);
  9483. }
  9484. bbreak=true;
  9485. }
  9486. else if([resulti[@"result"] intValue]==RESULT_ERROR)
  9487. {
  9488. result(resulti);
  9489. bbreak=true;
  9490. }
  9491. } retry:3];
  9492. });
  9493. sleep(RETRY_DELAY);
  9494. count++;
  9495. // download_json=[[RANetwork download_Offline:downSerial] mutableCopy];
  9496. //
  9497. // [RANetwork request_download_offline:downSerial completionHandler:^(NSMutableDictionary *result) {
  9498. // download_json=result;
  9499. // }];
  9500. //
  9501. }
  9502. // for(int i=0;i<150;i++)
  9503. // {
  9504. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  9505. // // result_params[@"resultSerial"]=uuid;
  9506. //
  9507. //
  9508. //
  9509. // sleep(2);
  9510. //
  9511. // // json=[self get_json:URL_CART parameters:params];
  9512. // // if(json!=nil)
  9513. // // {
  9514. // //
  9515. // // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9516. // // if([jsobj[@"result"] intValue]==2)
  9517. // // {
  9518. // // break;
  9519. // // }
  9520. // // }
  9521. //
  9522. // }
  9523. });
  9524. //
  9525. // NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  9526. // if(json==nil)
  9527. // return nil;
  9528. // NSError *error=nil;
  9529. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9530. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9531. // //
  9532. // // if (result==2)
  9533. // // {
  9534. // //
  9535. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9536. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9537. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9538. // ////
  9539. // //// [appDelegate update_count_mark];
  9540. // // }
  9541. // return jsobj;
  9542. }
  9543. + (void)request_fastupload:(NSMutableDictionary *)params filename:(NSString*)filename data:(NSData*) data url:(NSString *)url completionHandler:(resultHandler)result
  9544. {
  9545. //#ifdef test_server
  9546. // url=URL_REQUEST_RECORDS;
  9547. // params[@"prefix"]=URL_REQUEST_RECORDS;
  9548. //#endif
  9549. // [self request_file_fast:url parameters:params completionHandler:result];
  9550. #ifdef SCANNER_ORDER
  9551. params[@"site_name"]=[RADataProvider getSiteName];
  9552. #endif
  9553. [self request_upload_fast:data FileName:filename server:url parameters:params completionHandler:result];
  9554. }
  9555. +(void)request_err_log:(NSString*) up_params result:(NSString*)result_str module:(NSString*) module code:(int) code completionHandler:(resultHandler)result
  9556. {
  9557. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9558. AppDelegate *appDelegate = nil;
  9559. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9560. if(appDelegate.user!=nil)
  9561. [params setValue:appDelegate.user forKey:@"user"];
  9562. [params setValue:up_params forKey:@"upparam"];
  9563. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  9564. [params setValue:result_str forKey:@"result"];
  9565. [params setValue:module forKey:@"interfac"];
  9566. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  9567. // [params setValue:module forKey:@"module"];
  9568. // [[UIDevice currentDevice] name];
  9569. // if(appDelegate.offline_mode)
  9570. // {
  9571. // return [OLDataProvider offline_notimpl];
  9572. // }
  9573. if(appDelegate.offline_mode)
  9574. {
  9575. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9576. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9577. dispatch_async(dispatch_get_main_queue(), ^{
  9578. result(json);
  9579. });
  9580. });
  9581. return;
  9582. }
  9583. [self request_interface:URL_ERR_LOG parameters:params err_record_url:nil completionHandler:result retry:0];
  9584. //
  9585. // if(![self IsNetworkAvailable])
  9586. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9587. //
  9588. // NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  9589. // if(json==nil)
  9590. // return nil;
  9591. // NSError *error=nil;
  9592. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9593. // return jsobj;
  9594. }
  9595. @end