RANetwork.m 412 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326
  1. //
  2. // iSalesNetwork.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-6-20.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RANetwork.h"
  9. #import "RAUtils.h"
  10. #import "RASingleton.h"
  11. #import "GoogleAnalyst.h"
  12. #import "ERPUtils.h"
  13. #import "RAConvertor.h"
  14. #import "ActiveViewController.h"
  15. #import "ZipArchive.h"
  16. #import "RADataProvider.h"
  17. NSString *const kScreenName = @"kScreenName";
  18. NSString *const kAction = @"kAction";
  19. NSString *const kExtra = @"kExtra";
  20. NSString *const ScreenCodeLoginView = @"Login Screen";
  21. NSString *const ScreenCodeHomeView = @"Home Screen";
  22. NSString *const ScreenCodeCategory = @"Category Screen";
  23. NSString *const ScreenCodeCart = @"Cart Sceen";
  24. NSString *const ScreenCodeOrderList = @"Order History Screen";
  25. NSString *const ScreenCodeSearch = @"Search Screen";
  26. NSString *const ScreenCodeAccount = @"Account Screen";
  27. NSString *const ScreenCodeWishList = @"Wish List Screen";
  28. NSString *const ScreenCodePortfolio = @"Portfolio Screen";
  29. NSString *const ScreenCodeViewPortfolios = @"View Portfolios Screen";
  30. NSString *const ScreenCodeCamScan = @"Cam Scan Screen";
  31. NSString *const ScreenCodeScannerSetting = @"Scanner Setting Screen";
  32. NSString *const ScreenCodeOfflineSetting = @"Offline Setting Screen";
  33. NSString *const ScreenCodePlaceOrder = @"Place Order Screen";
  34. NSString *const ScreenCodeCustomerInfo = @"Customer Information Screen";
  35. NSString *const ScreenCodeNewCustomer = @"New Customer Screen";
  36. NSString *const ScreenCodeEditCustomer = @"Edit Customer Information Screen";
  37. NSString *const ScreenCodeModelInfo = @"Model Information Screen";
  38. NSString *const ScreenCodeOrderInfo = @"Order Information Screeen";
  39. NSString *const ScreenCodeUserSign = @"User Sign Screen";
  40. NSString *const ScreenCodeNewAddress = @"New Address Screen";
  41. NSString *const ScreenCodeAdvanceSearch = @"Account Advance Search Screen";
  42. NSString *const ScreenCodeCreatePortfolio = @"Create Portfolio Screen";
  43. NSString *const ScreenCodeParticularCategory = @"Particular Category Screen";
  44. NSString *const ScreenCodeEditPortfolio = @"Edit Portfolio Screen";
  45. NSString *const ScreenCodePriceSetting = @"Price Setting Screen";
  46. NSString *const ScreenCodeCategoryPrice = @"Category Price Screen";
  47. NSString *const ScreenCodeSetCatetoryPrice = @"Set Category Price Screen";
  48. NSString *const ScreenCodeUploadImage = @"Upload Image Screen";
  49. NSString *const ScreenCodeOfflineSync = @"Offline Sync Screen";
  50. @implementation RANetwork
  51. +(NSMutableDictionary*) prepare_additional_params:(NSMutableDictionary* ) params
  52. {
  53. AppDelegate *appDelegate = nil;
  54. //some UI methods ej
  55. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  56. // if(appDelegate.user!=nil)
  57. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.user key:@"usai"] forKey:@"user"];
  58. // if(appDelegate.password!=nil)
  59. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.password key:@"usai"] forKey:@"password"];
  60. //
  61. //
  62. //
  63. // if(appDelegate.user!=nil)
  64. // [params setValue:appDelegate.user forKey:@"user"];
  65. //
  66. // if(appDelegate.contact_id!=nil)
  67. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  68. // if(appDelegate.password!=nil)
  69. // [params setValue:appDelegate.password forKey:@"password"];
  70. //
  71. // [params setValue:appDelegate.build forKey:@"app_ver"];
  72. //
  73. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  74. // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  75. // [params setValue:short_version forKey:@"app_short_ver"];
  76. //
  77. //
  78. //
  79. //#if TARGET_IPHONE_SIMULATOR//模拟器
  80. // [params setValue:@"simulator_uuid" forKey:@"deviceid"];
  81. //#elif TARGET_OS_IPHONE//真机
  82. // UIDevice * dev = [UIDevice currentDevice];
  83. // NSUUID* uuid =dev.identifierForVendor;
  84. // [params setValue:uuid.UUIDString forKey:@"deviceid"];
  85. //#endif
  86. if(appDelegate.user!=nil && params[@"user"]==nil)
  87. [params setValue:appDelegate.user forKey:@"user"];
  88. if(appDelegate.password!=nil&& params[@"password"]==nil)
  89. [params setValue:appDelegate.password forKey:@"password"];
  90. if(appDelegate.ipad_perm!=nil)
  91. [params setValue:appDelegate.ipad_perm forKey:@"ipad_perm"];
  92. [params setValue:appDelegate.build forKey:@"app_ver"];
  93. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  94. NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  95. [params setValue:short_version forKey:@"app_short_ver"];
  96. #if TARGET_IPHONE_SIMULATOR//模拟器
  97. [params setValue:@"simulator_uuid" forKey:@"idfv"];
  98. #elif TARGET_OS_IPHONE//真机
  99. UIDevice * dev = [UIDevice currentDevice];
  100. NSUUID* uuid =dev.identifierForVendor;
  101. [params setValue:uuid.UUIDString forKey:@"idfv"];
  102. #endif
  103. //
  104. // NSString *userAction = [params valueForKey:kAction];
  105. // NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  106. // if ([userAction isEqualToString:@"Login"]) {
  107. // if (!extra) {
  108. // extra = [NSMutableDictionary dictionary];
  109. // }
  110. // [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  111. // }
  112. return params;
  113. }
  114. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString *) file //delegate:(id < NSURLConnectionDelegate >)delegate
  115. {
  116. // NSString* e=[AESCrypt AES128Encrypt:@"密码学中的高级加密标准(Advanced Encryption Standard,AES),又称 高级加密标准Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用。经过五年的甄选流程,高级加密标准由美国国家标准与技术研究院 (NIST)于2001年11月26日发布于FIPS PUB 197,并在2002年5月26日成为有效的标准。2006年,高级加密标准已然成为对称密钥加密中最流行的算法之一。 " key:@"usai2010"];
  117. // DebugLog(e);
  118. // NSString* d=[AESCrypt decrypt:@"VzB4+lENfbzWX7ggHh2Os1P69l5YBzKmM51yqA37AfoKgPY8bJgdK8M4WvF+wDyOsLWP\/o8H5+bHMivQp1u8wM2QV7SYzgzPwV85QKtYWIzEgLe9T0HO69EdutWz7k1rdAT\/mftsRin0Hy5SHk7txTZT\/zPH5X+FQiExCTFm5Zus39HYvp+VxCX4+kYeymn8B63AUd3mRQyscUvDjfgU2olKR\/TP8PV3g+VQMZxpKfol3P1iOtz3XQlHZV0pM6SAf+SwT0sPfrdn6CZFfNQlrKA9QjMrnBdMeSCquSIWXnmLv6okzvnlJnT0SjvJuUeqNdBC5EZ0ACnhI0MrXVZEsq1EuM9al7oPzvU5EZbjZpmx+fSFIkMzTT8bYClTnG1bsL1MCcU4pSODDorUj8zalA==" password:@"usai2010"];
  119. params = [self prepare_additional_params:params];
  120. DebugLog(@"\n++++++++++++++++++++++Request++++++++++++++++++++++\n%@\n++++++++++++++++++++++Params++++++++++++++++++++++\n%@\n",url,[RAConvertor dict2string:params]);
  121. return [super get_json:url parameters:params file:(NSString*)file err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  122. int result=[[jsobj valueForKey:@"result"] intValue];
  123. // UIApplication * app = [UIApplication sharedApplication];
  124. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  125. switch (result) {
  126. case 0:
  127. [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  128. break;
  129. case 1:
  130. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  131. break;
  132. case 2:
  133. [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  134. break;
  135. case 8:
  136. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  137. break;
  138. case 9:
  139. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  140. break;
  141. case 99:
  142. [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  143. break;
  144. default:
  145. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  146. break;
  147. }
  148. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  149. // {
  150. // [jsobj setValue:@"9" forKey:@"result"];
  151. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  152. // }
  153. return jsobj;
  154. } decrypt_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  155. return nil;
  156. // NSString* base64str = jsobj[@"str"];
  157. // NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"usai2010"];
  158. // jsobj=[[RAUtils string2dict:decryptstr] mutableCopy];
  159. // return jsobj;
  160. }];
  161. /*
  162. */
  163. return nil;
  164. }
  165. +(void) LoadImage:(NSString*) url into:(UIImageView*) container
  166. {
  167. DebugLog(@"LoadImage:(NSString*) url in:(UIImageView*) container");
  168. NSString* file_name=[url lastPathComponent];
  169. NSData* img_data = [iSalesDB load_cached_img:file_name loadFrom:url];
  170. if(img_data==nil)
  171. {
  172. DebugLog(@"IMG NOT CACHED %@",file_name);
  173. img_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
  174. [iSalesDB cache_img:img_data filename:file_name saveTo:url];
  175. //load from internet;
  176. }
  177. if(img_data!=nil)
  178. {
  179. UIImage * img =[UIImage imageWithData:img_data];
  180. if(img==nil)
  181. DebugLog(@"UIIMAGE IS NIL! %@",file_name);
  182. else
  183. dispatch_async(dispatch_get_main_queue(), ^{
  184. container.image =img;
  185. });
  186. }
  187. else
  188. {
  189. DebugLog(@"IMG DOWNLOAD FAILED! %@",file_name);
  190. }
  191. }
  192. //+(NSData*)fake_json:(NSString*) url
  193. //{
  194. // NSString* jsonfile = nil;
  195. // if([url isEqualToString:URL_UPDATE_AUTH])
  196. // {
  197. // jsonfile=@"login";
  198. //
  199. // }
  200. // else if([url isEqualToString:URL_REQUEST_CATMENU])
  201. // {
  202. // jsonfile=@"categorymenu";
  203. // }
  204. // else if([url isEqualToString:URL_LOAD_HOME])
  205. // {
  206. // jsonfile=@"homepage";
  207. // }
  208. // else if([url isEqualToString:URL_SEARCH])
  209. // {
  210. // jsonfile=@"search";
  211. // }
  212. // else if([url isEqualToString:URL_CATEGORY_LOADMORE])
  213. // {
  214. // jsonfile=@"category_more";
  215. // }else if([url isEqualToString:URL_ITEM_DETAIL])
  216. // {
  217. // jsonfile=@"detail";
  218. // }else if([url isEqualToString:URL_CART])
  219. // {
  220. // jsonfile=@"cart";
  221. // }else if([url isEqualToString:URL_ORDER_LIST])
  222. // {
  223. // jsonfile=@"orderlist";
  224. // }
  225. //// else if([url isEqualToString:URL_ORDER_INFO])
  226. //// {
  227. //// jsonfile=@"orderinfo";
  228. //// }
  229. //// else if([url isEqualToString:URL_ORDER_INFO])
  230. //// {
  231. //// jsonfile=@"orderinfo2label";
  232. //// }
  233. //
  234. //
  235. //
  236. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:jsonfile ofType:@"json" ]];
  237. // NSMutableString *result = [[NSMutableString alloc] initWithData:json encoding:NSUTF8StringEncoding];
  238. //
  239. // DebugLog(@"result: \n%@",result);
  240. // return json;
  241. //}
  242. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
  243. {
  244. NSString *screenName = [params valueForKey:kScreenName];
  245. NSString *userAction = [params valueForKey:kAction];
  246. NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  247. if ([userAction isEqualToString:@"Login"]) {
  248. if (!extra) {
  249. extra = [NSMutableDictionary dictionary];
  250. }
  251. [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  252. }
  253. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  254. [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  255. #endif
  256. return [self get_json:url parameters:params file:nil];
  257. // {
  258. // int retry = 0;
  259. //
  260. // __block AppDelegate *appDelegate = nil;
  261. //
  262. // dispatch_sync(dispatch_get_main_queue(), ^{
  263. // //some UI methods ej
  264. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  265. // });
  266. // if(appDelegate.user!=nil)
  267. // [params setValue:appDelegate.user forKey:@"user"];
  268. // if(appDelegate.password!=nil)
  269. // [params setValue:appDelegate.password forKey:@"password"];
  270. //
  271. //
  272. // if(appDelegate.ipad_perm!=nil)
  273. // [params setValue:appDelegate.ipad_perm forKey:@"ipad_perm"];
  274. //
  275. // [params setValue:appDelegate.build forKey:@"app_ver"];
  276. //
  277. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  278. // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  279. // [params setValue:short_version forKey:@"app_short_ver"];
  280. //
  281. // UIDevice * dev = [UIDevice currentDevice];
  282. // NSUUID* uuid =dev.identifierForVendor;
  283. //#if TARGET_IPHONE_SIMULATOR//模拟器
  284. // [params setValue:@"simulator_uuid" forKey:@"idfv"];
  285. //#elif TARGET_OS_IPHONE//真机
  286. // [params setValue:uuid.UUIDString forKey:@"idfv"];
  287. //#endif
  288. //
  289. //// NSString *screenName = [params valueForKey:kScreenName];
  290. //// NSString *userAction = [params valueForKey:kAction];
  291. //// NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  292. //// if ([userAction isEqualToString:@"Login"]) {
  293. //// if (!extra) {
  294. //// extra = [NSMutableDictionary dictionary];
  295. //// }
  296. //// [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  297. //// }
  298. //
  299. //repeat:
  300. // {
  301. //
  302. // // return [self fake_json:url];
  303. //
  304. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  305. // //分界线的标识符
  306. // NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
  307. // //根据url初始化request
  308. // NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
  309. // cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
  310. // timeoutInterval:JSON_TIMEOUT];
  311. // //分界线 --AaB03x
  312. // NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
  313. // //结束符 AaB03x--
  314. // NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
  315. // //要上传的图片
  316. // // UIImage *image=[params objectForKey:@"pic"];
  317. // //得到图片的data
  318. // // NSData* data = UIImagePNGRepresentation(image);
  319. // //http body的字符串
  320. // NSMutableString *body=[[NSMutableString alloc]init];
  321. //
  322. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  323. // // [params setValue:@"handset_login" forKey:@"action"];
  324. // // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  325. //
  326. // // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  327. // // [params setValue:password forKey:@"password"];
  328. // // [params setValue:[NSString stringWithFormat:@"%d",ver] forKey:@"auth_ver"];
  329. //
  330. //
  331. //
  332. // // [headers setValue:headQuerlString forKey:@"param"];
  333. //
  334. // //参数的集合的所有key的集合
  335. // NSArray *keys= [params allKeys];
  336. // DebugLog(@"================parms==================");
  337. // //遍历keys
  338. // for(int i=0;i<[keys count];i++)
  339. // {
  340. // //得到当前key
  341. // NSString *key=[keys objectAtIndex:i];
  342. // //如果key不是pic,说明value是字符类型,比如name:Boris
  343. // if(![key isEqualToString:@"pic"])
  344. // {
  345. // //添加分界线,换行
  346. // [body appendFormat:@"%@\r\n",MPboundary];
  347. // //添加字段名称,换2行
  348. // [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
  349. // //添加字段的值
  350. // [body appendFormat:@"%@\r\n",[params objectForKey:key]];
  351. // DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
  352. // }
  353. // }
  354. // DebugLog(@"================parms==================");
  355. // ////添加分界线,换行
  356. // [body appendFormat:@"%@\r\n",MPboundary];
  357. // //声明pic字段,文件名为boris.png
  358. // [body appendFormat:@"Content-Disposition: form-data; name=\"pic\"; filename=\"boris.png\"\r\n"];
  359. // //声明上传文件的格式
  360. // [body appendFormat:@"Content-Type: image/png\r\n\r\n"];
  361. //
  362. // //声明结束符:--AaB03x--
  363. // NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
  364. // //声明myRequestData,用来放入http body
  365. // NSMutableData *myRequestData=[NSMutableData data];
  366. // //将body字符串转化为UTF8格式的二进制
  367. // [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
  368. // //将image的data加入
  369. // // [myRequestData appendData:data];
  370. // //加入结束符--AaB03x--
  371. // [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
  372. //
  373. // //设置HTTPHeader中Content-Type的值
  374. // NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
  375. // //设置HTTPHeader
  376. // [request setValue:content forHTTPHeaderField:@"Content-Type"];
  377. //
  378. // // 关闭keep alive
  379. // [request setValue:@"close" forHTTPHeaderField:@"Connection"];
  380. // //设置Content-Length
  381. // [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[myRequestData length]] forHTTPHeaderField:@"Content-Length"];
  382. // //设置http body
  383. // [request setHTTPBody:myRequestData];
  384. // //http method
  385. // [request setHTTPMethod:@"POST"];
  386. //
  387. //
  388. // NSHTTPURLResponse* urlResponse = nil;
  389. //
  390. // NSError *error = nil;
  391. //
  392. // NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  393. //
  394. //
  395. // DebugLog(@"url: %@",url);
  396. //
  397. // DebugLog(@"response: %@",[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode]);
  398. //
  399. // if (responseData==nil) {
  400. //
  401. //// DebugLog(@"response error:%@", [error localizedDescription]);
  402. //
  403. //
  404. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  405. // //#define RESULT_FALSE 0
  406. // //#define RESULT_TRUE 2
  407. // //#define RESULT_NET_ERROR -3
  408. // //#define RESULT_NET_NOTAVAILABLE -4
  409. // //#define RESULT_ERROR -5
  410. // //#define RESULT_LOCALFILE_ERROR -7
  411. // //#define RESULT_USERAUTH_ERROR -9
  412. // //#define RESULT_UPDATE_USERAUTH_ERROR -11
  413. // //#define RESULT_SESSION_EXPIRED -13
  414. // //#define RESULT_VER_LOW
  415. //
  416. // // NSString * moreinfo = error.description ;
  417. //
  418. // NSString* err_msg = [error localizedDescription];
  419. //
  420. //
  421. // //-----------------retry 3 times for error code -1005------------------------
  422. // if(error.code==-1005&&retry<3)
  423. // {
  424. // retry++;
  425. // goto repeat;
  426. //
  427. // }
  428. // //-----------------end retry 3 times for error code -1005------------------------
  429. //
  430. // NSDictionary* error_json = [RAUtils error_dict:error];
  431. // [ret setObject:error_json forKey:@"err_obj"];
  432. // NSString* resp_msg= nil;
  433. //
  434. // if(err_msg.length==0)
  435. // {
  436. // err_msg =[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode];
  437. // resp_msg = err_msg;
  438. // }
  439. // [ret setValue:[NSString stringWithFormat:@"%d",RESULT_NET_ERROR] forKey:@"result"];
  440. // [ret setValue:err_msg forKey:@"err_msg"];
  441. // [ret setValue:resp_msg forKey:@"resp_msg"];
  442. // [ret setValue:[NSString stringWithFormat:@"%ld",(long)urlResponse.statusCode] forKey:@"resp_code"];
  443. //
  444. //
  445. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ret
  446. // options:0
  447. // error:nil];
  448. // if(![url isEqualToString:URL_ERR_LOG])
  449. // {
  450. // [RANetwork err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:[RAConvertor dict2string:ret]] module:url code:RESULT_NET_ERROR];
  451. // }
  452. //#if defined(BUILD_NPD)// || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  453. // [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  454. //#endif
  455. // return jsonData;
  456. //
  457. // }
  458. // else
  459. // {
  460. // NSString* err_msg = [error localizedDescription];
  461. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  462. //
  463. // DebugLog(@"data string: %@",str);
  464. // NSError *error1 = nil;
  465. //
  466. // NSMutableDictionary* jsobj = [[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error1] mutableCopy];
  467. //
  468. // if(jsobj==nil)// 服务器返回不是json
  469. // {
  470. //
  471. // jsobj=[[NSMutableDictionary alloc] init];
  472. // [jsobj setValue:@"1" forKey:@"result"];
  473. //
  474. // }
  475. //
  476. // int result=[[jsobj valueForKey:@"result"] intValue];
  477. // UIApplication * app = [UIApplication sharedApplication];
  478. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  479. // NSString* mode =[jsobj valueForKey:@"mode"];
  480. // [appDelegate SetMode:mode];
  481. // switch (result) {
  482. // case 0:
  483. // [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  484. // break;
  485. // case 1:
  486. // [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  487. // break;
  488. // case 2:
  489. // [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  490. // break;
  491. // case 8:
  492. // [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  493. // break;
  494. // case 9:
  495. // [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  496. // break;
  497. // case 99:
  498. // [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  499. // break;
  500. // default:
  501. // [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  502. // break;
  503. // }
  504. //
  505. //
  506. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  507. // {
  508. // [jsobj setValue:@"9" forKey:@"result"];
  509. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  510. // }
  511. //
  512. // if(![url isEqualToString:URL_ERR_LOG]&&![url isEqualToString:URL_DOWNLOAD_OFFLINE]/*&&result!=-3*/&&result!=2&&result!=99)
  513. // {
  514. // [RANetwork err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:str] module:url code:result];
  515. // }
  516. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsobj
  517. // options:0
  518. // error:nil];
  519. //#if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  520. // [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  521. //#endif
  522. // return jsonData;
  523. //
  524. // }
  525. //
  526. // return responseData;
  527. // }
  528. //}
  529. }
  530. //+(NSDictionary*)request_Editor:(NSString*) sourceid editor:(NSString*)editor
  531. //{
  532. //
  533. //}
  534. +(NSDictionary*) delete_portfoliolist:(NSString* ) listid
  535. {
  536. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  537. __block AppDelegate *appDelegate = nil;
  538. dispatch_sync(dispatch_get_main_queue(), ^{
  539. //some UI methods ej
  540. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  541. });
  542. if(appDelegate.user!=nil)
  543. [params setValue:appDelegate.user forKey:@"user"];
  544. if(appDelegate.contact_id!=nil)
  545. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  546. if(appDelegate.password!=nil)
  547. [params setValue:appDelegate.password forKey:@"password"];
  548. [params setValue:listid forKey:@"tearsheetsId"];
  549. // [params setValue:editor forKey:@"editor"];
  550. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  551. // [params setValue:@"Delete Portfolio" forKey:kAction];
  552. NSData* json = nil;
  553. if(appDelegate.offline_mode)
  554. {
  555. json = [OLDataProvider offline_removePDF:params];
  556. } else {
  557. if(![self IsNetworkAvailable])
  558. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  559. json=[self get_json:URL_PORTFOLIOLIST_REMOVE parameters:params];
  560. }
  561. if(json!=nil)
  562. {
  563. NSError *error=nil;
  564. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  565. return jsobj;
  566. }
  567. else
  568. return nil;
  569. }
  570. +(NSDictionary*) portfolio_remove:(NSString* ) item_ids
  571. {
  572. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  573. __block AppDelegate *appDelegate = nil;
  574. dispatch_sync(dispatch_get_main_queue(), ^{
  575. //some UI methods ej
  576. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  577. });
  578. if(appDelegate.user!=nil)
  579. [params setValue:appDelegate.user forKey:@"user"];
  580. if(appDelegate.contact_id!=nil)
  581. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  582. if(appDelegate.password!=nil)
  583. [params setValue:appDelegate.password forKey:@"password"];
  584. [params setValue:item_ids forKey:@"portfolioId"];
  585. // [params setValue:editor forKey:@"editor"];
  586. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  587. NSData* json = nil;
  588. if(appDelegate.offline_mode)
  589. {
  590. json = [OLDataProvider offline_removePortfolio:params];
  591. } else {
  592. if(![self IsNetworkAvailable])
  593. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  594. json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  595. }
  596. if(json!=nil)
  597. {
  598. NSError *error=nil;
  599. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  600. int result = [[jsobj valueForKey:@"result"] intValue];
  601. if (result==2)
  602. {
  603. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  604. [appDelegate update_count_mark];
  605. }
  606. return jsobj;
  607. }
  608. else
  609. return nil;
  610. }
  611. //+(NSDictionary*) watchlist_remove:(NSString* ) item_ids
  612. //{
  613. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  614. // __block AppDelegate *appDelegate = nil;
  615. //
  616. // dispatch_sync(dispatch_get_main_queue(), ^{
  617. // //some UI methods ej
  618. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  619. // });
  620. // if(appDelegate.user!=nil)
  621. // [params setValue:appDelegate.user forKey:@"user"];
  622. // if(appDelegate.contact_id!=nil)
  623. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  624. // if(appDelegate.password!=nil)
  625. // [params setValue:appDelegate.password forKey:@"password"];
  626. // [params setValue:item_ids forKey:@"collectId"];
  627. // // [params setValue:editor forKey:@"editor"];
  628. //
  629. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  630. //
  631. // if(appDelegate.offline_mode)
  632. // {
  633. // return [OLDataProvider offline_deletewishlist:params];
  634. // }
  635. // if(![self IsNetworkAvailable])
  636. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  637. //
  638. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  639. // if(json!=nil)
  640. // {
  641. // NSError *error=nil;
  642. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  643. // int result = [[jsobj valueForKey:@"result"] intValue];
  644. //
  645. // if (result==2)
  646. // {
  647. //
  648. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  649. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  650. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  651. //
  652. // [appDelegate update_count_mark];
  653. // }
  654. // return jsobj;
  655. // }
  656. // else
  657. // return nil;
  658. //}
  659. //+(NSDictionary*) move_cart2wish:(NSString* ) item_ids
  660. //{
  661. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  662. // __block AppDelegate *appDelegate = nil;
  663. //
  664. // dispatch_sync(dispatch_get_main_queue(), ^{
  665. // //some UI methods ej
  666. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  667. // });
  668. // if(appDelegate.user!=nil)
  669. // [params setValue:appDelegate.user forKey:@"user"];
  670. // if(appDelegate.contact_id!=nil)
  671. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  672. // if(appDelegate.password!=nil)
  673. // [params setValue:appDelegate.password forKey:@"password"];
  674. // if(appDelegate.order_code!=nil)
  675. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  676. // [params setValue:item_ids forKey:@"cartItemId"];
  677. // // [params setValue:editor forKey:@"editor"];
  678. //
  679. // [params setValue:ScreenCodeCart forKey:kScreenName];
  680. // // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  681. //
  682. // NSData* json = nil;
  683. // if(appDelegate.offline_mode)
  684. // {
  685. // json= [OLDataProvider offline_movecart2wish:params];
  686. // }
  687. // else
  688. // {
  689. // if(![self IsNetworkAvailable])
  690. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  691. //
  692. // json=[self get_json:URL_CART2WISH parameters:params];
  693. // }
  694. // if(json!=nil)
  695. // {
  696. // NSError *error=nil;
  697. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  698. // int result = [[jsobj valueForKey:@"result"] intValue];
  699. //
  700. // if (result==2)
  701. // {
  702. //
  703. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  704. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  705. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  706. //
  707. // [appDelegate update_count_mark];
  708. // }
  709. // return jsobj;
  710. // }
  711. // else
  712. // return nil;
  713. //}
  714. //+(NSDictionary*) move_wish2cart:(NSString* ) item_ids
  715. //{
  716. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  717. // __block AppDelegate *appDelegate = nil;
  718. //
  719. // dispatch_sync(dispatch_get_main_queue(), ^{
  720. // //some UI methods ej
  721. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  722. // });
  723. // if(appDelegate.user!=nil)
  724. // [params setValue:appDelegate.user forKey:@"user"];
  725. // if(appDelegate.contact_id!=nil)
  726. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  727. // if(appDelegate.password!=nil)
  728. // [params setValue:appDelegate.password forKey:@"password"];
  729. // if(appDelegate.order_code!=nil)
  730. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  731. // [params setValue:item_ids forKey:@"collectId"];
  732. // // [params setValue:editor forKey:@"editor"];
  733. //
  734. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  735. // [params setValue:@"Move To Cart" forKey:kAction];
  736. //
  737. // NSData *json = nil;
  738. // if(appDelegate.offline_mode)
  739. // {
  740. // json = [OLDataProvider offline_movewish2cart:params];
  741. // } else {
  742. // if(![self IsNetworkAvailable])
  743. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  744. //
  745. // json=[self get_json:URL_WISH2CART parameters:params];
  746. // }
  747. //
  748. // if(json!=nil)
  749. // {
  750. // NSError *error=nil;
  751. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  752. // int result = [[jsobj valueForKey:@"result"] intValue];
  753. //
  754. // if (result==2)
  755. // {
  756. //
  757. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  758. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  759. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  760. //
  761. // [appDelegate update_count_mark];
  762. // }
  763. // return jsobj;
  764. // }
  765. // else
  766. // return nil;
  767. //}
  768. //+(NSDictionary*) cart_remove:(NSString* ) item_ids
  769. //{
  770. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  771. // __block AppDelegate *appDelegate = nil;
  772. //
  773. // dispatch_sync(dispatch_get_main_queue(), ^{
  774. // //some UI methods ej
  775. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  776. // });
  777. // if(appDelegate.user!=nil)
  778. // [params setValue:appDelegate.user forKey:@"user"];
  779. // if(appDelegate.contact_id!=nil)
  780. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  781. // if(appDelegate.password!=nil)
  782. // [params setValue:appDelegate.password forKey:@"password"];
  783. //
  784. // if(appDelegate.order_code!=nil)
  785. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  786. // [params setValue:item_ids forKey:@"cartItemId"];
  787. // // [params setValue:editor forKey:@"editor"];
  788. //
  789. // [params setValue:ScreenCodeCart forKey:kScreenName];
  790. // // [params setValue:@"" forKey:kAction];
  791. //
  792. // NSData* json=nil;
  793. // if(appDelegate.offline_mode)
  794. // {
  795. // json= [OLDataProvider offline_cartremove:params];
  796. // }
  797. // else
  798. // {
  799. // if(![self IsNetworkAvailable])
  800. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  801. //
  802. // json=[self get_json:URL_CART_REMOVE parameters:params];
  803. // }
  804. // if(json!=nil)
  805. // {
  806. // NSError *error=nil;
  807. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  808. //
  809. // int result = [[jsobj valueForKey:@"result"] intValue];
  810. //
  811. // if (result==2)
  812. // {
  813. //
  814. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  815. //
  816. //
  817. // [appDelegate update_count_mark];
  818. // }
  819. // return jsobj;
  820. // }
  821. // else
  822. // return nil;
  823. //}
  824. //+(NSDictionary*) cart_check:(NSString* ) item_ids
  825. //{
  826. // return nil;
  827. // if(![self IsNetworkAvailable])
  828. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  829. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  830. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  831. // if(appDelegate.user!=nil)
  832. // [params setValue:appDelegate.user forKey:@"user"];
  833. // if(appDelegate.contact_id!=nil)
  834. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  835. // if(appDelegate.password!=nil)
  836. // [params setValue:appDelegate.password forKey:@"password"];
  837. // [params setValue:item_ids forKey:@"cartItemId"];
  838. // // [params setValue:editor forKey:@"editor"];
  839. // if(appDelegate.offline_mode)
  840. // {
  841. // return [OLDataProvider offline_notimpl];
  842. // }
  843. // NSData* json=[self get_json:URL_CART_CHECK parameters:params];
  844. // if(json!=nil)
  845. // {
  846. // NSError *error=nil;
  847. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  848. // return jsobj;
  849. // }
  850. // else
  851. // return nil;
  852. //}
  853. +(NSDictionary*)create_Address:(NSMutableDictionary*)params
  854. {
  855. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  856. __block AppDelegate *appDelegate = nil;
  857. dispatch_sync(dispatch_get_main_queue(), ^{
  858. //some UI methods ej
  859. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  860. });
  861. if(appDelegate.user!=nil)
  862. [params setValue:appDelegate.user forKey:@"user"];
  863. if(appDelegate.contact_id!=nil)
  864. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  865. if(appDelegate.password!=nil)
  866. [params setValue:appDelegate.password forKey:@"password"];
  867. // [params setValue:sourceid forKey:@"sourceid"];
  868. // [params setValue:editor forKey:@"editor"];
  869. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  870. NSData* json=nil;
  871. if(appDelegate.offline_mode)
  872. {
  873. json= [OLDataProvider offline_saveaddr:params];
  874. }
  875. else
  876. {
  877. if(![self IsNetworkAvailable])
  878. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  879. json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  880. }
  881. if(json!=nil)
  882. {
  883. NSError *error=nil;
  884. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  885. return jsobj;
  886. }
  887. else
  888. return nil;
  889. }
  890. +(NSDictionary*)copy_Order:(NSString*) order_code
  891. {
  892. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  893. __block AppDelegate *appDelegate = nil;
  894. dispatch_sync(dispatch_get_main_queue(), ^{
  895. //some UI methods ej
  896. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  897. });
  898. if(appDelegate.user!=nil)
  899. [params setValue:appDelegate.user forKey:@"user"];
  900. if(appDelegate.contact_id!=nil)
  901. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  902. if(appDelegate.password!=nil)
  903. [params setValue:appDelegate.password forKey:@"password"];
  904. // NSString* ssaved = @"false";
  905. // if(saved)
  906. // ssaved=@"true";
  907. // [params setValue:@"true" forKey:@"saved"];
  908. [params setValue:order_code forKey:@"code"];
  909. // [params setValue:sourceid forKey:@"sourceid"];
  910. // [params setValue:editor forKey:@"editor"];
  911. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  912. NSData* json=nil;
  913. if(appDelegate.offline_mode)
  914. {
  915. json= [OLDataProvider offline_copyorder:params];
  916. }
  917. else
  918. {
  919. if(![self IsNetworkAvailable])
  920. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  921. json=[self get_json:URL_COPY_ORDER parameters:params];
  922. }
  923. if(json!=nil)
  924. {
  925. NSError *error=nil;
  926. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  927. return jsobj;
  928. }
  929. else
  930. return nil;
  931. }
  932. +(NSDictionary*)sign_Order:(NSString*) order_code path:(NSString*)path
  933. {
  934. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  935. __block AppDelegate *appDelegate = nil;
  936. dispatch_sync(dispatch_get_main_queue(), ^{
  937. //some UI methods ej
  938. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  939. });
  940. if(appDelegate.user!=nil)
  941. [params setValue:appDelegate.user forKey:@"user"];
  942. if(appDelegate.contact_id!=nil)
  943. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  944. if(appDelegate.password!=nil)
  945. [params setValue:appDelegate.password forKey:@"password"];
  946. // NSString* ssaved = @"false";
  947. // if(saved)
  948. // ssaved=@"true";
  949. // [params setValue:@"true" forKey:@"saved"];
  950. [params setValue:order_code forKey:@"orderCode"];
  951. [params setValue:path forKey:@"picpath"];
  952. // [params setValue:sourceid forKey:@"sourceid"];
  953. // [params setValue:editor forKey:@"editor"];
  954. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  955. NSData* json=nil;
  956. if(appDelegate.offline_mode)
  957. {
  958. json= [OLDataProvider offline_signorder:params];
  959. }
  960. else
  961. {
  962. if(![self IsNetworkAvailable])
  963. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  964. json=[self get_json:URL_SIGN_ORDER parameters:params];
  965. }
  966. if(json!=nil)
  967. {
  968. NSError *error=nil;
  969. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  970. return jsobj;
  971. }
  972. else
  973. return nil;
  974. }
  975. +(NSDictionary*)commit_Order:(NSString*) order_code //saved:(bool) saved
  976. {
  977. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  978. __block AppDelegate *appDelegate = nil;
  979. dispatch_sync(dispatch_get_main_queue(), ^{
  980. //some UI methods ej
  981. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  982. });
  983. if(appDelegate.user!=nil)
  984. [params setValue:appDelegate.user forKey:@"user"];
  985. if(appDelegate.contact_id!=nil)
  986. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  987. if(appDelegate.password!=nil)
  988. [params setValue:appDelegate.password forKey:@"password"];
  989. // NSString* ssaved = @"false";
  990. // if(saved)
  991. // ssaved=@"true";
  992. [params setValue:@"true" forKey:@"saved"];
  993. [params setValue:order_code forKey:@"orderCode"];
  994. // [params setValue:sourceid forKey:@"sourceid"];
  995. // [params setValue:editor forKey:@"editor"];
  996. [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  997. NSData* json = nil;
  998. if(appDelegate.offline_mode)
  999. {
  1000. json= [OLDataProvider offline_submitorder:params];
  1001. }
  1002. else
  1003. {
  1004. if(![self IsNetworkAvailable])
  1005. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1006. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  1007. }
  1008. if(json!=nil)
  1009. {
  1010. NSError *error=nil;
  1011. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1012. return jsobj;
  1013. }
  1014. else
  1015. return nil;
  1016. }
  1017. //+(NSDictionary*)open_Order:(NSString*) order_code
  1018. //{
  1019. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1020. // __block AppDelegate *appDelegate = nil;
  1021. //
  1022. // dispatch_sync(dispatch_get_main_queue(), ^{
  1023. // //some UI methods ej
  1024. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1025. // });
  1026. // if(appDelegate.user!=nil)
  1027. // [params setValue:appDelegate.user forKey:@"user"];
  1028. // // if(appDelegate.contact_id!=nil)
  1029. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1030. // if(appDelegate.password!=nil)
  1031. // [params setValue:appDelegate.password forKey:@"password"];
  1032. //
  1033. // [params setValue:order_code forKey:@"orderCode"];
  1034. // // [params setValue:sourceid forKey:@"sourceid"];
  1035. // // [params setValue:editor forKey:@"editor"];
  1036. //
  1037. // [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  1038. //
  1039. // NSData* json=nil;
  1040. // if(appDelegate.offline_mode)
  1041. // {
  1042. // json=[OLDataProvider offline_editorder:params];
  1043. //
  1044. // }
  1045. // else
  1046. // {
  1047. // if(![self IsNetworkAvailable])
  1048. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1049. //
  1050. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  1051. // }
  1052. // if(json!=nil)
  1053. // {
  1054. // NSError *error=nil;
  1055. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1056. // int result = [[jsobj valueForKey:@"result"] intValue];
  1057. //
  1058. // if (result==2)
  1059. // {
  1060. //
  1061. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1062. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1063. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1064. //
  1065. // [appDelegate update_count_mark];
  1066. //
  1067. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1068. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  1069. // }
  1070. //
  1071. // }
  1072. //
  1073. // return jsobj;
  1074. // }
  1075. // else
  1076. // return nil;
  1077. //}
  1078. +(NSDictionary*)delete_Order:(NSString*) order_id
  1079. {
  1080. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1081. __block AppDelegate *appDelegate = nil;
  1082. dispatch_sync(dispatch_get_main_queue(), ^{
  1083. //some UI methods ej
  1084. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1085. });
  1086. if(appDelegate.user!=nil)
  1087. [params setValue:appDelegate.user forKey:@"user"];
  1088. // if(appDelegate.contact_id!=nil)
  1089. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1090. if(appDelegate.password!=nil)
  1091. [params setValue:appDelegate.password forKey:@"password"];
  1092. [params setValue:order_id forKey:@"orderId"];
  1093. // [params setValue:sourceid forKey:@"sourceid"];
  1094. // [params setValue:editor forKey:@"editor"];
  1095. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  1096. if(appDelegate.offline_mode)
  1097. {
  1098. return [OLDataProvider offline_notimpl];
  1099. }
  1100. if(![self IsNetworkAvailable])
  1101. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1102. NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  1103. if(json!=nil)
  1104. {
  1105. NSError *error=nil;
  1106. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1107. return jsobj;
  1108. }
  1109. else
  1110. return nil;
  1111. }
  1112. +(NSDictionary*)cancel_Order:(NSString*) order_id order_code:(NSString*) order_code
  1113. {
  1114. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1115. __block AppDelegate *appDelegate = nil;
  1116. dispatch_sync(dispatch_get_main_queue(), ^{
  1117. //some UI methods ej
  1118. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1119. });
  1120. if(appDelegate.user!=nil)
  1121. [params setValue:appDelegate.user forKey:@"user"];
  1122. // if(appDelegate.contact_id!=nil)
  1123. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1124. if(appDelegate.password!=nil)
  1125. [params setValue:appDelegate.password forKey:@"password"];
  1126. [params setValue:order_id forKey:@"orderId"];
  1127. [params setValue:order_code forKey:@"orderCode"];
  1128. // [params setValue:sourceid forKey:@"sourceid"];
  1129. // [params setValue:editor forKey:@"editor"];
  1130. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  1131. NSData* json=nil;
  1132. if(appDelegate.offline_mode)
  1133. {
  1134. json=[OLDataProvider offline_cancelorder:params];
  1135. }
  1136. else
  1137. {
  1138. if(![self IsNetworkAvailable])
  1139. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1140. json=[self get_json:URL_CANCEL_ORDER parameters:params];
  1141. }
  1142. if(json!=nil)
  1143. {
  1144. NSError *error=nil;
  1145. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1146. return jsobj;
  1147. }
  1148. else
  1149. return nil;
  1150. }
  1151. +(NSDictionary*)release_Order:(NSString*) order_code withScreen:(NSString *)screenName
  1152. {
  1153. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1154. __block AppDelegate *appDelegate = nil;
  1155. dispatch_sync(dispatch_get_main_queue(), ^{
  1156. //some UI methods ej
  1157. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1158. });
  1159. if(appDelegate.user!=nil)
  1160. [params setValue:appDelegate.user forKey:@"user"];
  1161. // if(appDelegate.contact_id!=nil)
  1162. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1163. if(appDelegate.password!=nil)
  1164. [params setValue:appDelegate.password forKey:@"password"];
  1165. [params setValue:order_code forKey:@"orderCode"];
  1166. // [params setValue:sourceid forKey:@"sourceid"];
  1167. // [params setValue:editor forKey:@"editor"];
  1168. if (screenName) {
  1169. [params setValue:screenName forKey:kScreenName];
  1170. }
  1171. NSData* json=nil;
  1172. if(appDelegate.offline_mode)
  1173. {
  1174. json= [OLDataProvider offline_resetorder:params];
  1175. }
  1176. else
  1177. {
  1178. if(![self IsNetworkAvailable])
  1179. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1180. json=[self get_json:URL_RELEASE_ORDER parameters:params];
  1181. }
  1182. if(json!=nil)
  1183. {
  1184. NSError *error=nil;
  1185. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1186. if([[jsobj valueForKey:@"result"]intValue]==2)
  1187. { [appDelegate SetSo:nil];
  1188. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1189. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1190. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1191. [appDelegate update_count_mark];
  1192. }
  1193. return jsobj;
  1194. }
  1195. else
  1196. return nil;
  1197. }
  1198. +(NSDictionary*)update_OrderCustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info
  1199. {
  1200. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1201. __block AppDelegate *appDelegate = nil;
  1202. dispatch_sync(dispatch_get_main_queue(), ^{
  1203. //some UI methods ej
  1204. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1205. });
  1206. if(appDelegate.user!=nil)
  1207. [info setValue:appDelegate.user forKey:@"user"];
  1208. // if(appDelegate.contact_id!=nil)
  1209. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1210. if(appDelegate.password!=nil)
  1211. [info setValue:appDelegate.password forKey:@"password"];
  1212. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1213. [info setValue:order_code forKey:@"orderCode"];
  1214. // [params setValue:sourceid forKey:@"sourceid"];
  1215. // [params setValue:editor forKey:@"editor"];
  1216. if(appDelegate.offline_mode)
  1217. {
  1218. return [OLDataProvider offline_notimpl];
  1219. }
  1220. if(![self IsNetworkAvailable])
  1221. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1222. NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  1223. if(json!=nil)
  1224. {
  1225. NSError *error=nil;
  1226. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1227. return jsobj;
  1228. }
  1229. else
  1230. return nil;
  1231. }
  1232. //+(NSDictionary*)commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url
  1233. //{
  1234. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1235. // __block AppDelegate *appDelegate = nil;
  1236. //
  1237. // dispatch_sync(dispatch_get_main_queue(), ^{
  1238. // //some UI methods ej
  1239. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1240. // });
  1241. // if(appDelegate.user!=nil)
  1242. // [params setValue:appDelegate.user forKey:@"user"];
  1243. // if(appDelegate.contact_id!=nil)
  1244. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1245. // if(appDelegate.password!=nil)
  1246. // [params setValue:appDelegate.password forKey:@"password"];
  1247. //
  1248. // // if(appDelegate.order_code!=nil)
  1249. // // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1250. //
  1251. // // NSDictionary* customerinfo= appDelegate.customerInfo;
  1252. // //
  1253. // // NSArray* keys=[customerinfo allKeys];
  1254. // // for(int i=0;i<keys.count;i++)
  1255. // // {
  1256. // // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1257. // // }
  1258. // //
  1259. // // [params setValue:sourceid forKey:@"sourceid"];
  1260. // // [params setValue:editor forKey:@"editor"];
  1261. //
  1262. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  1263. //
  1264. // if(appDelegate.offline_mode)
  1265. // {
  1266. // params[@"offline_Command"]=url;
  1267. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  1268. // }
  1269. //
  1270. // if(![self IsNetworkAvailable])
  1271. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1272. //
  1273. // NSData* json=[self get_json:url parameters:params];
  1274. // if(json!=nil)
  1275. // {
  1276. // NSError *error=nil;
  1277. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1278. // if([[jsobj valueForKey:@"result"]intValue]==2)
  1279. // [appDelegate SetSo:nil];
  1280. //
  1281. //
  1282. // return jsobj;
  1283. // }
  1284. // else
  1285. // return nil;
  1286. //}
  1287. +(NSDictionary*)saveandcommit_Order:(NSMutableDictionary*)params
  1288. {
  1289. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1290. __block AppDelegate *appDelegate = nil;
  1291. dispatch_sync(dispatch_get_main_queue(), ^{
  1292. //some UI methods ej
  1293. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1294. });
  1295. if(appDelegate.user!=nil)
  1296. [params setValue:appDelegate.user forKey:@"user"];
  1297. if(appDelegate.contact_id!=nil)
  1298. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1299. if(appDelegate.password!=nil)
  1300. [params setValue:appDelegate.password forKey:@"password"];
  1301. if(appDelegate.order_code!=nil)
  1302. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1303. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1304. //
  1305. // NSArray* keys=[customerinfo allKeys];
  1306. // for(int i=0;i<keys.count;i++)
  1307. // {
  1308. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1309. // }
  1310. //
  1311. // [params setValue:sourceid forKey:@"sourceid"];
  1312. // [params setValue:editor forKey:@"editor"];
  1313. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1314. NSData* json=nil;
  1315. if(appDelegate.offline_mode)
  1316. {
  1317. json=[OLDataProvider offline_submitorder:params];
  1318. }
  1319. else
  1320. {
  1321. if(![self IsNetworkAvailable])
  1322. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1323. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  1324. }
  1325. if(json!=nil)
  1326. {
  1327. NSError *error=nil;
  1328. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1329. if([[jsobj valueForKey:@"result"]intValue]==2)
  1330. [appDelegate SetSo:nil];
  1331. return jsobj;
  1332. }
  1333. else
  1334. return nil;
  1335. }
  1336. +(NSDictionary*)update_Customer:(NSMutableDictionary*)params
  1337. {
  1338. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1339. __block AppDelegate *appDelegate = nil;
  1340. dispatch_sync(dispatch_get_main_queue(), ^{
  1341. //some UI methods ej
  1342. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1343. });
  1344. if(appDelegate.user!=nil)
  1345. [params setValue:appDelegate.user forKey:@"user"];
  1346. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1347. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1348. // else
  1349. if(appDelegate.contact_id!=nil)
  1350. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1351. if(appDelegate.password!=nil)
  1352. [params setValue:appDelegate.password forKey:@"password"];
  1353. // NSDictionary* customerinfo=nil;
  1354. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1355. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1356. // else
  1357. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1358. //
  1359. // appDelegate.customerInfo;
  1360. // NSArray* keys=[customerinfo allKeys];
  1361. // for(int i=0;i<keys.count;i++)
  1362. // {
  1363. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1364. // }
  1365. // [params setValue:sourceid forKey:@"sourceid"];
  1366. // [params setValue:editor forKey:@"editor"];
  1367. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1368. NSData* json=nil;
  1369. if(appDelegate.offline_mode)
  1370. {
  1371. json= [OLDataProvider offline_saveContact:params];
  1372. }
  1373. else
  1374. {
  1375. if(![self IsNetworkAvailable])
  1376. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1377. json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  1378. }
  1379. if(json!=nil)
  1380. {
  1381. NSError *error=nil;
  1382. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1383. return jsobj;
  1384. }
  1385. else
  1386. return nil;
  1387. }
  1388. +(NSDictionary*)save_newCustomer:(NSMutableDictionary*)params
  1389. {
  1390. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1391. __block AppDelegate *appDelegate = nil;
  1392. dispatch_sync(dispatch_get_main_queue(), ^{
  1393. //some UI methods ej
  1394. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1395. });
  1396. if(appDelegate.user!=nil)
  1397. [params setValue:appDelegate.user forKey:@"user"];
  1398. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1399. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1400. // else
  1401. if(appDelegate.contact_id!=nil)
  1402. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1403. if(appDelegate.password!=nil)
  1404. [params setValue:appDelegate.password forKey:@"password"];
  1405. // NSDictionary* customerinfo=nil;
  1406. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1407. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1408. // else
  1409. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1410. //
  1411. // appDelegate.customerInfo;
  1412. // NSArray* keys=[customerinfo allKeys];
  1413. // for(int i=0;i<keys.count;i++)
  1414. // {
  1415. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1416. // }
  1417. // [params setValue:sourceid forKey:@"sourceid"];
  1418. // [params setValue:editor forKey:@"editor"];
  1419. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1420. NSData* json=nil;
  1421. if(appDelegate.offline_mode)
  1422. {
  1423. json= [OLDataProvider offline_saveNewContact:params];
  1424. }
  1425. else
  1426. {
  1427. if(![self IsNetworkAvailable])
  1428. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1429. json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  1430. }
  1431. if(json!=nil)
  1432. {
  1433. NSError *error=nil;
  1434. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1435. return jsobj;
  1436. }
  1437. else
  1438. return nil;
  1439. }
  1440. +(NSDictionary*)save_Order:(NSMutableDictionary*)params
  1441. {
  1442. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1443. __block AppDelegate *appDelegate = nil;
  1444. dispatch_sync(dispatch_get_main_queue(), ^{
  1445. //some UI methods ej
  1446. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1447. });
  1448. if(appDelegate.user!=nil)
  1449. [params setValue:appDelegate.user forKey:@"user"];
  1450. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1451. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1452. // else
  1453. if(appDelegate.contact_id!=nil)
  1454. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1455. if(appDelegate.password!=nil)
  1456. [params setValue:appDelegate.password forKey:@"password"];
  1457. if(appDelegate.order_code!=nil)
  1458. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1459. // NSDictionary* customerinfo=nil;
  1460. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1461. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1462. // else
  1463. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1464. //
  1465. // appDelegate.customerInfo;
  1466. // NSArray* keys=[customerinfo allKeys];
  1467. // for(int i=0;i<keys.count;i++)
  1468. // {
  1469. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1470. // }
  1471. // [params setValue:sourceid forKey:@"sourceid"];
  1472. // [params setValue:editor forKey:@"editor"];
  1473. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1474. NSData* json=nil;
  1475. if(appDelegate.offline_mode)
  1476. {
  1477. json= [OLDataProvider offline_saveorder:params];
  1478. }
  1479. else
  1480. {
  1481. if(![self IsNetworkAvailable])
  1482. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1483. json=[self get_json:URL_SAVE_ORDER parameters:params];
  1484. }
  1485. if(json!=nil)
  1486. {
  1487. NSError *error=nil;
  1488. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1489. NSString *so = [jsobj valueForKey:@"so#"];
  1490. if (so) {
  1491. [appDelegate SetSo:so];
  1492. }
  1493. return jsobj;
  1494. }
  1495. else
  1496. return nil;
  1497. }
  1498. //+(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
  1499. //{
  1500. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1501. // __block AppDelegate *appDelegate = nil;
  1502. //
  1503. // dispatch_sync(dispatch_get_main_queue(), ^{
  1504. // //some UI methods ej
  1505. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1506. // });
  1507. // if(appDelegate.user!=nil)
  1508. // [params setValue:appDelegate.user forKey:@"user"];
  1509. //
  1510. //
  1511. // // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1512. // // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1513. // // else
  1514. //
  1515. // if(appDelegate.contact_id!=nil)
  1516. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1517. // if(appDelegate.password!=nil)
  1518. // [params setValue:appDelegate.password forKey:@"password"];
  1519. //
  1520. // if(appDelegate.order_code!=nil)
  1521. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1522. // // [params setValue:sourceid forKey:@"sourceid"];
  1523. // // [params setValue:editor forKey:@"editor"];
  1524. // DebugLog(@"request editor url:%@",request_url);
  1525. //
  1526. //
  1527. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1528. // {
  1529. // [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1530. // }
  1531. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1532. // {
  1533. // [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1534. // }
  1535. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1536. // {
  1537. // [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  1538. // }
  1539. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1540. // {
  1541. // [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1542. // }
  1543. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1544. // {
  1545. // [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  1546. // }
  1547. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1548. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1549. // }
  1550. //
  1551. // NSData* json = nil;
  1552. // if(appDelegate.offline_mode)
  1553. // {
  1554. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1555. // {
  1556. // json= [OLDataProvider offline_createContact:params];
  1557. // }
  1558. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1559. // {
  1560. // json= [OLDataProvider offline_editContact:params];
  1561. // }
  1562. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1563. // {
  1564. // json= [OLDataProvider offline_contactAdvancedSearch:params];
  1565. // }
  1566. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1567. // {
  1568. // json= [OLDataProvider offline_placeorder:params];
  1569. // }
  1570. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1571. // {
  1572. // json= [OLDataProvider offline_addreditor:params];
  1573. // }
  1574. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1575. // json = [OLDataProvider offline_createTearSheet:params];
  1576. // }
  1577. //
  1578. // else
  1579. // return [OLDataProvider offline_notimpl];
  1580. // }
  1581. // else
  1582. // {
  1583. // if(![self IsNetworkAvailable])
  1584. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1585. //
  1586. // if([request_url isEqualToString:URL_CARTDELIVERY])
  1587. // {
  1588. // NSError *error=nil;
  1589. //
  1590. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1591. // params[@"resultSerial"]=uuid;
  1592. //
  1593. // for(int i=0;i<150;i++)
  1594. // {
  1595. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1596. // // result_params[@"resultSerial"]=uuid;
  1597. // json=[self get_json:request_url parameters:params];
  1598. // if(json!=nil)
  1599. // {
  1600. //
  1601. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1602. // if([jsobj[@"result"] intValue]==2 || [jsobj[@"result"] intValue] == 8)
  1603. // {
  1604. // break;
  1605. // }
  1606. // }
  1607. // sleep(2);
  1608. // }
  1609. // }
  1610. // else
  1611. // json =[self get_json:request_url parameters:params];
  1612. // }
  1613. // if(json!=nil)
  1614. // {
  1615. // NSError *error=nil;
  1616. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1617. // return jsobj;
  1618. // }
  1619. // else
  1620. // return nil;
  1621. //}
  1622. //+(NSDictionary*)request_OrderInfo:(NSString*) orderid
  1623. //{
  1624. // if(![self IsNetworkAvailable])
  1625. // return nil;
  1626. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1627. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1628. // if(appDelegate.user!=nil)
  1629. // [params setValue:appDelegate.user forKey:@"user"];
  1630. // if(appDelegate.password!=nil)
  1631. // [params setValue:appDelegate.password forKey:@"password"];
  1632. // [params setValue:orderid forKey:@"orderid"];
  1633. // NSData* json=[self get_json:URL_ORDER_INFO parameters:params];
  1634. // NSError *error=nil;
  1635. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1636. // return jsobj;
  1637. //}
  1638. +(NSDictionary*)request_OrderList:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged
  1639. {
  1640. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1641. __block AppDelegate *appDelegate = nil;
  1642. dispatch_sync(dispatch_get_main_queue(), ^{
  1643. //some UI methods ej
  1644. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1645. });
  1646. if(appDelegate.user!=nil)
  1647. [params setValue:appDelegate.user forKey:@"user"];
  1648. if(appDelegate.contact_id!=nil)
  1649. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1650. if(appDelegate.password!=nil)
  1651. [params setValue:appDelegate.password forKey:@"password"];
  1652. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1653. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1654. [params setValue:keywords forKey:@"keyWord"];
  1655. [params setValue:customer forKey:@"customer_filter"];
  1656. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  1657. [params setValue:status_code forKey:@"orderStatus"];
  1658. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1659. if (keywords) {
  1660. [params setObject:@"Search" forKey:kAction];
  1661. }
  1662. NSData* json=nil;
  1663. if(appDelegate.offline_mode)
  1664. {
  1665. json= [OLDataProvider offline_orderlist:params];
  1666. }
  1667. else
  1668. {
  1669. if(![self IsNetworkAvailable])
  1670. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1671. json=[self get_json:URL_ORDER_LIST parameters:params];
  1672. }
  1673. if(json==nil)
  1674. return nil;
  1675. NSError *error=nil;
  1676. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1677. return jsobj;
  1678. }
  1679. +(NSDictionary*)request_PDFList:(int ) offset limit:(int)limit keywords:(NSString* ) keywords
  1680. {
  1681. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1682. __block AppDelegate *appDelegate = nil;
  1683. dispatch_sync(dispatch_get_main_queue(), ^{
  1684. //some UI methods ej
  1685. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1686. });
  1687. if(appDelegate.user!=nil)
  1688. [params setValue:appDelegate.user forKey:@"user"];
  1689. if(appDelegate.contact_id!=nil)
  1690. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1691. if(appDelegate.password!=nil)
  1692. [params setValue:appDelegate.password forKey:@"password"];
  1693. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  1694. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  1695. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  1696. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  1697. // [params setValue:filter forKey:@"filter"];
  1698. [params setValue:keywords forKey:@"keyWord"];
  1699. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  1700. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  1701. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  1702. if (keywords) {
  1703. [params setObject:@"Search" forKey:kAction];
  1704. }
  1705. NSData* json = nil;
  1706. if(appDelegate.offline_mode)
  1707. {
  1708. json = [OLDataProvider offline_pdfList:params];
  1709. } else {
  1710. if(![self IsNetworkAvailable])
  1711. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1712. json=[self get_json:URL_DM_LIST parameters:params];
  1713. }
  1714. if(json==nil)
  1715. return nil;
  1716. NSError *error=nil;
  1717. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1718. return jsobj;
  1719. }
  1720. //+(NSString*) create_portfolio:(NSMutableDictionary*)params
  1721. //{
  1722. // __block AppDelegate *appDelegate = nil;
  1723. //
  1724. // dispatch_sync(dispatch_get_main_queue(), ^{
  1725. // //some UI methods ej
  1726. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1727. // });
  1728. // if(appDelegate.offline_mode)
  1729. // {
  1730. //
  1731. //
  1732. // NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  1733. // if(json==nil)
  1734. // return nil;
  1735. // NSError *error=nil;
  1736. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1737. //
  1738. // return jsobj[@"pdf_path"];
  1739. // }
  1740. // else
  1741. // {
  1742. // return nil;
  1743. // }
  1744. //}
  1745. //+(NSDictionary*)direct_save_TearSheet:(NSMutableDictionary*)params//(NSString*) request_url name:(NSString*)name delete:(NSString* )ids note:(NSString* )saveNote modelIds:(NSDictionary *)modelIds
  1746. //{
  1747. // NSMutableDictionary* off_params = [params mutableCopy];;
  1748. //
  1749. // params[@"off_params"]=[RAConvertor dict2string:off_params];;
  1750. // __block AppDelegate *appDelegate = nil;
  1751. //
  1752. // dispatch_sync(dispatch_get_main_queue(), ^{
  1753. // //some UI methods ej
  1754. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1755. // });
  1756. // if(appDelegate.user!=nil)
  1757. // [params setValue:appDelegate.user forKey:@"user"];
  1758. // if(appDelegate.contact_id!=nil)
  1759. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1760. // if(appDelegate.password!=nil)
  1761. // [params setValue:appDelegate.password forKey:@"password"];
  1762. //
  1763. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1764. //
  1765. // /*
  1766. // [params setValue:request_url forKey:@"pdfUrl"];
  1767. // [params setValue:name forKey:@"pdfName"];
  1768. // [params setValue:ids forKey:@"itemIds"];
  1769. // [params setValue:saveNote forKey:@"pdfNote"];
  1770. // [params setValue:[modelIds objectForKey:@"product_ids"] forKey:@"product_ids"];
  1771. // [params setValue:[modelIds objectForKey:@"item_ids"] forKey:@"item_ids"];
  1772. // [params setValue:[modelIds objectForKey:@"remove_item"] forKey:@"remove_item"];
  1773. // */
  1774. // NSData* json= nil;
  1775. //
  1776. // if(appDelegate.offline_mode)
  1777. // {
  1778. // json = [OLDataProvider offline_direct_save_TearSheet:params];
  1779. // }
  1780. // else
  1781. // {
  1782. // if(![self IsNetworkAvailable])
  1783. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1784. //
  1785. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1786. //
  1787. // NSError *error=nil;
  1788. //
  1789. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1790. // params[@"resultSerial"]=uuid;
  1791. //
  1792. // for(int i=0;i<150;i++)
  1793. // {
  1794. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1795. // // result_params[@"resultSerial"]=uuid;
  1796. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1797. // if(json!=nil)
  1798. // {
  1799. //
  1800. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1801. // if([jsobj[@"result"] intValue]==2)
  1802. // {
  1803. // break;
  1804. // }
  1805. // }
  1806. // sleep(5);
  1807. // }
  1808. //
  1809. // }
  1810. // if(json==nil)
  1811. // return nil;
  1812. // NSError *error=nil;
  1813. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1814. // return jsobj;
  1815. //}
  1816. //+(NSDictionary*)request_TearSheet:(NSMutableDictionary*)params//(NSString*) request_url
  1817. //{
  1818. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1819. // __block AppDelegate *appDelegate = nil;
  1820. //
  1821. // dispatch_sync(dispatch_get_main_queue(), ^{
  1822. // //some UI methods ej
  1823. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1824. // });
  1825. // if(appDelegate.user!=nil)
  1826. // [params setValue:appDelegate.user forKey:@"user"];
  1827. // if(appDelegate.contact_id!=nil)
  1828. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1829. // if(appDelegate.password!=nil)
  1830. // [params setValue:appDelegate.password forKey:@"password"];
  1831. //
  1832. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1833. //
  1834. // // [params setValue:request_url forKey:@"pdfUrl"];
  1835. // NSData* json= nil;
  1836. // if(appDelegate.offline_mode)
  1837. // {
  1838. // json= [OLDataProvider offline_request_tearsheet:params];
  1839. // }
  1840. // else
  1841. // {
  1842. // if(![self IsNetworkAvailable])
  1843. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1844. //
  1845. // NSError *error=nil;
  1846. //
  1847. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1848. // params[@"resultSerial"]=uuid;
  1849. //
  1850. // for(int i=0;i<150;i++)
  1851. // {
  1852. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1853. // // result_params[@"resultSerial"]=uuid;
  1854. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1855. // if(json!=nil)
  1856. // {
  1857. //
  1858. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1859. // if([jsobj[@"result"] intValue]==2)
  1860. // {
  1861. // break;
  1862. // }
  1863. // }
  1864. // sleep(5);
  1865. // }
  1866. // }
  1867. // if(json==nil)
  1868. // return nil;
  1869. // NSError *error=nil;
  1870. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1871. // return jsobj;
  1872. //}
  1873. //+(NSDictionary*)save_TearSheet:(NSMutableDictionary *)params//(NSString*) path name:(NSString*)name delete:(NSString* )ids note:(NSString*)note configureParams:(NSString *)configureParams modelIds:(NSDictionary *)modelIds
  1874. //{
  1875. //
  1876. //
  1877. // NSMutableDictionary* off_params = [params mutableCopy];;
  1878. //
  1879. // params[@"off_params"]=[RAConvertor dict2string:off_params];
  1880. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1881. // __block AppDelegate *appDelegate = nil;
  1882. //
  1883. // dispatch_sync(dispatch_get_main_queue(), ^{
  1884. // //some UI methods ej
  1885. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1886. // });
  1887. // if(appDelegate.user!=nil)
  1888. // [params setValue:appDelegate.user forKey:@"user"];
  1889. // if(appDelegate.contact_id!=nil)
  1890. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1891. // if(appDelegate.password!=nil)
  1892. // [params setValue:appDelegate.password forKey:@"password"];
  1893. //
  1894. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1895. //
  1896. // /*
  1897. // [params setValue:path forKey:@"pdfPath"];
  1898. // [params setValue:name forKey:@"pdfName"];
  1899. // [params setValue:note forKey:@"pdfNote"];
  1900. // [params setValue:ids forKey:@"itemIds"];
  1901. // [params setValue:configureParams forKey:@"configureParams"];
  1902. // [params setValue:[modelIds objectForKey:@"product_ids"] forKey:@"product_ids"];
  1903. // [params setValue:[modelIds objectForKey:@"item_ids"] forKey:@"item_ids"];
  1904. // [params setValue:[modelIds objectForKey:@"remove_item"] forKey:@"remove_item"];
  1905. // */
  1906. // NSData* json = nil;
  1907. // if(appDelegate.offline_mode)
  1908. // {
  1909. // json = [OLDataProvider offline_save_TearSheet:params];
  1910. // } else {
  1911. // if(![self IsNetworkAvailable])
  1912. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1913. //
  1914. // json=[self get_json:URL_SAVE_DM parameters:params];
  1915. // }
  1916. // if(json==nil)
  1917. // return nil;
  1918. // NSError *error=nil;
  1919. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1920. // return jsobj;
  1921. //}
  1922. +(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code//device:(NSString*) device
  1923. {
  1924. return nil;
  1925. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1926. __block AppDelegate *appDelegate = nil;
  1927. dispatch_sync(dispatch_get_main_queue(), ^{
  1928. //some UI methods ej
  1929. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1930. });
  1931. if(appDelegate.user!=nil)
  1932. [params setValue:appDelegate.user forKey:@"user"];
  1933. [params setValue:up_params forKey:@"upparam"];
  1934. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  1935. [params setValue:result forKey:@"result"];
  1936. [params setValue:module forKey:@"interfac"];
  1937. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  1938. // [params setValue:module forKey:@"module"];
  1939. // [[UIDevice currentDevice] name];
  1940. // if(appDelegate.offline_mode)
  1941. // {
  1942. // return [OLDataProvider offline_notimpl];
  1943. // }
  1944. if(![self IsNetworkAvailable])
  1945. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1946. NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  1947. if(json==nil)
  1948. return nil;
  1949. NSError *error=nil;
  1950. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1951. return jsobj;
  1952. }
  1953. //+(NSDictionary*)request_ContactList:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams
  1954. //{
  1955. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1956. //
  1957. // if(upparams!=nil)
  1958. // params = [upparams mutableCopy];
  1959. // __block AppDelegate *appDelegate = nil;
  1960. //
  1961. // dispatch_sync(dispatch_get_main_queue(), ^{
  1962. // //some UI methods ej
  1963. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1964. // });
  1965. // if(appDelegate.user!=nil)
  1966. // [params setValue:appDelegate.user forKey:@"user"];
  1967. //
  1968. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1969. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1970. // else
  1971. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1972. //
  1973. // if(appDelegate.password!=nil)
  1974. // [params setValue:appDelegate.password forKey:@"password"];
  1975. //
  1976. // [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1977. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1978. // [params setValue:contact_type forKey:@"contactType"];
  1979. // [params setValue:keywords forKey:@"keyword"];
  1980. //
  1981. // [params setObject:ScreenCodeAccount forKey:kScreenName];
  1982. // if (keywords) {
  1983. // [params setObject:@"Search" forKey:kAction];
  1984. // }
  1985. // if (upparams) {
  1986. // [params setObject:@"Advance Search" forKey:kAction];
  1987. // }
  1988. //
  1989. // NSString* url=nil;
  1990. // if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  1991. // url=URL_SHIPTO_LIST;
  1992. // else
  1993. // url=URL_CONTACT_LIST;
  1994. //
  1995. // if(appDelegate.offline_mode)
  1996. // return [OLDataProvider offline_contactlist:params];
  1997. //
  1998. // if(![self IsNetworkAvailable])
  1999. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2000. //
  2001. // NSData* json=[self get_json:url parameters:params];
  2002. // if(json==nil)
  2003. // return nil;
  2004. // NSError *error=nil;
  2005. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2006. // return jsobj;
  2007. //}
  2008. //+(NSDictionary*)request_OrderDetail:(NSMutableDictionary *) params
  2009. //{
  2010. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2011. // if (params == nil) {
  2012. // params = [[NSMutableDictionary alloc] init];
  2013. // }
  2014. // __block AppDelegate *appDelegate = nil;
  2015. //
  2016. // dispatch_sync(dispatch_get_main_queue(), ^{
  2017. // //some UI methods ej
  2018. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2019. // });
  2020. // if(appDelegate.user!=nil)
  2021. // [params setValue:appDelegate.user forKey:@"user"];
  2022. // if(appDelegate.contact_id!=nil)
  2023. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2024. // if(appDelegate.password!=nil)
  2025. // [params setValue:appDelegate.password forKey:@"password"];
  2026. //
  2027. //
  2028. // // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  2029. //
  2030. // [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  2031. //
  2032. // NSData* json=nil;
  2033. // if(appDelegate.offline_mode)
  2034. // {
  2035. // json= [OLDataProvider offline_orderdetail:params];
  2036. // }
  2037. // else
  2038. // {
  2039. // if(![self IsNetworkAvailable])
  2040. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2041. //
  2042. // NSError *error=nil;
  2043. //
  2044. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2045. // params[@"resultSerial"]=uuid;
  2046. //
  2047. // for(int i=0;i<150;i++)
  2048. // {
  2049. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2050. // // result_params[@"resultSerial"]=uuid;
  2051. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  2052. // if(json!=nil)
  2053. // {
  2054. //
  2055. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2056. // int resultCode = [jsobj[@"result"] intValue];
  2057. // if(resultCode==2 || resultCode == 8)
  2058. // {
  2059. // break;
  2060. // }
  2061. // }
  2062. // sleep(2);
  2063. // }
  2064. //
  2065. //
  2066. // }
  2067. // if(json==nil)
  2068. // return nil;
  2069. // NSError *error=nil;
  2070. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2071. // return jsobj;
  2072. //}
  2073. //+(NSDictionary*) add_toCart:(NSString* ) item_id count:(int) count name:(NSString *)name
  2074. //{
  2075. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2076. // __block AppDelegate *appDelegate = nil;
  2077. //
  2078. // dispatch_sync(dispatch_get_main_queue(), ^{
  2079. // //some UI methods ej
  2080. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2081. // });
  2082. // if(appDelegate.user!=nil)
  2083. // [params setValue:appDelegate.user forKey:@"user"];
  2084. // if(appDelegate.contact_id!=nil)
  2085. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2086. // if(appDelegate.password!=nil)
  2087. // [params setValue:appDelegate.password forKey:@"password"];
  2088. //
  2089. // if(appDelegate.order_code!=nil)
  2090. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2091. // [params setValue:item_id forKey:@"product_id"];
  2092. // [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  2093. //
  2094. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  2095. // [params setObject:@"Add To Cart" forKey:kAction];
  2096. // if (name) {
  2097. // NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  2098. // [params setObject:extra forKey:kExtra];
  2099. // }
  2100. //
  2101. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2102. //
  2103. // NSArray* keys=[customerinfo allKeys];
  2104. // for(int i=0;i<keys.count;i++)
  2105. // {
  2106. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2107. // }
  2108. //
  2109. // NSData* json=nil;
  2110. // if(appDelegate.offline_mode)
  2111. // {
  2112. // json=[OLDataProvider offline_add2cart:params];
  2113. // }
  2114. // else
  2115. // {
  2116. // if(![self IsNetworkAvailable])
  2117. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2118. //
  2119. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  2120. // }
  2121. // if(json==nil)
  2122. // return nil;
  2123. // NSError *error=nil;
  2124. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2125. //
  2126. //
  2127. //
  2128. // int result = [[jsobj valueForKey:@"result"] intValue];
  2129. //
  2130. // if (result==2)
  2131. // {
  2132. //
  2133. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2134. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2135. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2136. //
  2137. // [appDelegate update_count_mark];
  2138. // }
  2139. //
  2140. // return jsobj;
  2141. //}
  2142. //+(NSDictionary*) add_toCart_byName:(NSString* ) model_name withScreen:(NSString *)screenName
  2143. //{
  2144. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2145. // __block AppDelegate *appDelegate = nil;
  2146. //
  2147. // dispatch_sync(dispatch_get_main_queue(), ^{
  2148. // //some UI methods ej
  2149. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2150. // });
  2151. // if(appDelegate.user!=nil)
  2152. // [params setValue:appDelegate.user forKey:@"user"];
  2153. // if(appDelegate.contact_id!=nil)
  2154. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2155. // if(appDelegate.password!=nil)
  2156. // [params setValue:appDelegate.password forKey:@"password"];
  2157. //
  2158. // if(appDelegate.order_code!=nil)
  2159. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2160. // [params setValue:model_name forKey:@"product_name"];
  2161. // [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  2162. //
  2163. // [params setObject:screenName forKey:kScreenName];
  2164. // [params setObject:@"Add To Cart" forKey:kAction];
  2165. // if (!model_name) {
  2166. // model_name = @"";
  2167. // }
  2168. // [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  2169. //
  2170. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2171. //
  2172. // NSArray* keys=[customerinfo allKeys];
  2173. // for(int i=0;i<keys.count;i++)
  2174. // {
  2175. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2176. // }
  2177. // NSData* json=nil;
  2178. // if(appDelegate.offline_mode)
  2179. // {
  2180. // json= [OLDataProvider offline_add2cartbyname:params];
  2181. // }
  2182. // else
  2183. // {
  2184. // if(![self IsNetworkAvailable])
  2185. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2186. //
  2187. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  2188. // }
  2189. // if(json==nil)
  2190. // return nil;
  2191. // NSError *error=nil;
  2192. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2193. //
  2194. //
  2195. //
  2196. // int result = [[jsobj valueForKey:@"result"] intValue];
  2197. //
  2198. // if (result==2||result==8)
  2199. // {
  2200. //
  2201. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2202. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2203. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2204. //
  2205. // [appDelegate update_count_mark];
  2206. // }
  2207. //
  2208. // return jsobj;
  2209. //}
  2210. //+(NSDictionary*) new_Customer
  2211. //{
  2212. // if(![self IsNetworkAvailable])
  2213. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2214. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2215. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2216. // if(appDelegate.user!=nil)
  2217. // [params setValue:appDelegate.user forKey:@"user"];
  2218. //// if(appDelegate.contact_id!=nil)
  2219. //// [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2220. // if(appDelegate.password!=nil)
  2221. // [params setValue:appDelegate.password forKey:@"password"];
  2222. //
  2223. //// if(appDelegate.order_code!=nil)
  2224. //// [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2225. //
  2226. //
  2227. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2228. //
  2229. // NSArray* keys=[customerinfo allKeys];
  2230. // for(int i=0;i<keys.count;i++)
  2231. // {
  2232. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2233. // }
  2234. //
  2235. // NSData* json=[self get_json:URL_CUSTOMER_EDIT parameters:params];
  2236. // if(json==nil)
  2237. // return nil;
  2238. // NSError *error=nil;
  2239. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2240. // return jsobj;
  2241. //}
  2242. //+(NSDictionary*) new_Order
  2243. //{
  2244. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2245. // __block AppDelegate *appDelegate = nil;
  2246. //
  2247. // dispatch_sync(dispatch_get_main_queue(), ^{
  2248. // //some UI methods ej
  2249. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2250. // });
  2251. // if(appDelegate.user!=nil)
  2252. // [params setValue:appDelegate.user forKey:@"user"];
  2253. // if(appDelegate.contact_id!=nil)
  2254. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2255. // if(appDelegate.password!=nil)
  2256. // [params setValue:appDelegate.password forKey:@"password"];
  2257. //
  2258. // if(appDelegate.order_code!=nil)
  2259. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2260. //
  2261. //
  2262. // [params setObject:ScreenCodeOrderList forKey:kScreenName];
  2263. //
  2264. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2265. //
  2266. // NSArray* keys=[customerinfo allKeys];
  2267. // for(int i=0;i<keys.count;i++)
  2268. // {
  2269. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2270. // }
  2271. //
  2272. // NSData* json = nil;
  2273. // if(appDelegate.offline_mode)
  2274. // {
  2275. // json= [OLDataProvider offline_createorder:params];
  2276. // }
  2277. // else
  2278. // {
  2279. // if(![self IsNetworkAvailable])
  2280. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2281. //
  2282. // json=[self get_json:URL_NEW_ORDER parameters:params];
  2283. // }
  2284. // if(json==nil)
  2285. // return nil;
  2286. // NSError *error=nil;
  2287. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2288. // int result = [[jsobj valueForKey:@"result"] intValue];
  2289. //
  2290. // if (result==2)
  2291. // {
  2292. //
  2293. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2294. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2295. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2296. //
  2297. // [appDelegate update_count_mark];
  2298. // }
  2299. //
  2300. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  2301. //
  2302. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  2303. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  2304. // }
  2305. //
  2306. // return jsobj;
  2307. //}
  2308. +(NSDictionary*) add_toPortfolio:(NSString* ) item_id withScreen:(NSString *)screenName
  2309. {
  2310. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2311. __block AppDelegate *appDelegate = nil;
  2312. dispatch_sync(dispatch_get_main_queue(), ^{
  2313. //some UI methods ej
  2314. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2315. });
  2316. if(appDelegate.user!=nil)
  2317. [params setValue:appDelegate.user forKey:@"user"];
  2318. if(appDelegate.contact_id!=nil)
  2319. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2320. if(appDelegate.password!=nil)
  2321. [params setValue:appDelegate.password forKey:@"password"];
  2322. [params setValue:item_id forKey:@"product_id"];
  2323. [params setObject:screenName forKey:kScreenName];
  2324. NSData* json = nil;
  2325. if(appDelegate.offline_mode)
  2326. {
  2327. json = [OLDataProvider offline_add2Portfolio:params];
  2328. } else {
  2329. if(![self IsNetworkAvailable])
  2330. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2331. json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  2332. }
  2333. if(json==nil)
  2334. return nil;
  2335. NSError *error=nil;
  2336. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2337. int result = [[jsobj valueForKey:@"result"] intValue];
  2338. if (result==2)
  2339. {
  2340. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2341. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2342. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2343. [appDelegate update_count_mark];
  2344. }
  2345. return jsobj;
  2346. }
  2347. //+(NSDictionary*) add_toWatchList:(NSString* ) item_id withScreen:(NSString *)screenName
  2348. //{
  2349. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2350. // __block AppDelegate *appDelegate = nil;
  2351. //
  2352. // dispatch_sync(dispatch_get_main_queue(), ^{
  2353. // //some UI methods ej
  2354. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2355. // });
  2356. // if(appDelegate.user!=nil)
  2357. // [params setValue:appDelegate.user forKey:@"user"];
  2358. // if(appDelegate.contact_id!=nil)
  2359. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2360. // if(appDelegate.password!=nil)
  2361. // [params setValue:appDelegate.password forKey:@"password"];
  2362. //
  2363. //
  2364. // [params setValue:item_id forKey:@"product_id"];
  2365. //
  2366. // [params setObject:screenName forKey:kScreenName];
  2367. //
  2368. // if(appDelegate.offline_mode)
  2369. // {
  2370. // return [OLDataProvider offline_add2wishlist:params];
  2371. // }
  2372. // if(![self IsNetworkAvailable])
  2373. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2374. //
  2375. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  2376. // if(json==nil)
  2377. // return nil;
  2378. // NSError *error=nil;
  2379. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2380. // int result = [[jsobj valueForKey:@"result"] intValue];
  2381. //
  2382. // if (result==2)
  2383. // {
  2384. //
  2385. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2386. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2387. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2388. //
  2389. // [appDelegate update_count_mark];
  2390. // }
  2391. // return jsobj;
  2392. //}
  2393. //+(NSDictionary*) cart_setPrice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes
  2394. //{
  2395. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2396. // __block AppDelegate *appDelegate = nil;
  2397. //
  2398. // dispatch_sync(dispatch_get_main_queue(), ^{
  2399. // //some UI methods ej
  2400. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2401. // });
  2402. // if(appDelegate.user!=nil)
  2403. // [params setValue:appDelegate.user forKey:@"user"];
  2404. // if(appDelegate.contact_id!=nil)
  2405. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2406. // if(appDelegate.password!=nil)
  2407. // [params setValue:appDelegate.password forKey:@"password"];
  2408. //
  2409. // [params setValue:cart_id forKey:@"cartitem_id"];
  2410. // [params setValue:notes forKey:@"item_note"];
  2411. //
  2412. // [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  2413. //
  2414. // [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  2415. //
  2416. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2417. //
  2418. // NSData* json= nil;
  2419. // if(appDelegate.offline_mode)
  2420. // {
  2421. // json=[OLDataProvider offline_cartsetprice:params];
  2422. // }
  2423. // else
  2424. // {
  2425. // if(![self IsNetworkAvailable])
  2426. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2427. //
  2428. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2429. // }
  2430. // if(json==nil)
  2431. // return nil;
  2432. // NSError *error=nil;
  2433. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2434. // return jsobj;
  2435. //}
  2436. //+(NSDictionary*) portfolio_setQTY:(NSString*) watchlist_id QTY:(int)qty
  2437. //{
  2438. // if(![self IsNetworkAvailable])
  2439. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2440. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2441. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2442. // if(appDelegate.user!=nil)
  2443. // [params setValue:appDelegate.user forKey:@"user"];
  2444. // if(appDelegate.contact_id!=nil)
  2445. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2446. // if(appDelegate.password!=nil)
  2447. // [params setValue:appDelegate.password forKey:@"password"];
  2448. //
  2449. // [params setValue:watchlist_id forKey:@"item_id"];
  2450. //
  2451. // [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  2452. //
  2453. //
  2454. //
  2455. // NSData* json=[self get_json:URL_DM_SET_QTY parameters:params];
  2456. // if(json==nil)
  2457. // return nil;
  2458. // NSError *error=nil;
  2459. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2460. // return jsobj;
  2461. //}
  2462. +(NSDictionary*) portfolio_setPrice:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes
  2463. {
  2464. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2465. __block AppDelegate *appDelegate = nil;
  2466. dispatch_sync(dispatch_get_main_queue(), ^{
  2467. //some UI methods ej
  2468. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2469. });
  2470. if(appDelegate.user!=nil)
  2471. [params setValue:appDelegate.user forKey:@"user"];
  2472. if(appDelegate.contact_id!=nil)
  2473. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2474. if(appDelegate.password!=nil)
  2475. [params setValue:appDelegate.password forKey:@"password"];
  2476. [params setValue:watchlist_id forKey:@"item_id"];
  2477. // if(notes.length>0)
  2478. // [params setValue:notes forKey:@"notes"];
  2479. if(notes)
  2480. [params setValue:notes forKey:@"notes"];
  2481. if(price != -MAXFLOAT)
  2482. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  2483. if (discount != -MAXFLOAT)
  2484. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  2485. if(qty_p != -MAXFLOAT)
  2486. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  2487. if(qty != -INT32_MAX)
  2488. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  2489. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2490. NSData* json = nil;
  2491. if(appDelegate.offline_mode)
  2492. {
  2493. json = [OLDataProvider offline_editPortfolio:params];
  2494. } else {
  2495. if(![self IsNetworkAvailable])
  2496. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2497. json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  2498. }
  2499. if(json==nil)
  2500. return nil;
  2501. NSError *error=nil;
  2502. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2503. return jsobj;
  2504. }
  2505. //+(NSDictionary*) cart_setGeneralNote:(NSString*) order_code notes:(NSString*) notes
  2506. //{
  2507. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2508. // __block AppDelegate *appDelegate = nil;
  2509. //
  2510. // dispatch_sync(dispatch_get_main_queue(), ^{
  2511. // //some UI methods ej
  2512. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2513. // });
  2514. // if(appDelegate.user!=nil)
  2515. // [params setValue:appDelegate.user forKey:@"user"];
  2516. // if(appDelegate.contact_id!=nil)
  2517. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2518. // if(appDelegate.password!=nil)
  2519. // [params setValue:appDelegate.password forKey:@"password"];
  2520. //
  2521. // [params setValue:order_code forKey:@"orderCode"];
  2522. //
  2523. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2524. //
  2525. // if(notes.length==0)
  2526. // notes=@"";
  2527. //
  2528. //
  2529. // [params setValue:notes forKey:@"comments"];
  2530. // NSData* json=nil;
  2531. // if(appDelegate.offline_mode)
  2532. // {
  2533. // json= [OLDataProvider offline_updategnotes:params];
  2534. // }
  2535. // else
  2536. // {
  2537. // if(![self IsNetworkAvailable])
  2538. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2539. //
  2540. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  2541. // }
  2542. // if(json==nil)
  2543. // return nil;
  2544. // NSError *error=nil;
  2545. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2546. // return jsobj;
  2547. //}
  2548. //+(NSDictionary*) cart_setItemNote:(NSString*) cart_id notes:(NSString*) notes
  2549. //{
  2550. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2551. // __block AppDelegate *appDelegate = nil;
  2552. //
  2553. // dispatch_sync(dispatch_get_main_queue(), ^{
  2554. // //some UI methods ej
  2555. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2556. // });
  2557. // if(appDelegate.user!=nil)
  2558. // [params setValue:appDelegate.user forKey:@"user"];
  2559. // if(appDelegate.contact_id!=nil)
  2560. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2561. // if(appDelegate.password!=nil)
  2562. // [params setValue:appDelegate.password forKey:@"password"];
  2563. //
  2564. // [params setValue:cart_id forKey:@"cartitem_id"];
  2565. //
  2566. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2567. //
  2568. // if(notes.length==0)
  2569. // notes=@"";
  2570. //
  2571. //
  2572. // [params setValue:notes forKey:@"notes"];
  2573. // NSData* json=nil;
  2574. // if(appDelegate.offline_mode)
  2575. // {
  2576. // json= [OLDataProvider offline_cartsetlnotes:params];
  2577. // }
  2578. // else
  2579. // {
  2580. // if(![self IsNetworkAvailable])
  2581. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2582. //
  2583. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  2584. // }
  2585. // if(json==nil)
  2586. // return nil;
  2587. // NSError *error=nil;
  2588. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2589. // return jsobj;
  2590. //}
  2591. //+(NSDictionary*) cart_setFree:(NSString*) cart_id isfree:(bool) isfree
  2592. //{
  2593. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2594. // __block AppDelegate *appDelegate = nil;
  2595. //
  2596. // dispatch_sync(dispatch_get_main_queue(), ^{
  2597. // //some UI methods ej
  2598. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2599. // });
  2600. // if(appDelegate.user!=nil)
  2601. // [params setValue:appDelegate.user forKey:@"user"];
  2602. // if(appDelegate.contact_id!=nil)
  2603. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2604. // if(appDelegate.password!=nil)
  2605. // [params setValue:appDelegate.password forKey:@"password"];
  2606. //
  2607. // [params setValue:cart_id forKey:@"cartitem_id"];
  2608. //
  2609. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2610. //
  2611. // NSString* free=nil;
  2612. //
  2613. // if(isfree)
  2614. // free=@"true";
  2615. // else
  2616. // free=@"false";
  2617. //
  2618. // [params setValue:free forKey:@"free_giveaway"];
  2619. //
  2620. // if(appDelegate.offline_mode)
  2621. // {
  2622. // return [OLDataProvider offline_notimpl];
  2623. // }
  2624. // if(![self IsNetworkAvailable])
  2625. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2626. //
  2627. // NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2628. // if(json==nil)
  2629. // return nil;
  2630. // NSError *error=nil;
  2631. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2632. // return jsobj;
  2633. //}
  2634. //+(NSDictionary*) cart_setQTY:(NSString*) cart_id value:(int) value
  2635. //{
  2636. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2637. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2638. // if(appDelegate.user!=nil)
  2639. // [params setValue:appDelegate.user forKey:@"user"];
  2640. // if(appDelegate.contact_id!=nil)
  2641. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2642. // if(appDelegate.password!=nil)
  2643. // [params setValue:appDelegate.password forKey:@"password"];
  2644. //
  2645. // [params setValue:cart_id forKey:@"cartitem_id"];
  2646. //
  2647. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2648. //
  2649. // [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  2650. //
  2651. // NSData* json=nil;
  2652. // if(appDelegate.offline_mode)
  2653. // {
  2654. // json= [OLDataProvider offline_cartsetqty:params];
  2655. // }
  2656. // else
  2657. // {
  2658. // if(![self IsNetworkAvailable])
  2659. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2660. //
  2661. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2662. // }
  2663. // if(json==nil)
  2664. // return nil;
  2665. // NSError *error=nil;
  2666. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2667. // return jsobj;
  2668. //
  2669. //}
  2670. //+(NSDictionary*) cart_incresement:(NSString*) cart_id increse:(bool) increse
  2671. //{
  2672. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2673. // __block AppDelegate *appDelegate = nil;
  2674. //
  2675. // dispatch_sync(dispatch_get_main_queue(), ^{
  2676. // //some UI methods ej
  2677. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2678. // });
  2679. // if(appDelegate.user!=nil)
  2680. // [params setValue:appDelegate.user forKey:@"user"];
  2681. // if(appDelegate.contact_id!=nil)
  2682. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2683. // if(appDelegate.password!=nil)
  2684. // [params setValue:appDelegate.password forKey:@"password"];
  2685. //
  2686. // [params setValue:cart_id forKey:@"cartitem_id"];
  2687. //
  2688. // if(increse)
  2689. // [params setValue:@"1" forKey:@"incrementType"];
  2690. // else
  2691. // [params setValue:@"0" forKey:@"incrementType"];
  2692. //
  2693. //
  2694. //
  2695. // if(appDelegate.offline_mode)
  2696. // {
  2697. // return [OLDataProvider offline_notimpl];
  2698. // }
  2699. // if(![self IsNetworkAvailable])
  2700. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2701. //
  2702. // NSData* json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2703. // if(json==nil)
  2704. // return nil;
  2705. // NSError *error=nil;
  2706. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2707. // return jsobj;
  2708. //}
  2709. +(NSDictionary*) finish_download_Offline:(NSString* )vid
  2710. {
  2711. if(![self IsNetworkAvailable])
  2712. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2713. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2714. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  2715. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2716. // if(appDelegate.user!=nil)
  2717. // [params setValue:appDelegate.user forKey:@"user"];
  2718. // // if(appDelegate.contact_id!=nil)
  2719. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2720. // if(appDelegate.password!=nil)
  2721. // [params setValue:appDelegate.password forKey:@"password"];
  2722. [params setValue:vid forKey:@"downSerial"];
  2723. NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  2724. if(json==nil)
  2725. return nil;
  2726. NSError *error=nil;
  2727. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2728. // int result = [[jsobj valueForKey:@"result"] intValue];
  2729. //
  2730. // if (result==2)
  2731. // {
  2732. //
  2733. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2734. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2735. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2736. ////
  2737. //// [appDelegate update_count_mark];
  2738. // }
  2739. return jsobj;
  2740. }
  2741. +(NSDictionary*) download_Offline:(NSString* )vid
  2742. {
  2743. if(![self IsNetworkAvailable])
  2744. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2745. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2746. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2747. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2748. // if(appDelegate.user!=nil)
  2749. // [params setValue:appDelegate.user forKey:@"user"];
  2750. // // if(appDelegate.contact_id!=nil)
  2751. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2752. // if(appDelegate.password!=nil)
  2753. // [params setValue:appDelegate.password forKey:@"password"];
  2754. [params setValue:vid forKey:@"downSerial"];
  2755. NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  2756. if(json==nil)
  2757. return nil;
  2758. NSError *error=nil;
  2759. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2760. // int result = [[jsobj valueForKey:@"result"] intValue];
  2761. //
  2762. // if (result==2)
  2763. // {
  2764. //
  2765. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2766. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2767. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2768. ////
  2769. //// [appDelegate update_count_mark];
  2770. // }
  2771. return jsobj;
  2772. }
  2773. +(NSDictionary*) check_Offline:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid
  2774. {
  2775. if(![self IsNetworkAvailable])
  2776. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2777. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2778. __block AppDelegate *appDelegate = nil;
  2779. dispatch_sync(dispatch_get_main_queue(), ^{
  2780. //some UI methods ej
  2781. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2782. });
  2783. if(appDelegate.user!=nil)
  2784. [params setValue:appDelegate.user forKey:@"user"];
  2785. // if(appDelegate.contact_id!=nil)
  2786. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2787. if(appDelegate.password!=nil)
  2788. [params setValue:appDelegate.password forKey:@"password"];
  2789. [params setValue:ver forKey:@"ver"];
  2790. [params setValue:vid forKey:@"vid"];
  2791. if(buseinternaladdress)
  2792. [params setValue:@"true" forKey:@"internal_address"];
  2793. else
  2794. [params setValue:@"false" forKey:@"internal_address"];
  2795. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2796. NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  2797. if(json==nil)
  2798. return nil;
  2799. NSError *error=nil;
  2800. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2801. // int result = [[jsobj valueForKey:@"result"] intValue];
  2802. //
  2803. // if (result==2)
  2804. // {
  2805. //
  2806. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2807. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2808. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2809. ////
  2810. //// [appDelegate update_count_mark];
  2811. // }
  2812. return jsobj;
  2813. }
  2814. //+(NSDictionary*)request_Cart:(int)sort
  2815. //{
  2816. //
  2817. // DebugLog(@"iSalesNetwork::request_Cart");
  2818. //
  2819. //
  2820. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2821. // __block AppDelegate *appDelegate = nil;
  2822. //
  2823. // dispatch_sync(dispatch_get_main_queue(), ^{
  2824. // //some UI methods ej
  2825. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2826. // });
  2827. // if(appDelegate.user!=nil)
  2828. // [params setValue:appDelegate.user forKey:@"user"];
  2829. // // if(appDelegate.contact_id!=nil)
  2830. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2831. // if(appDelegate.password!=nil)
  2832. // [params setValue:appDelegate.password forKey:@"password"];
  2833. //
  2834. // if(appDelegate.order_code!=nil)
  2835. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2836. //
  2837. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2838. //
  2839. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2840. //
  2841. // NSData* json=nil;
  2842. // if(appDelegate.offline_mode)
  2843. // {
  2844. // json= [OLDataProvider offline_requestcart:params];
  2845. // }
  2846. // else
  2847. // {
  2848. // if(![self IsNetworkAvailable])
  2849. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2850. //
  2851. // NSError *error=nil;
  2852. //
  2853. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2854. // params[@"resultSerial"]=uuid;
  2855. //
  2856. // for(int i=0;i<150;i++)
  2857. // {
  2858. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2859. // // result_params[@"resultSerial"]=uuid;
  2860. // json=[self get_json:URL_CART parameters:params];
  2861. // if(json!=nil)
  2862. // {
  2863. //
  2864. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2865. // if([jsobj[@"result"] intValue]==2)
  2866. // {
  2867. // break;
  2868. // }
  2869. // }
  2870. // sleep(2);
  2871. // }
  2872. //
  2873. // }
  2874. // if(json==nil)
  2875. // return nil;
  2876. // NSError *error=nil;
  2877. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2878. // int result = [[jsobj valueForKey:@"result"] intValue];
  2879. //
  2880. // if (result==2)
  2881. // {
  2882. //
  2883. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2884. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2885. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2886. //
  2887. // [appDelegate update_count_mark];
  2888. // }
  2889. // return jsobj;
  2890. //}
  2891. //+(NSDictionary*)request_Portfolio:(int)sort
  2892. //{
  2893. //
  2894. //
  2895. //
  2896. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2897. // __block AppDelegate *appDelegate = nil;
  2898. //
  2899. // dispatch_sync(dispatch_get_main_queue(), ^{
  2900. // //some UI methods ej
  2901. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2902. // });
  2903. // if(appDelegate.user!=nil)
  2904. // [params setValue:appDelegate.user forKey:@"user"];
  2905. // if(appDelegate.contact_id!=nil)
  2906. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2907. // if(appDelegate.password!=nil)
  2908. // [params setValue:appDelegate.password forKey:@"password"];
  2909. //
  2910. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2911. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2912. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2913. //
  2914. // [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2915. //
  2916. // NSData* json = nil;
  2917. // if(appDelegate.offline_mode)
  2918. // {
  2919. // json = [OLDataProvider offline_portfolioList:params];
  2920. // } else {
  2921. // if(![self IsNetworkAvailable])
  2922. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2923. //
  2924. // json = [self get_json:URL_PORTFOLIO parameters:params];
  2925. // }
  2926. //
  2927. //
  2928. // if(json==nil)
  2929. // return nil;
  2930. // NSError *error=nil;
  2931. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2932. // int result = [[jsobj valueForKey:@"result"] intValue];
  2933. //
  2934. // if (result==2)
  2935. // {
  2936. //
  2937. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2938. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2939. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  2940. //
  2941. // [appDelegate update_count_mark];
  2942. // }
  2943. // return jsobj;
  2944. //}
  2945. //+(NSDictionary*)request_WatchList:(int)sort
  2946. //{
  2947. //
  2948. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2949. // __block AppDelegate *appDelegate = nil;
  2950. //
  2951. // dispatch_sync(dispatch_get_main_queue(), ^{
  2952. // //some UI methods ej
  2953. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2954. // });
  2955. // if(appDelegate.user!=nil)
  2956. // [params setValue:appDelegate.user forKey:@"user"];
  2957. // if(appDelegate.contact_id!=nil)
  2958. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2959. // if(appDelegate.password!=nil)
  2960. // [params setValue:appDelegate.password forKey:@"password"];
  2961. //
  2962. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2963. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2964. //
  2965. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2966. //
  2967. // [params setObject:ScreenCodeWishList forKey:kScreenName];
  2968. //
  2969. // if(appDelegate.offline_mode)
  2970. // {
  2971. // return [OLDataProvider offline_wishlist:params];
  2972. // }
  2973. // if(![self IsNetworkAvailable])
  2974. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2975. //
  2976. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  2977. // if(json==nil)
  2978. // return nil;
  2979. // NSError *error=nil;
  2980. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2981. // int result = [[jsobj valueForKey:@"result"] intValue];
  2982. //
  2983. // if (result==2)
  2984. // {
  2985. //
  2986. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2987. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2988. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2989. //
  2990. // [appDelegate update_count_mark];
  2991. // }
  2992. // return jsobj;
  2993. //}
  2994. //+(NSDictionary*)request_ItemDetail: (NSString* ) item_id model_name:(NSString*) model_name category_id:(NSString*) category_id use_name :(bool) use_name groupName:(NSString *)groupName
  2995. //{
  2996. //
  2997. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2998. // __block AppDelegate *appDelegate = nil;
  2999. //
  3000. // dispatch_sync(dispatch_get_main_queue(), ^{
  3001. // //some UI methods ej
  3002. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3003. // });
  3004. // if(appDelegate.user!=nil)
  3005. // [params setValue:appDelegate.user forKey:@"user"];
  3006. // if(appDelegate.contact_id!=nil)
  3007. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3008. // if(appDelegate.password!=nil)
  3009. // [params setValue:appDelegate.password forKey:@"password"];
  3010. // if(appDelegate.order_code!=nil)
  3011. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3012. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3013. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3014. // if(use_name)
  3015. // [params setValue:model_name forKey:@"product_name"];
  3016. // else
  3017. // [params setValue:item_id forKey:@"product_id"];
  3018. //
  3019. //
  3020. // [params setValue:category_id forKey:@"category"];
  3021. //
  3022. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  3023. // [params setObject:@"Open A Model" forKey:kAction];
  3024. // if (model_name) {
  3025. // NSDictionary *extra = @{@"ModelName" : model_name};
  3026. // [params setObject:extra forKey:kExtra];
  3027. // }
  3028. //
  3029. // if (groupName.length > 0) {
  3030. // [params setObject:groupName forKey:@"groupName"];
  3031. // }
  3032. //
  3033. // if(appDelegate.offline_mode)
  3034. // return [OLDataProvider offline_model:params];
  3035. //
  3036. // if(![self IsNetworkAvailable])
  3037. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3038. //
  3039. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  3040. // if(json==nil)
  3041. // return nil;
  3042. // NSError *error=nil;
  3043. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3044. // return jsobj;
  3045. //}
  3046. //+(NSDictionary*)category_LoadMore: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(int)offset
  3047. //{
  3048. // if(![self IsNetworkAvailable])
  3049. // return nil;
  3050. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3051. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3052. // if(appDelegate.user!=nil)
  3053. // [params setValue:appDelegate.user forKey:@"user"];
  3054. // if(appDelegate.contact_id!=nil)
  3055. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3056. // if(appDelegate.password!=nil)
  3057. // [params setValue:appDelegate.password forKey:@"password"];
  3058. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3059. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3060. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3061. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3062. // [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  3063. // [params setValue:filter forKey:@"filter"];
  3064. // [params setValue:keyword forKey:@"keyword"];
  3065. //
  3066. //
  3067. // NSData* json=[self get_json:URL_CATEGORY_LOADMORE parameters:params];
  3068. // if(json==nil)
  3069. // return nil;
  3070. // NSError *error=nil;
  3071. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3072. // return jsobj;
  3073. //
  3074. //}
  3075. //+(NSDictionary*)Category_addall: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  3076. //
  3077. //{
  3078. //
  3079. //
  3080. // __block AppDelegate *appDelegate = nil;
  3081. //
  3082. // dispatch_sync(dispatch_get_main_queue(), ^{
  3083. // //some UI methods ej
  3084. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3085. // });
  3086. //
  3087. //
  3088. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3089. //
  3090. // if(appDelegate.user!=nil)
  3091. // [params setValue:appDelegate.user forKey:@"user"];
  3092. // if(appDelegate.contact_id!=nil)
  3093. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3094. // if(appDelegate.password!=nil)
  3095. // [params setValue:appDelegate.password forKey:@"password"];
  3096. // if(appDelegate.order_code!=nil)
  3097. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3098. //
  3099. // [params setValue:addTo forKey:@"addTo"];
  3100. // [params setValue:orderCode forKey:@"orderCode"];
  3101. // [params setValue:alert forKey:@"alert"];
  3102. // [params setValue:qty forKey:@"sold_by_qty"];
  3103. // [params setValue:available forKey:@"available"];
  3104. // [params setValue:price forKey:@"price"];
  3105. // [params setValue:bestseller forKey:@"bestseller"];
  3106. // [params setValue:modelname forKey:@"modelName"];
  3107. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3108. //
  3109. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3110. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3111. // [params setValue:category forKey:@"category"];
  3112. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3113. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3114. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3115. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3116. // [params setValue:filter forKey:@"filter"];
  3117. // [params setValue:keyword forKey:@"keyword"];
  3118. //
  3119. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  3120. // if ([addTo isEqualToString:@"cart"]) {
  3121. // [params setObject:@"Add To Cart" forKey:kAction];
  3122. // }
  3123. //
  3124. //
  3125. // NSData* json= nil;
  3126. //
  3127. // if(appDelegate.offline_mode)
  3128. // {
  3129. // json= [OLDataProvider offline_categoryaddall:params];
  3130. // }
  3131. // else
  3132. // {
  3133. // if(![self IsNetworkAvailable])
  3134. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3135. //
  3136. //
  3137. // NSError *error=nil;
  3138. //
  3139. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3140. // params[@"resultSerial"]=uuid;
  3141. //
  3142. // for(int i=0;i<150;i++)
  3143. // {
  3144. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3145. // // result_params[@"resultSerial"]=uuid;
  3146. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  3147. // if(json!=nil)
  3148. // {
  3149. //
  3150. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3151. // int resultInt = [jsobj[@"result"] intValue];
  3152. // if(resultInt == 2 || resultInt == 8)
  3153. // {
  3154. // break;
  3155. // }
  3156. // }
  3157. // sleep(2);
  3158. // }
  3159. //
  3160. //
  3161. //
  3162. // }
  3163. // if(json==nil)
  3164. // return nil;
  3165. // NSError *error=nil;
  3166. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3167. // return jsobj;
  3168. //
  3169. //}
  3170. //+(NSDictionary*)category_addall2portfolio: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip
  3171. //{
  3172. //
  3173. //
  3174. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3175. //
  3176. //
  3177. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3178. //
  3179. // if(appDelegate.user!=nil)
  3180. // [params setValue:appDelegate.user forKey:@"user"];
  3181. // if(appDelegate.contact_id!=nil)
  3182. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3183. // if(appDelegate.password!=nil)
  3184. // [params setValue:appDelegate.password forKey:@"password"];
  3185. // if(appDelegate.order_code!=nil)
  3186. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3187. //
  3188. // [params setValue:alert forKey:@"alert"];
  3189. // [params setValue:qty forKey:@"sold_by_qty"];
  3190. // [params setValue:available forKey:@"available"];
  3191. // [params setValue:price forKey:@"price"];
  3192. // [params setValue:bestseller forKey:@"bestseller"];
  3193. // [params setValue:modelname forKey:@"modelName"];
  3194. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3195. //
  3196. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3197. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3198. // [params setValue:category forKey:@"category"];
  3199. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3200. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3201. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3202. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3203. // [params setValue:filter forKey:@"filter"];
  3204. // [params setValue:keyword forKey:@"keyword"];
  3205. //
  3206. //
  3207. //
  3208. // if(appDelegate.offline_mode)
  3209. // return [OLDataProvider offline_category:params];
  3210. // if(![self IsNetworkAvailable])
  3211. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3212. //
  3213. // NSData* json=[self get_json:URL_ADDALL2PORTFOLIO parameters:params];
  3214. // if(json==nil)
  3215. // return nil;
  3216. // NSError *error=nil;
  3217. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3218. // return jsobj;
  3219. //
  3220. //}
  3221. //+(NSDictionary*)category_addall2wish: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip
  3222. //{
  3223. //
  3224. //
  3225. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3226. //
  3227. //
  3228. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3229. //
  3230. // if(appDelegate.user!=nil)
  3231. // [params setValue:appDelegate.user forKey:@"user"];
  3232. // if(appDelegate.contact_id!=nil)
  3233. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3234. // if(appDelegate.password!=nil)
  3235. // [params setValue:appDelegate.password forKey:@"password"];
  3236. // if(appDelegate.order_code!=nil)
  3237. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3238. //
  3239. // [params setValue:alert forKey:@"alert"];
  3240. // [params setValue:qty forKey:@"sold_by_qty"];
  3241. // [params setValue:available forKey:@"available"];
  3242. // [params setValue:price forKey:@"price"];
  3243. // [params setValue:bestseller forKey:@"bestseller"];
  3244. // [params setValue:modelname forKey:@"modelName"];
  3245. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3246. //
  3247. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3248. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3249. // [params setValue:category forKey:@"category"];
  3250. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3251. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3252. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3253. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3254. // [params setValue:filter forKey:@"filter"];
  3255. // [params setValue:keyword forKey:@"keyword"];
  3256. //
  3257. //
  3258. //
  3259. // if(appDelegate.offline_mode)
  3260. // return [OLDataProvider offline_category:params];
  3261. // if(![self IsNetworkAvailable])
  3262. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3263. //
  3264. // NSData* json=[self get_json:URL_ADDALL2WISH parameters:params];
  3265. // if(json==nil)
  3266. // return nil;
  3267. // NSError *error=nil;
  3268. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3269. // return jsobj;
  3270. //
  3271. //}
  3272. //+(NSDictionary*)Category: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip
  3273. //{
  3274. //
  3275. //
  3276. // __block AppDelegate *appDelegate = nil;
  3277. //
  3278. // dispatch_sync(dispatch_get_main_queue(), ^{
  3279. // //some UI methods ej
  3280. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3281. // });
  3282. //
  3283. //
  3284. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3285. //
  3286. // if(appDelegate.user!=nil)
  3287. // [params setValue:appDelegate.user forKey:@"user"];
  3288. // if(appDelegate.contact_id!=nil)
  3289. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3290. // if(appDelegate.password!=nil)
  3291. // [params setValue:appDelegate.password forKey:@"password"];
  3292. // if(appDelegate.order_code!=nil)
  3293. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3294. //
  3295. // [params setValue:alert forKey:@"alert"];
  3296. // [params setValue:qty forKey:@"sold_by_qty"];
  3297. // [params setValue:available forKey:@"available"];
  3298. // [params setValue:price forKey:@"price"];
  3299. // [params setValue:bestseller forKey:@"bestseller"];
  3300. // [params setValue:modelname forKey:@"modelName"];
  3301. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3302. //
  3303. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3304. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3305. // [params setValue:category forKey:@"category"];
  3306. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3307. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3308. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3309. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3310. // [params setValue:filter forKey:@"filter"];
  3311. // [params setValue:keyword forKey:@"keyword"];
  3312. //
  3313. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  3314. // if (alert) {
  3315. // [params setObject:@"Filter" forKey:kAction];
  3316. // }
  3317. // if ([Singleton sharedInstance].homeItemClick) {
  3318. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  3319. // [Singleton sharedInstance].homeItemClick = NO;
  3320. //
  3321. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  3322. // [Singleton sharedInstance].homeClickedItemName = nil;
  3323. // [params setObject:extra forKey:kExtra];
  3324. //
  3325. // }
  3326. //
  3327. //
  3328. // if(appDelegate.offline_mode)
  3329. // return [OLDataProvider offline_category:params];
  3330. // if(![self IsNetworkAvailable])
  3331. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3332. //
  3333. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  3334. // if(json==nil)
  3335. // return nil;
  3336. // NSError *error=nil;
  3337. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3338. // return jsobj;
  3339. //
  3340. //}
  3341. //+(NSDictionary*)Search_addall:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  3342. //{
  3343. //
  3344. //
  3345. //
  3346. //
  3347. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3348. // __block AppDelegate *appDelegate = nil;
  3349. //
  3350. // dispatch_sync(dispatch_get_main_queue(), ^{
  3351. // //some UI methods ej
  3352. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3353. // });
  3354. // if(appDelegate.user!=nil)
  3355. // [params setValue:appDelegate.user forKey:@"user"];
  3356. // if(appDelegate.contact_id!=nil)
  3357. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3358. // if(appDelegate.password!=nil)
  3359. // [params setValue:appDelegate.password forKey:@"password"];
  3360. // if(appDelegate.order_code!=nil)
  3361. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3362. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3363. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3364. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3365. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3366. // // [params setValue:filter forKey:@"filter"];
  3367. // [params setValue:keywords forKey:@"keyword"];
  3368. // [params setValue:addTo forKey:@"addTo"];
  3369. //
  3370. // [params setValue:orderCode forKey:@"orderCode"];
  3371. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3372. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3373. // if(matchfull)
  3374. // [params setValue:@"true" forKey:@"exactMatch"];
  3375. // else
  3376. // [params setValue:@"false" forKey:@"exactMatch"];
  3377. //
  3378. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  3379. // if ([addTo isEqualToString:@"cart"]) {
  3380. // [params setObject:@"Add To Cart" forKey:kAction];
  3381. // }
  3382. //
  3383. // NSData* json=nil;
  3384. // if(appDelegate.offline_mode)
  3385. // {
  3386. // json=[OLDataProvider offline_searchaddall:params];
  3387. // }
  3388. // else
  3389. // {
  3390. // if(![self IsNetworkAvailable])
  3391. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3392. //
  3393. // NSError *error=nil;
  3394. //
  3395. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3396. // params[@"resultSerial"]=uuid;
  3397. //
  3398. // for(int i=0;i<150;i++)
  3399. // {
  3400. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3401. // // result_params[@"resultSerial"]=uuid;
  3402. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  3403. // if(json!=nil)
  3404. // {
  3405. //
  3406. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3407. // if([jsobj[@"result"] intValue]==2)
  3408. // {
  3409. // break;
  3410. // }
  3411. // }
  3412. // sleep(2);
  3413. // }
  3414. // }
  3415. // if(json==nil)
  3416. // return nil;
  3417. // NSError *error=nil;
  3418. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3419. // return jsobj;
  3420. //
  3421. //}
  3422. //+(NSDictionary*)Search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull
  3423. //{
  3424. //
  3425. //
  3426. //
  3427. //
  3428. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3429. // __block AppDelegate *appDelegate = nil;
  3430. //
  3431. // dispatch_sync(dispatch_get_main_queue(), ^{
  3432. // //some UI methods ej
  3433. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3434. // });
  3435. // if(appDelegate.user!=nil)
  3436. // [params setValue:appDelegate.user forKey:@"user"];
  3437. // if(appDelegate.contact_id!=nil)
  3438. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3439. // if(appDelegate.password!=nil)
  3440. // [params setValue:appDelegate.password forKey:@"password"];
  3441. // if(appDelegate.order_code!=nil)
  3442. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3443. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3444. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3445. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3446. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3447. // // [params setValue:filter forKey:@"filter"];
  3448. // [params setValue:keywords forKey:@"keyword"];
  3449. //
  3450. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3451. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3452. // if(matchfull)
  3453. // [params setValue:@"true" forKey:@"exactMatch"];
  3454. // else
  3455. // [params setValue:@"false" forKey:@"exactMatch"];
  3456. //
  3457. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  3458. // if (keywords) {
  3459. // [params setObject:@"Search" forKey:kAction];
  3460. // }
  3461. //
  3462. // if(appDelegate.offline_mode)
  3463. // {
  3464. // return [OLDataProvider offline_search:params];
  3465. // }
  3466. // if(![self IsNetworkAvailable])
  3467. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3468. //
  3469. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3470. // if(json==nil)
  3471. // return nil;
  3472. // NSError *error=nil;
  3473. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3474. // return jsobj;
  3475. //}
  3476. //+(NSDictionary*)ItemSearch_addall:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  3477. //{
  3478. // // for debug
  3479. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3480. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3481. //
  3482. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3483. // __block AppDelegate *appDelegate = nil;
  3484. //
  3485. // dispatch_sync(dispatch_get_main_queue(), ^{
  3486. // //some UI methods ej
  3487. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3488. // });
  3489. // if(appDelegate.user!=nil)
  3490. // [params setValue:appDelegate.user forKey:@"user"];
  3491. // if(appDelegate.contact_id!=nil)
  3492. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3493. // if(appDelegate.password!=nil)
  3494. // [params setValue:appDelegate.password forKey:@"password"];
  3495. // if(appDelegate.order_code!=nil)
  3496. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3497. //
  3498. // [params setValue:addTo forKey:@"addTo"];
  3499. //
  3500. // [params setValue:orderCode forKey:@"orderCode"];
  3501. //
  3502. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3503. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3504. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3505. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3506. // // [params setValue:filter forKey:@"filter"];
  3507. // [params setValue:covertype forKey:@"covertype"];
  3508. // [params setValue:ctgid forKey:@"ctgId"];
  3509. // [params setValue:modelname forKey:@"modelName"];
  3510. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3511. // [params setValue:alert forKey:@"alert"];
  3512. // [params setValue:qty forKey:@"sold_by_qty"];
  3513. // [params setValue:available forKey:@"available"];
  3514. // [params setValue:price forKey:@"price"];
  3515. // [params setValue:bestseller forKey:@"bestseller"];
  3516. //
  3517. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3518. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3519. //
  3520. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3521. // if ([addTo isEqualToString:@"cart"]) {
  3522. // [params setObject:@"Add To Cart" forKey:kAction];
  3523. // }
  3524. //
  3525. // NSData* json = nil;
  3526. //
  3527. // if(appDelegate.offline_mode)
  3528. // {
  3529. // json= [OLDataProvider offline_itemsearchaddall:params];
  3530. // }
  3531. // else
  3532. // {
  3533. // if(![self IsNetworkAvailable])
  3534. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3535. // NSError *error=nil;
  3536. //
  3537. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3538. // params[@"resultSerial"]=uuid;
  3539. //
  3540. // for(int i=0;i<150;i++)
  3541. // {
  3542. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3543. // // result_params[@"resultSerial"]=uuid;
  3544. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  3545. // if(json!=nil)
  3546. // {
  3547. //
  3548. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3549. // if([jsobj[@"result"] intValue]==2)
  3550. // {
  3551. // break;
  3552. // }
  3553. // }
  3554. // sleep(2);
  3555. // }
  3556. // }
  3557. // if(json==nil)
  3558. // return nil;
  3559. // NSError *error=nil;
  3560. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3561. // return jsobj;
  3562. //}
  3563. //+(NSDictionary*)ItemSearch:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller
  3564. //{
  3565. //
  3566. // // for debug
  3567. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3568. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3569. //
  3570. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3571. // __block AppDelegate *appDelegate = nil;
  3572. //
  3573. // dispatch_sync(dispatch_get_main_queue(), ^{
  3574. // //some UI methods ej
  3575. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3576. // });
  3577. // if(appDelegate.user!=nil)
  3578. // [params setValue:appDelegate.user forKey:@"user"];
  3579. // if(appDelegate.contact_id!=nil)
  3580. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3581. // if(appDelegate.password!=nil)
  3582. // [params setValue:appDelegate.password forKey:@"password"];
  3583. // if(appDelegate.order_code!=nil)
  3584. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3585. //
  3586. //
  3587. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3588. // if (alert && qty && available && price && bestseller) {
  3589. // [params setObject:@"Filter" forKey:kAction];
  3590. // }
  3591. // if ([Singleton sharedInstance].homeItemClick) {
  3592. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  3593. // [Singleton sharedInstance].homeItemClick = NO;
  3594. //
  3595. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  3596. // [Singleton sharedInstance].homeClickedItemName = nil;
  3597. // [params setObject:extra forKey:kExtra];
  3598. // }
  3599. //
  3600. //
  3601. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3602. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3603. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3604. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3605. // // [params setValue:filter forKey:@"filter"];
  3606. // [params setValue:covertype forKey:@"covertype"];
  3607. // [params setValue:ctgid forKey:@"ctgId"];
  3608. // [params setValue:modelname forKey:@"modelName"];
  3609. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3610. // [params setValue:alert forKey:@"alert"];
  3611. // [params setValue:qty forKey:@"sold_by_qty"];
  3612. // [params setValue:available forKey:@"available"];
  3613. // [params setValue:price forKey:@"price"];
  3614. // [params setValue:bestseller forKey:@"bestseller"];
  3615. //
  3616. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3617. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3618. //
  3619. // if(appDelegate.offline_mode)
  3620. // {
  3621. // return [OLDataProvider offline_itemsearch:params];
  3622. // }
  3623. // if(![self IsNetworkAvailable])
  3624. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3625. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  3626. // if(json==nil)
  3627. // return nil;
  3628. // NSError *error=nil;
  3629. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3630. // return jsobj;
  3631. //}
  3632. //+(NSDictionary*)Search: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword
  3633. //{
  3634. // if(![self IsNetworkAvailable])
  3635. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3636. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3637. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3638. // if(appDelegate.user!=nil)
  3639. // [params setValue:appDelegate.user forKey:@"user"];
  3640. // if(appDelegate.contact_id!=nil)
  3641. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3642. // if(appDelegate.password!=nil)
  3643. // [params setValue:appDelegate.password forKey:@"password"];
  3644. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3645. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3646. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3647. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3648. // [params setValue:filter forKey:@"filter"];
  3649. // [params setValue:keyword forKey:@"keyword"];
  3650. //
  3651. //
  3652. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3653. // if(json==nil)
  3654. // return nil;
  3655. // NSError *error=nil;
  3656. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3657. // return jsobj;
  3658. //}
  3659. +(NSDictionary*)request_model_qty: (NSString*) fashionId
  3660. {
  3661. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3662. __block AppDelegate *appDelegate = nil;
  3663. dispatch_sync(dispatch_get_main_queue(), ^{
  3664. //some UI methods ej
  3665. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3666. });
  3667. if(appDelegate.user!=nil)
  3668. [params setValue:appDelegate.user forKey:@"user"];
  3669. if(appDelegate.contact_id!=nil)
  3670. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3671. if(appDelegate.password!=nil)
  3672. [params setValue:appDelegate.password forKey:@"password"];
  3673. [params setValue:fashionId forKey:@"fashionId"];
  3674. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  3675. NSData* json = nil;
  3676. if(appDelegate.offline_mode)
  3677. {
  3678. json = [OLDataProvider offline_model_qty:params];
  3679. } else {
  3680. if(![self IsNetworkAvailable])
  3681. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3682. json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  3683. }
  3684. if(json==nil)
  3685. return nil;
  3686. NSError *error=nil;
  3687. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3688. return jsobj;
  3689. }
  3690. +(NSDictionary*)retrieve_password: (NSString*) user email:(NSString*) email
  3691. {
  3692. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3693. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3694. // if(appDelegate.user!=nil)
  3695. // [params setValue:appDelegate.user forKey:@"user"];
  3696. // if(appDelegate.contact_id!=nil)
  3697. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3698. // if(appDelegate.password!=nil)
  3699. // [params setValue:appDelegate.password forKey:@"password"];
  3700. [params setValue:user forKey:@"username"];
  3701. [params setValue:email forKey:@"email"];
  3702. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3703. if(![self IsNetworkAvailable])
  3704. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3705. NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  3706. if(json==nil)
  3707. return nil;
  3708. NSError *error=nil;
  3709. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3710. return jsobj;
  3711. }
  3712. +(NSDictionary*)load_HomePage:(int) price_template customid:(int) customid
  3713. {
  3714. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3715. __block AppDelegate *appDelegate = nil;
  3716. dispatch_sync(dispatch_get_main_queue(), ^{
  3717. //some UI methods ej
  3718. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3719. });
  3720. if(appDelegate.user!=nil)
  3721. [params setValue:appDelegate.user forKey:@"user"];
  3722. if(appDelegate.contact_id!=nil)
  3723. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3724. if(appDelegate.password!=nil)
  3725. [params setValue:appDelegate.password forKey:@"password"];
  3726. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3727. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3728. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  3729. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3730. if(appDelegate.offline_mode)
  3731. {
  3732. //params[@"offline_Command"]=url;
  3733. return [OLDataProvider offline_home];
  3734. }
  3735. if(![self IsNetworkAvailable])
  3736. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3737. NSData* json=[self get_json:URL_LOAD_HOME parameters:params];
  3738. if(json==nil)
  3739. return nil;
  3740. NSError *error=nil;
  3741. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3742. return jsobj;
  3743. }
  3744. //+(NSDictionary*)logout
  3745. //{
  3746. //
  3747. //
  3748. //
  3749. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3750. // __block AppDelegate *appDelegate = nil;
  3751. //
  3752. // dispatch_sync(dispatch_get_main_queue(), ^{
  3753. // //some UI methods ej
  3754. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3755. // });
  3756. // if(appDelegate.user!=nil)
  3757. // [params setValue:appDelegate.user forKey:@"user"];
  3758. //
  3759. //
  3760. // if(appDelegate.password!=nil)
  3761. // [params setValue:appDelegate.password forKey:@"password"];
  3762. //
  3763. //
  3764. // if(appDelegate.offline_mode)
  3765. // {
  3766. // return [OLDataProvider offline_logout:params];
  3767. // }
  3768. // if(![self IsNetworkAvailable])
  3769. // {
  3770. // DebugLog(@"NET ERR");
  3771. //
  3772. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3773. // // return nil;
  3774. // }
  3775. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  3776. // //if(json==nil)
  3777. //
  3778. //
  3779. // if(json==nil)
  3780. // return nil;
  3781. // NSError *error=nil;
  3782. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3783. // int result = [[jsobj valueForKey:@"result"] intValue];
  3784. //
  3785. // if (result==2)
  3786. // {
  3787. //
  3788. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  3789. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  3790. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  3791. //
  3792. // [appDelegate update_count_mark];
  3793. //
  3794. //
  3795. // appDelegate.can_show_price =false;
  3796. // appDelegate.can_see_price =false;
  3797. // appDelegate.can_create_portfolio =false;
  3798. // appDelegate.can_create_order =false;
  3799. //
  3800. //
  3801. // appDelegate.can_cancel_order =false;
  3802. // appDelegate.can_set_cart_price =false;
  3803. // appDelegate.can_delete_order =false;
  3804. // appDelegate.can_submit_order =false;
  3805. // appDelegate.can_set_tearsheet_price =false;
  3806. // appDelegate.can_update_contact_info = false;
  3807. //
  3808. // appDelegate.save_order_logout = false;
  3809. // appDelegate.submit_order_logout = false;
  3810. // appDelegate.alert_sold_in_quantities = false;
  3811. //
  3812. // appDelegate.ipad_perm =nil ;
  3813. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  3814. // appDelegate.OrderFilter= nil;
  3815. // [appDelegate SetSo:nil];
  3816. // [appDelegate set_main_button_panel];
  3817. //#ifdef RA_NOTIFICATION
  3818. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  3819. //#endif
  3820. // }
  3821. // return jsobj;
  3822. //}
  3823. +(NSDictionary*)request_Cagegory
  3824. {
  3825. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  3826. __block AppDelegate *appDelegate = nil;
  3827. dispatch_sync(dispatch_get_main_queue(), ^{
  3828. //some UI methods ej
  3829. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3830. });
  3831. if(appDelegate.offline_mode)
  3832. {
  3833. //params[@"offline_Command"]=url;
  3834. return [OLDataProvider offline_category_menu];
  3835. }
  3836. if(![self IsNetworkAvailable])
  3837. {
  3838. DebugLog(@"NET ERR");
  3839. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3840. // return nil;
  3841. }
  3842. NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  3843. //if(json==nil)
  3844. if(json==nil)
  3845. return nil;
  3846. NSError *error=nil;
  3847. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3848. return jsobj;
  3849. }
  3850. +(int)Authorize : (NSString*) user password:(NSString*) password{
  3851. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  3852. // return RESULT_NET_ERROR;
  3853. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3854. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3855. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3856. __block AppDelegate *appDelegate = nil;
  3857. dispatch_sync(dispatch_get_main_queue(), ^{
  3858. //some UI methods ej
  3859. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3860. });
  3861. if(appDelegate.duid !=nil)
  3862. [params setValue:appDelegate.duid forKey:@"udid"];
  3863. [params setValue:@"handset_login" forKey:@"action"];
  3864. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  3865. [params setValue:user forKey:@"user"];
  3866. [params setValue:password forKey:@"password"];
  3867. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  3868. #ifdef TEST
  3869. [params setValue:@"true" forKey:@"is_debug"];
  3870. #else
  3871. [params setValue:@"false" forKey:@"is_debug"];
  3872. #endif
  3873. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3874. [params setObject:@"Login" forKey:kAction];
  3875. NSData* json= nil;
  3876. if(appDelegate.offline_mode)
  3877. {
  3878. json= [OLDataProvider offline_login:params] ;
  3879. }
  3880. else
  3881. {
  3882. if(![self IsNetworkAvailable])
  3883. return RESULT_NET_NOTAVAILABLE;
  3884. json =[self get_json:URL_UPDATE_AUTH parameters:params];
  3885. }
  3886. if(json==nil)
  3887. return RESULT_NET_ERROR;
  3888. int ret = [self parse_authinfo:json user:user password:password];
  3889. DebugLog(@"parse_authinfo return %d ",ret);
  3890. return ret;
  3891. }
  3892. +(NSDictionary*)update_customer_img: (NSString*) contactid img_url:(NSString*) url
  3893. {
  3894. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3895. __block AppDelegate *appDelegate = nil;
  3896. dispatch_sync(dispatch_get_main_queue(), ^{
  3897. //some UI methods ej
  3898. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3899. });
  3900. if(appDelegate.user!=nil)
  3901. [params setValue:appDelegate.user forKey:@"user"];
  3902. // if(appDelegate.contact_id!=nil)
  3903. if(appDelegate.password!=nil)
  3904. [params setValue:appDelegate.password forKey:@"password"];
  3905. [params setValue:contactid forKey:@"contactId"];
  3906. [params setValue:url forKey:@"business_card"];
  3907. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  3908. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  3909. if(appDelegate.offline_mode)
  3910. {
  3911. return [OLDataProvider offline_notimpl];
  3912. }
  3913. if(![self IsNetworkAvailable])
  3914. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3915. NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  3916. if(json==nil)
  3917. return nil;
  3918. NSError *error=nil;
  3919. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3920. return jsobj;
  3921. }
  3922. +(NSDictionary*)request_PendingOrder:(NSString *)contactid
  3923. {
  3924. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3925. __block AppDelegate *appDelegate = nil;
  3926. dispatch_sync(dispatch_get_main_queue(), ^{
  3927. //some UI methods ej
  3928. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3929. });
  3930. if(appDelegate.user!=nil)
  3931. [params setValue:appDelegate.user forKey:@"user"];
  3932. // if(appDelegate.contact_id!=nil)
  3933. if(appDelegate.password!=nil)
  3934. [params setValue:appDelegate.password forKey:@"password"];
  3935. [params setValue:contactid forKey:@"contactId"];
  3936. if(appDelegate.offline_mode)
  3937. {
  3938. return [OLDataProvider offline_notimpl];
  3939. }
  3940. if(![self IsNetworkAvailable])
  3941. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3942. NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  3943. if(json==nil)
  3944. return nil;
  3945. NSError *error=nil;
  3946. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3947. return jsobj;
  3948. }
  3949. //+(NSDictionary*)request_CustomerInfo:(NSString* ) contactid
  3950. //{
  3951. //
  3952. //
  3953. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3954. // __block AppDelegate *appDelegate = nil;
  3955. //
  3956. // dispatch_sync(dispatch_get_main_queue(), ^{
  3957. // //some UI methods ej
  3958. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3959. // });
  3960. // if(appDelegate.user!=nil)
  3961. // [params setValue:appDelegate.user forKey:@"user"];
  3962. // // if(appDelegate.contact_id!=nil)
  3963. //
  3964. // if(appDelegate.password!=nil)
  3965. // [params setValue:appDelegate.password forKey:@"password"];
  3966. // [params setValue:contactid forKey:@"contactId"];
  3967. //
  3968. // [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  3969. //
  3970. // if(appDelegate.offline_mode)
  3971. // return [OLDataProvider offline_contactinfo:params];
  3972. // if(![self IsNetworkAvailable])
  3973. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3974. //
  3975. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  3976. // if(json==nil)
  3977. // return nil;
  3978. // NSError *error=nil;
  3979. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3980. // return jsobj;
  3981. //
  3982. //}
  3983. +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
  3984. {
  3985. DebugLog(@"parse_authinfo");
  3986. NSError *error=nil;
  3987. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3988. if(jsobj)
  3989. {
  3990. __block AppDelegate *appDelegate = nil;
  3991. dispatch_sync(dispatch_get_main_queue(), ^{
  3992. //some UI methods ej
  3993. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3994. });
  3995. int result = [[jsobj valueForKey:@"result"] intValue];
  3996. if (result<0)
  3997. return result;
  3998. if(result!=AP_USER_AUTH&& result!=9)
  3999. {
  4000. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  4001. // [appDelegate Logout];
  4002. if(result==8)
  4003. {
  4004. return RESULT_LOGIN_DEVICE;
  4005. }
  4006. return RESULT_FALSE;
  4007. }
  4008. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  4009. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  4010. user=[objheader objectForKey:@"username"] ;
  4011. DebugLog(@"required_ver=%@ ",required_ver);
  4012. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  4013. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  4014. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  4015. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  4016. // if([ibadge isEqual:[NSNull null]])
  4017. // strbadge=@"0";
  4018. // if(ibadge==nil)
  4019. // ibadge=@"0";
  4020. // if([strbadge isEqualToString:@"null"])
  4021. // strbadge=@"0";
  4022. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  4023. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  4024. if([appDelegate.build intValue]<[required_ver intValue])
  4025. return RESULT_VER_LOW;
  4026. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  4027. appDelegate.user = user;
  4028. appDelegate.password = password;
  4029. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  4030. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  4031. appDelegate.bLogin = true;
  4032. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  4033. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  4034. {
  4035. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  4036. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  4037. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  4038. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  4039. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  4040. }
  4041. NSString* mode =[jsobj valueForKey:@"mode"] ;
  4042. [appDelegate SetMode:mode];
  4043. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  4044. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  4045. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  4046. [appDelegate update_count_mark];
  4047. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  4048. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  4049. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  4050. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  4051. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  4052. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  4053. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  4054. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  4055. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  4056. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  4057. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  4058. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  4059. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  4060. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  4061. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  4062. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  4063. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  4064. [appDelegate set_main_button_panel];
  4065. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  4066. // shop order status filter
  4067. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  4068. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  4069. // Sales order status filter
  4070. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  4071. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  4072. // specialInstruction
  4073. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  4074. //-价格类型
  4075. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  4076. // 权限
  4077. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  4078. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  4079. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  4080. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  4081. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  4082. [[RASingleton sharedInstance] resetGlobalLock];
  4083. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  4084. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  4085. }
  4086. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  4087. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  4088. // {
  4089. // // no update on the server;
  4090. // return RESULT_TRUE;
  4091. // }
  4092. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  4093. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4094. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4095. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4096. // [defaults synchronize];
  4097. //
  4098. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  4099. // NSArray* keys= [objfuncs allKeys];
  4100. /*
  4101. db.setTransactionSuccessful();
  4102. db.endTransaction();
  4103. */
  4104. return RESULT_TRUE;
  4105. }
  4106. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  4107. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  4108. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  4109. return RESULT_USERAUTH_ERROR;
  4110. }
  4111. //+(bool) IsNetworkAvailable
  4112. //{
  4113. //
  4114. // if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) &&
  4115. // ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable))
  4116. // return false;
  4117. // return true;
  4118. //}
  4119. //+(NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim
  4120. //{
  4121. // NSScanner *theScanner = [NSScanner scannerWithString:html];
  4122. // NSString *text = nil;
  4123. //
  4124. // while ([theScanner isAtEnd] == NO) {
  4125. // // find start of tag
  4126. // [theScanner scanUpToString:@"<" intoString:NULL] ;
  4127. // // find end of tag
  4128. // [theScanner scanUpToString:@">" intoString:&text] ;
  4129. // // replace the found tag with a space
  4130. // //(you can filter multi-spaces out later if you wish)
  4131. // html = [html stringByReplacingOccurrencesOfString:
  4132. // [ NSString stringWithFormat:@"%@>", text]
  4133. // withString:@""];
  4134. // }
  4135. //
  4136. // return trim ? [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : html;
  4137. //}
  4138. //
  4139. //+(NSString *)flattenURL:(NSString *)url trimWhiteSpace:(BOOL)trim
  4140. //{
  4141. // NSScanner *theScanner = [NSScanner scannerWithString:url];
  4142. // NSString *text = nil;
  4143. //
  4144. // while ([theScanner isAtEnd] == NO) {
  4145. // // find start of tag
  4146. // [theScanner scanUpToString:@"/" intoString:NULL] ;
  4147. // // find end of tag
  4148. // [theScanner scanUpToString:@"/" intoString:&text] ;
  4149. // // replace the found tag with a space
  4150. // //(you can filter multi-spaces out later if you wish)
  4151. // url = [url stringByReplacingOccurrencesOfString:
  4152. // [ NSString stringWithFormat:@"%@", text]
  4153. // withString:@""];
  4154. // }
  4155. //
  4156. // return trim ? [url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : url;
  4157. //}
  4158. + (NSDictionary *)set_npd_shop_price_type:(NSInteger)priceType {
  4159. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4160. __block AppDelegate *appDelegate = nil;
  4161. dispatch_sync(dispatch_get_main_queue(), ^{
  4162. //some UI methods ej
  4163. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4164. });
  4165. if(appDelegate.user!=nil)
  4166. [dic setValue:appDelegate.user forKey:@"user"];
  4167. if(appDelegate.password!=nil)
  4168. [dic setValue:appDelegate.password forKey:@"password"];
  4169. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  4170. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  4171. NSData* json=nil;
  4172. if(appDelegate.offline_mode)
  4173. {
  4174. return [OLDataProvider offline_notimpl];
  4175. }
  4176. else
  4177. {
  4178. if(![self IsNetworkAvailable])
  4179. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4180. json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  4181. }
  4182. if(json!=nil)
  4183. {
  4184. NSError *error=nil;
  4185. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4186. return jsobj;
  4187. }
  4188. return nil;
  4189. }
  4190. + (NSDictionary *)get_npd_shop_givenPrice {
  4191. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4192. __block AppDelegate *appDelegate = nil;
  4193. dispatch_sync(dispatch_get_main_queue(), ^{
  4194. //some UI methods ej
  4195. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4196. });
  4197. if(appDelegate.user!=nil)
  4198. [dic setValue:appDelegate.user forKey:@"user"];
  4199. if(appDelegate.password!=nil)
  4200. [dic setValue:appDelegate.password forKey:@"password"];
  4201. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  4202. NSData* json=nil;
  4203. if(appDelegate.offline_mode)
  4204. {
  4205. return [OLDataProvider offline_notimpl];
  4206. }
  4207. else
  4208. {
  4209. if(![self IsNetworkAvailable])
  4210. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4211. json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  4212. }
  4213. if(json!=nil)
  4214. {
  4215. NSError *error=nil;
  4216. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4217. return jsobj;
  4218. }
  4219. return nil;
  4220. }
  4221. + (NSDictionary *)set_npd_shop_givenPrice:(NSMutableDictionary *)params {
  4222. __block AppDelegate *appDelegate = nil;
  4223. dispatch_sync(dispatch_get_main_queue(), ^{
  4224. //some UI methods ej
  4225. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4226. });
  4227. if(appDelegate.user!=nil)
  4228. [params setValue:appDelegate.user forKey:@"user"];
  4229. if(appDelegate.password!=nil)
  4230. [params setValue:appDelegate.password forKey:@"password"];
  4231. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  4232. NSData* json=nil;
  4233. if(appDelegate.offline_mode)
  4234. {
  4235. return [OLDataProvider offline_notimpl];
  4236. }
  4237. else
  4238. {
  4239. if(![self IsNetworkAvailable])
  4240. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4241. json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  4242. }
  4243. if(json!=nil)
  4244. {
  4245. NSError *error=nil;
  4246. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4247. return jsobj;
  4248. }
  4249. return nil;
  4250. }
  4251. + (NSDictionary *)merge_order:(NSMutableDictionary *)params {
  4252. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4253. __block AppDelegate *appDelegate = nil;
  4254. dispatch_sync(dispatch_get_main_queue(), ^{
  4255. //some UI methods ej
  4256. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4257. });
  4258. if(appDelegate.user!=nil)
  4259. [dic setValue:appDelegate.user forKey:@"user"];
  4260. if(appDelegate.password!=nil)
  4261. [dic setValue:appDelegate.password forKey:@"password"];
  4262. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  4263. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  4264. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  4265. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  4266. NSData* json=nil;
  4267. if(appDelegate.offline_mode)
  4268. {
  4269. return [OLDataProvider offline_notimpl];
  4270. }
  4271. else
  4272. {
  4273. if(![self IsNetworkAvailable])
  4274. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4275. json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  4276. }
  4277. if(json!=nil)
  4278. {
  4279. NSError *error=nil;
  4280. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4281. return jsobj;
  4282. }
  4283. else
  4284. return nil;
  4285. }
  4286. //+ (NSDictionary *)lock_order:(NSString *)oderCode
  4287. //{
  4288. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4289. // __block AppDelegate *appDelegate = nil;
  4290. //
  4291. // dispatch_sync(dispatch_get_main_queue(), ^{
  4292. // //some UI methods ej
  4293. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4294. // });
  4295. // if(appDelegate.user!=nil)
  4296. // [params setValue:appDelegate.user forKey:@"user"];
  4297. //
  4298. // if(appDelegate.password!=nil)
  4299. // [params setValue:appDelegate.password forKey:@"password"];
  4300. //
  4301. // [params setValue:oderCode forKey:@"orderCode"];
  4302. //
  4303. // NSData* json=nil;
  4304. // if(appDelegate.offline_mode)
  4305. // {
  4306. // json=[OLDataProvider offline_editorder:params];
  4307. //
  4308. // }
  4309. // else
  4310. // {
  4311. // if(![self IsNetworkAvailable])
  4312. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4313. //
  4314. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  4315. // }
  4316. // if(json!=nil)
  4317. // {
  4318. // NSError *error=nil;
  4319. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4320. //
  4321. // return jsobj;
  4322. // }
  4323. // else
  4324. // return nil;
  4325. //}
  4326. + (NSDictionary *)quoteOrder:(NSString *)so_id emailAddr:(NSString *)addr {
  4327. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4328. __block AppDelegate *appDelegate = nil;
  4329. dispatch_sync(dispatch_get_main_queue(), ^{
  4330. //some UI methods ej
  4331. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4332. });
  4333. if(appDelegate.user!=nil)
  4334. [dic setValue:appDelegate.user forKey:@"user"];
  4335. if(appDelegate.password!=nil)
  4336. [dic setValue:appDelegate.password forKey:@"password"];
  4337. [dic setValue:so_id forKey:@"orderCode"];
  4338. [dic setValue:addr forKey:@"email"];
  4339. [dic setObject:ScreenCodeCart forKey:kScreenName];
  4340. if (appDelegate.customerInfo) {
  4341. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4342. if (customer_cid) {
  4343. [dic setValue:customer_cid forKey:@"contactId"];
  4344. }
  4345. }
  4346. NSData* json=nil;
  4347. if(appDelegate.offline_mode)
  4348. {
  4349. return [OLDataProvider offline_notimpl];
  4350. }
  4351. else
  4352. {
  4353. if(![self IsNetworkAvailable])
  4354. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4355. json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  4356. }
  4357. if(json!=nil)
  4358. {
  4359. NSError *error=nil;
  4360. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4361. return jsobj;
  4362. }
  4363. return @{@"result" : @(RESULT_FALSE)};
  4364. }
  4365. + (NSDictionary *)notifyModel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName{
  4366. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4367. __block AppDelegate *appDelegate = nil;
  4368. dispatch_sync(dispatch_get_main_queue(), ^{
  4369. //some UI methods ej
  4370. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4371. });
  4372. if(appDelegate.user!=nil)
  4373. [dic setValue:appDelegate.user forKey:@"user"];
  4374. if(appDelegate.password!=nil)
  4375. [dic setValue:appDelegate.password forKey:@"password"];
  4376. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  4377. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4378. if (customer_cid) {
  4379. [dic setValue:customer_cid forKey:@"contactId"];
  4380. }
  4381. }
  4382. [dic setObject:screenName forKey:kScreenName];
  4383. [dic setValue:modelID forKey:@"productId"];
  4384. if (addr) { // 弹框输入
  4385. [dic setValue:addr forKey:@"email"];
  4386. } else {
  4387. // employee选择了Contact,并且Contact有Email
  4388. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  4389. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  4390. // if (email) {
  4391. // [dic setValue:email forKey:@"email"];
  4392. // }
  4393. // }
  4394. }
  4395. NSData* json=nil;
  4396. if(appDelegate.offline_mode)
  4397. {
  4398. return [OLDataProvider offline_notimpl];
  4399. }
  4400. else
  4401. {
  4402. if(![self IsNetworkAvailable])
  4403. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4404. json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  4405. }
  4406. if(json!=nil)
  4407. {
  4408. NSError *error=nil;
  4409. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4410. return jsobj;
  4411. }
  4412. return @{@"result" : @(RESULT_FALSE)};
  4413. }
  4414. + (NSDictionary *)quoteWishlist2EmailAddr:(NSString *)addr {
  4415. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4416. __block AppDelegate *appDelegate = nil;
  4417. dispatch_sync(dispatch_get_main_queue(), ^{
  4418. //some UI methods ej
  4419. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4420. });
  4421. if(appDelegate.user!=nil)
  4422. [dic setValue:appDelegate.user forKey:@"user"];
  4423. if(appDelegate.password!=nil)
  4424. [dic setValue:appDelegate.password forKey:@"password"];
  4425. [dic setValue:addr forKey:@"email"];
  4426. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  4427. // if (appDelegate.customerInfo) {
  4428. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4429. // if (customer_cid) {
  4430. // [dic setValue:customer_cid forKey:@"contactId"];
  4431. // }
  4432. // }
  4433. NSData* json=nil;
  4434. if(appDelegate.offline_mode)
  4435. {
  4436. return [OLDataProvider offline_notimpl];
  4437. }
  4438. else
  4439. {
  4440. if(![self IsNetworkAvailable])
  4441. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4442. json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  4443. }
  4444. if(json!=nil)
  4445. {
  4446. NSError *error=nil;
  4447. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4448. return jsobj;
  4449. }
  4450. return @{@"result" : @(RESULT_FALSE)};
  4451. }
  4452. + (NSDictionary *)movetobackorder:(NSString *)cart_item_id {
  4453. if (cart_item_id == nil || cart_item_id.length < 1) {
  4454. return @{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"};
  4455. }
  4456. __block AppDelegate *appDelegate = nil;
  4457. dispatch_sync(dispatch_get_main_queue(), ^{
  4458. //some UI methods ej
  4459. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4460. });
  4461. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4462. if(appDelegate.user!=nil)
  4463. [dic setValue:appDelegate.user forKey:@"user"];
  4464. if(appDelegate.password!=nil)
  4465. [dic setValue:appDelegate.password forKey:@"password"];
  4466. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  4467. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  4468. [dic setObject:ScreenCodeCart forKey:kScreenName];
  4469. if(![self IsNetworkAvailable])
  4470. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4471. NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  4472. if(json!=nil)
  4473. {
  4474. NSError *error=nil;
  4475. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4476. return jsobj;
  4477. }
  4478. return @{@"result" : @(RESULT_FALSE)};
  4479. }
  4480. + (NSDictionary*)request_hangTag:(NSString *)group {
  4481. #ifdef BUILD_UWAVER
  4482. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4483. __block AppDelegate *appDelegate = nil;
  4484. dispatch_sync(dispatch_get_main_queue(), ^{
  4485. //some UI methods ej
  4486. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4487. });
  4488. if(appDelegate.user!=nil)
  4489. [params setValue:appDelegate.user forKey:@"user"];
  4490. if(appDelegate.contact_id!=nil)
  4491. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4492. if(appDelegate.password!=nil)
  4493. [params setValue:appDelegate.password forKey:@"password"];
  4494. if (group) {
  4495. [params setValue:group forKey:@"groupName"];
  4496. }
  4497. NSString * uuid= [[NSUUID UUID] UUIDString];
  4498. params[@"resultSerial"]=uuid;
  4499. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4500. NSData* json = nil;
  4501. if(appDelegate.offline_mode)
  4502. {
  4503. json = [OLDataProvider offline_notimpl];
  4504. } else {
  4505. if(![self IsNetworkAvailable])
  4506. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4507. json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  4508. }
  4509. if(json==nil)
  4510. return nil;
  4511. NSError *error=nil;
  4512. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4513. return jsobj;
  4514. #else
  4515. return nil;
  4516. #endif
  4517. }
  4518. #pragma mark 2020 new interface
  4519. // 新接口逐步替换以前的网络请求,2020
  4520. +(void)request_home:(int) price_template customid:(int) customid completionHandler:(resultHandler)result
  4521. {
  4522. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4523. AppDelegate *appDelegate = nil;
  4524. //some UI methods ej
  4525. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4526. if(appDelegate.user!=nil)
  4527. [params setValue:appDelegate.user forKey:@"user"];
  4528. if(appDelegate.contact_id!=nil)
  4529. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4530. if(appDelegate.password!=nil)
  4531. [params setValue:appDelegate.password forKey:@"password"];
  4532. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4533. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4534. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  4535. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4536. if(appDelegate.offline_mode)
  4537. {
  4538. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4539. NSMutableDictionary* json = [[OLDataProvider offline_home] mutableCopy];
  4540. dispatch_async(dispatch_get_main_queue(), ^{
  4541. result(json);
  4542. });
  4543. });
  4544. return;
  4545. }
  4546. [self request_interface:URL_LOAD_HOME parameters:params err_record_url:nil completionHandler:result retry:0];
  4547. return;
  4548. }
  4549. +(void)request_category:(resultHandler)result
  4550. {
  4551. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  4552. AppDelegate *appDelegate = nil;
  4553. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4554. if(appDelegate.offline_mode)
  4555. {
  4556. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4557. NSMutableDictionary* json = [[OLDataProvider offline_category_menu] mutableCopy];
  4558. dispatch_async(dispatch_get_main_queue(), ^{
  4559. result(json);
  4560. });
  4561. });
  4562. return;
  4563. }
  4564. [self request_interface:URL_REQUEST_CATMENU parameters:[NSMutableDictionary new] err_record_url:nil completionHandler:result retry:0];
  4565. //
  4566. // if(![self IsNetworkAvailable])
  4567. // {
  4568. // DebugLog(@"NET ERR");
  4569. //
  4570. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4571. // // return nil;
  4572. // }
  4573. //
  4574. // NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  4575. // //if(json==nil)
  4576. //
  4577. //
  4578. // if(json==nil)
  4579. // return nil;
  4580. // NSError *error=nil;
  4581. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4582. // return jsobj;
  4583. }
  4584. +(void)request_categorylist: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip completionHandler:(resultHandler)result
  4585. {
  4586. AppDelegate *appDelegate = nil;
  4587. //some UI methods ej
  4588. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4589. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4590. if(appDelegate.user!=nil)
  4591. [params setValue:appDelegate.user forKey:@"user"];
  4592. if(appDelegate.contact_id!=nil)
  4593. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4594. if(appDelegate.password!=nil)
  4595. [params setValue:appDelegate.password forKey:@"password"];
  4596. if(appDelegate.order_code!=nil)
  4597. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4598. [params setValue:alert forKey:@"alert"];
  4599. [params setValue:qty forKey:@"sold_by_qty"];
  4600. [params setValue:available forKey:@"available"];
  4601. [params setValue:price forKey:@"price"];
  4602. [params setValue:bestseller forKey:@"bestseller"];
  4603. [params setValue:modelname forKey:@"modelName"];
  4604. [params setValue:modeldescrip forKey:@"modelDescription"];
  4605. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4606. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4607. [params setValue:category forKey:@"category"];
  4608. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4609. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4610. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4611. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4612. [params setValue:filter forKey:@"filter"];
  4613. [params setValue:keyword forKey:@"keyword"];
  4614. [params setObject:ScreenCodeCategory forKey:kScreenName];
  4615. if (alert) {
  4616. [params setObject:@"Filter" forKey:kAction];
  4617. }
  4618. if ([RASingleton sharedInstance].homeItemClick) {
  4619. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  4620. [RASingleton sharedInstance].homeItemClick = NO;
  4621. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  4622. [RASingleton sharedInstance].homeClickedItemName = nil;
  4623. [params setObject:extra forKey:kExtra];
  4624. }
  4625. if(appDelegate.offline_mode)
  4626. {
  4627. // [OLDataProvider offline_category:params completionHandler:result];
  4628. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4629. NSMutableDictionary* json = [[OLDataProvider offline_category:params] mutableCopy];
  4630. dispatch_async(dispatch_get_main_queue(), ^{
  4631. result(json);
  4632. });
  4633. });
  4634. return;
  4635. }
  4636. [self request_interface:URL_CATEGORY parameters:params err_record_url:nil completionHandler:result retry:0];
  4637. return ;
  4638. //
  4639. // if(![self IsNetworkAvailable])
  4640. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4641. //
  4642. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  4643. // if(json==nil)
  4644. // return nil;
  4645. // NSError *error=nil;
  4646. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4647. // return jsobj;
  4648. //
  4649. }
  4650. +(void)request_modeldetail: (NSString* ) item_id model_name:(NSString*) model_name upc_code:(NSString*) upc_code category_id:(NSString*) category_id use_name :(bool) use_name use_upc :(bool) use_upc groupName:(NSString *)groupName completionHandler:(resultHandler)result
  4651. {
  4652. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4653. AppDelegate *appDelegate = nil;
  4654. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4655. if(appDelegate.user!=nil)
  4656. [params setValue:appDelegate.user forKey:@"user"];
  4657. if(appDelegate.contact_id!=nil)
  4658. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4659. if(appDelegate.password!=nil)
  4660. [params setValue:appDelegate.password forKey:@"password"];
  4661. if(appDelegate.order_code!=nil)
  4662. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4663. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4664. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4665. if(use_name)
  4666. [params setValue:model_name forKey:@"product_name"];
  4667. else
  4668. if(use_upc){
  4669. params[@"search_upc"]=@true;
  4670. [params setValue:upc_code forKey:@"upc_code"];
  4671. }
  4672. else
  4673. [params setValue:item_id forKey:@"product_id"];
  4674. [params setValue:category_id forKey:@"category"];
  4675. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4676. [params setObject:@"Open A Model" forKey:kAction];
  4677. if (model_name) {
  4678. NSDictionary *extra = @{@"ModelName" : model_name};
  4679. [params setObject:extra forKey:kExtra];
  4680. }
  4681. if (groupName.length > 0) {
  4682. [params setObject:groupName forKey:@"groupName"];
  4683. }
  4684. if(appDelegate.offline_mode)
  4685. {
  4686. [OLDataProvider offline_model:params completionHandler:result];
  4687. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4688. // NSMutableDictionary* json = [[OLDataProvider offline_model:params] mutableCopy];
  4689. // dispatch_async(dispatch_get_main_queue(), ^{
  4690. // result(json);
  4691. // });
  4692. // });
  4693. return;
  4694. }
  4695. [self request_interface:URL_ITEM_DETAIL parameters:params err_record_url:nil completionHandler:result retry:0];
  4696. //
  4697. // if(appDelegate.offline_mode)
  4698. // return [OLDataProvider offline_model:params];
  4699. //
  4700. // if(![self IsNetworkAvailable])
  4701. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4702. //
  4703. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  4704. // if(json==nil)
  4705. // return nil;
  4706. // NSError *error=nil;
  4707. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4708. // return jsobj;
  4709. }
  4710. +(void)request_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull completionHandler:(resultHandler)result
  4711. {
  4712. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4713. AppDelegate *appDelegate = nil;
  4714. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4715. if(appDelegate.user!=nil)
  4716. [params setValue:appDelegate.user forKey:@"user"];
  4717. if(appDelegate.contact_id!=nil)
  4718. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4719. if(appDelegate.password!=nil)
  4720. [params setValue:appDelegate.password forKey:@"password"];
  4721. if(appDelegate.order_code!=nil)
  4722. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4723. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4724. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4725. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  4726. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4727. // [params setValue:filter forKey:@"filter"];
  4728. [params setValue:keywords forKey:@"keyword"];
  4729. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4730. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4731. if(matchfull)
  4732. [params setValue:@"true" forKey:@"exactMatch"];
  4733. else
  4734. [params setValue:@"false" forKey:@"exactMatch"];
  4735. [params setObject:ScreenCodeSearch forKey:kScreenName];
  4736. if (keywords) {
  4737. [params setObject:@"Search" forKey:kAction];
  4738. }
  4739. if(appDelegate.offline_mode)
  4740. {
  4741. // [OLDataProvider offline_search:params completionHandler:result];
  4742. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4743. NSMutableDictionary* json = [[OLDataProvider offline_search:params] mutableCopy];
  4744. dispatch_async(dispatch_get_main_queue(), ^{
  4745. result(json);
  4746. });
  4747. });
  4748. return;
  4749. }
  4750. [self request_interface:URL_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  4751. // if(appDelegate.offline_mode)
  4752. // {
  4753. // return [OLDataProvider offline_search:params];
  4754. // }
  4755. // if(![self IsNetworkAvailable])
  4756. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4757. //
  4758. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  4759. // if(json==nil)
  4760. // return nil;
  4761. // NSError *error=nil;
  4762. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4763. // return jsobj;
  4764. }
  4765. +(void)request_login: (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
  4766. {
  4767. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  4768. // return RESULT_NET_ERROR;
  4769. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4770. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4771. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4772. AppDelegate *appDelegate = nil;
  4773. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4774. if(appDelegate.duid !=nil)
  4775. [params setValue:appDelegate.duid forKey:@"udid"];
  4776. [params setValue:@"handset_login" forKey:@"action"];
  4777. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  4778. [params setValue:user forKey:@"user"];
  4779. [params setValue:password forKey:@"password"];
  4780. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  4781. #ifdef TEST
  4782. [params setValue:@"true" forKey:@"is_debug"];
  4783. #else
  4784. [params setValue:@"false" forKey:@"is_debug"];
  4785. #endif
  4786. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  4787. [params setObject:@"Login" forKey:kAction];
  4788. if(appDelegate.offline_mode)
  4789. {
  4790. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4791. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_login:params]] mutableCopy];
  4792. dispatch_async(dispatch_get_main_queue(), ^{
  4793. int ret = [self parse_logininfo:json user:user password:password] ;
  4794. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4795. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4796. result(retjson);
  4797. });
  4798. });
  4799. return;
  4800. }
  4801. NSString* url;
  4802. bool scan_guest = false;
  4803. #ifdef SCANNER_ORDER
  4804. params[@"site_name"]=[RADataProvider getSiteName];
  4805. params[@"_method"]=@"login";
  4806. url = [appDelegate.address stringByAppendingPathComponent:URL_UPDATE_AUTH];
  4807. if([user.uppercaseString isEqualToString:@"GUEST"]&&[password.uppercaseString isEqualToString:@"GUEST"])
  4808. scan_guest = true;
  4809. #else
  4810. url = URL_UPDATE_AUTH;
  4811. #endif
  4812. if(scan_guest)
  4813. {
  4814. [OLDataProvider realguestLogin];
  4815. // int ret = [self parse_logininfo:chresult user:user password:password] ;
  4816. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4817. retjson[@"result"]= [NSNumber numberWithInt:RESULT_TRUE];
  4818. result(retjson);
  4819. }
  4820. else
  4821. {
  4822. [self request_interface:url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *chresult) {
  4823. int ret = [self parse_logininfo:chresult user:user password:password] ;
  4824. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4825. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4826. result(retjson);
  4827. } retry:0];
  4828. }
  4829. //
  4830. // NSData* json= nil;
  4831. // if(appDelegate.offline_mode)
  4832. // {
  4833. // json= [OLDataProvider offline_login:params] ;
  4834. //
  4835. // }
  4836. // else
  4837. // {
  4838. // if(![self IsNetworkAvailable])
  4839. // return RESULT_NET_NOTAVAILABLE;
  4840. // json =[self get_json:URL_UPDATE_AUTH parameters:params];
  4841. //
  4842. // }
  4843. //
  4844. // if(json==nil)
  4845. // return RESULT_NET_ERROR;
  4846. //
  4847. // int ret = [self parse_authinfo:json user:user password:password];
  4848. // DebugLog(@"parse_authinfo return %d ",ret);
  4849. //
  4850. //
  4851. // return ret;
  4852. //
  4853. }
  4854. +(int)parse_logininfo : (NSMutableDictionary *) jsobj user:(NSString*) user password:(NSString*) password
  4855. {
  4856. // DebugLog(@"parse_authinfo");
  4857. // NSError *error=nil;
  4858. //
  4859. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4860. if(jsobj)
  4861. {
  4862. AppDelegate *appDelegate = nil;
  4863. //some UI methods ej
  4864. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4865. int result = [[jsobj valueForKey:@"result"] intValue];
  4866. if (result<0)
  4867. return result;
  4868. if(result!=AP_USER_AUTH&& result!=9)
  4869. {
  4870. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  4871. // [appDelegate Logout];
  4872. if(result==8)
  4873. {
  4874. return RESULT_LOGIN_DEVICE;
  4875. }
  4876. return RESULT_FALSE;
  4877. }
  4878. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  4879. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  4880. user=[objheader objectForKey:@"username"] ;
  4881. DebugLog(@"required_ver=%@ ",required_ver);
  4882. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  4883. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  4884. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  4885. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  4886. // if([ibadge isEqual:[NSNull null]])
  4887. // strbadge=@"0";
  4888. // if(ibadge==nil)
  4889. // ibadge=@"0";
  4890. // if([strbadge isEqualToString:@"null"])
  4891. // strbadge=@"0";
  4892. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  4893. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  4894. #ifndef SCANNER_ORDER
  4895. if([appDelegate.build intValue]<[required_ver intValue])
  4896. return RESULT_VER_LOW;
  4897. #endif
  4898. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  4899. appDelegate.user = user;
  4900. appDelegate.password = password;
  4901. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  4902. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  4903. appDelegate.bLogin = true;
  4904. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  4905. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  4906. {
  4907. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  4908. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  4909. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  4910. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  4911. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  4912. }
  4913. NSString* mode =[jsobj valueForKey:@"mode"] ;
  4914. [appDelegate SetMode:mode];
  4915. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  4916. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  4917. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  4918. [appDelegate update_count_mark];
  4919. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  4920. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  4921. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  4922. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  4923. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  4924. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  4925. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  4926. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  4927. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  4928. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  4929. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  4930. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  4931. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  4932. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  4933. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  4934. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  4935. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  4936. [appDelegate set_main_button_panel];
  4937. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  4938. // shop order status filter
  4939. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  4940. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  4941. // Sales order status filter
  4942. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  4943. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  4944. // specialInstruction
  4945. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  4946. //-价格类型
  4947. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  4948. // 权限
  4949. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  4950. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  4951. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  4952. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  4953. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  4954. [[RASingleton sharedInstance] resetGlobalLock];
  4955. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  4956. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  4957. }
  4958. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  4959. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  4960. // {
  4961. // // no update on the server;
  4962. // return RESULT_TRUE;
  4963. // }
  4964. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  4965. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4966. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4967. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4968. // [defaults synchronize];
  4969. //
  4970. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  4971. // NSArray* keys= [objfuncs allKeys];
  4972. /*
  4973. db.setTransactionSuccessful();
  4974. db.endTransaction();
  4975. */
  4976. return RESULT_TRUE;
  4977. }
  4978. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  4979. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  4980. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  4981. return RESULT_USERAUTH_ERROR;
  4982. }
  4983. +(void)request_contactlist:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams completionHandler:(resultHandler)result
  4984. {
  4985. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4986. if(upparams!=nil)
  4987. params = [upparams mutableCopy];
  4988. AppDelegate *appDelegate = nil;
  4989. //some UI methods ej
  4990. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4991. if(appDelegate.user!=nil)
  4992. [params setValue:appDelegate.user forKey:@"user"];
  4993. if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  4994. [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  4995. else
  4996. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4997. if(appDelegate.password!=nil)
  4998. [params setValue:appDelegate.password forKey:@"password"];
  4999. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  5000. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  5001. [params setValue:contact_type forKey:@"contactType"];
  5002. [params setValue:keywords forKey:@"keyword"];
  5003. [params setObject:ScreenCodeAccount forKey:kScreenName];
  5004. if (keywords) {
  5005. [params setObject:@"Search" forKey:kAction];
  5006. }
  5007. if (upparams) {
  5008. [params setObject:@"Advance Search" forKey:kAction];
  5009. }
  5010. NSString* url=nil;
  5011. if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  5012. url=URL_SHIPTO_LIST;
  5013. else
  5014. url=URL_CONTACT_LIST;
  5015. if(appDelegate.offline_mode)
  5016. {
  5017. [OLDataProvider offline_contactlist:params completionHandler:result];
  5018. return;
  5019. }
  5020. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  5021. //
  5022. // if(appDelegate.offline_mode)
  5023. // return [OLDataProvider offline_contactlist:params];
  5024. //
  5025. // if(![self IsNetworkAvailable])
  5026. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5027. //
  5028. // NSData* json=[self get_json:url parameters:params];
  5029. // if(json==nil)
  5030. // return nil;
  5031. // NSError *error=nil;
  5032. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5033. // return jsobj;
  5034. }
  5035. +(void)request_contactinfo:(NSString* ) contactid completionHandler:(resultHandler)result
  5036. {
  5037. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5038. AppDelegate *appDelegate = nil;
  5039. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5040. if(appDelegate.user!=nil)
  5041. [params setValue:appDelegate.user forKey:@"user"];
  5042. // if(appDelegate.contact_id!=nil)
  5043. if(appDelegate.password!=nil)
  5044. [params setValue:appDelegate.password forKey:@"password"];
  5045. [params setValue:contactid forKey:@"contactId"];
  5046. [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  5047. if(appDelegate.offline_mode)
  5048. {
  5049. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5050. // [OLDataProvider offline_contactinfo:params completionHandler:result] ;
  5051. // });
  5052. params[@"mode"]=appDelegate.mode;
  5053. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5054. NSMutableDictionary* json = [[OLDataProvider offline_contactinfo:params] mutableCopy];
  5055. dispatch_async(dispatch_get_main_queue(), ^{
  5056. result(json);
  5057. });
  5058. });
  5059. return;
  5060. }
  5061. [self request_interface:URL_CUSTOMER_INFO parameters:params err_record_url:nil completionHandler:result retry:0];
  5062. // if(appDelegate.offline_mode)
  5063. // return [OLDataProvider offline_contactinfo:params];
  5064. // if(![self IsNetworkAvailable])
  5065. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5066. //
  5067. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  5068. // if(json==nil)
  5069. // return nil;
  5070. // NSError *error=nil;
  5071. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5072. // return jsobj;
  5073. //
  5074. }
  5075. +(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  5076. {
  5077. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5078. AppDelegate *appDelegate = nil;
  5079. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5080. if(appDelegate.user!=nil)
  5081. [params setValue:appDelegate.user forKey:@"user"];
  5082. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  5083. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  5084. // else
  5085. if(appDelegate.contact_id!=nil)
  5086. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5087. if(appDelegate.password!=nil)
  5088. [params setValue:appDelegate.password forKey:@"password"];
  5089. if(appDelegate.order_code!=nil)
  5090. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5091. bool can_create_backorder=appDelegate.can_create_backorder;
  5092. // [params setValue:sourceid forKey:@"sourceid"];
  5093. // [params setValue:editor forKey:@"editor"];
  5094. DebugLog(@"request editor url:%@",request_url);
  5095. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  5096. {
  5097. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  5098. }
  5099. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  5100. {
  5101. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  5102. }
  5103. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  5104. {
  5105. [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  5106. }
  5107. else if([request_url isEqualToString:URL_CARTDELIVERY])
  5108. {
  5109. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  5110. }
  5111. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  5112. {
  5113. [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  5114. }
  5115. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  5116. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  5117. }
  5118. if(appDelegate.offline_mode)
  5119. {
  5120. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5121. NSData* json = nil;
  5122. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  5123. {
  5124. json= [OLDataProvider offline_createContact:params];
  5125. }
  5126. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  5127. {
  5128. json= [OLDataProvider offline_editContact:params];
  5129. }
  5130. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  5131. {
  5132. json= [OLDataProvider offline_contactAdvancedSearch:params];
  5133. }
  5134. else if([request_url isEqualToString:URL_CARTDELIVERY])
  5135. {
  5136. params[@"contact_id"]=params[@"contactId"];
  5137. params[@"can_create_backorder"]=@(can_create_backorder);
  5138. json= [OLDataProvider offline_placeorder:params];
  5139. }
  5140. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  5141. {
  5142. json= [OLDataProvider offline_addreditor:params];
  5143. }
  5144. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  5145. json = [OLDataProvider offline_createTearSheet:params];
  5146. }
  5147. dispatch_async(dispatch_get_main_queue(), ^{
  5148. if(json==nil)
  5149. result( [[OLDataProvider offline_notimpl] mutableCopy]);
  5150. else
  5151. result([[RAConvertor data2dict:json] mutableCopy]);
  5152. });
  5153. });
  5154. return;
  5155. }
  5156. else
  5157. {
  5158. if([request_url isEqualToString:URL_CARTDELIVERY])
  5159. {
  5160. NSString * uuid= [[NSUUID UUID] UUIDString];
  5161. params[@"resultSerial"]=uuid;
  5162. __block bool bbreak = false;
  5163. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5164. for(int i=0;i<150;i++)
  5165. {
  5166. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  5167. // result_params[@"resultSerial"]=uuid;
  5168. //json=[self get_json:request_url parameters:params];
  5169. if(bbreak)
  5170. break;
  5171. dispatch_async(dispatch_get_main_queue(), ^{
  5172. NSLog(@"request cart delivery %d",i);
  5173. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5174. if(resulti!=nil)
  5175. {
  5176. if([resulti[@"result"] intValue]==2 || [resulti[@"result"] intValue] == 8)
  5177. {
  5178. if(!bbreak) //此判断保证result只调用一次。
  5179. {
  5180. result(resulti);
  5181. NSLog(@"result called at %d",i);
  5182. }
  5183. bbreak=true;
  5184. }
  5185. }
  5186. } retry:3];
  5187. });
  5188. // [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  5189. sleep(2);
  5190. }
  5191. });
  5192. }
  5193. else
  5194. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  5195. }
  5196. // if(json!=nil)
  5197. // {
  5198. // NSError *error=nil;
  5199. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5200. // return jsobj;
  5201. // }
  5202. // else
  5203. // return nil;
  5204. }
  5205. +(void)request_wishlist:(int)sort completionHandler:(resultHandler)result
  5206. {
  5207. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5208. AppDelegate *appDelegate = nil;
  5209. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5210. if(appDelegate.user!=nil)
  5211. [params setValue:appDelegate.user forKey:@"user"];
  5212. if(appDelegate.contact_id!=nil)
  5213. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5214. if(appDelegate.password!=nil)
  5215. [params setValue:appDelegate.password forKey:@"password"];
  5216. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  5217. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  5218. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  5219. [params setObject:ScreenCodeWishList forKey:kScreenName];
  5220. if(appDelegate.offline_mode)
  5221. {
  5222. [OLDataProvider offline_wishlist:params completionHandler:^(NSMutableDictionary *resulti) {
  5223. int result_code = [[resulti valueForKey:@"result"] intValue];
  5224. if (result_code==2)
  5225. {
  5226. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  5227. [appDelegate update_count_mark];;
  5228. result(resulti);
  5229. }
  5230. }];
  5231. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5232. // NSMutableDictionary* json = [[OLDataProvider offline_wishlist:params] mutableCopy];
  5233. // dispatch_async(dispatch_get_main_queue(), ^{
  5234. // result(json);
  5235. // });
  5236. // });
  5237. return;
  5238. }
  5239. [self request_interface:URL_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5240. int result_code = [[resulti valueForKey:@"result"] intValue];
  5241. if (result_code==2)
  5242. {
  5243. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  5244. [appDelegate update_count_mark];;
  5245. result(resulti);
  5246. }
  5247. } retry:0];
  5248. // if(appDelegate.offline_mode)
  5249. // {
  5250. // return [OLDataProvider offline_wishlist:params];
  5251. // }
  5252. // if(![self IsNetworkAvailable])
  5253. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5254. //
  5255. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  5256. // if(json==nil)
  5257. // return nil;
  5258. // NSError *error=nil;
  5259. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5260. // int result = [[jsobj valueForKey:@"result"] intValue];
  5261. //
  5262. // if (result==2)
  5263. // {
  5264. //
  5265. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5266. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  5267. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5268. //
  5269. // [appDelegate update_count_mark];
  5270. // }
  5271. // return jsobj;
  5272. }
  5273. +(void)request_portfoliolist:(int)sort completionHandler:(resultHandler)result
  5274. {
  5275. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5276. AppDelegate *appDelegate = nil;
  5277. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5278. if(appDelegate.user!=nil)
  5279. [params setValue:appDelegate.user forKey:@"user"];
  5280. if(appDelegate.contact_id!=nil)
  5281. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5282. if(appDelegate.password!=nil)
  5283. [params setValue:appDelegate.password forKey:@"password"];
  5284. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  5285. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  5286. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  5287. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  5288. if(appDelegate.offline_mode)
  5289. {
  5290. params[@"user"]=appDelegate.user;
  5291. params[@"contact_id"]=appDelegate.contact_id;
  5292. params[@"can_see_price"]=@(appDelegate.can_see_price);
  5293. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5294. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_portfolioList:params]] mutableCopy];
  5295. dispatch_async(dispatch_get_main_queue(), ^{
  5296. if ([json[@"result"] intValue]==2)
  5297. {
  5298. appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  5299. [appDelegate update_count_mark];
  5300. }
  5301. result(json);
  5302. });
  5303. });
  5304. return;
  5305. }
  5306. [self request_interface:URL_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5307. if ([resulti[@"result"] intValue]==2)
  5308. {
  5309. appDelegate.port_count =[[resulti valueForKey:@"count"] intValue];
  5310. [appDelegate update_count_mark];
  5311. }
  5312. result(resulti);
  5313. } retry:0];
  5314. // NSData* json = nil;
  5315. // if(appDelegate.offline_mode)
  5316. // {
  5317. // json = [OLDataProvider offline_portfolioList:params];
  5318. // } else {
  5319. // if(![self IsNetworkAvailable])
  5320. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5321. //
  5322. // json = [self get_json:URL_PORTFOLIO parameters:params];
  5323. // }
  5324. //
  5325. //
  5326. // if(json==nil)
  5327. // return nil;
  5328. // NSError *error=nil;
  5329. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5330. // int result = [[jsobj valueForKey:@"result"] intValue];
  5331. //
  5332. // if (result==2)
  5333. // {
  5334. //
  5335. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5336. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  5337. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  5338. //
  5339. // [appDelegate update_count_mark];
  5340. // }
  5341. // return jsobj;
  5342. }
  5343. +(void)request_portfoliopdf:(int ) offset limit:(int)limit keywords:(NSString* ) keywords completionHandler:(resultHandler)result
  5344. {
  5345. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5346. AppDelegate *appDelegate = nil;
  5347. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5348. if(appDelegate.user!=nil)
  5349. [params setValue:appDelegate.user forKey:@"user"];
  5350. if(appDelegate.contact_id!=nil)
  5351. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5352. if(appDelegate.password!=nil)
  5353. [params setValue:appDelegate.password forKey:@"password"];
  5354. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  5355. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  5356. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  5357. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  5358. // [params setValue:filter forKey:@"filter"];
  5359. [params setValue:keywords forKey:@"keyWord"];
  5360. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  5361. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  5362. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  5363. if (keywords) {
  5364. [params setObject:@"Search" forKey:kAction];
  5365. }
  5366. if(appDelegate.offline_mode)
  5367. {
  5368. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5369. NSData* json = [[OLDataProvider offline_pdfList:params] mutableCopy];
  5370. dispatch_async(dispatch_get_main_queue(), ^{
  5371. result([[RAConvertor data2dict:json] mutableCopy]);
  5372. });
  5373. });
  5374. return;
  5375. }
  5376. [self request_interface:URL_DM_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  5377. return;
  5378. // NSData* json = nil;
  5379. // if(appDelegate.offline_mode)
  5380. // {
  5381. // json = [OLDataProvider offline_pdfList:params];
  5382. // } else {
  5383. // if(![self IsNetworkAvailable])
  5384. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5385. //
  5386. // json=[self get_json:URL_DM_LIST parameters:params];
  5387. // }
  5388. // if(json==nil)
  5389. // return nil;
  5390. // NSError *error=nil;
  5391. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5392. // return jsobj;
  5393. }
  5394. +(void)request_orderlist:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged completionHandler:(resultHandler)result
  5395. {
  5396. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5397. AppDelegate *appDelegate = nil;
  5398. //some UI methods ej
  5399. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5400. if(appDelegate.user!=nil)
  5401. [params setValue:appDelegate.user forKey:@"user"];
  5402. if(appDelegate.contact_id!=nil)
  5403. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5404. if(appDelegate.password!=nil)
  5405. [params setValue:appDelegate.password forKey:@"password"];
  5406. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  5407. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  5408. [params setValue:keywords forKey:@"keyWord"];
  5409. [params setValue:customer forKey:@"customer_filter"];
  5410. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  5411. [params setValue:status_code forKey:@"orderStatus"];
  5412. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  5413. if (keywords) {
  5414. [params setObject:@"Search" forKey:kAction];
  5415. }
  5416. if(appDelegate.offline_mode)
  5417. {
  5418. params[@"user"]=appDelegate.user;
  5419. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5420. NSData* json = [[OLDataProvider offline_orderlist:params] mutableCopy];
  5421. dispatch_async(dispatch_get_main_queue(), ^{
  5422. result([[RAConvertor data2dict:json] mutableCopy]);
  5423. });
  5424. });
  5425. return;
  5426. }
  5427. [self request_interface:URL_ORDER_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  5428. // NSData* json=nil;
  5429. // if(appDelegate.offline_mode)
  5430. // {
  5431. // json= [OLDataProvider offline_orderlist:params];
  5432. // }
  5433. // else
  5434. // {
  5435. // if(![self IsNetworkAvailable])
  5436. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5437. //
  5438. // json=[self get_json:URL_ORDER_LIST parameters:params];
  5439. // }
  5440. // if(json==nil)
  5441. // return nil;
  5442. // NSError *error=nil;
  5443. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5444. // return jsobj;
  5445. }
  5446. +(void)request_logout:(resultHandler)result
  5447. {
  5448. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5449. AppDelegate *appDelegate = nil;
  5450. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5451. if(appDelegate.user!=nil)
  5452. [params setValue:appDelegate.user forKey:@"user"];
  5453. if(appDelegate.password!=nil)
  5454. [params setValue:appDelegate.password forKey:@"password"];
  5455. if(appDelegate.offline_mode)
  5456. {
  5457. [OLDataProvider offline_logout:params completionHandler:result];
  5458. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5459. // NSMutableDictionary* json = [[OLDataProvider offline_logout:params] mutableCopy];
  5460. // dispatch_async(dispatch_get_main_queue(), ^{
  5461. // result(json);
  5462. // });
  5463. // });
  5464. return;
  5465. }
  5466. [self request_interface:URL_LOGOUT parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5467. NSMutableDictionary* jsobj=resulti;
  5468. int result_code = [[jsobj valueForKey:@"result"] intValue];
  5469. if (result_code==2)
  5470. {
  5471. appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  5472. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5473. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5474. [appDelegate update_count_mark];
  5475. appDelegate.can_show_price =false;
  5476. appDelegate.can_see_price =false;
  5477. appDelegate.can_create_portfolio =false;
  5478. appDelegate.can_create_order =false;
  5479. appDelegate.can_cancel_order =false;
  5480. appDelegate.can_set_cart_price =false;
  5481. appDelegate.can_delete_order =false;
  5482. appDelegate.can_submit_order =false;
  5483. appDelegate.can_set_tearsheet_price =false;
  5484. appDelegate.can_update_contact_info = false;
  5485. appDelegate.save_order_logout = false;
  5486. appDelegate.submit_order_logout = false;
  5487. appDelegate.alert_sold_in_quantities = false;
  5488. appDelegate.ipad_perm =nil ;
  5489. appDelegate.user_type = USER_ROLE_UNKNOWN;
  5490. appDelegate.OrderFilter= nil;
  5491. [appDelegate SetSo:nil];
  5492. [appDelegate set_main_button_panel];
  5493. #ifdef RA_NOTIFICATION
  5494. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5495. #endif
  5496. }
  5497. result(resulti);
  5498. } retry:0];
  5499. //
  5500. // if(appDelegate.offline_mode)
  5501. // {
  5502. // return [OLDataProvider offline_logout:params];
  5503. // }
  5504. // if(![self IsNetworkAvailable])
  5505. // {
  5506. // DebugLog(@"NET ERR");
  5507. //
  5508. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5509. // // return nil;
  5510. // }
  5511. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  5512. // //if(json==nil)
  5513. //
  5514. //
  5515. // if(json==nil)
  5516. // return nil;
  5517. // NSError *error=nil;
  5518. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5519. // int result = [[jsobj valueForKey:@"result"] intValue];
  5520. //
  5521. // if (result==2)
  5522. // {
  5523. //
  5524. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  5525. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5526. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5527. //
  5528. // [appDelegate update_count_mark];
  5529. //
  5530. //
  5531. // appDelegate.can_show_price =false;
  5532. // appDelegate.can_see_price =false;
  5533. // appDelegate.can_create_portfolio =false;
  5534. // appDelegate.can_create_order =false;
  5535. //
  5536. //
  5537. // appDelegate.can_cancel_order =false;
  5538. // appDelegate.can_set_cart_price =false;
  5539. // appDelegate.can_delete_order =false;
  5540. // appDelegate.can_submit_order =false;
  5541. // appDelegate.can_set_tearsheet_price =false;
  5542. // appDelegate.can_update_contact_info = false;
  5543. //
  5544. // appDelegate.save_order_logout = false;
  5545. // appDelegate.submit_order_logout = false;
  5546. // appDelegate.alert_sold_in_quantities = false;
  5547. //
  5548. // appDelegate.ipad_perm =nil ;
  5549. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  5550. // appDelegate.OrderFilter= nil;
  5551. // [appDelegate SetSo:nil];
  5552. // [appDelegate set_main_button_panel];
  5553. //#ifdef RA_NOTIFICATION
  5554. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5555. //#endif
  5556. // }
  5557. // return jsobj;
  5558. }
  5559. + (void)request_hangtag:(NSString *)group completionHandler:(resultHandler)result
  5560. {
  5561. #ifdef BUILD_UWAVER
  5562. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5563. AppDelegate *appDelegate = nil;
  5564. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5565. if(appDelegate.user!=nil)
  5566. [params setValue:appDelegate.user forKey:@"user"];
  5567. if(appDelegate.contact_id!=nil)
  5568. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5569. if(appDelegate.password!=nil)
  5570. [params setValue:appDelegate.password forKey:@"password"];
  5571. if (group) {
  5572. [params setValue:group forKey:@"groupName"];
  5573. }
  5574. NSString * uuid= [[NSUUID UUID] UUIDString];
  5575. params[@"resultSerial"]=uuid;
  5576. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  5577. if(appDelegate.offline_mode)
  5578. {
  5579. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5580. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5581. dispatch_async(dispatch_get_main_queue(), ^{
  5582. result(json);
  5583. });
  5584. });
  5585. return;
  5586. }
  5587. [self request_interface:URL_CREATE_HANG_TAG parameters:params err_record_url:nil completionHandler:result retry:0];
  5588. // NSData* json = nil;
  5589. // if(appDelegate.offline_mode)
  5590. // {
  5591. // json = [OLDataProvider offline_portfolioList:params];
  5592. // } else {
  5593. // if(![self IsNetworkAvailable])
  5594. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5595. //
  5596. // json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  5597. // }
  5598. //
  5599. //
  5600. // if(json==nil)
  5601. // return nil;
  5602. // NSError *error=nil;
  5603. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5604. //
  5605. // return jsobj;
  5606. #else
  5607. return result(nil);
  5608. #endif
  5609. }
  5610. + (void)request_movetobackorder:(NSString *)cart_item_id completionHandler:(resultHandler)result
  5611. {
  5612. if (cart_item_id == nil || cart_item_id.length < 1) {
  5613. result([@{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"} mutableCopy]);
  5614. }
  5615. AppDelegate *appDelegate = nil;
  5616. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5617. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5618. if(appDelegate.user!=nil)
  5619. [dic setValue:appDelegate.user forKey:@"user"];
  5620. if(appDelegate.password!=nil)
  5621. [dic setValue:appDelegate.password forKey:@"password"];
  5622. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  5623. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  5624. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5625. if(appDelegate.offline_mode)
  5626. {
  5627. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5628. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5629. dispatch_async(dispatch_get_main_queue(), ^{
  5630. result(json);
  5631. });
  5632. });
  5633. return;
  5634. }
  5635. [self request_interface:URL_MOVE_TO_BACK_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5636. // if(![self IsNetworkAvailable])
  5637. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5638. //
  5639. // NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  5640. //
  5641. // if(json!=nil)
  5642. // {
  5643. // NSError *error=nil;
  5644. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5645. //
  5646. // return jsobj;
  5647. // }
  5648. //
  5649. // return @{@"result" : @(RESULT_FALSE)};
  5650. }
  5651. + (void)request_emailwishlist:(NSString *)addr completionHandler:(resultHandler)result
  5652. {
  5653. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5654. AppDelegate *appDelegate = nil;
  5655. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5656. if(appDelegate.user!=nil)
  5657. [dic setValue:appDelegate.user forKey:@"user"];
  5658. if(appDelegate.password!=nil)
  5659. [dic setValue:appDelegate.password forKey:@"password"];
  5660. [dic setValue:addr forKey:@"email"];
  5661. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  5662. // if (appDelegate.customerInfo) {
  5663. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5664. // if (customer_cid) {
  5665. // [dic setValue:customer_cid forKey:@"contactId"];
  5666. // }
  5667. // }
  5668. if(appDelegate.offline_mode)
  5669. {
  5670. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5671. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5672. dispatch_async(dispatch_get_main_queue(), ^{
  5673. result(json);
  5674. });
  5675. });
  5676. return;
  5677. }
  5678. [self request_interface:URL_EMAIL_WISHLIST parameters:dic err_record_url:nil completionHandler:result retry:0];
  5679. // NSData* json=nil;
  5680. // if(appDelegate.offline_mode)
  5681. // {
  5682. // return [OLDataProvider offline_notimpl];
  5683. // }
  5684. // else
  5685. // {
  5686. // if(![self IsNetworkAvailable])
  5687. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5688. //
  5689. // json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  5690. // }
  5691. // if(json!=nil)
  5692. // {
  5693. // NSError *error=nil;
  5694. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5695. //
  5696. //
  5697. // return jsobj;
  5698. // }
  5699. //
  5700. // return @{@"result" : @(RESULT_FALSE)};
  5701. }
  5702. +(void)request_notifymodel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  5703. {
  5704. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5705. AppDelegate *appDelegate = nil;
  5706. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5707. if(appDelegate.user!=nil)
  5708. [dic setValue:appDelegate.user forKey:@"user"];
  5709. if(appDelegate.password!=nil)
  5710. [dic setValue:appDelegate.password forKey:@"password"];
  5711. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5712. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5713. if (customer_cid) {
  5714. [dic setValue:customer_cid forKey:@"contactId"];
  5715. }
  5716. }
  5717. [dic setObject:screenName forKey:kScreenName];
  5718. [dic setValue:modelID forKey:@"productId"];
  5719. if (addr) { // 弹框输入
  5720. [dic setValue:addr forKey:@"email"];
  5721. } else {
  5722. // employee选择了Contact,并且Contact有Email
  5723. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5724. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  5725. // if (email) {
  5726. // [dic setValue:email forKey:@"email"];
  5727. // }
  5728. // }
  5729. }
  5730. if(appDelegate.offline_mode)
  5731. {
  5732. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5733. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5734. dispatch_async(dispatch_get_main_queue(), ^{
  5735. result(json);
  5736. });
  5737. });
  5738. return;
  5739. }
  5740. [self request_interface:URL_NOTIFY_ME parameters:dic err_record_url:nil completionHandler:result retry:0];
  5741. // NSData* json=nil;
  5742. // if(appDelegate.offline_mode)
  5743. // {
  5744. // return [OLDataProvider offline_notimpl];
  5745. // }
  5746. // else
  5747. // {
  5748. // if(![self IsNetworkAvailable])
  5749. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5750. //
  5751. // json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  5752. // }
  5753. // if(json!=nil)
  5754. // {
  5755. // NSError *error=nil;
  5756. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5757. //
  5758. //
  5759. // return jsobj;
  5760. // }
  5761. //
  5762. // return @{@"result" : @(RESULT_FALSE)};
  5763. }
  5764. + (void)request_qouteorder:(NSString *)so_id emailAddr:(NSString *)addr completionHandler:(resultHandler)result
  5765. {
  5766. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5767. AppDelegate *appDelegate = nil;
  5768. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5769. if(appDelegate.user!=nil)
  5770. [dic setValue:appDelegate.user forKey:@"user"];
  5771. if(appDelegate.password!=nil)
  5772. [dic setValue:appDelegate.password forKey:@"password"];
  5773. [dic setValue:so_id forKey:@"orderCode"];
  5774. [dic setValue:addr forKey:@"email"];
  5775. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5776. if (appDelegate.customerInfo) {
  5777. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5778. if (customer_cid) {
  5779. [dic setValue:customer_cid forKey:@"contactId"];
  5780. }
  5781. }
  5782. if(appDelegate.offline_mode)
  5783. {
  5784. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5785. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5786. dispatch_async(dispatch_get_main_queue(), ^{
  5787. result(json);
  5788. });
  5789. });
  5790. return;
  5791. }
  5792. [self request_interface:URL_EMAIL_CART parameters:dic err_record_url:nil completionHandler:result retry:0];
  5793. // NSData* json=nil;
  5794. // if(appDelegate.offline_mode)
  5795. // {
  5796. // return [OLDataProvider offline_notimpl];
  5797. // }
  5798. // else
  5799. // {
  5800. // if(![self IsNetworkAvailable])
  5801. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5802. //
  5803. // json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  5804. // }
  5805. // if(json!=nil)
  5806. // {
  5807. // NSError *error=nil;
  5808. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5809. //
  5810. //
  5811. // return jsobj;
  5812. // }
  5813. //
  5814. // return @{@"result" : @(RESULT_FALSE)};
  5815. }
  5816. + (void)request_mergeorder:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  5817. {
  5818. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5819. AppDelegate *appDelegate = nil;
  5820. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5821. if(appDelegate.user!=nil)
  5822. [dic setValue:appDelegate.user forKey:@"user"];
  5823. if(appDelegate.password!=nil)
  5824. [dic setValue:appDelegate.password forKey:@"password"];
  5825. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  5826. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  5827. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  5828. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  5829. if(appDelegate.offline_mode)
  5830. {
  5831. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5832. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5833. dispatch_async(dispatch_get_main_queue(), ^{
  5834. result(json);
  5835. });
  5836. });
  5837. return;
  5838. }
  5839. [self request_interface:URL_SET_MERGE_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5840. // NSData* json=nil;
  5841. // if(appDelegate.offline_mode)
  5842. // {
  5843. // return [OLDataProvider offline_notimpl];
  5844. // }
  5845. // else
  5846. // {
  5847. // if(![self IsNetworkAvailable])
  5848. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5849. //
  5850. // json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  5851. // }
  5852. // if(json!=nil)
  5853. // {
  5854. // NSError *error=nil;
  5855. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5856. //
  5857. //
  5858. // return jsobj;
  5859. // }
  5860. // else
  5861. // return nil;
  5862. }
  5863. +(void)request_pendingorder:(NSString *)contactid completionHandler:(resultHandler)result
  5864. {
  5865. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5866. AppDelegate *appDelegate = nil;
  5867. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5868. if(appDelegate.user!=nil)
  5869. [params setValue:appDelegate.user forKey:@"user"];
  5870. // if(appDelegate.contact_id!=nil)
  5871. if(appDelegate.password!=nil)
  5872. [params setValue:appDelegate.password forKey:@"password"];
  5873. [params setValue:contactid forKey:@"contactId"];
  5874. if(appDelegate.offline_mode)
  5875. {
  5876. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5877. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5878. dispatch_async(dispatch_get_main_queue(), ^{
  5879. result(json);
  5880. });
  5881. });
  5882. return;
  5883. }
  5884. [self request_interface:URL_CUSTOMER_PENDINGORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  5885. //
  5886. // if(appDelegate.offline_mode)
  5887. // {
  5888. // return [OLDataProvider offline_notimpl];
  5889. // }
  5890. // if(![self IsNetworkAvailable])
  5891. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5892. //
  5893. // NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  5894. // if(json==nil)
  5895. // return nil;
  5896. // NSError *error=nil;
  5897. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5898. // return jsobj;
  5899. //
  5900. }
  5901. +(void) request_removeportfolio:(NSString* ) item_ids completionHandler:(resultHandler)result
  5902. {
  5903. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5904. AppDelegate *appDelegate = nil;
  5905. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5906. if(appDelegate.user!=nil)
  5907. [params setValue:appDelegate.user forKey:@"user"];
  5908. if(appDelegate.contact_id!=nil)
  5909. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5910. if(appDelegate.password!=nil)
  5911. [params setValue:appDelegate.password forKey:@"password"];
  5912. [params setValue:item_ids forKey:@"portfolioId"];
  5913. // [params setValue:editor forKey:@"editor"];
  5914. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  5915. if(appDelegate.offline_mode)
  5916. {
  5917. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5918. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_removePortfolio:params]] mutableCopy];
  5919. dispatch_async(dispatch_get_main_queue(), ^{
  5920. int result_code = [[resulti valueForKey:@"result"] intValue];
  5921. if (result_code==2)
  5922. {
  5923. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5924. [appDelegate update_count_mark];
  5925. };
  5926. result(resulti);
  5927. });
  5928. });
  5929. return;
  5930. }
  5931. [self request_interface:URL_PORTFOLIO_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5932. int result_code = [[resulti valueForKey:@"result"] intValue];
  5933. if (result_code==2)
  5934. {
  5935. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5936. [appDelegate update_count_mark];
  5937. };
  5938. result(resulti);
  5939. } retry:0];
  5940. // NSData* json = nil;
  5941. // if(appDelegate.offline_mode)
  5942. // {
  5943. // json = [OLDataProvider offline_removePortfolio:params];
  5944. // } else {
  5945. // if(![self IsNetworkAvailable])
  5946. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5947. // json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  5948. // }
  5949. // if(json!=nil)
  5950. // {
  5951. // NSError *error=nil;
  5952. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5953. //
  5954. //
  5955. // int result = [[jsobj valueForKey:@"result"] intValue];
  5956. //
  5957. // if (result==2)
  5958. // {
  5959. //
  5960. //
  5961. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5962. //
  5963. // [appDelegate update_count_mark];
  5964. // }
  5965. // return jsobj;
  5966. // }
  5967. // else
  5968. // return nil;
  5969. }
  5970. +(void) request_removeportfoliopdf:(NSString* ) listid completionHandler:(resultHandler)result
  5971. {
  5972. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5973. AppDelegate *appDelegate = nil;
  5974. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5975. if(appDelegate.user!=nil)
  5976. [params setValue:appDelegate.user forKey:@"user"];
  5977. if(appDelegate.contact_id!=nil)
  5978. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5979. if(appDelegate.password!=nil)
  5980. [params setValue:appDelegate.password forKey:@"password"];
  5981. [params setValue:listid forKey:@"tearsheetsId"];
  5982. // [params setValue:editor forKey:@"editor"];
  5983. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  5984. // [params setValue:@"Delete Portfolio" forKey:kAction];
  5985. if(appDelegate.offline_mode)
  5986. {
  5987. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5988. NSData* json = [[OLDataProvider offline_removePDF:params] mutableCopy];
  5989. dispatch_async(dispatch_get_main_queue(), ^{
  5990. result([[RAConvertor data2dict:json] mutableCopy]);
  5991. });
  5992. });
  5993. return;
  5994. }
  5995. [self request_interface:URL_PORTFOLIOLIST_REMOVE parameters:params err_record_url:nil completionHandler:result retry:0];
  5996. }
  5997. +(void) request_remove_wishlist:(NSString* ) item_ids completionHandler:(resultHandler)result
  5998. {
  5999. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6000. __block AppDelegate *appDelegate = nil;
  6001. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6002. if(appDelegate.user!=nil)
  6003. [params setValue:appDelegate.user forKey:@"user"];
  6004. if(appDelegate.contact_id!=nil)
  6005. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6006. if(appDelegate.password!=nil)
  6007. [params setValue:appDelegate.password forKey:@"password"];
  6008. [params setValue:item_ids forKey:@"collectId"];
  6009. // [params setValue:editor forKey:@"editor"];
  6010. [params setValue:ScreenCodeWishList forKey:kScreenName];
  6011. if(appDelegate.offline_mode)
  6012. {
  6013. // [OLDataProvider offline_deletewishlist:params completionHandler:result];
  6014. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6015. NSMutableDictionary* resulti = [[OLDataProvider offline_deletewishlist:params] mutableCopy];
  6016. dispatch_async(dispatch_get_main_queue(), ^{
  6017. int result_code = [[resulti valueForKey:@"result"] intValue];
  6018. if (result_code==2)
  6019. {
  6020. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6021. [appDelegate update_count_mark];
  6022. };
  6023. result(resulti);
  6024. });
  6025. });
  6026. return;
  6027. }
  6028. [self request_interface:URL_WATCHLIST_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6029. int result_code = [[resulti valueForKey:@"result"] intValue];
  6030. if (result_code==2)
  6031. {
  6032. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6033. [appDelegate update_count_mark];
  6034. };
  6035. result(resulti);
  6036. } retry:0];
  6037. //
  6038. //
  6039. // if(appDelegate.offline_mode)
  6040. // {
  6041. // return [OLDataProvider offline_deletewishlist:params];
  6042. // }
  6043. // if(![self IsNetworkAvailable])
  6044. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6045. //
  6046. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  6047. // if(json!=nil)
  6048. // {
  6049. // NSError *error=nil;
  6050. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6051. // int result = [[jsobj valueForKey:@"result"] intValue];
  6052. //
  6053. // if (result==2)
  6054. // {
  6055. //
  6056. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6057. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6058. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6059. //
  6060. // [appDelegate update_count_mark];
  6061. // }
  6062. // return jsobj;
  6063. // }
  6064. // else
  6065. // return nil;
  6066. }
  6067. +(void) request_remove_cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  6068. {
  6069. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6070. AppDelegate *appDelegate = nil;
  6071. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6072. #ifdef SCANNER_ORDER
  6073. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  6074. {
  6075. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  6076. //
  6077. //
  6078. // [appDelegate update_count_mark];
  6079. NSArray* arr=[RAConvertor string2arr:item_ids separator:@","];
  6080. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  6081. NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  6082. NSMutableDictionary* newsection =[cartTemplate[@"section_0"] mutableCopy];
  6083. int newcount = 0;
  6084. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  6085. int count = [section[@"count"] intValue];
  6086. for(int i=0;i<count;i++)
  6087. {
  6088. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  6089. int index = [arr indexOfObject:item[@"cart_item_id"]] ;
  6090. if(index <0)
  6091. {
  6092. newsection[[NSString stringWithFormat:@"item_%d",newcount]] = item;
  6093. newcount ++;
  6094. }
  6095. }
  6096. newsection[@"count"]=@(newcount);
  6097. RASingleton.sharedInstance.scan_cart[@"section_0"] = newsection;
  6098. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  6099. result(RASingleton.sharedInstance.scan_cart);
  6100. return;
  6101. }
  6102. #endif
  6103. if(appDelegate.user!=nil)
  6104. [params setValue:appDelegate.user forKey:@"user"];
  6105. if(appDelegate.contact_id!=nil)
  6106. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6107. if(appDelegate.password!=nil)
  6108. [params setValue:appDelegate.password forKey:@"password"];
  6109. if(appDelegate.order_code!=nil)
  6110. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6111. [params setValue:item_ids forKey:@"cartItemId"];
  6112. // [params setValue:editor forKey:@"editor"];
  6113. [params setValue:ScreenCodeCart forKey:kScreenName];
  6114. // [params setValue:@"" forKey:kAction];
  6115. if(appDelegate.offline_mode)
  6116. {
  6117. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6118. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_cartremove:params]] mutableCopy];
  6119. dispatch_async(dispatch_get_main_queue(), ^{
  6120. int result_code = [[resulti valueForKey:@"result"] intValue];
  6121. if (result_code==2)
  6122. {
  6123. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6124. [appDelegate update_count_mark];
  6125. };
  6126. result(resulti);
  6127. });
  6128. });
  6129. return;
  6130. }
  6131. [self request_interface:URL_CART_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6132. int result_code = [[resulti valueForKey:@"result"] intValue];
  6133. if (result_code==2)
  6134. {
  6135. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6136. [appDelegate update_count_mark];
  6137. };
  6138. result(resulti);
  6139. } retry:0];
  6140. //
  6141. // NSData* json=nil;
  6142. // if(appDelegate.offline_mode)
  6143. // {
  6144. // json= [OLDataProvider offline_cartremove:params];
  6145. // }
  6146. // else
  6147. // {
  6148. // if(![self IsNetworkAvailable])
  6149. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6150. //
  6151. // json=[self get_json:URL_CART_REMOVE parameters:params];
  6152. // }
  6153. // if(json!=nil)
  6154. // {
  6155. // NSError *error=nil;
  6156. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6157. //
  6158. // int result = [[jsobj valueForKey:@"result"] intValue];
  6159. //
  6160. // if (result==2)
  6161. // {
  6162. //
  6163. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6164. //
  6165. //
  6166. // [appDelegate update_count_mark];
  6167. // }
  6168. // return jsobj;
  6169. // }
  6170. // else
  6171. // return nil;
  6172. }
  6173. +(void)request_delete_account:(resultHandler)result
  6174. {
  6175. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6176. AppDelegate *appDelegate = nil;
  6177. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6178. if(appDelegate.user!=nil)
  6179. [params setValue:appDelegate.user forKey:@"user"];
  6180. if(appDelegate.password!=nil)
  6181. [params setValue:appDelegate.password forKey:@"password"];
  6182. if(appDelegate.offline_mode)
  6183. {
  6184. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6185. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  6186. dispatch_async(dispatch_get_main_queue(), ^{
  6187. result(json);
  6188. });
  6189. });
  6190. return;
  6191. }
  6192. #ifdef SCANNER_ORDER
  6193. params[@"site_name"]=[RADataProvider getSiteName];
  6194. params[@"_method"]=@"cancelOfflineOrderUser";
  6195. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_DELETE_ACCOUNT];
  6196. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  6197. #else
  6198. [self request_interface:URL_DELETE_ACCOUNT parameters:params err_record_url:nil completionHandler:result retry:0];
  6199. #endif
  6200. }
  6201. +(void) request_create_order:(resultHandler)result
  6202. {
  6203. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6204. AppDelegate *appDelegate = nil;
  6205. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6206. if(appDelegate.user!=nil)
  6207. [params setValue:appDelegate.user forKey:@"user"];
  6208. if(appDelegate.contact_id!=nil)
  6209. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6210. if(appDelegate.password!=nil)
  6211. [params setValue:appDelegate.password forKey:@"password"];
  6212. if(appDelegate.order_code!=nil)
  6213. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6214. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  6215. NSDictionary* customerinfo= appDelegate.customerInfo;
  6216. NSArray* keys=[customerinfo allKeys];
  6217. for(int i=0;i<keys.count;i++)
  6218. {
  6219. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  6220. }
  6221. if(appDelegate.offline_mode)
  6222. {
  6223. [OLDataProvider offline_createorder:params completionHandler:^(NSMutableDictionary *resulti) {
  6224. int result_code = [[resulti valueForKey:@"result"] intValue];
  6225. if (result_code==2)
  6226. {
  6227. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6228. [appDelegate update_count_mark];
  6229. };
  6230. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  6231. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6232. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  6233. }
  6234. result(resulti);
  6235. }];
  6236. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6237. // NSData* json = [[OLDataProvider offline_createorder:params] mutableCopy];
  6238. // dispatch_async(dispatch_get_main_queue(), ^{
  6239. // result([[RAConvertor data2dict:json] mutableCopy]);
  6240. // });
  6241. // });
  6242. return;
  6243. }
  6244. [self request_interface:URL_NEW_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6245. int result_code = [[resulti valueForKey:@"result"] intValue];
  6246. if (result_code==2)
  6247. {
  6248. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6249. [appDelegate update_count_mark];
  6250. };
  6251. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  6252. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6253. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  6254. }
  6255. result(resulti);
  6256. } retry:0];
  6257. //
  6258. // NSData* json = nil;
  6259. // if(appDelegate.offline_mode)
  6260. // {
  6261. // json= [OLDataProvider offline_createorder:params];
  6262. // }
  6263. // else
  6264. // {
  6265. // if(![self IsNetworkAvailable])
  6266. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6267. //
  6268. // json=[self get_json:URL_NEW_ORDER parameters:params];
  6269. // }
  6270. // if(json==nil)
  6271. // return nil;
  6272. // NSError *error=nil;
  6273. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6274. // int result = [[jsobj valueForKey:@"result"] intValue];
  6275. //
  6276. // if (result==2)
  6277. // {
  6278. //
  6279. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6280. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6281. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6282. //
  6283. // [appDelegate update_count_mark];
  6284. // }
  6285. //
  6286. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  6287. //
  6288. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6289. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  6290. // }
  6291. //
  6292. // return jsobj;
  6293. }
  6294. +(void)request_open_order:(NSString*) order_code completionHandler:(resultHandler)result
  6295. {
  6296. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6297. AppDelegate *appDelegate = nil;
  6298. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6299. if(appDelegate.user!=nil)
  6300. [params setValue:appDelegate.user forKey:@"user"];
  6301. // if(appDelegate.contact_id!=nil)
  6302. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6303. if(appDelegate.password!=nil)
  6304. [params setValue:appDelegate.password forKey:@"password"];
  6305. [params setValue:order_code forKey:@"orderCode"];
  6306. // [params setValue:sourceid forKey:@"sourceid"];
  6307. // [params setValue:editor forKey:@"editor"];
  6308. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  6309. if(appDelegate.offline_mode)
  6310. {
  6311. params[@"appDelegate.order_code"]=appDelegate.order_code;
  6312. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6313. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_editorder:params]] mutableCopy];
  6314. dispatch_async(dispatch_get_main_queue(), ^{
  6315. int result_code = [[resulti valueForKey:@"result"] intValue];
  6316. if (result_code==2)
  6317. {
  6318. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6319. [appDelegate update_count_mark];
  6320. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6321. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  6322. }
  6323. }
  6324. result(resulti);
  6325. });
  6326. });
  6327. return;
  6328. }
  6329. [self request_interface:URL_OPEN_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6330. int result_code = [[resulti valueForKey:@"result"] intValue];
  6331. if (result_code==2)
  6332. {
  6333. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6334. [appDelegate update_count_mark];
  6335. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6336. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  6337. }
  6338. }
  6339. result(resulti);
  6340. } retry:0];
  6341. //
  6342. // NSData* json=nil;
  6343. // if(appDelegate.offline_mode)
  6344. // {
  6345. // json=[OLDataProvider offline_editorder:params];
  6346. //
  6347. // }
  6348. // else
  6349. // {
  6350. // if(![self IsNetworkAvailable])
  6351. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6352. //
  6353. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  6354. // }
  6355. // if(json!=nil)
  6356. // {
  6357. // NSError *error=nil;
  6358. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6359. // int result = [[jsobj valueForKey:@"result"] intValue];
  6360. //
  6361. // if (result==2)
  6362. // {
  6363. //
  6364. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6365. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6366. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6367. //
  6368. // [appDelegate update_count_mark];
  6369. //
  6370. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6371. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  6372. // }
  6373. //
  6374. // }
  6375. //
  6376. // return jsobj;
  6377. // }
  6378. // else
  6379. // return nil;
  6380. }
  6381. +(void)request_cart:(int)sort completionHandler:(resultHandler)result
  6382. {
  6383. DebugLog(@"iSalesNetwork::request_Cart");
  6384. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6385. AppDelegate *appDelegate = nil;
  6386. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6387. #ifdef SCANNER_ORDER
  6388. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  6389. {
  6390. appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  6391. [appDelegate update_count_mark];
  6392. result(RASingleton.sharedInstance.scan_cart);
  6393. return;
  6394. }
  6395. #endif
  6396. if(appDelegate.user!=nil)
  6397. [params setValue:appDelegate.user forKey:@"user"];
  6398. // if(appDelegate.contact_id!=nil)
  6399. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6400. if(appDelegate.password!=nil)
  6401. [params setValue:appDelegate.password forKey:@"password"];
  6402. if(appDelegate.order_code!=nil)
  6403. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6404. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  6405. [params setObject:ScreenCodeCart forKey:kScreenName];
  6406. if(appDelegate.offline_mode)
  6407. {
  6408. [OLDataProvider offline_requestcart:params completionHandler:^(NSMutableDictionary *resulti) {
  6409. if([resulti[@"result"] intValue]==2)
  6410. {
  6411. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6412. [appDelegate update_count_mark];
  6413. result(resulti);
  6414. }
  6415. }];
  6416. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6417. // NSData* json = [[OLDataProvider offline_requestcart:params] mutableCopy];
  6418. // dispatch_async(dispatch_get_main_queue(), ^{
  6419. // result([[RAConvertor data2dict:json] mutableCopy]);
  6420. // });
  6421. // });
  6422. return;
  6423. }
  6424. NSString * uuid= [[NSUUID UUID] UUIDString];
  6425. params[@"resultSerial"]=uuid;
  6426. __block bool bbreak = false;
  6427. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6428. for(int i=0;i<150;i++)
  6429. {
  6430. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6431. // result_params[@"resultSerial"]=uuid;
  6432. if(bbreak)
  6433. break;
  6434. dispatch_async(dispatch_get_main_queue(), ^{
  6435. [self request_interface:URL_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6436. if([resulti[@"result"] intValue]==2)
  6437. {
  6438. if(!bbreak) //此判断保证result只调用一次。
  6439. {
  6440. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6441. [appDelegate update_count_mark];
  6442. result(resulti);
  6443. }
  6444. bbreak=true;
  6445. }
  6446. } retry:3];
  6447. });
  6448. sleep(2);
  6449. // json=[self get_json:URL_CART parameters:params];
  6450. // if(json!=nil)
  6451. // {
  6452. //
  6453. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6454. // if([jsobj[@"result"] intValue]==2)
  6455. // {
  6456. // break;
  6457. // }
  6458. // }
  6459. }
  6460. });
  6461. //
  6462. //
  6463. //
  6464. // NSData* json=nil;
  6465. // if(appDelegate.offline_mode)
  6466. // {
  6467. // json= [OLDataProvider offline_requestcart:params];
  6468. // }
  6469. // else
  6470. // {
  6471. // if(![self IsNetworkAvailable])
  6472. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6473. //
  6474. // NSError *error=nil;
  6475. //
  6476. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6477. // params[@"resultSerial"]=uuid;
  6478. //
  6479. // for(int i=0;i<150;i++)
  6480. // {
  6481. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6482. // // result_params[@"resultSerial"]=uuid;
  6483. // json=[self get_json:URL_CART parameters:params];
  6484. // if(json!=nil)
  6485. // {
  6486. //
  6487. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6488. // if([jsobj[@"result"] intValue]==2)
  6489. // {
  6490. // break;
  6491. // }
  6492. // }
  6493. // sleep(2);
  6494. // }
  6495. //
  6496. // }
  6497. // if(json==nil)
  6498. // return nil;
  6499. // NSError *error=nil;
  6500. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6501. // int result = [[jsobj valueForKey:@"result"] intValue];
  6502. //
  6503. // if (result==2)
  6504. // {
  6505. //
  6506. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6507. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  6508. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6509. //
  6510. // [appDelegate update_count_mark];
  6511. // }
  6512. // return jsobj;
  6513. }
  6514. +(void) request_move_wish2cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  6515. {
  6516. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6517. AppDelegate *appDelegate = nil;
  6518. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6519. if(appDelegate.user!=nil)
  6520. [params setValue:appDelegate.user forKey:@"user"];
  6521. if(appDelegate.contact_id!=nil)
  6522. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6523. if(appDelegate.password!=nil)
  6524. [params setValue:appDelegate.password forKey:@"password"];
  6525. if(appDelegate.order_code!=nil)
  6526. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6527. [params setValue:item_ids forKey:@"collectId"];
  6528. // [params setValue:editor forKey:@"editor"];
  6529. [params setValue:ScreenCodeWishList forKey:kScreenName];
  6530. [params setValue:@"Move To Cart" forKey:kAction];
  6531. if(appDelegate.offline_mode)
  6532. {
  6533. // [OLDataProvider offline_movewish2cart:params completionHandler:result];
  6534. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6535. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6536. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movewish2cart:params]] mutableCopy];
  6537. dispatch_async(dispatch_get_main_queue(), ^{
  6538. int result_code = [[resulti valueForKey:@"result"] intValue];
  6539. if (result_code==2)
  6540. {
  6541. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6542. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6543. [appDelegate update_count_mark];
  6544. }
  6545. result(resulti);
  6546. });
  6547. });
  6548. return;
  6549. }
  6550. [self request_interface:URL_WISH2CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6551. int result_code = [[resulti valueForKey:@"result"] intValue];
  6552. if (result_code==2)
  6553. {
  6554. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6555. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6556. [appDelegate update_count_mark];
  6557. }
  6558. result(resulti);
  6559. } retry:0];
  6560. //
  6561. // NSData *json = nil;
  6562. // if(appDelegate.offline_mode)
  6563. // {
  6564. // json = [OLDataProvider offline_movewish2cart:params];
  6565. // } else {
  6566. // if(![self IsNetworkAvailable])
  6567. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6568. //
  6569. // json=[self get_json:URL_WISH2CART parameters:params];
  6570. // }
  6571. //
  6572. // if(json!=nil)
  6573. // {
  6574. // NSError *error=nil;
  6575. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6576. // int result = [[jsobj valueForKey:@"result"] intValue];
  6577. //
  6578. // if (result==2)
  6579. // {
  6580. //
  6581. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6582. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6583. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6584. //
  6585. // [appDelegate update_count_mark];
  6586. // }
  6587. // return jsobj;
  6588. // }
  6589. // else
  6590. // return nil;
  6591. }
  6592. +(void) request_move_cart2wish:(NSString* ) item_ids completionHandler:(resultHandler)result
  6593. {
  6594. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6595. AppDelegate *appDelegate = nil;
  6596. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6597. if(appDelegate.user!=nil)
  6598. [params setValue:appDelegate.user forKey:@"user"];
  6599. if(appDelegate.contact_id!=nil)
  6600. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6601. if(appDelegate.password!=nil)
  6602. [params setValue:appDelegate.password forKey:@"password"];
  6603. if(appDelegate.order_code!=nil)
  6604. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6605. [params setValue:item_ids forKey:@"cartItemId"];
  6606. // [params setValue:editor forKey:@"editor"];
  6607. [params setValue:ScreenCodeCart forKey:kScreenName];
  6608. // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  6609. if(appDelegate.offline_mode)
  6610. {
  6611. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6612. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movecart2wish:params]] mutableCopy];
  6613. dispatch_async(dispatch_get_main_queue(), ^{
  6614. int result_code = [[resulti valueForKey:@"result"] intValue];
  6615. if (result_code==2)
  6616. {
  6617. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6618. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6619. [appDelegate update_count_mark];
  6620. }
  6621. result(resulti);
  6622. });
  6623. });
  6624. return;
  6625. }
  6626. [self request_interface:URL_CART2WISH parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6627. int result_code = [[resulti valueForKey:@"result"] intValue];
  6628. if (result_code==2)
  6629. {
  6630. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6631. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6632. [appDelegate update_count_mark];
  6633. }
  6634. result(resulti);
  6635. } retry:0];
  6636. //
  6637. // NSData* json = nil;
  6638. // if(appDelegate.offline_mode)
  6639. // {
  6640. // json= [OLDataProvider offline_movecart2wish:params];
  6641. // }
  6642. // else
  6643. // {
  6644. // if(![self IsNetworkAvailable])
  6645. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6646. //
  6647. // json=[self get_json:URL_CART2WISH parameters:params];
  6648. // }
  6649. // if(json!=nil)
  6650. // {
  6651. // NSError *error=nil;
  6652. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6653. // int result = [[jsobj valueForKey:@"result"] intValue];
  6654. //
  6655. // if (result==2)
  6656. // {
  6657. //
  6658. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6659. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6660. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6661. //
  6662. // [appDelegate update_count_mark];
  6663. // }
  6664. // return jsobj;
  6665. // }
  6666. // else
  6667. // return nil;
  6668. }
  6669. +(void)request_orderdetail:(NSMutableDictionary *) params completionHandler:(resultHandler)result
  6670. {
  6671. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6672. if (params == nil) {
  6673. params = [[NSMutableDictionary alloc] init];
  6674. }
  6675. AppDelegate *appDelegate = nil;
  6676. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6677. if(appDelegate.user!=nil)
  6678. [params setValue:appDelegate.user forKey:@"user"];
  6679. if(appDelegate.contact_id!=nil)
  6680. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6681. if(appDelegate.password!=nil)
  6682. [params setValue:appDelegate.password forKey:@"password"];
  6683. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  6684. [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  6685. if(appDelegate.offline_mode)
  6686. {
  6687. params[@"mode"]=appDelegate.mode;
  6688. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6689. NSData* json = [[OLDataProvider offline_orderdetail:params] mutableCopy];
  6690. dispatch_async(dispatch_get_main_queue(), ^{
  6691. result([[RAConvertor data2dict:json] mutableCopy]);
  6692. });
  6693. });
  6694. return;
  6695. }
  6696. NSString * uuid= [[NSUUID UUID] UUIDString];
  6697. params[@"resultSerial"]=uuid;
  6698. __block bool bbreak = false;
  6699. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6700. for(int i=0;i<150;i++)
  6701. {
  6702. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6703. // result_params[@"resultSerial"]=uuid;
  6704. if(bbreak)
  6705. break;
  6706. dispatch_async(dispatch_get_main_queue(), ^{
  6707. [self request_interface:URL_ORDER_DETAIL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6708. if([resulti[@"result"] intValue]==2||[resulti[@"result"] intValue]==8)
  6709. {
  6710. if(!bbreak)//此判断保证result只调用一次。
  6711. result(resulti);
  6712. bbreak=true;
  6713. }
  6714. } retry:3];
  6715. });
  6716. sleep(2);
  6717. }
  6718. });
  6719. //
  6720. // NSData* json=nil;
  6721. // if(appDelegate.offline_mode)
  6722. // {
  6723. // json= [OLDataProvider offline_orderdetail:params];
  6724. // }
  6725. // else
  6726. // {
  6727. // if(![self IsNetworkAvailable])
  6728. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6729. //
  6730. // NSError *error=nil;
  6731. //
  6732. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6733. // params[@"resultSerial"]=uuid;
  6734. //
  6735. // for(int i=0;i<150;i++)
  6736. // {
  6737. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6738. // // result_params[@"resultSerial"]=uuid;
  6739. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  6740. // if(json!=nil)
  6741. // {
  6742. //
  6743. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6744. // int resultCode = [jsobj[@"result"] intValue];
  6745. // if(resultCode==2 || resultCode == 8)
  6746. // {
  6747. // break;
  6748. // }
  6749. // }
  6750. // sleep(2);
  6751. // }
  6752. //
  6753. //
  6754. // }
  6755. // if(json==nil)
  6756. // return nil;
  6757. // NSError *error=nil;
  6758. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6759. // return jsobj;
  6760. }
  6761. //
  6762. //+(void)request_commit_order:(NSString*) order_code completionHandler:(resultHandler)result
  6763. //{
  6764. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6765. // AppDelegate *appDelegate = nil;
  6766. //
  6767. //
  6768. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6769. //
  6770. // if(appDelegate.user!=nil)
  6771. // [params setValue:appDelegate.user forKey:@"user"];
  6772. // if(appDelegate.contact_id!=nil)
  6773. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6774. // if(appDelegate.password!=nil)
  6775. // [params setValue:appDelegate.password forKey:@"password"];
  6776. // // NSString* ssaved = @"false";
  6777. // // if(saved)
  6778. // // ssaved=@"true";
  6779. // [params setValue:@"true" forKey:@"saved"];
  6780. // [params setValue:order_code forKey:@"orderCode"];
  6781. // // [params setValue:sourceid forKey:@"sourceid"];
  6782. // // [params setValue:editor forKey:@"editor"];
  6783. //
  6784. // [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  6785. //
  6786. //
  6787. // if(appDelegate.offline_mode)
  6788. // {
  6789. //
  6790. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6791. // NSMutableDictionary* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  6792. // dispatch_async(dispatch_get_main_queue(), ^{
  6793. // result(json);
  6794. // });
  6795. // });
  6796. //
  6797. // return;
  6798. // }
  6799. //
  6800. //
  6801. // [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6802. //
  6803. //// NSData* json = nil;
  6804. ////
  6805. //// if(appDelegate.offline_mode)
  6806. //// {
  6807. //// json= [OLDataProvider offline_submitorder:params];
  6808. //// }
  6809. //// else
  6810. //// {
  6811. //// if(![self IsNetworkAvailable])
  6812. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6813. ////
  6814. //// json=[self get_json:URL_COMMIT_ORDER parameters:params];
  6815. //// }
  6816. //// if(json!=nil)
  6817. //// {
  6818. //// NSError *error=nil;
  6819. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6820. //// return jsobj;
  6821. //// }
  6822. //// else
  6823. //// return nil;
  6824. //
  6825. //}
  6826. +(void)request_copy_order:(NSString*) order_code completionHandler:(resultHandler)result
  6827. {
  6828. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6829. AppDelegate *appDelegate = nil;
  6830. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6831. if(appDelegate.user!=nil)
  6832. [params setValue:appDelegate.user forKey:@"user"];
  6833. if(appDelegate.contact_id!=nil)
  6834. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6835. if(appDelegate.password!=nil)
  6836. [params setValue:appDelegate.password forKey:@"password"];
  6837. // NSString* ssaved = @"false";
  6838. // if(saved)
  6839. // ssaved=@"true";
  6840. // [params setValue:@"true" forKey:@"saved"];
  6841. [params setValue:order_code forKey:@"code"];
  6842. // [params setValue:sourceid forKey:@"sourceid"];
  6843. // [params setValue:editor forKey:@"editor"];
  6844. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  6845. if(appDelegate.offline_mode)
  6846. {
  6847. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6848. NSData* json = [[OLDataProvider offline_copyorder:params] mutableCopy];
  6849. dispatch_async(dispatch_get_main_queue(), ^{
  6850. result([[RAConvertor data2dict:json] mutableCopy]);
  6851. });
  6852. });
  6853. return;
  6854. }
  6855. [self request_interface:URL_COPY_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6856. // NSData* json=nil;
  6857. // if(appDelegate.offline_mode)
  6858. // {
  6859. // json= [OLDataProvider offline_copyorder:params];
  6860. // }
  6861. // else
  6862. // {
  6863. // if(![self IsNetworkAvailable])
  6864. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6865. //
  6866. // json=[self get_json:URL_COPY_ORDER parameters:params];
  6867. // }
  6868. // if(json!=nil)
  6869. // {
  6870. // NSError *error=nil;
  6871. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6872. // return jsobj;
  6873. // }
  6874. // else
  6875. // return nil;
  6876. }
  6877. //
  6878. //+ (void)request_fastdownload:(NSMutableDictionary *)params url:(NSString *)url completionHandler:(resultHandler)result
  6879. //{
  6880. //
  6881. // //#ifdef test_server
  6882. // // url=URL_REQUEST_RECORDS;
  6883. // // params[@"prefix"]=URL_REQUEST_RECORDS;
  6884. // //#endif
  6885. //
  6886. // [self request_file_fast:url parameters:params completionHandler:result];
  6887. //
  6888. //}
  6889. +(void) request_addto_portfolio:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6890. {
  6891. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6892. AppDelegate *appDelegate = nil;
  6893. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6894. if(appDelegate.user!=nil)
  6895. [params setValue:appDelegate.user forKey:@"user"];
  6896. if(appDelegate.contact_id!=nil)
  6897. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6898. if(appDelegate.password!=nil)
  6899. [params setValue:appDelegate.password forKey:@"password"];
  6900. [params setValue:item_id forKey:@"product_id"];
  6901. [params setObject:screenName forKey:kScreenName];
  6902. if(appDelegate.offline_mode)
  6903. {
  6904. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6905. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_add2Portfolio:params]] mutableCopy];
  6906. dispatch_async(dispatch_get_main_queue(), ^{
  6907. int result_code = [[resulti valueForKey:@"result"] intValue];
  6908. if (result_code==2)
  6909. {
  6910. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6911. [appDelegate update_count_mark];
  6912. }
  6913. result(resulti);
  6914. });
  6915. });
  6916. return;
  6917. }
  6918. [self request_interface:URL_ADD_TO_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6919. int result_code = [[resulti valueForKey:@"result"] intValue];
  6920. if (result_code==2)
  6921. {
  6922. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6923. [appDelegate update_count_mark];
  6924. }
  6925. result(resulti);
  6926. } retry:0];
  6927. //
  6928. // NSData* json = nil;
  6929. // if(appDelegate.offline_mode)
  6930. // {
  6931. // json = [OLDataProvider offline_add2Portfolio:params];
  6932. // } else {
  6933. // if(![self IsNetworkAvailable])
  6934. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6935. //
  6936. // json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  6937. // }
  6938. //
  6939. // if(json==nil)
  6940. // return nil;
  6941. // NSError *error=nil;
  6942. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6943. // int result = [[jsobj valueForKey:@"result"] intValue];
  6944. //
  6945. // if (result==2)
  6946. // {
  6947. //
  6948. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6949. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6950. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6951. //
  6952. // [appDelegate update_count_mark];
  6953. // }
  6954. // return jsobj;
  6955. }
  6956. +(void)request_addall_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  6957. {
  6958. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6959. AppDelegate *appDelegate = nil;
  6960. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6961. if(appDelegate.user!=nil)
  6962. [params setValue:appDelegate.user forKey:@"user"];
  6963. if(appDelegate.contact_id!=nil)
  6964. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6965. if(appDelegate.password!=nil)
  6966. [params setValue:appDelegate.password forKey:@"password"];
  6967. if(appDelegate.order_code!=nil)
  6968. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6969. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6970. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6971. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  6972. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6973. // [params setValue:filter forKey:@"filter"];
  6974. [params setValue:keywords forKey:@"keyword"];
  6975. [params setValue:addTo forKey:@"addTo"];
  6976. [params setValue:orderCode forKey:@"orderCode"];
  6977. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6978. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6979. if(matchfull)
  6980. [params setValue:@"true" forKey:@"exactMatch"];
  6981. else
  6982. [params setValue:@"false" forKey:@"exactMatch"];
  6983. [params setObject:ScreenCodeSearch forKey:kScreenName];
  6984. if ([addTo isEqualToString:@"cart"]) {
  6985. [params setObject:@"Add To Cart" forKey:kAction];
  6986. }
  6987. if(appDelegate.offline_mode)
  6988. {
  6989. if ([addTo isEqualToString:@"cart"])
  6990. {
  6991. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6992. }
  6993. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6994. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_searchaddall:params]] mutableCopy];
  6995. dispatch_async(dispatch_get_main_queue(), ^{
  6996. int result_code =[json[@"result"] intValue];
  6997. if (result_code==2||result_code==8)
  6998. {
  6999. if(json[@"cart_count"])
  7000. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7001. if(json[@"wish_count"])
  7002. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7003. if(json[@"portfolio_count"])
  7004. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7005. //
  7006. //
  7007. [appDelegate update_count_mark];
  7008. }
  7009. result(json);
  7010. });
  7011. });
  7012. return;
  7013. }
  7014. NSString * uuid= [[NSUUID UUID] UUIDString];
  7015. params[@"resultSerial"]=uuid;
  7016. __block bool bbreak = false;
  7017. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7018. for(int i=0;i<150;i++)
  7019. {
  7020. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7021. // result_params[@"resultSerial"]=uuid;
  7022. if(bbreak)
  7023. break;
  7024. dispatch_async(dispatch_get_main_queue(), ^{
  7025. [self request_interface:URL_SEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7026. if([resulti[@"result"] intValue]==2)
  7027. {
  7028. if(!bbreak)//此判断保证result只调用一次。
  7029. result(resulti);
  7030. bbreak=true;
  7031. }
  7032. } retry:3];
  7033. });
  7034. sleep(2);
  7035. }
  7036. });
  7037. //
  7038. //
  7039. // NSData* json=nil;
  7040. // if(appDelegate.offline_mode)
  7041. // {
  7042. // json=[OLDataProvider offline_searchaddall:params];
  7043. // }
  7044. // else
  7045. // {
  7046. // if(![self IsNetworkAvailable])
  7047. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7048. //
  7049. // NSError *error=nil;
  7050. //
  7051. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7052. // params[@"resultSerial"]=uuid;
  7053. //
  7054. // for(int i=0;i<150;i++)
  7055. // {
  7056. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7057. // // result_params[@"resultSerial"]=uuid;
  7058. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  7059. // if(json!=nil)
  7060. // {
  7061. //
  7062. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7063. // if([jsobj[@"result"] intValue]==2)
  7064. // {
  7065. // break;
  7066. // }
  7067. // }
  7068. // sleep(2);
  7069. // }
  7070. // }
  7071. // if(json==nil)
  7072. // return nil;
  7073. // NSError *error=nil;
  7074. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7075. // return jsobj;
  7076. }
  7077. +(void) request_addto_cart_byupc:(NSString* ) upc_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  7078. {
  7079. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7080. AppDelegate *appDelegate = nil;
  7081. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7082. if(appDelegate.user!=nil)
  7083. [params setValue:appDelegate.user forKey:@"user"];
  7084. if(appDelegate.contact_id!=nil)
  7085. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7086. if(appDelegate.password!=nil)
  7087. [params setValue:appDelegate.password forKey:@"password"];
  7088. if(appDelegate.order_code!=nil)
  7089. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7090. [params setValue:upc_code forKey:@"upc_code"];
  7091. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  7092. [params setObject:screenName forKey:kScreenName];
  7093. [params setObject:@"Add To Cart" forKey:kAction];
  7094. if (!upc_code) {
  7095. upc_code = @"";
  7096. }
  7097. [params setObject:@{@"UPCCode" : upc_code} forKey:kExtra];
  7098. params[@"search_upc"]=@true;
  7099. NSDictionary* customerinfo= appDelegate.customerInfo;
  7100. NSArray* keys=[customerinfo allKeys];
  7101. for(int i=0;i<keys.count;i++)
  7102. {
  7103. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7104. }
  7105. if(appDelegate.offline_mode)
  7106. {
  7107. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7108. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  7109. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7110. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyupc:params]] mutableCopy];
  7111. dispatch_async(dispatch_get_main_queue(), ^{
  7112. int result_code = [[json valueForKey:@"result"] intValue];
  7113. if (result_code==2||result_code==8)
  7114. {
  7115. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7116. [appDelegate update_count_mark];
  7117. }
  7118. result(json);
  7119. });
  7120. });
  7121. return;
  7122. }
  7123. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7124. int result_code = [[resulti valueForKey:@"result"] intValue];
  7125. if (result_code==2||result_code==8)
  7126. {
  7127. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7128. [appDelegate update_count_mark];
  7129. }
  7130. result(resulti);
  7131. } retry:0];
  7132. }
  7133. +(void) request_addto_cart_byname:(NSString* ) model_name withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  7134. {
  7135. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7136. AppDelegate *appDelegate = nil;
  7137. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7138. if(appDelegate.user!=nil)
  7139. [params setValue:appDelegate.user forKey:@"user"];
  7140. if(appDelegate.contact_id!=nil)
  7141. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7142. if(appDelegate.password!=nil)
  7143. [params setValue:appDelegate.password forKey:@"password"];
  7144. if(appDelegate.order_code!=nil)
  7145. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7146. [params setValue:model_name forKey:@"product_name"];
  7147. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  7148. [params setObject:screenName forKey:kScreenName];
  7149. [params setObject:@"Add To Cart" forKey:kAction];
  7150. if (!model_name) {
  7151. model_name = @"";
  7152. }
  7153. [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  7154. NSDictionary* customerinfo= appDelegate.customerInfo;
  7155. NSArray* keys=[customerinfo allKeys];
  7156. for(int i=0;i<keys.count;i++)
  7157. {
  7158. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7159. }
  7160. if(appDelegate.offline_mode)
  7161. {
  7162. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7163. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  7164. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7165. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyname:params]] mutableCopy];
  7166. dispatch_async(dispatch_get_main_queue(), ^{
  7167. int result_code = [[json valueForKey:@"result"] intValue];
  7168. if (result_code==2||result_code==8)
  7169. {
  7170. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7171. [appDelegate update_count_mark];
  7172. }
  7173. result(json);
  7174. });
  7175. });
  7176. return;
  7177. }
  7178. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7179. int result_code = [[resulti valueForKey:@"result"] intValue];
  7180. if (result_code==2||result_code==8)
  7181. {
  7182. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7183. [appDelegate update_count_mark];
  7184. }
  7185. result(resulti);
  7186. } retry:0];
  7187. // NSData* json=nil;
  7188. // if(appDelegate.offline_mode)
  7189. // {
  7190. // json= [OLDataProvider offline_add2cartbyname:params];
  7191. // }
  7192. // else
  7193. // {
  7194. // if(![self IsNetworkAvailable])
  7195. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7196. //
  7197. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  7198. // }
  7199. // if(json==nil)
  7200. // return nil;
  7201. // NSError *error=nil;
  7202. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7203. //
  7204. //
  7205. //
  7206. // int result = [[jsobj valueForKey:@"result"] intValue];
  7207. //
  7208. // if (result==2||result==8)
  7209. // {
  7210. //
  7211. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  7212. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  7213. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  7214. //
  7215. // [appDelegate update_count_mark];
  7216. // }
  7217. //
  7218. // return jsobj;
  7219. }
  7220. +(void) request_addto_wishlist:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  7221. {
  7222. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7223. AppDelegate *appDelegate = nil;
  7224. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7225. if(appDelegate.user!=nil)
  7226. [params setValue:appDelegate.user forKey:@"user"];
  7227. if(appDelegate.contact_id!=nil)
  7228. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7229. if(appDelegate.password!=nil)
  7230. [params setValue:appDelegate.password forKey:@"password"];
  7231. [params setValue:item_id forKey:@"product_id"];
  7232. [params setObject:screenName forKey:kScreenName];
  7233. if(appDelegate.offline_mode)
  7234. {
  7235. // [OLDataProvider offline_add2wishlist:params completionHandler:result];
  7236. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7237. NSMutableDictionary* resulti = [[OLDataProvider offline_add2wishlist:params] mutableCopy];
  7238. dispatch_async(dispatch_get_main_queue(), ^{
  7239. int result_code = [[resulti valueForKey:@"result"] intValue];
  7240. if (result_code==2||result_code==8)
  7241. {
  7242. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7243. [appDelegate update_count_mark];
  7244. }
  7245. result(resulti);
  7246. });
  7247. });
  7248. return;
  7249. }
  7250. [self request_interface:URL_ADD_TO_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7251. int result_code = [[resulti valueForKey:@"result"] intValue];
  7252. if (result_code==2||result_code==8)
  7253. {
  7254. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7255. [appDelegate update_count_mark];
  7256. }
  7257. result(resulti);
  7258. } retry:0];
  7259. // if(appDelegate.offline_mode)
  7260. // {
  7261. // return [OLDataProvider offline_add2wishlist:params];
  7262. // }
  7263. // if(![self IsNetworkAvailable])
  7264. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7265. //
  7266. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  7267. // if(json==nil)
  7268. // return nil;
  7269. // NSError *error=nil;
  7270. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7271. // int result = [[jsobj valueForKey:@"result"] intValue];
  7272. //
  7273. // if (result==2)
  7274. // {
  7275. //
  7276. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  7277. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  7278. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  7279. //
  7280. // [appDelegate update_count_mark];
  7281. // }
  7282. // return jsobj;
  7283. }
  7284. +(void)request_addall_itemsearch:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  7285. {
  7286. // for debug
  7287. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  7288. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7289. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7290. AppDelegate *appDelegate = nil;
  7291. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7292. if(appDelegate.user!=nil)
  7293. [params setValue:appDelegate.user forKey:@"user"];
  7294. if(appDelegate.contact_id!=nil)
  7295. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7296. if(appDelegate.password!=nil)
  7297. [params setValue:appDelegate.password forKey:@"password"];
  7298. if(appDelegate.order_code!=nil)
  7299. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7300. [params setValue:addTo forKey:@"addTo"];
  7301. [params setValue:orderCode forKey:@"orderCode"];
  7302. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7303. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7304. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  7305. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7306. // [params setValue:filter forKey:@"filter"];
  7307. [params setValue:covertype forKey:@"covertype"];
  7308. [params setValue:ctgid forKey:@"ctgId"];
  7309. [params setValue:modelname forKey:@"modelName"];
  7310. [params setValue:modeldescrip forKey:@"modelDescription"];
  7311. [params setValue:alert forKey:@"alert"];
  7312. [params setValue:qty forKey:@"sold_by_qty"];
  7313. [params setValue:available forKey:@"available"];
  7314. [params setValue:price forKey:@"price"];
  7315. [params setValue:bestseller forKey:@"bestseller"];
  7316. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7317. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7318. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  7319. if ([addTo isEqualToString:@"cart"]) {
  7320. [params setObject:@"Add To Cart" forKey:kAction];
  7321. }
  7322. if(appDelegate.offline_mode)
  7323. {
  7324. if ([addTo isEqualToString:@"cart"])
  7325. {
  7326. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7327. }
  7328. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7329. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_itemsearchaddall:params]] mutableCopy];
  7330. dispatch_async(dispatch_get_main_queue(), ^{
  7331. int result_code =[json[@"result"] intValue];
  7332. if (result_code==2||result_code==8)
  7333. {
  7334. if(json[@"cart_count"])
  7335. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7336. if(json[@"wish_count"])
  7337. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7338. if(json[@"portfolio_count"])
  7339. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7340. //
  7341. //
  7342. [appDelegate update_count_mark];
  7343. }
  7344. result(json);
  7345. });
  7346. });
  7347. return;
  7348. }
  7349. NSString * uuid= [[NSUUID UUID] UUIDString];
  7350. params[@"resultSerial"]=uuid;
  7351. __block bool bbreak = false;
  7352. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7353. for(int i=0;i<150;i++)
  7354. {
  7355. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7356. // result_params[@"resultSerial"]=uuid;
  7357. if(bbreak)
  7358. break;
  7359. dispatch_async(dispatch_get_main_queue(), ^{
  7360. [self request_interface:URL_ITEMSEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7361. if([resulti[@"result"] intValue]==2)
  7362. {
  7363. if(!bbreak)//此判断保证result只调用一次。
  7364. result(resulti);
  7365. bbreak=true;
  7366. }
  7367. } retry:3];
  7368. });
  7369. sleep(2);
  7370. }
  7371. });
  7372. //
  7373. // NSData* json = nil;
  7374. //
  7375. // if(appDelegate.offline_mode)
  7376. // {
  7377. // json= [OLDataProvider offline_itemsearchaddall:params];
  7378. // }
  7379. // else
  7380. // {
  7381. // if(![self IsNetworkAvailable])
  7382. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7383. // NSError *error=nil;
  7384. //
  7385. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7386. // params[@"resultSerial"]=uuid;
  7387. //
  7388. // for(int i=0;i<150;i++)
  7389. // {
  7390. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7391. // // result_params[@"resultSerial"]=uuid;
  7392. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  7393. // if(json!=nil)
  7394. // {
  7395. //
  7396. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7397. // if([jsobj[@"result"] intValue]==2)
  7398. // {
  7399. // break;
  7400. // }
  7401. // }
  7402. // sleep(2);
  7403. // }
  7404. // }
  7405. // if(json==nil)
  7406. // return nil;
  7407. // NSError *error=nil;
  7408. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7409. // return jsobj;
  7410. }
  7411. +(void)request_addall_category: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  7412. {
  7413. AppDelegate *appDelegate = nil;
  7414. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7415. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7416. if(appDelegate.user!=nil)
  7417. [params setValue:appDelegate.user forKey:@"user"];
  7418. if(appDelegate.contact_id!=nil)
  7419. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7420. if(appDelegate.password!=nil)
  7421. [params setValue:appDelegate.password forKey:@"password"];
  7422. if(appDelegate.order_code!=nil)
  7423. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7424. [params setValue:addTo forKey:@"addTo"];
  7425. [params setValue:orderCode forKey:@"orderCode"];
  7426. [params setValue:alert forKey:@"alert"];
  7427. [params setValue:qty forKey:@"sold_by_qty"];
  7428. [params setValue:available forKey:@"available"];
  7429. [params setValue:price forKey:@"price"];
  7430. [params setValue:bestseller forKey:@"bestseller"];
  7431. [params setValue:modelname forKey:@"modelName"];
  7432. [params setValue:modeldescrip forKey:@"modelDescription"];
  7433. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7434. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7435. [params setValue:category forKey:@"category"];
  7436. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7437. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7438. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7439. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7440. [params setValue:filter forKey:@"filter"];
  7441. [params setValue:keyword forKey:@"keyword"];
  7442. [params setObject:ScreenCodeCategory forKey:kScreenName];
  7443. if ([addTo isEqualToString:@"cart"]) {
  7444. [params setObject:@"Add To Cart" forKey:kAction];
  7445. }
  7446. if(appDelegate.offline_mode)
  7447. {
  7448. if ([addTo isEqualToString:@"cart"])
  7449. {
  7450. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7451. }
  7452. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7453. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_categoryaddall:params]] mutableCopy];
  7454. dispatch_async(dispatch_get_main_queue(), ^{
  7455. int result_code =[json[@"result"] intValue];
  7456. if (result_code==2||result_code==8)
  7457. {
  7458. if(json[@"cart_count"])
  7459. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7460. if(json[@"wish_count"])
  7461. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7462. if(json[@"portfolio_count"])
  7463. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7464. //
  7465. //
  7466. [appDelegate update_count_mark];
  7467. }
  7468. result(json);
  7469. });
  7470. });
  7471. return;
  7472. }
  7473. NSString * uuid= [[NSUUID UUID] UUIDString];
  7474. params[@"resultSerial"]=uuid;
  7475. __block bool bbreak = false;
  7476. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7477. for(int i=0;i<150;i++)
  7478. {
  7479. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7480. // result_params[@"resultSerial"]=uuid;
  7481. if(bbreak)
  7482. break;
  7483. dispatch_async(dispatch_get_main_queue(), ^{
  7484. [self request_interface:URL_CATEGORYADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7485. if([resulti[@"result"] intValue]==2|| [resulti[@"result"] intValue] == 8)
  7486. {
  7487. if(!bbreak)//此判断保证result只调用一次。
  7488. {
  7489. int result_code =[resulti[@"result"] intValue];
  7490. if (result_code==2||result_code==8)
  7491. {
  7492. if(resulti[@"cart_count"])
  7493. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7494. if(resulti[@"wish_count"])
  7495. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7496. if(resulti[@"portfolio_count"])
  7497. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  7498. //
  7499. //
  7500. [appDelegate update_count_mark];
  7501. }
  7502. result(resulti);
  7503. }
  7504. bbreak=true;
  7505. }
  7506. } retry:3];
  7507. });
  7508. sleep(2);
  7509. }
  7510. });
  7511. //
  7512. // NSData* json= nil;
  7513. //
  7514. // if(appDelegate.offline_mode)
  7515. // {
  7516. // json= [OLDataProvider offline_categoryaddall:params];
  7517. // }
  7518. // else
  7519. // {
  7520. // if(![self IsNetworkAvailable])
  7521. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7522. //
  7523. //
  7524. // NSError *error=nil;
  7525. //
  7526. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7527. // params[@"resultSerial"]=uuid;
  7528. //
  7529. // for(int i=0;i<150;i++)
  7530. // {
  7531. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7532. //// result_params[@"resultSerial"]=uuid;
  7533. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  7534. // if(json!=nil)
  7535. // {
  7536. //
  7537. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7538. // int resultInt = [jsobj[@"result"] intValue];
  7539. // if(resultInt == 2 || resultInt == 8)
  7540. // {
  7541. // break;
  7542. // }
  7543. // }
  7544. // sleep(2);
  7545. // }
  7546. //
  7547. //
  7548. //
  7549. // }
  7550. // if(json==nil)
  7551. // return nil;
  7552. // NSError *error=nil;
  7553. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7554. // return jsobj;
  7555. }
  7556. +(void)request_save_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7557. {
  7558. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7559. AppDelegate *appDelegate = nil;
  7560. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7561. if(appDelegate.user!=nil)
  7562. [params setValue:appDelegate.user forKey:@"user"];
  7563. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  7564. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7565. // else
  7566. if(appDelegate.contact_id!=nil)
  7567. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7568. if(appDelegate.password!=nil)
  7569. [params setValue:appDelegate.password forKey:@"password"];
  7570. if(appDelegate.order_code!=nil)
  7571. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7572. // NSDictionary* customerinfo=nil;
  7573. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  7574. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7575. // else
  7576. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7577. //
  7578. // appDelegate.customerInfo;
  7579. // NSArray* keys=[customerinfo allKeys];
  7580. // for(int i=0;i<keys.count;i++)
  7581. // {
  7582. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7583. // }
  7584. // [params setValue:sourceid forKey:@"sourceid"];
  7585. // [params setValue:editor forKey:@"editor"];
  7586. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  7587. if(appDelegate.offline_mode)
  7588. {
  7589. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7590. NSData* json = [[OLDataProvider offline_saveorder:params] mutableCopy];
  7591. dispatch_async(dispatch_get_main_queue(), ^{
  7592. result([[RAConvertor data2dict:json] mutableCopy]);
  7593. });
  7594. });
  7595. return;
  7596. }
  7597. [self request_interface:URL_SAVE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  7598. //
  7599. // NSData* json=nil;
  7600. //
  7601. // if(appDelegate.offline_mode)
  7602. // {
  7603. // json= [OLDataProvider offline_saveorder:params];
  7604. // }
  7605. // else
  7606. // {
  7607. // if(![self IsNetworkAvailable])
  7608. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7609. //
  7610. // json=[self get_json:URL_SAVE_ORDER parameters:params];
  7611. // }
  7612. // if(json!=nil)
  7613. // {
  7614. // NSError *error=nil;
  7615. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7616. // NSString *so = [jsobj valueForKey:@"so#"];
  7617. // if (so) {
  7618. // [appDelegate SetSo:so];
  7619. // }
  7620. // return jsobj;
  7621. // }
  7622. // else
  7623. // return nil;
  7624. }
  7625. +(void) request_update_cartqty:(NSString*) cart_id value:(int) value completionHandler:(resultHandler)result
  7626. {
  7627. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7628. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  7629. #ifdef SCANNER_ORDER
  7630. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7631. {
  7632. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7633. //
  7634. //
  7635. // [appDelegate update_count_mark];
  7636. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7637. int count = [section[@"count"] intValue];
  7638. for(int i=0;i<count;i++)
  7639. {
  7640. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7641. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7642. {
  7643. item[@"count"] =@(value);
  7644. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7645. break;
  7646. }
  7647. }
  7648. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7649. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7650. result(RASingleton.sharedInstance.scan_cart);
  7651. [OLDataProvider updateScanOrder:appDelegate.order_code];
  7652. return;
  7653. }
  7654. #endif
  7655. if(appDelegate.user!=nil)
  7656. [params setValue:appDelegate.user forKey:@"user"];
  7657. if(appDelegate.contact_id!=nil)
  7658. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7659. if(appDelegate.password!=nil)
  7660. [params setValue:appDelegate.password forKey:@"password"];
  7661. [params setValue:cart_id forKey:@"cartitem_id"];
  7662. [params setObject:ScreenCodeCart forKey:kScreenName];
  7663. [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  7664. if(appDelegate.offline_mode)
  7665. {
  7666. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7667. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7668. NSData* json = [[OLDataProvider offline_cartsetqty:params] mutableCopy];
  7669. dispatch_async(dispatch_get_main_queue(), ^{
  7670. result([[RAConvertor data2dict:json] mutableCopy]);
  7671. });
  7672. });
  7673. return;
  7674. }
  7675. [self request_interface:URL_CART_INCRESEMENT parameters:params err_record_url:nil completionHandler:result retry:0];
  7676. //
  7677. // NSData* json=nil;
  7678. // if(appDelegate.offline_mode)
  7679. // {
  7680. // json= [OLDataProvider offline_cartsetqty:params];
  7681. // }
  7682. // else
  7683. // {
  7684. // if(![self IsNetworkAvailable])
  7685. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7686. //
  7687. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  7688. // }
  7689. // if(json==nil)
  7690. // return nil;
  7691. // NSError *error=nil;
  7692. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7693. // return jsobj;
  7694. }
  7695. +(void) request_update_cartgeneralnote:(NSString*) order_code notes:(NSString*) notes completionHandler:(resultHandler)result
  7696. {
  7697. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7698. AppDelegate *appDelegate = nil;
  7699. #ifdef SCANNER_ORDER
  7700. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7701. {
  7702. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7703. //
  7704. //
  7705. // [appDelegate update_count_mark];
  7706. RASingleton.sharedInstance.scan_cart[@"general_note"] = notes;
  7707. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7708. result(RASingleton.sharedInstance.scan_cart);
  7709. return;
  7710. }
  7711. #endif
  7712. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7713. if(appDelegate.user!=nil)
  7714. [params setValue:appDelegate.user forKey:@"user"];
  7715. if(appDelegate.contact_id!=nil)
  7716. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7717. if(appDelegate.password!=nil)
  7718. [params setValue:appDelegate.password forKey:@"password"];
  7719. [params setValue:order_code forKey:@"orderCode"];
  7720. [params setObject:ScreenCodeCart forKey:kScreenName];
  7721. if(notes.length==0)
  7722. notes=@"";
  7723. [params setValue:notes forKey:@"comments"];
  7724. if(appDelegate.offline_mode)
  7725. {
  7726. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7727. NSData* json = [[OLDataProvider offline_updategnotes:params] mutableCopy];
  7728. dispatch_async(dispatch_get_main_queue(), ^{
  7729. result([[RAConvertor data2dict:json] mutableCopy]);
  7730. });
  7731. });
  7732. return;
  7733. }
  7734. [self request_interface:URL_CART_GENERAL_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7735. //
  7736. // NSData* json=nil;
  7737. // if(appDelegate.offline_mode)
  7738. // {
  7739. // json= [OLDataProvider offline_updategnotes:params];
  7740. // }
  7741. // else
  7742. // {
  7743. // if(![self IsNetworkAvailable])
  7744. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7745. //
  7746. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  7747. // }
  7748. // if(json==nil)
  7749. // return nil;
  7750. // NSError *error=nil;
  7751. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7752. // return jsobj;
  7753. }
  7754. +(void) request_update_cartitemnote:(NSString*) cart_id notes:(NSString*) notes completionHandler:(resultHandler)result
  7755. {
  7756. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7757. AppDelegate *appDelegate = nil;
  7758. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7759. #ifdef SCANNER_ORDER
  7760. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7761. {
  7762. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7763. //
  7764. //
  7765. // [appDelegate update_count_mark];
  7766. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7767. int count = [section[@"count"] intValue];
  7768. for(int i=0;i<count;i++)
  7769. {
  7770. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7771. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7772. {
  7773. item[@"note"] =notes;
  7774. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7775. break;
  7776. }
  7777. }
  7778. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7779. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7780. result(RASingleton.sharedInstance.scan_cart);
  7781. return;
  7782. }
  7783. #endif
  7784. if(appDelegate.user!=nil)
  7785. [params setValue:appDelegate.user forKey:@"user"];
  7786. if(appDelegate.contact_id!=nil)
  7787. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7788. if(appDelegate.password!=nil)
  7789. [params setValue:appDelegate.password forKey:@"password"];
  7790. [params setValue:cart_id forKey:@"cartitem_id"];
  7791. [params setObject:ScreenCodeCart forKey:kScreenName];
  7792. if(notes.length==0)
  7793. notes=@"";
  7794. [params setValue:notes forKey:@"notes"];
  7795. if(appDelegate.offline_mode)
  7796. {
  7797. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7798. NSData* json = [[OLDataProvider offline_cartsetlnotes:params] mutableCopy];
  7799. dispatch_async(dispatch_get_main_queue(), ^{
  7800. result([[RAConvertor data2dict:json] mutableCopy]);
  7801. });
  7802. });
  7803. return;
  7804. }
  7805. [self request_interface:URL_CART_ITEM_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7806. //
  7807. // NSData* json=nil;
  7808. // if(appDelegate.offline_mode)
  7809. // {
  7810. // json= [OLDataProvider offline_cartsetlnotes:params];
  7811. // }
  7812. // else
  7813. // {
  7814. // if(![self IsNetworkAvailable])
  7815. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7816. //
  7817. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  7818. // }
  7819. // if(json==nil)
  7820. // return nil;
  7821. // NSError *error=nil;
  7822. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7823. // return jsobj;
  7824. }
  7825. + (void)request_update_npd_shop_price_type:(NSInteger)priceType completionHandler:(resultHandler)result
  7826. {
  7827. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7828. AppDelegate *appDelegate = nil;
  7829. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7830. if(appDelegate.user!=nil)
  7831. [dic setValue:appDelegate.user forKey:@"user"];
  7832. if(appDelegate.password!=nil)
  7833. [dic setValue:appDelegate.password forKey:@"password"];
  7834. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  7835. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  7836. if(appDelegate.offline_mode)
  7837. {
  7838. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7839. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7840. dispatch_async(dispatch_get_main_queue(), ^{
  7841. result(json);
  7842. });
  7843. });
  7844. return;
  7845. }
  7846. [self request_interface:URL_SET_PRICE_TYPE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7847. //
  7848. // NSData* json=nil;
  7849. // if(appDelegate.offline_mode)
  7850. // {
  7851. // return [OLDataProvider offline_notimpl];
  7852. // }
  7853. // else
  7854. // {
  7855. // if(![self IsNetworkAvailable])
  7856. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7857. //
  7858. // json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  7859. // }
  7860. // if(json!=nil)
  7861. // {
  7862. // NSError *error=nil;
  7863. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7864. //
  7865. //
  7866. // return jsobj;
  7867. // }
  7868. //
  7869. //
  7870. // return nil;
  7871. }
  7872. + (void)request_npd_shop_givenprice:(resultHandler)result
  7873. {
  7874. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7875. AppDelegate *appDelegate = nil;
  7876. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7877. if(appDelegate.user!=nil)
  7878. [dic setValue:appDelegate.user forKey:@"user"];
  7879. if(appDelegate.password!=nil)
  7880. [dic setValue:appDelegate.password forKey:@"password"];
  7881. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  7882. if(appDelegate.offline_mode)
  7883. {
  7884. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7885. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7886. dispatch_async(dispatch_get_main_queue(), ^{
  7887. result(json);
  7888. });
  7889. });
  7890. return;
  7891. }
  7892. [self request_interface:URL_GET_CIVEN_PRICE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7893. //
  7894. // NSData* json=nil;
  7895. // if(appDelegate.offline_mode)
  7896. // {
  7897. // return [OLDataProvider offline_notimpl];
  7898. // }
  7899. // else
  7900. // {
  7901. // if(![self IsNetworkAvailable])
  7902. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7903. //
  7904. // json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  7905. // }
  7906. // if(json!=nil)
  7907. // {
  7908. // NSError *error=nil;
  7909. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7910. //
  7911. //
  7912. // return jsobj;
  7913. // }
  7914. //
  7915. //
  7916. // return nil;
  7917. }
  7918. + (void)request_update_npd_shop_givenprice:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  7919. {
  7920. AppDelegate *appDelegate = nil;
  7921. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7922. if(appDelegate.user!=nil)
  7923. [params setValue:appDelegate.user forKey:@"user"];
  7924. if(appDelegate.password!=nil)
  7925. [params setValue:appDelegate.password forKey:@"password"];
  7926. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  7927. if(appDelegate.offline_mode)
  7928. {
  7929. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7930. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7931. dispatch_async(dispatch_get_main_queue(), ^{
  7932. result(json);
  7933. });
  7934. });
  7935. return;
  7936. }
  7937. [self request_interface:URL_SET_GIVEN_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  7938. //
  7939. // NSData* json=nil;
  7940. // if(appDelegate.offline_mode)
  7941. // {
  7942. // return [OLDataProvider offline_notimpl];
  7943. // }
  7944. // else
  7945. // {
  7946. // if(![self IsNetworkAvailable])
  7947. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7948. //
  7949. // json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  7950. // }
  7951. // if(json!=nil)
  7952. // {
  7953. // NSError *error=nil;
  7954. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7955. //
  7956. //
  7957. // return jsobj;
  7958. // }
  7959. //
  7960. //
  7961. // return nil;
  7962. }
  7963. +(void) request_create_portfolio:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7964. {
  7965. AppDelegate *appDelegate = nil;
  7966. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7967. if(appDelegate.offline_mode)
  7968. {
  7969. params[@"contact_id"]=params[@"contactId"];
  7970. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7971. NSData* json = [[OLDataProvider offline_direct_save_TearSheet:params] mutableCopy];
  7972. dispatch_async(dispatch_get_main_queue(), ^{
  7973. result([[RAConvertor data2dict:json] mutableCopy]);
  7974. });
  7975. });
  7976. return;
  7977. }
  7978. //
  7979. // if(appDelegate.offline_mode)
  7980. // {
  7981. //
  7982. //
  7983. // NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  7984. // if(json==nil)
  7985. // return nil;
  7986. // NSError *error=nil;
  7987. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7988. //
  7989. // return jsobj[@"pdf_path"];
  7990. // }
  7991. // else
  7992. // {
  7993. // return nil;
  7994. // }
  7995. }
  7996. +(void)request_save_portfoliodirectly:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7997. {
  7998. NSMutableDictionary* off_params = [params mutableCopy];
  7999. AppDelegate *appDelegate = nil;
  8000. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8001. if(appDelegate.user!=nil)
  8002. [params setValue:appDelegate.user forKey:@"user"];
  8003. if(appDelegate.contact_id!=nil)
  8004. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8005. if(appDelegate.password!=nil)
  8006. params[@"off_params"]=[RAConvertor dict2string:off_params];
  8007. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  8008. [params setValue:appDelegate.password forKey:@"password"];
  8009. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  8010. if(appDelegate.offline_mode)
  8011. {
  8012. params[@"contact_id"]=appDelegate.contact_id;
  8013. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8014. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_direct_save_TearSheet:params]] mutableCopy];
  8015. dispatch_async(dispatch_get_main_queue(), ^{
  8016. result(json);
  8017. });
  8018. });
  8019. return;
  8020. }
  8021. NSString * uuid= [[NSUUID UUID] UUIDString];
  8022. params[@"resultSerial"]=uuid;
  8023. __block bool bbreak = false;
  8024. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8025. for(int i=0;i<150;i++)
  8026. {
  8027. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8028. // result_params[@"resultSerial"]=uuid;
  8029. if(bbreak)
  8030. break;
  8031. dispatch_async(dispatch_get_main_queue(), ^{
  8032. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8033. if([resulti[@"result"] intValue]==2)
  8034. {
  8035. if(!bbreak)//此判断保证result只调用一次。
  8036. result(resulti);
  8037. bbreak=true;
  8038. }
  8039. } retry:3];
  8040. });
  8041. sleep(2);
  8042. }
  8043. });
  8044. //
  8045. //
  8046. // NSData* json= nil;
  8047. //
  8048. // if(appDelegate.offline_mode)
  8049. // {
  8050. // json = [OLDataProvider offline_direct_save_TearSheet:params];
  8051. // }
  8052. // else
  8053. // {
  8054. // if(![self IsNetworkAvailable])
  8055. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8056. //
  8057. // json=[self get_json:URL_REQUEST_DM parameters:params];
  8058. //
  8059. // NSError *error=nil;
  8060. //
  8061. // NSString * uuid= [[NSUUID UUID] UUIDString];
  8062. // params[@"resultSerial"]=uuid;
  8063. //
  8064. // for(int i=0;i<150;i++)
  8065. // {
  8066. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8067. // // result_params[@"resultSerial"]=uuid;
  8068. // json=[self get_json:URL_REQUEST_DM parameters:params];
  8069. // if(json!=nil)
  8070. // {
  8071. //
  8072. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8073. // if([jsobj[@"result"] intValue]==2)
  8074. // {
  8075. // break;
  8076. // }
  8077. // }
  8078. // sleep(5);
  8079. // }
  8080. //
  8081. // }
  8082. // if(json==nil)
  8083. // return nil;
  8084. // NSError *error=nil;
  8085. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8086. // return jsobj;
  8087. }
  8088. +(void)request_save_portfolio:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  8089. {
  8090. AppDelegate *appDelegate = nil;
  8091. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8092. if(appDelegate.user!=nil)
  8093. [params setValue:appDelegate.user forKey:@"user"];
  8094. if(appDelegate.contact_id!=nil)
  8095. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8096. NSMutableDictionary* off_params = [params mutableCopy];;
  8097. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  8098. params[@"off_params"]=[RAConvertor dict2string:off_params];
  8099. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8100. if(appDelegate.password!=nil)
  8101. [params setValue:appDelegate.password forKey:@"password"];
  8102. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  8103. if(appDelegate.offline_mode)
  8104. {
  8105. params[@"contact_id"]=appDelegate.contact_id;
  8106. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8107. NSData* json = [[OLDataProvider offline_save_TearSheet:params] mutableCopy];
  8108. dispatch_async(dispatch_get_main_queue(), ^{
  8109. result([[RAConvertor data2dict:json] mutableCopy]);
  8110. });
  8111. });
  8112. return;
  8113. }
  8114. [self request_interface:URL_SAVE_DM parameters:params err_record_url:nil completionHandler:result retry:0];
  8115. //
  8116. // NSData* json = nil;
  8117. // if(appDelegate.offline_mode)
  8118. // {
  8119. // json = [OLDataProvider offline_save_TearSheet:params];
  8120. // } else {
  8121. // if(![self IsNetworkAvailable])
  8122. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8123. //
  8124. // json=[self get_json:URL_SAVE_DM parameters:params];
  8125. // }
  8126. // if(json==nil)
  8127. // return nil;
  8128. // NSError *error=nil;
  8129. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8130. // return jsobj;
  8131. }
  8132. +(void)request_portfoliopreview:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8133. {
  8134. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8135. AppDelegate *appDelegate = nil;
  8136. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8137. if(appDelegate.user!=nil)
  8138. [params setValue:appDelegate.user forKey:@"user"];
  8139. if(appDelegate.contact_id!=nil)
  8140. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8141. if(appDelegate.password!=nil)
  8142. [params setValue:appDelegate.password forKey:@"password"];
  8143. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  8144. // [params setValue:request_url forKey:@"pdfUrl"];
  8145. if(appDelegate.offline_mode)
  8146. {
  8147. params[@"contact_id"]=params[@"contactId"];
  8148. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8149. NSData* json = [[OLDataProvider offline_request_tearsheet:params] mutableCopy];
  8150. dispatch_async(dispatch_get_main_queue(), ^{
  8151. result([[RAConvertor data2dict:json] mutableCopy]);
  8152. });
  8153. });
  8154. return;
  8155. }
  8156. NSString * uuid= [[NSUUID UUID] UUIDString];
  8157. params[@"resultSerial"]=uuid;
  8158. __block bool bbreak = false;
  8159. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8160. for(int i=0;i<150;i++)
  8161. {
  8162. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8163. // result_params[@"resultSerial"]=uuid;
  8164. if(bbreak)
  8165. break;
  8166. dispatch_async(dispatch_get_main_queue(), ^{
  8167. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8168. if([resulti[@"result"] intValue]==2)
  8169. {
  8170. if(!bbreak)//此判断保证result只调用一次。
  8171. result(resulti);
  8172. bbreak=true;
  8173. }
  8174. } retry:3];
  8175. });
  8176. sleep(5);
  8177. }
  8178. });
  8179. //
  8180. // NSData* json= nil;
  8181. // if(appDelegate.offline_mode)
  8182. // {
  8183. // json= [OLDataProvider offline_request_tearsheet:params];
  8184. // }
  8185. // else
  8186. // {
  8187. // if(![self IsNetworkAvailable])
  8188. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8189. //
  8190. // NSError *error=nil;
  8191. //
  8192. // NSString * uuid= [[NSUUID UUID] UUIDString];
  8193. // params[@"resultSerial"]=uuid;
  8194. //
  8195. // for(int i=0;i<150;i++)
  8196. // {
  8197. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8198. // // result_params[@"resultSerial"]=uuid;
  8199. // json=[self get_json:URL_REQUEST_DM parameters:params];
  8200. // if(json!=nil)
  8201. // {
  8202. //
  8203. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8204. // if([jsobj[@"result"] intValue]==2)
  8205. // {
  8206. // break;
  8207. // }
  8208. // }
  8209. // sleep(5);
  8210. // }
  8211. // }
  8212. // if(json==nil)
  8213. // return nil;
  8214. // NSError *error=nil;
  8215. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8216. // return jsobj;
  8217. }
  8218. +(void)request_itemsearch:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller completionHandler:(resultHandler)result
  8219. {
  8220. // for debug
  8221. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  8222. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8223. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8224. AppDelegate *appDelegate = nil;
  8225. //some UI methods ej
  8226. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8227. if(appDelegate.user!=nil)
  8228. [params setValue:appDelegate.user forKey:@"user"];
  8229. if(appDelegate.contact_id!=nil)
  8230. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8231. if(appDelegate.password!=nil)
  8232. [params setValue:appDelegate.password forKey:@"password"];
  8233. if(appDelegate.order_code!=nil)
  8234. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8235. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  8236. if (alert && qty && available && price && bestseller) {
  8237. [params setObject:@"Filter" forKey:kAction];
  8238. }
  8239. if ([RASingleton sharedInstance].homeItemClick) {
  8240. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  8241. [RASingleton sharedInstance].homeItemClick = NO;
  8242. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  8243. [RASingleton sharedInstance].homeClickedItemName = nil;
  8244. [params setObject:extra forKey:kExtra];
  8245. }
  8246. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  8247. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  8248. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  8249. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  8250. // [params setValue:filter forKey:@"filter"];
  8251. [params setValue:covertype forKey:@"covertype"];
  8252. [params setValue:ctgid forKey:@"ctgId"];
  8253. [params setValue:modelname forKey:@"modelName"];
  8254. [params setValue:modeldescrip forKey:@"modelDescription"];
  8255. [params setValue:alert forKey:@"alert"];
  8256. [params setValue:qty forKey:@"sold_by_qty"];
  8257. [params setValue:available forKey:@"available"];
  8258. [params setValue:price forKey:@"price"];
  8259. [params setValue:bestseller forKey:@"bestseller"];
  8260. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  8261. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  8262. if(appDelegate.offline_mode)
  8263. {
  8264. // [OLDataProvider offline_itemsearch:params completionHandler:result];
  8265. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8266. NSMutableDictionary* json = [[OLDataProvider offline_itemsearch:params] mutableCopy];
  8267. dispatch_async(dispatch_get_main_queue(), ^{
  8268. result(json);
  8269. });
  8270. });
  8271. return;
  8272. }
  8273. [self request_interface:URL_ITEM_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  8274. // if(appDelegate.offline_mode)
  8275. // {
  8276. // return [OLDataProvider offline_itemsearch:params];
  8277. // }
  8278. // if(![self IsNetworkAvailable])
  8279. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8280. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  8281. // if(json==nil)
  8282. // return nil;
  8283. // NSError *error=nil;
  8284. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8285. // return jsobj;
  8286. }
  8287. +(void)request_modelqty: (NSString*) fashionId completionHandler:(resultHandler)result
  8288. {
  8289. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8290. AppDelegate *appDelegate = nil;
  8291. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8292. if(appDelegate.user!=nil)
  8293. [params setValue:appDelegate.user forKey:@"user"];
  8294. if(appDelegate.contact_id!=nil)
  8295. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8296. if(appDelegate.password!=nil)
  8297. [params setValue:appDelegate.password forKey:@"password"];
  8298. [params setValue:fashionId forKey:@"fashionId"];
  8299. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  8300. if(appDelegate.offline_mode)
  8301. {
  8302. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8303. NSData* json = [[OLDataProvider offline_model_qty:params] mutableCopy];
  8304. dispatch_async(dispatch_get_main_queue(), ^{
  8305. result([[RAConvertor data2dict:json] mutableCopy]);
  8306. });
  8307. });
  8308. return;
  8309. }
  8310. [self request_interface:URL_REQUEST_MODEL_QTY parameters:params err_record_url:nil completionHandler:result retry:0];
  8311. // NSData* json = nil;
  8312. // if(appDelegate.offline_mode)
  8313. // {
  8314. // json = [OLDataProvider offline_model_qty:params];
  8315. // } else {
  8316. // if(![self IsNetworkAvailable])
  8317. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8318. //
  8319. // json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  8320. // }
  8321. // if(json==nil)
  8322. // return nil;
  8323. // NSError *error=nil;
  8324. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8325. // return jsobj;
  8326. }
  8327. +(void) request_update_portfolio_price:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes completionHandler:(resultHandler)result
  8328. {
  8329. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8330. AppDelegate *appDelegate = nil;
  8331. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8332. if(appDelegate.user!=nil)
  8333. [params setValue:appDelegate.user forKey:@"user"];
  8334. if(appDelegate.contact_id!=nil)
  8335. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8336. if(appDelegate.password!=nil)
  8337. [params setValue:appDelegate.password forKey:@"password"];
  8338. [params setValue:watchlist_id forKey:@"item_id"];
  8339. // if(notes.length>0)
  8340. // [params setValue:notes forKey:@"notes"];
  8341. if(notes)
  8342. [params setValue:notes forKey:@"notes"];
  8343. if(price != -MAXFLOAT)
  8344. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  8345. if (discount != -MAXFLOAT)
  8346. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  8347. if(qty_p != -MAXFLOAT)
  8348. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  8349. if(qty != -INT32_MAX)
  8350. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  8351. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  8352. // NSData* json = nil;
  8353. if(appDelegate.offline_mode)
  8354. {
  8355. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8356. NSData* json = [[OLDataProvider offline_editPortfolio:params] mutableCopy];
  8357. dispatch_async(dispatch_get_main_queue(), ^{
  8358. result([[RAConvertor data2dict:json] mutableCopy]);
  8359. });
  8360. });
  8361. return;
  8362. }
  8363. [self request_interface:URL_PORTFOLIO_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8364. //
  8365. // if(appDelegate.offline_mode)
  8366. // {
  8367. // json = [OLDataProvider offline_editPortfolio:params];
  8368. // } else {
  8369. // if(![self IsNetworkAvailable])
  8370. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8371. //
  8372. // json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  8373. // }
  8374. // if(json==nil)
  8375. // return nil;
  8376. // NSError *error=nil;
  8377. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8378. // return jsobj;
  8379. }
  8380. +(void)request_add_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8381. {
  8382. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8383. AppDelegate *appDelegate = nil;
  8384. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8385. if(appDelegate.user!=nil)
  8386. [params setValue:appDelegate.user forKey:@"user"];
  8387. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  8388. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8389. // else
  8390. if(appDelegate.contact_id!=nil)
  8391. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8392. if(appDelegate.password!=nil)
  8393. [params setValue:appDelegate.password forKey:@"password"];
  8394. // NSDictionary* customerinfo=nil;
  8395. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  8396. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8397. // else
  8398. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8399. //
  8400. // appDelegate.customerInfo;
  8401. // NSArray* keys=[customerinfo allKeys];
  8402. // for(int i=0;i<keys.count;i++)
  8403. // {
  8404. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8405. // }
  8406. // [params setValue:sourceid forKey:@"sourceid"];
  8407. // [params setValue:editor forKey:@"editor"];
  8408. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  8409. if(appDelegate.offline_mode)
  8410. {
  8411. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8412. NSData* json = [[OLDataProvider offline_saveNewContact:params] mutableCopy];
  8413. dispatch_async(dispatch_get_main_queue(), ^{
  8414. result([[RAConvertor data2dict:json] mutableCopy]);
  8415. });
  8416. });
  8417. return;
  8418. }
  8419. [self request_interface:URL_CUSTOMER_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  8420. //
  8421. // NSData* json=nil;
  8422. // if(appDelegate.offline_mode)
  8423. // {
  8424. // json= [OLDataProvider offline_saveNewContact:params];
  8425. // }
  8426. // else
  8427. // {
  8428. // if(![self IsNetworkAvailable])
  8429. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8430. //
  8431. // json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  8432. // }
  8433. //
  8434. // if(json!=nil)
  8435. // {
  8436. // NSError *error=nil;
  8437. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8438. // return jsobj;
  8439. // }
  8440. // else
  8441. // return nil;
  8442. }
  8443. +(void)request_update_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8444. {
  8445. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8446. AppDelegate *appDelegate = nil;
  8447. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8448. if(appDelegate.user!=nil)
  8449. [params setValue:appDelegate.user forKey:@"user"];
  8450. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  8451. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8452. // else
  8453. if(appDelegate.contact_id!=nil)
  8454. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8455. if(appDelegate.password!=nil)
  8456. [params setValue:appDelegate.password forKey:@"password"];
  8457. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8458. if(appDelegate.offline_mode)
  8459. {
  8460. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8461. NSData* json = [[OLDataProvider offline_saveContact:params] mutableCopy];
  8462. dispatch_async(dispatch_get_main_queue(), ^{
  8463. result([[RAConvertor data2dict:json] mutableCopy]);
  8464. });
  8465. });
  8466. return;
  8467. }
  8468. [self request_interface:URL_CUSTOMER_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  8469. //
  8470. // NSData* json=nil;
  8471. // if(appDelegate.offline_mode)
  8472. // {
  8473. // json= [OLDataProvider offline_saveContact:params];
  8474. // }
  8475. // else
  8476. // {
  8477. // if(![self IsNetworkAvailable])
  8478. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8479. //
  8480. // json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  8481. // }
  8482. //
  8483. // if(json!=nil)
  8484. // {
  8485. // NSError *error=nil;
  8486. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8487. // return jsobj;
  8488. // }
  8489. // else
  8490. // return nil;
  8491. }
  8492. +(void)request_delete_order:(NSString*) order_id completionHandler:(resultHandler)result
  8493. {
  8494. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8495. AppDelegate *appDelegate = nil;
  8496. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8497. if(appDelegate.user!=nil)
  8498. [params setValue:appDelegate.user forKey:@"user"];
  8499. // if(appDelegate.contact_id!=nil)
  8500. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8501. if(appDelegate.password!=nil)
  8502. [params setValue:appDelegate.password forKey:@"password"];
  8503. [params setValue:order_id forKey:@"orderId"];
  8504. // [params setValue:sourceid forKey:@"sourceid"];
  8505. // [params setValue:editor forKey:@"editor"];
  8506. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8507. if(appDelegate.offline_mode)
  8508. {
  8509. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8510. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8511. dispatch_async(dispatch_get_main_queue(), ^{
  8512. result(json);
  8513. });
  8514. });
  8515. return;
  8516. }
  8517. [self request_interface:URL_DELETE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8518. //
  8519. // if(appDelegate.offline_mode)
  8520. // {
  8521. // return [OLDataProvider offline_notimpl];
  8522. // }
  8523. // if(![self IsNetworkAvailable])
  8524. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8525. //
  8526. // NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  8527. // if(json!=nil)
  8528. // {
  8529. // NSError *error=nil;
  8530. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8531. //
  8532. //
  8533. // return jsobj;
  8534. // }
  8535. // else
  8536. // return nil;
  8537. }
  8538. +(void)request_cancel_order:(NSString*) order_id order_code:(NSString*) order_code completionHandler:(resultHandler)result
  8539. {
  8540. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8541. AppDelegate *appDelegate = nil;
  8542. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8543. if(appDelegate.user!=nil)
  8544. [params setValue:appDelegate.user forKey:@"user"];
  8545. // if(appDelegate.contact_id!=nil)
  8546. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8547. if(appDelegate.password!=nil)
  8548. [params setValue:appDelegate.password forKey:@"password"];
  8549. [params setValue:order_id forKey:@"orderId"];
  8550. [params setValue:order_code forKey:@"orderCode"];
  8551. // [params setValue:sourceid forKey:@"sourceid"];
  8552. // [params setValue:editor forKey:@"editor"];
  8553. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8554. if(appDelegate.offline_mode)
  8555. {
  8556. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8557. NSData* json = [[OLDataProvider offline_cancelorder:params] mutableCopy];
  8558. dispatch_async(dispatch_get_main_queue(), ^{
  8559. result([[RAConvertor data2dict:json] mutableCopy]);
  8560. });
  8561. });
  8562. return;
  8563. }
  8564. [self request_interface:URL_CANCEL_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8565. //
  8566. // NSData* json=nil;
  8567. // if(appDelegate.offline_mode)
  8568. // {
  8569. // json=[OLDataProvider offline_cancelorder:params];
  8570. // }
  8571. // else
  8572. // {
  8573. // if(![self IsNetworkAvailable])
  8574. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8575. // json=[self get_json:URL_CANCEL_ORDER parameters:params];
  8576. // }
  8577. // if(json!=nil)
  8578. // {
  8579. // NSError *error=nil;
  8580. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8581. //
  8582. //
  8583. // return jsobj;
  8584. // }
  8585. // else
  8586. // return nil;
  8587. }
  8588. +(void)request_release_order:(NSString*) order_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  8589. {
  8590. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8591. AppDelegate *appDelegate = nil;
  8592. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8593. if(appDelegate.user!=nil)
  8594. [params setValue:appDelegate.user forKey:@"user"];
  8595. // if(appDelegate.contact_id!=nil)
  8596. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8597. if(appDelegate.password!=nil)
  8598. [params setValue:appDelegate.password forKey:@"password"];
  8599. [params setValue:order_code forKey:@"orderCode"];
  8600. // [params setValue:sourceid forKey:@"sourceid"];
  8601. // [params setValue:editor forKey:@"editor"];
  8602. if (screenName) {
  8603. [params setValue:screenName forKey:kScreenName];
  8604. }
  8605. if(appDelegate.offline_mode)
  8606. {
  8607. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8608. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_resetorder:params]] mutableCopy];
  8609. dispatch_async(dispatch_get_main_queue(), ^{
  8610. if([[resulti valueForKey:@"result"]intValue]==2)
  8611. { [appDelegate SetSo:nil];
  8612. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8613. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8614. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8615. [appDelegate update_count_mark];
  8616. dispatch_async(dispatch_get_main_queue(), ^{
  8617. result(resulti);
  8618. });
  8619. }
  8620. });
  8621. });
  8622. return;
  8623. }
  8624. [self request_interface:URL_RELEASE_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8625. if([[resulti valueForKey:@"result"]intValue]==2)
  8626. { [appDelegate SetSo:nil];
  8627. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8628. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8629. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8630. [appDelegate update_count_mark];
  8631. dispatch_async(dispatch_get_main_queue(), ^{
  8632. result(resulti);
  8633. });
  8634. }
  8635. } retry:0];
  8636. //
  8637. // NSData* json=nil;
  8638. // if(appDelegate.offline_mode)
  8639. // {
  8640. // json= [OLDataProvider offline_resetorder:params];
  8641. // }
  8642. // else
  8643. // {
  8644. // if(![self IsNetworkAvailable])
  8645. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8646. //
  8647. // json=[self get_json:URL_RELEASE_ORDER parameters:params];
  8648. // }
  8649. // if(json!=nil)
  8650. // {
  8651. // NSError *error=nil;
  8652. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8653. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8654. // { [appDelegate SetSo:nil];
  8655. //
  8656. //
  8657. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8658. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8659. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8660. //
  8661. // [appDelegate update_count_mark];
  8662. // }
  8663. // return jsobj;
  8664. // }
  8665. // else
  8666. // return nil;
  8667. }
  8668. +(void)request_update_order_signature:(NSString*) order_code path:(NSString*)path completionHandler:(resultHandler)result
  8669. {
  8670. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8671. AppDelegate *appDelegate = nil;
  8672. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8673. if(appDelegate.user!=nil)
  8674. [params setValue:appDelegate.user forKey:@"user"];
  8675. if(appDelegate.contact_id!=nil)
  8676. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8677. if(appDelegate.password!=nil)
  8678. [params setValue:appDelegate.password forKey:@"password"];
  8679. // NSString* ssaved = @"false";
  8680. // if(saved)
  8681. // ssaved=@"true";
  8682. // [params setValue:@"true" forKey:@"saved"];
  8683. [params setValue:order_code forKey:@"orderCode"];
  8684. [params setValue:path forKey:@"picpath"];
  8685. // [params setValue:sourceid forKey:@"sourceid"];
  8686. // [params setValue:editor forKey:@"editor"];
  8687. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  8688. if(appDelegate.offline_mode)
  8689. {
  8690. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8691. NSData* json = [[OLDataProvider offline_signorder:params] mutableCopy];
  8692. dispatch_async(dispatch_get_main_queue(), ^{
  8693. result([[RAConvertor data2dict:json] mutableCopy]);
  8694. });
  8695. });
  8696. return;
  8697. }
  8698. [self request_interface:URL_SIGN_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8699. //
  8700. // NSData* json=nil;
  8701. // if(appDelegate.offline_mode)
  8702. // {
  8703. // json= [OLDataProvider offline_signorder:params];
  8704. // }
  8705. // else
  8706. // {
  8707. // if(![self IsNetworkAvailable])
  8708. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8709. //
  8710. // json=[self get_json:URL_SIGN_ORDER parameters:params];
  8711. // }
  8712. // if(json!=nil)
  8713. // {
  8714. // NSError *error=nil;
  8715. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8716. // return jsobj;
  8717. // }
  8718. // else
  8719. // return nil;
  8720. }
  8721. +(void) request_update_cart_modelprice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8722. {
  8723. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8724. AppDelegate *appDelegate = nil;
  8725. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8726. #ifdef SCANNER_ORDER
  8727. // return;
  8728. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  8729. {
  8730. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  8731. //
  8732. //
  8733. // [appDelegate update_count_mark];
  8734. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  8735. int count = [section[@"count"] intValue];
  8736. for(int i=0;i<count;i++)
  8737. {
  8738. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  8739. if([item[@"cart_item_id"] isEqualToString:cart_id])
  8740. {
  8741. int item_count = [item[@"count"] intValue];
  8742. item[@"unit_price"] =@(price);
  8743. item[@"discount"] =@(discount);
  8744. item[@"subtotal_price"] =@(price*item_count);
  8745. if(discount>0)
  8746. item[@"note"] =[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  8747. else
  8748. item[@"note"] =@"";
  8749. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  8750. break;
  8751. }
  8752. }
  8753. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  8754. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  8755. result(RASingleton.sharedInstance.scan_cart);
  8756. [OLDataProvider updateScanOrder:appDelegate.order_code];
  8757. return;
  8758. }
  8759. #endif
  8760. if(appDelegate.user!=nil)
  8761. [params setValue:appDelegate.user forKey:@"user"];
  8762. if(appDelegate.contact_id!=nil)
  8763. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8764. if(appDelegate.password!=nil)
  8765. [params setValue:appDelegate.password forKey:@"password"];
  8766. [params setValue:cart_id forKey:@"cartitem_id"];
  8767. [params setValue:notes forKey:@"item_note"];
  8768. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  8769. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  8770. [params setObject:ScreenCodeCart forKey:kScreenName];
  8771. if(appDelegate.offline_mode)
  8772. {
  8773. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8774. NSData* json = [[OLDataProvider offline_cartsetprice:params] mutableCopy];
  8775. dispatch_async(dispatch_get_main_queue(), ^{
  8776. result([[RAConvertor data2dict:json] mutableCopy]);
  8777. });
  8778. });
  8779. return;
  8780. }
  8781. [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8782. //
  8783. // NSData* json= nil;
  8784. // if(appDelegate.offline_mode)
  8785. // {
  8786. // json=[OLDataProvider offline_cartsetprice:params];
  8787. // }
  8788. // else
  8789. // {
  8790. // if(![self IsNetworkAvailable])
  8791. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8792. //
  8793. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8794. // }
  8795. // if(json==nil)
  8796. // return nil;
  8797. // NSError *error=nil;
  8798. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8799. // return jsobj;
  8800. }
  8801. +(void) request_addto_cart:(NSString* ) item_id count:(int) count name:(NSString *)name completionHandler:(resultHandler)result
  8802. {
  8803. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8804. AppDelegate *appDelegate = nil;
  8805. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8806. if(appDelegate.user!=nil)
  8807. [params setValue:appDelegate.user forKey:@"user"];
  8808. if(appDelegate.contact_id!=nil)
  8809. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8810. if(appDelegate.password!=nil)
  8811. [params setValue:appDelegate.password forKey:@"password"];
  8812. if(appDelegate.order_code!=nil)
  8813. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8814. [params setValue:item_id forKey:@"product_id"];
  8815. [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  8816. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  8817. [params setObject:@"Add To Cart" forKey:kAction];
  8818. if (name) {
  8819. NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  8820. [params setObject:extra forKey:kExtra];
  8821. }
  8822. NSDictionary* customerinfo= appDelegate.customerInfo;
  8823. NSArray* keys=[customerinfo allKeys];
  8824. for(int i=0;i<keys.count;i++)
  8825. {
  8826. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8827. }
  8828. if(appDelegate.offline_mode)
  8829. {
  8830. // [OLDataProvider offline_add2cart:params completionHandler:^(NSMutableDictionary *resulti) {
  8831. // NSMutableDictionary* json = resulti;
  8832. // if ([json[@"result"] intValue]==2)
  8833. // {
  8834. // appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  8835. //
  8836. // [appDelegate update_count_mark];
  8837. // }
  8838. // result(json);
  8839. // }];
  8840. params[@"can_create_backorder"]= @(appDelegate.can_create_backorder);
  8841. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8842. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cart:params]] mutableCopy];
  8843. dispatch_async(dispatch_get_main_queue(), ^{
  8844. if ([json[@"result"] intValue]==2)
  8845. {
  8846. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  8847. [appDelegate update_count_mark];
  8848. }
  8849. result(json);
  8850. });
  8851. });
  8852. return;
  8853. }
  8854. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8855. if ([resulti[@"result"] intValue]==2)
  8856. {
  8857. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8858. [appDelegate update_count_mark];
  8859. }
  8860. result(resulti);
  8861. } retry:0];
  8862. //
  8863. // NSData* json=nil;
  8864. // if(appDelegate.offline_mode)
  8865. // {
  8866. // json=[OLDataProvider offline_add2cart:params];
  8867. // }
  8868. // else
  8869. // {
  8870. // if(![self IsNetworkAvailable])
  8871. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8872. //
  8873. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  8874. // }
  8875. // if(json==nil)
  8876. // return nil;
  8877. // NSError *error=nil;
  8878. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8879. //
  8880. //
  8881. //
  8882. // int result = [[jsobj valueForKey:@"result"] intValue];
  8883. //
  8884. // if (result==2)
  8885. // {
  8886. //
  8887. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8888. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8889. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8890. //
  8891. // [appDelegate update_count_mark];
  8892. // }
  8893. //
  8894. // return jsobj;
  8895. }
  8896. //+(void) request_update_cart_modelfree:(NSString*) cart_id isfree:(bool) isfree completionHandler:(resultHandler)result
  8897. //{
  8898. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8899. // AppDelegate *appDelegate = nil;
  8900. //
  8901. //
  8902. //
  8903. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8904. //
  8905. // if(appDelegate.user!=nil)
  8906. // [params setValue:appDelegate.user forKey:@"user"];
  8907. // if(appDelegate.contact_id!=nil)
  8908. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8909. // if(appDelegate.password!=nil)
  8910. // [params setValue:appDelegate.password forKey:@"password"];
  8911. //
  8912. // [params setValue:cart_id forKey:@"cartitem_id"];
  8913. //
  8914. // [params setObject:ScreenCodeCart forKey:kScreenName];
  8915. //
  8916. // NSString* free=nil;
  8917. //
  8918. // if(isfree)
  8919. // free=@"true";
  8920. // else
  8921. // free=@"false";
  8922. //
  8923. // [params setValue:free forKey:@"free_giveaway"];
  8924. //
  8925. //
  8926. // if(appDelegate.offline_mode)
  8927. // {
  8928. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8929. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8930. // dispatch_async(dispatch_get_main_queue(), ^{
  8931. // result(json);
  8932. // });
  8933. // });
  8934. //
  8935. // return;
  8936. //
  8937. // }
  8938. // [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8939. //
  8940. ////
  8941. ////
  8942. //// if(appDelegate.offline_mode)
  8943. //// {
  8944. //// return [OLDataProvider offline_notimpl];
  8945. //// }
  8946. //// if(![self IsNetworkAvailable])
  8947. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8948. ////
  8949. //// NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8950. //// if(json==nil)
  8951. //// return nil;
  8952. //// NSError *error=nil;
  8953. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8954. //// return jsobj;
  8955. //}
  8956. +(void)request_retrieve_password: (NSString*) user email:(NSString*) email completionHandler:(resultHandler)result
  8957. {
  8958. AppDelegate *appDelegate = nil;
  8959. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8960. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8961. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8962. // if(appDelegate.user!=nil)
  8963. // [params setValue:appDelegate.user forKey:@"user"];
  8964. // if(appDelegate.contact_id!=nil)
  8965. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8966. // if(appDelegate.password!=nil)
  8967. // [params setValue:appDelegate.password forKey:@"password"];
  8968. [params setValue:user forKey:@"username"];
  8969. [params setValue:email forKey:@"email"];
  8970. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  8971. if(appDelegate.offline_mode)
  8972. {
  8973. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8974. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8975. dispatch_async(dispatch_get_main_queue(), ^{
  8976. result(json);
  8977. });
  8978. });
  8979. return;
  8980. }
  8981. #ifdef SCANNER_ORDER
  8982. params[@"site_name"]=[RADataProvider getSiteName];
  8983. params[@"_method"]=@"forgotPasswordOfflineOrderUser";
  8984. params[@"user"]=user;
  8985. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_RETRIEVE_PASS];
  8986. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  8987. #else
  8988. [self request_interface:URL_RETRIEVE_PASS parameters:params err_record_url:nil completionHandler:result retry:0];
  8989. #endif
  8990. //
  8991. //
  8992. // if(![self IsNetworkAvailable])
  8993. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8994. //
  8995. // NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  8996. // if(json==nil)
  8997. // return nil;
  8998. // NSError *error=nil;
  8999. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9000. // return jsobj;
  9001. }
  9002. +(void)request_update_ordercustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info completionHandler:(resultHandler)result
  9003. {
  9004. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9005. AppDelegate *appDelegate = nil;
  9006. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9007. if(appDelegate.user!=nil)
  9008. [info setValue:appDelegate.user forKey:@"user"];
  9009. // if(appDelegate.contact_id!=nil)
  9010. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9011. if(appDelegate.password!=nil)
  9012. [info setValue:appDelegate.password forKey:@"password"];
  9013. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  9014. [info setValue:order_code forKey:@"orderCode"];
  9015. // [params setValue:sourceid forKey:@"sourceid"];
  9016. // [params setValue:editor forKey:@"editor"];
  9017. if(appDelegate.offline_mode)
  9018. {
  9019. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9020. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9021. dispatch_async(dispatch_get_main_queue(), ^{
  9022. result(json);
  9023. });
  9024. });
  9025. return;
  9026. }
  9027. [self request_interface:URL_UPDATE_ORDERCUSTOMER parameters:info err_record_url:nil completionHandler:result retry:0];
  9028. // if(appDelegate.offline_mode)
  9029. // {
  9030. // return [OLDataProvider offline_notimpl];
  9031. // }
  9032. // if(![self IsNetworkAvailable])
  9033. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9034. //
  9035. // NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  9036. // if(json!=nil)
  9037. // {
  9038. // NSError *error=nil;
  9039. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9040. // return jsobj;
  9041. // }
  9042. // else
  9043. // return nil;
  9044. }
  9045. +(void)request_update_customer_img: (NSString*) contactid img_url:(NSString*) url completionHandler:(resultHandler)result
  9046. {
  9047. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9048. AppDelegate *appDelegate = nil;
  9049. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9050. if(appDelegate.user!=nil)
  9051. [params setValue:appDelegate.user forKey:@"user"];
  9052. // if(appDelegate.contact_id!=nil)
  9053. if(appDelegate.password!=nil)
  9054. [params setValue:appDelegate.password forKey:@"password"];
  9055. [params setValue:contactid forKey:@"contactId"];
  9056. [params setValue:url forKey:@"business_card"];
  9057. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  9058. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  9059. if(appDelegate.offline_mode)
  9060. {
  9061. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9062. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9063. dispatch_async(dispatch_get_main_queue(), ^{
  9064. result(json);
  9065. });
  9066. });
  9067. return;
  9068. }
  9069. [self request_interface:URL_UPDATE_CUSTOMER_BCARD parameters:params err_record_url:nil completionHandler:result retry:0];
  9070. // if(appDelegate.offline_mode)
  9071. // {
  9072. // return [OLDataProvider offline_notimpl];
  9073. // }
  9074. // if(![self IsNetworkAvailable])
  9075. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9076. //
  9077. // NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  9078. // if(json==nil)
  9079. // return nil;
  9080. // NSError *error=nil;
  9081. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9082. // return jsobj;
  9083. }
  9084. +(void)request_commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url completionHandler:(resultHandler)result
  9085. {
  9086. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9087. AppDelegate *appDelegate = nil;
  9088. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9089. if(appDelegate.user!=nil)
  9090. [params setValue:appDelegate.user forKey:@"user"];
  9091. if(appDelegate.contact_id!=nil)
  9092. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9093. if(appDelegate.password!=nil)
  9094. [params setValue:appDelegate.password forKey:@"password"];
  9095. // if(appDelegate.order_code!=nil)
  9096. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  9097. // NSDictionary* customerinfo= appDelegate.customerInfo;
  9098. //
  9099. // NSArray* keys=[customerinfo allKeys];
  9100. // for(int i=0;i<keys.count;i++)
  9101. // {
  9102. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  9103. // }
  9104. //
  9105. // [params setValue:sourceid forKey:@"sourceid"];
  9106. // [params setValue:editor forKey:@"editor"];
  9107. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  9108. if(appDelegate.offline_mode)
  9109. {
  9110. params[@"offline_Command"]=url;
  9111. [OLDataProvider offline_commoneditor_partialrefresh:params completionHandler:result];
  9112. //
  9113. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9114. // NSMutableDictionary* json = [[OLDataProvider offline_commoneditor_partialrefresh:params] mutableCopy];
  9115. // dispatch_async(dispatch_get_main_queue(), ^{
  9116. // result(json);
  9117. // });
  9118. // });
  9119. return;
  9120. }
  9121. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  9122. //
  9123. // if(appDelegate.offline_mode)
  9124. // {
  9125. // params[@"offline_Command"]=url;
  9126. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  9127. // }
  9128. //
  9129. // if(![self IsNetworkAvailable])
  9130. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9131. //
  9132. // NSData* json=[self get_json:url parameters:params];
  9133. // if(json!=nil)
  9134. // {
  9135. // NSError *error=nil;
  9136. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9137. // if([[jsobj valueForKey:@"result"]intValue]==2)
  9138. // [appDelegate SetSo:nil];
  9139. //
  9140. //
  9141. // return jsobj;
  9142. // }
  9143. // else
  9144. // return nil;
  9145. }
  9146. +(void)request_add_address:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  9147. {
  9148. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9149. AppDelegate *appDelegate = nil;
  9150. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9151. if(appDelegate.user!=nil)
  9152. [params setValue:appDelegate.user forKey:@"user"];
  9153. if(appDelegate.contact_id!=nil)
  9154. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9155. if(appDelegate.password!=nil)
  9156. [params setValue:appDelegate.password forKey:@"password"];
  9157. // [params setValue:sourceid forKey:@"sourceid"];
  9158. // [params setValue:editor forKey:@"editor"];
  9159. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  9160. if(appDelegate.offline_mode)
  9161. {
  9162. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9163. NSData* json = [[OLDataProvider offline_saveaddr:params] mutableCopy];
  9164. dispatch_async(dispatch_get_main_queue(), ^{
  9165. result([[RAConvertor data2dict:json] mutableCopy]);
  9166. });
  9167. });
  9168. return;
  9169. }
  9170. [self request_interface:URL_ADDRESS_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  9171. //
  9172. // NSData* json=nil;
  9173. //
  9174. // if(appDelegate.offline_mode)
  9175. // {
  9176. // json= [OLDataProvider offline_saveaddr:params];
  9177. // }
  9178. // else
  9179. // {
  9180. // if(![self IsNetworkAvailable])
  9181. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9182. //
  9183. // json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  9184. // }
  9185. // if(json!=nil)
  9186. // {
  9187. // NSError *error=nil;
  9188. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9189. // return jsobj;
  9190. // }
  9191. // else
  9192. // return nil;
  9193. }
  9194. +(void)request_commit_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  9195. {
  9196. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9197. AppDelegate *appDelegate = nil;
  9198. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9199. if(appDelegate.user!=nil)
  9200. [params setValue:appDelegate.user forKey:@"user"];
  9201. if(appDelegate.contact_id!=nil)
  9202. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9203. if(appDelegate.password!=nil)
  9204. [params setValue:appDelegate.password forKey:@"password"];
  9205. if(appDelegate.order_code!=nil)
  9206. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  9207. // NSDictionary* customerinfo= appDelegate.customerInfo;
  9208. //
  9209. // NSArray* keys=[customerinfo allKeys];
  9210. // for(int i=0;i<keys.count;i++)
  9211. // {
  9212. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  9213. // }
  9214. //
  9215. // [params setValue:sourceid forKey:@"sourceid"];
  9216. // [params setValue:editor forKey:@"editor"];
  9217. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  9218. if(appDelegate.offline_mode)
  9219. {
  9220. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9221. NSData* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  9222. dispatch_async(dispatch_get_main_queue(), ^{
  9223. result([[RAConvertor data2dict:json] mutableCopy]);
  9224. });
  9225. });
  9226. return;
  9227. }
  9228. [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  9229. //
  9230. // NSData* json=nil;
  9231. // if(appDelegate.offline_mode)
  9232. // {
  9233. // json=[OLDataProvider offline_submitorder:params];
  9234. // }
  9235. // else
  9236. // {
  9237. // if(![self IsNetworkAvailable])
  9238. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9239. //
  9240. // json=[self get_json:URL_COMMIT_ORDER parameters:params];
  9241. // }
  9242. // if(json!=nil)
  9243. // {
  9244. // NSError *error=nil;
  9245. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9246. // if([[jsobj valueForKey:@"result"]intValue]==2)
  9247. // [appDelegate SetSo:nil];
  9248. //
  9249. //
  9250. // return jsobj;
  9251. // }
  9252. // else
  9253. // return nil;
  9254. }
  9255. +(void) request_new_offline_ticket:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid completionHandler:(resultHandler)result
  9256. {
  9257. // if(![self IsNetworkAvailable])
  9258. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9259. //
  9260. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9261. AppDelegate *appDelegate = nil;
  9262. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9263. if(appDelegate.user!=nil)
  9264. [params setValue:appDelegate.user forKey:@"user"];
  9265. // if(appDelegate.contact_id!=nil)
  9266. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9267. if(appDelegate.password!=nil)
  9268. [params setValue:appDelegate.password forKey:@"password"];
  9269. [params setValue:ver forKey:@"ver"];
  9270. [params setValue:vid forKey:@"vid"];
  9271. if(buseinternaladdress)
  9272. [params setValue:@"true" forKey:@"internal_address"];
  9273. else
  9274. [params setValue:@"false" forKey:@"internal_address"];
  9275. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  9276. // 无论当前是离线还是在线状态,都可以进行同步;
  9277. // if(appDelegate.offline_mode)
  9278. // {
  9279. //
  9280. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9281. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9282. // dispatch_async(dispatch_get_main_queue(), ^{
  9283. // result(json);
  9284. // });
  9285. // });
  9286. //
  9287. // return;
  9288. //
  9289. // }
  9290. [self request_interface:URL_CHECK_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  9291. //
  9292. // NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  9293. // if(json==nil)
  9294. // return nil;
  9295. // NSError *error=nil;
  9296. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9297. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9298. // //
  9299. // // if (result==2)
  9300. // // {
  9301. // //
  9302. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9303. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9304. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9305. // ////
  9306. // //// [appDelegate update_count_mark];
  9307. // // }
  9308. // return jsobj;
  9309. }
  9310. +(void) request_complete_offline_ticket:(NSString* )vid completionHandler:(resultHandler)result
  9311. {
  9312. AppDelegate *appDelegate = nil;
  9313. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9314. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9315. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  9316. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  9317. // if(appDelegate.user!=nil)
  9318. // [params setValue:appDelegate.user forKey:@"user"];
  9319. // // if(appDelegate.contact_id!=nil)
  9320. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9321. // if(appDelegate.password!=nil)
  9322. // [params setValue:appDelegate.password forKey:@"password"];
  9323. [params setValue:vid forKey:@"downSerial"];
  9324. // 无论当前是离线还是在线状态,都可以进行同步;
  9325. // if(appDelegate.offline_mode)
  9326. // {
  9327. //
  9328. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9329. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9330. // dispatch_async(dispatch_get_main_queue(), ^{
  9331. // result(json);
  9332. // });
  9333. // });
  9334. //
  9335. // return;
  9336. //
  9337. // }
  9338. [self request_interface:URL_FINISH_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  9339. // NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  9340. // if(json==nil)
  9341. // return nil;
  9342. // NSError *error=nil;
  9343. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9344. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9345. // //
  9346. // // if (result==2)
  9347. // // {
  9348. // //
  9349. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9350. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9351. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9352. // ////
  9353. // //// [appDelegate update_count_mark];
  9354. // // }
  9355. // return jsobj;
  9356. }
  9357. +(void) request_download_offline:(NSString* )vid completionHandler:(resultHandler)result
  9358. {
  9359. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9360. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  9361. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  9362. // if(appDelegate.user!=nil)
  9363. // [params setValue:appDelegate.user forKey:@"user"];
  9364. // // if(appDelegate.contact_id!=nil)
  9365. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9366. // if(appDelegate.password!=nil)
  9367. // [params setValue:appDelegate.password forKey:@"password"];
  9368. [params setValue:vid forKey:@"downSerial"];
  9369. // AppDelegate *appDelegate = nil;
  9370. //
  9371. //
  9372. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9373. // if(appDelegate.offline_mode)
  9374. // {
  9375. //
  9376. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9377. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9378. // dispatch_async(dispatch_get_main_queue(), ^{
  9379. // result(json);
  9380. // });
  9381. // });
  9382. //
  9383. // return;
  9384. //
  9385. // }
  9386. __block bool bbreak = false;
  9387. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9388. __block NSMutableDictionary* download_json=nil;
  9389. int count=0;
  9390. // __block bool preparing = true;
  9391. while ([[download_json valueForKey:@"result"] intValue]!=2&&count<REQUEST_DOWNLOAD_RETRY_TIMES) //超过60分钟还没准被好数据就视为服务器出错。
  9392. {
  9393. if(bbreak)
  9394. break;
  9395. dispatch_async(dispatch_get_main_queue(), ^{
  9396. [self request_interface:URL_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  9397. if([resulti[@"result"] intValue]==RESULT_TRUE)
  9398. {
  9399. if(!bbreak) //此判断保证result只调用一次。
  9400. {
  9401. // appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  9402. // [appDelegate update_count_mark];
  9403. resulti[@"request_count"]=[NSNumber numberWithInt:count];
  9404. result(resulti);
  9405. }
  9406. bbreak=true;
  9407. }
  9408. else if([resulti[@"result"] intValue]==RESULT_ERROR)
  9409. {
  9410. result(resulti);
  9411. bbreak=true;
  9412. }
  9413. } retry:3];
  9414. });
  9415. sleep(RETRY_DELAY);
  9416. count++;
  9417. // download_json=[[RANetwork download_Offline:downSerial] mutableCopy];
  9418. //
  9419. // [RANetwork request_download_offline:downSerial completionHandler:^(NSMutableDictionary *result) {
  9420. // download_json=result;
  9421. // }];
  9422. //
  9423. }
  9424. // for(int i=0;i<150;i++)
  9425. // {
  9426. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  9427. // // result_params[@"resultSerial"]=uuid;
  9428. //
  9429. //
  9430. //
  9431. // sleep(2);
  9432. //
  9433. // // json=[self get_json:URL_CART parameters:params];
  9434. // // if(json!=nil)
  9435. // // {
  9436. // //
  9437. // // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9438. // // if([jsobj[@"result"] intValue]==2)
  9439. // // {
  9440. // // break;
  9441. // // }
  9442. // // }
  9443. //
  9444. // }
  9445. });
  9446. //
  9447. // NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  9448. // if(json==nil)
  9449. // return nil;
  9450. // NSError *error=nil;
  9451. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9452. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9453. // //
  9454. // // if (result==2)
  9455. // // {
  9456. // //
  9457. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9458. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9459. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9460. // ////
  9461. // //// [appDelegate update_count_mark];
  9462. // // }
  9463. // return jsobj;
  9464. }
  9465. + (void)request_fastupload:(NSMutableDictionary *)params filename:(NSString*)filename data:(NSData*) data url:(NSString *)url completionHandler:(resultHandler)result
  9466. {
  9467. //#ifdef test_server
  9468. // url=URL_REQUEST_RECORDS;
  9469. // params[@"prefix"]=URL_REQUEST_RECORDS;
  9470. //#endif
  9471. // [self request_file_fast:url parameters:params completionHandler:result];
  9472. #ifdef SCANNER_ORDER
  9473. params[@"site_name"]=[RADataProvider getSiteName];
  9474. #endif
  9475. [self request_upload_fast:data FileName:filename server:url parameters:params completionHandler:result];
  9476. }
  9477. +(void)request_err_log:(NSString*) up_params result:(NSString*)result_str module:(NSString*) module code:(int) code completionHandler:(resultHandler)result
  9478. {
  9479. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9480. AppDelegate *appDelegate = nil;
  9481. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9482. if(appDelegate.user!=nil)
  9483. [params setValue:appDelegate.user forKey:@"user"];
  9484. [params setValue:up_params forKey:@"upparam"];
  9485. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  9486. [params setValue:result_str forKey:@"result"];
  9487. [params setValue:module forKey:@"interfac"];
  9488. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  9489. // [params setValue:module forKey:@"module"];
  9490. // [[UIDevice currentDevice] name];
  9491. // if(appDelegate.offline_mode)
  9492. // {
  9493. // return [OLDataProvider offline_notimpl];
  9494. // }
  9495. if(appDelegate.offline_mode)
  9496. {
  9497. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9498. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9499. dispatch_async(dispatch_get_main_queue(), ^{
  9500. result(json);
  9501. });
  9502. });
  9503. return;
  9504. }
  9505. [self request_interface:URL_ERR_LOG parameters:params err_record_url:nil completionHandler:result retry:0];
  9506. //
  9507. // if(![self IsNetworkAvailable])
  9508. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9509. //
  9510. // NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  9511. // if(json==nil)
  9512. // return nil;
  9513. // NSError *error=nil;
  9514. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9515. // return jsobj;
  9516. }
  9517. @end