RANetwork.m 403 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059
  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. NSString *const kScreenName = @"kScreenName";
  16. NSString *const kAction = @"kAction";
  17. NSString *const kExtra = @"kExtra";
  18. NSString *const ScreenCodeLoginView = @"Login Screen";
  19. NSString *const ScreenCodeHomeView = @"Home Screen";
  20. NSString *const ScreenCodeCategory = @"Category Screen";
  21. NSString *const ScreenCodeCart = @"Cart Sceen";
  22. NSString *const ScreenCodeOrderList = @"Order History Screen";
  23. NSString *const ScreenCodeSearch = @"Search Screen";
  24. NSString *const ScreenCodeAccount = @"Account Screen";
  25. NSString *const ScreenCodeWishList = @"Wish List Screen";
  26. NSString *const ScreenCodePortfolio = @"Portfolio Screen";
  27. NSString *const ScreenCodeViewPortfolios = @"View Portfolios Screen";
  28. NSString *const ScreenCodeCamScan = @"Cam Scan Screen";
  29. NSString *const ScreenCodeScannerSetting = @"Scanner Setting Screen";
  30. NSString *const ScreenCodeOfflineSetting = @"Offline Setting Screen";
  31. NSString *const ScreenCodePlaceOrder = @"Place Order Screen";
  32. NSString *const ScreenCodeCustomerInfo = @"Customer Information Screen";
  33. NSString *const ScreenCodeNewCustomer = @"New Customer Screen";
  34. NSString *const ScreenCodeEditCustomer = @"Edit Customer Information Screen";
  35. NSString *const ScreenCodeModelInfo = @"Model Information Screen";
  36. NSString *const ScreenCodeOrderInfo = @"Order Information Screeen";
  37. NSString *const ScreenCodeUserSign = @"User Sign Screen";
  38. NSString *const ScreenCodeNewAddress = @"New Address Screen";
  39. NSString *const ScreenCodeAdvanceSearch = @"Account Advance Search Screen";
  40. NSString *const ScreenCodeCreatePortfolio = @"Create Portfolio Screen";
  41. NSString *const ScreenCodeParticularCategory = @"Particular Category Screen";
  42. NSString *const ScreenCodeEditPortfolio = @"Edit Portfolio Screen";
  43. NSString *const ScreenCodePriceSetting = @"Price Setting Screen";
  44. NSString *const ScreenCodeCategoryPrice = @"Category Price Screen";
  45. NSString *const ScreenCodeSetCatetoryPrice = @"Set Category Price Screen";
  46. NSString *const ScreenCodeUploadImage = @"Upload Image Screen";
  47. NSString *const ScreenCodeOfflineSync = @"Offline Sync Screen";
  48. @implementation RANetwork
  49. +(NSMutableDictionary*) prepare_additional_params:(NSMutableDictionary* ) params
  50. {
  51. AppDelegate *appDelegate = nil;
  52. //some UI methods ej
  53. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  54. // if(appDelegate.user!=nil)
  55. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.user key:@"usai"] forKey:@"user"];
  56. // if(appDelegate.password!=nil)
  57. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.password key:@"usai"] forKey:@"password"];
  58. //
  59. //
  60. //
  61. // if(appDelegate.user!=nil)
  62. // [params setValue:appDelegate.user forKey:@"user"];
  63. //
  64. // if(appDelegate.contact_id!=nil)
  65. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  66. // if(appDelegate.password!=nil)
  67. // [params setValue:appDelegate.password forKey:@"password"];
  68. //
  69. // [params setValue:appDelegate.build forKey:@"app_ver"];
  70. //
  71. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  72. // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  73. // [params setValue:short_version forKey:@"app_short_ver"];
  74. //
  75. //
  76. //
  77. //#if TARGET_IPHONE_SIMULATOR//模拟器
  78. // [params setValue:@"simulator_uuid" forKey:@"deviceid"];
  79. //#elif TARGET_OS_IPHONE//真机
  80. // UIDevice * dev = [UIDevice currentDevice];
  81. // NSUUID* uuid =dev.identifierForVendor;
  82. // [params setValue:uuid.UUIDString forKey:@"deviceid"];
  83. //#endif
  84. if(appDelegate.user!=nil)
  85. [params setValue:appDelegate.user forKey:@"user"];
  86. if(appDelegate.password!=nil)
  87. [params setValue:appDelegate.password forKey:@"password"];
  88. if(appDelegate.ipad_perm!=nil)
  89. [params setValue:appDelegate.ipad_perm forKey:@"ipad_perm"];
  90. [params setValue:appDelegate.build forKey:@"app_ver"];
  91. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  92. NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  93. [params setValue:short_version forKey:@"app_short_ver"];
  94. #if TARGET_IPHONE_SIMULATOR//模拟器
  95. [params setValue:@"simulator_uuid" forKey:@"idfv"];
  96. #elif TARGET_OS_IPHONE//真机
  97. UIDevice * dev = [UIDevice currentDevice];
  98. NSUUID* uuid =dev.identifierForVendor;
  99. [params setValue:uuid.UUIDString forKey:@"idfv"];
  100. #endif
  101. //
  102. // NSString *userAction = [params valueForKey:kAction];
  103. // NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  104. // if ([userAction isEqualToString:@"Login"]) {
  105. // if (!extra) {
  106. // extra = [NSMutableDictionary dictionary];
  107. // }
  108. // [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  109. // }
  110. return params;
  111. }
  112. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString *) file //delegate:(id < NSURLConnectionDelegate >)delegate
  113. {
  114. // NSString* e=[AESCrypt AES128Encrypt:@"密码学中的高级加密标准(Advanced Encryption Standard,AES),又称 高级加密标准Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用。经过五年的甄选流程,高级加密标准由美国国家标准与技术研究院 (NIST)于2001年11月26日发布于FIPS PUB 197,并在2002年5月26日成为有效的标准。2006年,高级加密标准已然成为对称密钥加密中最流行的算法之一。 " key:@"usai2010"];
  115. // DebugLog(e);
  116. // NSString* d=[AESCrypt decrypt:@"VzB4+lENfbzWX7ggHh2Os1P69l5YBzKmM51yqA37AfoKgPY8bJgdK8M4WvF+wDyOsLWP\/o8H5+bHMivQp1u8wM2QV7SYzgzPwV85QKtYWIzEgLe9T0HO69EdutWz7k1rdAT\/mftsRin0Hy5SHk7txTZT\/zPH5X+FQiExCTFm5Zus39HYvp+VxCX4+kYeymn8B63AUd3mRQyscUvDjfgU2olKR\/TP8PV3g+VQMZxpKfol3P1iOtz3XQlHZV0pM6SAf+SwT0sPfrdn6CZFfNQlrKA9QjMrnBdMeSCquSIWXnmLv6okzvnlJnT0SjvJuUeqNdBC5EZ0ACnhI0MrXVZEsq1EuM9al7oPzvU5EZbjZpmx+fSFIkMzTT8bYClTnG1bsL1MCcU4pSODDorUj8zalA==" password:@"usai2010"];
  117. params = [self prepare_additional_params:params];
  118. DebugLog(@"\n++++++++++++++++++++++Request++++++++++++++++++++++\n%@\n++++++++++++++++++++++Params++++++++++++++++++++++\n%@\n",url,[RAConvertor dict2string:params]);
  119. return [super get_json:url parameters:params file:(NSString*)file err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  120. int result=[[jsobj valueForKey:@"result"] intValue];
  121. // UIApplication * app = [UIApplication sharedApplication];
  122. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  123. switch (result) {
  124. case 0:
  125. [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  126. break;
  127. case 1:
  128. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  129. break;
  130. case 2:
  131. [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  132. break;
  133. case 8:
  134. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  135. break;
  136. case 9:
  137. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  138. break;
  139. case 99:
  140. [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  141. break;
  142. default:
  143. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  144. break;
  145. }
  146. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  147. // {
  148. // [jsobj setValue:@"9" forKey:@"result"];
  149. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  150. // }
  151. return jsobj;
  152. } decrypt_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  153. return nil;
  154. // NSString* base64str = jsobj[@"str"];
  155. // NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"usai2010"];
  156. // jsobj=[[RAUtils string2dict:decryptstr] mutableCopy];
  157. // return jsobj;
  158. }];
  159. /*
  160. */
  161. return nil;
  162. }
  163. +(void) LoadImage:(NSString*) url into:(UIImageView*) container
  164. {
  165. DebugLog(@"LoadImage:(NSString*) url in:(UIImageView*) container");
  166. NSString* file_name=[url lastPathComponent];
  167. NSData* img_data = [iSalesDB load_cached_img:file_name loadFrom:url];
  168. if(img_data==nil)
  169. {
  170. DebugLog(@"IMG NOT CACHED %@",file_name);
  171. img_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
  172. [iSalesDB cache_img:img_data filename:file_name saveTo:url];
  173. //load from internet;
  174. }
  175. if(img_data!=nil)
  176. {
  177. UIImage * img =[UIImage imageWithData:img_data];
  178. if(img==nil)
  179. DebugLog(@"UIIMAGE IS NIL! %@",file_name);
  180. else
  181. dispatch_async(dispatch_get_main_queue(), ^{
  182. container.image =img;
  183. });
  184. }
  185. else
  186. {
  187. DebugLog(@"IMG DOWNLOAD FAILED! %@",file_name);
  188. }
  189. }
  190. //+(NSData*)fake_json:(NSString*) url
  191. //{
  192. // NSString* jsonfile = nil;
  193. // if([url isEqualToString:URL_UPDATE_AUTH])
  194. // {
  195. // jsonfile=@"login";
  196. //
  197. // }
  198. // else if([url isEqualToString:URL_REQUEST_CATMENU])
  199. // {
  200. // jsonfile=@"categorymenu";
  201. // }
  202. // else if([url isEqualToString:URL_LOAD_HOME])
  203. // {
  204. // jsonfile=@"homepage";
  205. // }
  206. // else if([url isEqualToString:URL_SEARCH])
  207. // {
  208. // jsonfile=@"search";
  209. // }
  210. // else if([url isEqualToString:URL_CATEGORY_LOADMORE])
  211. // {
  212. // jsonfile=@"category_more";
  213. // }else if([url isEqualToString:URL_ITEM_DETAIL])
  214. // {
  215. // jsonfile=@"detail";
  216. // }else if([url isEqualToString:URL_CART])
  217. // {
  218. // jsonfile=@"cart";
  219. // }else if([url isEqualToString:URL_ORDER_LIST])
  220. // {
  221. // jsonfile=@"orderlist";
  222. // }
  223. //// else if([url isEqualToString:URL_ORDER_INFO])
  224. //// {
  225. //// jsonfile=@"orderinfo";
  226. //// }
  227. //// else if([url isEqualToString:URL_ORDER_INFO])
  228. //// {
  229. //// jsonfile=@"orderinfo2label";
  230. //// }
  231. //
  232. //
  233. //
  234. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:jsonfile ofType:@"json" ]];
  235. // NSMutableString *result = [[NSMutableString alloc] initWithData:json encoding:NSUTF8StringEncoding];
  236. //
  237. // DebugLog(@"result: \n%@",result);
  238. // return json;
  239. //}
  240. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
  241. {
  242. NSString *screenName = [params valueForKey:kScreenName];
  243. NSString *userAction = [params valueForKey:kAction];
  244. NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  245. if ([userAction isEqualToString:@"Login"]) {
  246. if (!extra) {
  247. extra = [NSMutableDictionary dictionary];
  248. }
  249. [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  250. }
  251. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  252. [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  253. #endif
  254. return [self get_json:url parameters:params file:nil];
  255. // {
  256. // int retry = 0;
  257. //
  258. // __block AppDelegate *appDelegate = nil;
  259. //
  260. // dispatch_sync(dispatch_get_main_queue(), ^{
  261. // //some UI methods ej
  262. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  263. // });
  264. // if(appDelegate.user!=nil)
  265. // [params setValue:appDelegate.user forKey:@"user"];
  266. // if(appDelegate.password!=nil)
  267. // [params setValue:appDelegate.password forKey:@"password"];
  268. //
  269. //
  270. // if(appDelegate.ipad_perm!=nil)
  271. // [params setValue:appDelegate.ipad_perm forKey:@"ipad_perm"];
  272. //
  273. // [params setValue:appDelegate.build forKey:@"app_ver"];
  274. //
  275. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  276. // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  277. // [params setValue:short_version forKey:@"app_short_ver"];
  278. //
  279. // UIDevice * dev = [UIDevice currentDevice];
  280. // NSUUID* uuid =dev.identifierForVendor;
  281. //#if TARGET_IPHONE_SIMULATOR//模拟器
  282. // [params setValue:@"simulator_uuid" forKey:@"idfv"];
  283. //#elif TARGET_OS_IPHONE//真机
  284. // [params setValue:uuid.UUIDString forKey:@"idfv"];
  285. //#endif
  286. //
  287. //// NSString *screenName = [params valueForKey:kScreenName];
  288. //// NSString *userAction = [params valueForKey:kAction];
  289. //// NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  290. //// if ([userAction isEqualToString:@"Login"]) {
  291. //// if (!extra) {
  292. //// extra = [NSMutableDictionary dictionary];
  293. //// }
  294. //// [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  295. //// }
  296. //
  297. //repeat:
  298. // {
  299. //
  300. // // return [self fake_json:url];
  301. //
  302. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  303. // //分界线的标识符
  304. // NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
  305. // //根据url初始化request
  306. // NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
  307. // cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
  308. // timeoutInterval:JSON_TIMEOUT];
  309. // //分界线 --AaB03x
  310. // NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
  311. // //结束符 AaB03x--
  312. // NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
  313. // //要上传的图片
  314. // // UIImage *image=[params objectForKey:@"pic"];
  315. // //得到图片的data
  316. // // NSData* data = UIImagePNGRepresentation(image);
  317. // //http body的字符串
  318. // NSMutableString *body=[[NSMutableString alloc]init];
  319. //
  320. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  321. // // [params setValue:@"handset_login" forKey:@"action"];
  322. // // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  323. //
  324. // // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  325. // // [params setValue:password forKey:@"password"];
  326. // // [params setValue:[NSString stringWithFormat:@"%d",ver] forKey:@"auth_ver"];
  327. //
  328. //
  329. //
  330. // // [headers setValue:headQuerlString forKey:@"param"];
  331. //
  332. // //参数的集合的所有key的集合
  333. // NSArray *keys= [params allKeys];
  334. // DebugLog(@"================parms==================");
  335. // //遍历keys
  336. // for(int i=0;i<[keys count];i++)
  337. // {
  338. // //得到当前key
  339. // NSString *key=[keys objectAtIndex:i];
  340. // //如果key不是pic,说明value是字符类型,比如name:Boris
  341. // if(![key isEqualToString:@"pic"])
  342. // {
  343. // //添加分界线,换行
  344. // [body appendFormat:@"%@\r\n",MPboundary];
  345. // //添加字段名称,换2行
  346. // [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
  347. // //添加字段的值
  348. // [body appendFormat:@"%@\r\n",[params objectForKey:key]];
  349. // DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
  350. // }
  351. // }
  352. // DebugLog(@"================parms==================");
  353. // ////添加分界线,换行
  354. // [body appendFormat:@"%@\r\n",MPboundary];
  355. // //声明pic字段,文件名为boris.png
  356. // [body appendFormat:@"Content-Disposition: form-data; name=\"pic\"; filename=\"boris.png\"\r\n"];
  357. // //声明上传文件的格式
  358. // [body appendFormat:@"Content-Type: image/png\r\n\r\n"];
  359. //
  360. // //声明结束符:--AaB03x--
  361. // NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
  362. // //声明myRequestData,用来放入http body
  363. // NSMutableData *myRequestData=[NSMutableData data];
  364. // //将body字符串转化为UTF8格式的二进制
  365. // [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
  366. // //将image的data加入
  367. // // [myRequestData appendData:data];
  368. // //加入结束符--AaB03x--
  369. // [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
  370. //
  371. // //设置HTTPHeader中Content-Type的值
  372. // NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
  373. // //设置HTTPHeader
  374. // [request setValue:content forHTTPHeaderField:@"Content-Type"];
  375. //
  376. // // 关闭keep alive
  377. // [request setValue:@"close" forHTTPHeaderField:@"Connection"];
  378. // //设置Content-Length
  379. // [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[myRequestData length]] forHTTPHeaderField:@"Content-Length"];
  380. // //设置http body
  381. // [request setHTTPBody:myRequestData];
  382. // //http method
  383. // [request setHTTPMethod:@"POST"];
  384. //
  385. //
  386. // NSHTTPURLResponse* urlResponse = nil;
  387. //
  388. // NSError *error = nil;
  389. //
  390. // NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  391. //
  392. //
  393. // DebugLog(@"url: %@",url);
  394. //
  395. // DebugLog(@"response: %@",[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode]);
  396. //
  397. // if (responseData==nil) {
  398. //
  399. //// DebugLog(@"response error:%@", [error localizedDescription]);
  400. //
  401. //
  402. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  403. // //#define RESULT_FALSE 0
  404. // //#define RESULT_TRUE 2
  405. // //#define RESULT_NET_ERROR -3
  406. // //#define RESULT_NET_NOTAVAILABLE -4
  407. // //#define RESULT_ERROR -5
  408. // //#define RESULT_LOCALFILE_ERROR -7
  409. // //#define RESULT_USERAUTH_ERROR -9
  410. // //#define RESULT_UPDATE_USERAUTH_ERROR -11
  411. // //#define RESULT_SESSION_EXPIRED -13
  412. // //#define RESULT_VER_LOW
  413. //
  414. // // NSString * moreinfo = error.description ;
  415. //
  416. // NSString* err_msg = [error localizedDescription];
  417. //
  418. //
  419. // //-----------------retry 3 times for error code -1005------------------------
  420. // if(error.code==-1005&&retry<3)
  421. // {
  422. // retry++;
  423. // goto repeat;
  424. //
  425. // }
  426. // //-----------------end retry 3 times for error code -1005------------------------
  427. //
  428. // NSDictionary* error_json = [RAUtils error_dict:error];
  429. // [ret setObject:error_json forKey:@"err_obj"];
  430. // NSString* resp_msg= nil;
  431. //
  432. // if(err_msg.length==0)
  433. // {
  434. // err_msg =[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode];
  435. // resp_msg = err_msg;
  436. // }
  437. // [ret setValue:[NSString stringWithFormat:@"%d",RESULT_NET_ERROR] forKey:@"result"];
  438. // [ret setValue:err_msg forKey:@"err_msg"];
  439. // [ret setValue:resp_msg forKey:@"resp_msg"];
  440. // [ret setValue:[NSString stringWithFormat:@"%ld",(long)urlResponse.statusCode] forKey:@"resp_code"];
  441. //
  442. //
  443. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ret
  444. // options:0
  445. // error:nil];
  446. // if(![url isEqualToString:URL_ERR_LOG])
  447. // {
  448. // [RANetwork err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:[RAConvertor dict2string:ret]] module:url code:RESULT_NET_ERROR];
  449. // }
  450. //#if defined(BUILD_NPD)// || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  451. // [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  452. //#endif
  453. // return jsonData;
  454. //
  455. // }
  456. // else
  457. // {
  458. // NSString* err_msg = [error localizedDescription];
  459. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  460. //
  461. // DebugLog(@"data string: %@",str);
  462. // NSError *error1 = nil;
  463. //
  464. // NSMutableDictionary* jsobj = [[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error1] mutableCopy];
  465. //
  466. // if(jsobj==nil)// 服务器返回不是json
  467. // {
  468. //
  469. // jsobj=[[NSMutableDictionary alloc] init];
  470. // [jsobj setValue:@"1" forKey:@"result"];
  471. //
  472. // }
  473. //
  474. // int result=[[jsobj valueForKey:@"result"] intValue];
  475. // UIApplication * app = [UIApplication sharedApplication];
  476. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  477. // NSString* mode =[jsobj valueForKey:@"mode"];
  478. // [appDelegate SetMode:mode];
  479. // switch (result) {
  480. // case 0:
  481. // [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  482. // break;
  483. // case 1:
  484. // [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  485. // break;
  486. // case 2:
  487. // [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  488. // break;
  489. // case 8:
  490. // [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  491. // break;
  492. // case 9:
  493. // [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  494. // break;
  495. // case 99:
  496. // [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  497. // break;
  498. // default:
  499. // [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  500. // break;
  501. // }
  502. //
  503. //
  504. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  505. // {
  506. // [jsobj setValue:@"9" forKey:@"result"];
  507. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  508. // }
  509. //
  510. // if(![url isEqualToString:URL_ERR_LOG]&&![url isEqualToString:URL_DOWNLOAD_OFFLINE]/*&&result!=-3*/&&result!=2&&result!=99)
  511. // {
  512. // [RANetwork err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:str] module:url code:result];
  513. // }
  514. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsobj
  515. // options:0
  516. // error:nil];
  517. //#if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  518. // [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  519. //#endif
  520. // return jsonData;
  521. //
  522. // }
  523. //
  524. // return responseData;
  525. // }
  526. //}
  527. }
  528. //+(NSDictionary*)request_Editor:(NSString*) sourceid editor:(NSString*)editor
  529. //{
  530. //
  531. //}
  532. +(NSDictionary*) delete_portfoliolist:(NSString* ) listid
  533. {
  534. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  535. __block AppDelegate *appDelegate = nil;
  536. dispatch_sync(dispatch_get_main_queue(), ^{
  537. //some UI methods ej
  538. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  539. });
  540. if(appDelegate.user!=nil)
  541. [params setValue:appDelegate.user forKey:@"user"];
  542. if(appDelegate.contact_id!=nil)
  543. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  544. if(appDelegate.password!=nil)
  545. [params setValue:appDelegate.password forKey:@"password"];
  546. [params setValue:listid forKey:@"tearsheetsId"];
  547. // [params setValue:editor forKey:@"editor"];
  548. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  549. // [params setValue:@"Delete Portfolio" forKey:kAction];
  550. NSData* json = nil;
  551. if(appDelegate.offline_mode)
  552. {
  553. json = [OLDataProvider offline_removePDF:params];
  554. } else {
  555. if(![self IsNetworkAvailable])
  556. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  557. json=[self get_json:URL_PORTFOLIOLIST_REMOVE parameters:params];
  558. }
  559. if(json!=nil)
  560. {
  561. NSError *error=nil;
  562. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  563. return jsobj;
  564. }
  565. else
  566. return nil;
  567. }
  568. +(NSDictionary*) portfolio_remove:(NSString* ) item_ids
  569. {
  570. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  571. __block AppDelegate *appDelegate = nil;
  572. dispatch_sync(dispatch_get_main_queue(), ^{
  573. //some UI methods ej
  574. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  575. });
  576. if(appDelegate.user!=nil)
  577. [params setValue:appDelegate.user forKey:@"user"];
  578. if(appDelegate.contact_id!=nil)
  579. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  580. if(appDelegate.password!=nil)
  581. [params setValue:appDelegate.password forKey:@"password"];
  582. [params setValue:item_ids forKey:@"portfolioId"];
  583. // [params setValue:editor forKey:@"editor"];
  584. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  585. NSData* json = nil;
  586. if(appDelegate.offline_mode)
  587. {
  588. json = [OLDataProvider offline_removePortfolio:params];
  589. } else {
  590. if(![self IsNetworkAvailable])
  591. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  592. json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  593. }
  594. if(json!=nil)
  595. {
  596. NSError *error=nil;
  597. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  598. int result = [[jsobj valueForKey:@"result"] intValue];
  599. if (result==2)
  600. {
  601. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  602. [appDelegate update_count_mark];
  603. }
  604. return jsobj;
  605. }
  606. else
  607. return nil;
  608. }
  609. //+(NSDictionary*) watchlist_remove:(NSString* ) item_ids
  610. //{
  611. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  612. // __block AppDelegate *appDelegate = nil;
  613. //
  614. // dispatch_sync(dispatch_get_main_queue(), ^{
  615. // //some UI methods ej
  616. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  617. // });
  618. // if(appDelegate.user!=nil)
  619. // [params setValue:appDelegate.user forKey:@"user"];
  620. // if(appDelegate.contact_id!=nil)
  621. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  622. // if(appDelegate.password!=nil)
  623. // [params setValue:appDelegate.password forKey:@"password"];
  624. // [params setValue:item_ids forKey:@"collectId"];
  625. // // [params setValue:editor forKey:@"editor"];
  626. //
  627. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  628. //
  629. // if(appDelegate.offline_mode)
  630. // {
  631. // return [OLDataProvider offline_deletewishlist:params];
  632. // }
  633. // if(![self IsNetworkAvailable])
  634. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  635. //
  636. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  637. // if(json!=nil)
  638. // {
  639. // NSError *error=nil;
  640. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  641. // int result = [[jsobj valueForKey:@"result"] intValue];
  642. //
  643. // if (result==2)
  644. // {
  645. //
  646. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  647. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  648. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  649. //
  650. // [appDelegate update_count_mark];
  651. // }
  652. // return jsobj;
  653. // }
  654. // else
  655. // return nil;
  656. //}
  657. +(NSDictionary*) move_cart2wish:(NSString* ) item_ids
  658. {
  659. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  660. __block AppDelegate *appDelegate = nil;
  661. dispatch_sync(dispatch_get_main_queue(), ^{
  662. //some UI methods ej
  663. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  664. });
  665. if(appDelegate.user!=nil)
  666. [params setValue:appDelegate.user forKey:@"user"];
  667. if(appDelegate.contact_id!=nil)
  668. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  669. if(appDelegate.password!=nil)
  670. [params setValue:appDelegate.password forKey:@"password"];
  671. if(appDelegate.order_code!=nil)
  672. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  673. [params setValue:item_ids forKey:@"cartItemId"];
  674. // [params setValue:editor forKey:@"editor"];
  675. [params setValue:ScreenCodeCart forKey:kScreenName];
  676. // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  677. NSData* json = nil;
  678. if(appDelegate.offline_mode)
  679. {
  680. json= [OLDataProvider offline_movecart2wish:params];
  681. }
  682. else
  683. {
  684. if(![self IsNetworkAvailable])
  685. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  686. json=[self get_json:URL_CART2WISH parameters:params];
  687. }
  688. if(json!=nil)
  689. {
  690. NSError *error=nil;
  691. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  692. int result = [[jsobj valueForKey:@"result"] intValue];
  693. if (result==2)
  694. {
  695. //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  696. appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  697. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  698. [appDelegate update_count_mark];
  699. }
  700. return jsobj;
  701. }
  702. else
  703. return nil;
  704. }
  705. //+(NSDictionary*) move_wish2cart:(NSString* ) item_ids
  706. //{
  707. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  708. // __block AppDelegate *appDelegate = nil;
  709. //
  710. // dispatch_sync(dispatch_get_main_queue(), ^{
  711. // //some UI methods ej
  712. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  713. // });
  714. // if(appDelegate.user!=nil)
  715. // [params setValue:appDelegate.user forKey:@"user"];
  716. // if(appDelegate.contact_id!=nil)
  717. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  718. // if(appDelegate.password!=nil)
  719. // [params setValue:appDelegate.password forKey:@"password"];
  720. // if(appDelegate.order_code!=nil)
  721. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  722. // [params setValue:item_ids forKey:@"collectId"];
  723. // // [params setValue:editor forKey:@"editor"];
  724. //
  725. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  726. // [params setValue:@"Move To Cart" forKey:kAction];
  727. //
  728. // NSData *json = nil;
  729. // if(appDelegate.offline_mode)
  730. // {
  731. // json = [OLDataProvider offline_movewish2cart:params];
  732. // } else {
  733. // if(![self IsNetworkAvailable])
  734. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  735. //
  736. // json=[self get_json:URL_WISH2CART parameters:params];
  737. // }
  738. //
  739. // if(json!=nil)
  740. // {
  741. // NSError *error=nil;
  742. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  743. // int result = [[jsobj valueForKey:@"result"] intValue];
  744. //
  745. // if (result==2)
  746. // {
  747. //
  748. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  749. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  750. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  751. //
  752. // [appDelegate update_count_mark];
  753. // }
  754. // return jsobj;
  755. // }
  756. // else
  757. // return nil;
  758. //}
  759. +(NSDictionary*) cart_remove:(NSString* ) item_ids
  760. {
  761. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  762. __block AppDelegate *appDelegate = nil;
  763. dispatch_sync(dispatch_get_main_queue(), ^{
  764. //some UI methods ej
  765. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  766. });
  767. if(appDelegate.user!=nil)
  768. [params setValue:appDelegate.user forKey:@"user"];
  769. if(appDelegate.contact_id!=nil)
  770. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  771. if(appDelegate.password!=nil)
  772. [params setValue:appDelegate.password forKey:@"password"];
  773. if(appDelegate.order_code!=nil)
  774. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  775. [params setValue:item_ids forKey:@"cartItemId"];
  776. // [params setValue:editor forKey:@"editor"];
  777. [params setValue:ScreenCodeCart forKey:kScreenName];
  778. // [params setValue:@"" forKey:kAction];
  779. NSData* json=nil;
  780. if(appDelegate.offline_mode)
  781. {
  782. json= [OLDataProvider offline_cartremove:params];
  783. }
  784. else
  785. {
  786. if(![self IsNetworkAvailable])
  787. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  788. json=[self get_json:URL_CART_REMOVE parameters:params];
  789. }
  790. if(json!=nil)
  791. {
  792. NSError *error=nil;
  793. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  794. int result = [[jsobj valueForKey:@"result"] intValue];
  795. if (result==2)
  796. {
  797. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  798. [appDelegate update_count_mark];
  799. }
  800. return jsobj;
  801. }
  802. else
  803. return nil;
  804. }
  805. //+(NSDictionary*) cart_check:(NSString* ) item_ids
  806. //{
  807. // return nil;
  808. // if(![self IsNetworkAvailable])
  809. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  810. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  811. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  812. // if(appDelegate.user!=nil)
  813. // [params setValue:appDelegate.user forKey:@"user"];
  814. // if(appDelegate.contact_id!=nil)
  815. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  816. // if(appDelegate.password!=nil)
  817. // [params setValue:appDelegate.password forKey:@"password"];
  818. // [params setValue:item_ids forKey:@"cartItemId"];
  819. // // [params setValue:editor forKey:@"editor"];
  820. // if(appDelegate.offline_mode)
  821. // {
  822. // return [OLDataProvider offline_notimpl];
  823. // }
  824. // NSData* json=[self get_json:URL_CART_CHECK parameters:params];
  825. // if(json!=nil)
  826. // {
  827. // NSError *error=nil;
  828. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  829. // return jsobj;
  830. // }
  831. // else
  832. // return nil;
  833. //}
  834. +(NSDictionary*)create_Address:(NSMutableDictionary*)params
  835. {
  836. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  837. __block AppDelegate *appDelegate = nil;
  838. dispatch_sync(dispatch_get_main_queue(), ^{
  839. //some UI methods ej
  840. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  841. });
  842. if(appDelegate.user!=nil)
  843. [params setValue:appDelegate.user forKey:@"user"];
  844. if(appDelegate.contact_id!=nil)
  845. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  846. if(appDelegate.password!=nil)
  847. [params setValue:appDelegate.password forKey:@"password"];
  848. // [params setValue:sourceid forKey:@"sourceid"];
  849. // [params setValue:editor forKey:@"editor"];
  850. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  851. NSData* json=nil;
  852. if(appDelegate.offline_mode)
  853. {
  854. json= [OLDataProvider offline_saveaddr:params];
  855. }
  856. else
  857. {
  858. if(![self IsNetworkAvailable])
  859. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  860. json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  861. }
  862. if(json!=nil)
  863. {
  864. NSError *error=nil;
  865. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  866. return jsobj;
  867. }
  868. else
  869. return nil;
  870. }
  871. +(NSDictionary*)copy_Order:(NSString*) order_code
  872. {
  873. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  874. __block AppDelegate *appDelegate = nil;
  875. dispatch_sync(dispatch_get_main_queue(), ^{
  876. //some UI methods ej
  877. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  878. });
  879. if(appDelegate.user!=nil)
  880. [params setValue:appDelegate.user forKey:@"user"];
  881. if(appDelegate.contact_id!=nil)
  882. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  883. if(appDelegate.password!=nil)
  884. [params setValue:appDelegate.password forKey:@"password"];
  885. // NSString* ssaved = @"false";
  886. // if(saved)
  887. // ssaved=@"true";
  888. // [params setValue:@"true" forKey:@"saved"];
  889. [params setValue:order_code forKey:@"code"];
  890. // [params setValue:sourceid forKey:@"sourceid"];
  891. // [params setValue:editor forKey:@"editor"];
  892. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  893. NSData* json=nil;
  894. if(appDelegate.offline_mode)
  895. {
  896. json= [OLDataProvider offline_copyorder:params];
  897. }
  898. else
  899. {
  900. if(![self IsNetworkAvailable])
  901. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  902. json=[self get_json:URL_COPY_ORDER parameters:params];
  903. }
  904. if(json!=nil)
  905. {
  906. NSError *error=nil;
  907. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  908. return jsobj;
  909. }
  910. else
  911. return nil;
  912. }
  913. +(NSDictionary*)sign_Order:(NSString*) order_code path:(NSString*)path
  914. {
  915. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  916. __block AppDelegate *appDelegate = nil;
  917. dispatch_sync(dispatch_get_main_queue(), ^{
  918. //some UI methods ej
  919. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  920. });
  921. if(appDelegate.user!=nil)
  922. [params setValue:appDelegate.user forKey:@"user"];
  923. if(appDelegate.contact_id!=nil)
  924. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  925. if(appDelegate.password!=nil)
  926. [params setValue:appDelegate.password forKey:@"password"];
  927. // NSString* ssaved = @"false";
  928. // if(saved)
  929. // ssaved=@"true";
  930. // [params setValue:@"true" forKey:@"saved"];
  931. [params setValue:order_code forKey:@"orderCode"];
  932. [params setValue:path forKey:@"picpath"];
  933. // [params setValue:sourceid forKey:@"sourceid"];
  934. // [params setValue:editor forKey:@"editor"];
  935. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  936. NSData* json=nil;
  937. if(appDelegate.offline_mode)
  938. {
  939. json= [OLDataProvider offline_signorder:params];
  940. }
  941. else
  942. {
  943. if(![self IsNetworkAvailable])
  944. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  945. json=[self get_json:URL_SIGN_ORDER parameters:params];
  946. }
  947. if(json!=nil)
  948. {
  949. NSError *error=nil;
  950. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  951. return jsobj;
  952. }
  953. else
  954. return nil;
  955. }
  956. +(NSDictionary*)commit_Order:(NSString*) order_code //saved:(bool) saved
  957. {
  958. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  959. __block AppDelegate *appDelegate = nil;
  960. dispatch_sync(dispatch_get_main_queue(), ^{
  961. //some UI methods ej
  962. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  963. });
  964. if(appDelegate.user!=nil)
  965. [params setValue:appDelegate.user forKey:@"user"];
  966. if(appDelegate.contact_id!=nil)
  967. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  968. if(appDelegate.password!=nil)
  969. [params setValue:appDelegate.password forKey:@"password"];
  970. // NSString* ssaved = @"false";
  971. // if(saved)
  972. // ssaved=@"true";
  973. [params setValue:@"true" forKey:@"saved"];
  974. [params setValue:order_code forKey:@"orderCode"];
  975. // [params setValue:sourceid forKey:@"sourceid"];
  976. // [params setValue:editor forKey:@"editor"];
  977. [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  978. NSData* json = nil;
  979. if(appDelegate.offline_mode)
  980. {
  981. json= [OLDataProvider offline_submitorder:params];
  982. }
  983. else
  984. {
  985. if(![self IsNetworkAvailable])
  986. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  987. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  988. }
  989. if(json!=nil)
  990. {
  991. NSError *error=nil;
  992. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  993. return jsobj;
  994. }
  995. else
  996. return nil;
  997. }
  998. //+(NSDictionary*)open_Order:(NSString*) order_code
  999. //{
  1000. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1001. // __block AppDelegate *appDelegate = nil;
  1002. //
  1003. // dispatch_sync(dispatch_get_main_queue(), ^{
  1004. // //some UI methods ej
  1005. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1006. // });
  1007. // if(appDelegate.user!=nil)
  1008. // [params setValue:appDelegate.user forKey:@"user"];
  1009. // // if(appDelegate.contact_id!=nil)
  1010. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1011. // if(appDelegate.password!=nil)
  1012. // [params setValue:appDelegate.password forKey:@"password"];
  1013. //
  1014. // [params setValue:order_code forKey:@"orderCode"];
  1015. // // [params setValue:sourceid forKey:@"sourceid"];
  1016. // // [params setValue:editor forKey:@"editor"];
  1017. //
  1018. // [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  1019. //
  1020. // NSData* json=nil;
  1021. // if(appDelegate.offline_mode)
  1022. // {
  1023. // json=[OLDataProvider offline_editorder:params];
  1024. //
  1025. // }
  1026. // else
  1027. // {
  1028. // if(![self IsNetworkAvailable])
  1029. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1030. //
  1031. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  1032. // }
  1033. // if(json!=nil)
  1034. // {
  1035. // NSError *error=nil;
  1036. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1037. // int result = [[jsobj valueForKey:@"result"] intValue];
  1038. //
  1039. // if (result==2)
  1040. // {
  1041. //
  1042. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1043. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1044. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1045. //
  1046. // [appDelegate update_count_mark];
  1047. //
  1048. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1049. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  1050. // }
  1051. //
  1052. // }
  1053. //
  1054. // return jsobj;
  1055. // }
  1056. // else
  1057. // return nil;
  1058. //}
  1059. +(NSDictionary*)delete_Order:(NSString*) order_id
  1060. {
  1061. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1062. __block AppDelegate *appDelegate = nil;
  1063. dispatch_sync(dispatch_get_main_queue(), ^{
  1064. //some UI methods ej
  1065. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1066. });
  1067. if(appDelegate.user!=nil)
  1068. [params setValue:appDelegate.user forKey:@"user"];
  1069. // if(appDelegate.contact_id!=nil)
  1070. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1071. if(appDelegate.password!=nil)
  1072. [params setValue:appDelegate.password forKey:@"password"];
  1073. [params setValue:order_id forKey:@"orderId"];
  1074. // [params setValue:sourceid forKey:@"sourceid"];
  1075. // [params setValue:editor forKey:@"editor"];
  1076. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  1077. if(appDelegate.offline_mode)
  1078. {
  1079. return [OLDataProvider offline_notimpl];
  1080. }
  1081. if(![self IsNetworkAvailable])
  1082. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1083. NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  1084. if(json!=nil)
  1085. {
  1086. NSError *error=nil;
  1087. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1088. return jsobj;
  1089. }
  1090. else
  1091. return nil;
  1092. }
  1093. +(NSDictionary*)cancel_Order:(NSString*) order_id order_code:(NSString*) order_code
  1094. {
  1095. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1096. __block AppDelegate *appDelegate = nil;
  1097. dispatch_sync(dispatch_get_main_queue(), ^{
  1098. //some UI methods ej
  1099. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1100. });
  1101. if(appDelegate.user!=nil)
  1102. [params setValue:appDelegate.user forKey:@"user"];
  1103. // if(appDelegate.contact_id!=nil)
  1104. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1105. if(appDelegate.password!=nil)
  1106. [params setValue:appDelegate.password forKey:@"password"];
  1107. [params setValue:order_id forKey:@"orderId"];
  1108. [params setValue:order_code forKey:@"orderCode"];
  1109. // [params setValue:sourceid forKey:@"sourceid"];
  1110. // [params setValue:editor forKey:@"editor"];
  1111. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  1112. NSData* json=nil;
  1113. if(appDelegate.offline_mode)
  1114. {
  1115. json=[OLDataProvider offline_cancelorder:params];
  1116. }
  1117. else
  1118. {
  1119. if(![self IsNetworkAvailable])
  1120. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1121. json=[self get_json:URL_CANCEL_ORDER parameters:params];
  1122. }
  1123. if(json!=nil)
  1124. {
  1125. NSError *error=nil;
  1126. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1127. return jsobj;
  1128. }
  1129. else
  1130. return nil;
  1131. }
  1132. +(NSDictionary*)release_Order:(NSString*) order_code withScreen:(NSString *)screenName
  1133. {
  1134. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1135. __block AppDelegate *appDelegate = nil;
  1136. dispatch_sync(dispatch_get_main_queue(), ^{
  1137. //some UI methods ej
  1138. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1139. });
  1140. if(appDelegate.user!=nil)
  1141. [params setValue:appDelegate.user forKey:@"user"];
  1142. // if(appDelegate.contact_id!=nil)
  1143. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1144. if(appDelegate.password!=nil)
  1145. [params setValue:appDelegate.password forKey:@"password"];
  1146. [params setValue:order_code forKey:@"orderCode"];
  1147. // [params setValue:sourceid forKey:@"sourceid"];
  1148. // [params setValue:editor forKey:@"editor"];
  1149. if (screenName) {
  1150. [params setValue:screenName forKey:kScreenName];
  1151. }
  1152. NSData* json=nil;
  1153. if(appDelegate.offline_mode)
  1154. {
  1155. json= [OLDataProvider offline_resetorder:params];
  1156. }
  1157. else
  1158. {
  1159. if(![self IsNetworkAvailable])
  1160. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1161. json=[self get_json:URL_RELEASE_ORDER parameters:params];
  1162. }
  1163. if(json!=nil)
  1164. {
  1165. NSError *error=nil;
  1166. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1167. if([[jsobj valueForKey:@"result"]intValue]==2)
  1168. { [appDelegate SetSo:nil];
  1169. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1170. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1171. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1172. [appDelegate update_count_mark];
  1173. }
  1174. return jsobj;
  1175. }
  1176. else
  1177. return nil;
  1178. }
  1179. +(NSDictionary*)update_OrderCustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info
  1180. {
  1181. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1182. __block AppDelegate *appDelegate = nil;
  1183. dispatch_sync(dispatch_get_main_queue(), ^{
  1184. //some UI methods ej
  1185. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1186. });
  1187. if(appDelegate.user!=nil)
  1188. [info setValue:appDelegate.user forKey:@"user"];
  1189. // if(appDelegate.contact_id!=nil)
  1190. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1191. if(appDelegate.password!=nil)
  1192. [info setValue:appDelegate.password forKey:@"password"];
  1193. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1194. [info setValue:order_code forKey:@"orderCode"];
  1195. // [params setValue:sourceid forKey:@"sourceid"];
  1196. // [params setValue:editor forKey:@"editor"];
  1197. if(appDelegate.offline_mode)
  1198. {
  1199. return [OLDataProvider offline_notimpl];
  1200. }
  1201. if(![self IsNetworkAvailable])
  1202. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1203. NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  1204. if(json!=nil)
  1205. {
  1206. NSError *error=nil;
  1207. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1208. return jsobj;
  1209. }
  1210. else
  1211. return nil;
  1212. }
  1213. //+(NSDictionary*)commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url
  1214. //{
  1215. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1216. // __block AppDelegate *appDelegate = nil;
  1217. //
  1218. // dispatch_sync(dispatch_get_main_queue(), ^{
  1219. // //some UI methods ej
  1220. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1221. // });
  1222. // if(appDelegate.user!=nil)
  1223. // [params setValue:appDelegate.user forKey:@"user"];
  1224. // if(appDelegate.contact_id!=nil)
  1225. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1226. // if(appDelegate.password!=nil)
  1227. // [params setValue:appDelegate.password forKey:@"password"];
  1228. //
  1229. // // if(appDelegate.order_code!=nil)
  1230. // // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1231. //
  1232. // // NSDictionary* customerinfo= appDelegate.customerInfo;
  1233. // //
  1234. // // NSArray* keys=[customerinfo allKeys];
  1235. // // for(int i=0;i<keys.count;i++)
  1236. // // {
  1237. // // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1238. // // }
  1239. // //
  1240. // // [params setValue:sourceid forKey:@"sourceid"];
  1241. // // [params setValue:editor forKey:@"editor"];
  1242. //
  1243. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  1244. //
  1245. // if(appDelegate.offline_mode)
  1246. // {
  1247. // params[@"offline_Command"]=url;
  1248. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  1249. // }
  1250. //
  1251. // if(![self IsNetworkAvailable])
  1252. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1253. //
  1254. // NSData* json=[self get_json:url parameters:params];
  1255. // if(json!=nil)
  1256. // {
  1257. // NSError *error=nil;
  1258. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1259. // if([[jsobj valueForKey:@"result"]intValue]==2)
  1260. // [appDelegate SetSo:nil];
  1261. //
  1262. //
  1263. // return jsobj;
  1264. // }
  1265. // else
  1266. // return nil;
  1267. //}
  1268. +(NSDictionary*)saveandcommit_Order:(NSMutableDictionary*)params
  1269. {
  1270. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1271. __block AppDelegate *appDelegate = nil;
  1272. dispatch_sync(dispatch_get_main_queue(), ^{
  1273. //some UI methods ej
  1274. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1275. });
  1276. if(appDelegate.user!=nil)
  1277. [params setValue:appDelegate.user forKey:@"user"];
  1278. if(appDelegate.contact_id!=nil)
  1279. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1280. if(appDelegate.password!=nil)
  1281. [params setValue:appDelegate.password forKey:@"password"];
  1282. if(appDelegate.order_code!=nil)
  1283. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1284. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1285. //
  1286. // NSArray* keys=[customerinfo allKeys];
  1287. // for(int i=0;i<keys.count;i++)
  1288. // {
  1289. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1290. // }
  1291. //
  1292. // [params setValue:sourceid forKey:@"sourceid"];
  1293. // [params setValue:editor forKey:@"editor"];
  1294. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1295. NSData* json=nil;
  1296. if(appDelegate.offline_mode)
  1297. {
  1298. json=[OLDataProvider offline_submitorder:params];
  1299. }
  1300. else
  1301. {
  1302. if(![self IsNetworkAvailable])
  1303. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1304. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  1305. }
  1306. if(json!=nil)
  1307. {
  1308. NSError *error=nil;
  1309. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1310. if([[jsobj valueForKey:@"result"]intValue]==2)
  1311. [appDelegate SetSo:nil];
  1312. return jsobj;
  1313. }
  1314. else
  1315. return nil;
  1316. }
  1317. +(NSDictionary*)update_Customer:(NSMutableDictionary*)params
  1318. {
  1319. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1320. __block AppDelegate *appDelegate = nil;
  1321. dispatch_sync(dispatch_get_main_queue(), ^{
  1322. //some UI methods ej
  1323. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1324. });
  1325. if(appDelegate.user!=nil)
  1326. [params setValue:appDelegate.user forKey:@"user"];
  1327. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1328. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1329. // else
  1330. if(appDelegate.contact_id!=nil)
  1331. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1332. if(appDelegate.password!=nil)
  1333. [params setValue:appDelegate.password forKey:@"password"];
  1334. // NSDictionary* customerinfo=nil;
  1335. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1336. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1337. // else
  1338. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1339. //
  1340. // appDelegate.customerInfo;
  1341. // NSArray* keys=[customerinfo allKeys];
  1342. // for(int i=0;i<keys.count;i++)
  1343. // {
  1344. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1345. // }
  1346. // [params setValue:sourceid forKey:@"sourceid"];
  1347. // [params setValue:editor forKey:@"editor"];
  1348. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1349. NSData* json=nil;
  1350. if(appDelegate.offline_mode)
  1351. {
  1352. json= [OLDataProvider offline_saveContact:params];
  1353. }
  1354. else
  1355. {
  1356. if(![self IsNetworkAvailable])
  1357. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1358. json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  1359. }
  1360. if(json!=nil)
  1361. {
  1362. NSError *error=nil;
  1363. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1364. return jsobj;
  1365. }
  1366. else
  1367. return nil;
  1368. }
  1369. +(NSDictionary*)save_newCustomer:(NSMutableDictionary*)params
  1370. {
  1371. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1372. __block AppDelegate *appDelegate = nil;
  1373. dispatch_sync(dispatch_get_main_queue(), ^{
  1374. //some UI methods ej
  1375. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1376. });
  1377. if(appDelegate.user!=nil)
  1378. [params setValue:appDelegate.user forKey:@"user"];
  1379. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1380. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1381. // else
  1382. if(appDelegate.contact_id!=nil)
  1383. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1384. if(appDelegate.password!=nil)
  1385. [params setValue:appDelegate.password forKey:@"password"];
  1386. // NSDictionary* customerinfo=nil;
  1387. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1388. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1389. // else
  1390. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1391. //
  1392. // appDelegate.customerInfo;
  1393. // NSArray* keys=[customerinfo allKeys];
  1394. // for(int i=0;i<keys.count;i++)
  1395. // {
  1396. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1397. // }
  1398. // [params setValue:sourceid forKey:@"sourceid"];
  1399. // [params setValue:editor forKey:@"editor"];
  1400. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1401. NSData* json=nil;
  1402. if(appDelegate.offline_mode)
  1403. {
  1404. json= [OLDataProvider offline_saveNewContact:params];
  1405. }
  1406. else
  1407. {
  1408. if(![self IsNetworkAvailable])
  1409. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1410. json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  1411. }
  1412. if(json!=nil)
  1413. {
  1414. NSError *error=nil;
  1415. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1416. return jsobj;
  1417. }
  1418. else
  1419. return nil;
  1420. }
  1421. +(NSDictionary*)save_Order:(NSMutableDictionary*)params
  1422. {
  1423. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1424. __block AppDelegate *appDelegate = nil;
  1425. dispatch_sync(dispatch_get_main_queue(), ^{
  1426. //some UI methods ej
  1427. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1428. });
  1429. if(appDelegate.user!=nil)
  1430. [params setValue:appDelegate.user forKey:@"user"];
  1431. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1432. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1433. // else
  1434. if(appDelegate.contact_id!=nil)
  1435. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1436. if(appDelegate.password!=nil)
  1437. [params setValue:appDelegate.password forKey:@"password"];
  1438. if(appDelegate.order_code!=nil)
  1439. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1440. // NSDictionary* customerinfo=nil;
  1441. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1442. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1443. // else
  1444. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1445. //
  1446. // appDelegate.customerInfo;
  1447. // NSArray* keys=[customerinfo allKeys];
  1448. // for(int i=0;i<keys.count;i++)
  1449. // {
  1450. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1451. // }
  1452. // [params setValue:sourceid forKey:@"sourceid"];
  1453. // [params setValue:editor forKey:@"editor"];
  1454. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1455. NSData* json=nil;
  1456. if(appDelegate.offline_mode)
  1457. {
  1458. json= [OLDataProvider offline_saveorder:params];
  1459. }
  1460. else
  1461. {
  1462. if(![self IsNetworkAvailable])
  1463. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1464. json=[self get_json:URL_SAVE_ORDER parameters:params];
  1465. }
  1466. if(json!=nil)
  1467. {
  1468. NSError *error=nil;
  1469. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1470. NSString *so = [jsobj valueForKey:@"so#"];
  1471. if (so) {
  1472. [appDelegate SetSo:so];
  1473. }
  1474. return jsobj;
  1475. }
  1476. else
  1477. return nil;
  1478. }
  1479. //+(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
  1480. //{
  1481. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1482. // __block AppDelegate *appDelegate = nil;
  1483. //
  1484. // dispatch_sync(dispatch_get_main_queue(), ^{
  1485. // //some UI methods ej
  1486. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1487. // });
  1488. // if(appDelegate.user!=nil)
  1489. // [params setValue:appDelegate.user forKey:@"user"];
  1490. //
  1491. //
  1492. // // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1493. // // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1494. // // else
  1495. //
  1496. // if(appDelegate.contact_id!=nil)
  1497. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1498. // if(appDelegate.password!=nil)
  1499. // [params setValue:appDelegate.password forKey:@"password"];
  1500. //
  1501. // if(appDelegate.order_code!=nil)
  1502. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1503. // // [params setValue:sourceid forKey:@"sourceid"];
  1504. // // [params setValue:editor forKey:@"editor"];
  1505. // DebugLog(@"request editor url:%@",request_url);
  1506. //
  1507. //
  1508. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1509. // {
  1510. // [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1511. // }
  1512. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1513. // {
  1514. // [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1515. // }
  1516. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1517. // {
  1518. // [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  1519. // }
  1520. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1521. // {
  1522. // [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1523. // }
  1524. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1525. // {
  1526. // [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  1527. // }
  1528. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1529. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1530. // }
  1531. //
  1532. // NSData* json = nil;
  1533. // if(appDelegate.offline_mode)
  1534. // {
  1535. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1536. // {
  1537. // json= [OLDataProvider offline_createContact:params];
  1538. // }
  1539. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1540. // {
  1541. // json= [OLDataProvider offline_editContact:params];
  1542. // }
  1543. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1544. // {
  1545. // json= [OLDataProvider offline_contactAdvancedSearch:params];
  1546. // }
  1547. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1548. // {
  1549. // json= [OLDataProvider offline_placeorder:params];
  1550. // }
  1551. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1552. // {
  1553. // json= [OLDataProvider offline_addreditor:params];
  1554. // }
  1555. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1556. // json = [OLDataProvider offline_createTearSheet:params];
  1557. // }
  1558. //
  1559. // else
  1560. // return [OLDataProvider offline_notimpl];
  1561. // }
  1562. // else
  1563. // {
  1564. // if(![self IsNetworkAvailable])
  1565. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1566. //
  1567. // if([request_url isEqualToString:URL_CARTDELIVERY])
  1568. // {
  1569. // NSError *error=nil;
  1570. //
  1571. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1572. // params[@"resultSerial"]=uuid;
  1573. //
  1574. // for(int i=0;i<150;i++)
  1575. // {
  1576. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1577. // // result_params[@"resultSerial"]=uuid;
  1578. // json=[self get_json:request_url parameters:params];
  1579. // if(json!=nil)
  1580. // {
  1581. //
  1582. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1583. // if([jsobj[@"result"] intValue]==2 || [jsobj[@"result"] intValue] == 8)
  1584. // {
  1585. // break;
  1586. // }
  1587. // }
  1588. // sleep(2);
  1589. // }
  1590. // }
  1591. // else
  1592. // json =[self get_json:request_url parameters:params];
  1593. // }
  1594. // if(json!=nil)
  1595. // {
  1596. // NSError *error=nil;
  1597. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1598. // return jsobj;
  1599. // }
  1600. // else
  1601. // return nil;
  1602. //}
  1603. //+(NSDictionary*)request_OrderInfo:(NSString*) orderid
  1604. //{
  1605. // if(![self IsNetworkAvailable])
  1606. // return nil;
  1607. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1608. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1609. // if(appDelegate.user!=nil)
  1610. // [params setValue:appDelegate.user forKey:@"user"];
  1611. // if(appDelegate.password!=nil)
  1612. // [params setValue:appDelegate.password forKey:@"password"];
  1613. // [params setValue:orderid forKey:@"orderid"];
  1614. // NSData* json=[self get_json:URL_ORDER_INFO parameters:params];
  1615. // NSError *error=nil;
  1616. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1617. // return jsobj;
  1618. //}
  1619. +(NSDictionary*)request_OrderList:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged
  1620. {
  1621. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1622. __block AppDelegate *appDelegate = nil;
  1623. dispatch_sync(dispatch_get_main_queue(), ^{
  1624. //some UI methods ej
  1625. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1626. });
  1627. if(appDelegate.user!=nil)
  1628. [params setValue:appDelegate.user forKey:@"user"];
  1629. if(appDelegate.contact_id!=nil)
  1630. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1631. if(appDelegate.password!=nil)
  1632. [params setValue:appDelegate.password forKey:@"password"];
  1633. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1634. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1635. [params setValue:keywords forKey:@"keyWord"];
  1636. [params setValue:customer forKey:@"customer_filter"];
  1637. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  1638. [params setValue:status_code forKey:@"orderStatus"];
  1639. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1640. if (keywords) {
  1641. [params setObject:@"Search" forKey:kAction];
  1642. }
  1643. NSData* json=nil;
  1644. if(appDelegate.offline_mode)
  1645. {
  1646. json= [OLDataProvider offline_orderlist:params];
  1647. }
  1648. else
  1649. {
  1650. if(![self IsNetworkAvailable])
  1651. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1652. json=[self get_json:URL_ORDER_LIST parameters:params];
  1653. }
  1654. if(json==nil)
  1655. return nil;
  1656. NSError *error=nil;
  1657. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1658. return jsobj;
  1659. }
  1660. +(NSDictionary*)request_PDFList:(int ) offset limit:(int)limit keywords:(NSString* ) keywords
  1661. {
  1662. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1663. __block AppDelegate *appDelegate = nil;
  1664. dispatch_sync(dispatch_get_main_queue(), ^{
  1665. //some UI methods ej
  1666. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1667. });
  1668. if(appDelegate.user!=nil)
  1669. [params setValue:appDelegate.user forKey:@"user"];
  1670. if(appDelegate.contact_id!=nil)
  1671. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1672. if(appDelegate.password!=nil)
  1673. [params setValue:appDelegate.password forKey:@"password"];
  1674. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  1675. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  1676. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  1677. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  1678. // [params setValue:filter forKey:@"filter"];
  1679. [params setValue:keywords forKey:@"keyWord"];
  1680. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  1681. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  1682. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  1683. if (keywords) {
  1684. [params setObject:@"Search" forKey:kAction];
  1685. }
  1686. NSData* json = nil;
  1687. if(appDelegate.offline_mode)
  1688. {
  1689. json = [OLDataProvider offline_pdfList:params];
  1690. } else {
  1691. if(![self IsNetworkAvailable])
  1692. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1693. json=[self get_json:URL_DM_LIST parameters:params];
  1694. }
  1695. if(json==nil)
  1696. return nil;
  1697. NSError *error=nil;
  1698. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1699. return jsobj;
  1700. }
  1701. //+(NSString*) create_portfolio:(NSMutableDictionary*)params
  1702. //{
  1703. // __block AppDelegate *appDelegate = nil;
  1704. //
  1705. // dispatch_sync(dispatch_get_main_queue(), ^{
  1706. // //some UI methods ej
  1707. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1708. // });
  1709. // if(appDelegate.offline_mode)
  1710. // {
  1711. //
  1712. //
  1713. // NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  1714. // if(json==nil)
  1715. // return nil;
  1716. // NSError *error=nil;
  1717. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1718. //
  1719. // return jsobj[@"pdf_path"];
  1720. // }
  1721. // else
  1722. // {
  1723. // return nil;
  1724. // }
  1725. //}
  1726. //+(NSDictionary*)direct_save_TearSheet:(NSMutableDictionary*)params//(NSString*) request_url name:(NSString*)name delete:(NSString* )ids note:(NSString* )saveNote modelIds:(NSDictionary *)modelIds
  1727. //{
  1728. // NSMutableDictionary* off_params = [params mutableCopy];;
  1729. //
  1730. // params[@"off_params"]=[RAConvertor dict2string:off_params];;
  1731. // __block AppDelegate *appDelegate = nil;
  1732. //
  1733. // dispatch_sync(dispatch_get_main_queue(), ^{
  1734. // //some UI methods ej
  1735. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1736. // });
  1737. // if(appDelegate.user!=nil)
  1738. // [params setValue:appDelegate.user forKey:@"user"];
  1739. // if(appDelegate.contact_id!=nil)
  1740. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1741. // if(appDelegate.password!=nil)
  1742. // [params setValue:appDelegate.password forKey:@"password"];
  1743. //
  1744. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1745. //
  1746. // /*
  1747. // [params setValue:request_url forKey:@"pdfUrl"];
  1748. // [params setValue:name forKey:@"pdfName"];
  1749. // [params setValue:ids forKey:@"itemIds"];
  1750. // [params setValue:saveNote forKey:@"pdfNote"];
  1751. // [params setValue:[modelIds objectForKey:@"product_ids"] forKey:@"product_ids"];
  1752. // [params setValue:[modelIds objectForKey:@"item_ids"] forKey:@"item_ids"];
  1753. // [params setValue:[modelIds objectForKey:@"remove_item"] forKey:@"remove_item"];
  1754. // */
  1755. // NSData* json= nil;
  1756. //
  1757. // if(appDelegate.offline_mode)
  1758. // {
  1759. // json = [OLDataProvider offline_direct_save_TearSheet:params];
  1760. // }
  1761. // else
  1762. // {
  1763. // if(![self IsNetworkAvailable])
  1764. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1765. //
  1766. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1767. //
  1768. // NSError *error=nil;
  1769. //
  1770. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1771. // params[@"resultSerial"]=uuid;
  1772. //
  1773. // for(int i=0;i<150;i++)
  1774. // {
  1775. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1776. // // result_params[@"resultSerial"]=uuid;
  1777. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1778. // if(json!=nil)
  1779. // {
  1780. //
  1781. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1782. // if([jsobj[@"result"] intValue]==2)
  1783. // {
  1784. // break;
  1785. // }
  1786. // }
  1787. // sleep(5);
  1788. // }
  1789. //
  1790. // }
  1791. // if(json==nil)
  1792. // return nil;
  1793. // NSError *error=nil;
  1794. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1795. // return jsobj;
  1796. //}
  1797. //+(NSDictionary*)request_TearSheet:(NSMutableDictionary*)params//(NSString*) request_url
  1798. //{
  1799. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1800. // __block AppDelegate *appDelegate = nil;
  1801. //
  1802. // dispatch_sync(dispatch_get_main_queue(), ^{
  1803. // //some UI methods ej
  1804. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1805. // });
  1806. // if(appDelegate.user!=nil)
  1807. // [params setValue:appDelegate.user forKey:@"user"];
  1808. // if(appDelegate.contact_id!=nil)
  1809. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1810. // if(appDelegate.password!=nil)
  1811. // [params setValue:appDelegate.password forKey:@"password"];
  1812. //
  1813. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1814. //
  1815. // // [params setValue:request_url forKey:@"pdfUrl"];
  1816. // NSData* json= nil;
  1817. // if(appDelegate.offline_mode)
  1818. // {
  1819. // json= [OLDataProvider offline_request_tearsheet:params];
  1820. // }
  1821. // else
  1822. // {
  1823. // if(![self IsNetworkAvailable])
  1824. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1825. //
  1826. // NSError *error=nil;
  1827. //
  1828. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1829. // params[@"resultSerial"]=uuid;
  1830. //
  1831. // for(int i=0;i<150;i++)
  1832. // {
  1833. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1834. // // result_params[@"resultSerial"]=uuid;
  1835. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1836. // if(json!=nil)
  1837. // {
  1838. //
  1839. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1840. // if([jsobj[@"result"] intValue]==2)
  1841. // {
  1842. // break;
  1843. // }
  1844. // }
  1845. // sleep(5);
  1846. // }
  1847. // }
  1848. // if(json==nil)
  1849. // return nil;
  1850. // NSError *error=nil;
  1851. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1852. // return jsobj;
  1853. //}
  1854. //+(NSDictionary*)save_TearSheet:(NSMutableDictionary *)params//(NSString*) path name:(NSString*)name delete:(NSString* )ids note:(NSString*)note configureParams:(NSString *)configureParams modelIds:(NSDictionary *)modelIds
  1855. //{
  1856. //
  1857. //
  1858. // NSMutableDictionary* off_params = [params mutableCopy];;
  1859. //
  1860. // params[@"off_params"]=[RAConvertor dict2string:off_params];
  1861. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1862. // __block AppDelegate *appDelegate = nil;
  1863. //
  1864. // dispatch_sync(dispatch_get_main_queue(), ^{
  1865. // //some UI methods ej
  1866. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1867. // });
  1868. // if(appDelegate.user!=nil)
  1869. // [params setValue:appDelegate.user forKey:@"user"];
  1870. // if(appDelegate.contact_id!=nil)
  1871. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1872. // if(appDelegate.password!=nil)
  1873. // [params setValue:appDelegate.password forKey:@"password"];
  1874. //
  1875. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1876. //
  1877. // /*
  1878. // [params setValue:path forKey:@"pdfPath"];
  1879. // [params setValue:name forKey:@"pdfName"];
  1880. // [params setValue:note forKey:@"pdfNote"];
  1881. // [params setValue:ids forKey:@"itemIds"];
  1882. // [params setValue:configureParams forKey:@"configureParams"];
  1883. // [params setValue:[modelIds objectForKey:@"product_ids"] forKey:@"product_ids"];
  1884. // [params setValue:[modelIds objectForKey:@"item_ids"] forKey:@"item_ids"];
  1885. // [params setValue:[modelIds objectForKey:@"remove_item"] forKey:@"remove_item"];
  1886. // */
  1887. // NSData* json = nil;
  1888. // if(appDelegate.offline_mode)
  1889. // {
  1890. // json = [OLDataProvider offline_save_TearSheet:params];
  1891. // } else {
  1892. // if(![self IsNetworkAvailable])
  1893. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1894. //
  1895. // json=[self get_json:URL_SAVE_DM parameters:params];
  1896. // }
  1897. // if(json==nil)
  1898. // return nil;
  1899. // NSError *error=nil;
  1900. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1901. // return jsobj;
  1902. //}
  1903. +(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code//device:(NSString*) device
  1904. {
  1905. return nil;
  1906. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1907. __block AppDelegate *appDelegate = nil;
  1908. dispatch_sync(dispatch_get_main_queue(), ^{
  1909. //some UI methods ej
  1910. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1911. });
  1912. if(appDelegate.user!=nil)
  1913. [params setValue:appDelegate.user forKey:@"user"];
  1914. [params setValue:up_params forKey:@"upparam"];
  1915. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  1916. [params setValue:result forKey:@"result"];
  1917. [params setValue:module forKey:@"interfac"];
  1918. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  1919. // [params setValue:module forKey:@"module"];
  1920. // [[UIDevice currentDevice] name];
  1921. // if(appDelegate.offline_mode)
  1922. // {
  1923. // return [OLDataProvider offline_notimpl];
  1924. // }
  1925. if(![self IsNetworkAvailable])
  1926. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1927. NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  1928. if(json==nil)
  1929. return nil;
  1930. NSError *error=nil;
  1931. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1932. return jsobj;
  1933. }
  1934. //+(NSDictionary*)request_ContactList:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams
  1935. //{
  1936. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1937. //
  1938. // if(upparams!=nil)
  1939. // params = [upparams mutableCopy];
  1940. // __block AppDelegate *appDelegate = nil;
  1941. //
  1942. // dispatch_sync(dispatch_get_main_queue(), ^{
  1943. // //some UI methods ej
  1944. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1945. // });
  1946. // if(appDelegate.user!=nil)
  1947. // [params setValue:appDelegate.user forKey:@"user"];
  1948. //
  1949. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1950. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1951. // else
  1952. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1953. //
  1954. // if(appDelegate.password!=nil)
  1955. // [params setValue:appDelegate.password forKey:@"password"];
  1956. //
  1957. // [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1958. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1959. // [params setValue:contact_type forKey:@"contactType"];
  1960. // [params setValue:keywords forKey:@"keyword"];
  1961. //
  1962. // [params setObject:ScreenCodeAccount forKey:kScreenName];
  1963. // if (keywords) {
  1964. // [params setObject:@"Search" forKey:kAction];
  1965. // }
  1966. // if (upparams) {
  1967. // [params setObject:@"Advance Search" forKey:kAction];
  1968. // }
  1969. //
  1970. // NSString* url=nil;
  1971. // if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  1972. // url=URL_SHIPTO_LIST;
  1973. // else
  1974. // url=URL_CONTACT_LIST;
  1975. //
  1976. // if(appDelegate.offline_mode)
  1977. // return [OLDataProvider offline_contactlist:params];
  1978. //
  1979. // if(![self IsNetworkAvailable])
  1980. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1981. //
  1982. // NSData* json=[self get_json:url parameters:params];
  1983. // if(json==nil)
  1984. // return nil;
  1985. // NSError *error=nil;
  1986. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1987. // return jsobj;
  1988. //}
  1989. //+(NSDictionary*)request_OrderDetail:(NSMutableDictionary *) params
  1990. //{
  1991. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1992. // if (params == nil) {
  1993. // params = [[NSMutableDictionary alloc] init];
  1994. // }
  1995. // __block AppDelegate *appDelegate = nil;
  1996. //
  1997. // dispatch_sync(dispatch_get_main_queue(), ^{
  1998. // //some UI methods ej
  1999. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2000. // });
  2001. // if(appDelegate.user!=nil)
  2002. // [params setValue:appDelegate.user forKey:@"user"];
  2003. // if(appDelegate.contact_id!=nil)
  2004. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2005. // if(appDelegate.password!=nil)
  2006. // [params setValue:appDelegate.password forKey:@"password"];
  2007. //
  2008. //
  2009. // // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  2010. //
  2011. // [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  2012. //
  2013. // NSData* json=nil;
  2014. // if(appDelegate.offline_mode)
  2015. // {
  2016. // json= [OLDataProvider offline_orderdetail:params];
  2017. // }
  2018. // else
  2019. // {
  2020. // if(![self IsNetworkAvailable])
  2021. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2022. //
  2023. // NSError *error=nil;
  2024. //
  2025. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2026. // params[@"resultSerial"]=uuid;
  2027. //
  2028. // for(int i=0;i<150;i++)
  2029. // {
  2030. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2031. // // result_params[@"resultSerial"]=uuid;
  2032. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  2033. // if(json!=nil)
  2034. // {
  2035. //
  2036. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2037. // int resultCode = [jsobj[@"result"] intValue];
  2038. // if(resultCode==2 || resultCode == 8)
  2039. // {
  2040. // break;
  2041. // }
  2042. // }
  2043. // sleep(2);
  2044. // }
  2045. //
  2046. //
  2047. // }
  2048. // if(json==nil)
  2049. // return nil;
  2050. // NSError *error=nil;
  2051. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2052. // return jsobj;
  2053. //}
  2054. //+(NSDictionary*) add_toCart:(NSString* ) item_id count:(int) count name:(NSString *)name
  2055. //{
  2056. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2057. // __block AppDelegate *appDelegate = nil;
  2058. //
  2059. // dispatch_sync(dispatch_get_main_queue(), ^{
  2060. // //some UI methods ej
  2061. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2062. // });
  2063. // if(appDelegate.user!=nil)
  2064. // [params setValue:appDelegate.user forKey:@"user"];
  2065. // if(appDelegate.contact_id!=nil)
  2066. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2067. // if(appDelegate.password!=nil)
  2068. // [params setValue:appDelegate.password forKey:@"password"];
  2069. //
  2070. // if(appDelegate.order_code!=nil)
  2071. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2072. // [params setValue:item_id forKey:@"product_id"];
  2073. // [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  2074. //
  2075. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  2076. // [params setObject:@"Add To Cart" forKey:kAction];
  2077. // if (name) {
  2078. // NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  2079. // [params setObject:extra forKey:kExtra];
  2080. // }
  2081. //
  2082. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2083. //
  2084. // NSArray* keys=[customerinfo allKeys];
  2085. // for(int i=0;i<keys.count;i++)
  2086. // {
  2087. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2088. // }
  2089. //
  2090. // NSData* json=nil;
  2091. // if(appDelegate.offline_mode)
  2092. // {
  2093. // json=[OLDataProvider offline_add2cart:params];
  2094. // }
  2095. // else
  2096. // {
  2097. // if(![self IsNetworkAvailable])
  2098. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2099. //
  2100. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  2101. // }
  2102. // if(json==nil)
  2103. // return nil;
  2104. // NSError *error=nil;
  2105. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2106. //
  2107. //
  2108. //
  2109. // int result = [[jsobj valueForKey:@"result"] intValue];
  2110. //
  2111. // if (result==2)
  2112. // {
  2113. //
  2114. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2115. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2116. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2117. //
  2118. // [appDelegate update_count_mark];
  2119. // }
  2120. //
  2121. // return jsobj;
  2122. //}
  2123. //+(NSDictionary*) add_toCart_byName:(NSString* ) model_name withScreen:(NSString *)screenName
  2124. //{
  2125. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2126. // __block AppDelegate *appDelegate = nil;
  2127. //
  2128. // dispatch_sync(dispatch_get_main_queue(), ^{
  2129. // //some UI methods ej
  2130. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2131. // });
  2132. // if(appDelegate.user!=nil)
  2133. // [params setValue:appDelegate.user forKey:@"user"];
  2134. // if(appDelegate.contact_id!=nil)
  2135. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2136. // if(appDelegate.password!=nil)
  2137. // [params setValue:appDelegate.password forKey:@"password"];
  2138. //
  2139. // if(appDelegate.order_code!=nil)
  2140. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2141. // [params setValue:model_name forKey:@"product_name"];
  2142. // [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  2143. //
  2144. // [params setObject:screenName forKey:kScreenName];
  2145. // [params setObject:@"Add To Cart" forKey:kAction];
  2146. // if (!model_name) {
  2147. // model_name = @"";
  2148. // }
  2149. // [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  2150. //
  2151. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2152. //
  2153. // NSArray* keys=[customerinfo allKeys];
  2154. // for(int i=0;i<keys.count;i++)
  2155. // {
  2156. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2157. // }
  2158. // NSData* json=nil;
  2159. // if(appDelegate.offline_mode)
  2160. // {
  2161. // json= [OLDataProvider offline_add2cartbyname:params];
  2162. // }
  2163. // else
  2164. // {
  2165. // if(![self IsNetworkAvailable])
  2166. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2167. //
  2168. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  2169. // }
  2170. // if(json==nil)
  2171. // return nil;
  2172. // NSError *error=nil;
  2173. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2174. //
  2175. //
  2176. //
  2177. // int result = [[jsobj valueForKey:@"result"] intValue];
  2178. //
  2179. // if (result==2||result==8)
  2180. // {
  2181. //
  2182. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2183. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2184. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2185. //
  2186. // [appDelegate update_count_mark];
  2187. // }
  2188. //
  2189. // return jsobj;
  2190. //}
  2191. //+(NSDictionary*) new_Customer
  2192. //{
  2193. // if(![self IsNetworkAvailable])
  2194. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2195. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2196. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2197. // if(appDelegate.user!=nil)
  2198. // [params setValue:appDelegate.user forKey:@"user"];
  2199. //// if(appDelegate.contact_id!=nil)
  2200. //// [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2201. // if(appDelegate.password!=nil)
  2202. // [params setValue:appDelegate.password forKey:@"password"];
  2203. //
  2204. //// if(appDelegate.order_code!=nil)
  2205. //// [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2206. //
  2207. //
  2208. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2209. //
  2210. // NSArray* keys=[customerinfo allKeys];
  2211. // for(int i=0;i<keys.count;i++)
  2212. // {
  2213. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2214. // }
  2215. //
  2216. // NSData* json=[self get_json:URL_CUSTOMER_EDIT parameters:params];
  2217. // if(json==nil)
  2218. // return nil;
  2219. // NSError *error=nil;
  2220. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2221. // return jsobj;
  2222. //}
  2223. //+(NSDictionary*) new_Order
  2224. //{
  2225. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2226. // __block AppDelegate *appDelegate = nil;
  2227. //
  2228. // dispatch_sync(dispatch_get_main_queue(), ^{
  2229. // //some UI methods ej
  2230. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2231. // });
  2232. // if(appDelegate.user!=nil)
  2233. // [params setValue:appDelegate.user forKey:@"user"];
  2234. // if(appDelegate.contact_id!=nil)
  2235. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2236. // if(appDelegate.password!=nil)
  2237. // [params setValue:appDelegate.password forKey:@"password"];
  2238. //
  2239. // if(appDelegate.order_code!=nil)
  2240. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2241. //
  2242. //
  2243. // [params setObject:ScreenCodeOrderList forKey:kScreenName];
  2244. //
  2245. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2246. //
  2247. // NSArray* keys=[customerinfo allKeys];
  2248. // for(int i=0;i<keys.count;i++)
  2249. // {
  2250. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2251. // }
  2252. //
  2253. // NSData* json = nil;
  2254. // if(appDelegate.offline_mode)
  2255. // {
  2256. // json= [OLDataProvider offline_createorder:params];
  2257. // }
  2258. // else
  2259. // {
  2260. // if(![self IsNetworkAvailable])
  2261. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2262. //
  2263. // json=[self get_json:URL_NEW_ORDER parameters:params];
  2264. // }
  2265. // if(json==nil)
  2266. // return nil;
  2267. // NSError *error=nil;
  2268. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2269. // int result = [[jsobj valueForKey:@"result"] intValue];
  2270. //
  2271. // if (result==2)
  2272. // {
  2273. //
  2274. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2275. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2276. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2277. //
  2278. // [appDelegate update_count_mark];
  2279. // }
  2280. //
  2281. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  2282. //
  2283. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  2284. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  2285. // }
  2286. //
  2287. // return jsobj;
  2288. //}
  2289. +(NSDictionary*) add_toPortfolio:(NSString* ) item_id withScreen:(NSString *)screenName
  2290. {
  2291. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2292. __block AppDelegate *appDelegate = nil;
  2293. dispatch_sync(dispatch_get_main_queue(), ^{
  2294. //some UI methods ej
  2295. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2296. });
  2297. if(appDelegate.user!=nil)
  2298. [params setValue:appDelegate.user forKey:@"user"];
  2299. if(appDelegate.contact_id!=nil)
  2300. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2301. if(appDelegate.password!=nil)
  2302. [params setValue:appDelegate.password forKey:@"password"];
  2303. [params setValue:item_id forKey:@"product_id"];
  2304. [params setObject:screenName forKey:kScreenName];
  2305. NSData* json = nil;
  2306. if(appDelegate.offline_mode)
  2307. {
  2308. json = [OLDataProvider offline_add2Portfolio:params];
  2309. } else {
  2310. if(![self IsNetworkAvailable])
  2311. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2312. json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  2313. }
  2314. if(json==nil)
  2315. return nil;
  2316. NSError *error=nil;
  2317. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2318. int result = [[jsobj valueForKey:@"result"] intValue];
  2319. if (result==2)
  2320. {
  2321. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2322. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2323. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2324. [appDelegate update_count_mark];
  2325. }
  2326. return jsobj;
  2327. }
  2328. //+(NSDictionary*) add_toWatchList:(NSString* ) item_id withScreen:(NSString *)screenName
  2329. //{
  2330. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2331. // __block AppDelegate *appDelegate = nil;
  2332. //
  2333. // dispatch_sync(dispatch_get_main_queue(), ^{
  2334. // //some UI methods ej
  2335. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2336. // });
  2337. // if(appDelegate.user!=nil)
  2338. // [params setValue:appDelegate.user forKey:@"user"];
  2339. // if(appDelegate.contact_id!=nil)
  2340. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2341. // if(appDelegate.password!=nil)
  2342. // [params setValue:appDelegate.password forKey:@"password"];
  2343. //
  2344. //
  2345. // [params setValue:item_id forKey:@"product_id"];
  2346. //
  2347. // [params setObject:screenName forKey:kScreenName];
  2348. //
  2349. // if(appDelegate.offline_mode)
  2350. // {
  2351. // return [OLDataProvider offline_add2wishlist:params];
  2352. // }
  2353. // if(![self IsNetworkAvailable])
  2354. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2355. //
  2356. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  2357. // if(json==nil)
  2358. // return nil;
  2359. // NSError *error=nil;
  2360. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2361. // int result = [[jsobj valueForKey:@"result"] intValue];
  2362. //
  2363. // if (result==2)
  2364. // {
  2365. //
  2366. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2367. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2368. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2369. //
  2370. // [appDelegate update_count_mark];
  2371. // }
  2372. // return jsobj;
  2373. //}
  2374. +(NSDictionary*) cart_setPrice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes
  2375. {
  2376. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2377. __block AppDelegate *appDelegate = nil;
  2378. dispatch_sync(dispatch_get_main_queue(), ^{
  2379. //some UI methods ej
  2380. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2381. });
  2382. if(appDelegate.user!=nil)
  2383. [params setValue:appDelegate.user forKey:@"user"];
  2384. if(appDelegate.contact_id!=nil)
  2385. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2386. if(appDelegate.password!=nil)
  2387. [params setValue:appDelegate.password forKey:@"password"];
  2388. [params setValue:cart_id forKey:@"cartitem_id"];
  2389. [params setValue:notes forKey:@"item_note"];
  2390. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  2391. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  2392. [params setObject:ScreenCodeCart forKey:kScreenName];
  2393. NSData* json= nil;
  2394. if(appDelegate.offline_mode)
  2395. {
  2396. json=[OLDataProvider offline_cartsetprice:params];
  2397. }
  2398. else
  2399. {
  2400. if(![self IsNetworkAvailable])
  2401. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2402. json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2403. }
  2404. if(json==nil)
  2405. return nil;
  2406. NSError *error=nil;
  2407. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2408. return jsobj;
  2409. }
  2410. //+(NSDictionary*) portfolio_setQTY:(NSString*) watchlist_id QTY:(int)qty
  2411. //{
  2412. // if(![self IsNetworkAvailable])
  2413. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2414. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2415. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2416. // if(appDelegate.user!=nil)
  2417. // [params setValue:appDelegate.user forKey:@"user"];
  2418. // if(appDelegate.contact_id!=nil)
  2419. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2420. // if(appDelegate.password!=nil)
  2421. // [params setValue:appDelegate.password forKey:@"password"];
  2422. //
  2423. // [params setValue:watchlist_id forKey:@"item_id"];
  2424. //
  2425. // [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  2426. //
  2427. //
  2428. //
  2429. // NSData* json=[self get_json:URL_DM_SET_QTY parameters:params];
  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_setPrice:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes
  2437. {
  2438. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2439. __block AppDelegate *appDelegate = nil;
  2440. dispatch_sync(dispatch_get_main_queue(), ^{
  2441. //some UI methods ej
  2442. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2443. });
  2444. if(appDelegate.user!=nil)
  2445. [params setValue:appDelegate.user forKey:@"user"];
  2446. if(appDelegate.contact_id!=nil)
  2447. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2448. if(appDelegate.password!=nil)
  2449. [params setValue:appDelegate.password forKey:@"password"];
  2450. [params setValue:watchlist_id forKey:@"item_id"];
  2451. // if(notes.length>0)
  2452. // [params setValue:notes forKey:@"notes"];
  2453. if(notes)
  2454. [params setValue:notes forKey:@"notes"];
  2455. if(price != -MAXFLOAT)
  2456. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  2457. if (discount != -MAXFLOAT)
  2458. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  2459. if(qty_p != -MAXFLOAT)
  2460. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  2461. if(qty != -INT32_MAX)
  2462. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  2463. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2464. NSData* json = nil;
  2465. if(appDelegate.offline_mode)
  2466. {
  2467. json = [OLDataProvider offline_editPortfolio:params];
  2468. } else {
  2469. if(![self IsNetworkAvailable])
  2470. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2471. json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  2472. }
  2473. if(json==nil)
  2474. return nil;
  2475. NSError *error=nil;
  2476. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2477. return jsobj;
  2478. }
  2479. +(NSDictionary*) cart_setGeneralNote:(NSString*) order_code notes:(NSString*) notes
  2480. {
  2481. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2482. __block AppDelegate *appDelegate = nil;
  2483. dispatch_sync(dispatch_get_main_queue(), ^{
  2484. //some UI methods ej
  2485. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2486. });
  2487. if(appDelegate.user!=nil)
  2488. [params setValue:appDelegate.user forKey:@"user"];
  2489. if(appDelegate.contact_id!=nil)
  2490. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2491. if(appDelegate.password!=nil)
  2492. [params setValue:appDelegate.password forKey:@"password"];
  2493. [params setValue:order_code forKey:@"orderCode"];
  2494. [params setObject:ScreenCodeCart forKey:kScreenName];
  2495. if(notes.length==0)
  2496. notes=@"";
  2497. [params setValue:notes forKey:@"comments"];
  2498. NSData* json=nil;
  2499. if(appDelegate.offline_mode)
  2500. {
  2501. json= [OLDataProvider offline_updategnotes:params];
  2502. }
  2503. else
  2504. {
  2505. if(![self IsNetworkAvailable])
  2506. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2507. json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  2508. }
  2509. if(json==nil)
  2510. return nil;
  2511. NSError *error=nil;
  2512. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2513. return jsobj;
  2514. }
  2515. +(NSDictionary*) cart_setItemNote:(NSString*) cart_id notes:(NSString*) notes
  2516. {
  2517. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2518. __block AppDelegate *appDelegate = nil;
  2519. dispatch_sync(dispatch_get_main_queue(), ^{
  2520. //some UI methods ej
  2521. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2522. });
  2523. if(appDelegate.user!=nil)
  2524. [params setValue:appDelegate.user forKey:@"user"];
  2525. if(appDelegate.contact_id!=nil)
  2526. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2527. if(appDelegate.password!=nil)
  2528. [params setValue:appDelegate.password forKey:@"password"];
  2529. [params setValue:cart_id forKey:@"cartitem_id"];
  2530. [params setObject:ScreenCodeCart forKey:kScreenName];
  2531. if(notes.length==0)
  2532. notes=@"";
  2533. [params setValue:notes forKey:@"notes"];
  2534. NSData* json=nil;
  2535. if(appDelegate.offline_mode)
  2536. {
  2537. json= [OLDataProvider offline_cartsetlnotes:params];
  2538. }
  2539. else
  2540. {
  2541. if(![self IsNetworkAvailable])
  2542. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2543. json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  2544. }
  2545. if(json==nil)
  2546. return nil;
  2547. NSError *error=nil;
  2548. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2549. return jsobj;
  2550. }
  2551. +(NSDictionary*) cart_setFree:(NSString*) cart_id isfree:(bool) isfree
  2552. {
  2553. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2554. __block AppDelegate *appDelegate = nil;
  2555. dispatch_sync(dispatch_get_main_queue(), ^{
  2556. //some UI methods ej
  2557. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2558. });
  2559. if(appDelegate.user!=nil)
  2560. [params setValue:appDelegate.user forKey:@"user"];
  2561. if(appDelegate.contact_id!=nil)
  2562. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2563. if(appDelegate.password!=nil)
  2564. [params setValue:appDelegate.password forKey:@"password"];
  2565. [params setValue:cart_id forKey:@"cartitem_id"];
  2566. [params setObject:ScreenCodeCart forKey:kScreenName];
  2567. NSString* free=nil;
  2568. if(isfree)
  2569. free=@"true";
  2570. else
  2571. free=@"false";
  2572. [params setValue:free forKey:@"free_giveaway"];
  2573. if(appDelegate.offline_mode)
  2574. {
  2575. return [OLDataProvider offline_notimpl];
  2576. }
  2577. if(![self IsNetworkAvailable])
  2578. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2579. NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2580. if(json==nil)
  2581. return nil;
  2582. NSError *error=nil;
  2583. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2584. return jsobj;
  2585. }
  2586. //+(NSDictionary*) cart_setQTY:(NSString*) cart_id value:(int) value
  2587. //{
  2588. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2589. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2590. // if(appDelegate.user!=nil)
  2591. // [params setValue:appDelegate.user forKey:@"user"];
  2592. // if(appDelegate.contact_id!=nil)
  2593. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2594. // if(appDelegate.password!=nil)
  2595. // [params setValue:appDelegate.password forKey:@"password"];
  2596. //
  2597. // [params setValue:cart_id forKey:@"cartitem_id"];
  2598. //
  2599. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2600. //
  2601. // [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  2602. //
  2603. // NSData* json=nil;
  2604. // if(appDelegate.offline_mode)
  2605. // {
  2606. // json= [OLDataProvider offline_cartsetqty:params];
  2607. // }
  2608. // else
  2609. // {
  2610. // if(![self IsNetworkAvailable])
  2611. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2612. //
  2613. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2614. // }
  2615. // if(json==nil)
  2616. // return nil;
  2617. // NSError *error=nil;
  2618. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2619. // return jsobj;
  2620. //
  2621. //}
  2622. +(NSDictionary*) cart_incresement:(NSString*) cart_id increse:(bool) increse
  2623. {
  2624. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2625. __block AppDelegate *appDelegate = nil;
  2626. dispatch_sync(dispatch_get_main_queue(), ^{
  2627. //some UI methods ej
  2628. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2629. });
  2630. if(appDelegate.user!=nil)
  2631. [params setValue:appDelegate.user forKey:@"user"];
  2632. if(appDelegate.contact_id!=nil)
  2633. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2634. if(appDelegate.password!=nil)
  2635. [params setValue:appDelegate.password forKey:@"password"];
  2636. [params setValue:cart_id forKey:@"cartitem_id"];
  2637. if(increse)
  2638. [params setValue:@"1" forKey:@"incrementType"];
  2639. else
  2640. [params setValue:@"0" forKey:@"incrementType"];
  2641. if(appDelegate.offline_mode)
  2642. {
  2643. return [OLDataProvider offline_notimpl];
  2644. }
  2645. if(![self IsNetworkAvailable])
  2646. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2647. NSData* json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2648. if(json==nil)
  2649. return nil;
  2650. NSError *error=nil;
  2651. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2652. return jsobj;
  2653. }
  2654. +(NSDictionary*) finish_download_Offline:(NSString* )vid
  2655. {
  2656. if(![self IsNetworkAvailable])
  2657. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2658. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2659. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  2660. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2661. // if(appDelegate.user!=nil)
  2662. // [params setValue:appDelegate.user forKey:@"user"];
  2663. // // if(appDelegate.contact_id!=nil)
  2664. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2665. // if(appDelegate.password!=nil)
  2666. // [params setValue:appDelegate.password forKey:@"password"];
  2667. [params setValue:vid forKey:@"downSerial"];
  2668. NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  2669. if(json==nil)
  2670. return nil;
  2671. NSError *error=nil;
  2672. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2673. // int result = [[jsobj valueForKey:@"result"] intValue];
  2674. //
  2675. // if (result==2)
  2676. // {
  2677. //
  2678. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2679. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2680. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2681. ////
  2682. //// [appDelegate update_count_mark];
  2683. // }
  2684. return jsobj;
  2685. }
  2686. +(NSDictionary*) download_Offline:(NSString* )vid
  2687. {
  2688. if(![self IsNetworkAvailable])
  2689. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2690. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2691. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2692. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2693. // if(appDelegate.user!=nil)
  2694. // [params setValue:appDelegate.user forKey:@"user"];
  2695. // // if(appDelegate.contact_id!=nil)
  2696. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2697. // if(appDelegate.password!=nil)
  2698. // [params setValue:appDelegate.password forKey:@"password"];
  2699. [params setValue:vid forKey:@"downSerial"];
  2700. NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  2701. if(json==nil)
  2702. return nil;
  2703. NSError *error=nil;
  2704. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2705. // int result = [[jsobj valueForKey:@"result"] intValue];
  2706. //
  2707. // if (result==2)
  2708. // {
  2709. //
  2710. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2711. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2712. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2713. ////
  2714. //// [appDelegate update_count_mark];
  2715. // }
  2716. return jsobj;
  2717. }
  2718. +(NSDictionary*) check_Offline:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid
  2719. {
  2720. if(![self IsNetworkAvailable])
  2721. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2722. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2723. __block AppDelegate *appDelegate = nil;
  2724. dispatch_sync(dispatch_get_main_queue(), ^{
  2725. //some UI methods ej
  2726. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2727. });
  2728. if(appDelegate.user!=nil)
  2729. [params setValue:appDelegate.user forKey:@"user"];
  2730. // if(appDelegate.contact_id!=nil)
  2731. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2732. if(appDelegate.password!=nil)
  2733. [params setValue:appDelegate.password forKey:@"password"];
  2734. [params setValue:ver forKey:@"ver"];
  2735. [params setValue:vid forKey:@"vid"];
  2736. if(buseinternaladdress)
  2737. [params setValue:@"true" forKey:@"internal_address"];
  2738. else
  2739. [params setValue:@"false" forKey:@"internal_address"];
  2740. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2741. NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  2742. if(json==nil)
  2743. return nil;
  2744. NSError *error=nil;
  2745. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2746. // int result = [[jsobj valueForKey:@"result"] intValue];
  2747. //
  2748. // if (result==2)
  2749. // {
  2750. //
  2751. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2752. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2753. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2754. ////
  2755. //// [appDelegate update_count_mark];
  2756. // }
  2757. return jsobj;
  2758. }
  2759. //+(NSDictionary*)request_Cart:(int)sort
  2760. //{
  2761. //
  2762. // DebugLog(@"iSalesNetwork::request_Cart");
  2763. //
  2764. //
  2765. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2766. // __block AppDelegate *appDelegate = nil;
  2767. //
  2768. // dispatch_sync(dispatch_get_main_queue(), ^{
  2769. // //some UI methods ej
  2770. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2771. // });
  2772. // if(appDelegate.user!=nil)
  2773. // [params setValue:appDelegate.user forKey:@"user"];
  2774. // // if(appDelegate.contact_id!=nil)
  2775. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2776. // if(appDelegate.password!=nil)
  2777. // [params setValue:appDelegate.password forKey:@"password"];
  2778. //
  2779. // if(appDelegate.order_code!=nil)
  2780. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2781. //
  2782. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2783. //
  2784. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2785. //
  2786. // NSData* json=nil;
  2787. // if(appDelegate.offline_mode)
  2788. // {
  2789. // json= [OLDataProvider offline_requestcart:params];
  2790. // }
  2791. // else
  2792. // {
  2793. // if(![self IsNetworkAvailable])
  2794. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2795. //
  2796. // NSError *error=nil;
  2797. //
  2798. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2799. // params[@"resultSerial"]=uuid;
  2800. //
  2801. // for(int i=0;i<150;i++)
  2802. // {
  2803. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2804. // // result_params[@"resultSerial"]=uuid;
  2805. // json=[self get_json:URL_CART parameters:params];
  2806. // if(json!=nil)
  2807. // {
  2808. //
  2809. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2810. // if([jsobj[@"result"] intValue]==2)
  2811. // {
  2812. // break;
  2813. // }
  2814. // }
  2815. // sleep(2);
  2816. // }
  2817. //
  2818. // }
  2819. // if(json==nil)
  2820. // return nil;
  2821. // NSError *error=nil;
  2822. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2823. // int result = [[jsobj valueForKey:@"result"] intValue];
  2824. //
  2825. // if (result==2)
  2826. // {
  2827. //
  2828. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2829. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2830. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2831. //
  2832. // [appDelegate update_count_mark];
  2833. // }
  2834. // return jsobj;
  2835. //}
  2836. //+(NSDictionary*)request_Portfolio:(int)sort
  2837. //{
  2838. //
  2839. //
  2840. //
  2841. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2842. // __block AppDelegate *appDelegate = nil;
  2843. //
  2844. // dispatch_sync(dispatch_get_main_queue(), ^{
  2845. // //some UI methods ej
  2846. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2847. // });
  2848. // if(appDelegate.user!=nil)
  2849. // [params setValue:appDelegate.user forKey:@"user"];
  2850. // if(appDelegate.contact_id!=nil)
  2851. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2852. // if(appDelegate.password!=nil)
  2853. // [params setValue:appDelegate.password forKey:@"password"];
  2854. //
  2855. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2856. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2857. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2858. //
  2859. // [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2860. //
  2861. // NSData* json = nil;
  2862. // if(appDelegate.offline_mode)
  2863. // {
  2864. // json = [OLDataProvider offline_portfolioList:params];
  2865. // } else {
  2866. // if(![self IsNetworkAvailable])
  2867. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2868. //
  2869. // json = [self get_json:URL_PORTFOLIO parameters:params];
  2870. // }
  2871. //
  2872. //
  2873. // if(json==nil)
  2874. // return nil;
  2875. // NSError *error=nil;
  2876. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2877. // int result = [[jsobj valueForKey:@"result"] intValue];
  2878. //
  2879. // if (result==2)
  2880. // {
  2881. //
  2882. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2883. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2884. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  2885. //
  2886. // [appDelegate update_count_mark];
  2887. // }
  2888. // return jsobj;
  2889. //}
  2890. //+(NSDictionary*)request_WatchList:(int)sort
  2891. //{
  2892. //
  2893. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2894. // __block AppDelegate *appDelegate = nil;
  2895. //
  2896. // dispatch_sync(dispatch_get_main_queue(), ^{
  2897. // //some UI methods ej
  2898. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2899. // });
  2900. // if(appDelegate.user!=nil)
  2901. // [params setValue:appDelegate.user forKey:@"user"];
  2902. // if(appDelegate.contact_id!=nil)
  2903. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2904. // if(appDelegate.password!=nil)
  2905. // [params setValue:appDelegate.password forKey:@"password"];
  2906. //
  2907. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2908. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2909. //
  2910. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2911. //
  2912. // [params setObject:ScreenCodeWishList forKey:kScreenName];
  2913. //
  2914. // if(appDelegate.offline_mode)
  2915. // {
  2916. // return [OLDataProvider offline_wishlist:params];
  2917. // }
  2918. // if(![self IsNetworkAvailable])
  2919. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2920. //
  2921. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  2922. // if(json==nil)
  2923. // return nil;
  2924. // NSError *error=nil;
  2925. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2926. // int result = [[jsobj valueForKey:@"result"] intValue];
  2927. //
  2928. // if (result==2)
  2929. // {
  2930. //
  2931. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2932. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2933. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2934. //
  2935. // [appDelegate update_count_mark];
  2936. // }
  2937. // return jsobj;
  2938. //}
  2939. //+(NSDictionary*)request_ItemDetail: (NSString* ) item_id model_name:(NSString*) model_name category_id:(NSString*) category_id use_name :(bool) use_name groupName:(NSString *)groupName
  2940. //{
  2941. //
  2942. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2943. // __block AppDelegate *appDelegate = nil;
  2944. //
  2945. // dispatch_sync(dispatch_get_main_queue(), ^{
  2946. // //some UI methods ej
  2947. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2948. // });
  2949. // if(appDelegate.user!=nil)
  2950. // [params setValue:appDelegate.user forKey:@"user"];
  2951. // if(appDelegate.contact_id!=nil)
  2952. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2953. // if(appDelegate.password!=nil)
  2954. // [params setValue:appDelegate.password forKey:@"password"];
  2955. // if(appDelegate.order_code!=nil)
  2956. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2957. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2958. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2959. // if(use_name)
  2960. // [params setValue:model_name forKey:@"product_name"];
  2961. // else
  2962. // [params setValue:item_id forKey:@"product_id"];
  2963. //
  2964. //
  2965. // [params setValue:category_id forKey:@"category"];
  2966. //
  2967. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  2968. // [params setObject:@"Open A Model" forKey:kAction];
  2969. // if (model_name) {
  2970. // NSDictionary *extra = @{@"ModelName" : model_name};
  2971. // [params setObject:extra forKey:kExtra];
  2972. // }
  2973. //
  2974. // if (groupName.length > 0) {
  2975. // [params setObject:groupName forKey:@"groupName"];
  2976. // }
  2977. //
  2978. // if(appDelegate.offline_mode)
  2979. // return [OLDataProvider offline_model:params];
  2980. //
  2981. // if(![self IsNetworkAvailable])
  2982. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2983. //
  2984. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  2985. // if(json==nil)
  2986. // return nil;
  2987. // NSError *error=nil;
  2988. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2989. // return jsobj;
  2990. //}
  2991. //+(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
  2992. //{
  2993. // if(![self IsNetworkAvailable])
  2994. // return nil;
  2995. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2996. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2997. // if(appDelegate.user!=nil)
  2998. // [params setValue:appDelegate.user forKey:@"user"];
  2999. // if(appDelegate.contact_id!=nil)
  3000. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3001. // if(appDelegate.password!=nil)
  3002. // [params setValue:appDelegate.password forKey:@"password"];
  3003. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3004. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3005. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3006. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3007. // [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  3008. // [params setValue:filter forKey:@"filter"];
  3009. // [params setValue:keyword forKey:@"keyword"];
  3010. //
  3011. //
  3012. // NSData* json=[self get_json:URL_CATEGORY_LOADMORE parameters:params];
  3013. // if(json==nil)
  3014. // return nil;
  3015. // NSError *error=nil;
  3016. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3017. // return jsobj;
  3018. //
  3019. //}
  3020. //+(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
  3021. //
  3022. //{
  3023. //
  3024. //
  3025. // __block AppDelegate *appDelegate = nil;
  3026. //
  3027. // dispatch_sync(dispatch_get_main_queue(), ^{
  3028. // //some UI methods ej
  3029. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3030. // });
  3031. //
  3032. //
  3033. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3034. //
  3035. // if(appDelegate.user!=nil)
  3036. // [params setValue:appDelegate.user forKey:@"user"];
  3037. // if(appDelegate.contact_id!=nil)
  3038. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3039. // if(appDelegate.password!=nil)
  3040. // [params setValue:appDelegate.password forKey:@"password"];
  3041. // if(appDelegate.order_code!=nil)
  3042. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3043. //
  3044. // [params setValue:addTo forKey:@"addTo"];
  3045. // [params setValue:orderCode forKey:@"orderCode"];
  3046. // [params setValue:alert forKey:@"alert"];
  3047. // [params setValue:qty forKey:@"sold_by_qty"];
  3048. // [params setValue:available forKey:@"available"];
  3049. // [params setValue:price forKey:@"price"];
  3050. // [params setValue:bestseller forKey:@"bestseller"];
  3051. // [params setValue:modelname forKey:@"modelName"];
  3052. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3053. //
  3054. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3055. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3056. // [params setValue:category forKey:@"category"];
  3057. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3058. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3059. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3060. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3061. // [params setValue:filter forKey:@"filter"];
  3062. // [params setValue:keyword forKey:@"keyword"];
  3063. //
  3064. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  3065. // if ([addTo isEqualToString:@"cart"]) {
  3066. // [params setObject:@"Add To Cart" forKey:kAction];
  3067. // }
  3068. //
  3069. //
  3070. // NSData* json= nil;
  3071. //
  3072. // if(appDelegate.offline_mode)
  3073. // {
  3074. // json= [OLDataProvider offline_categoryaddall:params];
  3075. // }
  3076. // else
  3077. // {
  3078. // if(![self IsNetworkAvailable])
  3079. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3080. //
  3081. //
  3082. // NSError *error=nil;
  3083. //
  3084. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3085. // params[@"resultSerial"]=uuid;
  3086. //
  3087. // for(int i=0;i<150;i++)
  3088. // {
  3089. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3090. // // result_params[@"resultSerial"]=uuid;
  3091. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  3092. // if(json!=nil)
  3093. // {
  3094. //
  3095. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3096. // int resultInt = [jsobj[@"result"] intValue];
  3097. // if(resultInt == 2 || resultInt == 8)
  3098. // {
  3099. // break;
  3100. // }
  3101. // }
  3102. // sleep(2);
  3103. // }
  3104. //
  3105. //
  3106. //
  3107. // }
  3108. // if(json==nil)
  3109. // return nil;
  3110. // NSError *error=nil;
  3111. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3112. // return jsobj;
  3113. //
  3114. //}
  3115. //+(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
  3116. //{
  3117. //
  3118. //
  3119. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3120. //
  3121. //
  3122. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3123. //
  3124. // if(appDelegate.user!=nil)
  3125. // [params setValue:appDelegate.user forKey:@"user"];
  3126. // if(appDelegate.contact_id!=nil)
  3127. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3128. // if(appDelegate.password!=nil)
  3129. // [params setValue:appDelegate.password forKey:@"password"];
  3130. // if(appDelegate.order_code!=nil)
  3131. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3132. //
  3133. // [params setValue:alert forKey:@"alert"];
  3134. // [params setValue:qty forKey:@"sold_by_qty"];
  3135. // [params setValue:available forKey:@"available"];
  3136. // [params setValue:price forKey:@"price"];
  3137. // [params setValue:bestseller forKey:@"bestseller"];
  3138. // [params setValue:modelname forKey:@"modelName"];
  3139. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3140. //
  3141. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3142. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3143. // [params setValue:category forKey:@"category"];
  3144. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3145. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3146. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3147. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3148. // [params setValue:filter forKey:@"filter"];
  3149. // [params setValue:keyword forKey:@"keyword"];
  3150. //
  3151. //
  3152. //
  3153. // if(appDelegate.offline_mode)
  3154. // return [OLDataProvider offline_category:params];
  3155. // if(![self IsNetworkAvailable])
  3156. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3157. //
  3158. // NSData* json=[self get_json:URL_ADDALL2PORTFOLIO parameters:params];
  3159. // if(json==nil)
  3160. // return nil;
  3161. // NSError *error=nil;
  3162. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3163. // return jsobj;
  3164. //
  3165. //}
  3166. //+(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
  3167. //{
  3168. //
  3169. //
  3170. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3171. //
  3172. //
  3173. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3174. //
  3175. // if(appDelegate.user!=nil)
  3176. // [params setValue:appDelegate.user forKey:@"user"];
  3177. // if(appDelegate.contact_id!=nil)
  3178. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3179. // if(appDelegate.password!=nil)
  3180. // [params setValue:appDelegate.password forKey:@"password"];
  3181. // if(appDelegate.order_code!=nil)
  3182. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3183. //
  3184. // [params setValue:alert forKey:@"alert"];
  3185. // [params setValue:qty forKey:@"sold_by_qty"];
  3186. // [params setValue:available forKey:@"available"];
  3187. // [params setValue:price forKey:@"price"];
  3188. // [params setValue:bestseller forKey:@"bestseller"];
  3189. // [params setValue:modelname forKey:@"modelName"];
  3190. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3191. //
  3192. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3193. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3194. // [params setValue:category forKey:@"category"];
  3195. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3196. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3197. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3198. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3199. // [params setValue:filter forKey:@"filter"];
  3200. // [params setValue:keyword forKey:@"keyword"];
  3201. //
  3202. //
  3203. //
  3204. // if(appDelegate.offline_mode)
  3205. // return [OLDataProvider offline_category:params];
  3206. // if(![self IsNetworkAvailable])
  3207. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3208. //
  3209. // NSData* json=[self get_json:URL_ADDALL2WISH parameters:params];
  3210. // if(json==nil)
  3211. // return nil;
  3212. // NSError *error=nil;
  3213. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3214. // return jsobj;
  3215. //
  3216. //}
  3217. //+(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
  3218. //{
  3219. //
  3220. //
  3221. // __block AppDelegate *appDelegate = nil;
  3222. //
  3223. // dispatch_sync(dispatch_get_main_queue(), ^{
  3224. // //some UI methods ej
  3225. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3226. // });
  3227. //
  3228. //
  3229. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3230. //
  3231. // if(appDelegate.user!=nil)
  3232. // [params setValue:appDelegate.user forKey:@"user"];
  3233. // if(appDelegate.contact_id!=nil)
  3234. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3235. // if(appDelegate.password!=nil)
  3236. // [params setValue:appDelegate.password forKey:@"password"];
  3237. // if(appDelegate.order_code!=nil)
  3238. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3239. //
  3240. // [params setValue:alert forKey:@"alert"];
  3241. // [params setValue:qty forKey:@"sold_by_qty"];
  3242. // [params setValue:available forKey:@"available"];
  3243. // [params setValue:price forKey:@"price"];
  3244. // [params setValue:bestseller forKey:@"bestseller"];
  3245. // [params setValue:modelname forKey:@"modelName"];
  3246. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3247. //
  3248. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3249. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3250. // [params setValue:category forKey:@"category"];
  3251. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3252. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3253. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3254. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3255. // [params setValue:filter forKey:@"filter"];
  3256. // [params setValue:keyword forKey:@"keyword"];
  3257. //
  3258. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  3259. // if (alert) {
  3260. // [params setObject:@"Filter" forKey:kAction];
  3261. // }
  3262. // if ([Singleton sharedInstance].homeItemClick) {
  3263. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  3264. // [Singleton sharedInstance].homeItemClick = NO;
  3265. //
  3266. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  3267. // [Singleton sharedInstance].homeClickedItemName = nil;
  3268. // [params setObject:extra forKey:kExtra];
  3269. //
  3270. // }
  3271. //
  3272. //
  3273. // if(appDelegate.offline_mode)
  3274. // return [OLDataProvider offline_category:params];
  3275. // if(![self IsNetworkAvailable])
  3276. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3277. //
  3278. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  3279. // if(json==nil)
  3280. // return nil;
  3281. // NSError *error=nil;
  3282. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3283. // return jsobj;
  3284. //
  3285. //}
  3286. //+(NSDictionary*)Search_addall:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  3287. //{
  3288. //
  3289. //
  3290. //
  3291. //
  3292. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3293. // __block AppDelegate *appDelegate = nil;
  3294. //
  3295. // dispatch_sync(dispatch_get_main_queue(), ^{
  3296. // //some UI methods ej
  3297. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3298. // });
  3299. // if(appDelegate.user!=nil)
  3300. // [params setValue:appDelegate.user forKey:@"user"];
  3301. // if(appDelegate.contact_id!=nil)
  3302. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3303. // if(appDelegate.password!=nil)
  3304. // [params setValue:appDelegate.password forKey:@"password"];
  3305. // if(appDelegate.order_code!=nil)
  3306. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3307. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3308. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3309. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3310. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3311. // // [params setValue:filter forKey:@"filter"];
  3312. // [params setValue:keywords forKey:@"keyword"];
  3313. // [params setValue:addTo forKey:@"addTo"];
  3314. //
  3315. // [params setValue:orderCode forKey:@"orderCode"];
  3316. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3317. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3318. // if(matchfull)
  3319. // [params setValue:@"true" forKey:@"exactMatch"];
  3320. // else
  3321. // [params setValue:@"false" forKey:@"exactMatch"];
  3322. //
  3323. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  3324. // if ([addTo isEqualToString:@"cart"]) {
  3325. // [params setObject:@"Add To Cart" forKey:kAction];
  3326. // }
  3327. //
  3328. // NSData* json=nil;
  3329. // if(appDelegate.offline_mode)
  3330. // {
  3331. // json=[OLDataProvider offline_searchaddall:params];
  3332. // }
  3333. // else
  3334. // {
  3335. // if(![self IsNetworkAvailable])
  3336. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3337. //
  3338. // NSError *error=nil;
  3339. //
  3340. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3341. // params[@"resultSerial"]=uuid;
  3342. //
  3343. // for(int i=0;i<150;i++)
  3344. // {
  3345. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3346. // // result_params[@"resultSerial"]=uuid;
  3347. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  3348. // if(json!=nil)
  3349. // {
  3350. //
  3351. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3352. // if([jsobj[@"result"] intValue]==2)
  3353. // {
  3354. // break;
  3355. // }
  3356. // }
  3357. // sleep(2);
  3358. // }
  3359. // }
  3360. // if(json==nil)
  3361. // return nil;
  3362. // NSError *error=nil;
  3363. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3364. // return jsobj;
  3365. //
  3366. //}
  3367. //+(NSDictionary*)Search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull
  3368. //{
  3369. //
  3370. //
  3371. //
  3372. //
  3373. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3374. // __block AppDelegate *appDelegate = nil;
  3375. //
  3376. // dispatch_sync(dispatch_get_main_queue(), ^{
  3377. // //some UI methods ej
  3378. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3379. // });
  3380. // if(appDelegate.user!=nil)
  3381. // [params setValue:appDelegate.user forKey:@"user"];
  3382. // if(appDelegate.contact_id!=nil)
  3383. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3384. // if(appDelegate.password!=nil)
  3385. // [params setValue:appDelegate.password forKey:@"password"];
  3386. // if(appDelegate.order_code!=nil)
  3387. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3388. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3389. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3390. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3391. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3392. // // [params setValue:filter forKey:@"filter"];
  3393. // [params setValue:keywords forKey:@"keyword"];
  3394. //
  3395. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3396. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3397. // if(matchfull)
  3398. // [params setValue:@"true" forKey:@"exactMatch"];
  3399. // else
  3400. // [params setValue:@"false" forKey:@"exactMatch"];
  3401. //
  3402. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  3403. // if (keywords) {
  3404. // [params setObject:@"Search" forKey:kAction];
  3405. // }
  3406. //
  3407. // if(appDelegate.offline_mode)
  3408. // {
  3409. // return [OLDataProvider offline_search:params];
  3410. // }
  3411. // if(![self IsNetworkAvailable])
  3412. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3413. //
  3414. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  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. //+(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
  3422. //{
  3423. // // for debug
  3424. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3425. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3426. //
  3427. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3428. // __block AppDelegate *appDelegate = nil;
  3429. //
  3430. // dispatch_sync(dispatch_get_main_queue(), ^{
  3431. // //some UI methods ej
  3432. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3433. // });
  3434. // if(appDelegate.user!=nil)
  3435. // [params setValue:appDelegate.user forKey:@"user"];
  3436. // if(appDelegate.contact_id!=nil)
  3437. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3438. // if(appDelegate.password!=nil)
  3439. // [params setValue:appDelegate.password forKey:@"password"];
  3440. // if(appDelegate.order_code!=nil)
  3441. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3442. //
  3443. // [params setValue:addTo forKey:@"addTo"];
  3444. //
  3445. // [params setValue:orderCode forKey:@"orderCode"];
  3446. //
  3447. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3448. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3449. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3450. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3451. // // [params setValue:filter forKey:@"filter"];
  3452. // [params setValue:covertype forKey:@"covertype"];
  3453. // [params setValue:ctgid forKey:@"ctgId"];
  3454. // [params setValue:modelname forKey:@"modelName"];
  3455. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3456. // [params setValue:alert forKey:@"alert"];
  3457. // [params setValue:qty forKey:@"sold_by_qty"];
  3458. // [params setValue:available forKey:@"available"];
  3459. // [params setValue:price forKey:@"price"];
  3460. // [params setValue:bestseller forKey:@"bestseller"];
  3461. //
  3462. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3463. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3464. //
  3465. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3466. // if ([addTo isEqualToString:@"cart"]) {
  3467. // [params setObject:@"Add To Cart" forKey:kAction];
  3468. // }
  3469. //
  3470. // NSData* json = nil;
  3471. //
  3472. // if(appDelegate.offline_mode)
  3473. // {
  3474. // json= [OLDataProvider offline_itemsearchaddall:params];
  3475. // }
  3476. // else
  3477. // {
  3478. // if(![self IsNetworkAvailable])
  3479. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3480. // NSError *error=nil;
  3481. //
  3482. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3483. // params[@"resultSerial"]=uuid;
  3484. //
  3485. // for(int i=0;i<150;i++)
  3486. // {
  3487. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3488. // // result_params[@"resultSerial"]=uuid;
  3489. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  3490. // if(json!=nil)
  3491. // {
  3492. //
  3493. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3494. // if([jsobj[@"result"] intValue]==2)
  3495. // {
  3496. // break;
  3497. // }
  3498. // }
  3499. // sleep(2);
  3500. // }
  3501. // }
  3502. // if(json==nil)
  3503. // return nil;
  3504. // NSError *error=nil;
  3505. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3506. // return jsobj;
  3507. //}
  3508. //+(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
  3509. //{
  3510. //
  3511. // // for debug
  3512. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3513. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3514. //
  3515. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3516. // __block AppDelegate *appDelegate = nil;
  3517. //
  3518. // dispatch_sync(dispatch_get_main_queue(), ^{
  3519. // //some UI methods ej
  3520. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3521. // });
  3522. // if(appDelegate.user!=nil)
  3523. // [params setValue:appDelegate.user forKey:@"user"];
  3524. // if(appDelegate.contact_id!=nil)
  3525. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3526. // if(appDelegate.password!=nil)
  3527. // [params setValue:appDelegate.password forKey:@"password"];
  3528. // if(appDelegate.order_code!=nil)
  3529. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3530. //
  3531. //
  3532. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3533. // if (alert && qty && available && price && bestseller) {
  3534. // [params setObject:@"Filter" forKey:kAction];
  3535. // }
  3536. // if ([Singleton sharedInstance].homeItemClick) {
  3537. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  3538. // [Singleton sharedInstance].homeItemClick = NO;
  3539. //
  3540. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  3541. // [Singleton sharedInstance].homeClickedItemName = nil;
  3542. // [params setObject:extra forKey:kExtra];
  3543. // }
  3544. //
  3545. //
  3546. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3547. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3548. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3549. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3550. // // [params setValue:filter forKey:@"filter"];
  3551. // [params setValue:covertype forKey:@"covertype"];
  3552. // [params setValue:ctgid forKey:@"ctgId"];
  3553. // [params setValue:modelname forKey:@"modelName"];
  3554. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3555. // [params setValue:alert forKey:@"alert"];
  3556. // [params setValue:qty forKey:@"sold_by_qty"];
  3557. // [params setValue:available forKey:@"available"];
  3558. // [params setValue:price forKey:@"price"];
  3559. // [params setValue:bestseller forKey:@"bestseller"];
  3560. //
  3561. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3562. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3563. //
  3564. // if(appDelegate.offline_mode)
  3565. // {
  3566. // return [OLDataProvider offline_itemsearch:params];
  3567. // }
  3568. // if(![self IsNetworkAvailable])
  3569. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3570. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  3571. // if(json==nil)
  3572. // return nil;
  3573. // NSError *error=nil;
  3574. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3575. // return jsobj;
  3576. //}
  3577. //+(NSDictionary*)Search: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword
  3578. //{
  3579. // if(![self IsNetworkAvailable])
  3580. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3581. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3582. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3583. // if(appDelegate.user!=nil)
  3584. // [params setValue:appDelegate.user forKey:@"user"];
  3585. // if(appDelegate.contact_id!=nil)
  3586. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3587. // if(appDelegate.password!=nil)
  3588. // [params setValue:appDelegate.password forKey:@"password"];
  3589. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3590. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3591. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3592. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3593. // [params setValue:filter forKey:@"filter"];
  3594. // [params setValue:keyword forKey:@"keyword"];
  3595. //
  3596. //
  3597. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3598. // if(json==nil)
  3599. // return nil;
  3600. // NSError *error=nil;
  3601. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3602. // return jsobj;
  3603. //}
  3604. +(NSDictionary*)request_model_qty: (NSString*) fashionId
  3605. {
  3606. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3607. __block AppDelegate *appDelegate = nil;
  3608. dispatch_sync(dispatch_get_main_queue(), ^{
  3609. //some UI methods ej
  3610. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3611. });
  3612. if(appDelegate.user!=nil)
  3613. [params setValue:appDelegate.user forKey:@"user"];
  3614. if(appDelegate.contact_id!=nil)
  3615. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3616. if(appDelegate.password!=nil)
  3617. [params setValue:appDelegate.password forKey:@"password"];
  3618. [params setValue:fashionId forKey:@"fashionId"];
  3619. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  3620. NSData* json = nil;
  3621. if(appDelegate.offline_mode)
  3622. {
  3623. json = [OLDataProvider offline_model_qty:params];
  3624. } else {
  3625. if(![self IsNetworkAvailable])
  3626. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3627. json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  3628. }
  3629. if(json==nil)
  3630. return nil;
  3631. NSError *error=nil;
  3632. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3633. return jsobj;
  3634. }
  3635. +(NSDictionary*)retrieve_password: (NSString*) user email:(NSString*) email
  3636. {
  3637. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3638. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3639. // if(appDelegate.user!=nil)
  3640. // [params setValue:appDelegate.user forKey:@"user"];
  3641. // if(appDelegate.contact_id!=nil)
  3642. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3643. // if(appDelegate.password!=nil)
  3644. // [params setValue:appDelegate.password forKey:@"password"];
  3645. [params setValue:user forKey:@"username"];
  3646. [params setValue:email forKey:@"email"];
  3647. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3648. if(![self IsNetworkAvailable])
  3649. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3650. NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  3651. if(json==nil)
  3652. return nil;
  3653. NSError *error=nil;
  3654. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3655. return jsobj;
  3656. }
  3657. +(NSDictionary*)load_HomePage:(int) price_template customid:(int) customid
  3658. {
  3659. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3660. __block AppDelegate *appDelegate = nil;
  3661. dispatch_sync(dispatch_get_main_queue(), ^{
  3662. //some UI methods ej
  3663. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3664. });
  3665. if(appDelegate.user!=nil)
  3666. [params setValue:appDelegate.user forKey:@"user"];
  3667. if(appDelegate.contact_id!=nil)
  3668. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3669. if(appDelegate.password!=nil)
  3670. [params setValue:appDelegate.password forKey:@"password"];
  3671. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3672. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3673. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  3674. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3675. if(appDelegate.offline_mode)
  3676. {
  3677. //params[@"offline_Command"]=url;
  3678. return [OLDataProvider offline_home];
  3679. }
  3680. if(![self IsNetworkAvailable])
  3681. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3682. NSData* json=[self get_json:URL_LOAD_HOME parameters:params];
  3683. if(json==nil)
  3684. return nil;
  3685. NSError *error=nil;
  3686. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3687. return jsobj;
  3688. }
  3689. //+(NSDictionary*)logout
  3690. //{
  3691. //
  3692. //
  3693. //
  3694. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3695. // __block AppDelegate *appDelegate = nil;
  3696. //
  3697. // dispatch_sync(dispatch_get_main_queue(), ^{
  3698. // //some UI methods ej
  3699. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3700. // });
  3701. // if(appDelegate.user!=nil)
  3702. // [params setValue:appDelegate.user forKey:@"user"];
  3703. //
  3704. //
  3705. // if(appDelegate.password!=nil)
  3706. // [params setValue:appDelegate.password forKey:@"password"];
  3707. //
  3708. //
  3709. // if(appDelegate.offline_mode)
  3710. // {
  3711. // return [OLDataProvider offline_logout:params];
  3712. // }
  3713. // if(![self IsNetworkAvailable])
  3714. // {
  3715. // DebugLog(@"NET ERR");
  3716. //
  3717. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3718. // // return nil;
  3719. // }
  3720. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  3721. // //if(json==nil)
  3722. //
  3723. //
  3724. // if(json==nil)
  3725. // return nil;
  3726. // NSError *error=nil;
  3727. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3728. // int result = [[jsobj valueForKey:@"result"] intValue];
  3729. //
  3730. // if (result==2)
  3731. // {
  3732. //
  3733. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  3734. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  3735. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  3736. //
  3737. // [appDelegate update_count_mark];
  3738. //
  3739. //
  3740. // appDelegate.can_show_price =false;
  3741. // appDelegate.can_see_price =false;
  3742. // appDelegate.can_create_portfolio =false;
  3743. // appDelegate.can_create_order =false;
  3744. //
  3745. //
  3746. // appDelegate.can_cancel_order =false;
  3747. // appDelegate.can_set_cart_price =false;
  3748. // appDelegate.can_delete_order =false;
  3749. // appDelegate.can_submit_order =false;
  3750. // appDelegate.can_set_tearsheet_price =false;
  3751. // appDelegate.can_update_contact_info = false;
  3752. //
  3753. // appDelegate.save_order_logout = false;
  3754. // appDelegate.submit_order_logout = false;
  3755. // appDelegate.alert_sold_in_quantities = false;
  3756. //
  3757. // appDelegate.ipad_perm =nil ;
  3758. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  3759. // appDelegate.OrderFilter= nil;
  3760. // [appDelegate SetSo:nil];
  3761. // [appDelegate set_main_button_panel];
  3762. //#ifdef RA_NOTIFICATION
  3763. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  3764. //#endif
  3765. // }
  3766. // return jsobj;
  3767. //}
  3768. +(NSDictionary*)request_Cagegory
  3769. {
  3770. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  3771. __block AppDelegate *appDelegate = nil;
  3772. dispatch_sync(dispatch_get_main_queue(), ^{
  3773. //some UI methods ej
  3774. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3775. });
  3776. if(appDelegate.offline_mode)
  3777. {
  3778. //params[@"offline_Command"]=url;
  3779. return [OLDataProvider offline_category_menu];
  3780. }
  3781. if(![self IsNetworkAvailable])
  3782. {
  3783. DebugLog(@"NET ERR");
  3784. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3785. // return nil;
  3786. }
  3787. NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  3788. //if(json==nil)
  3789. if(json==nil)
  3790. return nil;
  3791. NSError *error=nil;
  3792. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3793. return jsobj;
  3794. }
  3795. +(int)Authorize : (NSString*) user password:(NSString*) password{
  3796. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  3797. // return RESULT_NET_ERROR;
  3798. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3799. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3800. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3801. __block AppDelegate *appDelegate = nil;
  3802. dispatch_sync(dispatch_get_main_queue(), ^{
  3803. //some UI methods ej
  3804. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3805. });
  3806. if(appDelegate.duid !=nil)
  3807. [params setValue:appDelegate.duid forKey:@"udid"];
  3808. [params setValue:@"handset_login" forKey:@"action"];
  3809. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  3810. [params setValue:user forKey:@"user"];
  3811. [params setValue:password forKey:@"password"];
  3812. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  3813. #ifdef TEST
  3814. [params setValue:@"true" forKey:@"is_debug"];
  3815. #else
  3816. [params setValue:@"false" forKey:@"is_debug"];
  3817. #endif
  3818. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3819. [params setObject:@"Login" forKey:kAction];
  3820. NSData* json= nil;
  3821. if(appDelegate.offline_mode)
  3822. {
  3823. json= [OLDataProvider offline_login:params] ;
  3824. }
  3825. else
  3826. {
  3827. if(![self IsNetworkAvailable])
  3828. return RESULT_NET_NOTAVAILABLE;
  3829. json =[self get_json:URL_UPDATE_AUTH parameters:params];
  3830. }
  3831. if(json==nil)
  3832. return RESULT_NET_ERROR;
  3833. int ret = [self parse_authinfo:json user:user password:password];
  3834. DebugLog(@"parse_authinfo return %d ",ret);
  3835. return ret;
  3836. }
  3837. +(NSDictionary*)update_customer_img: (NSString*) contactid img_url:(NSString*) url
  3838. {
  3839. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3840. __block AppDelegate *appDelegate = nil;
  3841. dispatch_sync(dispatch_get_main_queue(), ^{
  3842. //some UI methods ej
  3843. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3844. });
  3845. if(appDelegate.user!=nil)
  3846. [params setValue:appDelegate.user forKey:@"user"];
  3847. // if(appDelegate.contact_id!=nil)
  3848. if(appDelegate.password!=nil)
  3849. [params setValue:appDelegate.password forKey:@"password"];
  3850. [params setValue:contactid forKey:@"contactId"];
  3851. [params setValue:url forKey:@"business_card"];
  3852. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  3853. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  3854. if(appDelegate.offline_mode)
  3855. {
  3856. return [OLDataProvider offline_notimpl];
  3857. }
  3858. if(![self IsNetworkAvailable])
  3859. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3860. NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  3861. if(json==nil)
  3862. return nil;
  3863. NSError *error=nil;
  3864. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3865. return jsobj;
  3866. }
  3867. +(NSDictionary*)request_PendingOrder:(NSString *)contactid
  3868. {
  3869. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3870. __block AppDelegate *appDelegate = nil;
  3871. dispatch_sync(dispatch_get_main_queue(), ^{
  3872. //some UI methods ej
  3873. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3874. });
  3875. if(appDelegate.user!=nil)
  3876. [params setValue:appDelegate.user forKey:@"user"];
  3877. // if(appDelegate.contact_id!=nil)
  3878. if(appDelegate.password!=nil)
  3879. [params setValue:appDelegate.password forKey:@"password"];
  3880. [params setValue:contactid forKey:@"contactId"];
  3881. if(appDelegate.offline_mode)
  3882. {
  3883. return [OLDataProvider offline_notimpl];
  3884. }
  3885. if(![self IsNetworkAvailable])
  3886. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3887. NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  3888. if(json==nil)
  3889. return nil;
  3890. NSError *error=nil;
  3891. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3892. return jsobj;
  3893. }
  3894. //+(NSDictionary*)request_CustomerInfo:(NSString* ) contactid
  3895. //{
  3896. //
  3897. //
  3898. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3899. // __block AppDelegate *appDelegate = nil;
  3900. //
  3901. // dispatch_sync(dispatch_get_main_queue(), ^{
  3902. // //some UI methods ej
  3903. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3904. // });
  3905. // if(appDelegate.user!=nil)
  3906. // [params setValue:appDelegate.user forKey:@"user"];
  3907. // // if(appDelegate.contact_id!=nil)
  3908. //
  3909. // if(appDelegate.password!=nil)
  3910. // [params setValue:appDelegate.password forKey:@"password"];
  3911. // [params setValue:contactid forKey:@"contactId"];
  3912. //
  3913. // [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  3914. //
  3915. // if(appDelegate.offline_mode)
  3916. // return [OLDataProvider offline_contactinfo:params];
  3917. // if(![self IsNetworkAvailable])
  3918. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3919. //
  3920. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  3921. // if(json==nil)
  3922. // return nil;
  3923. // NSError *error=nil;
  3924. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3925. // return jsobj;
  3926. //
  3927. //}
  3928. +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
  3929. {
  3930. DebugLog(@"parse_authinfo");
  3931. NSError *error=nil;
  3932. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3933. if(jsobj)
  3934. {
  3935. __block AppDelegate *appDelegate = nil;
  3936. dispatch_sync(dispatch_get_main_queue(), ^{
  3937. //some UI methods ej
  3938. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3939. });
  3940. int result = [[jsobj valueForKey:@"result"] intValue];
  3941. if (result<0)
  3942. return result;
  3943. if(result!=AP_USER_AUTH&& result!=9)
  3944. {
  3945. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  3946. // [appDelegate Logout];
  3947. if(result==8)
  3948. {
  3949. return RESULT_LOGIN_DEVICE;
  3950. }
  3951. return RESULT_FALSE;
  3952. }
  3953. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  3954. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  3955. user=[objheader objectForKey:@"username"] ;
  3956. DebugLog(@"required_ver=%@ ",required_ver);
  3957. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  3958. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  3959. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  3960. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  3961. // if([ibadge isEqual:[NSNull null]])
  3962. // strbadge=@"0";
  3963. // if(ibadge==nil)
  3964. // ibadge=@"0";
  3965. // if([strbadge isEqualToString:@"null"])
  3966. // strbadge=@"0";
  3967. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  3968. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  3969. if([appDelegate.build intValue]<[required_ver intValue])
  3970. return RESULT_VER_LOW;
  3971. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  3972. appDelegate.user = user;
  3973. appDelegate.password = password;
  3974. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  3975. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  3976. appDelegate.bLogin = true;
  3977. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  3978. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  3979. {
  3980. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  3981. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  3982. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  3983. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  3984. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  3985. }
  3986. NSString* mode =[jsobj valueForKey:@"mode"] ;
  3987. [appDelegate SetMode:mode];
  3988. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  3989. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  3990. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  3991. [appDelegate update_count_mark];
  3992. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  3993. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  3994. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  3995. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  3996. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  3997. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  3998. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  3999. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  4000. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  4001. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  4002. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  4003. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  4004. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  4005. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  4006. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  4007. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  4008. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  4009. [appDelegate set_main_button_panel];
  4010. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  4011. // shop order status filter
  4012. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  4013. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  4014. // Sales order status filter
  4015. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  4016. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  4017. // specialInstruction
  4018. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  4019. //-价格类型
  4020. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  4021. // 权限
  4022. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  4023. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  4024. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  4025. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  4026. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  4027. [[RASingleton sharedInstance] resetGlobalLock];
  4028. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  4029. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  4030. }
  4031. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  4032. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  4033. // {
  4034. // // no update on the server;
  4035. // return RESULT_TRUE;
  4036. // }
  4037. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  4038. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4039. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4040. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4041. // [defaults synchronize];
  4042. //
  4043. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  4044. // NSArray* keys= [objfuncs allKeys];
  4045. /*
  4046. db.setTransactionSuccessful();
  4047. db.endTransaction();
  4048. */
  4049. return RESULT_TRUE;
  4050. }
  4051. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  4052. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  4053. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  4054. return RESULT_USERAUTH_ERROR;
  4055. }
  4056. //+(bool) IsNetworkAvailable
  4057. //{
  4058. //
  4059. // if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) &&
  4060. // ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable))
  4061. // return false;
  4062. // return true;
  4063. //}
  4064. //+(NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim
  4065. //{
  4066. // NSScanner *theScanner = [NSScanner scannerWithString:html];
  4067. // NSString *text = nil;
  4068. //
  4069. // while ([theScanner isAtEnd] == NO) {
  4070. // // find start of tag
  4071. // [theScanner scanUpToString:@"<" intoString:NULL] ;
  4072. // // find end of tag
  4073. // [theScanner scanUpToString:@">" intoString:&text] ;
  4074. // // replace the found tag with a space
  4075. // //(you can filter multi-spaces out later if you wish)
  4076. // html = [html stringByReplacingOccurrencesOfString:
  4077. // [ NSString stringWithFormat:@"%@>", text]
  4078. // withString:@""];
  4079. // }
  4080. //
  4081. // return trim ? [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : html;
  4082. //}
  4083. //
  4084. //+(NSString *)flattenURL:(NSString *)url trimWhiteSpace:(BOOL)trim
  4085. //{
  4086. // NSScanner *theScanner = [NSScanner scannerWithString:url];
  4087. // NSString *text = nil;
  4088. //
  4089. // while ([theScanner isAtEnd] == NO) {
  4090. // // find start of tag
  4091. // [theScanner scanUpToString:@"/" intoString:NULL] ;
  4092. // // find end of tag
  4093. // [theScanner scanUpToString:@"/" intoString:&text] ;
  4094. // // replace the found tag with a space
  4095. // //(you can filter multi-spaces out later if you wish)
  4096. // url = [url stringByReplacingOccurrencesOfString:
  4097. // [ NSString stringWithFormat:@"%@", text]
  4098. // withString:@""];
  4099. // }
  4100. //
  4101. // return trim ? [url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : url;
  4102. //}
  4103. + (NSDictionary *)set_npd_shop_price_type:(NSInteger)priceType {
  4104. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4105. __block AppDelegate *appDelegate = nil;
  4106. dispatch_sync(dispatch_get_main_queue(), ^{
  4107. //some UI methods ej
  4108. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4109. });
  4110. if(appDelegate.user!=nil)
  4111. [dic setValue:appDelegate.user forKey:@"user"];
  4112. if(appDelegate.password!=nil)
  4113. [dic setValue:appDelegate.password forKey:@"password"];
  4114. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  4115. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  4116. NSData* json=nil;
  4117. if(appDelegate.offline_mode)
  4118. {
  4119. return [OLDataProvider offline_notimpl];
  4120. }
  4121. else
  4122. {
  4123. if(![self IsNetworkAvailable])
  4124. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4125. json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  4126. }
  4127. if(json!=nil)
  4128. {
  4129. NSError *error=nil;
  4130. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4131. return jsobj;
  4132. }
  4133. return nil;
  4134. }
  4135. + (NSDictionary *)get_npd_shop_givenPrice {
  4136. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4137. __block AppDelegate *appDelegate = nil;
  4138. dispatch_sync(dispatch_get_main_queue(), ^{
  4139. //some UI methods ej
  4140. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4141. });
  4142. if(appDelegate.user!=nil)
  4143. [dic setValue:appDelegate.user forKey:@"user"];
  4144. if(appDelegate.password!=nil)
  4145. [dic setValue:appDelegate.password forKey:@"password"];
  4146. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  4147. NSData* json=nil;
  4148. if(appDelegate.offline_mode)
  4149. {
  4150. return [OLDataProvider offline_notimpl];
  4151. }
  4152. else
  4153. {
  4154. if(![self IsNetworkAvailable])
  4155. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4156. json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  4157. }
  4158. if(json!=nil)
  4159. {
  4160. NSError *error=nil;
  4161. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4162. return jsobj;
  4163. }
  4164. return nil;
  4165. }
  4166. + (NSDictionary *)set_npd_shop_givenPrice:(NSMutableDictionary *)params {
  4167. __block AppDelegate *appDelegate = nil;
  4168. dispatch_sync(dispatch_get_main_queue(), ^{
  4169. //some UI methods ej
  4170. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4171. });
  4172. if(appDelegate.user!=nil)
  4173. [params setValue:appDelegate.user forKey:@"user"];
  4174. if(appDelegate.password!=nil)
  4175. [params setValue:appDelegate.password forKey:@"password"];
  4176. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  4177. NSData* json=nil;
  4178. if(appDelegate.offline_mode)
  4179. {
  4180. return [OLDataProvider offline_notimpl];
  4181. }
  4182. else
  4183. {
  4184. if(![self IsNetworkAvailable])
  4185. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4186. json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  4187. }
  4188. if(json!=nil)
  4189. {
  4190. NSError *error=nil;
  4191. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4192. return jsobj;
  4193. }
  4194. return nil;
  4195. }
  4196. + (NSDictionary *)merge_order:(NSMutableDictionary *)params {
  4197. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4198. __block AppDelegate *appDelegate = nil;
  4199. dispatch_sync(dispatch_get_main_queue(), ^{
  4200. //some UI methods ej
  4201. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4202. });
  4203. if(appDelegate.user!=nil)
  4204. [dic setValue:appDelegate.user forKey:@"user"];
  4205. if(appDelegate.password!=nil)
  4206. [dic setValue:appDelegate.password forKey:@"password"];
  4207. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  4208. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  4209. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  4210. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  4211. NSData* json=nil;
  4212. if(appDelegate.offline_mode)
  4213. {
  4214. return [OLDataProvider offline_notimpl];
  4215. }
  4216. else
  4217. {
  4218. if(![self IsNetworkAvailable])
  4219. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4220. json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  4221. }
  4222. if(json!=nil)
  4223. {
  4224. NSError *error=nil;
  4225. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4226. return jsobj;
  4227. }
  4228. else
  4229. return nil;
  4230. }
  4231. //+ (NSDictionary *)lock_order:(NSString *)oderCode
  4232. //{
  4233. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4234. // __block AppDelegate *appDelegate = nil;
  4235. //
  4236. // dispatch_sync(dispatch_get_main_queue(), ^{
  4237. // //some UI methods ej
  4238. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4239. // });
  4240. // if(appDelegate.user!=nil)
  4241. // [params setValue:appDelegate.user forKey:@"user"];
  4242. //
  4243. // if(appDelegate.password!=nil)
  4244. // [params setValue:appDelegate.password forKey:@"password"];
  4245. //
  4246. // [params setValue:oderCode forKey:@"orderCode"];
  4247. //
  4248. // NSData* json=nil;
  4249. // if(appDelegate.offline_mode)
  4250. // {
  4251. // json=[OLDataProvider offline_editorder:params];
  4252. //
  4253. // }
  4254. // else
  4255. // {
  4256. // if(![self IsNetworkAvailable])
  4257. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4258. //
  4259. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  4260. // }
  4261. // if(json!=nil)
  4262. // {
  4263. // NSError *error=nil;
  4264. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4265. //
  4266. // return jsobj;
  4267. // }
  4268. // else
  4269. // return nil;
  4270. //}
  4271. + (NSDictionary *)quoteOrder:(NSString *)so_id emailAddr:(NSString *)addr {
  4272. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4273. __block AppDelegate *appDelegate = nil;
  4274. dispatch_sync(dispatch_get_main_queue(), ^{
  4275. //some UI methods ej
  4276. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4277. });
  4278. if(appDelegate.user!=nil)
  4279. [dic setValue:appDelegate.user forKey:@"user"];
  4280. if(appDelegate.password!=nil)
  4281. [dic setValue:appDelegate.password forKey:@"password"];
  4282. [dic setValue:so_id forKey:@"orderCode"];
  4283. [dic setValue:addr forKey:@"email"];
  4284. [dic setObject:ScreenCodeCart forKey:kScreenName];
  4285. if (appDelegate.customerInfo) {
  4286. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4287. if (customer_cid) {
  4288. [dic setValue:customer_cid forKey:@"contactId"];
  4289. }
  4290. }
  4291. NSData* json=nil;
  4292. if(appDelegate.offline_mode)
  4293. {
  4294. return [OLDataProvider offline_notimpl];
  4295. }
  4296. else
  4297. {
  4298. if(![self IsNetworkAvailable])
  4299. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4300. json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  4301. }
  4302. if(json!=nil)
  4303. {
  4304. NSError *error=nil;
  4305. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4306. return jsobj;
  4307. }
  4308. return @{@"result" : @(RESULT_FALSE)};
  4309. }
  4310. + (NSDictionary *)notifyModel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName{
  4311. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4312. __block AppDelegate *appDelegate = nil;
  4313. dispatch_sync(dispatch_get_main_queue(), ^{
  4314. //some UI methods ej
  4315. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4316. });
  4317. if(appDelegate.user!=nil)
  4318. [dic setValue:appDelegate.user forKey:@"user"];
  4319. if(appDelegate.password!=nil)
  4320. [dic setValue:appDelegate.password forKey:@"password"];
  4321. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  4322. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4323. if (customer_cid) {
  4324. [dic setValue:customer_cid forKey:@"contactId"];
  4325. }
  4326. }
  4327. [dic setObject:screenName forKey:kScreenName];
  4328. [dic setValue:modelID forKey:@"productId"];
  4329. if (addr) { // 弹框输入
  4330. [dic setValue:addr forKey:@"email"];
  4331. } else {
  4332. // employee选择了Contact,并且Contact有Email
  4333. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  4334. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  4335. // if (email) {
  4336. // [dic setValue:email forKey:@"email"];
  4337. // }
  4338. // }
  4339. }
  4340. NSData* json=nil;
  4341. if(appDelegate.offline_mode)
  4342. {
  4343. return [OLDataProvider offline_notimpl];
  4344. }
  4345. else
  4346. {
  4347. if(![self IsNetworkAvailable])
  4348. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4349. json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  4350. }
  4351. if(json!=nil)
  4352. {
  4353. NSError *error=nil;
  4354. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4355. return jsobj;
  4356. }
  4357. return @{@"result" : @(RESULT_FALSE)};
  4358. }
  4359. + (NSDictionary *)quoteWishlist2EmailAddr:(NSString *)addr {
  4360. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4361. __block AppDelegate *appDelegate = nil;
  4362. dispatch_sync(dispatch_get_main_queue(), ^{
  4363. //some UI methods ej
  4364. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4365. });
  4366. if(appDelegate.user!=nil)
  4367. [dic setValue:appDelegate.user forKey:@"user"];
  4368. if(appDelegate.password!=nil)
  4369. [dic setValue:appDelegate.password forKey:@"password"];
  4370. [dic setValue:addr forKey:@"email"];
  4371. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  4372. // if (appDelegate.customerInfo) {
  4373. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4374. // if (customer_cid) {
  4375. // [dic setValue:customer_cid forKey:@"contactId"];
  4376. // }
  4377. // }
  4378. NSData* json=nil;
  4379. if(appDelegate.offline_mode)
  4380. {
  4381. return [OLDataProvider offline_notimpl];
  4382. }
  4383. else
  4384. {
  4385. if(![self IsNetworkAvailable])
  4386. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4387. json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  4388. }
  4389. if(json!=nil)
  4390. {
  4391. NSError *error=nil;
  4392. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4393. return jsobj;
  4394. }
  4395. return @{@"result" : @(RESULT_FALSE)};
  4396. }
  4397. + (NSDictionary *)movetobackorder:(NSString *)cart_item_id {
  4398. if (cart_item_id == nil || cart_item_id.length < 1) {
  4399. return @{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"};
  4400. }
  4401. __block AppDelegate *appDelegate = nil;
  4402. dispatch_sync(dispatch_get_main_queue(), ^{
  4403. //some UI methods ej
  4404. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4405. });
  4406. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4407. if(appDelegate.user!=nil)
  4408. [dic setValue:appDelegate.user forKey:@"user"];
  4409. if(appDelegate.password!=nil)
  4410. [dic setValue:appDelegate.password forKey:@"password"];
  4411. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  4412. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  4413. [dic setObject:ScreenCodeCart forKey:kScreenName];
  4414. if(![self IsNetworkAvailable])
  4415. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4416. NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  4417. if(json!=nil)
  4418. {
  4419. NSError *error=nil;
  4420. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4421. return jsobj;
  4422. }
  4423. return @{@"result" : @(RESULT_FALSE)};
  4424. }
  4425. + (NSDictionary*)request_hangTag:(NSString *)group {
  4426. #ifdef BUILD_UWAVER
  4427. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4428. __block AppDelegate *appDelegate = nil;
  4429. dispatch_sync(dispatch_get_main_queue(), ^{
  4430. //some UI methods ej
  4431. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4432. });
  4433. if(appDelegate.user!=nil)
  4434. [params setValue:appDelegate.user forKey:@"user"];
  4435. if(appDelegate.contact_id!=nil)
  4436. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4437. if(appDelegate.password!=nil)
  4438. [params setValue:appDelegate.password forKey:@"password"];
  4439. if (group) {
  4440. [params setValue:group forKey:@"groupName"];
  4441. }
  4442. NSString * uuid= [[NSUUID UUID] UUIDString];
  4443. params[@"resultSerial"]=uuid;
  4444. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4445. NSData* json = nil;
  4446. if(appDelegate.offline_mode)
  4447. {
  4448. json = [OLDataProvider offline_notimpl];
  4449. } else {
  4450. if(![self IsNetworkAvailable])
  4451. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4452. json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  4453. }
  4454. if(json==nil)
  4455. return nil;
  4456. NSError *error=nil;
  4457. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4458. return jsobj;
  4459. #else
  4460. return nil;
  4461. #endif
  4462. }
  4463. #pragma mark 2020 new interface
  4464. // 新接口逐步替换以前的网络请求,2020
  4465. +(void)request_home:(int) price_template customid:(int) customid completionHandler:(resultHandler)result
  4466. {
  4467. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4468. AppDelegate *appDelegate = nil;
  4469. //some UI methods ej
  4470. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4471. if(appDelegate.user!=nil)
  4472. [params setValue:appDelegate.user forKey:@"user"];
  4473. if(appDelegate.contact_id!=nil)
  4474. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4475. if(appDelegate.password!=nil)
  4476. [params setValue:appDelegate.password forKey:@"password"];
  4477. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4478. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4479. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  4480. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4481. if(appDelegate.offline_mode)
  4482. {
  4483. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4484. NSMutableDictionary* json = [[OLDataProvider offline_home] mutableCopy];
  4485. dispatch_async(dispatch_get_main_queue(), ^{
  4486. result(json);
  4487. });
  4488. });
  4489. return;
  4490. }
  4491. [self request_interface:URL_LOAD_HOME parameters:params err_record_url:nil completionHandler:result retry:0];
  4492. return;
  4493. }
  4494. +(void)request_category:(resultHandler)result
  4495. {
  4496. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  4497. AppDelegate *appDelegate = nil;
  4498. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4499. if(appDelegate.offline_mode)
  4500. {
  4501. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4502. NSMutableDictionary* json = [[OLDataProvider offline_category_menu] mutableCopy];
  4503. dispatch_async(dispatch_get_main_queue(), ^{
  4504. result(json);
  4505. });
  4506. });
  4507. return;
  4508. }
  4509. [self request_interface:URL_REQUEST_CATMENU parameters:[NSMutableDictionary new] err_record_url:nil completionHandler:result retry:0];
  4510. //
  4511. // if(![self IsNetworkAvailable])
  4512. // {
  4513. // DebugLog(@"NET ERR");
  4514. //
  4515. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4516. // // return nil;
  4517. // }
  4518. //
  4519. // NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  4520. // //if(json==nil)
  4521. //
  4522. //
  4523. // if(json==nil)
  4524. // return nil;
  4525. // NSError *error=nil;
  4526. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4527. // return jsobj;
  4528. }
  4529. +(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
  4530. {
  4531. AppDelegate *appDelegate = nil;
  4532. //some UI methods ej
  4533. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4534. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4535. if(appDelegate.user!=nil)
  4536. [params setValue:appDelegate.user forKey:@"user"];
  4537. if(appDelegate.contact_id!=nil)
  4538. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4539. if(appDelegate.password!=nil)
  4540. [params setValue:appDelegate.password forKey:@"password"];
  4541. if(appDelegate.order_code!=nil)
  4542. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4543. [params setValue:alert forKey:@"alert"];
  4544. [params setValue:qty forKey:@"sold_by_qty"];
  4545. [params setValue:available forKey:@"available"];
  4546. [params setValue:price forKey:@"price"];
  4547. [params setValue:bestseller forKey:@"bestseller"];
  4548. [params setValue:modelname forKey:@"modelName"];
  4549. [params setValue:modeldescrip forKey:@"modelDescription"];
  4550. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4551. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4552. [params setValue:category forKey:@"category"];
  4553. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4554. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4555. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4556. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4557. [params setValue:filter forKey:@"filter"];
  4558. [params setValue:keyword forKey:@"keyword"];
  4559. [params setObject:ScreenCodeCategory forKey:kScreenName];
  4560. if (alert) {
  4561. [params setObject:@"Filter" forKey:kAction];
  4562. }
  4563. if ([RASingleton sharedInstance].homeItemClick) {
  4564. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  4565. [RASingleton sharedInstance].homeItemClick = NO;
  4566. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  4567. [RASingleton sharedInstance].homeClickedItemName = nil;
  4568. [params setObject:extra forKey:kExtra];
  4569. }
  4570. if(appDelegate.offline_mode)
  4571. {
  4572. // [OLDataProvider offline_category:params completionHandler:result];
  4573. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4574. NSMutableDictionary* json = [[OLDataProvider offline_category:params] mutableCopy];
  4575. dispatch_async(dispatch_get_main_queue(), ^{
  4576. result(json);
  4577. });
  4578. });
  4579. return;
  4580. }
  4581. [self request_interface:URL_CATEGORY parameters:params err_record_url:nil completionHandler:result retry:0];
  4582. return ;
  4583. //
  4584. // if(![self IsNetworkAvailable])
  4585. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4586. //
  4587. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  4588. // if(json==nil)
  4589. // return nil;
  4590. // NSError *error=nil;
  4591. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4592. // return jsobj;
  4593. //
  4594. }
  4595. +(void)request_modeldetail: (NSString* ) item_id model_name:(NSString*) model_name category_id:(NSString*) category_id use_name :(bool) use_name groupName:(NSString *)groupName completionHandler:(resultHandler)result
  4596. {
  4597. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4598. AppDelegate *appDelegate = nil;
  4599. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4600. if(appDelegate.user!=nil)
  4601. [params setValue:appDelegate.user forKey:@"user"];
  4602. if(appDelegate.contact_id!=nil)
  4603. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4604. if(appDelegate.password!=nil)
  4605. [params setValue:appDelegate.password forKey:@"password"];
  4606. if(appDelegate.order_code!=nil)
  4607. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4608. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4609. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4610. if(use_name)
  4611. [params setValue:model_name forKey:@"product_name"];
  4612. else
  4613. [params setValue:item_id forKey:@"product_id"];
  4614. [params setValue:category_id forKey:@"category"];
  4615. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4616. [params setObject:@"Open A Model" forKey:kAction];
  4617. if (model_name) {
  4618. NSDictionary *extra = @{@"ModelName" : model_name};
  4619. [params setObject:extra forKey:kExtra];
  4620. }
  4621. if (groupName.length > 0) {
  4622. [params setObject:groupName forKey:@"groupName"];
  4623. }
  4624. if(appDelegate.offline_mode)
  4625. {
  4626. [OLDataProvider offline_model:params completionHandler:result];
  4627. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4628. // NSMutableDictionary* json = [[OLDataProvider offline_model:params] mutableCopy];
  4629. // dispatch_async(dispatch_get_main_queue(), ^{
  4630. // result(json);
  4631. // });
  4632. // });
  4633. return;
  4634. }
  4635. [self request_interface:URL_ITEM_DETAIL parameters:params err_record_url:nil completionHandler:result retry:0];
  4636. //
  4637. // if(appDelegate.offline_mode)
  4638. // return [OLDataProvider offline_model:params];
  4639. //
  4640. // if(![self IsNetworkAvailable])
  4641. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4642. //
  4643. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  4644. // if(json==nil)
  4645. // return nil;
  4646. // NSError *error=nil;
  4647. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4648. // return jsobj;
  4649. }
  4650. +(void)request_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull 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. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  4666. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4667. // [params setValue:filter forKey:@"filter"];
  4668. [params setValue:keywords forKey:@"keyword"];
  4669. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4670. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4671. if(matchfull)
  4672. [params setValue:@"true" forKey:@"exactMatch"];
  4673. else
  4674. [params setValue:@"false" forKey:@"exactMatch"];
  4675. [params setObject:ScreenCodeSearch forKey:kScreenName];
  4676. if (keywords) {
  4677. [params setObject:@"Search" forKey:kAction];
  4678. }
  4679. if(appDelegate.offline_mode)
  4680. {
  4681. // [OLDataProvider offline_search:params completionHandler:result];
  4682. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4683. NSMutableDictionary* json = [[OLDataProvider offline_search:params] mutableCopy];
  4684. dispatch_async(dispatch_get_main_queue(), ^{
  4685. result(json);
  4686. });
  4687. });
  4688. return;
  4689. }
  4690. [self request_interface:URL_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  4691. // if(appDelegate.offline_mode)
  4692. // {
  4693. // return [OLDataProvider offline_search:params];
  4694. // }
  4695. // if(![self IsNetworkAvailable])
  4696. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4697. //
  4698. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  4699. // if(json==nil)
  4700. // return nil;
  4701. // NSError *error=nil;
  4702. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4703. // return jsobj;
  4704. }
  4705. +(void)request_login: (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
  4706. {
  4707. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  4708. // return RESULT_NET_ERROR;
  4709. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4710. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4711. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4712. AppDelegate *appDelegate = nil;
  4713. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4714. if(appDelegate.duid !=nil)
  4715. [params setValue:appDelegate.duid forKey:@"udid"];
  4716. [params setValue:@"handset_login" forKey:@"action"];
  4717. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  4718. [params setValue:user forKey:@"user"];
  4719. [params setValue:password forKey:@"password"];
  4720. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  4721. #ifdef TEST
  4722. [params setValue:@"true" forKey:@"is_debug"];
  4723. #else
  4724. [params setValue:@"false" forKey:@"is_debug"];
  4725. #endif
  4726. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  4727. [params setObject:@"Login" forKey:kAction];
  4728. if(appDelegate.offline_mode)
  4729. {
  4730. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4731. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_login:params]] mutableCopy];
  4732. dispatch_async(dispatch_get_main_queue(), ^{
  4733. int ret = [self parse_logininfo:json user:user password:password] ;
  4734. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4735. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4736. result(retjson);
  4737. });
  4738. });
  4739. return;
  4740. }
  4741. [self request_interface:URL_UPDATE_AUTH parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *chresult) {
  4742. int ret = [self parse_logininfo:chresult user:user password:password] ;
  4743. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4744. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4745. result(retjson);
  4746. } retry:0];
  4747. //
  4748. // NSData* json= nil;
  4749. // if(appDelegate.offline_mode)
  4750. // {
  4751. // json= [OLDataProvider offline_login:params] ;
  4752. //
  4753. // }
  4754. // else
  4755. // {
  4756. // if(![self IsNetworkAvailable])
  4757. // return RESULT_NET_NOTAVAILABLE;
  4758. // json =[self get_json:URL_UPDATE_AUTH parameters:params];
  4759. //
  4760. // }
  4761. //
  4762. // if(json==nil)
  4763. // return RESULT_NET_ERROR;
  4764. //
  4765. // int ret = [self parse_authinfo:json user:user password:password];
  4766. // DebugLog(@"parse_authinfo return %d ",ret);
  4767. //
  4768. //
  4769. // return ret;
  4770. //
  4771. }
  4772. +(int)parse_logininfo : (NSMutableDictionary *) jsobj user:(NSString*) user password:(NSString*) password
  4773. {
  4774. // DebugLog(@"parse_authinfo");
  4775. // NSError *error=nil;
  4776. //
  4777. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4778. if(jsobj)
  4779. {
  4780. AppDelegate *appDelegate = nil;
  4781. //some UI methods ej
  4782. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4783. int result = [[jsobj valueForKey:@"result"] intValue];
  4784. if (result<0)
  4785. return result;
  4786. if(result!=AP_USER_AUTH&& result!=9)
  4787. {
  4788. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  4789. // [appDelegate Logout];
  4790. if(result==8)
  4791. {
  4792. return RESULT_LOGIN_DEVICE;
  4793. }
  4794. return RESULT_FALSE;
  4795. }
  4796. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  4797. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  4798. user=[objheader objectForKey:@"username"] ;
  4799. DebugLog(@"required_ver=%@ ",required_ver);
  4800. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  4801. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  4802. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  4803. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  4804. // if([ibadge isEqual:[NSNull null]])
  4805. // strbadge=@"0";
  4806. // if(ibadge==nil)
  4807. // ibadge=@"0";
  4808. // if([strbadge isEqualToString:@"null"])
  4809. // strbadge=@"0";
  4810. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  4811. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  4812. if([appDelegate.build intValue]<[required_ver intValue])
  4813. return RESULT_VER_LOW;
  4814. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  4815. appDelegate.user = user;
  4816. appDelegate.password = password;
  4817. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  4818. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  4819. appDelegate.bLogin = true;
  4820. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  4821. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  4822. {
  4823. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  4824. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  4825. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  4826. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  4827. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  4828. }
  4829. NSString* mode =[jsobj valueForKey:@"mode"] ;
  4830. [appDelegate SetMode:mode];
  4831. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  4832. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  4833. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  4834. [appDelegate update_count_mark];
  4835. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  4836. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  4837. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  4838. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  4839. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  4840. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  4841. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  4842. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  4843. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  4844. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  4845. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  4846. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  4847. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  4848. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  4849. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  4850. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  4851. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  4852. [appDelegate set_main_button_panel];
  4853. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  4854. // shop order status filter
  4855. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  4856. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  4857. // Sales order status filter
  4858. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  4859. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  4860. // specialInstruction
  4861. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  4862. //-价格类型
  4863. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  4864. // 权限
  4865. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  4866. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  4867. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  4868. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  4869. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  4870. [[RASingleton sharedInstance] resetGlobalLock];
  4871. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  4872. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  4873. }
  4874. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  4875. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  4876. // {
  4877. // // no update on the server;
  4878. // return RESULT_TRUE;
  4879. // }
  4880. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  4881. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4882. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4883. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4884. // [defaults synchronize];
  4885. //
  4886. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  4887. // NSArray* keys= [objfuncs allKeys];
  4888. /*
  4889. db.setTransactionSuccessful();
  4890. db.endTransaction();
  4891. */
  4892. return RESULT_TRUE;
  4893. }
  4894. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  4895. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  4896. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  4897. return RESULT_USERAUTH_ERROR;
  4898. }
  4899. +(void)request_contactlist:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams completionHandler:(resultHandler)result
  4900. {
  4901. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4902. if(upparams!=nil)
  4903. params = [upparams mutableCopy];
  4904. AppDelegate *appDelegate = nil;
  4905. //some UI methods ej
  4906. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4907. if(appDelegate.user!=nil)
  4908. [params setValue:appDelegate.user forKey:@"user"];
  4909. if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  4910. [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  4911. else
  4912. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4913. if(appDelegate.password!=nil)
  4914. [params setValue:appDelegate.password forKey:@"password"];
  4915. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  4916. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  4917. [params setValue:contact_type forKey:@"contactType"];
  4918. [params setValue:keywords forKey:@"keyword"];
  4919. [params setObject:ScreenCodeAccount forKey:kScreenName];
  4920. if (keywords) {
  4921. [params setObject:@"Search" forKey:kAction];
  4922. }
  4923. if (upparams) {
  4924. [params setObject:@"Advance Search" forKey:kAction];
  4925. }
  4926. NSString* url=nil;
  4927. if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  4928. url=URL_SHIPTO_LIST;
  4929. else
  4930. url=URL_CONTACT_LIST;
  4931. if(appDelegate.offline_mode)
  4932. {
  4933. [OLDataProvider offline_contactlist:params completionHandler:result];
  4934. return;
  4935. }
  4936. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  4937. //
  4938. // if(appDelegate.offline_mode)
  4939. // return [OLDataProvider offline_contactlist:params];
  4940. //
  4941. // if(![self IsNetworkAvailable])
  4942. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4943. //
  4944. // NSData* json=[self get_json:url parameters:params];
  4945. // if(json==nil)
  4946. // return nil;
  4947. // NSError *error=nil;
  4948. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4949. // return jsobj;
  4950. }
  4951. +(void)request_contactinfo:(NSString* ) contactid completionHandler:(resultHandler)result
  4952. {
  4953. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4954. AppDelegate *appDelegate = nil;
  4955. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4956. if(appDelegate.user!=nil)
  4957. [params setValue:appDelegate.user forKey:@"user"];
  4958. // if(appDelegate.contact_id!=nil)
  4959. if(appDelegate.password!=nil)
  4960. [params setValue:appDelegate.password forKey:@"password"];
  4961. [params setValue:contactid forKey:@"contactId"];
  4962. [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  4963. if(appDelegate.offline_mode)
  4964. {
  4965. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4966. // [OLDataProvider offline_contactinfo:params completionHandler:result] ;
  4967. // });
  4968. params[@"mode"]=appDelegate.mode;
  4969. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4970. NSMutableDictionary* json = [[OLDataProvider offline_contactinfo:params] mutableCopy];
  4971. dispatch_async(dispatch_get_main_queue(), ^{
  4972. result(json);
  4973. });
  4974. });
  4975. return;
  4976. }
  4977. [self request_interface:URL_CUSTOMER_INFO parameters:params err_record_url:nil completionHandler:result retry:0];
  4978. // if(appDelegate.offline_mode)
  4979. // return [OLDataProvider offline_contactinfo:params];
  4980. // if(![self IsNetworkAvailable])
  4981. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4982. //
  4983. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  4984. // if(json==nil)
  4985. // return nil;
  4986. // NSError *error=nil;
  4987. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4988. // return jsobj;
  4989. //
  4990. }
  4991. +(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  4992. {
  4993. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4994. AppDelegate *appDelegate = nil;
  4995. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4996. if(appDelegate.user!=nil)
  4997. [params setValue:appDelegate.user forKey:@"user"];
  4998. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  4999. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  5000. // else
  5001. if(appDelegate.contact_id!=nil)
  5002. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5003. if(appDelegate.password!=nil)
  5004. [params setValue:appDelegate.password forKey:@"password"];
  5005. if(appDelegate.order_code!=nil)
  5006. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5007. bool can_create_backorder=appDelegate.can_create_backorder;
  5008. // [params setValue:sourceid forKey:@"sourceid"];
  5009. // [params setValue:editor forKey:@"editor"];
  5010. DebugLog(@"request editor url:%@",request_url);
  5011. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  5012. {
  5013. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  5014. }
  5015. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  5016. {
  5017. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  5018. }
  5019. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  5020. {
  5021. [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  5022. }
  5023. else if([request_url isEqualToString:URL_CARTDELIVERY])
  5024. {
  5025. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  5026. }
  5027. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  5028. {
  5029. [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  5030. }
  5031. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  5032. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  5033. }
  5034. if(appDelegate.offline_mode)
  5035. {
  5036. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5037. NSData* json = nil;
  5038. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  5039. {
  5040. json= [OLDataProvider offline_createContact:params];
  5041. }
  5042. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  5043. {
  5044. json= [OLDataProvider offline_editContact:params];
  5045. }
  5046. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  5047. {
  5048. json= [OLDataProvider offline_contactAdvancedSearch:params];
  5049. }
  5050. else if([request_url isEqualToString:URL_CARTDELIVERY])
  5051. {
  5052. params[@"contact_id"]=params[@"contactId"];
  5053. params[@"can_create_backorder"]=@(can_create_backorder);
  5054. json= [OLDataProvider offline_placeorder:params];
  5055. }
  5056. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  5057. {
  5058. json= [OLDataProvider offline_addreditor:params];
  5059. }
  5060. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  5061. json = [OLDataProvider offline_createTearSheet:params];
  5062. }
  5063. dispatch_async(dispatch_get_main_queue(), ^{
  5064. if(json==nil)
  5065. result( [[OLDataProvider offline_notimpl] mutableCopy]);
  5066. else
  5067. result([[RAConvertor data2dict:json] mutableCopy]);
  5068. });
  5069. });
  5070. return;
  5071. }
  5072. else
  5073. {
  5074. if([request_url isEqualToString:URL_CARTDELIVERY])
  5075. {
  5076. NSString * uuid= [[NSUUID UUID] UUIDString];
  5077. params[@"resultSerial"]=uuid;
  5078. __block bool bbreak = false;
  5079. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5080. for(int i=0;i<150;i++)
  5081. {
  5082. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  5083. // result_params[@"resultSerial"]=uuid;
  5084. //json=[self get_json:request_url parameters:params];
  5085. if(bbreak)
  5086. break;
  5087. dispatch_async(dispatch_get_main_queue(), ^{
  5088. NSLog(@"request cart delivery %d",i);
  5089. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5090. if(resulti!=nil)
  5091. {
  5092. if([resulti[@"result"] intValue]==2 || [resulti[@"result"] intValue] == 8)
  5093. {
  5094. if(!bbreak) //此判断保证result只调用一次。
  5095. {
  5096. result(resulti);
  5097. NSLog(@"result called at %d",i);
  5098. }
  5099. bbreak=true;
  5100. }
  5101. }
  5102. } retry:3];
  5103. });
  5104. // [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  5105. sleep(2);
  5106. }
  5107. });
  5108. }
  5109. else
  5110. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  5111. }
  5112. // if(json!=nil)
  5113. // {
  5114. // NSError *error=nil;
  5115. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5116. // return jsobj;
  5117. // }
  5118. // else
  5119. // return nil;
  5120. }
  5121. +(void)request_wishlist:(int)sort completionHandler:(resultHandler)result
  5122. {
  5123. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5124. AppDelegate *appDelegate = nil;
  5125. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5126. if(appDelegate.user!=nil)
  5127. [params setValue:appDelegate.user forKey:@"user"];
  5128. if(appDelegate.contact_id!=nil)
  5129. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5130. if(appDelegate.password!=nil)
  5131. [params setValue:appDelegate.password forKey:@"password"];
  5132. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  5133. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  5134. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  5135. [params setObject:ScreenCodeWishList forKey:kScreenName];
  5136. if(appDelegate.offline_mode)
  5137. {
  5138. [OLDataProvider offline_wishlist:params completionHandler:^(NSMutableDictionary *resulti) {
  5139. int result_code = [[resulti valueForKey:@"result"] intValue];
  5140. if (result_code==2)
  5141. {
  5142. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  5143. [appDelegate update_count_mark];;
  5144. result(resulti);
  5145. }
  5146. }];
  5147. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5148. // NSMutableDictionary* json = [[OLDataProvider offline_wishlist:params] mutableCopy];
  5149. // dispatch_async(dispatch_get_main_queue(), ^{
  5150. // result(json);
  5151. // });
  5152. // });
  5153. return;
  5154. }
  5155. [self request_interface:URL_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5156. int result_code = [[resulti valueForKey:@"result"] intValue];
  5157. if (result_code==2)
  5158. {
  5159. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  5160. [appDelegate update_count_mark];;
  5161. result(resulti);
  5162. }
  5163. } retry:0];
  5164. // if(appDelegate.offline_mode)
  5165. // {
  5166. // return [OLDataProvider offline_wishlist:params];
  5167. // }
  5168. // if(![self IsNetworkAvailable])
  5169. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5170. //
  5171. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  5172. // if(json==nil)
  5173. // return nil;
  5174. // NSError *error=nil;
  5175. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5176. // int result = [[jsobj valueForKey:@"result"] intValue];
  5177. //
  5178. // if (result==2)
  5179. // {
  5180. //
  5181. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5182. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  5183. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5184. //
  5185. // [appDelegate update_count_mark];
  5186. // }
  5187. // return jsobj;
  5188. }
  5189. +(void)request_portfoliolist:(int)sort completionHandler:(resultHandler)result
  5190. {
  5191. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5192. AppDelegate *appDelegate = nil;
  5193. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5194. if(appDelegate.user!=nil)
  5195. [params setValue:appDelegate.user forKey:@"user"];
  5196. if(appDelegate.contact_id!=nil)
  5197. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5198. if(appDelegate.password!=nil)
  5199. [params setValue:appDelegate.password forKey:@"password"];
  5200. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  5201. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  5202. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  5203. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  5204. if(appDelegate.offline_mode)
  5205. {
  5206. params[@"user"]=appDelegate.user;
  5207. params[@"contact_id"]=appDelegate.contact_id;
  5208. params[@"can_see_price"]=@(appDelegate.can_see_price);
  5209. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5210. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_portfolioList:params]] mutableCopy];
  5211. dispatch_async(dispatch_get_main_queue(), ^{
  5212. if ([json[@"result"] intValue]==2)
  5213. {
  5214. appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  5215. [appDelegate update_count_mark];
  5216. }
  5217. result(json);
  5218. });
  5219. });
  5220. return;
  5221. }
  5222. [self request_interface:URL_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5223. if ([resulti[@"result"] intValue]==2)
  5224. {
  5225. appDelegate.port_count =[[resulti valueForKey:@"count"] intValue];
  5226. [appDelegate update_count_mark];
  5227. }
  5228. result(resulti);
  5229. } retry:0];
  5230. // NSData* json = nil;
  5231. // if(appDelegate.offline_mode)
  5232. // {
  5233. // json = [OLDataProvider offline_portfolioList:params];
  5234. // } else {
  5235. // if(![self IsNetworkAvailable])
  5236. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5237. //
  5238. // json = [self get_json:URL_PORTFOLIO parameters:params];
  5239. // }
  5240. //
  5241. //
  5242. // if(json==nil)
  5243. // return nil;
  5244. // NSError *error=nil;
  5245. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5246. // int result = [[jsobj valueForKey:@"result"] intValue];
  5247. //
  5248. // if (result==2)
  5249. // {
  5250. //
  5251. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5252. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  5253. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  5254. //
  5255. // [appDelegate update_count_mark];
  5256. // }
  5257. // return jsobj;
  5258. }
  5259. +(void)request_portfoliopdf:(int ) offset limit:(int)limit keywords:(NSString* ) keywords completionHandler:(resultHandler)result
  5260. {
  5261. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5262. AppDelegate *appDelegate = nil;
  5263. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5264. if(appDelegate.user!=nil)
  5265. [params setValue:appDelegate.user forKey:@"user"];
  5266. if(appDelegate.contact_id!=nil)
  5267. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5268. if(appDelegate.password!=nil)
  5269. [params setValue:appDelegate.password forKey:@"password"];
  5270. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  5271. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  5272. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  5273. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  5274. // [params setValue:filter forKey:@"filter"];
  5275. [params setValue:keywords forKey:@"keyWord"];
  5276. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  5277. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  5278. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  5279. if (keywords) {
  5280. [params setObject:@"Search" forKey:kAction];
  5281. }
  5282. if(appDelegate.offline_mode)
  5283. {
  5284. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5285. NSData* json = [[OLDataProvider offline_pdfList:params] mutableCopy];
  5286. dispatch_async(dispatch_get_main_queue(), ^{
  5287. result([[RAConvertor data2dict:json] mutableCopy]);
  5288. });
  5289. });
  5290. return;
  5291. }
  5292. [self request_interface:URL_DM_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  5293. return;
  5294. // NSData* json = nil;
  5295. // if(appDelegate.offline_mode)
  5296. // {
  5297. // json = [OLDataProvider offline_pdfList:params];
  5298. // } else {
  5299. // if(![self IsNetworkAvailable])
  5300. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5301. //
  5302. // json=[self get_json:URL_DM_LIST parameters:params];
  5303. // }
  5304. // if(json==nil)
  5305. // return nil;
  5306. // NSError *error=nil;
  5307. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5308. // return jsobj;
  5309. }
  5310. +(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
  5311. {
  5312. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5313. AppDelegate *appDelegate = nil;
  5314. //some UI methods ej
  5315. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5316. if(appDelegate.user!=nil)
  5317. [params setValue:appDelegate.user forKey:@"user"];
  5318. if(appDelegate.contact_id!=nil)
  5319. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5320. if(appDelegate.password!=nil)
  5321. [params setValue:appDelegate.password forKey:@"password"];
  5322. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  5323. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  5324. [params setValue:keywords forKey:@"keyWord"];
  5325. [params setValue:customer forKey:@"customer_filter"];
  5326. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  5327. [params setValue:status_code forKey:@"orderStatus"];
  5328. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  5329. if (keywords) {
  5330. [params setObject:@"Search" forKey:kAction];
  5331. }
  5332. if(appDelegate.offline_mode)
  5333. {
  5334. params[@"user"]=appDelegate.user;
  5335. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5336. NSData* json = [[OLDataProvider offline_orderlist:params] mutableCopy];
  5337. dispatch_async(dispatch_get_main_queue(), ^{
  5338. result([[RAConvertor data2dict:json] mutableCopy]);
  5339. });
  5340. });
  5341. return;
  5342. }
  5343. [self request_interface:URL_ORDER_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  5344. // NSData* json=nil;
  5345. // if(appDelegate.offline_mode)
  5346. // {
  5347. // json= [OLDataProvider offline_orderlist:params];
  5348. // }
  5349. // else
  5350. // {
  5351. // if(![self IsNetworkAvailable])
  5352. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5353. //
  5354. // json=[self get_json:URL_ORDER_LIST parameters:params];
  5355. // }
  5356. // if(json==nil)
  5357. // return nil;
  5358. // NSError *error=nil;
  5359. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5360. // return jsobj;
  5361. }
  5362. +(void)request_logout:(resultHandler)result
  5363. {
  5364. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5365. AppDelegate *appDelegate = nil;
  5366. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5367. if(appDelegate.user!=nil)
  5368. [params setValue:appDelegate.user forKey:@"user"];
  5369. if(appDelegate.password!=nil)
  5370. [params setValue:appDelegate.password forKey:@"password"];
  5371. if(appDelegate.offline_mode)
  5372. {
  5373. [OLDataProvider offline_logout:params completionHandler:result];
  5374. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5375. // NSMutableDictionary* json = [[OLDataProvider offline_logout:params] mutableCopy];
  5376. // dispatch_async(dispatch_get_main_queue(), ^{
  5377. // result(json);
  5378. // });
  5379. // });
  5380. return;
  5381. }
  5382. [self request_interface:URL_LOGOUT parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5383. NSMutableDictionary* jsobj=resulti;
  5384. int result_code = [[jsobj valueForKey:@"result"] intValue];
  5385. if (result_code==2)
  5386. {
  5387. appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  5388. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5389. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5390. [appDelegate update_count_mark];
  5391. appDelegate.can_show_price =false;
  5392. appDelegate.can_see_price =false;
  5393. appDelegate.can_create_portfolio =false;
  5394. appDelegate.can_create_order =false;
  5395. appDelegate.can_cancel_order =false;
  5396. appDelegate.can_set_cart_price =false;
  5397. appDelegate.can_delete_order =false;
  5398. appDelegate.can_submit_order =false;
  5399. appDelegate.can_set_tearsheet_price =false;
  5400. appDelegate.can_update_contact_info = false;
  5401. appDelegate.save_order_logout = false;
  5402. appDelegate.submit_order_logout = false;
  5403. appDelegate.alert_sold_in_quantities = false;
  5404. appDelegate.ipad_perm =nil ;
  5405. appDelegate.user_type = USER_ROLE_UNKNOWN;
  5406. appDelegate.OrderFilter= nil;
  5407. [appDelegate SetSo:nil];
  5408. [appDelegate set_main_button_panel];
  5409. #ifdef RA_NOTIFICATION
  5410. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5411. #endif
  5412. }
  5413. result(resulti);
  5414. } retry:0];
  5415. //
  5416. // if(appDelegate.offline_mode)
  5417. // {
  5418. // return [OLDataProvider offline_logout:params];
  5419. // }
  5420. // if(![self IsNetworkAvailable])
  5421. // {
  5422. // DebugLog(@"NET ERR");
  5423. //
  5424. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5425. // // return nil;
  5426. // }
  5427. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  5428. // //if(json==nil)
  5429. //
  5430. //
  5431. // if(json==nil)
  5432. // return nil;
  5433. // NSError *error=nil;
  5434. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5435. // int result = [[jsobj valueForKey:@"result"] intValue];
  5436. //
  5437. // if (result==2)
  5438. // {
  5439. //
  5440. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  5441. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5442. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5443. //
  5444. // [appDelegate update_count_mark];
  5445. //
  5446. //
  5447. // appDelegate.can_show_price =false;
  5448. // appDelegate.can_see_price =false;
  5449. // appDelegate.can_create_portfolio =false;
  5450. // appDelegate.can_create_order =false;
  5451. //
  5452. //
  5453. // appDelegate.can_cancel_order =false;
  5454. // appDelegate.can_set_cart_price =false;
  5455. // appDelegate.can_delete_order =false;
  5456. // appDelegate.can_submit_order =false;
  5457. // appDelegate.can_set_tearsheet_price =false;
  5458. // appDelegate.can_update_contact_info = false;
  5459. //
  5460. // appDelegate.save_order_logout = false;
  5461. // appDelegate.submit_order_logout = false;
  5462. // appDelegate.alert_sold_in_quantities = false;
  5463. //
  5464. // appDelegate.ipad_perm =nil ;
  5465. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  5466. // appDelegate.OrderFilter= nil;
  5467. // [appDelegate SetSo:nil];
  5468. // [appDelegate set_main_button_panel];
  5469. //#ifdef RA_NOTIFICATION
  5470. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5471. //#endif
  5472. // }
  5473. // return jsobj;
  5474. }
  5475. + (void)request_hangtag:(NSString *)group completionHandler:(resultHandler)result
  5476. {
  5477. #ifdef BUILD_UWAVER
  5478. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5479. AppDelegate *appDelegate = nil;
  5480. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5481. if(appDelegate.user!=nil)
  5482. [params setValue:appDelegate.user forKey:@"user"];
  5483. if(appDelegate.contact_id!=nil)
  5484. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5485. if(appDelegate.password!=nil)
  5486. [params setValue:appDelegate.password forKey:@"password"];
  5487. if (group) {
  5488. [params setValue:group forKey:@"groupName"];
  5489. }
  5490. NSString * uuid= [[NSUUID UUID] UUIDString];
  5491. params[@"resultSerial"]=uuid;
  5492. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  5493. if(appDelegate.offline_mode)
  5494. {
  5495. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5496. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5497. dispatch_async(dispatch_get_main_queue(), ^{
  5498. result(json);
  5499. });
  5500. });
  5501. return;
  5502. }
  5503. [self request_interface:URL_CREATE_HANG_TAG parameters:params err_record_url:nil completionHandler:result retry:0];
  5504. // NSData* json = nil;
  5505. // if(appDelegate.offline_mode)
  5506. // {
  5507. // json = [OLDataProvider offline_portfolioList:params];
  5508. // } else {
  5509. // if(![self IsNetworkAvailable])
  5510. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5511. //
  5512. // json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  5513. // }
  5514. //
  5515. //
  5516. // if(json==nil)
  5517. // return nil;
  5518. // NSError *error=nil;
  5519. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5520. //
  5521. // return jsobj;
  5522. #else
  5523. return result(nil);
  5524. #endif
  5525. }
  5526. + (void)request_movetobackorder:(NSString *)cart_item_id completionHandler:(resultHandler)result
  5527. {
  5528. if (cart_item_id == nil || cart_item_id.length < 1) {
  5529. result([@{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"} mutableCopy]);
  5530. }
  5531. AppDelegate *appDelegate = nil;
  5532. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5533. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5534. if(appDelegate.user!=nil)
  5535. [dic setValue:appDelegate.user forKey:@"user"];
  5536. if(appDelegate.password!=nil)
  5537. [dic setValue:appDelegate.password forKey:@"password"];
  5538. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  5539. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  5540. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5541. if(appDelegate.offline_mode)
  5542. {
  5543. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5544. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5545. dispatch_async(dispatch_get_main_queue(), ^{
  5546. result(json);
  5547. });
  5548. });
  5549. return;
  5550. }
  5551. [self request_interface:URL_MOVE_TO_BACK_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5552. // if(![self IsNetworkAvailable])
  5553. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5554. //
  5555. // NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  5556. //
  5557. // if(json!=nil)
  5558. // {
  5559. // NSError *error=nil;
  5560. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5561. //
  5562. // return jsobj;
  5563. // }
  5564. //
  5565. // return @{@"result" : @(RESULT_FALSE)};
  5566. }
  5567. + (void)request_emailwishlist:(NSString *)addr completionHandler:(resultHandler)result
  5568. {
  5569. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5570. AppDelegate *appDelegate = nil;
  5571. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5572. if(appDelegate.user!=nil)
  5573. [dic setValue:appDelegate.user forKey:@"user"];
  5574. if(appDelegate.password!=nil)
  5575. [dic setValue:appDelegate.password forKey:@"password"];
  5576. [dic setValue:addr forKey:@"email"];
  5577. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  5578. // if (appDelegate.customerInfo) {
  5579. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5580. // if (customer_cid) {
  5581. // [dic setValue:customer_cid forKey:@"contactId"];
  5582. // }
  5583. // }
  5584. if(appDelegate.offline_mode)
  5585. {
  5586. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5587. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5588. dispatch_async(dispatch_get_main_queue(), ^{
  5589. result(json);
  5590. });
  5591. });
  5592. return;
  5593. }
  5594. [self request_interface:URL_EMAIL_WISHLIST parameters:dic err_record_url:nil completionHandler:result retry:0];
  5595. // NSData* json=nil;
  5596. // if(appDelegate.offline_mode)
  5597. // {
  5598. // return [OLDataProvider offline_notimpl];
  5599. // }
  5600. // else
  5601. // {
  5602. // if(![self IsNetworkAvailable])
  5603. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5604. //
  5605. // json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  5606. // }
  5607. // if(json!=nil)
  5608. // {
  5609. // NSError *error=nil;
  5610. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5611. //
  5612. //
  5613. // return jsobj;
  5614. // }
  5615. //
  5616. // return @{@"result" : @(RESULT_FALSE)};
  5617. }
  5618. +(void)request_notifymodel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  5619. {
  5620. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5621. AppDelegate *appDelegate = nil;
  5622. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5623. if(appDelegate.user!=nil)
  5624. [dic setValue:appDelegate.user forKey:@"user"];
  5625. if(appDelegate.password!=nil)
  5626. [dic setValue:appDelegate.password forKey:@"password"];
  5627. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5628. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5629. if (customer_cid) {
  5630. [dic setValue:customer_cid forKey:@"contactId"];
  5631. }
  5632. }
  5633. [dic setObject:screenName forKey:kScreenName];
  5634. [dic setValue:modelID forKey:@"productId"];
  5635. if (addr) { // 弹框输入
  5636. [dic setValue:addr forKey:@"email"];
  5637. } else {
  5638. // employee选择了Contact,并且Contact有Email
  5639. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5640. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  5641. // if (email) {
  5642. // [dic setValue:email forKey:@"email"];
  5643. // }
  5644. // }
  5645. }
  5646. if(appDelegate.offline_mode)
  5647. {
  5648. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5649. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5650. dispatch_async(dispatch_get_main_queue(), ^{
  5651. result(json);
  5652. });
  5653. });
  5654. return;
  5655. }
  5656. [self request_interface:URL_NOTIFY_ME parameters:dic err_record_url:nil completionHandler:result retry:0];
  5657. // NSData* json=nil;
  5658. // if(appDelegate.offline_mode)
  5659. // {
  5660. // return [OLDataProvider offline_notimpl];
  5661. // }
  5662. // else
  5663. // {
  5664. // if(![self IsNetworkAvailable])
  5665. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5666. //
  5667. // json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  5668. // }
  5669. // if(json!=nil)
  5670. // {
  5671. // NSError *error=nil;
  5672. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5673. //
  5674. //
  5675. // return jsobj;
  5676. // }
  5677. //
  5678. // return @{@"result" : @(RESULT_FALSE)};
  5679. }
  5680. + (void)request_qouteorder:(NSString *)so_id emailAddr:(NSString *)addr completionHandler:(resultHandler)result
  5681. {
  5682. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5683. AppDelegate *appDelegate = nil;
  5684. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5685. if(appDelegate.user!=nil)
  5686. [dic setValue:appDelegate.user forKey:@"user"];
  5687. if(appDelegate.password!=nil)
  5688. [dic setValue:appDelegate.password forKey:@"password"];
  5689. [dic setValue:so_id forKey:@"orderCode"];
  5690. [dic setValue:addr forKey:@"email"];
  5691. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5692. if (appDelegate.customerInfo) {
  5693. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5694. if (customer_cid) {
  5695. [dic setValue:customer_cid forKey:@"contactId"];
  5696. }
  5697. }
  5698. if(appDelegate.offline_mode)
  5699. {
  5700. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5701. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5702. dispatch_async(dispatch_get_main_queue(), ^{
  5703. result(json);
  5704. });
  5705. });
  5706. return;
  5707. }
  5708. [self request_interface:URL_EMAIL_CART parameters:dic err_record_url:nil completionHandler:result retry:0];
  5709. // NSData* json=nil;
  5710. // if(appDelegate.offline_mode)
  5711. // {
  5712. // return [OLDataProvider offline_notimpl];
  5713. // }
  5714. // else
  5715. // {
  5716. // if(![self IsNetworkAvailable])
  5717. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5718. //
  5719. // json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  5720. // }
  5721. // if(json!=nil)
  5722. // {
  5723. // NSError *error=nil;
  5724. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5725. //
  5726. //
  5727. // return jsobj;
  5728. // }
  5729. //
  5730. // return @{@"result" : @(RESULT_FALSE)};
  5731. }
  5732. + (void)request_mergeorder:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  5733. {
  5734. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5735. AppDelegate *appDelegate = nil;
  5736. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5737. if(appDelegate.user!=nil)
  5738. [dic setValue:appDelegate.user forKey:@"user"];
  5739. if(appDelegate.password!=nil)
  5740. [dic setValue:appDelegate.password forKey:@"password"];
  5741. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  5742. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  5743. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  5744. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  5745. if(appDelegate.offline_mode)
  5746. {
  5747. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5748. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5749. dispatch_async(dispatch_get_main_queue(), ^{
  5750. result(json);
  5751. });
  5752. });
  5753. return;
  5754. }
  5755. [self request_interface:URL_SET_MERGE_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5756. // NSData* json=nil;
  5757. // if(appDelegate.offline_mode)
  5758. // {
  5759. // return [OLDataProvider offline_notimpl];
  5760. // }
  5761. // else
  5762. // {
  5763. // if(![self IsNetworkAvailable])
  5764. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5765. //
  5766. // json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  5767. // }
  5768. // if(json!=nil)
  5769. // {
  5770. // NSError *error=nil;
  5771. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5772. //
  5773. //
  5774. // return jsobj;
  5775. // }
  5776. // else
  5777. // return nil;
  5778. }
  5779. +(void)request_pendingorder:(NSString *)contactid completionHandler:(resultHandler)result
  5780. {
  5781. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5782. AppDelegate *appDelegate = nil;
  5783. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5784. if(appDelegate.user!=nil)
  5785. [params setValue:appDelegate.user forKey:@"user"];
  5786. // if(appDelegate.contact_id!=nil)
  5787. if(appDelegate.password!=nil)
  5788. [params setValue:appDelegate.password forKey:@"password"];
  5789. [params setValue:contactid forKey:@"contactId"];
  5790. if(appDelegate.offline_mode)
  5791. {
  5792. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5793. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5794. dispatch_async(dispatch_get_main_queue(), ^{
  5795. result(json);
  5796. });
  5797. });
  5798. return;
  5799. }
  5800. [self request_interface:URL_CUSTOMER_PENDINGORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  5801. //
  5802. // if(appDelegate.offline_mode)
  5803. // {
  5804. // return [OLDataProvider offline_notimpl];
  5805. // }
  5806. // if(![self IsNetworkAvailable])
  5807. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5808. //
  5809. // NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  5810. // if(json==nil)
  5811. // return nil;
  5812. // NSError *error=nil;
  5813. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5814. // return jsobj;
  5815. //
  5816. }
  5817. +(void) request_removeportfolio:(NSString* ) item_ids completionHandler:(resultHandler)result
  5818. {
  5819. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5820. AppDelegate *appDelegate = nil;
  5821. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5822. if(appDelegate.user!=nil)
  5823. [params setValue:appDelegate.user forKey:@"user"];
  5824. if(appDelegate.contact_id!=nil)
  5825. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5826. if(appDelegate.password!=nil)
  5827. [params setValue:appDelegate.password forKey:@"password"];
  5828. [params setValue:item_ids forKey:@"portfolioId"];
  5829. // [params setValue:editor forKey:@"editor"];
  5830. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  5831. if(appDelegate.offline_mode)
  5832. {
  5833. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5834. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_removePortfolio:params]] mutableCopy];
  5835. dispatch_async(dispatch_get_main_queue(), ^{
  5836. int result_code = [[resulti valueForKey:@"result"] intValue];
  5837. if (result_code==2)
  5838. {
  5839. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5840. [appDelegate update_count_mark];
  5841. };
  5842. result(resulti);
  5843. });
  5844. });
  5845. return;
  5846. }
  5847. [self request_interface:URL_PORTFOLIO_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5848. int result_code = [[resulti valueForKey:@"result"] intValue];
  5849. if (result_code==2)
  5850. {
  5851. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5852. [appDelegate update_count_mark];
  5853. };
  5854. result(resulti);
  5855. } retry:0];
  5856. // NSData* json = nil;
  5857. // if(appDelegate.offline_mode)
  5858. // {
  5859. // json = [OLDataProvider offline_removePortfolio:params];
  5860. // } else {
  5861. // if(![self IsNetworkAvailable])
  5862. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5863. // json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  5864. // }
  5865. // if(json!=nil)
  5866. // {
  5867. // NSError *error=nil;
  5868. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5869. //
  5870. //
  5871. // int result = [[jsobj valueForKey:@"result"] intValue];
  5872. //
  5873. // if (result==2)
  5874. // {
  5875. //
  5876. //
  5877. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5878. //
  5879. // [appDelegate update_count_mark];
  5880. // }
  5881. // return jsobj;
  5882. // }
  5883. // else
  5884. // return nil;
  5885. }
  5886. +(void) request_removeportfoliopdf:(NSString* ) listid completionHandler:(resultHandler)result
  5887. {
  5888. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5889. AppDelegate *appDelegate = nil;
  5890. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5891. if(appDelegate.user!=nil)
  5892. [params setValue:appDelegate.user forKey:@"user"];
  5893. if(appDelegate.contact_id!=nil)
  5894. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5895. if(appDelegate.password!=nil)
  5896. [params setValue:appDelegate.password forKey:@"password"];
  5897. [params setValue:listid forKey:@"tearsheetsId"];
  5898. // [params setValue:editor forKey:@"editor"];
  5899. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  5900. // [params setValue:@"Delete Portfolio" forKey:kAction];
  5901. if(appDelegate.offline_mode)
  5902. {
  5903. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5904. NSData* json = [[OLDataProvider offline_removePDF:params] mutableCopy];
  5905. dispatch_async(dispatch_get_main_queue(), ^{
  5906. result([[RAConvertor data2dict:json] mutableCopy]);
  5907. });
  5908. });
  5909. return;
  5910. }
  5911. [self request_interface:URL_PORTFOLIOLIST_REMOVE parameters:params err_record_url:nil completionHandler:result retry:0];
  5912. }
  5913. +(void) request_remove_wishlist:(NSString* ) item_ids completionHandler:(resultHandler)result
  5914. {
  5915. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5916. __block AppDelegate *appDelegate = nil;
  5917. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5918. if(appDelegate.user!=nil)
  5919. [params setValue:appDelegate.user forKey:@"user"];
  5920. if(appDelegate.contact_id!=nil)
  5921. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5922. if(appDelegate.password!=nil)
  5923. [params setValue:appDelegate.password forKey:@"password"];
  5924. [params setValue:item_ids forKey:@"collectId"];
  5925. // [params setValue:editor forKey:@"editor"];
  5926. [params setValue:ScreenCodeWishList forKey:kScreenName];
  5927. if(appDelegate.offline_mode)
  5928. {
  5929. // [OLDataProvider offline_deletewishlist:params completionHandler:result];
  5930. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5931. NSMutableDictionary* resulti = [[OLDataProvider offline_deletewishlist:params] mutableCopy];
  5932. dispatch_async(dispatch_get_main_queue(), ^{
  5933. int result_code = [[resulti valueForKey:@"result"] intValue];
  5934. if (result_code==2)
  5935. {
  5936. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  5937. [appDelegate update_count_mark];
  5938. };
  5939. result(resulti);
  5940. });
  5941. });
  5942. return;
  5943. }
  5944. [self request_interface:URL_WATCHLIST_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5945. int result_code = [[resulti valueForKey:@"result"] intValue];
  5946. if (result_code==2)
  5947. {
  5948. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  5949. [appDelegate update_count_mark];
  5950. };
  5951. result(resulti);
  5952. } retry:0];
  5953. //
  5954. //
  5955. // if(appDelegate.offline_mode)
  5956. // {
  5957. // return [OLDataProvider offline_deletewishlist:params];
  5958. // }
  5959. // if(![self IsNetworkAvailable])
  5960. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5961. //
  5962. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  5963. // if(json!=nil)
  5964. // {
  5965. // NSError *error=nil;
  5966. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5967. // int result = [[jsobj valueForKey:@"result"] intValue];
  5968. //
  5969. // if (result==2)
  5970. // {
  5971. //
  5972. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5973. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  5974. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5975. //
  5976. // [appDelegate update_count_mark];
  5977. // }
  5978. // return jsobj;
  5979. // }
  5980. // else
  5981. // return nil;
  5982. }
  5983. +(void) request_remove_cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  5984. {
  5985. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5986. AppDelegate *appDelegate = nil;
  5987. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5988. if(appDelegate.user!=nil)
  5989. [params setValue:appDelegate.user forKey:@"user"];
  5990. if(appDelegate.contact_id!=nil)
  5991. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5992. if(appDelegate.password!=nil)
  5993. [params setValue:appDelegate.password forKey:@"password"];
  5994. if(appDelegate.order_code!=nil)
  5995. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5996. [params setValue:item_ids forKey:@"cartItemId"];
  5997. // [params setValue:editor forKey:@"editor"];
  5998. [params setValue:ScreenCodeCart forKey:kScreenName];
  5999. // [params setValue:@"" forKey:kAction];
  6000. if(appDelegate.offline_mode)
  6001. {
  6002. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6003. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_cartremove:params]] mutableCopy];
  6004. dispatch_async(dispatch_get_main_queue(), ^{
  6005. int result_code = [[resulti valueForKey:@"result"] intValue];
  6006. if (result_code==2)
  6007. {
  6008. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6009. [appDelegate update_count_mark];
  6010. };
  6011. result(resulti);
  6012. });
  6013. });
  6014. return;
  6015. }
  6016. [self request_interface:URL_CART_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6017. int result_code = [[resulti valueForKey:@"result"] intValue];
  6018. if (result_code==2)
  6019. {
  6020. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6021. [appDelegate update_count_mark];
  6022. };
  6023. result(resulti);
  6024. } retry:0];
  6025. //
  6026. // NSData* json=nil;
  6027. // if(appDelegate.offline_mode)
  6028. // {
  6029. // json= [OLDataProvider offline_cartremove:params];
  6030. // }
  6031. // else
  6032. // {
  6033. // if(![self IsNetworkAvailable])
  6034. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6035. //
  6036. // json=[self get_json:URL_CART_REMOVE parameters:params];
  6037. // }
  6038. // if(json!=nil)
  6039. // {
  6040. // NSError *error=nil;
  6041. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6042. //
  6043. // int result = [[jsobj valueForKey:@"result"] intValue];
  6044. //
  6045. // if (result==2)
  6046. // {
  6047. //
  6048. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6049. //
  6050. //
  6051. // [appDelegate update_count_mark];
  6052. // }
  6053. // return jsobj;
  6054. // }
  6055. // else
  6056. // return nil;
  6057. }
  6058. +(void) request_create_order:(resultHandler)result
  6059. {
  6060. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6061. AppDelegate *appDelegate = nil;
  6062. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6063. if(appDelegate.user!=nil)
  6064. [params setValue:appDelegate.user forKey:@"user"];
  6065. if(appDelegate.contact_id!=nil)
  6066. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6067. if(appDelegate.password!=nil)
  6068. [params setValue:appDelegate.password forKey:@"password"];
  6069. if(appDelegate.order_code!=nil)
  6070. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6071. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  6072. NSDictionary* customerinfo= appDelegate.customerInfo;
  6073. NSArray* keys=[customerinfo allKeys];
  6074. for(int i=0;i<keys.count;i++)
  6075. {
  6076. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  6077. }
  6078. if(appDelegate.offline_mode)
  6079. {
  6080. [OLDataProvider offline_createorder:params completionHandler:^(NSMutableDictionary *resulti) {
  6081. int result_code = [[resulti valueForKey:@"result"] intValue];
  6082. if (result_code==2)
  6083. {
  6084. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6085. [appDelegate update_count_mark];
  6086. };
  6087. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  6088. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6089. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  6090. }
  6091. result(resulti);
  6092. }];
  6093. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6094. // NSData* json = [[OLDataProvider offline_createorder:params] mutableCopy];
  6095. // dispatch_async(dispatch_get_main_queue(), ^{
  6096. // result([[RAConvertor data2dict:json] mutableCopy]);
  6097. // });
  6098. // });
  6099. return;
  6100. }
  6101. [self request_interface:URL_NEW_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6102. int result_code = [[resulti valueForKey:@"result"] intValue];
  6103. if (result_code==2)
  6104. {
  6105. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6106. [appDelegate update_count_mark];
  6107. };
  6108. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  6109. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6110. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  6111. }
  6112. result(resulti);
  6113. } retry:0];
  6114. //
  6115. // NSData* json = nil;
  6116. // if(appDelegate.offline_mode)
  6117. // {
  6118. // json= [OLDataProvider offline_createorder:params];
  6119. // }
  6120. // else
  6121. // {
  6122. // if(![self IsNetworkAvailable])
  6123. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6124. //
  6125. // json=[self get_json:URL_NEW_ORDER parameters:params];
  6126. // }
  6127. // if(json==nil)
  6128. // return nil;
  6129. // NSError *error=nil;
  6130. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6131. // int result = [[jsobj valueForKey:@"result"] intValue];
  6132. //
  6133. // if (result==2)
  6134. // {
  6135. //
  6136. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6137. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6138. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6139. //
  6140. // [appDelegate update_count_mark];
  6141. // }
  6142. //
  6143. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  6144. //
  6145. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6146. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  6147. // }
  6148. //
  6149. // return jsobj;
  6150. }
  6151. +(void)request_open_order:(NSString*) order_code completionHandler:(resultHandler)result
  6152. {
  6153. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6154. AppDelegate *appDelegate = nil;
  6155. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6156. if(appDelegate.user!=nil)
  6157. [params setValue:appDelegate.user forKey:@"user"];
  6158. // if(appDelegate.contact_id!=nil)
  6159. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6160. if(appDelegate.password!=nil)
  6161. [params setValue:appDelegate.password forKey:@"password"];
  6162. [params setValue:order_code forKey:@"orderCode"];
  6163. // [params setValue:sourceid forKey:@"sourceid"];
  6164. // [params setValue:editor forKey:@"editor"];
  6165. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  6166. if(appDelegate.offline_mode)
  6167. {
  6168. params[@"appDelegate.order_code"]=appDelegate.order_code;
  6169. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6170. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_editorder:params]] mutableCopy];
  6171. dispatch_async(dispatch_get_main_queue(), ^{
  6172. int result_code = [[resulti valueForKey:@"result"] intValue];
  6173. if (result_code==2)
  6174. {
  6175. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6176. [appDelegate update_count_mark];
  6177. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6178. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  6179. }
  6180. }
  6181. result(resulti);
  6182. });
  6183. });
  6184. return;
  6185. }
  6186. [self request_interface:URL_OPEN_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6187. int result_code = [[resulti valueForKey:@"result"] intValue];
  6188. if (result_code==2)
  6189. {
  6190. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6191. [appDelegate update_count_mark];
  6192. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6193. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  6194. }
  6195. }
  6196. result(resulti);
  6197. } retry:0];
  6198. //
  6199. // NSData* json=nil;
  6200. // if(appDelegate.offline_mode)
  6201. // {
  6202. // json=[OLDataProvider offline_editorder:params];
  6203. //
  6204. // }
  6205. // else
  6206. // {
  6207. // if(![self IsNetworkAvailable])
  6208. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6209. //
  6210. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  6211. // }
  6212. // if(json!=nil)
  6213. // {
  6214. // NSError *error=nil;
  6215. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6216. // int result = [[jsobj valueForKey:@"result"] intValue];
  6217. //
  6218. // if (result==2)
  6219. // {
  6220. //
  6221. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6222. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6223. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6224. //
  6225. // [appDelegate update_count_mark];
  6226. //
  6227. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6228. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  6229. // }
  6230. //
  6231. // }
  6232. //
  6233. // return jsobj;
  6234. // }
  6235. // else
  6236. // return nil;
  6237. }
  6238. +(void)request_cart:(int)sort completionHandler:(resultHandler)result
  6239. {
  6240. DebugLog(@"iSalesNetwork::request_Cart");
  6241. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6242. AppDelegate *appDelegate = nil;
  6243. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6244. if(appDelegate.user!=nil)
  6245. [params setValue:appDelegate.user forKey:@"user"];
  6246. // if(appDelegate.contact_id!=nil)
  6247. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6248. if(appDelegate.password!=nil)
  6249. [params setValue:appDelegate.password forKey:@"password"];
  6250. if(appDelegate.order_code!=nil)
  6251. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6252. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  6253. [params setObject:ScreenCodeCart forKey:kScreenName];
  6254. if(appDelegate.offline_mode)
  6255. {
  6256. [OLDataProvider offline_requestcart:params completionHandler:^(NSMutableDictionary *resulti) {
  6257. if([resulti[@"result"] intValue]==2)
  6258. {
  6259. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6260. [appDelegate update_count_mark];
  6261. result(resulti);
  6262. }
  6263. }];
  6264. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6265. // NSData* json = [[OLDataProvider offline_requestcart:params] mutableCopy];
  6266. // dispatch_async(dispatch_get_main_queue(), ^{
  6267. // result([[RAConvertor data2dict:json] mutableCopy]);
  6268. // });
  6269. // });
  6270. return;
  6271. }
  6272. NSString * uuid= [[NSUUID UUID] UUIDString];
  6273. params[@"resultSerial"]=uuid;
  6274. __block bool bbreak = false;
  6275. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6276. for(int i=0;i<150;i++)
  6277. {
  6278. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6279. // result_params[@"resultSerial"]=uuid;
  6280. if(bbreak)
  6281. break;
  6282. dispatch_async(dispatch_get_main_queue(), ^{
  6283. [self request_interface:URL_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6284. if([resulti[@"result"] intValue]==2)
  6285. {
  6286. if(!bbreak) //此判断保证result只调用一次。
  6287. {
  6288. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6289. [appDelegate update_count_mark];
  6290. result(resulti);
  6291. }
  6292. bbreak=true;
  6293. }
  6294. } retry:3];
  6295. });
  6296. sleep(2);
  6297. // json=[self get_json:URL_CART parameters:params];
  6298. // if(json!=nil)
  6299. // {
  6300. //
  6301. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6302. // if([jsobj[@"result"] intValue]==2)
  6303. // {
  6304. // break;
  6305. // }
  6306. // }
  6307. }
  6308. });
  6309. //
  6310. //
  6311. //
  6312. // NSData* json=nil;
  6313. // if(appDelegate.offline_mode)
  6314. // {
  6315. // json= [OLDataProvider offline_requestcart:params];
  6316. // }
  6317. // else
  6318. // {
  6319. // if(![self IsNetworkAvailable])
  6320. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6321. //
  6322. // NSError *error=nil;
  6323. //
  6324. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6325. // params[@"resultSerial"]=uuid;
  6326. //
  6327. // for(int i=0;i<150;i++)
  6328. // {
  6329. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6330. // // result_params[@"resultSerial"]=uuid;
  6331. // json=[self get_json:URL_CART parameters:params];
  6332. // if(json!=nil)
  6333. // {
  6334. //
  6335. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6336. // if([jsobj[@"result"] intValue]==2)
  6337. // {
  6338. // break;
  6339. // }
  6340. // }
  6341. // sleep(2);
  6342. // }
  6343. //
  6344. // }
  6345. // if(json==nil)
  6346. // return nil;
  6347. // NSError *error=nil;
  6348. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6349. // int result = [[jsobj valueForKey:@"result"] intValue];
  6350. //
  6351. // if (result==2)
  6352. // {
  6353. //
  6354. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6355. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  6356. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6357. //
  6358. // [appDelegate update_count_mark];
  6359. // }
  6360. // return jsobj;
  6361. }
  6362. +(void) request_move_wish2cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  6363. {
  6364. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6365. AppDelegate *appDelegate = nil;
  6366. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6367. if(appDelegate.user!=nil)
  6368. [params setValue:appDelegate.user forKey:@"user"];
  6369. if(appDelegate.contact_id!=nil)
  6370. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6371. if(appDelegate.password!=nil)
  6372. [params setValue:appDelegate.password forKey:@"password"];
  6373. if(appDelegate.order_code!=nil)
  6374. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6375. [params setValue:item_ids forKey:@"collectId"];
  6376. // [params setValue:editor forKey:@"editor"];
  6377. [params setValue:ScreenCodeWishList forKey:kScreenName];
  6378. [params setValue:@"Move To Cart" forKey:kAction];
  6379. if(appDelegate.offline_mode)
  6380. {
  6381. // [OLDataProvider offline_movewish2cart:params completionHandler:result];
  6382. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6383. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6384. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movewish2cart:params]] mutableCopy];
  6385. dispatch_async(dispatch_get_main_queue(), ^{
  6386. int result_code = [[resulti valueForKey:@"result"] intValue];
  6387. if (result_code==2)
  6388. {
  6389. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6390. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6391. [appDelegate update_count_mark];
  6392. }
  6393. result(resulti);
  6394. });
  6395. });
  6396. return;
  6397. }
  6398. [self request_interface:URL_WISH2CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6399. int result_code = [[resulti valueForKey:@"result"] intValue];
  6400. if (result_code==2)
  6401. {
  6402. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6403. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6404. [appDelegate update_count_mark];
  6405. }
  6406. result(resulti);
  6407. } retry:0];
  6408. //
  6409. // NSData *json = nil;
  6410. // if(appDelegate.offline_mode)
  6411. // {
  6412. // json = [OLDataProvider offline_movewish2cart:params];
  6413. // } else {
  6414. // if(![self IsNetworkAvailable])
  6415. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6416. //
  6417. // json=[self get_json:URL_WISH2CART parameters:params];
  6418. // }
  6419. //
  6420. // if(json!=nil)
  6421. // {
  6422. // NSError *error=nil;
  6423. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6424. // int result = [[jsobj valueForKey:@"result"] intValue];
  6425. //
  6426. // if (result==2)
  6427. // {
  6428. //
  6429. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6430. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6431. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6432. //
  6433. // [appDelegate update_count_mark];
  6434. // }
  6435. // return jsobj;
  6436. // }
  6437. // else
  6438. // return nil;
  6439. }
  6440. +(void) request_move_cart2wish:(NSString* ) item_ids completionHandler:(resultHandler)result
  6441. {
  6442. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6443. AppDelegate *appDelegate = nil;
  6444. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6445. if(appDelegate.user!=nil)
  6446. [params setValue:appDelegate.user forKey:@"user"];
  6447. if(appDelegate.contact_id!=nil)
  6448. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6449. if(appDelegate.password!=nil)
  6450. [params setValue:appDelegate.password forKey:@"password"];
  6451. if(appDelegate.order_code!=nil)
  6452. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6453. [params setValue:item_ids forKey:@"cartItemId"];
  6454. // [params setValue:editor forKey:@"editor"];
  6455. [params setValue:ScreenCodeCart forKey:kScreenName];
  6456. // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  6457. if(appDelegate.offline_mode)
  6458. {
  6459. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6460. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movecart2wish:params]] mutableCopy];
  6461. dispatch_async(dispatch_get_main_queue(), ^{
  6462. int result_code = [[resulti valueForKey:@"result"] intValue];
  6463. if (result_code==2)
  6464. {
  6465. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6466. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6467. [appDelegate update_count_mark];
  6468. }
  6469. result(resulti);
  6470. });
  6471. });
  6472. return;
  6473. }
  6474. [self request_interface:URL_CART2WISH parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6475. int result_code = [[resulti valueForKey:@"result"] intValue];
  6476. if (result_code==2)
  6477. {
  6478. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6479. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6480. [appDelegate update_count_mark];
  6481. }
  6482. result(resulti);
  6483. } retry:0];
  6484. //
  6485. // NSData* json = nil;
  6486. // if(appDelegate.offline_mode)
  6487. // {
  6488. // json= [OLDataProvider offline_movecart2wish:params];
  6489. // }
  6490. // else
  6491. // {
  6492. // if(![self IsNetworkAvailable])
  6493. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6494. //
  6495. // json=[self get_json:URL_CART2WISH parameters:params];
  6496. // }
  6497. // if(json!=nil)
  6498. // {
  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:@"wish_count"] intValue];
  6508. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6509. //
  6510. // [appDelegate update_count_mark];
  6511. // }
  6512. // return jsobj;
  6513. // }
  6514. // else
  6515. // return nil;
  6516. }
  6517. +(void)request_orderdetail:(NSMutableDictionary *) params completionHandler:(resultHandler)result
  6518. {
  6519. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6520. if (params == nil) {
  6521. params = [[NSMutableDictionary alloc] init];
  6522. }
  6523. AppDelegate *appDelegate = nil;
  6524. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6525. if(appDelegate.user!=nil)
  6526. [params setValue:appDelegate.user forKey:@"user"];
  6527. if(appDelegate.contact_id!=nil)
  6528. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6529. if(appDelegate.password!=nil)
  6530. [params setValue:appDelegate.password forKey:@"password"];
  6531. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  6532. [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  6533. if(appDelegate.offline_mode)
  6534. {
  6535. params[@"mode"]=appDelegate.mode;
  6536. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6537. NSData* json = [[OLDataProvider offline_orderdetail:params] mutableCopy];
  6538. dispatch_async(dispatch_get_main_queue(), ^{
  6539. result([[RAConvertor data2dict:json] mutableCopy]);
  6540. });
  6541. });
  6542. return;
  6543. }
  6544. NSString * uuid= [[NSUUID UUID] UUIDString];
  6545. params[@"resultSerial"]=uuid;
  6546. __block bool bbreak = false;
  6547. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6548. for(int i=0;i<150;i++)
  6549. {
  6550. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6551. // result_params[@"resultSerial"]=uuid;
  6552. if(bbreak)
  6553. break;
  6554. dispatch_async(dispatch_get_main_queue(), ^{
  6555. [self request_interface:URL_ORDER_DETAIL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6556. if([resulti[@"result"] intValue]==2||[resulti[@"result"] intValue]==8)
  6557. {
  6558. if(!bbreak)//此判断保证result只调用一次。
  6559. result(resulti);
  6560. bbreak=true;
  6561. }
  6562. } retry:3];
  6563. });
  6564. sleep(2);
  6565. }
  6566. });
  6567. //
  6568. // NSData* json=nil;
  6569. // if(appDelegate.offline_mode)
  6570. // {
  6571. // json= [OLDataProvider offline_orderdetail:params];
  6572. // }
  6573. // else
  6574. // {
  6575. // if(![self IsNetworkAvailable])
  6576. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6577. //
  6578. // NSError *error=nil;
  6579. //
  6580. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6581. // params[@"resultSerial"]=uuid;
  6582. //
  6583. // for(int i=0;i<150;i++)
  6584. // {
  6585. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6586. // // result_params[@"resultSerial"]=uuid;
  6587. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  6588. // if(json!=nil)
  6589. // {
  6590. //
  6591. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6592. // int resultCode = [jsobj[@"result"] intValue];
  6593. // if(resultCode==2 || resultCode == 8)
  6594. // {
  6595. // break;
  6596. // }
  6597. // }
  6598. // sleep(2);
  6599. // }
  6600. //
  6601. //
  6602. // }
  6603. // if(json==nil)
  6604. // return nil;
  6605. // NSError *error=nil;
  6606. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6607. // return jsobj;
  6608. }
  6609. //
  6610. //+(void)request_commit_order:(NSString*) order_code completionHandler:(resultHandler)result
  6611. //{
  6612. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6613. // AppDelegate *appDelegate = nil;
  6614. //
  6615. //
  6616. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6617. //
  6618. // if(appDelegate.user!=nil)
  6619. // [params setValue:appDelegate.user forKey:@"user"];
  6620. // if(appDelegate.contact_id!=nil)
  6621. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6622. // if(appDelegate.password!=nil)
  6623. // [params setValue:appDelegate.password forKey:@"password"];
  6624. // // NSString* ssaved = @"false";
  6625. // // if(saved)
  6626. // // ssaved=@"true";
  6627. // [params setValue:@"true" forKey:@"saved"];
  6628. // [params setValue:order_code forKey:@"orderCode"];
  6629. // // [params setValue:sourceid forKey:@"sourceid"];
  6630. // // [params setValue:editor forKey:@"editor"];
  6631. //
  6632. // [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  6633. //
  6634. //
  6635. // if(appDelegate.offline_mode)
  6636. // {
  6637. //
  6638. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6639. // NSMutableDictionary* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  6640. // dispatch_async(dispatch_get_main_queue(), ^{
  6641. // result(json);
  6642. // });
  6643. // });
  6644. //
  6645. // return;
  6646. // }
  6647. //
  6648. //
  6649. // [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6650. //
  6651. //// NSData* json = nil;
  6652. ////
  6653. //// if(appDelegate.offline_mode)
  6654. //// {
  6655. //// json= [OLDataProvider offline_submitorder:params];
  6656. //// }
  6657. //// else
  6658. //// {
  6659. //// if(![self IsNetworkAvailable])
  6660. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6661. ////
  6662. //// json=[self get_json:URL_COMMIT_ORDER parameters:params];
  6663. //// }
  6664. //// if(json!=nil)
  6665. //// {
  6666. //// NSError *error=nil;
  6667. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6668. //// return jsobj;
  6669. //// }
  6670. //// else
  6671. //// return nil;
  6672. //
  6673. //}
  6674. +(void)request_copy_order:(NSString*) order_code completionHandler:(resultHandler)result
  6675. {
  6676. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6677. AppDelegate *appDelegate = nil;
  6678. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6679. if(appDelegate.user!=nil)
  6680. [params setValue:appDelegate.user forKey:@"user"];
  6681. if(appDelegate.contact_id!=nil)
  6682. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6683. if(appDelegate.password!=nil)
  6684. [params setValue:appDelegate.password forKey:@"password"];
  6685. // NSString* ssaved = @"false";
  6686. // if(saved)
  6687. // ssaved=@"true";
  6688. // [params setValue:@"true" forKey:@"saved"];
  6689. [params setValue:order_code forKey:@"code"];
  6690. // [params setValue:sourceid forKey:@"sourceid"];
  6691. // [params setValue:editor forKey:@"editor"];
  6692. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  6693. if(appDelegate.offline_mode)
  6694. {
  6695. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6696. NSData* json = [[OLDataProvider offline_copyorder:params] mutableCopy];
  6697. dispatch_async(dispatch_get_main_queue(), ^{
  6698. result([[RAConvertor data2dict:json] mutableCopy]);
  6699. });
  6700. });
  6701. return;
  6702. }
  6703. [self request_interface:URL_COPY_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6704. // NSData* json=nil;
  6705. // if(appDelegate.offline_mode)
  6706. // {
  6707. // json= [OLDataProvider offline_copyorder:params];
  6708. // }
  6709. // else
  6710. // {
  6711. // if(![self IsNetworkAvailable])
  6712. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6713. //
  6714. // json=[self get_json:URL_COPY_ORDER parameters:params];
  6715. // }
  6716. // if(json!=nil)
  6717. // {
  6718. // NSError *error=nil;
  6719. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6720. // return jsobj;
  6721. // }
  6722. // else
  6723. // return nil;
  6724. }
  6725. //
  6726. //+ (void)request_fastdownload:(NSMutableDictionary *)params url:(NSString *)url completionHandler:(resultHandler)result
  6727. //{
  6728. //
  6729. // //#ifdef test_server
  6730. // // url=URL_REQUEST_RECORDS;
  6731. // // params[@"prefix"]=URL_REQUEST_RECORDS;
  6732. // //#endif
  6733. //
  6734. // [self request_file_fast:url parameters:params completionHandler:result];
  6735. //
  6736. //}
  6737. +(void) request_addto_portfolio:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6738. {
  6739. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6740. AppDelegate *appDelegate = nil;
  6741. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6742. if(appDelegate.user!=nil)
  6743. [params setValue:appDelegate.user forKey:@"user"];
  6744. if(appDelegate.contact_id!=nil)
  6745. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6746. if(appDelegate.password!=nil)
  6747. [params setValue:appDelegate.password forKey:@"password"];
  6748. [params setValue:item_id forKey:@"product_id"];
  6749. [params setObject:screenName forKey:kScreenName];
  6750. if(appDelegate.offline_mode)
  6751. {
  6752. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6753. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_add2Portfolio:params]] mutableCopy];
  6754. dispatch_async(dispatch_get_main_queue(), ^{
  6755. int result_code = [[resulti valueForKey:@"result"] intValue];
  6756. if (result_code==2)
  6757. {
  6758. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6759. [appDelegate update_count_mark];
  6760. }
  6761. result(resulti);
  6762. });
  6763. });
  6764. return;
  6765. }
  6766. [self request_interface:URL_ADD_TO_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6767. int result_code = [[resulti valueForKey:@"result"] intValue];
  6768. if (result_code==2)
  6769. {
  6770. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6771. [appDelegate update_count_mark];
  6772. }
  6773. result(resulti);
  6774. } retry:0];
  6775. //
  6776. // NSData* json = nil;
  6777. // if(appDelegate.offline_mode)
  6778. // {
  6779. // json = [OLDataProvider offline_add2Portfolio:params];
  6780. // } else {
  6781. // if(![self IsNetworkAvailable])
  6782. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6783. //
  6784. // json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  6785. // }
  6786. //
  6787. // if(json==nil)
  6788. // return nil;
  6789. // NSError *error=nil;
  6790. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6791. // int result = [[jsobj valueForKey:@"result"] intValue];
  6792. //
  6793. // if (result==2)
  6794. // {
  6795. //
  6796. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6797. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6798. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6799. //
  6800. // [appDelegate update_count_mark];
  6801. // }
  6802. // return jsobj;
  6803. }
  6804. +(void)request_addall_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  6805. {
  6806. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6807. AppDelegate *appDelegate = nil;
  6808. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6809. if(appDelegate.user!=nil)
  6810. [params setValue:appDelegate.user forKey:@"user"];
  6811. if(appDelegate.contact_id!=nil)
  6812. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6813. if(appDelegate.password!=nil)
  6814. [params setValue:appDelegate.password forKey:@"password"];
  6815. if(appDelegate.order_code!=nil)
  6816. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6817. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6818. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6819. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  6820. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6821. // [params setValue:filter forKey:@"filter"];
  6822. [params setValue:keywords forKey:@"keyword"];
  6823. [params setValue:addTo forKey:@"addTo"];
  6824. [params setValue:orderCode forKey:@"orderCode"];
  6825. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6826. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6827. if(matchfull)
  6828. [params setValue:@"true" forKey:@"exactMatch"];
  6829. else
  6830. [params setValue:@"false" forKey:@"exactMatch"];
  6831. [params setObject:ScreenCodeSearch forKey:kScreenName];
  6832. if ([addTo isEqualToString:@"cart"]) {
  6833. [params setObject:@"Add To Cart" forKey:kAction];
  6834. }
  6835. if(appDelegate.offline_mode)
  6836. {
  6837. if ([addTo isEqualToString:@"cart"])
  6838. {
  6839. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6840. }
  6841. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6842. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_searchaddall:params]] mutableCopy];
  6843. dispatch_async(dispatch_get_main_queue(), ^{
  6844. int result_code =[json[@"result"] intValue];
  6845. if (result_code==2||result_code==8)
  6846. {
  6847. if(json[@"cart_count"])
  6848. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6849. if(json[@"wish_count"])
  6850. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  6851. if(json[@"portfolio_count"])
  6852. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  6853. //
  6854. //
  6855. [appDelegate update_count_mark];
  6856. }
  6857. result(json);
  6858. });
  6859. });
  6860. return;
  6861. }
  6862. NSString * uuid= [[NSUUID UUID] UUIDString];
  6863. params[@"resultSerial"]=uuid;
  6864. __block bool bbreak = false;
  6865. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6866. for(int i=0;i<150;i++)
  6867. {
  6868. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6869. // result_params[@"resultSerial"]=uuid;
  6870. if(bbreak)
  6871. break;
  6872. dispatch_async(dispatch_get_main_queue(), ^{
  6873. [self request_interface:URL_SEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6874. if([resulti[@"result"] intValue]==2)
  6875. {
  6876. if(!bbreak)//此判断保证result只调用一次。
  6877. result(resulti);
  6878. bbreak=true;
  6879. }
  6880. } retry:3];
  6881. });
  6882. sleep(2);
  6883. }
  6884. });
  6885. //
  6886. //
  6887. // NSData* json=nil;
  6888. // if(appDelegate.offline_mode)
  6889. // {
  6890. // json=[OLDataProvider offline_searchaddall:params];
  6891. // }
  6892. // else
  6893. // {
  6894. // if(![self IsNetworkAvailable])
  6895. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6896. //
  6897. // NSError *error=nil;
  6898. //
  6899. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6900. // params[@"resultSerial"]=uuid;
  6901. //
  6902. // for(int i=0;i<150;i++)
  6903. // {
  6904. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6905. // // result_params[@"resultSerial"]=uuid;
  6906. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  6907. // if(json!=nil)
  6908. // {
  6909. //
  6910. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6911. // if([jsobj[@"result"] intValue]==2)
  6912. // {
  6913. // break;
  6914. // }
  6915. // }
  6916. // sleep(2);
  6917. // }
  6918. // }
  6919. // if(json==nil)
  6920. // return nil;
  6921. // NSError *error=nil;
  6922. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6923. // return jsobj;
  6924. }
  6925. +(void) request_addto_cart_byupc:(NSString* ) upc_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6926. {
  6927. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6928. AppDelegate *appDelegate = nil;
  6929. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6930. if(appDelegate.user!=nil)
  6931. [params setValue:appDelegate.user forKey:@"user"];
  6932. if(appDelegate.contact_id!=nil)
  6933. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6934. if(appDelegate.password!=nil)
  6935. [params setValue:appDelegate.password forKey:@"password"];
  6936. if(appDelegate.order_code!=nil)
  6937. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6938. [params setValue:upc_code forKey:@"upc_code"];
  6939. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  6940. [params setObject:screenName forKey:kScreenName];
  6941. [params setObject:@"Add To Cart" forKey:kAction];
  6942. if (!upc_code) {
  6943. upc_code = @"";
  6944. }
  6945. [params setObject:@{@"UPCCode" : upc_code} forKey:kExtra];
  6946. params[@"search_upc"]=@true;
  6947. NSDictionary* customerinfo= appDelegate.customerInfo;
  6948. NSArray* keys=[customerinfo allKeys];
  6949. for(int i=0;i<keys.count;i++)
  6950. {
  6951. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  6952. }
  6953. if(appDelegate.offline_mode)
  6954. {
  6955. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6956. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  6957. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6958. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyname:params]] mutableCopy];
  6959. dispatch_async(dispatch_get_main_queue(), ^{
  6960. int result_code = [[json valueForKey:@"result"] intValue];
  6961. if (result_code==2||result_code==8)
  6962. {
  6963. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6964. [appDelegate update_count_mark];
  6965. }
  6966. result(json);
  6967. });
  6968. });
  6969. return;
  6970. }
  6971. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6972. int result_code = [[resulti valueForKey:@"result"] intValue];
  6973. if (result_code==2||result_code==8)
  6974. {
  6975. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6976. [appDelegate update_count_mark];
  6977. }
  6978. result(resulti);
  6979. } retry:0];
  6980. }
  6981. +(void) request_addto_cart_byname:(NSString* ) model_name withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6982. {
  6983. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6984. AppDelegate *appDelegate = nil;
  6985. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6986. if(appDelegate.user!=nil)
  6987. [params setValue:appDelegate.user forKey:@"user"];
  6988. if(appDelegate.contact_id!=nil)
  6989. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6990. if(appDelegate.password!=nil)
  6991. [params setValue:appDelegate.password forKey:@"password"];
  6992. if(appDelegate.order_code!=nil)
  6993. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6994. [params setValue:model_name forKey:@"product_name"];
  6995. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  6996. [params setObject:screenName forKey:kScreenName];
  6997. [params setObject:@"Add To Cart" forKey:kAction];
  6998. if (!model_name) {
  6999. model_name = @"";
  7000. }
  7001. [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  7002. NSDictionary* customerinfo= appDelegate.customerInfo;
  7003. NSArray* keys=[customerinfo allKeys];
  7004. for(int i=0;i<keys.count;i++)
  7005. {
  7006. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7007. }
  7008. if(appDelegate.offline_mode)
  7009. {
  7010. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7011. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  7012. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7013. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyname:params]] mutableCopy];
  7014. dispatch_async(dispatch_get_main_queue(), ^{
  7015. int result_code = [[json valueForKey:@"result"] intValue];
  7016. if (result_code==2||result_code==8)
  7017. {
  7018. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7019. [appDelegate update_count_mark];
  7020. }
  7021. result(json);
  7022. });
  7023. });
  7024. return;
  7025. }
  7026. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7027. int result_code = [[resulti valueForKey:@"result"] intValue];
  7028. if (result_code==2||result_code==8)
  7029. {
  7030. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7031. [appDelegate update_count_mark];
  7032. }
  7033. result(resulti);
  7034. } retry:0];
  7035. // NSData* json=nil;
  7036. // if(appDelegate.offline_mode)
  7037. // {
  7038. // json= [OLDataProvider offline_add2cartbyname:params];
  7039. // }
  7040. // else
  7041. // {
  7042. // if(![self IsNetworkAvailable])
  7043. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7044. //
  7045. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  7046. // }
  7047. // if(json==nil)
  7048. // return nil;
  7049. // NSError *error=nil;
  7050. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7051. //
  7052. //
  7053. //
  7054. // int result = [[jsobj valueForKey:@"result"] intValue];
  7055. //
  7056. // if (result==2||result==8)
  7057. // {
  7058. //
  7059. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  7060. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  7061. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  7062. //
  7063. // [appDelegate update_count_mark];
  7064. // }
  7065. //
  7066. // return jsobj;
  7067. }
  7068. +(void) request_addto_wishlist:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  7069. {
  7070. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7071. AppDelegate *appDelegate = nil;
  7072. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7073. if(appDelegate.user!=nil)
  7074. [params setValue:appDelegate.user forKey:@"user"];
  7075. if(appDelegate.contact_id!=nil)
  7076. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7077. if(appDelegate.password!=nil)
  7078. [params setValue:appDelegate.password forKey:@"password"];
  7079. [params setValue:item_id forKey:@"product_id"];
  7080. [params setObject:screenName forKey:kScreenName];
  7081. if(appDelegate.offline_mode)
  7082. {
  7083. // [OLDataProvider offline_add2wishlist:params completionHandler:result];
  7084. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7085. NSMutableDictionary* resulti = [[OLDataProvider offline_add2wishlist:params] mutableCopy];
  7086. dispatch_async(dispatch_get_main_queue(), ^{
  7087. int result_code = [[resulti valueForKey:@"result"] intValue];
  7088. if (result_code==2||result_code==8)
  7089. {
  7090. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7091. [appDelegate update_count_mark];
  7092. }
  7093. result(resulti);
  7094. });
  7095. });
  7096. return;
  7097. }
  7098. [self request_interface:URL_ADD_TO_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7099. int result_code = [[resulti valueForKey:@"result"] intValue];
  7100. if (result_code==2||result_code==8)
  7101. {
  7102. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7103. [appDelegate update_count_mark];
  7104. }
  7105. result(resulti);
  7106. } retry:0];
  7107. // if(appDelegate.offline_mode)
  7108. // {
  7109. // return [OLDataProvider offline_add2wishlist:params];
  7110. // }
  7111. // if(![self IsNetworkAvailable])
  7112. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7113. //
  7114. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  7115. // if(json==nil)
  7116. // return nil;
  7117. // NSError *error=nil;
  7118. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7119. // int result = [[jsobj valueForKey:@"result"] intValue];
  7120. //
  7121. // if (result==2)
  7122. // {
  7123. //
  7124. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  7125. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  7126. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  7127. //
  7128. // [appDelegate update_count_mark];
  7129. // }
  7130. // return jsobj;
  7131. }
  7132. +(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
  7133. {
  7134. // for debug
  7135. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  7136. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7137. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7138. AppDelegate *appDelegate = nil;
  7139. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7140. if(appDelegate.user!=nil)
  7141. [params setValue:appDelegate.user forKey:@"user"];
  7142. if(appDelegate.contact_id!=nil)
  7143. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7144. if(appDelegate.password!=nil)
  7145. [params setValue:appDelegate.password forKey:@"password"];
  7146. if(appDelegate.order_code!=nil)
  7147. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7148. [params setValue:addTo forKey:@"addTo"];
  7149. [params setValue:orderCode forKey:@"orderCode"];
  7150. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7151. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7152. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  7153. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7154. // [params setValue:filter forKey:@"filter"];
  7155. [params setValue:covertype forKey:@"covertype"];
  7156. [params setValue:ctgid forKey:@"ctgId"];
  7157. [params setValue:modelname forKey:@"modelName"];
  7158. [params setValue:modeldescrip forKey:@"modelDescription"];
  7159. [params setValue:alert forKey:@"alert"];
  7160. [params setValue:qty forKey:@"sold_by_qty"];
  7161. [params setValue:available forKey:@"available"];
  7162. [params setValue:price forKey:@"price"];
  7163. [params setValue:bestseller forKey:@"bestseller"];
  7164. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7165. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7166. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  7167. if ([addTo isEqualToString:@"cart"]) {
  7168. [params setObject:@"Add To Cart" forKey:kAction];
  7169. }
  7170. if(appDelegate.offline_mode)
  7171. {
  7172. if ([addTo isEqualToString:@"cart"])
  7173. {
  7174. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7175. }
  7176. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7177. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_itemsearchaddall:params]] mutableCopy];
  7178. dispatch_async(dispatch_get_main_queue(), ^{
  7179. int result_code =[json[@"result"] intValue];
  7180. if (result_code==2||result_code==8)
  7181. {
  7182. if(json[@"cart_count"])
  7183. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7184. if(json[@"wish_count"])
  7185. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7186. if(json[@"portfolio_count"])
  7187. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7188. //
  7189. //
  7190. [appDelegate update_count_mark];
  7191. }
  7192. result(json);
  7193. });
  7194. });
  7195. return;
  7196. }
  7197. NSString * uuid= [[NSUUID UUID] UUIDString];
  7198. params[@"resultSerial"]=uuid;
  7199. __block bool bbreak = false;
  7200. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7201. for(int i=0;i<150;i++)
  7202. {
  7203. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7204. // result_params[@"resultSerial"]=uuid;
  7205. if(bbreak)
  7206. break;
  7207. dispatch_async(dispatch_get_main_queue(), ^{
  7208. [self request_interface:URL_ITEMSEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7209. if([resulti[@"result"] intValue]==2)
  7210. {
  7211. if(!bbreak)//此判断保证result只调用一次。
  7212. result(resulti);
  7213. bbreak=true;
  7214. }
  7215. } retry:3];
  7216. });
  7217. sleep(2);
  7218. }
  7219. });
  7220. //
  7221. // NSData* json = nil;
  7222. //
  7223. // if(appDelegate.offline_mode)
  7224. // {
  7225. // json= [OLDataProvider offline_itemsearchaddall:params];
  7226. // }
  7227. // else
  7228. // {
  7229. // if(![self IsNetworkAvailable])
  7230. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7231. // NSError *error=nil;
  7232. //
  7233. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7234. // params[@"resultSerial"]=uuid;
  7235. //
  7236. // for(int i=0;i<150;i++)
  7237. // {
  7238. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7239. // // result_params[@"resultSerial"]=uuid;
  7240. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  7241. // if(json!=nil)
  7242. // {
  7243. //
  7244. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7245. // if([jsobj[@"result"] intValue]==2)
  7246. // {
  7247. // break;
  7248. // }
  7249. // }
  7250. // sleep(2);
  7251. // }
  7252. // }
  7253. // if(json==nil)
  7254. // return nil;
  7255. // NSError *error=nil;
  7256. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7257. // return jsobj;
  7258. }
  7259. +(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
  7260. {
  7261. AppDelegate *appDelegate = nil;
  7262. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7263. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7264. if(appDelegate.user!=nil)
  7265. [params setValue:appDelegate.user forKey:@"user"];
  7266. if(appDelegate.contact_id!=nil)
  7267. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7268. if(appDelegate.password!=nil)
  7269. [params setValue:appDelegate.password forKey:@"password"];
  7270. if(appDelegate.order_code!=nil)
  7271. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7272. [params setValue:addTo forKey:@"addTo"];
  7273. [params setValue:orderCode forKey:@"orderCode"];
  7274. [params setValue:alert forKey:@"alert"];
  7275. [params setValue:qty forKey:@"sold_by_qty"];
  7276. [params setValue:available forKey:@"available"];
  7277. [params setValue:price forKey:@"price"];
  7278. [params setValue:bestseller forKey:@"bestseller"];
  7279. [params setValue:modelname forKey:@"modelName"];
  7280. [params setValue:modeldescrip forKey:@"modelDescription"];
  7281. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7282. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7283. [params setValue:category forKey:@"category"];
  7284. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7285. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7286. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7287. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7288. [params setValue:filter forKey:@"filter"];
  7289. [params setValue:keyword forKey:@"keyword"];
  7290. [params setObject:ScreenCodeCategory forKey:kScreenName];
  7291. if ([addTo isEqualToString:@"cart"]) {
  7292. [params setObject:@"Add To Cart" forKey:kAction];
  7293. }
  7294. if(appDelegate.offline_mode)
  7295. {
  7296. if ([addTo isEqualToString:@"cart"])
  7297. {
  7298. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7299. }
  7300. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7301. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_categoryaddall:params]] mutableCopy];
  7302. dispatch_async(dispatch_get_main_queue(), ^{
  7303. int result_code =[json[@"result"] intValue];
  7304. if (result_code==2||result_code==8)
  7305. {
  7306. if(json[@"cart_count"])
  7307. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7308. if(json[@"wish_count"])
  7309. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7310. if(json[@"portfolio_count"])
  7311. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7312. //
  7313. //
  7314. [appDelegate update_count_mark];
  7315. }
  7316. result(json);
  7317. });
  7318. });
  7319. return;
  7320. }
  7321. NSString * uuid= [[NSUUID UUID] UUIDString];
  7322. params[@"resultSerial"]=uuid;
  7323. __block bool bbreak = false;
  7324. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7325. for(int i=0;i<150;i++)
  7326. {
  7327. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7328. // result_params[@"resultSerial"]=uuid;
  7329. if(bbreak)
  7330. break;
  7331. dispatch_async(dispatch_get_main_queue(), ^{
  7332. [self request_interface:URL_CATEGORYADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7333. if([resulti[@"result"] intValue]==2|| [resulti[@"result"] intValue] == 8)
  7334. {
  7335. if(!bbreak)//此判断保证result只调用一次。
  7336. {
  7337. int result_code =[resulti[@"result"] intValue];
  7338. if (result_code==2||result_code==8)
  7339. {
  7340. if(resulti[@"cart_count"])
  7341. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7342. if(resulti[@"wish_count"])
  7343. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7344. if(resulti[@"portfolio_count"])
  7345. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  7346. //
  7347. //
  7348. [appDelegate update_count_mark];
  7349. }
  7350. result(resulti);
  7351. }
  7352. bbreak=true;
  7353. }
  7354. } retry:3];
  7355. });
  7356. sleep(2);
  7357. }
  7358. });
  7359. //
  7360. // NSData* json= nil;
  7361. //
  7362. // if(appDelegate.offline_mode)
  7363. // {
  7364. // json= [OLDataProvider offline_categoryaddall:params];
  7365. // }
  7366. // else
  7367. // {
  7368. // if(![self IsNetworkAvailable])
  7369. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7370. //
  7371. //
  7372. // NSError *error=nil;
  7373. //
  7374. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7375. // params[@"resultSerial"]=uuid;
  7376. //
  7377. // for(int i=0;i<150;i++)
  7378. // {
  7379. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7380. //// result_params[@"resultSerial"]=uuid;
  7381. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  7382. // if(json!=nil)
  7383. // {
  7384. //
  7385. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7386. // int resultInt = [jsobj[@"result"] intValue];
  7387. // if(resultInt == 2 || resultInt == 8)
  7388. // {
  7389. // break;
  7390. // }
  7391. // }
  7392. // sleep(2);
  7393. // }
  7394. //
  7395. //
  7396. //
  7397. // }
  7398. // if(json==nil)
  7399. // return nil;
  7400. // NSError *error=nil;
  7401. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7402. // return jsobj;
  7403. }
  7404. +(void)request_save_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7405. {
  7406. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7407. AppDelegate *appDelegate = nil;
  7408. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7409. if(appDelegate.user!=nil)
  7410. [params setValue:appDelegate.user forKey:@"user"];
  7411. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  7412. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7413. // else
  7414. if(appDelegate.contact_id!=nil)
  7415. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7416. if(appDelegate.password!=nil)
  7417. [params setValue:appDelegate.password forKey:@"password"];
  7418. if(appDelegate.order_code!=nil)
  7419. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7420. // NSDictionary* customerinfo=nil;
  7421. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  7422. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7423. // else
  7424. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7425. //
  7426. // appDelegate.customerInfo;
  7427. // NSArray* keys=[customerinfo allKeys];
  7428. // for(int i=0;i<keys.count;i++)
  7429. // {
  7430. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7431. // }
  7432. // [params setValue:sourceid forKey:@"sourceid"];
  7433. // [params setValue:editor forKey:@"editor"];
  7434. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  7435. if(appDelegate.offline_mode)
  7436. {
  7437. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7438. NSData* json = [[OLDataProvider offline_saveorder:params] mutableCopy];
  7439. dispatch_async(dispatch_get_main_queue(), ^{
  7440. result([[RAConvertor data2dict:json] mutableCopy]);
  7441. });
  7442. });
  7443. return;
  7444. }
  7445. [self request_interface:URL_SAVE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  7446. //
  7447. // NSData* json=nil;
  7448. //
  7449. // if(appDelegate.offline_mode)
  7450. // {
  7451. // json= [OLDataProvider offline_saveorder:params];
  7452. // }
  7453. // else
  7454. // {
  7455. // if(![self IsNetworkAvailable])
  7456. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7457. //
  7458. // json=[self get_json:URL_SAVE_ORDER parameters:params];
  7459. // }
  7460. // if(json!=nil)
  7461. // {
  7462. // NSError *error=nil;
  7463. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7464. // NSString *so = [jsobj valueForKey:@"so#"];
  7465. // if (so) {
  7466. // [appDelegate SetSo:so];
  7467. // }
  7468. // return jsobj;
  7469. // }
  7470. // else
  7471. // return nil;
  7472. }
  7473. +(void) request_update_cartqty:(NSString*) cart_id value:(int) value completionHandler:(resultHandler)result
  7474. {
  7475. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7476. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  7477. if(appDelegate.user!=nil)
  7478. [params setValue:appDelegate.user forKey:@"user"];
  7479. if(appDelegate.contact_id!=nil)
  7480. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7481. if(appDelegate.password!=nil)
  7482. [params setValue:appDelegate.password forKey:@"password"];
  7483. [params setValue:cart_id forKey:@"cartitem_id"];
  7484. [params setObject:ScreenCodeCart forKey:kScreenName];
  7485. [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  7486. if(appDelegate.offline_mode)
  7487. {
  7488. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7489. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7490. NSData* json = [[OLDataProvider offline_cartsetqty:params] mutableCopy];
  7491. dispatch_async(dispatch_get_main_queue(), ^{
  7492. result([[RAConvertor data2dict:json] mutableCopy]);
  7493. });
  7494. });
  7495. return;
  7496. }
  7497. [self request_interface:URL_CART_INCRESEMENT parameters:params err_record_url:nil completionHandler:result retry:0];
  7498. //
  7499. // NSData* json=nil;
  7500. // if(appDelegate.offline_mode)
  7501. // {
  7502. // json= [OLDataProvider offline_cartsetqty:params];
  7503. // }
  7504. // else
  7505. // {
  7506. // if(![self IsNetworkAvailable])
  7507. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7508. //
  7509. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  7510. // }
  7511. // if(json==nil)
  7512. // return nil;
  7513. // NSError *error=nil;
  7514. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7515. // return jsobj;
  7516. }
  7517. +(void) request_update_cartgeneralnote:(NSString*) order_code notes:(NSString*) notes completionHandler:(resultHandler)result
  7518. {
  7519. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7520. AppDelegate *appDelegate = nil;
  7521. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7522. if(appDelegate.user!=nil)
  7523. [params setValue:appDelegate.user forKey:@"user"];
  7524. if(appDelegate.contact_id!=nil)
  7525. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7526. if(appDelegate.password!=nil)
  7527. [params setValue:appDelegate.password forKey:@"password"];
  7528. [params setValue:order_code forKey:@"orderCode"];
  7529. [params setObject:ScreenCodeCart forKey:kScreenName];
  7530. if(notes.length==0)
  7531. notes=@"";
  7532. [params setValue:notes forKey:@"comments"];
  7533. if(appDelegate.offline_mode)
  7534. {
  7535. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7536. NSData* json = [[OLDataProvider offline_updategnotes:params] mutableCopy];
  7537. dispatch_async(dispatch_get_main_queue(), ^{
  7538. result([[RAConvertor data2dict:json] mutableCopy]);
  7539. });
  7540. });
  7541. return;
  7542. }
  7543. [self request_interface:URL_CART_GENERAL_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7544. //
  7545. // NSData* json=nil;
  7546. // if(appDelegate.offline_mode)
  7547. // {
  7548. // json= [OLDataProvider offline_updategnotes:params];
  7549. // }
  7550. // else
  7551. // {
  7552. // if(![self IsNetworkAvailable])
  7553. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7554. //
  7555. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  7556. // }
  7557. // if(json==nil)
  7558. // return nil;
  7559. // NSError *error=nil;
  7560. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7561. // return jsobj;
  7562. }
  7563. +(void) request_update_cartitemnote:(NSString*) cart_id notes:(NSString*) notes completionHandler:(resultHandler)result
  7564. {
  7565. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7566. AppDelegate *appDelegate = nil;
  7567. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7568. if(appDelegate.user!=nil)
  7569. [params setValue:appDelegate.user forKey:@"user"];
  7570. if(appDelegate.contact_id!=nil)
  7571. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7572. if(appDelegate.password!=nil)
  7573. [params setValue:appDelegate.password forKey:@"password"];
  7574. [params setValue:cart_id forKey:@"cartitem_id"];
  7575. [params setObject:ScreenCodeCart forKey:kScreenName];
  7576. if(notes.length==0)
  7577. notes=@"";
  7578. [params setValue:notes forKey:@"notes"];
  7579. if(appDelegate.offline_mode)
  7580. {
  7581. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7582. NSData* json = [[OLDataProvider offline_cartsetlnotes:params] mutableCopy];
  7583. dispatch_async(dispatch_get_main_queue(), ^{
  7584. result([[RAConvertor data2dict:json] mutableCopy]);
  7585. });
  7586. });
  7587. return;
  7588. }
  7589. [self request_interface:URL_CART_ITEM_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7590. //
  7591. // NSData* json=nil;
  7592. // if(appDelegate.offline_mode)
  7593. // {
  7594. // json= [OLDataProvider offline_cartsetlnotes:params];
  7595. // }
  7596. // else
  7597. // {
  7598. // if(![self IsNetworkAvailable])
  7599. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7600. //
  7601. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  7602. // }
  7603. // if(json==nil)
  7604. // return nil;
  7605. // NSError *error=nil;
  7606. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7607. // return jsobj;
  7608. }
  7609. + (void)request_update_npd_shop_price_type:(NSInteger)priceType completionHandler:(resultHandler)result
  7610. {
  7611. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7612. AppDelegate *appDelegate = nil;
  7613. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7614. if(appDelegate.user!=nil)
  7615. [dic setValue:appDelegate.user forKey:@"user"];
  7616. if(appDelegate.password!=nil)
  7617. [dic setValue:appDelegate.password forKey:@"password"];
  7618. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  7619. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  7620. if(appDelegate.offline_mode)
  7621. {
  7622. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7623. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7624. dispatch_async(dispatch_get_main_queue(), ^{
  7625. result(json);
  7626. });
  7627. });
  7628. return;
  7629. }
  7630. [self request_interface:URL_SET_PRICE_TYPE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7631. //
  7632. // NSData* json=nil;
  7633. // if(appDelegate.offline_mode)
  7634. // {
  7635. // return [OLDataProvider offline_notimpl];
  7636. // }
  7637. // else
  7638. // {
  7639. // if(![self IsNetworkAvailable])
  7640. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7641. //
  7642. // json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  7643. // }
  7644. // if(json!=nil)
  7645. // {
  7646. // NSError *error=nil;
  7647. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7648. //
  7649. //
  7650. // return jsobj;
  7651. // }
  7652. //
  7653. //
  7654. // return nil;
  7655. }
  7656. + (void)request_npd_shop_givenprice:(resultHandler)result
  7657. {
  7658. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7659. AppDelegate *appDelegate = nil;
  7660. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7661. if(appDelegate.user!=nil)
  7662. [dic setValue:appDelegate.user forKey:@"user"];
  7663. if(appDelegate.password!=nil)
  7664. [dic setValue:appDelegate.password forKey:@"password"];
  7665. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  7666. if(appDelegate.offline_mode)
  7667. {
  7668. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7669. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7670. dispatch_async(dispatch_get_main_queue(), ^{
  7671. result(json);
  7672. });
  7673. });
  7674. return;
  7675. }
  7676. [self request_interface:URL_GET_CIVEN_PRICE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7677. //
  7678. // NSData* json=nil;
  7679. // if(appDelegate.offline_mode)
  7680. // {
  7681. // return [OLDataProvider offline_notimpl];
  7682. // }
  7683. // else
  7684. // {
  7685. // if(![self IsNetworkAvailable])
  7686. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7687. //
  7688. // json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  7689. // }
  7690. // if(json!=nil)
  7691. // {
  7692. // NSError *error=nil;
  7693. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7694. //
  7695. //
  7696. // return jsobj;
  7697. // }
  7698. //
  7699. //
  7700. // return nil;
  7701. }
  7702. + (void)request_update_npd_shop_givenprice:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  7703. {
  7704. AppDelegate *appDelegate = nil;
  7705. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7706. if(appDelegate.user!=nil)
  7707. [params setValue:appDelegate.user forKey:@"user"];
  7708. if(appDelegate.password!=nil)
  7709. [params setValue:appDelegate.password forKey:@"password"];
  7710. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  7711. if(appDelegate.offline_mode)
  7712. {
  7713. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7714. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7715. dispatch_async(dispatch_get_main_queue(), ^{
  7716. result(json);
  7717. });
  7718. });
  7719. return;
  7720. }
  7721. [self request_interface:URL_SET_GIVEN_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  7722. //
  7723. // NSData* json=nil;
  7724. // if(appDelegate.offline_mode)
  7725. // {
  7726. // return [OLDataProvider offline_notimpl];
  7727. // }
  7728. // else
  7729. // {
  7730. // if(![self IsNetworkAvailable])
  7731. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7732. //
  7733. // json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  7734. // }
  7735. // if(json!=nil)
  7736. // {
  7737. // NSError *error=nil;
  7738. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7739. //
  7740. //
  7741. // return jsobj;
  7742. // }
  7743. //
  7744. //
  7745. // return nil;
  7746. }
  7747. +(void) request_create_portfolio:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7748. {
  7749. AppDelegate *appDelegate = nil;
  7750. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7751. if(appDelegate.offline_mode)
  7752. {
  7753. params[@"contact_id"]=params[@"contactId"];
  7754. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7755. NSData* json = [[OLDataProvider offline_direct_save_TearSheet:params] mutableCopy];
  7756. dispatch_async(dispatch_get_main_queue(), ^{
  7757. result([[RAConvertor data2dict:json] mutableCopy]);
  7758. });
  7759. });
  7760. return;
  7761. }
  7762. //
  7763. // if(appDelegate.offline_mode)
  7764. // {
  7765. //
  7766. //
  7767. // NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  7768. // if(json==nil)
  7769. // return nil;
  7770. // NSError *error=nil;
  7771. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7772. //
  7773. // return jsobj[@"pdf_path"];
  7774. // }
  7775. // else
  7776. // {
  7777. // return nil;
  7778. // }
  7779. }
  7780. +(void)request_save_portfoliodirectly:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7781. {
  7782. NSMutableDictionary* off_params = [params mutableCopy];;
  7783. params[@"off_params"]=[RAConvertor dict2string:off_params];;
  7784. AppDelegate *appDelegate = nil;
  7785. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7786. if(appDelegate.user!=nil)
  7787. [params setValue:appDelegate.user forKey:@"user"];
  7788. if(appDelegate.contact_id!=nil)
  7789. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7790. if(appDelegate.password!=nil)
  7791. [params setValue:appDelegate.password forKey:@"password"];
  7792. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7793. if(appDelegate.offline_mode)
  7794. {
  7795. params[@"contact_id"]=appDelegate.contact_id;
  7796. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7797. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_direct_save_TearSheet:params]] mutableCopy];
  7798. dispatch_async(dispatch_get_main_queue(), ^{
  7799. result(json);
  7800. });
  7801. });
  7802. return;
  7803. }
  7804. NSString * uuid= [[NSUUID UUID] UUIDString];
  7805. params[@"resultSerial"]=uuid;
  7806. __block bool bbreak = false;
  7807. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7808. for(int i=0;i<150;i++)
  7809. {
  7810. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7811. // result_params[@"resultSerial"]=uuid;
  7812. if(bbreak)
  7813. break;
  7814. dispatch_async(dispatch_get_main_queue(), ^{
  7815. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7816. if([resulti[@"result"] intValue]==2)
  7817. {
  7818. if(!bbreak)//此判断保证result只调用一次。
  7819. result(resulti);
  7820. bbreak=true;
  7821. }
  7822. } retry:3];
  7823. });
  7824. sleep(2);
  7825. }
  7826. });
  7827. //
  7828. //
  7829. // NSData* json= nil;
  7830. //
  7831. // if(appDelegate.offline_mode)
  7832. // {
  7833. // json = [OLDataProvider offline_direct_save_TearSheet:params];
  7834. // }
  7835. // else
  7836. // {
  7837. // if(![self IsNetworkAvailable])
  7838. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7839. //
  7840. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7841. //
  7842. // NSError *error=nil;
  7843. //
  7844. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7845. // params[@"resultSerial"]=uuid;
  7846. //
  7847. // for(int i=0;i<150;i++)
  7848. // {
  7849. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7850. // // result_params[@"resultSerial"]=uuid;
  7851. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7852. // if(json!=nil)
  7853. // {
  7854. //
  7855. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7856. // if([jsobj[@"result"] intValue]==2)
  7857. // {
  7858. // break;
  7859. // }
  7860. // }
  7861. // sleep(5);
  7862. // }
  7863. //
  7864. // }
  7865. // if(json==nil)
  7866. // return nil;
  7867. // NSError *error=nil;
  7868. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7869. // return jsobj;
  7870. }
  7871. +(void)request_save_portfolio:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  7872. {
  7873. NSMutableDictionary* off_params = [params mutableCopy];;
  7874. params[@"off_params"]=[RAConvertor dict2string:off_params];
  7875. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7876. AppDelegate *appDelegate = nil;
  7877. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7878. if(appDelegate.user!=nil)
  7879. [params setValue:appDelegate.user forKey:@"user"];
  7880. if(appDelegate.contact_id!=nil)
  7881. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7882. if(appDelegate.password!=nil)
  7883. [params setValue:appDelegate.password forKey:@"password"];
  7884. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7885. if(appDelegate.offline_mode)
  7886. {
  7887. params[@"contact_id"]=appDelegate.contact_id;
  7888. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7889. NSData* json = [[OLDataProvider offline_save_TearSheet:params] mutableCopy];
  7890. dispatch_async(dispatch_get_main_queue(), ^{
  7891. result([[RAConvertor data2dict:json] mutableCopy]);
  7892. });
  7893. });
  7894. return;
  7895. }
  7896. [self request_interface:URL_SAVE_DM parameters:params err_record_url:nil completionHandler:result retry:0];
  7897. //
  7898. // NSData* json = nil;
  7899. // if(appDelegate.offline_mode)
  7900. // {
  7901. // json = [OLDataProvider offline_save_TearSheet:params];
  7902. // } else {
  7903. // if(![self IsNetworkAvailable])
  7904. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7905. //
  7906. // json=[self get_json:URL_SAVE_DM parameters:params];
  7907. // }
  7908. // if(json==nil)
  7909. // return nil;
  7910. // NSError *error=nil;
  7911. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7912. // return jsobj;
  7913. }
  7914. +(void)request_portfoliopreview:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7915. {
  7916. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7917. AppDelegate *appDelegate = nil;
  7918. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7919. if(appDelegate.user!=nil)
  7920. [params setValue:appDelegate.user forKey:@"user"];
  7921. if(appDelegate.contact_id!=nil)
  7922. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7923. if(appDelegate.password!=nil)
  7924. [params setValue:appDelegate.password forKey:@"password"];
  7925. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7926. // [params setValue:request_url forKey:@"pdfUrl"];
  7927. if(appDelegate.offline_mode)
  7928. {
  7929. params[@"contact_id"]=params[@"contactId"];
  7930. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7931. NSData* json = [[OLDataProvider offline_request_tearsheet:params] mutableCopy];
  7932. dispatch_async(dispatch_get_main_queue(), ^{
  7933. result([[RAConvertor data2dict:json] mutableCopy]);
  7934. });
  7935. });
  7936. return;
  7937. }
  7938. NSString * uuid= [[NSUUID UUID] UUIDString];
  7939. params[@"resultSerial"]=uuid;
  7940. __block bool bbreak = false;
  7941. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7942. for(int i=0;i<150;i++)
  7943. {
  7944. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7945. // result_params[@"resultSerial"]=uuid;
  7946. if(bbreak)
  7947. break;
  7948. dispatch_async(dispatch_get_main_queue(), ^{
  7949. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7950. if([resulti[@"result"] intValue]==2)
  7951. {
  7952. if(!bbreak)//此判断保证result只调用一次。
  7953. result(resulti);
  7954. bbreak=true;
  7955. }
  7956. } retry:3];
  7957. });
  7958. sleep(5);
  7959. }
  7960. });
  7961. //
  7962. // NSData* json= nil;
  7963. // if(appDelegate.offline_mode)
  7964. // {
  7965. // json= [OLDataProvider offline_request_tearsheet:params];
  7966. // }
  7967. // else
  7968. // {
  7969. // if(![self IsNetworkAvailable])
  7970. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7971. //
  7972. // NSError *error=nil;
  7973. //
  7974. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7975. // params[@"resultSerial"]=uuid;
  7976. //
  7977. // for(int i=0;i<150;i++)
  7978. // {
  7979. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7980. // // result_params[@"resultSerial"]=uuid;
  7981. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7982. // if(json!=nil)
  7983. // {
  7984. //
  7985. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7986. // if([jsobj[@"result"] intValue]==2)
  7987. // {
  7988. // break;
  7989. // }
  7990. // }
  7991. // sleep(5);
  7992. // }
  7993. // }
  7994. // if(json==nil)
  7995. // return nil;
  7996. // NSError *error=nil;
  7997. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7998. // return jsobj;
  7999. }
  8000. +(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
  8001. {
  8002. // for debug
  8003. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  8004. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8005. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8006. AppDelegate *appDelegate = nil;
  8007. //some UI methods ej
  8008. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8009. if(appDelegate.user!=nil)
  8010. [params setValue:appDelegate.user forKey:@"user"];
  8011. if(appDelegate.contact_id!=nil)
  8012. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8013. if(appDelegate.password!=nil)
  8014. [params setValue:appDelegate.password forKey:@"password"];
  8015. if(appDelegate.order_code!=nil)
  8016. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8017. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  8018. if (alert && qty && available && price && bestseller) {
  8019. [params setObject:@"Filter" forKey:kAction];
  8020. }
  8021. if ([RASingleton sharedInstance].homeItemClick) {
  8022. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  8023. [RASingleton sharedInstance].homeItemClick = NO;
  8024. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  8025. [RASingleton sharedInstance].homeClickedItemName = nil;
  8026. [params setObject:extra forKey:kExtra];
  8027. }
  8028. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  8029. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  8030. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  8031. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  8032. // [params setValue:filter forKey:@"filter"];
  8033. [params setValue:covertype forKey:@"covertype"];
  8034. [params setValue:ctgid forKey:@"ctgId"];
  8035. [params setValue:modelname forKey:@"modelName"];
  8036. [params setValue:modeldescrip forKey:@"modelDescription"];
  8037. [params setValue:alert forKey:@"alert"];
  8038. [params setValue:qty forKey:@"sold_by_qty"];
  8039. [params setValue:available forKey:@"available"];
  8040. [params setValue:price forKey:@"price"];
  8041. [params setValue:bestseller forKey:@"bestseller"];
  8042. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  8043. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  8044. if(appDelegate.offline_mode)
  8045. {
  8046. // [OLDataProvider offline_itemsearch:params completionHandler:result];
  8047. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8048. NSMutableDictionary* json = [[OLDataProvider offline_itemsearch:params] mutableCopy];
  8049. dispatch_async(dispatch_get_main_queue(), ^{
  8050. result(json);
  8051. });
  8052. });
  8053. return;
  8054. }
  8055. [self request_interface:URL_ITEM_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  8056. // if(appDelegate.offline_mode)
  8057. // {
  8058. // return [OLDataProvider offline_itemsearch:params];
  8059. // }
  8060. // if(![self IsNetworkAvailable])
  8061. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8062. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  8063. // if(json==nil)
  8064. // return nil;
  8065. // NSError *error=nil;
  8066. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8067. // return jsobj;
  8068. }
  8069. +(void)request_modelqty: (NSString*) fashionId completionHandler:(resultHandler)result
  8070. {
  8071. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8072. AppDelegate *appDelegate = nil;
  8073. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8074. if(appDelegate.user!=nil)
  8075. [params setValue:appDelegate.user forKey:@"user"];
  8076. if(appDelegate.contact_id!=nil)
  8077. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8078. if(appDelegate.password!=nil)
  8079. [params setValue:appDelegate.password forKey:@"password"];
  8080. [params setValue:fashionId forKey:@"fashionId"];
  8081. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  8082. if(appDelegate.offline_mode)
  8083. {
  8084. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8085. NSData* json = [[OLDataProvider offline_model_qty:params] mutableCopy];
  8086. dispatch_async(dispatch_get_main_queue(), ^{
  8087. result([[RAConvertor data2dict:json] mutableCopy]);
  8088. });
  8089. });
  8090. return;
  8091. }
  8092. [self request_interface:URL_REQUEST_MODEL_QTY parameters:params err_record_url:nil completionHandler:result retry:0];
  8093. // NSData* json = nil;
  8094. // if(appDelegate.offline_mode)
  8095. // {
  8096. // json = [OLDataProvider offline_model_qty:params];
  8097. // } else {
  8098. // if(![self IsNetworkAvailable])
  8099. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8100. //
  8101. // json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  8102. // }
  8103. // if(json==nil)
  8104. // return nil;
  8105. // NSError *error=nil;
  8106. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8107. // return jsobj;
  8108. }
  8109. +(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
  8110. {
  8111. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8112. AppDelegate *appDelegate = nil;
  8113. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8114. if(appDelegate.user!=nil)
  8115. [params setValue:appDelegate.user forKey:@"user"];
  8116. if(appDelegate.contact_id!=nil)
  8117. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8118. if(appDelegate.password!=nil)
  8119. [params setValue:appDelegate.password forKey:@"password"];
  8120. [params setValue:watchlist_id forKey:@"item_id"];
  8121. // if(notes.length>0)
  8122. // [params setValue:notes forKey:@"notes"];
  8123. if(notes)
  8124. [params setValue:notes forKey:@"notes"];
  8125. if(price != -MAXFLOAT)
  8126. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  8127. if (discount != -MAXFLOAT)
  8128. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  8129. if(qty_p != -MAXFLOAT)
  8130. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  8131. if(qty != -INT32_MAX)
  8132. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  8133. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  8134. // NSData* json = nil;
  8135. if(appDelegate.offline_mode)
  8136. {
  8137. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8138. NSData* json = [[OLDataProvider offline_editPortfolio:params] mutableCopy];
  8139. dispatch_async(dispatch_get_main_queue(), ^{
  8140. result([[RAConvertor data2dict:json] mutableCopy]);
  8141. });
  8142. });
  8143. return;
  8144. }
  8145. [self request_interface:URL_PORTFOLIO_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8146. //
  8147. // if(appDelegate.offline_mode)
  8148. // {
  8149. // json = [OLDataProvider offline_editPortfolio:params];
  8150. // } else {
  8151. // if(![self IsNetworkAvailable])
  8152. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8153. //
  8154. // json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  8155. // }
  8156. // if(json==nil)
  8157. // return nil;
  8158. // NSError *error=nil;
  8159. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8160. // return jsobj;
  8161. }
  8162. +(void)request_add_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8163. {
  8164. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8165. AppDelegate *appDelegate = nil;
  8166. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8167. if(appDelegate.user!=nil)
  8168. [params setValue:appDelegate.user forKey:@"user"];
  8169. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  8170. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8171. // else
  8172. if(appDelegate.contact_id!=nil)
  8173. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8174. if(appDelegate.password!=nil)
  8175. [params setValue:appDelegate.password forKey:@"password"];
  8176. // NSDictionary* customerinfo=nil;
  8177. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  8178. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8179. // else
  8180. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8181. //
  8182. // appDelegate.customerInfo;
  8183. // NSArray* keys=[customerinfo allKeys];
  8184. // for(int i=0;i<keys.count;i++)
  8185. // {
  8186. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8187. // }
  8188. // [params setValue:sourceid forKey:@"sourceid"];
  8189. // [params setValue:editor forKey:@"editor"];
  8190. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  8191. if(appDelegate.offline_mode)
  8192. {
  8193. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8194. NSData* json = [[OLDataProvider offline_saveNewContact:params] mutableCopy];
  8195. dispatch_async(dispatch_get_main_queue(), ^{
  8196. result([[RAConvertor data2dict:json] mutableCopy]);
  8197. });
  8198. });
  8199. return;
  8200. }
  8201. [self request_interface:URL_CUSTOMER_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  8202. //
  8203. // NSData* json=nil;
  8204. // if(appDelegate.offline_mode)
  8205. // {
  8206. // json= [OLDataProvider offline_saveNewContact:params];
  8207. // }
  8208. // else
  8209. // {
  8210. // if(![self IsNetworkAvailable])
  8211. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8212. //
  8213. // json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  8214. // }
  8215. //
  8216. // if(json!=nil)
  8217. // {
  8218. // NSError *error=nil;
  8219. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8220. // return jsobj;
  8221. // }
  8222. // else
  8223. // return nil;
  8224. }
  8225. +(void)request_update_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8226. {
  8227. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8228. AppDelegate *appDelegate = nil;
  8229. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8230. if(appDelegate.user!=nil)
  8231. [params setValue:appDelegate.user forKey:@"user"];
  8232. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  8233. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8234. // else
  8235. if(appDelegate.contact_id!=nil)
  8236. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8237. if(appDelegate.password!=nil)
  8238. [params setValue:appDelegate.password forKey:@"password"];
  8239. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8240. if(appDelegate.offline_mode)
  8241. {
  8242. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8243. NSData* json = [[OLDataProvider offline_saveContact:params] mutableCopy];
  8244. dispatch_async(dispatch_get_main_queue(), ^{
  8245. result([[RAConvertor data2dict:json] mutableCopy]);
  8246. });
  8247. });
  8248. return;
  8249. }
  8250. [self request_interface:URL_CUSTOMER_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  8251. //
  8252. // NSData* json=nil;
  8253. // if(appDelegate.offline_mode)
  8254. // {
  8255. // json= [OLDataProvider offline_saveContact:params];
  8256. // }
  8257. // else
  8258. // {
  8259. // if(![self IsNetworkAvailable])
  8260. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8261. //
  8262. // json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  8263. // }
  8264. //
  8265. // if(json!=nil)
  8266. // {
  8267. // NSError *error=nil;
  8268. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8269. // return jsobj;
  8270. // }
  8271. // else
  8272. // return nil;
  8273. }
  8274. +(void)request_delete_order:(NSString*) order_id completionHandler:(resultHandler)result
  8275. {
  8276. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8277. AppDelegate *appDelegate = nil;
  8278. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8279. if(appDelegate.user!=nil)
  8280. [params setValue:appDelegate.user forKey:@"user"];
  8281. // if(appDelegate.contact_id!=nil)
  8282. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8283. if(appDelegate.password!=nil)
  8284. [params setValue:appDelegate.password forKey:@"password"];
  8285. [params setValue:order_id forKey:@"orderId"];
  8286. // [params setValue:sourceid forKey:@"sourceid"];
  8287. // [params setValue:editor forKey:@"editor"];
  8288. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8289. if(appDelegate.offline_mode)
  8290. {
  8291. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8292. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8293. dispatch_async(dispatch_get_main_queue(), ^{
  8294. result(json);
  8295. });
  8296. });
  8297. return;
  8298. }
  8299. [self request_interface:URL_DELETE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8300. //
  8301. // if(appDelegate.offline_mode)
  8302. // {
  8303. // return [OLDataProvider offline_notimpl];
  8304. // }
  8305. // if(![self IsNetworkAvailable])
  8306. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8307. //
  8308. // NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  8309. // if(json!=nil)
  8310. // {
  8311. // NSError *error=nil;
  8312. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8313. //
  8314. //
  8315. // return jsobj;
  8316. // }
  8317. // else
  8318. // return nil;
  8319. }
  8320. +(void)request_cancel_order:(NSString*) order_id order_code:(NSString*) order_code completionHandler:(resultHandler)result
  8321. {
  8322. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8323. AppDelegate *appDelegate = nil;
  8324. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8325. if(appDelegate.user!=nil)
  8326. [params setValue:appDelegate.user forKey:@"user"];
  8327. // if(appDelegate.contact_id!=nil)
  8328. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8329. if(appDelegate.password!=nil)
  8330. [params setValue:appDelegate.password forKey:@"password"];
  8331. [params setValue:order_id forKey:@"orderId"];
  8332. [params setValue:order_code forKey:@"orderCode"];
  8333. // [params setValue:sourceid forKey:@"sourceid"];
  8334. // [params setValue:editor forKey:@"editor"];
  8335. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8336. if(appDelegate.offline_mode)
  8337. {
  8338. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8339. NSData* json = [[OLDataProvider offline_cancelorder:params] mutableCopy];
  8340. dispatch_async(dispatch_get_main_queue(), ^{
  8341. result([[RAConvertor data2dict:json] mutableCopy]);
  8342. });
  8343. });
  8344. return;
  8345. }
  8346. [self request_interface:URL_CANCEL_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8347. //
  8348. // NSData* json=nil;
  8349. // if(appDelegate.offline_mode)
  8350. // {
  8351. // json=[OLDataProvider offline_cancelorder:params];
  8352. // }
  8353. // else
  8354. // {
  8355. // if(![self IsNetworkAvailable])
  8356. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8357. // json=[self get_json:URL_CANCEL_ORDER parameters:params];
  8358. // }
  8359. // if(json!=nil)
  8360. // {
  8361. // NSError *error=nil;
  8362. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8363. //
  8364. //
  8365. // return jsobj;
  8366. // }
  8367. // else
  8368. // return nil;
  8369. }
  8370. +(void)request_release_order:(NSString*) order_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  8371. {
  8372. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8373. AppDelegate *appDelegate = nil;
  8374. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8375. if(appDelegate.user!=nil)
  8376. [params setValue:appDelegate.user forKey:@"user"];
  8377. // if(appDelegate.contact_id!=nil)
  8378. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8379. if(appDelegate.password!=nil)
  8380. [params setValue:appDelegate.password forKey:@"password"];
  8381. [params setValue:order_code forKey:@"orderCode"];
  8382. // [params setValue:sourceid forKey:@"sourceid"];
  8383. // [params setValue:editor forKey:@"editor"];
  8384. if (screenName) {
  8385. [params setValue:screenName forKey:kScreenName];
  8386. }
  8387. if(appDelegate.offline_mode)
  8388. {
  8389. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8390. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_resetorder:params]] mutableCopy];
  8391. dispatch_async(dispatch_get_main_queue(), ^{
  8392. if([[resulti valueForKey:@"result"]intValue]==2)
  8393. { [appDelegate SetSo:nil];
  8394. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8395. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8396. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8397. [appDelegate update_count_mark];
  8398. }
  8399. });
  8400. });
  8401. return;
  8402. }
  8403. [self request_interface:URL_RELEASE_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8404. if([[resulti valueForKey:@"result"]intValue]==2)
  8405. { [appDelegate SetSo:nil];
  8406. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8407. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8408. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8409. [appDelegate update_count_mark];
  8410. }
  8411. } retry:0];
  8412. //
  8413. // NSData* json=nil;
  8414. // if(appDelegate.offline_mode)
  8415. // {
  8416. // json= [OLDataProvider offline_resetorder:params];
  8417. // }
  8418. // else
  8419. // {
  8420. // if(![self IsNetworkAvailable])
  8421. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8422. //
  8423. // json=[self get_json:URL_RELEASE_ORDER parameters:params];
  8424. // }
  8425. // if(json!=nil)
  8426. // {
  8427. // NSError *error=nil;
  8428. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8429. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8430. // { [appDelegate SetSo:nil];
  8431. //
  8432. //
  8433. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8434. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8435. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8436. //
  8437. // [appDelegate update_count_mark];
  8438. // }
  8439. // return jsobj;
  8440. // }
  8441. // else
  8442. // return nil;
  8443. }
  8444. +(void)request_update_order_signature:(NSString*) order_code path:(NSString*)path completionHandler:(resultHandler)result
  8445. {
  8446. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8447. AppDelegate *appDelegate = nil;
  8448. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8449. if(appDelegate.user!=nil)
  8450. [params setValue:appDelegate.user forKey:@"user"];
  8451. if(appDelegate.contact_id!=nil)
  8452. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8453. if(appDelegate.password!=nil)
  8454. [params setValue:appDelegate.password forKey:@"password"];
  8455. // NSString* ssaved = @"false";
  8456. // if(saved)
  8457. // ssaved=@"true";
  8458. // [params setValue:@"true" forKey:@"saved"];
  8459. [params setValue:order_code forKey:@"orderCode"];
  8460. [params setValue:path forKey:@"picpath"];
  8461. // [params setValue:sourceid forKey:@"sourceid"];
  8462. // [params setValue:editor forKey:@"editor"];
  8463. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  8464. if(appDelegate.offline_mode)
  8465. {
  8466. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8467. NSData* json = [[OLDataProvider offline_signorder:params] mutableCopy];
  8468. dispatch_async(dispatch_get_main_queue(), ^{
  8469. result([[RAConvertor data2dict:json] mutableCopy]);
  8470. });
  8471. });
  8472. return;
  8473. }
  8474. [self request_interface:URL_SIGN_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8475. //
  8476. // NSData* json=nil;
  8477. // if(appDelegate.offline_mode)
  8478. // {
  8479. // json= [OLDataProvider offline_signorder:params];
  8480. // }
  8481. // else
  8482. // {
  8483. // if(![self IsNetworkAvailable])
  8484. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8485. //
  8486. // json=[self get_json:URL_SIGN_ORDER parameters:params];
  8487. // }
  8488. // if(json!=nil)
  8489. // {
  8490. // NSError *error=nil;
  8491. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8492. // return jsobj;
  8493. // }
  8494. // else
  8495. // return nil;
  8496. }
  8497. +(void) request_update_cart_modelprice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8498. {
  8499. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8500. AppDelegate *appDelegate = nil;
  8501. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8502. if(appDelegate.user!=nil)
  8503. [params setValue:appDelegate.user forKey:@"user"];
  8504. if(appDelegate.contact_id!=nil)
  8505. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8506. if(appDelegate.password!=nil)
  8507. [params setValue:appDelegate.password forKey:@"password"];
  8508. [params setValue:cart_id forKey:@"cartitem_id"];
  8509. [params setValue:notes forKey:@"item_note"];
  8510. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  8511. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  8512. [params setObject:ScreenCodeCart forKey:kScreenName];
  8513. if(appDelegate.offline_mode)
  8514. {
  8515. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8516. NSData* json = [[OLDataProvider offline_cartsetprice:params] mutableCopy];
  8517. dispatch_async(dispatch_get_main_queue(), ^{
  8518. result([[RAConvertor data2dict:json] mutableCopy]);
  8519. });
  8520. });
  8521. return;
  8522. }
  8523. [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8524. //
  8525. // NSData* json= nil;
  8526. // if(appDelegate.offline_mode)
  8527. // {
  8528. // json=[OLDataProvider offline_cartsetprice:params];
  8529. // }
  8530. // else
  8531. // {
  8532. // if(![self IsNetworkAvailable])
  8533. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8534. //
  8535. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8536. // }
  8537. // if(json==nil)
  8538. // return nil;
  8539. // NSError *error=nil;
  8540. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8541. // return jsobj;
  8542. }
  8543. +(void) request_addto_cart:(NSString* ) item_id count:(int) count name:(NSString *)name completionHandler:(resultHandler)result
  8544. {
  8545. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8546. AppDelegate *appDelegate = nil;
  8547. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8548. if(appDelegate.user!=nil)
  8549. [params setValue:appDelegate.user forKey:@"user"];
  8550. if(appDelegate.contact_id!=nil)
  8551. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8552. if(appDelegate.password!=nil)
  8553. [params setValue:appDelegate.password forKey:@"password"];
  8554. if(appDelegate.order_code!=nil)
  8555. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8556. [params setValue:item_id forKey:@"product_id"];
  8557. [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  8558. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  8559. [params setObject:@"Add To Cart" forKey:kAction];
  8560. if (name) {
  8561. NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  8562. [params setObject:extra forKey:kExtra];
  8563. }
  8564. NSDictionary* customerinfo= appDelegate.customerInfo;
  8565. NSArray* keys=[customerinfo allKeys];
  8566. for(int i=0;i<keys.count;i++)
  8567. {
  8568. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8569. }
  8570. if(appDelegate.offline_mode)
  8571. {
  8572. // [OLDataProvider offline_add2cart:params completionHandler:^(NSMutableDictionary *resulti) {
  8573. // NSMutableDictionary* json = resulti;
  8574. // if ([json[@"result"] intValue]==2)
  8575. // {
  8576. // appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  8577. //
  8578. // [appDelegate update_count_mark];
  8579. // }
  8580. // result(json);
  8581. // }];
  8582. params[@"can_create_backorder"]= @(appDelegate.can_create_backorder);
  8583. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8584. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cart:params]] mutableCopy];
  8585. dispatch_async(dispatch_get_main_queue(), ^{
  8586. if ([json[@"result"] intValue]==2)
  8587. {
  8588. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  8589. [appDelegate update_count_mark];
  8590. }
  8591. result(json);
  8592. });
  8593. });
  8594. return;
  8595. }
  8596. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8597. if ([resulti[@"result"] intValue]==2)
  8598. {
  8599. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8600. [appDelegate update_count_mark];
  8601. }
  8602. result(resulti);
  8603. } retry:0];
  8604. //
  8605. // NSData* json=nil;
  8606. // if(appDelegate.offline_mode)
  8607. // {
  8608. // json=[OLDataProvider offline_add2cart:params];
  8609. // }
  8610. // else
  8611. // {
  8612. // if(![self IsNetworkAvailable])
  8613. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8614. //
  8615. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  8616. // }
  8617. // if(json==nil)
  8618. // return nil;
  8619. // NSError *error=nil;
  8620. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8621. //
  8622. //
  8623. //
  8624. // int result = [[jsobj valueForKey:@"result"] intValue];
  8625. //
  8626. // if (result==2)
  8627. // {
  8628. //
  8629. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8630. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8631. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8632. //
  8633. // [appDelegate update_count_mark];
  8634. // }
  8635. //
  8636. // return jsobj;
  8637. }
  8638. //+(void) request_update_cart_modelfree:(NSString*) cart_id isfree:(bool) isfree completionHandler:(resultHandler)result
  8639. //{
  8640. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8641. // AppDelegate *appDelegate = nil;
  8642. //
  8643. //
  8644. //
  8645. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8646. //
  8647. // if(appDelegate.user!=nil)
  8648. // [params setValue:appDelegate.user forKey:@"user"];
  8649. // if(appDelegate.contact_id!=nil)
  8650. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8651. // if(appDelegate.password!=nil)
  8652. // [params setValue:appDelegate.password forKey:@"password"];
  8653. //
  8654. // [params setValue:cart_id forKey:@"cartitem_id"];
  8655. //
  8656. // [params setObject:ScreenCodeCart forKey:kScreenName];
  8657. //
  8658. // NSString* free=nil;
  8659. //
  8660. // if(isfree)
  8661. // free=@"true";
  8662. // else
  8663. // free=@"false";
  8664. //
  8665. // [params setValue:free forKey:@"free_giveaway"];
  8666. //
  8667. //
  8668. // if(appDelegate.offline_mode)
  8669. // {
  8670. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8671. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8672. // dispatch_async(dispatch_get_main_queue(), ^{
  8673. // result(json);
  8674. // });
  8675. // });
  8676. //
  8677. // return;
  8678. //
  8679. // }
  8680. // [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8681. //
  8682. ////
  8683. ////
  8684. //// if(appDelegate.offline_mode)
  8685. //// {
  8686. //// return [OLDataProvider offline_notimpl];
  8687. //// }
  8688. //// if(![self IsNetworkAvailable])
  8689. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8690. ////
  8691. //// NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8692. //// if(json==nil)
  8693. //// return nil;
  8694. //// NSError *error=nil;
  8695. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8696. //// return jsobj;
  8697. //}
  8698. +(void)request_retrieve_password: (NSString*) user email:(NSString*) email completionHandler:(resultHandler)result
  8699. {
  8700. AppDelegate *appDelegate = nil;
  8701. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8702. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8703. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8704. // if(appDelegate.user!=nil)
  8705. // [params setValue:appDelegate.user forKey:@"user"];
  8706. // if(appDelegate.contact_id!=nil)
  8707. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8708. // if(appDelegate.password!=nil)
  8709. // [params setValue:appDelegate.password forKey:@"password"];
  8710. [params setValue:user forKey:@"username"];
  8711. [params setValue:email forKey:@"email"];
  8712. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  8713. if(appDelegate.offline_mode)
  8714. {
  8715. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8716. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8717. dispatch_async(dispatch_get_main_queue(), ^{
  8718. result(json);
  8719. });
  8720. });
  8721. return;
  8722. }
  8723. [self request_interface:URL_RETRIEVE_PASS parameters:params err_record_url:nil completionHandler:result retry:0];
  8724. //
  8725. //
  8726. // if(![self IsNetworkAvailable])
  8727. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8728. //
  8729. // NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  8730. // if(json==nil)
  8731. // return nil;
  8732. // NSError *error=nil;
  8733. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8734. // return jsobj;
  8735. }
  8736. +(void)request_update_ordercustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info completionHandler:(resultHandler)result
  8737. {
  8738. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8739. AppDelegate *appDelegate = nil;
  8740. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8741. if(appDelegate.user!=nil)
  8742. [info setValue:appDelegate.user forKey:@"user"];
  8743. // if(appDelegate.contact_id!=nil)
  8744. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8745. if(appDelegate.password!=nil)
  8746. [info setValue:appDelegate.password forKey:@"password"];
  8747. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8748. [info setValue:order_code forKey:@"orderCode"];
  8749. // [params setValue:sourceid forKey:@"sourceid"];
  8750. // [params setValue:editor forKey:@"editor"];
  8751. if(appDelegate.offline_mode)
  8752. {
  8753. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8754. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8755. dispatch_async(dispatch_get_main_queue(), ^{
  8756. result(json);
  8757. });
  8758. });
  8759. return;
  8760. }
  8761. [self request_interface:URL_UPDATE_ORDERCUSTOMER parameters:info err_record_url:nil completionHandler:result retry:0];
  8762. // if(appDelegate.offline_mode)
  8763. // {
  8764. // return [OLDataProvider offline_notimpl];
  8765. // }
  8766. // if(![self IsNetworkAvailable])
  8767. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8768. //
  8769. // NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  8770. // if(json!=nil)
  8771. // {
  8772. // NSError *error=nil;
  8773. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8774. // return jsobj;
  8775. // }
  8776. // else
  8777. // return nil;
  8778. }
  8779. +(void)request_update_customer_img: (NSString*) contactid img_url:(NSString*) url completionHandler:(resultHandler)result
  8780. {
  8781. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8782. AppDelegate *appDelegate = nil;
  8783. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8784. if(appDelegate.user!=nil)
  8785. [params setValue:appDelegate.user forKey:@"user"];
  8786. // if(appDelegate.contact_id!=nil)
  8787. if(appDelegate.password!=nil)
  8788. [params setValue:appDelegate.password forKey:@"password"];
  8789. [params setValue:contactid forKey:@"contactId"];
  8790. [params setValue:url forKey:@"business_card"];
  8791. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  8792. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8793. if(appDelegate.offline_mode)
  8794. {
  8795. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8796. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8797. dispatch_async(dispatch_get_main_queue(), ^{
  8798. result(json);
  8799. });
  8800. });
  8801. return;
  8802. }
  8803. [self request_interface:URL_UPDATE_CUSTOMER_BCARD parameters:params err_record_url:nil completionHandler:result retry:0];
  8804. // if(appDelegate.offline_mode)
  8805. // {
  8806. // return [OLDataProvider offline_notimpl];
  8807. // }
  8808. // if(![self IsNetworkAvailable])
  8809. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8810. //
  8811. // NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  8812. // if(json==nil)
  8813. // return nil;
  8814. // NSError *error=nil;
  8815. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8816. // return jsobj;
  8817. }
  8818. +(void)request_commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url completionHandler:(resultHandler)result
  8819. {
  8820. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8821. AppDelegate *appDelegate = nil;
  8822. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8823. if(appDelegate.user!=nil)
  8824. [params setValue:appDelegate.user forKey:@"user"];
  8825. if(appDelegate.contact_id!=nil)
  8826. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8827. if(appDelegate.password!=nil)
  8828. [params setValue:appDelegate.password forKey:@"password"];
  8829. // if(appDelegate.order_code!=nil)
  8830. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8831. // NSDictionary* customerinfo= appDelegate.customerInfo;
  8832. //
  8833. // NSArray* keys=[customerinfo allKeys];
  8834. // for(int i=0;i<keys.count;i++)
  8835. // {
  8836. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8837. // }
  8838. //
  8839. // [params setValue:sourceid forKey:@"sourceid"];
  8840. // [params setValue:editor forKey:@"editor"];
  8841. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  8842. if(appDelegate.offline_mode)
  8843. {
  8844. params[@"offline_Command"]=url;
  8845. [OLDataProvider offline_commoneditor_partialrefresh:params completionHandler:result];
  8846. //
  8847. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8848. // NSMutableDictionary* json = [[OLDataProvider offline_commoneditor_partialrefresh:params] mutableCopy];
  8849. // dispatch_async(dispatch_get_main_queue(), ^{
  8850. // result(json);
  8851. // });
  8852. // });
  8853. return;
  8854. }
  8855. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  8856. //
  8857. // if(appDelegate.offline_mode)
  8858. // {
  8859. // params[@"offline_Command"]=url;
  8860. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  8861. // }
  8862. //
  8863. // if(![self IsNetworkAvailable])
  8864. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8865. //
  8866. // NSData* json=[self get_json:url parameters:params];
  8867. // if(json!=nil)
  8868. // {
  8869. // NSError *error=nil;
  8870. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8871. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8872. // [appDelegate SetSo:nil];
  8873. //
  8874. //
  8875. // return jsobj;
  8876. // }
  8877. // else
  8878. // return nil;
  8879. }
  8880. +(void)request_add_address:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8881. {
  8882. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8883. AppDelegate *appDelegate = nil;
  8884. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8885. if(appDelegate.user!=nil)
  8886. [params setValue:appDelegate.user forKey:@"user"];
  8887. if(appDelegate.contact_id!=nil)
  8888. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8889. if(appDelegate.password!=nil)
  8890. [params setValue:appDelegate.password forKey:@"password"];
  8891. // [params setValue:sourceid forKey:@"sourceid"];
  8892. // [params setValue:editor forKey:@"editor"];
  8893. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  8894. if(appDelegate.offline_mode)
  8895. {
  8896. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8897. NSData* json = [[OLDataProvider offline_saveaddr:params] mutableCopy];
  8898. dispatch_async(dispatch_get_main_queue(), ^{
  8899. result([[RAConvertor data2dict:json] mutableCopy]);
  8900. });
  8901. });
  8902. return;
  8903. }
  8904. [self request_interface:URL_ADDRESS_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  8905. //
  8906. // NSData* json=nil;
  8907. //
  8908. // if(appDelegate.offline_mode)
  8909. // {
  8910. // json= [OLDataProvider offline_saveaddr:params];
  8911. // }
  8912. // else
  8913. // {
  8914. // if(![self IsNetworkAvailable])
  8915. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8916. //
  8917. // json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  8918. // }
  8919. // if(json!=nil)
  8920. // {
  8921. // NSError *error=nil;
  8922. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8923. // return jsobj;
  8924. // }
  8925. // else
  8926. // return nil;
  8927. }
  8928. +(void)request_commit_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8929. {
  8930. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8931. AppDelegate *appDelegate = nil;
  8932. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8933. if(appDelegate.user!=nil)
  8934. [params setValue:appDelegate.user forKey:@"user"];
  8935. if(appDelegate.contact_id!=nil)
  8936. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8937. if(appDelegate.password!=nil)
  8938. [params setValue:appDelegate.password forKey:@"password"];
  8939. if(appDelegate.order_code!=nil)
  8940. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8941. // NSDictionary* customerinfo= appDelegate.customerInfo;
  8942. //
  8943. // NSArray* keys=[customerinfo allKeys];
  8944. // for(int i=0;i<keys.count;i++)
  8945. // {
  8946. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8947. // }
  8948. //
  8949. // [params setValue:sourceid forKey:@"sourceid"];
  8950. // [params setValue:editor forKey:@"editor"];
  8951. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  8952. if(appDelegate.offline_mode)
  8953. {
  8954. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8955. NSData* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  8956. dispatch_async(dispatch_get_main_queue(), ^{
  8957. result([[RAConvertor data2dict:json] mutableCopy]);
  8958. });
  8959. });
  8960. return;
  8961. }
  8962. [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8963. //
  8964. // NSData* json=nil;
  8965. // if(appDelegate.offline_mode)
  8966. // {
  8967. // json=[OLDataProvider offline_submitorder:params];
  8968. // }
  8969. // else
  8970. // {
  8971. // if(![self IsNetworkAvailable])
  8972. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8973. //
  8974. // json=[self get_json:URL_COMMIT_ORDER parameters:params];
  8975. // }
  8976. // if(json!=nil)
  8977. // {
  8978. // NSError *error=nil;
  8979. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8980. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8981. // [appDelegate SetSo:nil];
  8982. //
  8983. //
  8984. // return jsobj;
  8985. // }
  8986. // else
  8987. // return nil;
  8988. }
  8989. +(void) request_new_offline_ticket:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid completionHandler:(resultHandler)result
  8990. {
  8991. // if(![self IsNetworkAvailable])
  8992. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8993. //
  8994. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8995. AppDelegate *appDelegate = nil;
  8996. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8997. if(appDelegate.user!=nil)
  8998. [params setValue:appDelegate.user forKey:@"user"];
  8999. // if(appDelegate.contact_id!=nil)
  9000. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9001. if(appDelegate.password!=nil)
  9002. [params setValue:appDelegate.password forKey:@"password"];
  9003. [params setValue:ver forKey:@"ver"];
  9004. [params setValue:vid forKey:@"vid"];
  9005. if(buseinternaladdress)
  9006. [params setValue:@"true" forKey:@"internal_address"];
  9007. else
  9008. [params setValue:@"false" forKey:@"internal_address"];
  9009. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  9010. // 无论当前是离线还是在线状态,都可以进行同步;
  9011. // if(appDelegate.offline_mode)
  9012. // {
  9013. //
  9014. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9015. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9016. // dispatch_async(dispatch_get_main_queue(), ^{
  9017. // result(json);
  9018. // });
  9019. // });
  9020. //
  9021. // return;
  9022. //
  9023. // }
  9024. [self request_interface:URL_CHECK_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  9025. //
  9026. // NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  9027. // if(json==nil)
  9028. // return nil;
  9029. // NSError *error=nil;
  9030. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9031. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9032. // //
  9033. // // if (result==2)
  9034. // // {
  9035. // //
  9036. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9037. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9038. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9039. // ////
  9040. // //// [appDelegate update_count_mark];
  9041. // // }
  9042. // return jsobj;
  9043. }
  9044. +(void) request_complete_offline_ticket:(NSString* )vid completionHandler:(resultHandler)result
  9045. {
  9046. AppDelegate *appDelegate = nil;
  9047. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9048. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9049. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  9050. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  9051. // if(appDelegate.user!=nil)
  9052. // [params setValue:appDelegate.user forKey:@"user"];
  9053. // // if(appDelegate.contact_id!=nil)
  9054. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9055. // if(appDelegate.password!=nil)
  9056. // [params setValue:appDelegate.password forKey:@"password"];
  9057. [params setValue:vid forKey:@"downSerial"];
  9058. // 无论当前是离线还是在线状态,都可以进行同步;
  9059. // if(appDelegate.offline_mode)
  9060. // {
  9061. //
  9062. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9063. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9064. // dispatch_async(dispatch_get_main_queue(), ^{
  9065. // result(json);
  9066. // });
  9067. // });
  9068. //
  9069. // return;
  9070. //
  9071. // }
  9072. [self request_interface:URL_FINISH_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  9073. // NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  9074. // if(json==nil)
  9075. // return nil;
  9076. // NSError *error=nil;
  9077. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9078. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9079. // //
  9080. // // if (result==2)
  9081. // // {
  9082. // //
  9083. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9084. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9085. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9086. // ////
  9087. // //// [appDelegate update_count_mark];
  9088. // // }
  9089. // return jsobj;
  9090. }
  9091. +(void) request_download_offline:(NSString* )vid completionHandler:(resultHandler)result
  9092. {
  9093. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9094. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  9095. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  9096. // if(appDelegate.user!=nil)
  9097. // [params setValue:appDelegate.user forKey:@"user"];
  9098. // // if(appDelegate.contact_id!=nil)
  9099. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9100. // if(appDelegate.password!=nil)
  9101. // [params setValue:appDelegate.password forKey:@"password"];
  9102. [params setValue:vid forKey:@"downSerial"];
  9103. // AppDelegate *appDelegate = nil;
  9104. //
  9105. //
  9106. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9107. // if(appDelegate.offline_mode)
  9108. // {
  9109. //
  9110. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9111. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9112. // dispatch_async(dispatch_get_main_queue(), ^{
  9113. // result(json);
  9114. // });
  9115. // });
  9116. //
  9117. // return;
  9118. //
  9119. // }
  9120. __block bool bbreak = false;
  9121. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9122. __block NSMutableDictionary* download_json=nil;
  9123. int count=0;
  9124. // __block bool preparing = true;
  9125. while ([[download_json valueForKey:@"result"] intValue]!=2&&count<REQUEST_DOWNLOAD_RETRY_TIMES) //超过60分钟还没准被好数据就视为服务器出错。
  9126. {
  9127. if(bbreak)
  9128. break;
  9129. dispatch_async(dispatch_get_main_queue(), ^{
  9130. [self request_interface:URL_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  9131. if([resulti[@"result"] intValue]==RESULT_TRUE)
  9132. {
  9133. if(!bbreak) //此判断保证result只调用一次。
  9134. {
  9135. // appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  9136. // [appDelegate update_count_mark];
  9137. resulti[@"request_count"]=[NSNumber numberWithInt:count];
  9138. result(resulti);
  9139. }
  9140. bbreak=true;
  9141. }
  9142. else if([resulti[@"result"] intValue]==RESULT_ERROR)
  9143. {
  9144. result(resulti);
  9145. bbreak=true;
  9146. }
  9147. } retry:3];
  9148. });
  9149. sleep(RETRY_DELAY);
  9150. count++;
  9151. // download_json=[[RANetwork download_Offline:downSerial] mutableCopy];
  9152. //
  9153. // [RANetwork request_download_offline:downSerial completionHandler:^(NSMutableDictionary *result) {
  9154. // download_json=result;
  9155. // }];
  9156. //
  9157. }
  9158. // for(int i=0;i<150;i++)
  9159. // {
  9160. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  9161. // // result_params[@"resultSerial"]=uuid;
  9162. //
  9163. //
  9164. //
  9165. // sleep(2);
  9166. //
  9167. // // json=[self get_json:URL_CART parameters:params];
  9168. // // if(json!=nil)
  9169. // // {
  9170. // //
  9171. // // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9172. // // if([jsobj[@"result"] intValue]==2)
  9173. // // {
  9174. // // break;
  9175. // // }
  9176. // // }
  9177. //
  9178. // }
  9179. });
  9180. //
  9181. // NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  9182. // if(json==nil)
  9183. // return nil;
  9184. // NSError *error=nil;
  9185. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9186. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9187. // //
  9188. // // if (result==2)
  9189. // // {
  9190. // //
  9191. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9192. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9193. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9194. // ////
  9195. // //// [appDelegate update_count_mark];
  9196. // // }
  9197. // return jsobj;
  9198. }
  9199. + (void)request_fastupload:(NSMutableDictionary *)params filename:(NSString*)filename data:(NSData*) data url:(NSString *)url completionHandler:(resultHandler)result
  9200. {
  9201. //#ifdef test_server
  9202. // url=URL_REQUEST_RECORDS;
  9203. // params[@"prefix"]=URL_REQUEST_RECORDS;
  9204. //#endif
  9205. // [self request_file_fast:url parameters:params completionHandler:result];
  9206. [self request_upload_fast:data FileName:filename server:url parameters:params completionHandler:result];
  9207. }
  9208. +(void)request_err_log:(NSString*) up_params result:(NSString*)result_str module:(NSString*) module code:(int) code completionHandler:(resultHandler)result
  9209. {
  9210. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9211. AppDelegate *appDelegate = nil;
  9212. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9213. if(appDelegate.user!=nil)
  9214. [params setValue:appDelegate.user forKey:@"user"];
  9215. [params setValue:up_params forKey:@"upparam"];
  9216. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  9217. [params setValue:result_str forKey:@"result"];
  9218. [params setValue:module forKey:@"interfac"];
  9219. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  9220. // [params setValue:module forKey:@"module"];
  9221. // [[UIDevice currentDevice] name];
  9222. // if(appDelegate.offline_mode)
  9223. // {
  9224. // return [OLDataProvider offline_notimpl];
  9225. // }
  9226. if(appDelegate.offline_mode)
  9227. {
  9228. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9229. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9230. dispatch_async(dispatch_get_main_queue(), ^{
  9231. result(json);
  9232. });
  9233. });
  9234. return;
  9235. }
  9236. [self request_interface:URL_ERR_LOG parameters:params err_record_url:nil completionHandler:result retry:0];
  9237. //
  9238. // if(![self IsNetworkAvailable])
  9239. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9240. //
  9241. // NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  9242. // if(json==nil)
  9243. // return nil;
  9244. // NSError *error=nil;
  9245. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9246. // return jsobj;
  9247. }
  9248. @end