RANetwork.m 394 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933
  1. //
  2. // iSalesNetwork.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-6-20.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RANetwork.h"
  9. #import "RAUtils.h"
  10. #import "RASingleton.h"
  11. #ifdef GOOGLE_ANALYTICS
  12. #import "GoogleAnalyst.h"
  13. #endif
  14. #import "ERPUtils.h"
  15. #import "RAConvertor.h"
  16. #import "ActiveViewController.h"
  17. #import "ZipArchive.h"
  18. #import "RADataProvider.h"
  19. NSString *const kScreenName = @"kScreenName";
  20. NSString *const kAction = @"kAction";
  21. NSString *const kExtra = @"kExtra";
  22. NSString *const ScreenCodeLoginView = @"Login Screen";
  23. NSString *const ScreenCodeHomeView = @"Home Screen";
  24. NSString *const ScreenCodeCategory = @"Category Screen";
  25. NSString *const ScreenCodeCart = @"Cart Sceen";
  26. NSString *const ScreenCodeOrderList = @"Order History Screen";
  27. NSString *const ScreenCodeSearch = @"Search Screen";
  28. NSString *const ScreenCodeAccount = @"Account Screen";
  29. NSString *const ScreenCodeWishList = @"Wish List Screen";
  30. NSString *const ScreenCodePortfolio = @"Portfolio Screen";
  31. NSString *const ScreenCodeViewPortfolios = @"View Portfolios Screen";
  32. NSString *const ScreenCodeCamScan = @"Cam Scan Screen";
  33. NSString *const ScreenCodeScannerSetting = @"Scanner Setting Screen";
  34. NSString *const ScreenCodeOfflineSetting = @"Offline Setting Screen";
  35. NSString *const ScreenCodePlaceOrder = @"Place Order Screen";
  36. NSString *const ScreenCodeCustomerInfo = @"Customer Information Screen";
  37. NSString *const ScreenCodeNewCustomer = @"New Customer Screen";
  38. NSString *const ScreenCodeEditCustomer = @"Edit Customer Information Screen";
  39. NSString *const ScreenCodeModelInfo = @"Model Information Screen";
  40. NSString *const ScreenCodeOrderInfo = @"Order Information Screeen";
  41. NSString *const ScreenCodeUserSign = @"User Sign Screen";
  42. NSString *const ScreenCodeNewAddress = @"New Address Screen";
  43. NSString *const ScreenCodeAdvanceSearch = @"Account Advance Search Screen";
  44. NSString *const ScreenCodeCreatePortfolio = @"Create Portfolio Screen";
  45. NSString *const ScreenCodeParticularCategory = @"Particular Category Screen";
  46. NSString *const ScreenCodeEditPortfolio = @"Edit Portfolio Screen";
  47. NSString *const ScreenCodePriceSetting = @"Price Setting Screen";
  48. NSString *const ScreenCodeCategoryPrice = @"Category Price Screen";
  49. NSString *const ScreenCodeSetCatetoryPrice = @"Set Category Price Screen";
  50. NSString *const ScreenCodeUploadImage = @"Upload Image Screen";
  51. NSString *const ScreenCodeOfflineSync = @"Offline Sync Screen";
  52. @implementation RANetwork
  53. +(NSMutableDictionary*) prepare_additional_params:(NSMutableDictionary* ) params
  54. {
  55. AppDelegate *appDelegate = nil;
  56. //some UI methods ej
  57. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  58. // if(appDelegate.user!=nil)
  59. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.user key:@"usai"] forKey:@"user"];
  60. // if(appDelegate.password!=nil)
  61. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.password key:@"usai"] forKey:@"password"];
  62. //
  63. //
  64. //
  65. // if(appDelegate.user!=nil)
  66. // [params setValue:appDelegate.user forKey:@"user"];
  67. //
  68. // if(appDelegate.contact_id!=nil)
  69. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  70. // if(appDelegate.password!=nil)
  71. // [params setValue:appDelegate.password forKey:@"password"];
  72. //
  73. // [params setValue:appDelegate.build forKey:@"app_ver"];
  74. //
  75. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  76. // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  77. // [params setValue:short_version forKey:@"app_short_ver"];
  78. //
  79. //
  80. //
  81. //#if TARGET_IPHONE_SIMULATOR//模拟器
  82. // [params setValue:@"simulator_uuid" forKey:@"deviceid"];
  83. //#elif TARGET_OS_IPHONE//真机
  84. // UIDevice * dev = [UIDevice currentDevice];
  85. // NSUUID* uuid =dev.identifierForVendor;
  86. // [params setValue:uuid.UUIDString forKey:@"deviceid"];
  87. //#endif
  88. if(appDelegate.user!=nil && params[@"user"]==nil)
  89. [params setValue:appDelegate.user forKey:@"user"];
  90. if(appDelegate.password!=nil&& params[@"password"]==nil)
  91. [params setValue:appDelegate.password forKey:@"password"];
  92. if(appDelegate.ipad_perm!=nil)
  93. [params setValue:appDelegate.ipad_perm forKey:@"ipad_perm"];
  94. [params setValue:appDelegate.build forKey:@"app_ver"];
  95. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  96. NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  97. [params setValue:short_version forKey:@"app_short_ver"];
  98. #if TARGET_IPHONE_SIMULATOR//模拟器
  99. [params setValue:@"simulator_uuid" forKey:@"idfv"];
  100. #elif TARGET_OS_IPHONE//真机
  101. UIDevice * dev = [UIDevice currentDevice];
  102. NSUUID* uuid =dev.identifierForVendor;
  103. [params setValue:uuid.UUIDString forKey:@"idfv"];
  104. #endif
  105. //
  106. // NSString *userAction = [params valueForKey:kAction];
  107. // NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  108. // if ([userAction isEqualToString:@"Login"]) {
  109. // if (!extra) {
  110. // extra = [NSMutableDictionary dictionary];
  111. // }
  112. // [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  113. // }
  114. return params;
  115. }
  116. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString *) file //delegate:(id < NSURLConnectionDelegate >)delegate
  117. {
  118. // NSString* e=[AESCrypt AES128Encrypt:@"密码学中的高级加密标准(Advanced Encryption Standard,AES),又称 高级加密标准Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用。经过五年的甄选流程,高级加密标准由美国国家标准与技术研究院 (NIST)于2001年11月26日发布于FIPS PUB 197,并在2002年5月26日成为有效的标准。2006年,高级加密标准已然成为对称密钥加密中最流行的算法之一。 " key:@"usai2010"];
  119. // DebugLog(e);
  120. // NSString* d=[AESCrypt decrypt:@"VzB4+lENfbzWX7ggHh2Os1P69l5YBzKmM51yqA37AfoKgPY8bJgdK8M4WvF+wDyOsLWP\/o8H5+bHMivQp1u8wM2QV7SYzgzPwV85QKtYWIzEgLe9T0HO69EdutWz7k1rdAT\/mftsRin0Hy5SHk7txTZT\/zPH5X+FQiExCTFm5Zus39HYvp+VxCX4+kYeymn8B63AUd3mRQyscUvDjfgU2olKR\/TP8PV3g+VQMZxpKfol3P1iOtz3XQlHZV0pM6SAf+SwT0sPfrdn6CZFfNQlrKA9QjMrnBdMeSCquSIWXnmLv6okzvnlJnT0SjvJuUeqNdBC5EZ0ACnhI0MrXVZEsq1EuM9al7oPzvU5EZbjZpmx+fSFIkMzTT8bYClTnG1bsL1MCcU4pSODDorUj8zalA==" password:@"usai2010"];
  121. params = [self prepare_additional_params:params];
  122. DebugLog(@"\n++++++++++++++++++++++Request++++++++++++++++++++++\n%@\n++++++++++++++++++++++Params++++++++++++++++++++++\n%@\n",url,[RAConvertor dict2string:params]);
  123. return [super get_json:url parameters:params file:(NSString*)file err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  124. int result=[[jsobj valueForKey:@"result"] intValue];
  125. // UIApplication * app = [UIApplication sharedApplication];
  126. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  127. switch (result) {
  128. case 0:
  129. [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  130. break;
  131. case 1:
  132. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  133. break;
  134. case 2:
  135. [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  136. break;
  137. case 8:
  138. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  139. break;
  140. case 9:
  141. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  142. break;
  143. case 99:
  144. [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  145. break;
  146. default:
  147. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  148. break;
  149. }
  150. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  151. // {
  152. // [jsobj setValue:@"9" forKey:@"result"];
  153. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  154. // }
  155. return jsobj;
  156. } decrypt_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  157. return nil;
  158. // NSString* base64str = jsobj[@"str"];
  159. // NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"usai2010"];
  160. // jsobj=[[RAUtils string2dict:decryptstr] mutableCopy];
  161. // return jsobj;
  162. }];
  163. /*
  164. */
  165. return nil;
  166. }
  167. +(void) LoadImage:(NSString*) url into:(UIImageView*) container
  168. {
  169. DebugLog(@"LoadImage:(NSString*) url in:(UIImageView*) container");
  170. NSString* file_name=[url lastPathComponent];
  171. NSData* img_data = [iSalesDB load_cached_img:file_name loadFrom:url];
  172. if(img_data==nil)
  173. {
  174. DebugLog(@"IMG NOT CACHED %@",file_name);
  175. img_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
  176. [iSalesDB cache_img:img_data filename:file_name saveTo:url];
  177. //load from internet;
  178. }
  179. if(img_data!=nil)
  180. {
  181. UIImage * img =[UIImage imageWithData:img_data];
  182. if(img==nil)
  183. DebugLog(@"UIIMAGE IS NIL! %@",file_name);
  184. else
  185. dispatch_async(dispatch_get_main_queue(), ^{
  186. container.image =img;
  187. });
  188. }
  189. else
  190. {
  191. DebugLog(@"IMG DOWNLOAD FAILED! %@",file_name);
  192. }
  193. }
  194. //+(NSData*)fake_json:(NSString*) url
  195. //{
  196. // NSString* jsonfile = nil;
  197. // if([url isEqualToString:URL_UPDATE_AUTH])
  198. // {
  199. // jsonfile=@"login";
  200. //
  201. // }
  202. // else if([url isEqualToString:URL_REQUEST_CATMENU])
  203. // {
  204. // jsonfile=@"categorymenu";
  205. // }
  206. // else if([url isEqualToString:URL_LOAD_HOME])
  207. // {
  208. // jsonfile=@"homepage";
  209. // }
  210. // else if([url isEqualToString:URL_SEARCH])
  211. // {
  212. // jsonfile=@"search";
  213. // }
  214. // else if([url isEqualToString:URL_CATEGORY_LOADMORE])
  215. // {
  216. // jsonfile=@"category_more";
  217. // }else if([url isEqualToString:URL_ITEM_DETAIL])
  218. // {
  219. // jsonfile=@"detail";
  220. // }else if([url isEqualToString:URL_CART])
  221. // {
  222. // jsonfile=@"cart";
  223. // }else if([url isEqualToString:URL_ORDER_LIST])
  224. // {
  225. // jsonfile=@"orderlist";
  226. // }
  227. //// else if([url isEqualToString:URL_ORDER_INFO])
  228. //// {
  229. //// jsonfile=@"orderinfo";
  230. //// }
  231. //// else if([url isEqualToString:URL_ORDER_INFO])
  232. //// {
  233. //// jsonfile=@"orderinfo2label";
  234. //// }
  235. //
  236. //
  237. //
  238. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:jsonfile ofType:@"json" ]];
  239. // NSMutableString *result = [[NSMutableString alloc] initWithData:json encoding:NSUTF8StringEncoding];
  240. //
  241. // DebugLog(@"result: \n%@",result);
  242. // return json;
  243. //}
  244. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
  245. {
  246. NSString *userAction = [params valueForKey:kAction];
  247. NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  248. if ([userAction isEqualToString:@"Login"]) {
  249. if (!extra) {
  250. extra = [NSMutableDictionary dictionary];
  251. }
  252. [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  253. }
  254. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  255. NSString *screenName = [params valueForKey:kScreenName];
  256. [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  257. #endif
  258. return [self get_json:url parameters:params file:nil];
  259. }
  260. //+(NSDictionary*)request_Editor:(NSString*) sourceid editor:(NSString*)editor
  261. //{
  262. //
  263. //}
  264. +(NSDictionary*) delete_portfoliolist:(NSString* ) listid
  265. {
  266. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  267. __block AppDelegate *appDelegate = nil;
  268. dispatch_sync(dispatch_get_main_queue(), ^{
  269. //some UI methods ej
  270. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  271. });
  272. if(appDelegate.user!=nil)
  273. [params setValue:appDelegate.user forKey:@"user"];
  274. if(appDelegate.contact_id!=nil)
  275. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  276. if(appDelegate.password!=nil)
  277. [params setValue:appDelegate.password forKey:@"password"];
  278. [params setValue:listid forKey:@"tearsheetsId"];
  279. // [params setValue:editor forKey:@"editor"];
  280. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  281. // [params setValue:@"Delete Portfolio" forKey:kAction];
  282. NSData* json = nil;
  283. if(appDelegate.offline_mode)
  284. {
  285. json = [OLDataProvider offline_removePDF:params];
  286. } else {
  287. if(![self IsNetworkAvailable])
  288. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  289. json=[self get_json:URL_PORTFOLIOLIST_REMOVE parameters:params];
  290. }
  291. if(json!=nil)
  292. {
  293. NSError *error=nil;
  294. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  295. return jsobj;
  296. }
  297. else
  298. return nil;
  299. }
  300. +(NSDictionary*) portfolio_remove:(NSString* ) item_ids
  301. {
  302. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  303. __block AppDelegate *appDelegate = nil;
  304. dispatch_sync(dispatch_get_main_queue(), ^{
  305. //some UI methods ej
  306. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  307. });
  308. if(appDelegate.user!=nil)
  309. [params setValue:appDelegate.user forKey:@"user"];
  310. if(appDelegate.contact_id!=nil)
  311. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  312. if(appDelegate.password!=nil)
  313. [params setValue:appDelegate.password forKey:@"password"];
  314. [params setValue:item_ids forKey:@"portfolioId"];
  315. // [params setValue:editor forKey:@"editor"];
  316. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  317. NSData* json = nil;
  318. if(appDelegate.offline_mode)
  319. {
  320. json = [OLDataProvider offline_removePortfolio:params];
  321. } else {
  322. if(![self IsNetworkAvailable])
  323. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  324. json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  325. }
  326. if(json!=nil)
  327. {
  328. NSError *error=nil;
  329. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  330. int result = [[jsobj valueForKey:@"result"] intValue];
  331. if (result==2)
  332. {
  333. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  334. [appDelegate update_count_mark];
  335. }
  336. return jsobj;
  337. }
  338. else
  339. return nil;
  340. }
  341. //+(NSDictionary*) watchlist_remove:(NSString* ) item_ids
  342. //{
  343. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  344. // __block AppDelegate *appDelegate = nil;
  345. //
  346. // dispatch_sync(dispatch_get_main_queue(), ^{
  347. // //some UI methods ej
  348. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  349. // });
  350. // if(appDelegate.user!=nil)
  351. // [params setValue:appDelegate.user forKey:@"user"];
  352. // if(appDelegate.contact_id!=nil)
  353. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  354. // if(appDelegate.password!=nil)
  355. // [params setValue:appDelegate.password forKey:@"password"];
  356. // [params setValue:item_ids forKey:@"collectId"];
  357. // // [params setValue:editor forKey:@"editor"];
  358. //
  359. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  360. //
  361. // if(appDelegate.offline_mode)
  362. // {
  363. // return [OLDataProvider offline_deletewishlist:params];
  364. // }
  365. // if(![self IsNetworkAvailable])
  366. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  367. //
  368. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  369. // if(json!=nil)
  370. // {
  371. // NSError *error=nil;
  372. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  373. // int result = [[jsobj valueForKey:@"result"] intValue];
  374. //
  375. // if (result==2)
  376. // {
  377. //
  378. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  379. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  380. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  381. //
  382. // [appDelegate update_count_mark];
  383. // }
  384. // return jsobj;
  385. // }
  386. // else
  387. // return nil;
  388. //}
  389. //+(NSDictionary*) move_cart2wish:(NSString* ) item_ids
  390. //{
  391. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  392. // __block AppDelegate *appDelegate = nil;
  393. //
  394. // dispatch_sync(dispatch_get_main_queue(), ^{
  395. // //some UI methods ej
  396. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  397. // });
  398. // if(appDelegate.user!=nil)
  399. // [params setValue:appDelegate.user forKey:@"user"];
  400. // if(appDelegate.contact_id!=nil)
  401. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  402. // if(appDelegate.password!=nil)
  403. // [params setValue:appDelegate.password forKey:@"password"];
  404. // if(appDelegate.order_code!=nil)
  405. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  406. // [params setValue:item_ids forKey:@"cartItemId"];
  407. // // [params setValue:editor forKey:@"editor"];
  408. //
  409. // [params setValue:ScreenCodeCart forKey:kScreenName];
  410. // // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  411. //
  412. // NSData* json = nil;
  413. // if(appDelegate.offline_mode)
  414. // {
  415. // json= [OLDataProvider offline_movecart2wish:params];
  416. // }
  417. // else
  418. // {
  419. // if(![self IsNetworkAvailable])
  420. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  421. //
  422. // json=[self get_json:URL_CART2WISH parameters:params];
  423. // }
  424. // if(json!=nil)
  425. // {
  426. // NSError *error=nil;
  427. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  428. // int result = [[jsobj valueForKey:@"result"] intValue];
  429. //
  430. // if (result==2)
  431. // {
  432. //
  433. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  434. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  435. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  436. //
  437. // [appDelegate update_count_mark];
  438. // }
  439. // return jsobj;
  440. // }
  441. // else
  442. // return nil;
  443. //}
  444. //+(NSDictionary*) move_wish2cart:(NSString* ) item_ids
  445. //{
  446. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  447. // __block AppDelegate *appDelegate = nil;
  448. //
  449. // dispatch_sync(dispatch_get_main_queue(), ^{
  450. // //some UI methods ej
  451. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  452. // });
  453. // if(appDelegate.user!=nil)
  454. // [params setValue:appDelegate.user forKey:@"user"];
  455. // if(appDelegate.contact_id!=nil)
  456. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  457. // if(appDelegate.password!=nil)
  458. // [params setValue:appDelegate.password forKey:@"password"];
  459. // if(appDelegate.order_code!=nil)
  460. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  461. // [params setValue:item_ids forKey:@"collectId"];
  462. // // [params setValue:editor forKey:@"editor"];
  463. //
  464. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  465. // [params setValue:@"Move To Cart" forKey:kAction];
  466. //
  467. // NSData *json = nil;
  468. // if(appDelegate.offline_mode)
  469. // {
  470. // json = [OLDataProvider offline_movewish2cart:params];
  471. // } else {
  472. // if(![self IsNetworkAvailable])
  473. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  474. //
  475. // json=[self get_json:URL_WISH2CART parameters:params];
  476. // }
  477. //
  478. // if(json!=nil)
  479. // {
  480. // NSError *error=nil;
  481. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  482. // int result = [[jsobj valueForKey:@"result"] intValue];
  483. //
  484. // if (result==2)
  485. // {
  486. //
  487. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  488. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  489. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  490. //
  491. // [appDelegate update_count_mark];
  492. // }
  493. // return jsobj;
  494. // }
  495. // else
  496. // return nil;
  497. //}
  498. //+(NSDictionary*) cart_remove:(NSString* ) item_ids
  499. //{
  500. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  501. // __block AppDelegate *appDelegate = nil;
  502. //
  503. // dispatch_sync(dispatch_get_main_queue(), ^{
  504. // //some UI methods ej
  505. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  506. // });
  507. // if(appDelegate.user!=nil)
  508. // [params setValue:appDelegate.user forKey:@"user"];
  509. // if(appDelegate.contact_id!=nil)
  510. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  511. // if(appDelegate.password!=nil)
  512. // [params setValue:appDelegate.password forKey:@"password"];
  513. //
  514. // if(appDelegate.order_code!=nil)
  515. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  516. // [params setValue:item_ids forKey:@"cartItemId"];
  517. // // [params setValue:editor forKey:@"editor"];
  518. //
  519. // [params setValue:ScreenCodeCart forKey:kScreenName];
  520. // // [params setValue:@"" forKey:kAction];
  521. //
  522. // NSData* json=nil;
  523. // if(appDelegate.offline_mode)
  524. // {
  525. // json= [OLDataProvider offline_cartremove:params];
  526. // }
  527. // else
  528. // {
  529. // if(![self IsNetworkAvailable])
  530. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  531. //
  532. // json=[self get_json:URL_CART_REMOVE parameters:params];
  533. // }
  534. // if(json!=nil)
  535. // {
  536. // NSError *error=nil;
  537. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  538. //
  539. // int result = [[jsobj valueForKey:@"result"] intValue];
  540. //
  541. // if (result==2)
  542. // {
  543. //
  544. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  545. //
  546. //
  547. // [appDelegate update_count_mark];
  548. // }
  549. // return jsobj;
  550. // }
  551. // else
  552. // return nil;
  553. //}
  554. //+(NSDictionary*) cart_check:(NSString* ) item_ids
  555. //{
  556. // return nil;
  557. // if(![self IsNetworkAvailable])
  558. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  559. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  560. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  561. // if(appDelegate.user!=nil)
  562. // [params setValue:appDelegate.user forKey:@"user"];
  563. // if(appDelegate.contact_id!=nil)
  564. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  565. // if(appDelegate.password!=nil)
  566. // [params setValue:appDelegate.password forKey:@"password"];
  567. // [params setValue:item_ids forKey:@"cartItemId"];
  568. // // [params setValue:editor forKey:@"editor"];
  569. // if(appDelegate.offline_mode)
  570. // {
  571. // return [OLDataProvider offline_notimpl];
  572. // }
  573. // NSData* json=[self get_json:URL_CART_CHECK parameters:params];
  574. // if(json!=nil)
  575. // {
  576. // NSError *error=nil;
  577. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  578. // return jsobj;
  579. // }
  580. // else
  581. // return nil;
  582. //}
  583. +(NSDictionary*)create_Address:(NSMutableDictionary*)params
  584. {
  585. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  586. __block AppDelegate *appDelegate = nil;
  587. dispatch_sync(dispatch_get_main_queue(), ^{
  588. //some UI methods ej
  589. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  590. });
  591. if(appDelegate.user!=nil)
  592. [params setValue:appDelegate.user forKey:@"user"];
  593. if(appDelegate.contact_id!=nil)
  594. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  595. if(appDelegate.password!=nil)
  596. [params setValue:appDelegate.password forKey:@"password"];
  597. // [params setValue:sourceid forKey:@"sourceid"];
  598. // [params setValue:editor forKey:@"editor"];
  599. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  600. NSData* json=nil;
  601. if(appDelegate.offline_mode)
  602. {
  603. json= [OLDataProvider offline_saveaddr:params];
  604. }
  605. else
  606. {
  607. if(![self IsNetworkAvailable])
  608. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  609. json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  610. }
  611. if(json!=nil)
  612. {
  613. NSError *error=nil;
  614. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  615. return jsobj;
  616. }
  617. else
  618. return nil;
  619. }
  620. +(NSDictionary*)copy_Order:(NSString*) order_code
  621. {
  622. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  623. __block AppDelegate *appDelegate = nil;
  624. dispatch_sync(dispatch_get_main_queue(), ^{
  625. //some UI methods ej
  626. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  627. });
  628. if(appDelegate.user!=nil)
  629. [params setValue:appDelegate.user forKey:@"user"];
  630. if(appDelegate.contact_id!=nil)
  631. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  632. if(appDelegate.password!=nil)
  633. [params setValue:appDelegate.password forKey:@"password"];
  634. // NSString* ssaved = @"false";
  635. // if(saved)
  636. // ssaved=@"true";
  637. // [params setValue:@"true" forKey:@"saved"];
  638. [params setValue:order_code forKey:@"code"];
  639. // [params setValue:sourceid forKey:@"sourceid"];
  640. // [params setValue:editor forKey:@"editor"];
  641. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  642. NSData* json=nil;
  643. if(appDelegate.offline_mode)
  644. {
  645. json= [OLDataProvider offline_copyorder:params];
  646. }
  647. else
  648. {
  649. if(![self IsNetworkAvailable])
  650. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  651. json=[self get_json:URL_COPY_ORDER parameters:params];
  652. }
  653. if(json!=nil)
  654. {
  655. NSError *error=nil;
  656. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  657. return jsobj;
  658. }
  659. else
  660. return nil;
  661. }
  662. +(NSDictionary*)sign_Order:(NSString*) order_code path:(NSString*)path
  663. {
  664. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  665. __block AppDelegate *appDelegate = nil;
  666. dispatch_sync(dispatch_get_main_queue(), ^{
  667. //some UI methods ej
  668. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  669. });
  670. if(appDelegate.user!=nil)
  671. [params setValue:appDelegate.user forKey:@"user"];
  672. if(appDelegate.contact_id!=nil)
  673. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  674. if(appDelegate.password!=nil)
  675. [params setValue:appDelegate.password forKey:@"password"];
  676. // NSString* ssaved = @"false";
  677. // if(saved)
  678. // ssaved=@"true";
  679. // [params setValue:@"true" forKey:@"saved"];
  680. [params setValue:order_code forKey:@"orderCode"];
  681. [params setValue:path forKey:@"picpath"];
  682. // [params setValue:sourceid forKey:@"sourceid"];
  683. // [params setValue:editor forKey:@"editor"];
  684. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  685. NSData* json=nil;
  686. if(appDelegate.offline_mode)
  687. {
  688. json= [OLDataProvider offline_signorder:params];
  689. }
  690. else
  691. {
  692. if(![self IsNetworkAvailable])
  693. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  694. json=[self get_json:URL_SIGN_ORDER parameters:params];
  695. }
  696. if(json!=nil)
  697. {
  698. NSError *error=nil;
  699. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  700. return jsobj;
  701. }
  702. else
  703. return nil;
  704. }
  705. +(NSDictionary*)commit_Order:(NSString*) order_code //saved:(bool) saved
  706. {
  707. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  708. __block AppDelegate *appDelegate = nil;
  709. dispatch_sync(dispatch_get_main_queue(), ^{
  710. //some UI methods ej
  711. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  712. });
  713. if(appDelegate.user!=nil)
  714. [params setValue:appDelegate.user forKey:@"user"];
  715. if(appDelegate.contact_id!=nil)
  716. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  717. if(appDelegate.password!=nil)
  718. [params setValue:appDelegate.password forKey:@"password"];
  719. // NSString* ssaved = @"false";
  720. // if(saved)
  721. // ssaved=@"true";
  722. [params setValue:@"true" forKey:@"saved"];
  723. [params setValue:order_code forKey:@"orderCode"];
  724. // [params setValue:sourceid forKey:@"sourceid"];
  725. // [params setValue:editor forKey:@"editor"];
  726. [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  727. NSData* json = nil;
  728. if(appDelegate.offline_mode)
  729. {
  730. json= [OLDataProvider offline_submitorder:params];
  731. }
  732. else
  733. {
  734. if(![self IsNetworkAvailable])
  735. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  736. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  737. }
  738. if(json!=nil)
  739. {
  740. NSError *error=nil;
  741. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  742. return jsobj;
  743. }
  744. else
  745. return nil;
  746. }
  747. //+(NSDictionary*)open_Order:(NSString*) order_code
  748. //{
  749. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  750. // __block AppDelegate *appDelegate = nil;
  751. //
  752. // dispatch_sync(dispatch_get_main_queue(), ^{
  753. // //some UI methods ej
  754. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  755. // });
  756. // if(appDelegate.user!=nil)
  757. // [params setValue:appDelegate.user forKey:@"user"];
  758. // // if(appDelegate.contact_id!=nil)
  759. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  760. // if(appDelegate.password!=nil)
  761. // [params setValue:appDelegate.password forKey:@"password"];
  762. //
  763. // [params setValue:order_code forKey:@"orderCode"];
  764. // // [params setValue:sourceid forKey:@"sourceid"];
  765. // // [params setValue:editor forKey:@"editor"];
  766. //
  767. // [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  768. //
  769. // NSData* json=nil;
  770. // if(appDelegate.offline_mode)
  771. // {
  772. // json=[OLDataProvider offline_editorder:params];
  773. //
  774. // }
  775. // else
  776. // {
  777. // if(![self IsNetworkAvailable])
  778. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  779. //
  780. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  781. // }
  782. // if(json!=nil)
  783. // {
  784. // NSError *error=nil;
  785. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  786. // int result = [[jsobj valueForKey:@"result"] intValue];
  787. //
  788. // if (result==2)
  789. // {
  790. //
  791. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  792. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  793. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  794. //
  795. // [appDelegate update_count_mark];
  796. //
  797. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  798. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  799. // }
  800. //
  801. // }
  802. //
  803. // return jsobj;
  804. // }
  805. // else
  806. // return nil;
  807. //}
  808. +(NSDictionary*)delete_Order:(NSString*) order_id
  809. {
  810. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  811. __block AppDelegate *appDelegate = nil;
  812. dispatch_sync(dispatch_get_main_queue(), ^{
  813. //some UI methods ej
  814. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  815. });
  816. if(appDelegate.user!=nil)
  817. [params setValue:appDelegate.user forKey:@"user"];
  818. // if(appDelegate.contact_id!=nil)
  819. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  820. if(appDelegate.password!=nil)
  821. [params setValue:appDelegate.password forKey:@"password"];
  822. [params setValue:order_id forKey:@"orderId"];
  823. // [params setValue:sourceid forKey:@"sourceid"];
  824. // [params setValue:editor forKey:@"editor"];
  825. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  826. if(appDelegate.offline_mode)
  827. {
  828. return [OLDataProvider offline_notimpl];
  829. }
  830. if(![self IsNetworkAvailable])
  831. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  832. NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  833. if(json!=nil)
  834. {
  835. NSError *error=nil;
  836. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  837. return jsobj;
  838. }
  839. else
  840. return nil;
  841. }
  842. +(NSDictionary*)cancel_Order:(NSString*) order_id order_code:(NSString*) order_code
  843. {
  844. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  845. __block AppDelegate *appDelegate = nil;
  846. dispatch_sync(dispatch_get_main_queue(), ^{
  847. //some UI methods ej
  848. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  849. });
  850. if(appDelegate.user!=nil)
  851. [params setValue:appDelegate.user forKey:@"user"];
  852. // if(appDelegate.contact_id!=nil)
  853. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  854. if(appDelegate.password!=nil)
  855. [params setValue:appDelegate.password forKey:@"password"];
  856. [params setValue:order_id forKey:@"orderId"];
  857. [params setValue:order_code forKey:@"orderCode"];
  858. // [params setValue:sourceid forKey:@"sourceid"];
  859. // [params setValue:editor forKey:@"editor"];
  860. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  861. NSData* json=nil;
  862. if(appDelegate.offline_mode)
  863. {
  864. json=[OLDataProvider offline_cancelorder:params];
  865. }
  866. else
  867. {
  868. if(![self IsNetworkAvailable])
  869. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  870. json=[self get_json:URL_CANCEL_ORDER parameters:params];
  871. }
  872. if(json!=nil)
  873. {
  874. NSError *error=nil;
  875. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  876. return jsobj;
  877. }
  878. else
  879. return nil;
  880. }
  881. +(NSDictionary*)release_Order:(NSString*) order_code withScreen:(NSString *)screenName
  882. {
  883. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  884. __block AppDelegate *appDelegate = nil;
  885. dispatch_sync(dispatch_get_main_queue(), ^{
  886. //some UI methods ej
  887. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  888. });
  889. if(appDelegate.user!=nil)
  890. [params setValue:appDelegate.user forKey:@"user"];
  891. // if(appDelegate.contact_id!=nil)
  892. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  893. if(appDelegate.password!=nil)
  894. [params setValue:appDelegate.password forKey:@"password"];
  895. [params setValue:order_code forKey:@"orderCode"];
  896. // [params setValue:sourceid forKey:@"sourceid"];
  897. // [params setValue:editor forKey:@"editor"];
  898. if (screenName) {
  899. [params setValue:screenName forKey:kScreenName];
  900. }
  901. NSData* json=nil;
  902. if(appDelegate.offline_mode)
  903. {
  904. json= [OLDataProvider offline_resetorder:params];
  905. }
  906. else
  907. {
  908. if(![self IsNetworkAvailable])
  909. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  910. json=[self get_json:URL_RELEASE_ORDER parameters:params];
  911. }
  912. if(json!=nil)
  913. {
  914. NSError *error=nil;
  915. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  916. if([[jsobj valueForKey:@"result"]intValue]==2)
  917. { [appDelegate SetSo:nil];
  918. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  919. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  920. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  921. [appDelegate update_count_mark];
  922. }
  923. return jsobj;
  924. }
  925. else
  926. return nil;
  927. }
  928. +(NSDictionary*)update_OrderCustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info
  929. {
  930. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  931. __block AppDelegate *appDelegate = nil;
  932. dispatch_sync(dispatch_get_main_queue(), ^{
  933. //some UI methods ej
  934. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  935. });
  936. if(appDelegate.user!=nil)
  937. [info setValue:appDelegate.user forKey:@"user"];
  938. // if(appDelegate.contact_id!=nil)
  939. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  940. if(appDelegate.password!=nil)
  941. [info setValue:appDelegate.password forKey:@"password"];
  942. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  943. [info setValue:order_code forKey:@"orderCode"];
  944. // [params setValue:sourceid forKey:@"sourceid"];
  945. // [params setValue:editor forKey:@"editor"];
  946. if(appDelegate.offline_mode)
  947. {
  948. return [OLDataProvider offline_notimpl];
  949. }
  950. if(![self IsNetworkAvailable])
  951. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  952. NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  953. if(json!=nil)
  954. {
  955. NSError *error=nil;
  956. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  957. return jsobj;
  958. }
  959. else
  960. return nil;
  961. }
  962. //+(NSDictionary*)commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url
  963. //{
  964. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  965. // __block AppDelegate *appDelegate = nil;
  966. //
  967. // dispatch_sync(dispatch_get_main_queue(), ^{
  968. // //some UI methods ej
  969. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  970. // });
  971. // if(appDelegate.user!=nil)
  972. // [params setValue:appDelegate.user forKey:@"user"];
  973. // if(appDelegate.contact_id!=nil)
  974. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  975. // if(appDelegate.password!=nil)
  976. // [params setValue:appDelegate.password forKey:@"password"];
  977. //
  978. // // if(appDelegate.order_code!=nil)
  979. // // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  980. //
  981. // // NSDictionary* customerinfo= appDelegate.customerInfo;
  982. // //
  983. // // NSArray* keys=[customerinfo allKeys];
  984. // // for(int i=0;i<keys.count;i++)
  985. // // {
  986. // // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  987. // // }
  988. // //
  989. // // [params setValue:sourceid forKey:@"sourceid"];
  990. // // [params setValue:editor forKey:@"editor"];
  991. //
  992. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  993. //
  994. // if(appDelegate.offline_mode)
  995. // {
  996. // params[@"offline_Command"]=url;
  997. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  998. // }
  999. //
  1000. // if(![self IsNetworkAvailable])
  1001. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1002. //
  1003. // NSData* json=[self get_json:url parameters:params];
  1004. // if(json!=nil)
  1005. // {
  1006. // NSError *error=nil;
  1007. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1008. // if([[jsobj valueForKey:@"result"]intValue]==2)
  1009. // [appDelegate SetSo:nil];
  1010. //
  1011. //
  1012. // return jsobj;
  1013. // }
  1014. // else
  1015. // return nil;
  1016. //}
  1017. +(NSDictionary*)saveandcommit_Order:(NSMutableDictionary*)params
  1018. {
  1019. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1020. __block AppDelegate *appDelegate = nil;
  1021. dispatch_sync(dispatch_get_main_queue(), ^{
  1022. //some UI methods ej
  1023. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1024. });
  1025. if(appDelegate.user!=nil)
  1026. [params setValue:appDelegate.user forKey:@"user"];
  1027. if(appDelegate.contact_id!=nil)
  1028. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1029. if(appDelegate.password!=nil)
  1030. [params setValue:appDelegate.password forKey:@"password"];
  1031. if(appDelegate.order_code!=nil)
  1032. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1033. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1034. //
  1035. // NSArray* keys=[customerinfo allKeys];
  1036. // for(int i=0;i<keys.count;i++)
  1037. // {
  1038. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1039. // }
  1040. //
  1041. // [params setValue:sourceid forKey:@"sourceid"];
  1042. // [params setValue:editor forKey:@"editor"];
  1043. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1044. NSData* json=nil;
  1045. if(appDelegate.offline_mode)
  1046. {
  1047. json=[OLDataProvider offline_submitorder:params];
  1048. }
  1049. else
  1050. {
  1051. if(![self IsNetworkAvailable])
  1052. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1053. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  1054. }
  1055. if(json!=nil)
  1056. {
  1057. NSError *error=nil;
  1058. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1059. if([[jsobj valueForKey:@"result"]intValue]==2)
  1060. [appDelegate SetSo:nil];
  1061. return jsobj;
  1062. }
  1063. else
  1064. return nil;
  1065. }
  1066. +(NSDictionary*)update_Customer:(NSMutableDictionary*)params
  1067. {
  1068. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1069. __block AppDelegate *appDelegate = nil;
  1070. dispatch_sync(dispatch_get_main_queue(), ^{
  1071. //some UI methods ej
  1072. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1073. });
  1074. if(appDelegate.user!=nil)
  1075. [params setValue:appDelegate.user forKey:@"user"];
  1076. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1077. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1078. // else
  1079. if(appDelegate.contact_id!=nil)
  1080. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1081. if(appDelegate.password!=nil)
  1082. [params setValue:appDelegate.password forKey:@"password"];
  1083. // NSDictionary* customerinfo=nil;
  1084. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1085. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1086. // else
  1087. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1088. //
  1089. // appDelegate.customerInfo;
  1090. // NSArray* keys=[customerinfo allKeys];
  1091. // for(int i=0;i<keys.count;i++)
  1092. // {
  1093. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1094. // }
  1095. // [params setValue:sourceid forKey:@"sourceid"];
  1096. // [params setValue:editor forKey:@"editor"];
  1097. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1098. NSData* json=nil;
  1099. if(appDelegate.offline_mode)
  1100. {
  1101. json= [OLDataProvider offline_saveContact:params];
  1102. }
  1103. else
  1104. {
  1105. if(![self IsNetworkAvailable])
  1106. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1107. json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  1108. }
  1109. if(json!=nil)
  1110. {
  1111. NSError *error=nil;
  1112. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1113. return jsobj;
  1114. }
  1115. else
  1116. return nil;
  1117. }
  1118. +(NSDictionary*)save_newCustomer:(NSMutableDictionary*)params
  1119. {
  1120. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1121. __block AppDelegate *appDelegate = nil;
  1122. dispatch_sync(dispatch_get_main_queue(), ^{
  1123. //some UI methods ej
  1124. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1125. });
  1126. if(appDelegate.user!=nil)
  1127. [params setValue:appDelegate.user forKey:@"user"];
  1128. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1129. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1130. // else
  1131. if(appDelegate.contact_id!=nil)
  1132. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1133. if(appDelegate.password!=nil)
  1134. [params setValue:appDelegate.password forKey:@"password"];
  1135. // NSDictionary* customerinfo=nil;
  1136. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1137. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1138. // else
  1139. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1140. //
  1141. // appDelegate.customerInfo;
  1142. // NSArray* keys=[customerinfo allKeys];
  1143. // for(int i=0;i<keys.count;i++)
  1144. // {
  1145. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1146. // }
  1147. // [params setValue:sourceid forKey:@"sourceid"];
  1148. // [params setValue:editor forKey:@"editor"];
  1149. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1150. NSData* json=nil;
  1151. if(appDelegate.offline_mode)
  1152. {
  1153. json= [OLDataProvider offline_saveNewContact:params];
  1154. }
  1155. else
  1156. {
  1157. if(![self IsNetworkAvailable])
  1158. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1159. json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  1160. }
  1161. if(json!=nil)
  1162. {
  1163. NSError *error=nil;
  1164. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1165. return jsobj;
  1166. }
  1167. else
  1168. return nil;
  1169. }
  1170. +(NSDictionary*)save_Order:(NSMutableDictionary*)params
  1171. {
  1172. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1173. __block AppDelegate *appDelegate = nil;
  1174. dispatch_sync(dispatch_get_main_queue(), ^{
  1175. //some UI methods ej
  1176. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1177. });
  1178. if(appDelegate.user!=nil)
  1179. [params setValue:appDelegate.user forKey:@"user"];
  1180. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1181. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1182. // else
  1183. if(appDelegate.contact_id!=nil)
  1184. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1185. if(appDelegate.password!=nil)
  1186. [params setValue:appDelegate.password forKey:@"password"];
  1187. if(appDelegate.order_code!=nil)
  1188. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1189. // NSDictionary* customerinfo=nil;
  1190. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1191. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1192. // else
  1193. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1194. //
  1195. // appDelegate.customerInfo;
  1196. // NSArray* keys=[customerinfo allKeys];
  1197. // for(int i=0;i<keys.count;i++)
  1198. // {
  1199. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1200. // }
  1201. // [params setValue:sourceid forKey:@"sourceid"];
  1202. // [params setValue:editor forKey:@"editor"];
  1203. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1204. NSData* json=nil;
  1205. if(appDelegate.offline_mode)
  1206. {
  1207. json= [OLDataProvider offline_saveorder:params];
  1208. }
  1209. else
  1210. {
  1211. if(![self IsNetworkAvailable])
  1212. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1213. json=[self get_json:URL_SAVE_ORDER parameters:params];
  1214. }
  1215. if(json!=nil)
  1216. {
  1217. NSError *error=nil;
  1218. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1219. NSString *so = [jsobj valueForKey:@"so#"];
  1220. if (so) {
  1221. [appDelegate SetSo:so];
  1222. }
  1223. return jsobj;
  1224. }
  1225. else
  1226. return nil;
  1227. }
  1228. //+(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
  1229. //{
  1230. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1231. // __block AppDelegate *appDelegate = nil;
  1232. //
  1233. // dispatch_sync(dispatch_get_main_queue(), ^{
  1234. // //some UI methods ej
  1235. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1236. // });
  1237. // if(appDelegate.user!=nil)
  1238. // [params setValue:appDelegate.user forKey:@"user"];
  1239. //
  1240. //
  1241. // // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1242. // // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1243. // // else
  1244. //
  1245. // if(appDelegate.contact_id!=nil)
  1246. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1247. // if(appDelegate.password!=nil)
  1248. // [params setValue:appDelegate.password forKey:@"password"];
  1249. //
  1250. // if(appDelegate.order_code!=nil)
  1251. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1252. // // [params setValue:sourceid forKey:@"sourceid"];
  1253. // // [params setValue:editor forKey:@"editor"];
  1254. // DebugLog(@"request editor url:%@",request_url);
  1255. //
  1256. //
  1257. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1258. // {
  1259. // [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1260. // }
  1261. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1262. // {
  1263. // [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1264. // }
  1265. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1266. // {
  1267. // [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  1268. // }
  1269. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1270. // {
  1271. // [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1272. // }
  1273. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1274. // {
  1275. // [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  1276. // }
  1277. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1278. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1279. // }
  1280. //
  1281. // NSData* json = nil;
  1282. // if(appDelegate.offline_mode)
  1283. // {
  1284. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1285. // {
  1286. // json= [OLDataProvider offline_createContact:params];
  1287. // }
  1288. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1289. // {
  1290. // json= [OLDataProvider offline_editContact:params];
  1291. // }
  1292. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1293. // {
  1294. // json= [OLDataProvider offline_contactAdvancedSearch:params];
  1295. // }
  1296. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1297. // {
  1298. // json= [OLDataProvider offline_placeorder:params];
  1299. // }
  1300. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1301. // {
  1302. // json= [OLDataProvider offline_addreditor:params];
  1303. // }
  1304. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1305. // json = [OLDataProvider offline_createTearSheet:params];
  1306. // }
  1307. //
  1308. // else
  1309. // return [OLDataProvider offline_notimpl];
  1310. // }
  1311. // else
  1312. // {
  1313. // if(![self IsNetworkAvailable])
  1314. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1315. //
  1316. // if([request_url isEqualToString:URL_CARTDELIVERY])
  1317. // {
  1318. // NSError *error=nil;
  1319. //
  1320. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1321. // params[@"resultSerial"]=uuid;
  1322. //
  1323. // for(int i=0;i<150;i++)
  1324. // {
  1325. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1326. // // result_params[@"resultSerial"]=uuid;
  1327. // json=[self get_json:request_url parameters:params];
  1328. // if(json!=nil)
  1329. // {
  1330. //
  1331. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1332. // if([jsobj[@"result"] intValue]==2 || [jsobj[@"result"] intValue] == 8)
  1333. // {
  1334. // break;
  1335. // }
  1336. // }
  1337. // sleep(2);
  1338. // }
  1339. // }
  1340. // else
  1341. // json =[self get_json:request_url parameters:params];
  1342. // }
  1343. // if(json!=nil)
  1344. // {
  1345. // NSError *error=nil;
  1346. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1347. // return jsobj;
  1348. // }
  1349. // else
  1350. // return nil;
  1351. //}
  1352. //+(NSDictionary*)request_OrderInfo:(NSString*) orderid
  1353. //{
  1354. // if(![self IsNetworkAvailable])
  1355. // return nil;
  1356. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1357. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1358. // if(appDelegate.user!=nil)
  1359. // [params setValue:appDelegate.user forKey:@"user"];
  1360. // if(appDelegate.password!=nil)
  1361. // [params setValue:appDelegate.password forKey:@"password"];
  1362. // [params setValue:orderid forKey:@"orderid"];
  1363. // NSData* json=[self get_json:URL_ORDER_INFO parameters:params];
  1364. // NSError *error=nil;
  1365. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1366. // return jsobj;
  1367. //}
  1368. +(NSDictionary*)request_OrderList:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged
  1369. {
  1370. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1371. __block AppDelegate *appDelegate = nil;
  1372. dispatch_sync(dispatch_get_main_queue(), ^{
  1373. //some UI methods ej
  1374. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1375. });
  1376. if(appDelegate.user!=nil)
  1377. [params setValue:appDelegate.user forKey:@"user"];
  1378. if(appDelegate.contact_id!=nil)
  1379. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1380. if(appDelegate.password!=nil)
  1381. [params setValue:appDelegate.password forKey:@"password"];
  1382. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1383. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1384. [params setValue:keywords forKey:@"keyWord"];
  1385. [params setValue:customer forKey:@"customer_filter"];
  1386. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  1387. [params setValue:status_code forKey:@"orderStatus"];
  1388. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1389. if (keywords) {
  1390. [params setObject:@"Search" forKey:kAction];
  1391. }
  1392. NSData* json=nil;
  1393. if(appDelegate.offline_mode)
  1394. {
  1395. json= [OLDataProvider offline_orderlist:params];
  1396. }
  1397. else
  1398. {
  1399. if(![self IsNetworkAvailable])
  1400. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1401. json=[self get_json:URL_ORDER_LIST parameters:params];
  1402. }
  1403. if(json==nil)
  1404. return nil;
  1405. NSError *error=nil;
  1406. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1407. return jsobj;
  1408. }
  1409. +(NSDictionary*)request_PDFList:(int ) offset limit:(int)limit keywords:(NSString* ) keywords
  1410. {
  1411. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1412. __block AppDelegate *appDelegate = nil;
  1413. dispatch_sync(dispatch_get_main_queue(), ^{
  1414. //some UI methods ej
  1415. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1416. });
  1417. if(appDelegate.user!=nil)
  1418. [params setValue:appDelegate.user forKey:@"user"];
  1419. if(appDelegate.contact_id!=nil)
  1420. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1421. if(appDelegate.password!=nil)
  1422. [params setValue:appDelegate.password forKey:@"password"];
  1423. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  1424. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  1425. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  1426. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  1427. // [params setValue:filter forKey:@"filter"];
  1428. [params setValue:keywords forKey:@"keyWord"];
  1429. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  1430. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  1431. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  1432. if (keywords) {
  1433. [params setObject:@"Search" forKey:kAction];
  1434. }
  1435. NSData* json = nil;
  1436. if(appDelegate.offline_mode)
  1437. {
  1438. json = [OLDataProvider offline_pdfList:params];
  1439. } else {
  1440. if(![self IsNetworkAvailable])
  1441. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1442. json=[self get_json:URL_DM_LIST parameters:params];
  1443. }
  1444. if(json==nil)
  1445. return nil;
  1446. NSError *error=nil;
  1447. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1448. return jsobj;
  1449. }
  1450. +(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code//device:(NSString*) device
  1451. {
  1452. #ifdef ERR_LOG
  1453. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1454. __block AppDelegate *appDelegate = nil;
  1455. dispatch_sync(dispatch_get_main_queue(), ^{
  1456. //some UI methods ej
  1457. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1458. });
  1459. if(appDelegate.user!=nil)
  1460. [params setValue:appDelegate.user forKey:@"user"];
  1461. [params setValue:up_params forKey:@"upparam"];
  1462. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  1463. [params setValue:result forKey:@"result"];
  1464. [params setValue:module forKey:@"interfac"];
  1465. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  1466. // [params setValue:module forKey:@"module"];
  1467. // [[UIDevice currentDevice] name];
  1468. // if(appDelegate.offline_mode)
  1469. // {
  1470. // return [OLDataProvider offline_notimpl];
  1471. // }
  1472. if(![self IsNetworkAvailable])
  1473. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1474. NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  1475. if(json==nil)
  1476. return nil;
  1477. NSError *error=nil;
  1478. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1479. return jsobj;
  1480. #else
  1481. return nil;
  1482. #endif
  1483. }
  1484. //+(NSDictionary*)request_ContactList:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams
  1485. //{
  1486. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1487. //
  1488. // if(upparams!=nil)
  1489. // params = [upparams mutableCopy];
  1490. // __block AppDelegate *appDelegate = nil;
  1491. //
  1492. // dispatch_sync(dispatch_get_main_queue(), ^{
  1493. // //some UI methods ej
  1494. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1495. // });
  1496. // if(appDelegate.user!=nil)
  1497. // [params setValue:appDelegate.user forKey:@"user"];
  1498. //
  1499. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1500. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1501. // else
  1502. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1503. //
  1504. // if(appDelegate.password!=nil)
  1505. // [params setValue:appDelegate.password forKey:@"password"];
  1506. //
  1507. // [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1508. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1509. // [params setValue:contact_type forKey:@"contactType"];
  1510. // [params setValue:keywords forKey:@"keyword"];
  1511. //
  1512. // [params setObject:ScreenCodeAccount forKey:kScreenName];
  1513. // if (keywords) {
  1514. // [params setObject:@"Search" forKey:kAction];
  1515. // }
  1516. // if (upparams) {
  1517. // [params setObject:@"Advance Search" forKey:kAction];
  1518. // }
  1519. //
  1520. // NSString* url=nil;
  1521. // if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  1522. // url=URL_SHIPTO_LIST;
  1523. // else
  1524. // url=URL_CONTACT_LIST;
  1525. //
  1526. // if(appDelegate.offline_mode)
  1527. // return [OLDataProvider offline_contactlist:params];
  1528. //
  1529. // if(![self IsNetworkAvailable])
  1530. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1531. //
  1532. // NSData* json=[self get_json:url parameters:params];
  1533. // if(json==nil)
  1534. // return nil;
  1535. // NSError *error=nil;
  1536. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1537. // return jsobj;
  1538. //}
  1539. //+(NSDictionary*)request_OrderDetail:(NSMutableDictionary *) params
  1540. //{
  1541. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1542. // if (params == nil) {
  1543. // params = [[NSMutableDictionary alloc] init];
  1544. // }
  1545. // __block AppDelegate *appDelegate = nil;
  1546. //
  1547. // dispatch_sync(dispatch_get_main_queue(), ^{
  1548. // //some UI methods ej
  1549. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1550. // });
  1551. // if(appDelegate.user!=nil)
  1552. // [params setValue:appDelegate.user forKey:@"user"];
  1553. // if(appDelegate.contact_id!=nil)
  1554. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1555. // if(appDelegate.password!=nil)
  1556. // [params setValue:appDelegate.password forKey:@"password"];
  1557. //
  1558. //
  1559. // // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1560. //
  1561. // [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  1562. //
  1563. // NSData* json=nil;
  1564. // if(appDelegate.offline_mode)
  1565. // {
  1566. // json= [OLDataProvider offline_orderdetail:params];
  1567. // }
  1568. // else
  1569. // {
  1570. // if(![self IsNetworkAvailable])
  1571. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1572. //
  1573. // NSError *error=nil;
  1574. //
  1575. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1576. // params[@"resultSerial"]=uuid;
  1577. //
  1578. // for(int i=0;i<150;i++)
  1579. // {
  1580. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1581. // // result_params[@"resultSerial"]=uuid;
  1582. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  1583. // if(json!=nil)
  1584. // {
  1585. //
  1586. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1587. // int resultCode = [jsobj[@"result"] intValue];
  1588. // if(resultCode==2 || resultCode == 8)
  1589. // {
  1590. // break;
  1591. // }
  1592. // }
  1593. // sleep(2);
  1594. // }
  1595. //
  1596. //
  1597. // }
  1598. // if(json==nil)
  1599. // return nil;
  1600. // NSError *error=nil;
  1601. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1602. // return jsobj;
  1603. //}
  1604. //+(NSDictionary*) add_toCart:(NSString* ) item_id count:(int) count name:(NSString *)name
  1605. //{
  1606. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1607. // __block AppDelegate *appDelegate = nil;
  1608. //
  1609. // dispatch_sync(dispatch_get_main_queue(), ^{
  1610. // //some UI methods ej
  1611. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1612. // });
  1613. // if(appDelegate.user!=nil)
  1614. // [params setValue:appDelegate.user forKey:@"user"];
  1615. // if(appDelegate.contact_id!=nil)
  1616. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1617. // if(appDelegate.password!=nil)
  1618. // [params setValue:appDelegate.password forKey:@"password"];
  1619. //
  1620. // if(appDelegate.order_code!=nil)
  1621. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1622. // [params setValue:item_id forKey:@"product_id"];
  1623. // [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  1624. //
  1625. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  1626. // [params setObject:@"Add To Cart" forKey:kAction];
  1627. // if (name) {
  1628. // NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  1629. // [params setObject:extra forKey:kExtra];
  1630. // }
  1631. //
  1632. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1633. //
  1634. // NSArray* keys=[customerinfo allKeys];
  1635. // for(int i=0;i<keys.count;i++)
  1636. // {
  1637. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1638. // }
  1639. //
  1640. // NSData* json=nil;
  1641. // if(appDelegate.offline_mode)
  1642. // {
  1643. // json=[OLDataProvider offline_add2cart:params];
  1644. // }
  1645. // else
  1646. // {
  1647. // if(![self IsNetworkAvailable])
  1648. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1649. //
  1650. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  1651. // }
  1652. // if(json==nil)
  1653. // return nil;
  1654. // NSError *error=nil;
  1655. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1656. //
  1657. //
  1658. //
  1659. // int result = [[jsobj valueForKey:@"result"] intValue];
  1660. //
  1661. // if (result==2)
  1662. // {
  1663. //
  1664. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1665. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1666. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1667. //
  1668. // [appDelegate update_count_mark];
  1669. // }
  1670. //
  1671. // return jsobj;
  1672. //}
  1673. //+(NSDictionary*) add_toCart_byName:(NSString* ) model_name withScreen:(NSString *)screenName
  1674. //{
  1675. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1676. // __block AppDelegate *appDelegate = nil;
  1677. //
  1678. // dispatch_sync(dispatch_get_main_queue(), ^{
  1679. // //some UI methods ej
  1680. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1681. // });
  1682. // if(appDelegate.user!=nil)
  1683. // [params setValue:appDelegate.user forKey:@"user"];
  1684. // if(appDelegate.contact_id!=nil)
  1685. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1686. // if(appDelegate.password!=nil)
  1687. // [params setValue:appDelegate.password forKey:@"password"];
  1688. //
  1689. // if(appDelegate.order_code!=nil)
  1690. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1691. // [params setValue:model_name forKey:@"product_name"];
  1692. // [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  1693. //
  1694. // [params setObject:screenName forKey:kScreenName];
  1695. // [params setObject:@"Add To Cart" forKey:kAction];
  1696. // if (!model_name) {
  1697. // model_name = @"";
  1698. // }
  1699. // [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  1700. //
  1701. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1702. //
  1703. // NSArray* keys=[customerinfo allKeys];
  1704. // for(int i=0;i<keys.count;i++)
  1705. // {
  1706. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1707. // }
  1708. // NSData* json=nil;
  1709. // if(appDelegate.offline_mode)
  1710. // {
  1711. // json= [OLDataProvider offline_add2cartbyname:params];
  1712. // }
  1713. // else
  1714. // {
  1715. // if(![self IsNetworkAvailable])
  1716. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1717. //
  1718. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  1719. // }
  1720. // if(json==nil)
  1721. // return nil;
  1722. // NSError *error=nil;
  1723. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1724. //
  1725. //
  1726. //
  1727. // int result = [[jsobj valueForKey:@"result"] intValue];
  1728. //
  1729. // if (result==2||result==8)
  1730. // {
  1731. //
  1732. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1733. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1734. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1735. //
  1736. // [appDelegate update_count_mark];
  1737. // }
  1738. //
  1739. // return jsobj;
  1740. //}
  1741. //+(NSDictionary*) new_Customer
  1742. //{
  1743. // if(![self IsNetworkAvailable])
  1744. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1745. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1746. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1747. // if(appDelegate.user!=nil)
  1748. // [params setValue:appDelegate.user forKey:@"user"];
  1749. //// if(appDelegate.contact_id!=nil)
  1750. //// [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1751. // if(appDelegate.password!=nil)
  1752. // [params setValue:appDelegate.password forKey:@"password"];
  1753. //
  1754. //// if(appDelegate.order_code!=nil)
  1755. //// [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1756. //
  1757. //
  1758. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1759. //
  1760. // NSArray* keys=[customerinfo allKeys];
  1761. // for(int i=0;i<keys.count;i++)
  1762. // {
  1763. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1764. // }
  1765. //
  1766. // NSData* json=[self get_json:URL_CUSTOMER_EDIT parameters:params];
  1767. // if(json==nil)
  1768. // return nil;
  1769. // NSError *error=nil;
  1770. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1771. // return jsobj;
  1772. //}
  1773. //+(NSDictionary*) new_Order
  1774. //{
  1775. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1776. // __block AppDelegate *appDelegate = nil;
  1777. //
  1778. // dispatch_sync(dispatch_get_main_queue(), ^{
  1779. // //some UI methods ej
  1780. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1781. // });
  1782. // if(appDelegate.user!=nil)
  1783. // [params setValue:appDelegate.user forKey:@"user"];
  1784. // if(appDelegate.contact_id!=nil)
  1785. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1786. // if(appDelegate.password!=nil)
  1787. // [params setValue:appDelegate.password forKey:@"password"];
  1788. //
  1789. // if(appDelegate.order_code!=nil)
  1790. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1791. //
  1792. //
  1793. // [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1794. //
  1795. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1796. //
  1797. // NSArray* keys=[customerinfo allKeys];
  1798. // for(int i=0;i<keys.count;i++)
  1799. // {
  1800. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1801. // }
  1802. //
  1803. // NSData* json = nil;
  1804. // if(appDelegate.offline_mode)
  1805. // {
  1806. // json= [OLDataProvider offline_createorder:params];
  1807. // }
  1808. // else
  1809. // {
  1810. // if(![self IsNetworkAvailable])
  1811. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1812. //
  1813. // json=[self get_json:URL_NEW_ORDER parameters:params];
  1814. // }
  1815. // if(json==nil)
  1816. // return nil;
  1817. // NSError *error=nil;
  1818. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1819. // int result = [[jsobj valueForKey:@"result"] intValue];
  1820. //
  1821. // if (result==2)
  1822. // {
  1823. //
  1824. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1825. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1826. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1827. //
  1828. // [appDelegate update_count_mark];
  1829. // }
  1830. //
  1831. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  1832. //
  1833. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1834. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  1835. // }
  1836. //
  1837. // return jsobj;
  1838. //}
  1839. +(NSDictionary*) add_toPortfolio:(NSString* ) item_id withScreen:(NSString *)screenName
  1840. {
  1841. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1842. __block AppDelegate *appDelegate = nil;
  1843. dispatch_sync(dispatch_get_main_queue(), ^{
  1844. //some UI methods ej
  1845. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1846. });
  1847. if(appDelegate.user!=nil)
  1848. [params setValue:appDelegate.user forKey:@"user"];
  1849. if(appDelegate.contact_id!=nil)
  1850. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1851. if(appDelegate.password!=nil)
  1852. [params setValue:appDelegate.password forKey:@"password"];
  1853. [params setValue:item_id forKey:@"product_id"];
  1854. [params setObject:screenName forKey:kScreenName];
  1855. NSData* json = nil;
  1856. if(appDelegate.offline_mode)
  1857. {
  1858. json = [OLDataProvider offline_add2Portfolio:params];
  1859. } else {
  1860. if(![self IsNetworkAvailable])
  1861. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1862. json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  1863. }
  1864. if(json==nil)
  1865. return nil;
  1866. NSError *error=nil;
  1867. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1868. int result = [[jsobj valueForKey:@"result"] intValue];
  1869. if (result==2)
  1870. {
  1871. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1872. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1873. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1874. [appDelegate update_count_mark];
  1875. }
  1876. return jsobj;
  1877. }
  1878. //+(NSDictionary*) add_toWatchList:(NSString* ) item_id withScreen:(NSString *)screenName
  1879. //{
  1880. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1881. // __block AppDelegate *appDelegate = nil;
  1882. //
  1883. // dispatch_sync(dispatch_get_main_queue(), ^{
  1884. // //some UI methods ej
  1885. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1886. // });
  1887. // if(appDelegate.user!=nil)
  1888. // [params setValue:appDelegate.user forKey:@"user"];
  1889. // if(appDelegate.contact_id!=nil)
  1890. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1891. // if(appDelegate.password!=nil)
  1892. // [params setValue:appDelegate.password forKey:@"password"];
  1893. //
  1894. //
  1895. // [params setValue:item_id forKey:@"product_id"];
  1896. //
  1897. // [params setObject:screenName forKey:kScreenName];
  1898. //
  1899. // if(appDelegate.offline_mode)
  1900. // {
  1901. // return [OLDataProvider offline_add2wishlist:params];
  1902. // }
  1903. // if(![self IsNetworkAvailable])
  1904. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1905. //
  1906. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  1907. // if(json==nil)
  1908. // return nil;
  1909. // NSError *error=nil;
  1910. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1911. // int result = [[jsobj valueForKey:@"result"] intValue];
  1912. //
  1913. // if (result==2)
  1914. // {
  1915. //
  1916. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1917. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1918. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1919. //
  1920. // [appDelegate update_count_mark];
  1921. // }
  1922. // return jsobj;
  1923. //}
  1924. //+(NSDictionary*) cart_setPrice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes
  1925. //{
  1926. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1927. // __block AppDelegate *appDelegate = nil;
  1928. //
  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. // if(appDelegate.contact_id!=nil)
  1936. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1937. // if(appDelegate.password!=nil)
  1938. // [params setValue:appDelegate.password forKey:@"password"];
  1939. //
  1940. // [params setValue:cart_id forKey:@"cartitem_id"];
  1941. // [params setValue:notes forKey:@"item_note"];
  1942. //
  1943. // [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  1944. //
  1945. // [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  1946. //
  1947. // [params setObject:ScreenCodeCart forKey:kScreenName];
  1948. //
  1949. // NSData* json= nil;
  1950. // if(appDelegate.offline_mode)
  1951. // {
  1952. // json=[OLDataProvider offline_cartsetprice:params];
  1953. // }
  1954. // else
  1955. // {
  1956. // if(![self IsNetworkAvailable])
  1957. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1958. //
  1959. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  1960. // }
  1961. // if(json==nil)
  1962. // return nil;
  1963. // NSError *error=nil;
  1964. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1965. // return jsobj;
  1966. //}
  1967. //+(NSDictionary*) portfolio_setQTY:(NSString*) watchlist_id QTY:(int)qty
  1968. //{
  1969. // if(![self IsNetworkAvailable])
  1970. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1971. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1972. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1973. // if(appDelegate.user!=nil)
  1974. // [params setValue:appDelegate.user forKey:@"user"];
  1975. // if(appDelegate.contact_id!=nil)
  1976. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1977. // if(appDelegate.password!=nil)
  1978. // [params setValue:appDelegate.password forKey:@"password"];
  1979. //
  1980. // [params setValue:watchlist_id forKey:@"item_id"];
  1981. //
  1982. // [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  1983. //
  1984. //
  1985. //
  1986. // NSData* json=[self get_json:URL_DM_SET_QTY parameters:params];
  1987. // if(json==nil)
  1988. // return nil;
  1989. // NSError *error=nil;
  1990. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1991. // return jsobj;
  1992. //}
  1993. +(NSDictionary*) portfolio_setPrice:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes
  1994. {
  1995. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1996. __block AppDelegate *appDelegate = nil;
  1997. dispatch_sync(dispatch_get_main_queue(), ^{
  1998. //some UI methods ej
  1999. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2000. });
  2001. if(appDelegate.user!=nil)
  2002. [params setValue:appDelegate.user forKey:@"user"];
  2003. if(appDelegate.contact_id!=nil)
  2004. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2005. if(appDelegate.password!=nil)
  2006. [params setValue:appDelegate.password forKey:@"password"];
  2007. [params setValue:watchlist_id forKey:@"item_id"];
  2008. // if(notes.length>0)
  2009. // [params setValue:notes forKey:@"notes"];
  2010. if(notes)
  2011. [params setValue:notes forKey:@"notes"];
  2012. if(price != -MAXFLOAT)
  2013. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  2014. if (discount != -MAXFLOAT)
  2015. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  2016. if(qty_p != -MAXFLOAT)
  2017. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  2018. if(qty != -INT32_MAX)
  2019. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  2020. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2021. NSData* json = nil;
  2022. if(appDelegate.offline_mode)
  2023. {
  2024. json = [OLDataProvider offline_editPortfolio:params];
  2025. } else {
  2026. if(![self IsNetworkAvailable])
  2027. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2028. json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  2029. }
  2030. if(json==nil)
  2031. return nil;
  2032. NSError *error=nil;
  2033. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2034. return jsobj;
  2035. }
  2036. //+(NSDictionary*) cart_setGeneralNote:(NSString*) order_code notes:(NSString*) notes
  2037. //{
  2038. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2039. // __block AppDelegate *appDelegate = nil;
  2040. //
  2041. // dispatch_sync(dispatch_get_main_queue(), ^{
  2042. // //some UI methods ej
  2043. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2044. // });
  2045. // if(appDelegate.user!=nil)
  2046. // [params setValue:appDelegate.user forKey:@"user"];
  2047. // if(appDelegate.contact_id!=nil)
  2048. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2049. // if(appDelegate.password!=nil)
  2050. // [params setValue:appDelegate.password forKey:@"password"];
  2051. //
  2052. // [params setValue:order_code forKey:@"orderCode"];
  2053. //
  2054. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2055. //
  2056. // if(notes.length==0)
  2057. // notes=@"";
  2058. //
  2059. //
  2060. // [params setValue:notes forKey:@"comments"];
  2061. // NSData* json=nil;
  2062. // if(appDelegate.offline_mode)
  2063. // {
  2064. // json= [OLDataProvider offline_updategnotes:params];
  2065. // }
  2066. // else
  2067. // {
  2068. // if(![self IsNetworkAvailable])
  2069. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2070. //
  2071. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  2072. // }
  2073. // if(json==nil)
  2074. // return nil;
  2075. // NSError *error=nil;
  2076. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2077. // return jsobj;
  2078. //}
  2079. //+(NSDictionary*) cart_setItemNote:(NSString*) cart_id notes:(NSString*) notes
  2080. //{
  2081. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2082. // __block AppDelegate *appDelegate = nil;
  2083. //
  2084. // dispatch_sync(dispatch_get_main_queue(), ^{
  2085. // //some UI methods ej
  2086. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2087. // });
  2088. // if(appDelegate.user!=nil)
  2089. // [params setValue:appDelegate.user forKey:@"user"];
  2090. // if(appDelegate.contact_id!=nil)
  2091. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2092. // if(appDelegate.password!=nil)
  2093. // [params setValue:appDelegate.password forKey:@"password"];
  2094. //
  2095. // [params setValue:cart_id forKey:@"cartitem_id"];
  2096. //
  2097. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2098. //
  2099. // if(notes.length==0)
  2100. // notes=@"";
  2101. //
  2102. //
  2103. // [params setValue:notes forKey:@"notes"];
  2104. // NSData* json=nil;
  2105. // if(appDelegate.offline_mode)
  2106. // {
  2107. // json= [OLDataProvider offline_cartsetlnotes:params];
  2108. // }
  2109. // else
  2110. // {
  2111. // if(![self IsNetworkAvailable])
  2112. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2113. //
  2114. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  2115. // }
  2116. // if(json==nil)
  2117. // return nil;
  2118. // NSError *error=nil;
  2119. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2120. // return jsobj;
  2121. //}
  2122. //+(NSDictionary*) cart_setFree:(NSString*) cart_id isfree:(bool) isfree
  2123. //{
  2124. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2125. // __block AppDelegate *appDelegate = nil;
  2126. //
  2127. // dispatch_sync(dispatch_get_main_queue(), ^{
  2128. // //some UI methods ej
  2129. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2130. // });
  2131. // if(appDelegate.user!=nil)
  2132. // [params setValue:appDelegate.user forKey:@"user"];
  2133. // if(appDelegate.contact_id!=nil)
  2134. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2135. // if(appDelegate.password!=nil)
  2136. // [params setValue:appDelegate.password forKey:@"password"];
  2137. //
  2138. // [params setValue:cart_id forKey:@"cartitem_id"];
  2139. //
  2140. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2141. //
  2142. // NSString* free=nil;
  2143. //
  2144. // if(isfree)
  2145. // free=@"true";
  2146. // else
  2147. // free=@"false";
  2148. //
  2149. // [params setValue:free forKey:@"free_giveaway"];
  2150. //
  2151. // if(appDelegate.offline_mode)
  2152. // {
  2153. // return [OLDataProvider offline_notimpl];
  2154. // }
  2155. // if(![self IsNetworkAvailable])
  2156. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2157. //
  2158. // NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2159. // if(json==nil)
  2160. // return nil;
  2161. // NSError *error=nil;
  2162. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2163. // return jsobj;
  2164. //}
  2165. //+(NSDictionary*) cart_setQTY:(NSString*) cart_id value:(int) value
  2166. //{
  2167. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2168. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2169. // if(appDelegate.user!=nil)
  2170. // [params setValue:appDelegate.user forKey:@"user"];
  2171. // if(appDelegate.contact_id!=nil)
  2172. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2173. // if(appDelegate.password!=nil)
  2174. // [params setValue:appDelegate.password forKey:@"password"];
  2175. //
  2176. // [params setValue:cart_id forKey:@"cartitem_id"];
  2177. //
  2178. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2179. //
  2180. // [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  2181. //
  2182. // NSData* json=nil;
  2183. // if(appDelegate.offline_mode)
  2184. // {
  2185. // json= [OLDataProvider offline_cartsetqty:params];
  2186. // }
  2187. // else
  2188. // {
  2189. // if(![self IsNetworkAvailable])
  2190. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2191. //
  2192. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2193. // }
  2194. // if(json==nil)
  2195. // return nil;
  2196. // NSError *error=nil;
  2197. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2198. // return jsobj;
  2199. //
  2200. //}
  2201. //+(NSDictionary*) cart_incresement:(NSString*) cart_id increse:(bool) increse
  2202. //{
  2203. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2204. // __block AppDelegate *appDelegate = nil;
  2205. //
  2206. // dispatch_sync(dispatch_get_main_queue(), ^{
  2207. // //some UI methods ej
  2208. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2209. // });
  2210. // if(appDelegate.user!=nil)
  2211. // [params setValue:appDelegate.user forKey:@"user"];
  2212. // if(appDelegate.contact_id!=nil)
  2213. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2214. // if(appDelegate.password!=nil)
  2215. // [params setValue:appDelegate.password forKey:@"password"];
  2216. //
  2217. // [params setValue:cart_id forKey:@"cartitem_id"];
  2218. //
  2219. // if(increse)
  2220. // [params setValue:@"1" forKey:@"incrementType"];
  2221. // else
  2222. // [params setValue:@"0" forKey:@"incrementType"];
  2223. //
  2224. //
  2225. //
  2226. // if(appDelegate.offline_mode)
  2227. // {
  2228. // return [OLDataProvider offline_notimpl];
  2229. // }
  2230. // if(![self IsNetworkAvailable])
  2231. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2232. //
  2233. // NSData* json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2234. // if(json==nil)
  2235. // return nil;
  2236. // NSError *error=nil;
  2237. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2238. // return jsobj;
  2239. //}
  2240. +(NSDictionary*) finish_download_Offline:(NSString* )vid
  2241. {
  2242. if(![self IsNetworkAvailable])
  2243. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2244. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2245. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  2246. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2247. // if(appDelegate.user!=nil)
  2248. // [params setValue:appDelegate.user forKey:@"user"];
  2249. // // if(appDelegate.contact_id!=nil)
  2250. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2251. // if(appDelegate.password!=nil)
  2252. // [params setValue:appDelegate.password forKey:@"password"];
  2253. [params setValue:vid forKey:@"downSerial"];
  2254. NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  2255. if(json==nil)
  2256. return nil;
  2257. NSError *error=nil;
  2258. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2259. // int result = [[jsobj valueForKey:@"result"] intValue];
  2260. //
  2261. // if (result==2)
  2262. // {
  2263. //
  2264. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2265. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2266. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2267. ////
  2268. //// [appDelegate update_count_mark];
  2269. // }
  2270. return jsobj;
  2271. }
  2272. +(NSDictionary*) download_Offline:(NSString* )vid
  2273. {
  2274. if(![self IsNetworkAvailable])
  2275. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2276. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2277. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2278. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2279. // if(appDelegate.user!=nil)
  2280. // [params setValue:appDelegate.user forKey:@"user"];
  2281. // // if(appDelegate.contact_id!=nil)
  2282. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2283. // if(appDelegate.password!=nil)
  2284. // [params setValue:appDelegate.password forKey:@"password"];
  2285. [params setValue:vid forKey:@"downSerial"];
  2286. NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  2287. if(json==nil)
  2288. return nil;
  2289. NSError *error=nil;
  2290. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2291. // int result = [[jsobj valueForKey:@"result"] intValue];
  2292. //
  2293. // if (result==2)
  2294. // {
  2295. //
  2296. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2297. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2298. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2299. ////
  2300. //// [appDelegate update_count_mark];
  2301. // }
  2302. return jsobj;
  2303. }
  2304. +(NSDictionary*) check_Offline:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid
  2305. {
  2306. if(![self IsNetworkAvailable])
  2307. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2308. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2309. __block AppDelegate *appDelegate = nil;
  2310. dispatch_sync(dispatch_get_main_queue(), ^{
  2311. //some UI methods ej
  2312. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2313. });
  2314. if(appDelegate.user!=nil)
  2315. [params setValue:appDelegate.user forKey:@"user"];
  2316. // if(appDelegate.contact_id!=nil)
  2317. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2318. if(appDelegate.password!=nil)
  2319. [params setValue:appDelegate.password forKey:@"password"];
  2320. [params setValue:ver forKey:@"ver"];
  2321. [params setValue:vid forKey:@"vid"];
  2322. if(buseinternaladdress)
  2323. [params setValue:@"true" forKey:@"internal_address"];
  2324. else
  2325. [params setValue:@"false" forKey:@"internal_address"];
  2326. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2327. NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  2328. if(json==nil)
  2329. return nil;
  2330. NSError *error=nil;
  2331. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2332. // int result = [[jsobj valueForKey:@"result"] intValue];
  2333. //
  2334. // if (result==2)
  2335. // {
  2336. //
  2337. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2338. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2339. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2340. ////
  2341. //// [appDelegate update_count_mark];
  2342. // }
  2343. return jsobj;
  2344. }
  2345. //+(NSDictionary*)request_Cart:(int)sort
  2346. //{
  2347. //
  2348. // DebugLog(@"iSalesNetwork::request_Cart");
  2349. //
  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. // if(appDelegate.order_code!=nil)
  2366. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2367. //
  2368. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2369. //
  2370. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2371. //
  2372. // NSData* json=nil;
  2373. // if(appDelegate.offline_mode)
  2374. // {
  2375. // json= [OLDataProvider offline_requestcart:params];
  2376. // }
  2377. // else
  2378. // {
  2379. // if(![self IsNetworkAvailable])
  2380. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2381. //
  2382. // NSError *error=nil;
  2383. //
  2384. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2385. // params[@"resultSerial"]=uuid;
  2386. //
  2387. // for(int i=0;i<150;i++)
  2388. // {
  2389. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2390. // // result_params[@"resultSerial"]=uuid;
  2391. // json=[self get_json:URL_CART parameters:params];
  2392. // if(json!=nil)
  2393. // {
  2394. //
  2395. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2396. // if([jsobj[@"result"] intValue]==2)
  2397. // {
  2398. // break;
  2399. // }
  2400. // }
  2401. // sleep(2);
  2402. // }
  2403. //
  2404. // }
  2405. // if(json==nil)
  2406. // return nil;
  2407. // NSError *error=nil;
  2408. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2409. // int result = [[jsobj valueForKey:@"result"] intValue];
  2410. //
  2411. // if (result==2)
  2412. // {
  2413. //
  2414. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2415. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2416. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2417. //
  2418. // [appDelegate update_count_mark];
  2419. // }
  2420. // return jsobj;
  2421. //}
  2422. //+(NSDictionary*)request_Portfolio:(int)sort
  2423. //{
  2424. //
  2425. //
  2426. //
  2427. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2428. // __block AppDelegate *appDelegate = nil;
  2429. //
  2430. // dispatch_sync(dispatch_get_main_queue(), ^{
  2431. // //some UI methods ej
  2432. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2433. // });
  2434. // if(appDelegate.user!=nil)
  2435. // [params setValue:appDelegate.user forKey:@"user"];
  2436. // if(appDelegate.contact_id!=nil)
  2437. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2438. // if(appDelegate.password!=nil)
  2439. // [params setValue:appDelegate.password forKey:@"password"];
  2440. //
  2441. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2442. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2443. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2444. //
  2445. // [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2446. //
  2447. // NSData* json = nil;
  2448. // if(appDelegate.offline_mode)
  2449. // {
  2450. // json = [OLDataProvider offline_portfolioList:params];
  2451. // } else {
  2452. // if(![self IsNetworkAvailable])
  2453. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2454. //
  2455. // json = [self get_json:URL_PORTFOLIO parameters:params];
  2456. // }
  2457. //
  2458. //
  2459. // if(json==nil)
  2460. // return nil;
  2461. // NSError *error=nil;
  2462. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2463. // int result = [[jsobj valueForKey:@"result"] intValue];
  2464. //
  2465. // if (result==2)
  2466. // {
  2467. //
  2468. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2469. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2470. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  2471. //
  2472. // [appDelegate update_count_mark];
  2473. // }
  2474. // return jsobj;
  2475. //}
  2476. //+(NSDictionary*)request_WatchList:(int)sort
  2477. //{
  2478. //
  2479. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2480. // __block AppDelegate *appDelegate = nil;
  2481. //
  2482. // dispatch_sync(dispatch_get_main_queue(), ^{
  2483. // //some UI methods ej
  2484. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2485. // });
  2486. // if(appDelegate.user!=nil)
  2487. // [params setValue:appDelegate.user forKey:@"user"];
  2488. // if(appDelegate.contact_id!=nil)
  2489. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2490. // if(appDelegate.password!=nil)
  2491. // [params setValue:appDelegate.password forKey:@"password"];
  2492. //
  2493. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2494. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2495. //
  2496. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2497. //
  2498. // [params setObject:ScreenCodeWishList forKey:kScreenName];
  2499. //
  2500. // if(appDelegate.offline_mode)
  2501. // {
  2502. // return [OLDataProvider offline_wishlist:params];
  2503. // }
  2504. // if(![self IsNetworkAvailable])
  2505. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2506. //
  2507. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  2508. // if(json==nil)
  2509. // return nil;
  2510. // NSError *error=nil;
  2511. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2512. // int result = [[jsobj valueForKey:@"result"] intValue];
  2513. //
  2514. // if (result==2)
  2515. // {
  2516. //
  2517. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2518. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2519. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2520. //
  2521. // [appDelegate update_count_mark];
  2522. // }
  2523. // return jsobj;
  2524. //}
  2525. //+(NSDictionary*)request_ItemDetail: (NSString* ) item_id model_name:(NSString*) model_name category_id:(NSString*) category_id use_name :(bool) use_name groupName:(NSString *)groupName
  2526. //{
  2527. //
  2528. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2529. // __block AppDelegate *appDelegate = nil;
  2530. //
  2531. // dispatch_sync(dispatch_get_main_queue(), ^{
  2532. // //some UI methods ej
  2533. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2534. // });
  2535. // if(appDelegate.user!=nil)
  2536. // [params setValue:appDelegate.user forKey:@"user"];
  2537. // if(appDelegate.contact_id!=nil)
  2538. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2539. // if(appDelegate.password!=nil)
  2540. // [params setValue:appDelegate.password forKey:@"password"];
  2541. // if(appDelegate.order_code!=nil)
  2542. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2543. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2544. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2545. // if(use_name)
  2546. // [params setValue:model_name forKey:@"product_name"];
  2547. // else
  2548. // [params setValue:item_id forKey:@"product_id"];
  2549. //
  2550. //
  2551. // [params setValue:category_id forKey:@"category"];
  2552. //
  2553. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  2554. // [params setObject:@"Open A Model" forKey:kAction];
  2555. // if (model_name) {
  2556. // NSDictionary *extra = @{@"ModelName" : model_name};
  2557. // [params setObject:extra forKey:kExtra];
  2558. // }
  2559. //
  2560. // if (groupName.length > 0) {
  2561. // [params setObject:groupName forKey:@"groupName"];
  2562. // }
  2563. //
  2564. // if(appDelegate.offline_mode)
  2565. // return [OLDataProvider offline_model:params];
  2566. //
  2567. // if(![self IsNetworkAvailable])
  2568. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2569. //
  2570. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  2571. // if(json==nil)
  2572. // return nil;
  2573. // NSError *error=nil;
  2574. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2575. // return jsobj;
  2576. //}
  2577. //+(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
  2578. //{
  2579. // if(![self IsNetworkAvailable])
  2580. // return nil;
  2581. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2582. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2583. // if(appDelegate.user!=nil)
  2584. // [params setValue:appDelegate.user forKey:@"user"];
  2585. // if(appDelegate.contact_id!=nil)
  2586. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2587. // if(appDelegate.password!=nil)
  2588. // [params setValue:appDelegate.password forKey:@"password"];
  2589. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2590. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2591. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2592. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2593. // [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  2594. // [params setValue:filter forKey:@"filter"];
  2595. // [params setValue:keyword forKey:@"keyword"];
  2596. //
  2597. //
  2598. // NSData* json=[self get_json:URL_CATEGORY_LOADMORE parameters:params];
  2599. // if(json==nil)
  2600. // return nil;
  2601. // NSError *error=nil;
  2602. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2603. // return jsobj;
  2604. //
  2605. //}
  2606. //+(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
  2607. //
  2608. //{
  2609. //
  2610. //
  2611. // __block AppDelegate *appDelegate = nil;
  2612. //
  2613. // dispatch_sync(dispatch_get_main_queue(), ^{
  2614. // //some UI methods ej
  2615. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2616. // });
  2617. //
  2618. //
  2619. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2620. //
  2621. // if(appDelegate.user!=nil)
  2622. // [params setValue:appDelegate.user forKey:@"user"];
  2623. // if(appDelegate.contact_id!=nil)
  2624. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2625. // if(appDelegate.password!=nil)
  2626. // [params setValue:appDelegate.password forKey:@"password"];
  2627. // if(appDelegate.order_code!=nil)
  2628. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2629. //
  2630. // [params setValue:addTo forKey:@"addTo"];
  2631. // [params setValue:orderCode forKey:@"orderCode"];
  2632. // [params setValue:alert forKey:@"alert"];
  2633. // [params setValue:qty forKey:@"sold_by_qty"];
  2634. // [params setValue:available forKey:@"available"];
  2635. // [params setValue:price forKey:@"price"];
  2636. // [params setValue:bestseller forKey:@"bestseller"];
  2637. // [params setValue:modelname forKey:@"modelName"];
  2638. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2639. //
  2640. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2641. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2642. // [params setValue:category forKey:@"category"];
  2643. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2644. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2645. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2646. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2647. // [params setValue:filter forKey:@"filter"];
  2648. // [params setValue:keyword forKey:@"keyword"];
  2649. //
  2650. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  2651. // if ([addTo isEqualToString:@"cart"]) {
  2652. // [params setObject:@"Add To Cart" forKey:kAction];
  2653. // }
  2654. //
  2655. //
  2656. // NSData* json= nil;
  2657. //
  2658. // if(appDelegate.offline_mode)
  2659. // {
  2660. // json= [OLDataProvider offline_categoryaddall:params];
  2661. // }
  2662. // else
  2663. // {
  2664. // if(![self IsNetworkAvailable])
  2665. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2666. //
  2667. //
  2668. // NSError *error=nil;
  2669. //
  2670. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2671. // params[@"resultSerial"]=uuid;
  2672. //
  2673. // for(int i=0;i<150;i++)
  2674. // {
  2675. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2676. // // result_params[@"resultSerial"]=uuid;
  2677. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  2678. // if(json!=nil)
  2679. // {
  2680. //
  2681. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2682. // int resultInt = [jsobj[@"result"] intValue];
  2683. // if(resultInt == 2 || resultInt == 8)
  2684. // {
  2685. // break;
  2686. // }
  2687. // }
  2688. // sleep(2);
  2689. // }
  2690. //
  2691. //
  2692. //
  2693. // }
  2694. // if(json==nil)
  2695. // return nil;
  2696. // NSError *error=nil;
  2697. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2698. // return jsobj;
  2699. //
  2700. //}
  2701. //+(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
  2702. //{
  2703. //
  2704. //
  2705. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2706. //
  2707. //
  2708. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2709. //
  2710. // if(appDelegate.user!=nil)
  2711. // [params setValue:appDelegate.user forKey:@"user"];
  2712. // if(appDelegate.contact_id!=nil)
  2713. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2714. // if(appDelegate.password!=nil)
  2715. // [params setValue:appDelegate.password forKey:@"password"];
  2716. // if(appDelegate.order_code!=nil)
  2717. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2718. //
  2719. // [params setValue:alert forKey:@"alert"];
  2720. // [params setValue:qty forKey:@"sold_by_qty"];
  2721. // [params setValue:available forKey:@"available"];
  2722. // [params setValue:price forKey:@"price"];
  2723. // [params setValue:bestseller forKey:@"bestseller"];
  2724. // [params setValue:modelname forKey:@"modelName"];
  2725. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2726. //
  2727. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2728. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2729. // [params setValue:category forKey:@"category"];
  2730. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2731. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2732. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2733. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2734. // [params setValue:filter forKey:@"filter"];
  2735. // [params setValue:keyword forKey:@"keyword"];
  2736. //
  2737. //
  2738. //
  2739. // if(appDelegate.offline_mode)
  2740. // return [OLDataProvider offline_category:params];
  2741. // if(![self IsNetworkAvailable])
  2742. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2743. //
  2744. // NSData* json=[self get_json:URL_ADDALL2PORTFOLIO parameters:params];
  2745. // if(json==nil)
  2746. // return nil;
  2747. // NSError *error=nil;
  2748. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2749. // return jsobj;
  2750. //
  2751. //}
  2752. //+(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
  2753. //{
  2754. //
  2755. //
  2756. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2757. //
  2758. //
  2759. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2760. //
  2761. // if(appDelegate.user!=nil)
  2762. // [params setValue:appDelegate.user forKey:@"user"];
  2763. // if(appDelegate.contact_id!=nil)
  2764. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2765. // if(appDelegate.password!=nil)
  2766. // [params setValue:appDelegate.password forKey:@"password"];
  2767. // if(appDelegate.order_code!=nil)
  2768. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2769. //
  2770. // [params setValue:alert forKey:@"alert"];
  2771. // [params setValue:qty forKey:@"sold_by_qty"];
  2772. // [params setValue:available forKey:@"available"];
  2773. // [params setValue:price forKey:@"price"];
  2774. // [params setValue:bestseller forKey:@"bestseller"];
  2775. // [params setValue:modelname forKey:@"modelName"];
  2776. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2777. //
  2778. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2779. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2780. // [params setValue:category forKey:@"category"];
  2781. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2782. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2783. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2784. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2785. // [params setValue:filter forKey:@"filter"];
  2786. // [params setValue:keyword forKey:@"keyword"];
  2787. //
  2788. //
  2789. //
  2790. // if(appDelegate.offline_mode)
  2791. // return [OLDataProvider offline_category:params];
  2792. // if(![self IsNetworkAvailable])
  2793. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2794. //
  2795. // NSData* json=[self get_json:URL_ADDALL2WISH parameters:params];
  2796. // if(json==nil)
  2797. // return nil;
  2798. // NSError *error=nil;
  2799. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2800. // return jsobj;
  2801. //
  2802. //}
  2803. //+(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
  2804. //{
  2805. //
  2806. //
  2807. // __block AppDelegate *appDelegate = nil;
  2808. //
  2809. // dispatch_sync(dispatch_get_main_queue(), ^{
  2810. // //some UI methods ej
  2811. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2812. // });
  2813. //
  2814. //
  2815. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2816. //
  2817. // if(appDelegate.user!=nil)
  2818. // [params setValue:appDelegate.user forKey:@"user"];
  2819. // if(appDelegate.contact_id!=nil)
  2820. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2821. // if(appDelegate.password!=nil)
  2822. // [params setValue:appDelegate.password forKey:@"password"];
  2823. // if(appDelegate.order_code!=nil)
  2824. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2825. //
  2826. // [params setValue:alert forKey:@"alert"];
  2827. // [params setValue:qty forKey:@"sold_by_qty"];
  2828. // [params setValue:available forKey:@"available"];
  2829. // [params setValue:price forKey:@"price"];
  2830. // [params setValue:bestseller forKey:@"bestseller"];
  2831. // [params setValue:modelname forKey:@"modelName"];
  2832. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2833. //
  2834. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2835. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2836. // [params setValue:category forKey:@"category"];
  2837. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2838. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2839. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2840. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2841. // [params setValue:filter forKey:@"filter"];
  2842. // [params setValue:keyword forKey:@"keyword"];
  2843. //
  2844. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  2845. // if (alert) {
  2846. // [params setObject:@"Filter" forKey:kAction];
  2847. // }
  2848. // if ([Singleton sharedInstance].homeItemClick) {
  2849. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  2850. // [Singleton sharedInstance].homeItemClick = NO;
  2851. //
  2852. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  2853. // [Singleton sharedInstance].homeClickedItemName = nil;
  2854. // [params setObject:extra forKey:kExtra];
  2855. //
  2856. // }
  2857. //
  2858. //
  2859. // if(appDelegate.offline_mode)
  2860. // return [OLDataProvider offline_category:params];
  2861. // if(![self IsNetworkAvailable])
  2862. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2863. //
  2864. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  2865. // if(json==nil)
  2866. // return nil;
  2867. // NSError *error=nil;
  2868. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2869. // return jsobj;
  2870. //
  2871. //}
  2872. //+(NSDictionary*)Search_addall:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  2873. //{
  2874. //
  2875. //
  2876. //
  2877. //
  2878. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2879. // __block AppDelegate *appDelegate = nil;
  2880. //
  2881. // dispatch_sync(dispatch_get_main_queue(), ^{
  2882. // //some UI methods ej
  2883. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2884. // });
  2885. // if(appDelegate.user!=nil)
  2886. // [params setValue:appDelegate.user forKey:@"user"];
  2887. // if(appDelegate.contact_id!=nil)
  2888. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2889. // if(appDelegate.password!=nil)
  2890. // [params setValue:appDelegate.password forKey:@"password"];
  2891. // if(appDelegate.order_code!=nil)
  2892. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2893. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2894. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2895. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2896. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2897. // // [params setValue:filter forKey:@"filter"];
  2898. // [params setValue:keywords forKey:@"keyword"];
  2899. // [params setValue:addTo forKey:@"addTo"];
  2900. //
  2901. // [params setValue:orderCode forKey:@"orderCode"];
  2902. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2903. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2904. // if(matchfull)
  2905. // [params setValue:@"true" forKey:@"exactMatch"];
  2906. // else
  2907. // [params setValue:@"false" forKey:@"exactMatch"];
  2908. //
  2909. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  2910. // if ([addTo isEqualToString:@"cart"]) {
  2911. // [params setObject:@"Add To Cart" forKey:kAction];
  2912. // }
  2913. //
  2914. // NSData* json=nil;
  2915. // if(appDelegate.offline_mode)
  2916. // {
  2917. // json=[OLDataProvider offline_searchaddall:params];
  2918. // }
  2919. // else
  2920. // {
  2921. // if(![self IsNetworkAvailable])
  2922. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2923. //
  2924. // NSError *error=nil;
  2925. //
  2926. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2927. // params[@"resultSerial"]=uuid;
  2928. //
  2929. // for(int i=0;i<150;i++)
  2930. // {
  2931. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2932. // // result_params[@"resultSerial"]=uuid;
  2933. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  2934. // if(json!=nil)
  2935. // {
  2936. //
  2937. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2938. // if([jsobj[@"result"] intValue]==2)
  2939. // {
  2940. // break;
  2941. // }
  2942. // }
  2943. // sleep(2);
  2944. // }
  2945. // }
  2946. // if(json==nil)
  2947. // return nil;
  2948. // NSError *error=nil;
  2949. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2950. // return jsobj;
  2951. //
  2952. //}
  2953. //+(NSDictionary*)Search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull
  2954. //{
  2955. //
  2956. //
  2957. //
  2958. //
  2959. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2960. // __block AppDelegate *appDelegate = nil;
  2961. //
  2962. // dispatch_sync(dispatch_get_main_queue(), ^{
  2963. // //some UI methods ej
  2964. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2965. // });
  2966. // if(appDelegate.user!=nil)
  2967. // [params setValue:appDelegate.user forKey:@"user"];
  2968. // if(appDelegate.contact_id!=nil)
  2969. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2970. // if(appDelegate.password!=nil)
  2971. // [params setValue:appDelegate.password forKey:@"password"];
  2972. // if(appDelegate.order_code!=nil)
  2973. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2974. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2975. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2976. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2977. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2978. // // [params setValue:filter forKey:@"filter"];
  2979. // [params setValue:keywords forKey:@"keyword"];
  2980. //
  2981. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2982. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2983. // if(matchfull)
  2984. // [params setValue:@"true" forKey:@"exactMatch"];
  2985. // else
  2986. // [params setValue:@"false" forKey:@"exactMatch"];
  2987. //
  2988. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  2989. // if (keywords) {
  2990. // [params setObject:@"Search" forKey:kAction];
  2991. // }
  2992. //
  2993. // if(appDelegate.offline_mode)
  2994. // {
  2995. // return [OLDataProvider offline_search:params];
  2996. // }
  2997. // if(![self IsNetworkAvailable])
  2998. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2999. //
  3000. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3001. // if(json==nil)
  3002. // return nil;
  3003. // NSError *error=nil;
  3004. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3005. // return jsobj;
  3006. //}
  3007. //+(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
  3008. //{
  3009. // // for debug
  3010. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3011. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3012. //
  3013. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3014. // __block AppDelegate *appDelegate = nil;
  3015. //
  3016. // dispatch_sync(dispatch_get_main_queue(), ^{
  3017. // //some UI methods ej
  3018. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3019. // });
  3020. // if(appDelegate.user!=nil)
  3021. // [params setValue:appDelegate.user forKey:@"user"];
  3022. // if(appDelegate.contact_id!=nil)
  3023. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3024. // if(appDelegate.password!=nil)
  3025. // [params setValue:appDelegate.password forKey:@"password"];
  3026. // if(appDelegate.order_code!=nil)
  3027. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3028. //
  3029. // [params setValue:addTo forKey:@"addTo"];
  3030. //
  3031. // [params setValue:orderCode forKey:@"orderCode"];
  3032. //
  3033. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3034. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3035. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3036. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3037. // // [params setValue:filter forKey:@"filter"];
  3038. // [params setValue:covertype forKey:@"covertype"];
  3039. // [params setValue:ctgid forKey:@"ctgId"];
  3040. // [params setValue:modelname forKey:@"modelName"];
  3041. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3042. // [params setValue:alert forKey:@"alert"];
  3043. // [params setValue:qty forKey:@"sold_by_qty"];
  3044. // [params setValue:available forKey:@"available"];
  3045. // [params setValue:price forKey:@"price"];
  3046. // [params setValue:bestseller forKey:@"bestseller"];
  3047. //
  3048. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3049. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3050. //
  3051. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3052. // if ([addTo isEqualToString:@"cart"]) {
  3053. // [params setObject:@"Add To Cart" forKey:kAction];
  3054. // }
  3055. //
  3056. // NSData* json = nil;
  3057. //
  3058. // if(appDelegate.offline_mode)
  3059. // {
  3060. // json= [OLDataProvider offline_itemsearchaddall:params];
  3061. // }
  3062. // else
  3063. // {
  3064. // if(![self IsNetworkAvailable])
  3065. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3066. // NSError *error=nil;
  3067. //
  3068. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3069. // params[@"resultSerial"]=uuid;
  3070. //
  3071. // for(int i=0;i<150;i++)
  3072. // {
  3073. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3074. // // result_params[@"resultSerial"]=uuid;
  3075. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  3076. // if(json!=nil)
  3077. // {
  3078. //
  3079. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3080. // if([jsobj[@"result"] intValue]==2)
  3081. // {
  3082. // break;
  3083. // }
  3084. // }
  3085. // sleep(2);
  3086. // }
  3087. // }
  3088. // if(json==nil)
  3089. // return nil;
  3090. // NSError *error=nil;
  3091. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3092. // return jsobj;
  3093. //}
  3094. //+(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
  3095. //{
  3096. //
  3097. // // for debug
  3098. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3099. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3100. //
  3101. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3102. // __block AppDelegate *appDelegate = nil;
  3103. //
  3104. // dispatch_sync(dispatch_get_main_queue(), ^{
  3105. // //some UI methods ej
  3106. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3107. // });
  3108. // if(appDelegate.user!=nil)
  3109. // [params setValue:appDelegate.user forKey:@"user"];
  3110. // if(appDelegate.contact_id!=nil)
  3111. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3112. // if(appDelegate.password!=nil)
  3113. // [params setValue:appDelegate.password forKey:@"password"];
  3114. // if(appDelegate.order_code!=nil)
  3115. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3116. //
  3117. //
  3118. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3119. // if (alert && qty && available && price && bestseller) {
  3120. // [params setObject:@"Filter" forKey:kAction];
  3121. // }
  3122. // if ([Singleton sharedInstance].homeItemClick) {
  3123. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  3124. // [Singleton sharedInstance].homeItemClick = NO;
  3125. //
  3126. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  3127. // [Singleton sharedInstance].homeClickedItemName = nil;
  3128. // [params setObject:extra forKey:kExtra];
  3129. // }
  3130. //
  3131. //
  3132. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3133. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3134. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3135. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3136. // // [params setValue:filter forKey:@"filter"];
  3137. // [params setValue:covertype forKey:@"covertype"];
  3138. // [params setValue:ctgid forKey:@"ctgId"];
  3139. // [params setValue:modelname forKey:@"modelName"];
  3140. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3141. // [params setValue:alert forKey:@"alert"];
  3142. // [params setValue:qty forKey:@"sold_by_qty"];
  3143. // [params setValue:available forKey:@"available"];
  3144. // [params setValue:price forKey:@"price"];
  3145. // [params setValue:bestseller forKey:@"bestseller"];
  3146. //
  3147. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3148. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3149. //
  3150. // if(appDelegate.offline_mode)
  3151. // {
  3152. // return [OLDataProvider offline_itemsearch:params];
  3153. // }
  3154. // if(![self IsNetworkAvailable])
  3155. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3156. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  3157. // if(json==nil)
  3158. // return nil;
  3159. // NSError *error=nil;
  3160. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3161. // return jsobj;
  3162. //}
  3163. //+(NSDictionary*)Search: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword
  3164. //{
  3165. // if(![self IsNetworkAvailable])
  3166. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3167. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3168. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3169. // if(appDelegate.user!=nil)
  3170. // [params setValue:appDelegate.user forKey:@"user"];
  3171. // if(appDelegate.contact_id!=nil)
  3172. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3173. // if(appDelegate.password!=nil)
  3174. // [params setValue:appDelegate.password forKey:@"password"];
  3175. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3176. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3177. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3178. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3179. // [params setValue:filter forKey:@"filter"];
  3180. // [params setValue:keyword forKey:@"keyword"];
  3181. //
  3182. //
  3183. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3184. // if(json==nil)
  3185. // return nil;
  3186. // NSError *error=nil;
  3187. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3188. // return jsobj;
  3189. //}
  3190. +(NSDictionary*)request_model_qty: (NSString*) fashionId
  3191. {
  3192. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3193. __block AppDelegate *appDelegate = nil;
  3194. dispatch_sync(dispatch_get_main_queue(), ^{
  3195. //some UI methods ej
  3196. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3197. });
  3198. if(appDelegate.user!=nil)
  3199. [params setValue:appDelegate.user forKey:@"user"];
  3200. if(appDelegate.contact_id!=nil)
  3201. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3202. if(appDelegate.password!=nil)
  3203. [params setValue:appDelegate.password forKey:@"password"];
  3204. [params setValue:fashionId forKey:@"fashionId"];
  3205. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  3206. NSData* json = nil;
  3207. if(appDelegate.offline_mode)
  3208. {
  3209. json = [OLDataProvider offline_model_qty:params];
  3210. } else {
  3211. if(![self IsNetworkAvailable])
  3212. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3213. json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  3214. }
  3215. if(json==nil)
  3216. return nil;
  3217. NSError *error=nil;
  3218. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3219. return jsobj;
  3220. }
  3221. +(NSDictionary*)retrieve_password: (NSString*) user email:(NSString*) email
  3222. {
  3223. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3224. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3225. // if(appDelegate.user!=nil)
  3226. // [params setValue:appDelegate.user forKey:@"user"];
  3227. // if(appDelegate.contact_id!=nil)
  3228. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3229. // if(appDelegate.password!=nil)
  3230. // [params setValue:appDelegate.password forKey:@"password"];
  3231. [params setValue:user forKey:@"username"];
  3232. [params setValue:email forKey:@"email"];
  3233. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3234. if(![self IsNetworkAvailable])
  3235. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3236. NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  3237. if(json==nil)
  3238. return nil;
  3239. NSError *error=nil;
  3240. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3241. return jsobj;
  3242. }
  3243. +(NSDictionary*)load_HomePage:(int) price_template customid:(int) customid
  3244. {
  3245. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3246. __block AppDelegate *appDelegate = nil;
  3247. dispatch_sync(dispatch_get_main_queue(), ^{
  3248. //some UI methods ej
  3249. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3250. });
  3251. if(appDelegate.user!=nil)
  3252. [params setValue:appDelegate.user forKey:@"user"];
  3253. if(appDelegate.contact_id!=nil)
  3254. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3255. if(appDelegate.password!=nil)
  3256. [params setValue:appDelegate.password forKey:@"password"];
  3257. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3258. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3259. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  3260. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3261. if(appDelegate.offline_mode)
  3262. {
  3263. //params[@"offline_Command"]=url;
  3264. return [OLDataProvider offline_home];
  3265. }
  3266. if(![self IsNetworkAvailable])
  3267. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3268. NSData* json=[self get_json:URL_LOAD_HOME parameters:params];
  3269. if(json==nil)
  3270. return nil;
  3271. NSError *error=nil;
  3272. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3273. return jsobj;
  3274. }
  3275. //+(NSDictionary*)logout
  3276. //{
  3277. //
  3278. //
  3279. //
  3280. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3281. // __block AppDelegate *appDelegate = nil;
  3282. //
  3283. // dispatch_sync(dispatch_get_main_queue(), ^{
  3284. // //some UI methods ej
  3285. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3286. // });
  3287. // if(appDelegate.user!=nil)
  3288. // [params setValue:appDelegate.user forKey:@"user"];
  3289. //
  3290. //
  3291. // if(appDelegate.password!=nil)
  3292. // [params setValue:appDelegate.password forKey:@"password"];
  3293. //
  3294. //
  3295. // if(appDelegate.offline_mode)
  3296. // {
  3297. // return [OLDataProvider offline_logout:params];
  3298. // }
  3299. // if(![self IsNetworkAvailable])
  3300. // {
  3301. // DebugLog(@"NET ERR");
  3302. //
  3303. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3304. // // return nil;
  3305. // }
  3306. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  3307. // //if(json==nil)
  3308. //
  3309. //
  3310. // if(json==nil)
  3311. // return nil;
  3312. // NSError *error=nil;
  3313. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3314. // int result = [[jsobj valueForKey:@"result"] intValue];
  3315. //
  3316. // if (result==2)
  3317. // {
  3318. //
  3319. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  3320. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  3321. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  3322. //
  3323. // [appDelegate update_count_mark];
  3324. //
  3325. //
  3326. // appDelegate.can_show_price =false;
  3327. // appDelegate.can_see_price =false;
  3328. // appDelegate.can_create_portfolio =false;
  3329. // appDelegate.can_create_order =false;
  3330. //
  3331. //
  3332. // appDelegate.can_cancel_order =false;
  3333. // appDelegate.can_set_cart_price =false;
  3334. // appDelegate.can_delete_order =false;
  3335. // appDelegate.can_submit_order =false;
  3336. // appDelegate.can_set_tearsheet_price =false;
  3337. // appDelegate.can_update_contact_info = false;
  3338. //
  3339. // appDelegate.save_order_logout = false;
  3340. // appDelegate.submit_order_logout = false;
  3341. // appDelegate.alert_sold_in_quantities = false;
  3342. //
  3343. // appDelegate.ipad_perm =nil ;
  3344. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  3345. // appDelegate.OrderFilter= nil;
  3346. // [appDelegate SetSo:nil];
  3347. // [appDelegate set_main_button_panel];
  3348. //#ifdef RA_NOTIFICATION
  3349. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  3350. //#endif
  3351. // }
  3352. // return jsobj;
  3353. //}
  3354. +(NSDictionary*)request_Cagegory
  3355. {
  3356. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  3357. __block AppDelegate *appDelegate = nil;
  3358. dispatch_sync(dispatch_get_main_queue(), ^{
  3359. //some UI methods ej
  3360. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3361. });
  3362. if(appDelegate.offline_mode)
  3363. {
  3364. //params[@"offline_Command"]=url;
  3365. return [OLDataProvider offline_category_menu];
  3366. }
  3367. if(![self IsNetworkAvailable])
  3368. {
  3369. DebugLog(@"NET ERR");
  3370. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3371. // return nil;
  3372. }
  3373. NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  3374. //if(json==nil)
  3375. if(json==nil)
  3376. return nil;
  3377. NSError *error=nil;
  3378. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3379. return jsobj;
  3380. }
  3381. +(int)Authorize : (NSString*) user password:(NSString*) password{
  3382. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  3383. // return RESULT_NET_ERROR;
  3384. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3385. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3386. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3387. __block AppDelegate *appDelegate = nil;
  3388. dispatch_sync(dispatch_get_main_queue(), ^{
  3389. //some UI methods ej
  3390. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3391. });
  3392. if(appDelegate.duid !=nil)
  3393. [params setValue:appDelegate.duid forKey:@"udid"];
  3394. [params setValue:@"handset_login" forKey:@"action"];
  3395. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  3396. [params setValue:user forKey:@"user"];
  3397. [params setValue:password forKey:@"password"];
  3398. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  3399. #ifdef TEST
  3400. [params setValue:@"true" forKey:@"is_debug"];
  3401. #else
  3402. [params setValue:@"false" forKey:@"is_debug"];
  3403. #endif
  3404. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3405. [params setObject:@"Login" forKey:kAction];
  3406. NSData* json= nil;
  3407. if(appDelegate.offline_mode)
  3408. {
  3409. json= [OLDataProvider offline_login:params] ;
  3410. }
  3411. else
  3412. {
  3413. if(![self IsNetworkAvailable])
  3414. return RESULT_NET_NOTAVAILABLE;
  3415. json =[self get_json:URL_UPDATE_AUTH parameters:params];
  3416. }
  3417. if(json==nil)
  3418. return RESULT_NET_ERROR;
  3419. int ret = [self parse_authinfo:json user:user password:password];
  3420. DebugLog(@"parse_authinfo return %d ",ret);
  3421. return ret;
  3422. }
  3423. +(NSDictionary*)update_customer_img: (NSString*) contactid img_url:(NSString*) url
  3424. {
  3425. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3426. __block AppDelegate *appDelegate = nil;
  3427. dispatch_sync(dispatch_get_main_queue(), ^{
  3428. //some UI methods ej
  3429. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3430. });
  3431. if(appDelegate.user!=nil)
  3432. [params setValue:appDelegate.user forKey:@"user"];
  3433. // if(appDelegate.contact_id!=nil)
  3434. if(appDelegate.password!=nil)
  3435. [params setValue:appDelegate.password forKey:@"password"];
  3436. [params setValue:contactid forKey:@"contactId"];
  3437. [params setValue:url forKey:@"business_card"];
  3438. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  3439. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  3440. if(appDelegate.offline_mode)
  3441. {
  3442. return [OLDataProvider offline_notimpl];
  3443. }
  3444. if(![self IsNetworkAvailable])
  3445. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3446. NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  3447. if(json==nil)
  3448. return nil;
  3449. NSError *error=nil;
  3450. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3451. return jsobj;
  3452. }
  3453. +(NSDictionary*)request_PendingOrder:(NSString *)contactid
  3454. {
  3455. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3456. __block AppDelegate *appDelegate = nil;
  3457. dispatch_sync(dispatch_get_main_queue(), ^{
  3458. //some UI methods ej
  3459. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3460. });
  3461. if(appDelegate.user!=nil)
  3462. [params setValue:appDelegate.user forKey:@"user"];
  3463. // if(appDelegate.contact_id!=nil)
  3464. if(appDelegate.password!=nil)
  3465. [params setValue:appDelegate.password forKey:@"password"];
  3466. [params setValue:contactid forKey:@"contactId"];
  3467. if(appDelegate.offline_mode)
  3468. {
  3469. return [OLDataProvider offline_notimpl];
  3470. }
  3471. if(![self IsNetworkAvailable])
  3472. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3473. NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  3474. if(json==nil)
  3475. return nil;
  3476. NSError *error=nil;
  3477. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3478. return jsobj;
  3479. }
  3480. //+(NSDictionary*)request_CustomerInfo:(NSString* ) contactid
  3481. //{
  3482. //
  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. //
  3495. // if(appDelegate.password!=nil)
  3496. // [params setValue:appDelegate.password forKey:@"password"];
  3497. // [params setValue:contactid forKey:@"contactId"];
  3498. //
  3499. // [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  3500. //
  3501. // if(appDelegate.offline_mode)
  3502. // return [OLDataProvider offline_contactinfo:params];
  3503. // if(![self IsNetworkAvailable])
  3504. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3505. //
  3506. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  3507. // if(json==nil)
  3508. // return nil;
  3509. // NSError *error=nil;
  3510. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3511. // return jsobj;
  3512. //
  3513. //}
  3514. +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
  3515. {
  3516. DebugLog(@"parse_authinfo");
  3517. NSError *error=nil;
  3518. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3519. if(jsobj)
  3520. {
  3521. __block AppDelegate *appDelegate = nil;
  3522. dispatch_sync(dispatch_get_main_queue(), ^{
  3523. //some UI methods ej
  3524. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3525. });
  3526. int result = [[jsobj valueForKey:@"result"] intValue];
  3527. if (result<0)
  3528. return result;
  3529. if(result!=AP_USER_AUTH&& result!=9)
  3530. {
  3531. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  3532. // [appDelegate Logout];
  3533. if(result==8)
  3534. {
  3535. return RESULT_LOGIN_DEVICE;
  3536. }
  3537. return RESULT_FALSE;
  3538. }
  3539. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  3540. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  3541. user=[objheader objectForKey:@"username"] ;
  3542. DebugLog(@"required_ver=%@ ",required_ver);
  3543. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  3544. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  3545. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  3546. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  3547. // if([ibadge isEqual:[NSNull null]])
  3548. // strbadge=@"0";
  3549. // if(ibadge==nil)
  3550. // ibadge=@"0";
  3551. // if([strbadge isEqualToString:@"null"])
  3552. // strbadge=@"0";
  3553. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  3554. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  3555. if([appDelegate.build intValue]<[required_ver intValue])
  3556. return RESULT_VER_LOW;
  3557. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  3558. appDelegate.user = user;
  3559. appDelegate.password = password;
  3560. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  3561. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  3562. appDelegate.bLogin = true;
  3563. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  3564. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  3565. {
  3566. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  3567. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  3568. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  3569. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  3570. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  3571. }
  3572. NSString* mode =[jsobj valueForKey:@"mode"] ;
  3573. [appDelegate SetMode:mode];
  3574. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  3575. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  3576. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  3577. [appDelegate update_count_mark];
  3578. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  3579. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  3580. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  3581. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  3582. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  3583. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  3584. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  3585. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  3586. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  3587. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  3588. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  3589. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  3590. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  3591. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  3592. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  3593. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  3594. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  3595. [appDelegate set_main_button_panel];
  3596. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  3597. // shop order status filter
  3598. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  3599. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  3600. // Sales order status filter
  3601. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  3602. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  3603. // specialInstruction
  3604. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  3605. //-价格类型
  3606. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  3607. // 权限
  3608. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  3609. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  3610. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  3611. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  3612. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  3613. [[RASingleton sharedInstance] resetGlobalLock];
  3614. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  3615. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  3616. }
  3617. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  3618. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  3619. // {
  3620. // // no update on the server;
  3621. // return RESULT_TRUE;
  3622. // }
  3623. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  3624. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3625. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3626. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3627. // [defaults synchronize];
  3628. //
  3629. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  3630. // NSArray* keys= [objfuncs allKeys];
  3631. /*
  3632. db.setTransactionSuccessful();
  3633. db.endTransaction();
  3634. */
  3635. return RESULT_TRUE;
  3636. }
  3637. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  3638. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  3639. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  3640. return RESULT_USERAUTH_ERROR;
  3641. }
  3642. //+(bool) IsNetworkAvailable
  3643. //{
  3644. //
  3645. // if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) &&
  3646. // ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable))
  3647. // return false;
  3648. // return true;
  3649. //}
  3650. //+(NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim
  3651. //{
  3652. // NSScanner *theScanner = [NSScanner scannerWithString:html];
  3653. // NSString *text = nil;
  3654. //
  3655. // while ([theScanner isAtEnd] == NO) {
  3656. // // find start of tag
  3657. // [theScanner scanUpToString:@"<" intoString:NULL] ;
  3658. // // find end of tag
  3659. // [theScanner scanUpToString:@">" intoString:&text] ;
  3660. // // replace the found tag with a space
  3661. // //(you can filter multi-spaces out later if you wish)
  3662. // html = [html stringByReplacingOccurrencesOfString:
  3663. // [ NSString stringWithFormat:@"%@>", text]
  3664. // withString:@""];
  3665. // }
  3666. //
  3667. // return trim ? [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : html;
  3668. //}
  3669. //
  3670. //+(NSString *)flattenURL:(NSString *)url trimWhiteSpace:(BOOL)trim
  3671. //{
  3672. // NSScanner *theScanner = [NSScanner scannerWithString:url];
  3673. // NSString *text = nil;
  3674. //
  3675. // while ([theScanner isAtEnd] == NO) {
  3676. // // find start of tag
  3677. // [theScanner scanUpToString:@"/" intoString:NULL] ;
  3678. // // find end of tag
  3679. // [theScanner scanUpToString:@"/" intoString:&text] ;
  3680. // // replace the found tag with a space
  3681. // //(you can filter multi-spaces out later if you wish)
  3682. // url = [url stringByReplacingOccurrencesOfString:
  3683. // [ NSString stringWithFormat:@"%@", text]
  3684. // withString:@""];
  3685. // }
  3686. //
  3687. // return trim ? [url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : url;
  3688. //}
  3689. + (NSDictionary *)set_npd_shop_price_type:(NSInteger)priceType {
  3690. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3691. __block AppDelegate *appDelegate = nil;
  3692. dispatch_sync(dispatch_get_main_queue(), ^{
  3693. //some UI methods ej
  3694. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3695. });
  3696. if(appDelegate.user!=nil)
  3697. [dic setValue:appDelegate.user forKey:@"user"];
  3698. if(appDelegate.password!=nil)
  3699. [dic setValue:appDelegate.password forKey:@"password"];
  3700. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  3701. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  3702. NSData* json=nil;
  3703. if(appDelegate.offline_mode)
  3704. {
  3705. return [OLDataProvider offline_notimpl];
  3706. }
  3707. else
  3708. {
  3709. if(![self IsNetworkAvailable])
  3710. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3711. json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  3712. }
  3713. if(json!=nil)
  3714. {
  3715. NSError *error=nil;
  3716. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3717. return jsobj;
  3718. }
  3719. return nil;
  3720. }
  3721. + (NSDictionary *)get_npd_shop_givenPrice {
  3722. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3723. __block AppDelegate *appDelegate = nil;
  3724. dispatch_sync(dispatch_get_main_queue(), ^{
  3725. //some UI methods ej
  3726. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3727. });
  3728. if(appDelegate.user!=nil)
  3729. [dic setValue:appDelegate.user forKey:@"user"];
  3730. if(appDelegate.password!=nil)
  3731. [dic setValue:appDelegate.password forKey:@"password"];
  3732. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  3733. NSData* json=nil;
  3734. if(appDelegate.offline_mode)
  3735. {
  3736. return [OLDataProvider offline_notimpl];
  3737. }
  3738. else
  3739. {
  3740. if(![self IsNetworkAvailable])
  3741. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3742. json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  3743. }
  3744. if(json!=nil)
  3745. {
  3746. NSError *error=nil;
  3747. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3748. return jsobj;
  3749. }
  3750. return nil;
  3751. }
  3752. + (NSDictionary *)set_npd_shop_givenPrice:(NSMutableDictionary *)params {
  3753. __block AppDelegate *appDelegate = nil;
  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. if(appDelegate.password!=nil)
  3761. [params setValue:appDelegate.password forKey:@"password"];
  3762. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  3763. NSData* json=nil;
  3764. if(appDelegate.offline_mode)
  3765. {
  3766. return [OLDataProvider offline_notimpl];
  3767. }
  3768. else
  3769. {
  3770. if(![self IsNetworkAvailable])
  3771. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3772. json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  3773. }
  3774. if(json!=nil)
  3775. {
  3776. NSError *error=nil;
  3777. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3778. return jsobj;
  3779. }
  3780. return nil;
  3781. }
  3782. + (NSDictionary *)merge_order:(NSMutableDictionary *)params {
  3783. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3784. __block AppDelegate *appDelegate = nil;
  3785. dispatch_sync(dispatch_get_main_queue(), ^{
  3786. //some UI methods ej
  3787. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3788. });
  3789. if(appDelegate.user!=nil)
  3790. [dic setValue:appDelegate.user forKey:@"user"];
  3791. if(appDelegate.password!=nil)
  3792. [dic setValue:appDelegate.password forKey:@"password"];
  3793. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  3794. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  3795. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  3796. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  3797. NSData* json=nil;
  3798. if(appDelegate.offline_mode)
  3799. {
  3800. return [OLDataProvider offline_notimpl];
  3801. }
  3802. else
  3803. {
  3804. if(![self IsNetworkAvailable])
  3805. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3806. json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  3807. }
  3808. if(json!=nil)
  3809. {
  3810. NSError *error=nil;
  3811. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3812. return jsobj;
  3813. }
  3814. else
  3815. return nil;
  3816. }
  3817. //+ (NSDictionary *)lock_order:(NSString *)oderCode
  3818. //{
  3819. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3820. // __block AppDelegate *appDelegate = nil;
  3821. //
  3822. // dispatch_sync(dispatch_get_main_queue(), ^{
  3823. // //some UI methods ej
  3824. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3825. // });
  3826. // if(appDelegate.user!=nil)
  3827. // [params setValue:appDelegate.user forKey:@"user"];
  3828. //
  3829. // if(appDelegate.password!=nil)
  3830. // [params setValue:appDelegate.password forKey:@"password"];
  3831. //
  3832. // [params setValue:oderCode forKey:@"orderCode"];
  3833. //
  3834. // NSData* json=nil;
  3835. // if(appDelegate.offline_mode)
  3836. // {
  3837. // json=[OLDataProvider offline_editorder:params];
  3838. //
  3839. // }
  3840. // else
  3841. // {
  3842. // if(![self IsNetworkAvailable])
  3843. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3844. //
  3845. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  3846. // }
  3847. // if(json!=nil)
  3848. // {
  3849. // NSError *error=nil;
  3850. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3851. //
  3852. // return jsobj;
  3853. // }
  3854. // else
  3855. // return nil;
  3856. //}
  3857. + (NSDictionary *)quoteOrder:(NSString *)so_id emailAddr:(NSString *)addr {
  3858. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3859. __block AppDelegate *appDelegate = nil;
  3860. dispatch_sync(dispatch_get_main_queue(), ^{
  3861. //some UI methods ej
  3862. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3863. });
  3864. if(appDelegate.user!=nil)
  3865. [dic setValue:appDelegate.user forKey:@"user"];
  3866. if(appDelegate.password!=nil)
  3867. [dic setValue:appDelegate.password forKey:@"password"];
  3868. [dic setValue:so_id forKey:@"orderCode"];
  3869. [dic setValue:addr forKey:@"email"];
  3870. [dic setObject:ScreenCodeCart forKey:kScreenName];
  3871. if (appDelegate.customerInfo) {
  3872. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  3873. if (customer_cid) {
  3874. [dic setValue:customer_cid forKey:@"contactId"];
  3875. }
  3876. }
  3877. NSData* json=nil;
  3878. if(appDelegate.offline_mode)
  3879. {
  3880. return [OLDataProvider offline_notimpl];
  3881. }
  3882. else
  3883. {
  3884. if(![self IsNetworkAvailable])
  3885. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3886. json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  3887. }
  3888. if(json!=nil)
  3889. {
  3890. NSError *error=nil;
  3891. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3892. return jsobj;
  3893. }
  3894. return @{@"result" : @(RESULT_FALSE)};
  3895. }
  3896. + (NSDictionary *)notifyModel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName{
  3897. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3898. __block AppDelegate *appDelegate = nil;
  3899. dispatch_sync(dispatch_get_main_queue(), ^{
  3900. //some UI methods ej
  3901. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3902. });
  3903. if(appDelegate.user!=nil)
  3904. [dic setValue:appDelegate.user forKey:@"user"];
  3905. if(appDelegate.password!=nil)
  3906. [dic setValue:appDelegate.password forKey:@"password"];
  3907. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  3908. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  3909. if (customer_cid) {
  3910. [dic setValue:customer_cid forKey:@"contactId"];
  3911. }
  3912. }
  3913. [dic setObject:screenName forKey:kScreenName];
  3914. [dic setValue:modelID forKey:@"productId"];
  3915. if (addr) { // 弹框输入
  3916. [dic setValue:addr forKey:@"email"];
  3917. } else {
  3918. // employee选择了Contact,并且Contact有Email
  3919. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  3920. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  3921. // if (email) {
  3922. // [dic setValue:email forKey:@"email"];
  3923. // }
  3924. // }
  3925. }
  3926. NSData* json=nil;
  3927. if(appDelegate.offline_mode)
  3928. {
  3929. return [OLDataProvider offline_notimpl];
  3930. }
  3931. else
  3932. {
  3933. if(![self IsNetworkAvailable])
  3934. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3935. json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  3936. }
  3937. if(json!=nil)
  3938. {
  3939. NSError *error=nil;
  3940. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3941. return jsobj;
  3942. }
  3943. return @{@"result" : @(RESULT_FALSE)};
  3944. }
  3945. + (NSDictionary *)quoteWishlist2EmailAddr:(NSString *)addr {
  3946. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3947. __block AppDelegate *appDelegate = nil;
  3948. dispatch_sync(dispatch_get_main_queue(), ^{
  3949. //some UI methods ej
  3950. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3951. });
  3952. if(appDelegate.user!=nil)
  3953. [dic setValue:appDelegate.user forKey:@"user"];
  3954. if(appDelegate.password!=nil)
  3955. [dic setValue:appDelegate.password forKey:@"password"];
  3956. [dic setValue:addr forKey:@"email"];
  3957. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  3958. // if (appDelegate.customerInfo) {
  3959. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  3960. // if (customer_cid) {
  3961. // [dic setValue:customer_cid forKey:@"contactId"];
  3962. // }
  3963. // }
  3964. NSData* json=nil;
  3965. if(appDelegate.offline_mode)
  3966. {
  3967. return [OLDataProvider offline_notimpl];
  3968. }
  3969. else
  3970. {
  3971. if(![self IsNetworkAvailable])
  3972. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3973. json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  3974. }
  3975. if(json!=nil)
  3976. {
  3977. NSError *error=nil;
  3978. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3979. return jsobj;
  3980. }
  3981. return @{@"result" : @(RESULT_FALSE)};
  3982. }
  3983. + (NSDictionary *)movetobackorder:(NSString *)cart_item_id {
  3984. if (cart_item_id == nil || cart_item_id.length < 1) {
  3985. return @{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"};
  3986. }
  3987. __block AppDelegate *appDelegate = nil;
  3988. dispatch_sync(dispatch_get_main_queue(), ^{
  3989. //some UI methods ej
  3990. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3991. });
  3992. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3993. if(appDelegate.user!=nil)
  3994. [dic setValue:appDelegate.user forKey:@"user"];
  3995. if(appDelegate.password!=nil)
  3996. [dic setValue:appDelegate.password forKey:@"password"];
  3997. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  3998. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  3999. [dic setObject:ScreenCodeCart forKey:kScreenName];
  4000. if(![self IsNetworkAvailable])
  4001. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4002. NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  4003. if(json!=nil)
  4004. {
  4005. NSError *error=nil;
  4006. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4007. return jsobj;
  4008. }
  4009. return @{@"result" : @(RESULT_FALSE)};
  4010. }
  4011. + (NSDictionary*)request_hangTag:(NSString *)group {
  4012. #ifdef BUILD_UWAVER
  4013. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4014. __block AppDelegate *appDelegate = nil;
  4015. dispatch_sync(dispatch_get_main_queue(), ^{
  4016. //some UI methods ej
  4017. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4018. });
  4019. if(appDelegate.user!=nil)
  4020. [params setValue:appDelegate.user forKey:@"user"];
  4021. if(appDelegate.contact_id!=nil)
  4022. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4023. if(appDelegate.password!=nil)
  4024. [params setValue:appDelegate.password forKey:@"password"];
  4025. if (group) {
  4026. [params setValue:group forKey:@"groupName"];
  4027. }
  4028. NSString * uuid= [[NSUUID UUID] UUIDString];
  4029. params[@"resultSerial"]=uuid;
  4030. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4031. NSData* json = nil;
  4032. if(appDelegate.offline_mode)
  4033. {
  4034. return [OLDataProvider offline_notimpl];
  4035. } else {
  4036. if(![self IsNetworkAvailable])
  4037. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4038. json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  4039. }
  4040. if(json==nil)
  4041. return nil;
  4042. NSError *error=nil;
  4043. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4044. return jsobj;
  4045. #else
  4046. return nil;
  4047. #endif
  4048. }
  4049. #pragma mark 2020 new interface
  4050. // 新接口逐步替换以前的网络请求,2020
  4051. +(void)request_home:(int) price_template customid:(int) customid completionHandler:(resultHandler)result
  4052. {
  4053. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4054. AppDelegate *appDelegate = nil;
  4055. //some UI methods ej
  4056. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4057. if(appDelegate.user!=nil)
  4058. [params setValue:appDelegate.user forKey:@"user"];
  4059. if(appDelegate.contact_id!=nil)
  4060. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4061. if(appDelegate.password!=nil)
  4062. [params setValue:appDelegate.password forKey:@"password"];
  4063. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4064. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4065. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  4066. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4067. if(appDelegate.offline_mode)
  4068. {
  4069. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4070. NSMutableDictionary* json = [[OLDataProvider offline_home] mutableCopy];
  4071. dispatch_async(dispatch_get_main_queue(), ^{
  4072. result(json);
  4073. });
  4074. });
  4075. return;
  4076. }
  4077. [self request_interface:URL_LOAD_HOME parameters:params err_record_url:nil completionHandler:result retry:0];
  4078. return;
  4079. }
  4080. +(void)request_category:(resultHandler)result
  4081. {
  4082. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  4083. AppDelegate *appDelegate = nil;
  4084. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4085. if(appDelegate.offline_mode)
  4086. {
  4087. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4088. NSMutableDictionary* json = [[OLDataProvider offline_category_menu] mutableCopy];
  4089. dispatch_async(dispatch_get_main_queue(), ^{
  4090. result(json);
  4091. });
  4092. });
  4093. return;
  4094. }
  4095. [self request_interface:URL_REQUEST_CATMENU parameters:[NSMutableDictionary new] err_record_url:nil completionHandler:result retry:0];
  4096. //
  4097. // if(![self IsNetworkAvailable])
  4098. // {
  4099. // DebugLog(@"NET ERR");
  4100. //
  4101. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4102. // // return nil;
  4103. // }
  4104. //
  4105. // NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  4106. // //if(json==nil)
  4107. //
  4108. //
  4109. // if(json==nil)
  4110. // return nil;
  4111. // NSError *error=nil;
  4112. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4113. // return jsobj;
  4114. }
  4115. +(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
  4116. {
  4117. AppDelegate *appDelegate = nil;
  4118. //some UI methods ej
  4119. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4120. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4121. if(appDelegate.user!=nil)
  4122. [params setValue:appDelegate.user forKey:@"user"];
  4123. if(appDelegate.contact_id!=nil)
  4124. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4125. if(appDelegate.password!=nil)
  4126. [params setValue:appDelegate.password forKey:@"password"];
  4127. if(appDelegate.order_code!=nil)
  4128. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4129. [params setValue:alert forKey:@"alert"];
  4130. [params setValue:qty forKey:@"sold_by_qty"];
  4131. [params setValue:available forKey:@"available"];
  4132. [params setValue:price forKey:@"price"];
  4133. [params setValue:bestseller forKey:@"bestseller"];
  4134. [params setValue:modelname forKey:@"modelName"];
  4135. [params setValue:modeldescrip forKey:@"modelDescription"];
  4136. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4137. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4138. [params setValue:category forKey:@"category"];
  4139. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4140. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4141. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4142. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4143. [params setValue:filter forKey:@"filter"];
  4144. [params setValue:keyword forKey:@"keyword"];
  4145. [params setObject:ScreenCodeCategory forKey:kScreenName];
  4146. if (alert) {
  4147. [params setObject:@"Filter" forKey:kAction];
  4148. }
  4149. if ([RASingleton sharedInstance].homeItemClick) {
  4150. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  4151. [RASingleton sharedInstance].homeItemClick = NO;
  4152. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  4153. [RASingleton sharedInstance].homeClickedItemName = nil;
  4154. [params setObject:extra forKey:kExtra];
  4155. }
  4156. if(appDelegate.offline_mode)
  4157. {
  4158. // [OLDataProvider offline_category:params completionHandler:result];
  4159. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4160. NSMutableDictionary* json = [[OLDataProvider offline_category:params] mutableCopy];
  4161. dispatch_async(dispatch_get_main_queue(), ^{
  4162. result(json);
  4163. });
  4164. });
  4165. return;
  4166. }
  4167. [self request_interface:URL_CATEGORY parameters:params err_record_url:nil completionHandler:result retry:0];
  4168. return ;
  4169. //
  4170. // if(![self IsNetworkAvailable])
  4171. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4172. //
  4173. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  4174. // if(json==nil)
  4175. // return nil;
  4176. // NSError *error=nil;
  4177. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4178. // return jsobj;
  4179. //
  4180. }
  4181. +(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
  4182. {
  4183. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4184. AppDelegate *appDelegate = nil;
  4185. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4186. if(appDelegate.user!=nil)
  4187. [params setValue:appDelegate.user forKey:@"user"];
  4188. if(appDelegate.contact_id!=nil)
  4189. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4190. if(appDelegate.password!=nil)
  4191. [params setValue:appDelegate.password forKey:@"password"];
  4192. if(appDelegate.order_code!=nil)
  4193. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4194. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4195. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4196. if(use_name)
  4197. [params setValue:model_name forKey:@"product_name"];
  4198. else
  4199. if(use_upc){
  4200. params[@"search_upc"]=@true;
  4201. [params setValue:upc_code forKey:@"upc_code"];
  4202. }
  4203. else
  4204. [params setValue:item_id forKey:@"product_id"];
  4205. [params setValue:category_id forKey:@"category"];
  4206. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4207. [params setObject:@"Open A Model" forKey:kAction];
  4208. if (model_name) {
  4209. NSDictionary *extra = @{@"ModelName" : model_name};
  4210. [params setObject:extra forKey:kExtra];
  4211. }
  4212. if (groupName.length > 0) {
  4213. [params setObject:groupName forKey:@"groupName"];
  4214. }
  4215. if(appDelegate.offline_mode)
  4216. {
  4217. [OLDataProvider offline_model:params completionHandler:result];
  4218. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4219. // NSMutableDictionary* json = [[OLDataProvider offline_model:params] mutableCopy];
  4220. // dispatch_async(dispatch_get_main_queue(), ^{
  4221. // result(json);
  4222. // });
  4223. // });
  4224. return;
  4225. }
  4226. [self request_interface:URL_ITEM_DETAIL parameters:params err_record_url:nil completionHandler:result retry:0];
  4227. //
  4228. // if(appDelegate.offline_mode)
  4229. // return [OLDataProvider offline_model:params];
  4230. //
  4231. // if(![self IsNetworkAvailable])
  4232. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4233. //
  4234. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  4235. // if(json==nil)
  4236. // return nil;
  4237. // NSError *error=nil;
  4238. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4239. // return jsobj;
  4240. }
  4241. +(void)request_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull completionHandler:(resultHandler)result
  4242. {
  4243. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4244. AppDelegate *appDelegate = nil;
  4245. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4246. if(appDelegate.user!=nil)
  4247. [params setValue:appDelegate.user forKey:@"user"];
  4248. if(appDelegate.contact_id!=nil)
  4249. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4250. if(appDelegate.password!=nil)
  4251. [params setValue:appDelegate.password forKey:@"password"];
  4252. if(appDelegate.order_code!=nil)
  4253. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4254. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4255. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4256. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  4257. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4258. // [params setValue:filter forKey:@"filter"];
  4259. [params setValue:keywords forKey:@"keyword"];
  4260. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4261. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4262. if(matchfull)
  4263. [params setValue:@"true" forKey:@"exactMatch"];
  4264. else
  4265. [params setValue:@"false" forKey:@"exactMatch"];
  4266. [params setObject:ScreenCodeSearch forKey:kScreenName];
  4267. if (keywords) {
  4268. [params setObject:@"Search" forKey:kAction];
  4269. }
  4270. if(appDelegate.offline_mode)
  4271. {
  4272. // [OLDataProvider offline_search:params completionHandler:result];
  4273. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4274. NSMutableDictionary* json = [[OLDataProvider offline_search:params] mutableCopy];
  4275. dispatch_async(dispatch_get_main_queue(), ^{
  4276. result(json);
  4277. });
  4278. });
  4279. return;
  4280. }
  4281. [self request_interface:URL_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  4282. // if(appDelegate.offline_mode)
  4283. // {
  4284. // return [OLDataProvider offline_search:params];
  4285. // }
  4286. // if(![self IsNetworkAvailable])
  4287. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4288. //
  4289. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  4290. // if(json==nil)
  4291. // return nil;
  4292. // NSError *error=nil;
  4293. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4294. // return jsobj;
  4295. }
  4296. +(void)request_login: (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
  4297. {
  4298. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  4299. // return RESULT_NET_ERROR;
  4300. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4301. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4302. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4303. AppDelegate *appDelegate = nil;
  4304. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4305. if(appDelegate.duid !=nil)
  4306. [params setValue:appDelegate.duid forKey:@"udid"];
  4307. [params setValue:@"handset_login" forKey:@"action"];
  4308. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  4309. [params setValue:user forKey:@"user"];
  4310. [params setValue:password forKey:@"password"];
  4311. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  4312. #ifdef TEST
  4313. [params setValue:@"true" forKey:@"is_debug"];
  4314. #else
  4315. [params setValue:@"false" forKey:@"is_debug"];
  4316. #endif
  4317. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  4318. [params setObject:@"Login" forKey:kAction];
  4319. if(appDelegate.offline_mode)
  4320. {
  4321. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4322. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_login:params]] mutableCopy];
  4323. dispatch_async(dispatch_get_main_queue(), ^{
  4324. int ret = [self parse_logininfo:json user:user password:password] ;
  4325. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4326. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4327. result(retjson);
  4328. });
  4329. });
  4330. return;
  4331. }
  4332. NSString* url;
  4333. bool scan_guest = false;
  4334. #ifdef SCANNER_ORDER
  4335. params[@"site_name"]=[RADataProvider getSiteName];
  4336. params[@"_method"]=@"login";
  4337. url = [appDelegate.address stringByAppendingPathComponent:URL_UPDATE_AUTH];
  4338. if([user.uppercaseString isEqualToString:@"GUEST"]&&[password.uppercaseString isEqualToString:@"GUEST"])
  4339. scan_guest = true;
  4340. #else
  4341. url = URL_UPDATE_AUTH;
  4342. #endif
  4343. if(scan_guest)
  4344. {
  4345. [OLDataProvider realguestLogin];
  4346. // int ret = [self parse_logininfo:chresult user:user password:password] ;
  4347. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4348. retjson[@"result"]= [NSNumber numberWithInt:RESULT_TRUE];
  4349. result(retjson);
  4350. }
  4351. else
  4352. {
  4353. [self request_interface:url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *chresult) {
  4354. int ret = [self parse_logininfo:chresult user:user password:password] ;
  4355. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4356. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4357. result(retjson);
  4358. } retry:0];
  4359. }
  4360. //
  4361. // NSData* json= nil;
  4362. // if(appDelegate.offline_mode)
  4363. // {
  4364. // json= [OLDataProvider offline_login:params] ;
  4365. //
  4366. // }
  4367. // else
  4368. // {
  4369. // if(![self IsNetworkAvailable])
  4370. // return RESULT_NET_NOTAVAILABLE;
  4371. // json =[self get_json:URL_UPDATE_AUTH parameters:params];
  4372. //
  4373. // }
  4374. //
  4375. // if(json==nil)
  4376. // return RESULT_NET_ERROR;
  4377. //
  4378. // int ret = [self parse_authinfo:json user:user password:password];
  4379. // DebugLog(@"parse_authinfo return %d ",ret);
  4380. //
  4381. //
  4382. // return ret;
  4383. //
  4384. }
  4385. +(int)parse_logininfo : (NSMutableDictionary *) jsobj user:(NSString*) user password:(NSString*) password
  4386. {
  4387. // DebugLog(@"parse_authinfo");
  4388. // NSError *error=nil;
  4389. //
  4390. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4391. if(jsobj)
  4392. {
  4393. AppDelegate *appDelegate = nil;
  4394. //some UI methods ej
  4395. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4396. int result = [[jsobj valueForKey:@"result"] intValue];
  4397. if (result<0)
  4398. return result;
  4399. if(result!=AP_USER_AUTH&& result!=9)
  4400. {
  4401. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  4402. // [appDelegate Logout];
  4403. if(result==8)
  4404. {
  4405. return RESULT_LOGIN_DEVICE;
  4406. }
  4407. return RESULT_FALSE;
  4408. }
  4409. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  4410. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  4411. user=[objheader objectForKey:@"username"] ;
  4412. DebugLog(@"required_ver=%@ ",required_ver);
  4413. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  4414. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  4415. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  4416. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  4417. // if([ibadge isEqual:[NSNull null]])
  4418. // strbadge=@"0";
  4419. // if(ibadge==nil)
  4420. // ibadge=@"0";
  4421. // if([strbadge isEqualToString:@"null"])
  4422. // strbadge=@"0";
  4423. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  4424. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  4425. #ifndef SCANNER_ORDER
  4426. if([appDelegate.build intValue]<[required_ver intValue])
  4427. return RESULT_VER_LOW;
  4428. #endif
  4429. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  4430. appDelegate.user = user;
  4431. appDelegate.password = password;
  4432. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  4433. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  4434. appDelegate.bLogin = true;
  4435. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  4436. #ifdef SCANNER_ORDER
  4437. appDelegate.available_price_group = objheader[@"price_group"];
  4438. [RADataProvider default_price_group];
  4439. #endif
  4440. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  4441. {
  4442. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  4443. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  4444. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  4445. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  4446. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  4447. }
  4448. NSString* mode =[jsobj valueForKey:@"mode"] ;
  4449. [appDelegate SetMode:mode];
  4450. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  4451. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  4452. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  4453. [appDelegate update_count_mark];
  4454. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  4455. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  4456. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  4457. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  4458. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  4459. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  4460. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  4461. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  4462. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  4463. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  4464. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  4465. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  4466. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  4467. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  4468. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  4469. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  4470. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  4471. [appDelegate set_main_button_panel];
  4472. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  4473. // shop order status filter
  4474. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  4475. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  4476. // Sales order status filter
  4477. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  4478. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  4479. // specialInstruction
  4480. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  4481. //-价格类型
  4482. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  4483. // 权限
  4484. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  4485. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  4486. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  4487. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  4488. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  4489. [[RASingleton sharedInstance] resetGlobalLock];
  4490. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  4491. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  4492. }
  4493. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  4494. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  4495. // {
  4496. // // no update on the server;
  4497. // return RESULT_TRUE;
  4498. // }
  4499. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  4500. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4501. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4502. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4503. // [defaults synchronize];
  4504. //
  4505. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  4506. // NSArray* keys= [objfuncs allKeys];
  4507. /*
  4508. db.setTransactionSuccessful();
  4509. db.endTransaction();
  4510. */
  4511. return RESULT_TRUE;
  4512. }
  4513. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  4514. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  4515. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  4516. return RESULT_USERAUTH_ERROR;
  4517. }
  4518. +(void)request_contactlist:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams completionHandler:(resultHandler)result
  4519. {
  4520. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4521. if(upparams!=nil)
  4522. params = [upparams mutableCopy];
  4523. AppDelegate *appDelegate = nil;
  4524. //some UI methods ej
  4525. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4526. if(appDelegate.user!=nil)
  4527. [params setValue:appDelegate.user forKey:@"user"];
  4528. if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  4529. [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  4530. else
  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",offset ] forKey:@"offset"];
  4535. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  4536. [params setValue:contact_type forKey:@"contactType"];
  4537. [params setValue:keywords forKey:@"keyword"];
  4538. [params setObject:ScreenCodeAccount forKey:kScreenName];
  4539. if (keywords) {
  4540. [params setObject:@"Search" forKey:kAction];
  4541. }
  4542. if (upparams) {
  4543. [params setObject:@"Advance Search" forKey:kAction];
  4544. }
  4545. NSString* url=nil;
  4546. if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  4547. url=URL_SHIPTO_LIST;
  4548. else
  4549. url=URL_CONTACT_LIST;
  4550. if(appDelegate.offline_mode)
  4551. {
  4552. [OLDataProvider offline_contactlist:params completionHandler:result];
  4553. return;
  4554. }
  4555. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  4556. //
  4557. // if(appDelegate.offline_mode)
  4558. // return [OLDataProvider offline_contactlist:params];
  4559. //
  4560. // if(![self IsNetworkAvailable])
  4561. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4562. //
  4563. // NSData* json=[self get_json:url parameters:params];
  4564. // if(json==nil)
  4565. // return nil;
  4566. // NSError *error=nil;
  4567. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4568. // return jsobj;
  4569. }
  4570. +(void)request_contactinfo:(NSString* ) contactid completionHandler:(resultHandler)result
  4571. {
  4572. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4573. AppDelegate *appDelegate = nil;
  4574. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4575. if(appDelegate.user!=nil)
  4576. [params setValue:appDelegate.user forKey:@"user"];
  4577. // if(appDelegate.contact_id!=nil)
  4578. if(appDelegate.password!=nil)
  4579. [params setValue:appDelegate.password forKey:@"password"];
  4580. [params setValue:contactid forKey:@"contactId"];
  4581. [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  4582. if(appDelegate.offline_mode)
  4583. {
  4584. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4585. // [OLDataProvider offline_contactinfo:params completionHandler:result] ;
  4586. // });
  4587. params[@"mode"]=appDelegate.mode;
  4588. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4589. NSMutableDictionary* json = [[OLDataProvider offline_contactinfo:params] mutableCopy];
  4590. dispatch_async(dispatch_get_main_queue(), ^{
  4591. result(json);
  4592. });
  4593. });
  4594. return;
  4595. }
  4596. [self request_interface:URL_CUSTOMER_INFO parameters:params err_record_url:nil completionHandler:result retry:0];
  4597. // if(appDelegate.offline_mode)
  4598. // return [OLDataProvider offline_contactinfo:params];
  4599. // if(![self IsNetworkAvailable])
  4600. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4601. //
  4602. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  4603. // if(json==nil)
  4604. // return nil;
  4605. // NSError *error=nil;
  4606. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4607. // return jsobj;
  4608. //
  4609. }
  4610. +(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  4611. {
  4612. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4613. AppDelegate *appDelegate = nil;
  4614. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4615. if(appDelegate.user!=nil)
  4616. [params setValue:appDelegate.user forKey:@"user"];
  4617. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  4618. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  4619. // else
  4620. if(appDelegate.contact_id!=nil)
  4621. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4622. if(appDelegate.password!=nil)
  4623. [params setValue:appDelegate.password forKey:@"password"];
  4624. if(appDelegate.order_code!=nil)
  4625. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4626. bool can_create_backorder=appDelegate.can_create_backorder;
  4627. // [params setValue:sourceid forKey:@"sourceid"];
  4628. // [params setValue:editor forKey:@"editor"];
  4629. DebugLog(@"request editor url:%@",request_url);
  4630. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  4631. {
  4632. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  4633. }
  4634. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  4635. {
  4636. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  4637. }
  4638. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  4639. {
  4640. [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  4641. }
  4642. else if([request_url isEqualToString:URL_CARTDELIVERY])
  4643. {
  4644. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  4645. }
  4646. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  4647. {
  4648. [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  4649. }
  4650. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  4651. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  4652. }
  4653. if(appDelegate.offline_mode)
  4654. {
  4655. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4656. NSData* json = nil;
  4657. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  4658. {
  4659. json= [OLDataProvider offline_createContact:params];
  4660. }
  4661. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  4662. {
  4663. json= [OLDataProvider offline_editContact:params];
  4664. }
  4665. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  4666. {
  4667. json= [OLDataProvider offline_contactAdvancedSearch:params];
  4668. }
  4669. else if([request_url isEqualToString:URL_CARTDELIVERY])
  4670. {
  4671. params[@"contact_id"]=params[@"contactId"];
  4672. params[@"can_create_backorder"]=@(can_create_backorder);
  4673. json= [OLDataProvider offline_placeorder:params];
  4674. }
  4675. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  4676. {
  4677. json= [OLDataProvider offline_addreditor:params];
  4678. }
  4679. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  4680. json = [OLDataProvider offline_createTearSheet:params];
  4681. }
  4682. dispatch_async(dispatch_get_main_queue(), ^{
  4683. if(json==nil)
  4684. result( [[OLDataProvider offline_notimpl] mutableCopy]);
  4685. else
  4686. result([[RAConvertor data2dict:json] mutableCopy]);
  4687. });
  4688. });
  4689. return;
  4690. }
  4691. else
  4692. {
  4693. if([request_url isEqualToString:URL_CARTDELIVERY])
  4694. {
  4695. NSString * uuid= [[NSUUID UUID] UUIDString];
  4696. params[@"resultSerial"]=uuid;
  4697. __block bool bbreak = false;
  4698. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4699. for(int i=0;i<150;i++)
  4700. {
  4701. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  4702. // result_params[@"resultSerial"]=uuid;
  4703. //json=[self get_json:request_url parameters:params];
  4704. if(bbreak)
  4705. break;
  4706. dispatch_async(dispatch_get_main_queue(), ^{
  4707. DebugLog(@"request cart delivery %d",i);
  4708. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  4709. if(resulti!=nil)
  4710. {
  4711. if([resulti[@"result"] intValue]==2 || [resulti[@"result"] intValue] == 8)
  4712. {
  4713. if(!bbreak) //此判断保证result只调用一次。
  4714. {
  4715. result(resulti);
  4716. DebugLog(@"result called at %d",i);
  4717. }
  4718. bbreak=true;
  4719. }
  4720. }
  4721. } retry:3];
  4722. });
  4723. // [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  4724. sleep(2);
  4725. }
  4726. });
  4727. }
  4728. else
  4729. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  4730. }
  4731. // if(json!=nil)
  4732. // {
  4733. // NSError *error=nil;
  4734. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4735. // return jsobj;
  4736. // }
  4737. // else
  4738. // return nil;
  4739. }
  4740. +(void)request_wishlist:(int)sort completionHandler:(resultHandler)result
  4741. {
  4742. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4743. AppDelegate *appDelegate = nil;
  4744. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4745. if(appDelegate.user!=nil)
  4746. [params setValue:appDelegate.user forKey:@"user"];
  4747. if(appDelegate.contact_id!=nil)
  4748. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4749. if(appDelegate.password!=nil)
  4750. [params setValue:appDelegate.password forKey:@"password"];
  4751. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  4752. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  4753. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  4754. [params setObject:ScreenCodeWishList forKey:kScreenName];
  4755. if(appDelegate.offline_mode)
  4756. {
  4757. [OLDataProvider offline_wishlist:params completionHandler:^(NSMutableDictionary *resulti) {
  4758. int result_code = [[resulti valueForKey:@"result"] intValue];
  4759. if (result_code==2)
  4760. {
  4761. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  4762. [appDelegate update_count_mark];;
  4763. result(resulti);
  4764. }
  4765. }];
  4766. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4767. // NSMutableDictionary* json = [[OLDataProvider offline_wishlist:params] mutableCopy];
  4768. // dispatch_async(dispatch_get_main_queue(), ^{
  4769. // result(json);
  4770. // });
  4771. // });
  4772. return;
  4773. }
  4774. [self request_interface:URL_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  4775. int result_code = [[resulti valueForKey:@"result"] intValue];
  4776. if (result_code==2)
  4777. {
  4778. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  4779. [appDelegate update_count_mark];;
  4780. result(resulti);
  4781. }
  4782. } retry:0];
  4783. // if(appDelegate.offline_mode)
  4784. // {
  4785. // return [OLDataProvider offline_wishlist:params];
  4786. // }
  4787. // if(![self IsNetworkAvailable])
  4788. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4789. //
  4790. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  4791. // if(json==nil)
  4792. // return nil;
  4793. // NSError *error=nil;
  4794. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4795. // int result = [[jsobj valueForKey:@"result"] intValue];
  4796. //
  4797. // if (result==2)
  4798. // {
  4799. //
  4800. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  4801. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  4802. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  4803. //
  4804. // [appDelegate update_count_mark];
  4805. // }
  4806. // return jsobj;
  4807. }
  4808. +(void)request_portfoliolist:(int)sort completionHandler:(resultHandler)result
  4809. {
  4810. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4811. AppDelegate *appDelegate = nil;
  4812. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4813. if(appDelegate.user!=nil)
  4814. [params setValue:appDelegate.user forKey:@"user"];
  4815. if(appDelegate.contact_id!=nil)
  4816. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4817. if(appDelegate.password!=nil)
  4818. [params setValue:appDelegate.password forKey:@"password"];
  4819. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  4820. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  4821. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  4822. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  4823. if(appDelegate.offline_mode)
  4824. {
  4825. params[@"user"]=appDelegate.user;
  4826. params[@"contact_id"]=appDelegate.contact_id;
  4827. params[@"can_see_price"]=@(appDelegate.can_see_price);
  4828. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4829. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_portfolioList:params]] mutableCopy];
  4830. dispatch_async(dispatch_get_main_queue(), ^{
  4831. if ([json[@"result"] intValue]==2)
  4832. {
  4833. appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  4834. [appDelegate update_count_mark];
  4835. }
  4836. result(json);
  4837. });
  4838. });
  4839. return;
  4840. }
  4841. [self request_interface:URL_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  4842. if ([resulti[@"result"] intValue]==2)
  4843. {
  4844. appDelegate.port_count =[[resulti valueForKey:@"count"] intValue];
  4845. [appDelegate update_count_mark];
  4846. }
  4847. result(resulti);
  4848. } retry:0];
  4849. // NSData* json = nil;
  4850. // if(appDelegate.offline_mode)
  4851. // {
  4852. // json = [OLDataProvider offline_portfolioList:params];
  4853. // } else {
  4854. // if(![self IsNetworkAvailable])
  4855. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4856. //
  4857. // json = [self get_json:URL_PORTFOLIO parameters:params];
  4858. // }
  4859. //
  4860. //
  4861. // if(json==nil)
  4862. // return nil;
  4863. // NSError *error=nil;
  4864. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4865. // int result = [[jsobj valueForKey:@"result"] intValue];
  4866. //
  4867. // if (result==2)
  4868. // {
  4869. //
  4870. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  4871. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  4872. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  4873. //
  4874. // [appDelegate update_count_mark];
  4875. // }
  4876. // return jsobj;
  4877. }
  4878. +(void)request_portfoliopdf:(int ) offset limit:(int)limit keywords:(NSString* ) keywords completionHandler:(resultHandler)result
  4879. {
  4880. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4881. AppDelegate *appDelegate = nil;
  4882. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4883. if(appDelegate.user!=nil)
  4884. [params setValue:appDelegate.user forKey:@"user"];
  4885. if(appDelegate.contact_id!=nil)
  4886. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4887. if(appDelegate.password!=nil)
  4888. [params setValue:appDelegate.password forKey:@"password"];
  4889. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4890. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4891. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  4892. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4893. // [params setValue:filter forKey:@"filter"];
  4894. [params setValue:keywords forKey:@"keyWord"];
  4895. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  4896. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  4897. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  4898. if (keywords) {
  4899. [params setObject:@"Search" forKey:kAction];
  4900. }
  4901. if(appDelegate.offline_mode)
  4902. {
  4903. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4904. NSData* json = [[OLDataProvider offline_pdfList:params] mutableCopy];
  4905. dispatch_async(dispatch_get_main_queue(), ^{
  4906. result([[RAConvertor data2dict:json] mutableCopy]);
  4907. });
  4908. });
  4909. return;
  4910. }
  4911. [self request_interface:URL_DM_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  4912. return;
  4913. // NSData* json = nil;
  4914. // if(appDelegate.offline_mode)
  4915. // {
  4916. // json = [OLDataProvider offline_pdfList:params];
  4917. // } else {
  4918. // if(![self IsNetworkAvailable])
  4919. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4920. //
  4921. // json=[self get_json:URL_DM_LIST parameters:params];
  4922. // }
  4923. // if(json==nil)
  4924. // return nil;
  4925. // NSError *error=nil;
  4926. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4927. // return jsobj;
  4928. }
  4929. +(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
  4930. {
  4931. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4932. AppDelegate *appDelegate = nil;
  4933. //some UI methods ej
  4934. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4935. if(appDelegate.user!=nil)
  4936. [params setValue:appDelegate.user forKey:@"user"];
  4937. if(appDelegate.contact_id!=nil)
  4938. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4939. if(appDelegate.password!=nil)
  4940. [params setValue:appDelegate.password forKey:@"password"];
  4941. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  4942. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  4943. [params setValue:keywords forKey:@"keyWord"];
  4944. [params setValue:customer forKey:@"customer_filter"];
  4945. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  4946. [params setValue:status_code forKey:@"orderStatus"];
  4947. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  4948. if (keywords) {
  4949. [params setObject:@"Search" forKey:kAction];
  4950. }
  4951. if(appDelegate.offline_mode)
  4952. {
  4953. params[@"user"]=appDelegate.user;
  4954. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4955. NSData* json = [[OLDataProvider offline_orderlist:params] mutableCopy];
  4956. dispatch_async(dispatch_get_main_queue(), ^{
  4957. result([[RAConvertor data2dict:json] mutableCopy]);
  4958. });
  4959. });
  4960. return;
  4961. }
  4962. [self request_interface:URL_ORDER_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  4963. // NSData* json=nil;
  4964. // if(appDelegate.offline_mode)
  4965. // {
  4966. // json= [OLDataProvider offline_orderlist:params];
  4967. // }
  4968. // else
  4969. // {
  4970. // if(![self IsNetworkAvailable])
  4971. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4972. //
  4973. // json=[self get_json:URL_ORDER_LIST parameters:params];
  4974. // }
  4975. // if(json==nil)
  4976. // return nil;
  4977. // NSError *error=nil;
  4978. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4979. // return jsobj;
  4980. }
  4981. +(void)request_logout:(resultHandler)result
  4982. {
  4983. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4984. AppDelegate *appDelegate = nil;
  4985. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4986. if(appDelegate.user!=nil)
  4987. [params setValue:appDelegate.user forKey:@"user"];
  4988. if(appDelegate.password!=nil)
  4989. [params setValue:appDelegate.password forKey:@"password"];
  4990. if(appDelegate.offline_mode)
  4991. {
  4992. [OLDataProvider offline_logout:params completionHandler:result];
  4993. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4994. // NSMutableDictionary* json = [[OLDataProvider offline_logout:params] mutableCopy];
  4995. // dispatch_async(dispatch_get_main_queue(), ^{
  4996. // result(json);
  4997. // });
  4998. // });
  4999. return;
  5000. }
  5001. [self request_interface:URL_LOGOUT parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5002. NSMutableDictionary* jsobj=resulti;
  5003. int result_code = [[jsobj valueForKey:@"result"] intValue];
  5004. if (result_code==2)
  5005. {
  5006. appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  5007. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5008. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5009. [appDelegate update_count_mark];
  5010. appDelegate.can_show_price =false;
  5011. appDelegate.can_see_price =false;
  5012. appDelegate.can_create_portfolio =false;
  5013. appDelegate.can_create_order =false;
  5014. appDelegate.can_cancel_order =false;
  5015. appDelegate.can_set_cart_price =false;
  5016. appDelegate.can_delete_order =false;
  5017. appDelegate.can_submit_order =false;
  5018. appDelegate.can_set_tearsheet_price =false;
  5019. appDelegate.can_update_contact_info = false;
  5020. appDelegate.save_order_logout = false;
  5021. appDelegate.submit_order_logout = false;
  5022. appDelegate.alert_sold_in_quantities = false;
  5023. appDelegate.ipad_perm =nil ;
  5024. appDelegate.user_type = USER_ROLE_UNKNOWN;
  5025. appDelegate.OrderFilter= nil;
  5026. [appDelegate SetSo:nil];
  5027. [appDelegate set_main_button_panel];
  5028. #ifdef RA_NOTIFICATION
  5029. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5030. #endif
  5031. }
  5032. result(resulti);
  5033. } retry:0];
  5034. //
  5035. // if(appDelegate.offline_mode)
  5036. // {
  5037. // return [OLDataProvider offline_logout:params];
  5038. // }
  5039. // if(![self IsNetworkAvailable])
  5040. // {
  5041. // DebugLog(@"NET ERR");
  5042. //
  5043. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5044. // // return nil;
  5045. // }
  5046. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  5047. // //if(json==nil)
  5048. //
  5049. //
  5050. // if(json==nil)
  5051. // return nil;
  5052. // NSError *error=nil;
  5053. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5054. // int result = [[jsobj valueForKey:@"result"] intValue];
  5055. //
  5056. // if (result==2)
  5057. // {
  5058. //
  5059. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  5060. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5061. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5062. //
  5063. // [appDelegate update_count_mark];
  5064. //
  5065. //
  5066. // appDelegate.can_show_price =false;
  5067. // appDelegate.can_see_price =false;
  5068. // appDelegate.can_create_portfolio =false;
  5069. // appDelegate.can_create_order =false;
  5070. //
  5071. //
  5072. // appDelegate.can_cancel_order =false;
  5073. // appDelegate.can_set_cart_price =false;
  5074. // appDelegate.can_delete_order =false;
  5075. // appDelegate.can_submit_order =false;
  5076. // appDelegate.can_set_tearsheet_price =false;
  5077. // appDelegate.can_update_contact_info = false;
  5078. //
  5079. // appDelegate.save_order_logout = false;
  5080. // appDelegate.submit_order_logout = false;
  5081. // appDelegate.alert_sold_in_quantities = false;
  5082. //
  5083. // appDelegate.ipad_perm =nil ;
  5084. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  5085. // appDelegate.OrderFilter= nil;
  5086. // [appDelegate SetSo:nil];
  5087. // [appDelegate set_main_button_panel];
  5088. //#ifdef RA_NOTIFICATION
  5089. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5090. //#endif
  5091. // }
  5092. // return jsobj;
  5093. }
  5094. + (void)request_hangtag:(NSString *)group completionHandler:(resultHandler)result
  5095. {
  5096. #ifdef BUILD_UWAVER
  5097. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5098. AppDelegate *appDelegate = nil;
  5099. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5100. if(appDelegate.user!=nil)
  5101. [params setValue:appDelegate.user forKey:@"user"];
  5102. if(appDelegate.contact_id!=nil)
  5103. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5104. if(appDelegate.password!=nil)
  5105. [params setValue:appDelegate.password forKey:@"password"];
  5106. if (group) {
  5107. [params setValue:group forKey:@"groupName"];
  5108. }
  5109. NSString * uuid= [[NSUUID UUID] UUIDString];
  5110. params[@"resultSerial"]=uuid;
  5111. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  5112. if(appDelegate.offline_mode)
  5113. {
  5114. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5115. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5116. dispatch_async(dispatch_get_main_queue(), ^{
  5117. result(json);
  5118. });
  5119. });
  5120. return;
  5121. }
  5122. [self request_interface:URL_CREATE_HANG_TAG parameters:params err_record_url:nil completionHandler:result retry:0];
  5123. // NSData* json = nil;
  5124. // if(appDelegate.offline_mode)
  5125. // {
  5126. // json = [OLDataProvider offline_portfolioList:params];
  5127. // } else {
  5128. // if(![self IsNetworkAvailable])
  5129. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5130. //
  5131. // json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  5132. // }
  5133. //
  5134. //
  5135. // if(json==nil)
  5136. // return nil;
  5137. // NSError *error=nil;
  5138. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5139. //
  5140. // return jsobj;
  5141. #else
  5142. return result(nil);
  5143. #endif
  5144. }
  5145. + (void)request_movetobackorder:(NSString *)cart_item_id completionHandler:(resultHandler)result
  5146. {
  5147. if (cart_item_id == nil || cart_item_id.length < 1) {
  5148. result([@{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"} mutableCopy]);
  5149. }
  5150. AppDelegate *appDelegate = nil;
  5151. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5152. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5153. if(appDelegate.user!=nil)
  5154. [dic setValue:appDelegate.user forKey:@"user"];
  5155. if(appDelegate.password!=nil)
  5156. [dic setValue:appDelegate.password forKey:@"password"];
  5157. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  5158. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  5159. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5160. if(appDelegate.offline_mode)
  5161. {
  5162. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5163. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5164. dispatch_async(dispatch_get_main_queue(), ^{
  5165. result(json);
  5166. });
  5167. });
  5168. return;
  5169. }
  5170. [self request_interface:URL_MOVE_TO_BACK_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5171. // if(![self IsNetworkAvailable])
  5172. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5173. //
  5174. // NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  5175. //
  5176. // if(json!=nil)
  5177. // {
  5178. // NSError *error=nil;
  5179. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5180. //
  5181. // return jsobj;
  5182. // }
  5183. //
  5184. // return @{@"result" : @(RESULT_FALSE)};
  5185. }
  5186. + (void)request_emailwishlist:(NSString *)addr completionHandler:(resultHandler)result
  5187. {
  5188. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5189. AppDelegate *appDelegate = nil;
  5190. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5191. if(appDelegate.user!=nil)
  5192. [dic setValue:appDelegate.user forKey:@"user"];
  5193. if(appDelegate.password!=nil)
  5194. [dic setValue:appDelegate.password forKey:@"password"];
  5195. [dic setValue:addr forKey:@"email"];
  5196. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  5197. // if (appDelegate.customerInfo) {
  5198. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5199. // if (customer_cid) {
  5200. // [dic setValue:customer_cid forKey:@"contactId"];
  5201. // }
  5202. // }
  5203. if(appDelegate.offline_mode)
  5204. {
  5205. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5206. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5207. dispatch_async(dispatch_get_main_queue(), ^{
  5208. result(json);
  5209. });
  5210. });
  5211. return;
  5212. }
  5213. [self request_interface:URL_EMAIL_WISHLIST parameters:dic err_record_url:nil completionHandler:result retry:0];
  5214. // NSData* json=nil;
  5215. // if(appDelegate.offline_mode)
  5216. // {
  5217. // return [OLDataProvider offline_notimpl];
  5218. // }
  5219. // else
  5220. // {
  5221. // if(![self IsNetworkAvailable])
  5222. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5223. //
  5224. // json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  5225. // }
  5226. // if(json!=nil)
  5227. // {
  5228. // NSError *error=nil;
  5229. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5230. //
  5231. //
  5232. // return jsobj;
  5233. // }
  5234. //
  5235. // return @{@"result" : @(RESULT_FALSE)};
  5236. }
  5237. +(void)request_notifymodel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  5238. {
  5239. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5240. AppDelegate *appDelegate = nil;
  5241. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5242. if(appDelegate.user!=nil)
  5243. [dic setValue:appDelegate.user forKey:@"user"];
  5244. if(appDelegate.password!=nil)
  5245. [dic setValue:appDelegate.password forKey:@"password"];
  5246. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5247. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5248. if (customer_cid) {
  5249. [dic setValue:customer_cid forKey:@"contactId"];
  5250. }
  5251. }
  5252. [dic setObject:screenName forKey:kScreenName];
  5253. [dic setValue:modelID forKey:@"productId"];
  5254. if (addr) { // 弹框输入
  5255. [dic setValue:addr forKey:@"email"];
  5256. } else {
  5257. // employee选择了Contact,并且Contact有Email
  5258. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5259. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  5260. // if (email) {
  5261. // [dic setValue:email forKey:@"email"];
  5262. // }
  5263. // }
  5264. }
  5265. if(appDelegate.offline_mode)
  5266. {
  5267. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5268. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5269. dispatch_async(dispatch_get_main_queue(), ^{
  5270. result(json);
  5271. });
  5272. });
  5273. return;
  5274. }
  5275. [self request_interface:URL_NOTIFY_ME parameters:dic err_record_url:nil completionHandler:result retry:0];
  5276. // NSData* json=nil;
  5277. // if(appDelegate.offline_mode)
  5278. // {
  5279. // return [OLDataProvider offline_notimpl];
  5280. // }
  5281. // else
  5282. // {
  5283. // if(![self IsNetworkAvailable])
  5284. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5285. //
  5286. // json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  5287. // }
  5288. // if(json!=nil)
  5289. // {
  5290. // NSError *error=nil;
  5291. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5292. //
  5293. //
  5294. // return jsobj;
  5295. // }
  5296. //
  5297. // return @{@"result" : @(RESULT_FALSE)};
  5298. }
  5299. + (void)request_qouteorder:(NSString *)so_id emailAddr:(NSString *)addr completionHandler:(resultHandler)result
  5300. {
  5301. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5302. AppDelegate *appDelegate = nil;
  5303. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5304. if(appDelegate.user!=nil)
  5305. [dic setValue:appDelegate.user forKey:@"user"];
  5306. if(appDelegate.password!=nil)
  5307. [dic setValue:appDelegate.password forKey:@"password"];
  5308. [dic setValue:so_id forKey:@"orderCode"];
  5309. [dic setValue:addr forKey:@"email"];
  5310. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5311. if (appDelegate.customerInfo) {
  5312. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5313. if (customer_cid) {
  5314. [dic setValue:customer_cid forKey:@"contactId"];
  5315. }
  5316. }
  5317. if(appDelegate.offline_mode)
  5318. {
  5319. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5320. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5321. dispatch_async(dispatch_get_main_queue(), ^{
  5322. result(json);
  5323. });
  5324. });
  5325. return;
  5326. }
  5327. [self request_interface:URL_EMAIL_CART parameters:dic err_record_url:nil completionHandler:result retry:0];
  5328. // NSData* json=nil;
  5329. // if(appDelegate.offline_mode)
  5330. // {
  5331. // return [OLDataProvider offline_notimpl];
  5332. // }
  5333. // else
  5334. // {
  5335. // if(![self IsNetworkAvailable])
  5336. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5337. //
  5338. // json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  5339. // }
  5340. // if(json!=nil)
  5341. // {
  5342. // NSError *error=nil;
  5343. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5344. //
  5345. //
  5346. // return jsobj;
  5347. // }
  5348. //
  5349. // return @{@"result" : @(RESULT_FALSE)};
  5350. }
  5351. + (void)request_mergeorder:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  5352. {
  5353. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5354. AppDelegate *appDelegate = nil;
  5355. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5356. if(appDelegate.user!=nil)
  5357. [dic setValue:appDelegate.user forKey:@"user"];
  5358. if(appDelegate.password!=nil)
  5359. [dic setValue:appDelegate.password forKey:@"password"];
  5360. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  5361. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  5362. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  5363. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  5364. if(appDelegate.offline_mode)
  5365. {
  5366. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5367. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5368. dispatch_async(dispatch_get_main_queue(), ^{
  5369. result(json);
  5370. });
  5371. });
  5372. return;
  5373. }
  5374. [self request_interface:URL_SET_MERGE_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5375. // NSData* json=nil;
  5376. // if(appDelegate.offline_mode)
  5377. // {
  5378. // return [OLDataProvider offline_notimpl];
  5379. // }
  5380. // else
  5381. // {
  5382. // if(![self IsNetworkAvailable])
  5383. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5384. //
  5385. // json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  5386. // }
  5387. // if(json!=nil)
  5388. // {
  5389. // NSError *error=nil;
  5390. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5391. //
  5392. //
  5393. // return jsobj;
  5394. // }
  5395. // else
  5396. // return nil;
  5397. }
  5398. +(void)request_pendingorder:(NSString *)contactid completionHandler:(resultHandler)result
  5399. {
  5400. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5401. AppDelegate *appDelegate = nil;
  5402. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5403. if(appDelegate.user!=nil)
  5404. [params setValue:appDelegate.user forKey:@"user"];
  5405. // if(appDelegate.contact_id!=nil)
  5406. if(appDelegate.password!=nil)
  5407. [params setValue:appDelegate.password forKey:@"password"];
  5408. [params setValue:contactid forKey:@"contactId"];
  5409. if(appDelegate.offline_mode)
  5410. {
  5411. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5412. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5413. dispatch_async(dispatch_get_main_queue(), ^{
  5414. result(json);
  5415. });
  5416. });
  5417. return;
  5418. }
  5419. [self request_interface:URL_CUSTOMER_PENDINGORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  5420. //
  5421. // if(appDelegate.offline_mode)
  5422. // {
  5423. // return [OLDataProvider offline_notimpl];
  5424. // }
  5425. // if(![self IsNetworkAvailable])
  5426. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5427. //
  5428. // NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  5429. // if(json==nil)
  5430. // return nil;
  5431. // NSError *error=nil;
  5432. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5433. // return jsobj;
  5434. //
  5435. }
  5436. +(void) request_removeportfolio:(NSString* ) item_ids completionHandler:(resultHandler)result
  5437. {
  5438. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5439. AppDelegate *appDelegate = nil;
  5440. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5441. if(appDelegate.user!=nil)
  5442. [params setValue:appDelegate.user forKey:@"user"];
  5443. if(appDelegate.contact_id!=nil)
  5444. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5445. if(appDelegate.password!=nil)
  5446. [params setValue:appDelegate.password forKey:@"password"];
  5447. [params setValue:item_ids forKey:@"portfolioId"];
  5448. // [params setValue:editor forKey:@"editor"];
  5449. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  5450. if(appDelegate.offline_mode)
  5451. {
  5452. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5453. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_removePortfolio:params]] mutableCopy];
  5454. dispatch_async(dispatch_get_main_queue(), ^{
  5455. int result_code = [[resulti valueForKey:@"result"] intValue];
  5456. if (result_code==2)
  5457. {
  5458. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5459. [appDelegate update_count_mark];
  5460. };
  5461. result(resulti);
  5462. });
  5463. });
  5464. return;
  5465. }
  5466. [self request_interface:URL_PORTFOLIO_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5467. int result_code = [[resulti valueForKey:@"result"] intValue];
  5468. if (result_code==2)
  5469. {
  5470. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5471. [appDelegate update_count_mark];
  5472. };
  5473. result(resulti);
  5474. } retry:0];
  5475. // NSData* json = nil;
  5476. // if(appDelegate.offline_mode)
  5477. // {
  5478. // json = [OLDataProvider offline_removePortfolio:params];
  5479. // } else {
  5480. // if(![self IsNetworkAvailable])
  5481. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5482. // json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  5483. // }
  5484. // if(json!=nil)
  5485. // {
  5486. // NSError *error=nil;
  5487. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5488. //
  5489. //
  5490. // int result = [[jsobj valueForKey:@"result"] intValue];
  5491. //
  5492. // if (result==2)
  5493. // {
  5494. //
  5495. //
  5496. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5497. //
  5498. // [appDelegate update_count_mark];
  5499. // }
  5500. // return jsobj;
  5501. // }
  5502. // else
  5503. // return nil;
  5504. }
  5505. +(void) request_removeportfoliopdf:(NSString* ) listid completionHandler:(resultHandler)result
  5506. {
  5507. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5508. AppDelegate *appDelegate = nil;
  5509. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5510. if(appDelegate.user!=nil)
  5511. [params setValue:appDelegate.user forKey:@"user"];
  5512. if(appDelegate.contact_id!=nil)
  5513. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5514. if(appDelegate.password!=nil)
  5515. [params setValue:appDelegate.password forKey:@"password"];
  5516. [params setValue:listid forKey:@"tearsheetsId"];
  5517. // [params setValue:editor forKey:@"editor"];
  5518. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  5519. // [params setValue:@"Delete Portfolio" forKey:kAction];
  5520. if(appDelegate.offline_mode)
  5521. {
  5522. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5523. NSData* json = [[OLDataProvider offline_removePDF:params] mutableCopy];
  5524. dispatch_async(dispatch_get_main_queue(), ^{
  5525. result([[RAConvertor data2dict:json] mutableCopy]);
  5526. });
  5527. });
  5528. return;
  5529. }
  5530. [self request_interface:URL_PORTFOLIOLIST_REMOVE parameters:params err_record_url:nil completionHandler:result retry:0];
  5531. }
  5532. +(void) request_remove_wishlist:(NSString* ) item_ids completionHandler:(resultHandler)result
  5533. {
  5534. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5535. __block AppDelegate *appDelegate = nil;
  5536. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5537. if(appDelegate.user!=nil)
  5538. [params setValue:appDelegate.user forKey:@"user"];
  5539. if(appDelegate.contact_id!=nil)
  5540. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5541. if(appDelegate.password!=nil)
  5542. [params setValue:appDelegate.password forKey:@"password"];
  5543. [params setValue:item_ids forKey:@"collectId"];
  5544. // [params setValue:editor forKey:@"editor"];
  5545. [params setValue:ScreenCodeWishList forKey:kScreenName];
  5546. if(appDelegate.offline_mode)
  5547. {
  5548. // [OLDataProvider offline_deletewishlist:params completionHandler:result];
  5549. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5550. NSMutableDictionary* resulti = [[OLDataProvider offline_deletewishlist:params] mutableCopy];
  5551. dispatch_async(dispatch_get_main_queue(), ^{
  5552. int result_code = [[resulti valueForKey:@"result"] intValue];
  5553. if (result_code==2)
  5554. {
  5555. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  5556. [appDelegate update_count_mark];
  5557. };
  5558. result(resulti);
  5559. });
  5560. });
  5561. return;
  5562. }
  5563. [self request_interface:URL_WATCHLIST_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5564. int result_code = [[resulti valueForKey:@"result"] intValue];
  5565. if (result_code==2)
  5566. {
  5567. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  5568. [appDelegate update_count_mark];
  5569. };
  5570. result(resulti);
  5571. } retry:0];
  5572. //
  5573. //
  5574. // if(appDelegate.offline_mode)
  5575. // {
  5576. // return [OLDataProvider offline_deletewishlist:params];
  5577. // }
  5578. // if(![self IsNetworkAvailable])
  5579. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5580. //
  5581. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  5582. // if(json!=nil)
  5583. // {
  5584. // NSError *error=nil;
  5585. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5586. // int result = [[jsobj valueForKey:@"result"] intValue];
  5587. //
  5588. // if (result==2)
  5589. // {
  5590. //
  5591. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5592. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  5593. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5594. //
  5595. // [appDelegate update_count_mark];
  5596. // }
  5597. // return jsobj;
  5598. // }
  5599. // else
  5600. // return nil;
  5601. }
  5602. +(void) request_remove_cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  5603. {
  5604. #ifdef SCANNER_ORDER
  5605. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  5606. {
  5607. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  5608. //
  5609. //
  5610. // [appDelegate update_count_mark];
  5611. NSArray* arr=[RAConvertor string2arr:item_ids separator:@","];
  5612. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  5613. NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  5614. NSMutableDictionary* newsection =[cartTemplate[@"section_0"] mutableCopy];
  5615. int newcount = 0;
  5616. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  5617. int count = [section[@"count"] intValue];
  5618. for(int i=0;i<count;i++)
  5619. {
  5620. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  5621. long index = [arr indexOfObject:item[@"cart_item_id"]] ;
  5622. if(index <0)
  5623. {
  5624. newsection[[NSString stringWithFormat:@"item_%d",newcount]] = item;
  5625. newcount ++;
  5626. }
  5627. }
  5628. newsection[@"count"]=@(newcount);
  5629. RASingleton.sharedInstance.scan_cart[@"section_0"] = newsection;
  5630. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  5631. result(RASingleton.sharedInstance.scan_cart);
  5632. return;
  5633. }
  5634. #else
  5635. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5636. AppDelegate *appDelegate = nil;
  5637. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5638. if(appDelegate.user!=nil)
  5639. [params setValue:appDelegate.user forKey:@"user"];
  5640. if(appDelegate.contact_id!=nil)
  5641. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5642. if(appDelegate.password!=nil)
  5643. [params setValue:appDelegate.password forKey:@"password"];
  5644. if(appDelegate.order_code!=nil)
  5645. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5646. [params setValue:item_ids forKey:@"cartItemId"];
  5647. // [params setValue:editor forKey:@"editor"];
  5648. [params setValue:ScreenCodeCart forKey:kScreenName];
  5649. // [params setValue:@"" forKey:kAction];
  5650. if(appDelegate.offline_mode)
  5651. {
  5652. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5653. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_cartremove:params]] mutableCopy];
  5654. dispatch_async(dispatch_get_main_queue(), ^{
  5655. int result_code = [[resulti valueForKey:@"result"] intValue];
  5656. if (result_code==2)
  5657. {
  5658. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5659. [appDelegate update_count_mark];
  5660. };
  5661. result(resulti);
  5662. });
  5663. });
  5664. return;
  5665. }
  5666. [self request_interface:URL_CART_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5667. int result_code = [[resulti valueForKey:@"result"] intValue];
  5668. if (result_code==2)
  5669. {
  5670. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5671. [appDelegate update_count_mark];
  5672. };
  5673. result(resulti);
  5674. } retry:0];
  5675. #endif
  5676. }
  5677. +(void)request_delete_account:(resultHandler)result
  5678. {
  5679. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5680. AppDelegate *appDelegate = nil;
  5681. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5682. if(appDelegate.user!=nil)
  5683. [params setValue:appDelegate.user forKey:@"user"];
  5684. if(appDelegate.password!=nil)
  5685. [params setValue:appDelegate.password forKey:@"password"];
  5686. if(appDelegate.offline_mode)
  5687. {
  5688. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5689. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5690. dispatch_async(dispatch_get_main_queue(), ^{
  5691. result(json);
  5692. });
  5693. });
  5694. return;
  5695. }
  5696. #ifdef SCANNER_ORDER
  5697. params[@"site_name"]=[RADataProvider getSiteName];
  5698. params[@"_method"]=@"cancelOfflineOrderUser";
  5699. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_DELETE_ACCOUNT];
  5700. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  5701. #else
  5702. [self request_interface:URL_DELETE_ACCOUNT parameters:params err_record_url:nil completionHandler:result retry:0];
  5703. #endif
  5704. }
  5705. +(void) request_create_order:(resultHandler)result
  5706. {
  5707. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5708. AppDelegate *appDelegate = nil;
  5709. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5710. if(appDelegate.user!=nil)
  5711. [params setValue:appDelegate.user forKey:@"user"];
  5712. if(appDelegate.contact_id!=nil)
  5713. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5714. if(appDelegate.password!=nil)
  5715. [params setValue:appDelegate.password forKey:@"password"];
  5716. if(appDelegate.order_code!=nil)
  5717. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5718. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  5719. NSDictionary* customerinfo= appDelegate.customerInfo;
  5720. NSArray* keys=[customerinfo allKeys];
  5721. for(int i=0;i<keys.count;i++)
  5722. {
  5723. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  5724. }
  5725. if(appDelegate.offline_mode)
  5726. {
  5727. [OLDataProvider offline_createorder:params completionHandler:^(NSMutableDictionary *resulti) {
  5728. int result_code = [[resulti valueForKey:@"result"] intValue];
  5729. if (result_code==2)
  5730. {
  5731. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5732. [appDelegate update_count_mark];
  5733. };
  5734. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  5735. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5736. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  5737. }
  5738. result(resulti);
  5739. }];
  5740. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5741. // NSData* json = [[OLDataProvider offline_createorder:params] mutableCopy];
  5742. // dispatch_async(dispatch_get_main_queue(), ^{
  5743. // result([[RAConvertor data2dict:json] mutableCopy]);
  5744. // });
  5745. // });
  5746. return;
  5747. }
  5748. [self request_interface:URL_NEW_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5749. int result_code = [[resulti valueForKey:@"result"] intValue];
  5750. if (result_code==2)
  5751. {
  5752. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5753. [appDelegate update_count_mark];
  5754. };
  5755. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  5756. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5757. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  5758. }
  5759. result(resulti);
  5760. } retry:0];
  5761. //
  5762. // NSData* json = nil;
  5763. // if(appDelegate.offline_mode)
  5764. // {
  5765. // json= [OLDataProvider offline_createorder:params];
  5766. // }
  5767. // else
  5768. // {
  5769. // if(![self IsNetworkAvailable])
  5770. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5771. //
  5772. // json=[self get_json:URL_NEW_ORDER parameters:params];
  5773. // }
  5774. // if(json==nil)
  5775. // return nil;
  5776. // NSError *error=nil;
  5777. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5778. // int result = [[jsobj valueForKey:@"result"] intValue];
  5779. //
  5780. // if (result==2)
  5781. // {
  5782. //
  5783. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5784. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  5785. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5786. //
  5787. // [appDelegate update_count_mark];
  5788. // }
  5789. //
  5790. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  5791. //
  5792. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5793. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  5794. // }
  5795. //
  5796. // return jsobj;
  5797. }
  5798. +(void)request_open_order:(NSString*) order_code completionHandler:(resultHandler)result
  5799. {
  5800. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5801. AppDelegate *appDelegate = nil;
  5802. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5803. if(appDelegate.user!=nil)
  5804. [params setValue:appDelegate.user forKey:@"user"];
  5805. // if(appDelegate.contact_id!=nil)
  5806. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5807. if(appDelegate.password!=nil)
  5808. [params setValue:appDelegate.password forKey:@"password"];
  5809. [params setValue:order_code forKey:@"orderCode"];
  5810. // [params setValue:sourceid forKey:@"sourceid"];
  5811. // [params setValue:editor forKey:@"editor"];
  5812. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  5813. if(appDelegate.offline_mode)
  5814. {
  5815. params[@"appDelegate.order_code"]=appDelegate.order_code;
  5816. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5817. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_editorder:params]] mutableCopy];
  5818. dispatch_async(dispatch_get_main_queue(), ^{
  5819. int result_code = [[resulti valueForKey:@"result"] intValue];
  5820. if (result_code==2)
  5821. {
  5822. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5823. [appDelegate update_count_mark];
  5824. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5825. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  5826. }
  5827. }
  5828. result(resulti);
  5829. });
  5830. });
  5831. return;
  5832. }
  5833. [self request_interface:URL_OPEN_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5834. int result_code = [[resulti valueForKey:@"result"] intValue];
  5835. if (result_code==2)
  5836. {
  5837. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5838. [appDelegate update_count_mark];
  5839. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5840. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  5841. }
  5842. }
  5843. result(resulti);
  5844. } retry:0];
  5845. //
  5846. // NSData* json=nil;
  5847. // if(appDelegate.offline_mode)
  5848. // {
  5849. // json=[OLDataProvider offline_editorder:params];
  5850. //
  5851. // }
  5852. // else
  5853. // {
  5854. // if(![self IsNetworkAvailable])
  5855. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5856. //
  5857. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  5858. // }
  5859. // if(json!=nil)
  5860. // {
  5861. // NSError *error=nil;
  5862. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5863. // int result = [[jsobj valueForKey:@"result"] intValue];
  5864. //
  5865. // if (result==2)
  5866. // {
  5867. //
  5868. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5869. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  5870. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5871. //
  5872. // [appDelegate update_count_mark];
  5873. //
  5874. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5875. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  5876. // }
  5877. //
  5878. // }
  5879. //
  5880. // return jsobj;
  5881. // }
  5882. // else
  5883. // return nil;
  5884. }
  5885. +(void)request_order_discount:(double)discount completionHandler:(resultHandler)result
  5886. {
  5887. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5888. AppDelegate *appDelegate = nil;
  5889. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5890. if(appDelegate.user!=nil)
  5891. [params setValue:appDelegate.user forKey:@"user"];
  5892. // if(appDelegate.contact_id!=nil)
  5893. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5894. if(appDelegate.password!=nil)
  5895. [params setValue:appDelegate.password forKey:@"password"];
  5896. if(appDelegate.order_code!=nil)
  5897. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5898. [params setValue:@(discount) forKey:@"app_discount"];
  5899. if(appDelegate.offline_mode)
  5900. {
  5901. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5902. NSMutableDictionary* json = [[OLDataProvider offline_setorderdiscount:params] mutableCopy];
  5903. dispatch_async(dispatch_get_main_queue(), ^{
  5904. result(json);
  5905. });
  5906. });
  5907. return;
  5908. //
  5909. //
  5910. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5911. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5912. // dispatch_async(dispatch_get_main_queue(), ^{
  5913. // result(json);
  5914. // });
  5915. // });
  5916. //
  5917. // return;
  5918. }
  5919. [self request_interface:URL_ORDER_DISCOUNT parameters:params err_record_url:nil completionHandler:result retry:0];
  5920. }
  5921. +(void)request_cart:(int)sort completionHandler:(resultHandler)result
  5922. {
  5923. DebugLog(@"iSalesNetwork::request_Cart");
  5924. AppDelegate *appDelegate = nil;
  5925. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5926. #ifdef SCANNER_ORDER
  5927. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  5928. {
  5929. appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  5930. [appDelegate update_count_mark];
  5931. result(RASingleton.sharedInstance.scan_cart);
  5932. return;
  5933. }
  5934. #else
  5935. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5936. if(appDelegate.user!=nil)
  5937. [params setValue:appDelegate.user forKey:@"user"];
  5938. // if(appDelegate.contact_id!=nil)
  5939. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5940. if(appDelegate.password!=nil)
  5941. [params setValue:appDelegate.password forKey:@"password"];
  5942. if(appDelegate.order_code!=nil)
  5943. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5944. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  5945. [params setObject:ScreenCodeCart forKey:kScreenName];
  5946. if(appDelegate.offline_mode)
  5947. {
  5948. [OLDataProvider offline_requestcart:params completionHandler:^(NSMutableDictionary *resulti) {
  5949. if([resulti[@"result"] intValue]==2)
  5950. {
  5951. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5952. [appDelegate update_count_mark];
  5953. result(resulti);
  5954. }
  5955. }];
  5956. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5957. // NSData* json = [[OLDataProvider offline_requestcart:params] mutableCopy];
  5958. // dispatch_async(dispatch_get_main_queue(), ^{
  5959. // result([[RAConvertor data2dict:json] mutableCopy]);
  5960. // });
  5961. // });
  5962. return;
  5963. }
  5964. NSString * uuid= [[NSUUID UUID] UUIDString];
  5965. params[@"resultSerial"]=uuid;
  5966. __block bool bbreak = false;
  5967. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5968. for(int i=0;i<150;i++)
  5969. {
  5970. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  5971. // result_params[@"resultSerial"]=uuid;
  5972. if(bbreak)
  5973. break;
  5974. dispatch_async(dispatch_get_main_queue(), ^{
  5975. [self request_interface:URL_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5976. if([resulti[@"result"] intValue]==2)
  5977. {
  5978. if(!bbreak) //此判断保证result只调用一次。
  5979. {
  5980. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5981. [appDelegate update_count_mark];
  5982. result(resulti);
  5983. }
  5984. bbreak=true;
  5985. }
  5986. } retry:3];
  5987. });
  5988. sleep(2);
  5989. // json=[self get_json:URL_CART parameters:params];
  5990. // if(json!=nil)
  5991. // {
  5992. //
  5993. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5994. // if([jsobj[@"result"] intValue]==2)
  5995. // {
  5996. // break;
  5997. // }
  5998. // }
  5999. }
  6000. });
  6001. //
  6002. //
  6003. //
  6004. // NSData* json=nil;
  6005. // if(appDelegate.offline_mode)
  6006. // {
  6007. // json= [OLDataProvider offline_requestcart:params];
  6008. // }
  6009. // else
  6010. // {
  6011. // if(![self IsNetworkAvailable])
  6012. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6013. //
  6014. // NSError *error=nil;
  6015. //
  6016. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6017. // params[@"resultSerial"]=uuid;
  6018. //
  6019. // for(int i=0;i<150;i++)
  6020. // {
  6021. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6022. // // result_params[@"resultSerial"]=uuid;
  6023. // json=[self get_json:URL_CART parameters:params];
  6024. // if(json!=nil)
  6025. // {
  6026. //
  6027. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6028. // if([jsobj[@"result"] intValue]==2)
  6029. // {
  6030. // break;
  6031. // }
  6032. // }
  6033. // sleep(2);
  6034. // }
  6035. //
  6036. // }
  6037. // if(json==nil)
  6038. // return nil;
  6039. // NSError *error=nil;
  6040. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6041. // int result = [[jsobj valueForKey:@"result"] intValue];
  6042. //
  6043. // if (result==2)
  6044. // {
  6045. //
  6046. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6047. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  6048. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6049. //
  6050. // [appDelegate update_count_mark];
  6051. // }
  6052. // return jsobj;
  6053. #endif
  6054. }
  6055. +(void) request_move_wish2cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  6056. {
  6057. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6058. AppDelegate *appDelegate = nil;
  6059. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6060. if(appDelegate.user!=nil)
  6061. [params setValue:appDelegate.user forKey:@"user"];
  6062. if(appDelegate.contact_id!=nil)
  6063. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6064. if(appDelegate.password!=nil)
  6065. [params setValue:appDelegate.password forKey:@"password"];
  6066. if(appDelegate.order_code!=nil)
  6067. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6068. [params setValue:item_ids forKey:@"collectId"];
  6069. // [params setValue:editor forKey:@"editor"];
  6070. [params setValue:ScreenCodeWishList forKey:kScreenName];
  6071. [params setValue:@"Move To Cart" forKey:kAction];
  6072. if(appDelegate.offline_mode)
  6073. {
  6074. // [OLDataProvider offline_movewish2cart:params completionHandler:result];
  6075. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6076. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6077. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movewish2cart:params]] mutableCopy];
  6078. dispatch_async(dispatch_get_main_queue(), ^{
  6079. int result_code = [[resulti valueForKey:@"result"] intValue];
  6080. if (result_code==2)
  6081. {
  6082. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6083. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6084. [appDelegate update_count_mark];
  6085. }
  6086. result(resulti);
  6087. });
  6088. });
  6089. return;
  6090. }
  6091. [self request_interface:URL_WISH2CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6092. int result_code = [[resulti valueForKey:@"result"] intValue];
  6093. if (result_code==2)
  6094. {
  6095. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6096. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6097. [appDelegate update_count_mark];
  6098. }
  6099. result(resulti);
  6100. } retry:0];
  6101. //
  6102. // NSData *json = nil;
  6103. // if(appDelegate.offline_mode)
  6104. // {
  6105. // json = [OLDataProvider offline_movewish2cart:params];
  6106. // } else {
  6107. // if(![self IsNetworkAvailable])
  6108. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6109. //
  6110. // json=[self get_json:URL_WISH2CART parameters:params];
  6111. // }
  6112. //
  6113. // if(json!=nil)
  6114. // {
  6115. // NSError *error=nil;
  6116. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6117. // int result = [[jsobj valueForKey:@"result"] intValue];
  6118. //
  6119. // if (result==2)
  6120. // {
  6121. //
  6122. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6123. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6124. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6125. //
  6126. // [appDelegate update_count_mark];
  6127. // }
  6128. // return jsobj;
  6129. // }
  6130. // else
  6131. // return nil;
  6132. }
  6133. +(void) request_move_cart2wish:(NSString* ) item_ids completionHandler:(resultHandler)result
  6134. {
  6135. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6136. AppDelegate *appDelegate = nil;
  6137. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6138. if(appDelegate.user!=nil)
  6139. [params setValue:appDelegate.user forKey:@"user"];
  6140. if(appDelegate.contact_id!=nil)
  6141. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6142. if(appDelegate.password!=nil)
  6143. [params setValue:appDelegate.password forKey:@"password"];
  6144. if(appDelegate.order_code!=nil)
  6145. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6146. [params setValue:item_ids forKey:@"cartItemId"];
  6147. // [params setValue:editor forKey:@"editor"];
  6148. [params setValue:ScreenCodeCart forKey:kScreenName];
  6149. // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  6150. if(appDelegate.offline_mode)
  6151. {
  6152. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6153. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movecart2wish:params]] mutableCopy];
  6154. dispatch_async(dispatch_get_main_queue(), ^{
  6155. int result_code = [[resulti valueForKey:@"result"] intValue];
  6156. if (result_code==2)
  6157. {
  6158. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6159. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6160. [appDelegate update_count_mark];
  6161. }
  6162. result(resulti);
  6163. });
  6164. });
  6165. return;
  6166. }
  6167. [self request_interface:URL_CART2WISH parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6168. int result_code = [[resulti valueForKey:@"result"] intValue];
  6169. if (result_code==2)
  6170. {
  6171. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6172. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6173. [appDelegate update_count_mark];
  6174. }
  6175. result(resulti);
  6176. } retry:0];
  6177. //
  6178. // NSData* json = nil;
  6179. // if(appDelegate.offline_mode)
  6180. // {
  6181. // json= [OLDataProvider offline_movecart2wish:params];
  6182. // }
  6183. // else
  6184. // {
  6185. // if(![self IsNetworkAvailable])
  6186. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6187. //
  6188. // json=[self get_json:URL_CART2WISH parameters:params];
  6189. // }
  6190. // if(json!=nil)
  6191. // {
  6192. // NSError *error=nil;
  6193. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6194. // int result = [[jsobj valueForKey:@"result"] intValue];
  6195. //
  6196. // if (result==2)
  6197. // {
  6198. //
  6199. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6200. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6201. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6202. //
  6203. // [appDelegate update_count_mark];
  6204. // }
  6205. // return jsobj;
  6206. // }
  6207. // else
  6208. // return nil;
  6209. }
  6210. +(void)request_orderdetail:(NSMutableDictionary *) params completionHandler:(resultHandler)result
  6211. {
  6212. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6213. if (params == nil) {
  6214. params = [[NSMutableDictionary alloc] init];
  6215. }
  6216. AppDelegate *appDelegate = nil;
  6217. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6218. if(appDelegate.user!=nil)
  6219. [params setValue:appDelegate.user forKey:@"user"];
  6220. if(appDelegate.contact_id!=nil)
  6221. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6222. if(appDelegate.password!=nil)
  6223. [params setValue:appDelegate.password forKey:@"password"];
  6224. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  6225. [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  6226. if(appDelegate.offline_mode)
  6227. {
  6228. params[@"mode"]=appDelegate.mode;
  6229. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6230. NSData* json = [[OLDataProvider offline_orderdetail:params] mutableCopy];
  6231. dispatch_async(dispatch_get_main_queue(), ^{
  6232. result([[RAConvertor data2dict:json] mutableCopy]);
  6233. });
  6234. });
  6235. return;
  6236. }
  6237. NSString * uuid= [[NSUUID UUID] UUIDString];
  6238. params[@"resultSerial"]=uuid;
  6239. __block bool bbreak = false;
  6240. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6241. for(int i=0;i<150;i++)
  6242. {
  6243. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6244. // result_params[@"resultSerial"]=uuid;
  6245. if(bbreak)
  6246. break;
  6247. dispatch_async(dispatch_get_main_queue(), ^{
  6248. [self request_interface:URL_ORDER_DETAIL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6249. if([resulti[@"result"] intValue]==2||[resulti[@"result"] intValue]==8)
  6250. {
  6251. if(!bbreak)//此判断保证result只调用一次。
  6252. result(resulti);
  6253. bbreak=true;
  6254. }
  6255. } retry:3];
  6256. });
  6257. sleep(2);
  6258. }
  6259. });
  6260. //
  6261. // NSData* json=nil;
  6262. // if(appDelegate.offline_mode)
  6263. // {
  6264. // json= [OLDataProvider offline_orderdetail:params];
  6265. // }
  6266. // else
  6267. // {
  6268. // if(![self IsNetworkAvailable])
  6269. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6270. //
  6271. // NSError *error=nil;
  6272. //
  6273. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6274. // params[@"resultSerial"]=uuid;
  6275. //
  6276. // for(int i=0;i<150;i++)
  6277. // {
  6278. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6279. // // result_params[@"resultSerial"]=uuid;
  6280. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  6281. // if(json!=nil)
  6282. // {
  6283. //
  6284. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6285. // int resultCode = [jsobj[@"result"] intValue];
  6286. // if(resultCode==2 || resultCode == 8)
  6287. // {
  6288. // break;
  6289. // }
  6290. // }
  6291. // sleep(2);
  6292. // }
  6293. //
  6294. //
  6295. // }
  6296. // if(json==nil)
  6297. // return nil;
  6298. // NSError *error=nil;
  6299. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6300. // return jsobj;
  6301. }
  6302. //
  6303. //+(void)request_commit_order:(NSString*) order_code completionHandler:(resultHandler)result
  6304. //{
  6305. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6306. // AppDelegate *appDelegate = nil;
  6307. //
  6308. //
  6309. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6310. //
  6311. // if(appDelegate.user!=nil)
  6312. // [params setValue:appDelegate.user forKey:@"user"];
  6313. // if(appDelegate.contact_id!=nil)
  6314. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6315. // if(appDelegate.password!=nil)
  6316. // [params setValue:appDelegate.password forKey:@"password"];
  6317. // // NSString* ssaved = @"false";
  6318. // // if(saved)
  6319. // // ssaved=@"true";
  6320. // [params setValue:@"true" forKey:@"saved"];
  6321. // [params setValue:order_code forKey:@"orderCode"];
  6322. // // [params setValue:sourceid forKey:@"sourceid"];
  6323. // // [params setValue:editor forKey:@"editor"];
  6324. //
  6325. // [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  6326. //
  6327. //
  6328. // if(appDelegate.offline_mode)
  6329. // {
  6330. //
  6331. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6332. // NSMutableDictionary* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  6333. // dispatch_async(dispatch_get_main_queue(), ^{
  6334. // result(json);
  6335. // });
  6336. // });
  6337. //
  6338. // return;
  6339. // }
  6340. //
  6341. //
  6342. // [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6343. //
  6344. //// NSData* json = nil;
  6345. ////
  6346. //// if(appDelegate.offline_mode)
  6347. //// {
  6348. //// json= [OLDataProvider offline_submitorder:params];
  6349. //// }
  6350. //// else
  6351. //// {
  6352. //// if(![self IsNetworkAvailable])
  6353. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6354. ////
  6355. //// json=[self get_json:URL_COMMIT_ORDER parameters:params];
  6356. //// }
  6357. //// if(json!=nil)
  6358. //// {
  6359. //// NSError *error=nil;
  6360. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6361. //// return jsobj;
  6362. //// }
  6363. //// else
  6364. //// return nil;
  6365. //
  6366. //}
  6367. +(void)request_copy_order:(NSString*) order_code completionHandler:(resultHandler)result
  6368. {
  6369. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6370. AppDelegate *appDelegate = nil;
  6371. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6372. if(appDelegate.user!=nil)
  6373. [params setValue:appDelegate.user forKey:@"user"];
  6374. if(appDelegate.contact_id!=nil)
  6375. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6376. if(appDelegate.password!=nil)
  6377. [params setValue:appDelegate.password forKey:@"password"];
  6378. // NSString* ssaved = @"false";
  6379. // if(saved)
  6380. // ssaved=@"true";
  6381. // [params setValue:@"true" forKey:@"saved"];
  6382. [params setValue:order_code forKey:@"code"];
  6383. // [params setValue:sourceid forKey:@"sourceid"];
  6384. // [params setValue:editor forKey:@"editor"];
  6385. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  6386. if(appDelegate.offline_mode)
  6387. {
  6388. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6389. NSData* json = [[OLDataProvider offline_copyorder:params] mutableCopy];
  6390. dispatch_async(dispatch_get_main_queue(), ^{
  6391. result([[RAConvertor data2dict:json] mutableCopy]);
  6392. });
  6393. });
  6394. return;
  6395. }
  6396. [self request_interface:URL_COPY_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6397. // NSData* json=nil;
  6398. // if(appDelegate.offline_mode)
  6399. // {
  6400. // json= [OLDataProvider offline_copyorder:params];
  6401. // }
  6402. // else
  6403. // {
  6404. // if(![self IsNetworkAvailable])
  6405. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6406. //
  6407. // json=[self get_json:URL_COPY_ORDER parameters:params];
  6408. // }
  6409. // if(json!=nil)
  6410. // {
  6411. // NSError *error=nil;
  6412. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6413. // return jsobj;
  6414. // }
  6415. // else
  6416. // return nil;
  6417. }
  6418. //
  6419. //+ (void)request_fastdownload:(NSMutableDictionary *)params url:(NSString *)url completionHandler:(resultHandler)result
  6420. //{
  6421. //
  6422. // //#ifdef test_server
  6423. // // url=URL_REQUEST_RECORDS;
  6424. // // params[@"prefix"]=URL_REQUEST_RECORDS;
  6425. // //#endif
  6426. //
  6427. // [self request_file_fast:url parameters:params completionHandler:result];
  6428. //
  6429. //}
  6430. +(void) request_addto_portfolio:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6431. {
  6432. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6433. AppDelegate *appDelegate = nil;
  6434. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6435. if(appDelegate.user!=nil)
  6436. [params setValue:appDelegate.user forKey:@"user"];
  6437. if(appDelegate.contact_id!=nil)
  6438. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6439. if(appDelegate.password!=nil)
  6440. [params setValue:appDelegate.password forKey:@"password"];
  6441. [params setValue:item_id forKey:@"product_id"];
  6442. [params setObject:screenName forKey:kScreenName];
  6443. if(appDelegate.offline_mode)
  6444. {
  6445. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6446. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_add2Portfolio:params]] mutableCopy];
  6447. dispatch_async(dispatch_get_main_queue(), ^{
  6448. int result_code = [[resulti valueForKey:@"result"] intValue];
  6449. if (result_code==2)
  6450. {
  6451. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6452. [appDelegate update_count_mark];
  6453. }
  6454. result(resulti);
  6455. });
  6456. });
  6457. return;
  6458. }
  6459. [self request_interface:URL_ADD_TO_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6460. int result_code = [[resulti valueForKey:@"result"] intValue];
  6461. if (result_code==2)
  6462. {
  6463. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6464. [appDelegate update_count_mark];
  6465. }
  6466. result(resulti);
  6467. } retry:0];
  6468. //
  6469. // NSData* json = nil;
  6470. // if(appDelegate.offline_mode)
  6471. // {
  6472. // json = [OLDataProvider offline_add2Portfolio:params];
  6473. // } else {
  6474. // if(![self IsNetworkAvailable])
  6475. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6476. //
  6477. // json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  6478. // }
  6479. //
  6480. // if(json==nil)
  6481. // return nil;
  6482. // NSError *error=nil;
  6483. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6484. // int result = [[jsobj valueForKey:@"result"] intValue];
  6485. //
  6486. // if (result==2)
  6487. // {
  6488. //
  6489. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6490. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6491. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6492. //
  6493. // [appDelegate update_count_mark];
  6494. // }
  6495. // return jsobj;
  6496. }
  6497. +(void)request_addall_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  6498. {
  6499. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6500. AppDelegate *appDelegate = nil;
  6501. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6502. if(appDelegate.user!=nil)
  6503. [params setValue:appDelegate.user forKey:@"user"];
  6504. if(appDelegate.contact_id!=nil)
  6505. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6506. if(appDelegate.password!=nil)
  6507. [params setValue:appDelegate.password forKey:@"password"];
  6508. if(appDelegate.order_code!=nil)
  6509. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6510. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6511. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6512. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  6513. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6514. // [params setValue:filter forKey:@"filter"];
  6515. [params setValue:keywords forKey:@"keyword"];
  6516. [params setValue:addTo forKey:@"addTo"];
  6517. [params setValue:orderCode forKey:@"orderCode"];
  6518. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6519. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6520. if(matchfull)
  6521. [params setValue:@"true" forKey:@"exactMatch"];
  6522. else
  6523. [params setValue:@"false" forKey:@"exactMatch"];
  6524. [params setObject:ScreenCodeSearch forKey:kScreenName];
  6525. if ([addTo isEqualToString:@"cart"]) {
  6526. [params setObject:@"Add To Cart" forKey:kAction];
  6527. }
  6528. if(appDelegate.offline_mode)
  6529. {
  6530. if ([addTo isEqualToString:@"cart"])
  6531. {
  6532. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6533. }
  6534. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6535. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_searchaddall:params]] mutableCopy];
  6536. dispatch_async(dispatch_get_main_queue(), ^{
  6537. int result_code =[json[@"result"] intValue];
  6538. if (result_code==2||result_code==8)
  6539. {
  6540. if(json[@"cart_count"])
  6541. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6542. if(json[@"wish_count"])
  6543. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  6544. if(json[@"portfolio_count"])
  6545. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  6546. //
  6547. //
  6548. [appDelegate update_count_mark];
  6549. }
  6550. result(json);
  6551. });
  6552. });
  6553. return;
  6554. }
  6555. NSString * uuid= [[NSUUID UUID] UUIDString];
  6556. params[@"resultSerial"]=uuid;
  6557. __block bool bbreak = false;
  6558. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6559. for(int i=0;i<150;i++)
  6560. {
  6561. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6562. // result_params[@"resultSerial"]=uuid;
  6563. if(bbreak)
  6564. break;
  6565. dispatch_async(dispatch_get_main_queue(), ^{
  6566. [self request_interface:URL_SEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6567. if([resulti[@"result"] intValue]==2)
  6568. {
  6569. if(!bbreak)//此判断保证result只调用一次。
  6570. result(resulti);
  6571. bbreak=true;
  6572. }
  6573. } retry:3];
  6574. });
  6575. sleep(2);
  6576. }
  6577. });
  6578. //
  6579. //
  6580. // NSData* json=nil;
  6581. // if(appDelegate.offline_mode)
  6582. // {
  6583. // json=[OLDataProvider offline_searchaddall:params];
  6584. // }
  6585. // else
  6586. // {
  6587. // if(![self IsNetworkAvailable])
  6588. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6589. //
  6590. // NSError *error=nil;
  6591. //
  6592. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6593. // params[@"resultSerial"]=uuid;
  6594. //
  6595. // for(int i=0;i<150;i++)
  6596. // {
  6597. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6598. // // result_params[@"resultSerial"]=uuid;
  6599. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  6600. // if(json!=nil)
  6601. // {
  6602. //
  6603. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6604. // if([jsobj[@"result"] intValue]==2)
  6605. // {
  6606. // break;
  6607. // }
  6608. // }
  6609. // sleep(2);
  6610. // }
  6611. // }
  6612. // if(json==nil)
  6613. // return nil;
  6614. // NSError *error=nil;
  6615. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6616. // return jsobj;
  6617. }
  6618. +(void) request_addto_cart_byupc:(NSString* ) upc_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6619. {
  6620. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6621. AppDelegate *appDelegate = nil;
  6622. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6623. if(appDelegate.user!=nil)
  6624. [params setValue:appDelegate.user forKey:@"user"];
  6625. if(appDelegate.contact_id!=nil)
  6626. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6627. if(appDelegate.password!=nil)
  6628. [params setValue:appDelegate.password forKey:@"password"];
  6629. if(appDelegate.order_code!=nil)
  6630. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6631. [params setValue:upc_code forKey:@"upc_code"];
  6632. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  6633. [params setObject:screenName forKey:kScreenName];
  6634. [params setObject:@"Add To Cart" forKey:kAction];
  6635. if (!upc_code) {
  6636. upc_code = @"";
  6637. }
  6638. [params setObject:@{@"UPCCode" : upc_code} forKey:kExtra];
  6639. params[@"search_upc"]=@true;
  6640. NSDictionary* customerinfo= appDelegate.customerInfo;
  6641. NSArray* keys=[customerinfo allKeys];
  6642. for(int i=0;i<keys.count;i++)
  6643. {
  6644. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  6645. }
  6646. if(appDelegate.offline_mode)
  6647. {
  6648. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6649. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  6650. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6651. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyupc:params]] mutableCopy];
  6652. dispatch_async(dispatch_get_main_queue(), ^{
  6653. int result_code = [[json valueForKey:@"result"] intValue];
  6654. if (result_code==2||result_code==8)
  6655. {
  6656. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6657. [appDelegate update_count_mark];
  6658. }
  6659. result(json);
  6660. });
  6661. });
  6662. return;
  6663. }
  6664. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6665. int result_code = [[resulti valueForKey:@"result"] intValue];
  6666. if (result_code==2||result_code==8)
  6667. {
  6668. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6669. [appDelegate update_count_mark];
  6670. }
  6671. result(resulti);
  6672. } retry:0];
  6673. }
  6674. +(void) request_addto_cart_byname:(NSString* ) model_name withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6675. {
  6676. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6677. AppDelegate *appDelegate = nil;
  6678. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6679. if(appDelegate.user!=nil)
  6680. [params setValue:appDelegate.user forKey:@"user"];
  6681. if(appDelegate.contact_id!=nil)
  6682. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6683. if(appDelegate.password!=nil)
  6684. [params setValue:appDelegate.password forKey:@"password"];
  6685. if(appDelegate.order_code!=nil)
  6686. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6687. [params setValue:model_name forKey:@"product_name"];
  6688. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  6689. [params setObject:screenName forKey:kScreenName];
  6690. [params setObject:@"Add To Cart" forKey:kAction];
  6691. if (!model_name) {
  6692. model_name = @"";
  6693. }
  6694. [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  6695. NSDictionary* customerinfo= appDelegate.customerInfo;
  6696. NSArray* keys=[customerinfo allKeys];
  6697. for(int i=0;i<keys.count;i++)
  6698. {
  6699. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  6700. }
  6701. if(appDelegate.offline_mode)
  6702. {
  6703. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6704. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  6705. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6706. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyname:params]] mutableCopy];
  6707. dispatch_async(dispatch_get_main_queue(), ^{
  6708. int result_code = [[json valueForKey:@"result"] intValue];
  6709. if (result_code==2||result_code==8)
  6710. {
  6711. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6712. [appDelegate update_count_mark];
  6713. }
  6714. result(json);
  6715. });
  6716. });
  6717. return;
  6718. }
  6719. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6720. int result_code = [[resulti valueForKey:@"result"] intValue];
  6721. if (result_code==2||result_code==8)
  6722. {
  6723. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6724. [appDelegate update_count_mark];
  6725. }
  6726. result(resulti);
  6727. } retry:0];
  6728. // NSData* json=nil;
  6729. // if(appDelegate.offline_mode)
  6730. // {
  6731. // json= [OLDataProvider offline_add2cartbyname:params];
  6732. // }
  6733. // else
  6734. // {
  6735. // if(![self IsNetworkAvailable])
  6736. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6737. //
  6738. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  6739. // }
  6740. // if(json==nil)
  6741. // return nil;
  6742. // NSError *error=nil;
  6743. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6744. //
  6745. //
  6746. //
  6747. // int result = [[jsobj valueForKey:@"result"] intValue];
  6748. //
  6749. // if (result==2||result==8)
  6750. // {
  6751. //
  6752. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6753. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6754. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6755. //
  6756. // [appDelegate update_count_mark];
  6757. // }
  6758. //
  6759. // return jsobj;
  6760. }
  6761. +(void) request_addto_wishlist:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6762. {
  6763. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6764. AppDelegate *appDelegate = nil;
  6765. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6766. if(appDelegate.user!=nil)
  6767. [params setValue:appDelegate.user forKey:@"user"];
  6768. if(appDelegate.contact_id!=nil)
  6769. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6770. if(appDelegate.password!=nil)
  6771. [params setValue:appDelegate.password forKey:@"password"];
  6772. [params setValue:item_id forKey:@"product_id"];
  6773. [params setObject:screenName forKey:kScreenName];
  6774. if(appDelegate.offline_mode)
  6775. {
  6776. // [OLDataProvider offline_add2wishlist:params completionHandler:result];
  6777. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6778. NSMutableDictionary* resulti = [[OLDataProvider offline_add2wishlist:params] mutableCopy];
  6779. dispatch_async(dispatch_get_main_queue(), ^{
  6780. int result_code = [[resulti valueForKey:@"result"] intValue];
  6781. if (result_code==2||result_code==8)
  6782. {
  6783. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6784. [appDelegate update_count_mark];
  6785. }
  6786. result(resulti);
  6787. });
  6788. });
  6789. return;
  6790. }
  6791. [self request_interface:URL_ADD_TO_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6792. int result_code = [[resulti valueForKey:@"result"] intValue];
  6793. if (result_code==2||result_code==8)
  6794. {
  6795. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6796. [appDelegate update_count_mark];
  6797. }
  6798. result(resulti);
  6799. } retry:0];
  6800. // if(appDelegate.offline_mode)
  6801. // {
  6802. // return [OLDataProvider offline_add2wishlist:params];
  6803. // }
  6804. // if(![self IsNetworkAvailable])
  6805. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6806. //
  6807. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  6808. // if(json==nil)
  6809. // return nil;
  6810. // NSError *error=nil;
  6811. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6812. // int result = [[jsobj valueForKey:@"result"] intValue];
  6813. //
  6814. // if (result==2)
  6815. // {
  6816. //
  6817. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6818. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6819. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6820. //
  6821. // [appDelegate update_count_mark];
  6822. // }
  6823. // return jsobj;
  6824. }
  6825. +(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
  6826. {
  6827. // for debug
  6828. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  6829. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6830. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6831. AppDelegate *appDelegate = nil;
  6832. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6833. if(appDelegate.user!=nil)
  6834. [params setValue:appDelegate.user forKey:@"user"];
  6835. if(appDelegate.contact_id!=nil)
  6836. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6837. if(appDelegate.password!=nil)
  6838. [params setValue:appDelegate.password forKey:@"password"];
  6839. if(appDelegate.order_code!=nil)
  6840. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6841. [params setValue:addTo forKey:@"addTo"];
  6842. [params setValue:orderCode forKey:@"orderCode"];
  6843. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6844. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6845. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  6846. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6847. // [params setValue:filter forKey:@"filter"];
  6848. [params setValue:covertype forKey:@"covertype"];
  6849. [params setValue:ctgid forKey:@"ctgId"];
  6850. [params setValue:modelname forKey:@"modelName"];
  6851. [params setValue:modeldescrip forKey:@"modelDescription"];
  6852. [params setValue:alert forKey:@"alert"];
  6853. [params setValue:qty forKey:@"sold_by_qty"];
  6854. [params setValue:available forKey:@"available"];
  6855. [params setValue:price forKey:@"price"];
  6856. [params setValue:bestseller forKey:@"bestseller"];
  6857. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6858. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6859. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  6860. if ([addTo isEqualToString:@"cart"]) {
  6861. [params setObject:@"Add To Cart" forKey:kAction];
  6862. }
  6863. if(appDelegate.offline_mode)
  6864. {
  6865. if ([addTo isEqualToString:@"cart"])
  6866. {
  6867. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6868. }
  6869. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6870. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_itemsearchaddall:params]] mutableCopy];
  6871. dispatch_async(dispatch_get_main_queue(), ^{
  6872. int result_code =[json[@"result"] intValue];
  6873. if (result_code==2||result_code==8)
  6874. {
  6875. if(json[@"cart_count"])
  6876. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6877. if(json[@"wish_count"])
  6878. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  6879. if(json[@"portfolio_count"])
  6880. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  6881. //
  6882. //
  6883. [appDelegate update_count_mark];
  6884. }
  6885. result(json);
  6886. });
  6887. });
  6888. return;
  6889. }
  6890. NSString * uuid= [[NSUUID UUID] UUIDString];
  6891. params[@"resultSerial"]=uuid;
  6892. __block bool bbreak = false;
  6893. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6894. for(int i=0;i<150;i++)
  6895. {
  6896. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6897. // result_params[@"resultSerial"]=uuid;
  6898. if(bbreak)
  6899. break;
  6900. dispatch_async(dispatch_get_main_queue(), ^{
  6901. [self request_interface:URL_ITEMSEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6902. if([resulti[@"result"] intValue]==2)
  6903. {
  6904. if(!bbreak)//此判断保证result只调用一次。
  6905. result(resulti);
  6906. bbreak=true;
  6907. }
  6908. } retry:3];
  6909. });
  6910. sleep(2);
  6911. }
  6912. });
  6913. //
  6914. // NSData* json = nil;
  6915. //
  6916. // if(appDelegate.offline_mode)
  6917. // {
  6918. // json= [OLDataProvider offline_itemsearchaddall:params];
  6919. // }
  6920. // else
  6921. // {
  6922. // if(![self IsNetworkAvailable])
  6923. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6924. // NSError *error=nil;
  6925. //
  6926. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6927. // params[@"resultSerial"]=uuid;
  6928. //
  6929. // for(int i=0;i<150;i++)
  6930. // {
  6931. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6932. // // result_params[@"resultSerial"]=uuid;
  6933. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  6934. // if(json!=nil)
  6935. // {
  6936. //
  6937. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6938. // if([jsobj[@"result"] intValue]==2)
  6939. // {
  6940. // break;
  6941. // }
  6942. // }
  6943. // sleep(2);
  6944. // }
  6945. // }
  6946. // if(json==nil)
  6947. // return nil;
  6948. // NSError *error=nil;
  6949. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6950. // return jsobj;
  6951. }
  6952. +(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
  6953. {
  6954. AppDelegate *appDelegate = nil;
  6955. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6956. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6957. if(appDelegate.user!=nil)
  6958. [params setValue:appDelegate.user forKey:@"user"];
  6959. if(appDelegate.contact_id!=nil)
  6960. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6961. if(appDelegate.password!=nil)
  6962. [params setValue:appDelegate.password forKey:@"password"];
  6963. if(appDelegate.order_code!=nil)
  6964. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6965. [params setValue:addTo forKey:@"addTo"];
  6966. [params setValue:orderCode forKey:@"orderCode"];
  6967. [params setValue:alert forKey:@"alert"];
  6968. [params setValue:qty forKey:@"sold_by_qty"];
  6969. [params setValue:available forKey:@"available"];
  6970. [params setValue:price forKey:@"price"];
  6971. [params setValue:bestseller forKey:@"bestseller"];
  6972. [params setValue:modelname forKey:@"modelName"];
  6973. [params setValue:modeldescrip forKey:@"modelDescription"];
  6974. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6975. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6976. [params setValue:category forKey:@"category"];
  6977. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6978. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6979. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6980. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6981. [params setValue:filter forKey:@"filter"];
  6982. [params setValue:keyword forKey:@"keyword"];
  6983. [params setObject:ScreenCodeCategory forKey:kScreenName];
  6984. if ([addTo isEqualToString:@"cart"]) {
  6985. [params setObject:@"Add To Cart" forKey:kAction];
  6986. }
  6987. if(appDelegate.offline_mode)
  6988. {
  6989. if ([addTo isEqualToString:@"cart"])
  6990. {
  6991. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6992. }
  6993. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6994. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_categoryaddall:params]] mutableCopy];
  6995. dispatch_async(dispatch_get_main_queue(), ^{
  6996. int result_code =[json[@"result"] intValue];
  6997. if (result_code==2||result_code==8)
  6998. {
  6999. if(json[@"cart_count"])
  7000. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7001. if(json[@"wish_count"])
  7002. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7003. if(json[@"portfolio_count"])
  7004. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7005. //
  7006. //
  7007. [appDelegate update_count_mark];
  7008. }
  7009. result(json);
  7010. });
  7011. });
  7012. return;
  7013. }
  7014. NSString * uuid= [[NSUUID UUID] UUIDString];
  7015. params[@"resultSerial"]=uuid;
  7016. __block bool bbreak = false;
  7017. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7018. for(int i=0;i<150;i++)
  7019. {
  7020. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7021. // result_params[@"resultSerial"]=uuid;
  7022. if(bbreak)
  7023. break;
  7024. dispatch_async(dispatch_get_main_queue(), ^{
  7025. [self request_interface:URL_CATEGORYADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7026. if([resulti[@"result"] intValue]==2|| [resulti[@"result"] intValue] == 8)
  7027. {
  7028. if(!bbreak)//此判断保证result只调用一次。
  7029. {
  7030. int result_code =[resulti[@"result"] intValue];
  7031. if (result_code==2||result_code==8)
  7032. {
  7033. if(resulti[@"cart_count"])
  7034. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7035. if(resulti[@"wish_count"])
  7036. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7037. if(resulti[@"portfolio_count"])
  7038. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  7039. //
  7040. //
  7041. [appDelegate update_count_mark];
  7042. }
  7043. result(resulti);
  7044. }
  7045. bbreak=true;
  7046. }
  7047. } retry:3];
  7048. });
  7049. sleep(2);
  7050. }
  7051. });
  7052. //
  7053. // NSData* json= nil;
  7054. //
  7055. // if(appDelegate.offline_mode)
  7056. // {
  7057. // json= [OLDataProvider offline_categoryaddall:params];
  7058. // }
  7059. // else
  7060. // {
  7061. // if(![self IsNetworkAvailable])
  7062. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7063. //
  7064. //
  7065. // NSError *error=nil;
  7066. //
  7067. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7068. // params[@"resultSerial"]=uuid;
  7069. //
  7070. // for(int i=0;i<150;i++)
  7071. // {
  7072. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7073. //// result_params[@"resultSerial"]=uuid;
  7074. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  7075. // if(json!=nil)
  7076. // {
  7077. //
  7078. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7079. // int resultInt = [jsobj[@"result"] intValue];
  7080. // if(resultInt == 2 || resultInt == 8)
  7081. // {
  7082. // break;
  7083. // }
  7084. // }
  7085. // sleep(2);
  7086. // }
  7087. //
  7088. //
  7089. //
  7090. // }
  7091. // if(json==nil)
  7092. // return nil;
  7093. // NSError *error=nil;
  7094. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7095. // return jsobj;
  7096. }
  7097. +(void)request_save_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7098. {
  7099. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7100. AppDelegate *appDelegate = nil;
  7101. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7102. if(appDelegate.user!=nil)
  7103. [params setValue:appDelegate.user forKey:@"user"];
  7104. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  7105. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7106. // else
  7107. if(appDelegate.contact_id!=nil)
  7108. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7109. if(appDelegate.password!=nil)
  7110. [params setValue:appDelegate.password forKey:@"password"];
  7111. if(appDelegate.order_code!=nil)
  7112. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7113. // NSDictionary* customerinfo=nil;
  7114. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  7115. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7116. // else
  7117. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7118. //
  7119. // appDelegate.customerInfo;
  7120. // NSArray* keys=[customerinfo allKeys];
  7121. // for(int i=0;i<keys.count;i++)
  7122. // {
  7123. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7124. // }
  7125. // [params setValue:sourceid forKey:@"sourceid"];
  7126. // [params setValue:editor forKey:@"editor"];
  7127. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  7128. if(appDelegate.offline_mode)
  7129. {
  7130. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7131. NSData* json = [[OLDataProvider offline_saveorder:params] mutableCopy];
  7132. dispatch_async(dispatch_get_main_queue(), ^{
  7133. result([[RAConvertor data2dict:json] mutableCopy]);
  7134. });
  7135. });
  7136. return;
  7137. }
  7138. [self request_interface:URL_SAVE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  7139. //
  7140. // NSData* json=nil;
  7141. //
  7142. // if(appDelegate.offline_mode)
  7143. // {
  7144. // json= [OLDataProvider offline_saveorder:params];
  7145. // }
  7146. // else
  7147. // {
  7148. // if(![self IsNetworkAvailable])
  7149. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7150. //
  7151. // json=[self get_json:URL_SAVE_ORDER parameters:params];
  7152. // }
  7153. // if(json!=nil)
  7154. // {
  7155. // NSError *error=nil;
  7156. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7157. // NSString *so = [jsobj valueForKey:@"so#"];
  7158. // if (so) {
  7159. // [appDelegate SetSo:so];
  7160. // }
  7161. // return jsobj;
  7162. // }
  7163. // else
  7164. // return nil;
  7165. }
  7166. +(void) request_update_cartqty:(NSString*) cart_id value:(int) value completionHandler:(resultHandler)result
  7167. {
  7168. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  7169. #ifdef SCANNER_ORDER
  7170. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7171. {
  7172. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7173. //
  7174. //
  7175. // [appDelegate update_count_mark];
  7176. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7177. int count = [section[@"count"] intValue];
  7178. for(int i=0;i<count;i++)
  7179. {
  7180. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7181. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7182. {
  7183. item[@"count"] =@(value);
  7184. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7185. break;
  7186. }
  7187. }
  7188. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7189. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7190. result(RASingleton.sharedInstance.scan_cart);
  7191. [OLDataProvider updateScanOrder:appDelegate.order_code];
  7192. return;
  7193. }
  7194. #else
  7195. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7196. if(appDelegate.user!=nil)
  7197. [params setValue:appDelegate.user forKey:@"user"];
  7198. if(appDelegate.contact_id!=nil)
  7199. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7200. if(appDelegate.password!=nil)
  7201. [params setValue:appDelegate.password forKey:@"password"];
  7202. [params setValue:cart_id forKey:@"cartitem_id"];
  7203. [params setObject:ScreenCodeCart forKey:kScreenName];
  7204. [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  7205. if(appDelegate.offline_mode)
  7206. {
  7207. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7208. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7209. NSData* json = [[OLDataProvider offline_cartsetqty:params] mutableCopy];
  7210. dispatch_async(dispatch_get_main_queue(), ^{
  7211. result([[RAConvertor data2dict:json] mutableCopy]);
  7212. });
  7213. });
  7214. return;
  7215. }
  7216. [self request_interface:URL_CART_INCRESEMENT parameters:params err_record_url:nil completionHandler:result retry:0];
  7217. //
  7218. // NSData* json=nil;
  7219. // if(appDelegate.offline_mode)
  7220. // {
  7221. // json= [OLDataProvider offline_cartsetqty:params];
  7222. // }
  7223. // else
  7224. // {
  7225. // if(![self IsNetworkAvailable])
  7226. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7227. //
  7228. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  7229. // }
  7230. // if(json==nil)
  7231. // return nil;
  7232. // NSError *error=nil;
  7233. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7234. // return jsobj;
  7235. #endif
  7236. }
  7237. +(void) request_update_cartgeneralnote:(NSString*) order_code notes:(NSString*) notes completionHandler:(resultHandler)result
  7238. {
  7239. #ifdef SCANNER_ORDER
  7240. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7241. {
  7242. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7243. //
  7244. //
  7245. // [appDelegate update_count_mark];
  7246. RASingleton.sharedInstance.scan_cart[@"general_note"] = notes;
  7247. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7248. result(RASingleton.sharedInstance.scan_cart);
  7249. return;
  7250. }
  7251. #else
  7252. AppDelegate *appDelegate = nil;
  7253. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7254. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7255. if(appDelegate.user!=nil)
  7256. [params setValue:appDelegate.user forKey:@"user"];
  7257. if(appDelegate.contact_id!=nil)
  7258. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7259. if(appDelegate.password!=nil)
  7260. [params setValue:appDelegate.password forKey:@"password"];
  7261. [params setValue:order_code forKey:@"orderCode"];
  7262. [params setObject:ScreenCodeCart forKey:kScreenName];
  7263. if(notes.length==0)
  7264. notes=@"";
  7265. [params setValue:notes forKey:@"comments"];
  7266. if(appDelegate.offline_mode)
  7267. {
  7268. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7269. NSData* json = [[OLDataProvider offline_updategnotes:params] mutableCopy];
  7270. dispatch_async(dispatch_get_main_queue(), ^{
  7271. result([[RAConvertor data2dict:json] mutableCopy]);
  7272. });
  7273. });
  7274. return;
  7275. }
  7276. [self request_interface:URL_CART_GENERAL_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7277. //
  7278. // NSData* json=nil;
  7279. // if(appDelegate.offline_mode)
  7280. // {
  7281. // json= [OLDataProvider offline_updategnotes:params];
  7282. // }
  7283. // else
  7284. // {
  7285. // if(![self IsNetworkAvailable])
  7286. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7287. //
  7288. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  7289. // }
  7290. // if(json==nil)
  7291. // return nil;
  7292. // NSError *error=nil;
  7293. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7294. // return jsobj;
  7295. #endif
  7296. }
  7297. +(void) request_update_cartitemnote:(NSString*) cart_id notes:(NSString*) notes completionHandler:(resultHandler)result
  7298. {
  7299. AppDelegate *appDelegate = nil;
  7300. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7301. #ifdef SCANNER_ORDER
  7302. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7303. {
  7304. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7305. //
  7306. //
  7307. // [appDelegate update_count_mark];
  7308. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7309. int count = [section[@"count"] intValue];
  7310. for(int i=0;i<count;i++)
  7311. {
  7312. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7313. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7314. {
  7315. item[@"note"] =notes;
  7316. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7317. break;
  7318. }
  7319. }
  7320. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7321. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7322. result(RASingleton.sharedInstance.scan_cart);
  7323. return;
  7324. }
  7325. #else
  7326. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7327. if(appDelegate.user!=nil)
  7328. [params setValue:appDelegate.user forKey:@"user"];
  7329. if(appDelegate.contact_id!=nil)
  7330. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7331. if(appDelegate.password!=nil)
  7332. [params setValue:appDelegate.password forKey:@"password"];
  7333. [params setValue:cart_id forKey:@"cartitem_id"];
  7334. [params setObject:ScreenCodeCart forKey:kScreenName];
  7335. if(notes.length==0)
  7336. notes=@"";
  7337. [params setValue:notes forKey:@"notes"];
  7338. if(appDelegate.offline_mode)
  7339. {
  7340. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7341. NSData* json = [[OLDataProvider offline_cartsetlnotes:params] mutableCopy];
  7342. dispatch_async(dispatch_get_main_queue(), ^{
  7343. result([[RAConvertor data2dict:json] mutableCopy]);
  7344. });
  7345. });
  7346. return;
  7347. }
  7348. [self request_interface:URL_CART_ITEM_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7349. //
  7350. // NSData* json=nil;
  7351. // if(appDelegate.offline_mode)
  7352. // {
  7353. // json= [OLDataProvider offline_cartsetlnotes:params];
  7354. // }
  7355. // else
  7356. // {
  7357. // if(![self IsNetworkAvailable])
  7358. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7359. //
  7360. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  7361. // }
  7362. // if(json==nil)
  7363. // return nil;
  7364. // NSError *error=nil;
  7365. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7366. // return jsobj;
  7367. #endif
  7368. }
  7369. + (void)request_update_npd_shop_price_type:(NSInteger)priceType completionHandler:(resultHandler)result
  7370. {
  7371. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7372. AppDelegate *appDelegate = nil;
  7373. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7374. if(appDelegate.user!=nil)
  7375. [dic setValue:appDelegate.user forKey:@"user"];
  7376. if(appDelegate.password!=nil)
  7377. [dic setValue:appDelegate.password forKey:@"password"];
  7378. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  7379. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  7380. if(appDelegate.offline_mode)
  7381. {
  7382. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7383. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7384. dispatch_async(dispatch_get_main_queue(), ^{
  7385. result(json);
  7386. });
  7387. });
  7388. return;
  7389. }
  7390. [self request_interface:URL_SET_PRICE_TYPE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7391. //
  7392. // NSData* json=nil;
  7393. // if(appDelegate.offline_mode)
  7394. // {
  7395. // return [OLDataProvider offline_notimpl];
  7396. // }
  7397. // else
  7398. // {
  7399. // if(![self IsNetworkAvailable])
  7400. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7401. //
  7402. // json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  7403. // }
  7404. // if(json!=nil)
  7405. // {
  7406. // NSError *error=nil;
  7407. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7408. //
  7409. //
  7410. // return jsobj;
  7411. // }
  7412. //
  7413. //
  7414. // return nil;
  7415. }
  7416. + (void)request_npd_shop_givenprice:(resultHandler)result
  7417. {
  7418. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7419. AppDelegate *appDelegate = nil;
  7420. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7421. if(appDelegate.user!=nil)
  7422. [dic setValue:appDelegate.user forKey:@"user"];
  7423. if(appDelegate.password!=nil)
  7424. [dic setValue:appDelegate.password forKey:@"password"];
  7425. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  7426. if(appDelegate.offline_mode)
  7427. {
  7428. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7429. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7430. dispatch_async(dispatch_get_main_queue(), ^{
  7431. result(json);
  7432. });
  7433. });
  7434. return;
  7435. }
  7436. [self request_interface:URL_GET_CIVEN_PRICE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7437. //
  7438. // NSData* json=nil;
  7439. // if(appDelegate.offline_mode)
  7440. // {
  7441. // return [OLDataProvider offline_notimpl];
  7442. // }
  7443. // else
  7444. // {
  7445. // if(![self IsNetworkAvailable])
  7446. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7447. //
  7448. // json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  7449. // }
  7450. // if(json!=nil)
  7451. // {
  7452. // NSError *error=nil;
  7453. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7454. //
  7455. //
  7456. // return jsobj;
  7457. // }
  7458. //
  7459. //
  7460. // return nil;
  7461. }
  7462. + (void)request_update_npd_shop_givenprice:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  7463. {
  7464. AppDelegate *appDelegate = nil;
  7465. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7466. if(appDelegate.user!=nil)
  7467. [params setValue:appDelegate.user forKey:@"user"];
  7468. if(appDelegate.password!=nil)
  7469. [params setValue:appDelegate.password forKey:@"password"];
  7470. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  7471. if(appDelegate.offline_mode)
  7472. {
  7473. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7474. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7475. dispatch_async(dispatch_get_main_queue(), ^{
  7476. result(json);
  7477. });
  7478. });
  7479. return;
  7480. }
  7481. [self request_interface:URL_SET_GIVEN_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  7482. //
  7483. // NSData* json=nil;
  7484. // if(appDelegate.offline_mode)
  7485. // {
  7486. // return [OLDataProvider offline_notimpl];
  7487. // }
  7488. // else
  7489. // {
  7490. // if(![self IsNetworkAvailable])
  7491. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7492. //
  7493. // json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  7494. // }
  7495. // if(json!=nil)
  7496. // {
  7497. // NSError *error=nil;
  7498. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7499. //
  7500. //
  7501. // return jsobj;
  7502. // }
  7503. //
  7504. //
  7505. // return nil;
  7506. }
  7507. +(void) request_create_portfolio:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7508. {
  7509. AppDelegate *appDelegate = nil;
  7510. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7511. if(appDelegate.offline_mode)
  7512. {
  7513. params[@"contact_id"]=params[@"contactId"];
  7514. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7515. NSData* json = [[OLDataProvider offline_direct_save_TearSheet:params] mutableCopy];
  7516. dispatch_async(dispatch_get_main_queue(), ^{
  7517. result([[RAConvertor data2dict:json] mutableCopy]);
  7518. });
  7519. });
  7520. return;
  7521. }
  7522. //
  7523. // if(appDelegate.offline_mode)
  7524. // {
  7525. //
  7526. //
  7527. // NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  7528. // if(json==nil)
  7529. // return nil;
  7530. // NSError *error=nil;
  7531. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7532. //
  7533. // return jsobj[@"pdf_path"];
  7534. // }
  7535. // else
  7536. // {
  7537. // return nil;
  7538. // }
  7539. }
  7540. +(void)request_save_portfoliodirectly:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7541. {
  7542. NSMutableDictionary* off_params = [params mutableCopy];
  7543. AppDelegate *appDelegate = nil;
  7544. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7545. if(appDelegate.user!=nil)
  7546. [params setValue:appDelegate.user forKey:@"user"];
  7547. if(appDelegate.contact_id!=nil)
  7548. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7549. if(appDelegate.password!=nil)
  7550. params[@"off_params"]=[RAConvertor dict2string:off_params];
  7551. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  7552. [params setValue:appDelegate.password forKey:@"password"];
  7553. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7554. if(appDelegate.offline_mode)
  7555. {
  7556. params[@"contact_id"]=appDelegate.contact_id;
  7557. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7558. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_direct_save_TearSheet:params]] mutableCopy];
  7559. dispatch_async(dispatch_get_main_queue(), ^{
  7560. result(json);
  7561. });
  7562. });
  7563. return;
  7564. }
  7565. NSString * uuid= [[NSUUID UUID] UUIDString];
  7566. params[@"resultSerial"]=uuid;
  7567. __block bool bbreak = false;
  7568. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7569. for(int i=0;i<150;i++)
  7570. {
  7571. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7572. // result_params[@"resultSerial"]=uuid;
  7573. if(bbreak)
  7574. break;
  7575. dispatch_async(dispatch_get_main_queue(), ^{
  7576. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7577. if([resulti[@"result"] intValue]==2)
  7578. {
  7579. if(!bbreak)//此判断保证result只调用一次。
  7580. result(resulti);
  7581. bbreak=true;
  7582. }
  7583. } retry:3];
  7584. });
  7585. sleep(2);
  7586. }
  7587. });
  7588. //
  7589. //
  7590. // NSData* json= nil;
  7591. //
  7592. // if(appDelegate.offline_mode)
  7593. // {
  7594. // json = [OLDataProvider offline_direct_save_TearSheet:params];
  7595. // }
  7596. // else
  7597. // {
  7598. // if(![self IsNetworkAvailable])
  7599. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7600. //
  7601. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7602. //
  7603. // NSError *error=nil;
  7604. //
  7605. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7606. // params[@"resultSerial"]=uuid;
  7607. //
  7608. // for(int i=0;i<150;i++)
  7609. // {
  7610. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7611. // // result_params[@"resultSerial"]=uuid;
  7612. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7613. // if(json!=nil)
  7614. // {
  7615. //
  7616. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7617. // if([jsobj[@"result"] intValue]==2)
  7618. // {
  7619. // break;
  7620. // }
  7621. // }
  7622. // sleep(5);
  7623. // }
  7624. //
  7625. // }
  7626. // if(json==nil)
  7627. // return nil;
  7628. // NSError *error=nil;
  7629. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7630. // return jsobj;
  7631. }
  7632. +(void)request_save_portfolio:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  7633. {
  7634. AppDelegate *appDelegate = nil;
  7635. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7636. if(appDelegate.user!=nil)
  7637. [params setValue:appDelegate.user forKey:@"user"];
  7638. if(appDelegate.contact_id!=nil)
  7639. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7640. NSMutableDictionary* off_params = [params mutableCopy];;
  7641. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  7642. params[@"off_params"]=[RAConvertor dict2string:off_params];
  7643. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7644. if(appDelegate.password!=nil)
  7645. [params setValue:appDelegate.password forKey:@"password"];
  7646. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7647. if(appDelegate.offline_mode)
  7648. {
  7649. params[@"contact_id"]=appDelegate.contact_id;
  7650. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7651. NSData* json = [[OLDataProvider offline_save_TearSheet:params] mutableCopy];
  7652. dispatch_async(dispatch_get_main_queue(), ^{
  7653. result([[RAConvertor data2dict:json] mutableCopy]);
  7654. });
  7655. });
  7656. return;
  7657. }
  7658. [self request_interface:URL_SAVE_DM parameters:params err_record_url:nil completionHandler:result retry:0];
  7659. //
  7660. // NSData* json = nil;
  7661. // if(appDelegate.offline_mode)
  7662. // {
  7663. // json = [OLDataProvider offline_save_TearSheet:params];
  7664. // } else {
  7665. // if(![self IsNetworkAvailable])
  7666. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7667. //
  7668. // json=[self get_json:URL_SAVE_DM parameters:params];
  7669. // }
  7670. // if(json==nil)
  7671. // return nil;
  7672. // NSError *error=nil;
  7673. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7674. // return jsobj;
  7675. }
  7676. +(void)request_portfoliopreview:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7677. {
  7678. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7679. AppDelegate *appDelegate = nil;
  7680. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7681. if(appDelegate.user!=nil)
  7682. [params setValue:appDelegate.user forKey:@"user"];
  7683. if(appDelegate.contact_id!=nil)
  7684. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7685. if(appDelegate.password!=nil)
  7686. [params setValue:appDelegate.password forKey:@"password"];
  7687. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7688. // [params setValue:request_url forKey:@"pdfUrl"];
  7689. if(appDelegate.offline_mode)
  7690. {
  7691. params[@"contact_id"]=params[@"contactId"];
  7692. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7693. NSData* json = [[OLDataProvider offline_request_tearsheet:params] mutableCopy];
  7694. dispatch_async(dispatch_get_main_queue(), ^{
  7695. result([[RAConvertor data2dict:json] mutableCopy]);
  7696. });
  7697. });
  7698. return;
  7699. }
  7700. NSString * uuid= [[NSUUID UUID] UUIDString];
  7701. params[@"resultSerial"]=uuid;
  7702. __block bool bbreak = false;
  7703. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7704. for(int i=0;i<150;i++)
  7705. {
  7706. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7707. // result_params[@"resultSerial"]=uuid;
  7708. if(bbreak)
  7709. break;
  7710. dispatch_async(dispatch_get_main_queue(), ^{
  7711. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7712. if([resulti[@"result"] intValue]==2)
  7713. {
  7714. if(!bbreak)//此判断保证result只调用一次。
  7715. result(resulti);
  7716. bbreak=true;
  7717. }
  7718. } retry:3];
  7719. });
  7720. sleep(5);
  7721. }
  7722. });
  7723. //
  7724. // NSData* json= nil;
  7725. // if(appDelegate.offline_mode)
  7726. // {
  7727. // json= [OLDataProvider offline_request_tearsheet:params];
  7728. // }
  7729. // else
  7730. // {
  7731. // if(![self IsNetworkAvailable])
  7732. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7733. //
  7734. // NSError *error=nil;
  7735. //
  7736. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7737. // params[@"resultSerial"]=uuid;
  7738. //
  7739. // for(int i=0;i<150;i++)
  7740. // {
  7741. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7742. // // result_params[@"resultSerial"]=uuid;
  7743. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7744. // if(json!=nil)
  7745. // {
  7746. //
  7747. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7748. // if([jsobj[@"result"] intValue]==2)
  7749. // {
  7750. // break;
  7751. // }
  7752. // }
  7753. // sleep(5);
  7754. // }
  7755. // }
  7756. // if(json==nil)
  7757. // return nil;
  7758. // NSError *error=nil;
  7759. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7760. // return jsobj;
  7761. }
  7762. +(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
  7763. {
  7764. // for debug
  7765. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  7766. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7767. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7768. AppDelegate *appDelegate = nil;
  7769. //some UI methods ej
  7770. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7771. if(appDelegate.user!=nil)
  7772. [params setValue:appDelegate.user forKey:@"user"];
  7773. if(appDelegate.contact_id!=nil)
  7774. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7775. if(appDelegate.password!=nil)
  7776. [params setValue:appDelegate.password forKey:@"password"];
  7777. if(appDelegate.order_code!=nil)
  7778. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7779. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  7780. if (alert && qty && available && price && bestseller) {
  7781. [params setObject:@"Filter" forKey:kAction];
  7782. }
  7783. if ([RASingleton sharedInstance].homeItemClick) {
  7784. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  7785. [RASingleton sharedInstance].homeItemClick = NO;
  7786. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  7787. [RASingleton sharedInstance].homeClickedItemName = nil;
  7788. [params setObject:extra forKey:kExtra];
  7789. }
  7790. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7791. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7792. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  7793. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7794. // [params setValue:filter forKey:@"filter"];
  7795. [params setValue:covertype forKey:@"covertype"];
  7796. [params setValue:ctgid forKey:@"ctgId"];
  7797. [params setValue:modelname forKey:@"modelName"];
  7798. [params setValue:modeldescrip forKey:@"modelDescription"];
  7799. [params setValue:alert forKey:@"alert"];
  7800. [params setValue:qty forKey:@"sold_by_qty"];
  7801. [params setValue:available forKey:@"available"];
  7802. [params setValue:price forKey:@"price"];
  7803. [params setValue:bestseller forKey:@"bestseller"];
  7804. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7805. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7806. if(appDelegate.offline_mode)
  7807. {
  7808. // [OLDataProvider offline_itemsearch:params completionHandler:result];
  7809. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7810. NSMutableDictionary* json = [[OLDataProvider offline_itemsearch:params] mutableCopy];
  7811. dispatch_async(dispatch_get_main_queue(), ^{
  7812. result(json);
  7813. });
  7814. });
  7815. return;
  7816. }
  7817. [self request_interface:URL_ITEM_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  7818. // if(appDelegate.offline_mode)
  7819. // {
  7820. // return [OLDataProvider offline_itemsearch:params];
  7821. // }
  7822. // if(![self IsNetworkAvailable])
  7823. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7824. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  7825. // if(json==nil)
  7826. // return nil;
  7827. // NSError *error=nil;
  7828. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7829. // return jsobj;
  7830. }
  7831. +(void)request_modelqty: (NSString*) fashionId completionHandler:(resultHandler)result
  7832. {
  7833. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7834. AppDelegate *appDelegate = nil;
  7835. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7836. if(appDelegate.user!=nil)
  7837. [params setValue:appDelegate.user forKey:@"user"];
  7838. if(appDelegate.contact_id!=nil)
  7839. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7840. if(appDelegate.password!=nil)
  7841. [params setValue:appDelegate.password forKey:@"password"];
  7842. [params setValue:fashionId forKey:@"fashionId"];
  7843. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  7844. if(appDelegate.offline_mode)
  7845. {
  7846. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7847. NSData* json = [[OLDataProvider offline_model_qty:params] mutableCopy];
  7848. dispatch_async(dispatch_get_main_queue(), ^{
  7849. result([[RAConvertor data2dict:json] mutableCopy]);
  7850. });
  7851. });
  7852. return;
  7853. }
  7854. [self request_interface:URL_REQUEST_MODEL_QTY parameters:params err_record_url:nil completionHandler:result retry:0];
  7855. // NSData* json = nil;
  7856. // if(appDelegate.offline_mode)
  7857. // {
  7858. // json = [OLDataProvider offline_model_qty:params];
  7859. // } else {
  7860. // if(![self IsNetworkAvailable])
  7861. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7862. //
  7863. // json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  7864. // }
  7865. // if(json==nil)
  7866. // return nil;
  7867. // NSError *error=nil;
  7868. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7869. // return jsobj;
  7870. }
  7871. +(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
  7872. {
  7873. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7874. AppDelegate *appDelegate = nil;
  7875. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7876. if(appDelegate.user!=nil)
  7877. [params setValue:appDelegate.user forKey:@"user"];
  7878. if(appDelegate.contact_id!=nil)
  7879. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7880. if(appDelegate.password!=nil)
  7881. [params setValue:appDelegate.password forKey:@"password"];
  7882. [params setValue:watchlist_id forKey:@"item_id"];
  7883. // if(notes.length>0)
  7884. // [params setValue:notes forKey:@"notes"];
  7885. if(notes)
  7886. [params setValue:notes forKey:@"notes"];
  7887. if(price != -MAXFLOAT)
  7888. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  7889. if (discount != -MAXFLOAT)
  7890. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  7891. if(qty_p != -MAXFLOAT)
  7892. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  7893. if(qty != -INT32_MAX)
  7894. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  7895. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  7896. // NSData* json = nil;
  7897. if(appDelegate.offline_mode)
  7898. {
  7899. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7900. NSData* json = [[OLDataProvider offline_editPortfolio:params] mutableCopy];
  7901. dispatch_async(dispatch_get_main_queue(), ^{
  7902. result([[RAConvertor data2dict:json] mutableCopy]);
  7903. });
  7904. });
  7905. return;
  7906. }
  7907. [self request_interface:URL_PORTFOLIO_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  7908. //
  7909. // if(appDelegate.offline_mode)
  7910. // {
  7911. // json = [OLDataProvider offline_editPortfolio:params];
  7912. // } else {
  7913. // if(![self IsNetworkAvailable])
  7914. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7915. //
  7916. // json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  7917. // }
  7918. // if(json==nil)
  7919. // return nil;
  7920. // NSError *error=nil;
  7921. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7922. // return jsobj;
  7923. }
  7924. +(void)request_add_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7925. {
  7926. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7927. AppDelegate *appDelegate = nil;
  7928. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7929. if(appDelegate.user!=nil)
  7930. [params setValue:appDelegate.user forKey:@"user"];
  7931. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  7932. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7933. // else
  7934. if(appDelegate.contact_id!=nil)
  7935. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7936. if(appDelegate.password!=nil)
  7937. [params setValue:appDelegate.password forKey:@"password"];
  7938. // NSDictionary* customerinfo=nil;
  7939. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  7940. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7941. // else
  7942. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7943. //
  7944. // appDelegate.customerInfo;
  7945. // NSArray* keys=[customerinfo allKeys];
  7946. // for(int i=0;i<keys.count;i++)
  7947. // {
  7948. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7949. // }
  7950. // [params setValue:sourceid forKey:@"sourceid"];
  7951. // [params setValue:editor forKey:@"editor"];
  7952. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  7953. if(appDelegate.offline_mode)
  7954. {
  7955. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7956. NSData* json = [[OLDataProvider offline_saveNewContact:params] mutableCopy];
  7957. dispatch_async(dispatch_get_main_queue(), ^{
  7958. result([[RAConvertor data2dict:json] mutableCopy]);
  7959. });
  7960. });
  7961. return;
  7962. }
  7963. [self request_interface:URL_CUSTOMER_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  7964. //
  7965. // NSData* json=nil;
  7966. // if(appDelegate.offline_mode)
  7967. // {
  7968. // json= [OLDataProvider offline_saveNewContact:params];
  7969. // }
  7970. // else
  7971. // {
  7972. // if(![self IsNetworkAvailable])
  7973. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7974. //
  7975. // json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  7976. // }
  7977. //
  7978. // if(json!=nil)
  7979. // {
  7980. // NSError *error=nil;
  7981. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7982. // return jsobj;
  7983. // }
  7984. // else
  7985. // return nil;
  7986. }
  7987. +(void)request_update_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7988. {
  7989. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7990. AppDelegate *appDelegate = nil;
  7991. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7992. if(appDelegate.user!=nil)
  7993. [params setValue:appDelegate.user forKey:@"user"];
  7994. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  7995. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7996. // else
  7997. if(appDelegate.contact_id!=nil)
  7998. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7999. if(appDelegate.password!=nil)
  8000. [params setValue:appDelegate.password forKey:@"password"];
  8001. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8002. if(appDelegate.offline_mode)
  8003. {
  8004. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8005. NSData* json = [[OLDataProvider offline_saveContact:params] mutableCopy];
  8006. dispatch_async(dispatch_get_main_queue(), ^{
  8007. result([[RAConvertor data2dict:json] mutableCopy]);
  8008. });
  8009. });
  8010. return;
  8011. }
  8012. [self request_interface:URL_CUSTOMER_UPDATE parameters:params err_record_url:nil completionHandler:result retry:0];
  8013. //
  8014. // NSData* json=nil;
  8015. // if(appDelegate.offline_mode)
  8016. // {
  8017. // json= [OLDataProvider offline_saveContact:params];
  8018. // }
  8019. // else
  8020. // {
  8021. // if(![self IsNetworkAvailable])
  8022. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8023. //
  8024. // json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  8025. // }
  8026. //
  8027. // if(json!=nil)
  8028. // {
  8029. // NSError *error=nil;
  8030. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8031. // return jsobj;
  8032. // }
  8033. // else
  8034. // return nil;
  8035. }
  8036. +(void)request_delete_order:(NSString*) order_id completionHandler:(resultHandler)result
  8037. {
  8038. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8039. AppDelegate *appDelegate = nil;
  8040. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8041. if(appDelegate.user!=nil)
  8042. [params setValue:appDelegate.user forKey:@"user"];
  8043. // if(appDelegate.contact_id!=nil)
  8044. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8045. if(appDelegate.password!=nil)
  8046. [params setValue:appDelegate.password forKey:@"password"];
  8047. [params setValue:order_id forKey:@"orderId"];
  8048. // [params setValue:sourceid forKey:@"sourceid"];
  8049. // [params setValue:editor forKey:@"editor"];
  8050. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8051. if(appDelegate.offline_mode)
  8052. {
  8053. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8054. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8055. dispatch_async(dispatch_get_main_queue(), ^{
  8056. result(json);
  8057. });
  8058. });
  8059. return;
  8060. }
  8061. [self request_interface:URL_DELETE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8062. //
  8063. // if(appDelegate.offline_mode)
  8064. // {
  8065. // return [OLDataProvider offline_notimpl];
  8066. // }
  8067. // if(![self IsNetworkAvailable])
  8068. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8069. //
  8070. // NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  8071. // if(json!=nil)
  8072. // {
  8073. // NSError *error=nil;
  8074. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8075. //
  8076. //
  8077. // return jsobj;
  8078. // }
  8079. // else
  8080. // return nil;
  8081. }
  8082. +(void)request_cancel_order:(NSString*) order_id order_code:(NSString*) order_code completionHandler:(resultHandler)result
  8083. {
  8084. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8085. AppDelegate *appDelegate = nil;
  8086. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8087. if(appDelegate.user!=nil)
  8088. [params setValue:appDelegate.user forKey:@"user"];
  8089. // if(appDelegate.contact_id!=nil)
  8090. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8091. if(appDelegate.password!=nil)
  8092. [params setValue:appDelegate.password forKey:@"password"];
  8093. [params setValue:order_id forKey:@"orderId"];
  8094. [params setValue:order_code forKey:@"orderCode"];
  8095. // [params setValue:sourceid forKey:@"sourceid"];
  8096. // [params setValue:editor forKey:@"editor"];
  8097. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8098. if(appDelegate.offline_mode)
  8099. {
  8100. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8101. NSData* json = [[OLDataProvider offline_cancelorder:params] mutableCopy];
  8102. dispatch_async(dispatch_get_main_queue(), ^{
  8103. result([[RAConvertor data2dict:json] mutableCopy]);
  8104. });
  8105. });
  8106. return;
  8107. }
  8108. [self request_interface:URL_CANCEL_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8109. //
  8110. // NSData* json=nil;
  8111. // if(appDelegate.offline_mode)
  8112. // {
  8113. // json=[OLDataProvider offline_cancelorder:params];
  8114. // }
  8115. // else
  8116. // {
  8117. // if(![self IsNetworkAvailable])
  8118. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8119. // json=[self get_json:URL_CANCEL_ORDER parameters:params];
  8120. // }
  8121. // if(json!=nil)
  8122. // {
  8123. // NSError *error=nil;
  8124. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8125. //
  8126. //
  8127. // return jsobj;
  8128. // }
  8129. // else
  8130. // return nil;
  8131. }
  8132. +(void)request_release_order:(NSString*) order_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  8133. {
  8134. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8135. AppDelegate *appDelegate = nil;
  8136. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8137. if(appDelegate.user!=nil)
  8138. [params setValue:appDelegate.user forKey:@"user"];
  8139. // if(appDelegate.contact_id!=nil)
  8140. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8141. if(appDelegate.password!=nil)
  8142. [params setValue:appDelegate.password forKey:@"password"];
  8143. [params setValue:order_code forKey:@"orderCode"];
  8144. // [params setValue:sourceid forKey:@"sourceid"];
  8145. // [params setValue:editor forKey:@"editor"];
  8146. if (screenName) {
  8147. [params setValue:screenName forKey:kScreenName];
  8148. }
  8149. if(appDelegate.offline_mode)
  8150. {
  8151. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8152. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_resetorder:params]] mutableCopy];
  8153. dispatch_async(dispatch_get_main_queue(), ^{
  8154. if([[resulti valueForKey:@"result"]intValue]==2)
  8155. { [appDelegate SetSo:nil];
  8156. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8157. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8158. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8159. [appDelegate update_count_mark];
  8160. dispatch_async(dispatch_get_main_queue(), ^{
  8161. result(resulti);
  8162. });
  8163. }
  8164. });
  8165. });
  8166. return;
  8167. }
  8168. [self request_interface:URL_RELEASE_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8169. if([[resulti valueForKey:@"result"]intValue]==2)
  8170. { [appDelegate SetSo:nil];
  8171. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8172. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8173. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8174. [appDelegate update_count_mark];
  8175. dispatch_async(dispatch_get_main_queue(), ^{
  8176. result(resulti);
  8177. });
  8178. }
  8179. } retry:0];
  8180. //
  8181. // NSData* json=nil;
  8182. // if(appDelegate.offline_mode)
  8183. // {
  8184. // json= [OLDataProvider offline_resetorder:params];
  8185. // }
  8186. // else
  8187. // {
  8188. // if(![self IsNetworkAvailable])
  8189. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8190. //
  8191. // json=[self get_json:URL_RELEASE_ORDER parameters:params];
  8192. // }
  8193. // if(json!=nil)
  8194. // {
  8195. // NSError *error=nil;
  8196. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8197. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8198. // { [appDelegate SetSo:nil];
  8199. //
  8200. //
  8201. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8202. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8203. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8204. //
  8205. // [appDelegate update_count_mark];
  8206. // }
  8207. // return jsobj;
  8208. // }
  8209. // else
  8210. // return nil;
  8211. }
  8212. +(void)request_update_order_signature:(NSString*) order_code path:(NSString*)path completionHandler:(resultHandler)result
  8213. {
  8214. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8215. AppDelegate *appDelegate = nil;
  8216. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8217. if(appDelegate.user!=nil)
  8218. [params setValue:appDelegate.user forKey:@"user"];
  8219. if(appDelegate.contact_id!=nil)
  8220. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8221. if(appDelegate.password!=nil)
  8222. [params setValue:appDelegate.password forKey:@"password"];
  8223. // NSString* ssaved = @"false";
  8224. // if(saved)
  8225. // ssaved=@"true";
  8226. // [params setValue:@"true" forKey:@"saved"];
  8227. [params setValue:order_code forKey:@"orderCode"];
  8228. [params setValue:path forKey:@"picpath"];
  8229. // [params setValue:sourceid forKey:@"sourceid"];
  8230. // [params setValue:editor forKey:@"editor"];
  8231. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  8232. if(appDelegate.offline_mode)
  8233. {
  8234. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8235. NSData* json = [[OLDataProvider offline_signorder:params] mutableCopy];
  8236. dispatch_async(dispatch_get_main_queue(), ^{
  8237. result([[RAConvertor data2dict:json] mutableCopy]);
  8238. });
  8239. });
  8240. return;
  8241. }
  8242. [self request_interface:URL_SIGN_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8243. //
  8244. // NSData* json=nil;
  8245. // if(appDelegate.offline_mode)
  8246. // {
  8247. // json= [OLDataProvider offline_signorder:params];
  8248. // }
  8249. // else
  8250. // {
  8251. // if(![self IsNetworkAvailable])
  8252. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8253. //
  8254. // json=[self get_json:URL_SIGN_ORDER parameters:params];
  8255. // }
  8256. // if(json!=nil)
  8257. // {
  8258. // NSError *error=nil;
  8259. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8260. // return jsobj;
  8261. // }
  8262. // else
  8263. // return nil;
  8264. }
  8265. #ifdef SCANNER_ORDER
  8266. +(void) request_scan_bulkdiscount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8267. {
  8268. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  8269. //
  8270. //
  8271. // [appDelegate update_count_mark];
  8272. if(RASingleton.sharedInstance.price_type==0)
  8273. {
  8274. result(RASingleton.sharedInstance.scan_cart);
  8275. return;
  8276. }
  8277. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  8278. int count = [section[@"count"] intValue];
  8279. for(int i=0;i<count;i++)
  8280. {
  8281. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  8282. if ([item[@"special_price"] boolValue]||[item[@"net_price"] boolValue])
  8283. continue;
  8284. int item_count = [item[@"count"] intValue];
  8285. float price=[item[@"unit_price"] floatValue] ;
  8286. item[@"discount"] =@(discount);
  8287. item[@"subtotal_price"] =@(price*item_count);
  8288. if(discount>0)
  8289. item[@"note"] =[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  8290. else
  8291. item[@"note"] =@"";
  8292. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  8293. }
  8294. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  8295. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  8296. result(RASingleton.sharedInstance.scan_cart);
  8297. AppDelegate *appDelegate = nil;
  8298. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8299. [OLDataProvider updateScanOrder:appDelegate.order_code];
  8300. return;
  8301. }
  8302. #endif
  8303. +(void) request_update_cart_modelprice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8304. {
  8305. AppDelegate *appDelegate = nil;
  8306. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8307. #ifdef SCANNER_ORDER
  8308. // return;
  8309. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  8310. {
  8311. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  8312. //
  8313. //
  8314. // [appDelegate update_count_mark];
  8315. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  8316. int count = [section[@"count"] intValue];
  8317. for(int i=0;i<count;i++)
  8318. {
  8319. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  8320. if([item[@"cart_item_id"] isEqualToString:cart_id])
  8321. {
  8322. int item_count = [item[@"count"] intValue];
  8323. item[@"unit_price"] =@(price);
  8324. item[@"discount"] =@(discount);
  8325. item[@"subtotal_price"] =@(price*item_count);
  8326. if(discount>0)
  8327. item[@"note"] =[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  8328. else
  8329. item[@"note"] =@"";
  8330. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  8331. break;
  8332. }
  8333. }
  8334. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  8335. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  8336. result(RASingleton.sharedInstance.scan_cart);
  8337. [OLDataProvider updateScanOrder:appDelegate.order_code];
  8338. return;
  8339. }
  8340. #else
  8341. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8342. if(appDelegate.user!=nil)
  8343. [params setValue:appDelegate.user forKey:@"user"];
  8344. if(appDelegate.contact_id!=nil)
  8345. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8346. if(appDelegate.password!=nil)
  8347. [params setValue:appDelegate.password forKey:@"password"];
  8348. [params setValue:cart_id forKey:@"cartitem_id"];
  8349. [params setValue:notes forKey:@"item_note"];
  8350. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  8351. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  8352. [params setObject:ScreenCodeCart forKey:kScreenName];
  8353. if(appDelegate.offline_mode)
  8354. {
  8355. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8356. NSData* json = [[OLDataProvider offline_cartsetprice:params] mutableCopy];
  8357. dispatch_async(dispatch_get_main_queue(), ^{
  8358. result([[RAConvertor data2dict:json] mutableCopy]);
  8359. });
  8360. });
  8361. return;
  8362. }
  8363. [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8364. //
  8365. // NSData* json= nil;
  8366. // if(appDelegate.offline_mode)
  8367. // {
  8368. // json=[OLDataProvider offline_cartsetprice:params];
  8369. // }
  8370. // else
  8371. // {
  8372. // if(![self IsNetworkAvailable])
  8373. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8374. //
  8375. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8376. // }
  8377. // if(json==nil)
  8378. // return nil;
  8379. // NSError *error=nil;
  8380. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8381. // return jsobj;
  8382. #endif
  8383. }
  8384. +(void) request_addto_cart:(NSString* ) item_id count:(int) count name:(NSString *)name completionHandler:(resultHandler)result
  8385. {
  8386. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8387. AppDelegate *appDelegate = nil;
  8388. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8389. if(appDelegate.user!=nil)
  8390. [params setValue:appDelegate.user forKey:@"user"];
  8391. if(appDelegate.contact_id!=nil)
  8392. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8393. if(appDelegate.password!=nil)
  8394. [params setValue:appDelegate.password forKey:@"password"];
  8395. if(appDelegate.order_code!=nil)
  8396. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8397. [params setValue:item_id forKey:@"product_id"];
  8398. [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  8399. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  8400. [params setObject:@"Add To Cart" forKey:kAction];
  8401. if (name) {
  8402. NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  8403. [params setObject:extra forKey:kExtra];
  8404. }
  8405. NSDictionary* customerinfo= appDelegate.customerInfo;
  8406. NSArray* keys=[customerinfo allKeys];
  8407. for(int i=0;i<keys.count;i++)
  8408. {
  8409. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8410. }
  8411. if(appDelegate.offline_mode)
  8412. {
  8413. // [OLDataProvider offline_add2cart:params completionHandler:^(NSMutableDictionary *resulti) {
  8414. // NSMutableDictionary* json = resulti;
  8415. // if ([json[@"result"] intValue]==2)
  8416. // {
  8417. // appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  8418. //
  8419. // [appDelegate update_count_mark];
  8420. // }
  8421. // result(json);
  8422. // }];
  8423. params[@"can_create_backorder"]= @(appDelegate.can_create_backorder);
  8424. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8425. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cart:params]] mutableCopy];
  8426. dispatch_async(dispatch_get_main_queue(), ^{
  8427. if ([json[@"result"] intValue]==2)
  8428. {
  8429. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  8430. [appDelegate update_count_mark];
  8431. }
  8432. result(json);
  8433. });
  8434. });
  8435. return;
  8436. }
  8437. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8438. if ([resulti[@"result"] intValue]==2)
  8439. {
  8440. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8441. [appDelegate update_count_mark];
  8442. }
  8443. result(resulti);
  8444. } retry:0];
  8445. //
  8446. // NSData* json=nil;
  8447. // if(appDelegate.offline_mode)
  8448. // {
  8449. // json=[OLDataProvider offline_add2cart:params];
  8450. // }
  8451. // else
  8452. // {
  8453. // if(![self IsNetworkAvailable])
  8454. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8455. //
  8456. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  8457. // }
  8458. // if(json==nil)
  8459. // return nil;
  8460. // NSError *error=nil;
  8461. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8462. //
  8463. //
  8464. //
  8465. // int result = [[jsobj valueForKey:@"result"] intValue];
  8466. //
  8467. // if (result==2)
  8468. // {
  8469. //
  8470. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8471. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8472. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8473. //
  8474. // [appDelegate update_count_mark];
  8475. // }
  8476. //
  8477. // return jsobj;
  8478. }
  8479. //+(void) request_update_cart_modelfree:(NSString*) cart_id isfree:(bool) isfree completionHandler:(resultHandler)result
  8480. //{
  8481. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8482. // AppDelegate *appDelegate = nil;
  8483. //
  8484. //
  8485. //
  8486. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8487. //
  8488. // if(appDelegate.user!=nil)
  8489. // [params setValue:appDelegate.user forKey:@"user"];
  8490. // if(appDelegate.contact_id!=nil)
  8491. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8492. // if(appDelegate.password!=nil)
  8493. // [params setValue:appDelegate.password forKey:@"password"];
  8494. //
  8495. // [params setValue:cart_id forKey:@"cartitem_id"];
  8496. //
  8497. // [params setObject:ScreenCodeCart forKey:kScreenName];
  8498. //
  8499. // NSString* free=nil;
  8500. //
  8501. // if(isfree)
  8502. // free=@"true";
  8503. // else
  8504. // free=@"false";
  8505. //
  8506. // [params setValue:free forKey:@"free_giveaway"];
  8507. //
  8508. //
  8509. // if(appDelegate.offline_mode)
  8510. // {
  8511. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8512. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8513. // dispatch_async(dispatch_get_main_queue(), ^{
  8514. // result(json);
  8515. // });
  8516. // });
  8517. //
  8518. // return;
  8519. //
  8520. // }
  8521. // [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8522. //
  8523. ////
  8524. ////
  8525. //// if(appDelegate.offline_mode)
  8526. //// {
  8527. //// return [OLDataProvider offline_notimpl];
  8528. //// }
  8529. //// if(![self IsNetworkAvailable])
  8530. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8531. ////
  8532. //// NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8533. //// if(json==nil)
  8534. //// return nil;
  8535. //// NSError *error=nil;
  8536. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8537. //// return jsobj;
  8538. //}
  8539. +(void)request_retrieve_password: (NSString*) user email:(NSString*) email completionHandler:(resultHandler)result
  8540. {
  8541. AppDelegate *appDelegate = nil;
  8542. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8543. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8544. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8545. // if(appDelegate.user!=nil)
  8546. // [params setValue:appDelegate.user forKey:@"user"];
  8547. // if(appDelegate.contact_id!=nil)
  8548. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8549. // if(appDelegate.password!=nil)
  8550. // [params setValue:appDelegate.password forKey:@"password"];
  8551. [params setValue:user forKey:@"username"];
  8552. [params setValue:email forKey:@"email"];
  8553. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  8554. if(appDelegate.offline_mode)
  8555. {
  8556. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8557. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8558. dispatch_async(dispatch_get_main_queue(), ^{
  8559. result(json);
  8560. });
  8561. });
  8562. return;
  8563. }
  8564. #ifdef SCANNER_ORDER
  8565. params[@"site_name"]=[RADataProvider getSiteName];
  8566. params[@"_method"]=@"forgotPasswordOfflineOrderUser";
  8567. params[@"user"]=user;
  8568. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_RETRIEVE_PASS];
  8569. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  8570. #else
  8571. [self request_interface:URL_RETRIEVE_PASS parameters:params err_record_url:nil completionHandler:result retry:0];
  8572. #endif
  8573. //
  8574. //
  8575. // if(![self IsNetworkAvailable])
  8576. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8577. //
  8578. // NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  8579. // if(json==nil)
  8580. // return nil;
  8581. // NSError *error=nil;
  8582. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8583. // return jsobj;
  8584. }
  8585. +(void)request_update_ordercustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info completionHandler:(resultHandler)result
  8586. {
  8587. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8588. AppDelegate *appDelegate = nil;
  8589. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8590. if(appDelegate.user!=nil)
  8591. [info setValue:appDelegate.user forKey:@"user"];
  8592. // if(appDelegate.contact_id!=nil)
  8593. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8594. if(appDelegate.password!=nil)
  8595. [info setValue:appDelegate.password forKey:@"password"];
  8596. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8597. [info setValue:order_code forKey:@"orderCode"];
  8598. // [params setValue:sourceid forKey:@"sourceid"];
  8599. // [params setValue:editor forKey:@"editor"];
  8600. if(appDelegate.offline_mode)
  8601. {
  8602. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8603. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8604. dispatch_async(dispatch_get_main_queue(), ^{
  8605. result(json);
  8606. });
  8607. });
  8608. return;
  8609. }
  8610. [self request_interface:URL_UPDATE_ORDERCUSTOMER parameters:info err_record_url:nil completionHandler:result retry:0];
  8611. // if(appDelegate.offline_mode)
  8612. // {
  8613. // return [OLDataProvider offline_notimpl];
  8614. // }
  8615. // if(![self IsNetworkAvailable])
  8616. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8617. //
  8618. // NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  8619. // if(json!=nil)
  8620. // {
  8621. // NSError *error=nil;
  8622. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8623. // return jsobj;
  8624. // }
  8625. // else
  8626. // return nil;
  8627. }
  8628. +(void)request_update_customer_img: (NSString*) contactid img_url:(NSString*) url completionHandler:(resultHandler)result
  8629. {
  8630. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8631. AppDelegate *appDelegate = nil;
  8632. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8633. if(appDelegate.user!=nil)
  8634. [params setValue:appDelegate.user forKey:@"user"];
  8635. // if(appDelegate.contact_id!=nil)
  8636. if(appDelegate.password!=nil)
  8637. [params setValue:appDelegate.password forKey:@"password"];
  8638. [params setValue:contactid forKey:@"contactId"];
  8639. [params setValue:url forKey:@"business_card"];
  8640. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  8641. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8642. if(appDelegate.offline_mode)
  8643. {
  8644. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8645. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8646. dispatch_async(dispatch_get_main_queue(), ^{
  8647. result(json);
  8648. });
  8649. });
  8650. return;
  8651. }
  8652. [self request_interface:URL_UPDATE_CUSTOMER_BCARD parameters:params err_record_url:nil completionHandler:result retry:0];
  8653. // if(appDelegate.offline_mode)
  8654. // {
  8655. // return [OLDataProvider offline_notimpl];
  8656. // }
  8657. // if(![self IsNetworkAvailable])
  8658. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8659. //
  8660. // NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  8661. // if(json==nil)
  8662. // return nil;
  8663. // NSError *error=nil;
  8664. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8665. // return jsobj;
  8666. }
  8667. +(void)request_commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url completionHandler:(resultHandler)result
  8668. {
  8669. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8670. AppDelegate *appDelegate = nil;
  8671. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8672. if(appDelegate.user!=nil)
  8673. [params setValue:appDelegate.user forKey:@"user"];
  8674. if(appDelegate.contact_id!=nil)
  8675. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8676. if(appDelegate.password!=nil)
  8677. [params setValue:appDelegate.password forKey:@"password"];
  8678. // if(appDelegate.order_code!=nil)
  8679. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8680. // NSDictionary* customerinfo= appDelegate.customerInfo;
  8681. //
  8682. // NSArray* keys=[customerinfo allKeys];
  8683. // for(int i=0;i<keys.count;i++)
  8684. // {
  8685. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8686. // }
  8687. //
  8688. // [params setValue:sourceid forKey:@"sourceid"];
  8689. // [params setValue:editor forKey:@"editor"];
  8690. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  8691. if(appDelegate.offline_mode)
  8692. {
  8693. params[@"offline_Command"]=url;
  8694. [OLDataProvider offline_commoneditor_partialrefresh:params completionHandler:result];
  8695. //
  8696. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8697. // NSMutableDictionary* json = [[OLDataProvider offline_commoneditor_partialrefresh:params] mutableCopy];
  8698. // dispatch_async(dispatch_get_main_queue(), ^{
  8699. // result(json);
  8700. // });
  8701. // });
  8702. return;
  8703. }
  8704. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  8705. //
  8706. // if(appDelegate.offline_mode)
  8707. // {
  8708. // params[@"offline_Command"]=url;
  8709. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  8710. // }
  8711. //
  8712. // if(![self IsNetworkAvailable])
  8713. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8714. //
  8715. // NSData* json=[self get_json:url parameters:params];
  8716. // if(json!=nil)
  8717. // {
  8718. // NSError *error=nil;
  8719. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8720. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8721. // [appDelegate SetSo:nil];
  8722. //
  8723. //
  8724. // return jsobj;
  8725. // }
  8726. // else
  8727. // return nil;
  8728. }
  8729. +(void)request_add_address:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8730. {
  8731. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8732. AppDelegate *appDelegate = nil;
  8733. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8734. if(appDelegate.user!=nil)
  8735. [params setValue:appDelegate.user forKey:@"user"];
  8736. if(appDelegate.contact_id!=nil)
  8737. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8738. if(appDelegate.password!=nil)
  8739. [params setValue:appDelegate.password forKey:@"password"];
  8740. // [params setValue:sourceid forKey:@"sourceid"];
  8741. // [params setValue:editor forKey:@"editor"];
  8742. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  8743. if(appDelegate.offline_mode)
  8744. {
  8745. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8746. NSData* json = [[OLDataProvider offline_saveaddr:params] mutableCopy];
  8747. dispatch_async(dispatch_get_main_queue(), ^{
  8748. result([[RAConvertor data2dict:json] mutableCopy]);
  8749. });
  8750. });
  8751. return;
  8752. }
  8753. [self request_interface:URL_ADDRESS_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  8754. //
  8755. // NSData* json=nil;
  8756. //
  8757. // if(appDelegate.offline_mode)
  8758. // {
  8759. // json= [OLDataProvider offline_saveaddr:params];
  8760. // }
  8761. // else
  8762. // {
  8763. // if(![self IsNetworkAvailable])
  8764. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8765. //
  8766. // json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  8767. // }
  8768. // if(json!=nil)
  8769. // {
  8770. // NSError *error=nil;
  8771. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8772. // return jsobj;
  8773. // }
  8774. // else
  8775. // return nil;
  8776. }
  8777. +(void)request_commit_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8778. {
  8779. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8780. AppDelegate *appDelegate = nil;
  8781. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8782. if(appDelegate.user!=nil)
  8783. [params setValue:appDelegate.user forKey:@"user"];
  8784. if(appDelegate.contact_id!=nil)
  8785. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8786. if(appDelegate.password!=nil)
  8787. [params setValue:appDelegate.password forKey:@"password"];
  8788. if(appDelegate.order_code!=nil)
  8789. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8790. // NSDictionary* customerinfo= appDelegate.customerInfo;
  8791. //
  8792. // NSArray* keys=[customerinfo allKeys];
  8793. // for(int i=0;i<keys.count;i++)
  8794. // {
  8795. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8796. // }
  8797. //
  8798. // [params setValue:sourceid forKey:@"sourceid"];
  8799. // [params setValue:editor forKey:@"editor"];
  8800. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  8801. if(appDelegate.offline_mode)
  8802. {
  8803. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8804. NSData* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  8805. dispatch_async(dispatch_get_main_queue(), ^{
  8806. result([[RAConvertor data2dict:json] mutableCopy]);
  8807. });
  8808. });
  8809. return;
  8810. }
  8811. [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8812. //
  8813. // NSData* json=nil;
  8814. // if(appDelegate.offline_mode)
  8815. // {
  8816. // json=[OLDataProvider offline_submitorder:params];
  8817. // }
  8818. // else
  8819. // {
  8820. // if(![self IsNetworkAvailable])
  8821. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8822. //
  8823. // json=[self get_json:URL_COMMIT_ORDER parameters:params];
  8824. // }
  8825. // if(json!=nil)
  8826. // {
  8827. // NSError *error=nil;
  8828. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8829. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8830. // [appDelegate SetSo:nil];
  8831. //
  8832. //
  8833. // return jsobj;
  8834. // }
  8835. // else
  8836. // return nil;
  8837. }
  8838. +(void) request_new_offline_ticket:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid completionHandler:(resultHandler)result
  8839. {
  8840. // if(![self IsNetworkAvailable])
  8841. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8842. //
  8843. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8844. AppDelegate *appDelegate = nil;
  8845. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8846. if(appDelegate.user!=nil)
  8847. [params setValue:appDelegate.user forKey:@"user"];
  8848. // if(appDelegate.contact_id!=nil)
  8849. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8850. if(appDelegate.password!=nil)
  8851. [params setValue:appDelegate.password forKey:@"password"];
  8852. [params setValue:ver forKey:@"ver"];
  8853. [params setValue:vid forKey:@"vid"];
  8854. if(buseinternaladdress)
  8855. [params setValue:@"true" forKey:@"internal_address"];
  8856. else
  8857. [params setValue:@"false" forKey:@"internal_address"];
  8858. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  8859. // 无论当前是离线还是在线状态,都可以进行同步;
  8860. // if(appDelegate.offline_mode)
  8861. // {
  8862. //
  8863. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8864. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8865. // dispatch_async(dispatch_get_main_queue(), ^{
  8866. // result(json);
  8867. // });
  8868. // });
  8869. //
  8870. // return;
  8871. //
  8872. // }
  8873. [self request_interface:URL_CHECK_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  8874. //
  8875. // NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  8876. // if(json==nil)
  8877. // return nil;
  8878. // NSError *error=nil;
  8879. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8880. // // int result = [[jsobj valueForKey:@"result"] intValue];
  8881. // //
  8882. // // if (result==2)
  8883. // // {
  8884. // //
  8885. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8886. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  8887. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8888. // ////
  8889. // //// [appDelegate update_count_mark];
  8890. // // }
  8891. // return jsobj;
  8892. }
  8893. +(void) request_complete_offline_ticket:(NSString* )vid completionHandler:(resultHandler)result
  8894. {
  8895. // AppDelegate *appDelegate = nil;
  8896. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8897. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8898. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  8899. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8900. // if(appDelegate.user!=nil)
  8901. // [params setValue:appDelegate.user forKey:@"user"];
  8902. // // if(appDelegate.contact_id!=nil)
  8903. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8904. // if(appDelegate.password!=nil)
  8905. // [params setValue:appDelegate.password forKey:@"password"];
  8906. [params setValue:vid forKey:@"downSerial"];
  8907. // 无论当前是离线还是在线状态,都可以进行同步;
  8908. // if(appDelegate.offline_mode)
  8909. // {
  8910. //
  8911. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8912. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8913. // dispatch_async(dispatch_get_main_queue(), ^{
  8914. // result(json);
  8915. // });
  8916. // });
  8917. //
  8918. // return;
  8919. //
  8920. // }
  8921. [self request_interface:URL_FINISH_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  8922. // NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  8923. // if(json==nil)
  8924. // return nil;
  8925. // NSError *error=nil;
  8926. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8927. // // int result = [[jsobj valueForKey:@"result"] intValue];
  8928. // //
  8929. // // if (result==2)
  8930. // // {
  8931. // //
  8932. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8933. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  8934. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8935. // ////
  8936. // //// [appDelegate update_count_mark];
  8937. // // }
  8938. // return jsobj;
  8939. }
  8940. +(void) request_download_offline:(NSString* )vid completionHandler:(resultHandler)result
  8941. {
  8942. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8943. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  8944. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8945. // if(appDelegate.user!=nil)
  8946. // [params setValue:appDelegate.user forKey:@"user"];
  8947. // // if(appDelegate.contact_id!=nil)
  8948. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8949. // if(appDelegate.password!=nil)
  8950. // [params setValue:appDelegate.password forKey:@"password"];
  8951. [params setValue:vid forKey:@"downSerial"];
  8952. // AppDelegate *appDelegate = nil;
  8953. //
  8954. //
  8955. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8956. // if(appDelegate.offline_mode)
  8957. // {
  8958. //
  8959. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8960. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8961. // dispatch_async(dispatch_get_main_queue(), ^{
  8962. // result(json);
  8963. // });
  8964. // });
  8965. //
  8966. // return;
  8967. //
  8968. // }
  8969. __block bool bbreak = false;
  8970. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8971. __block NSMutableDictionary* download_json=nil;
  8972. int count=0;
  8973. // __block bool preparing = true;
  8974. while ([[download_json valueForKey:@"result"] intValue]!=2&&count<REQUEST_DOWNLOAD_RETRY_TIMES) //超过60分钟还没准被好数据就视为服务器出错。
  8975. {
  8976. if(bbreak)
  8977. break;
  8978. dispatch_async(dispatch_get_main_queue(), ^{
  8979. [self request_interface:URL_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8980. if([resulti[@"result"] intValue]==RESULT_TRUE)
  8981. {
  8982. if(!bbreak) //此判断保证result只调用一次。
  8983. {
  8984. // appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8985. // [appDelegate update_count_mark];
  8986. resulti[@"request_count"]=[NSNumber numberWithInt:count];
  8987. result(resulti);
  8988. }
  8989. bbreak=true;
  8990. }
  8991. else if([resulti[@"result"] intValue]==RESULT_ERROR)
  8992. {
  8993. result(resulti);
  8994. bbreak=true;
  8995. }
  8996. } retry:3];
  8997. });
  8998. sleep(RETRY_DELAY);
  8999. count++;
  9000. // download_json=[[RANetwork download_Offline:downSerial] mutableCopy];
  9001. //
  9002. // [RANetwork request_download_offline:downSerial completionHandler:^(NSMutableDictionary *result) {
  9003. // download_json=result;
  9004. // }];
  9005. //
  9006. }
  9007. // for(int i=0;i<150;i++)
  9008. // {
  9009. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  9010. // // result_params[@"resultSerial"]=uuid;
  9011. //
  9012. //
  9013. //
  9014. // sleep(2);
  9015. //
  9016. // // json=[self get_json:URL_CART parameters:params];
  9017. // // if(json!=nil)
  9018. // // {
  9019. // //
  9020. // // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9021. // // if([jsobj[@"result"] intValue]==2)
  9022. // // {
  9023. // // break;
  9024. // // }
  9025. // // }
  9026. //
  9027. // }
  9028. });
  9029. //
  9030. // NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  9031. // if(json==nil)
  9032. // return nil;
  9033. // NSError *error=nil;
  9034. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9035. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9036. // //
  9037. // // if (result==2)
  9038. // // {
  9039. // //
  9040. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9041. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9042. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9043. // ////
  9044. // //// [appDelegate update_count_mark];
  9045. // // }
  9046. // return jsobj;
  9047. }
  9048. + (void)request_fastupload:(NSMutableDictionary *)params filename:(NSString*)filename data:(NSData*) data url:(NSString *)url completionHandler:(resultHandler)result
  9049. {
  9050. //#ifdef test_server
  9051. // url=URL_REQUEST_RECORDS;
  9052. // params[@"prefix"]=URL_REQUEST_RECORDS;
  9053. //#endif
  9054. // [self request_file_fast:url parameters:params completionHandler:result];
  9055. #ifdef SCANNER_ORDER
  9056. params[@"site_name"]=[RADataProvider getSiteName];
  9057. #endif
  9058. [self request_upload_fast:data FileName:filename server:url parameters:params completionHandler:result];
  9059. }
  9060. +(void)request_err_log:(NSString*) up_params result:(NSString*)result_str module:(NSString*) module code:(int) code completionHandler:(resultHandler)result
  9061. {
  9062. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9063. AppDelegate *appDelegate = nil;
  9064. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9065. if(appDelegate.user!=nil)
  9066. [params setValue:appDelegate.user forKey:@"user"];
  9067. [params setValue:up_params forKey:@"upparam"];
  9068. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  9069. [params setValue:result_str forKey:@"result"];
  9070. [params setValue:module forKey:@"interfac"];
  9071. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  9072. // [params setValue:module forKey:@"module"];
  9073. // [[UIDevice currentDevice] name];
  9074. // if(appDelegate.offline_mode)
  9075. // {
  9076. // return [OLDataProvider offline_notimpl];
  9077. // }
  9078. if(appDelegate.offline_mode)
  9079. {
  9080. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9081. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9082. dispatch_async(dispatch_get_main_queue(), ^{
  9083. result(json);
  9084. });
  9085. });
  9086. return;
  9087. }
  9088. [self request_interface:URL_ERR_LOG parameters:params err_record_url:nil completionHandler:result retry:0];
  9089. //
  9090. // if(![self IsNetworkAvailable])
  9091. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9092. //
  9093. // NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  9094. // if(json==nil)
  9095. // return nil;
  9096. // NSError *error=nil;
  9097. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9098. // return jsobj;
  9099. }
  9100. @end