RANetwork.m 416 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410
  1. //
  2. // iSalesNetwork.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-6-20.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RANetwork.h"
  9. #import "RAUtils.h"
  10. #import "RASingleton.h"
  11. #ifdef GOOGLE_ANALYTICS
  12. #import "GoogleAnalyst.h"
  13. #endif
  14. #import "ERPUtils.h"
  15. #import "RAConvertor.h"
  16. #import "ActiveViewController.h"
  17. #import "ZipArchive.h"
  18. #import "RADataProvider.h"
  19. NSString *const kScreenName = @"kScreenName";
  20. NSString *const kAction = @"kAction";
  21. NSString *const kExtra = @"kExtra";
  22. NSString *const ScreenCodeLoginView = @"Login Screen";
  23. NSString *const ScreenCodeHomeView = @"Home Screen";
  24. NSString *const ScreenCodeCategory = @"Category Screen";
  25. NSString *const ScreenCodeCart = @"Cart Sceen";
  26. NSString *const ScreenCodeOrderList = @"Order History Screen";
  27. NSString *const ScreenCodeSearch = @"Search Screen";
  28. NSString *const ScreenCodeAccount = @"Account Screen";
  29. NSString *const ScreenCodeWishList = @"Wish List Screen";
  30. NSString *const ScreenCodePortfolio = @"Portfolio Screen";
  31. NSString *const ScreenCodeViewPortfolios = @"View Portfolios Screen";
  32. NSString *const ScreenCodeCamScan = @"Cam Scan Screen";
  33. NSString *const ScreenCodeScannerSetting = @"Scanner Setting Screen";
  34. NSString *const ScreenCodeOfflineSetting = @"Offline Setting Screen";
  35. NSString *const ScreenCodePlaceOrder = @"Place Order Screen";
  36. NSString *const ScreenCodeCustomerInfo = @"Customer Information Screen";
  37. NSString *const ScreenCodeNewCustomer = @"New Customer Screen";
  38. NSString *const ScreenCodeEditCustomer = @"Edit Customer Information Screen";
  39. NSString *const ScreenCodeModelInfo = @"Model Information Screen";
  40. NSString *const ScreenCodeOrderInfo = @"Order Information Screeen";
  41. NSString *const ScreenCodeUserSign = @"User Sign Screen";
  42. NSString *const ScreenCodeNewAddress = @"New Address Screen";
  43. NSString *const ScreenCodeAdvanceSearch = @"Account Advance Search Screen";
  44. NSString *const ScreenCodeCreatePortfolio = @"Create Portfolio Screen";
  45. NSString *const ScreenCodeParticularCategory = @"Particular Category Screen";
  46. NSString *const ScreenCodeEditPortfolio = @"Edit Portfolio Screen";
  47. NSString *const ScreenCodePriceSetting = @"Price Setting Screen";
  48. NSString *const ScreenCodeCategoryPrice = @"Category Price Screen";
  49. NSString *const ScreenCodeSetCatetoryPrice = @"Set Category Price Screen";
  50. NSString *const ScreenCodeUploadImage = @"Upload Image Screen";
  51. NSString *const ScreenCodeOfflineSync = @"Offline Sync Screen";
  52. @implementation RANetwork
  53. +(NSMutableDictionary*) prepare_additional_params:(NSMutableDictionary* ) params
  54. {
  55. AppDelegate *appDelegate = nil;
  56. //some UI methods ej
  57. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  58. // if(appDelegate.user!=nil)
  59. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.user key:@"usai"] forKey:@"user"];
  60. // if(appDelegate.password!=nil)
  61. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.password key:@"usai"] forKey:@"password"];
  62. //
  63. //
  64. //
  65. // if(appDelegate.user!=nil)
  66. // [params setValue:appDelegate.user forKey:@"user"];
  67. //
  68. // if(appDelegate.contact_id!=nil)
  69. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  70. // if(appDelegate.password!=nil)
  71. // [params setValue:appDelegate.password forKey:@"password"];
  72. //
  73. // [params setValue:appDelegate.build forKey:@"app_ver"];
  74. //
  75. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  76. // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  77. // [params setValue:short_version forKey:@"app_short_ver"];
  78. //
  79. //
  80. //
  81. //#if TARGET_IPHONE_SIMULATOR//模拟器
  82. // [params setValue:@"simulator_uuid" forKey:@"deviceid"];
  83. //#elif TARGET_OS_IPHONE//真机
  84. // UIDevice * dev = [UIDevice currentDevice];
  85. // NSUUID* uuid =dev.identifierForVendor;
  86. // [params setValue:uuid.UUIDString forKey:@"deviceid"];
  87. //#endif
  88. if(appDelegate.user!=nil && params[@"user"]==nil)
  89. [params setValue:appDelegate.user forKey:@"user"];
  90. if(appDelegate.password!=nil&& params[@"password"]==nil)
  91. [params setValue:appDelegate.password forKey:@"password"];
  92. if(appDelegate.ipad_perm!=nil)
  93. [params setValue:appDelegate.ipad_perm forKey:@"ipad_perm"];
  94. [params setValue:appDelegate.build forKey:@"app_ver"];
  95. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  96. NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  97. [params setValue:short_version forKey:@"app_short_ver"];
  98. #if TARGET_IPHONE_SIMULATOR//模拟器
  99. [params setValue:@"simulator_uuid" forKey:@"idfv"];
  100. #elif TARGET_OS_IPHONE//真机
  101. UIDevice * dev = [UIDevice currentDevice];
  102. NSUUID* uuid =dev.identifierForVendor;
  103. [params setValue:uuid.UUIDString forKey:@"idfv"];
  104. #endif
  105. //
  106. // NSString *userAction = [params valueForKey:kAction];
  107. // NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  108. // if ([userAction isEqualToString:@"Login"]) {
  109. // if (!extra) {
  110. // extra = [NSMutableDictionary dictionary];
  111. // }
  112. // [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  113. // }
  114. return params;
  115. }
  116. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString *) file //delegate:(id < NSURLConnectionDelegate >)delegate
  117. {
  118. // NSString* e=[AESCrypt AES128Encrypt:@"密码学中的高级加密标准(Advanced Encryption Standard,AES),又称 高级加密标准Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用。经过五年的甄选流程,高级加密标准由美国国家标准与技术研究院 (NIST)于2001年11月26日发布于FIPS PUB 197,并在2002年5月26日成为有效的标准。2006年,高级加密标准已然成为对称密钥加密中最流行的算法之一。 " key:@"usai2010"];
  119. // DebugLog(e);
  120. // NSString* d=[AESCrypt decrypt:@"VzB4+lENfbzWX7ggHh2Os1P69l5YBzKmM51yqA37AfoKgPY8bJgdK8M4WvF+wDyOsLWP\/o8H5+bHMivQp1u8wM2QV7SYzgzPwV85QKtYWIzEgLe9T0HO69EdutWz7k1rdAT\/mftsRin0Hy5SHk7txTZT\/zPH5X+FQiExCTFm5Zus39HYvp+VxCX4+kYeymn8B63AUd3mRQyscUvDjfgU2olKR\/TP8PV3g+VQMZxpKfol3P1iOtz3XQlHZV0pM6SAf+SwT0sPfrdn6CZFfNQlrKA9QjMrnBdMeSCquSIWXnmLv6okzvnlJnT0SjvJuUeqNdBC5EZ0ACnhI0MrXVZEsq1EuM9al7oPzvU5EZbjZpmx+fSFIkMzTT8bYClTnG1bsL1MCcU4pSODDorUj8zalA==" password:@"usai2010"];
  121. params = [self prepare_additional_params:params];
  122. DebugLog(@"\n++++++++++++++++++++++Request++++++++++++++++++++++\n%@\n++++++++++++++++++++++Params++++++++++++++++++++++\n%@\n",url,[RAConvertor dict2string:params]);
  123. return [super get_json:url parameters:params file:(NSString*)file err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  124. int result=[[jsobj valueForKey:@"result"] intValue];
  125. // UIApplication * app = [UIApplication sharedApplication];
  126. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  127. switch (result) {
  128. case 0:
  129. [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  130. break;
  131. case 1:
  132. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  133. break;
  134. case 2:
  135. [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  136. break;
  137. case 8:
  138. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  139. break;
  140. case 9:
  141. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  142. break;
  143. case 99:
  144. [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  145. break;
  146. default:
  147. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  148. break;
  149. }
  150. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  151. // {
  152. // [jsobj setValue:@"9" forKey:@"result"];
  153. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  154. // }
  155. return jsobj;
  156. } decrypt_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  157. return nil;
  158. // NSString* base64str = jsobj[@"str"];
  159. // NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"usai2010"];
  160. // jsobj=[[RAUtils string2dict:decryptstr] mutableCopy];
  161. // return jsobj;
  162. }];
  163. /*
  164. */
  165. return nil;
  166. }
  167. +(void) LoadImage:(NSString*) url into:(UIImageView*) container
  168. {
  169. DebugLog(@"LoadImage:(NSString*) url in:(UIImageView*) container");
  170. NSString* file_name=[url lastPathComponent];
  171. NSData* img_data = [iSalesDB load_cached_img:file_name loadFrom:url];
  172. if(img_data==nil)
  173. {
  174. DebugLog(@"IMG NOT CACHED %@",file_name);
  175. img_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
  176. [iSalesDB cache_img:img_data filename:file_name saveTo:url];
  177. //load from internet;
  178. }
  179. if(img_data!=nil)
  180. {
  181. UIImage * img =[UIImage imageWithData:img_data];
  182. if(img==nil)
  183. DebugLog(@"UIIMAGE IS NIL! %@",file_name);
  184. else
  185. dispatch_async(dispatch_get_main_queue(), ^{
  186. container.image =img;
  187. });
  188. }
  189. else
  190. {
  191. DebugLog(@"IMG DOWNLOAD FAILED! %@",file_name);
  192. }
  193. }
  194. //+(NSData*)fake_json:(NSString*) url
  195. //{
  196. // NSString* jsonfile = nil;
  197. // if([url isEqualToString:URL_UPDATE_AUTH])
  198. // {
  199. // jsonfile=@"login";
  200. //
  201. // }
  202. // else if([url isEqualToString:URL_REQUEST_CATMENU])
  203. // {
  204. // jsonfile=@"categorymenu";
  205. // }
  206. // else if([url isEqualToString:URL_LOAD_HOME])
  207. // {
  208. // jsonfile=@"homepage";
  209. // }
  210. // else if([url isEqualToString:URL_SEARCH])
  211. // {
  212. // jsonfile=@"search";
  213. // }
  214. // else if([url isEqualToString:URL_CATEGORY_LOADMORE])
  215. // {
  216. // jsonfile=@"category_more";
  217. // }else if([url isEqualToString:URL_ITEM_DETAIL])
  218. // {
  219. // jsonfile=@"detail";
  220. // }else if([url isEqualToString:URL_CART])
  221. // {
  222. // jsonfile=@"cart";
  223. // }else if([url isEqualToString:URL_ORDER_LIST])
  224. // {
  225. // jsonfile=@"orderlist";
  226. // }
  227. //// else if([url isEqualToString:URL_ORDER_INFO])
  228. //// {
  229. //// jsonfile=@"orderinfo";
  230. //// }
  231. //// else if([url isEqualToString:URL_ORDER_INFO])
  232. //// {
  233. //// jsonfile=@"orderinfo2label";
  234. //// }
  235. //
  236. //
  237. //
  238. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:jsonfile ofType:@"json" ]];
  239. // NSMutableString *result = [[NSMutableString alloc] initWithData:json encoding:NSUTF8StringEncoding];
  240. //
  241. // DebugLog(@"result: \n%@",result);
  242. // return json;
  243. //}
  244. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
  245. {
  246. NSString *screenName = [params valueForKey:kScreenName];
  247. NSString *userAction = [params valueForKey:kAction];
  248. NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  249. if ([userAction isEqualToString:@"Login"]) {
  250. if (!extra) {
  251. extra = [NSMutableDictionary dictionary];
  252. }
  253. [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  254. }
  255. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  256. [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  257. #endif
  258. return [self get_json:url parameters:params file:nil];
  259. // {
  260. // int retry = 0;
  261. //
  262. // __block AppDelegate *appDelegate = nil;
  263. //
  264. // dispatch_sync(dispatch_get_main_queue(), ^{
  265. // //some UI methods ej
  266. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  267. // });
  268. // if(appDelegate.user!=nil)
  269. // [params setValue:appDelegate.user forKey:@"user"];
  270. // if(appDelegate.password!=nil)
  271. // [params setValue:appDelegate.password forKey:@"password"];
  272. //
  273. //
  274. // if(appDelegate.ipad_perm!=nil)
  275. // [params setValue:appDelegate.ipad_perm forKey:@"ipad_perm"];
  276. //
  277. // [params setValue:appDelegate.build forKey:@"app_ver"];
  278. //
  279. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  280. // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  281. // [params setValue:short_version forKey:@"app_short_ver"];
  282. //
  283. // UIDevice * dev = [UIDevice currentDevice];
  284. // NSUUID* uuid =dev.identifierForVendor;
  285. //#if TARGET_IPHONE_SIMULATOR//模拟器
  286. // [params setValue:@"simulator_uuid" forKey:@"idfv"];
  287. //#elif TARGET_OS_IPHONE//真机
  288. // [params setValue:uuid.UUIDString forKey:@"idfv"];
  289. //#endif
  290. //
  291. //// NSString *screenName = [params valueForKey:kScreenName];
  292. //// NSString *userAction = [params valueForKey:kAction];
  293. //// NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  294. //// if ([userAction isEqualToString:@"Login"]) {
  295. //// if (!extra) {
  296. //// extra = [NSMutableDictionary dictionary];
  297. //// }
  298. //// [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  299. //// }
  300. //
  301. //repeat:
  302. // {
  303. //
  304. // // return [self fake_json:url];
  305. //
  306. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  307. // //分界线的标识符
  308. // NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
  309. // //根据url初始化request
  310. // NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
  311. // cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
  312. // timeoutInterval:JSON_TIMEOUT];
  313. // //分界线 --AaB03x
  314. // NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
  315. // //结束符 AaB03x--
  316. // NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
  317. // //要上传的图片
  318. // // UIImage *image=[params objectForKey:@"pic"];
  319. // //得到图片的data
  320. // // NSData* data = UIImagePNGRepresentation(image);
  321. // //http body的字符串
  322. // NSMutableString *body=[[NSMutableString alloc]init];
  323. //
  324. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  325. // // [params setValue:@"handset_login" forKey:@"action"];
  326. // // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  327. //
  328. // // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  329. // // [params setValue:password forKey:@"password"];
  330. // // [params setValue:[NSString stringWithFormat:@"%d",ver] forKey:@"auth_ver"];
  331. //
  332. //
  333. //
  334. // // [headers setValue:headQuerlString forKey:@"param"];
  335. //
  336. // //参数的集合的所有key的集合
  337. // NSArray *keys= [params allKeys];
  338. // DebugLog(@"================parms==================");
  339. // //遍历keys
  340. // for(int i=0;i<[keys count];i++)
  341. // {
  342. // //得到当前key
  343. // NSString *key=[keys objectAtIndex:i];
  344. // //如果key不是pic,说明value是字符类型,比如name:Boris
  345. // if(![key isEqualToString:@"pic"])
  346. // {
  347. // //添加分界线,换行
  348. // [body appendFormat:@"%@\r\n",MPboundary];
  349. // //添加字段名称,换2行
  350. // [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
  351. // //添加字段的值
  352. // [body appendFormat:@"%@\r\n",[params objectForKey:key]];
  353. // DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
  354. // }
  355. // }
  356. // DebugLog(@"================parms==================");
  357. // ////添加分界线,换行
  358. // [body appendFormat:@"%@\r\n",MPboundary];
  359. // //声明pic字段,文件名为boris.png
  360. // [body appendFormat:@"Content-Disposition: form-data; name=\"pic\"; filename=\"boris.png\"\r\n"];
  361. // //声明上传文件的格式
  362. // [body appendFormat:@"Content-Type: image/png\r\n\r\n"];
  363. //
  364. // //声明结束符:--AaB03x--
  365. // NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
  366. // //声明myRequestData,用来放入http body
  367. // NSMutableData *myRequestData=[NSMutableData data];
  368. // //将body字符串转化为UTF8格式的二进制
  369. // [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
  370. // //将image的data加入
  371. // // [myRequestData appendData:data];
  372. // //加入结束符--AaB03x--
  373. // [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
  374. //
  375. // //设置HTTPHeader中Content-Type的值
  376. // NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
  377. // //设置HTTPHeader
  378. // [request setValue:content forHTTPHeaderField:@"Content-Type"];
  379. //
  380. // // 关闭keep alive
  381. // [request setValue:@"close" forHTTPHeaderField:@"Connection"];
  382. // //设置Content-Length
  383. // [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[myRequestData length]] forHTTPHeaderField:@"Content-Length"];
  384. // //设置http body
  385. // [request setHTTPBody:myRequestData];
  386. // //http method
  387. // [request setHTTPMethod:@"POST"];
  388. //
  389. //
  390. // NSHTTPURLResponse* urlResponse = nil;
  391. //
  392. // NSError *error = nil;
  393. //
  394. // NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  395. //
  396. //
  397. // DebugLog(@"url: %@",url);
  398. //
  399. // DebugLog(@"response: %@",[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode]);
  400. //
  401. // if (responseData==nil) {
  402. //
  403. //// DebugLog(@"response error:%@", [error localizedDescription]);
  404. //
  405. //
  406. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  407. // //#define RESULT_FALSE 0
  408. // //#define RESULT_TRUE 2
  409. // //#define RESULT_NET_ERROR -3
  410. // //#define RESULT_NET_NOTAVAILABLE -4
  411. // //#define RESULT_ERROR -5
  412. // //#define RESULT_LOCALFILE_ERROR -7
  413. // //#define RESULT_USERAUTH_ERROR -9
  414. // //#define RESULT_UPDATE_USERAUTH_ERROR -11
  415. // //#define RESULT_SESSION_EXPIRED -13
  416. // //#define RESULT_VER_LOW
  417. //
  418. // // NSString * moreinfo = error.description ;
  419. //
  420. // NSString* err_msg = [error localizedDescription];
  421. //
  422. //
  423. // //-----------------retry 3 times for error code -1005------------------------
  424. // if(error.code==-1005&&retry<3)
  425. // {
  426. // retry++;
  427. // goto repeat;
  428. //
  429. // }
  430. // //-----------------end retry 3 times for error code -1005------------------------
  431. //
  432. // NSDictionary* error_json = [RAUtils error_dict:error];
  433. // [ret setObject:error_json forKey:@"err_obj"];
  434. // NSString* resp_msg= nil;
  435. //
  436. // if(err_msg.length==0)
  437. // {
  438. // err_msg =[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode];
  439. // resp_msg = err_msg;
  440. // }
  441. // [ret setValue:[NSString stringWithFormat:@"%d",RESULT_NET_ERROR] forKey:@"result"];
  442. // [ret setValue:err_msg forKey:@"err_msg"];
  443. // [ret setValue:resp_msg forKey:@"resp_msg"];
  444. // [ret setValue:[NSString stringWithFormat:@"%ld",(long)urlResponse.statusCode] forKey:@"resp_code"];
  445. //
  446. //
  447. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ret
  448. // options:0
  449. // error:nil];
  450. // if(![url isEqualToString:URL_ERR_LOG])
  451. // {
  452. // [RANetwork err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:[RAConvertor dict2string:ret]] module:url code:RESULT_NET_ERROR];
  453. // }
  454. //#if defined(BUILD_NPD)// || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  455. // [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  456. //#endif
  457. // return jsonData;
  458. //
  459. // }
  460. // else
  461. // {
  462. // NSString* err_msg = [error localizedDescription];
  463. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  464. //
  465. // DebugLog(@"data string: %@",str);
  466. // NSError *error1 = nil;
  467. //
  468. // NSMutableDictionary* jsobj = [[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error1] mutableCopy];
  469. //
  470. // if(jsobj==nil)// 服务器返回不是json
  471. // {
  472. //
  473. // jsobj=[[NSMutableDictionary alloc] init];
  474. // [jsobj setValue:@"1" forKey:@"result"];
  475. //
  476. // }
  477. //
  478. // int result=[[jsobj valueForKey:@"result"] intValue];
  479. // UIApplication * app = [UIApplication sharedApplication];
  480. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  481. // NSString* mode =[jsobj valueForKey:@"mode"];
  482. // [appDelegate SetMode:mode];
  483. // switch (result) {
  484. // case 0:
  485. // [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  486. // break;
  487. // case 1:
  488. // [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  489. // break;
  490. // case 2:
  491. // [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  492. // break;
  493. // case 8:
  494. // [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  495. // break;
  496. // case 9:
  497. // [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  498. // break;
  499. // case 99:
  500. // [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  501. // break;
  502. // default:
  503. // [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  504. // break;
  505. // }
  506. //
  507. //
  508. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  509. // {
  510. // [jsobj setValue:@"9" forKey:@"result"];
  511. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  512. // }
  513. //
  514. // if(![url isEqualToString:URL_ERR_LOG]&&![url isEqualToString:URL_DOWNLOAD_OFFLINE]/*&&result!=-3*/&&result!=2&&result!=99)
  515. // {
  516. // [RANetwork err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:str] module:url code:result];
  517. // }
  518. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsobj
  519. // options:0
  520. // error:nil];
  521. //#if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  522. // [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  523. //#endif
  524. // return jsonData;
  525. //
  526. // }
  527. //
  528. // return responseData;
  529. // }
  530. //}
  531. }
  532. //+(NSDictionary*)request_Editor:(NSString*) sourceid editor:(NSString*)editor
  533. //{
  534. //
  535. //}
  536. +(NSDictionary*) delete_portfoliolist:(NSString* ) listid
  537. {
  538. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  539. __block AppDelegate *appDelegate = nil;
  540. dispatch_sync(dispatch_get_main_queue(), ^{
  541. //some UI methods ej
  542. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  543. });
  544. if(appDelegate.user!=nil)
  545. [params setValue:appDelegate.user forKey:@"user"];
  546. if(appDelegate.contact_id!=nil)
  547. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  548. if(appDelegate.password!=nil)
  549. [params setValue:appDelegate.password forKey:@"password"];
  550. [params setValue:listid forKey:@"tearsheetsId"];
  551. // [params setValue:editor forKey:@"editor"];
  552. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  553. // [params setValue:@"Delete Portfolio" forKey:kAction];
  554. NSData* json = nil;
  555. if(appDelegate.offline_mode)
  556. {
  557. json = [OLDataProvider offline_removePDF:params];
  558. } else {
  559. if(![self IsNetworkAvailable])
  560. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  561. json=[self get_json:URL_PORTFOLIOLIST_REMOVE parameters:params];
  562. }
  563. if(json!=nil)
  564. {
  565. NSError *error=nil;
  566. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  567. return jsobj;
  568. }
  569. else
  570. return nil;
  571. }
  572. +(NSDictionary*) portfolio_remove:(NSString* ) item_ids
  573. {
  574. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  575. __block AppDelegate *appDelegate = nil;
  576. dispatch_sync(dispatch_get_main_queue(), ^{
  577. //some UI methods ej
  578. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  579. });
  580. if(appDelegate.user!=nil)
  581. [params setValue:appDelegate.user forKey:@"user"];
  582. if(appDelegate.contact_id!=nil)
  583. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  584. if(appDelegate.password!=nil)
  585. [params setValue:appDelegate.password forKey:@"password"];
  586. [params setValue:item_ids forKey:@"portfolioId"];
  587. // [params setValue:editor forKey:@"editor"];
  588. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  589. NSData* json = nil;
  590. if(appDelegate.offline_mode)
  591. {
  592. json = [OLDataProvider offline_removePortfolio:params];
  593. } else {
  594. if(![self IsNetworkAvailable])
  595. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  596. json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  597. }
  598. if(json!=nil)
  599. {
  600. NSError *error=nil;
  601. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  602. int result = [[jsobj valueForKey:@"result"] intValue];
  603. if (result==2)
  604. {
  605. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  606. [appDelegate update_count_mark];
  607. }
  608. return jsobj;
  609. }
  610. else
  611. return nil;
  612. }
  613. //+(NSDictionary*) watchlist_remove:(NSString* ) item_ids
  614. //{
  615. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  616. // __block AppDelegate *appDelegate = nil;
  617. //
  618. // dispatch_sync(dispatch_get_main_queue(), ^{
  619. // //some UI methods ej
  620. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  621. // });
  622. // if(appDelegate.user!=nil)
  623. // [params setValue:appDelegate.user forKey:@"user"];
  624. // if(appDelegate.contact_id!=nil)
  625. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  626. // if(appDelegate.password!=nil)
  627. // [params setValue:appDelegate.password forKey:@"password"];
  628. // [params setValue:item_ids forKey:@"collectId"];
  629. // // [params setValue:editor forKey:@"editor"];
  630. //
  631. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  632. //
  633. // if(appDelegate.offline_mode)
  634. // {
  635. // return [OLDataProvider offline_deletewishlist:params];
  636. // }
  637. // if(![self IsNetworkAvailable])
  638. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  639. //
  640. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  641. // if(json!=nil)
  642. // {
  643. // NSError *error=nil;
  644. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  645. // int result = [[jsobj valueForKey:@"result"] intValue];
  646. //
  647. // if (result==2)
  648. // {
  649. //
  650. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  651. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  652. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  653. //
  654. // [appDelegate update_count_mark];
  655. // }
  656. // return jsobj;
  657. // }
  658. // else
  659. // return nil;
  660. //}
  661. //+(NSDictionary*) move_cart2wish:(NSString* ) item_ids
  662. //{
  663. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  664. // __block AppDelegate *appDelegate = nil;
  665. //
  666. // dispatch_sync(dispatch_get_main_queue(), ^{
  667. // //some UI methods ej
  668. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  669. // });
  670. // if(appDelegate.user!=nil)
  671. // [params setValue:appDelegate.user forKey:@"user"];
  672. // if(appDelegate.contact_id!=nil)
  673. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  674. // if(appDelegate.password!=nil)
  675. // [params setValue:appDelegate.password forKey:@"password"];
  676. // if(appDelegate.order_code!=nil)
  677. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  678. // [params setValue:item_ids forKey:@"cartItemId"];
  679. // // [params setValue:editor forKey:@"editor"];
  680. //
  681. // [params setValue:ScreenCodeCart forKey:kScreenName];
  682. // // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  683. //
  684. // NSData* json = nil;
  685. // if(appDelegate.offline_mode)
  686. // {
  687. // json= [OLDataProvider offline_movecart2wish:params];
  688. // }
  689. // else
  690. // {
  691. // if(![self IsNetworkAvailable])
  692. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  693. //
  694. // json=[self get_json:URL_CART2WISH parameters:params];
  695. // }
  696. // if(json!=nil)
  697. // {
  698. // NSError *error=nil;
  699. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  700. // int result = [[jsobj valueForKey:@"result"] intValue];
  701. //
  702. // if (result==2)
  703. // {
  704. //
  705. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  706. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  707. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  708. //
  709. // [appDelegate update_count_mark];
  710. // }
  711. // return jsobj;
  712. // }
  713. // else
  714. // return nil;
  715. //}
  716. //+(NSDictionary*) move_wish2cart:(NSString* ) item_ids
  717. //{
  718. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  719. // __block AppDelegate *appDelegate = nil;
  720. //
  721. // dispatch_sync(dispatch_get_main_queue(), ^{
  722. // //some UI methods ej
  723. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  724. // });
  725. // if(appDelegate.user!=nil)
  726. // [params setValue:appDelegate.user forKey:@"user"];
  727. // if(appDelegate.contact_id!=nil)
  728. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  729. // if(appDelegate.password!=nil)
  730. // [params setValue:appDelegate.password forKey:@"password"];
  731. // if(appDelegate.order_code!=nil)
  732. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  733. // [params setValue:item_ids forKey:@"collectId"];
  734. // // [params setValue:editor forKey:@"editor"];
  735. //
  736. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  737. // [params setValue:@"Move To Cart" forKey:kAction];
  738. //
  739. // NSData *json = nil;
  740. // if(appDelegate.offline_mode)
  741. // {
  742. // json = [OLDataProvider offline_movewish2cart:params];
  743. // } else {
  744. // if(![self IsNetworkAvailable])
  745. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  746. //
  747. // json=[self get_json:URL_WISH2CART parameters:params];
  748. // }
  749. //
  750. // if(json!=nil)
  751. // {
  752. // NSError *error=nil;
  753. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  754. // int result = [[jsobj valueForKey:@"result"] intValue];
  755. //
  756. // if (result==2)
  757. // {
  758. //
  759. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  760. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  761. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  762. //
  763. // [appDelegate update_count_mark];
  764. // }
  765. // return jsobj;
  766. // }
  767. // else
  768. // return nil;
  769. //}
  770. //+(NSDictionary*) cart_remove:(NSString* ) item_ids
  771. //{
  772. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  773. // __block AppDelegate *appDelegate = nil;
  774. //
  775. // dispatch_sync(dispatch_get_main_queue(), ^{
  776. // //some UI methods ej
  777. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  778. // });
  779. // if(appDelegate.user!=nil)
  780. // [params setValue:appDelegate.user forKey:@"user"];
  781. // if(appDelegate.contact_id!=nil)
  782. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  783. // if(appDelegate.password!=nil)
  784. // [params setValue:appDelegate.password forKey:@"password"];
  785. //
  786. // if(appDelegate.order_code!=nil)
  787. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  788. // [params setValue:item_ids forKey:@"cartItemId"];
  789. // // [params setValue:editor forKey:@"editor"];
  790. //
  791. // [params setValue:ScreenCodeCart forKey:kScreenName];
  792. // // [params setValue:@"" forKey:kAction];
  793. //
  794. // NSData* json=nil;
  795. // if(appDelegate.offline_mode)
  796. // {
  797. // json= [OLDataProvider offline_cartremove:params];
  798. // }
  799. // else
  800. // {
  801. // if(![self IsNetworkAvailable])
  802. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  803. //
  804. // json=[self get_json:URL_CART_REMOVE parameters:params];
  805. // }
  806. // if(json!=nil)
  807. // {
  808. // NSError *error=nil;
  809. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  810. //
  811. // int result = [[jsobj valueForKey:@"result"] intValue];
  812. //
  813. // if (result==2)
  814. // {
  815. //
  816. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  817. //
  818. //
  819. // [appDelegate update_count_mark];
  820. // }
  821. // return jsobj;
  822. // }
  823. // else
  824. // return nil;
  825. //}
  826. //+(NSDictionary*) cart_check:(NSString* ) item_ids
  827. //{
  828. // return nil;
  829. // if(![self IsNetworkAvailable])
  830. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  831. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  832. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  833. // if(appDelegate.user!=nil)
  834. // [params setValue:appDelegate.user forKey:@"user"];
  835. // if(appDelegate.contact_id!=nil)
  836. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  837. // if(appDelegate.password!=nil)
  838. // [params setValue:appDelegate.password forKey:@"password"];
  839. // [params setValue:item_ids forKey:@"cartItemId"];
  840. // // [params setValue:editor forKey:@"editor"];
  841. // if(appDelegate.offline_mode)
  842. // {
  843. // return [OLDataProvider offline_notimpl];
  844. // }
  845. // NSData* json=[self get_json:URL_CART_CHECK parameters:params];
  846. // if(json!=nil)
  847. // {
  848. // NSError *error=nil;
  849. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  850. // return jsobj;
  851. // }
  852. // else
  853. // return nil;
  854. //}
  855. +(NSDictionary*)create_Address:(NSMutableDictionary*)params
  856. {
  857. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  858. __block AppDelegate *appDelegate = nil;
  859. dispatch_sync(dispatch_get_main_queue(), ^{
  860. //some UI methods ej
  861. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  862. });
  863. if(appDelegate.user!=nil)
  864. [params setValue:appDelegate.user forKey:@"user"];
  865. if(appDelegate.contact_id!=nil)
  866. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  867. if(appDelegate.password!=nil)
  868. [params setValue:appDelegate.password forKey:@"password"];
  869. // [params setValue:sourceid forKey:@"sourceid"];
  870. // [params setValue:editor forKey:@"editor"];
  871. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  872. NSData* json=nil;
  873. if(appDelegate.offline_mode)
  874. {
  875. json= [OLDataProvider offline_saveaddr:params];
  876. }
  877. else
  878. {
  879. if(![self IsNetworkAvailable])
  880. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  881. json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  882. }
  883. if(json!=nil)
  884. {
  885. NSError *error=nil;
  886. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  887. return jsobj;
  888. }
  889. else
  890. return nil;
  891. }
  892. +(NSDictionary*)copy_Order:(NSString*) order_code
  893. {
  894. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  895. __block AppDelegate *appDelegate = nil;
  896. dispatch_sync(dispatch_get_main_queue(), ^{
  897. //some UI methods ej
  898. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  899. });
  900. if(appDelegate.user!=nil)
  901. [params setValue:appDelegate.user forKey:@"user"];
  902. if(appDelegate.contact_id!=nil)
  903. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  904. if(appDelegate.password!=nil)
  905. [params setValue:appDelegate.password forKey:@"password"];
  906. // NSString* ssaved = @"false";
  907. // if(saved)
  908. // ssaved=@"true";
  909. // [params setValue:@"true" forKey:@"saved"];
  910. [params setValue:order_code forKey:@"code"];
  911. // [params setValue:sourceid forKey:@"sourceid"];
  912. // [params setValue:editor forKey:@"editor"];
  913. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  914. NSData* json=nil;
  915. if(appDelegate.offline_mode)
  916. {
  917. json= [OLDataProvider offline_copyorder:params];
  918. }
  919. else
  920. {
  921. if(![self IsNetworkAvailable])
  922. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  923. json=[self get_json:URL_COPY_ORDER parameters:params];
  924. }
  925. if(json!=nil)
  926. {
  927. NSError *error=nil;
  928. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  929. return jsobj;
  930. }
  931. else
  932. return nil;
  933. }
  934. +(NSDictionary*)sign_Order:(NSString*) order_code path:(NSString*)path
  935. {
  936. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  937. __block AppDelegate *appDelegate = nil;
  938. dispatch_sync(dispatch_get_main_queue(), ^{
  939. //some UI methods ej
  940. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  941. });
  942. if(appDelegate.user!=nil)
  943. [params setValue:appDelegate.user forKey:@"user"];
  944. if(appDelegate.contact_id!=nil)
  945. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  946. if(appDelegate.password!=nil)
  947. [params setValue:appDelegate.password forKey:@"password"];
  948. // NSString* ssaved = @"false";
  949. // if(saved)
  950. // ssaved=@"true";
  951. // [params setValue:@"true" forKey:@"saved"];
  952. [params setValue:order_code forKey:@"orderCode"];
  953. [params setValue:path forKey:@"picpath"];
  954. // [params setValue:sourceid forKey:@"sourceid"];
  955. // [params setValue:editor forKey:@"editor"];
  956. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  957. NSData* json=nil;
  958. if(appDelegate.offline_mode)
  959. {
  960. json= [OLDataProvider offline_signorder:params];
  961. }
  962. else
  963. {
  964. if(![self IsNetworkAvailable])
  965. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  966. json=[self get_json:URL_SIGN_ORDER parameters:params];
  967. }
  968. if(json!=nil)
  969. {
  970. NSError *error=nil;
  971. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  972. return jsobj;
  973. }
  974. else
  975. return nil;
  976. }
  977. +(NSDictionary*)commit_Order:(NSString*) order_code //saved:(bool) saved
  978. {
  979. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  980. __block AppDelegate *appDelegate = nil;
  981. dispatch_sync(dispatch_get_main_queue(), ^{
  982. //some UI methods ej
  983. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  984. });
  985. if(appDelegate.user!=nil)
  986. [params setValue:appDelegate.user forKey:@"user"];
  987. if(appDelegate.contact_id!=nil)
  988. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  989. if(appDelegate.password!=nil)
  990. [params setValue:appDelegate.password forKey:@"password"];
  991. // NSString* ssaved = @"false";
  992. // if(saved)
  993. // ssaved=@"true";
  994. [params setValue:@"true" forKey:@"saved"];
  995. [params setValue:order_code forKey:@"orderCode"];
  996. // [params setValue:sourceid forKey:@"sourceid"];
  997. // [params setValue:editor forKey:@"editor"];
  998. [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  999. NSData* json = nil;
  1000. if(appDelegate.offline_mode)
  1001. {
  1002. json= [OLDataProvider offline_submitorder:params];
  1003. }
  1004. else
  1005. {
  1006. if(![self IsNetworkAvailable])
  1007. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1008. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  1009. }
  1010. if(json!=nil)
  1011. {
  1012. NSError *error=nil;
  1013. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1014. return jsobj;
  1015. }
  1016. else
  1017. return nil;
  1018. }
  1019. //+(NSDictionary*)open_Order:(NSString*) order_code
  1020. //{
  1021. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1022. // __block AppDelegate *appDelegate = nil;
  1023. //
  1024. // dispatch_sync(dispatch_get_main_queue(), ^{
  1025. // //some UI methods ej
  1026. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1027. // });
  1028. // if(appDelegate.user!=nil)
  1029. // [params setValue:appDelegate.user forKey:@"user"];
  1030. // // if(appDelegate.contact_id!=nil)
  1031. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1032. // if(appDelegate.password!=nil)
  1033. // [params setValue:appDelegate.password forKey:@"password"];
  1034. //
  1035. // [params setValue:order_code forKey:@"orderCode"];
  1036. // // [params setValue:sourceid forKey:@"sourceid"];
  1037. // // [params setValue:editor forKey:@"editor"];
  1038. //
  1039. // [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  1040. //
  1041. // NSData* json=nil;
  1042. // if(appDelegate.offline_mode)
  1043. // {
  1044. // json=[OLDataProvider offline_editorder:params];
  1045. //
  1046. // }
  1047. // else
  1048. // {
  1049. // if(![self IsNetworkAvailable])
  1050. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1051. //
  1052. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  1053. // }
  1054. // if(json!=nil)
  1055. // {
  1056. // NSError *error=nil;
  1057. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1058. // int result = [[jsobj valueForKey:@"result"] intValue];
  1059. //
  1060. // if (result==2)
  1061. // {
  1062. //
  1063. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1064. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1065. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1066. //
  1067. // [appDelegate update_count_mark];
  1068. //
  1069. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1070. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  1071. // }
  1072. //
  1073. // }
  1074. //
  1075. // return jsobj;
  1076. // }
  1077. // else
  1078. // return nil;
  1079. //}
  1080. +(NSDictionary*)delete_Order:(NSString*) order_id
  1081. {
  1082. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1083. __block AppDelegate *appDelegate = nil;
  1084. dispatch_sync(dispatch_get_main_queue(), ^{
  1085. //some UI methods ej
  1086. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1087. });
  1088. if(appDelegate.user!=nil)
  1089. [params setValue:appDelegate.user forKey:@"user"];
  1090. // if(appDelegate.contact_id!=nil)
  1091. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1092. if(appDelegate.password!=nil)
  1093. [params setValue:appDelegate.password forKey:@"password"];
  1094. [params setValue:order_id forKey:@"orderId"];
  1095. // [params setValue:sourceid forKey:@"sourceid"];
  1096. // [params setValue:editor forKey:@"editor"];
  1097. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  1098. if(appDelegate.offline_mode)
  1099. {
  1100. return [OLDataProvider offline_notimpl];
  1101. }
  1102. if(![self IsNetworkAvailable])
  1103. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1104. NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  1105. if(json!=nil)
  1106. {
  1107. NSError *error=nil;
  1108. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1109. return jsobj;
  1110. }
  1111. else
  1112. return nil;
  1113. }
  1114. +(NSDictionary*)cancel_Order:(NSString*) order_id order_code:(NSString*) order_code
  1115. {
  1116. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1117. __block AppDelegate *appDelegate = nil;
  1118. dispatch_sync(dispatch_get_main_queue(), ^{
  1119. //some UI methods ej
  1120. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1121. });
  1122. if(appDelegate.user!=nil)
  1123. [params setValue:appDelegate.user forKey:@"user"];
  1124. // if(appDelegate.contact_id!=nil)
  1125. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1126. if(appDelegate.password!=nil)
  1127. [params setValue:appDelegate.password forKey:@"password"];
  1128. [params setValue:order_id forKey:@"orderId"];
  1129. [params setValue:order_code forKey:@"orderCode"];
  1130. // [params setValue:sourceid forKey:@"sourceid"];
  1131. // [params setValue:editor forKey:@"editor"];
  1132. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  1133. NSData* json=nil;
  1134. if(appDelegate.offline_mode)
  1135. {
  1136. json=[OLDataProvider offline_cancelorder:params];
  1137. }
  1138. else
  1139. {
  1140. if(![self IsNetworkAvailable])
  1141. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1142. json=[self get_json:URL_CANCEL_ORDER parameters:params];
  1143. }
  1144. if(json!=nil)
  1145. {
  1146. NSError *error=nil;
  1147. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1148. return jsobj;
  1149. }
  1150. else
  1151. return nil;
  1152. }
  1153. +(NSDictionary*)release_Order:(NSString*) order_code withScreen:(NSString *)screenName
  1154. {
  1155. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1156. __block AppDelegate *appDelegate = nil;
  1157. dispatch_sync(dispatch_get_main_queue(), ^{
  1158. //some UI methods ej
  1159. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1160. });
  1161. if(appDelegate.user!=nil)
  1162. [params setValue:appDelegate.user forKey:@"user"];
  1163. // if(appDelegate.contact_id!=nil)
  1164. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1165. if(appDelegate.password!=nil)
  1166. [params setValue:appDelegate.password forKey:@"password"];
  1167. [params setValue:order_code forKey:@"orderCode"];
  1168. // [params setValue:sourceid forKey:@"sourceid"];
  1169. // [params setValue:editor forKey:@"editor"];
  1170. if (screenName) {
  1171. [params setValue:screenName forKey:kScreenName];
  1172. }
  1173. NSData* json=nil;
  1174. if(appDelegate.offline_mode)
  1175. {
  1176. json= [OLDataProvider offline_resetorder:params];
  1177. }
  1178. else
  1179. {
  1180. if(![self IsNetworkAvailable])
  1181. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1182. json=[self get_json:URL_RELEASE_ORDER parameters:params];
  1183. }
  1184. if(json!=nil)
  1185. {
  1186. NSError *error=nil;
  1187. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1188. if([[jsobj valueForKey:@"result"]intValue]==2)
  1189. { [appDelegate SetSo:nil];
  1190. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1191. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1192. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1193. [appDelegate update_count_mark];
  1194. }
  1195. return jsobj;
  1196. }
  1197. else
  1198. return nil;
  1199. }
  1200. +(NSDictionary*)update_OrderCustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info
  1201. {
  1202. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1203. __block AppDelegate *appDelegate = nil;
  1204. dispatch_sync(dispatch_get_main_queue(), ^{
  1205. //some UI methods ej
  1206. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1207. });
  1208. if(appDelegate.user!=nil)
  1209. [info setValue:appDelegate.user forKey:@"user"];
  1210. // if(appDelegate.contact_id!=nil)
  1211. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1212. if(appDelegate.password!=nil)
  1213. [info setValue:appDelegate.password forKey:@"password"];
  1214. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1215. [info setValue:order_code forKey:@"orderCode"];
  1216. // [params setValue:sourceid forKey:@"sourceid"];
  1217. // [params setValue:editor forKey:@"editor"];
  1218. if(appDelegate.offline_mode)
  1219. {
  1220. return [OLDataProvider offline_notimpl];
  1221. }
  1222. if(![self IsNetworkAvailable])
  1223. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1224. NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  1225. if(json!=nil)
  1226. {
  1227. NSError *error=nil;
  1228. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1229. return jsobj;
  1230. }
  1231. else
  1232. return nil;
  1233. }
  1234. //+(NSDictionary*)commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url
  1235. //{
  1236. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1237. // __block AppDelegate *appDelegate = nil;
  1238. //
  1239. // dispatch_sync(dispatch_get_main_queue(), ^{
  1240. // //some UI methods ej
  1241. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1242. // });
  1243. // if(appDelegate.user!=nil)
  1244. // [params setValue:appDelegate.user forKey:@"user"];
  1245. // if(appDelegate.contact_id!=nil)
  1246. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1247. // if(appDelegate.password!=nil)
  1248. // [params setValue:appDelegate.password forKey:@"password"];
  1249. //
  1250. // // if(appDelegate.order_code!=nil)
  1251. // // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1252. //
  1253. // // NSDictionary* customerinfo= appDelegate.customerInfo;
  1254. // //
  1255. // // NSArray* keys=[customerinfo allKeys];
  1256. // // for(int i=0;i<keys.count;i++)
  1257. // // {
  1258. // // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1259. // // }
  1260. // //
  1261. // // [params setValue:sourceid forKey:@"sourceid"];
  1262. // // [params setValue:editor forKey:@"editor"];
  1263. //
  1264. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  1265. //
  1266. // if(appDelegate.offline_mode)
  1267. // {
  1268. // params[@"offline_Command"]=url;
  1269. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  1270. // }
  1271. //
  1272. // if(![self IsNetworkAvailable])
  1273. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1274. //
  1275. // NSData* json=[self get_json:url parameters:params];
  1276. // if(json!=nil)
  1277. // {
  1278. // NSError *error=nil;
  1279. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1280. // if([[jsobj valueForKey:@"result"]intValue]==2)
  1281. // [appDelegate SetSo:nil];
  1282. //
  1283. //
  1284. // return jsobj;
  1285. // }
  1286. // else
  1287. // return nil;
  1288. //}
  1289. +(NSDictionary*)saveandcommit_Order:(NSMutableDictionary*)params
  1290. {
  1291. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1292. __block AppDelegate *appDelegate = nil;
  1293. dispatch_sync(dispatch_get_main_queue(), ^{
  1294. //some UI methods ej
  1295. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1296. });
  1297. if(appDelegate.user!=nil)
  1298. [params setValue:appDelegate.user forKey:@"user"];
  1299. if(appDelegate.contact_id!=nil)
  1300. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1301. if(appDelegate.password!=nil)
  1302. [params setValue:appDelegate.password forKey:@"password"];
  1303. if(appDelegate.order_code!=nil)
  1304. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1305. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1306. //
  1307. // NSArray* keys=[customerinfo allKeys];
  1308. // for(int i=0;i<keys.count;i++)
  1309. // {
  1310. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1311. // }
  1312. //
  1313. // [params setValue:sourceid forKey:@"sourceid"];
  1314. // [params setValue:editor forKey:@"editor"];
  1315. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1316. NSData* json=nil;
  1317. if(appDelegate.offline_mode)
  1318. {
  1319. json=[OLDataProvider offline_submitorder:params];
  1320. }
  1321. else
  1322. {
  1323. if(![self IsNetworkAvailable])
  1324. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1325. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  1326. }
  1327. if(json!=nil)
  1328. {
  1329. NSError *error=nil;
  1330. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1331. if([[jsobj valueForKey:@"result"]intValue]==2)
  1332. [appDelegate SetSo:nil];
  1333. return jsobj;
  1334. }
  1335. else
  1336. return nil;
  1337. }
  1338. +(NSDictionary*)update_Customer:(NSMutableDictionary*)params
  1339. {
  1340. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1341. __block AppDelegate *appDelegate = nil;
  1342. dispatch_sync(dispatch_get_main_queue(), ^{
  1343. //some UI methods ej
  1344. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1345. });
  1346. if(appDelegate.user!=nil)
  1347. [params setValue:appDelegate.user forKey:@"user"];
  1348. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1349. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1350. // else
  1351. if(appDelegate.contact_id!=nil)
  1352. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1353. if(appDelegate.password!=nil)
  1354. [params setValue:appDelegate.password forKey:@"password"];
  1355. // NSDictionary* customerinfo=nil;
  1356. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1357. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1358. // else
  1359. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1360. //
  1361. // appDelegate.customerInfo;
  1362. // NSArray* keys=[customerinfo allKeys];
  1363. // for(int i=0;i<keys.count;i++)
  1364. // {
  1365. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1366. // }
  1367. // [params setValue:sourceid forKey:@"sourceid"];
  1368. // [params setValue:editor forKey:@"editor"];
  1369. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1370. NSData* json=nil;
  1371. if(appDelegate.offline_mode)
  1372. {
  1373. json= [OLDataProvider offline_saveContact:params];
  1374. }
  1375. else
  1376. {
  1377. if(![self IsNetworkAvailable])
  1378. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1379. json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  1380. }
  1381. if(json!=nil)
  1382. {
  1383. NSError *error=nil;
  1384. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1385. return jsobj;
  1386. }
  1387. else
  1388. return nil;
  1389. }
  1390. +(NSDictionary*)save_newCustomer:(NSMutableDictionary*)params
  1391. {
  1392. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1393. __block AppDelegate *appDelegate = nil;
  1394. dispatch_sync(dispatch_get_main_queue(), ^{
  1395. //some UI methods ej
  1396. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1397. });
  1398. if(appDelegate.user!=nil)
  1399. [params setValue:appDelegate.user forKey:@"user"];
  1400. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1401. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1402. // else
  1403. if(appDelegate.contact_id!=nil)
  1404. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1405. if(appDelegate.password!=nil)
  1406. [params setValue:appDelegate.password forKey:@"password"];
  1407. // NSDictionary* customerinfo=nil;
  1408. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1409. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1410. // else
  1411. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1412. //
  1413. // appDelegate.customerInfo;
  1414. // NSArray* keys=[customerinfo allKeys];
  1415. // for(int i=0;i<keys.count;i++)
  1416. // {
  1417. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1418. // }
  1419. // [params setValue:sourceid forKey:@"sourceid"];
  1420. // [params setValue:editor forKey:@"editor"];
  1421. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1422. NSData* json=nil;
  1423. if(appDelegate.offline_mode)
  1424. {
  1425. json= [OLDataProvider offline_saveNewContact:params];
  1426. }
  1427. else
  1428. {
  1429. if(![self IsNetworkAvailable])
  1430. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1431. json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  1432. }
  1433. if(json!=nil)
  1434. {
  1435. NSError *error=nil;
  1436. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1437. return jsobj;
  1438. }
  1439. else
  1440. return nil;
  1441. }
  1442. +(NSDictionary*)save_Order:(NSMutableDictionary*)params
  1443. {
  1444. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1445. __block AppDelegate *appDelegate = nil;
  1446. dispatch_sync(dispatch_get_main_queue(), ^{
  1447. //some UI methods ej
  1448. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1449. });
  1450. if(appDelegate.user!=nil)
  1451. [params setValue:appDelegate.user forKey:@"user"];
  1452. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1453. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1454. // else
  1455. if(appDelegate.contact_id!=nil)
  1456. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1457. if(appDelegate.password!=nil)
  1458. [params setValue:appDelegate.password forKey:@"password"];
  1459. if(appDelegate.order_code!=nil)
  1460. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1461. // NSDictionary* customerinfo=nil;
  1462. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1463. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1464. // else
  1465. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1466. //
  1467. // appDelegate.customerInfo;
  1468. // NSArray* keys=[customerinfo allKeys];
  1469. // for(int i=0;i<keys.count;i++)
  1470. // {
  1471. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1472. // }
  1473. // [params setValue:sourceid forKey:@"sourceid"];
  1474. // [params setValue:editor forKey:@"editor"];
  1475. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1476. NSData* json=nil;
  1477. if(appDelegate.offline_mode)
  1478. {
  1479. json= [OLDataProvider offline_saveorder:params];
  1480. }
  1481. else
  1482. {
  1483. if(![self IsNetworkAvailable])
  1484. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1485. json=[self get_json:URL_SAVE_ORDER parameters:params];
  1486. }
  1487. if(json!=nil)
  1488. {
  1489. NSError *error=nil;
  1490. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1491. NSString *so = [jsobj valueForKey:@"so#"];
  1492. if (so) {
  1493. [appDelegate SetSo:so];
  1494. }
  1495. return jsobj;
  1496. }
  1497. else
  1498. return nil;
  1499. }
  1500. //+(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
  1501. //{
  1502. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1503. // __block AppDelegate *appDelegate = nil;
  1504. //
  1505. // dispatch_sync(dispatch_get_main_queue(), ^{
  1506. // //some UI methods ej
  1507. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1508. // });
  1509. // if(appDelegate.user!=nil)
  1510. // [params setValue:appDelegate.user forKey:@"user"];
  1511. //
  1512. //
  1513. // // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1514. // // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1515. // // else
  1516. //
  1517. // if(appDelegate.contact_id!=nil)
  1518. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1519. // if(appDelegate.password!=nil)
  1520. // [params setValue:appDelegate.password forKey:@"password"];
  1521. //
  1522. // if(appDelegate.order_code!=nil)
  1523. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1524. // // [params setValue:sourceid forKey:@"sourceid"];
  1525. // // [params setValue:editor forKey:@"editor"];
  1526. // DebugLog(@"request editor url:%@",request_url);
  1527. //
  1528. //
  1529. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1530. // {
  1531. // [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1532. // }
  1533. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1534. // {
  1535. // [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1536. // }
  1537. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1538. // {
  1539. // [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  1540. // }
  1541. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1542. // {
  1543. // [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1544. // }
  1545. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1546. // {
  1547. // [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  1548. // }
  1549. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1550. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1551. // }
  1552. //
  1553. // NSData* json = nil;
  1554. // if(appDelegate.offline_mode)
  1555. // {
  1556. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1557. // {
  1558. // json= [OLDataProvider offline_createContact:params];
  1559. // }
  1560. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1561. // {
  1562. // json= [OLDataProvider offline_editContact:params];
  1563. // }
  1564. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1565. // {
  1566. // json= [OLDataProvider offline_contactAdvancedSearch:params];
  1567. // }
  1568. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1569. // {
  1570. // json= [OLDataProvider offline_placeorder:params];
  1571. // }
  1572. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1573. // {
  1574. // json= [OLDataProvider offline_addreditor:params];
  1575. // }
  1576. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1577. // json = [OLDataProvider offline_createTearSheet:params];
  1578. // }
  1579. //
  1580. // else
  1581. // return [OLDataProvider offline_notimpl];
  1582. // }
  1583. // else
  1584. // {
  1585. // if(![self IsNetworkAvailable])
  1586. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1587. //
  1588. // if([request_url isEqualToString:URL_CARTDELIVERY])
  1589. // {
  1590. // NSError *error=nil;
  1591. //
  1592. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1593. // params[@"resultSerial"]=uuid;
  1594. //
  1595. // for(int i=0;i<150;i++)
  1596. // {
  1597. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1598. // // result_params[@"resultSerial"]=uuid;
  1599. // json=[self get_json:request_url parameters:params];
  1600. // if(json!=nil)
  1601. // {
  1602. //
  1603. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1604. // if([jsobj[@"result"] intValue]==2 || [jsobj[@"result"] intValue] == 8)
  1605. // {
  1606. // break;
  1607. // }
  1608. // }
  1609. // sleep(2);
  1610. // }
  1611. // }
  1612. // else
  1613. // json =[self get_json:request_url parameters:params];
  1614. // }
  1615. // if(json!=nil)
  1616. // {
  1617. // NSError *error=nil;
  1618. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1619. // return jsobj;
  1620. // }
  1621. // else
  1622. // return nil;
  1623. //}
  1624. //+(NSDictionary*)request_OrderInfo:(NSString*) orderid
  1625. //{
  1626. // if(![self IsNetworkAvailable])
  1627. // return nil;
  1628. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1629. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1630. // if(appDelegate.user!=nil)
  1631. // [params setValue:appDelegate.user forKey:@"user"];
  1632. // if(appDelegate.password!=nil)
  1633. // [params setValue:appDelegate.password forKey:@"password"];
  1634. // [params setValue:orderid forKey:@"orderid"];
  1635. // NSData* json=[self get_json:URL_ORDER_INFO parameters:params];
  1636. // NSError *error=nil;
  1637. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1638. // return jsobj;
  1639. //}
  1640. +(NSDictionary*)request_OrderList:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged
  1641. {
  1642. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1643. __block AppDelegate *appDelegate = nil;
  1644. dispatch_sync(dispatch_get_main_queue(), ^{
  1645. //some UI methods ej
  1646. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1647. });
  1648. if(appDelegate.user!=nil)
  1649. [params setValue:appDelegate.user forKey:@"user"];
  1650. if(appDelegate.contact_id!=nil)
  1651. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1652. if(appDelegate.password!=nil)
  1653. [params setValue:appDelegate.password forKey:@"password"];
  1654. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1655. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1656. [params setValue:keywords forKey:@"keyWord"];
  1657. [params setValue:customer forKey:@"customer_filter"];
  1658. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  1659. [params setValue:status_code forKey:@"orderStatus"];
  1660. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1661. if (keywords) {
  1662. [params setObject:@"Search" forKey:kAction];
  1663. }
  1664. NSData* json=nil;
  1665. if(appDelegate.offline_mode)
  1666. {
  1667. json= [OLDataProvider offline_orderlist:params];
  1668. }
  1669. else
  1670. {
  1671. if(![self IsNetworkAvailable])
  1672. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1673. json=[self get_json:URL_ORDER_LIST parameters:params];
  1674. }
  1675. if(json==nil)
  1676. return nil;
  1677. NSError *error=nil;
  1678. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1679. return jsobj;
  1680. }
  1681. +(NSDictionary*)request_PDFList:(int ) offset limit:(int)limit keywords:(NSString* ) keywords
  1682. {
  1683. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1684. __block AppDelegate *appDelegate = nil;
  1685. dispatch_sync(dispatch_get_main_queue(), ^{
  1686. //some UI methods ej
  1687. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1688. });
  1689. if(appDelegate.user!=nil)
  1690. [params setValue:appDelegate.user forKey:@"user"];
  1691. if(appDelegate.contact_id!=nil)
  1692. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1693. if(appDelegate.password!=nil)
  1694. [params setValue:appDelegate.password forKey:@"password"];
  1695. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  1696. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  1697. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  1698. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  1699. // [params setValue:filter forKey:@"filter"];
  1700. [params setValue:keywords forKey:@"keyWord"];
  1701. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  1702. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  1703. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  1704. if (keywords) {
  1705. [params setObject:@"Search" forKey:kAction];
  1706. }
  1707. NSData* json = nil;
  1708. if(appDelegate.offline_mode)
  1709. {
  1710. json = [OLDataProvider offline_pdfList:params];
  1711. } else {
  1712. if(![self IsNetworkAvailable])
  1713. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1714. json=[self get_json:URL_DM_LIST parameters:params];
  1715. }
  1716. if(json==nil)
  1717. return nil;
  1718. NSError *error=nil;
  1719. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1720. return jsobj;
  1721. }
  1722. //+(NSString*) create_portfolio:(NSMutableDictionary*)params
  1723. //{
  1724. // __block AppDelegate *appDelegate = nil;
  1725. //
  1726. // dispatch_sync(dispatch_get_main_queue(), ^{
  1727. // //some UI methods ej
  1728. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1729. // });
  1730. // if(appDelegate.offline_mode)
  1731. // {
  1732. //
  1733. //
  1734. // NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  1735. // if(json==nil)
  1736. // return nil;
  1737. // NSError *error=nil;
  1738. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1739. //
  1740. // return jsobj[@"pdf_path"];
  1741. // }
  1742. // else
  1743. // {
  1744. // return nil;
  1745. // }
  1746. //}
  1747. //+(NSDictionary*)direct_save_TearSheet:(NSMutableDictionary*)params//(NSString*) request_url name:(NSString*)name delete:(NSString* )ids note:(NSString* )saveNote modelIds:(NSDictionary *)modelIds
  1748. //{
  1749. // NSMutableDictionary* off_params = [params mutableCopy];;
  1750. //
  1751. // params[@"off_params"]=[RAConvertor dict2string:off_params];;
  1752. // __block AppDelegate *appDelegate = nil;
  1753. //
  1754. // dispatch_sync(dispatch_get_main_queue(), ^{
  1755. // //some UI methods ej
  1756. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1757. // });
  1758. // if(appDelegate.user!=nil)
  1759. // [params setValue:appDelegate.user forKey:@"user"];
  1760. // if(appDelegate.contact_id!=nil)
  1761. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1762. // if(appDelegate.password!=nil)
  1763. // [params setValue:appDelegate.password forKey:@"password"];
  1764. //
  1765. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1766. //
  1767. // /*
  1768. // [params setValue:request_url forKey:@"pdfUrl"];
  1769. // [params setValue:name forKey:@"pdfName"];
  1770. // [params setValue:ids forKey:@"itemIds"];
  1771. // [params setValue:saveNote forKey:@"pdfNote"];
  1772. // [params setValue:[modelIds objectForKey:@"product_ids"] forKey:@"product_ids"];
  1773. // [params setValue:[modelIds objectForKey:@"item_ids"] forKey:@"item_ids"];
  1774. // [params setValue:[modelIds objectForKey:@"remove_item"] forKey:@"remove_item"];
  1775. // */
  1776. // NSData* json= nil;
  1777. //
  1778. // if(appDelegate.offline_mode)
  1779. // {
  1780. // json = [OLDataProvider offline_direct_save_TearSheet:params];
  1781. // }
  1782. // else
  1783. // {
  1784. // if(![self IsNetworkAvailable])
  1785. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1786. //
  1787. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1788. //
  1789. // NSError *error=nil;
  1790. //
  1791. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1792. // params[@"resultSerial"]=uuid;
  1793. //
  1794. // for(int i=0;i<150;i++)
  1795. // {
  1796. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1797. // // result_params[@"resultSerial"]=uuid;
  1798. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1799. // if(json!=nil)
  1800. // {
  1801. //
  1802. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1803. // if([jsobj[@"result"] intValue]==2)
  1804. // {
  1805. // break;
  1806. // }
  1807. // }
  1808. // sleep(5);
  1809. // }
  1810. //
  1811. // }
  1812. // if(json==nil)
  1813. // return nil;
  1814. // NSError *error=nil;
  1815. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1816. // return jsobj;
  1817. //}
  1818. //+(NSDictionary*)request_TearSheet:(NSMutableDictionary*)params//(NSString*) request_url
  1819. //{
  1820. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1821. // __block AppDelegate *appDelegate = nil;
  1822. //
  1823. // dispatch_sync(dispatch_get_main_queue(), ^{
  1824. // //some UI methods ej
  1825. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1826. // });
  1827. // if(appDelegate.user!=nil)
  1828. // [params setValue:appDelegate.user forKey:@"user"];
  1829. // if(appDelegate.contact_id!=nil)
  1830. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1831. // if(appDelegate.password!=nil)
  1832. // [params setValue:appDelegate.password forKey:@"password"];
  1833. //
  1834. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1835. //
  1836. // // [params setValue:request_url forKey:@"pdfUrl"];
  1837. // NSData* json= nil;
  1838. // if(appDelegate.offline_mode)
  1839. // {
  1840. // json= [OLDataProvider offline_request_tearsheet:params];
  1841. // }
  1842. // else
  1843. // {
  1844. // if(![self IsNetworkAvailable])
  1845. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1846. //
  1847. // NSError *error=nil;
  1848. //
  1849. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1850. // params[@"resultSerial"]=uuid;
  1851. //
  1852. // for(int i=0;i<150;i++)
  1853. // {
  1854. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1855. // // result_params[@"resultSerial"]=uuid;
  1856. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1857. // if(json!=nil)
  1858. // {
  1859. //
  1860. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1861. // if([jsobj[@"result"] intValue]==2)
  1862. // {
  1863. // break;
  1864. // }
  1865. // }
  1866. // sleep(5);
  1867. // }
  1868. // }
  1869. // if(json==nil)
  1870. // return nil;
  1871. // NSError *error=nil;
  1872. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1873. // return jsobj;
  1874. //}
  1875. //+(NSDictionary*)save_TearSheet:(NSMutableDictionary *)params//(NSString*) path name:(NSString*)name delete:(NSString* )ids note:(NSString*)note configureParams:(NSString *)configureParams modelIds:(NSDictionary *)modelIds
  1876. //{
  1877. //
  1878. //
  1879. // NSMutableDictionary* off_params = [params mutableCopy];;
  1880. //
  1881. // params[@"off_params"]=[RAConvertor dict2string:off_params];
  1882. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1883. // __block AppDelegate *appDelegate = nil;
  1884. //
  1885. // dispatch_sync(dispatch_get_main_queue(), ^{
  1886. // //some UI methods ej
  1887. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1888. // });
  1889. // if(appDelegate.user!=nil)
  1890. // [params setValue:appDelegate.user forKey:@"user"];
  1891. // if(appDelegate.contact_id!=nil)
  1892. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1893. // if(appDelegate.password!=nil)
  1894. // [params setValue:appDelegate.password forKey:@"password"];
  1895. //
  1896. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1897. //
  1898. // /*
  1899. // [params setValue:path forKey:@"pdfPath"];
  1900. // [params setValue:name forKey:@"pdfName"];
  1901. // [params setValue:note forKey:@"pdfNote"];
  1902. // [params setValue:ids forKey:@"itemIds"];
  1903. // [params setValue:configureParams forKey:@"configureParams"];
  1904. // [params setValue:[modelIds objectForKey:@"product_ids"] forKey:@"product_ids"];
  1905. // [params setValue:[modelIds objectForKey:@"item_ids"] forKey:@"item_ids"];
  1906. // [params setValue:[modelIds objectForKey:@"remove_item"] forKey:@"remove_item"];
  1907. // */
  1908. // NSData* json = nil;
  1909. // if(appDelegate.offline_mode)
  1910. // {
  1911. // json = [OLDataProvider offline_save_TearSheet:params];
  1912. // } else {
  1913. // if(![self IsNetworkAvailable])
  1914. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1915. //
  1916. // json=[self get_json:URL_SAVE_DM parameters:params];
  1917. // }
  1918. // if(json==nil)
  1919. // return nil;
  1920. // NSError *error=nil;
  1921. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1922. // return jsobj;
  1923. //}
  1924. +(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code//device:(NSString*) device
  1925. {
  1926. return nil;
  1927. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1928. __block AppDelegate *appDelegate = nil;
  1929. dispatch_sync(dispatch_get_main_queue(), ^{
  1930. //some UI methods ej
  1931. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1932. });
  1933. if(appDelegate.user!=nil)
  1934. [params setValue:appDelegate.user forKey:@"user"];
  1935. [params setValue:up_params forKey:@"upparam"];
  1936. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  1937. [params setValue:result forKey:@"result"];
  1938. [params setValue:module forKey:@"interfac"];
  1939. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  1940. // [params setValue:module forKey:@"module"];
  1941. // [[UIDevice currentDevice] name];
  1942. // if(appDelegate.offline_mode)
  1943. // {
  1944. // return [OLDataProvider offline_notimpl];
  1945. // }
  1946. if(![self IsNetworkAvailable])
  1947. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1948. NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  1949. if(json==nil)
  1950. return nil;
  1951. NSError *error=nil;
  1952. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1953. return jsobj;
  1954. }
  1955. //+(NSDictionary*)request_ContactList:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams
  1956. //{
  1957. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1958. //
  1959. // if(upparams!=nil)
  1960. // params = [upparams mutableCopy];
  1961. // __block AppDelegate *appDelegate = nil;
  1962. //
  1963. // dispatch_sync(dispatch_get_main_queue(), ^{
  1964. // //some UI methods ej
  1965. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1966. // });
  1967. // if(appDelegate.user!=nil)
  1968. // [params setValue:appDelegate.user forKey:@"user"];
  1969. //
  1970. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1971. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1972. // else
  1973. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1974. //
  1975. // if(appDelegate.password!=nil)
  1976. // [params setValue:appDelegate.password forKey:@"password"];
  1977. //
  1978. // [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1979. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1980. // [params setValue:contact_type forKey:@"contactType"];
  1981. // [params setValue:keywords forKey:@"keyword"];
  1982. //
  1983. // [params setObject:ScreenCodeAccount forKey:kScreenName];
  1984. // if (keywords) {
  1985. // [params setObject:@"Search" forKey:kAction];
  1986. // }
  1987. // if (upparams) {
  1988. // [params setObject:@"Advance Search" forKey:kAction];
  1989. // }
  1990. //
  1991. // NSString* url=nil;
  1992. // if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  1993. // url=URL_SHIPTO_LIST;
  1994. // else
  1995. // url=URL_CONTACT_LIST;
  1996. //
  1997. // if(appDelegate.offline_mode)
  1998. // return [OLDataProvider offline_contactlist:params];
  1999. //
  2000. // if(![self IsNetworkAvailable])
  2001. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2002. //
  2003. // NSData* json=[self get_json:url parameters:params];
  2004. // if(json==nil)
  2005. // return nil;
  2006. // NSError *error=nil;
  2007. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2008. // return jsobj;
  2009. //}
  2010. //+(NSDictionary*)request_OrderDetail:(NSMutableDictionary *) params
  2011. //{
  2012. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2013. // if (params == nil) {
  2014. // params = [[NSMutableDictionary alloc] init];
  2015. // }
  2016. // __block AppDelegate *appDelegate = nil;
  2017. //
  2018. // dispatch_sync(dispatch_get_main_queue(), ^{
  2019. // //some UI methods ej
  2020. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2021. // });
  2022. // if(appDelegate.user!=nil)
  2023. // [params setValue:appDelegate.user forKey:@"user"];
  2024. // if(appDelegate.contact_id!=nil)
  2025. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2026. // if(appDelegate.password!=nil)
  2027. // [params setValue:appDelegate.password forKey:@"password"];
  2028. //
  2029. //
  2030. // // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  2031. //
  2032. // [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  2033. //
  2034. // NSData* json=nil;
  2035. // if(appDelegate.offline_mode)
  2036. // {
  2037. // json= [OLDataProvider offline_orderdetail:params];
  2038. // }
  2039. // else
  2040. // {
  2041. // if(![self IsNetworkAvailable])
  2042. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2043. //
  2044. // NSError *error=nil;
  2045. //
  2046. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2047. // params[@"resultSerial"]=uuid;
  2048. //
  2049. // for(int i=0;i<150;i++)
  2050. // {
  2051. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2052. // // result_params[@"resultSerial"]=uuid;
  2053. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  2054. // if(json!=nil)
  2055. // {
  2056. //
  2057. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2058. // int resultCode = [jsobj[@"result"] intValue];
  2059. // if(resultCode==2 || resultCode == 8)
  2060. // {
  2061. // break;
  2062. // }
  2063. // }
  2064. // sleep(2);
  2065. // }
  2066. //
  2067. //
  2068. // }
  2069. // if(json==nil)
  2070. // return nil;
  2071. // NSError *error=nil;
  2072. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2073. // return jsobj;
  2074. //}
  2075. //+(NSDictionary*) add_toCart:(NSString* ) item_id count:(int) count name:(NSString *)name
  2076. //{
  2077. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2078. // __block AppDelegate *appDelegate = nil;
  2079. //
  2080. // dispatch_sync(dispatch_get_main_queue(), ^{
  2081. // //some UI methods ej
  2082. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2083. // });
  2084. // if(appDelegate.user!=nil)
  2085. // [params setValue:appDelegate.user forKey:@"user"];
  2086. // if(appDelegate.contact_id!=nil)
  2087. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2088. // if(appDelegate.password!=nil)
  2089. // [params setValue:appDelegate.password forKey:@"password"];
  2090. //
  2091. // if(appDelegate.order_code!=nil)
  2092. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2093. // [params setValue:item_id forKey:@"product_id"];
  2094. // [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  2095. //
  2096. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  2097. // [params setObject:@"Add To Cart" forKey:kAction];
  2098. // if (name) {
  2099. // NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  2100. // [params setObject:extra forKey:kExtra];
  2101. // }
  2102. //
  2103. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2104. //
  2105. // NSArray* keys=[customerinfo allKeys];
  2106. // for(int i=0;i<keys.count;i++)
  2107. // {
  2108. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2109. // }
  2110. //
  2111. // NSData* json=nil;
  2112. // if(appDelegate.offline_mode)
  2113. // {
  2114. // json=[OLDataProvider offline_add2cart:params];
  2115. // }
  2116. // else
  2117. // {
  2118. // if(![self IsNetworkAvailable])
  2119. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2120. //
  2121. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  2122. // }
  2123. // if(json==nil)
  2124. // return nil;
  2125. // NSError *error=nil;
  2126. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2127. //
  2128. //
  2129. //
  2130. // int result = [[jsobj valueForKey:@"result"] intValue];
  2131. //
  2132. // if (result==2)
  2133. // {
  2134. //
  2135. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2136. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2137. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2138. //
  2139. // [appDelegate update_count_mark];
  2140. // }
  2141. //
  2142. // return jsobj;
  2143. //}
  2144. //+(NSDictionary*) add_toCart_byName:(NSString* ) model_name withScreen:(NSString *)screenName
  2145. //{
  2146. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2147. // __block AppDelegate *appDelegate = nil;
  2148. //
  2149. // dispatch_sync(dispatch_get_main_queue(), ^{
  2150. // //some UI methods ej
  2151. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2152. // });
  2153. // if(appDelegate.user!=nil)
  2154. // [params setValue:appDelegate.user forKey:@"user"];
  2155. // if(appDelegate.contact_id!=nil)
  2156. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2157. // if(appDelegate.password!=nil)
  2158. // [params setValue:appDelegate.password forKey:@"password"];
  2159. //
  2160. // if(appDelegate.order_code!=nil)
  2161. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2162. // [params setValue:model_name forKey:@"product_name"];
  2163. // [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  2164. //
  2165. // [params setObject:screenName forKey:kScreenName];
  2166. // [params setObject:@"Add To Cart" forKey:kAction];
  2167. // if (!model_name) {
  2168. // model_name = @"";
  2169. // }
  2170. // [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  2171. //
  2172. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2173. //
  2174. // NSArray* keys=[customerinfo allKeys];
  2175. // for(int i=0;i<keys.count;i++)
  2176. // {
  2177. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2178. // }
  2179. // NSData* json=nil;
  2180. // if(appDelegate.offline_mode)
  2181. // {
  2182. // json= [OLDataProvider offline_add2cartbyname:params];
  2183. // }
  2184. // else
  2185. // {
  2186. // if(![self IsNetworkAvailable])
  2187. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2188. //
  2189. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  2190. // }
  2191. // if(json==nil)
  2192. // return nil;
  2193. // NSError *error=nil;
  2194. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2195. //
  2196. //
  2197. //
  2198. // int result = [[jsobj valueForKey:@"result"] intValue];
  2199. //
  2200. // if (result==2||result==8)
  2201. // {
  2202. //
  2203. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2204. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2205. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2206. //
  2207. // [appDelegate update_count_mark];
  2208. // }
  2209. //
  2210. // return jsobj;
  2211. //}
  2212. //+(NSDictionary*) new_Customer
  2213. //{
  2214. // if(![self IsNetworkAvailable])
  2215. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2216. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2217. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2218. // if(appDelegate.user!=nil)
  2219. // [params setValue:appDelegate.user forKey:@"user"];
  2220. //// if(appDelegate.contact_id!=nil)
  2221. //// [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2222. // if(appDelegate.password!=nil)
  2223. // [params setValue:appDelegate.password forKey:@"password"];
  2224. //
  2225. //// if(appDelegate.order_code!=nil)
  2226. //// [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2227. //
  2228. //
  2229. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2230. //
  2231. // NSArray* keys=[customerinfo allKeys];
  2232. // for(int i=0;i<keys.count;i++)
  2233. // {
  2234. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2235. // }
  2236. //
  2237. // NSData* json=[self get_json:URL_CUSTOMER_EDIT parameters:params];
  2238. // if(json==nil)
  2239. // return nil;
  2240. // NSError *error=nil;
  2241. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2242. // return jsobj;
  2243. //}
  2244. //+(NSDictionary*) new_Order
  2245. //{
  2246. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2247. // __block AppDelegate *appDelegate = nil;
  2248. //
  2249. // dispatch_sync(dispatch_get_main_queue(), ^{
  2250. // //some UI methods ej
  2251. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2252. // });
  2253. // if(appDelegate.user!=nil)
  2254. // [params setValue:appDelegate.user forKey:@"user"];
  2255. // if(appDelegate.contact_id!=nil)
  2256. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2257. // if(appDelegate.password!=nil)
  2258. // [params setValue:appDelegate.password forKey:@"password"];
  2259. //
  2260. // if(appDelegate.order_code!=nil)
  2261. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2262. //
  2263. //
  2264. // [params setObject:ScreenCodeOrderList forKey:kScreenName];
  2265. //
  2266. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2267. //
  2268. // NSArray* keys=[customerinfo allKeys];
  2269. // for(int i=0;i<keys.count;i++)
  2270. // {
  2271. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2272. // }
  2273. //
  2274. // NSData* json = nil;
  2275. // if(appDelegate.offline_mode)
  2276. // {
  2277. // json= [OLDataProvider offline_createorder:params];
  2278. // }
  2279. // else
  2280. // {
  2281. // if(![self IsNetworkAvailable])
  2282. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2283. //
  2284. // json=[self get_json:URL_NEW_ORDER parameters:params];
  2285. // }
  2286. // if(json==nil)
  2287. // return nil;
  2288. // NSError *error=nil;
  2289. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2290. // int result = [[jsobj valueForKey:@"result"] intValue];
  2291. //
  2292. // if (result==2)
  2293. // {
  2294. //
  2295. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2296. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2297. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2298. //
  2299. // [appDelegate update_count_mark];
  2300. // }
  2301. //
  2302. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  2303. //
  2304. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  2305. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  2306. // }
  2307. //
  2308. // return jsobj;
  2309. //}
  2310. +(NSDictionary*) add_toPortfolio:(NSString* ) item_id withScreen:(NSString *)screenName
  2311. {
  2312. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2313. __block AppDelegate *appDelegate = nil;
  2314. dispatch_sync(dispatch_get_main_queue(), ^{
  2315. //some UI methods ej
  2316. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2317. });
  2318. if(appDelegate.user!=nil)
  2319. [params setValue:appDelegate.user forKey:@"user"];
  2320. if(appDelegate.contact_id!=nil)
  2321. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2322. if(appDelegate.password!=nil)
  2323. [params setValue:appDelegate.password forKey:@"password"];
  2324. [params setValue:item_id forKey:@"product_id"];
  2325. [params setObject:screenName forKey:kScreenName];
  2326. NSData* json = nil;
  2327. if(appDelegate.offline_mode)
  2328. {
  2329. json = [OLDataProvider offline_add2Portfolio:params];
  2330. } else {
  2331. if(![self IsNetworkAvailable])
  2332. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2333. json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  2334. }
  2335. if(json==nil)
  2336. return nil;
  2337. NSError *error=nil;
  2338. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2339. int result = [[jsobj valueForKey:@"result"] intValue];
  2340. if (result==2)
  2341. {
  2342. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2343. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2344. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2345. [appDelegate update_count_mark];
  2346. }
  2347. return jsobj;
  2348. }
  2349. //+(NSDictionary*) add_toWatchList:(NSString* ) item_id withScreen:(NSString *)screenName
  2350. //{
  2351. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2352. // __block AppDelegate *appDelegate = nil;
  2353. //
  2354. // dispatch_sync(dispatch_get_main_queue(), ^{
  2355. // //some UI methods ej
  2356. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2357. // });
  2358. // if(appDelegate.user!=nil)
  2359. // [params setValue:appDelegate.user forKey:@"user"];
  2360. // if(appDelegate.contact_id!=nil)
  2361. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2362. // if(appDelegate.password!=nil)
  2363. // [params setValue:appDelegate.password forKey:@"password"];
  2364. //
  2365. //
  2366. // [params setValue:item_id forKey:@"product_id"];
  2367. //
  2368. // [params setObject:screenName forKey:kScreenName];
  2369. //
  2370. // if(appDelegate.offline_mode)
  2371. // {
  2372. // return [OLDataProvider offline_add2wishlist:params];
  2373. // }
  2374. // if(![self IsNetworkAvailable])
  2375. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2376. //
  2377. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  2378. // if(json==nil)
  2379. // return nil;
  2380. // NSError *error=nil;
  2381. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2382. // int result = [[jsobj valueForKey:@"result"] intValue];
  2383. //
  2384. // if (result==2)
  2385. // {
  2386. //
  2387. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2388. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2389. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2390. //
  2391. // [appDelegate update_count_mark];
  2392. // }
  2393. // return jsobj;
  2394. //}
  2395. //+(NSDictionary*) cart_setPrice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes
  2396. //{
  2397. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2398. // __block AppDelegate *appDelegate = nil;
  2399. //
  2400. // dispatch_sync(dispatch_get_main_queue(), ^{
  2401. // //some UI methods ej
  2402. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2403. // });
  2404. // if(appDelegate.user!=nil)
  2405. // [params setValue:appDelegate.user forKey:@"user"];
  2406. // if(appDelegate.contact_id!=nil)
  2407. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2408. // if(appDelegate.password!=nil)
  2409. // [params setValue:appDelegate.password forKey:@"password"];
  2410. //
  2411. // [params setValue:cart_id forKey:@"cartitem_id"];
  2412. // [params setValue:notes forKey:@"item_note"];
  2413. //
  2414. // [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  2415. //
  2416. // [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  2417. //
  2418. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2419. //
  2420. // NSData* json= nil;
  2421. // if(appDelegate.offline_mode)
  2422. // {
  2423. // json=[OLDataProvider offline_cartsetprice:params];
  2424. // }
  2425. // else
  2426. // {
  2427. // if(![self IsNetworkAvailable])
  2428. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2429. //
  2430. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2431. // }
  2432. // if(json==nil)
  2433. // return nil;
  2434. // NSError *error=nil;
  2435. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2436. // return jsobj;
  2437. //}
  2438. //+(NSDictionary*) portfolio_setQTY:(NSString*) watchlist_id QTY:(int)qty
  2439. //{
  2440. // if(![self IsNetworkAvailable])
  2441. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2442. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2443. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2444. // if(appDelegate.user!=nil)
  2445. // [params setValue:appDelegate.user forKey:@"user"];
  2446. // if(appDelegate.contact_id!=nil)
  2447. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2448. // if(appDelegate.password!=nil)
  2449. // [params setValue:appDelegate.password forKey:@"password"];
  2450. //
  2451. // [params setValue:watchlist_id forKey:@"item_id"];
  2452. //
  2453. // [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  2454. //
  2455. //
  2456. //
  2457. // NSData* json=[self get_json:URL_DM_SET_QTY parameters:params];
  2458. // if(json==nil)
  2459. // return nil;
  2460. // NSError *error=nil;
  2461. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2462. // return jsobj;
  2463. //}
  2464. +(NSDictionary*) portfolio_setPrice:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes
  2465. {
  2466. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2467. __block AppDelegate *appDelegate = nil;
  2468. dispatch_sync(dispatch_get_main_queue(), ^{
  2469. //some UI methods ej
  2470. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2471. });
  2472. if(appDelegate.user!=nil)
  2473. [params setValue:appDelegate.user forKey:@"user"];
  2474. if(appDelegate.contact_id!=nil)
  2475. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2476. if(appDelegate.password!=nil)
  2477. [params setValue:appDelegate.password forKey:@"password"];
  2478. [params setValue:watchlist_id forKey:@"item_id"];
  2479. // if(notes.length>0)
  2480. // [params setValue:notes forKey:@"notes"];
  2481. if(notes)
  2482. [params setValue:notes forKey:@"notes"];
  2483. if(price != -MAXFLOAT)
  2484. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  2485. if (discount != -MAXFLOAT)
  2486. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  2487. if(qty_p != -MAXFLOAT)
  2488. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  2489. if(qty != -INT32_MAX)
  2490. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  2491. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2492. NSData* json = nil;
  2493. if(appDelegate.offline_mode)
  2494. {
  2495. json = [OLDataProvider offline_editPortfolio:params];
  2496. } else {
  2497. if(![self IsNetworkAvailable])
  2498. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2499. json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  2500. }
  2501. if(json==nil)
  2502. return nil;
  2503. NSError *error=nil;
  2504. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2505. return jsobj;
  2506. }
  2507. //+(NSDictionary*) cart_setGeneralNote:(NSString*) order_code notes:(NSString*) notes
  2508. //{
  2509. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2510. // __block AppDelegate *appDelegate = nil;
  2511. //
  2512. // dispatch_sync(dispatch_get_main_queue(), ^{
  2513. // //some UI methods ej
  2514. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2515. // });
  2516. // if(appDelegate.user!=nil)
  2517. // [params setValue:appDelegate.user forKey:@"user"];
  2518. // if(appDelegate.contact_id!=nil)
  2519. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2520. // if(appDelegate.password!=nil)
  2521. // [params setValue:appDelegate.password forKey:@"password"];
  2522. //
  2523. // [params setValue:order_code forKey:@"orderCode"];
  2524. //
  2525. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2526. //
  2527. // if(notes.length==0)
  2528. // notes=@"";
  2529. //
  2530. //
  2531. // [params setValue:notes forKey:@"comments"];
  2532. // NSData* json=nil;
  2533. // if(appDelegate.offline_mode)
  2534. // {
  2535. // json= [OLDataProvider offline_updategnotes:params];
  2536. // }
  2537. // else
  2538. // {
  2539. // if(![self IsNetworkAvailable])
  2540. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2541. //
  2542. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  2543. // }
  2544. // if(json==nil)
  2545. // return nil;
  2546. // NSError *error=nil;
  2547. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2548. // return jsobj;
  2549. //}
  2550. //+(NSDictionary*) cart_setItemNote:(NSString*) cart_id notes:(NSString*) notes
  2551. //{
  2552. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2553. // __block AppDelegate *appDelegate = nil;
  2554. //
  2555. // dispatch_sync(dispatch_get_main_queue(), ^{
  2556. // //some UI methods ej
  2557. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2558. // });
  2559. // if(appDelegate.user!=nil)
  2560. // [params setValue:appDelegate.user forKey:@"user"];
  2561. // if(appDelegate.contact_id!=nil)
  2562. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2563. // if(appDelegate.password!=nil)
  2564. // [params setValue:appDelegate.password forKey:@"password"];
  2565. //
  2566. // [params setValue:cart_id forKey:@"cartitem_id"];
  2567. //
  2568. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2569. //
  2570. // if(notes.length==0)
  2571. // notes=@"";
  2572. //
  2573. //
  2574. // [params setValue:notes forKey:@"notes"];
  2575. // NSData* json=nil;
  2576. // if(appDelegate.offline_mode)
  2577. // {
  2578. // json= [OLDataProvider offline_cartsetlnotes:params];
  2579. // }
  2580. // else
  2581. // {
  2582. // if(![self IsNetworkAvailable])
  2583. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2584. //
  2585. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  2586. // }
  2587. // if(json==nil)
  2588. // return nil;
  2589. // NSError *error=nil;
  2590. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2591. // return jsobj;
  2592. //}
  2593. //+(NSDictionary*) cart_setFree:(NSString*) cart_id isfree:(bool) isfree
  2594. //{
  2595. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2596. // __block AppDelegate *appDelegate = nil;
  2597. //
  2598. // dispatch_sync(dispatch_get_main_queue(), ^{
  2599. // //some UI methods ej
  2600. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2601. // });
  2602. // if(appDelegate.user!=nil)
  2603. // [params setValue:appDelegate.user forKey:@"user"];
  2604. // if(appDelegate.contact_id!=nil)
  2605. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2606. // if(appDelegate.password!=nil)
  2607. // [params setValue:appDelegate.password forKey:@"password"];
  2608. //
  2609. // [params setValue:cart_id forKey:@"cartitem_id"];
  2610. //
  2611. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2612. //
  2613. // NSString* free=nil;
  2614. //
  2615. // if(isfree)
  2616. // free=@"true";
  2617. // else
  2618. // free=@"false";
  2619. //
  2620. // [params setValue:free forKey:@"free_giveaway"];
  2621. //
  2622. // if(appDelegate.offline_mode)
  2623. // {
  2624. // return [OLDataProvider offline_notimpl];
  2625. // }
  2626. // if(![self IsNetworkAvailable])
  2627. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2628. //
  2629. // NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2630. // if(json==nil)
  2631. // return nil;
  2632. // NSError *error=nil;
  2633. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2634. // return jsobj;
  2635. //}
  2636. //+(NSDictionary*) cart_setQTY:(NSString*) cart_id value:(int) value
  2637. //{
  2638. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2639. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2640. // if(appDelegate.user!=nil)
  2641. // [params setValue:appDelegate.user forKey:@"user"];
  2642. // if(appDelegate.contact_id!=nil)
  2643. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2644. // if(appDelegate.password!=nil)
  2645. // [params setValue:appDelegate.password forKey:@"password"];
  2646. //
  2647. // [params setValue:cart_id forKey:@"cartitem_id"];
  2648. //
  2649. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2650. //
  2651. // [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  2652. //
  2653. // NSData* json=nil;
  2654. // if(appDelegate.offline_mode)
  2655. // {
  2656. // json= [OLDataProvider offline_cartsetqty:params];
  2657. // }
  2658. // else
  2659. // {
  2660. // if(![self IsNetworkAvailable])
  2661. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2662. //
  2663. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2664. // }
  2665. // if(json==nil)
  2666. // return nil;
  2667. // NSError *error=nil;
  2668. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2669. // return jsobj;
  2670. //
  2671. //}
  2672. //+(NSDictionary*) cart_incresement:(NSString*) cart_id increse:(bool) increse
  2673. //{
  2674. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2675. // __block AppDelegate *appDelegate = nil;
  2676. //
  2677. // dispatch_sync(dispatch_get_main_queue(), ^{
  2678. // //some UI methods ej
  2679. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2680. // });
  2681. // if(appDelegate.user!=nil)
  2682. // [params setValue:appDelegate.user forKey:@"user"];
  2683. // if(appDelegate.contact_id!=nil)
  2684. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2685. // if(appDelegate.password!=nil)
  2686. // [params setValue:appDelegate.password forKey:@"password"];
  2687. //
  2688. // [params setValue:cart_id forKey:@"cartitem_id"];
  2689. //
  2690. // if(increse)
  2691. // [params setValue:@"1" forKey:@"incrementType"];
  2692. // else
  2693. // [params setValue:@"0" forKey:@"incrementType"];
  2694. //
  2695. //
  2696. //
  2697. // if(appDelegate.offline_mode)
  2698. // {
  2699. // return [OLDataProvider offline_notimpl];
  2700. // }
  2701. // if(![self IsNetworkAvailable])
  2702. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2703. //
  2704. // NSData* json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2705. // if(json==nil)
  2706. // return nil;
  2707. // NSError *error=nil;
  2708. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2709. // return jsobj;
  2710. //}
  2711. +(NSDictionary*) finish_download_Offline:(NSString* )vid
  2712. {
  2713. if(![self IsNetworkAvailable])
  2714. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2715. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2716. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  2717. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2718. // if(appDelegate.user!=nil)
  2719. // [params setValue:appDelegate.user forKey:@"user"];
  2720. // // if(appDelegate.contact_id!=nil)
  2721. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2722. // if(appDelegate.password!=nil)
  2723. // [params setValue:appDelegate.password forKey:@"password"];
  2724. [params setValue:vid forKey:@"downSerial"];
  2725. NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  2726. if(json==nil)
  2727. return nil;
  2728. NSError *error=nil;
  2729. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2730. // int result = [[jsobj valueForKey:@"result"] intValue];
  2731. //
  2732. // if (result==2)
  2733. // {
  2734. //
  2735. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2736. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2737. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2738. ////
  2739. //// [appDelegate update_count_mark];
  2740. // }
  2741. return jsobj;
  2742. }
  2743. +(NSDictionary*) download_Offline:(NSString* )vid
  2744. {
  2745. if(![self IsNetworkAvailable])
  2746. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2747. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2748. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2749. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2750. // if(appDelegate.user!=nil)
  2751. // [params setValue:appDelegate.user forKey:@"user"];
  2752. // // if(appDelegate.contact_id!=nil)
  2753. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2754. // if(appDelegate.password!=nil)
  2755. // [params setValue:appDelegate.password forKey:@"password"];
  2756. [params setValue:vid forKey:@"downSerial"];
  2757. NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  2758. if(json==nil)
  2759. return nil;
  2760. NSError *error=nil;
  2761. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2762. // int result = [[jsobj valueForKey:@"result"] intValue];
  2763. //
  2764. // if (result==2)
  2765. // {
  2766. //
  2767. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2768. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2769. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2770. ////
  2771. //// [appDelegate update_count_mark];
  2772. // }
  2773. return jsobj;
  2774. }
  2775. +(NSDictionary*) check_Offline:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid
  2776. {
  2777. if(![self IsNetworkAvailable])
  2778. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2779. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2780. __block AppDelegate *appDelegate = nil;
  2781. dispatch_sync(dispatch_get_main_queue(), ^{
  2782. //some UI methods ej
  2783. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2784. });
  2785. if(appDelegate.user!=nil)
  2786. [params setValue:appDelegate.user forKey:@"user"];
  2787. // if(appDelegate.contact_id!=nil)
  2788. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2789. if(appDelegate.password!=nil)
  2790. [params setValue:appDelegate.password forKey:@"password"];
  2791. [params setValue:ver forKey:@"ver"];
  2792. [params setValue:vid forKey:@"vid"];
  2793. if(buseinternaladdress)
  2794. [params setValue:@"true" forKey:@"internal_address"];
  2795. else
  2796. [params setValue:@"false" forKey:@"internal_address"];
  2797. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2798. NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  2799. if(json==nil)
  2800. return nil;
  2801. NSError *error=nil;
  2802. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2803. // int result = [[jsobj valueForKey:@"result"] intValue];
  2804. //
  2805. // if (result==2)
  2806. // {
  2807. //
  2808. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2809. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2810. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2811. ////
  2812. //// [appDelegate update_count_mark];
  2813. // }
  2814. return jsobj;
  2815. }
  2816. //+(NSDictionary*)request_Cart:(int)sort
  2817. //{
  2818. //
  2819. // DebugLog(@"iSalesNetwork::request_Cart");
  2820. //
  2821. //
  2822. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2823. // __block AppDelegate *appDelegate = nil;
  2824. //
  2825. // dispatch_sync(dispatch_get_main_queue(), ^{
  2826. // //some UI methods ej
  2827. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2828. // });
  2829. // if(appDelegate.user!=nil)
  2830. // [params setValue:appDelegate.user forKey:@"user"];
  2831. // // if(appDelegate.contact_id!=nil)
  2832. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2833. // if(appDelegate.password!=nil)
  2834. // [params setValue:appDelegate.password forKey:@"password"];
  2835. //
  2836. // if(appDelegate.order_code!=nil)
  2837. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2838. //
  2839. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2840. //
  2841. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2842. //
  2843. // NSData* json=nil;
  2844. // if(appDelegate.offline_mode)
  2845. // {
  2846. // json= [OLDataProvider offline_requestcart:params];
  2847. // }
  2848. // else
  2849. // {
  2850. // if(![self IsNetworkAvailable])
  2851. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2852. //
  2853. // NSError *error=nil;
  2854. //
  2855. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2856. // params[@"resultSerial"]=uuid;
  2857. //
  2858. // for(int i=0;i<150;i++)
  2859. // {
  2860. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2861. // // result_params[@"resultSerial"]=uuid;
  2862. // json=[self get_json:URL_CART parameters:params];
  2863. // if(json!=nil)
  2864. // {
  2865. //
  2866. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2867. // if([jsobj[@"result"] intValue]==2)
  2868. // {
  2869. // break;
  2870. // }
  2871. // }
  2872. // sleep(2);
  2873. // }
  2874. //
  2875. // }
  2876. // if(json==nil)
  2877. // return nil;
  2878. // NSError *error=nil;
  2879. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2880. // int result = [[jsobj valueForKey:@"result"] intValue];
  2881. //
  2882. // if (result==2)
  2883. // {
  2884. //
  2885. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2886. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2887. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2888. //
  2889. // [appDelegate update_count_mark];
  2890. // }
  2891. // return jsobj;
  2892. //}
  2893. //+(NSDictionary*)request_Portfolio:(int)sort
  2894. //{
  2895. //
  2896. //
  2897. //
  2898. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2899. // __block AppDelegate *appDelegate = nil;
  2900. //
  2901. // dispatch_sync(dispatch_get_main_queue(), ^{
  2902. // //some UI methods ej
  2903. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2904. // });
  2905. // if(appDelegate.user!=nil)
  2906. // [params setValue:appDelegate.user forKey:@"user"];
  2907. // if(appDelegate.contact_id!=nil)
  2908. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2909. // if(appDelegate.password!=nil)
  2910. // [params setValue:appDelegate.password forKey:@"password"];
  2911. //
  2912. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2913. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2914. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2915. //
  2916. // [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2917. //
  2918. // NSData* json = nil;
  2919. // if(appDelegate.offline_mode)
  2920. // {
  2921. // json = [OLDataProvider offline_portfolioList:params];
  2922. // } else {
  2923. // if(![self IsNetworkAvailable])
  2924. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2925. //
  2926. // json = [self get_json:URL_PORTFOLIO parameters:params];
  2927. // }
  2928. //
  2929. //
  2930. // if(json==nil)
  2931. // return nil;
  2932. // NSError *error=nil;
  2933. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2934. // int result = [[jsobj valueForKey:@"result"] intValue];
  2935. //
  2936. // if (result==2)
  2937. // {
  2938. //
  2939. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2940. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2941. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  2942. //
  2943. // [appDelegate update_count_mark];
  2944. // }
  2945. // return jsobj;
  2946. //}
  2947. //+(NSDictionary*)request_WatchList:(int)sort
  2948. //{
  2949. //
  2950. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2951. // __block AppDelegate *appDelegate = nil;
  2952. //
  2953. // dispatch_sync(dispatch_get_main_queue(), ^{
  2954. // //some UI methods ej
  2955. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2956. // });
  2957. // if(appDelegate.user!=nil)
  2958. // [params setValue:appDelegate.user forKey:@"user"];
  2959. // if(appDelegate.contact_id!=nil)
  2960. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2961. // if(appDelegate.password!=nil)
  2962. // [params setValue:appDelegate.password forKey:@"password"];
  2963. //
  2964. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2965. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2966. //
  2967. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2968. //
  2969. // [params setObject:ScreenCodeWishList forKey:kScreenName];
  2970. //
  2971. // if(appDelegate.offline_mode)
  2972. // {
  2973. // return [OLDataProvider offline_wishlist:params];
  2974. // }
  2975. // if(![self IsNetworkAvailable])
  2976. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2977. //
  2978. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  2979. // if(json==nil)
  2980. // return nil;
  2981. // NSError *error=nil;
  2982. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2983. // int result = [[jsobj valueForKey:@"result"] intValue];
  2984. //
  2985. // if (result==2)
  2986. // {
  2987. //
  2988. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2989. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2990. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2991. //
  2992. // [appDelegate update_count_mark];
  2993. // }
  2994. // return jsobj;
  2995. //}
  2996. //+(NSDictionary*)request_ItemDetail: (NSString* ) item_id model_name:(NSString*) model_name category_id:(NSString*) category_id use_name :(bool) use_name groupName:(NSString *)groupName
  2997. //{
  2998. //
  2999. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3000. // __block AppDelegate *appDelegate = nil;
  3001. //
  3002. // dispatch_sync(dispatch_get_main_queue(), ^{
  3003. // //some UI methods ej
  3004. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3005. // });
  3006. // if(appDelegate.user!=nil)
  3007. // [params setValue:appDelegate.user forKey:@"user"];
  3008. // if(appDelegate.contact_id!=nil)
  3009. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3010. // if(appDelegate.password!=nil)
  3011. // [params setValue:appDelegate.password forKey:@"password"];
  3012. // if(appDelegate.order_code!=nil)
  3013. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3014. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3015. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3016. // if(use_name)
  3017. // [params setValue:model_name forKey:@"product_name"];
  3018. // else
  3019. // [params setValue:item_id forKey:@"product_id"];
  3020. //
  3021. //
  3022. // [params setValue:category_id forKey:@"category"];
  3023. //
  3024. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  3025. // [params setObject:@"Open A Model" forKey:kAction];
  3026. // if (model_name) {
  3027. // NSDictionary *extra = @{@"ModelName" : model_name};
  3028. // [params setObject:extra forKey:kExtra];
  3029. // }
  3030. //
  3031. // if (groupName.length > 0) {
  3032. // [params setObject:groupName forKey:@"groupName"];
  3033. // }
  3034. //
  3035. // if(appDelegate.offline_mode)
  3036. // return [OLDataProvider offline_model:params];
  3037. //
  3038. // if(![self IsNetworkAvailable])
  3039. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3040. //
  3041. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  3042. // if(json==nil)
  3043. // return nil;
  3044. // NSError *error=nil;
  3045. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3046. // return jsobj;
  3047. //}
  3048. //+(NSDictionary*)category_LoadMore: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(int)offset
  3049. //{
  3050. // if(![self IsNetworkAvailable])
  3051. // return nil;
  3052. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3053. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3054. // if(appDelegate.user!=nil)
  3055. // [params setValue:appDelegate.user forKey:@"user"];
  3056. // if(appDelegate.contact_id!=nil)
  3057. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3058. // if(appDelegate.password!=nil)
  3059. // [params setValue:appDelegate.password forKey:@"password"];
  3060. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3061. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3062. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3063. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3064. // [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  3065. // [params setValue:filter forKey:@"filter"];
  3066. // [params setValue:keyword forKey:@"keyword"];
  3067. //
  3068. //
  3069. // NSData* json=[self get_json:URL_CATEGORY_LOADMORE parameters:params];
  3070. // if(json==nil)
  3071. // return nil;
  3072. // NSError *error=nil;
  3073. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3074. // return jsobj;
  3075. //
  3076. //}
  3077. //+(NSDictionary*)Category_addall: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  3078. //
  3079. //{
  3080. //
  3081. //
  3082. // __block AppDelegate *appDelegate = nil;
  3083. //
  3084. // dispatch_sync(dispatch_get_main_queue(), ^{
  3085. // //some UI methods ej
  3086. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3087. // });
  3088. //
  3089. //
  3090. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3091. //
  3092. // if(appDelegate.user!=nil)
  3093. // [params setValue:appDelegate.user forKey:@"user"];
  3094. // if(appDelegate.contact_id!=nil)
  3095. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3096. // if(appDelegate.password!=nil)
  3097. // [params setValue:appDelegate.password forKey:@"password"];
  3098. // if(appDelegate.order_code!=nil)
  3099. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3100. //
  3101. // [params setValue:addTo forKey:@"addTo"];
  3102. // [params setValue:orderCode forKey:@"orderCode"];
  3103. // [params setValue:alert forKey:@"alert"];
  3104. // [params setValue:qty forKey:@"sold_by_qty"];
  3105. // [params setValue:available forKey:@"available"];
  3106. // [params setValue:price forKey:@"price"];
  3107. // [params setValue:bestseller forKey:@"bestseller"];
  3108. // [params setValue:modelname forKey:@"modelName"];
  3109. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3110. //
  3111. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3112. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3113. // [params setValue:category forKey:@"category"];
  3114. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3115. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3116. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3117. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3118. // [params setValue:filter forKey:@"filter"];
  3119. // [params setValue:keyword forKey:@"keyword"];
  3120. //
  3121. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  3122. // if ([addTo isEqualToString:@"cart"]) {
  3123. // [params setObject:@"Add To Cart" forKey:kAction];
  3124. // }
  3125. //
  3126. //
  3127. // NSData* json= nil;
  3128. //
  3129. // if(appDelegate.offline_mode)
  3130. // {
  3131. // json= [OLDataProvider offline_categoryaddall:params];
  3132. // }
  3133. // else
  3134. // {
  3135. // if(![self IsNetworkAvailable])
  3136. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3137. //
  3138. //
  3139. // NSError *error=nil;
  3140. //
  3141. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3142. // params[@"resultSerial"]=uuid;
  3143. //
  3144. // for(int i=0;i<150;i++)
  3145. // {
  3146. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3147. // // result_params[@"resultSerial"]=uuid;
  3148. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  3149. // if(json!=nil)
  3150. // {
  3151. //
  3152. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3153. // int resultInt = [jsobj[@"result"] intValue];
  3154. // if(resultInt == 2 || resultInt == 8)
  3155. // {
  3156. // break;
  3157. // }
  3158. // }
  3159. // sleep(2);
  3160. // }
  3161. //
  3162. //
  3163. //
  3164. // }
  3165. // if(json==nil)
  3166. // return nil;
  3167. // NSError *error=nil;
  3168. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3169. // return jsobj;
  3170. //
  3171. //}
  3172. //+(NSDictionary*)category_addall2portfolio: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip
  3173. //{
  3174. //
  3175. //
  3176. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3177. //
  3178. //
  3179. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3180. //
  3181. // if(appDelegate.user!=nil)
  3182. // [params setValue:appDelegate.user forKey:@"user"];
  3183. // if(appDelegate.contact_id!=nil)
  3184. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3185. // if(appDelegate.password!=nil)
  3186. // [params setValue:appDelegate.password forKey:@"password"];
  3187. // if(appDelegate.order_code!=nil)
  3188. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3189. //
  3190. // [params setValue:alert forKey:@"alert"];
  3191. // [params setValue:qty forKey:@"sold_by_qty"];
  3192. // [params setValue:available forKey:@"available"];
  3193. // [params setValue:price forKey:@"price"];
  3194. // [params setValue:bestseller forKey:@"bestseller"];
  3195. // [params setValue:modelname forKey:@"modelName"];
  3196. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3197. //
  3198. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3199. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3200. // [params setValue:category forKey:@"category"];
  3201. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3202. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3203. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3204. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3205. // [params setValue:filter forKey:@"filter"];
  3206. // [params setValue:keyword forKey:@"keyword"];
  3207. //
  3208. //
  3209. //
  3210. // if(appDelegate.offline_mode)
  3211. // return [OLDataProvider offline_category:params];
  3212. // if(![self IsNetworkAvailable])
  3213. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3214. //
  3215. // NSData* json=[self get_json:URL_ADDALL2PORTFOLIO parameters:params];
  3216. // if(json==nil)
  3217. // return nil;
  3218. // NSError *error=nil;
  3219. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3220. // return jsobj;
  3221. //
  3222. //}
  3223. //+(NSDictionary*)category_addall2wish: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip
  3224. //{
  3225. //
  3226. //
  3227. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3228. //
  3229. //
  3230. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3231. //
  3232. // if(appDelegate.user!=nil)
  3233. // [params setValue:appDelegate.user forKey:@"user"];
  3234. // if(appDelegate.contact_id!=nil)
  3235. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3236. // if(appDelegate.password!=nil)
  3237. // [params setValue:appDelegate.password forKey:@"password"];
  3238. // if(appDelegate.order_code!=nil)
  3239. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3240. //
  3241. // [params setValue:alert forKey:@"alert"];
  3242. // [params setValue:qty forKey:@"sold_by_qty"];
  3243. // [params setValue:available forKey:@"available"];
  3244. // [params setValue:price forKey:@"price"];
  3245. // [params setValue:bestseller forKey:@"bestseller"];
  3246. // [params setValue:modelname forKey:@"modelName"];
  3247. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3248. //
  3249. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3250. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3251. // [params setValue:category forKey:@"category"];
  3252. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3253. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3254. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3255. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3256. // [params setValue:filter forKey:@"filter"];
  3257. // [params setValue:keyword forKey:@"keyword"];
  3258. //
  3259. //
  3260. //
  3261. // if(appDelegate.offline_mode)
  3262. // return [OLDataProvider offline_category:params];
  3263. // if(![self IsNetworkAvailable])
  3264. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3265. //
  3266. // NSData* json=[self get_json:URL_ADDALL2WISH parameters:params];
  3267. // if(json==nil)
  3268. // return nil;
  3269. // NSError *error=nil;
  3270. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3271. // return jsobj;
  3272. //
  3273. //}
  3274. //+(NSDictionary*)Category: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip
  3275. //{
  3276. //
  3277. //
  3278. // __block AppDelegate *appDelegate = nil;
  3279. //
  3280. // dispatch_sync(dispatch_get_main_queue(), ^{
  3281. // //some UI methods ej
  3282. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3283. // });
  3284. //
  3285. //
  3286. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3287. //
  3288. // if(appDelegate.user!=nil)
  3289. // [params setValue:appDelegate.user forKey:@"user"];
  3290. // if(appDelegate.contact_id!=nil)
  3291. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3292. // if(appDelegate.password!=nil)
  3293. // [params setValue:appDelegate.password forKey:@"password"];
  3294. // if(appDelegate.order_code!=nil)
  3295. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3296. //
  3297. // [params setValue:alert forKey:@"alert"];
  3298. // [params setValue:qty forKey:@"sold_by_qty"];
  3299. // [params setValue:available forKey:@"available"];
  3300. // [params setValue:price forKey:@"price"];
  3301. // [params setValue:bestseller forKey:@"bestseller"];
  3302. // [params setValue:modelname forKey:@"modelName"];
  3303. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3304. //
  3305. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3306. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3307. // [params setValue:category forKey:@"category"];
  3308. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3309. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3310. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3311. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3312. // [params setValue:filter forKey:@"filter"];
  3313. // [params setValue:keyword forKey:@"keyword"];
  3314. //
  3315. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  3316. // if (alert) {
  3317. // [params setObject:@"Filter" forKey:kAction];
  3318. // }
  3319. // if ([Singleton sharedInstance].homeItemClick) {
  3320. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  3321. // [Singleton sharedInstance].homeItemClick = NO;
  3322. //
  3323. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  3324. // [Singleton sharedInstance].homeClickedItemName = nil;
  3325. // [params setObject:extra forKey:kExtra];
  3326. //
  3327. // }
  3328. //
  3329. //
  3330. // if(appDelegate.offline_mode)
  3331. // return [OLDataProvider offline_category:params];
  3332. // if(![self IsNetworkAvailable])
  3333. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3334. //
  3335. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  3336. // if(json==nil)
  3337. // return nil;
  3338. // NSError *error=nil;
  3339. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3340. // return jsobj;
  3341. //
  3342. //}
  3343. //+(NSDictionary*)Search_addall:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  3344. //{
  3345. //
  3346. //
  3347. //
  3348. //
  3349. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3350. // __block AppDelegate *appDelegate = nil;
  3351. //
  3352. // dispatch_sync(dispatch_get_main_queue(), ^{
  3353. // //some UI methods ej
  3354. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3355. // });
  3356. // if(appDelegate.user!=nil)
  3357. // [params setValue:appDelegate.user forKey:@"user"];
  3358. // if(appDelegate.contact_id!=nil)
  3359. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3360. // if(appDelegate.password!=nil)
  3361. // [params setValue:appDelegate.password forKey:@"password"];
  3362. // if(appDelegate.order_code!=nil)
  3363. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3364. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3365. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3366. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3367. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3368. // // [params setValue:filter forKey:@"filter"];
  3369. // [params setValue:keywords forKey:@"keyword"];
  3370. // [params setValue:addTo forKey:@"addTo"];
  3371. //
  3372. // [params setValue:orderCode forKey:@"orderCode"];
  3373. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3374. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3375. // if(matchfull)
  3376. // [params setValue:@"true" forKey:@"exactMatch"];
  3377. // else
  3378. // [params setValue:@"false" forKey:@"exactMatch"];
  3379. //
  3380. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  3381. // if ([addTo isEqualToString:@"cart"]) {
  3382. // [params setObject:@"Add To Cart" forKey:kAction];
  3383. // }
  3384. //
  3385. // NSData* json=nil;
  3386. // if(appDelegate.offline_mode)
  3387. // {
  3388. // json=[OLDataProvider offline_searchaddall:params];
  3389. // }
  3390. // else
  3391. // {
  3392. // if(![self IsNetworkAvailable])
  3393. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3394. //
  3395. // NSError *error=nil;
  3396. //
  3397. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3398. // params[@"resultSerial"]=uuid;
  3399. //
  3400. // for(int i=0;i<150;i++)
  3401. // {
  3402. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3403. // // result_params[@"resultSerial"]=uuid;
  3404. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  3405. // if(json!=nil)
  3406. // {
  3407. //
  3408. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3409. // if([jsobj[@"result"] intValue]==2)
  3410. // {
  3411. // break;
  3412. // }
  3413. // }
  3414. // sleep(2);
  3415. // }
  3416. // }
  3417. // if(json==nil)
  3418. // return nil;
  3419. // NSError *error=nil;
  3420. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3421. // return jsobj;
  3422. //
  3423. //}
  3424. //+(NSDictionary*)Search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull
  3425. //{
  3426. //
  3427. //
  3428. //
  3429. //
  3430. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3431. // __block AppDelegate *appDelegate = nil;
  3432. //
  3433. // dispatch_sync(dispatch_get_main_queue(), ^{
  3434. // //some UI methods ej
  3435. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3436. // });
  3437. // if(appDelegate.user!=nil)
  3438. // [params setValue:appDelegate.user forKey:@"user"];
  3439. // if(appDelegate.contact_id!=nil)
  3440. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3441. // if(appDelegate.password!=nil)
  3442. // [params setValue:appDelegate.password forKey:@"password"];
  3443. // if(appDelegate.order_code!=nil)
  3444. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3445. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3446. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3447. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3448. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3449. // // [params setValue:filter forKey:@"filter"];
  3450. // [params setValue:keywords forKey:@"keyword"];
  3451. //
  3452. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3453. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3454. // if(matchfull)
  3455. // [params setValue:@"true" forKey:@"exactMatch"];
  3456. // else
  3457. // [params setValue:@"false" forKey:@"exactMatch"];
  3458. //
  3459. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  3460. // if (keywords) {
  3461. // [params setObject:@"Search" forKey:kAction];
  3462. // }
  3463. //
  3464. // if(appDelegate.offline_mode)
  3465. // {
  3466. // return [OLDataProvider offline_search:params];
  3467. // }
  3468. // if(![self IsNetworkAvailable])
  3469. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3470. //
  3471. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3472. // if(json==nil)
  3473. // return nil;
  3474. // NSError *error=nil;
  3475. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3476. // return jsobj;
  3477. //}
  3478. //+(NSDictionary*)ItemSearch_addall:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  3479. //{
  3480. // // for debug
  3481. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3482. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3483. //
  3484. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3485. // __block AppDelegate *appDelegate = nil;
  3486. //
  3487. // dispatch_sync(dispatch_get_main_queue(), ^{
  3488. // //some UI methods ej
  3489. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3490. // });
  3491. // if(appDelegate.user!=nil)
  3492. // [params setValue:appDelegate.user forKey:@"user"];
  3493. // if(appDelegate.contact_id!=nil)
  3494. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3495. // if(appDelegate.password!=nil)
  3496. // [params setValue:appDelegate.password forKey:@"password"];
  3497. // if(appDelegate.order_code!=nil)
  3498. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3499. //
  3500. // [params setValue:addTo forKey:@"addTo"];
  3501. //
  3502. // [params setValue:orderCode forKey:@"orderCode"];
  3503. //
  3504. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3505. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3506. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3507. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3508. // // [params setValue:filter forKey:@"filter"];
  3509. // [params setValue:covertype forKey:@"covertype"];
  3510. // [params setValue:ctgid forKey:@"ctgId"];
  3511. // [params setValue:modelname forKey:@"modelName"];
  3512. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3513. // [params setValue:alert forKey:@"alert"];
  3514. // [params setValue:qty forKey:@"sold_by_qty"];
  3515. // [params setValue:available forKey:@"available"];
  3516. // [params setValue:price forKey:@"price"];
  3517. // [params setValue:bestseller forKey:@"bestseller"];
  3518. //
  3519. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3520. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3521. //
  3522. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3523. // if ([addTo isEqualToString:@"cart"]) {
  3524. // [params setObject:@"Add To Cart" forKey:kAction];
  3525. // }
  3526. //
  3527. // NSData* json = nil;
  3528. //
  3529. // if(appDelegate.offline_mode)
  3530. // {
  3531. // json= [OLDataProvider offline_itemsearchaddall:params];
  3532. // }
  3533. // else
  3534. // {
  3535. // if(![self IsNetworkAvailable])
  3536. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3537. // NSError *error=nil;
  3538. //
  3539. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3540. // params[@"resultSerial"]=uuid;
  3541. //
  3542. // for(int i=0;i<150;i++)
  3543. // {
  3544. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3545. // // result_params[@"resultSerial"]=uuid;
  3546. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  3547. // if(json!=nil)
  3548. // {
  3549. //
  3550. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3551. // if([jsobj[@"result"] intValue]==2)
  3552. // {
  3553. // break;
  3554. // }
  3555. // }
  3556. // sleep(2);
  3557. // }
  3558. // }
  3559. // if(json==nil)
  3560. // return nil;
  3561. // NSError *error=nil;
  3562. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3563. // return jsobj;
  3564. //}
  3565. //+(NSDictionary*)ItemSearch:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller
  3566. //{
  3567. //
  3568. // // for debug
  3569. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3570. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3571. //
  3572. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3573. // __block AppDelegate *appDelegate = nil;
  3574. //
  3575. // dispatch_sync(dispatch_get_main_queue(), ^{
  3576. // //some UI methods ej
  3577. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3578. // });
  3579. // if(appDelegate.user!=nil)
  3580. // [params setValue:appDelegate.user forKey:@"user"];
  3581. // if(appDelegate.contact_id!=nil)
  3582. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3583. // if(appDelegate.password!=nil)
  3584. // [params setValue:appDelegate.password forKey:@"password"];
  3585. // if(appDelegate.order_code!=nil)
  3586. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3587. //
  3588. //
  3589. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3590. // if (alert && qty && available && price && bestseller) {
  3591. // [params setObject:@"Filter" forKey:kAction];
  3592. // }
  3593. // if ([Singleton sharedInstance].homeItemClick) {
  3594. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  3595. // [Singleton sharedInstance].homeItemClick = NO;
  3596. //
  3597. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  3598. // [Singleton sharedInstance].homeClickedItemName = nil;
  3599. // [params setObject:extra forKey:kExtra];
  3600. // }
  3601. //
  3602. //
  3603. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3604. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3605. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3606. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3607. // // [params setValue:filter forKey:@"filter"];
  3608. // [params setValue:covertype forKey:@"covertype"];
  3609. // [params setValue:ctgid forKey:@"ctgId"];
  3610. // [params setValue:modelname forKey:@"modelName"];
  3611. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3612. // [params setValue:alert forKey:@"alert"];
  3613. // [params setValue:qty forKey:@"sold_by_qty"];
  3614. // [params setValue:available forKey:@"available"];
  3615. // [params setValue:price forKey:@"price"];
  3616. // [params setValue:bestseller forKey:@"bestseller"];
  3617. //
  3618. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3619. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3620. //
  3621. // if(appDelegate.offline_mode)
  3622. // {
  3623. // return [OLDataProvider offline_itemsearch:params];
  3624. // }
  3625. // if(![self IsNetworkAvailable])
  3626. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3627. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  3628. // if(json==nil)
  3629. // return nil;
  3630. // NSError *error=nil;
  3631. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3632. // return jsobj;
  3633. //}
  3634. //+(NSDictionary*)Search: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword
  3635. //{
  3636. // if(![self IsNetworkAvailable])
  3637. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3638. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3639. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3640. // if(appDelegate.user!=nil)
  3641. // [params setValue:appDelegate.user forKey:@"user"];
  3642. // if(appDelegate.contact_id!=nil)
  3643. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3644. // if(appDelegate.password!=nil)
  3645. // [params setValue:appDelegate.password forKey:@"password"];
  3646. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3647. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3648. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3649. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3650. // [params setValue:filter forKey:@"filter"];
  3651. // [params setValue:keyword forKey:@"keyword"];
  3652. //
  3653. //
  3654. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3655. // if(json==nil)
  3656. // return nil;
  3657. // NSError *error=nil;
  3658. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3659. // return jsobj;
  3660. //}
  3661. +(NSDictionary*)request_model_qty: (NSString*) fashionId
  3662. {
  3663. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3664. __block AppDelegate *appDelegate = nil;
  3665. dispatch_sync(dispatch_get_main_queue(), ^{
  3666. //some UI methods ej
  3667. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3668. });
  3669. if(appDelegate.user!=nil)
  3670. [params setValue:appDelegate.user forKey:@"user"];
  3671. if(appDelegate.contact_id!=nil)
  3672. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3673. if(appDelegate.password!=nil)
  3674. [params setValue:appDelegate.password forKey:@"password"];
  3675. [params setValue:fashionId forKey:@"fashionId"];
  3676. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  3677. NSData* json = nil;
  3678. if(appDelegate.offline_mode)
  3679. {
  3680. json = [OLDataProvider offline_model_qty:params];
  3681. } else {
  3682. if(![self IsNetworkAvailable])
  3683. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3684. json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  3685. }
  3686. if(json==nil)
  3687. return nil;
  3688. NSError *error=nil;
  3689. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3690. return jsobj;
  3691. }
  3692. +(NSDictionary*)retrieve_password: (NSString*) user email:(NSString*) email
  3693. {
  3694. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3695. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3696. // if(appDelegate.user!=nil)
  3697. // [params setValue:appDelegate.user forKey:@"user"];
  3698. // if(appDelegate.contact_id!=nil)
  3699. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3700. // if(appDelegate.password!=nil)
  3701. // [params setValue:appDelegate.password forKey:@"password"];
  3702. [params setValue:user forKey:@"username"];
  3703. [params setValue:email forKey:@"email"];
  3704. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3705. if(![self IsNetworkAvailable])
  3706. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3707. NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  3708. if(json==nil)
  3709. return nil;
  3710. NSError *error=nil;
  3711. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3712. return jsobj;
  3713. }
  3714. +(NSDictionary*)load_HomePage:(int) price_template customid:(int) customid
  3715. {
  3716. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3717. __block AppDelegate *appDelegate = nil;
  3718. dispatch_sync(dispatch_get_main_queue(), ^{
  3719. //some UI methods ej
  3720. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3721. });
  3722. if(appDelegate.user!=nil)
  3723. [params setValue:appDelegate.user forKey:@"user"];
  3724. if(appDelegate.contact_id!=nil)
  3725. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3726. if(appDelegate.password!=nil)
  3727. [params setValue:appDelegate.password forKey:@"password"];
  3728. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3729. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3730. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  3731. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3732. if(appDelegate.offline_mode)
  3733. {
  3734. //params[@"offline_Command"]=url;
  3735. return [OLDataProvider offline_home];
  3736. }
  3737. if(![self IsNetworkAvailable])
  3738. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3739. NSData* json=[self get_json:URL_LOAD_HOME parameters:params];
  3740. if(json==nil)
  3741. return nil;
  3742. NSError *error=nil;
  3743. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3744. return jsobj;
  3745. }
  3746. //+(NSDictionary*)logout
  3747. //{
  3748. //
  3749. //
  3750. //
  3751. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3752. // __block AppDelegate *appDelegate = nil;
  3753. //
  3754. // dispatch_sync(dispatch_get_main_queue(), ^{
  3755. // //some UI methods ej
  3756. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3757. // });
  3758. // if(appDelegate.user!=nil)
  3759. // [params setValue:appDelegate.user forKey:@"user"];
  3760. //
  3761. //
  3762. // if(appDelegate.password!=nil)
  3763. // [params setValue:appDelegate.password forKey:@"password"];
  3764. //
  3765. //
  3766. // if(appDelegate.offline_mode)
  3767. // {
  3768. // return [OLDataProvider offline_logout:params];
  3769. // }
  3770. // if(![self IsNetworkAvailable])
  3771. // {
  3772. // DebugLog(@"NET ERR");
  3773. //
  3774. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3775. // // return nil;
  3776. // }
  3777. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  3778. // //if(json==nil)
  3779. //
  3780. //
  3781. // if(json==nil)
  3782. // return nil;
  3783. // NSError *error=nil;
  3784. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3785. // int result = [[jsobj valueForKey:@"result"] intValue];
  3786. //
  3787. // if (result==2)
  3788. // {
  3789. //
  3790. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  3791. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  3792. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  3793. //
  3794. // [appDelegate update_count_mark];
  3795. //
  3796. //
  3797. // appDelegate.can_show_price =false;
  3798. // appDelegate.can_see_price =false;
  3799. // appDelegate.can_create_portfolio =false;
  3800. // appDelegate.can_create_order =false;
  3801. //
  3802. //
  3803. // appDelegate.can_cancel_order =false;
  3804. // appDelegate.can_set_cart_price =false;
  3805. // appDelegate.can_delete_order =false;
  3806. // appDelegate.can_submit_order =false;
  3807. // appDelegate.can_set_tearsheet_price =false;
  3808. // appDelegate.can_update_contact_info = false;
  3809. //
  3810. // appDelegate.save_order_logout = false;
  3811. // appDelegate.submit_order_logout = false;
  3812. // appDelegate.alert_sold_in_quantities = false;
  3813. //
  3814. // appDelegate.ipad_perm =nil ;
  3815. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  3816. // appDelegate.OrderFilter= nil;
  3817. // [appDelegate SetSo:nil];
  3818. // [appDelegate set_main_button_panel];
  3819. //#ifdef RA_NOTIFICATION
  3820. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  3821. //#endif
  3822. // }
  3823. // return jsobj;
  3824. //}
  3825. +(NSDictionary*)request_Cagegory
  3826. {
  3827. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  3828. __block AppDelegate *appDelegate = nil;
  3829. dispatch_sync(dispatch_get_main_queue(), ^{
  3830. //some UI methods ej
  3831. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3832. });
  3833. if(appDelegate.offline_mode)
  3834. {
  3835. //params[@"offline_Command"]=url;
  3836. return [OLDataProvider offline_category_menu];
  3837. }
  3838. if(![self IsNetworkAvailable])
  3839. {
  3840. DebugLog(@"NET ERR");
  3841. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3842. // return nil;
  3843. }
  3844. NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  3845. //if(json==nil)
  3846. if(json==nil)
  3847. return nil;
  3848. NSError *error=nil;
  3849. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3850. return jsobj;
  3851. }
  3852. +(int)Authorize : (NSString*) user password:(NSString*) password{
  3853. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  3854. // return RESULT_NET_ERROR;
  3855. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3856. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3857. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3858. __block AppDelegate *appDelegate = nil;
  3859. dispatch_sync(dispatch_get_main_queue(), ^{
  3860. //some UI methods ej
  3861. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3862. });
  3863. if(appDelegate.duid !=nil)
  3864. [params setValue:appDelegate.duid forKey:@"udid"];
  3865. [params setValue:@"handset_login" forKey:@"action"];
  3866. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  3867. [params setValue:user forKey:@"user"];
  3868. [params setValue:password forKey:@"password"];
  3869. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  3870. #ifdef TEST
  3871. [params setValue:@"true" forKey:@"is_debug"];
  3872. #else
  3873. [params setValue:@"false" forKey:@"is_debug"];
  3874. #endif
  3875. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3876. [params setObject:@"Login" forKey:kAction];
  3877. NSData* json= nil;
  3878. if(appDelegate.offline_mode)
  3879. {
  3880. json= [OLDataProvider offline_login:params] ;
  3881. }
  3882. else
  3883. {
  3884. if(![self IsNetworkAvailable])
  3885. return RESULT_NET_NOTAVAILABLE;
  3886. json =[self get_json:URL_UPDATE_AUTH parameters:params];
  3887. }
  3888. if(json==nil)
  3889. return RESULT_NET_ERROR;
  3890. int ret = [self parse_authinfo:json user:user password:password];
  3891. DebugLog(@"parse_authinfo return %d ",ret);
  3892. return ret;
  3893. }
  3894. +(NSDictionary*)update_customer_img: (NSString*) contactid img_url:(NSString*) url
  3895. {
  3896. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3897. __block AppDelegate *appDelegate = nil;
  3898. dispatch_sync(dispatch_get_main_queue(), ^{
  3899. //some UI methods ej
  3900. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3901. });
  3902. if(appDelegate.user!=nil)
  3903. [params setValue:appDelegate.user forKey:@"user"];
  3904. // if(appDelegate.contact_id!=nil)
  3905. if(appDelegate.password!=nil)
  3906. [params setValue:appDelegate.password forKey:@"password"];
  3907. [params setValue:contactid forKey:@"contactId"];
  3908. [params setValue:url forKey:@"business_card"];
  3909. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  3910. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  3911. if(appDelegate.offline_mode)
  3912. {
  3913. return [OLDataProvider offline_notimpl];
  3914. }
  3915. if(![self IsNetworkAvailable])
  3916. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3917. NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  3918. if(json==nil)
  3919. return nil;
  3920. NSError *error=nil;
  3921. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3922. return jsobj;
  3923. }
  3924. +(NSDictionary*)request_PendingOrder:(NSString *)contactid
  3925. {
  3926. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3927. __block AppDelegate *appDelegate = nil;
  3928. dispatch_sync(dispatch_get_main_queue(), ^{
  3929. //some UI methods ej
  3930. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3931. });
  3932. if(appDelegate.user!=nil)
  3933. [params setValue:appDelegate.user forKey:@"user"];
  3934. // if(appDelegate.contact_id!=nil)
  3935. if(appDelegate.password!=nil)
  3936. [params setValue:appDelegate.password forKey:@"password"];
  3937. [params setValue:contactid forKey:@"contactId"];
  3938. if(appDelegate.offline_mode)
  3939. {
  3940. return [OLDataProvider offline_notimpl];
  3941. }
  3942. if(![self IsNetworkAvailable])
  3943. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3944. NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  3945. if(json==nil)
  3946. return nil;
  3947. NSError *error=nil;
  3948. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3949. return jsobj;
  3950. }
  3951. //+(NSDictionary*)request_CustomerInfo:(NSString* ) contactid
  3952. //{
  3953. //
  3954. //
  3955. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3956. // __block AppDelegate *appDelegate = nil;
  3957. //
  3958. // dispatch_sync(dispatch_get_main_queue(), ^{
  3959. // //some UI methods ej
  3960. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3961. // });
  3962. // if(appDelegate.user!=nil)
  3963. // [params setValue:appDelegate.user forKey:@"user"];
  3964. // // if(appDelegate.contact_id!=nil)
  3965. //
  3966. // if(appDelegate.password!=nil)
  3967. // [params setValue:appDelegate.password forKey:@"password"];
  3968. // [params setValue:contactid forKey:@"contactId"];
  3969. //
  3970. // [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  3971. //
  3972. // if(appDelegate.offline_mode)
  3973. // return [OLDataProvider offline_contactinfo:params];
  3974. // if(![self IsNetworkAvailable])
  3975. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3976. //
  3977. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  3978. // if(json==nil)
  3979. // return nil;
  3980. // NSError *error=nil;
  3981. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3982. // return jsobj;
  3983. //
  3984. //}
  3985. +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
  3986. {
  3987. DebugLog(@"parse_authinfo");
  3988. NSError *error=nil;
  3989. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3990. if(jsobj)
  3991. {
  3992. __block AppDelegate *appDelegate = nil;
  3993. dispatch_sync(dispatch_get_main_queue(), ^{
  3994. //some UI methods ej
  3995. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3996. });
  3997. int result = [[jsobj valueForKey:@"result"] intValue];
  3998. if (result<0)
  3999. return result;
  4000. if(result!=AP_USER_AUTH&& result!=9)
  4001. {
  4002. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  4003. // [appDelegate Logout];
  4004. if(result==8)
  4005. {
  4006. return RESULT_LOGIN_DEVICE;
  4007. }
  4008. return RESULT_FALSE;
  4009. }
  4010. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  4011. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  4012. user=[objheader objectForKey:@"username"] ;
  4013. DebugLog(@"required_ver=%@ ",required_ver);
  4014. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  4015. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  4016. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  4017. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  4018. // if([ibadge isEqual:[NSNull null]])
  4019. // strbadge=@"0";
  4020. // if(ibadge==nil)
  4021. // ibadge=@"0";
  4022. // if([strbadge isEqualToString:@"null"])
  4023. // strbadge=@"0";
  4024. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  4025. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  4026. if([appDelegate.build intValue]<[required_ver intValue])
  4027. return RESULT_VER_LOW;
  4028. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  4029. appDelegate.user = user;
  4030. appDelegate.password = password;
  4031. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  4032. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  4033. appDelegate.bLogin = true;
  4034. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  4035. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  4036. {
  4037. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  4038. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  4039. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  4040. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  4041. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  4042. }
  4043. NSString* mode =[jsobj valueForKey:@"mode"] ;
  4044. [appDelegate SetMode:mode];
  4045. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  4046. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  4047. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  4048. [appDelegate update_count_mark];
  4049. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  4050. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  4051. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  4052. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  4053. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  4054. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  4055. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  4056. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  4057. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  4058. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  4059. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  4060. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  4061. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  4062. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  4063. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  4064. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  4065. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  4066. [appDelegate set_main_button_panel];
  4067. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  4068. // shop order status filter
  4069. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  4070. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  4071. // Sales order status filter
  4072. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  4073. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  4074. // specialInstruction
  4075. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  4076. //-价格类型
  4077. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  4078. // 权限
  4079. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  4080. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  4081. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  4082. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  4083. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  4084. [[RASingleton sharedInstance] resetGlobalLock];
  4085. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  4086. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  4087. }
  4088. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  4089. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  4090. // {
  4091. // // no update on the server;
  4092. // return RESULT_TRUE;
  4093. // }
  4094. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  4095. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4096. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4097. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4098. // [defaults synchronize];
  4099. //
  4100. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  4101. // NSArray* keys= [objfuncs allKeys];
  4102. /*
  4103. db.setTransactionSuccessful();
  4104. db.endTransaction();
  4105. */
  4106. return RESULT_TRUE;
  4107. }
  4108. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  4109. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  4110. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  4111. return RESULT_USERAUTH_ERROR;
  4112. }
  4113. //+(bool) IsNetworkAvailable
  4114. //{
  4115. //
  4116. // if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) &&
  4117. // ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable))
  4118. // return false;
  4119. // return true;
  4120. //}
  4121. //+(NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim
  4122. //{
  4123. // NSScanner *theScanner = [NSScanner scannerWithString:html];
  4124. // NSString *text = nil;
  4125. //
  4126. // while ([theScanner isAtEnd] == NO) {
  4127. // // find start of tag
  4128. // [theScanner scanUpToString:@"<" intoString:NULL] ;
  4129. // // find end of tag
  4130. // [theScanner scanUpToString:@">" intoString:&text] ;
  4131. // // replace the found tag with a space
  4132. // //(you can filter multi-spaces out later if you wish)
  4133. // html = [html stringByReplacingOccurrencesOfString:
  4134. // [ NSString stringWithFormat:@"%@>", text]
  4135. // withString:@""];
  4136. // }
  4137. //
  4138. // return trim ? [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : html;
  4139. //}
  4140. //
  4141. //+(NSString *)flattenURL:(NSString *)url trimWhiteSpace:(BOOL)trim
  4142. //{
  4143. // NSScanner *theScanner = [NSScanner scannerWithString:url];
  4144. // NSString *text = nil;
  4145. //
  4146. // while ([theScanner isAtEnd] == NO) {
  4147. // // find start of tag
  4148. // [theScanner scanUpToString:@"/" intoString:NULL] ;
  4149. // // find end of tag
  4150. // [theScanner scanUpToString:@"/" intoString:&text] ;
  4151. // // replace the found tag with a space
  4152. // //(you can filter multi-spaces out later if you wish)
  4153. // url = [url stringByReplacingOccurrencesOfString:
  4154. // [ NSString stringWithFormat:@"%@", text]
  4155. // withString:@""];
  4156. // }
  4157. //
  4158. // return trim ? [url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : url;
  4159. //}
  4160. + (NSDictionary *)set_npd_shop_price_type:(NSInteger)priceType {
  4161. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4162. __block AppDelegate *appDelegate = nil;
  4163. dispatch_sync(dispatch_get_main_queue(), ^{
  4164. //some UI methods ej
  4165. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4166. });
  4167. if(appDelegate.user!=nil)
  4168. [dic setValue:appDelegate.user forKey:@"user"];
  4169. if(appDelegate.password!=nil)
  4170. [dic setValue:appDelegate.password forKey:@"password"];
  4171. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  4172. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  4173. NSData* json=nil;
  4174. if(appDelegate.offline_mode)
  4175. {
  4176. return [OLDataProvider offline_notimpl];
  4177. }
  4178. else
  4179. {
  4180. if(![self IsNetworkAvailable])
  4181. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4182. json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  4183. }
  4184. if(json!=nil)
  4185. {
  4186. NSError *error=nil;
  4187. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4188. return jsobj;
  4189. }
  4190. return nil;
  4191. }
  4192. + (NSDictionary *)get_npd_shop_givenPrice {
  4193. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4194. __block AppDelegate *appDelegate = nil;
  4195. dispatch_sync(dispatch_get_main_queue(), ^{
  4196. //some UI methods ej
  4197. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4198. });
  4199. if(appDelegate.user!=nil)
  4200. [dic setValue:appDelegate.user forKey:@"user"];
  4201. if(appDelegate.password!=nil)
  4202. [dic setValue:appDelegate.password forKey:@"password"];
  4203. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  4204. NSData* json=nil;
  4205. if(appDelegate.offline_mode)
  4206. {
  4207. return [OLDataProvider offline_notimpl];
  4208. }
  4209. else
  4210. {
  4211. if(![self IsNetworkAvailable])
  4212. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4213. json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  4214. }
  4215. if(json!=nil)
  4216. {
  4217. NSError *error=nil;
  4218. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4219. return jsobj;
  4220. }
  4221. return nil;
  4222. }
  4223. + (NSDictionary *)set_npd_shop_givenPrice:(NSMutableDictionary *)params {
  4224. __block AppDelegate *appDelegate = nil;
  4225. dispatch_sync(dispatch_get_main_queue(), ^{
  4226. //some UI methods ej
  4227. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4228. });
  4229. if(appDelegate.user!=nil)
  4230. [params setValue:appDelegate.user forKey:@"user"];
  4231. if(appDelegate.password!=nil)
  4232. [params setValue:appDelegate.password forKey:@"password"];
  4233. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  4234. NSData* json=nil;
  4235. if(appDelegate.offline_mode)
  4236. {
  4237. return [OLDataProvider offline_notimpl];
  4238. }
  4239. else
  4240. {
  4241. if(![self IsNetworkAvailable])
  4242. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4243. json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  4244. }
  4245. if(json!=nil)
  4246. {
  4247. NSError *error=nil;
  4248. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4249. return jsobj;
  4250. }
  4251. return nil;
  4252. }
  4253. + (NSDictionary *)merge_order:(NSMutableDictionary *)params {
  4254. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4255. __block AppDelegate *appDelegate = nil;
  4256. dispatch_sync(dispatch_get_main_queue(), ^{
  4257. //some UI methods ej
  4258. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4259. });
  4260. if(appDelegate.user!=nil)
  4261. [dic setValue:appDelegate.user forKey:@"user"];
  4262. if(appDelegate.password!=nil)
  4263. [dic setValue:appDelegate.password forKey:@"password"];
  4264. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  4265. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  4266. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  4267. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  4268. NSData* json=nil;
  4269. if(appDelegate.offline_mode)
  4270. {
  4271. return [OLDataProvider offline_notimpl];
  4272. }
  4273. else
  4274. {
  4275. if(![self IsNetworkAvailable])
  4276. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4277. json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  4278. }
  4279. if(json!=nil)
  4280. {
  4281. NSError *error=nil;
  4282. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4283. return jsobj;
  4284. }
  4285. else
  4286. return nil;
  4287. }
  4288. //+ (NSDictionary *)lock_order:(NSString *)oderCode
  4289. //{
  4290. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4291. // __block AppDelegate *appDelegate = nil;
  4292. //
  4293. // dispatch_sync(dispatch_get_main_queue(), ^{
  4294. // //some UI methods ej
  4295. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4296. // });
  4297. // if(appDelegate.user!=nil)
  4298. // [params setValue:appDelegate.user forKey:@"user"];
  4299. //
  4300. // if(appDelegate.password!=nil)
  4301. // [params setValue:appDelegate.password forKey:@"password"];
  4302. //
  4303. // [params setValue:oderCode forKey:@"orderCode"];
  4304. //
  4305. // NSData* json=nil;
  4306. // if(appDelegate.offline_mode)
  4307. // {
  4308. // json=[OLDataProvider offline_editorder:params];
  4309. //
  4310. // }
  4311. // else
  4312. // {
  4313. // if(![self IsNetworkAvailable])
  4314. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4315. //
  4316. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  4317. // }
  4318. // if(json!=nil)
  4319. // {
  4320. // NSError *error=nil;
  4321. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4322. //
  4323. // return jsobj;
  4324. // }
  4325. // else
  4326. // return nil;
  4327. //}
  4328. + (NSDictionary *)quoteOrder:(NSString *)so_id emailAddr:(NSString *)addr {
  4329. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4330. __block AppDelegate *appDelegate = nil;
  4331. dispatch_sync(dispatch_get_main_queue(), ^{
  4332. //some UI methods ej
  4333. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4334. });
  4335. if(appDelegate.user!=nil)
  4336. [dic setValue:appDelegate.user forKey:@"user"];
  4337. if(appDelegate.password!=nil)
  4338. [dic setValue:appDelegate.password forKey:@"password"];
  4339. [dic setValue:so_id forKey:@"orderCode"];
  4340. [dic setValue:addr forKey:@"email"];
  4341. [dic setObject:ScreenCodeCart forKey:kScreenName];
  4342. if (appDelegate.customerInfo) {
  4343. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4344. if (customer_cid) {
  4345. [dic setValue:customer_cid forKey:@"contactId"];
  4346. }
  4347. }
  4348. NSData* json=nil;
  4349. if(appDelegate.offline_mode)
  4350. {
  4351. return [OLDataProvider offline_notimpl];
  4352. }
  4353. else
  4354. {
  4355. if(![self IsNetworkAvailable])
  4356. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4357. json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  4358. }
  4359. if(json!=nil)
  4360. {
  4361. NSError *error=nil;
  4362. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4363. return jsobj;
  4364. }
  4365. return @{@"result" : @(RESULT_FALSE)};
  4366. }
  4367. + (NSDictionary *)notifyModel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName{
  4368. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4369. __block AppDelegate *appDelegate = nil;
  4370. dispatch_sync(dispatch_get_main_queue(), ^{
  4371. //some UI methods ej
  4372. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4373. });
  4374. if(appDelegate.user!=nil)
  4375. [dic setValue:appDelegate.user forKey:@"user"];
  4376. if(appDelegate.password!=nil)
  4377. [dic setValue:appDelegate.password forKey:@"password"];
  4378. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  4379. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4380. if (customer_cid) {
  4381. [dic setValue:customer_cid forKey:@"contactId"];
  4382. }
  4383. }
  4384. [dic setObject:screenName forKey:kScreenName];
  4385. [dic setValue:modelID forKey:@"productId"];
  4386. if (addr) { // 弹框输入
  4387. [dic setValue:addr forKey:@"email"];
  4388. } else {
  4389. // employee选择了Contact,并且Contact有Email
  4390. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  4391. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  4392. // if (email) {
  4393. // [dic setValue:email forKey:@"email"];
  4394. // }
  4395. // }
  4396. }
  4397. NSData* json=nil;
  4398. if(appDelegate.offline_mode)
  4399. {
  4400. return [OLDataProvider offline_notimpl];
  4401. }
  4402. else
  4403. {
  4404. if(![self IsNetworkAvailable])
  4405. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4406. json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  4407. }
  4408. if(json!=nil)
  4409. {
  4410. NSError *error=nil;
  4411. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4412. return jsobj;
  4413. }
  4414. return @{@"result" : @(RESULT_FALSE)};
  4415. }
  4416. + (NSDictionary *)quoteWishlist2EmailAddr:(NSString *)addr {
  4417. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4418. __block AppDelegate *appDelegate = nil;
  4419. dispatch_sync(dispatch_get_main_queue(), ^{
  4420. //some UI methods ej
  4421. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4422. });
  4423. if(appDelegate.user!=nil)
  4424. [dic setValue:appDelegate.user forKey:@"user"];
  4425. if(appDelegate.password!=nil)
  4426. [dic setValue:appDelegate.password forKey:@"password"];
  4427. [dic setValue:addr forKey:@"email"];
  4428. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  4429. // if (appDelegate.customerInfo) {
  4430. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4431. // if (customer_cid) {
  4432. // [dic setValue:customer_cid forKey:@"contactId"];
  4433. // }
  4434. // }
  4435. NSData* json=nil;
  4436. if(appDelegate.offline_mode)
  4437. {
  4438. return [OLDataProvider offline_notimpl];
  4439. }
  4440. else
  4441. {
  4442. if(![self IsNetworkAvailable])
  4443. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4444. json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  4445. }
  4446. if(json!=nil)
  4447. {
  4448. NSError *error=nil;
  4449. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4450. return jsobj;
  4451. }
  4452. return @{@"result" : @(RESULT_FALSE)};
  4453. }
  4454. + (NSDictionary *)movetobackorder:(NSString *)cart_item_id {
  4455. if (cart_item_id == nil || cart_item_id.length < 1) {
  4456. return @{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"};
  4457. }
  4458. __block AppDelegate *appDelegate = nil;
  4459. dispatch_sync(dispatch_get_main_queue(), ^{
  4460. //some UI methods ej
  4461. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4462. });
  4463. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4464. if(appDelegate.user!=nil)
  4465. [dic setValue:appDelegate.user forKey:@"user"];
  4466. if(appDelegate.password!=nil)
  4467. [dic setValue:appDelegate.password forKey:@"password"];
  4468. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  4469. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  4470. [dic setObject:ScreenCodeCart forKey:kScreenName];
  4471. if(![self IsNetworkAvailable])
  4472. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4473. NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  4474. if(json!=nil)
  4475. {
  4476. NSError *error=nil;
  4477. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4478. return jsobj;
  4479. }
  4480. return @{@"result" : @(RESULT_FALSE)};
  4481. }
  4482. + (NSDictionary*)request_hangTag:(NSString *)group {
  4483. #ifdef BUILD_UWAVER
  4484. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4485. __block AppDelegate *appDelegate = nil;
  4486. dispatch_sync(dispatch_get_main_queue(), ^{
  4487. //some UI methods ej
  4488. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4489. });
  4490. if(appDelegate.user!=nil)
  4491. [params setValue:appDelegate.user forKey:@"user"];
  4492. if(appDelegate.contact_id!=nil)
  4493. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4494. if(appDelegate.password!=nil)
  4495. [params setValue:appDelegate.password forKey:@"password"];
  4496. if (group) {
  4497. [params setValue:group forKey:@"groupName"];
  4498. }
  4499. NSString * uuid= [[NSUUID UUID] UUIDString];
  4500. params[@"resultSerial"]=uuid;
  4501. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4502. NSData* json = nil;
  4503. if(appDelegate.offline_mode)
  4504. {
  4505. json = [OLDataProvider offline_notimpl];
  4506. } else {
  4507. if(![self IsNetworkAvailable])
  4508. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4509. json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  4510. }
  4511. if(json==nil)
  4512. return nil;
  4513. NSError *error=nil;
  4514. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4515. return jsobj;
  4516. #else
  4517. return nil;
  4518. #endif
  4519. }
  4520. #pragma mark 2020 new interface
  4521. // 新接口逐步替换以前的网络请求,2020
  4522. +(void)request_home:(int) price_template customid:(int) customid completionHandler:(resultHandler)result
  4523. {
  4524. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4525. AppDelegate *appDelegate = nil;
  4526. //some UI methods ej
  4527. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4528. if(appDelegate.user!=nil)
  4529. [params setValue:appDelegate.user forKey:@"user"];
  4530. if(appDelegate.contact_id!=nil)
  4531. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4532. if(appDelegate.password!=nil)
  4533. [params setValue:appDelegate.password forKey:@"password"];
  4534. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4535. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4536. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  4537. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4538. if(appDelegate.offline_mode)
  4539. {
  4540. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4541. NSMutableDictionary* json = [[OLDataProvider offline_home] mutableCopy];
  4542. dispatch_async(dispatch_get_main_queue(), ^{
  4543. result(json);
  4544. });
  4545. });
  4546. return;
  4547. }
  4548. [self request_interface:URL_LOAD_HOME parameters:params err_record_url:nil completionHandler:result retry:0];
  4549. return;
  4550. }
  4551. +(void)request_category:(resultHandler)result
  4552. {
  4553. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  4554. AppDelegate *appDelegate = nil;
  4555. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4556. if(appDelegate.offline_mode)
  4557. {
  4558. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4559. NSMutableDictionary* json = [[OLDataProvider offline_category_menu] mutableCopy];
  4560. dispatch_async(dispatch_get_main_queue(), ^{
  4561. result(json);
  4562. });
  4563. });
  4564. return;
  4565. }
  4566. [self request_interface:URL_REQUEST_CATMENU parameters:[NSMutableDictionary new] err_record_url:nil completionHandler:result retry:0];
  4567. //
  4568. // if(![self IsNetworkAvailable])
  4569. // {
  4570. // DebugLog(@"NET ERR");
  4571. //
  4572. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4573. // // return nil;
  4574. // }
  4575. //
  4576. // NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  4577. // //if(json==nil)
  4578. //
  4579. //
  4580. // if(json==nil)
  4581. // return nil;
  4582. // NSError *error=nil;
  4583. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4584. // return jsobj;
  4585. }
  4586. +(void)request_categorylist: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip completionHandler:(resultHandler)result
  4587. {
  4588. AppDelegate *appDelegate = nil;
  4589. //some UI methods ej
  4590. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4591. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4592. if(appDelegate.user!=nil)
  4593. [params setValue:appDelegate.user forKey:@"user"];
  4594. if(appDelegate.contact_id!=nil)
  4595. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4596. if(appDelegate.password!=nil)
  4597. [params setValue:appDelegate.password forKey:@"password"];
  4598. if(appDelegate.order_code!=nil)
  4599. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4600. [params setValue:alert forKey:@"alert"];
  4601. [params setValue:qty forKey:@"sold_by_qty"];
  4602. [params setValue:available forKey:@"available"];
  4603. [params setValue:price forKey:@"price"];
  4604. [params setValue:bestseller forKey:@"bestseller"];
  4605. [params setValue:modelname forKey:@"modelName"];
  4606. [params setValue:modeldescrip forKey:@"modelDescription"];
  4607. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4608. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4609. [params setValue:category forKey:@"category"];
  4610. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4611. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4612. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4613. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4614. [params setValue:filter forKey:@"filter"];
  4615. [params setValue:keyword forKey:@"keyword"];
  4616. [params setObject:ScreenCodeCategory forKey:kScreenName];
  4617. if (alert) {
  4618. [params setObject:@"Filter" forKey:kAction];
  4619. }
  4620. if ([RASingleton sharedInstance].homeItemClick) {
  4621. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  4622. [RASingleton sharedInstance].homeItemClick = NO;
  4623. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  4624. [RASingleton sharedInstance].homeClickedItemName = nil;
  4625. [params setObject:extra forKey:kExtra];
  4626. }
  4627. if(appDelegate.offline_mode)
  4628. {
  4629. // [OLDataProvider offline_category:params completionHandler:result];
  4630. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4631. NSMutableDictionary* json = [[OLDataProvider offline_category:params] mutableCopy];
  4632. dispatch_async(dispatch_get_main_queue(), ^{
  4633. result(json);
  4634. });
  4635. });
  4636. return;
  4637. }
  4638. [self request_interface:URL_CATEGORY parameters:params err_record_url:nil completionHandler:result retry:0];
  4639. return ;
  4640. //
  4641. // if(![self IsNetworkAvailable])
  4642. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4643. //
  4644. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  4645. // if(json==nil)
  4646. // return nil;
  4647. // NSError *error=nil;
  4648. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4649. // return jsobj;
  4650. //
  4651. }
  4652. +(void)request_modeldetail: (NSString* ) item_id model_name:(NSString*) model_name upc_code:(NSString*) upc_code category_id:(NSString*) category_id use_name :(bool) use_name use_upc :(bool) use_upc groupName:(NSString *)groupName completionHandler:(resultHandler)result
  4653. {
  4654. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4655. AppDelegate *appDelegate = nil;
  4656. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4657. if(appDelegate.user!=nil)
  4658. [params setValue:appDelegate.user forKey:@"user"];
  4659. if(appDelegate.contact_id!=nil)
  4660. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4661. if(appDelegate.password!=nil)
  4662. [params setValue:appDelegate.password forKey:@"password"];
  4663. if(appDelegate.order_code!=nil)
  4664. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4665. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4666. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4667. if(use_name)
  4668. [params setValue:model_name forKey:@"product_name"];
  4669. else
  4670. if(use_upc){
  4671. params[@"search_upc"]=@true;
  4672. [params setValue:upc_code forKey:@"upc_code"];
  4673. }
  4674. else
  4675. [params setValue:item_id forKey:@"product_id"];
  4676. [params setValue:category_id forKey:@"category"];
  4677. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4678. [params setObject:@"Open A Model" forKey:kAction];
  4679. if (model_name) {
  4680. NSDictionary *extra = @{@"ModelName" : model_name};
  4681. [params setObject:extra forKey:kExtra];
  4682. }
  4683. if (groupName.length > 0) {
  4684. [params setObject:groupName forKey:@"groupName"];
  4685. }
  4686. if(appDelegate.offline_mode)
  4687. {
  4688. [OLDataProvider offline_model:params completionHandler:result];
  4689. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4690. // NSMutableDictionary* json = [[OLDataProvider offline_model:params] mutableCopy];
  4691. // dispatch_async(dispatch_get_main_queue(), ^{
  4692. // result(json);
  4693. // });
  4694. // });
  4695. return;
  4696. }
  4697. [self request_interface:URL_ITEM_DETAIL parameters:params err_record_url:nil completionHandler:result retry:0];
  4698. //
  4699. // if(appDelegate.offline_mode)
  4700. // return [OLDataProvider offline_model:params];
  4701. //
  4702. // if(![self IsNetworkAvailable])
  4703. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4704. //
  4705. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  4706. // if(json==nil)
  4707. // return nil;
  4708. // NSError *error=nil;
  4709. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4710. // return jsobj;
  4711. }
  4712. +(void)request_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull completionHandler:(resultHandler)result
  4713. {
  4714. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4715. AppDelegate *appDelegate = nil;
  4716. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4717. if(appDelegate.user!=nil)
  4718. [params setValue:appDelegate.user forKey:@"user"];
  4719. if(appDelegate.contact_id!=nil)
  4720. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4721. if(appDelegate.password!=nil)
  4722. [params setValue:appDelegate.password forKey:@"password"];
  4723. if(appDelegate.order_code!=nil)
  4724. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4725. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4726. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4727. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  4728. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4729. // [params setValue:filter forKey:@"filter"];
  4730. [params setValue:keywords forKey:@"keyword"];
  4731. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4732. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4733. if(matchfull)
  4734. [params setValue:@"true" forKey:@"exactMatch"];
  4735. else
  4736. [params setValue:@"false" forKey:@"exactMatch"];
  4737. [params setObject:ScreenCodeSearch forKey:kScreenName];
  4738. if (keywords) {
  4739. [params setObject:@"Search" forKey:kAction];
  4740. }
  4741. if(appDelegate.offline_mode)
  4742. {
  4743. // [OLDataProvider offline_search:params completionHandler:result];
  4744. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4745. NSMutableDictionary* json = [[OLDataProvider offline_search:params] mutableCopy];
  4746. dispatch_async(dispatch_get_main_queue(), ^{
  4747. result(json);
  4748. });
  4749. });
  4750. return;
  4751. }
  4752. [self request_interface:URL_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  4753. // if(appDelegate.offline_mode)
  4754. // {
  4755. // return [OLDataProvider offline_search:params];
  4756. // }
  4757. // if(![self IsNetworkAvailable])
  4758. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4759. //
  4760. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  4761. // if(json==nil)
  4762. // return nil;
  4763. // NSError *error=nil;
  4764. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4765. // return jsobj;
  4766. }
  4767. +(void)request_login: (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
  4768. {
  4769. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  4770. // return RESULT_NET_ERROR;
  4771. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4772. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4773. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4774. AppDelegate *appDelegate = nil;
  4775. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4776. if(appDelegate.duid !=nil)
  4777. [params setValue:appDelegate.duid forKey:@"udid"];
  4778. [params setValue:@"handset_login" forKey:@"action"];
  4779. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  4780. [params setValue:user forKey:@"user"];
  4781. [params setValue:password forKey:@"password"];
  4782. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  4783. #ifdef TEST
  4784. [params setValue:@"true" forKey:@"is_debug"];
  4785. #else
  4786. [params setValue:@"false" forKey:@"is_debug"];
  4787. #endif
  4788. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  4789. [params setObject:@"Login" forKey:kAction];
  4790. if(appDelegate.offline_mode)
  4791. {
  4792. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4793. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_login:params]] mutableCopy];
  4794. dispatch_async(dispatch_get_main_queue(), ^{
  4795. int ret = [self parse_logininfo:json user:user password:password] ;
  4796. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4797. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4798. result(retjson);
  4799. });
  4800. });
  4801. return;
  4802. }
  4803. NSString* url;
  4804. bool scan_guest = false;
  4805. #ifdef SCANNER_ORDER
  4806. params[@"site_name"]=[RADataProvider getSiteName];
  4807. params[@"_method"]=@"login";
  4808. url = [appDelegate.address stringByAppendingPathComponent:URL_UPDATE_AUTH];
  4809. if([user.uppercaseString isEqualToString:@"GUEST"]&&[password.uppercaseString isEqualToString:@"GUEST"])
  4810. scan_guest = true;
  4811. #else
  4812. url = URL_UPDATE_AUTH;
  4813. #endif
  4814. if(scan_guest)
  4815. {
  4816. [OLDataProvider realguestLogin];
  4817. // int ret = [self parse_logininfo:chresult user:user password:password] ;
  4818. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4819. retjson[@"result"]= [NSNumber numberWithInt:RESULT_TRUE];
  4820. result(retjson);
  4821. }
  4822. else
  4823. {
  4824. [self request_interface:url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *chresult) {
  4825. int ret = [self parse_logininfo:chresult user:user password:password] ;
  4826. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4827. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4828. result(retjson);
  4829. } retry:0];
  4830. }
  4831. //
  4832. // NSData* json= nil;
  4833. // if(appDelegate.offline_mode)
  4834. // {
  4835. // json= [OLDataProvider offline_login:params] ;
  4836. //
  4837. // }
  4838. // else
  4839. // {
  4840. // if(![self IsNetworkAvailable])
  4841. // return RESULT_NET_NOTAVAILABLE;
  4842. // json =[self get_json:URL_UPDATE_AUTH parameters:params];
  4843. //
  4844. // }
  4845. //
  4846. // if(json==nil)
  4847. // return RESULT_NET_ERROR;
  4848. //
  4849. // int ret = [self parse_authinfo:json user:user password:password];
  4850. // DebugLog(@"parse_authinfo return %d ",ret);
  4851. //
  4852. //
  4853. // return ret;
  4854. //
  4855. }
  4856. +(int)parse_logininfo : (NSMutableDictionary *) jsobj user:(NSString*) user password:(NSString*) password
  4857. {
  4858. // DebugLog(@"parse_authinfo");
  4859. // NSError *error=nil;
  4860. //
  4861. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4862. if(jsobj)
  4863. {
  4864. AppDelegate *appDelegate = nil;
  4865. //some UI methods ej
  4866. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4867. int result = [[jsobj valueForKey:@"result"] intValue];
  4868. if (result<0)
  4869. return result;
  4870. if(result!=AP_USER_AUTH&& result!=9)
  4871. {
  4872. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  4873. // [appDelegate Logout];
  4874. if(result==8)
  4875. {
  4876. return RESULT_LOGIN_DEVICE;
  4877. }
  4878. return RESULT_FALSE;
  4879. }
  4880. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  4881. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  4882. user=[objheader objectForKey:@"username"] ;
  4883. DebugLog(@"required_ver=%@ ",required_ver);
  4884. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  4885. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  4886. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  4887. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  4888. // if([ibadge isEqual:[NSNull null]])
  4889. // strbadge=@"0";
  4890. // if(ibadge==nil)
  4891. // ibadge=@"0";
  4892. // if([strbadge isEqualToString:@"null"])
  4893. // strbadge=@"0";
  4894. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  4895. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  4896. #ifndef SCANNER_ORDER
  4897. if([appDelegate.build intValue]<[required_ver intValue])
  4898. return RESULT_VER_LOW;
  4899. #endif
  4900. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  4901. appDelegate.user = user;
  4902. appDelegate.password = password;
  4903. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  4904. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  4905. appDelegate.bLogin = true;
  4906. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  4907. #ifdef SCANNER_ORDER
  4908. appDelegate.available_price_group = objheader[@"price_group"];
  4909. [RADataProvider default_price_group];
  4910. #endif
  4911. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  4912. {
  4913. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  4914. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  4915. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  4916. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  4917. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  4918. }
  4919. NSString* mode =[jsobj valueForKey:@"mode"] ;
  4920. [appDelegate SetMode:mode];
  4921. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  4922. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  4923. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  4924. [appDelegate update_count_mark];
  4925. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  4926. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  4927. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  4928. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  4929. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  4930. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  4931. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  4932. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  4933. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  4934. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  4935. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  4936. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  4937. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  4938. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  4939. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  4940. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  4941. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  4942. [appDelegate set_main_button_panel];
  4943. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  4944. // shop order status filter
  4945. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  4946. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  4947. // Sales order status filter
  4948. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  4949. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  4950. // specialInstruction
  4951. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  4952. //-价格类型
  4953. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  4954. // 权限
  4955. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  4956. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  4957. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  4958. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  4959. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  4960. [[RASingleton sharedInstance] resetGlobalLock];
  4961. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  4962. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  4963. }
  4964. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  4965. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  4966. // {
  4967. // // no update on the server;
  4968. // return RESULT_TRUE;
  4969. // }
  4970. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  4971. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4972. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4973. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4974. // [defaults synchronize];
  4975. //
  4976. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  4977. // NSArray* keys= [objfuncs allKeys];
  4978. /*
  4979. db.setTransactionSuccessful();
  4980. db.endTransaction();
  4981. */
  4982. return RESULT_TRUE;
  4983. }
  4984. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  4985. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  4986. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  4987. return RESULT_USERAUTH_ERROR;
  4988. }
  4989. +(void)request_contactlist:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams completionHandler:(resultHandler)result
  4990. {
  4991. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4992. if(upparams!=nil)
  4993. params = [upparams mutableCopy];
  4994. AppDelegate *appDelegate = nil;
  4995. //some UI methods ej
  4996. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4997. if(appDelegate.user!=nil)
  4998. [params setValue:appDelegate.user forKey:@"user"];
  4999. if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  5000. [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  5001. else
  5002. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5003. if(appDelegate.password!=nil)
  5004. [params setValue:appDelegate.password forKey:@"password"];
  5005. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  5006. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  5007. [params setValue:contact_type forKey:@"contactType"];
  5008. [params setValue:keywords forKey:@"keyword"];
  5009. [params setObject:ScreenCodeAccount forKey:kScreenName];
  5010. if (keywords) {
  5011. [params setObject:@"Search" forKey:kAction];
  5012. }
  5013. if (upparams) {
  5014. [params setObject:@"Advance Search" forKey:kAction];
  5015. }
  5016. NSString* url=nil;
  5017. if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  5018. url=URL_SHIPTO_LIST;
  5019. else
  5020. url=URL_CONTACT_LIST;
  5021. if(appDelegate.offline_mode)
  5022. {
  5023. [OLDataProvider offline_contactlist:params completionHandler:result];
  5024. return;
  5025. }
  5026. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  5027. //
  5028. // if(appDelegate.offline_mode)
  5029. // return [OLDataProvider offline_contactlist:params];
  5030. //
  5031. // if(![self IsNetworkAvailable])
  5032. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5033. //
  5034. // NSData* json=[self get_json:url parameters:params];
  5035. // if(json==nil)
  5036. // return nil;
  5037. // NSError *error=nil;
  5038. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5039. // return jsobj;
  5040. }
  5041. +(void)request_contactinfo:(NSString* ) contactid completionHandler:(resultHandler)result
  5042. {
  5043. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5044. AppDelegate *appDelegate = nil;
  5045. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5046. if(appDelegate.user!=nil)
  5047. [params setValue:appDelegate.user forKey:@"user"];
  5048. // if(appDelegate.contact_id!=nil)
  5049. if(appDelegate.password!=nil)
  5050. [params setValue:appDelegate.password forKey:@"password"];
  5051. [params setValue:contactid forKey:@"contactId"];
  5052. [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  5053. if(appDelegate.offline_mode)
  5054. {
  5055. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5056. // [OLDataProvider offline_contactinfo:params completionHandler:result] ;
  5057. // });
  5058. params[@"mode"]=appDelegate.mode;
  5059. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5060. NSMutableDictionary* json = [[OLDataProvider offline_contactinfo:params] mutableCopy];
  5061. dispatch_async(dispatch_get_main_queue(), ^{
  5062. result(json);
  5063. });
  5064. });
  5065. return;
  5066. }
  5067. [self request_interface:URL_CUSTOMER_INFO parameters:params err_record_url:nil completionHandler:result retry:0];
  5068. // if(appDelegate.offline_mode)
  5069. // return [OLDataProvider offline_contactinfo:params];
  5070. // if(![self IsNetworkAvailable])
  5071. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5072. //
  5073. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  5074. // if(json==nil)
  5075. // return nil;
  5076. // NSError *error=nil;
  5077. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5078. // return jsobj;
  5079. //
  5080. }
  5081. +(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  5082. {
  5083. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5084. AppDelegate *appDelegate = nil;
  5085. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5086. if(appDelegate.user!=nil)
  5087. [params setValue:appDelegate.user forKey:@"user"];
  5088. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  5089. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  5090. // else
  5091. if(appDelegate.contact_id!=nil)
  5092. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5093. if(appDelegate.password!=nil)
  5094. [params setValue:appDelegate.password forKey:@"password"];
  5095. if(appDelegate.order_code!=nil)
  5096. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5097. bool can_create_backorder=appDelegate.can_create_backorder;
  5098. // [params setValue:sourceid forKey:@"sourceid"];
  5099. // [params setValue:editor forKey:@"editor"];
  5100. DebugLog(@"request editor url:%@",request_url);
  5101. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  5102. {
  5103. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  5104. }
  5105. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  5106. {
  5107. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  5108. }
  5109. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  5110. {
  5111. [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  5112. }
  5113. else if([request_url isEqualToString:URL_CARTDELIVERY])
  5114. {
  5115. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  5116. }
  5117. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  5118. {
  5119. [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  5120. }
  5121. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  5122. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  5123. }
  5124. if(appDelegate.offline_mode)
  5125. {
  5126. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5127. NSData* json = nil;
  5128. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  5129. {
  5130. json= [OLDataProvider offline_createContact:params];
  5131. }
  5132. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  5133. {
  5134. json= [OLDataProvider offline_editContact:params];
  5135. }
  5136. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  5137. {
  5138. json= [OLDataProvider offline_contactAdvancedSearch:params];
  5139. }
  5140. else if([request_url isEqualToString:URL_CARTDELIVERY])
  5141. {
  5142. params[@"contact_id"]=params[@"contactId"];
  5143. params[@"can_create_backorder"]=@(can_create_backorder);
  5144. json= [OLDataProvider offline_placeorder:params];
  5145. }
  5146. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  5147. {
  5148. json= [OLDataProvider offline_addreditor:params];
  5149. }
  5150. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  5151. json = [OLDataProvider offline_createTearSheet:params];
  5152. }
  5153. dispatch_async(dispatch_get_main_queue(), ^{
  5154. if(json==nil)
  5155. result( [[OLDataProvider offline_notimpl] mutableCopy]);
  5156. else
  5157. result([[RAConvertor data2dict:json] mutableCopy]);
  5158. });
  5159. });
  5160. return;
  5161. }
  5162. else
  5163. {
  5164. if([request_url isEqualToString:URL_CARTDELIVERY])
  5165. {
  5166. NSString * uuid= [[NSUUID UUID] UUIDString];
  5167. params[@"resultSerial"]=uuid;
  5168. __block bool bbreak = false;
  5169. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5170. for(int i=0;i<150;i++)
  5171. {
  5172. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  5173. // result_params[@"resultSerial"]=uuid;
  5174. //json=[self get_json:request_url parameters:params];
  5175. if(bbreak)
  5176. break;
  5177. dispatch_async(dispatch_get_main_queue(), ^{
  5178. NSLog(@"request cart delivery %d",i);
  5179. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5180. if(resulti!=nil)
  5181. {
  5182. if([resulti[@"result"] intValue]==2 || [resulti[@"result"] intValue] == 8)
  5183. {
  5184. if(!bbreak) //此判断保证result只调用一次。
  5185. {
  5186. result(resulti);
  5187. NSLog(@"result called at %d",i);
  5188. }
  5189. bbreak=true;
  5190. }
  5191. }
  5192. } retry:3];
  5193. });
  5194. // [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  5195. sleep(2);
  5196. }
  5197. });
  5198. }
  5199. else
  5200. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  5201. }
  5202. // if(json!=nil)
  5203. // {
  5204. // NSError *error=nil;
  5205. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5206. // return jsobj;
  5207. // }
  5208. // else
  5209. // return nil;
  5210. }
  5211. +(void)request_wishlist:(int)sort completionHandler:(resultHandler)result
  5212. {
  5213. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5214. AppDelegate *appDelegate = nil;
  5215. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5216. if(appDelegate.user!=nil)
  5217. [params setValue:appDelegate.user forKey:@"user"];
  5218. if(appDelegate.contact_id!=nil)
  5219. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5220. if(appDelegate.password!=nil)
  5221. [params setValue:appDelegate.password forKey:@"password"];
  5222. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  5223. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  5224. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  5225. [params setObject:ScreenCodeWishList forKey:kScreenName];
  5226. if(appDelegate.offline_mode)
  5227. {
  5228. [OLDataProvider offline_wishlist:params completionHandler:^(NSMutableDictionary *resulti) {
  5229. int result_code = [[resulti valueForKey:@"result"] intValue];
  5230. if (result_code==2)
  5231. {
  5232. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  5233. [appDelegate update_count_mark];;
  5234. result(resulti);
  5235. }
  5236. }];
  5237. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5238. // NSMutableDictionary* json = [[OLDataProvider offline_wishlist:params] mutableCopy];
  5239. // dispatch_async(dispatch_get_main_queue(), ^{
  5240. // result(json);
  5241. // });
  5242. // });
  5243. return;
  5244. }
  5245. [self request_interface:URL_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5246. int result_code = [[resulti valueForKey:@"result"] intValue];
  5247. if (result_code==2)
  5248. {
  5249. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  5250. [appDelegate update_count_mark];;
  5251. result(resulti);
  5252. }
  5253. } retry:0];
  5254. // if(appDelegate.offline_mode)
  5255. // {
  5256. // return [OLDataProvider offline_wishlist:params];
  5257. // }
  5258. // if(![self IsNetworkAvailable])
  5259. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5260. //
  5261. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  5262. // if(json==nil)
  5263. // return nil;
  5264. // NSError *error=nil;
  5265. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5266. // int result = [[jsobj valueForKey:@"result"] intValue];
  5267. //
  5268. // if (result==2)
  5269. // {
  5270. //
  5271. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5272. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  5273. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5274. //
  5275. // [appDelegate update_count_mark];
  5276. // }
  5277. // return jsobj;
  5278. }
  5279. +(void)request_portfoliolist:(int)sort completionHandler:(resultHandler)result
  5280. {
  5281. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5282. AppDelegate *appDelegate = nil;
  5283. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5284. if(appDelegate.user!=nil)
  5285. [params setValue:appDelegate.user forKey:@"user"];
  5286. if(appDelegate.contact_id!=nil)
  5287. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5288. if(appDelegate.password!=nil)
  5289. [params setValue:appDelegate.password forKey:@"password"];
  5290. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  5291. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  5292. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  5293. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  5294. if(appDelegate.offline_mode)
  5295. {
  5296. params[@"user"]=appDelegate.user;
  5297. params[@"contact_id"]=appDelegate.contact_id;
  5298. params[@"can_see_price"]=@(appDelegate.can_see_price);
  5299. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5300. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_portfolioList:params]] mutableCopy];
  5301. dispatch_async(dispatch_get_main_queue(), ^{
  5302. if ([json[@"result"] intValue]==2)
  5303. {
  5304. appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  5305. [appDelegate update_count_mark];
  5306. }
  5307. result(json);
  5308. });
  5309. });
  5310. return;
  5311. }
  5312. [self request_interface:URL_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5313. if ([resulti[@"result"] intValue]==2)
  5314. {
  5315. appDelegate.port_count =[[resulti valueForKey:@"count"] intValue];
  5316. [appDelegate update_count_mark];
  5317. }
  5318. result(resulti);
  5319. } retry:0];
  5320. // NSData* json = nil;
  5321. // if(appDelegate.offline_mode)
  5322. // {
  5323. // json = [OLDataProvider offline_portfolioList:params];
  5324. // } else {
  5325. // if(![self IsNetworkAvailable])
  5326. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5327. //
  5328. // json = [self get_json:URL_PORTFOLIO parameters:params];
  5329. // }
  5330. //
  5331. //
  5332. // if(json==nil)
  5333. // return nil;
  5334. // NSError *error=nil;
  5335. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5336. // int result = [[jsobj valueForKey:@"result"] intValue];
  5337. //
  5338. // if (result==2)
  5339. // {
  5340. //
  5341. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5342. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  5343. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  5344. //
  5345. // [appDelegate update_count_mark];
  5346. // }
  5347. // return jsobj;
  5348. }
  5349. +(void)request_portfoliopdf:(int ) offset limit:(int)limit keywords:(NSString* ) keywords completionHandler:(resultHandler)result
  5350. {
  5351. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5352. AppDelegate *appDelegate = nil;
  5353. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5354. if(appDelegate.user!=nil)
  5355. [params setValue:appDelegate.user forKey:@"user"];
  5356. if(appDelegate.contact_id!=nil)
  5357. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5358. if(appDelegate.password!=nil)
  5359. [params setValue:appDelegate.password forKey:@"password"];
  5360. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  5361. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  5362. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  5363. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  5364. // [params setValue:filter forKey:@"filter"];
  5365. [params setValue:keywords forKey:@"keyWord"];
  5366. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  5367. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  5368. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  5369. if (keywords) {
  5370. [params setObject:@"Search" forKey:kAction];
  5371. }
  5372. if(appDelegate.offline_mode)
  5373. {
  5374. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5375. NSData* json = [[OLDataProvider offline_pdfList:params] mutableCopy];
  5376. dispatch_async(dispatch_get_main_queue(), ^{
  5377. result([[RAConvertor data2dict:json] mutableCopy]);
  5378. });
  5379. });
  5380. return;
  5381. }
  5382. [self request_interface:URL_DM_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  5383. return;
  5384. // NSData* json = nil;
  5385. // if(appDelegate.offline_mode)
  5386. // {
  5387. // json = [OLDataProvider offline_pdfList:params];
  5388. // } else {
  5389. // if(![self IsNetworkAvailable])
  5390. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5391. //
  5392. // json=[self get_json:URL_DM_LIST parameters:params];
  5393. // }
  5394. // if(json==nil)
  5395. // return nil;
  5396. // NSError *error=nil;
  5397. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5398. // return jsobj;
  5399. }
  5400. +(void)request_orderlist:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged completionHandler:(resultHandler)result
  5401. {
  5402. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5403. AppDelegate *appDelegate = nil;
  5404. //some UI methods ej
  5405. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5406. if(appDelegate.user!=nil)
  5407. [params setValue:appDelegate.user forKey:@"user"];
  5408. if(appDelegate.contact_id!=nil)
  5409. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5410. if(appDelegate.password!=nil)
  5411. [params setValue:appDelegate.password forKey:@"password"];
  5412. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  5413. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  5414. [params setValue:keywords forKey:@"keyWord"];
  5415. [params setValue:customer forKey:@"customer_filter"];
  5416. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  5417. [params setValue:status_code forKey:@"orderStatus"];
  5418. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  5419. if (keywords) {
  5420. [params setObject:@"Search" forKey:kAction];
  5421. }
  5422. if(appDelegate.offline_mode)
  5423. {
  5424. params[@"user"]=appDelegate.user;
  5425. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5426. NSData* json = [[OLDataProvider offline_orderlist:params] mutableCopy];
  5427. dispatch_async(dispatch_get_main_queue(), ^{
  5428. result([[RAConvertor data2dict:json] mutableCopy]);
  5429. });
  5430. });
  5431. return;
  5432. }
  5433. [self request_interface:URL_ORDER_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  5434. // NSData* json=nil;
  5435. // if(appDelegate.offline_mode)
  5436. // {
  5437. // json= [OLDataProvider offline_orderlist:params];
  5438. // }
  5439. // else
  5440. // {
  5441. // if(![self IsNetworkAvailable])
  5442. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5443. //
  5444. // json=[self get_json:URL_ORDER_LIST parameters:params];
  5445. // }
  5446. // if(json==nil)
  5447. // return nil;
  5448. // NSError *error=nil;
  5449. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5450. // return jsobj;
  5451. }
  5452. +(void)request_logout:(resultHandler)result
  5453. {
  5454. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5455. AppDelegate *appDelegate = nil;
  5456. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5457. if(appDelegate.user!=nil)
  5458. [params setValue:appDelegate.user forKey:@"user"];
  5459. if(appDelegate.password!=nil)
  5460. [params setValue:appDelegate.password forKey:@"password"];
  5461. if(appDelegate.offline_mode)
  5462. {
  5463. [OLDataProvider offline_logout:params completionHandler:result];
  5464. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5465. // NSMutableDictionary* json = [[OLDataProvider offline_logout:params] mutableCopy];
  5466. // dispatch_async(dispatch_get_main_queue(), ^{
  5467. // result(json);
  5468. // });
  5469. // });
  5470. return;
  5471. }
  5472. [self request_interface:URL_LOGOUT parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5473. NSMutableDictionary* jsobj=resulti;
  5474. int result_code = [[jsobj valueForKey:@"result"] intValue];
  5475. if (result_code==2)
  5476. {
  5477. appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  5478. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5479. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5480. [appDelegate update_count_mark];
  5481. appDelegate.can_show_price =false;
  5482. appDelegate.can_see_price =false;
  5483. appDelegate.can_create_portfolio =false;
  5484. appDelegate.can_create_order =false;
  5485. appDelegate.can_cancel_order =false;
  5486. appDelegate.can_set_cart_price =false;
  5487. appDelegate.can_delete_order =false;
  5488. appDelegate.can_submit_order =false;
  5489. appDelegate.can_set_tearsheet_price =false;
  5490. appDelegate.can_update_contact_info = false;
  5491. appDelegate.save_order_logout = false;
  5492. appDelegate.submit_order_logout = false;
  5493. appDelegate.alert_sold_in_quantities = false;
  5494. appDelegate.ipad_perm =nil ;
  5495. appDelegate.user_type = USER_ROLE_UNKNOWN;
  5496. appDelegate.OrderFilter= nil;
  5497. [appDelegate SetSo:nil];
  5498. [appDelegate set_main_button_panel];
  5499. #ifdef RA_NOTIFICATION
  5500. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5501. #endif
  5502. }
  5503. result(resulti);
  5504. } retry:0];
  5505. //
  5506. // if(appDelegate.offline_mode)
  5507. // {
  5508. // return [OLDataProvider offline_logout:params];
  5509. // }
  5510. // if(![self IsNetworkAvailable])
  5511. // {
  5512. // DebugLog(@"NET ERR");
  5513. //
  5514. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5515. // // return nil;
  5516. // }
  5517. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  5518. // //if(json==nil)
  5519. //
  5520. //
  5521. // if(json==nil)
  5522. // return nil;
  5523. // NSError *error=nil;
  5524. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5525. // int result = [[jsobj valueForKey:@"result"] intValue];
  5526. //
  5527. // if (result==2)
  5528. // {
  5529. //
  5530. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  5531. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5532. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5533. //
  5534. // [appDelegate update_count_mark];
  5535. //
  5536. //
  5537. // appDelegate.can_show_price =false;
  5538. // appDelegate.can_see_price =false;
  5539. // appDelegate.can_create_portfolio =false;
  5540. // appDelegate.can_create_order =false;
  5541. //
  5542. //
  5543. // appDelegate.can_cancel_order =false;
  5544. // appDelegate.can_set_cart_price =false;
  5545. // appDelegate.can_delete_order =false;
  5546. // appDelegate.can_submit_order =false;
  5547. // appDelegate.can_set_tearsheet_price =false;
  5548. // appDelegate.can_update_contact_info = false;
  5549. //
  5550. // appDelegate.save_order_logout = false;
  5551. // appDelegate.submit_order_logout = false;
  5552. // appDelegate.alert_sold_in_quantities = false;
  5553. //
  5554. // appDelegate.ipad_perm =nil ;
  5555. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  5556. // appDelegate.OrderFilter= nil;
  5557. // [appDelegate SetSo:nil];
  5558. // [appDelegate set_main_button_panel];
  5559. //#ifdef RA_NOTIFICATION
  5560. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5561. //#endif
  5562. // }
  5563. // return jsobj;
  5564. }
  5565. + (void)request_hangtag:(NSString *)group completionHandler:(resultHandler)result
  5566. {
  5567. #ifdef BUILD_UWAVER
  5568. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5569. AppDelegate *appDelegate = nil;
  5570. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5571. if(appDelegate.user!=nil)
  5572. [params setValue:appDelegate.user forKey:@"user"];
  5573. if(appDelegate.contact_id!=nil)
  5574. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5575. if(appDelegate.password!=nil)
  5576. [params setValue:appDelegate.password forKey:@"password"];
  5577. if (group) {
  5578. [params setValue:group forKey:@"groupName"];
  5579. }
  5580. NSString * uuid= [[NSUUID UUID] UUIDString];
  5581. params[@"resultSerial"]=uuid;
  5582. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  5583. if(appDelegate.offline_mode)
  5584. {
  5585. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5586. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5587. dispatch_async(dispatch_get_main_queue(), ^{
  5588. result(json);
  5589. });
  5590. });
  5591. return;
  5592. }
  5593. [self request_interface:URL_CREATE_HANG_TAG parameters:params err_record_url:nil completionHandler:result retry:0];
  5594. // NSData* json = nil;
  5595. // if(appDelegate.offline_mode)
  5596. // {
  5597. // json = [OLDataProvider offline_portfolioList:params];
  5598. // } else {
  5599. // if(![self IsNetworkAvailable])
  5600. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5601. //
  5602. // json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  5603. // }
  5604. //
  5605. //
  5606. // if(json==nil)
  5607. // return nil;
  5608. // NSError *error=nil;
  5609. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5610. //
  5611. // return jsobj;
  5612. #else
  5613. return result(nil);
  5614. #endif
  5615. }
  5616. + (void)request_movetobackorder:(NSString *)cart_item_id completionHandler:(resultHandler)result
  5617. {
  5618. if (cart_item_id == nil || cart_item_id.length < 1) {
  5619. result([@{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"} mutableCopy]);
  5620. }
  5621. AppDelegate *appDelegate = nil;
  5622. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5623. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5624. if(appDelegate.user!=nil)
  5625. [dic setValue:appDelegate.user forKey:@"user"];
  5626. if(appDelegate.password!=nil)
  5627. [dic setValue:appDelegate.password forKey:@"password"];
  5628. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  5629. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  5630. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5631. if(appDelegate.offline_mode)
  5632. {
  5633. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5634. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5635. dispatch_async(dispatch_get_main_queue(), ^{
  5636. result(json);
  5637. });
  5638. });
  5639. return;
  5640. }
  5641. [self request_interface:URL_MOVE_TO_BACK_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5642. // if(![self IsNetworkAvailable])
  5643. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5644. //
  5645. // NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  5646. //
  5647. // if(json!=nil)
  5648. // {
  5649. // NSError *error=nil;
  5650. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5651. //
  5652. // return jsobj;
  5653. // }
  5654. //
  5655. // return @{@"result" : @(RESULT_FALSE)};
  5656. }
  5657. + (void)request_emailwishlist:(NSString *)addr completionHandler:(resultHandler)result
  5658. {
  5659. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5660. AppDelegate *appDelegate = nil;
  5661. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5662. if(appDelegate.user!=nil)
  5663. [dic setValue:appDelegate.user forKey:@"user"];
  5664. if(appDelegate.password!=nil)
  5665. [dic setValue:appDelegate.password forKey:@"password"];
  5666. [dic setValue:addr forKey:@"email"];
  5667. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  5668. // if (appDelegate.customerInfo) {
  5669. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5670. // if (customer_cid) {
  5671. // [dic setValue:customer_cid forKey:@"contactId"];
  5672. // }
  5673. // }
  5674. if(appDelegate.offline_mode)
  5675. {
  5676. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5677. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5678. dispatch_async(dispatch_get_main_queue(), ^{
  5679. result(json);
  5680. });
  5681. });
  5682. return;
  5683. }
  5684. [self request_interface:URL_EMAIL_WISHLIST parameters:dic err_record_url:nil completionHandler:result retry:0];
  5685. // NSData* json=nil;
  5686. // if(appDelegate.offline_mode)
  5687. // {
  5688. // return [OLDataProvider offline_notimpl];
  5689. // }
  5690. // else
  5691. // {
  5692. // if(![self IsNetworkAvailable])
  5693. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5694. //
  5695. // json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  5696. // }
  5697. // if(json!=nil)
  5698. // {
  5699. // NSError *error=nil;
  5700. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5701. //
  5702. //
  5703. // return jsobj;
  5704. // }
  5705. //
  5706. // return @{@"result" : @(RESULT_FALSE)};
  5707. }
  5708. +(void)request_notifymodel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  5709. {
  5710. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5711. AppDelegate *appDelegate = nil;
  5712. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5713. if(appDelegate.user!=nil)
  5714. [dic setValue:appDelegate.user forKey:@"user"];
  5715. if(appDelegate.password!=nil)
  5716. [dic setValue:appDelegate.password forKey:@"password"];
  5717. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5718. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5719. if (customer_cid) {
  5720. [dic setValue:customer_cid forKey:@"contactId"];
  5721. }
  5722. }
  5723. [dic setObject:screenName forKey:kScreenName];
  5724. [dic setValue:modelID forKey:@"productId"];
  5725. if (addr) { // 弹框输入
  5726. [dic setValue:addr forKey:@"email"];
  5727. } else {
  5728. // employee选择了Contact,并且Contact有Email
  5729. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5730. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  5731. // if (email) {
  5732. // [dic setValue:email forKey:@"email"];
  5733. // }
  5734. // }
  5735. }
  5736. if(appDelegate.offline_mode)
  5737. {
  5738. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5739. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5740. dispatch_async(dispatch_get_main_queue(), ^{
  5741. result(json);
  5742. });
  5743. });
  5744. return;
  5745. }
  5746. [self request_interface:URL_NOTIFY_ME parameters:dic err_record_url:nil completionHandler:result retry:0];
  5747. // NSData* json=nil;
  5748. // if(appDelegate.offline_mode)
  5749. // {
  5750. // return [OLDataProvider offline_notimpl];
  5751. // }
  5752. // else
  5753. // {
  5754. // if(![self IsNetworkAvailable])
  5755. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5756. //
  5757. // json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  5758. // }
  5759. // if(json!=nil)
  5760. // {
  5761. // NSError *error=nil;
  5762. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5763. //
  5764. //
  5765. // return jsobj;
  5766. // }
  5767. //
  5768. // return @{@"result" : @(RESULT_FALSE)};
  5769. }
  5770. + (void)request_qouteorder:(NSString *)so_id emailAddr:(NSString *)addr completionHandler:(resultHandler)result
  5771. {
  5772. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5773. AppDelegate *appDelegate = nil;
  5774. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5775. if(appDelegate.user!=nil)
  5776. [dic setValue:appDelegate.user forKey:@"user"];
  5777. if(appDelegate.password!=nil)
  5778. [dic setValue:appDelegate.password forKey:@"password"];
  5779. [dic setValue:so_id forKey:@"orderCode"];
  5780. [dic setValue:addr forKey:@"email"];
  5781. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5782. if (appDelegate.customerInfo) {
  5783. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5784. if (customer_cid) {
  5785. [dic setValue:customer_cid forKey:@"contactId"];
  5786. }
  5787. }
  5788. if(appDelegate.offline_mode)
  5789. {
  5790. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5791. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5792. dispatch_async(dispatch_get_main_queue(), ^{
  5793. result(json);
  5794. });
  5795. });
  5796. return;
  5797. }
  5798. [self request_interface:URL_EMAIL_CART parameters:dic err_record_url:nil completionHandler:result retry:0];
  5799. // NSData* json=nil;
  5800. // if(appDelegate.offline_mode)
  5801. // {
  5802. // return [OLDataProvider offline_notimpl];
  5803. // }
  5804. // else
  5805. // {
  5806. // if(![self IsNetworkAvailable])
  5807. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5808. //
  5809. // json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  5810. // }
  5811. // if(json!=nil)
  5812. // {
  5813. // NSError *error=nil;
  5814. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5815. //
  5816. //
  5817. // return jsobj;
  5818. // }
  5819. //
  5820. // return @{@"result" : @(RESULT_FALSE)};
  5821. }
  5822. + (void)request_mergeorder:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  5823. {
  5824. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5825. AppDelegate *appDelegate = nil;
  5826. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5827. if(appDelegate.user!=nil)
  5828. [dic setValue:appDelegate.user forKey:@"user"];
  5829. if(appDelegate.password!=nil)
  5830. [dic setValue:appDelegate.password forKey:@"password"];
  5831. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  5832. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  5833. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  5834. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  5835. if(appDelegate.offline_mode)
  5836. {
  5837. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5838. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5839. dispatch_async(dispatch_get_main_queue(), ^{
  5840. result(json);
  5841. });
  5842. });
  5843. return;
  5844. }
  5845. [self request_interface:URL_SET_MERGE_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5846. // NSData* json=nil;
  5847. // if(appDelegate.offline_mode)
  5848. // {
  5849. // return [OLDataProvider offline_notimpl];
  5850. // }
  5851. // else
  5852. // {
  5853. // if(![self IsNetworkAvailable])
  5854. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5855. //
  5856. // json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  5857. // }
  5858. // if(json!=nil)
  5859. // {
  5860. // NSError *error=nil;
  5861. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5862. //
  5863. //
  5864. // return jsobj;
  5865. // }
  5866. // else
  5867. // return nil;
  5868. }
  5869. +(void)request_pendingorder:(NSString *)contactid completionHandler:(resultHandler)result
  5870. {
  5871. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5872. AppDelegate *appDelegate = nil;
  5873. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5874. if(appDelegate.user!=nil)
  5875. [params setValue:appDelegate.user forKey:@"user"];
  5876. // if(appDelegate.contact_id!=nil)
  5877. if(appDelegate.password!=nil)
  5878. [params setValue:appDelegate.password forKey:@"password"];
  5879. [params setValue:contactid forKey:@"contactId"];
  5880. if(appDelegate.offline_mode)
  5881. {
  5882. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5883. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5884. dispatch_async(dispatch_get_main_queue(), ^{
  5885. result(json);
  5886. });
  5887. });
  5888. return;
  5889. }
  5890. [self request_interface:URL_CUSTOMER_PENDINGORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  5891. //
  5892. // if(appDelegate.offline_mode)
  5893. // {
  5894. // return [OLDataProvider offline_notimpl];
  5895. // }
  5896. // if(![self IsNetworkAvailable])
  5897. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5898. //
  5899. // NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  5900. // if(json==nil)
  5901. // return nil;
  5902. // NSError *error=nil;
  5903. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5904. // return jsobj;
  5905. //
  5906. }
  5907. +(void) request_removeportfolio:(NSString* ) item_ids completionHandler:(resultHandler)result
  5908. {
  5909. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5910. AppDelegate *appDelegate = nil;
  5911. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5912. if(appDelegate.user!=nil)
  5913. [params setValue:appDelegate.user forKey:@"user"];
  5914. if(appDelegate.contact_id!=nil)
  5915. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5916. if(appDelegate.password!=nil)
  5917. [params setValue:appDelegate.password forKey:@"password"];
  5918. [params setValue:item_ids forKey:@"portfolioId"];
  5919. // [params setValue:editor forKey:@"editor"];
  5920. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  5921. if(appDelegate.offline_mode)
  5922. {
  5923. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5924. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_removePortfolio:params]] mutableCopy];
  5925. dispatch_async(dispatch_get_main_queue(), ^{
  5926. int result_code = [[resulti valueForKey:@"result"] intValue];
  5927. if (result_code==2)
  5928. {
  5929. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5930. [appDelegate update_count_mark];
  5931. };
  5932. result(resulti);
  5933. });
  5934. });
  5935. return;
  5936. }
  5937. [self request_interface:URL_PORTFOLIO_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5938. int result_code = [[resulti valueForKey:@"result"] intValue];
  5939. if (result_code==2)
  5940. {
  5941. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5942. [appDelegate update_count_mark];
  5943. };
  5944. result(resulti);
  5945. } retry:0];
  5946. // NSData* json = nil;
  5947. // if(appDelegate.offline_mode)
  5948. // {
  5949. // json = [OLDataProvider offline_removePortfolio:params];
  5950. // } else {
  5951. // if(![self IsNetworkAvailable])
  5952. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5953. // json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  5954. // }
  5955. // if(json!=nil)
  5956. // {
  5957. // NSError *error=nil;
  5958. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5959. //
  5960. //
  5961. // int result = [[jsobj valueForKey:@"result"] intValue];
  5962. //
  5963. // if (result==2)
  5964. // {
  5965. //
  5966. //
  5967. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5968. //
  5969. // [appDelegate update_count_mark];
  5970. // }
  5971. // return jsobj;
  5972. // }
  5973. // else
  5974. // return nil;
  5975. }
  5976. +(void) request_removeportfoliopdf:(NSString* ) listid completionHandler:(resultHandler)result
  5977. {
  5978. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5979. AppDelegate *appDelegate = nil;
  5980. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5981. if(appDelegate.user!=nil)
  5982. [params setValue:appDelegate.user forKey:@"user"];
  5983. if(appDelegate.contact_id!=nil)
  5984. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5985. if(appDelegate.password!=nil)
  5986. [params setValue:appDelegate.password forKey:@"password"];
  5987. [params setValue:listid forKey:@"tearsheetsId"];
  5988. // [params setValue:editor forKey:@"editor"];
  5989. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  5990. // [params setValue:@"Delete Portfolio" forKey:kAction];
  5991. if(appDelegate.offline_mode)
  5992. {
  5993. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5994. NSData* json = [[OLDataProvider offline_removePDF:params] mutableCopy];
  5995. dispatch_async(dispatch_get_main_queue(), ^{
  5996. result([[RAConvertor data2dict:json] mutableCopy]);
  5997. });
  5998. });
  5999. return;
  6000. }
  6001. [self request_interface:URL_PORTFOLIOLIST_REMOVE parameters:params err_record_url:nil completionHandler:result retry:0];
  6002. }
  6003. +(void) request_remove_wishlist:(NSString* ) item_ids completionHandler:(resultHandler)result
  6004. {
  6005. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6006. __block AppDelegate *appDelegate = nil;
  6007. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6008. if(appDelegate.user!=nil)
  6009. [params setValue:appDelegate.user forKey:@"user"];
  6010. if(appDelegate.contact_id!=nil)
  6011. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6012. if(appDelegate.password!=nil)
  6013. [params setValue:appDelegate.password forKey:@"password"];
  6014. [params setValue:item_ids forKey:@"collectId"];
  6015. // [params setValue:editor forKey:@"editor"];
  6016. [params setValue:ScreenCodeWishList forKey:kScreenName];
  6017. if(appDelegate.offline_mode)
  6018. {
  6019. // [OLDataProvider offline_deletewishlist:params completionHandler:result];
  6020. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6021. NSMutableDictionary* resulti = [[OLDataProvider offline_deletewishlist:params] mutableCopy];
  6022. dispatch_async(dispatch_get_main_queue(), ^{
  6023. int result_code = [[resulti valueForKey:@"result"] intValue];
  6024. if (result_code==2)
  6025. {
  6026. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6027. [appDelegate update_count_mark];
  6028. };
  6029. result(resulti);
  6030. });
  6031. });
  6032. return;
  6033. }
  6034. [self request_interface:URL_WATCHLIST_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6035. int result_code = [[resulti valueForKey:@"result"] intValue];
  6036. if (result_code==2)
  6037. {
  6038. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6039. [appDelegate update_count_mark];
  6040. };
  6041. result(resulti);
  6042. } retry:0];
  6043. //
  6044. //
  6045. // if(appDelegate.offline_mode)
  6046. // {
  6047. // return [OLDataProvider offline_deletewishlist:params];
  6048. // }
  6049. // if(![self IsNetworkAvailable])
  6050. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6051. //
  6052. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  6053. // if(json!=nil)
  6054. // {
  6055. // NSError *error=nil;
  6056. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6057. // int result = [[jsobj valueForKey:@"result"] intValue];
  6058. //
  6059. // if (result==2)
  6060. // {
  6061. //
  6062. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6063. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6064. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6065. //
  6066. // [appDelegate update_count_mark];
  6067. // }
  6068. // return jsobj;
  6069. // }
  6070. // else
  6071. // return nil;
  6072. }
  6073. +(void) request_remove_cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  6074. {
  6075. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6076. AppDelegate *appDelegate = nil;
  6077. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6078. #ifdef SCANNER_ORDER
  6079. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  6080. {
  6081. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  6082. //
  6083. //
  6084. // [appDelegate update_count_mark];
  6085. NSArray* arr=[RAConvertor string2arr:item_ids separator:@","];
  6086. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  6087. NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  6088. NSMutableDictionary* newsection =[cartTemplate[@"section_0"] mutableCopy];
  6089. int newcount = 0;
  6090. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  6091. int count = [section[@"count"] intValue];
  6092. for(int i=0;i<count;i++)
  6093. {
  6094. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  6095. int index = [arr indexOfObject:item[@"cart_item_id"]] ;
  6096. if(index <0)
  6097. {
  6098. newsection[[NSString stringWithFormat:@"item_%d",newcount]] = item;
  6099. newcount ++;
  6100. }
  6101. }
  6102. newsection[@"count"]=@(newcount);
  6103. RASingleton.sharedInstance.scan_cart[@"section_0"] = newsection;
  6104. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  6105. result(RASingleton.sharedInstance.scan_cart);
  6106. return;
  6107. }
  6108. #endif
  6109. if(appDelegate.user!=nil)
  6110. [params setValue:appDelegate.user forKey:@"user"];
  6111. if(appDelegate.contact_id!=nil)
  6112. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6113. if(appDelegate.password!=nil)
  6114. [params setValue:appDelegate.password forKey:@"password"];
  6115. if(appDelegate.order_code!=nil)
  6116. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6117. [params setValue:item_ids forKey:@"cartItemId"];
  6118. // [params setValue:editor forKey:@"editor"];
  6119. [params setValue:ScreenCodeCart forKey:kScreenName];
  6120. // [params setValue:@"" forKey:kAction];
  6121. if(appDelegate.offline_mode)
  6122. {
  6123. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6124. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_cartremove:params]] mutableCopy];
  6125. dispatch_async(dispatch_get_main_queue(), ^{
  6126. int result_code = [[resulti valueForKey:@"result"] intValue];
  6127. if (result_code==2)
  6128. {
  6129. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6130. [appDelegate update_count_mark];
  6131. };
  6132. result(resulti);
  6133. });
  6134. });
  6135. return;
  6136. }
  6137. [self request_interface:URL_CART_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6138. int result_code = [[resulti valueForKey:@"result"] intValue];
  6139. if (result_code==2)
  6140. {
  6141. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6142. [appDelegate update_count_mark];
  6143. };
  6144. result(resulti);
  6145. } retry:0];
  6146. //
  6147. // NSData* json=nil;
  6148. // if(appDelegate.offline_mode)
  6149. // {
  6150. // json= [OLDataProvider offline_cartremove:params];
  6151. // }
  6152. // else
  6153. // {
  6154. // if(![self IsNetworkAvailable])
  6155. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6156. //
  6157. // json=[self get_json:URL_CART_REMOVE parameters:params];
  6158. // }
  6159. // if(json!=nil)
  6160. // {
  6161. // NSError *error=nil;
  6162. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6163. //
  6164. // int result = [[jsobj valueForKey:@"result"] intValue];
  6165. //
  6166. // if (result==2)
  6167. // {
  6168. //
  6169. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6170. //
  6171. //
  6172. // [appDelegate update_count_mark];
  6173. // }
  6174. // return jsobj;
  6175. // }
  6176. // else
  6177. // return nil;
  6178. }
  6179. +(void)request_delete_account:(resultHandler)result
  6180. {
  6181. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6182. AppDelegate *appDelegate = nil;
  6183. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6184. if(appDelegate.user!=nil)
  6185. [params setValue:appDelegate.user forKey:@"user"];
  6186. if(appDelegate.password!=nil)
  6187. [params setValue:appDelegate.password forKey:@"password"];
  6188. if(appDelegate.offline_mode)
  6189. {
  6190. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6191. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  6192. dispatch_async(dispatch_get_main_queue(), ^{
  6193. result(json);
  6194. });
  6195. });
  6196. return;
  6197. }
  6198. #ifdef SCANNER_ORDER
  6199. params[@"site_name"]=[RADataProvider getSiteName];
  6200. params[@"_method"]=@"cancelOfflineOrderUser";
  6201. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_DELETE_ACCOUNT];
  6202. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  6203. #else
  6204. [self request_interface:URL_DELETE_ACCOUNT parameters:params err_record_url:nil completionHandler:result retry:0];
  6205. #endif
  6206. }
  6207. +(void) request_create_order:(resultHandler)result
  6208. {
  6209. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6210. AppDelegate *appDelegate = nil;
  6211. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6212. if(appDelegate.user!=nil)
  6213. [params setValue:appDelegate.user forKey:@"user"];
  6214. if(appDelegate.contact_id!=nil)
  6215. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6216. if(appDelegate.password!=nil)
  6217. [params setValue:appDelegate.password forKey:@"password"];
  6218. if(appDelegate.order_code!=nil)
  6219. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6220. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  6221. NSDictionary* customerinfo= appDelegate.customerInfo;
  6222. NSArray* keys=[customerinfo allKeys];
  6223. for(int i=0;i<keys.count;i++)
  6224. {
  6225. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  6226. }
  6227. if(appDelegate.offline_mode)
  6228. {
  6229. [OLDataProvider offline_createorder:params completionHandler:^(NSMutableDictionary *resulti) {
  6230. int result_code = [[resulti valueForKey:@"result"] intValue];
  6231. if (result_code==2)
  6232. {
  6233. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6234. [appDelegate update_count_mark];
  6235. };
  6236. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  6237. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6238. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  6239. }
  6240. result(resulti);
  6241. }];
  6242. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6243. // NSData* json = [[OLDataProvider offline_createorder:params] mutableCopy];
  6244. // dispatch_async(dispatch_get_main_queue(), ^{
  6245. // result([[RAConvertor data2dict:json] mutableCopy]);
  6246. // });
  6247. // });
  6248. return;
  6249. }
  6250. [self request_interface:URL_NEW_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6251. int result_code = [[resulti valueForKey:@"result"] intValue];
  6252. if (result_code==2)
  6253. {
  6254. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6255. [appDelegate update_count_mark];
  6256. };
  6257. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  6258. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6259. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  6260. }
  6261. result(resulti);
  6262. } retry:0];
  6263. //
  6264. // NSData* json = nil;
  6265. // if(appDelegate.offline_mode)
  6266. // {
  6267. // json= [OLDataProvider offline_createorder:params];
  6268. // }
  6269. // else
  6270. // {
  6271. // if(![self IsNetworkAvailable])
  6272. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6273. //
  6274. // json=[self get_json:URL_NEW_ORDER parameters:params];
  6275. // }
  6276. // if(json==nil)
  6277. // return nil;
  6278. // NSError *error=nil;
  6279. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6280. // int result = [[jsobj valueForKey:@"result"] intValue];
  6281. //
  6282. // if (result==2)
  6283. // {
  6284. //
  6285. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6286. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6287. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6288. //
  6289. // [appDelegate update_count_mark];
  6290. // }
  6291. //
  6292. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  6293. //
  6294. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6295. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  6296. // }
  6297. //
  6298. // return jsobj;
  6299. }
  6300. +(void)request_open_order:(NSString*) order_code completionHandler:(resultHandler)result
  6301. {
  6302. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6303. AppDelegate *appDelegate = nil;
  6304. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6305. if(appDelegate.user!=nil)
  6306. [params setValue:appDelegate.user forKey:@"user"];
  6307. // if(appDelegate.contact_id!=nil)
  6308. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6309. if(appDelegate.password!=nil)
  6310. [params setValue:appDelegate.password forKey:@"password"];
  6311. [params setValue:order_code forKey:@"orderCode"];
  6312. // [params setValue:sourceid forKey:@"sourceid"];
  6313. // [params setValue:editor forKey:@"editor"];
  6314. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  6315. if(appDelegate.offline_mode)
  6316. {
  6317. params[@"appDelegate.order_code"]=appDelegate.order_code;
  6318. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6319. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_editorder:params]] mutableCopy];
  6320. dispatch_async(dispatch_get_main_queue(), ^{
  6321. int result_code = [[resulti valueForKey:@"result"] intValue];
  6322. if (result_code==2)
  6323. {
  6324. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6325. [appDelegate update_count_mark];
  6326. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6327. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  6328. }
  6329. }
  6330. result(resulti);
  6331. });
  6332. });
  6333. return;
  6334. }
  6335. [self request_interface:URL_OPEN_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6336. int result_code = [[resulti valueForKey:@"result"] intValue];
  6337. if (result_code==2)
  6338. {
  6339. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6340. [appDelegate update_count_mark];
  6341. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6342. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  6343. }
  6344. }
  6345. result(resulti);
  6346. } retry:0];
  6347. //
  6348. // NSData* json=nil;
  6349. // if(appDelegate.offline_mode)
  6350. // {
  6351. // json=[OLDataProvider offline_editorder:params];
  6352. //
  6353. // }
  6354. // else
  6355. // {
  6356. // if(![self IsNetworkAvailable])
  6357. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6358. //
  6359. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  6360. // }
  6361. // if(json!=nil)
  6362. // {
  6363. // NSError *error=nil;
  6364. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6365. // int result = [[jsobj valueForKey:@"result"] intValue];
  6366. //
  6367. // if (result==2)
  6368. // {
  6369. //
  6370. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6371. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6372. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6373. //
  6374. // [appDelegate update_count_mark];
  6375. //
  6376. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6377. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  6378. // }
  6379. //
  6380. // }
  6381. //
  6382. // return jsobj;
  6383. // }
  6384. // else
  6385. // return nil;
  6386. }
  6387. +(void)request_order_discount:(double)discount completionHandler:(resultHandler)result
  6388. {
  6389. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6390. AppDelegate *appDelegate = nil;
  6391. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6392. if(appDelegate.user!=nil)
  6393. [params setValue:appDelegate.user forKey:@"user"];
  6394. // if(appDelegate.contact_id!=nil)
  6395. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6396. if(appDelegate.password!=nil)
  6397. [params setValue:appDelegate.password forKey:@"password"];
  6398. if(appDelegate.order_code!=nil)
  6399. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6400. [params setValue:@(discount) forKey:@"app_discount"];
  6401. if(appDelegate.offline_mode)
  6402. {
  6403. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6404. NSMutableDictionary* json = [[OLDataProvider offline_cartsetallprice:params] mutableCopy];
  6405. dispatch_async(dispatch_get_main_queue(), ^{
  6406. result(json);
  6407. });
  6408. });
  6409. return;
  6410. //
  6411. //
  6412. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6413. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  6414. // dispatch_async(dispatch_get_main_queue(), ^{
  6415. // result(json);
  6416. // });
  6417. // });
  6418. //
  6419. // return;
  6420. }
  6421. [self request_interface:URL_ORDER_DISCOUNT parameters:params err_record_url:nil completionHandler:result retry:0];
  6422. }
  6423. +(void)request_cart:(int)sort completionHandler:(resultHandler)result
  6424. {
  6425. DebugLog(@"iSalesNetwork::request_Cart");
  6426. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6427. AppDelegate *appDelegate = nil;
  6428. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6429. #ifdef SCANNER_ORDER
  6430. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  6431. {
  6432. appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  6433. [appDelegate update_count_mark];
  6434. result(RASingleton.sharedInstance.scan_cart);
  6435. return;
  6436. }
  6437. #endif
  6438. if(appDelegate.user!=nil)
  6439. [params setValue:appDelegate.user forKey:@"user"];
  6440. // if(appDelegate.contact_id!=nil)
  6441. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6442. if(appDelegate.password!=nil)
  6443. [params setValue:appDelegate.password forKey:@"password"];
  6444. if(appDelegate.order_code!=nil)
  6445. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6446. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  6447. [params setObject:ScreenCodeCart forKey:kScreenName];
  6448. if(appDelegate.offline_mode)
  6449. {
  6450. [OLDataProvider offline_requestcart:params completionHandler:^(NSMutableDictionary *resulti) {
  6451. if([resulti[@"result"] intValue]==2)
  6452. {
  6453. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6454. [appDelegate update_count_mark];
  6455. result(resulti);
  6456. }
  6457. }];
  6458. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6459. // NSData* json = [[OLDataProvider offline_requestcart:params] mutableCopy];
  6460. // dispatch_async(dispatch_get_main_queue(), ^{
  6461. // result([[RAConvertor data2dict:json] mutableCopy]);
  6462. // });
  6463. // });
  6464. return;
  6465. }
  6466. NSString * uuid= [[NSUUID UUID] UUIDString];
  6467. params[@"resultSerial"]=uuid;
  6468. __block bool bbreak = false;
  6469. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6470. for(int i=0;i<150;i++)
  6471. {
  6472. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6473. // result_params[@"resultSerial"]=uuid;
  6474. if(bbreak)
  6475. break;
  6476. dispatch_async(dispatch_get_main_queue(), ^{
  6477. [self request_interface:URL_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6478. if([resulti[@"result"] intValue]==2)
  6479. {
  6480. if(!bbreak) //此判断保证result只调用一次。
  6481. {
  6482. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6483. [appDelegate update_count_mark];
  6484. result(resulti);
  6485. }
  6486. bbreak=true;
  6487. }
  6488. } retry:3];
  6489. });
  6490. sleep(2);
  6491. // json=[self get_json:URL_CART parameters:params];
  6492. // if(json!=nil)
  6493. // {
  6494. //
  6495. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6496. // if([jsobj[@"result"] intValue]==2)
  6497. // {
  6498. // break;
  6499. // }
  6500. // }
  6501. }
  6502. });
  6503. //
  6504. //
  6505. //
  6506. // NSData* json=nil;
  6507. // if(appDelegate.offline_mode)
  6508. // {
  6509. // json= [OLDataProvider offline_requestcart:params];
  6510. // }
  6511. // else
  6512. // {
  6513. // if(![self IsNetworkAvailable])
  6514. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6515. //
  6516. // NSError *error=nil;
  6517. //
  6518. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6519. // params[@"resultSerial"]=uuid;
  6520. //
  6521. // for(int i=0;i<150;i++)
  6522. // {
  6523. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6524. // // result_params[@"resultSerial"]=uuid;
  6525. // json=[self get_json:URL_CART parameters:params];
  6526. // if(json!=nil)
  6527. // {
  6528. //
  6529. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6530. // if([jsobj[@"result"] intValue]==2)
  6531. // {
  6532. // break;
  6533. // }
  6534. // }
  6535. // sleep(2);
  6536. // }
  6537. //
  6538. // }
  6539. // if(json==nil)
  6540. // return nil;
  6541. // NSError *error=nil;
  6542. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6543. // int result = [[jsobj valueForKey:@"result"] intValue];
  6544. //
  6545. // if (result==2)
  6546. // {
  6547. //
  6548. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6549. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  6550. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6551. //
  6552. // [appDelegate update_count_mark];
  6553. // }
  6554. // return jsobj;
  6555. }
  6556. +(void) request_move_wish2cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  6557. {
  6558. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6559. AppDelegate *appDelegate = nil;
  6560. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6561. if(appDelegate.user!=nil)
  6562. [params setValue:appDelegate.user forKey:@"user"];
  6563. if(appDelegate.contact_id!=nil)
  6564. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6565. if(appDelegate.password!=nil)
  6566. [params setValue:appDelegate.password forKey:@"password"];
  6567. if(appDelegate.order_code!=nil)
  6568. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6569. [params setValue:item_ids forKey:@"collectId"];
  6570. // [params setValue:editor forKey:@"editor"];
  6571. [params setValue:ScreenCodeWishList forKey:kScreenName];
  6572. [params setValue:@"Move To Cart" forKey:kAction];
  6573. if(appDelegate.offline_mode)
  6574. {
  6575. // [OLDataProvider offline_movewish2cart:params completionHandler:result];
  6576. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6577. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6578. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movewish2cart:params]] mutableCopy];
  6579. dispatch_async(dispatch_get_main_queue(), ^{
  6580. int result_code = [[resulti valueForKey:@"result"] intValue];
  6581. if (result_code==2)
  6582. {
  6583. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6584. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6585. [appDelegate update_count_mark];
  6586. }
  6587. result(resulti);
  6588. });
  6589. });
  6590. return;
  6591. }
  6592. [self request_interface:URL_WISH2CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6593. int result_code = [[resulti valueForKey:@"result"] intValue];
  6594. if (result_code==2)
  6595. {
  6596. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6597. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6598. [appDelegate update_count_mark];
  6599. }
  6600. result(resulti);
  6601. } retry:0];
  6602. //
  6603. // NSData *json = nil;
  6604. // if(appDelegate.offline_mode)
  6605. // {
  6606. // json = [OLDataProvider offline_movewish2cart:params];
  6607. // } else {
  6608. // if(![self IsNetworkAvailable])
  6609. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6610. //
  6611. // json=[self get_json:URL_WISH2CART parameters:params];
  6612. // }
  6613. //
  6614. // if(json!=nil)
  6615. // {
  6616. // NSError *error=nil;
  6617. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6618. // int result = [[jsobj valueForKey:@"result"] intValue];
  6619. //
  6620. // if (result==2)
  6621. // {
  6622. //
  6623. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6624. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6625. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6626. //
  6627. // [appDelegate update_count_mark];
  6628. // }
  6629. // return jsobj;
  6630. // }
  6631. // else
  6632. // return nil;
  6633. }
  6634. +(void) request_move_cart2wish:(NSString* ) item_ids completionHandler:(resultHandler)result
  6635. {
  6636. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6637. AppDelegate *appDelegate = nil;
  6638. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6639. if(appDelegate.user!=nil)
  6640. [params setValue:appDelegate.user forKey:@"user"];
  6641. if(appDelegate.contact_id!=nil)
  6642. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6643. if(appDelegate.password!=nil)
  6644. [params setValue:appDelegate.password forKey:@"password"];
  6645. if(appDelegate.order_code!=nil)
  6646. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6647. [params setValue:item_ids forKey:@"cartItemId"];
  6648. // [params setValue:editor forKey:@"editor"];
  6649. [params setValue:ScreenCodeCart forKey:kScreenName];
  6650. // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  6651. if(appDelegate.offline_mode)
  6652. {
  6653. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6654. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movecart2wish:params]] mutableCopy];
  6655. dispatch_async(dispatch_get_main_queue(), ^{
  6656. int result_code = [[resulti valueForKey:@"result"] intValue];
  6657. if (result_code==2)
  6658. {
  6659. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6660. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6661. [appDelegate update_count_mark];
  6662. }
  6663. result(resulti);
  6664. });
  6665. });
  6666. return;
  6667. }
  6668. [self request_interface:URL_CART2WISH parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6669. int result_code = [[resulti valueForKey:@"result"] intValue];
  6670. if (result_code==2)
  6671. {
  6672. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6673. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6674. [appDelegate update_count_mark];
  6675. }
  6676. result(resulti);
  6677. } retry:0];
  6678. //
  6679. // NSData* json = nil;
  6680. // if(appDelegate.offline_mode)
  6681. // {
  6682. // json= [OLDataProvider offline_movecart2wish:params];
  6683. // }
  6684. // else
  6685. // {
  6686. // if(![self IsNetworkAvailable])
  6687. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6688. //
  6689. // json=[self get_json:URL_CART2WISH parameters:params];
  6690. // }
  6691. // if(json!=nil)
  6692. // {
  6693. // NSError *error=nil;
  6694. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6695. // int result = [[jsobj valueForKey:@"result"] intValue];
  6696. //
  6697. // if (result==2)
  6698. // {
  6699. //
  6700. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6701. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6702. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6703. //
  6704. // [appDelegate update_count_mark];
  6705. // }
  6706. // return jsobj;
  6707. // }
  6708. // else
  6709. // return nil;
  6710. }
  6711. +(void)request_orderdetail:(NSMutableDictionary *) params completionHandler:(resultHandler)result
  6712. {
  6713. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6714. if (params == nil) {
  6715. params = [[NSMutableDictionary alloc] init];
  6716. }
  6717. AppDelegate *appDelegate = nil;
  6718. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6719. if(appDelegate.user!=nil)
  6720. [params setValue:appDelegate.user forKey:@"user"];
  6721. if(appDelegate.contact_id!=nil)
  6722. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6723. if(appDelegate.password!=nil)
  6724. [params setValue:appDelegate.password forKey:@"password"];
  6725. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  6726. [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  6727. if(appDelegate.offline_mode)
  6728. {
  6729. params[@"mode"]=appDelegate.mode;
  6730. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6731. NSData* json = [[OLDataProvider offline_orderdetail:params] mutableCopy];
  6732. dispatch_async(dispatch_get_main_queue(), ^{
  6733. result([[RAConvertor data2dict:json] mutableCopy]);
  6734. });
  6735. });
  6736. return;
  6737. }
  6738. NSString * uuid= [[NSUUID UUID] UUIDString];
  6739. params[@"resultSerial"]=uuid;
  6740. __block bool bbreak = false;
  6741. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6742. for(int i=0;i<150;i++)
  6743. {
  6744. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6745. // result_params[@"resultSerial"]=uuid;
  6746. if(bbreak)
  6747. break;
  6748. dispatch_async(dispatch_get_main_queue(), ^{
  6749. [self request_interface:URL_ORDER_DETAIL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6750. if([resulti[@"result"] intValue]==2||[resulti[@"result"] intValue]==8)
  6751. {
  6752. if(!bbreak)//此判断保证result只调用一次。
  6753. result(resulti);
  6754. bbreak=true;
  6755. }
  6756. } retry:3];
  6757. });
  6758. sleep(2);
  6759. }
  6760. });
  6761. //
  6762. // NSData* json=nil;
  6763. // if(appDelegate.offline_mode)
  6764. // {
  6765. // json= [OLDataProvider offline_orderdetail:params];
  6766. // }
  6767. // else
  6768. // {
  6769. // if(![self IsNetworkAvailable])
  6770. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6771. //
  6772. // NSError *error=nil;
  6773. //
  6774. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6775. // params[@"resultSerial"]=uuid;
  6776. //
  6777. // for(int i=0;i<150;i++)
  6778. // {
  6779. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6780. // // result_params[@"resultSerial"]=uuid;
  6781. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  6782. // if(json!=nil)
  6783. // {
  6784. //
  6785. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6786. // int resultCode = [jsobj[@"result"] intValue];
  6787. // if(resultCode==2 || resultCode == 8)
  6788. // {
  6789. // break;
  6790. // }
  6791. // }
  6792. // sleep(2);
  6793. // }
  6794. //
  6795. //
  6796. // }
  6797. // if(json==nil)
  6798. // return nil;
  6799. // NSError *error=nil;
  6800. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6801. // return jsobj;
  6802. }
  6803. //
  6804. //+(void)request_commit_order:(NSString*) order_code completionHandler:(resultHandler)result
  6805. //{
  6806. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6807. // AppDelegate *appDelegate = nil;
  6808. //
  6809. //
  6810. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6811. //
  6812. // if(appDelegate.user!=nil)
  6813. // [params setValue:appDelegate.user forKey:@"user"];
  6814. // if(appDelegate.contact_id!=nil)
  6815. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6816. // if(appDelegate.password!=nil)
  6817. // [params setValue:appDelegate.password forKey:@"password"];
  6818. // // NSString* ssaved = @"false";
  6819. // // if(saved)
  6820. // // ssaved=@"true";
  6821. // [params setValue:@"true" forKey:@"saved"];
  6822. // [params setValue:order_code forKey:@"orderCode"];
  6823. // // [params setValue:sourceid forKey:@"sourceid"];
  6824. // // [params setValue:editor forKey:@"editor"];
  6825. //
  6826. // [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  6827. //
  6828. //
  6829. // if(appDelegate.offline_mode)
  6830. // {
  6831. //
  6832. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6833. // NSMutableDictionary* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  6834. // dispatch_async(dispatch_get_main_queue(), ^{
  6835. // result(json);
  6836. // });
  6837. // });
  6838. //
  6839. // return;
  6840. // }
  6841. //
  6842. //
  6843. // [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6844. //
  6845. //// NSData* json = nil;
  6846. ////
  6847. //// if(appDelegate.offline_mode)
  6848. //// {
  6849. //// json= [OLDataProvider offline_submitorder:params];
  6850. //// }
  6851. //// else
  6852. //// {
  6853. //// if(![self IsNetworkAvailable])
  6854. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6855. ////
  6856. //// json=[self get_json:URL_COMMIT_ORDER parameters:params];
  6857. //// }
  6858. //// if(json!=nil)
  6859. //// {
  6860. //// NSError *error=nil;
  6861. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6862. //// return jsobj;
  6863. //// }
  6864. //// else
  6865. //// return nil;
  6866. //
  6867. //}
  6868. +(void)request_copy_order:(NSString*) order_code completionHandler:(resultHandler)result
  6869. {
  6870. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6871. AppDelegate *appDelegate = nil;
  6872. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6873. if(appDelegate.user!=nil)
  6874. [params setValue:appDelegate.user forKey:@"user"];
  6875. if(appDelegate.contact_id!=nil)
  6876. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6877. if(appDelegate.password!=nil)
  6878. [params setValue:appDelegate.password forKey:@"password"];
  6879. // NSString* ssaved = @"false";
  6880. // if(saved)
  6881. // ssaved=@"true";
  6882. // [params setValue:@"true" forKey:@"saved"];
  6883. [params setValue:order_code forKey:@"code"];
  6884. // [params setValue:sourceid forKey:@"sourceid"];
  6885. // [params setValue:editor forKey:@"editor"];
  6886. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  6887. if(appDelegate.offline_mode)
  6888. {
  6889. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6890. NSData* json = [[OLDataProvider offline_copyorder:params] mutableCopy];
  6891. dispatch_async(dispatch_get_main_queue(), ^{
  6892. result([[RAConvertor data2dict:json] mutableCopy]);
  6893. });
  6894. });
  6895. return;
  6896. }
  6897. [self request_interface:URL_COPY_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6898. // NSData* json=nil;
  6899. // if(appDelegate.offline_mode)
  6900. // {
  6901. // json= [OLDataProvider offline_copyorder:params];
  6902. // }
  6903. // else
  6904. // {
  6905. // if(![self IsNetworkAvailable])
  6906. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6907. //
  6908. // json=[self get_json:URL_COPY_ORDER parameters:params];
  6909. // }
  6910. // if(json!=nil)
  6911. // {
  6912. // NSError *error=nil;
  6913. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6914. // return jsobj;
  6915. // }
  6916. // else
  6917. // return nil;
  6918. }
  6919. //
  6920. //+ (void)request_fastdownload:(NSMutableDictionary *)params url:(NSString *)url completionHandler:(resultHandler)result
  6921. //{
  6922. //
  6923. // //#ifdef test_server
  6924. // // url=URL_REQUEST_RECORDS;
  6925. // // params[@"prefix"]=URL_REQUEST_RECORDS;
  6926. // //#endif
  6927. //
  6928. // [self request_file_fast:url parameters:params completionHandler:result];
  6929. //
  6930. //}
  6931. +(void) request_addto_portfolio:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6932. {
  6933. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6934. AppDelegate *appDelegate = nil;
  6935. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6936. if(appDelegate.user!=nil)
  6937. [params setValue:appDelegate.user forKey:@"user"];
  6938. if(appDelegate.contact_id!=nil)
  6939. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6940. if(appDelegate.password!=nil)
  6941. [params setValue:appDelegate.password forKey:@"password"];
  6942. [params setValue:item_id forKey:@"product_id"];
  6943. [params setObject:screenName forKey:kScreenName];
  6944. if(appDelegate.offline_mode)
  6945. {
  6946. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6947. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_add2Portfolio:params]] mutableCopy];
  6948. dispatch_async(dispatch_get_main_queue(), ^{
  6949. int result_code = [[resulti valueForKey:@"result"] intValue];
  6950. if (result_code==2)
  6951. {
  6952. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6953. [appDelegate update_count_mark];
  6954. }
  6955. result(resulti);
  6956. });
  6957. });
  6958. return;
  6959. }
  6960. [self request_interface:URL_ADD_TO_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6961. int result_code = [[resulti valueForKey:@"result"] intValue];
  6962. if (result_code==2)
  6963. {
  6964. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6965. [appDelegate update_count_mark];
  6966. }
  6967. result(resulti);
  6968. } retry:0];
  6969. //
  6970. // NSData* json = nil;
  6971. // if(appDelegate.offline_mode)
  6972. // {
  6973. // json = [OLDataProvider offline_add2Portfolio:params];
  6974. // } else {
  6975. // if(![self IsNetworkAvailable])
  6976. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6977. //
  6978. // json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  6979. // }
  6980. //
  6981. // if(json==nil)
  6982. // return nil;
  6983. // NSError *error=nil;
  6984. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6985. // int result = [[jsobj valueForKey:@"result"] intValue];
  6986. //
  6987. // if (result==2)
  6988. // {
  6989. //
  6990. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6991. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6992. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6993. //
  6994. // [appDelegate update_count_mark];
  6995. // }
  6996. // return jsobj;
  6997. }
  6998. +(void)request_addall_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  6999. {
  7000. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7001. AppDelegate *appDelegate = nil;
  7002. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7003. if(appDelegate.user!=nil)
  7004. [params setValue:appDelegate.user forKey:@"user"];
  7005. if(appDelegate.contact_id!=nil)
  7006. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7007. if(appDelegate.password!=nil)
  7008. [params setValue:appDelegate.password forKey:@"password"];
  7009. if(appDelegate.order_code!=nil)
  7010. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7011. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7012. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7013. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  7014. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7015. // [params setValue:filter forKey:@"filter"];
  7016. [params setValue:keywords forKey:@"keyword"];
  7017. [params setValue:addTo forKey:@"addTo"];
  7018. [params setValue:orderCode forKey:@"orderCode"];
  7019. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7020. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7021. if(matchfull)
  7022. [params setValue:@"true" forKey:@"exactMatch"];
  7023. else
  7024. [params setValue:@"false" forKey:@"exactMatch"];
  7025. [params setObject:ScreenCodeSearch forKey:kScreenName];
  7026. if ([addTo isEqualToString:@"cart"]) {
  7027. [params setObject:@"Add To Cart" forKey:kAction];
  7028. }
  7029. if(appDelegate.offline_mode)
  7030. {
  7031. if ([addTo isEqualToString:@"cart"])
  7032. {
  7033. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7034. }
  7035. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7036. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_searchaddall:params]] mutableCopy];
  7037. dispatch_async(dispatch_get_main_queue(), ^{
  7038. int result_code =[json[@"result"] intValue];
  7039. if (result_code==2||result_code==8)
  7040. {
  7041. if(json[@"cart_count"])
  7042. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7043. if(json[@"wish_count"])
  7044. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7045. if(json[@"portfolio_count"])
  7046. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7047. //
  7048. //
  7049. [appDelegate update_count_mark];
  7050. }
  7051. result(json);
  7052. });
  7053. });
  7054. return;
  7055. }
  7056. NSString * uuid= [[NSUUID UUID] UUIDString];
  7057. params[@"resultSerial"]=uuid;
  7058. __block bool bbreak = false;
  7059. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7060. for(int i=0;i<150;i++)
  7061. {
  7062. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7063. // result_params[@"resultSerial"]=uuid;
  7064. if(bbreak)
  7065. break;
  7066. dispatch_async(dispatch_get_main_queue(), ^{
  7067. [self request_interface:URL_SEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7068. if([resulti[@"result"] intValue]==2)
  7069. {
  7070. if(!bbreak)//此判断保证result只调用一次。
  7071. result(resulti);
  7072. bbreak=true;
  7073. }
  7074. } retry:3];
  7075. });
  7076. sleep(2);
  7077. }
  7078. });
  7079. //
  7080. //
  7081. // NSData* json=nil;
  7082. // if(appDelegate.offline_mode)
  7083. // {
  7084. // json=[OLDataProvider offline_searchaddall:params];
  7085. // }
  7086. // else
  7087. // {
  7088. // if(![self IsNetworkAvailable])
  7089. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7090. //
  7091. // NSError *error=nil;
  7092. //
  7093. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7094. // params[@"resultSerial"]=uuid;
  7095. //
  7096. // for(int i=0;i<150;i++)
  7097. // {
  7098. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7099. // // result_params[@"resultSerial"]=uuid;
  7100. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  7101. // if(json!=nil)
  7102. // {
  7103. //
  7104. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7105. // if([jsobj[@"result"] intValue]==2)
  7106. // {
  7107. // break;
  7108. // }
  7109. // }
  7110. // sleep(2);
  7111. // }
  7112. // }
  7113. // if(json==nil)
  7114. // return nil;
  7115. // NSError *error=nil;
  7116. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7117. // return jsobj;
  7118. }
  7119. +(void) request_addto_cart_byupc:(NSString* ) upc_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  7120. {
  7121. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7122. AppDelegate *appDelegate = nil;
  7123. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7124. if(appDelegate.user!=nil)
  7125. [params setValue:appDelegate.user forKey:@"user"];
  7126. if(appDelegate.contact_id!=nil)
  7127. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7128. if(appDelegate.password!=nil)
  7129. [params setValue:appDelegate.password forKey:@"password"];
  7130. if(appDelegate.order_code!=nil)
  7131. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7132. [params setValue:upc_code forKey:@"upc_code"];
  7133. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  7134. [params setObject:screenName forKey:kScreenName];
  7135. [params setObject:@"Add To Cart" forKey:kAction];
  7136. if (!upc_code) {
  7137. upc_code = @"";
  7138. }
  7139. [params setObject:@{@"UPCCode" : upc_code} forKey:kExtra];
  7140. params[@"search_upc"]=@true;
  7141. NSDictionary* customerinfo= appDelegate.customerInfo;
  7142. NSArray* keys=[customerinfo allKeys];
  7143. for(int i=0;i<keys.count;i++)
  7144. {
  7145. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7146. }
  7147. if(appDelegate.offline_mode)
  7148. {
  7149. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7150. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  7151. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7152. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyupc:params]] mutableCopy];
  7153. dispatch_async(dispatch_get_main_queue(), ^{
  7154. int result_code = [[json valueForKey:@"result"] intValue];
  7155. if (result_code==2||result_code==8)
  7156. {
  7157. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7158. [appDelegate update_count_mark];
  7159. }
  7160. result(json);
  7161. });
  7162. });
  7163. return;
  7164. }
  7165. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7166. int result_code = [[resulti valueForKey:@"result"] intValue];
  7167. if (result_code==2||result_code==8)
  7168. {
  7169. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7170. [appDelegate update_count_mark];
  7171. }
  7172. result(resulti);
  7173. } retry:0];
  7174. }
  7175. +(void) request_addto_cart_byname:(NSString* ) model_name withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  7176. {
  7177. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7178. AppDelegate *appDelegate = nil;
  7179. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7180. if(appDelegate.user!=nil)
  7181. [params setValue:appDelegate.user forKey:@"user"];
  7182. if(appDelegate.contact_id!=nil)
  7183. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7184. if(appDelegate.password!=nil)
  7185. [params setValue:appDelegate.password forKey:@"password"];
  7186. if(appDelegate.order_code!=nil)
  7187. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7188. [params setValue:model_name forKey:@"product_name"];
  7189. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  7190. [params setObject:screenName forKey:kScreenName];
  7191. [params setObject:@"Add To Cart" forKey:kAction];
  7192. if (!model_name) {
  7193. model_name = @"";
  7194. }
  7195. [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  7196. NSDictionary* customerinfo= appDelegate.customerInfo;
  7197. NSArray* keys=[customerinfo allKeys];
  7198. for(int i=0;i<keys.count;i++)
  7199. {
  7200. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7201. }
  7202. if(appDelegate.offline_mode)
  7203. {
  7204. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7205. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  7206. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7207. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyname:params]] mutableCopy];
  7208. dispatch_async(dispatch_get_main_queue(), ^{
  7209. int result_code = [[json valueForKey:@"result"] intValue];
  7210. if (result_code==2||result_code==8)
  7211. {
  7212. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7213. [appDelegate update_count_mark];
  7214. }
  7215. result(json);
  7216. });
  7217. });
  7218. return;
  7219. }
  7220. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7221. int result_code = [[resulti valueForKey:@"result"] intValue];
  7222. if (result_code==2||result_code==8)
  7223. {
  7224. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7225. [appDelegate update_count_mark];
  7226. }
  7227. result(resulti);
  7228. } retry:0];
  7229. // NSData* json=nil;
  7230. // if(appDelegate.offline_mode)
  7231. // {
  7232. // json= [OLDataProvider offline_add2cartbyname:params];
  7233. // }
  7234. // else
  7235. // {
  7236. // if(![self IsNetworkAvailable])
  7237. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7238. //
  7239. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  7240. // }
  7241. // if(json==nil)
  7242. // return nil;
  7243. // NSError *error=nil;
  7244. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7245. //
  7246. //
  7247. //
  7248. // int result = [[jsobj valueForKey:@"result"] intValue];
  7249. //
  7250. // if (result==2||result==8)
  7251. // {
  7252. //
  7253. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  7254. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  7255. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  7256. //
  7257. // [appDelegate update_count_mark];
  7258. // }
  7259. //
  7260. // return jsobj;
  7261. }
  7262. +(void) request_addto_wishlist:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  7263. {
  7264. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7265. AppDelegate *appDelegate = nil;
  7266. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7267. if(appDelegate.user!=nil)
  7268. [params setValue:appDelegate.user forKey:@"user"];
  7269. if(appDelegate.contact_id!=nil)
  7270. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7271. if(appDelegate.password!=nil)
  7272. [params setValue:appDelegate.password forKey:@"password"];
  7273. [params setValue:item_id forKey:@"product_id"];
  7274. [params setObject:screenName forKey:kScreenName];
  7275. if(appDelegate.offline_mode)
  7276. {
  7277. // [OLDataProvider offline_add2wishlist:params completionHandler:result];
  7278. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7279. NSMutableDictionary* resulti = [[OLDataProvider offline_add2wishlist:params] mutableCopy];
  7280. dispatch_async(dispatch_get_main_queue(), ^{
  7281. int result_code = [[resulti valueForKey:@"result"] intValue];
  7282. if (result_code==2||result_code==8)
  7283. {
  7284. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7285. [appDelegate update_count_mark];
  7286. }
  7287. result(resulti);
  7288. });
  7289. });
  7290. return;
  7291. }
  7292. [self request_interface:URL_ADD_TO_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7293. int result_code = [[resulti valueForKey:@"result"] intValue];
  7294. if (result_code==2||result_code==8)
  7295. {
  7296. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7297. [appDelegate update_count_mark];
  7298. }
  7299. result(resulti);
  7300. } retry:0];
  7301. // if(appDelegate.offline_mode)
  7302. // {
  7303. // return [OLDataProvider offline_add2wishlist:params];
  7304. // }
  7305. // if(![self IsNetworkAvailable])
  7306. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7307. //
  7308. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  7309. // if(json==nil)
  7310. // return nil;
  7311. // NSError *error=nil;
  7312. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7313. // int result = [[jsobj valueForKey:@"result"] intValue];
  7314. //
  7315. // if (result==2)
  7316. // {
  7317. //
  7318. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  7319. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  7320. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  7321. //
  7322. // [appDelegate update_count_mark];
  7323. // }
  7324. // return jsobj;
  7325. }
  7326. +(void)request_addall_itemsearch:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  7327. {
  7328. // for debug
  7329. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  7330. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7331. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7332. AppDelegate *appDelegate = nil;
  7333. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7334. if(appDelegate.user!=nil)
  7335. [params setValue:appDelegate.user forKey:@"user"];
  7336. if(appDelegate.contact_id!=nil)
  7337. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7338. if(appDelegate.password!=nil)
  7339. [params setValue:appDelegate.password forKey:@"password"];
  7340. if(appDelegate.order_code!=nil)
  7341. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7342. [params setValue:addTo forKey:@"addTo"];
  7343. [params setValue:orderCode forKey:@"orderCode"];
  7344. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7345. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7346. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  7347. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7348. // [params setValue:filter forKey:@"filter"];
  7349. [params setValue:covertype forKey:@"covertype"];
  7350. [params setValue:ctgid forKey:@"ctgId"];
  7351. [params setValue:modelname forKey:@"modelName"];
  7352. [params setValue:modeldescrip forKey:@"modelDescription"];
  7353. [params setValue:alert forKey:@"alert"];
  7354. [params setValue:qty forKey:@"sold_by_qty"];
  7355. [params setValue:available forKey:@"available"];
  7356. [params setValue:price forKey:@"price"];
  7357. [params setValue:bestseller forKey:@"bestseller"];
  7358. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7359. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7360. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  7361. if ([addTo isEqualToString:@"cart"]) {
  7362. [params setObject:@"Add To Cart" forKey:kAction];
  7363. }
  7364. if(appDelegate.offline_mode)
  7365. {
  7366. if ([addTo isEqualToString:@"cart"])
  7367. {
  7368. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7369. }
  7370. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7371. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_itemsearchaddall:params]] mutableCopy];
  7372. dispatch_async(dispatch_get_main_queue(), ^{
  7373. int result_code =[json[@"result"] intValue];
  7374. if (result_code==2||result_code==8)
  7375. {
  7376. if(json[@"cart_count"])
  7377. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7378. if(json[@"wish_count"])
  7379. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7380. if(json[@"portfolio_count"])
  7381. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7382. //
  7383. //
  7384. [appDelegate update_count_mark];
  7385. }
  7386. result(json);
  7387. });
  7388. });
  7389. return;
  7390. }
  7391. NSString * uuid= [[NSUUID UUID] UUIDString];
  7392. params[@"resultSerial"]=uuid;
  7393. __block bool bbreak = false;
  7394. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7395. for(int i=0;i<150;i++)
  7396. {
  7397. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7398. // result_params[@"resultSerial"]=uuid;
  7399. if(bbreak)
  7400. break;
  7401. dispatch_async(dispatch_get_main_queue(), ^{
  7402. [self request_interface:URL_ITEMSEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7403. if([resulti[@"result"] intValue]==2)
  7404. {
  7405. if(!bbreak)//此判断保证result只调用一次。
  7406. result(resulti);
  7407. bbreak=true;
  7408. }
  7409. } retry:3];
  7410. });
  7411. sleep(2);
  7412. }
  7413. });
  7414. //
  7415. // NSData* json = nil;
  7416. //
  7417. // if(appDelegate.offline_mode)
  7418. // {
  7419. // json= [OLDataProvider offline_itemsearchaddall:params];
  7420. // }
  7421. // else
  7422. // {
  7423. // if(![self IsNetworkAvailable])
  7424. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7425. // NSError *error=nil;
  7426. //
  7427. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7428. // params[@"resultSerial"]=uuid;
  7429. //
  7430. // for(int i=0;i<150;i++)
  7431. // {
  7432. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7433. // // result_params[@"resultSerial"]=uuid;
  7434. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  7435. // if(json!=nil)
  7436. // {
  7437. //
  7438. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7439. // if([jsobj[@"result"] intValue]==2)
  7440. // {
  7441. // break;
  7442. // }
  7443. // }
  7444. // sleep(2);
  7445. // }
  7446. // }
  7447. // if(json==nil)
  7448. // return nil;
  7449. // NSError *error=nil;
  7450. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7451. // return jsobj;
  7452. }
  7453. +(void)request_addall_category: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword offset:(long) offset limit:(long) limit alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  7454. {
  7455. AppDelegate *appDelegate = nil;
  7456. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7457. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7458. if(appDelegate.user!=nil)
  7459. [params setValue:appDelegate.user forKey:@"user"];
  7460. if(appDelegate.contact_id!=nil)
  7461. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7462. if(appDelegate.password!=nil)
  7463. [params setValue:appDelegate.password forKey:@"password"];
  7464. if(appDelegate.order_code!=nil)
  7465. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7466. [params setValue:addTo forKey:@"addTo"];
  7467. [params setValue:orderCode forKey:@"orderCode"];
  7468. [params setValue:alert forKey:@"alert"];
  7469. [params setValue:qty forKey:@"sold_by_qty"];
  7470. [params setValue:available forKey:@"available"];
  7471. [params setValue:price forKey:@"price"];
  7472. [params setValue:bestseller forKey:@"bestseller"];
  7473. [params setValue:modelname forKey:@"modelName"];
  7474. [params setValue:modeldescrip forKey:@"modelDescription"];
  7475. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7476. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7477. [params setValue:category forKey:@"category"];
  7478. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7479. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7480. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7481. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7482. [params setValue:filter forKey:@"filter"];
  7483. [params setValue:keyword forKey:@"keyword"];
  7484. [params setObject:ScreenCodeCategory forKey:kScreenName];
  7485. if ([addTo isEqualToString:@"cart"]) {
  7486. [params setObject:@"Add To Cart" forKey:kAction];
  7487. }
  7488. if(appDelegate.offline_mode)
  7489. {
  7490. if ([addTo isEqualToString:@"cart"])
  7491. {
  7492. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7493. }
  7494. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7495. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_categoryaddall:params]] mutableCopy];
  7496. dispatch_async(dispatch_get_main_queue(), ^{
  7497. int result_code =[json[@"result"] intValue];
  7498. if (result_code==2||result_code==8)
  7499. {
  7500. if(json[@"cart_count"])
  7501. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7502. if(json[@"wish_count"])
  7503. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7504. if(json[@"portfolio_count"])
  7505. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7506. //
  7507. //
  7508. [appDelegate update_count_mark];
  7509. }
  7510. result(json);
  7511. });
  7512. });
  7513. return;
  7514. }
  7515. NSString * uuid= [[NSUUID UUID] UUIDString];
  7516. params[@"resultSerial"]=uuid;
  7517. __block bool bbreak = false;
  7518. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7519. for(int i=0;i<150;i++)
  7520. {
  7521. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7522. // result_params[@"resultSerial"]=uuid;
  7523. if(bbreak)
  7524. break;
  7525. dispatch_async(dispatch_get_main_queue(), ^{
  7526. [self request_interface:URL_CATEGORYADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7527. if([resulti[@"result"] intValue]==2|| [resulti[@"result"] intValue] == 8)
  7528. {
  7529. if(!bbreak)//此判断保证result只调用一次。
  7530. {
  7531. int result_code =[resulti[@"result"] intValue];
  7532. if (result_code==2||result_code==8)
  7533. {
  7534. if(resulti[@"cart_count"])
  7535. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7536. if(resulti[@"wish_count"])
  7537. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7538. if(resulti[@"portfolio_count"])
  7539. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  7540. //
  7541. //
  7542. [appDelegate update_count_mark];
  7543. }
  7544. result(resulti);
  7545. }
  7546. bbreak=true;
  7547. }
  7548. } retry:3];
  7549. });
  7550. sleep(2);
  7551. }
  7552. });
  7553. //
  7554. // NSData* json= nil;
  7555. //
  7556. // if(appDelegate.offline_mode)
  7557. // {
  7558. // json= [OLDataProvider offline_categoryaddall:params];
  7559. // }
  7560. // else
  7561. // {
  7562. // if(![self IsNetworkAvailable])
  7563. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7564. //
  7565. //
  7566. // NSError *error=nil;
  7567. //
  7568. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7569. // params[@"resultSerial"]=uuid;
  7570. //
  7571. // for(int i=0;i<150;i++)
  7572. // {
  7573. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7574. //// result_params[@"resultSerial"]=uuid;
  7575. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  7576. // if(json!=nil)
  7577. // {
  7578. //
  7579. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7580. // int resultInt = [jsobj[@"result"] intValue];
  7581. // if(resultInt == 2 || resultInt == 8)
  7582. // {
  7583. // break;
  7584. // }
  7585. // }
  7586. // sleep(2);
  7587. // }
  7588. //
  7589. //
  7590. //
  7591. // }
  7592. // if(json==nil)
  7593. // return nil;
  7594. // NSError *error=nil;
  7595. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7596. // return jsobj;
  7597. }
  7598. +(void)request_save_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7599. {
  7600. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7601. AppDelegate *appDelegate = nil;
  7602. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7603. if(appDelegate.user!=nil)
  7604. [params setValue:appDelegate.user forKey:@"user"];
  7605. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  7606. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7607. // else
  7608. if(appDelegate.contact_id!=nil)
  7609. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7610. if(appDelegate.password!=nil)
  7611. [params setValue:appDelegate.password forKey:@"password"];
  7612. if(appDelegate.order_code!=nil)
  7613. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7614. // NSDictionary* customerinfo=nil;
  7615. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  7616. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7617. // else
  7618. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7619. //
  7620. // appDelegate.customerInfo;
  7621. // NSArray* keys=[customerinfo allKeys];
  7622. // for(int i=0;i<keys.count;i++)
  7623. // {
  7624. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7625. // }
  7626. // [params setValue:sourceid forKey:@"sourceid"];
  7627. // [params setValue:editor forKey:@"editor"];
  7628. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  7629. if(appDelegate.offline_mode)
  7630. {
  7631. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7632. NSData* json = [[OLDataProvider offline_saveorder:params] mutableCopy];
  7633. dispatch_async(dispatch_get_main_queue(), ^{
  7634. result([[RAConvertor data2dict:json] mutableCopy]);
  7635. });
  7636. });
  7637. return;
  7638. }
  7639. [self request_interface:URL_SAVE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  7640. //
  7641. // NSData* json=nil;
  7642. //
  7643. // if(appDelegate.offline_mode)
  7644. // {
  7645. // json= [OLDataProvider offline_saveorder:params];
  7646. // }
  7647. // else
  7648. // {
  7649. // if(![self IsNetworkAvailable])
  7650. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7651. //
  7652. // json=[self get_json:URL_SAVE_ORDER parameters:params];
  7653. // }
  7654. // if(json!=nil)
  7655. // {
  7656. // NSError *error=nil;
  7657. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7658. // NSString *so = [jsobj valueForKey:@"so#"];
  7659. // if (so) {
  7660. // [appDelegate SetSo:so];
  7661. // }
  7662. // return jsobj;
  7663. // }
  7664. // else
  7665. // return nil;
  7666. }
  7667. +(void) request_update_cartqty:(NSString*) cart_id value:(int) value completionHandler:(resultHandler)result
  7668. {
  7669. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7670. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  7671. #ifdef SCANNER_ORDER
  7672. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7673. {
  7674. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7675. //
  7676. //
  7677. // [appDelegate update_count_mark];
  7678. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7679. int count = [section[@"count"] intValue];
  7680. for(int i=0;i<count;i++)
  7681. {
  7682. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7683. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7684. {
  7685. item[@"count"] =@(value);
  7686. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7687. break;
  7688. }
  7689. }
  7690. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7691. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7692. result(RASingleton.sharedInstance.scan_cart);
  7693. [OLDataProvider updateScanOrder:appDelegate.order_code];
  7694. return;
  7695. }
  7696. #endif
  7697. if(appDelegate.user!=nil)
  7698. [params setValue:appDelegate.user forKey:@"user"];
  7699. if(appDelegate.contact_id!=nil)
  7700. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7701. if(appDelegate.password!=nil)
  7702. [params setValue:appDelegate.password forKey:@"password"];
  7703. [params setValue:cart_id forKey:@"cartitem_id"];
  7704. [params setObject:ScreenCodeCart forKey:kScreenName];
  7705. [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  7706. if(appDelegate.offline_mode)
  7707. {
  7708. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7709. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7710. NSData* json = [[OLDataProvider offline_cartsetqty:params] mutableCopy];
  7711. dispatch_async(dispatch_get_main_queue(), ^{
  7712. result([[RAConvertor data2dict:json] mutableCopy]);
  7713. });
  7714. });
  7715. return;
  7716. }
  7717. [self request_interface:URL_CART_INCRESEMENT parameters:params err_record_url:nil completionHandler:result retry:0];
  7718. //
  7719. // NSData* json=nil;
  7720. // if(appDelegate.offline_mode)
  7721. // {
  7722. // json= [OLDataProvider offline_cartsetqty:params];
  7723. // }
  7724. // else
  7725. // {
  7726. // if(![self IsNetworkAvailable])
  7727. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7728. //
  7729. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  7730. // }
  7731. // if(json==nil)
  7732. // return nil;
  7733. // NSError *error=nil;
  7734. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7735. // return jsobj;
  7736. }
  7737. +(void) request_update_cartgeneralnote:(NSString*) order_code notes:(NSString*) notes completionHandler:(resultHandler)result
  7738. {
  7739. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7740. AppDelegate *appDelegate = nil;
  7741. #ifdef SCANNER_ORDER
  7742. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7743. {
  7744. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7745. //
  7746. //
  7747. // [appDelegate update_count_mark];
  7748. RASingleton.sharedInstance.scan_cart[@"general_note"] = notes;
  7749. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7750. result(RASingleton.sharedInstance.scan_cart);
  7751. return;
  7752. }
  7753. #endif
  7754. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7755. if(appDelegate.user!=nil)
  7756. [params setValue:appDelegate.user forKey:@"user"];
  7757. if(appDelegate.contact_id!=nil)
  7758. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7759. if(appDelegate.password!=nil)
  7760. [params setValue:appDelegate.password forKey:@"password"];
  7761. [params setValue:order_code forKey:@"orderCode"];
  7762. [params setObject:ScreenCodeCart forKey:kScreenName];
  7763. if(notes.length==0)
  7764. notes=@"";
  7765. [params setValue:notes forKey:@"comments"];
  7766. if(appDelegate.offline_mode)
  7767. {
  7768. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7769. NSData* json = [[OLDataProvider offline_updategnotes:params] mutableCopy];
  7770. dispatch_async(dispatch_get_main_queue(), ^{
  7771. result([[RAConvertor data2dict:json] mutableCopy]);
  7772. });
  7773. });
  7774. return;
  7775. }
  7776. [self request_interface:URL_CART_GENERAL_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7777. //
  7778. // NSData* json=nil;
  7779. // if(appDelegate.offline_mode)
  7780. // {
  7781. // json= [OLDataProvider offline_updategnotes:params];
  7782. // }
  7783. // else
  7784. // {
  7785. // if(![self IsNetworkAvailable])
  7786. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7787. //
  7788. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  7789. // }
  7790. // if(json==nil)
  7791. // return nil;
  7792. // NSError *error=nil;
  7793. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7794. // return jsobj;
  7795. }
  7796. +(void) request_update_cartitemnote:(NSString*) cart_id notes:(NSString*) notes completionHandler:(resultHandler)result
  7797. {
  7798. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7799. AppDelegate *appDelegate = nil;
  7800. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7801. #ifdef SCANNER_ORDER
  7802. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7803. {
  7804. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7805. //
  7806. //
  7807. // [appDelegate update_count_mark];
  7808. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7809. int count = [section[@"count"] intValue];
  7810. for(int i=0;i<count;i++)
  7811. {
  7812. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7813. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7814. {
  7815. item[@"note"] =notes;
  7816. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7817. break;
  7818. }
  7819. }
  7820. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7821. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7822. result(RASingleton.sharedInstance.scan_cart);
  7823. return;
  7824. }
  7825. #endif
  7826. if(appDelegate.user!=nil)
  7827. [params setValue:appDelegate.user forKey:@"user"];
  7828. if(appDelegate.contact_id!=nil)
  7829. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7830. if(appDelegate.password!=nil)
  7831. [params setValue:appDelegate.password forKey:@"password"];
  7832. [params setValue:cart_id forKey:@"cartitem_id"];
  7833. [params setObject:ScreenCodeCart forKey:kScreenName];
  7834. if(notes.length==0)
  7835. notes=@"";
  7836. [params setValue:notes forKey:@"notes"];
  7837. if(appDelegate.offline_mode)
  7838. {
  7839. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7840. NSData* json = [[OLDataProvider offline_cartsetlnotes:params] mutableCopy];
  7841. dispatch_async(dispatch_get_main_queue(), ^{
  7842. result([[RAConvertor data2dict:json] mutableCopy]);
  7843. });
  7844. });
  7845. return;
  7846. }
  7847. [self request_interface:URL_CART_ITEM_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7848. //
  7849. // NSData* json=nil;
  7850. // if(appDelegate.offline_mode)
  7851. // {
  7852. // json= [OLDataProvider offline_cartsetlnotes:params];
  7853. // }
  7854. // else
  7855. // {
  7856. // if(![self IsNetworkAvailable])
  7857. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7858. //
  7859. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  7860. // }
  7861. // if(json==nil)
  7862. // return nil;
  7863. // NSError *error=nil;
  7864. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7865. // return jsobj;
  7866. }
  7867. + (void)request_update_npd_shop_price_type:(NSInteger)priceType completionHandler:(resultHandler)result
  7868. {
  7869. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7870. AppDelegate *appDelegate = nil;
  7871. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7872. if(appDelegate.user!=nil)
  7873. [dic setValue:appDelegate.user forKey:@"user"];
  7874. if(appDelegate.password!=nil)
  7875. [dic setValue:appDelegate.password forKey:@"password"];
  7876. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  7877. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  7878. if(appDelegate.offline_mode)
  7879. {
  7880. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7881. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7882. dispatch_async(dispatch_get_main_queue(), ^{
  7883. result(json);
  7884. });
  7885. });
  7886. return;
  7887. }
  7888. [self request_interface:URL_SET_PRICE_TYPE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7889. //
  7890. // NSData* json=nil;
  7891. // if(appDelegate.offline_mode)
  7892. // {
  7893. // return [OLDataProvider offline_notimpl];
  7894. // }
  7895. // else
  7896. // {
  7897. // if(![self IsNetworkAvailable])
  7898. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7899. //
  7900. // json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  7901. // }
  7902. // if(json!=nil)
  7903. // {
  7904. // NSError *error=nil;
  7905. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7906. //
  7907. //
  7908. // return jsobj;
  7909. // }
  7910. //
  7911. //
  7912. // return nil;
  7913. }
  7914. + (void)request_npd_shop_givenprice:(resultHandler)result
  7915. {
  7916. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7917. AppDelegate *appDelegate = nil;
  7918. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7919. if(appDelegate.user!=nil)
  7920. [dic setValue:appDelegate.user forKey:@"user"];
  7921. if(appDelegate.password!=nil)
  7922. [dic setValue:appDelegate.password forKey:@"password"];
  7923. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  7924. if(appDelegate.offline_mode)
  7925. {
  7926. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7927. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7928. dispatch_async(dispatch_get_main_queue(), ^{
  7929. result(json);
  7930. });
  7931. });
  7932. return;
  7933. }
  7934. [self request_interface:URL_GET_CIVEN_PRICE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7935. //
  7936. // NSData* json=nil;
  7937. // if(appDelegate.offline_mode)
  7938. // {
  7939. // return [OLDataProvider offline_notimpl];
  7940. // }
  7941. // else
  7942. // {
  7943. // if(![self IsNetworkAvailable])
  7944. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7945. //
  7946. // json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  7947. // }
  7948. // if(json!=nil)
  7949. // {
  7950. // NSError *error=nil;
  7951. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7952. //
  7953. //
  7954. // return jsobj;
  7955. // }
  7956. //
  7957. //
  7958. // return nil;
  7959. }
  7960. + (void)request_update_npd_shop_givenprice:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  7961. {
  7962. AppDelegate *appDelegate = nil;
  7963. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7964. if(appDelegate.user!=nil)
  7965. [params setValue:appDelegate.user forKey:@"user"];
  7966. if(appDelegate.password!=nil)
  7967. [params setValue:appDelegate.password forKey:@"password"];
  7968. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  7969. if(appDelegate.offline_mode)
  7970. {
  7971. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7972. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7973. dispatch_async(dispatch_get_main_queue(), ^{
  7974. result(json);
  7975. });
  7976. });
  7977. return;
  7978. }
  7979. [self request_interface:URL_SET_GIVEN_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  7980. //
  7981. // NSData* json=nil;
  7982. // if(appDelegate.offline_mode)
  7983. // {
  7984. // return [OLDataProvider offline_notimpl];
  7985. // }
  7986. // else
  7987. // {
  7988. // if(![self IsNetworkAvailable])
  7989. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7990. //
  7991. // json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  7992. // }
  7993. // if(json!=nil)
  7994. // {
  7995. // NSError *error=nil;
  7996. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7997. //
  7998. //
  7999. // return jsobj;
  8000. // }
  8001. //
  8002. //
  8003. // return nil;
  8004. }
  8005. +(void) request_create_portfolio:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8006. {
  8007. AppDelegate *appDelegate = nil;
  8008. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8009. if(appDelegate.offline_mode)
  8010. {
  8011. params[@"contact_id"]=params[@"contactId"];
  8012. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8013. NSData* json = [[OLDataProvider offline_direct_save_TearSheet:params] mutableCopy];
  8014. dispatch_async(dispatch_get_main_queue(), ^{
  8015. result([[RAConvertor data2dict:json] mutableCopy]);
  8016. });
  8017. });
  8018. return;
  8019. }
  8020. //
  8021. // if(appDelegate.offline_mode)
  8022. // {
  8023. //
  8024. //
  8025. // NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  8026. // if(json==nil)
  8027. // return nil;
  8028. // NSError *error=nil;
  8029. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8030. //
  8031. // return jsobj[@"pdf_path"];
  8032. // }
  8033. // else
  8034. // {
  8035. // return nil;
  8036. // }
  8037. }
  8038. +(void)request_save_portfoliodirectly:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8039. {
  8040. NSMutableDictionary* off_params = [params mutableCopy];
  8041. AppDelegate *appDelegate = nil;
  8042. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8043. if(appDelegate.user!=nil)
  8044. [params setValue:appDelegate.user forKey:@"user"];
  8045. if(appDelegate.contact_id!=nil)
  8046. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8047. if(appDelegate.password!=nil)
  8048. params[@"off_params"]=[RAConvertor dict2string:off_params];
  8049. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  8050. [params setValue:appDelegate.password forKey:@"password"];
  8051. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  8052. if(appDelegate.offline_mode)
  8053. {
  8054. params[@"contact_id"]=appDelegate.contact_id;
  8055. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8056. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_direct_save_TearSheet:params]] mutableCopy];
  8057. dispatch_async(dispatch_get_main_queue(), ^{
  8058. result(json);
  8059. });
  8060. });
  8061. return;
  8062. }
  8063. NSString * uuid= [[NSUUID UUID] UUIDString];
  8064. params[@"resultSerial"]=uuid;
  8065. __block bool bbreak = false;
  8066. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8067. for(int i=0;i<150;i++)
  8068. {
  8069. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8070. // result_params[@"resultSerial"]=uuid;
  8071. if(bbreak)
  8072. break;
  8073. dispatch_async(dispatch_get_main_queue(), ^{
  8074. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8075. if([resulti[@"result"] intValue]==2)
  8076. {
  8077. if(!bbreak)//此判断保证result只调用一次。
  8078. result(resulti);
  8079. bbreak=true;
  8080. }
  8081. } retry:3];
  8082. });
  8083. sleep(2);
  8084. }
  8085. });
  8086. //
  8087. //
  8088. // NSData* json= nil;
  8089. //
  8090. // if(appDelegate.offline_mode)
  8091. // {
  8092. // json = [OLDataProvider offline_direct_save_TearSheet:params];
  8093. // }
  8094. // else
  8095. // {
  8096. // if(![self IsNetworkAvailable])
  8097. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8098. //
  8099. // json=[self get_json:URL_REQUEST_DM parameters:params];
  8100. //
  8101. // NSError *error=nil;
  8102. //
  8103. // NSString * uuid= [[NSUUID UUID] UUIDString];
  8104. // params[@"resultSerial"]=uuid;
  8105. //
  8106. // for(int i=0;i<150;i++)
  8107. // {
  8108. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8109. // // result_params[@"resultSerial"]=uuid;
  8110. // json=[self get_json:URL_REQUEST_DM parameters:params];
  8111. // if(json!=nil)
  8112. // {
  8113. //
  8114. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8115. // if([jsobj[@"result"] intValue]==2)
  8116. // {
  8117. // break;
  8118. // }
  8119. // }
  8120. // sleep(5);
  8121. // }
  8122. //
  8123. // }
  8124. // if(json==nil)
  8125. // return nil;
  8126. // NSError *error=nil;
  8127. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8128. // return jsobj;
  8129. }
  8130. +(void)request_save_portfolio:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  8131. {
  8132. AppDelegate *appDelegate = nil;
  8133. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8134. if(appDelegate.user!=nil)
  8135. [params setValue:appDelegate.user forKey:@"user"];
  8136. if(appDelegate.contact_id!=nil)
  8137. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8138. NSMutableDictionary* off_params = [params mutableCopy];;
  8139. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  8140. params[@"off_params"]=[RAConvertor dict2string:off_params];
  8141. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8142. if(appDelegate.password!=nil)
  8143. [params setValue:appDelegate.password forKey:@"password"];
  8144. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  8145. if(appDelegate.offline_mode)
  8146. {
  8147. params[@"contact_id"]=appDelegate.contact_id;
  8148. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8149. NSData* json = [[OLDataProvider offline_save_TearSheet:params] mutableCopy];
  8150. dispatch_async(dispatch_get_main_queue(), ^{
  8151. result([[RAConvertor data2dict:json] mutableCopy]);
  8152. });
  8153. });
  8154. return;
  8155. }
  8156. [self request_interface:URL_SAVE_DM parameters:params err_record_url:nil completionHandler:result retry:0];
  8157. //
  8158. // NSData* json = nil;
  8159. // if(appDelegate.offline_mode)
  8160. // {
  8161. // json = [OLDataProvider offline_save_TearSheet:params];
  8162. // } else {
  8163. // if(![self IsNetworkAvailable])
  8164. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8165. //
  8166. // json=[self get_json:URL_SAVE_DM parameters:params];
  8167. // }
  8168. // if(json==nil)
  8169. // return nil;
  8170. // NSError *error=nil;
  8171. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8172. // return jsobj;
  8173. }
  8174. +(void)request_portfoliopreview:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8175. {
  8176. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8177. AppDelegate *appDelegate = nil;
  8178. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8179. if(appDelegate.user!=nil)
  8180. [params setValue:appDelegate.user forKey:@"user"];
  8181. if(appDelegate.contact_id!=nil)
  8182. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8183. if(appDelegate.password!=nil)
  8184. [params setValue:appDelegate.password forKey:@"password"];
  8185. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  8186. // [params setValue:request_url forKey:@"pdfUrl"];
  8187. if(appDelegate.offline_mode)
  8188. {
  8189. params[@"contact_id"]=params[@"contactId"];
  8190. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8191. NSData* json = [[OLDataProvider offline_request_tearsheet:params] mutableCopy];
  8192. dispatch_async(dispatch_get_main_queue(), ^{
  8193. result([[RAConvertor data2dict:json] mutableCopy]);
  8194. });
  8195. });
  8196. return;
  8197. }
  8198. NSString * uuid= [[NSUUID UUID] UUIDString];
  8199. params[@"resultSerial"]=uuid;
  8200. __block bool bbreak = false;
  8201. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8202. for(int i=0;i<150;i++)
  8203. {
  8204. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8205. // result_params[@"resultSerial"]=uuid;
  8206. if(bbreak)
  8207. break;
  8208. dispatch_async(dispatch_get_main_queue(), ^{
  8209. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8210. if([resulti[@"result"] intValue]==2)
  8211. {
  8212. if(!bbreak)//此判断保证result只调用一次。
  8213. result(resulti);
  8214. bbreak=true;
  8215. }
  8216. } retry:3];
  8217. });
  8218. sleep(5);
  8219. }
  8220. });
  8221. //
  8222. // NSData* json= nil;
  8223. // if(appDelegate.offline_mode)
  8224. // {
  8225. // json= [OLDataProvider offline_request_tearsheet:params];
  8226. // }
  8227. // else
  8228. // {
  8229. // if(![self IsNetworkAvailable])
  8230. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8231. //
  8232. // NSError *error=nil;
  8233. //
  8234. // NSString * uuid= [[NSUUID UUID] UUIDString];
  8235. // params[@"resultSerial"]=uuid;
  8236. //
  8237. // for(int i=0;i<150;i++)
  8238. // {
  8239. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8240. // // result_params[@"resultSerial"]=uuid;
  8241. // json=[self get_json:URL_REQUEST_DM parameters:params];
  8242. // if(json!=nil)
  8243. // {
  8244. //
  8245. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8246. // if([jsobj[@"result"] intValue]==2)
  8247. // {
  8248. // break;
  8249. // }
  8250. // }
  8251. // sleep(5);
  8252. // }
  8253. // }
  8254. // if(json==nil)
  8255. // return nil;
  8256. // NSError *error=nil;
  8257. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8258. // return jsobj;
  8259. }
  8260. +(void)request_itemsearch:(long ) offset limit :(long)limit covertype:(NSString* ) covertype ctgid:(NSString*)ctgid modelname:(NSString*) modelname modeldescrip:(NSString*)modeldescrip alert:(NSString*)alert qty:(NSString*)qty available:(NSString*)available price:(NSString*)price bestseller:(NSString*)bestseller completionHandler:(resultHandler)result
  8261. {
  8262. // for debug
  8263. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  8264. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8265. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8266. AppDelegate *appDelegate = nil;
  8267. //some UI methods ej
  8268. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8269. if(appDelegate.user!=nil)
  8270. [params setValue:appDelegate.user forKey:@"user"];
  8271. if(appDelegate.contact_id!=nil)
  8272. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8273. if(appDelegate.password!=nil)
  8274. [params setValue:appDelegate.password forKey:@"password"];
  8275. if(appDelegate.order_code!=nil)
  8276. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8277. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  8278. if (alert && qty && available && price && bestseller) {
  8279. [params setObject:@"Filter" forKey:kAction];
  8280. }
  8281. if ([RASingleton sharedInstance].homeItemClick) {
  8282. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  8283. [RASingleton sharedInstance].homeItemClick = NO;
  8284. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  8285. [RASingleton sharedInstance].homeClickedItemName = nil;
  8286. [params setObject:extra forKey:kExtra];
  8287. }
  8288. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  8289. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  8290. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  8291. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  8292. // [params setValue:filter forKey:@"filter"];
  8293. [params setValue:covertype forKey:@"covertype"];
  8294. [params setValue:ctgid forKey:@"ctgId"];
  8295. [params setValue:modelname forKey:@"modelName"];
  8296. [params setValue:modeldescrip forKey:@"modelDescription"];
  8297. [params setValue:alert forKey:@"alert"];
  8298. [params setValue:qty forKey:@"sold_by_qty"];
  8299. [params setValue:available forKey:@"available"];
  8300. [params setValue:price forKey:@"price"];
  8301. [params setValue:bestseller forKey:@"bestseller"];
  8302. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  8303. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  8304. if(appDelegate.offline_mode)
  8305. {
  8306. // [OLDataProvider offline_itemsearch:params completionHandler:result];
  8307. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8308. NSMutableDictionary* json = [[OLDataProvider offline_itemsearch:params] mutableCopy];
  8309. dispatch_async(dispatch_get_main_queue(), ^{
  8310. result(json);
  8311. });
  8312. });
  8313. return;
  8314. }
  8315. [self request_interface:URL_ITEM_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  8316. // if(appDelegate.offline_mode)
  8317. // {
  8318. // return [OLDataProvider offline_itemsearch:params];
  8319. // }
  8320. // if(![self IsNetworkAvailable])
  8321. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8322. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  8323. // if(json==nil)
  8324. // return nil;
  8325. // NSError *error=nil;
  8326. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8327. // return jsobj;
  8328. }
  8329. +(void)request_modelqty: (NSString*) fashionId completionHandler:(resultHandler)result
  8330. {
  8331. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8332. AppDelegate *appDelegate = nil;
  8333. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8334. if(appDelegate.user!=nil)
  8335. [params setValue:appDelegate.user forKey:@"user"];
  8336. if(appDelegate.contact_id!=nil)
  8337. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8338. if(appDelegate.password!=nil)
  8339. [params setValue:appDelegate.password forKey:@"password"];
  8340. [params setValue:fashionId forKey:@"fashionId"];
  8341. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  8342. if(appDelegate.offline_mode)
  8343. {
  8344. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8345. NSData* json = [[OLDataProvider offline_model_qty:params] mutableCopy];
  8346. dispatch_async(dispatch_get_main_queue(), ^{
  8347. result([[RAConvertor data2dict:json] mutableCopy]);
  8348. });
  8349. });
  8350. return;
  8351. }
  8352. [self request_interface:URL_REQUEST_MODEL_QTY parameters:params err_record_url:nil completionHandler:result retry:0];
  8353. // NSData* json = nil;
  8354. // if(appDelegate.offline_mode)
  8355. // {
  8356. // json = [OLDataProvider offline_model_qty:params];
  8357. // } else {
  8358. // if(![self IsNetworkAvailable])
  8359. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8360. //
  8361. // json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  8362. // }
  8363. // if(json==nil)
  8364. // return nil;
  8365. // NSError *error=nil;
  8366. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8367. // return jsobj;
  8368. }
  8369. +(void) request_update_portfolio_price:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes completionHandler:(resultHandler)result
  8370. {
  8371. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8372. AppDelegate *appDelegate = nil;
  8373. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8374. if(appDelegate.user!=nil)
  8375. [params setValue:appDelegate.user forKey:@"user"];
  8376. if(appDelegate.contact_id!=nil)
  8377. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8378. if(appDelegate.password!=nil)
  8379. [params setValue:appDelegate.password forKey:@"password"];
  8380. [params setValue:watchlist_id forKey:@"item_id"];
  8381. // if(notes.length>0)
  8382. // [params setValue:notes forKey:@"notes"];
  8383. if(notes)
  8384. [params setValue:notes forKey:@"notes"];
  8385. if(price != -MAXFLOAT)
  8386. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  8387. if (discount != -MAXFLOAT)
  8388. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  8389. if(qty_p != -MAXFLOAT)
  8390. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  8391. if(qty != -INT32_MAX)
  8392. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  8393. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  8394. // NSData* json = nil;
  8395. if(appDelegate.offline_mode)
  8396. {
  8397. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8398. NSData* json = [[OLDataProvider offline_editPortfolio:params] mutableCopy];
  8399. dispatch_async(dispatch_get_main_queue(), ^{
  8400. result([[RAConvertor data2dict:json] mutableCopy]);
  8401. });
  8402. });
  8403. return;
  8404. }
  8405. [self request_interface:URL_PORTFOLIO_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8406. //
  8407. // if(appDelegate.offline_mode)
  8408. // {
  8409. // json = [OLDataProvider offline_editPortfolio:params];
  8410. // } else {
  8411. // if(![self IsNetworkAvailable])
  8412. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8413. //
  8414. // json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  8415. // }
  8416. // if(json==nil)
  8417. // return nil;
  8418. // NSError *error=nil;
  8419. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8420. // return jsobj;
  8421. }
  8422. +(void)request_add_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8423. {
  8424. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8425. AppDelegate *appDelegate = nil;
  8426. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8427. if(appDelegate.user!=nil)
  8428. [params setValue:appDelegate.user forKey:@"user"];
  8429. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  8430. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8431. // else
  8432. if(appDelegate.contact_id!=nil)
  8433. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8434. if(appDelegate.password!=nil)
  8435. [params setValue:appDelegate.password forKey:@"password"];
  8436. // NSDictionary* customerinfo=nil;
  8437. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  8438. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8439. // else
  8440. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8441. //
  8442. // appDelegate.customerInfo;
  8443. // NSArray* keys=[customerinfo allKeys];
  8444. // for(int i=0;i<keys.count;i++)
  8445. // {
  8446. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8447. // }
  8448. // [params setValue:sourceid forKey:@"sourceid"];
  8449. // [params setValue:editor forKey:@"editor"];
  8450. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  8451. if(appDelegate.offline_mode)
  8452. {
  8453. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8454. NSData* json = [[OLDataProvider offline_saveNewContact:params] mutableCopy];
  8455. dispatch_async(dispatch_get_main_queue(), ^{
  8456. result([[RAConvertor data2dict:json] mutableCopy]);
  8457. });
  8458. });
  8459. return;
  8460. }
  8461. [self request_interface:URL_CUSTOMER_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  8462. //
  8463. // NSData* json=nil;
  8464. // if(appDelegate.offline_mode)
  8465. // {
  8466. // json= [OLDataProvider offline_saveNewContact:params];
  8467. // }
  8468. // else
  8469. // {
  8470. // if(![self IsNetworkAvailable])
  8471. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8472. //
  8473. // json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  8474. // }
  8475. //
  8476. // if(json!=nil)
  8477. // {
  8478. // NSError *error=nil;
  8479. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8480. // return jsobj;
  8481. // }
  8482. // else
  8483. // return nil;
  8484. }
  8485. +(void)request_update_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8486. {
  8487. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8488. AppDelegate *appDelegate = nil;
  8489. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8490. if(appDelegate.user!=nil)
  8491. [params setValue:appDelegate.user forKey:@"user"];
  8492. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  8493. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8494. // else
  8495. if(appDelegate.contact_id!=nil)
  8496. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8497. if(appDelegate.password!=nil)
  8498. [params setValue:appDelegate.password forKey:@"password"];
  8499. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8500. if(appDelegate.offline_mode)
  8501. {
  8502. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8503. NSData* json = [[OLDataProvider offline_saveContact:params] mutableCopy];
  8504. dispatch_async(dispatch_get_main_queue(), ^{
  8505. result([[RAConvertor data2dict:json] mutableCopy]);
  8506. });
  8507. });
  8508. return;
  8509. }
  8510. [self request_interface:URL_CUSTOMER_UPDATE parameters:params err_record_url:nil completionHandler:result retry:0];
  8511. //
  8512. // NSData* json=nil;
  8513. // if(appDelegate.offline_mode)
  8514. // {
  8515. // json= [OLDataProvider offline_saveContact:params];
  8516. // }
  8517. // else
  8518. // {
  8519. // if(![self IsNetworkAvailable])
  8520. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8521. //
  8522. // json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  8523. // }
  8524. //
  8525. // if(json!=nil)
  8526. // {
  8527. // NSError *error=nil;
  8528. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8529. // return jsobj;
  8530. // }
  8531. // else
  8532. // return nil;
  8533. }
  8534. +(void)request_delete_order:(NSString*) order_id completionHandler:(resultHandler)result
  8535. {
  8536. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8537. AppDelegate *appDelegate = nil;
  8538. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8539. if(appDelegate.user!=nil)
  8540. [params setValue:appDelegate.user forKey:@"user"];
  8541. // if(appDelegate.contact_id!=nil)
  8542. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8543. if(appDelegate.password!=nil)
  8544. [params setValue:appDelegate.password forKey:@"password"];
  8545. [params setValue:order_id forKey:@"orderId"];
  8546. // [params setValue:sourceid forKey:@"sourceid"];
  8547. // [params setValue:editor forKey:@"editor"];
  8548. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8549. if(appDelegate.offline_mode)
  8550. {
  8551. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8552. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8553. dispatch_async(dispatch_get_main_queue(), ^{
  8554. result(json);
  8555. });
  8556. });
  8557. return;
  8558. }
  8559. [self request_interface:URL_DELETE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8560. //
  8561. // if(appDelegate.offline_mode)
  8562. // {
  8563. // return [OLDataProvider offline_notimpl];
  8564. // }
  8565. // if(![self IsNetworkAvailable])
  8566. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8567. //
  8568. // NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  8569. // if(json!=nil)
  8570. // {
  8571. // NSError *error=nil;
  8572. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8573. //
  8574. //
  8575. // return jsobj;
  8576. // }
  8577. // else
  8578. // return nil;
  8579. }
  8580. +(void)request_cancel_order:(NSString*) order_id order_code:(NSString*) order_code completionHandler:(resultHandler)result
  8581. {
  8582. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8583. AppDelegate *appDelegate = nil;
  8584. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8585. if(appDelegate.user!=nil)
  8586. [params setValue:appDelegate.user forKey:@"user"];
  8587. // if(appDelegate.contact_id!=nil)
  8588. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8589. if(appDelegate.password!=nil)
  8590. [params setValue:appDelegate.password forKey:@"password"];
  8591. [params setValue:order_id forKey:@"orderId"];
  8592. [params setValue:order_code forKey:@"orderCode"];
  8593. // [params setValue:sourceid forKey:@"sourceid"];
  8594. // [params setValue:editor forKey:@"editor"];
  8595. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8596. if(appDelegate.offline_mode)
  8597. {
  8598. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8599. NSData* json = [[OLDataProvider offline_cancelorder:params] mutableCopy];
  8600. dispatch_async(dispatch_get_main_queue(), ^{
  8601. result([[RAConvertor data2dict:json] mutableCopy]);
  8602. });
  8603. });
  8604. return;
  8605. }
  8606. [self request_interface:URL_CANCEL_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8607. //
  8608. // NSData* json=nil;
  8609. // if(appDelegate.offline_mode)
  8610. // {
  8611. // json=[OLDataProvider offline_cancelorder:params];
  8612. // }
  8613. // else
  8614. // {
  8615. // if(![self IsNetworkAvailable])
  8616. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8617. // json=[self get_json:URL_CANCEL_ORDER parameters:params];
  8618. // }
  8619. // if(json!=nil)
  8620. // {
  8621. // NSError *error=nil;
  8622. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8623. //
  8624. //
  8625. // return jsobj;
  8626. // }
  8627. // else
  8628. // return nil;
  8629. }
  8630. +(void)request_release_order:(NSString*) order_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  8631. {
  8632. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8633. AppDelegate *appDelegate = nil;
  8634. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8635. if(appDelegate.user!=nil)
  8636. [params setValue:appDelegate.user forKey:@"user"];
  8637. // if(appDelegate.contact_id!=nil)
  8638. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8639. if(appDelegate.password!=nil)
  8640. [params setValue:appDelegate.password forKey:@"password"];
  8641. [params setValue:order_code forKey:@"orderCode"];
  8642. // [params setValue:sourceid forKey:@"sourceid"];
  8643. // [params setValue:editor forKey:@"editor"];
  8644. if (screenName) {
  8645. [params setValue:screenName forKey:kScreenName];
  8646. }
  8647. if(appDelegate.offline_mode)
  8648. {
  8649. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8650. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_resetorder:params]] mutableCopy];
  8651. dispatch_async(dispatch_get_main_queue(), ^{
  8652. if([[resulti valueForKey:@"result"]intValue]==2)
  8653. { [appDelegate SetSo:nil];
  8654. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8655. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8656. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8657. [appDelegate update_count_mark];
  8658. dispatch_async(dispatch_get_main_queue(), ^{
  8659. result(resulti);
  8660. });
  8661. }
  8662. });
  8663. });
  8664. return;
  8665. }
  8666. [self request_interface:URL_RELEASE_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8667. if([[resulti valueForKey:@"result"]intValue]==2)
  8668. { [appDelegate SetSo:nil];
  8669. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8670. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8671. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8672. [appDelegate update_count_mark];
  8673. dispatch_async(dispatch_get_main_queue(), ^{
  8674. result(resulti);
  8675. });
  8676. }
  8677. } retry:0];
  8678. //
  8679. // NSData* json=nil;
  8680. // if(appDelegate.offline_mode)
  8681. // {
  8682. // json= [OLDataProvider offline_resetorder:params];
  8683. // }
  8684. // else
  8685. // {
  8686. // if(![self IsNetworkAvailable])
  8687. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8688. //
  8689. // json=[self get_json:URL_RELEASE_ORDER parameters:params];
  8690. // }
  8691. // if(json!=nil)
  8692. // {
  8693. // NSError *error=nil;
  8694. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8695. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8696. // { [appDelegate SetSo:nil];
  8697. //
  8698. //
  8699. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8700. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8701. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8702. //
  8703. // [appDelegate update_count_mark];
  8704. // }
  8705. // return jsobj;
  8706. // }
  8707. // else
  8708. // return nil;
  8709. }
  8710. +(void)request_update_order_signature:(NSString*) order_code path:(NSString*)path completionHandler:(resultHandler)result
  8711. {
  8712. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8713. AppDelegate *appDelegate = nil;
  8714. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8715. if(appDelegate.user!=nil)
  8716. [params setValue:appDelegate.user forKey:@"user"];
  8717. if(appDelegate.contact_id!=nil)
  8718. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8719. if(appDelegate.password!=nil)
  8720. [params setValue:appDelegate.password forKey:@"password"];
  8721. // NSString* ssaved = @"false";
  8722. // if(saved)
  8723. // ssaved=@"true";
  8724. // [params setValue:@"true" forKey:@"saved"];
  8725. [params setValue:order_code forKey:@"orderCode"];
  8726. [params setValue:path forKey:@"picpath"];
  8727. // [params setValue:sourceid forKey:@"sourceid"];
  8728. // [params setValue:editor forKey:@"editor"];
  8729. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  8730. if(appDelegate.offline_mode)
  8731. {
  8732. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8733. NSData* json = [[OLDataProvider offline_signorder:params] mutableCopy];
  8734. dispatch_async(dispatch_get_main_queue(), ^{
  8735. result([[RAConvertor data2dict:json] mutableCopy]);
  8736. });
  8737. });
  8738. return;
  8739. }
  8740. [self request_interface:URL_SIGN_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8741. //
  8742. // NSData* json=nil;
  8743. // if(appDelegate.offline_mode)
  8744. // {
  8745. // json= [OLDataProvider offline_signorder:params];
  8746. // }
  8747. // else
  8748. // {
  8749. // if(![self IsNetworkAvailable])
  8750. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8751. //
  8752. // json=[self get_json:URL_SIGN_ORDER parameters:params];
  8753. // }
  8754. // if(json!=nil)
  8755. // {
  8756. // NSError *error=nil;
  8757. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8758. // return jsobj;
  8759. // }
  8760. // else
  8761. // return nil;
  8762. }
  8763. +(void) request_scan_bulkdiscount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8764. {
  8765. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  8766. //
  8767. //
  8768. // [appDelegate update_count_mark];
  8769. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  8770. int count = [section[@"count"] intValue];
  8771. for(int i=0;i<count;i++)
  8772. {
  8773. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  8774. if ([item[@"special_price"] boolValue]||[item[@"net_price"] boolValue])
  8775. continue;
  8776. int item_count = [item[@"count"] intValue];
  8777. float price=[item[@"unit_price"] floatValue] ;
  8778. item[@"discount"] =@(discount);
  8779. item[@"subtotal_price"] =@(price*item_count);
  8780. if(discount>0)
  8781. item[@"note"] =[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  8782. else
  8783. item[@"note"] =@"";
  8784. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  8785. }
  8786. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  8787. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  8788. result(RASingleton.sharedInstance.scan_cart);
  8789. AppDelegate *appDelegate = nil;
  8790. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8791. [OLDataProvider updateScanOrder:appDelegate.order_code];
  8792. return;
  8793. }
  8794. +(void) request_update_cart_modelprice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8795. {
  8796. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8797. AppDelegate *appDelegate = nil;
  8798. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8799. #ifdef SCANNER_ORDER
  8800. // return;
  8801. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  8802. {
  8803. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  8804. //
  8805. //
  8806. // [appDelegate update_count_mark];
  8807. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  8808. int count = [section[@"count"] intValue];
  8809. for(int i=0;i<count;i++)
  8810. {
  8811. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  8812. if([item[@"cart_item_id"] isEqualToString:cart_id])
  8813. {
  8814. int item_count = [item[@"count"] intValue];
  8815. item[@"unit_price"] =@(price);
  8816. item[@"discount"] =@(discount);
  8817. item[@"subtotal_price"] =@(price*item_count);
  8818. if(discount>0)
  8819. item[@"note"] =[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  8820. else
  8821. item[@"note"] =@"";
  8822. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  8823. break;
  8824. }
  8825. }
  8826. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  8827. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  8828. result(RASingleton.sharedInstance.scan_cart);
  8829. [OLDataProvider updateScanOrder:appDelegate.order_code];
  8830. return;
  8831. }
  8832. #endif
  8833. if(appDelegate.user!=nil)
  8834. [params setValue:appDelegate.user forKey:@"user"];
  8835. if(appDelegate.contact_id!=nil)
  8836. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8837. if(appDelegate.password!=nil)
  8838. [params setValue:appDelegate.password forKey:@"password"];
  8839. [params setValue:cart_id forKey:@"cartitem_id"];
  8840. [params setValue:notes forKey:@"item_note"];
  8841. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  8842. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  8843. [params setObject:ScreenCodeCart forKey:kScreenName];
  8844. if(appDelegate.offline_mode)
  8845. {
  8846. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8847. NSData* json = [[OLDataProvider offline_cartsetprice:params] mutableCopy];
  8848. dispatch_async(dispatch_get_main_queue(), ^{
  8849. result([[RAConvertor data2dict:json] mutableCopy]);
  8850. });
  8851. });
  8852. return;
  8853. }
  8854. [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8855. //
  8856. // NSData* json= nil;
  8857. // if(appDelegate.offline_mode)
  8858. // {
  8859. // json=[OLDataProvider offline_cartsetprice:params];
  8860. // }
  8861. // else
  8862. // {
  8863. // if(![self IsNetworkAvailable])
  8864. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8865. //
  8866. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8867. // }
  8868. // if(json==nil)
  8869. // return nil;
  8870. // NSError *error=nil;
  8871. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8872. // return jsobj;
  8873. }
  8874. +(void) request_addto_cart:(NSString* ) item_id count:(int) count name:(NSString *)name completionHandler:(resultHandler)result
  8875. {
  8876. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8877. AppDelegate *appDelegate = nil;
  8878. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8879. if(appDelegate.user!=nil)
  8880. [params setValue:appDelegate.user forKey:@"user"];
  8881. if(appDelegate.contact_id!=nil)
  8882. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8883. if(appDelegate.password!=nil)
  8884. [params setValue:appDelegate.password forKey:@"password"];
  8885. if(appDelegate.order_code!=nil)
  8886. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8887. [params setValue:item_id forKey:@"product_id"];
  8888. [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  8889. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  8890. [params setObject:@"Add To Cart" forKey:kAction];
  8891. if (name) {
  8892. NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  8893. [params setObject:extra forKey:kExtra];
  8894. }
  8895. NSDictionary* customerinfo= appDelegate.customerInfo;
  8896. NSArray* keys=[customerinfo allKeys];
  8897. for(int i=0;i<keys.count;i++)
  8898. {
  8899. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8900. }
  8901. if(appDelegate.offline_mode)
  8902. {
  8903. // [OLDataProvider offline_add2cart:params completionHandler:^(NSMutableDictionary *resulti) {
  8904. // NSMutableDictionary* json = resulti;
  8905. // if ([json[@"result"] intValue]==2)
  8906. // {
  8907. // appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  8908. //
  8909. // [appDelegate update_count_mark];
  8910. // }
  8911. // result(json);
  8912. // }];
  8913. params[@"can_create_backorder"]= @(appDelegate.can_create_backorder);
  8914. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8915. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cart:params]] mutableCopy];
  8916. dispatch_async(dispatch_get_main_queue(), ^{
  8917. if ([json[@"result"] intValue]==2)
  8918. {
  8919. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  8920. [appDelegate update_count_mark];
  8921. }
  8922. result(json);
  8923. });
  8924. });
  8925. return;
  8926. }
  8927. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8928. if ([resulti[@"result"] intValue]==2)
  8929. {
  8930. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8931. [appDelegate update_count_mark];
  8932. }
  8933. result(resulti);
  8934. } retry:0];
  8935. //
  8936. // NSData* json=nil;
  8937. // if(appDelegate.offline_mode)
  8938. // {
  8939. // json=[OLDataProvider offline_add2cart:params];
  8940. // }
  8941. // else
  8942. // {
  8943. // if(![self IsNetworkAvailable])
  8944. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8945. //
  8946. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  8947. // }
  8948. // if(json==nil)
  8949. // return nil;
  8950. // NSError *error=nil;
  8951. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8952. //
  8953. //
  8954. //
  8955. // int result = [[jsobj valueForKey:@"result"] intValue];
  8956. //
  8957. // if (result==2)
  8958. // {
  8959. //
  8960. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8961. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8962. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8963. //
  8964. // [appDelegate update_count_mark];
  8965. // }
  8966. //
  8967. // return jsobj;
  8968. }
  8969. //+(void) request_update_cart_modelfree:(NSString*) cart_id isfree:(bool) isfree completionHandler:(resultHandler)result
  8970. //{
  8971. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8972. // AppDelegate *appDelegate = nil;
  8973. //
  8974. //
  8975. //
  8976. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8977. //
  8978. // if(appDelegate.user!=nil)
  8979. // [params setValue:appDelegate.user forKey:@"user"];
  8980. // if(appDelegate.contact_id!=nil)
  8981. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8982. // if(appDelegate.password!=nil)
  8983. // [params setValue:appDelegate.password forKey:@"password"];
  8984. //
  8985. // [params setValue:cart_id forKey:@"cartitem_id"];
  8986. //
  8987. // [params setObject:ScreenCodeCart forKey:kScreenName];
  8988. //
  8989. // NSString* free=nil;
  8990. //
  8991. // if(isfree)
  8992. // free=@"true";
  8993. // else
  8994. // free=@"false";
  8995. //
  8996. // [params setValue:free forKey:@"free_giveaway"];
  8997. //
  8998. //
  8999. // if(appDelegate.offline_mode)
  9000. // {
  9001. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9002. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9003. // dispatch_async(dispatch_get_main_queue(), ^{
  9004. // result(json);
  9005. // });
  9006. // });
  9007. //
  9008. // return;
  9009. //
  9010. // }
  9011. // [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  9012. //
  9013. ////
  9014. ////
  9015. //// if(appDelegate.offline_mode)
  9016. //// {
  9017. //// return [OLDataProvider offline_notimpl];
  9018. //// }
  9019. //// if(![self IsNetworkAvailable])
  9020. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9021. ////
  9022. //// NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  9023. //// if(json==nil)
  9024. //// return nil;
  9025. //// NSError *error=nil;
  9026. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9027. //// return jsobj;
  9028. //}
  9029. +(void)request_retrieve_password: (NSString*) user email:(NSString*) email completionHandler:(resultHandler)result
  9030. {
  9031. AppDelegate *appDelegate = nil;
  9032. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9033. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9034. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  9035. // if(appDelegate.user!=nil)
  9036. // [params setValue:appDelegate.user forKey:@"user"];
  9037. // if(appDelegate.contact_id!=nil)
  9038. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9039. // if(appDelegate.password!=nil)
  9040. // [params setValue:appDelegate.password forKey:@"password"];
  9041. [params setValue:user forKey:@"username"];
  9042. [params setValue:email forKey:@"email"];
  9043. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  9044. if(appDelegate.offline_mode)
  9045. {
  9046. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9047. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9048. dispatch_async(dispatch_get_main_queue(), ^{
  9049. result(json);
  9050. });
  9051. });
  9052. return;
  9053. }
  9054. #ifdef SCANNER_ORDER
  9055. params[@"site_name"]=[RADataProvider getSiteName];
  9056. params[@"_method"]=@"forgotPasswordOfflineOrderUser";
  9057. params[@"user"]=user;
  9058. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_RETRIEVE_PASS];
  9059. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  9060. #else
  9061. [self request_interface:URL_RETRIEVE_PASS parameters:params err_record_url:nil completionHandler:result retry:0];
  9062. #endif
  9063. //
  9064. //
  9065. // if(![self IsNetworkAvailable])
  9066. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9067. //
  9068. // NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  9069. // if(json==nil)
  9070. // return nil;
  9071. // NSError *error=nil;
  9072. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9073. // return jsobj;
  9074. }
  9075. +(void)request_update_ordercustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info completionHandler:(resultHandler)result
  9076. {
  9077. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9078. AppDelegate *appDelegate = nil;
  9079. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9080. if(appDelegate.user!=nil)
  9081. [info setValue:appDelegate.user forKey:@"user"];
  9082. // if(appDelegate.contact_id!=nil)
  9083. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9084. if(appDelegate.password!=nil)
  9085. [info setValue:appDelegate.password forKey:@"password"];
  9086. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  9087. [info setValue:order_code forKey:@"orderCode"];
  9088. // [params setValue:sourceid forKey:@"sourceid"];
  9089. // [params setValue:editor forKey:@"editor"];
  9090. if(appDelegate.offline_mode)
  9091. {
  9092. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9093. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9094. dispatch_async(dispatch_get_main_queue(), ^{
  9095. result(json);
  9096. });
  9097. });
  9098. return;
  9099. }
  9100. [self request_interface:URL_UPDATE_ORDERCUSTOMER parameters:info err_record_url:nil completionHandler:result retry:0];
  9101. // if(appDelegate.offline_mode)
  9102. // {
  9103. // return [OLDataProvider offline_notimpl];
  9104. // }
  9105. // if(![self IsNetworkAvailable])
  9106. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9107. //
  9108. // NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  9109. // if(json!=nil)
  9110. // {
  9111. // NSError *error=nil;
  9112. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9113. // return jsobj;
  9114. // }
  9115. // else
  9116. // return nil;
  9117. }
  9118. +(void)request_update_customer_img: (NSString*) contactid img_url:(NSString*) url completionHandler:(resultHandler)result
  9119. {
  9120. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9121. AppDelegate *appDelegate = nil;
  9122. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9123. if(appDelegate.user!=nil)
  9124. [params setValue:appDelegate.user forKey:@"user"];
  9125. // if(appDelegate.contact_id!=nil)
  9126. if(appDelegate.password!=nil)
  9127. [params setValue:appDelegate.password forKey:@"password"];
  9128. [params setValue:contactid forKey:@"contactId"];
  9129. [params setValue:url forKey:@"business_card"];
  9130. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  9131. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  9132. if(appDelegate.offline_mode)
  9133. {
  9134. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9135. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9136. dispatch_async(dispatch_get_main_queue(), ^{
  9137. result(json);
  9138. });
  9139. });
  9140. return;
  9141. }
  9142. [self request_interface:URL_UPDATE_CUSTOMER_BCARD parameters:params err_record_url:nil completionHandler:result retry:0];
  9143. // if(appDelegate.offline_mode)
  9144. // {
  9145. // return [OLDataProvider offline_notimpl];
  9146. // }
  9147. // if(![self IsNetworkAvailable])
  9148. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9149. //
  9150. // NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  9151. // if(json==nil)
  9152. // return nil;
  9153. // NSError *error=nil;
  9154. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9155. // return jsobj;
  9156. }
  9157. +(void)request_commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url completionHandler:(resultHandler)result
  9158. {
  9159. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9160. AppDelegate *appDelegate = nil;
  9161. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9162. if(appDelegate.user!=nil)
  9163. [params setValue:appDelegate.user forKey:@"user"];
  9164. if(appDelegate.contact_id!=nil)
  9165. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9166. if(appDelegate.password!=nil)
  9167. [params setValue:appDelegate.password forKey:@"password"];
  9168. // if(appDelegate.order_code!=nil)
  9169. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  9170. // NSDictionary* customerinfo= appDelegate.customerInfo;
  9171. //
  9172. // NSArray* keys=[customerinfo allKeys];
  9173. // for(int i=0;i<keys.count;i++)
  9174. // {
  9175. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  9176. // }
  9177. //
  9178. // [params setValue:sourceid forKey:@"sourceid"];
  9179. // [params setValue:editor forKey:@"editor"];
  9180. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  9181. if(appDelegate.offline_mode)
  9182. {
  9183. params[@"offline_Command"]=url;
  9184. [OLDataProvider offline_commoneditor_partialrefresh:params completionHandler:result];
  9185. //
  9186. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9187. // NSMutableDictionary* json = [[OLDataProvider offline_commoneditor_partialrefresh:params] mutableCopy];
  9188. // dispatch_async(dispatch_get_main_queue(), ^{
  9189. // result(json);
  9190. // });
  9191. // });
  9192. return;
  9193. }
  9194. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  9195. //
  9196. // if(appDelegate.offline_mode)
  9197. // {
  9198. // params[@"offline_Command"]=url;
  9199. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  9200. // }
  9201. //
  9202. // if(![self IsNetworkAvailable])
  9203. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9204. //
  9205. // NSData* json=[self get_json:url parameters:params];
  9206. // if(json!=nil)
  9207. // {
  9208. // NSError *error=nil;
  9209. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9210. // if([[jsobj valueForKey:@"result"]intValue]==2)
  9211. // [appDelegate SetSo:nil];
  9212. //
  9213. //
  9214. // return jsobj;
  9215. // }
  9216. // else
  9217. // return nil;
  9218. }
  9219. +(void)request_add_address:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  9220. {
  9221. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9222. AppDelegate *appDelegate = nil;
  9223. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9224. if(appDelegate.user!=nil)
  9225. [params setValue:appDelegate.user forKey:@"user"];
  9226. if(appDelegate.contact_id!=nil)
  9227. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9228. if(appDelegate.password!=nil)
  9229. [params setValue:appDelegate.password forKey:@"password"];
  9230. // [params setValue:sourceid forKey:@"sourceid"];
  9231. // [params setValue:editor forKey:@"editor"];
  9232. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  9233. if(appDelegate.offline_mode)
  9234. {
  9235. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9236. NSData* json = [[OLDataProvider offline_saveaddr:params] mutableCopy];
  9237. dispatch_async(dispatch_get_main_queue(), ^{
  9238. result([[RAConvertor data2dict:json] mutableCopy]);
  9239. });
  9240. });
  9241. return;
  9242. }
  9243. [self request_interface:URL_ADDRESS_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  9244. //
  9245. // NSData* json=nil;
  9246. //
  9247. // if(appDelegate.offline_mode)
  9248. // {
  9249. // json= [OLDataProvider offline_saveaddr:params];
  9250. // }
  9251. // else
  9252. // {
  9253. // if(![self IsNetworkAvailable])
  9254. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9255. //
  9256. // json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  9257. // }
  9258. // if(json!=nil)
  9259. // {
  9260. // NSError *error=nil;
  9261. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9262. // return jsobj;
  9263. // }
  9264. // else
  9265. // return nil;
  9266. }
  9267. +(void)request_commit_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  9268. {
  9269. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9270. AppDelegate *appDelegate = nil;
  9271. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9272. if(appDelegate.user!=nil)
  9273. [params setValue:appDelegate.user forKey:@"user"];
  9274. if(appDelegate.contact_id!=nil)
  9275. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9276. if(appDelegate.password!=nil)
  9277. [params setValue:appDelegate.password forKey:@"password"];
  9278. if(appDelegate.order_code!=nil)
  9279. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  9280. // NSDictionary* customerinfo= appDelegate.customerInfo;
  9281. //
  9282. // NSArray* keys=[customerinfo allKeys];
  9283. // for(int i=0;i<keys.count;i++)
  9284. // {
  9285. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  9286. // }
  9287. //
  9288. // [params setValue:sourceid forKey:@"sourceid"];
  9289. // [params setValue:editor forKey:@"editor"];
  9290. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  9291. if(appDelegate.offline_mode)
  9292. {
  9293. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9294. NSData* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  9295. dispatch_async(dispatch_get_main_queue(), ^{
  9296. result([[RAConvertor data2dict:json] mutableCopy]);
  9297. });
  9298. });
  9299. return;
  9300. }
  9301. [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  9302. //
  9303. // NSData* json=nil;
  9304. // if(appDelegate.offline_mode)
  9305. // {
  9306. // json=[OLDataProvider offline_submitorder:params];
  9307. // }
  9308. // else
  9309. // {
  9310. // if(![self IsNetworkAvailable])
  9311. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9312. //
  9313. // json=[self get_json:URL_COMMIT_ORDER parameters:params];
  9314. // }
  9315. // if(json!=nil)
  9316. // {
  9317. // NSError *error=nil;
  9318. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9319. // if([[jsobj valueForKey:@"result"]intValue]==2)
  9320. // [appDelegate SetSo:nil];
  9321. //
  9322. //
  9323. // return jsobj;
  9324. // }
  9325. // else
  9326. // return nil;
  9327. }
  9328. +(void) request_new_offline_ticket:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid completionHandler:(resultHandler)result
  9329. {
  9330. // if(![self IsNetworkAvailable])
  9331. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9332. //
  9333. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9334. AppDelegate *appDelegate = nil;
  9335. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9336. if(appDelegate.user!=nil)
  9337. [params setValue:appDelegate.user forKey:@"user"];
  9338. // if(appDelegate.contact_id!=nil)
  9339. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9340. if(appDelegate.password!=nil)
  9341. [params setValue:appDelegate.password forKey:@"password"];
  9342. [params setValue:ver forKey:@"ver"];
  9343. [params setValue:vid forKey:@"vid"];
  9344. if(buseinternaladdress)
  9345. [params setValue:@"true" forKey:@"internal_address"];
  9346. else
  9347. [params setValue:@"false" forKey:@"internal_address"];
  9348. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  9349. // 无论当前是离线还是在线状态,都可以进行同步;
  9350. // if(appDelegate.offline_mode)
  9351. // {
  9352. //
  9353. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9354. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9355. // dispatch_async(dispatch_get_main_queue(), ^{
  9356. // result(json);
  9357. // });
  9358. // });
  9359. //
  9360. // return;
  9361. //
  9362. // }
  9363. [self request_interface:URL_CHECK_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  9364. //
  9365. // NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  9366. // if(json==nil)
  9367. // return nil;
  9368. // NSError *error=nil;
  9369. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9370. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9371. // //
  9372. // // if (result==2)
  9373. // // {
  9374. // //
  9375. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9376. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9377. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9378. // ////
  9379. // //// [appDelegate update_count_mark];
  9380. // // }
  9381. // return jsobj;
  9382. }
  9383. +(void) request_complete_offline_ticket:(NSString* )vid completionHandler:(resultHandler)result
  9384. {
  9385. AppDelegate *appDelegate = nil;
  9386. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9387. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9388. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  9389. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  9390. // if(appDelegate.user!=nil)
  9391. // [params setValue:appDelegate.user forKey:@"user"];
  9392. // // if(appDelegate.contact_id!=nil)
  9393. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9394. // if(appDelegate.password!=nil)
  9395. // [params setValue:appDelegate.password forKey:@"password"];
  9396. [params setValue:vid forKey:@"downSerial"];
  9397. // 无论当前是离线还是在线状态,都可以进行同步;
  9398. // if(appDelegate.offline_mode)
  9399. // {
  9400. //
  9401. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9402. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9403. // dispatch_async(dispatch_get_main_queue(), ^{
  9404. // result(json);
  9405. // });
  9406. // });
  9407. //
  9408. // return;
  9409. //
  9410. // }
  9411. [self request_interface:URL_FINISH_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  9412. // NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  9413. // if(json==nil)
  9414. // return nil;
  9415. // NSError *error=nil;
  9416. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9417. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9418. // //
  9419. // // if (result==2)
  9420. // // {
  9421. // //
  9422. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9423. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9424. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9425. // ////
  9426. // //// [appDelegate update_count_mark];
  9427. // // }
  9428. // return jsobj;
  9429. }
  9430. +(void) request_download_offline:(NSString* )vid completionHandler:(resultHandler)result
  9431. {
  9432. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9433. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  9434. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  9435. // if(appDelegate.user!=nil)
  9436. // [params setValue:appDelegate.user forKey:@"user"];
  9437. // // if(appDelegate.contact_id!=nil)
  9438. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9439. // if(appDelegate.password!=nil)
  9440. // [params setValue:appDelegate.password forKey:@"password"];
  9441. [params setValue:vid forKey:@"downSerial"];
  9442. // AppDelegate *appDelegate = nil;
  9443. //
  9444. //
  9445. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9446. // if(appDelegate.offline_mode)
  9447. // {
  9448. //
  9449. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9450. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9451. // dispatch_async(dispatch_get_main_queue(), ^{
  9452. // result(json);
  9453. // });
  9454. // });
  9455. //
  9456. // return;
  9457. //
  9458. // }
  9459. __block bool bbreak = false;
  9460. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9461. __block NSMutableDictionary* download_json=nil;
  9462. int count=0;
  9463. // __block bool preparing = true;
  9464. while ([[download_json valueForKey:@"result"] intValue]!=2&&count<REQUEST_DOWNLOAD_RETRY_TIMES) //超过60分钟还没准被好数据就视为服务器出错。
  9465. {
  9466. if(bbreak)
  9467. break;
  9468. dispatch_async(dispatch_get_main_queue(), ^{
  9469. [self request_interface:URL_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  9470. if([resulti[@"result"] intValue]==RESULT_TRUE)
  9471. {
  9472. if(!bbreak) //此判断保证result只调用一次。
  9473. {
  9474. // appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  9475. // [appDelegate update_count_mark];
  9476. resulti[@"request_count"]=[NSNumber numberWithInt:count];
  9477. result(resulti);
  9478. }
  9479. bbreak=true;
  9480. }
  9481. else if([resulti[@"result"] intValue]==RESULT_ERROR)
  9482. {
  9483. result(resulti);
  9484. bbreak=true;
  9485. }
  9486. } retry:3];
  9487. });
  9488. sleep(RETRY_DELAY);
  9489. count++;
  9490. // download_json=[[RANetwork download_Offline:downSerial] mutableCopy];
  9491. //
  9492. // [RANetwork request_download_offline:downSerial completionHandler:^(NSMutableDictionary *result) {
  9493. // download_json=result;
  9494. // }];
  9495. //
  9496. }
  9497. // for(int i=0;i<150;i++)
  9498. // {
  9499. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  9500. // // result_params[@"resultSerial"]=uuid;
  9501. //
  9502. //
  9503. //
  9504. // sleep(2);
  9505. //
  9506. // // json=[self get_json:URL_CART parameters:params];
  9507. // // if(json!=nil)
  9508. // // {
  9509. // //
  9510. // // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9511. // // if([jsobj[@"result"] intValue]==2)
  9512. // // {
  9513. // // break;
  9514. // // }
  9515. // // }
  9516. //
  9517. // }
  9518. });
  9519. //
  9520. // NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  9521. // if(json==nil)
  9522. // return nil;
  9523. // NSError *error=nil;
  9524. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9525. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9526. // //
  9527. // // if (result==2)
  9528. // // {
  9529. // //
  9530. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9531. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9532. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9533. // ////
  9534. // //// [appDelegate update_count_mark];
  9535. // // }
  9536. // return jsobj;
  9537. }
  9538. + (void)request_fastupload:(NSMutableDictionary *)params filename:(NSString*)filename data:(NSData*) data url:(NSString *)url completionHandler:(resultHandler)result
  9539. {
  9540. //#ifdef test_server
  9541. // url=URL_REQUEST_RECORDS;
  9542. // params[@"prefix"]=URL_REQUEST_RECORDS;
  9543. //#endif
  9544. // [self request_file_fast:url parameters:params completionHandler:result];
  9545. #ifdef SCANNER_ORDER
  9546. params[@"site_name"]=[RADataProvider getSiteName];
  9547. #endif
  9548. [self request_upload_fast:data FileName:filename server:url parameters:params completionHandler:result];
  9549. }
  9550. +(void)request_err_log:(NSString*) up_params result:(NSString*)result_str module:(NSString*) module code:(int) code completionHandler:(resultHandler)result
  9551. {
  9552. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9553. AppDelegate *appDelegate = nil;
  9554. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9555. if(appDelegate.user!=nil)
  9556. [params setValue:appDelegate.user forKey:@"user"];
  9557. [params setValue:up_params forKey:@"upparam"];
  9558. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  9559. [params setValue:result_str forKey:@"result"];
  9560. [params setValue:module forKey:@"interfac"];
  9561. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  9562. // [params setValue:module forKey:@"module"];
  9563. // [[UIDevice currentDevice] name];
  9564. // if(appDelegate.offline_mode)
  9565. // {
  9566. // return [OLDataProvider offline_notimpl];
  9567. // }
  9568. if(appDelegate.offline_mode)
  9569. {
  9570. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9571. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9572. dispatch_async(dispatch_get_main_queue(), ^{
  9573. result(json);
  9574. });
  9575. });
  9576. return;
  9577. }
  9578. [self request_interface:URL_ERR_LOG parameters:params err_record_url:nil completionHandler:result retry:0];
  9579. //
  9580. // if(![self IsNetworkAvailable])
  9581. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9582. //
  9583. // NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  9584. // if(json==nil)
  9585. // return nil;
  9586. // NSError *error=nil;
  9587. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9588. // return jsobj;
  9589. }
  9590. @end