RANetwork.m 409 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237
  1. //
  2. // iSalesNetwork.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-6-20.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RANetwork.h"
  9. #import "RAUtils.h"
  10. #import "RASingleton.h"
  11. #import "GoogleAnalyst.h"
  12. #import "ERPUtils.h"
  13. #import "RAConvertor.h"
  14. #import "ActiveViewController.h"
  15. #import "ZipArchive.h"
  16. NSString *const kScreenName = @"kScreenName";
  17. NSString *const kAction = @"kAction";
  18. NSString *const kExtra = @"kExtra";
  19. NSString *const ScreenCodeLoginView = @"Login Screen";
  20. NSString *const ScreenCodeHomeView = @"Home Screen";
  21. NSString *const ScreenCodeCategory = @"Category Screen";
  22. NSString *const ScreenCodeCart = @"Cart Sceen";
  23. NSString *const ScreenCodeOrderList = @"Order History Screen";
  24. NSString *const ScreenCodeSearch = @"Search Screen";
  25. NSString *const ScreenCodeAccount = @"Account Screen";
  26. NSString *const ScreenCodeWishList = @"Wish List Screen";
  27. NSString *const ScreenCodePortfolio = @"Portfolio Screen";
  28. NSString *const ScreenCodeViewPortfolios = @"View Portfolios Screen";
  29. NSString *const ScreenCodeCamScan = @"Cam Scan Screen";
  30. NSString *const ScreenCodeScannerSetting = @"Scanner Setting Screen";
  31. NSString *const ScreenCodeOfflineSetting = @"Offline Setting Screen";
  32. NSString *const ScreenCodePlaceOrder = @"Place Order Screen";
  33. NSString *const ScreenCodeCustomerInfo = @"Customer Information Screen";
  34. NSString *const ScreenCodeNewCustomer = @"New Customer Screen";
  35. NSString *const ScreenCodeEditCustomer = @"Edit Customer Information Screen";
  36. NSString *const ScreenCodeModelInfo = @"Model Information Screen";
  37. NSString *const ScreenCodeOrderInfo = @"Order Information Screeen";
  38. NSString *const ScreenCodeUserSign = @"User Sign Screen";
  39. NSString *const ScreenCodeNewAddress = @"New Address Screen";
  40. NSString *const ScreenCodeAdvanceSearch = @"Account Advance Search Screen";
  41. NSString *const ScreenCodeCreatePortfolio = @"Create Portfolio Screen";
  42. NSString *const ScreenCodeParticularCategory = @"Particular Category Screen";
  43. NSString *const ScreenCodeEditPortfolio = @"Edit Portfolio Screen";
  44. NSString *const ScreenCodePriceSetting = @"Price Setting Screen";
  45. NSString *const ScreenCodeCategoryPrice = @"Category Price Screen";
  46. NSString *const ScreenCodeSetCatetoryPrice = @"Set Category Price Screen";
  47. NSString *const ScreenCodeUploadImage = @"Upload Image Screen";
  48. NSString *const ScreenCodeOfflineSync = @"Offline Sync Screen";
  49. @implementation RANetwork
  50. +(NSMutableDictionary*) prepare_additional_params:(NSMutableDictionary* ) params
  51. {
  52. AppDelegate *appDelegate = nil;
  53. //some UI methods ej
  54. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  55. // if(appDelegate.user!=nil)
  56. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.user key:@"usai"] forKey:@"user"];
  57. // if(appDelegate.password!=nil)
  58. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.password key:@"usai"] forKey:@"password"];
  59. //
  60. //
  61. //
  62. // if(appDelegate.user!=nil)
  63. // [params setValue:appDelegate.user forKey:@"user"];
  64. //
  65. // if(appDelegate.contact_id!=nil)
  66. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  67. // if(appDelegate.password!=nil)
  68. // [params setValue:appDelegate.password forKey:@"password"];
  69. //
  70. // [params setValue:appDelegate.build forKey:@"app_ver"];
  71. //
  72. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  73. // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  74. // [params setValue:short_version forKey:@"app_short_ver"];
  75. //
  76. //
  77. //
  78. //#if TARGET_IPHONE_SIMULATOR//模拟器
  79. // [params setValue:@"simulator_uuid" forKey:@"deviceid"];
  80. //#elif TARGET_OS_IPHONE//真机
  81. // UIDevice * dev = [UIDevice currentDevice];
  82. // NSUUID* uuid =dev.identifierForVendor;
  83. // [params setValue:uuid.UUIDString forKey:@"deviceid"];
  84. //#endif
  85. if(appDelegate.user!=nil)
  86. [params setValue:appDelegate.user forKey:@"user"];
  87. if(appDelegate.password!=nil)
  88. [params setValue:appDelegate.password forKey:@"password"];
  89. if(appDelegate.ipad_perm!=nil)
  90. [params setValue:appDelegate.ipad_perm forKey:@"ipad_perm"];
  91. [params setValue:appDelegate.build forKey:@"app_ver"];
  92. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  93. NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  94. [params setValue:short_version forKey:@"app_short_ver"];
  95. #if TARGET_IPHONE_SIMULATOR//模拟器
  96. [params setValue:@"simulator_uuid" forKey:@"idfv"];
  97. #elif TARGET_OS_IPHONE//真机
  98. UIDevice * dev = [UIDevice currentDevice];
  99. NSUUID* uuid =dev.identifierForVendor;
  100. [params setValue:uuid.UUIDString forKey:@"idfv"];
  101. #endif
  102. //
  103. // NSString *userAction = [params valueForKey:kAction];
  104. // NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  105. // if ([userAction isEqualToString:@"Login"]) {
  106. // if (!extra) {
  107. // extra = [NSMutableDictionary dictionary];
  108. // }
  109. // [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  110. // }
  111. return params;
  112. }
  113. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString *) file //delegate:(id < NSURLConnectionDelegate >)delegate
  114. {
  115. // NSString* e=[AESCrypt AES128Encrypt:@"密码学中的高级加密标准(Advanced Encryption Standard,AES),又称 高级加密标准Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用。经过五年的甄选流程,高级加密标准由美国国家标准与技术研究院 (NIST)于2001年11月26日发布于FIPS PUB 197,并在2002年5月26日成为有效的标准。2006年,高级加密标准已然成为对称密钥加密中最流行的算法之一。 " key:@"usai2010"];
  116. // DebugLog(e);
  117. // NSString* d=[AESCrypt decrypt:@"VzB4+lENfbzWX7ggHh2Os1P69l5YBzKmM51yqA37AfoKgPY8bJgdK8M4WvF+wDyOsLWP\/o8H5+bHMivQp1u8wM2QV7SYzgzPwV85QKtYWIzEgLe9T0HO69EdutWz7k1rdAT\/mftsRin0Hy5SHk7txTZT\/zPH5X+FQiExCTFm5Zus39HYvp+VxCX4+kYeymn8B63AUd3mRQyscUvDjfgU2olKR\/TP8PV3g+VQMZxpKfol3P1iOtz3XQlHZV0pM6SAf+SwT0sPfrdn6CZFfNQlrKA9QjMrnBdMeSCquSIWXnmLv6okzvnlJnT0SjvJuUeqNdBC5EZ0ACnhI0MrXVZEsq1EuM9al7oPzvU5EZbjZpmx+fSFIkMzTT8bYClTnG1bsL1MCcU4pSODDorUj8zalA==" password:@"usai2010"];
  118. params = [self prepare_additional_params:params];
  119. DebugLog(@"\n++++++++++++++++++++++Request++++++++++++++++++++++\n%@\n++++++++++++++++++++++Params++++++++++++++++++++++\n%@\n",url,[RAConvertor dict2string:params]);
  120. return [super get_json:url parameters:params file:(NSString*)file err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  121. int result=[[jsobj valueForKey:@"result"] intValue];
  122. // UIApplication * app = [UIApplication sharedApplication];
  123. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  124. switch (result) {
  125. case 0:
  126. [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  127. break;
  128. case 1:
  129. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  130. break;
  131. case 2:
  132. [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  133. break;
  134. case 8:
  135. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  136. break;
  137. case 9:
  138. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  139. break;
  140. case 99:
  141. [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  142. break;
  143. default:
  144. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  145. break;
  146. }
  147. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  148. // {
  149. // [jsobj setValue:@"9" forKey:@"result"];
  150. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  151. // }
  152. return jsobj;
  153. } decrypt_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  154. return nil;
  155. // NSString* base64str = jsobj[@"str"];
  156. // NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"usai2010"];
  157. // jsobj=[[RAUtils string2dict:decryptstr] mutableCopy];
  158. // return jsobj;
  159. }];
  160. /*
  161. */
  162. return nil;
  163. }
  164. +(void) LoadImage:(NSString*) url into:(UIImageView*) container
  165. {
  166. DebugLog(@"LoadImage:(NSString*) url in:(UIImageView*) container");
  167. NSString* file_name=[url lastPathComponent];
  168. NSData* img_data = [iSalesDB load_cached_img:file_name loadFrom:url];
  169. if(img_data==nil)
  170. {
  171. DebugLog(@"IMG NOT CACHED %@",file_name);
  172. img_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
  173. [iSalesDB cache_img:img_data filename:file_name saveTo:url];
  174. //load from internet;
  175. }
  176. if(img_data!=nil)
  177. {
  178. UIImage * img =[UIImage imageWithData:img_data];
  179. if(img==nil)
  180. DebugLog(@"UIIMAGE IS NIL! %@",file_name);
  181. else
  182. dispatch_async(dispatch_get_main_queue(), ^{
  183. container.image =img;
  184. });
  185. }
  186. else
  187. {
  188. DebugLog(@"IMG DOWNLOAD FAILED! %@",file_name);
  189. }
  190. }
  191. //+(NSData*)fake_json:(NSString*) url
  192. //{
  193. // NSString* jsonfile = nil;
  194. // if([url isEqualToString:URL_UPDATE_AUTH])
  195. // {
  196. // jsonfile=@"login";
  197. //
  198. // }
  199. // else if([url isEqualToString:URL_REQUEST_CATMENU])
  200. // {
  201. // jsonfile=@"categorymenu";
  202. // }
  203. // else if([url isEqualToString:URL_LOAD_HOME])
  204. // {
  205. // jsonfile=@"homepage";
  206. // }
  207. // else if([url isEqualToString:URL_SEARCH])
  208. // {
  209. // jsonfile=@"search";
  210. // }
  211. // else if([url isEqualToString:URL_CATEGORY_LOADMORE])
  212. // {
  213. // jsonfile=@"category_more";
  214. // }else if([url isEqualToString:URL_ITEM_DETAIL])
  215. // {
  216. // jsonfile=@"detail";
  217. // }else if([url isEqualToString:URL_CART])
  218. // {
  219. // jsonfile=@"cart";
  220. // }else if([url isEqualToString:URL_ORDER_LIST])
  221. // {
  222. // jsonfile=@"orderlist";
  223. // }
  224. //// else if([url isEqualToString:URL_ORDER_INFO])
  225. //// {
  226. //// jsonfile=@"orderinfo";
  227. //// }
  228. //// else if([url isEqualToString:URL_ORDER_INFO])
  229. //// {
  230. //// jsonfile=@"orderinfo2label";
  231. //// }
  232. //
  233. //
  234. //
  235. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:jsonfile ofType:@"json" ]];
  236. // NSMutableString *result = [[NSMutableString alloc] initWithData:json encoding:NSUTF8StringEncoding];
  237. //
  238. // DebugLog(@"result: \n%@",result);
  239. // return json;
  240. //}
  241. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
  242. {
  243. NSString *screenName = [params valueForKey:kScreenName];
  244. NSString *userAction = [params valueForKey:kAction];
  245. NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  246. if ([userAction isEqualToString:@"Login"]) {
  247. if (!extra) {
  248. extra = [NSMutableDictionary dictionary];
  249. }
  250. [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  251. }
  252. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  253. [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  254. #endif
  255. return [self get_json:url parameters:params file:nil];
  256. // {
  257. // int retry = 0;
  258. //
  259. // __block AppDelegate *appDelegate = nil;
  260. //
  261. // dispatch_sync(dispatch_get_main_queue(), ^{
  262. // //some UI methods ej
  263. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  264. // });
  265. // if(appDelegate.user!=nil)
  266. // [params setValue:appDelegate.user forKey:@"user"];
  267. // if(appDelegate.password!=nil)
  268. // [params setValue:appDelegate.password forKey:@"password"];
  269. //
  270. //
  271. // if(appDelegate.ipad_perm!=nil)
  272. // [params setValue:appDelegate.ipad_perm forKey:@"ipad_perm"];
  273. //
  274. // [params setValue:appDelegate.build forKey:@"app_ver"];
  275. //
  276. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  277. // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  278. // [params setValue:short_version forKey:@"app_short_ver"];
  279. //
  280. // UIDevice * dev = [UIDevice currentDevice];
  281. // NSUUID* uuid =dev.identifierForVendor;
  282. //#if TARGET_IPHONE_SIMULATOR//模拟器
  283. // [params setValue:@"simulator_uuid" forKey:@"idfv"];
  284. //#elif TARGET_OS_IPHONE//真机
  285. // [params setValue:uuid.UUIDString forKey:@"idfv"];
  286. //#endif
  287. //
  288. //// NSString *screenName = [params valueForKey:kScreenName];
  289. //// NSString *userAction = [params valueForKey:kAction];
  290. //// NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  291. //// if ([userAction isEqualToString:@"Login"]) {
  292. //// if (!extra) {
  293. //// extra = [NSMutableDictionary dictionary];
  294. //// }
  295. //// [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  296. //// }
  297. //
  298. //repeat:
  299. // {
  300. //
  301. // // return [self fake_json:url];
  302. //
  303. // // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  304. // //分界线的标识符
  305. // NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
  306. // //根据url初始化request
  307. // NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
  308. // cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
  309. // timeoutInterval:JSON_TIMEOUT];
  310. // //分界线 --AaB03x
  311. // NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
  312. // //结束符 AaB03x--
  313. // NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
  314. // //要上传的图片
  315. // // UIImage *image=[params objectForKey:@"pic"];
  316. // //得到图片的data
  317. // // NSData* data = UIImagePNGRepresentation(image);
  318. // //http body的字符串
  319. // NSMutableString *body=[[NSMutableString alloc]init];
  320. //
  321. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  322. // // [params setValue:@"handset_login" forKey:@"action"];
  323. // // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  324. //
  325. // // [params setValue:appDelegate.sessionid forKey:@"sessionid"];
  326. // // [params setValue:password forKey:@"password"];
  327. // // [params setValue:[NSString stringWithFormat:@"%d",ver] forKey:@"auth_ver"];
  328. //
  329. //
  330. //
  331. // // [headers setValue:headQuerlString forKey:@"param"];
  332. //
  333. // //参数的集合的所有key的集合
  334. // NSArray *keys= [params allKeys];
  335. // DebugLog(@"================parms==================");
  336. // //遍历keys
  337. // for(int i=0;i<[keys count];i++)
  338. // {
  339. // //得到当前key
  340. // NSString *key=[keys objectAtIndex:i];
  341. // //如果key不是pic,说明value是字符类型,比如name:Boris
  342. // if(![key isEqualToString:@"pic"])
  343. // {
  344. // //添加分界线,换行
  345. // [body appendFormat:@"%@\r\n",MPboundary];
  346. // //添加字段名称,换2行
  347. // [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
  348. // //添加字段的值
  349. // [body appendFormat:@"%@\r\n",[params objectForKey:key]];
  350. // DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
  351. // }
  352. // }
  353. // DebugLog(@"================parms==================");
  354. // ////添加分界线,换行
  355. // [body appendFormat:@"%@\r\n",MPboundary];
  356. // //声明pic字段,文件名为boris.png
  357. // [body appendFormat:@"Content-Disposition: form-data; name=\"pic\"; filename=\"boris.png\"\r\n"];
  358. // //声明上传文件的格式
  359. // [body appendFormat:@"Content-Type: image/png\r\n\r\n"];
  360. //
  361. // //声明结束符:--AaB03x--
  362. // NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
  363. // //声明myRequestData,用来放入http body
  364. // NSMutableData *myRequestData=[NSMutableData data];
  365. // //将body字符串转化为UTF8格式的二进制
  366. // [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
  367. // //将image的data加入
  368. // // [myRequestData appendData:data];
  369. // //加入结束符--AaB03x--
  370. // [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
  371. //
  372. // //设置HTTPHeader中Content-Type的值
  373. // NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
  374. // //设置HTTPHeader
  375. // [request setValue:content forHTTPHeaderField:@"Content-Type"];
  376. //
  377. // // 关闭keep alive
  378. // [request setValue:@"close" forHTTPHeaderField:@"Connection"];
  379. // //设置Content-Length
  380. // [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[myRequestData length]] forHTTPHeaderField:@"Content-Length"];
  381. // //设置http body
  382. // [request setHTTPBody:myRequestData];
  383. // //http method
  384. // [request setHTTPMethod:@"POST"];
  385. //
  386. //
  387. // NSHTTPURLResponse* urlResponse = nil;
  388. //
  389. // NSError *error = nil;
  390. //
  391. // NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
  392. //
  393. //
  394. // DebugLog(@"url: %@",url);
  395. //
  396. // DebugLog(@"response: %@",[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode]);
  397. //
  398. // if (responseData==nil) {
  399. //
  400. //// DebugLog(@"response error:%@", [error localizedDescription]);
  401. //
  402. //
  403. // NSMutableDictionary* ret = [[NSMutableDictionary alloc] init];
  404. // //#define RESULT_FALSE 0
  405. // //#define RESULT_TRUE 2
  406. // //#define RESULT_NET_ERROR -3
  407. // //#define RESULT_NET_NOTAVAILABLE -4
  408. // //#define RESULT_ERROR -5
  409. // //#define RESULT_LOCALFILE_ERROR -7
  410. // //#define RESULT_USERAUTH_ERROR -9
  411. // //#define RESULT_UPDATE_USERAUTH_ERROR -11
  412. // //#define RESULT_SESSION_EXPIRED -13
  413. // //#define RESULT_VER_LOW
  414. //
  415. // // NSString * moreinfo = error.description ;
  416. //
  417. // NSString* err_msg = [error localizedDescription];
  418. //
  419. //
  420. // //-----------------retry 3 times for error code -1005------------------------
  421. // if(error.code==-1005&&retry<3)
  422. // {
  423. // retry++;
  424. // goto repeat;
  425. //
  426. // }
  427. // //-----------------end retry 3 times for error code -1005------------------------
  428. //
  429. // NSDictionary* error_json = [RAUtils error_dict:error];
  430. // [ret setObject:error_json forKey:@"err_obj"];
  431. // NSString* resp_msg= nil;
  432. //
  433. // if(err_msg.length==0)
  434. // {
  435. // err_msg =[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode];
  436. // resp_msg = err_msg;
  437. // }
  438. // [ret setValue:[NSString stringWithFormat:@"%d",RESULT_NET_ERROR] forKey:@"result"];
  439. // [ret setValue:err_msg forKey:@"err_msg"];
  440. // [ret setValue:resp_msg forKey:@"resp_msg"];
  441. // [ret setValue:[NSString stringWithFormat:@"%ld",(long)urlResponse.statusCode] forKey:@"resp_code"];
  442. //
  443. //
  444. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:ret
  445. // options:0
  446. // error:nil];
  447. // if(![url isEqualToString:URL_ERR_LOG])
  448. // {
  449. // [RANetwork err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:[RAConvertor dict2string:ret]] module:url code:RESULT_NET_ERROR];
  450. // }
  451. //#if defined(BUILD_NPD)// || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  452. // [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  453. //#endif
  454. // return jsonData;
  455. //
  456. // }
  457. // else
  458. // {
  459. // NSString* err_msg = [error localizedDescription];
  460. // NSMutableString *str = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
  461. //
  462. // DebugLog(@"data string: %@",str);
  463. // NSError *error1 = nil;
  464. //
  465. // NSMutableDictionary* jsobj = [[NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error1] mutableCopy];
  466. //
  467. // if(jsobj==nil)// 服务器返回不是json
  468. // {
  469. //
  470. // jsobj=[[NSMutableDictionary alloc] init];
  471. // [jsobj setValue:@"1" forKey:@"result"];
  472. //
  473. // }
  474. //
  475. // int result=[[jsobj valueForKey:@"result"] intValue];
  476. // UIApplication * app = [UIApplication sharedApplication];
  477. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  478. // NSString* mode =[jsobj valueForKey:@"mode"];
  479. // [appDelegate SetMode:mode];
  480. // switch (result) {
  481. // case 0:
  482. // [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  483. // break;
  484. // case 1:
  485. // [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  486. // break;
  487. // case 2:
  488. // [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  489. // break;
  490. // case 8:
  491. // [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  492. // break;
  493. // case 9:
  494. // [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  495. // break;
  496. // case 99:
  497. // [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  498. // break;
  499. // default:
  500. // [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  501. // break;
  502. // }
  503. //
  504. //
  505. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  506. // {
  507. // [jsobj setValue:@"9" forKey:@"result"];
  508. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  509. // }
  510. //
  511. // if(![url isEqualToString:URL_ERR_LOG]&&![url isEqualToString:URL_DOWNLOAD_OFFLINE]/*&&result!=-3*/&&result!=2&&result!=99)
  512. // {
  513. // [RANetwork err_log:[RAUtils base64en:[RAConvertor dict2string:params]] result:[RAUtils base64en:str] module:url code:result];
  514. // }
  515. // NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsobj
  516. // options:0
  517. // error:nil];
  518. //#if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  519. // [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  520. //#endif
  521. // return jsonData;
  522. //
  523. // }
  524. //
  525. // return responseData;
  526. // }
  527. //}
  528. }
  529. //+(NSDictionary*)request_Editor:(NSString*) sourceid editor:(NSString*)editor
  530. //{
  531. //
  532. //}
  533. +(NSDictionary*) delete_portfoliolist:(NSString* ) listid
  534. {
  535. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  536. __block AppDelegate *appDelegate = nil;
  537. dispatch_sync(dispatch_get_main_queue(), ^{
  538. //some UI methods ej
  539. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  540. });
  541. if(appDelegate.user!=nil)
  542. [params setValue:appDelegate.user forKey:@"user"];
  543. if(appDelegate.contact_id!=nil)
  544. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  545. if(appDelegate.password!=nil)
  546. [params setValue:appDelegate.password forKey:@"password"];
  547. [params setValue:listid forKey:@"tearsheetsId"];
  548. // [params setValue:editor forKey:@"editor"];
  549. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  550. // [params setValue:@"Delete Portfolio" forKey:kAction];
  551. NSData* json = nil;
  552. if(appDelegate.offline_mode)
  553. {
  554. json = [OLDataProvider offline_removePDF:params];
  555. } else {
  556. if(![self IsNetworkAvailable])
  557. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  558. json=[self get_json:URL_PORTFOLIOLIST_REMOVE parameters:params];
  559. }
  560. if(json!=nil)
  561. {
  562. NSError *error=nil;
  563. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  564. return jsobj;
  565. }
  566. else
  567. return nil;
  568. }
  569. +(NSDictionary*) portfolio_remove:(NSString* ) item_ids
  570. {
  571. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  572. __block AppDelegate *appDelegate = nil;
  573. dispatch_sync(dispatch_get_main_queue(), ^{
  574. //some UI methods ej
  575. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  576. });
  577. if(appDelegate.user!=nil)
  578. [params setValue:appDelegate.user forKey:@"user"];
  579. if(appDelegate.contact_id!=nil)
  580. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  581. if(appDelegate.password!=nil)
  582. [params setValue:appDelegate.password forKey:@"password"];
  583. [params setValue:item_ids forKey:@"portfolioId"];
  584. // [params setValue:editor forKey:@"editor"];
  585. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  586. NSData* json = nil;
  587. if(appDelegate.offline_mode)
  588. {
  589. json = [OLDataProvider offline_removePortfolio:params];
  590. } else {
  591. if(![self IsNetworkAvailable])
  592. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  593. json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  594. }
  595. if(json!=nil)
  596. {
  597. NSError *error=nil;
  598. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  599. int result = [[jsobj valueForKey:@"result"] intValue];
  600. if (result==2)
  601. {
  602. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  603. [appDelegate update_count_mark];
  604. }
  605. return jsobj;
  606. }
  607. else
  608. return nil;
  609. }
  610. //+(NSDictionary*) watchlist_remove:(NSString* ) item_ids
  611. //{
  612. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  613. // __block AppDelegate *appDelegate = nil;
  614. //
  615. // dispatch_sync(dispatch_get_main_queue(), ^{
  616. // //some UI methods ej
  617. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  618. // });
  619. // if(appDelegate.user!=nil)
  620. // [params setValue:appDelegate.user forKey:@"user"];
  621. // if(appDelegate.contact_id!=nil)
  622. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  623. // if(appDelegate.password!=nil)
  624. // [params setValue:appDelegate.password forKey:@"password"];
  625. // [params setValue:item_ids forKey:@"collectId"];
  626. // // [params setValue:editor forKey:@"editor"];
  627. //
  628. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  629. //
  630. // if(appDelegate.offline_mode)
  631. // {
  632. // return [OLDataProvider offline_deletewishlist:params];
  633. // }
  634. // if(![self IsNetworkAvailable])
  635. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  636. //
  637. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  638. // if(json!=nil)
  639. // {
  640. // NSError *error=nil;
  641. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  642. // int result = [[jsobj valueForKey:@"result"] intValue];
  643. //
  644. // if (result==2)
  645. // {
  646. //
  647. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  648. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  649. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  650. //
  651. // [appDelegate update_count_mark];
  652. // }
  653. // return jsobj;
  654. // }
  655. // else
  656. // return nil;
  657. //}
  658. //+(NSDictionary*) move_cart2wish:(NSString* ) item_ids
  659. //{
  660. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  661. // __block AppDelegate *appDelegate = nil;
  662. //
  663. // dispatch_sync(dispatch_get_main_queue(), ^{
  664. // //some UI methods ej
  665. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  666. // });
  667. // if(appDelegate.user!=nil)
  668. // [params setValue:appDelegate.user forKey:@"user"];
  669. // if(appDelegate.contact_id!=nil)
  670. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  671. // if(appDelegate.password!=nil)
  672. // [params setValue:appDelegate.password forKey:@"password"];
  673. // if(appDelegate.order_code!=nil)
  674. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  675. // [params setValue:item_ids forKey:@"cartItemId"];
  676. // // [params setValue:editor forKey:@"editor"];
  677. //
  678. // [params setValue:ScreenCodeCart forKey:kScreenName];
  679. // // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  680. //
  681. // NSData* json = nil;
  682. // if(appDelegate.offline_mode)
  683. // {
  684. // json= [OLDataProvider offline_movecart2wish:params];
  685. // }
  686. // else
  687. // {
  688. // if(![self IsNetworkAvailable])
  689. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  690. //
  691. // json=[self get_json:URL_CART2WISH parameters:params];
  692. // }
  693. // if(json!=nil)
  694. // {
  695. // NSError *error=nil;
  696. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  697. // int result = [[jsobj valueForKey:@"result"] intValue];
  698. //
  699. // if (result==2)
  700. // {
  701. //
  702. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  703. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  704. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  705. //
  706. // [appDelegate update_count_mark];
  707. // }
  708. // return jsobj;
  709. // }
  710. // else
  711. // return nil;
  712. //}
  713. //+(NSDictionary*) move_wish2cart:(NSString* ) item_ids
  714. //{
  715. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  716. // __block AppDelegate *appDelegate = nil;
  717. //
  718. // dispatch_sync(dispatch_get_main_queue(), ^{
  719. // //some UI methods ej
  720. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  721. // });
  722. // if(appDelegate.user!=nil)
  723. // [params setValue:appDelegate.user forKey:@"user"];
  724. // if(appDelegate.contact_id!=nil)
  725. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  726. // if(appDelegate.password!=nil)
  727. // [params setValue:appDelegate.password forKey:@"password"];
  728. // if(appDelegate.order_code!=nil)
  729. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  730. // [params setValue:item_ids forKey:@"collectId"];
  731. // // [params setValue:editor forKey:@"editor"];
  732. //
  733. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  734. // [params setValue:@"Move To Cart" forKey:kAction];
  735. //
  736. // NSData *json = nil;
  737. // if(appDelegate.offline_mode)
  738. // {
  739. // json = [OLDataProvider offline_movewish2cart:params];
  740. // } else {
  741. // if(![self IsNetworkAvailable])
  742. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  743. //
  744. // json=[self get_json:URL_WISH2CART parameters:params];
  745. // }
  746. //
  747. // if(json!=nil)
  748. // {
  749. // NSError *error=nil;
  750. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  751. // int result = [[jsobj valueForKey:@"result"] intValue];
  752. //
  753. // if (result==2)
  754. // {
  755. //
  756. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  757. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  758. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  759. //
  760. // [appDelegate update_count_mark];
  761. // }
  762. // return jsobj;
  763. // }
  764. // else
  765. // return nil;
  766. //}
  767. //+(NSDictionary*) cart_remove:(NSString* ) item_ids
  768. //{
  769. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  770. // __block AppDelegate *appDelegate = nil;
  771. //
  772. // dispatch_sync(dispatch_get_main_queue(), ^{
  773. // //some UI methods ej
  774. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  775. // });
  776. // if(appDelegate.user!=nil)
  777. // [params setValue:appDelegate.user forKey:@"user"];
  778. // if(appDelegate.contact_id!=nil)
  779. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  780. // if(appDelegate.password!=nil)
  781. // [params setValue:appDelegate.password forKey:@"password"];
  782. //
  783. // if(appDelegate.order_code!=nil)
  784. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  785. // [params setValue:item_ids forKey:@"cartItemId"];
  786. // // [params setValue:editor forKey:@"editor"];
  787. //
  788. // [params setValue:ScreenCodeCart forKey:kScreenName];
  789. // // [params setValue:@"" forKey:kAction];
  790. //
  791. // NSData* json=nil;
  792. // if(appDelegate.offline_mode)
  793. // {
  794. // json= [OLDataProvider offline_cartremove:params];
  795. // }
  796. // else
  797. // {
  798. // if(![self IsNetworkAvailable])
  799. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  800. //
  801. // json=[self get_json:URL_CART_REMOVE parameters:params];
  802. // }
  803. // if(json!=nil)
  804. // {
  805. // NSError *error=nil;
  806. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  807. //
  808. // int result = [[jsobj valueForKey:@"result"] intValue];
  809. //
  810. // if (result==2)
  811. // {
  812. //
  813. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  814. //
  815. //
  816. // [appDelegate update_count_mark];
  817. // }
  818. // return jsobj;
  819. // }
  820. // else
  821. // return nil;
  822. //}
  823. //+(NSDictionary*) cart_check:(NSString* ) item_ids
  824. //{
  825. // return nil;
  826. // if(![self IsNetworkAvailable])
  827. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  828. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  829. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  830. // if(appDelegate.user!=nil)
  831. // [params setValue:appDelegate.user forKey:@"user"];
  832. // if(appDelegate.contact_id!=nil)
  833. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  834. // if(appDelegate.password!=nil)
  835. // [params setValue:appDelegate.password forKey:@"password"];
  836. // [params setValue:item_ids forKey:@"cartItemId"];
  837. // // [params setValue:editor forKey:@"editor"];
  838. // if(appDelegate.offline_mode)
  839. // {
  840. // return [OLDataProvider offline_notimpl];
  841. // }
  842. // NSData* json=[self get_json:URL_CART_CHECK parameters:params];
  843. // if(json!=nil)
  844. // {
  845. // NSError *error=nil;
  846. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  847. // return jsobj;
  848. // }
  849. // else
  850. // return nil;
  851. //}
  852. +(NSDictionary*)create_Address:(NSMutableDictionary*)params
  853. {
  854. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  855. __block AppDelegate *appDelegate = nil;
  856. dispatch_sync(dispatch_get_main_queue(), ^{
  857. //some UI methods ej
  858. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  859. });
  860. if(appDelegate.user!=nil)
  861. [params setValue:appDelegate.user forKey:@"user"];
  862. if(appDelegate.contact_id!=nil)
  863. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  864. if(appDelegate.password!=nil)
  865. [params setValue:appDelegate.password forKey:@"password"];
  866. // [params setValue:sourceid forKey:@"sourceid"];
  867. // [params setValue:editor forKey:@"editor"];
  868. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  869. NSData* json=nil;
  870. if(appDelegate.offline_mode)
  871. {
  872. json= [OLDataProvider offline_saveaddr:params];
  873. }
  874. else
  875. {
  876. if(![self IsNetworkAvailable])
  877. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  878. json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  879. }
  880. if(json!=nil)
  881. {
  882. NSError *error=nil;
  883. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  884. return jsobj;
  885. }
  886. else
  887. return nil;
  888. }
  889. +(NSDictionary*)copy_Order:(NSString*) order_code
  890. {
  891. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  892. __block AppDelegate *appDelegate = nil;
  893. dispatch_sync(dispatch_get_main_queue(), ^{
  894. //some UI methods ej
  895. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  896. });
  897. if(appDelegate.user!=nil)
  898. [params setValue:appDelegate.user forKey:@"user"];
  899. if(appDelegate.contact_id!=nil)
  900. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  901. if(appDelegate.password!=nil)
  902. [params setValue:appDelegate.password forKey:@"password"];
  903. // NSString* ssaved = @"false";
  904. // if(saved)
  905. // ssaved=@"true";
  906. // [params setValue:@"true" forKey:@"saved"];
  907. [params setValue:order_code forKey:@"code"];
  908. // [params setValue:sourceid forKey:@"sourceid"];
  909. // [params setValue:editor forKey:@"editor"];
  910. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  911. NSData* json=nil;
  912. if(appDelegate.offline_mode)
  913. {
  914. json= [OLDataProvider offline_copyorder:params];
  915. }
  916. else
  917. {
  918. if(![self IsNetworkAvailable])
  919. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  920. json=[self get_json:URL_COPY_ORDER parameters:params];
  921. }
  922. if(json!=nil)
  923. {
  924. NSError *error=nil;
  925. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  926. return jsobj;
  927. }
  928. else
  929. return nil;
  930. }
  931. +(NSDictionary*)sign_Order:(NSString*) order_code path:(NSString*)path
  932. {
  933. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  934. __block AppDelegate *appDelegate = nil;
  935. dispatch_sync(dispatch_get_main_queue(), ^{
  936. //some UI methods ej
  937. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  938. });
  939. if(appDelegate.user!=nil)
  940. [params setValue:appDelegate.user forKey:@"user"];
  941. if(appDelegate.contact_id!=nil)
  942. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  943. if(appDelegate.password!=nil)
  944. [params setValue:appDelegate.password forKey:@"password"];
  945. // NSString* ssaved = @"false";
  946. // if(saved)
  947. // ssaved=@"true";
  948. // [params setValue:@"true" forKey:@"saved"];
  949. [params setValue:order_code forKey:@"orderCode"];
  950. [params setValue:path forKey:@"picpath"];
  951. // [params setValue:sourceid forKey:@"sourceid"];
  952. // [params setValue:editor forKey:@"editor"];
  953. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  954. NSData* json=nil;
  955. if(appDelegate.offline_mode)
  956. {
  957. json= [OLDataProvider offline_signorder:params];
  958. }
  959. else
  960. {
  961. if(![self IsNetworkAvailable])
  962. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  963. json=[self get_json:URL_SIGN_ORDER parameters:params];
  964. }
  965. if(json!=nil)
  966. {
  967. NSError *error=nil;
  968. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  969. return jsobj;
  970. }
  971. else
  972. return nil;
  973. }
  974. +(NSDictionary*)commit_Order:(NSString*) order_code //saved:(bool) saved
  975. {
  976. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  977. __block AppDelegate *appDelegate = nil;
  978. dispatch_sync(dispatch_get_main_queue(), ^{
  979. //some UI methods ej
  980. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  981. });
  982. if(appDelegate.user!=nil)
  983. [params setValue:appDelegate.user forKey:@"user"];
  984. if(appDelegate.contact_id!=nil)
  985. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  986. if(appDelegate.password!=nil)
  987. [params setValue:appDelegate.password forKey:@"password"];
  988. // NSString* ssaved = @"false";
  989. // if(saved)
  990. // ssaved=@"true";
  991. [params setValue:@"true" forKey:@"saved"];
  992. [params setValue:order_code forKey:@"orderCode"];
  993. // [params setValue:sourceid forKey:@"sourceid"];
  994. // [params setValue:editor forKey:@"editor"];
  995. [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  996. NSData* json = nil;
  997. if(appDelegate.offline_mode)
  998. {
  999. json= [OLDataProvider offline_submitorder:params];
  1000. }
  1001. else
  1002. {
  1003. if(![self IsNetworkAvailable])
  1004. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1005. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  1006. }
  1007. if(json!=nil)
  1008. {
  1009. NSError *error=nil;
  1010. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1011. return jsobj;
  1012. }
  1013. else
  1014. return nil;
  1015. }
  1016. //+(NSDictionary*)open_Order:(NSString*) order_code
  1017. //{
  1018. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1019. // __block AppDelegate *appDelegate = nil;
  1020. //
  1021. // dispatch_sync(dispatch_get_main_queue(), ^{
  1022. // //some UI methods ej
  1023. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1024. // });
  1025. // if(appDelegate.user!=nil)
  1026. // [params setValue:appDelegate.user forKey:@"user"];
  1027. // // if(appDelegate.contact_id!=nil)
  1028. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1029. // if(appDelegate.password!=nil)
  1030. // [params setValue:appDelegate.password forKey:@"password"];
  1031. //
  1032. // [params setValue:order_code forKey:@"orderCode"];
  1033. // // [params setValue:sourceid forKey:@"sourceid"];
  1034. // // [params setValue:editor forKey:@"editor"];
  1035. //
  1036. // [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  1037. //
  1038. // NSData* json=nil;
  1039. // if(appDelegate.offline_mode)
  1040. // {
  1041. // json=[OLDataProvider offline_editorder:params];
  1042. //
  1043. // }
  1044. // else
  1045. // {
  1046. // if(![self IsNetworkAvailable])
  1047. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1048. //
  1049. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  1050. // }
  1051. // if(json!=nil)
  1052. // {
  1053. // NSError *error=nil;
  1054. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1055. // int result = [[jsobj valueForKey:@"result"] intValue];
  1056. //
  1057. // if (result==2)
  1058. // {
  1059. //
  1060. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1061. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1062. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1063. //
  1064. // [appDelegate update_count_mark];
  1065. //
  1066. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1067. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  1068. // }
  1069. //
  1070. // }
  1071. //
  1072. // return jsobj;
  1073. // }
  1074. // else
  1075. // return nil;
  1076. //}
  1077. +(NSDictionary*)delete_Order:(NSString*) order_id
  1078. {
  1079. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1080. __block AppDelegate *appDelegate = nil;
  1081. dispatch_sync(dispatch_get_main_queue(), ^{
  1082. //some UI methods ej
  1083. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1084. });
  1085. if(appDelegate.user!=nil)
  1086. [params setValue:appDelegate.user forKey:@"user"];
  1087. // if(appDelegate.contact_id!=nil)
  1088. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1089. if(appDelegate.password!=nil)
  1090. [params setValue:appDelegate.password forKey:@"password"];
  1091. [params setValue:order_id forKey:@"orderId"];
  1092. // [params setValue:sourceid forKey:@"sourceid"];
  1093. // [params setValue:editor forKey:@"editor"];
  1094. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  1095. if(appDelegate.offline_mode)
  1096. {
  1097. return [OLDataProvider offline_notimpl];
  1098. }
  1099. if(![self IsNetworkAvailable])
  1100. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1101. NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  1102. if(json!=nil)
  1103. {
  1104. NSError *error=nil;
  1105. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1106. return jsobj;
  1107. }
  1108. else
  1109. return nil;
  1110. }
  1111. +(NSDictionary*)cancel_Order:(NSString*) order_id order_code:(NSString*) order_code
  1112. {
  1113. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1114. __block AppDelegate *appDelegate = nil;
  1115. dispatch_sync(dispatch_get_main_queue(), ^{
  1116. //some UI methods ej
  1117. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1118. });
  1119. if(appDelegate.user!=nil)
  1120. [params setValue:appDelegate.user forKey:@"user"];
  1121. // if(appDelegate.contact_id!=nil)
  1122. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1123. if(appDelegate.password!=nil)
  1124. [params setValue:appDelegate.password forKey:@"password"];
  1125. [params setValue:order_id forKey:@"orderId"];
  1126. [params setValue:order_code forKey:@"orderCode"];
  1127. // [params setValue:sourceid forKey:@"sourceid"];
  1128. // [params setValue:editor forKey:@"editor"];
  1129. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  1130. NSData* json=nil;
  1131. if(appDelegate.offline_mode)
  1132. {
  1133. json=[OLDataProvider offline_cancelorder:params];
  1134. }
  1135. else
  1136. {
  1137. if(![self IsNetworkAvailable])
  1138. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1139. json=[self get_json:URL_CANCEL_ORDER parameters:params];
  1140. }
  1141. if(json!=nil)
  1142. {
  1143. NSError *error=nil;
  1144. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1145. return jsobj;
  1146. }
  1147. else
  1148. return nil;
  1149. }
  1150. +(NSDictionary*)release_Order:(NSString*) order_code withScreen:(NSString *)screenName
  1151. {
  1152. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1153. __block AppDelegate *appDelegate = nil;
  1154. dispatch_sync(dispatch_get_main_queue(), ^{
  1155. //some UI methods ej
  1156. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1157. });
  1158. if(appDelegate.user!=nil)
  1159. [params setValue:appDelegate.user forKey:@"user"];
  1160. // if(appDelegate.contact_id!=nil)
  1161. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1162. if(appDelegate.password!=nil)
  1163. [params setValue:appDelegate.password forKey:@"password"];
  1164. [params setValue:order_code forKey:@"orderCode"];
  1165. // [params setValue:sourceid forKey:@"sourceid"];
  1166. // [params setValue:editor forKey:@"editor"];
  1167. if (screenName) {
  1168. [params setValue:screenName forKey:kScreenName];
  1169. }
  1170. NSData* json=nil;
  1171. if(appDelegate.offline_mode)
  1172. {
  1173. json= [OLDataProvider offline_resetorder:params];
  1174. }
  1175. else
  1176. {
  1177. if(![self IsNetworkAvailable])
  1178. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1179. json=[self get_json:URL_RELEASE_ORDER parameters:params];
  1180. }
  1181. if(json!=nil)
  1182. {
  1183. NSError *error=nil;
  1184. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1185. if([[jsobj valueForKey:@"result"]intValue]==2)
  1186. { [appDelegate SetSo:nil];
  1187. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1188. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1189. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1190. [appDelegate update_count_mark];
  1191. }
  1192. return jsobj;
  1193. }
  1194. else
  1195. return nil;
  1196. }
  1197. +(NSDictionary*)update_OrderCustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info
  1198. {
  1199. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1200. __block AppDelegate *appDelegate = nil;
  1201. dispatch_sync(dispatch_get_main_queue(), ^{
  1202. //some UI methods ej
  1203. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1204. });
  1205. if(appDelegate.user!=nil)
  1206. [info setValue:appDelegate.user forKey:@"user"];
  1207. // if(appDelegate.contact_id!=nil)
  1208. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1209. if(appDelegate.password!=nil)
  1210. [info setValue:appDelegate.password forKey:@"password"];
  1211. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1212. [info setValue:order_code forKey:@"orderCode"];
  1213. // [params setValue:sourceid forKey:@"sourceid"];
  1214. // [params setValue:editor forKey:@"editor"];
  1215. if(appDelegate.offline_mode)
  1216. {
  1217. return [OLDataProvider offline_notimpl];
  1218. }
  1219. if(![self IsNetworkAvailable])
  1220. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1221. NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  1222. if(json!=nil)
  1223. {
  1224. NSError *error=nil;
  1225. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1226. return jsobj;
  1227. }
  1228. else
  1229. return nil;
  1230. }
  1231. //+(NSDictionary*)commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url
  1232. //{
  1233. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1234. // __block AppDelegate *appDelegate = nil;
  1235. //
  1236. // dispatch_sync(dispatch_get_main_queue(), ^{
  1237. // //some UI methods ej
  1238. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1239. // });
  1240. // if(appDelegate.user!=nil)
  1241. // [params setValue:appDelegate.user forKey:@"user"];
  1242. // if(appDelegate.contact_id!=nil)
  1243. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1244. // if(appDelegate.password!=nil)
  1245. // [params setValue:appDelegate.password forKey:@"password"];
  1246. //
  1247. // // if(appDelegate.order_code!=nil)
  1248. // // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1249. //
  1250. // // NSDictionary* customerinfo= appDelegate.customerInfo;
  1251. // //
  1252. // // NSArray* keys=[customerinfo allKeys];
  1253. // // for(int i=0;i<keys.count;i++)
  1254. // // {
  1255. // // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1256. // // }
  1257. // //
  1258. // // [params setValue:sourceid forKey:@"sourceid"];
  1259. // // [params setValue:editor forKey:@"editor"];
  1260. //
  1261. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  1262. //
  1263. // if(appDelegate.offline_mode)
  1264. // {
  1265. // params[@"offline_Command"]=url;
  1266. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  1267. // }
  1268. //
  1269. // if(![self IsNetworkAvailable])
  1270. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1271. //
  1272. // NSData* json=[self get_json:url parameters:params];
  1273. // if(json!=nil)
  1274. // {
  1275. // NSError *error=nil;
  1276. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1277. // if([[jsobj valueForKey:@"result"]intValue]==2)
  1278. // [appDelegate SetSo:nil];
  1279. //
  1280. //
  1281. // return jsobj;
  1282. // }
  1283. // else
  1284. // return nil;
  1285. //}
  1286. +(NSDictionary*)saveandcommit_Order:(NSMutableDictionary*)params
  1287. {
  1288. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1289. __block AppDelegate *appDelegate = nil;
  1290. dispatch_sync(dispatch_get_main_queue(), ^{
  1291. //some UI methods ej
  1292. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1293. });
  1294. if(appDelegate.user!=nil)
  1295. [params setValue:appDelegate.user forKey:@"user"];
  1296. if(appDelegate.contact_id!=nil)
  1297. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1298. if(appDelegate.password!=nil)
  1299. [params setValue:appDelegate.password forKey:@"password"];
  1300. if(appDelegate.order_code!=nil)
  1301. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1302. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1303. //
  1304. // NSArray* keys=[customerinfo allKeys];
  1305. // for(int i=0;i<keys.count;i++)
  1306. // {
  1307. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1308. // }
  1309. //
  1310. // [params setValue:sourceid forKey:@"sourceid"];
  1311. // [params setValue:editor forKey:@"editor"];
  1312. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1313. NSData* json=nil;
  1314. if(appDelegate.offline_mode)
  1315. {
  1316. json=[OLDataProvider offline_submitorder:params];
  1317. }
  1318. else
  1319. {
  1320. if(![self IsNetworkAvailable])
  1321. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1322. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  1323. }
  1324. if(json!=nil)
  1325. {
  1326. NSError *error=nil;
  1327. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1328. if([[jsobj valueForKey:@"result"]intValue]==2)
  1329. [appDelegate SetSo:nil];
  1330. return jsobj;
  1331. }
  1332. else
  1333. return nil;
  1334. }
  1335. +(NSDictionary*)update_Customer:(NSMutableDictionary*)params
  1336. {
  1337. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1338. __block AppDelegate *appDelegate = nil;
  1339. dispatch_sync(dispatch_get_main_queue(), ^{
  1340. //some UI methods ej
  1341. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1342. });
  1343. if(appDelegate.user!=nil)
  1344. [params setValue:appDelegate.user forKey:@"user"];
  1345. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1346. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1347. // else
  1348. if(appDelegate.contact_id!=nil)
  1349. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1350. if(appDelegate.password!=nil)
  1351. [params setValue:appDelegate.password forKey:@"password"];
  1352. // NSDictionary* customerinfo=nil;
  1353. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1354. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1355. // else
  1356. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1357. //
  1358. // appDelegate.customerInfo;
  1359. // NSArray* keys=[customerinfo allKeys];
  1360. // for(int i=0;i<keys.count;i++)
  1361. // {
  1362. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1363. // }
  1364. // [params setValue:sourceid forKey:@"sourceid"];
  1365. // [params setValue:editor forKey:@"editor"];
  1366. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1367. NSData* json=nil;
  1368. if(appDelegate.offline_mode)
  1369. {
  1370. json= [OLDataProvider offline_saveContact:params];
  1371. }
  1372. else
  1373. {
  1374. if(![self IsNetworkAvailable])
  1375. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1376. json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  1377. }
  1378. if(json!=nil)
  1379. {
  1380. NSError *error=nil;
  1381. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1382. return jsobj;
  1383. }
  1384. else
  1385. return nil;
  1386. }
  1387. +(NSDictionary*)save_newCustomer:(NSMutableDictionary*)params
  1388. {
  1389. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1390. __block AppDelegate *appDelegate = nil;
  1391. dispatch_sync(dispatch_get_main_queue(), ^{
  1392. //some UI methods ej
  1393. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1394. });
  1395. if(appDelegate.user!=nil)
  1396. [params setValue:appDelegate.user forKey:@"user"];
  1397. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1398. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1399. // else
  1400. if(appDelegate.contact_id!=nil)
  1401. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1402. if(appDelegate.password!=nil)
  1403. [params setValue:appDelegate.password forKey:@"password"];
  1404. // NSDictionary* customerinfo=nil;
  1405. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1406. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1407. // else
  1408. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1409. //
  1410. // appDelegate.customerInfo;
  1411. // NSArray* keys=[customerinfo allKeys];
  1412. // for(int i=0;i<keys.count;i++)
  1413. // {
  1414. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1415. // }
  1416. // [params setValue:sourceid forKey:@"sourceid"];
  1417. // [params setValue:editor forKey:@"editor"];
  1418. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1419. NSData* json=nil;
  1420. if(appDelegate.offline_mode)
  1421. {
  1422. json= [OLDataProvider offline_saveNewContact:params];
  1423. }
  1424. else
  1425. {
  1426. if(![self IsNetworkAvailable])
  1427. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1428. json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  1429. }
  1430. if(json!=nil)
  1431. {
  1432. NSError *error=nil;
  1433. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1434. return jsobj;
  1435. }
  1436. else
  1437. return nil;
  1438. }
  1439. +(NSDictionary*)save_Order:(NSMutableDictionary*)params
  1440. {
  1441. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1442. __block AppDelegate *appDelegate = nil;
  1443. dispatch_sync(dispatch_get_main_queue(), ^{
  1444. //some UI methods ej
  1445. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1446. });
  1447. if(appDelegate.user!=nil)
  1448. [params setValue:appDelegate.user forKey:@"user"];
  1449. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1450. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1451. // else
  1452. if(appDelegate.contact_id!=nil)
  1453. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1454. if(appDelegate.password!=nil)
  1455. [params setValue:appDelegate.password forKey:@"password"];
  1456. if(appDelegate.order_code!=nil)
  1457. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1458. // NSDictionary* customerinfo=nil;
  1459. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1460. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1461. // else
  1462. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1463. //
  1464. // appDelegate.customerInfo;
  1465. // NSArray* keys=[customerinfo allKeys];
  1466. // for(int i=0;i<keys.count;i++)
  1467. // {
  1468. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1469. // }
  1470. // [params setValue:sourceid forKey:@"sourceid"];
  1471. // [params setValue:editor forKey:@"editor"];
  1472. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1473. NSData* json=nil;
  1474. if(appDelegate.offline_mode)
  1475. {
  1476. json= [OLDataProvider offline_saveorder:params];
  1477. }
  1478. else
  1479. {
  1480. if(![self IsNetworkAvailable])
  1481. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1482. json=[self get_json:URL_SAVE_ORDER parameters:params];
  1483. }
  1484. if(json!=nil)
  1485. {
  1486. NSError *error=nil;
  1487. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1488. NSString *so = [jsobj valueForKey:@"so#"];
  1489. if (so) {
  1490. [appDelegate SetSo:so];
  1491. }
  1492. return jsobj;
  1493. }
  1494. else
  1495. return nil;
  1496. }
  1497. //+(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
  1498. //{
  1499. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1500. // __block AppDelegate *appDelegate = nil;
  1501. //
  1502. // dispatch_sync(dispatch_get_main_queue(), ^{
  1503. // //some UI methods ej
  1504. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1505. // });
  1506. // if(appDelegate.user!=nil)
  1507. // [params setValue:appDelegate.user forKey:@"user"];
  1508. //
  1509. //
  1510. // // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1511. // // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1512. // // else
  1513. //
  1514. // if(appDelegate.contact_id!=nil)
  1515. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1516. // if(appDelegate.password!=nil)
  1517. // [params setValue:appDelegate.password forKey:@"password"];
  1518. //
  1519. // if(appDelegate.order_code!=nil)
  1520. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1521. // // [params setValue:sourceid forKey:@"sourceid"];
  1522. // // [params setValue:editor forKey:@"editor"];
  1523. // DebugLog(@"request editor url:%@",request_url);
  1524. //
  1525. //
  1526. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1527. // {
  1528. // [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1529. // }
  1530. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1531. // {
  1532. // [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1533. // }
  1534. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1535. // {
  1536. // [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  1537. // }
  1538. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1539. // {
  1540. // [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1541. // }
  1542. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1543. // {
  1544. // [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  1545. // }
  1546. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1547. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1548. // }
  1549. //
  1550. // NSData* json = nil;
  1551. // if(appDelegate.offline_mode)
  1552. // {
  1553. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1554. // {
  1555. // json= [OLDataProvider offline_createContact:params];
  1556. // }
  1557. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1558. // {
  1559. // json= [OLDataProvider offline_editContact:params];
  1560. // }
  1561. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1562. // {
  1563. // json= [OLDataProvider offline_contactAdvancedSearch:params];
  1564. // }
  1565. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1566. // {
  1567. // json= [OLDataProvider offline_placeorder:params];
  1568. // }
  1569. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1570. // {
  1571. // json= [OLDataProvider offline_addreditor:params];
  1572. // }
  1573. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1574. // json = [OLDataProvider offline_createTearSheet:params];
  1575. // }
  1576. //
  1577. // else
  1578. // return [OLDataProvider offline_notimpl];
  1579. // }
  1580. // else
  1581. // {
  1582. // if(![self IsNetworkAvailable])
  1583. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1584. //
  1585. // if([request_url isEqualToString:URL_CARTDELIVERY])
  1586. // {
  1587. // NSError *error=nil;
  1588. //
  1589. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1590. // params[@"resultSerial"]=uuid;
  1591. //
  1592. // for(int i=0;i<150;i++)
  1593. // {
  1594. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1595. // // result_params[@"resultSerial"]=uuid;
  1596. // json=[self get_json:request_url parameters:params];
  1597. // if(json!=nil)
  1598. // {
  1599. //
  1600. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1601. // if([jsobj[@"result"] intValue]==2 || [jsobj[@"result"] intValue] == 8)
  1602. // {
  1603. // break;
  1604. // }
  1605. // }
  1606. // sleep(2);
  1607. // }
  1608. // }
  1609. // else
  1610. // json =[self get_json:request_url parameters:params];
  1611. // }
  1612. // if(json!=nil)
  1613. // {
  1614. // NSError *error=nil;
  1615. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1616. // return jsobj;
  1617. // }
  1618. // else
  1619. // return nil;
  1620. //}
  1621. //+(NSDictionary*)request_OrderInfo:(NSString*) orderid
  1622. //{
  1623. // if(![self IsNetworkAvailable])
  1624. // return nil;
  1625. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1626. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1627. // if(appDelegate.user!=nil)
  1628. // [params setValue:appDelegate.user forKey:@"user"];
  1629. // if(appDelegate.password!=nil)
  1630. // [params setValue:appDelegate.password forKey:@"password"];
  1631. // [params setValue:orderid forKey:@"orderid"];
  1632. // NSData* json=[self get_json:URL_ORDER_INFO parameters:params];
  1633. // NSError *error=nil;
  1634. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1635. // return jsobj;
  1636. //}
  1637. +(NSDictionary*)request_OrderList:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged
  1638. {
  1639. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1640. __block AppDelegate *appDelegate = nil;
  1641. dispatch_sync(dispatch_get_main_queue(), ^{
  1642. //some UI methods ej
  1643. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1644. });
  1645. if(appDelegate.user!=nil)
  1646. [params setValue:appDelegate.user forKey:@"user"];
  1647. if(appDelegate.contact_id!=nil)
  1648. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1649. if(appDelegate.password!=nil)
  1650. [params setValue:appDelegate.password forKey:@"password"];
  1651. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1652. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1653. [params setValue:keywords forKey:@"keyWord"];
  1654. [params setValue:customer forKey:@"customer_filter"];
  1655. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  1656. [params setValue:status_code forKey:@"orderStatus"];
  1657. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1658. if (keywords) {
  1659. [params setObject:@"Search" forKey:kAction];
  1660. }
  1661. NSData* json=nil;
  1662. if(appDelegate.offline_mode)
  1663. {
  1664. json= [OLDataProvider offline_orderlist:params];
  1665. }
  1666. else
  1667. {
  1668. if(![self IsNetworkAvailable])
  1669. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1670. json=[self get_json:URL_ORDER_LIST parameters:params];
  1671. }
  1672. if(json==nil)
  1673. return nil;
  1674. NSError *error=nil;
  1675. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1676. return jsobj;
  1677. }
  1678. +(NSDictionary*)request_PDFList:(int ) offset limit:(int)limit keywords:(NSString* ) keywords
  1679. {
  1680. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1681. __block AppDelegate *appDelegate = nil;
  1682. dispatch_sync(dispatch_get_main_queue(), ^{
  1683. //some UI methods ej
  1684. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1685. });
  1686. if(appDelegate.user!=nil)
  1687. [params setValue:appDelegate.user forKey:@"user"];
  1688. if(appDelegate.contact_id!=nil)
  1689. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1690. if(appDelegate.password!=nil)
  1691. [params setValue:appDelegate.password forKey:@"password"];
  1692. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  1693. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  1694. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  1695. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  1696. // [params setValue:filter forKey:@"filter"];
  1697. [params setValue:keywords forKey:@"keyWord"];
  1698. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  1699. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  1700. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  1701. if (keywords) {
  1702. [params setObject:@"Search" forKey:kAction];
  1703. }
  1704. NSData* json = nil;
  1705. if(appDelegate.offline_mode)
  1706. {
  1707. json = [OLDataProvider offline_pdfList:params];
  1708. } else {
  1709. if(![self IsNetworkAvailable])
  1710. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1711. json=[self get_json:URL_DM_LIST parameters:params];
  1712. }
  1713. if(json==nil)
  1714. return nil;
  1715. NSError *error=nil;
  1716. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1717. return jsobj;
  1718. }
  1719. //+(NSString*) create_portfolio:(NSMutableDictionary*)params
  1720. //{
  1721. // __block AppDelegate *appDelegate = nil;
  1722. //
  1723. // dispatch_sync(dispatch_get_main_queue(), ^{
  1724. // //some UI methods ej
  1725. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1726. // });
  1727. // if(appDelegate.offline_mode)
  1728. // {
  1729. //
  1730. //
  1731. // NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  1732. // if(json==nil)
  1733. // return nil;
  1734. // NSError *error=nil;
  1735. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1736. //
  1737. // return jsobj[@"pdf_path"];
  1738. // }
  1739. // else
  1740. // {
  1741. // return nil;
  1742. // }
  1743. //}
  1744. //+(NSDictionary*)direct_save_TearSheet:(NSMutableDictionary*)params//(NSString*) request_url name:(NSString*)name delete:(NSString* )ids note:(NSString* )saveNote modelIds:(NSDictionary *)modelIds
  1745. //{
  1746. // NSMutableDictionary* off_params = [params mutableCopy];;
  1747. //
  1748. // params[@"off_params"]=[RAConvertor dict2string:off_params];;
  1749. // __block AppDelegate *appDelegate = nil;
  1750. //
  1751. // dispatch_sync(dispatch_get_main_queue(), ^{
  1752. // //some UI methods ej
  1753. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1754. // });
  1755. // if(appDelegate.user!=nil)
  1756. // [params setValue:appDelegate.user forKey:@"user"];
  1757. // if(appDelegate.contact_id!=nil)
  1758. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1759. // if(appDelegate.password!=nil)
  1760. // [params setValue:appDelegate.password forKey:@"password"];
  1761. //
  1762. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1763. //
  1764. // /*
  1765. // [params setValue:request_url forKey:@"pdfUrl"];
  1766. // [params setValue:name forKey:@"pdfName"];
  1767. // [params setValue:ids forKey:@"itemIds"];
  1768. // [params setValue:saveNote forKey:@"pdfNote"];
  1769. // [params setValue:[modelIds objectForKey:@"product_ids"] forKey:@"product_ids"];
  1770. // [params setValue:[modelIds objectForKey:@"item_ids"] forKey:@"item_ids"];
  1771. // [params setValue:[modelIds objectForKey:@"remove_item"] forKey:@"remove_item"];
  1772. // */
  1773. // NSData* json= nil;
  1774. //
  1775. // if(appDelegate.offline_mode)
  1776. // {
  1777. // json = [OLDataProvider offline_direct_save_TearSheet:params];
  1778. // }
  1779. // else
  1780. // {
  1781. // if(![self IsNetworkAvailable])
  1782. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1783. //
  1784. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1785. //
  1786. // NSError *error=nil;
  1787. //
  1788. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1789. // params[@"resultSerial"]=uuid;
  1790. //
  1791. // for(int i=0;i<150;i++)
  1792. // {
  1793. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1794. // // result_params[@"resultSerial"]=uuid;
  1795. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1796. // if(json!=nil)
  1797. // {
  1798. //
  1799. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1800. // if([jsobj[@"result"] intValue]==2)
  1801. // {
  1802. // break;
  1803. // }
  1804. // }
  1805. // sleep(5);
  1806. // }
  1807. //
  1808. // }
  1809. // if(json==nil)
  1810. // return nil;
  1811. // NSError *error=nil;
  1812. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1813. // return jsobj;
  1814. //}
  1815. //+(NSDictionary*)request_TearSheet:(NSMutableDictionary*)params//(NSString*) request_url
  1816. //{
  1817. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1818. // __block AppDelegate *appDelegate = nil;
  1819. //
  1820. // dispatch_sync(dispatch_get_main_queue(), ^{
  1821. // //some UI methods ej
  1822. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1823. // });
  1824. // if(appDelegate.user!=nil)
  1825. // [params setValue:appDelegate.user forKey:@"user"];
  1826. // if(appDelegate.contact_id!=nil)
  1827. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1828. // if(appDelegate.password!=nil)
  1829. // [params setValue:appDelegate.password forKey:@"password"];
  1830. //
  1831. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1832. //
  1833. // // [params setValue:request_url forKey:@"pdfUrl"];
  1834. // NSData* json= nil;
  1835. // if(appDelegate.offline_mode)
  1836. // {
  1837. // json= [OLDataProvider offline_request_tearsheet:params];
  1838. // }
  1839. // else
  1840. // {
  1841. // if(![self IsNetworkAvailable])
  1842. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1843. //
  1844. // NSError *error=nil;
  1845. //
  1846. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1847. // params[@"resultSerial"]=uuid;
  1848. //
  1849. // for(int i=0;i<150;i++)
  1850. // {
  1851. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1852. // // result_params[@"resultSerial"]=uuid;
  1853. // json=[self get_json:URL_REQUEST_DM parameters:params];
  1854. // if(json!=nil)
  1855. // {
  1856. //
  1857. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1858. // if([jsobj[@"result"] intValue]==2)
  1859. // {
  1860. // break;
  1861. // }
  1862. // }
  1863. // sleep(5);
  1864. // }
  1865. // }
  1866. // if(json==nil)
  1867. // return nil;
  1868. // NSError *error=nil;
  1869. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1870. // return jsobj;
  1871. //}
  1872. //+(NSDictionary*)save_TearSheet:(NSMutableDictionary *)params//(NSString*) path name:(NSString*)name delete:(NSString* )ids note:(NSString*)note configureParams:(NSString *)configureParams modelIds:(NSDictionary *)modelIds
  1873. //{
  1874. //
  1875. //
  1876. // NSMutableDictionary* off_params = [params mutableCopy];;
  1877. //
  1878. // params[@"off_params"]=[RAConvertor dict2string:off_params];
  1879. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1880. // __block AppDelegate *appDelegate = nil;
  1881. //
  1882. // dispatch_sync(dispatch_get_main_queue(), ^{
  1883. // //some UI methods ej
  1884. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1885. // });
  1886. // if(appDelegate.user!=nil)
  1887. // [params setValue:appDelegate.user forKey:@"user"];
  1888. // if(appDelegate.contact_id!=nil)
  1889. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1890. // if(appDelegate.password!=nil)
  1891. // [params setValue:appDelegate.password forKey:@"password"];
  1892. //
  1893. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1894. //
  1895. // /*
  1896. // [params setValue:path forKey:@"pdfPath"];
  1897. // [params setValue:name forKey:@"pdfName"];
  1898. // [params setValue:note forKey:@"pdfNote"];
  1899. // [params setValue:ids forKey:@"itemIds"];
  1900. // [params setValue:configureParams forKey:@"configureParams"];
  1901. // [params setValue:[modelIds objectForKey:@"product_ids"] forKey:@"product_ids"];
  1902. // [params setValue:[modelIds objectForKey:@"item_ids"] forKey:@"item_ids"];
  1903. // [params setValue:[modelIds objectForKey:@"remove_item"] forKey:@"remove_item"];
  1904. // */
  1905. // NSData* json = nil;
  1906. // if(appDelegate.offline_mode)
  1907. // {
  1908. // json = [OLDataProvider offline_save_TearSheet:params];
  1909. // } else {
  1910. // if(![self IsNetworkAvailable])
  1911. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1912. //
  1913. // json=[self get_json:URL_SAVE_DM parameters:params];
  1914. // }
  1915. // if(json==nil)
  1916. // return nil;
  1917. // NSError *error=nil;
  1918. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1919. // return jsobj;
  1920. //}
  1921. +(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code//device:(NSString*) device
  1922. {
  1923. return nil;
  1924. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1925. __block AppDelegate *appDelegate = nil;
  1926. dispatch_sync(dispatch_get_main_queue(), ^{
  1927. //some UI methods ej
  1928. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1929. });
  1930. if(appDelegate.user!=nil)
  1931. [params setValue:appDelegate.user forKey:@"user"];
  1932. [params setValue:up_params forKey:@"upparam"];
  1933. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  1934. [params setValue:result forKey:@"result"];
  1935. [params setValue:module forKey:@"interfac"];
  1936. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  1937. // [params setValue:module forKey:@"module"];
  1938. // [[UIDevice currentDevice] name];
  1939. // if(appDelegate.offline_mode)
  1940. // {
  1941. // return [OLDataProvider offline_notimpl];
  1942. // }
  1943. if(![self IsNetworkAvailable])
  1944. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1945. NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  1946. if(json==nil)
  1947. return nil;
  1948. NSError *error=nil;
  1949. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1950. return jsobj;
  1951. }
  1952. //+(NSDictionary*)request_ContactList:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams
  1953. //{
  1954. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1955. //
  1956. // if(upparams!=nil)
  1957. // params = [upparams mutableCopy];
  1958. // __block AppDelegate *appDelegate = nil;
  1959. //
  1960. // dispatch_sync(dispatch_get_main_queue(), ^{
  1961. // //some UI methods ej
  1962. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1963. // });
  1964. // if(appDelegate.user!=nil)
  1965. // [params setValue:appDelegate.user forKey:@"user"];
  1966. //
  1967. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1968. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1969. // else
  1970. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1971. //
  1972. // if(appDelegate.password!=nil)
  1973. // [params setValue:appDelegate.password forKey:@"password"];
  1974. //
  1975. // [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1976. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1977. // [params setValue:contact_type forKey:@"contactType"];
  1978. // [params setValue:keywords forKey:@"keyword"];
  1979. //
  1980. // [params setObject:ScreenCodeAccount forKey:kScreenName];
  1981. // if (keywords) {
  1982. // [params setObject:@"Search" forKey:kAction];
  1983. // }
  1984. // if (upparams) {
  1985. // [params setObject:@"Advance Search" forKey:kAction];
  1986. // }
  1987. //
  1988. // NSString* url=nil;
  1989. // if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  1990. // url=URL_SHIPTO_LIST;
  1991. // else
  1992. // url=URL_CONTACT_LIST;
  1993. //
  1994. // if(appDelegate.offline_mode)
  1995. // return [OLDataProvider offline_contactlist:params];
  1996. //
  1997. // if(![self IsNetworkAvailable])
  1998. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1999. //
  2000. // NSData* json=[self get_json:url parameters:params];
  2001. // if(json==nil)
  2002. // return nil;
  2003. // NSError *error=nil;
  2004. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2005. // return jsobj;
  2006. //}
  2007. //+(NSDictionary*)request_OrderDetail:(NSMutableDictionary *) params
  2008. //{
  2009. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2010. // if (params == nil) {
  2011. // params = [[NSMutableDictionary alloc] init];
  2012. // }
  2013. // __block AppDelegate *appDelegate = nil;
  2014. //
  2015. // dispatch_sync(dispatch_get_main_queue(), ^{
  2016. // //some UI methods ej
  2017. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2018. // });
  2019. // if(appDelegate.user!=nil)
  2020. // [params setValue:appDelegate.user forKey:@"user"];
  2021. // if(appDelegate.contact_id!=nil)
  2022. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2023. // if(appDelegate.password!=nil)
  2024. // [params setValue:appDelegate.password forKey:@"password"];
  2025. //
  2026. //
  2027. // // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  2028. //
  2029. // [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  2030. //
  2031. // NSData* json=nil;
  2032. // if(appDelegate.offline_mode)
  2033. // {
  2034. // json= [OLDataProvider offline_orderdetail:params];
  2035. // }
  2036. // else
  2037. // {
  2038. // if(![self IsNetworkAvailable])
  2039. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2040. //
  2041. // NSError *error=nil;
  2042. //
  2043. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2044. // params[@"resultSerial"]=uuid;
  2045. //
  2046. // for(int i=0;i<150;i++)
  2047. // {
  2048. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2049. // // result_params[@"resultSerial"]=uuid;
  2050. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  2051. // if(json!=nil)
  2052. // {
  2053. //
  2054. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2055. // int resultCode = [jsobj[@"result"] intValue];
  2056. // if(resultCode==2 || resultCode == 8)
  2057. // {
  2058. // break;
  2059. // }
  2060. // }
  2061. // sleep(2);
  2062. // }
  2063. //
  2064. //
  2065. // }
  2066. // if(json==nil)
  2067. // return nil;
  2068. // NSError *error=nil;
  2069. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2070. // return jsobj;
  2071. //}
  2072. //+(NSDictionary*) add_toCart:(NSString* ) item_id count:(int) count name:(NSString *)name
  2073. //{
  2074. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2075. // __block AppDelegate *appDelegate = nil;
  2076. //
  2077. // dispatch_sync(dispatch_get_main_queue(), ^{
  2078. // //some UI methods ej
  2079. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2080. // });
  2081. // if(appDelegate.user!=nil)
  2082. // [params setValue:appDelegate.user forKey:@"user"];
  2083. // if(appDelegate.contact_id!=nil)
  2084. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2085. // if(appDelegate.password!=nil)
  2086. // [params setValue:appDelegate.password forKey:@"password"];
  2087. //
  2088. // if(appDelegate.order_code!=nil)
  2089. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2090. // [params setValue:item_id forKey:@"product_id"];
  2091. // [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  2092. //
  2093. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  2094. // [params setObject:@"Add To Cart" forKey:kAction];
  2095. // if (name) {
  2096. // NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  2097. // [params setObject:extra forKey:kExtra];
  2098. // }
  2099. //
  2100. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2101. //
  2102. // NSArray* keys=[customerinfo allKeys];
  2103. // for(int i=0;i<keys.count;i++)
  2104. // {
  2105. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2106. // }
  2107. //
  2108. // NSData* json=nil;
  2109. // if(appDelegate.offline_mode)
  2110. // {
  2111. // json=[OLDataProvider offline_add2cart:params];
  2112. // }
  2113. // else
  2114. // {
  2115. // if(![self IsNetworkAvailable])
  2116. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2117. //
  2118. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  2119. // }
  2120. // if(json==nil)
  2121. // return nil;
  2122. // NSError *error=nil;
  2123. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2124. //
  2125. //
  2126. //
  2127. // int result = [[jsobj valueForKey:@"result"] intValue];
  2128. //
  2129. // if (result==2)
  2130. // {
  2131. //
  2132. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2133. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2134. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2135. //
  2136. // [appDelegate update_count_mark];
  2137. // }
  2138. //
  2139. // return jsobj;
  2140. //}
  2141. //+(NSDictionary*) add_toCart_byName:(NSString* ) model_name withScreen:(NSString *)screenName
  2142. //{
  2143. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2144. // __block AppDelegate *appDelegate = nil;
  2145. //
  2146. // dispatch_sync(dispatch_get_main_queue(), ^{
  2147. // //some UI methods ej
  2148. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2149. // });
  2150. // if(appDelegate.user!=nil)
  2151. // [params setValue:appDelegate.user forKey:@"user"];
  2152. // if(appDelegate.contact_id!=nil)
  2153. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2154. // if(appDelegate.password!=nil)
  2155. // [params setValue:appDelegate.password forKey:@"password"];
  2156. //
  2157. // if(appDelegate.order_code!=nil)
  2158. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2159. // [params setValue:model_name forKey:@"product_name"];
  2160. // [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  2161. //
  2162. // [params setObject:screenName forKey:kScreenName];
  2163. // [params setObject:@"Add To Cart" forKey:kAction];
  2164. // if (!model_name) {
  2165. // model_name = @"";
  2166. // }
  2167. // [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  2168. //
  2169. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2170. //
  2171. // NSArray* keys=[customerinfo allKeys];
  2172. // for(int i=0;i<keys.count;i++)
  2173. // {
  2174. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2175. // }
  2176. // NSData* json=nil;
  2177. // if(appDelegate.offline_mode)
  2178. // {
  2179. // json= [OLDataProvider offline_add2cartbyname:params];
  2180. // }
  2181. // else
  2182. // {
  2183. // if(![self IsNetworkAvailable])
  2184. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2185. //
  2186. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  2187. // }
  2188. // if(json==nil)
  2189. // return nil;
  2190. // NSError *error=nil;
  2191. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2192. //
  2193. //
  2194. //
  2195. // int result = [[jsobj valueForKey:@"result"] intValue];
  2196. //
  2197. // if (result==2||result==8)
  2198. // {
  2199. //
  2200. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2201. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2202. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2203. //
  2204. // [appDelegate update_count_mark];
  2205. // }
  2206. //
  2207. // return jsobj;
  2208. //}
  2209. //+(NSDictionary*) new_Customer
  2210. //{
  2211. // if(![self IsNetworkAvailable])
  2212. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2213. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2214. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2215. // if(appDelegate.user!=nil)
  2216. // [params setValue:appDelegate.user forKey:@"user"];
  2217. //// if(appDelegate.contact_id!=nil)
  2218. //// [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2219. // if(appDelegate.password!=nil)
  2220. // [params setValue:appDelegate.password forKey:@"password"];
  2221. //
  2222. //// if(appDelegate.order_code!=nil)
  2223. //// [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2224. //
  2225. //
  2226. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2227. //
  2228. // NSArray* keys=[customerinfo allKeys];
  2229. // for(int i=0;i<keys.count;i++)
  2230. // {
  2231. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2232. // }
  2233. //
  2234. // NSData* json=[self get_json:URL_CUSTOMER_EDIT parameters:params];
  2235. // if(json==nil)
  2236. // return nil;
  2237. // NSError *error=nil;
  2238. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2239. // return jsobj;
  2240. //}
  2241. //+(NSDictionary*) new_Order
  2242. //{
  2243. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2244. // __block AppDelegate *appDelegate = nil;
  2245. //
  2246. // dispatch_sync(dispatch_get_main_queue(), ^{
  2247. // //some UI methods ej
  2248. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2249. // });
  2250. // if(appDelegate.user!=nil)
  2251. // [params setValue:appDelegate.user forKey:@"user"];
  2252. // if(appDelegate.contact_id!=nil)
  2253. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2254. // if(appDelegate.password!=nil)
  2255. // [params setValue:appDelegate.password forKey:@"password"];
  2256. //
  2257. // if(appDelegate.order_code!=nil)
  2258. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2259. //
  2260. //
  2261. // [params setObject:ScreenCodeOrderList forKey:kScreenName];
  2262. //
  2263. // NSDictionary* customerinfo= appDelegate.customerInfo;
  2264. //
  2265. // NSArray* keys=[customerinfo allKeys];
  2266. // for(int i=0;i<keys.count;i++)
  2267. // {
  2268. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  2269. // }
  2270. //
  2271. // NSData* json = nil;
  2272. // if(appDelegate.offline_mode)
  2273. // {
  2274. // json= [OLDataProvider offline_createorder:params];
  2275. // }
  2276. // else
  2277. // {
  2278. // if(![self IsNetworkAvailable])
  2279. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2280. //
  2281. // json=[self get_json:URL_NEW_ORDER parameters:params];
  2282. // }
  2283. // if(json==nil)
  2284. // return nil;
  2285. // NSError *error=nil;
  2286. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2287. // int result = [[jsobj valueForKey:@"result"] intValue];
  2288. //
  2289. // if (result==2)
  2290. // {
  2291. //
  2292. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2293. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2294. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2295. //
  2296. // [appDelegate update_count_mark];
  2297. // }
  2298. //
  2299. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  2300. //
  2301. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  2302. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  2303. // }
  2304. //
  2305. // return jsobj;
  2306. //}
  2307. +(NSDictionary*) add_toPortfolio:(NSString* ) item_id withScreen:(NSString *)screenName
  2308. {
  2309. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2310. __block AppDelegate *appDelegate = nil;
  2311. dispatch_sync(dispatch_get_main_queue(), ^{
  2312. //some UI methods ej
  2313. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2314. });
  2315. if(appDelegate.user!=nil)
  2316. [params setValue:appDelegate.user forKey:@"user"];
  2317. if(appDelegate.contact_id!=nil)
  2318. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2319. if(appDelegate.password!=nil)
  2320. [params setValue:appDelegate.password forKey:@"password"];
  2321. [params setValue:item_id forKey:@"product_id"];
  2322. [params setObject:screenName forKey:kScreenName];
  2323. NSData* json = nil;
  2324. if(appDelegate.offline_mode)
  2325. {
  2326. json = [OLDataProvider offline_add2Portfolio:params];
  2327. } else {
  2328. if(![self IsNetworkAvailable])
  2329. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2330. json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  2331. }
  2332. if(json==nil)
  2333. return nil;
  2334. NSError *error=nil;
  2335. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2336. int result = [[jsobj valueForKey:@"result"] intValue];
  2337. if (result==2)
  2338. {
  2339. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2340. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2341. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2342. [appDelegate update_count_mark];
  2343. }
  2344. return jsobj;
  2345. }
  2346. //+(NSDictionary*) add_toWatchList:(NSString* ) item_id withScreen:(NSString *)screenName
  2347. //{
  2348. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2349. // __block AppDelegate *appDelegate = nil;
  2350. //
  2351. // dispatch_sync(dispatch_get_main_queue(), ^{
  2352. // //some UI methods ej
  2353. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2354. // });
  2355. // if(appDelegate.user!=nil)
  2356. // [params setValue:appDelegate.user forKey:@"user"];
  2357. // if(appDelegate.contact_id!=nil)
  2358. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2359. // if(appDelegate.password!=nil)
  2360. // [params setValue:appDelegate.password forKey:@"password"];
  2361. //
  2362. //
  2363. // [params setValue:item_id forKey:@"product_id"];
  2364. //
  2365. // [params setObject:screenName forKey:kScreenName];
  2366. //
  2367. // if(appDelegate.offline_mode)
  2368. // {
  2369. // return [OLDataProvider offline_add2wishlist:params];
  2370. // }
  2371. // if(![self IsNetworkAvailable])
  2372. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2373. //
  2374. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  2375. // if(json==nil)
  2376. // return nil;
  2377. // NSError *error=nil;
  2378. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2379. // int result = [[jsobj valueForKey:@"result"] intValue];
  2380. //
  2381. // if (result==2)
  2382. // {
  2383. //
  2384. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2385. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  2386. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2387. //
  2388. // [appDelegate update_count_mark];
  2389. // }
  2390. // return jsobj;
  2391. //}
  2392. //+(NSDictionary*) cart_setPrice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes
  2393. //{
  2394. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2395. // __block AppDelegate *appDelegate = nil;
  2396. //
  2397. // dispatch_sync(dispatch_get_main_queue(), ^{
  2398. // //some UI methods ej
  2399. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2400. // });
  2401. // if(appDelegate.user!=nil)
  2402. // [params setValue:appDelegate.user forKey:@"user"];
  2403. // if(appDelegate.contact_id!=nil)
  2404. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2405. // if(appDelegate.password!=nil)
  2406. // [params setValue:appDelegate.password forKey:@"password"];
  2407. //
  2408. // [params setValue:cart_id forKey:@"cartitem_id"];
  2409. // [params setValue:notes forKey:@"item_note"];
  2410. //
  2411. // [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  2412. //
  2413. // [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  2414. //
  2415. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2416. //
  2417. // NSData* json= nil;
  2418. // if(appDelegate.offline_mode)
  2419. // {
  2420. // json=[OLDataProvider offline_cartsetprice:params];
  2421. // }
  2422. // else
  2423. // {
  2424. // if(![self IsNetworkAvailable])
  2425. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2426. //
  2427. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2428. // }
  2429. // if(json==nil)
  2430. // return nil;
  2431. // NSError *error=nil;
  2432. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2433. // return jsobj;
  2434. //}
  2435. //+(NSDictionary*) portfolio_setQTY:(NSString*) watchlist_id QTY:(int)qty
  2436. //{
  2437. // if(![self IsNetworkAvailable])
  2438. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2439. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2440. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2441. // if(appDelegate.user!=nil)
  2442. // [params setValue:appDelegate.user forKey:@"user"];
  2443. // if(appDelegate.contact_id!=nil)
  2444. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2445. // if(appDelegate.password!=nil)
  2446. // [params setValue:appDelegate.password forKey:@"password"];
  2447. //
  2448. // [params setValue:watchlist_id forKey:@"item_id"];
  2449. //
  2450. // [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  2451. //
  2452. //
  2453. //
  2454. // NSData* json=[self get_json:URL_DM_SET_QTY parameters:params];
  2455. // if(json==nil)
  2456. // return nil;
  2457. // NSError *error=nil;
  2458. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2459. // return jsobj;
  2460. //}
  2461. +(NSDictionary*) portfolio_setPrice:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes
  2462. {
  2463. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2464. __block AppDelegate *appDelegate = nil;
  2465. dispatch_sync(dispatch_get_main_queue(), ^{
  2466. //some UI methods ej
  2467. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2468. });
  2469. if(appDelegate.user!=nil)
  2470. [params setValue:appDelegate.user forKey:@"user"];
  2471. if(appDelegate.contact_id!=nil)
  2472. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2473. if(appDelegate.password!=nil)
  2474. [params setValue:appDelegate.password forKey:@"password"];
  2475. [params setValue:watchlist_id forKey:@"item_id"];
  2476. // if(notes.length>0)
  2477. // [params setValue:notes forKey:@"notes"];
  2478. if(notes)
  2479. [params setValue:notes forKey:@"notes"];
  2480. if(price != -MAXFLOAT)
  2481. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  2482. if (discount != -MAXFLOAT)
  2483. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  2484. if(qty_p != -MAXFLOAT)
  2485. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  2486. if(qty != -INT32_MAX)
  2487. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  2488. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2489. NSData* json = nil;
  2490. if(appDelegate.offline_mode)
  2491. {
  2492. json = [OLDataProvider offline_editPortfolio:params];
  2493. } else {
  2494. if(![self IsNetworkAvailable])
  2495. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2496. json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  2497. }
  2498. if(json==nil)
  2499. return nil;
  2500. NSError *error=nil;
  2501. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2502. return jsobj;
  2503. }
  2504. //+(NSDictionary*) cart_setGeneralNote:(NSString*) order_code notes:(NSString*) notes
  2505. //{
  2506. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2507. // __block AppDelegate *appDelegate = nil;
  2508. //
  2509. // dispatch_sync(dispatch_get_main_queue(), ^{
  2510. // //some UI methods ej
  2511. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2512. // });
  2513. // if(appDelegate.user!=nil)
  2514. // [params setValue:appDelegate.user forKey:@"user"];
  2515. // if(appDelegate.contact_id!=nil)
  2516. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2517. // if(appDelegate.password!=nil)
  2518. // [params setValue:appDelegate.password forKey:@"password"];
  2519. //
  2520. // [params setValue:order_code forKey:@"orderCode"];
  2521. //
  2522. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2523. //
  2524. // if(notes.length==0)
  2525. // notes=@"";
  2526. //
  2527. //
  2528. // [params setValue:notes forKey:@"comments"];
  2529. // NSData* json=nil;
  2530. // if(appDelegate.offline_mode)
  2531. // {
  2532. // json= [OLDataProvider offline_updategnotes:params];
  2533. // }
  2534. // else
  2535. // {
  2536. // if(![self IsNetworkAvailable])
  2537. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2538. //
  2539. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  2540. // }
  2541. // if(json==nil)
  2542. // return nil;
  2543. // NSError *error=nil;
  2544. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2545. // return jsobj;
  2546. //}
  2547. //+(NSDictionary*) cart_setItemNote:(NSString*) cart_id notes:(NSString*) notes
  2548. //{
  2549. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2550. // __block AppDelegate *appDelegate = nil;
  2551. //
  2552. // dispatch_sync(dispatch_get_main_queue(), ^{
  2553. // //some UI methods ej
  2554. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2555. // });
  2556. // if(appDelegate.user!=nil)
  2557. // [params setValue:appDelegate.user forKey:@"user"];
  2558. // if(appDelegate.contact_id!=nil)
  2559. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2560. // if(appDelegate.password!=nil)
  2561. // [params setValue:appDelegate.password forKey:@"password"];
  2562. //
  2563. // [params setValue:cart_id forKey:@"cartitem_id"];
  2564. //
  2565. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2566. //
  2567. // if(notes.length==0)
  2568. // notes=@"";
  2569. //
  2570. //
  2571. // [params setValue:notes forKey:@"notes"];
  2572. // NSData* json=nil;
  2573. // if(appDelegate.offline_mode)
  2574. // {
  2575. // json= [OLDataProvider offline_cartsetlnotes:params];
  2576. // }
  2577. // else
  2578. // {
  2579. // if(![self IsNetworkAvailable])
  2580. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2581. //
  2582. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  2583. // }
  2584. // if(json==nil)
  2585. // return nil;
  2586. // NSError *error=nil;
  2587. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2588. // return jsobj;
  2589. //}
  2590. //+(NSDictionary*) cart_setFree:(NSString*) cart_id isfree:(bool) isfree
  2591. //{
  2592. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2593. // __block AppDelegate *appDelegate = nil;
  2594. //
  2595. // dispatch_sync(dispatch_get_main_queue(), ^{
  2596. // //some UI methods ej
  2597. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2598. // });
  2599. // if(appDelegate.user!=nil)
  2600. // [params setValue:appDelegate.user forKey:@"user"];
  2601. // if(appDelegate.contact_id!=nil)
  2602. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2603. // if(appDelegate.password!=nil)
  2604. // [params setValue:appDelegate.password forKey:@"password"];
  2605. //
  2606. // [params setValue:cart_id forKey:@"cartitem_id"];
  2607. //
  2608. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2609. //
  2610. // NSString* free=nil;
  2611. //
  2612. // if(isfree)
  2613. // free=@"true";
  2614. // else
  2615. // free=@"false";
  2616. //
  2617. // [params setValue:free forKey:@"free_giveaway"];
  2618. //
  2619. // if(appDelegate.offline_mode)
  2620. // {
  2621. // return [OLDataProvider offline_notimpl];
  2622. // }
  2623. // if(![self IsNetworkAvailable])
  2624. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2625. //
  2626. // NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2627. // if(json==nil)
  2628. // return nil;
  2629. // NSError *error=nil;
  2630. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2631. // return jsobj;
  2632. //}
  2633. //+(NSDictionary*) cart_setQTY:(NSString*) cart_id value:(int) value
  2634. //{
  2635. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2636. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2637. // if(appDelegate.user!=nil)
  2638. // [params setValue:appDelegate.user forKey:@"user"];
  2639. // if(appDelegate.contact_id!=nil)
  2640. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2641. // if(appDelegate.password!=nil)
  2642. // [params setValue:appDelegate.password forKey:@"password"];
  2643. //
  2644. // [params setValue:cart_id forKey:@"cartitem_id"];
  2645. //
  2646. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2647. //
  2648. // [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  2649. //
  2650. // NSData* json=nil;
  2651. // if(appDelegate.offline_mode)
  2652. // {
  2653. // json= [OLDataProvider offline_cartsetqty:params];
  2654. // }
  2655. // else
  2656. // {
  2657. // if(![self IsNetworkAvailable])
  2658. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2659. //
  2660. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2661. // }
  2662. // if(json==nil)
  2663. // return nil;
  2664. // NSError *error=nil;
  2665. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2666. // return jsobj;
  2667. //
  2668. //}
  2669. //+(NSDictionary*) cart_incresement:(NSString*) cart_id increse:(bool) increse
  2670. //{
  2671. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2672. // __block AppDelegate *appDelegate = nil;
  2673. //
  2674. // dispatch_sync(dispatch_get_main_queue(), ^{
  2675. // //some UI methods ej
  2676. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2677. // });
  2678. // if(appDelegate.user!=nil)
  2679. // [params setValue:appDelegate.user forKey:@"user"];
  2680. // if(appDelegate.contact_id!=nil)
  2681. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2682. // if(appDelegate.password!=nil)
  2683. // [params setValue:appDelegate.password forKey:@"password"];
  2684. //
  2685. // [params setValue:cart_id forKey:@"cartitem_id"];
  2686. //
  2687. // if(increse)
  2688. // [params setValue:@"1" forKey:@"incrementType"];
  2689. // else
  2690. // [params setValue:@"0" forKey:@"incrementType"];
  2691. //
  2692. //
  2693. //
  2694. // if(appDelegate.offline_mode)
  2695. // {
  2696. // return [OLDataProvider offline_notimpl];
  2697. // }
  2698. // if(![self IsNetworkAvailable])
  2699. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2700. //
  2701. // NSData* json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2702. // if(json==nil)
  2703. // return nil;
  2704. // NSError *error=nil;
  2705. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2706. // return jsobj;
  2707. //}
  2708. +(NSDictionary*) finish_download_Offline:(NSString* )vid
  2709. {
  2710. if(![self IsNetworkAvailable])
  2711. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2712. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2713. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  2714. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2715. // if(appDelegate.user!=nil)
  2716. // [params setValue:appDelegate.user forKey:@"user"];
  2717. // // if(appDelegate.contact_id!=nil)
  2718. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2719. // if(appDelegate.password!=nil)
  2720. // [params setValue:appDelegate.password forKey:@"password"];
  2721. [params setValue:vid forKey:@"downSerial"];
  2722. NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  2723. if(json==nil)
  2724. return nil;
  2725. NSError *error=nil;
  2726. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2727. // int result = [[jsobj valueForKey:@"result"] intValue];
  2728. //
  2729. // if (result==2)
  2730. // {
  2731. //
  2732. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2733. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2734. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2735. ////
  2736. //// [appDelegate update_count_mark];
  2737. // }
  2738. return jsobj;
  2739. }
  2740. +(NSDictionary*) download_Offline:(NSString* )vid
  2741. {
  2742. if(![self IsNetworkAvailable])
  2743. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2744. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2745. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2746. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2747. // if(appDelegate.user!=nil)
  2748. // [params setValue:appDelegate.user forKey:@"user"];
  2749. // // if(appDelegate.contact_id!=nil)
  2750. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2751. // if(appDelegate.password!=nil)
  2752. // [params setValue:appDelegate.password forKey:@"password"];
  2753. [params setValue:vid forKey:@"downSerial"];
  2754. NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  2755. if(json==nil)
  2756. return nil;
  2757. NSError *error=nil;
  2758. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2759. // int result = [[jsobj valueForKey:@"result"] intValue];
  2760. //
  2761. // if (result==2)
  2762. // {
  2763. //
  2764. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2765. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2766. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2767. ////
  2768. //// [appDelegate update_count_mark];
  2769. // }
  2770. return jsobj;
  2771. }
  2772. +(NSDictionary*) check_Offline:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid
  2773. {
  2774. if(![self IsNetworkAvailable])
  2775. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2776. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2777. __block AppDelegate *appDelegate = nil;
  2778. dispatch_sync(dispatch_get_main_queue(), ^{
  2779. //some UI methods ej
  2780. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2781. });
  2782. if(appDelegate.user!=nil)
  2783. [params setValue:appDelegate.user forKey:@"user"];
  2784. // if(appDelegate.contact_id!=nil)
  2785. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2786. if(appDelegate.password!=nil)
  2787. [params setValue:appDelegate.password forKey:@"password"];
  2788. [params setValue:ver forKey:@"ver"];
  2789. [params setValue:vid forKey:@"vid"];
  2790. if(buseinternaladdress)
  2791. [params setValue:@"true" forKey:@"internal_address"];
  2792. else
  2793. [params setValue:@"false" forKey:@"internal_address"];
  2794. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2795. NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  2796. if(json==nil)
  2797. return nil;
  2798. NSError *error=nil;
  2799. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2800. // int result = [[jsobj valueForKey:@"result"] intValue];
  2801. //
  2802. // if (result==2)
  2803. // {
  2804. //
  2805. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2806. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2807. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2808. ////
  2809. //// [appDelegate update_count_mark];
  2810. // }
  2811. return jsobj;
  2812. }
  2813. //+(NSDictionary*)request_Cart:(int)sort
  2814. //{
  2815. //
  2816. // DebugLog(@"iSalesNetwork::request_Cart");
  2817. //
  2818. //
  2819. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2820. // __block AppDelegate *appDelegate = nil;
  2821. //
  2822. // dispatch_sync(dispatch_get_main_queue(), ^{
  2823. // //some UI methods ej
  2824. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2825. // });
  2826. // if(appDelegate.user!=nil)
  2827. // [params setValue:appDelegate.user forKey:@"user"];
  2828. // // if(appDelegate.contact_id!=nil)
  2829. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2830. // if(appDelegate.password!=nil)
  2831. // [params setValue:appDelegate.password forKey:@"password"];
  2832. //
  2833. // if(appDelegate.order_code!=nil)
  2834. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2835. //
  2836. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2837. //
  2838. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2839. //
  2840. // NSData* json=nil;
  2841. // if(appDelegate.offline_mode)
  2842. // {
  2843. // json= [OLDataProvider offline_requestcart:params];
  2844. // }
  2845. // else
  2846. // {
  2847. // if(![self IsNetworkAvailable])
  2848. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2849. //
  2850. // NSError *error=nil;
  2851. //
  2852. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2853. // params[@"resultSerial"]=uuid;
  2854. //
  2855. // for(int i=0;i<150;i++)
  2856. // {
  2857. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2858. // // result_params[@"resultSerial"]=uuid;
  2859. // json=[self get_json:URL_CART parameters:params];
  2860. // if(json!=nil)
  2861. // {
  2862. //
  2863. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2864. // if([jsobj[@"result"] intValue]==2)
  2865. // {
  2866. // break;
  2867. // }
  2868. // }
  2869. // sleep(2);
  2870. // }
  2871. //
  2872. // }
  2873. // if(json==nil)
  2874. // return nil;
  2875. // NSError *error=nil;
  2876. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2877. // int result = [[jsobj valueForKey:@"result"] intValue];
  2878. //
  2879. // if (result==2)
  2880. // {
  2881. //
  2882. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2883. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2884. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2885. //
  2886. // [appDelegate update_count_mark];
  2887. // }
  2888. // return jsobj;
  2889. //}
  2890. //+(NSDictionary*)request_Portfolio:(int)sort
  2891. //{
  2892. //
  2893. //
  2894. //
  2895. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2896. // __block AppDelegate *appDelegate = nil;
  2897. //
  2898. // dispatch_sync(dispatch_get_main_queue(), ^{
  2899. // //some UI methods ej
  2900. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2901. // });
  2902. // if(appDelegate.user!=nil)
  2903. // [params setValue:appDelegate.user forKey:@"user"];
  2904. // if(appDelegate.contact_id!=nil)
  2905. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2906. // if(appDelegate.password!=nil)
  2907. // [params setValue:appDelegate.password forKey:@"password"];
  2908. //
  2909. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2910. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2911. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2912. //
  2913. // [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2914. //
  2915. // NSData* json = nil;
  2916. // if(appDelegate.offline_mode)
  2917. // {
  2918. // json = [OLDataProvider offline_portfolioList:params];
  2919. // } else {
  2920. // if(![self IsNetworkAvailable])
  2921. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2922. //
  2923. // json = [self get_json:URL_PORTFOLIO parameters:params];
  2924. // }
  2925. //
  2926. //
  2927. // if(json==nil)
  2928. // return nil;
  2929. // NSError *error=nil;
  2930. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2931. // int result = [[jsobj valueForKey:@"result"] intValue];
  2932. //
  2933. // if (result==2)
  2934. // {
  2935. //
  2936. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2937. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2938. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  2939. //
  2940. // [appDelegate update_count_mark];
  2941. // }
  2942. // return jsobj;
  2943. //}
  2944. //+(NSDictionary*)request_WatchList:(int)sort
  2945. //{
  2946. //
  2947. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2948. // __block AppDelegate *appDelegate = nil;
  2949. //
  2950. // dispatch_sync(dispatch_get_main_queue(), ^{
  2951. // //some UI methods ej
  2952. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2953. // });
  2954. // if(appDelegate.user!=nil)
  2955. // [params setValue:appDelegate.user forKey:@"user"];
  2956. // if(appDelegate.contact_id!=nil)
  2957. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2958. // if(appDelegate.password!=nil)
  2959. // [params setValue:appDelegate.password forKey:@"password"];
  2960. //
  2961. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2962. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2963. //
  2964. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2965. //
  2966. // [params setObject:ScreenCodeWishList forKey:kScreenName];
  2967. //
  2968. // if(appDelegate.offline_mode)
  2969. // {
  2970. // return [OLDataProvider offline_wishlist:params];
  2971. // }
  2972. // if(![self IsNetworkAvailable])
  2973. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2974. //
  2975. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  2976. // if(json==nil)
  2977. // return nil;
  2978. // NSError *error=nil;
  2979. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2980. // int result = [[jsobj valueForKey:@"result"] intValue];
  2981. //
  2982. // if (result==2)
  2983. // {
  2984. //
  2985. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2986. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2987. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2988. //
  2989. // [appDelegate update_count_mark];
  2990. // }
  2991. // return jsobj;
  2992. //}
  2993. //+(NSDictionary*)request_ItemDetail: (NSString* ) item_id model_name:(NSString*) model_name category_id:(NSString*) category_id use_name :(bool) use_name groupName:(NSString *)groupName
  2994. //{
  2995. //
  2996. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2997. // __block AppDelegate *appDelegate = nil;
  2998. //
  2999. // dispatch_sync(dispatch_get_main_queue(), ^{
  3000. // //some UI methods ej
  3001. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3002. // });
  3003. // if(appDelegate.user!=nil)
  3004. // [params setValue:appDelegate.user forKey:@"user"];
  3005. // if(appDelegate.contact_id!=nil)
  3006. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3007. // if(appDelegate.password!=nil)
  3008. // [params setValue:appDelegate.password forKey:@"password"];
  3009. // if(appDelegate.order_code!=nil)
  3010. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3011. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3012. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3013. // if(use_name)
  3014. // [params setValue:model_name forKey:@"product_name"];
  3015. // else
  3016. // [params setValue:item_id forKey:@"product_id"];
  3017. //
  3018. //
  3019. // [params setValue:category_id forKey:@"category"];
  3020. //
  3021. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  3022. // [params setObject:@"Open A Model" forKey:kAction];
  3023. // if (model_name) {
  3024. // NSDictionary *extra = @{@"ModelName" : model_name};
  3025. // [params setObject:extra forKey:kExtra];
  3026. // }
  3027. //
  3028. // if (groupName.length > 0) {
  3029. // [params setObject:groupName forKey:@"groupName"];
  3030. // }
  3031. //
  3032. // if(appDelegate.offline_mode)
  3033. // return [OLDataProvider offline_model:params];
  3034. //
  3035. // if(![self IsNetworkAvailable])
  3036. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3037. //
  3038. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  3039. // if(json==nil)
  3040. // return nil;
  3041. // NSError *error=nil;
  3042. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3043. // return jsobj;
  3044. //}
  3045. //+(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
  3046. //{
  3047. // if(![self IsNetworkAvailable])
  3048. // return nil;
  3049. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3050. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3051. // if(appDelegate.user!=nil)
  3052. // [params setValue:appDelegate.user forKey:@"user"];
  3053. // if(appDelegate.contact_id!=nil)
  3054. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3055. // if(appDelegate.password!=nil)
  3056. // [params setValue:appDelegate.password forKey:@"password"];
  3057. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3058. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3059. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3060. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3061. // [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  3062. // [params setValue:filter forKey:@"filter"];
  3063. // [params setValue:keyword forKey:@"keyword"];
  3064. //
  3065. //
  3066. // NSData* json=[self get_json:URL_CATEGORY_LOADMORE parameters:params];
  3067. // if(json==nil)
  3068. // return nil;
  3069. // NSError *error=nil;
  3070. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3071. // return jsobj;
  3072. //
  3073. //}
  3074. //+(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
  3075. //
  3076. //{
  3077. //
  3078. //
  3079. // __block AppDelegate *appDelegate = nil;
  3080. //
  3081. // dispatch_sync(dispatch_get_main_queue(), ^{
  3082. // //some UI methods ej
  3083. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3084. // });
  3085. //
  3086. //
  3087. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3088. //
  3089. // if(appDelegate.user!=nil)
  3090. // [params setValue:appDelegate.user forKey:@"user"];
  3091. // if(appDelegate.contact_id!=nil)
  3092. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3093. // if(appDelegate.password!=nil)
  3094. // [params setValue:appDelegate.password forKey:@"password"];
  3095. // if(appDelegate.order_code!=nil)
  3096. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3097. //
  3098. // [params setValue:addTo forKey:@"addTo"];
  3099. // [params setValue:orderCode forKey:@"orderCode"];
  3100. // [params setValue:alert forKey:@"alert"];
  3101. // [params setValue:qty forKey:@"sold_by_qty"];
  3102. // [params setValue:available forKey:@"available"];
  3103. // [params setValue:price forKey:@"price"];
  3104. // [params setValue:bestseller forKey:@"bestseller"];
  3105. // [params setValue:modelname forKey:@"modelName"];
  3106. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3107. //
  3108. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3109. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3110. // [params setValue:category forKey:@"category"];
  3111. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3112. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3113. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3114. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3115. // [params setValue:filter forKey:@"filter"];
  3116. // [params setValue:keyword forKey:@"keyword"];
  3117. //
  3118. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  3119. // if ([addTo isEqualToString:@"cart"]) {
  3120. // [params setObject:@"Add To Cart" forKey:kAction];
  3121. // }
  3122. //
  3123. //
  3124. // NSData* json= nil;
  3125. //
  3126. // if(appDelegate.offline_mode)
  3127. // {
  3128. // json= [OLDataProvider offline_categoryaddall:params];
  3129. // }
  3130. // else
  3131. // {
  3132. // if(![self IsNetworkAvailable])
  3133. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3134. //
  3135. //
  3136. // NSError *error=nil;
  3137. //
  3138. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3139. // params[@"resultSerial"]=uuid;
  3140. //
  3141. // for(int i=0;i<150;i++)
  3142. // {
  3143. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3144. // // result_params[@"resultSerial"]=uuid;
  3145. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  3146. // if(json!=nil)
  3147. // {
  3148. //
  3149. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3150. // int resultInt = [jsobj[@"result"] intValue];
  3151. // if(resultInt == 2 || resultInt == 8)
  3152. // {
  3153. // break;
  3154. // }
  3155. // }
  3156. // sleep(2);
  3157. // }
  3158. //
  3159. //
  3160. //
  3161. // }
  3162. // if(json==nil)
  3163. // return nil;
  3164. // NSError *error=nil;
  3165. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3166. // return jsobj;
  3167. //
  3168. //}
  3169. //+(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
  3170. //{
  3171. //
  3172. //
  3173. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3174. //
  3175. //
  3176. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3177. //
  3178. // if(appDelegate.user!=nil)
  3179. // [params setValue:appDelegate.user forKey:@"user"];
  3180. // if(appDelegate.contact_id!=nil)
  3181. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3182. // if(appDelegate.password!=nil)
  3183. // [params setValue:appDelegate.password forKey:@"password"];
  3184. // if(appDelegate.order_code!=nil)
  3185. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3186. //
  3187. // [params setValue:alert forKey:@"alert"];
  3188. // [params setValue:qty forKey:@"sold_by_qty"];
  3189. // [params setValue:available forKey:@"available"];
  3190. // [params setValue:price forKey:@"price"];
  3191. // [params setValue:bestseller forKey:@"bestseller"];
  3192. // [params setValue:modelname forKey:@"modelName"];
  3193. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3194. //
  3195. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3196. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3197. // [params setValue:category forKey:@"category"];
  3198. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3199. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3200. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3201. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3202. // [params setValue:filter forKey:@"filter"];
  3203. // [params setValue:keyword forKey:@"keyword"];
  3204. //
  3205. //
  3206. //
  3207. // if(appDelegate.offline_mode)
  3208. // return [OLDataProvider offline_category:params];
  3209. // if(![self IsNetworkAvailable])
  3210. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3211. //
  3212. // NSData* json=[self get_json:URL_ADDALL2PORTFOLIO parameters:params];
  3213. // if(json==nil)
  3214. // return nil;
  3215. // NSError *error=nil;
  3216. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3217. // return jsobj;
  3218. //
  3219. //}
  3220. //+(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
  3221. //{
  3222. //
  3223. //
  3224. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3225. //
  3226. //
  3227. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3228. //
  3229. // if(appDelegate.user!=nil)
  3230. // [params setValue:appDelegate.user forKey:@"user"];
  3231. // if(appDelegate.contact_id!=nil)
  3232. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3233. // if(appDelegate.password!=nil)
  3234. // [params setValue:appDelegate.password forKey:@"password"];
  3235. // if(appDelegate.order_code!=nil)
  3236. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3237. //
  3238. // [params setValue:alert forKey:@"alert"];
  3239. // [params setValue:qty forKey:@"sold_by_qty"];
  3240. // [params setValue:available forKey:@"available"];
  3241. // [params setValue:price forKey:@"price"];
  3242. // [params setValue:bestseller forKey:@"bestseller"];
  3243. // [params setValue:modelname forKey:@"modelName"];
  3244. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3245. //
  3246. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3247. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3248. // [params setValue:category forKey:@"category"];
  3249. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3250. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3251. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3252. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3253. // [params setValue:filter forKey:@"filter"];
  3254. // [params setValue:keyword forKey:@"keyword"];
  3255. //
  3256. //
  3257. //
  3258. // if(appDelegate.offline_mode)
  3259. // return [OLDataProvider offline_category:params];
  3260. // if(![self IsNetworkAvailable])
  3261. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3262. //
  3263. // NSData* json=[self get_json:URL_ADDALL2WISH parameters:params];
  3264. // if(json==nil)
  3265. // return nil;
  3266. // NSError *error=nil;
  3267. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3268. // return jsobj;
  3269. //
  3270. //}
  3271. //+(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
  3272. //{
  3273. //
  3274. //
  3275. // __block AppDelegate *appDelegate = nil;
  3276. //
  3277. // dispatch_sync(dispatch_get_main_queue(), ^{
  3278. // //some UI methods ej
  3279. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3280. // });
  3281. //
  3282. //
  3283. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3284. //
  3285. // if(appDelegate.user!=nil)
  3286. // [params setValue:appDelegate.user forKey:@"user"];
  3287. // if(appDelegate.contact_id!=nil)
  3288. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3289. // if(appDelegate.password!=nil)
  3290. // [params setValue:appDelegate.password forKey:@"password"];
  3291. // if(appDelegate.order_code!=nil)
  3292. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3293. //
  3294. // [params setValue:alert forKey:@"alert"];
  3295. // [params setValue:qty forKey:@"sold_by_qty"];
  3296. // [params setValue:available forKey:@"available"];
  3297. // [params setValue:price forKey:@"price"];
  3298. // [params setValue:bestseller forKey:@"bestseller"];
  3299. // [params setValue:modelname forKey:@"modelName"];
  3300. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3301. //
  3302. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3303. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3304. // [params setValue:category forKey:@"category"];
  3305. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3306. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3307. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3308. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3309. // [params setValue:filter forKey:@"filter"];
  3310. // [params setValue:keyword forKey:@"keyword"];
  3311. //
  3312. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  3313. // if (alert) {
  3314. // [params setObject:@"Filter" forKey:kAction];
  3315. // }
  3316. // if ([Singleton sharedInstance].homeItemClick) {
  3317. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  3318. // [Singleton sharedInstance].homeItemClick = NO;
  3319. //
  3320. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  3321. // [Singleton sharedInstance].homeClickedItemName = nil;
  3322. // [params setObject:extra forKey:kExtra];
  3323. //
  3324. // }
  3325. //
  3326. //
  3327. // if(appDelegate.offline_mode)
  3328. // return [OLDataProvider offline_category:params];
  3329. // if(![self IsNetworkAvailable])
  3330. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3331. //
  3332. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  3333. // if(json==nil)
  3334. // return nil;
  3335. // NSError *error=nil;
  3336. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3337. // return jsobj;
  3338. //
  3339. //}
  3340. //+(NSDictionary*)Search_addall:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  3341. //{
  3342. //
  3343. //
  3344. //
  3345. //
  3346. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3347. // __block AppDelegate *appDelegate = nil;
  3348. //
  3349. // dispatch_sync(dispatch_get_main_queue(), ^{
  3350. // //some UI methods ej
  3351. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3352. // });
  3353. // if(appDelegate.user!=nil)
  3354. // [params setValue:appDelegate.user forKey:@"user"];
  3355. // if(appDelegate.contact_id!=nil)
  3356. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3357. // if(appDelegate.password!=nil)
  3358. // [params setValue:appDelegate.password forKey:@"password"];
  3359. // if(appDelegate.order_code!=nil)
  3360. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3361. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3362. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3363. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3364. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3365. // // [params setValue:filter forKey:@"filter"];
  3366. // [params setValue:keywords forKey:@"keyword"];
  3367. // [params setValue:addTo forKey:@"addTo"];
  3368. //
  3369. // [params setValue:orderCode forKey:@"orderCode"];
  3370. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3371. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3372. // if(matchfull)
  3373. // [params setValue:@"true" forKey:@"exactMatch"];
  3374. // else
  3375. // [params setValue:@"false" forKey:@"exactMatch"];
  3376. //
  3377. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  3378. // if ([addTo isEqualToString:@"cart"]) {
  3379. // [params setObject:@"Add To Cart" forKey:kAction];
  3380. // }
  3381. //
  3382. // NSData* json=nil;
  3383. // if(appDelegate.offline_mode)
  3384. // {
  3385. // json=[OLDataProvider offline_searchaddall:params];
  3386. // }
  3387. // else
  3388. // {
  3389. // if(![self IsNetworkAvailable])
  3390. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3391. //
  3392. // NSError *error=nil;
  3393. //
  3394. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3395. // params[@"resultSerial"]=uuid;
  3396. //
  3397. // for(int i=0;i<150;i++)
  3398. // {
  3399. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3400. // // result_params[@"resultSerial"]=uuid;
  3401. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  3402. // if(json!=nil)
  3403. // {
  3404. //
  3405. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3406. // if([jsobj[@"result"] intValue]==2)
  3407. // {
  3408. // break;
  3409. // }
  3410. // }
  3411. // sleep(2);
  3412. // }
  3413. // }
  3414. // if(json==nil)
  3415. // return nil;
  3416. // NSError *error=nil;
  3417. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3418. // return jsobj;
  3419. //
  3420. //}
  3421. //+(NSDictionary*)Search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull
  3422. //{
  3423. //
  3424. //
  3425. //
  3426. //
  3427. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3428. // __block AppDelegate *appDelegate = nil;
  3429. //
  3430. // dispatch_sync(dispatch_get_main_queue(), ^{
  3431. // //some UI methods ej
  3432. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3433. // });
  3434. // if(appDelegate.user!=nil)
  3435. // [params setValue:appDelegate.user forKey:@"user"];
  3436. // if(appDelegate.contact_id!=nil)
  3437. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3438. // if(appDelegate.password!=nil)
  3439. // [params setValue:appDelegate.password forKey:@"password"];
  3440. // if(appDelegate.order_code!=nil)
  3441. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3442. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3443. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3444. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3445. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3446. // // [params setValue:filter forKey:@"filter"];
  3447. // [params setValue:keywords forKey:@"keyword"];
  3448. //
  3449. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3450. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3451. // if(matchfull)
  3452. // [params setValue:@"true" forKey:@"exactMatch"];
  3453. // else
  3454. // [params setValue:@"false" forKey:@"exactMatch"];
  3455. //
  3456. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  3457. // if (keywords) {
  3458. // [params setObject:@"Search" forKey:kAction];
  3459. // }
  3460. //
  3461. // if(appDelegate.offline_mode)
  3462. // {
  3463. // return [OLDataProvider offline_search:params];
  3464. // }
  3465. // if(![self IsNetworkAvailable])
  3466. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3467. //
  3468. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3469. // if(json==nil)
  3470. // return nil;
  3471. // NSError *error=nil;
  3472. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3473. // return jsobj;
  3474. //}
  3475. //+(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
  3476. //{
  3477. // // for debug
  3478. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3479. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3480. //
  3481. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3482. // __block AppDelegate *appDelegate = nil;
  3483. //
  3484. // dispatch_sync(dispatch_get_main_queue(), ^{
  3485. // //some UI methods ej
  3486. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3487. // });
  3488. // if(appDelegate.user!=nil)
  3489. // [params setValue:appDelegate.user forKey:@"user"];
  3490. // if(appDelegate.contact_id!=nil)
  3491. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3492. // if(appDelegate.password!=nil)
  3493. // [params setValue:appDelegate.password forKey:@"password"];
  3494. // if(appDelegate.order_code!=nil)
  3495. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3496. //
  3497. // [params setValue:addTo forKey:@"addTo"];
  3498. //
  3499. // [params setValue:orderCode forKey:@"orderCode"];
  3500. //
  3501. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3502. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3503. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3504. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3505. // // [params setValue:filter forKey:@"filter"];
  3506. // [params setValue:covertype forKey:@"covertype"];
  3507. // [params setValue:ctgid forKey:@"ctgId"];
  3508. // [params setValue:modelname forKey:@"modelName"];
  3509. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3510. // [params setValue:alert forKey:@"alert"];
  3511. // [params setValue:qty forKey:@"sold_by_qty"];
  3512. // [params setValue:available forKey:@"available"];
  3513. // [params setValue:price forKey:@"price"];
  3514. // [params setValue:bestseller forKey:@"bestseller"];
  3515. //
  3516. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3517. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3518. //
  3519. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3520. // if ([addTo isEqualToString:@"cart"]) {
  3521. // [params setObject:@"Add To Cart" forKey:kAction];
  3522. // }
  3523. //
  3524. // NSData* json = nil;
  3525. //
  3526. // if(appDelegate.offline_mode)
  3527. // {
  3528. // json= [OLDataProvider offline_itemsearchaddall:params];
  3529. // }
  3530. // else
  3531. // {
  3532. // if(![self IsNetworkAvailable])
  3533. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3534. // NSError *error=nil;
  3535. //
  3536. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3537. // params[@"resultSerial"]=uuid;
  3538. //
  3539. // for(int i=0;i<150;i++)
  3540. // {
  3541. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3542. // // result_params[@"resultSerial"]=uuid;
  3543. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  3544. // if(json!=nil)
  3545. // {
  3546. //
  3547. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3548. // if([jsobj[@"result"] intValue]==2)
  3549. // {
  3550. // break;
  3551. // }
  3552. // }
  3553. // sleep(2);
  3554. // }
  3555. // }
  3556. // if(json==nil)
  3557. // return nil;
  3558. // NSError *error=nil;
  3559. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3560. // return jsobj;
  3561. //}
  3562. //+(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
  3563. //{
  3564. //
  3565. // // for debug
  3566. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3567. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3568. //
  3569. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3570. // __block AppDelegate *appDelegate = nil;
  3571. //
  3572. // dispatch_sync(dispatch_get_main_queue(), ^{
  3573. // //some UI methods ej
  3574. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3575. // });
  3576. // if(appDelegate.user!=nil)
  3577. // [params setValue:appDelegate.user forKey:@"user"];
  3578. // if(appDelegate.contact_id!=nil)
  3579. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3580. // if(appDelegate.password!=nil)
  3581. // [params setValue:appDelegate.password forKey:@"password"];
  3582. // if(appDelegate.order_code!=nil)
  3583. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3584. //
  3585. //
  3586. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3587. // if (alert && qty && available && price && bestseller) {
  3588. // [params setObject:@"Filter" forKey:kAction];
  3589. // }
  3590. // if ([Singleton sharedInstance].homeItemClick) {
  3591. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  3592. // [Singleton sharedInstance].homeItemClick = NO;
  3593. //
  3594. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  3595. // [Singleton sharedInstance].homeClickedItemName = nil;
  3596. // [params setObject:extra forKey:kExtra];
  3597. // }
  3598. //
  3599. //
  3600. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3601. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3602. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3603. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3604. // // [params setValue:filter forKey:@"filter"];
  3605. // [params setValue:covertype forKey:@"covertype"];
  3606. // [params setValue:ctgid forKey:@"ctgId"];
  3607. // [params setValue:modelname forKey:@"modelName"];
  3608. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3609. // [params setValue:alert forKey:@"alert"];
  3610. // [params setValue:qty forKey:@"sold_by_qty"];
  3611. // [params setValue:available forKey:@"available"];
  3612. // [params setValue:price forKey:@"price"];
  3613. // [params setValue:bestseller forKey:@"bestseller"];
  3614. //
  3615. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3616. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3617. //
  3618. // if(appDelegate.offline_mode)
  3619. // {
  3620. // return [OLDataProvider offline_itemsearch:params];
  3621. // }
  3622. // if(![self IsNetworkAvailable])
  3623. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3624. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  3625. // if(json==nil)
  3626. // return nil;
  3627. // NSError *error=nil;
  3628. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3629. // return jsobj;
  3630. //}
  3631. //+(NSDictionary*)Search: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword
  3632. //{
  3633. // if(![self IsNetworkAvailable])
  3634. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3635. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3636. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3637. // if(appDelegate.user!=nil)
  3638. // [params setValue:appDelegate.user forKey:@"user"];
  3639. // if(appDelegate.contact_id!=nil)
  3640. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3641. // if(appDelegate.password!=nil)
  3642. // [params setValue:appDelegate.password forKey:@"password"];
  3643. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3644. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3645. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3646. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3647. // [params setValue:filter forKey:@"filter"];
  3648. // [params setValue:keyword forKey:@"keyword"];
  3649. //
  3650. //
  3651. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3652. // if(json==nil)
  3653. // return nil;
  3654. // NSError *error=nil;
  3655. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3656. // return jsobj;
  3657. //}
  3658. +(NSDictionary*)request_model_qty: (NSString*) fashionId
  3659. {
  3660. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3661. __block AppDelegate *appDelegate = nil;
  3662. dispatch_sync(dispatch_get_main_queue(), ^{
  3663. //some UI methods ej
  3664. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3665. });
  3666. if(appDelegate.user!=nil)
  3667. [params setValue:appDelegate.user forKey:@"user"];
  3668. if(appDelegate.contact_id!=nil)
  3669. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3670. if(appDelegate.password!=nil)
  3671. [params setValue:appDelegate.password forKey:@"password"];
  3672. [params setValue:fashionId forKey:@"fashionId"];
  3673. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  3674. NSData* json = nil;
  3675. if(appDelegate.offline_mode)
  3676. {
  3677. json = [OLDataProvider offline_model_qty:params];
  3678. } else {
  3679. if(![self IsNetworkAvailable])
  3680. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3681. json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  3682. }
  3683. if(json==nil)
  3684. return nil;
  3685. NSError *error=nil;
  3686. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3687. return jsobj;
  3688. }
  3689. +(NSDictionary*)retrieve_password: (NSString*) user email:(NSString*) email
  3690. {
  3691. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3692. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3693. // if(appDelegate.user!=nil)
  3694. // [params setValue:appDelegate.user forKey:@"user"];
  3695. // if(appDelegate.contact_id!=nil)
  3696. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3697. // if(appDelegate.password!=nil)
  3698. // [params setValue:appDelegate.password forKey:@"password"];
  3699. [params setValue:user forKey:@"username"];
  3700. [params setValue:email forKey:@"email"];
  3701. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3702. if(![self IsNetworkAvailable])
  3703. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3704. NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  3705. if(json==nil)
  3706. return nil;
  3707. NSError *error=nil;
  3708. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3709. return jsobj;
  3710. }
  3711. +(NSDictionary*)load_HomePage:(int) price_template customid:(int) customid
  3712. {
  3713. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3714. __block AppDelegate *appDelegate = nil;
  3715. dispatch_sync(dispatch_get_main_queue(), ^{
  3716. //some UI methods ej
  3717. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3718. });
  3719. if(appDelegate.user!=nil)
  3720. [params setValue:appDelegate.user forKey:@"user"];
  3721. if(appDelegate.contact_id!=nil)
  3722. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3723. if(appDelegate.password!=nil)
  3724. [params setValue:appDelegate.password forKey:@"password"];
  3725. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3726. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3727. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  3728. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3729. if(appDelegate.offline_mode)
  3730. {
  3731. //params[@"offline_Command"]=url;
  3732. return [OLDataProvider offline_home];
  3733. }
  3734. if(![self IsNetworkAvailable])
  3735. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3736. NSData* json=[self get_json:URL_LOAD_HOME parameters:params];
  3737. if(json==nil)
  3738. return nil;
  3739. NSError *error=nil;
  3740. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3741. return jsobj;
  3742. }
  3743. //+(NSDictionary*)logout
  3744. //{
  3745. //
  3746. //
  3747. //
  3748. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3749. // __block AppDelegate *appDelegate = nil;
  3750. //
  3751. // dispatch_sync(dispatch_get_main_queue(), ^{
  3752. // //some UI methods ej
  3753. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3754. // });
  3755. // if(appDelegate.user!=nil)
  3756. // [params setValue:appDelegate.user forKey:@"user"];
  3757. //
  3758. //
  3759. // if(appDelegate.password!=nil)
  3760. // [params setValue:appDelegate.password forKey:@"password"];
  3761. //
  3762. //
  3763. // if(appDelegate.offline_mode)
  3764. // {
  3765. // return [OLDataProvider offline_logout:params];
  3766. // }
  3767. // if(![self IsNetworkAvailable])
  3768. // {
  3769. // DebugLog(@"NET ERR");
  3770. //
  3771. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3772. // // return nil;
  3773. // }
  3774. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  3775. // //if(json==nil)
  3776. //
  3777. //
  3778. // if(json==nil)
  3779. // return nil;
  3780. // NSError *error=nil;
  3781. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3782. // int result = [[jsobj valueForKey:@"result"] intValue];
  3783. //
  3784. // if (result==2)
  3785. // {
  3786. //
  3787. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  3788. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  3789. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  3790. //
  3791. // [appDelegate update_count_mark];
  3792. //
  3793. //
  3794. // appDelegate.can_show_price =false;
  3795. // appDelegate.can_see_price =false;
  3796. // appDelegate.can_create_portfolio =false;
  3797. // appDelegate.can_create_order =false;
  3798. //
  3799. //
  3800. // appDelegate.can_cancel_order =false;
  3801. // appDelegate.can_set_cart_price =false;
  3802. // appDelegate.can_delete_order =false;
  3803. // appDelegate.can_submit_order =false;
  3804. // appDelegate.can_set_tearsheet_price =false;
  3805. // appDelegate.can_update_contact_info = false;
  3806. //
  3807. // appDelegate.save_order_logout = false;
  3808. // appDelegate.submit_order_logout = false;
  3809. // appDelegate.alert_sold_in_quantities = false;
  3810. //
  3811. // appDelegate.ipad_perm =nil ;
  3812. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  3813. // appDelegate.OrderFilter= nil;
  3814. // [appDelegate SetSo:nil];
  3815. // [appDelegate set_main_button_panel];
  3816. //#ifdef RA_NOTIFICATION
  3817. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  3818. //#endif
  3819. // }
  3820. // return jsobj;
  3821. //}
  3822. +(NSDictionary*)request_Cagegory
  3823. {
  3824. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  3825. __block AppDelegate *appDelegate = nil;
  3826. dispatch_sync(dispatch_get_main_queue(), ^{
  3827. //some UI methods ej
  3828. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3829. });
  3830. if(appDelegate.offline_mode)
  3831. {
  3832. //params[@"offline_Command"]=url;
  3833. return [OLDataProvider offline_category_menu];
  3834. }
  3835. if(![self IsNetworkAvailable])
  3836. {
  3837. DebugLog(@"NET ERR");
  3838. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3839. // return nil;
  3840. }
  3841. NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  3842. //if(json==nil)
  3843. if(json==nil)
  3844. return nil;
  3845. NSError *error=nil;
  3846. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3847. return jsobj;
  3848. }
  3849. +(int)Authorize : (NSString*) user password:(NSString*) password{
  3850. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  3851. // return RESULT_NET_ERROR;
  3852. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3853. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3854. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3855. __block AppDelegate *appDelegate = nil;
  3856. dispatch_sync(dispatch_get_main_queue(), ^{
  3857. //some UI methods ej
  3858. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3859. });
  3860. if(appDelegate.duid !=nil)
  3861. [params setValue:appDelegate.duid forKey:@"udid"];
  3862. [params setValue:@"handset_login" forKey:@"action"];
  3863. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  3864. [params setValue:user forKey:@"user"];
  3865. [params setValue:password forKey:@"password"];
  3866. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  3867. #ifdef TEST
  3868. [params setValue:@"true" forKey:@"is_debug"];
  3869. #else
  3870. [params setValue:@"false" forKey:@"is_debug"];
  3871. #endif
  3872. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3873. [params setObject:@"Login" forKey:kAction];
  3874. NSData* json= nil;
  3875. if(appDelegate.offline_mode)
  3876. {
  3877. json= [OLDataProvider offline_login:params] ;
  3878. }
  3879. else
  3880. {
  3881. if(![self IsNetworkAvailable])
  3882. return RESULT_NET_NOTAVAILABLE;
  3883. json =[self get_json:URL_UPDATE_AUTH parameters:params];
  3884. }
  3885. if(json==nil)
  3886. return RESULT_NET_ERROR;
  3887. int ret = [self parse_authinfo:json user:user password:password];
  3888. DebugLog(@"parse_authinfo return %d ",ret);
  3889. return ret;
  3890. }
  3891. +(NSDictionary*)update_customer_img: (NSString*) contactid img_url:(NSString*) url
  3892. {
  3893. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3894. __block AppDelegate *appDelegate = nil;
  3895. dispatch_sync(dispatch_get_main_queue(), ^{
  3896. //some UI methods ej
  3897. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3898. });
  3899. if(appDelegate.user!=nil)
  3900. [params setValue:appDelegate.user forKey:@"user"];
  3901. // if(appDelegate.contact_id!=nil)
  3902. if(appDelegate.password!=nil)
  3903. [params setValue:appDelegate.password forKey:@"password"];
  3904. [params setValue:contactid forKey:@"contactId"];
  3905. [params setValue:url forKey:@"business_card"];
  3906. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  3907. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  3908. if(appDelegate.offline_mode)
  3909. {
  3910. return [OLDataProvider offline_notimpl];
  3911. }
  3912. if(![self IsNetworkAvailable])
  3913. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3914. NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  3915. if(json==nil)
  3916. return nil;
  3917. NSError *error=nil;
  3918. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3919. return jsobj;
  3920. }
  3921. +(NSDictionary*)request_PendingOrder:(NSString *)contactid
  3922. {
  3923. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3924. __block AppDelegate *appDelegate = nil;
  3925. dispatch_sync(dispatch_get_main_queue(), ^{
  3926. //some UI methods ej
  3927. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3928. });
  3929. if(appDelegate.user!=nil)
  3930. [params setValue:appDelegate.user forKey:@"user"];
  3931. // if(appDelegate.contact_id!=nil)
  3932. if(appDelegate.password!=nil)
  3933. [params setValue:appDelegate.password forKey:@"password"];
  3934. [params setValue:contactid forKey:@"contactId"];
  3935. if(appDelegate.offline_mode)
  3936. {
  3937. return [OLDataProvider offline_notimpl];
  3938. }
  3939. if(![self IsNetworkAvailable])
  3940. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3941. NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  3942. if(json==nil)
  3943. return nil;
  3944. NSError *error=nil;
  3945. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3946. return jsobj;
  3947. }
  3948. //+(NSDictionary*)request_CustomerInfo:(NSString* ) contactid
  3949. //{
  3950. //
  3951. //
  3952. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3953. // __block AppDelegate *appDelegate = nil;
  3954. //
  3955. // dispatch_sync(dispatch_get_main_queue(), ^{
  3956. // //some UI methods ej
  3957. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3958. // });
  3959. // if(appDelegate.user!=nil)
  3960. // [params setValue:appDelegate.user forKey:@"user"];
  3961. // // if(appDelegate.contact_id!=nil)
  3962. //
  3963. // if(appDelegate.password!=nil)
  3964. // [params setValue:appDelegate.password forKey:@"password"];
  3965. // [params setValue:contactid forKey:@"contactId"];
  3966. //
  3967. // [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  3968. //
  3969. // if(appDelegate.offline_mode)
  3970. // return [OLDataProvider offline_contactinfo:params];
  3971. // if(![self IsNetworkAvailable])
  3972. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3973. //
  3974. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  3975. // if(json==nil)
  3976. // return nil;
  3977. // NSError *error=nil;
  3978. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3979. // return jsobj;
  3980. //
  3981. //}
  3982. +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
  3983. {
  3984. DebugLog(@"parse_authinfo");
  3985. NSError *error=nil;
  3986. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3987. if(jsobj)
  3988. {
  3989. __block AppDelegate *appDelegate = nil;
  3990. dispatch_sync(dispatch_get_main_queue(), ^{
  3991. //some UI methods ej
  3992. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3993. });
  3994. int result = [[jsobj valueForKey:@"result"] intValue];
  3995. if (result<0)
  3996. return result;
  3997. if(result!=AP_USER_AUTH&& result!=9)
  3998. {
  3999. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  4000. // [appDelegate Logout];
  4001. if(result==8)
  4002. {
  4003. return RESULT_LOGIN_DEVICE;
  4004. }
  4005. return RESULT_FALSE;
  4006. }
  4007. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  4008. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  4009. user=[objheader objectForKey:@"username"] ;
  4010. DebugLog(@"required_ver=%@ ",required_ver);
  4011. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  4012. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  4013. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  4014. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  4015. // if([ibadge isEqual:[NSNull null]])
  4016. // strbadge=@"0";
  4017. // if(ibadge==nil)
  4018. // ibadge=@"0";
  4019. // if([strbadge isEqualToString:@"null"])
  4020. // strbadge=@"0";
  4021. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  4022. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  4023. if([appDelegate.build intValue]<[required_ver intValue])
  4024. return RESULT_VER_LOW;
  4025. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  4026. appDelegate.user = user;
  4027. appDelegate.password = password;
  4028. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  4029. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  4030. appDelegate.bLogin = true;
  4031. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  4032. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  4033. {
  4034. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  4035. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  4036. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  4037. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  4038. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  4039. }
  4040. NSString* mode =[jsobj valueForKey:@"mode"] ;
  4041. [appDelegate SetMode:mode];
  4042. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  4043. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  4044. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  4045. [appDelegate update_count_mark];
  4046. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  4047. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  4048. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  4049. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  4050. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  4051. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  4052. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  4053. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  4054. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  4055. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  4056. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  4057. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  4058. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  4059. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  4060. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  4061. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  4062. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  4063. [appDelegate set_main_button_panel];
  4064. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  4065. // shop order status filter
  4066. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  4067. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  4068. // Sales order status filter
  4069. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  4070. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  4071. // specialInstruction
  4072. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  4073. //-价格类型
  4074. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  4075. // 权限
  4076. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  4077. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  4078. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  4079. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  4080. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  4081. [[RASingleton sharedInstance] resetGlobalLock];
  4082. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  4083. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  4084. }
  4085. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  4086. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  4087. // {
  4088. // // no update on the server;
  4089. // return RESULT_TRUE;
  4090. // }
  4091. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  4092. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4093. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4094. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4095. // [defaults synchronize];
  4096. //
  4097. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  4098. // NSArray* keys= [objfuncs allKeys];
  4099. /*
  4100. db.setTransactionSuccessful();
  4101. db.endTransaction();
  4102. */
  4103. return RESULT_TRUE;
  4104. }
  4105. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  4106. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  4107. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  4108. return RESULT_USERAUTH_ERROR;
  4109. }
  4110. //+(bool) IsNetworkAvailable
  4111. //{
  4112. //
  4113. // if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) &&
  4114. // ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable))
  4115. // return false;
  4116. // return true;
  4117. //}
  4118. //+(NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim
  4119. //{
  4120. // NSScanner *theScanner = [NSScanner scannerWithString:html];
  4121. // NSString *text = nil;
  4122. //
  4123. // while ([theScanner isAtEnd] == NO) {
  4124. // // find start of tag
  4125. // [theScanner scanUpToString:@"<" intoString:NULL] ;
  4126. // // find end of tag
  4127. // [theScanner scanUpToString:@">" intoString:&text] ;
  4128. // // replace the found tag with a space
  4129. // //(you can filter multi-spaces out later if you wish)
  4130. // html = [html stringByReplacingOccurrencesOfString:
  4131. // [ NSString stringWithFormat:@"%@>", text]
  4132. // withString:@""];
  4133. // }
  4134. //
  4135. // return trim ? [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : html;
  4136. //}
  4137. //
  4138. //+(NSString *)flattenURL:(NSString *)url trimWhiteSpace:(BOOL)trim
  4139. //{
  4140. // NSScanner *theScanner = [NSScanner scannerWithString:url];
  4141. // NSString *text = nil;
  4142. //
  4143. // while ([theScanner isAtEnd] == NO) {
  4144. // // find start of tag
  4145. // [theScanner scanUpToString:@"/" intoString:NULL] ;
  4146. // // find end of tag
  4147. // [theScanner scanUpToString:@"/" intoString:&text] ;
  4148. // // replace the found tag with a space
  4149. // //(you can filter multi-spaces out later if you wish)
  4150. // url = [url stringByReplacingOccurrencesOfString:
  4151. // [ NSString stringWithFormat:@"%@", text]
  4152. // withString:@""];
  4153. // }
  4154. //
  4155. // return trim ? [url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : url;
  4156. //}
  4157. + (NSDictionary *)set_npd_shop_price_type:(NSInteger)priceType {
  4158. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4159. __block AppDelegate *appDelegate = nil;
  4160. dispatch_sync(dispatch_get_main_queue(), ^{
  4161. //some UI methods ej
  4162. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4163. });
  4164. if(appDelegate.user!=nil)
  4165. [dic setValue:appDelegate.user forKey:@"user"];
  4166. if(appDelegate.password!=nil)
  4167. [dic setValue:appDelegate.password forKey:@"password"];
  4168. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  4169. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  4170. NSData* json=nil;
  4171. if(appDelegate.offline_mode)
  4172. {
  4173. return [OLDataProvider offline_notimpl];
  4174. }
  4175. else
  4176. {
  4177. if(![self IsNetworkAvailable])
  4178. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4179. json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  4180. }
  4181. if(json!=nil)
  4182. {
  4183. NSError *error=nil;
  4184. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4185. return jsobj;
  4186. }
  4187. return nil;
  4188. }
  4189. + (NSDictionary *)get_npd_shop_givenPrice {
  4190. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4191. __block AppDelegate *appDelegate = nil;
  4192. dispatch_sync(dispatch_get_main_queue(), ^{
  4193. //some UI methods ej
  4194. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4195. });
  4196. if(appDelegate.user!=nil)
  4197. [dic setValue:appDelegate.user forKey:@"user"];
  4198. if(appDelegate.password!=nil)
  4199. [dic setValue:appDelegate.password forKey:@"password"];
  4200. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  4201. NSData* json=nil;
  4202. if(appDelegate.offline_mode)
  4203. {
  4204. return [OLDataProvider offline_notimpl];
  4205. }
  4206. else
  4207. {
  4208. if(![self IsNetworkAvailable])
  4209. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4210. json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  4211. }
  4212. if(json!=nil)
  4213. {
  4214. NSError *error=nil;
  4215. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4216. return jsobj;
  4217. }
  4218. return nil;
  4219. }
  4220. + (NSDictionary *)set_npd_shop_givenPrice:(NSMutableDictionary *)params {
  4221. __block AppDelegate *appDelegate = nil;
  4222. dispatch_sync(dispatch_get_main_queue(), ^{
  4223. //some UI methods ej
  4224. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4225. });
  4226. if(appDelegate.user!=nil)
  4227. [params setValue:appDelegate.user forKey:@"user"];
  4228. if(appDelegate.password!=nil)
  4229. [params setValue:appDelegate.password forKey:@"password"];
  4230. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  4231. NSData* json=nil;
  4232. if(appDelegate.offline_mode)
  4233. {
  4234. return [OLDataProvider offline_notimpl];
  4235. }
  4236. else
  4237. {
  4238. if(![self IsNetworkAvailable])
  4239. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4240. json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  4241. }
  4242. if(json!=nil)
  4243. {
  4244. NSError *error=nil;
  4245. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4246. return jsobj;
  4247. }
  4248. return nil;
  4249. }
  4250. + (NSDictionary *)merge_order:(NSMutableDictionary *)params {
  4251. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4252. __block AppDelegate *appDelegate = nil;
  4253. dispatch_sync(dispatch_get_main_queue(), ^{
  4254. //some UI methods ej
  4255. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4256. });
  4257. if(appDelegate.user!=nil)
  4258. [dic setValue:appDelegate.user forKey:@"user"];
  4259. if(appDelegate.password!=nil)
  4260. [dic setValue:appDelegate.password forKey:@"password"];
  4261. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  4262. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  4263. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  4264. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  4265. NSData* json=nil;
  4266. if(appDelegate.offline_mode)
  4267. {
  4268. return [OLDataProvider offline_notimpl];
  4269. }
  4270. else
  4271. {
  4272. if(![self IsNetworkAvailable])
  4273. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4274. json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  4275. }
  4276. if(json!=nil)
  4277. {
  4278. NSError *error=nil;
  4279. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4280. return jsobj;
  4281. }
  4282. else
  4283. return nil;
  4284. }
  4285. //+ (NSDictionary *)lock_order:(NSString *)oderCode
  4286. //{
  4287. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4288. // __block AppDelegate *appDelegate = nil;
  4289. //
  4290. // dispatch_sync(dispatch_get_main_queue(), ^{
  4291. // //some UI methods ej
  4292. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4293. // });
  4294. // if(appDelegate.user!=nil)
  4295. // [params setValue:appDelegate.user forKey:@"user"];
  4296. //
  4297. // if(appDelegate.password!=nil)
  4298. // [params setValue:appDelegate.password forKey:@"password"];
  4299. //
  4300. // [params setValue:oderCode forKey:@"orderCode"];
  4301. //
  4302. // NSData* json=nil;
  4303. // if(appDelegate.offline_mode)
  4304. // {
  4305. // json=[OLDataProvider offline_editorder:params];
  4306. //
  4307. // }
  4308. // else
  4309. // {
  4310. // if(![self IsNetworkAvailable])
  4311. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4312. //
  4313. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  4314. // }
  4315. // if(json!=nil)
  4316. // {
  4317. // NSError *error=nil;
  4318. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4319. //
  4320. // return jsobj;
  4321. // }
  4322. // else
  4323. // return nil;
  4324. //}
  4325. + (NSDictionary *)quoteOrder:(NSString *)so_id emailAddr:(NSString *)addr {
  4326. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4327. __block AppDelegate *appDelegate = nil;
  4328. dispatch_sync(dispatch_get_main_queue(), ^{
  4329. //some UI methods ej
  4330. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4331. });
  4332. if(appDelegate.user!=nil)
  4333. [dic setValue:appDelegate.user forKey:@"user"];
  4334. if(appDelegate.password!=nil)
  4335. [dic setValue:appDelegate.password forKey:@"password"];
  4336. [dic setValue:so_id forKey:@"orderCode"];
  4337. [dic setValue:addr forKey:@"email"];
  4338. [dic setObject:ScreenCodeCart forKey:kScreenName];
  4339. if (appDelegate.customerInfo) {
  4340. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4341. if (customer_cid) {
  4342. [dic setValue:customer_cid forKey:@"contactId"];
  4343. }
  4344. }
  4345. NSData* json=nil;
  4346. if(appDelegate.offline_mode)
  4347. {
  4348. return [OLDataProvider offline_notimpl];
  4349. }
  4350. else
  4351. {
  4352. if(![self IsNetworkAvailable])
  4353. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4354. json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  4355. }
  4356. if(json!=nil)
  4357. {
  4358. NSError *error=nil;
  4359. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4360. return jsobj;
  4361. }
  4362. return @{@"result" : @(RESULT_FALSE)};
  4363. }
  4364. + (NSDictionary *)notifyModel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName{
  4365. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4366. __block AppDelegate *appDelegate = nil;
  4367. dispatch_sync(dispatch_get_main_queue(), ^{
  4368. //some UI methods ej
  4369. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4370. });
  4371. if(appDelegate.user!=nil)
  4372. [dic setValue:appDelegate.user forKey:@"user"];
  4373. if(appDelegate.password!=nil)
  4374. [dic setValue:appDelegate.password forKey:@"password"];
  4375. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  4376. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4377. if (customer_cid) {
  4378. [dic setValue:customer_cid forKey:@"contactId"];
  4379. }
  4380. }
  4381. [dic setObject:screenName forKey:kScreenName];
  4382. [dic setValue:modelID forKey:@"productId"];
  4383. if (addr) { // 弹框输入
  4384. [dic setValue:addr forKey:@"email"];
  4385. } else {
  4386. // employee选择了Contact,并且Contact有Email
  4387. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  4388. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  4389. // if (email) {
  4390. // [dic setValue:email forKey:@"email"];
  4391. // }
  4392. // }
  4393. }
  4394. NSData* json=nil;
  4395. if(appDelegate.offline_mode)
  4396. {
  4397. return [OLDataProvider offline_notimpl];
  4398. }
  4399. else
  4400. {
  4401. if(![self IsNetworkAvailable])
  4402. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4403. json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  4404. }
  4405. if(json!=nil)
  4406. {
  4407. NSError *error=nil;
  4408. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4409. return jsobj;
  4410. }
  4411. return @{@"result" : @(RESULT_FALSE)};
  4412. }
  4413. + (NSDictionary *)quoteWishlist2EmailAddr:(NSString *)addr {
  4414. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4415. __block AppDelegate *appDelegate = nil;
  4416. dispatch_sync(dispatch_get_main_queue(), ^{
  4417. //some UI methods ej
  4418. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4419. });
  4420. if(appDelegate.user!=nil)
  4421. [dic setValue:appDelegate.user forKey:@"user"];
  4422. if(appDelegate.password!=nil)
  4423. [dic setValue:appDelegate.password forKey:@"password"];
  4424. [dic setValue:addr forKey:@"email"];
  4425. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  4426. // if (appDelegate.customerInfo) {
  4427. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  4428. // if (customer_cid) {
  4429. // [dic setValue:customer_cid forKey:@"contactId"];
  4430. // }
  4431. // }
  4432. NSData* json=nil;
  4433. if(appDelegate.offline_mode)
  4434. {
  4435. return [OLDataProvider offline_notimpl];
  4436. }
  4437. else
  4438. {
  4439. if(![self IsNetworkAvailable])
  4440. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4441. json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  4442. }
  4443. if(json!=nil)
  4444. {
  4445. NSError *error=nil;
  4446. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4447. return jsobj;
  4448. }
  4449. return @{@"result" : @(RESULT_FALSE)};
  4450. }
  4451. + (NSDictionary *)movetobackorder:(NSString *)cart_item_id {
  4452. if (cart_item_id == nil || cart_item_id.length < 1) {
  4453. return @{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"};
  4454. }
  4455. __block AppDelegate *appDelegate = nil;
  4456. dispatch_sync(dispatch_get_main_queue(), ^{
  4457. //some UI methods ej
  4458. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4459. });
  4460. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  4461. if(appDelegate.user!=nil)
  4462. [dic setValue:appDelegate.user forKey:@"user"];
  4463. if(appDelegate.password!=nil)
  4464. [dic setValue:appDelegate.password forKey:@"password"];
  4465. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  4466. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  4467. [dic setObject:ScreenCodeCart forKey:kScreenName];
  4468. if(![self IsNetworkAvailable])
  4469. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4470. NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  4471. if(json!=nil)
  4472. {
  4473. NSError *error=nil;
  4474. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4475. return jsobj;
  4476. }
  4477. return @{@"result" : @(RESULT_FALSE)};
  4478. }
  4479. + (NSDictionary*)request_hangTag:(NSString *)group {
  4480. #ifdef BUILD_UWAVER
  4481. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4482. __block AppDelegate *appDelegate = nil;
  4483. dispatch_sync(dispatch_get_main_queue(), ^{
  4484. //some UI methods ej
  4485. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4486. });
  4487. if(appDelegate.user!=nil)
  4488. [params setValue:appDelegate.user forKey:@"user"];
  4489. if(appDelegate.contact_id!=nil)
  4490. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4491. if(appDelegate.password!=nil)
  4492. [params setValue:appDelegate.password forKey:@"password"];
  4493. if (group) {
  4494. [params setValue:group forKey:@"groupName"];
  4495. }
  4496. NSString * uuid= [[NSUUID UUID] UUIDString];
  4497. params[@"resultSerial"]=uuid;
  4498. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4499. NSData* json = nil;
  4500. if(appDelegate.offline_mode)
  4501. {
  4502. json = [OLDataProvider offline_notimpl];
  4503. } else {
  4504. if(![self IsNetworkAvailable])
  4505. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4506. json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  4507. }
  4508. if(json==nil)
  4509. return nil;
  4510. NSError *error=nil;
  4511. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4512. return jsobj;
  4513. #else
  4514. return nil;
  4515. #endif
  4516. }
  4517. #pragma mark 2020 new interface
  4518. // 新接口逐步替换以前的网络请求,2020
  4519. +(void)request_home:(int) price_template customid:(int) customid completionHandler:(resultHandler)result
  4520. {
  4521. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4522. AppDelegate *appDelegate = nil;
  4523. //some UI methods ej
  4524. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4525. if(appDelegate.user!=nil)
  4526. [params setValue:appDelegate.user forKey:@"user"];
  4527. if(appDelegate.contact_id!=nil)
  4528. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4529. if(appDelegate.password!=nil)
  4530. [params setValue:appDelegate.password forKey:@"password"];
  4531. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4532. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4533. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  4534. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4535. if(appDelegate.offline_mode)
  4536. {
  4537. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4538. NSMutableDictionary* json = [[OLDataProvider offline_home] mutableCopy];
  4539. dispatch_async(dispatch_get_main_queue(), ^{
  4540. result(json);
  4541. });
  4542. });
  4543. return;
  4544. }
  4545. [self request_interface:URL_LOAD_HOME parameters:params err_record_url:nil completionHandler:result retry:0];
  4546. return;
  4547. }
  4548. +(void)request_category:(resultHandler)result
  4549. {
  4550. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  4551. AppDelegate *appDelegate = nil;
  4552. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4553. if(appDelegate.offline_mode)
  4554. {
  4555. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4556. NSMutableDictionary* json = [[OLDataProvider offline_category_menu] mutableCopy];
  4557. dispatch_async(dispatch_get_main_queue(), ^{
  4558. result(json);
  4559. });
  4560. });
  4561. return;
  4562. }
  4563. [self request_interface:URL_REQUEST_CATMENU parameters:[NSMutableDictionary new] err_record_url:nil completionHandler:result retry:0];
  4564. //
  4565. // if(![self IsNetworkAvailable])
  4566. // {
  4567. // DebugLog(@"NET ERR");
  4568. //
  4569. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4570. // // return nil;
  4571. // }
  4572. //
  4573. // NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  4574. // //if(json==nil)
  4575. //
  4576. //
  4577. // if(json==nil)
  4578. // return nil;
  4579. // NSError *error=nil;
  4580. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4581. // return jsobj;
  4582. }
  4583. +(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
  4584. {
  4585. AppDelegate *appDelegate = nil;
  4586. //some UI methods ej
  4587. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4588. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4589. if(appDelegate.user!=nil)
  4590. [params setValue:appDelegate.user forKey:@"user"];
  4591. if(appDelegate.contact_id!=nil)
  4592. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4593. if(appDelegate.password!=nil)
  4594. [params setValue:appDelegate.password forKey:@"password"];
  4595. if(appDelegate.order_code!=nil)
  4596. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4597. [params setValue:alert forKey:@"alert"];
  4598. [params setValue:qty forKey:@"sold_by_qty"];
  4599. [params setValue:available forKey:@"available"];
  4600. [params setValue:price forKey:@"price"];
  4601. [params setValue:bestseller forKey:@"bestseller"];
  4602. [params setValue:modelname forKey:@"modelName"];
  4603. [params setValue:modeldescrip forKey:@"modelDescription"];
  4604. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4605. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4606. [params setValue:category forKey:@"category"];
  4607. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4608. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4609. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4610. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4611. [params setValue:filter forKey:@"filter"];
  4612. [params setValue:keyword forKey:@"keyword"];
  4613. [params setObject:ScreenCodeCategory forKey:kScreenName];
  4614. if (alert) {
  4615. [params setObject:@"Filter" forKey:kAction];
  4616. }
  4617. if ([RASingleton sharedInstance].homeItemClick) {
  4618. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  4619. [RASingleton sharedInstance].homeItemClick = NO;
  4620. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  4621. [RASingleton sharedInstance].homeClickedItemName = nil;
  4622. [params setObject:extra forKey:kExtra];
  4623. }
  4624. if(appDelegate.offline_mode)
  4625. {
  4626. // [OLDataProvider offline_category:params completionHandler:result];
  4627. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4628. NSMutableDictionary* json = [[OLDataProvider offline_category:params] mutableCopy];
  4629. dispatch_async(dispatch_get_main_queue(), ^{
  4630. result(json);
  4631. });
  4632. });
  4633. return;
  4634. }
  4635. [self request_interface:URL_CATEGORY parameters:params err_record_url:nil completionHandler:result retry:0];
  4636. return ;
  4637. //
  4638. // if(![self IsNetworkAvailable])
  4639. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4640. //
  4641. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  4642. // if(json==nil)
  4643. // return nil;
  4644. // NSError *error=nil;
  4645. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4646. // return jsobj;
  4647. //
  4648. }
  4649. +(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
  4650. {
  4651. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4652. AppDelegate *appDelegate = nil;
  4653. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4654. if(appDelegate.user!=nil)
  4655. [params setValue:appDelegate.user forKey:@"user"];
  4656. if(appDelegate.contact_id!=nil)
  4657. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4658. if(appDelegate.password!=nil)
  4659. [params setValue:appDelegate.password forKey:@"password"];
  4660. if(appDelegate.order_code!=nil)
  4661. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4662. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4663. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4664. if(use_name)
  4665. [params setValue:model_name forKey:@"product_name"];
  4666. else
  4667. if(use_upc){
  4668. params[@"search_upc"]=@true;
  4669. [params setValue:upc_code forKey:@"upc_code"];
  4670. }
  4671. else
  4672. [params setValue:item_id forKey:@"product_id"];
  4673. [params setValue:category_id forKey:@"category"];
  4674. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4675. [params setObject:@"Open A Model" forKey:kAction];
  4676. if (model_name) {
  4677. NSDictionary *extra = @{@"ModelName" : model_name};
  4678. [params setObject:extra forKey:kExtra];
  4679. }
  4680. if (groupName.length > 0) {
  4681. [params setObject:groupName forKey:@"groupName"];
  4682. }
  4683. if(appDelegate.offline_mode)
  4684. {
  4685. [OLDataProvider offline_model:params completionHandler:result];
  4686. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4687. // NSMutableDictionary* json = [[OLDataProvider offline_model:params] mutableCopy];
  4688. // dispatch_async(dispatch_get_main_queue(), ^{
  4689. // result(json);
  4690. // });
  4691. // });
  4692. return;
  4693. }
  4694. [self request_interface:URL_ITEM_DETAIL parameters:params err_record_url:nil completionHandler:result retry:0];
  4695. //
  4696. // if(appDelegate.offline_mode)
  4697. // return [OLDataProvider offline_model:params];
  4698. //
  4699. // if(![self IsNetworkAvailable])
  4700. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4701. //
  4702. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  4703. // if(json==nil)
  4704. // return nil;
  4705. // NSError *error=nil;
  4706. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4707. // return jsobj;
  4708. }
  4709. +(void)request_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull completionHandler:(resultHandler)result
  4710. {
  4711. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4712. AppDelegate *appDelegate = nil;
  4713. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4714. if(appDelegate.user!=nil)
  4715. [params setValue:appDelegate.user forKey:@"user"];
  4716. if(appDelegate.contact_id!=nil)
  4717. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4718. if(appDelegate.password!=nil)
  4719. [params setValue:appDelegate.password forKey:@"password"];
  4720. if(appDelegate.order_code!=nil)
  4721. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4722. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4723. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4724. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  4725. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4726. // [params setValue:filter forKey:@"filter"];
  4727. [params setValue:keywords forKey:@"keyword"];
  4728. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4729. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4730. if(matchfull)
  4731. [params setValue:@"true" forKey:@"exactMatch"];
  4732. else
  4733. [params setValue:@"false" forKey:@"exactMatch"];
  4734. [params setObject:ScreenCodeSearch forKey:kScreenName];
  4735. if (keywords) {
  4736. [params setObject:@"Search" forKey:kAction];
  4737. }
  4738. if(appDelegate.offline_mode)
  4739. {
  4740. // [OLDataProvider offline_search:params completionHandler:result];
  4741. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4742. NSMutableDictionary* json = [[OLDataProvider offline_search:params] mutableCopy];
  4743. dispatch_async(dispatch_get_main_queue(), ^{
  4744. result(json);
  4745. });
  4746. });
  4747. return;
  4748. }
  4749. [self request_interface:URL_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  4750. // if(appDelegate.offline_mode)
  4751. // {
  4752. // return [OLDataProvider offline_search:params];
  4753. // }
  4754. // if(![self IsNetworkAvailable])
  4755. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4756. //
  4757. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  4758. // if(json==nil)
  4759. // return nil;
  4760. // NSError *error=nil;
  4761. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4762. // return jsobj;
  4763. }
  4764. +(void)request_login: (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
  4765. {
  4766. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  4767. // return RESULT_NET_ERROR;
  4768. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4769. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4770. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4771. AppDelegate *appDelegate = nil;
  4772. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4773. if(appDelegate.duid !=nil)
  4774. [params setValue:appDelegate.duid forKey:@"udid"];
  4775. [params setValue:@"handset_login" forKey:@"action"];
  4776. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  4777. [params setValue:user forKey:@"user"];
  4778. [params setValue:password forKey:@"password"];
  4779. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  4780. #ifdef TEST
  4781. [params setValue:@"true" forKey:@"is_debug"];
  4782. #else
  4783. [params setValue:@"false" forKey:@"is_debug"];
  4784. #endif
  4785. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  4786. [params setObject:@"Login" forKey:kAction];
  4787. if(appDelegate.offline_mode)
  4788. {
  4789. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4790. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_login:params]] mutableCopy];
  4791. dispatch_async(dispatch_get_main_queue(), ^{
  4792. int ret = [self parse_logininfo:json user:user password:password] ;
  4793. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4794. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4795. result(retjson);
  4796. });
  4797. });
  4798. return;
  4799. }
  4800. [self request_interface:URL_UPDATE_AUTH parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *chresult) {
  4801. int ret = [self parse_logininfo:chresult user:user password:password] ;
  4802. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4803. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4804. result(retjson);
  4805. } retry:0];
  4806. //
  4807. // NSData* json= nil;
  4808. // if(appDelegate.offline_mode)
  4809. // {
  4810. // json= [OLDataProvider offline_login:params] ;
  4811. //
  4812. // }
  4813. // else
  4814. // {
  4815. // if(![self IsNetworkAvailable])
  4816. // return RESULT_NET_NOTAVAILABLE;
  4817. // json =[self get_json:URL_UPDATE_AUTH parameters:params];
  4818. //
  4819. // }
  4820. //
  4821. // if(json==nil)
  4822. // return RESULT_NET_ERROR;
  4823. //
  4824. // int ret = [self parse_authinfo:json user:user password:password];
  4825. // DebugLog(@"parse_authinfo return %d ",ret);
  4826. //
  4827. //
  4828. // return ret;
  4829. //
  4830. }
  4831. +(int)parse_logininfo : (NSMutableDictionary *) jsobj user:(NSString*) user password:(NSString*) password
  4832. {
  4833. // DebugLog(@"parse_authinfo");
  4834. // NSError *error=nil;
  4835. //
  4836. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4837. if(jsobj)
  4838. {
  4839. AppDelegate *appDelegate = nil;
  4840. //some UI methods ej
  4841. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4842. int result = [[jsobj valueForKey:@"result"] intValue];
  4843. if (result<0)
  4844. return result;
  4845. if(result!=AP_USER_AUTH&& result!=9)
  4846. {
  4847. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  4848. // [appDelegate Logout];
  4849. if(result==8)
  4850. {
  4851. return RESULT_LOGIN_DEVICE;
  4852. }
  4853. return RESULT_FALSE;
  4854. }
  4855. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  4856. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  4857. user=[objheader objectForKey:@"username"] ;
  4858. DebugLog(@"required_ver=%@ ",required_ver);
  4859. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  4860. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  4861. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  4862. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  4863. // if([ibadge isEqual:[NSNull null]])
  4864. // strbadge=@"0";
  4865. // if(ibadge==nil)
  4866. // ibadge=@"0";
  4867. // if([strbadge isEqualToString:@"null"])
  4868. // strbadge=@"0";
  4869. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  4870. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  4871. if([appDelegate.build intValue]<[required_ver intValue])
  4872. return RESULT_VER_LOW;
  4873. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  4874. appDelegate.user = user;
  4875. appDelegate.password = password;
  4876. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  4877. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  4878. appDelegate.bLogin = true;
  4879. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  4880. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  4881. {
  4882. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  4883. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  4884. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  4885. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  4886. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  4887. }
  4888. NSString* mode =[jsobj valueForKey:@"mode"] ;
  4889. [appDelegate SetMode:mode];
  4890. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  4891. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  4892. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  4893. [appDelegate update_count_mark];
  4894. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  4895. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  4896. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  4897. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  4898. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  4899. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  4900. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  4901. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  4902. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  4903. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  4904. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  4905. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  4906. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  4907. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  4908. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  4909. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  4910. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  4911. [appDelegate set_main_button_panel];
  4912. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  4913. // shop order status filter
  4914. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  4915. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  4916. // Sales order status filter
  4917. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  4918. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  4919. // specialInstruction
  4920. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  4921. //-价格类型
  4922. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  4923. // 权限
  4924. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  4925. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  4926. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  4927. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  4928. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  4929. [[RASingleton sharedInstance] resetGlobalLock];
  4930. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  4931. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  4932. }
  4933. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  4934. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  4935. // {
  4936. // // no update on the server;
  4937. // return RESULT_TRUE;
  4938. // }
  4939. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  4940. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4941. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4942. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4943. // [defaults synchronize];
  4944. //
  4945. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  4946. // NSArray* keys= [objfuncs allKeys];
  4947. /*
  4948. db.setTransactionSuccessful();
  4949. db.endTransaction();
  4950. */
  4951. return RESULT_TRUE;
  4952. }
  4953. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  4954. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  4955. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  4956. return RESULT_USERAUTH_ERROR;
  4957. }
  4958. +(void)request_contactlist:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams completionHandler:(resultHandler)result
  4959. {
  4960. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4961. if(upparams!=nil)
  4962. params = [upparams mutableCopy];
  4963. AppDelegate *appDelegate = nil;
  4964. //some UI methods ej
  4965. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4966. if(appDelegate.user!=nil)
  4967. [params setValue:appDelegate.user forKey:@"user"];
  4968. if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  4969. [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  4970. else
  4971. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4972. if(appDelegate.password!=nil)
  4973. [params setValue:appDelegate.password forKey:@"password"];
  4974. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  4975. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  4976. [params setValue:contact_type forKey:@"contactType"];
  4977. [params setValue:keywords forKey:@"keyword"];
  4978. [params setObject:ScreenCodeAccount forKey:kScreenName];
  4979. if (keywords) {
  4980. [params setObject:@"Search" forKey:kAction];
  4981. }
  4982. if (upparams) {
  4983. [params setObject:@"Advance Search" forKey:kAction];
  4984. }
  4985. NSString* url=nil;
  4986. if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  4987. url=URL_SHIPTO_LIST;
  4988. else
  4989. url=URL_CONTACT_LIST;
  4990. if(appDelegate.offline_mode)
  4991. {
  4992. [OLDataProvider offline_contactlist:params completionHandler:result];
  4993. return;
  4994. }
  4995. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  4996. //
  4997. // if(appDelegate.offline_mode)
  4998. // return [OLDataProvider offline_contactlist:params];
  4999. //
  5000. // if(![self IsNetworkAvailable])
  5001. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5002. //
  5003. // NSData* json=[self get_json:url parameters:params];
  5004. // if(json==nil)
  5005. // return nil;
  5006. // NSError *error=nil;
  5007. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5008. // return jsobj;
  5009. }
  5010. +(void)request_contactinfo:(NSString* ) contactid completionHandler:(resultHandler)result
  5011. {
  5012. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5013. AppDelegate *appDelegate = nil;
  5014. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5015. if(appDelegate.user!=nil)
  5016. [params setValue:appDelegate.user forKey:@"user"];
  5017. // if(appDelegate.contact_id!=nil)
  5018. if(appDelegate.password!=nil)
  5019. [params setValue:appDelegate.password forKey:@"password"];
  5020. [params setValue:contactid forKey:@"contactId"];
  5021. [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  5022. if(appDelegate.offline_mode)
  5023. {
  5024. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5025. // [OLDataProvider offline_contactinfo:params completionHandler:result] ;
  5026. // });
  5027. params[@"mode"]=appDelegate.mode;
  5028. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5029. NSMutableDictionary* json = [[OLDataProvider offline_contactinfo:params] mutableCopy];
  5030. dispatch_async(dispatch_get_main_queue(), ^{
  5031. result(json);
  5032. });
  5033. });
  5034. return;
  5035. }
  5036. [self request_interface:URL_CUSTOMER_INFO parameters:params err_record_url:nil completionHandler:result retry:0];
  5037. // if(appDelegate.offline_mode)
  5038. // return [OLDataProvider offline_contactinfo:params];
  5039. // if(![self IsNetworkAvailable])
  5040. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5041. //
  5042. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  5043. // if(json==nil)
  5044. // return nil;
  5045. // NSError *error=nil;
  5046. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5047. // return jsobj;
  5048. //
  5049. }
  5050. +(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  5051. {
  5052. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5053. AppDelegate *appDelegate = nil;
  5054. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5055. if(appDelegate.user!=nil)
  5056. [params setValue:appDelegate.user forKey:@"user"];
  5057. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  5058. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  5059. // else
  5060. if(appDelegate.contact_id!=nil)
  5061. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5062. if(appDelegate.password!=nil)
  5063. [params setValue:appDelegate.password forKey:@"password"];
  5064. if(appDelegate.order_code!=nil)
  5065. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5066. bool can_create_backorder=appDelegate.can_create_backorder;
  5067. // [params setValue:sourceid forKey:@"sourceid"];
  5068. // [params setValue:editor forKey:@"editor"];
  5069. DebugLog(@"request editor url:%@",request_url);
  5070. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  5071. {
  5072. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  5073. }
  5074. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  5075. {
  5076. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  5077. }
  5078. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  5079. {
  5080. [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  5081. }
  5082. else if([request_url isEqualToString:URL_CARTDELIVERY])
  5083. {
  5084. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  5085. }
  5086. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  5087. {
  5088. [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  5089. }
  5090. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  5091. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  5092. }
  5093. if(appDelegate.offline_mode)
  5094. {
  5095. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5096. NSData* json = nil;
  5097. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  5098. {
  5099. json= [OLDataProvider offline_createContact:params];
  5100. }
  5101. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  5102. {
  5103. json= [OLDataProvider offline_editContact:params];
  5104. }
  5105. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  5106. {
  5107. json= [OLDataProvider offline_contactAdvancedSearch:params];
  5108. }
  5109. else if([request_url isEqualToString:URL_CARTDELIVERY])
  5110. {
  5111. params[@"contact_id"]=params[@"contactId"];
  5112. params[@"can_create_backorder"]=@(can_create_backorder);
  5113. json= [OLDataProvider offline_placeorder:params];
  5114. }
  5115. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  5116. {
  5117. json= [OLDataProvider offline_addreditor:params];
  5118. }
  5119. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  5120. json = [OLDataProvider offline_createTearSheet:params];
  5121. }
  5122. dispatch_async(dispatch_get_main_queue(), ^{
  5123. if(json==nil)
  5124. result( [[OLDataProvider offline_notimpl] mutableCopy]);
  5125. else
  5126. result([[RAConvertor data2dict:json] mutableCopy]);
  5127. });
  5128. });
  5129. return;
  5130. }
  5131. else
  5132. {
  5133. if([request_url isEqualToString:URL_CARTDELIVERY])
  5134. {
  5135. NSString * uuid= [[NSUUID UUID] UUIDString];
  5136. params[@"resultSerial"]=uuid;
  5137. __block bool bbreak = false;
  5138. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5139. for(int i=0;i<150;i++)
  5140. {
  5141. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  5142. // result_params[@"resultSerial"]=uuid;
  5143. //json=[self get_json:request_url parameters:params];
  5144. if(bbreak)
  5145. break;
  5146. dispatch_async(dispatch_get_main_queue(), ^{
  5147. NSLog(@"request cart delivery %d",i);
  5148. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5149. if(resulti!=nil)
  5150. {
  5151. if([resulti[@"result"] intValue]==2 || [resulti[@"result"] intValue] == 8)
  5152. {
  5153. if(!bbreak) //此判断保证result只调用一次。
  5154. {
  5155. result(resulti);
  5156. NSLog(@"result called at %d",i);
  5157. }
  5158. bbreak=true;
  5159. }
  5160. }
  5161. } retry:3];
  5162. });
  5163. // [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  5164. sleep(2);
  5165. }
  5166. });
  5167. }
  5168. else
  5169. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  5170. }
  5171. // if(json!=nil)
  5172. // {
  5173. // NSError *error=nil;
  5174. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5175. // return jsobj;
  5176. // }
  5177. // else
  5178. // return nil;
  5179. }
  5180. +(void)request_wishlist:(int)sort completionHandler:(resultHandler)result
  5181. {
  5182. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5183. AppDelegate *appDelegate = nil;
  5184. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5185. if(appDelegate.user!=nil)
  5186. [params setValue:appDelegate.user forKey:@"user"];
  5187. if(appDelegate.contact_id!=nil)
  5188. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5189. if(appDelegate.password!=nil)
  5190. [params setValue:appDelegate.password forKey:@"password"];
  5191. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  5192. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  5193. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  5194. [params setObject:ScreenCodeWishList forKey:kScreenName];
  5195. if(appDelegate.offline_mode)
  5196. {
  5197. [OLDataProvider offline_wishlist:params completionHandler:^(NSMutableDictionary *resulti) {
  5198. int result_code = [[resulti valueForKey:@"result"] intValue];
  5199. if (result_code==2)
  5200. {
  5201. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  5202. [appDelegate update_count_mark];;
  5203. result(resulti);
  5204. }
  5205. }];
  5206. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5207. // NSMutableDictionary* json = [[OLDataProvider offline_wishlist:params] mutableCopy];
  5208. // dispatch_async(dispatch_get_main_queue(), ^{
  5209. // result(json);
  5210. // });
  5211. // });
  5212. return;
  5213. }
  5214. [self request_interface:URL_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5215. int result_code = [[resulti valueForKey:@"result"] intValue];
  5216. if (result_code==2)
  5217. {
  5218. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  5219. [appDelegate update_count_mark];;
  5220. result(resulti);
  5221. }
  5222. } retry:0];
  5223. // if(appDelegate.offline_mode)
  5224. // {
  5225. // return [OLDataProvider offline_wishlist:params];
  5226. // }
  5227. // if(![self IsNetworkAvailable])
  5228. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5229. //
  5230. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  5231. // if(json==nil)
  5232. // return nil;
  5233. // NSError *error=nil;
  5234. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5235. // int result = [[jsobj valueForKey:@"result"] intValue];
  5236. //
  5237. // if (result==2)
  5238. // {
  5239. //
  5240. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5241. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  5242. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5243. //
  5244. // [appDelegate update_count_mark];
  5245. // }
  5246. // return jsobj;
  5247. }
  5248. +(void)request_portfoliolist:(int)sort completionHandler:(resultHandler)result
  5249. {
  5250. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5251. AppDelegate *appDelegate = nil;
  5252. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5253. if(appDelegate.user!=nil)
  5254. [params setValue:appDelegate.user forKey:@"user"];
  5255. if(appDelegate.contact_id!=nil)
  5256. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5257. if(appDelegate.password!=nil)
  5258. [params setValue:appDelegate.password forKey:@"password"];
  5259. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  5260. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  5261. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  5262. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  5263. if(appDelegate.offline_mode)
  5264. {
  5265. params[@"user"]=appDelegate.user;
  5266. params[@"contact_id"]=appDelegate.contact_id;
  5267. params[@"can_see_price"]=@(appDelegate.can_see_price);
  5268. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5269. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_portfolioList:params]] mutableCopy];
  5270. dispatch_async(dispatch_get_main_queue(), ^{
  5271. if ([json[@"result"] intValue]==2)
  5272. {
  5273. appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  5274. [appDelegate update_count_mark];
  5275. }
  5276. result(json);
  5277. });
  5278. });
  5279. return;
  5280. }
  5281. [self request_interface:URL_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5282. if ([resulti[@"result"] intValue]==2)
  5283. {
  5284. appDelegate.port_count =[[resulti valueForKey:@"count"] intValue];
  5285. [appDelegate update_count_mark];
  5286. }
  5287. result(resulti);
  5288. } retry:0];
  5289. // NSData* json = nil;
  5290. // if(appDelegate.offline_mode)
  5291. // {
  5292. // json = [OLDataProvider offline_portfolioList:params];
  5293. // } else {
  5294. // if(![self IsNetworkAvailable])
  5295. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5296. //
  5297. // json = [self get_json:URL_PORTFOLIO parameters:params];
  5298. // }
  5299. //
  5300. //
  5301. // if(json==nil)
  5302. // return nil;
  5303. // NSError *error=nil;
  5304. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5305. // int result = [[jsobj valueForKey:@"result"] intValue];
  5306. //
  5307. // if (result==2)
  5308. // {
  5309. //
  5310. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5311. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  5312. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  5313. //
  5314. // [appDelegate update_count_mark];
  5315. // }
  5316. // return jsobj;
  5317. }
  5318. +(void)request_portfoliopdf:(int ) offset limit:(int)limit keywords:(NSString* ) keywords completionHandler:(resultHandler)result
  5319. {
  5320. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5321. AppDelegate *appDelegate = nil;
  5322. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5323. if(appDelegate.user!=nil)
  5324. [params setValue:appDelegate.user forKey:@"user"];
  5325. if(appDelegate.contact_id!=nil)
  5326. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5327. if(appDelegate.password!=nil)
  5328. [params setValue:appDelegate.password forKey:@"password"];
  5329. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  5330. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  5331. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  5332. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  5333. // [params setValue:filter forKey:@"filter"];
  5334. [params setValue:keywords forKey:@"keyWord"];
  5335. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  5336. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  5337. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  5338. if (keywords) {
  5339. [params setObject:@"Search" forKey:kAction];
  5340. }
  5341. if(appDelegate.offline_mode)
  5342. {
  5343. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5344. NSData* json = [[OLDataProvider offline_pdfList:params] mutableCopy];
  5345. dispatch_async(dispatch_get_main_queue(), ^{
  5346. result([[RAConvertor data2dict:json] mutableCopy]);
  5347. });
  5348. });
  5349. return;
  5350. }
  5351. [self request_interface:URL_DM_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  5352. return;
  5353. // NSData* json = nil;
  5354. // if(appDelegate.offline_mode)
  5355. // {
  5356. // json = [OLDataProvider offline_pdfList:params];
  5357. // } else {
  5358. // if(![self IsNetworkAvailable])
  5359. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5360. //
  5361. // json=[self get_json:URL_DM_LIST parameters:params];
  5362. // }
  5363. // if(json==nil)
  5364. // return nil;
  5365. // NSError *error=nil;
  5366. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5367. // return jsobj;
  5368. }
  5369. +(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
  5370. {
  5371. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5372. AppDelegate *appDelegate = nil;
  5373. //some UI methods ej
  5374. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5375. if(appDelegate.user!=nil)
  5376. [params setValue:appDelegate.user forKey:@"user"];
  5377. if(appDelegate.contact_id!=nil)
  5378. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5379. if(appDelegate.password!=nil)
  5380. [params setValue:appDelegate.password forKey:@"password"];
  5381. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  5382. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  5383. [params setValue:keywords forKey:@"keyWord"];
  5384. [params setValue:customer forKey:@"customer_filter"];
  5385. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  5386. [params setValue:status_code forKey:@"orderStatus"];
  5387. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  5388. if (keywords) {
  5389. [params setObject:@"Search" forKey:kAction];
  5390. }
  5391. if(appDelegate.offline_mode)
  5392. {
  5393. params[@"user"]=appDelegate.user;
  5394. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5395. NSData* json = [[OLDataProvider offline_orderlist:params] mutableCopy];
  5396. dispatch_async(dispatch_get_main_queue(), ^{
  5397. result([[RAConvertor data2dict:json] mutableCopy]);
  5398. });
  5399. });
  5400. return;
  5401. }
  5402. [self request_interface:URL_ORDER_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  5403. // NSData* json=nil;
  5404. // if(appDelegate.offline_mode)
  5405. // {
  5406. // json= [OLDataProvider offline_orderlist:params];
  5407. // }
  5408. // else
  5409. // {
  5410. // if(![self IsNetworkAvailable])
  5411. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5412. //
  5413. // json=[self get_json:URL_ORDER_LIST parameters:params];
  5414. // }
  5415. // if(json==nil)
  5416. // return nil;
  5417. // NSError *error=nil;
  5418. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5419. // return jsobj;
  5420. }
  5421. +(void)request_logout:(resultHandler)result
  5422. {
  5423. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5424. AppDelegate *appDelegate = nil;
  5425. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5426. if(appDelegate.user!=nil)
  5427. [params setValue:appDelegate.user forKey:@"user"];
  5428. if(appDelegate.password!=nil)
  5429. [params setValue:appDelegate.password forKey:@"password"];
  5430. if(appDelegate.offline_mode)
  5431. {
  5432. [OLDataProvider offline_logout:params completionHandler:result];
  5433. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5434. // NSMutableDictionary* json = [[OLDataProvider offline_logout:params] mutableCopy];
  5435. // dispatch_async(dispatch_get_main_queue(), ^{
  5436. // result(json);
  5437. // });
  5438. // });
  5439. return;
  5440. }
  5441. [self request_interface:URL_LOGOUT parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5442. NSMutableDictionary* jsobj=resulti;
  5443. int result_code = [[jsobj valueForKey:@"result"] intValue];
  5444. if (result_code==2)
  5445. {
  5446. appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  5447. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5448. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5449. [appDelegate update_count_mark];
  5450. appDelegate.can_show_price =false;
  5451. appDelegate.can_see_price =false;
  5452. appDelegate.can_create_portfolio =false;
  5453. appDelegate.can_create_order =false;
  5454. appDelegate.can_cancel_order =false;
  5455. appDelegate.can_set_cart_price =false;
  5456. appDelegate.can_delete_order =false;
  5457. appDelegate.can_submit_order =false;
  5458. appDelegate.can_set_tearsheet_price =false;
  5459. appDelegate.can_update_contact_info = false;
  5460. appDelegate.save_order_logout = false;
  5461. appDelegate.submit_order_logout = false;
  5462. appDelegate.alert_sold_in_quantities = false;
  5463. appDelegate.ipad_perm =nil ;
  5464. appDelegate.user_type = USER_ROLE_UNKNOWN;
  5465. appDelegate.OrderFilter= nil;
  5466. [appDelegate SetSo:nil];
  5467. [appDelegate set_main_button_panel];
  5468. #ifdef RA_NOTIFICATION
  5469. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5470. #endif
  5471. }
  5472. result(resulti);
  5473. } retry:0];
  5474. //
  5475. // if(appDelegate.offline_mode)
  5476. // {
  5477. // return [OLDataProvider offline_logout:params];
  5478. // }
  5479. // if(![self IsNetworkAvailable])
  5480. // {
  5481. // DebugLog(@"NET ERR");
  5482. //
  5483. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5484. // // return nil;
  5485. // }
  5486. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  5487. // //if(json==nil)
  5488. //
  5489. //
  5490. // if(json==nil)
  5491. // return nil;
  5492. // NSError *error=nil;
  5493. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5494. // int result = [[jsobj valueForKey:@"result"] intValue];
  5495. //
  5496. // if (result==2)
  5497. // {
  5498. //
  5499. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  5500. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5501. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5502. //
  5503. // [appDelegate update_count_mark];
  5504. //
  5505. //
  5506. // appDelegate.can_show_price =false;
  5507. // appDelegate.can_see_price =false;
  5508. // appDelegate.can_create_portfolio =false;
  5509. // appDelegate.can_create_order =false;
  5510. //
  5511. //
  5512. // appDelegate.can_cancel_order =false;
  5513. // appDelegate.can_set_cart_price =false;
  5514. // appDelegate.can_delete_order =false;
  5515. // appDelegate.can_submit_order =false;
  5516. // appDelegate.can_set_tearsheet_price =false;
  5517. // appDelegate.can_update_contact_info = false;
  5518. //
  5519. // appDelegate.save_order_logout = false;
  5520. // appDelegate.submit_order_logout = false;
  5521. // appDelegate.alert_sold_in_quantities = false;
  5522. //
  5523. // appDelegate.ipad_perm =nil ;
  5524. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  5525. // appDelegate.OrderFilter= nil;
  5526. // [appDelegate SetSo:nil];
  5527. // [appDelegate set_main_button_panel];
  5528. //#ifdef RA_NOTIFICATION
  5529. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5530. //#endif
  5531. // }
  5532. // return jsobj;
  5533. }
  5534. + (void)request_hangtag:(NSString *)group completionHandler:(resultHandler)result
  5535. {
  5536. #ifdef BUILD_UWAVER
  5537. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5538. AppDelegate *appDelegate = nil;
  5539. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5540. if(appDelegate.user!=nil)
  5541. [params setValue:appDelegate.user forKey:@"user"];
  5542. if(appDelegate.contact_id!=nil)
  5543. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5544. if(appDelegate.password!=nil)
  5545. [params setValue:appDelegate.password forKey:@"password"];
  5546. if (group) {
  5547. [params setValue:group forKey:@"groupName"];
  5548. }
  5549. NSString * uuid= [[NSUUID UUID] UUIDString];
  5550. params[@"resultSerial"]=uuid;
  5551. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  5552. if(appDelegate.offline_mode)
  5553. {
  5554. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5555. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5556. dispatch_async(dispatch_get_main_queue(), ^{
  5557. result(json);
  5558. });
  5559. });
  5560. return;
  5561. }
  5562. [self request_interface:URL_CREATE_HANG_TAG parameters:params err_record_url:nil completionHandler:result retry:0];
  5563. // NSData* json = nil;
  5564. // if(appDelegate.offline_mode)
  5565. // {
  5566. // json = [OLDataProvider offline_portfolioList:params];
  5567. // } else {
  5568. // if(![self IsNetworkAvailable])
  5569. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5570. //
  5571. // json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  5572. // }
  5573. //
  5574. //
  5575. // if(json==nil)
  5576. // return nil;
  5577. // NSError *error=nil;
  5578. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5579. //
  5580. // return jsobj;
  5581. #else
  5582. return result(nil);
  5583. #endif
  5584. }
  5585. + (void)request_movetobackorder:(NSString *)cart_item_id completionHandler:(resultHandler)result
  5586. {
  5587. if (cart_item_id == nil || cart_item_id.length < 1) {
  5588. result([@{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"} mutableCopy]);
  5589. }
  5590. AppDelegate *appDelegate = nil;
  5591. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5592. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5593. if(appDelegate.user!=nil)
  5594. [dic setValue:appDelegate.user forKey:@"user"];
  5595. if(appDelegate.password!=nil)
  5596. [dic setValue:appDelegate.password forKey:@"password"];
  5597. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  5598. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  5599. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5600. if(appDelegate.offline_mode)
  5601. {
  5602. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5603. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5604. dispatch_async(dispatch_get_main_queue(), ^{
  5605. result(json);
  5606. });
  5607. });
  5608. return;
  5609. }
  5610. [self request_interface:URL_MOVE_TO_BACK_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5611. // if(![self IsNetworkAvailable])
  5612. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5613. //
  5614. // NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  5615. //
  5616. // if(json!=nil)
  5617. // {
  5618. // NSError *error=nil;
  5619. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5620. //
  5621. // return jsobj;
  5622. // }
  5623. //
  5624. // return @{@"result" : @(RESULT_FALSE)};
  5625. }
  5626. + (void)request_emailwishlist:(NSString *)addr completionHandler:(resultHandler)result
  5627. {
  5628. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5629. AppDelegate *appDelegate = nil;
  5630. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5631. if(appDelegate.user!=nil)
  5632. [dic setValue:appDelegate.user forKey:@"user"];
  5633. if(appDelegate.password!=nil)
  5634. [dic setValue:appDelegate.password forKey:@"password"];
  5635. [dic setValue:addr forKey:@"email"];
  5636. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  5637. // if (appDelegate.customerInfo) {
  5638. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5639. // if (customer_cid) {
  5640. // [dic setValue:customer_cid forKey:@"contactId"];
  5641. // }
  5642. // }
  5643. if(appDelegate.offline_mode)
  5644. {
  5645. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5646. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5647. dispatch_async(dispatch_get_main_queue(), ^{
  5648. result(json);
  5649. });
  5650. });
  5651. return;
  5652. }
  5653. [self request_interface:URL_EMAIL_WISHLIST parameters:dic err_record_url:nil completionHandler:result retry:0];
  5654. // NSData* json=nil;
  5655. // if(appDelegate.offline_mode)
  5656. // {
  5657. // return [OLDataProvider offline_notimpl];
  5658. // }
  5659. // else
  5660. // {
  5661. // if(![self IsNetworkAvailable])
  5662. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5663. //
  5664. // json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  5665. // }
  5666. // if(json!=nil)
  5667. // {
  5668. // NSError *error=nil;
  5669. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5670. //
  5671. //
  5672. // return jsobj;
  5673. // }
  5674. //
  5675. // return @{@"result" : @(RESULT_FALSE)};
  5676. }
  5677. +(void)request_notifymodel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  5678. {
  5679. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5680. AppDelegate *appDelegate = nil;
  5681. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5682. if(appDelegate.user!=nil)
  5683. [dic setValue:appDelegate.user forKey:@"user"];
  5684. if(appDelegate.password!=nil)
  5685. [dic setValue:appDelegate.password forKey:@"password"];
  5686. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5687. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5688. if (customer_cid) {
  5689. [dic setValue:customer_cid forKey:@"contactId"];
  5690. }
  5691. }
  5692. [dic setObject:screenName forKey:kScreenName];
  5693. [dic setValue:modelID forKey:@"productId"];
  5694. if (addr) { // 弹框输入
  5695. [dic setValue:addr forKey:@"email"];
  5696. } else {
  5697. // employee选择了Contact,并且Contact有Email
  5698. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5699. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  5700. // if (email) {
  5701. // [dic setValue:email forKey:@"email"];
  5702. // }
  5703. // }
  5704. }
  5705. if(appDelegate.offline_mode)
  5706. {
  5707. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5708. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5709. dispatch_async(dispatch_get_main_queue(), ^{
  5710. result(json);
  5711. });
  5712. });
  5713. return;
  5714. }
  5715. [self request_interface:URL_NOTIFY_ME parameters:dic err_record_url:nil completionHandler:result retry:0];
  5716. // NSData* json=nil;
  5717. // if(appDelegate.offline_mode)
  5718. // {
  5719. // return [OLDataProvider offline_notimpl];
  5720. // }
  5721. // else
  5722. // {
  5723. // if(![self IsNetworkAvailable])
  5724. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5725. //
  5726. // json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  5727. // }
  5728. // if(json!=nil)
  5729. // {
  5730. // NSError *error=nil;
  5731. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5732. //
  5733. //
  5734. // return jsobj;
  5735. // }
  5736. //
  5737. // return @{@"result" : @(RESULT_FALSE)};
  5738. }
  5739. + (void)request_qouteorder:(NSString *)so_id emailAddr:(NSString *)addr completionHandler:(resultHandler)result
  5740. {
  5741. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5742. AppDelegate *appDelegate = nil;
  5743. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5744. if(appDelegate.user!=nil)
  5745. [dic setValue:appDelegate.user forKey:@"user"];
  5746. if(appDelegate.password!=nil)
  5747. [dic setValue:appDelegate.password forKey:@"password"];
  5748. [dic setValue:so_id forKey:@"orderCode"];
  5749. [dic setValue:addr forKey:@"email"];
  5750. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5751. if (appDelegate.customerInfo) {
  5752. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5753. if (customer_cid) {
  5754. [dic setValue:customer_cid forKey:@"contactId"];
  5755. }
  5756. }
  5757. if(appDelegate.offline_mode)
  5758. {
  5759. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5760. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5761. dispatch_async(dispatch_get_main_queue(), ^{
  5762. result(json);
  5763. });
  5764. });
  5765. return;
  5766. }
  5767. [self request_interface:URL_EMAIL_CART parameters:dic err_record_url:nil completionHandler:result retry:0];
  5768. // NSData* json=nil;
  5769. // if(appDelegate.offline_mode)
  5770. // {
  5771. // return [OLDataProvider offline_notimpl];
  5772. // }
  5773. // else
  5774. // {
  5775. // if(![self IsNetworkAvailable])
  5776. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5777. //
  5778. // json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  5779. // }
  5780. // if(json!=nil)
  5781. // {
  5782. // NSError *error=nil;
  5783. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5784. //
  5785. //
  5786. // return jsobj;
  5787. // }
  5788. //
  5789. // return @{@"result" : @(RESULT_FALSE)};
  5790. }
  5791. + (void)request_mergeorder:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  5792. {
  5793. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5794. AppDelegate *appDelegate = nil;
  5795. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5796. if(appDelegate.user!=nil)
  5797. [dic setValue:appDelegate.user forKey:@"user"];
  5798. if(appDelegate.password!=nil)
  5799. [dic setValue:appDelegate.password forKey:@"password"];
  5800. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  5801. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  5802. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  5803. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  5804. if(appDelegate.offline_mode)
  5805. {
  5806. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5807. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5808. dispatch_async(dispatch_get_main_queue(), ^{
  5809. result(json);
  5810. });
  5811. });
  5812. return;
  5813. }
  5814. [self request_interface:URL_SET_MERGE_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5815. // NSData* json=nil;
  5816. // if(appDelegate.offline_mode)
  5817. // {
  5818. // return [OLDataProvider offline_notimpl];
  5819. // }
  5820. // else
  5821. // {
  5822. // if(![self IsNetworkAvailable])
  5823. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5824. //
  5825. // json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  5826. // }
  5827. // if(json!=nil)
  5828. // {
  5829. // NSError *error=nil;
  5830. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5831. //
  5832. //
  5833. // return jsobj;
  5834. // }
  5835. // else
  5836. // return nil;
  5837. }
  5838. +(void)request_pendingorder:(NSString *)contactid completionHandler:(resultHandler)result
  5839. {
  5840. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5841. AppDelegate *appDelegate = nil;
  5842. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5843. if(appDelegate.user!=nil)
  5844. [params setValue:appDelegate.user forKey:@"user"];
  5845. // if(appDelegate.contact_id!=nil)
  5846. if(appDelegate.password!=nil)
  5847. [params setValue:appDelegate.password forKey:@"password"];
  5848. [params setValue:contactid forKey:@"contactId"];
  5849. if(appDelegate.offline_mode)
  5850. {
  5851. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5852. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5853. dispatch_async(dispatch_get_main_queue(), ^{
  5854. result(json);
  5855. });
  5856. });
  5857. return;
  5858. }
  5859. [self request_interface:URL_CUSTOMER_PENDINGORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  5860. //
  5861. // if(appDelegate.offline_mode)
  5862. // {
  5863. // return [OLDataProvider offline_notimpl];
  5864. // }
  5865. // if(![self IsNetworkAvailable])
  5866. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5867. //
  5868. // NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  5869. // if(json==nil)
  5870. // return nil;
  5871. // NSError *error=nil;
  5872. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5873. // return jsobj;
  5874. //
  5875. }
  5876. +(void) request_removeportfolio:(NSString* ) item_ids completionHandler:(resultHandler)result
  5877. {
  5878. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5879. AppDelegate *appDelegate = nil;
  5880. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5881. if(appDelegate.user!=nil)
  5882. [params setValue:appDelegate.user forKey:@"user"];
  5883. if(appDelegate.contact_id!=nil)
  5884. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5885. if(appDelegate.password!=nil)
  5886. [params setValue:appDelegate.password forKey:@"password"];
  5887. [params setValue:item_ids forKey:@"portfolioId"];
  5888. // [params setValue:editor forKey:@"editor"];
  5889. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  5890. if(appDelegate.offline_mode)
  5891. {
  5892. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5893. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_removePortfolio:params]] mutableCopy];
  5894. dispatch_async(dispatch_get_main_queue(), ^{
  5895. int result_code = [[resulti valueForKey:@"result"] intValue];
  5896. if (result_code==2)
  5897. {
  5898. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5899. [appDelegate update_count_mark];
  5900. };
  5901. result(resulti);
  5902. });
  5903. });
  5904. return;
  5905. }
  5906. [self request_interface:URL_PORTFOLIO_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5907. int result_code = [[resulti valueForKey:@"result"] intValue];
  5908. if (result_code==2)
  5909. {
  5910. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5911. [appDelegate update_count_mark];
  5912. };
  5913. result(resulti);
  5914. } retry:0];
  5915. // NSData* json = nil;
  5916. // if(appDelegate.offline_mode)
  5917. // {
  5918. // json = [OLDataProvider offline_removePortfolio:params];
  5919. // } else {
  5920. // if(![self IsNetworkAvailable])
  5921. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5922. // json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  5923. // }
  5924. // if(json!=nil)
  5925. // {
  5926. // NSError *error=nil;
  5927. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5928. //
  5929. //
  5930. // int result = [[jsobj valueForKey:@"result"] intValue];
  5931. //
  5932. // if (result==2)
  5933. // {
  5934. //
  5935. //
  5936. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5937. //
  5938. // [appDelegate update_count_mark];
  5939. // }
  5940. // return jsobj;
  5941. // }
  5942. // else
  5943. // return nil;
  5944. }
  5945. +(void) request_removeportfoliopdf:(NSString* ) listid completionHandler:(resultHandler)result
  5946. {
  5947. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5948. AppDelegate *appDelegate = nil;
  5949. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5950. if(appDelegate.user!=nil)
  5951. [params setValue:appDelegate.user forKey:@"user"];
  5952. if(appDelegate.contact_id!=nil)
  5953. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5954. if(appDelegate.password!=nil)
  5955. [params setValue:appDelegate.password forKey:@"password"];
  5956. [params setValue:listid forKey:@"tearsheetsId"];
  5957. // [params setValue:editor forKey:@"editor"];
  5958. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  5959. // [params setValue:@"Delete Portfolio" forKey:kAction];
  5960. if(appDelegate.offline_mode)
  5961. {
  5962. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5963. NSData* json = [[OLDataProvider offline_removePDF:params] mutableCopy];
  5964. dispatch_async(dispatch_get_main_queue(), ^{
  5965. result([[RAConvertor data2dict:json] mutableCopy]);
  5966. });
  5967. });
  5968. return;
  5969. }
  5970. [self request_interface:URL_PORTFOLIOLIST_REMOVE parameters:params err_record_url:nil completionHandler:result retry:0];
  5971. }
  5972. +(void) request_remove_wishlist:(NSString* ) item_ids completionHandler:(resultHandler)result
  5973. {
  5974. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5975. __block AppDelegate *appDelegate = nil;
  5976. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5977. if(appDelegate.user!=nil)
  5978. [params setValue:appDelegate.user forKey:@"user"];
  5979. if(appDelegate.contact_id!=nil)
  5980. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5981. if(appDelegate.password!=nil)
  5982. [params setValue:appDelegate.password forKey:@"password"];
  5983. [params setValue:item_ids forKey:@"collectId"];
  5984. // [params setValue:editor forKey:@"editor"];
  5985. [params setValue:ScreenCodeWishList forKey:kScreenName];
  5986. if(appDelegate.offline_mode)
  5987. {
  5988. // [OLDataProvider offline_deletewishlist:params completionHandler:result];
  5989. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5990. NSMutableDictionary* resulti = [[OLDataProvider offline_deletewishlist:params] mutableCopy];
  5991. dispatch_async(dispatch_get_main_queue(), ^{
  5992. int result_code = [[resulti valueForKey:@"result"] intValue];
  5993. if (result_code==2)
  5994. {
  5995. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  5996. [appDelegate update_count_mark];
  5997. };
  5998. result(resulti);
  5999. });
  6000. });
  6001. return;
  6002. }
  6003. [self request_interface:URL_WATCHLIST_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6004. int result_code = [[resulti valueForKey:@"result"] intValue];
  6005. if (result_code==2)
  6006. {
  6007. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6008. [appDelegate update_count_mark];
  6009. };
  6010. result(resulti);
  6011. } retry:0];
  6012. //
  6013. //
  6014. // if(appDelegate.offline_mode)
  6015. // {
  6016. // return [OLDataProvider offline_deletewishlist:params];
  6017. // }
  6018. // if(![self IsNetworkAvailable])
  6019. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6020. //
  6021. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  6022. // if(json!=nil)
  6023. // {
  6024. // NSError *error=nil;
  6025. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6026. // int result = [[jsobj valueForKey:@"result"] intValue];
  6027. //
  6028. // if (result==2)
  6029. // {
  6030. //
  6031. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6032. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6033. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6034. //
  6035. // [appDelegate update_count_mark];
  6036. // }
  6037. // return jsobj;
  6038. // }
  6039. // else
  6040. // return nil;
  6041. }
  6042. +(void) request_remove_cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  6043. {
  6044. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6045. AppDelegate *appDelegate = nil;
  6046. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6047. #ifdef SCANNER_ORDER
  6048. if(RASingleton.sharedInstance.enable_OfflineOrder)
  6049. {
  6050. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  6051. //
  6052. //
  6053. // [appDelegate update_count_mark];
  6054. NSArray* arr=[RAConvertor string2arr:item_ids separator:@","];
  6055. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  6056. NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  6057. NSMutableDictionary* newsection =[cartTemplate[@"section_0"] mutableCopy];
  6058. int newcount = 0;
  6059. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  6060. int count = [section[@"count"] intValue];
  6061. for(int i=0;i<count;i++)
  6062. {
  6063. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  6064. int index = [arr indexOfObject:item[@"cart_item_id"]] ;
  6065. if(index <0)
  6066. {
  6067. newsection[[NSString stringWithFormat:@"item_%d",newcount]] = item;
  6068. newcount ++;
  6069. }
  6070. }
  6071. newsection[@"count"]=@(newcount);
  6072. RASingleton.sharedInstance.scan_cart[@"section_0"] = newsection;
  6073. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  6074. result(RASingleton.sharedInstance.scan_cart);
  6075. return;
  6076. }
  6077. #endif
  6078. if(appDelegate.user!=nil)
  6079. [params setValue:appDelegate.user forKey:@"user"];
  6080. if(appDelegate.contact_id!=nil)
  6081. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6082. if(appDelegate.password!=nil)
  6083. [params setValue:appDelegate.password forKey:@"password"];
  6084. if(appDelegate.order_code!=nil)
  6085. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6086. [params setValue:item_ids forKey:@"cartItemId"];
  6087. // [params setValue:editor forKey:@"editor"];
  6088. [params setValue:ScreenCodeCart forKey:kScreenName];
  6089. // [params setValue:@"" forKey:kAction];
  6090. if(appDelegate.offline_mode)
  6091. {
  6092. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6093. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_cartremove:params]] mutableCopy];
  6094. dispatch_async(dispatch_get_main_queue(), ^{
  6095. int result_code = [[resulti valueForKey:@"result"] intValue];
  6096. if (result_code==2)
  6097. {
  6098. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6099. [appDelegate update_count_mark];
  6100. };
  6101. result(resulti);
  6102. });
  6103. });
  6104. return;
  6105. }
  6106. [self request_interface:URL_CART_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6107. int result_code = [[resulti valueForKey:@"result"] intValue];
  6108. if (result_code==2)
  6109. {
  6110. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6111. [appDelegate update_count_mark];
  6112. };
  6113. result(resulti);
  6114. } retry:0];
  6115. //
  6116. // NSData* json=nil;
  6117. // if(appDelegate.offline_mode)
  6118. // {
  6119. // json= [OLDataProvider offline_cartremove:params];
  6120. // }
  6121. // else
  6122. // {
  6123. // if(![self IsNetworkAvailable])
  6124. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6125. //
  6126. // json=[self get_json:URL_CART_REMOVE parameters:params];
  6127. // }
  6128. // if(json!=nil)
  6129. // {
  6130. // NSError *error=nil;
  6131. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6132. //
  6133. // int result = [[jsobj valueForKey:@"result"] intValue];
  6134. //
  6135. // if (result==2)
  6136. // {
  6137. //
  6138. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6139. //
  6140. //
  6141. // [appDelegate update_count_mark];
  6142. // }
  6143. // return jsobj;
  6144. // }
  6145. // else
  6146. // return nil;
  6147. }
  6148. +(void) request_create_order:(resultHandler)result
  6149. {
  6150. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6151. AppDelegate *appDelegate = nil;
  6152. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6153. if(appDelegate.user!=nil)
  6154. [params setValue:appDelegate.user forKey:@"user"];
  6155. if(appDelegate.contact_id!=nil)
  6156. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6157. if(appDelegate.password!=nil)
  6158. [params setValue:appDelegate.password forKey:@"password"];
  6159. if(appDelegate.order_code!=nil)
  6160. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6161. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  6162. NSDictionary* customerinfo= appDelegate.customerInfo;
  6163. NSArray* keys=[customerinfo allKeys];
  6164. for(int i=0;i<keys.count;i++)
  6165. {
  6166. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  6167. }
  6168. if(appDelegate.offline_mode)
  6169. {
  6170. [OLDataProvider offline_createorder:params completionHandler:^(NSMutableDictionary *resulti) {
  6171. int result_code = [[resulti valueForKey:@"result"] intValue];
  6172. if (result_code==2)
  6173. {
  6174. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6175. [appDelegate update_count_mark];
  6176. };
  6177. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  6178. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6179. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  6180. }
  6181. result(resulti);
  6182. }];
  6183. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6184. // NSData* json = [[OLDataProvider offline_createorder:params] mutableCopy];
  6185. // dispatch_async(dispatch_get_main_queue(), ^{
  6186. // result([[RAConvertor data2dict:json] mutableCopy]);
  6187. // });
  6188. // });
  6189. return;
  6190. }
  6191. [self request_interface:URL_NEW_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6192. int result_code = [[resulti valueForKey:@"result"] intValue];
  6193. if (result_code==2)
  6194. {
  6195. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6196. [appDelegate update_count_mark];
  6197. };
  6198. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  6199. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6200. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  6201. }
  6202. result(resulti);
  6203. } retry:0];
  6204. //
  6205. // NSData* json = nil;
  6206. // if(appDelegate.offline_mode)
  6207. // {
  6208. // json= [OLDataProvider offline_createorder:params];
  6209. // }
  6210. // else
  6211. // {
  6212. // if(![self IsNetworkAvailable])
  6213. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6214. //
  6215. // json=[self get_json:URL_NEW_ORDER parameters:params];
  6216. // }
  6217. // if(json==nil)
  6218. // return nil;
  6219. // NSError *error=nil;
  6220. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6221. // int result = [[jsobj valueForKey:@"result"] intValue];
  6222. //
  6223. // if (result==2)
  6224. // {
  6225. //
  6226. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6227. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6228. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6229. //
  6230. // [appDelegate update_count_mark];
  6231. // }
  6232. //
  6233. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  6234. //
  6235. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6236. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  6237. // }
  6238. //
  6239. // return jsobj;
  6240. }
  6241. +(void)request_open_order:(NSString*) order_code completionHandler:(resultHandler)result
  6242. {
  6243. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6244. AppDelegate *appDelegate = nil;
  6245. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6246. if(appDelegate.user!=nil)
  6247. [params setValue:appDelegate.user forKey:@"user"];
  6248. // if(appDelegate.contact_id!=nil)
  6249. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6250. if(appDelegate.password!=nil)
  6251. [params setValue:appDelegate.password forKey:@"password"];
  6252. [params setValue:order_code forKey:@"orderCode"];
  6253. // [params setValue:sourceid forKey:@"sourceid"];
  6254. // [params setValue:editor forKey:@"editor"];
  6255. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  6256. if(appDelegate.offline_mode)
  6257. {
  6258. params[@"appDelegate.order_code"]=appDelegate.order_code;
  6259. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6260. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_editorder:params]] mutableCopy];
  6261. dispatch_async(dispatch_get_main_queue(), ^{
  6262. int result_code = [[resulti valueForKey:@"result"] intValue];
  6263. if (result_code==2)
  6264. {
  6265. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6266. [appDelegate update_count_mark];
  6267. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6268. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  6269. }
  6270. }
  6271. result(resulti);
  6272. });
  6273. });
  6274. return;
  6275. }
  6276. [self request_interface:URL_OPEN_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6277. int result_code = [[resulti valueForKey:@"result"] intValue];
  6278. if (result_code==2)
  6279. {
  6280. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6281. [appDelegate update_count_mark];
  6282. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6283. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  6284. }
  6285. }
  6286. result(resulti);
  6287. } retry:0];
  6288. //
  6289. // NSData* json=nil;
  6290. // if(appDelegate.offline_mode)
  6291. // {
  6292. // json=[OLDataProvider offline_editorder:params];
  6293. //
  6294. // }
  6295. // else
  6296. // {
  6297. // if(![self IsNetworkAvailable])
  6298. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6299. //
  6300. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  6301. // }
  6302. // if(json!=nil)
  6303. // {
  6304. // NSError *error=nil;
  6305. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6306. // int result = [[jsobj valueForKey:@"result"] intValue];
  6307. //
  6308. // if (result==2)
  6309. // {
  6310. //
  6311. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6312. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6313. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6314. //
  6315. // [appDelegate update_count_mark];
  6316. //
  6317. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  6318. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  6319. // }
  6320. //
  6321. // }
  6322. //
  6323. // return jsobj;
  6324. // }
  6325. // else
  6326. // return nil;
  6327. }
  6328. +(void)request_cart:(int)sort completionHandler:(resultHandler)result
  6329. {
  6330. DebugLog(@"iSalesNetwork::request_Cart");
  6331. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6332. AppDelegate *appDelegate = nil;
  6333. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6334. if(RASingleton.sharedInstance.enable_OfflineOrder)
  6335. {
  6336. appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  6337. [appDelegate update_count_mark];
  6338. result(RASingleton.sharedInstance.scan_cart);
  6339. return;
  6340. }
  6341. if(appDelegate.user!=nil)
  6342. [params setValue:appDelegate.user forKey:@"user"];
  6343. // if(appDelegate.contact_id!=nil)
  6344. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6345. if(appDelegate.password!=nil)
  6346. [params setValue:appDelegate.password forKey:@"password"];
  6347. if(appDelegate.order_code!=nil)
  6348. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6349. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  6350. [params setObject:ScreenCodeCart forKey:kScreenName];
  6351. if(appDelegate.offline_mode)
  6352. {
  6353. [OLDataProvider offline_requestcart:params completionHandler:^(NSMutableDictionary *resulti) {
  6354. if([resulti[@"result"] intValue]==2)
  6355. {
  6356. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6357. [appDelegate update_count_mark];
  6358. result(resulti);
  6359. }
  6360. }];
  6361. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6362. // NSData* json = [[OLDataProvider offline_requestcart:params] mutableCopy];
  6363. // dispatch_async(dispatch_get_main_queue(), ^{
  6364. // result([[RAConvertor data2dict:json] mutableCopy]);
  6365. // });
  6366. // });
  6367. return;
  6368. }
  6369. NSString * uuid= [[NSUUID UUID] UUIDString];
  6370. params[@"resultSerial"]=uuid;
  6371. __block bool bbreak = false;
  6372. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6373. for(int i=0;i<150;i++)
  6374. {
  6375. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6376. // result_params[@"resultSerial"]=uuid;
  6377. if(bbreak)
  6378. break;
  6379. dispatch_async(dispatch_get_main_queue(), ^{
  6380. [self request_interface:URL_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6381. if([resulti[@"result"] intValue]==2)
  6382. {
  6383. if(!bbreak) //此判断保证result只调用一次。
  6384. {
  6385. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6386. [appDelegate update_count_mark];
  6387. result(resulti);
  6388. }
  6389. bbreak=true;
  6390. }
  6391. } retry:3];
  6392. });
  6393. sleep(2);
  6394. // json=[self get_json:URL_CART parameters:params];
  6395. // if(json!=nil)
  6396. // {
  6397. //
  6398. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6399. // if([jsobj[@"result"] intValue]==2)
  6400. // {
  6401. // break;
  6402. // }
  6403. // }
  6404. }
  6405. });
  6406. //
  6407. //
  6408. //
  6409. // NSData* json=nil;
  6410. // if(appDelegate.offline_mode)
  6411. // {
  6412. // json= [OLDataProvider offline_requestcart:params];
  6413. // }
  6414. // else
  6415. // {
  6416. // if(![self IsNetworkAvailable])
  6417. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6418. //
  6419. // NSError *error=nil;
  6420. //
  6421. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6422. // params[@"resultSerial"]=uuid;
  6423. //
  6424. // for(int i=0;i<150;i++)
  6425. // {
  6426. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6427. // // result_params[@"resultSerial"]=uuid;
  6428. // json=[self get_json:URL_CART parameters:params];
  6429. // if(json!=nil)
  6430. // {
  6431. //
  6432. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6433. // if([jsobj[@"result"] intValue]==2)
  6434. // {
  6435. // break;
  6436. // }
  6437. // }
  6438. // sleep(2);
  6439. // }
  6440. //
  6441. // }
  6442. // if(json==nil)
  6443. // return nil;
  6444. // NSError *error=nil;
  6445. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6446. // int result = [[jsobj valueForKey:@"result"] intValue];
  6447. //
  6448. // if (result==2)
  6449. // {
  6450. //
  6451. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6452. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  6453. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6454. //
  6455. // [appDelegate update_count_mark];
  6456. // }
  6457. // return jsobj;
  6458. }
  6459. +(void) request_move_wish2cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  6460. {
  6461. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6462. AppDelegate *appDelegate = nil;
  6463. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6464. if(appDelegate.user!=nil)
  6465. [params setValue:appDelegate.user forKey:@"user"];
  6466. if(appDelegate.contact_id!=nil)
  6467. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6468. if(appDelegate.password!=nil)
  6469. [params setValue:appDelegate.password forKey:@"password"];
  6470. if(appDelegate.order_code!=nil)
  6471. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6472. [params setValue:item_ids forKey:@"collectId"];
  6473. // [params setValue:editor forKey:@"editor"];
  6474. [params setValue:ScreenCodeWishList forKey:kScreenName];
  6475. [params setValue:@"Move To Cart" forKey:kAction];
  6476. if(appDelegate.offline_mode)
  6477. {
  6478. // [OLDataProvider offline_movewish2cart:params completionHandler:result];
  6479. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6480. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6481. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movewish2cart:params]] mutableCopy];
  6482. dispatch_async(dispatch_get_main_queue(), ^{
  6483. int result_code = [[resulti valueForKey:@"result"] intValue];
  6484. if (result_code==2)
  6485. {
  6486. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6487. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6488. [appDelegate update_count_mark];
  6489. }
  6490. result(resulti);
  6491. });
  6492. });
  6493. return;
  6494. }
  6495. [self request_interface:URL_WISH2CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6496. int result_code = [[resulti valueForKey:@"result"] intValue];
  6497. if (result_code==2)
  6498. {
  6499. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6500. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6501. [appDelegate update_count_mark];
  6502. }
  6503. result(resulti);
  6504. } retry:0];
  6505. //
  6506. // NSData *json = nil;
  6507. // if(appDelegate.offline_mode)
  6508. // {
  6509. // json = [OLDataProvider offline_movewish2cart:params];
  6510. // } else {
  6511. // if(![self IsNetworkAvailable])
  6512. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6513. //
  6514. // json=[self get_json:URL_WISH2CART parameters:params];
  6515. // }
  6516. //
  6517. // if(json!=nil)
  6518. // {
  6519. // NSError *error=nil;
  6520. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6521. // int result = [[jsobj valueForKey:@"result"] intValue];
  6522. //
  6523. // if (result==2)
  6524. // {
  6525. //
  6526. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6527. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6528. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6529. //
  6530. // [appDelegate update_count_mark];
  6531. // }
  6532. // return jsobj;
  6533. // }
  6534. // else
  6535. // return nil;
  6536. }
  6537. +(void) request_move_cart2wish:(NSString* ) item_ids completionHandler:(resultHandler)result
  6538. {
  6539. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6540. AppDelegate *appDelegate = nil;
  6541. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6542. if(appDelegate.user!=nil)
  6543. [params setValue:appDelegate.user forKey:@"user"];
  6544. if(appDelegate.contact_id!=nil)
  6545. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6546. if(appDelegate.password!=nil)
  6547. [params setValue:appDelegate.password forKey:@"password"];
  6548. if(appDelegate.order_code!=nil)
  6549. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6550. [params setValue:item_ids forKey:@"cartItemId"];
  6551. // [params setValue:editor forKey:@"editor"];
  6552. [params setValue:ScreenCodeCart forKey:kScreenName];
  6553. // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  6554. if(appDelegate.offline_mode)
  6555. {
  6556. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6557. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movecart2wish:params]] mutableCopy];
  6558. dispatch_async(dispatch_get_main_queue(), ^{
  6559. int result_code = [[resulti valueForKey:@"result"] intValue];
  6560. if (result_code==2)
  6561. {
  6562. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6563. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6564. [appDelegate update_count_mark];
  6565. }
  6566. result(resulti);
  6567. });
  6568. });
  6569. return;
  6570. }
  6571. [self request_interface:URL_CART2WISH parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6572. int result_code = [[resulti valueForKey:@"result"] intValue];
  6573. if (result_code==2)
  6574. {
  6575. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6576. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6577. [appDelegate update_count_mark];
  6578. }
  6579. result(resulti);
  6580. } retry:0];
  6581. //
  6582. // NSData* json = nil;
  6583. // if(appDelegate.offline_mode)
  6584. // {
  6585. // json= [OLDataProvider offline_movecart2wish:params];
  6586. // }
  6587. // else
  6588. // {
  6589. // if(![self IsNetworkAvailable])
  6590. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6591. //
  6592. // json=[self get_json:URL_CART2WISH parameters:params];
  6593. // }
  6594. // if(json!=nil)
  6595. // {
  6596. // NSError *error=nil;
  6597. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6598. // int result = [[jsobj valueForKey:@"result"] intValue];
  6599. //
  6600. // if (result==2)
  6601. // {
  6602. //
  6603. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6604. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6605. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6606. //
  6607. // [appDelegate update_count_mark];
  6608. // }
  6609. // return jsobj;
  6610. // }
  6611. // else
  6612. // return nil;
  6613. }
  6614. +(void)request_orderdetail:(NSMutableDictionary *) params completionHandler:(resultHandler)result
  6615. {
  6616. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6617. if (params == nil) {
  6618. params = [[NSMutableDictionary alloc] init];
  6619. }
  6620. AppDelegate *appDelegate = nil;
  6621. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6622. if(appDelegate.user!=nil)
  6623. [params setValue:appDelegate.user forKey:@"user"];
  6624. if(appDelegate.contact_id!=nil)
  6625. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6626. if(appDelegate.password!=nil)
  6627. [params setValue:appDelegate.password forKey:@"password"];
  6628. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  6629. [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  6630. if(appDelegate.offline_mode)
  6631. {
  6632. params[@"mode"]=appDelegate.mode;
  6633. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6634. NSData* json = [[OLDataProvider offline_orderdetail:params] mutableCopy];
  6635. dispatch_async(dispatch_get_main_queue(), ^{
  6636. result([[RAConvertor data2dict:json] mutableCopy]);
  6637. });
  6638. });
  6639. return;
  6640. }
  6641. NSString * uuid= [[NSUUID UUID] UUIDString];
  6642. params[@"resultSerial"]=uuid;
  6643. __block bool bbreak = false;
  6644. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6645. for(int i=0;i<150;i++)
  6646. {
  6647. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6648. // result_params[@"resultSerial"]=uuid;
  6649. if(bbreak)
  6650. break;
  6651. dispatch_async(dispatch_get_main_queue(), ^{
  6652. [self request_interface:URL_ORDER_DETAIL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6653. if([resulti[@"result"] intValue]==2||[resulti[@"result"] intValue]==8)
  6654. {
  6655. if(!bbreak)//此判断保证result只调用一次。
  6656. result(resulti);
  6657. bbreak=true;
  6658. }
  6659. } retry:3];
  6660. });
  6661. sleep(2);
  6662. }
  6663. });
  6664. //
  6665. // NSData* json=nil;
  6666. // if(appDelegate.offline_mode)
  6667. // {
  6668. // json= [OLDataProvider offline_orderdetail:params];
  6669. // }
  6670. // else
  6671. // {
  6672. // if(![self IsNetworkAvailable])
  6673. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6674. //
  6675. // NSError *error=nil;
  6676. //
  6677. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6678. // params[@"resultSerial"]=uuid;
  6679. //
  6680. // for(int i=0;i<150;i++)
  6681. // {
  6682. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6683. // // result_params[@"resultSerial"]=uuid;
  6684. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  6685. // if(json!=nil)
  6686. // {
  6687. //
  6688. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6689. // int resultCode = [jsobj[@"result"] intValue];
  6690. // if(resultCode==2 || resultCode == 8)
  6691. // {
  6692. // break;
  6693. // }
  6694. // }
  6695. // sleep(2);
  6696. // }
  6697. //
  6698. //
  6699. // }
  6700. // if(json==nil)
  6701. // return nil;
  6702. // NSError *error=nil;
  6703. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6704. // return jsobj;
  6705. }
  6706. //
  6707. //+(void)request_commit_order:(NSString*) order_code completionHandler:(resultHandler)result
  6708. //{
  6709. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6710. // AppDelegate *appDelegate = nil;
  6711. //
  6712. //
  6713. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6714. //
  6715. // if(appDelegate.user!=nil)
  6716. // [params setValue:appDelegate.user forKey:@"user"];
  6717. // if(appDelegate.contact_id!=nil)
  6718. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6719. // if(appDelegate.password!=nil)
  6720. // [params setValue:appDelegate.password forKey:@"password"];
  6721. // // NSString* ssaved = @"false";
  6722. // // if(saved)
  6723. // // ssaved=@"true";
  6724. // [params setValue:@"true" forKey:@"saved"];
  6725. // [params setValue:order_code forKey:@"orderCode"];
  6726. // // [params setValue:sourceid forKey:@"sourceid"];
  6727. // // [params setValue:editor forKey:@"editor"];
  6728. //
  6729. // [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  6730. //
  6731. //
  6732. // if(appDelegate.offline_mode)
  6733. // {
  6734. //
  6735. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6736. // NSMutableDictionary* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  6737. // dispatch_async(dispatch_get_main_queue(), ^{
  6738. // result(json);
  6739. // });
  6740. // });
  6741. //
  6742. // return;
  6743. // }
  6744. //
  6745. //
  6746. // [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6747. //
  6748. //// NSData* json = nil;
  6749. ////
  6750. //// if(appDelegate.offline_mode)
  6751. //// {
  6752. //// json= [OLDataProvider offline_submitorder:params];
  6753. //// }
  6754. //// else
  6755. //// {
  6756. //// if(![self IsNetworkAvailable])
  6757. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6758. ////
  6759. //// json=[self get_json:URL_COMMIT_ORDER parameters:params];
  6760. //// }
  6761. //// if(json!=nil)
  6762. //// {
  6763. //// NSError *error=nil;
  6764. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6765. //// return jsobj;
  6766. //// }
  6767. //// else
  6768. //// return nil;
  6769. //
  6770. //}
  6771. +(void)request_copy_order:(NSString*) order_code completionHandler:(resultHandler)result
  6772. {
  6773. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6774. AppDelegate *appDelegate = nil;
  6775. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6776. if(appDelegate.user!=nil)
  6777. [params setValue:appDelegate.user forKey:@"user"];
  6778. if(appDelegate.contact_id!=nil)
  6779. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6780. if(appDelegate.password!=nil)
  6781. [params setValue:appDelegate.password forKey:@"password"];
  6782. // NSString* ssaved = @"false";
  6783. // if(saved)
  6784. // ssaved=@"true";
  6785. // [params setValue:@"true" forKey:@"saved"];
  6786. [params setValue:order_code forKey:@"code"];
  6787. // [params setValue:sourceid forKey:@"sourceid"];
  6788. // [params setValue:editor forKey:@"editor"];
  6789. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  6790. if(appDelegate.offline_mode)
  6791. {
  6792. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6793. NSData* json = [[OLDataProvider offline_copyorder:params] mutableCopy];
  6794. dispatch_async(dispatch_get_main_queue(), ^{
  6795. result([[RAConvertor data2dict:json] mutableCopy]);
  6796. });
  6797. });
  6798. return;
  6799. }
  6800. [self request_interface:URL_COPY_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6801. // NSData* json=nil;
  6802. // if(appDelegate.offline_mode)
  6803. // {
  6804. // json= [OLDataProvider offline_copyorder:params];
  6805. // }
  6806. // else
  6807. // {
  6808. // if(![self IsNetworkAvailable])
  6809. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6810. //
  6811. // json=[self get_json:URL_COPY_ORDER parameters:params];
  6812. // }
  6813. // if(json!=nil)
  6814. // {
  6815. // NSError *error=nil;
  6816. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6817. // return jsobj;
  6818. // }
  6819. // else
  6820. // return nil;
  6821. }
  6822. //
  6823. //+ (void)request_fastdownload:(NSMutableDictionary *)params url:(NSString *)url completionHandler:(resultHandler)result
  6824. //{
  6825. //
  6826. // //#ifdef test_server
  6827. // // url=URL_REQUEST_RECORDS;
  6828. // // params[@"prefix"]=URL_REQUEST_RECORDS;
  6829. // //#endif
  6830. //
  6831. // [self request_file_fast:url parameters:params completionHandler:result];
  6832. //
  6833. //}
  6834. +(void) request_addto_portfolio:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6835. {
  6836. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6837. AppDelegate *appDelegate = nil;
  6838. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6839. if(appDelegate.user!=nil)
  6840. [params setValue:appDelegate.user forKey:@"user"];
  6841. if(appDelegate.contact_id!=nil)
  6842. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6843. if(appDelegate.password!=nil)
  6844. [params setValue:appDelegate.password forKey:@"password"];
  6845. [params setValue:item_id forKey:@"product_id"];
  6846. [params setObject:screenName forKey:kScreenName];
  6847. if(appDelegate.offline_mode)
  6848. {
  6849. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6850. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_add2Portfolio:params]] mutableCopy];
  6851. dispatch_async(dispatch_get_main_queue(), ^{
  6852. int result_code = [[resulti valueForKey:@"result"] intValue];
  6853. if (result_code==2)
  6854. {
  6855. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6856. [appDelegate update_count_mark];
  6857. }
  6858. result(resulti);
  6859. });
  6860. });
  6861. return;
  6862. }
  6863. [self request_interface:URL_ADD_TO_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6864. int result_code = [[resulti valueForKey:@"result"] intValue];
  6865. if (result_code==2)
  6866. {
  6867. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6868. [appDelegate update_count_mark];
  6869. }
  6870. result(resulti);
  6871. } retry:0];
  6872. //
  6873. // NSData* json = nil;
  6874. // if(appDelegate.offline_mode)
  6875. // {
  6876. // json = [OLDataProvider offline_add2Portfolio:params];
  6877. // } else {
  6878. // if(![self IsNetworkAvailable])
  6879. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6880. //
  6881. // json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  6882. // }
  6883. //
  6884. // if(json==nil)
  6885. // return nil;
  6886. // NSError *error=nil;
  6887. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6888. // int result = [[jsobj valueForKey:@"result"] intValue];
  6889. //
  6890. // if (result==2)
  6891. // {
  6892. //
  6893. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6894. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6895. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6896. //
  6897. // [appDelegate update_count_mark];
  6898. // }
  6899. // return jsobj;
  6900. }
  6901. +(void)request_addall_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  6902. {
  6903. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6904. AppDelegate *appDelegate = nil;
  6905. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6906. if(appDelegate.user!=nil)
  6907. [params setValue:appDelegate.user forKey:@"user"];
  6908. if(appDelegate.contact_id!=nil)
  6909. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6910. if(appDelegate.password!=nil)
  6911. [params setValue:appDelegate.password forKey:@"password"];
  6912. if(appDelegate.order_code!=nil)
  6913. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6914. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6915. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6916. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  6917. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6918. // [params setValue:filter forKey:@"filter"];
  6919. [params setValue:keywords forKey:@"keyword"];
  6920. [params setValue:addTo forKey:@"addTo"];
  6921. [params setValue:orderCode forKey:@"orderCode"];
  6922. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6923. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6924. if(matchfull)
  6925. [params setValue:@"true" forKey:@"exactMatch"];
  6926. else
  6927. [params setValue:@"false" forKey:@"exactMatch"];
  6928. [params setObject:ScreenCodeSearch forKey:kScreenName];
  6929. if ([addTo isEqualToString:@"cart"]) {
  6930. [params setObject:@"Add To Cart" forKey:kAction];
  6931. }
  6932. if(appDelegate.offline_mode)
  6933. {
  6934. if ([addTo isEqualToString:@"cart"])
  6935. {
  6936. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6937. }
  6938. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6939. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_searchaddall:params]] mutableCopy];
  6940. dispatch_async(dispatch_get_main_queue(), ^{
  6941. int result_code =[json[@"result"] intValue];
  6942. if (result_code==2||result_code==8)
  6943. {
  6944. if(json[@"cart_count"])
  6945. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6946. if(json[@"wish_count"])
  6947. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  6948. if(json[@"portfolio_count"])
  6949. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  6950. //
  6951. //
  6952. [appDelegate update_count_mark];
  6953. }
  6954. result(json);
  6955. });
  6956. });
  6957. return;
  6958. }
  6959. NSString * uuid= [[NSUUID UUID] UUIDString];
  6960. params[@"resultSerial"]=uuid;
  6961. __block bool bbreak = false;
  6962. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6963. for(int i=0;i<150;i++)
  6964. {
  6965. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6966. // result_params[@"resultSerial"]=uuid;
  6967. if(bbreak)
  6968. break;
  6969. dispatch_async(dispatch_get_main_queue(), ^{
  6970. [self request_interface:URL_SEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6971. if([resulti[@"result"] intValue]==2)
  6972. {
  6973. if(!bbreak)//此判断保证result只调用一次。
  6974. result(resulti);
  6975. bbreak=true;
  6976. }
  6977. } retry:3];
  6978. });
  6979. sleep(2);
  6980. }
  6981. });
  6982. //
  6983. //
  6984. // NSData* json=nil;
  6985. // if(appDelegate.offline_mode)
  6986. // {
  6987. // json=[OLDataProvider offline_searchaddall:params];
  6988. // }
  6989. // else
  6990. // {
  6991. // if(![self IsNetworkAvailable])
  6992. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6993. //
  6994. // NSError *error=nil;
  6995. //
  6996. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6997. // params[@"resultSerial"]=uuid;
  6998. //
  6999. // for(int i=0;i<150;i++)
  7000. // {
  7001. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7002. // // result_params[@"resultSerial"]=uuid;
  7003. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  7004. // if(json!=nil)
  7005. // {
  7006. //
  7007. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7008. // if([jsobj[@"result"] intValue]==2)
  7009. // {
  7010. // break;
  7011. // }
  7012. // }
  7013. // sleep(2);
  7014. // }
  7015. // }
  7016. // if(json==nil)
  7017. // return nil;
  7018. // NSError *error=nil;
  7019. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7020. // return jsobj;
  7021. }
  7022. +(void) request_addto_cart_byupc:(NSString* ) upc_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  7023. {
  7024. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7025. AppDelegate *appDelegate = nil;
  7026. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7027. if(appDelegate.user!=nil)
  7028. [params setValue:appDelegate.user forKey:@"user"];
  7029. if(appDelegate.contact_id!=nil)
  7030. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7031. if(appDelegate.password!=nil)
  7032. [params setValue:appDelegate.password forKey:@"password"];
  7033. if(appDelegate.order_code!=nil)
  7034. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7035. [params setValue:upc_code forKey:@"upc_code"];
  7036. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  7037. [params setObject:screenName forKey:kScreenName];
  7038. [params setObject:@"Add To Cart" forKey:kAction];
  7039. if (!upc_code) {
  7040. upc_code = @"";
  7041. }
  7042. [params setObject:@{@"UPCCode" : upc_code} forKey:kExtra];
  7043. params[@"search_upc"]=@true;
  7044. NSDictionary* customerinfo= appDelegate.customerInfo;
  7045. NSArray* keys=[customerinfo allKeys];
  7046. for(int i=0;i<keys.count;i++)
  7047. {
  7048. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7049. }
  7050. if(appDelegate.offline_mode)
  7051. {
  7052. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7053. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  7054. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7055. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyupc:params]] mutableCopy];
  7056. dispatch_async(dispatch_get_main_queue(), ^{
  7057. int result_code = [[json valueForKey:@"result"] intValue];
  7058. if (result_code==2||result_code==8)
  7059. {
  7060. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7061. [appDelegate update_count_mark];
  7062. }
  7063. result(json);
  7064. });
  7065. });
  7066. return;
  7067. }
  7068. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7069. int result_code = [[resulti valueForKey:@"result"] intValue];
  7070. if (result_code==2||result_code==8)
  7071. {
  7072. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7073. [appDelegate update_count_mark];
  7074. }
  7075. result(resulti);
  7076. } retry:0];
  7077. }
  7078. +(void) request_addto_cart_byname:(NSString* ) model_name withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  7079. {
  7080. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7081. AppDelegate *appDelegate = nil;
  7082. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7083. if(appDelegate.user!=nil)
  7084. [params setValue:appDelegate.user forKey:@"user"];
  7085. if(appDelegate.contact_id!=nil)
  7086. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7087. if(appDelegate.password!=nil)
  7088. [params setValue:appDelegate.password forKey:@"password"];
  7089. if(appDelegate.order_code!=nil)
  7090. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7091. [params setValue:model_name forKey:@"product_name"];
  7092. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  7093. [params setObject:screenName forKey:kScreenName];
  7094. [params setObject:@"Add To Cart" forKey:kAction];
  7095. if (!model_name) {
  7096. model_name = @"";
  7097. }
  7098. [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  7099. NSDictionary* customerinfo= appDelegate.customerInfo;
  7100. NSArray* keys=[customerinfo allKeys];
  7101. for(int i=0;i<keys.count;i++)
  7102. {
  7103. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7104. }
  7105. if(appDelegate.offline_mode)
  7106. {
  7107. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7108. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  7109. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7110. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyname:params]] mutableCopy];
  7111. dispatch_async(dispatch_get_main_queue(), ^{
  7112. int result_code = [[json valueForKey:@"result"] intValue];
  7113. if (result_code==2||result_code==8)
  7114. {
  7115. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7116. [appDelegate update_count_mark];
  7117. }
  7118. result(json);
  7119. });
  7120. });
  7121. return;
  7122. }
  7123. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7124. int result_code = [[resulti valueForKey:@"result"] intValue];
  7125. if (result_code==2||result_code==8)
  7126. {
  7127. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7128. [appDelegate update_count_mark];
  7129. }
  7130. result(resulti);
  7131. } retry:0];
  7132. // NSData* json=nil;
  7133. // if(appDelegate.offline_mode)
  7134. // {
  7135. // json= [OLDataProvider offline_add2cartbyname:params];
  7136. // }
  7137. // else
  7138. // {
  7139. // if(![self IsNetworkAvailable])
  7140. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7141. //
  7142. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  7143. // }
  7144. // if(json==nil)
  7145. // return nil;
  7146. // NSError *error=nil;
  7147. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7148. //
  7149. //
  7150. //
  7151. // int result = [[jsobj valueForKey:@"result"] intValue];
  7152. //
  7153. // if (result==2||result==8)
  7154. // {
  7155. //
  7156. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  7157. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  7158. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  7159. //
  7160. // [appDelegate update_count_mark];
  7161. // }
  7162. //
  7163. // return jsobj;
  7164. }
  7165. +(void) request_addto_wishlist:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  7166. {
  7167. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7168. AppDelegate *appDelegate = nil;
  7169. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7170. if(appDelegate.user!=nil)
  7171. [params setValue:appDelegate.user forKey:@"user"];
  7172. if(appDelegate.contact_id!=nil)
  7173. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7174. if(appDelegate.password!=nil)
  7175. [params setValue:appDelegate.password forKey:@"password"];
  7176. [params setValue:item_id forKey:@"product_id"];
  7177. [params setObject:screenName forKey:kScreenName];
  7178. if(appDelegate.offline_mode)
  7179. {
  7180. // [OLDataProvider offline_add2wishlist:params completionHandler:result];
  7181. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7182. NSMutableDictionary* resulti = [[OLDataProvider offline_add2wishlist:params] mutableCopy];
  7183. dispatch_async(dispatch_get_main_queue(), ^{
  7184. int result_code = [[resulti valueForKey:@"result"] intValue];
  7185. if (result_code==2||result_code==8)
  7186. {
  7187. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7188. [appDelegate update_count_mark];
  7189. }
  7190. result(resulti);
  7191. });
  7192. });
  7193. return;
  7194. }
  7195. [self request_interface:URL_ADD_TO_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7196. int result_code = [[resulti valueForKey:@"result"] intValue];
  7197. if (result_code==2||result_code==8)
  7198. {
  7199. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7200. [appDelegate update_count_mark];
  7201. }
  7202. result(resulti);
  7203. } retry:0];
  7204. // if(appDelegate.offline_mode)
  7205. // {
  7206. // return [OLDataProvider offline_add2wishlist:params];
  7207. // }
  7208. // if(![self IsNetworkAvailable])
  7209. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7210. //
  7211. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  7212. // if(json==nil)
  7213. // return nil;
  7214. // NSError *error=nil;
  7215. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7216. // int result = [[jsobj valueForKey:@"result"] intValue];
  7217. //
  7218. // if (result==2)
  7219. // {
  7220. //
  7221. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  7222. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  7223. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  7224. //
  7225. // [appDelegate update_count_mark];
  7226. // }
  7227. // return jsobj;
  7228. }
  7229. +(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
  7230. {
  7231. // for debug
  7232. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  7233. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7234. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7235. AppDelegate *appDelegate = nil;
  7236. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7237. if(appDelegate.user!=nil)
  7238. [params setValue:appDelegate.user forKey:@"user"];
  7239. if(appDelegate.contact_id!=nil)
  7240. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7241. if(appDelegate.password!=nil)
  7242. [params setValue:appDelegate.password forKey:@"password"];
  7243. if(appDelegate.order_code!=nil)
  7244. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7245. [params setValue:addTo forKey:@"addTo"];
  7246. [params setValue:orderCode forKey:@"orderCode"];
  7247. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7248. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7249. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  7250. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7251. // [params setValue:filter forKey:@"filter"];
  7252. [params setValue:covertype forKey:@"covertype"];
  7253. [params setValue:ctgid forKey:@"ctgId"];
  7254. [params setValue:modelname forKey:@"modelName"];
  7255. [params setValue:modeldescrip forKey:@"modelDescription"];
  7256. [params setValue:alert forKey:@"alert"];
  7257. [params setValue:qty forKey:@"sold_by_qty"];
  7258. [params setValue:available forKey:@"available"];
  7259. [params setValue:price forKey:@"price"];
  7260. [params setValue:bestseller forKey:@"bestseller"];
  7261. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7262. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7263. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  7264. if ([addTo isEqualToString:@"cart"]) {
  7265. [params setObject:@"Add To Cart" forKey:kAction];
  7266. }
  7267. if(appDelegate.offline_mode)
  7268. {
  7269. if ([addTo isEqualToString:@"cart"])
  7270. {
  7271. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7272. }
  7273. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7274. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_itemsearchaddall:params]] mutableCopy];
  7275. dispatch_async(dispatch_get_main_queue(), ^{
  7276. int result_code =[json[@"result"] intValue];
  7277. if (result_code==2||result_code==8)
  7278. {
  7279. if(json[@"cart_count"])
  7280. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7281. if(json[@"wish_count"])
  7282. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7283. if(json[@"portfolio_count"])
  7284. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7285. //
  7286. //
  7287. [appDelegate update_count_mark];
  7288. }
  7289. result(json);
  7290. });
  7291. });
  7292. return;
  7293. }
  7294. NSString * uuid= [[NSUUID UUID] UUIDString];
  7295. params[@"resultSerial"]=uuid;
  7296. __block bool bbreak = false;
  7297. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7298. for(int i=0;i<150;i++)
  7299. {
  7300. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7301. // result_params[@"resultSerial"]=uuid;
  7302. if(bbreak)
  7303. break;
  7304. dispatch_async(dispatch_get_main_queue(), ^{
  7305. [self request_interface:URL_ITEMSEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7306. if([resulti[@"result"] intValue]==2)
  7307. {
  7308. if(!bbreak)//此判断保证result只调用一次。
  7309. result(resulti);
  7310. bbreak=true;
  7311. }
  7312. } retry:3];
  7313. });
  7314. sleep(2);
  7315. }
  7316. });
  7317. //
  7318. // NSData* json = nil;
  7319. //
  7320. // if(appDelegate.offline_mode)
  7321. // {
  7322. // json= [OLDataProvider offline_itemsearchaddall:params];
  7323. // }
  7324. // else
  7325. // {
  7326. // if(![self IsNetworkAvailable])
  7327. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7328. // NSError *error=nil;
  7329. //
  7330. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7331. // params[@"resultSerial"]=uuid;
  7332. //
  7333. // for(int i=0;i<150;i++)
  7334. // {
  7335. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7336. // // result_params[@"resultSerial"]=uuid;
  7337. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  7338. // if(json!=nil)
  7339. // {
  7340. //
  7341. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7342. // if([jsobj[@"result"] intValue]==2)
  7343. // {
  7344. // break;
  7345. // }
  7346. // }
  7347. // sleep(2);
  7348. // }
  7349. // }
  7350. // if(json==nil)
  7351. // return nil;
  7352. // NSError *error=nil;
  7353. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7354. // return jsobj;
  7355. }
  7356. +(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
  7357. {
  7358. AppDelegate *appDelegate = nil;
  7359. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7360. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7361. if(appDelegate.user!=nil)
  7362. [params setValue:appDelegate.user forKey:@"user"];
  7363. if(appDelegate.contact_id!=nil)
  7364. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7365. if(appDelegate.password!=nil)
  7366. [params setValue:appDelegate.password forKey:@"password"];
  7367. if(appDelegate.order_code!=nil)
  7368. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7369. [params setValue:addTo forKey:@"addTo"];
  7370. [params setValue:orderCode forKey:@"orderCode"];
  7371. [params setValue:alert forKey:@"alert"];
  7372. [params setValue:qty forKey:@"sold_by_qty"];
  7373. [params setValue:available forKey:@"available"];
  7374. [params setValue:price forKey:@"price"];
  7375. [params setValue:bestseller forKey:@"bestseller"];
  7376. [params setValue:modelname forKey:@"modelName"];
  7377. [params setValue:modeldescrip forKey:@"modelDescription"];
  7378. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7379. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7380. [params setValue:category forKey:@"category"];
  7381. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7382. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7383. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7384. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7385. [params setValue:filter forKey:@"filter"];
  7386. [params setValue:keyword forKey:@"keyword"];
  7387. [params setObject:ScreenCodeCategory forKey:kScreenName];
  7388. if ([addTo isEqualToString:@"cart"]) {
  7389. [params setObject:@"Add To Cart" forKey:kAction];
  7390. }
  7391. if(appDelegate.offline_mode)
  7392. {
  7393. if ([addTo isEqualToString:@"cart"])
  7394. {
  7395. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7396. }
  7397. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7398. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_categoryaddall:params]] mutableCopy];
  7399. dispatch_async(dispatch_get_main_queue(), ^{
  7400. int result_code =[json[@"result"] intValue];
  7401. if (result_code==2||result_code==8)
  7402. {
  7403. if(json[@"cart_count"])
  7404. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7405. if(json[@"wish_count"])
  7406. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7407. if(json[@"portfolio_count"])
  7408. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7409. //
  7410. //
  7411. [appDelegate update_count_mark];
  7412. }
  7413. result(json);
  7414. });
  7415. });
  7416. return;
  7417. }
  7418. NSString * uuid= [[NSUUID UUID] UUIDString];
  7419. params[@"resultSerial"]=uuid;
  7420. __block bool bbreak = false;
  7421. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7422. for(int i=0;i<150;i++)
  7423. {
  7424. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7425. // result_params[@"resultSerial"]=uuid;
  7426. if(bbreak)
  7427. break;
  7428. dispatch_async(dispatch_get_main_queue(), ^{
  7429. [self request_interface:URL_CATEGORYADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7430. if([resulti[@"result"] intValue]==2|| [resulti[@"result"] intValue] == 8)
  7431. {
  7432. if(!bbreak)//此判断保证result只调用一次。
  7433. {
  7434. int result_code =[resulti[@"result"] intValue];
  7435. if (result_code==2||result_code==8)
  7436. {
  7437. if(resulti[@"cart_count"])
  7438. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7439. if(resulti[@"wish_count"])
  7440. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7441. if(resulti[@"portfolio_count"])
  7442. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  7443. //
  7444. //
  7445. [appDelegate update_count_mark];
  7446. }
  7447. result(resulti);
  7448. }
  7449. bbreak=true;
  7450. }
  7451. } retry:3];
  7452. });
  7453. sleep(2);
  7454. }
  7455. });
  7456. //
  7457. // NSData* json= nil;
  7458. //
  7459. // if(appDelegate.offline_mode)
  7460. // {
  7461. // json= [OLDataProvider offline_categoryaddall:params];
  7462. // }
  7463. // else
  7464. // {
  7465. // if(![self IsNetworkAvailable])
  7466. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7467. //
  7468. //
  7469. // NSError *error=nil;
  7470. //
  7471. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7472. // params[@"resultSerial"]=uuid;
  7473. //
  7474. // for(int i=0;i<150;i++)
  7475. // {
  7476. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7477. //// result_params[@"resultSerial"]=uuid;
  7478. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  7479. // if(json!=nil)
  7480. // {
  7481. //
  7482. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7483. // int resultInt = [jsobj[@"result"] intValue];
  7484. // if(resultInt == 2 || resultInt == 8)
  7485. // {
  7486. // break;
  7487. // }
  7488. // }
  7489. // sleep(2);
  7490. // }
  7491. //
  7492. //
  7493. //
  7494. // }
  7495. // if(json==nil)
  7496. // return nil;
  7497. // NSError *error=nil;
  7498. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7499. // return jsobj;
  7500. }
  7501. +(void)request_save_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7502. {
  7503. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7504. AppDelegate *appDelegate = nil;
  7505. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7506. if(appDelegate.user!=nil)
  7507. [params setValue:appDelegate.user forKey:@"user"];
  7508. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  7509. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7510. // else
  7511. if(appDelegate.contact_id!=nil)
  7512. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7513. if(appDelegate.password!=nil)
  7514. [params setValue:appDelegate.password forKey:@"password"];
  7515. if(appDelegate.order_code!=nil)
  7516. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7517. // NSDictionary* customerinfo=nil;
  7518. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  7519. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7520. // else
  7521. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7522. //
  7523. // appDelegate.customerInfo;
  7524. // NSArray* keys=[customerinfo allKeys];
  7525. // for(int i=0;i<keys.count;i++)
  7526. // {
  7527. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7528. // }
  7529. // [params setValue:sourceid forKey:@"sourceid"];
  7530. // [params setValue:editor forKey:@"editor"];
  7531. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  7532. if(appDelegate.offline_mode)
  7533. {
  7534. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7535. NSData* json = [[OLDataProvider offline_saveorder:params] mutableCopy];
  7536. dispatch_async(dispatch_get_main_queue(), ^{
  7537. result([[RAConvertor data2dict:json] mutableCopy]);
  7538. });
  7539. });
  7540. return;
  7541. }
  7542. [self request_interface:URL_SAVE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  7543. //
  7544. // NSData* json=nil;
  7545. //
  7546. // if(appDelegate.offline_mode)
  7547. // {
  7548. // json= [OLDataProvider offline_saveorder:params];
  7549. // }
  7550. // else
  7551. // {
  7552. // if(![self IsNetworkAvailable])
  7553. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7554. //
  7555. // json=[self get_json:URL_SAVE_ORDER parameters:params];
  7556. // }
  7557. // if(json!=nil)
  7558. // {
  7559. // NSError *error=nil;
  7560. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7561. // NSString *so = [jsobj valueForKey:@"so#"];
  7562. // if (so) {
  7563. // [appDelegate SetSo:so];
  7564. // }
  7565. // return jsobj;
  7566. // }
  7567. // else
  7568. // return nil;
  7569. }
  7570. +(void) request_update_cartqty:(NSString*) cart_id value:(int) value completionHandler:(resultHandler)result
  7571. {
  7572. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7573. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  7574. if(RASingleton.sharedInstance.enable_OfflineOrder)
  7575. {
  7576. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7577. //
  7578. //
  7579. // [appDelegate update_count_mark];
  7580. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7581. int count = [section[@"count"] intValue];
  7582. for(int i=0;i<count;i++)
  7583. {
  7584. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7585. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7586. {
  7587. item[@"count"] =@(value);
  7588. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7589. break;
  7590. }
  7591. }
  7592. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7593. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7594. result(RASingleton.sharedInstance.scan_cart);
  7595. return;
  7596. }
  7597. if(appDelegate.user!=nil)
  7598. [params setValue:appDelegate.user forKey:@"user"];
  7599. if(appDelegate.contact_id!=nil)
  7600. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7601. if(appDelegate.password!=nil)
  7602. [params setValue:appDelegate.password forKey:@"password"];
  7603. [params setValue:cart_id forKey:@"cartitem_id"];
  7604. [params setObject:ScreenCodeCart forKey:kScreenName];
  7605. [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  7606. if(appDelegate.offline_mode)
  7607. {
  7608. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7609. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7610. NSData* json = [[OLDataProvider offline_cartsetqty:params] mutableCopy];
  7611. dispatch_async(dispatch_get_main_queue(), ^{
  7612. result([[RAConvertor data2dict:json] mutableCopy]);
  7613. });
  7614. });
  7615. return;
  7616. }
  7617. [self request_interface:URL_CART_INCRESEMENT parameters:params err_record_url:nil completionHandler:result retry:0];
  7618. //
  7619. // NSData* json=nil;
  7620. // if(appDelegate.offline_mode)
  7621. // {
  7622. // json= [OLDataProvider offline_cartsetqty:params];
  7623. // }
  7624. // else
  7625. // {
  7626. // if(![self IsNetworkAvailable])
  7627. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7628. //
  7629. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  7630. // }
  7631. // if(json==nil)
  7632. // return nil;
  7633. // NSError *error=nil;
  7634. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7635. // return jsobj;
  7636. }
  7637. +(void) request_update_cartgeneralnote:(NSString*) order_code notes:(NSString*) notes completionHandler:(resultHandler)result
  7638. {
  7639. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7640. AppDelegate *appDelegate = nil;
  7641. if(RASingleton.sharedInstance.enable_OfflineOrder)
  7642. {
  7643. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7644. //
  7645. //
  7646. // [appDelegate update_count_mark];
  7647. RASingleton.sharedInstance.scan_cart[@"general_note"] = notes;
  7648. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7649. result(RASingleton.sharedInstance.scan_cart);
  7650. return;
  7651. }
  7652. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7653. if(appDelegate.user!=nil)
  7654. [params setValue:appDelegate.user forKey:@"user"];
  7655. if(appDelegate.contact_id!=nil)
  7656. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7657. if(appDelegate.password!=nil)
  7658. [params setValue:appDelegate.password forKey:@"password"];
  7659. [params setValue:order_code forKey:@"orderCode"];
  7660. [params setObject:ScreenCodeCart forKey:kScreenName];
  7661. if(notes.length==0)
  7662. notes=@"";
  7663. [params setValue:notes forKey:@"comments"];
  7664. if(appDelegate.offline_mode)
  7665. {
  7666. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7667. NSData* json = [[OLDataProvider offline_updategnotes:params] mutableCopy];
  7668. dispatch_async(dispatch_get_main_queue(), ^{
  7669. result([[RAConvertor data2dict:json] mutableCopy]);
  7670. });
  7671. });
  7672. return;
  7673. }
  7674. [self request_interface:URL_CART_GENERAL_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7675. //
  7676. // NSData* json=nil;
  7677. // if(appDelegate.offline_mode)
  7678. // {
  7679. // json= [OLDataProvider offline_updategnotes:params];
  7680. // }
  7681. // else
  7682. // {
  7683. // if(![self IsNetworkAvailable])
  7684. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7685. //
  7686. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  7687. // }
  7688. // if(json==nil)
  7689. // return nil;
  7690. // NSError *error=nil;
  7691. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7692. // return jsobj;
  7693. }
  7694. +(void) request_update_cartitemnote:(NSString*) cart_id notes:(NSString*) notes completionHandler:(resultHandler)result
  7695. {
  7696. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7697. AppDelegate *appDelegate = nil;
  7698. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7699. if(RASingleton.sharedInstance.enable_OfflineOrder)
  7700. {
  7701. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7702. //
  7703. //
  7704. // [appDelegate update_count_mark];
  7705. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7706. int count = [section[@"count"] intValue];
  7707. for(int i=0;i<count;i++)
  7708. {
  7709. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7710. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7711. {
  7712. item[@"note"] =notes;
  7713. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7714. break;
  7715. }
  7716. }
  7717. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7718. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7719. result(RASingleton.sharedInstance.scan_cart);
  7720. return;
  7721. }
  7722. if(appDelegate.user!=nil)
  7723. [params setValue:appDelegate.user forKey:@"user"];
  7724. if(appDelegate.contact_id!=nil)
  7725. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7726. if(appDelegate.password!=nil)
  7727. [params setValue:appDelegate.password forKey:@"password"];
  7728. [params setValue:cart_id forKey:@"cartitem_id"];
  7729. [params setObject:ScreenCodeCart forKey:kScreenName];
  7730. if(notes.length==0)
  7731. notes=@"";
  7732. [params setValue:notes forKey:@"notes"];
  7733. if(appDelegate.offline_mode)
  7734. {
  7735. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7736. NSData* json = [[OLDataProvider offline_cartsetlnotes:params] mutableCopy];
  7737. dispatch_async(dispatch_get_main_queue(), ^{
  7738. result([[RAConvertor data2dict:json] mutableCopy]);
  7739. });
  7740. });
  7741. return;
  7742. }
  7743. [self request_interface:URL_CART_ITEM_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7744. //
  7745. // NSData* json=nil;
  7746. // if(appDelegate.offline_mode)
  7747. // {
  7748. // json= [OLDataProvider offline_cartsetlnotes:params];
  7749. // }
  7750. // else
  7751. // {
  7752. // if(![self IsNetworkAvailable])
  7753. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7754. //
  7755. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  7756. // }
  7757. // if(json==nil)
  7758. // return nil;
  7759. // NSError *error=nil;
  7760. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7761. // return jsobj;
  7762. }
  7763. + (void)request_update_npd_shop_price_type:(NSInteger)priceType completionHandler:(resultHandler)result
  7764. {
  7765. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7766. AppDelegate *appDelegate = nil;
  7767. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7768. if(appDelegate.user!=nil)
  7769. [dic setValue:appDelegate.user forKey:@"user"];
  7770. if(appDelegate.password!=nil)
  7771. [dic setValue:appDelegate.password forKey:@"password"];
  7772. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  7773. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  7774. if(appDelegate.offline_mode)
  7775. {
  7776. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7777. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7778. dispatch_async(dispatch_get_main_queue(), ^{
  7779. result(json);
  7780. });
  7781. });
  7782. return;
  7783. }
  7784. [self request_interface:URL_SET_PRICE_TYPE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7785. //
  7786. // NSData* json=nil;
  7787. // if(appDelegate.offline_mode)
  7788. // {
  7789. // return [OLDataProvider offline_notimpl];
  7790. // }
  7791. // else
  7792. // {
  7793. // if(![self IsNetworkAvailable])
  7794. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7795. //
  7796. // json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  7797. // }
  7798. // if(json!=nil)
  7799. // {
  7800. // NSError *error=nil;
  7801. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7802. //
  7803. //
  7804. // return jsobj;
  7805. // }
  7806. //
  7807. //
  7808. // return nil;
  7809. }
  7810. + (void)request_npd_shop_givenprice:(resultHandler)result
  7811. {
  7812. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7813. AppDelegate *appDelegate = nil;
  7814. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7815. if(appDelegate.user!=nil)
  7816. [dic setValue:appDelegate.user forKey:@"user"];
  7817. if(appDelegate.password!=nil)
  7818. [dic setValue:appDelegate.password forKey:@"password"];
  7819. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  7820. if(appDelegate.offline_mode)
  7821. {
  7822. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7823. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7824. dispatch_async(dispatch_get_main_queue(), ^{
  7825. result(json);
  7826. });
  7827. });
  7828. return;
  7829. }
  7830. [self request_interface:URL_GET_CIVEN_PRICE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7831. //
  7832. // NSData* json=nil;
  7833. // if(appDelegate.offline_mode)
  7834. // {
  7835. // return [OLDataProvider offline_notimpl];
  7836. // }
  7837. // else
  7838. // {
  7839. // if(![self IsNetworkAvailable])
  7840. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7841. //
  7842. // json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  7843. // }
  7844. // if(json!=nil)
  7845. // {
  7846. // NSError *error=nil;
  7847. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7848. //
  7849. //
  7850. // return jsobj;
  7851. // }
  7852. //
  7853. //
  7854. // return nil;
  7855. }
  7856. + (void)request_update_npd_shop_givenprice:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  7857. {
  7858. AppDelegate *appDelegate = nil;
  7859. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7860. if(appDelegate.user!=nil)
  7861. [params setValue:appDelegate.user forKey:@"user"];
  7862. if(appDelegate.password!=nil)
  7863. [params setValue:appDelegate.password forKey:@"password"];
  7864. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  7865. if(appDelegate.offline_mode)
  7866. {
  7867. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7868. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7869. dispatch_async(dispatch_get_main_queue(), ^{
  7870. result(json);
  7871. });
  7872. });
  7873. return;
  7874. }
  7875. [self request_interface:URL_SET_GIVEN_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  7876. //
  7877. // NSData* json=nil;
  7878. // if(appDelegate.offline_mode)
  7879. // {
  7880. // return [OLDataProvider offline_notimpl];
  7881. // }
  7882. // else
  7883. // {
  7884. // if(![self IsNetworkAvailable])
  7885. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7886. //
  7887. // json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  7888. // }
  7889. // if(json!=nil)
  7890. // {
  7891. // NSError *error=nil;
  7892. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7893. //
  7894. //
  7895. // return jsobj;
  7896. // }
  7897. //
  7898. //
  7899. // return nil;
  7900. }
  7901. +(void) request_create_portfolio:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7902. {
  7903. AppDelegate *appDelegate = nil;
  7904. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7905. if(appDelegate.offline_mode)
  7906. {
  7907. params[@"contact_id"]=params[@"contactId"];
  7908. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7909. NSData* json = [[OLDataProvider offline_direct_save_TearSheet:params] mutableCopy];
  7910. dispatch_async(dispatch_get_main_queue(), ^{
  7911. result([[RAConvertor data2dict:json] mutableCopy]);
  7912. });
  7913. });
  7914. return;
  7915. }
  7916. //
  7917. // if(appDelegate.offline_mode)
  7918. // {
  7919. //
  7920. //
  7921. // NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  7922. // if(json==nil)
  7923. // return nil;
  7924. // NSError *error=nil;
  7925. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7926. //
  7927. // return jsobj[@"pdf_path"];
  7928. // }
  7929. // else
  7930. // {
  7931. // return nil;
  7932. // }
  7933. }
  7934. +(void)request_save_portfoliodirectly:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7935. {
  7936. NSMutableDictionary* off_params = [params mutableCopy];
  7937. AppDelegate *appDelegate = nil;
  7938. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7939. if(appDelegate.user!=nil)
  7940. [params setValue:appDelegate.user forKey:@"user"];
  7941. if(appDelegate.contact_id!=nil)
  7942. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7943. if(appDelegate.password!=nil)
  7944. params[@"off_params"]=[RAConvertor dict2string:off_params];
  7945. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  7946. [params setValue:appDelegate.password forKey:@"password"];
  7947. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7948. if(appDelegate.offline_mode)
  7949. {
  7950. params[@"contact_id"]=appDelegate.contact_id;
  7951. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7952. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_direct_save_TearSheet:params]] mutableCopy];
  7953. dispatch_async(dispatch_get_main_queue(), ^{
  7954. result(json);
  7955. });
  7956. });
  7957. return;
  7958. }
  7959. NSString * uuid= [[NSUUID UUID] UUIDString];
  7960. params[@"resultSerial"]=uuid;
  7961. __block bool bbreak = false;
  7962. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7963. for(int i=0;i<150;i++)
  7964. {
  7965. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7966. // result_params[@"resultSerial"]=uuid;
  7967. if(bbreak)
  7968. break;
  7969. dispatch_async(dispatch_get_main_queue(), ^{
  7970. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7971. if([resulti[@"result"] intValue]==2)
  7972. {
  7973. if(!bbreak)//此判断保证result只调用一次。
  7974. result(resulti);
  7975. bbreak=true;
  7976. }
  7977. } retry:3];
  7978. });
  7979. sleep(2);
  7980. }
  7981. });
  7982. //
  7983. //
  7984. // NSData* json= nil;
  7985. //
  7986. // if(appDelegate.offline_mode)
  7987. // {
  7988. // json = [OLDataProvider offline_direct_save_TearSheet:params];
  7989. // }
  7990. // else
  7991. // {
  7992. // if(![self IsNetworkAvailable])
  7993. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7994. //
  7995. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7996. //
  7997. // NSError *error=nil;
  7998. //
  7999. // NSString * uuid= [[NSUUID UUID] UUIDString];
  8000. // params[@"resultSerial"]=uuid;
  8001. //
  8002. // for(int i=0;i<150;i++)
  8003. // {
  8004. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8005. // // result_params[@"resultSerial"]=uuid;
  8006. // json=[self get_json:URL_REQUEST_DM parameters:params];
  8007. // if(json!=nil)
  8008. // {
  8009. //
  8010. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8011. // if([jsobj[@"result"] intValue]==2)
  8012. // {
  8013. // break;
  8014. // }
  8015. // }
  8016. // sleep(5);
  8017. // }
  8018. //
  8019. // }
  8020. // if(json==nil)
  8021. // return nil;
  8022. // NSError *error=nil;
  8023. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8024. // return jsobj;
  8025. }
  8026. +(void)request_save_portfolio:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  8027. {
  8028. AppDelegate *appDelegate = nil;
  8029. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8030. if(appDelegate.user!=nil)
  8031. [params setValue:appDelegate.user forKey:@"user"];
  8032. if(appDelegate.contact_id!=nil)
  8033. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8034. NSMutableDictionary* off_params = [params mutableCopy];;
  8035. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  8036. params[@"off_params"]=[RAConvertor dict2string:off_params];
  8037. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8038. if(appDelegate.password!=nil)
  8039. [params setValue:appDelegate.password forKey:@"password"];
  8040. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  8041. if(appDelegate.offline_mode)
  8042. {
  8043. params[@"contact_id"]=appDelegate.contact_id;
  8044. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8045. NSData* json = [[OLDataProvider offline_save_TearSheet:params] mutableCopy];
  8046. dispatch_async(dispatch_get_main_queue(), ^{
  8047. result([[RAConvertor data2dict:json] mutableCopy]);
  8048. });
  8049. });
  8050. return;
  8051. }
  8052. [self request_interface:URL_SAVE_DM parameters:params err_record_url:nil completionHandler:result retry:0];
  8053. //
  8054. // NSData* json = nil;
  8055. // if(appDelegate.offline_mode)
  8056. // {
  8057. // json = [OLDataProvider offline_save_TearSheet:params];
  8058. // } else {
  8059. // if(![self IsNetworkAvailable])
  8060. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8061. //
  8062. // json=[self get_json:URL_SAVE_DM parameters:params];
  8063. // }
  8064. // if(json==nil)
  8065. // return nil;
  8066. // NSError *error=nil;
  8067. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8068. // return jsobj;
  8069. }
  8070. +(void)request_portfoliopreview:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8071. {
  8072. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8073. AppDelegate *appDelegate = nil;
  8074. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8075. if(appDelegate.user!=nil)
  8076. [params setValue:appDelegate.user forKey:@"user"];
  8077. if(appDelegate.contact_id!=nil)
  8078. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8079. if(appDelegate.password!=nil)
  8080. [params setValue:appDelegate.password forKey:@"password"];
  8081. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  8082. // [params setValue:request_url forKey:@"pdfUrl"];
  8083. if(appDelegate.offline_mode)
  8084. {
  8085. params[@"contact_id"]=params[@"contactId"];
  8086. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8087. NSData* json = [[OLDataProvider offline_request_tearsheet:params] mutableCopy];
  8088. dispatch_async(dispatch_get_main_queue(), ^{
  8089. result([[RAConvertor data2dict:json] mutableCopy]);
  8090. });
  8091. });
  8092. return;
  8093. }
  8094. NSString * uuid= [[NSUUID UUID] UUIDString];
  8095. params[@"resultSerial"]=uuid;
  8096. __block bool bbreak = false;
  8097. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8098. for(int i=0;i<150;i++)
  8099. {
  8100. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8101. // result_params[@"resultSerial"]=uuid;
  8102. if(bbreak)
  8103. break;
  8104. dispatch_async(dispatch_get_main_queue(), ^{
  8105. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8106. if([resulti[@"result"] intValue]==2)
  8107. {
  8108. if(!bbreak)//此判断保证result只调用一次。
  8109. result(resulti);
  8110. bbreak=true;
  8111. }
  8112. } retry:3];
  8113. });
  8114. sleep(5);
  8115. }
  8116. });
  8117. //
  8118. // NSData* json= nil;
  8119. // if(appDelegate.offline_mode)
  8120. // {
  8121. // json= [OLDataProvider offline_request_tearsheet:params];
  8122. // }
  8123. // else
  8124. // {
  8125. // if(![self IsNetworkAvailable])
  8126. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8127. //
  8128. // NSError *error=nil;
  8129. //
  8130. // NSString * uuid= [[NSUUID UUID] UUIDString];
  8131. // params[@"resultSerial"]=uuid;
  8132. //
  8133. // for(int i=0;i<150;i++)
  8134. // {
  8135. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  8136. // // result_params[@"resultSerial"]=uuid;
  8137. // json=[self get_json:URL_REQUEST_DM parameters:params];
  8138. // if(json!=nil)
  8139. // {
  8140. //
  8141. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8142. // if([jsobj[@"result"] intValue]==2)
  8143. // {
  8144. // break;
  8145. // }
  8146. // }
  8147. // sleep(5);
  8148. // }
  8149. // }
  8150. // if(json==nil)
  8151. // return nil;
  8152. // NSError *error=nil;
  8153. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8154. // return jsobj;
  8155. }
  8156. +(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
  8157. {
  8158. // for debug
  8159. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  8160. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8161. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8162. AppDelegate *appDelegate = nil;
  8163. //some UI methods ej
  8164. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8165. if(appDelegate.user!=nil)
  8166. [params setValue:appDelegate.user forKey:@"user"];
  8167. if(appDelegate.contact_id!=nil)
  8168. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8169. if(appDelegate.password!=nil)
  8170. [params setValue:appDelegate.password forKey:@"password"];
  8171. if(appDelegate.order_code!=nil)
  8172. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8173. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  8174. if (alert && qty && available && price && bestseller) {
  8175. [params setObject:@"Filter" forKey:kAction];
  8176. }
  8177. if ([RASingleton sharedInstance].homeItemClick) {
  8178. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  8179. [RASingleton sharedInstance].homeItemClick = NO;
  8180. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  8181. [RASingleton sharedInstance].homeClickedItemName = nil;
  8182. [params setObject:extra forKey:kExtra];
  8183. }
  8184. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  8185. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  8186. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  8187. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  8188. // [params setValue:filter forKey:@"filter"];
  8189. [params setValue:covertype forKey:@"covertype"];
  8190. [params setValue:ctgid forKey:@"ctgId"];
  8191. [params setValue:modelname forKey:@"modelName"];
  8192. [params setValue:modeldescrip forKey:@"modelDescription"];
  8193. [params setValue:alert forKey:@"alert"];
  8194. [params setValue:qty forKey:@"sold_by_qty"];
  8195. [params setValue:available forKey:@"available"];
  8196. [params setValue:price forKey:@"price"];
  8197. [params setValue:bestseller forKey:@"bestseller"];
  8198. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  8199. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  8200. if(appDelegate.offline_mode)
  8201. {
  8202. // [OLDataProvider offline_itemsearch:params completionHandler:result];
  8203. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8204. NSMutableDictionary* json = [[OLDataProvider offline_itemsearch:params] mutableCopy];
  8205. dispatch_async(dispatch_get_main_queue(), ^{
  8206. result(json);
  8207. });
  8208. });
  8209. return;
  8210. }
  8211. [self request_interface:URL_ITEM_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  8212. // if(appDelegate.offline_mode)
  8213. // {
  8214. // return [OLDataProvider offline_itemsearch:params];
  8215. // }
  8216. // if(![self IsNetworkAvailable])
  8217. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8218. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  8219. // if(json==nil)
  8220. // return nil;
  8221. // NSError *error=nil;
  8222. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8223. // return jsobj;
  8224. }
  8225. +(void)request_modelqty: (NSString*) fashionId completionHandler:(resultHandler)result
  8226. {
  8227. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8228. AppDelegate *appDelegate = nil;
  8229. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8230. if(appDelegate.user!=nil)
  8231. [params setValue:appDelegate.user forKey:@"user"];
  8232. if(appDelegate.contact_id!=nil)
  8233. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8234. if(appDelegate.password!=nil)
  8235. [params setValue:appDelegate.password forKey:@"password"];
  8236. [params setValue:fashionId forKey:@"fashionId"];
  8237. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  8238. if(appDelegate.offline_mode)
  8239. {
  8240. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8241. NSData* json = [[OLDataProvider offline_model_qty:params] mutableCopy];
  8242. dispatch_async(dispatch_get_main_queue(), ^{
  8243. result([[RAConvertor data2dict:json] mutableCopy]);
  8244. });
  8245. });
  8246. return;
  8247. }
  8248. [self request_interface:URL_REQUEST_MODEL_QTY parameters:params err_record_url:nil completionHandler:result retry:0];
  8249. // NSData* json = nil;
  8250. // if(appDelegate.offline_mode)
  8251. // {
  8252. // json = [OLDataProvider offline_model_qty:params];
  8253. // } else {
  8254. // if(![self IsNetworkAvailable])
  8255. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8256. //
  8257. // json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  8258. // }
  8259. // if(json==nil)
  8260. // return nil;
  8261. // NSError *error=nil;
  8262. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8263. // return jsobj;
  8264. }
  8265. +(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
  8266. {
  8267. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8268. AppDelegate *appDelegate = nil;
  8269. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8270. if(appDelegate.user!=nil)
  8271. [params setValue:appDelegate.user forKey:@"user"];
  8272. if(appDelegate.contact_id!=nil)
  8273. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8274. if(appDelegate.password!=nil)
  8275. [params setValue:appDelegate.password forKey:@"password"];
  8276. [params setValue:watchlist_id forKey:@"item_id"];
  8277. // if(notes.length>0)
  8278. // [params setValue:notes forKey:@"notes"];
  8279. if(notes)
  8280. [params setValue:notes forKey:@"notes"];
  8281. if(price != -MAXFLOAT)
  8282. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  8283. if (discount != -MAXFLOAT)
  8284. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  8285. if(qty_p != -MAXFLOAT)
  8286. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  8287. if(qty != -INT32_MAX)
  8288. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  8289. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  8290. // NSData* json = nil;
  8291. if(appDelegate.offline_mode)
  8292. {
  8293. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8294. NSData* json = [[OLDataProvider offline_editPortfolio:params] mutableCopy];
  8295. dispatch_async(dispatch_get_main_queue(), ^{
  8296. result([[RAConvertor data2dict:json] mutableCopy]);
  8297. });
  8298. });
  8299. return;
  8300. }
  8301. [self request_interface:URL_PORTFOLIO_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8302. //
  8303. // if(appDelegate.offline_mode)
  8304. // {
  8305. // json = [OLDataProvider offline_editPortfolio:params];
  8306. // } else {
  8307. // if(![self IsNetworkAvailable])
  8308. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8309. //
  8310. // json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  8311. // }
  8312. // if(json==nil)
  8313. // return nil;
  8314. // NSError *error=nil;
  8315. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8316. // return jsobj;
  8317. }
  8318. +(void)request_add_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8319. {
  8320. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8321. AppDelegate *appDelegate = nil;
  8322. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8323. if(appDelegate.user!=nil)
  8324. [params setValue:appDelegate.user forKey:@"user"];
  8325. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  8326. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8327. // else
  8328. if(appDelegate.contact_id!=nil)
  8329. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8330. if(appDelegate.password!=nil)
  8331. [params setValue:appDelegate.password forKey:@"password"];
  8332. // NSDictionary* customerinfo=nil;
  8333. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  8334. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8335. // else
  8336. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8337. //
  8338. // appDelegate.customerInfo;
  8339. // NSArray* keys=[customerinfo allKeys];
  8340. // for(int i=0;i<keys.count;i++)
  8341. // {
  8342. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8343. // }
  8344. // [params setValue:sourceid forKey:@"sourceid"];
  8345. // [params setValue:editor forKey:@"editor"];
  8346. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  8347. if(appDelegate.offline_mode)
  8348. {
  8349. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8350. NSData* json = [[OLDataProvider offline_saveNewContact:params] mutableCopy];
  8351. dispatch_async(dispatch_get_main_queue(), ^{
  8352. result([[RAConvertor data2dict:json] mutableCopy]);
  8353. });
  8354. });
  8355. return;
  8356. }
  8357. [self request_interface:URL_CUSTOMER_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  8358. //
  8359. // NSData* json=nil;
  8360. // if(appDelegate.offline_mode)
  8361. // {
  8362. // json= [OLDataProvider offline_saveNewContact:params];
  8363. // }
  8364. // else
  8365. // {
  8366. // if(![self IsNetworkAvailable])
  8367. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8368. //
  8369. // json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  8370. // }
  8371. //
  8372. // if(json!=nil)
  8373. // {
  8374. // NSError *error=nil;
  8375. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8376. // return jsobj;
  8377. // }
  8378. // else
  8379. // return nil;
  8380. }
  8381. +(void)request_update_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8382. {
  8383. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8384. AppDelegate *appDelegate = nil;
  8385. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8386. if(appDelegate.user!=nil)
  8387. [params setValue:appDelegate.user forKey:@"user"];
  8388. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  8389. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8390. // else
  8391. if(appDelegate.contact_id!=nil)
  8392. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8393. if(appDelegate.password!=nil)
  8394. [params setValue:appDelegate.password forKey:@"password"];
  8395. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8396. if(appDelegate.offline_mode)
  8397. {
  8398. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8399. NSData* json = [[OLDataProvider offline_saveContact:params] mutableCopy];
  8400. dispatch_async(dispatch_get_main_queue(), ^{
  8401. result([[RAConvertor data2dict:json] mutableCopy]);
  8402. });
  8403. });
  8404. return;
  8405. }
  8406. [self request_interface:URL_CUSTOMER_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  8407. //
  8408. // NSData* json=nil;
  8409. // if(appDelegate.offline_mode)
  8410. // {
  8411. // json= [OLDataProvider offline_saveContact:params];
  8412. // }
  8413. // else
  8414. // {
  8415. // if(![self IsNetworkAvailable])
  8416. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8417. //
  8418. // json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  8419. // }
  8420. //
  8421. // if(json!=nil)
  8422. // {
  8423. // NSError *error=nil;
  8424. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8425. // return jsobj;
  8426. // }
  8427. // else
  8428. // return nil;
  8429. }
  8430. +(void)request_delete_order:(NSString*) order_id completionHandler:(resultHandler)result
  8431. {
  8432. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8433. AppDelegate *appDelegate = nil;
  8434. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8435. if(appDelegate.user!=nil)
  8436. [params setValue:appDelegate.user forKey:@"user"];
  8437. // if(appDelegate.contact_id!=nil)
  8438. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8439. if(appDelegate.password!=nil)
  8440. [params setValue:appDelegate.password forKey:@"password"];
  8441. [params setValue:order_id forKey:@"orderId"];
  8442. // [params setValue:sourceid forKey:@"sourceid"];
  8443. // [params setValue:editor forKey:@"editor"];
  8444. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8445. if(appDelegate.offline_mode)
  8446. {
  8447. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8448. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8449. dispatch_async(dispatch_get_main_queue(), ^{
  8450. result(json);
  8451. });
  8452. });
  8453. return;
  8454. }
  8455. [self request_interface:URL_DELETE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8456. //
  8457. // if(appDelegate.offline_mode)
  8458. // {
  8459. // return [OLDataProvider offline_notimpl];
  8460. // }
  8461. // if(![self IsNetworkAvailable])
  8462. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8463. //
  8464. // NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  8465. // if(json!=nil)
  8466. // {
  8467. // NSError *error=nil;
  8468. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8469. //
  8470. //
  8471. // return jsobj;
  8472. // }
  8473. // else
  8474. // return nil;
  8475. }
  8476. +(void)request_cancel_order:(NSString*) order_id order_code:(NSString*) order_code completionHandler:(resultHandler)result
  8477. {
  8478. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8479. AppDelegate *appDelegate = nil;
  8480. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8481. if(appDelegate.user!=nil)
  8482. [params setValue:appDelegate.user forKey:@"user"];
  8483. // if(appDelegate.contact_id!=nil)
  8484. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8485. if(appDelegate.password!=nil)
  8486. [params setValue:appDelegate.password forKey:@"password"];
  8487. [params setValue:order_id forKey:@"orderId"];
  8488. [params setValue:order_code forKey:@"orderCode"];
  8489. // [params setValue:sourceid forKey:@"sourceid"];
  8490. // [params setValue:editor forKey:@"editor"];
  8491. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8492. if(appDelegate.offline_mode)
  8493. {
  8494. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8495. NSData* json = [[OLDataProvider offline_cancelorder:params] mutableCopy];
  8496. dispatch_async(dispatch_get_main_queue(), ^{
  8497. result([[RAConvertor data2dict:json] mutableCopy]);
  8498. });
  8499. });
  8500. return;
  8501. }
  8502. [self request_interface:URL_CANCEL_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8503. //
  8504. // NSData* json=nil;
  8505. // if(appDelegate.offline_mode)
  8506. // {
  8507. // json=[OLDataProvider offline_cancelorder:params];
  8508. // }
  8509. // else
  8510. // {
  8511. // if(![self IsNetworkAvailable])
  8512. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8513. // json=[self get_json:URL_CANCEL_ORDER parameters:params];
  8514. // }
  8515. // if(json!=nil)
  8516. // {
  8517. // NSError *error=nil;
  8518. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8519. //
  8520. //
  8521. // return jsobj;
  8522. // }
  8523. // else
  8524. // return nil;
  8525. }
  8526. +(void)request_release_order:(NSString*) order_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  8527. {
  8528. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8529. AppDelegate *appDelegate = nil;
  8530. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8531. if(appDelegate.user!=nil)
  8532. [params setValue:appDelegate.user forKey:@"user"];
  8533. // if(appDelegate.contact_id!=nil)
  8534. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8535. if(appDelegate.password!=nil)
  8536. [params setValue:appDelegate.password forKey:@"password"];
  8537. [params setValue:order_code forKey:@"orderCode"];
  8538. // [params setValue:sourceid forKey:@"sourceid"];
  8539. // [params setValue:editor forKey:@"editor"];
  8540. if (screenName) {
  8541. [params setValue:screenName forKey:kScreenName];
  8542. }
  8543. if(appDelegate.offline_mode)
  8544. {
  8545. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8546. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_resetorder:params]] mutableCopy];
  8547. dispatch_async(dispatch_get_main_queue(), ^{
  8548. if([[resulti valueForKey:@"result"]intValue]==2)
  8549. { [appDelegate SetSo:nil];
  8550. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8551. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8552. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8553. [appDelegate update_count_mark];
  8554. dispatch_async(dispatch_get_main_queue(), ^{
  8555. result(resulti);
  8556. });
  8557. }
  8558. });
  8559. });
  8560. return;
  8561. }
  8562. [self request_interface:URL_RELEASE_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8563. if([[resulti valueForKey:@"result"]intValue]==2)
  8564. { [appDelegate SetSo:nil];
  8565. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8566. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8567. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8568. [appDelegate update_count_mark];
  8569. dispatch_async(dispatch_get_main_queue(), ^{
  8570. result(resulti);
  8571. });
  8572. }
  8573. } retry:0];
  8574. //
  8575. // NSData* json=nil;
  8576. // if(appDelegate.offline_mode)
  8577. // {
  8578. // json= [OLDataProvider offline_resetorder:params];
  8579. // }
  8580. // else
  8581. // {
  8582. // if(![self IsNetworkAvailable])
  8583. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8584. //
  8585. // json=[self get_json:URL_RELEASE_ORDER parameters:params];
  8586. // }
  8587. // if(json!=nil)
  8588. // {
  8589. // NSError *error=nil;
  8590. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8591. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8592. // { [appDelegate SetSo:nil];
  8593. //
  8594. //
  8595. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8596. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8597. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8598. //
  8599. // [appDelegate update_count_mark];
  8600. // }
  8601. // return jsobj;
  8602. // }
  8603. // else
  8604. // return nil;
  8605. }
  8606. +(void)request_update_order_signature:(NSString*) order_code path:(NSString*)path completionHandler:(resultHandler)result
  8607. {
  8608. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8609. AppDelegate *appDelegate = nil;
  8610. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8611. if(appDelegate.user!=nil)
  8612. [params setValue:appDelegate.user forKey:@"user"];
  8613. if(appDelegate.contact_id!=nil)
  8614. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8615. if(appDelegate.password!=nil)
  8616. [params setValue:appDelegate.password forKey:@"password"];
  8617. // NSString* ssaved = @"false";
  8618. // if(saved)
  8619. // ssaved=@"true";
  8620. // [params setValue:@"true" forKey:@"saved"];
  8621. [params setValue:order_code forKey:@"orderCode"];
  8622. [params setValue:path forKey:@"picpath"];
  8623. // [params setValue:sourceid forKey:@"sourceid"];
  8624. // [params setValue:editor forKey:@"editor"];
  8625. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  8626. if(appDelegate.offline_mode)
  8627. {
  8628. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8629. NSData* json = [[OLDataProvider offline_signorder:params] mutableCopy];
  8630. dispatch_async(dispatch_get_main_queue(), ^{
  8631. result([[RAConvertor data2dict:json] mutableCopy]);
  8632. });
  8633. });
  8634. return;
  8635. }
  8636. [self request_interface:URL_SIGN_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8637. //
  8638. // NSData* json=nil;
  8639. // if(appDelegate.offline_mode)
  8640. // {
  8641. // json= [OLDataProvider offline_signorder:params];
  8642. // }
  8643. // else
  8644. // {
  8645. // if(![self IsNetworkAvailable])
  8646. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8647. //
  8648. // json=[self get_json:URL_SIGN_ORDER parameters:params];
  8649. // }
  8650. // if(json!=nil)
  8651. // {
  8652. // NSError *error=nil;
  8653. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8654. // return jsobj;
  8655. // }
  8656. // else
  8657. // return nil;
  8658. }
  8659. +(void) request_update_cart_modelprice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8660. {
  8661. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8662. AppDelegate *appDelegate = nil;
  8663. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8664. if(RASingleton.sharedInstance.enable_OfflineOrder)
  8665. {
  8666. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  8667. //
  8668. //
  8669. // [appDelegate update_count_mark];
  8670. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  8671. int count = [section[@"count"] intValue];
  8672. for(int i=0;i<count;i++)
  8673. {
  8674. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  8675. if([item[@"cart_item_id"] isEqualToString:cart_id])
  8676. {
  8677. int item_count = [item[@"count"] intValue];
  8678. item[@"unit_price"] =@(price);
  8679. item[@"discount"] =@(discount);
  8680. item[@"subtotal_price"] =@(price*item_count);
  8681. item[@"note"] =@"PRICE MODIFIED";
  8682. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  8683. break;
  8684. }
  8685. }
  8686. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  8687. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  8688. result(RASingleton.sharedInstance.scan_cart);
  8689. return;
  8690. }
  8691. if(appDelegate.user!=nil)
  8692. [params setValue:appDelegate.user forKey:@"user"];
  8693. if(appDelegate.contact_id!=nil)
  8694. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8695. if(appDelegate.password!=nil)
  8696. [params setValue:appDelegate.password forKey:@"password"];
  8697. [params setValue:cart_id forKey:@"cartitem_id"];
  8698. [params setValue:notes forKey:@"item_note"];
  8699. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  8700. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  8701. [params setObject:ScreenCodeCart forKey:kScreenName];
  8702. if(appDelegate.offline_mode)
  8703. {
  8704. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8705. NSData* json = [[OLDataProvider offline_cartsetprice:params] mutableCopy];
  8706. dispatch_async(dispatch_get_main_queue(), ^{
  8707. result([[RAConvertor data2dict:json] mutableCopy]);
  8708. });
  8709. });
  8710. return;
  8711. }
  8712. [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8713. //
  8714. // NSData* json= nil;
  8715. // if(appDelegate.offline_mode)
  8716. // {
  8717. // json=[OLDataProvider offline_cartsetprice:params];
  8718. // }
  8719. // else
  8720. // {
  8721. // if(![self IsNetworkAvailable])
  8722. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8723. //
  8724. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8725. // }
  8726. // if(json==nil)
  8727. // return nil;
  8728. // NSError *error=nil;
  8729. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8730. // return jsobj;
  8731. }
  8732. +(void) request_addto_cart:(NSString* ) item_id count:(int) count name:(NSString *)name completionHandler:(resultHandler)result
  8733. {
  8734. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8735. AppDelegate *appDelegate = nil;
  8736. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8737. if(appDelegate.user!=nil)
  8738. [params setValue:appDelegate.user forKey:@"user"];
  8739. if(appDelegate.contact_id!=nil)
  8740. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8741. if(appDelegate.password!=nil)
  8742. [params setValue:appDelegate.password forKey:@"password"];
  8743. if(appDelegate.order_code!=nil)
  8744. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8745. [params setValue:item_id forKey:@"product_id"];
  8746. [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  8747. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  8748. [params setObject:@"Add To Cart" forKey:kAction];
  8749. if (name) {
  8750. NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  8751. [params setObject:extra forKey:kExtra];
  8752. }
  8753. NSDictionary* customerinfo= appDelegate.customerInfo;
  8754. NSArray* keys=[customerinfo allKeys];
  8755. for(int i=0;i<keys.count;i++)
  8756. {
  8757. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8758. }
  8759. if(appDelegate.offline_mode)
  8760. {
  8761. // [OLDataProvider offline_add2cart:params completionHandler:^(NSMutableDictionary *resulti) {
  8762. // NSMutableDictionary* json = resulti;
  8763. // if ([json[@"result"] intValue]==2)
  8764. // {
  8765. // appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  8766. //
  8767. // [appDelegate update_count_mark];
  8768. // }
  8769. // result(json);
  8770. // }];
  8771. params[@"can_create_backorder"]= @(appDelegate.can_create_backorder);
  8772. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8773. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cart:params]] mutableCopy];
  8774. dispatch_async(dispatch_get_main_queue(), ^{
  8775. if ([json[@"result"] intValue]==2)
  8776. {
  8777. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  8778. [appDelegate update_count_mark];
  8779. }
  8780. result(json);
  8781. });
  8782. });
  8783. return;
  8784. }
  8785. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8786. if ([resulti[@"result"] intValue]==2)
  8787. {
  8788. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8789. [appDelegate update_count_mark];
  8790. }
  8791. result(resulti);
  8792. } retry:0];
  8793. //
  8794. // NSData* json=nil;
  8795. // if(appDelegate.offline_mode)
  8796. // {
  8797. // json=[OLDataProvider offline_add2cart:params];
  8798. // }
  8799. // else
  8800. // {
  8801. // if(![self IsNetworkAvailable])
  8802. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8803. //
  8804. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  8805. // }
  8806. // if(json==nil)
  8807. // return nil;
  8808. // NSError *error=nil;
  8809. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8810. //
  8811. //
  8812. //
  8813. // int result = [[jsobj valueForKey:@"result"] intValue];
  8814. //
  8815. // if (result==2)
  8816. // {
  8817. //
  8818. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8819. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8820. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8821. //
  8822. // [appDelegate update_count_mark];
  8823. // }
  8824. //
  8825. // return jsobj;
  8826. }
  8827. //+(void) request_update_cart_modelfree:(NSString*) cart_id isfree:(bool) isfree completionHandler:(resultHandler)result
  8828. //{
  8829. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8830. // AppDelegate *appDelegate = nil;
  8831. //
  8832. //
  8833. //
  8834. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8835. //
  8836. // if(appDelegate.user!=nil)
  8837. // [params setValue:appDelegate.user forKey:@"user"];
  8838. // if(appDelegate.contact_id!=nil)
  8839. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8840. // if(appDelegate.password!=nil)
  8841. // [params setValue:appDelegate.password forKey:@"password"];
  8842. //
  8843. // [params setValue:cart_id forKey:@"cartitem_id"];
  8844. //
  8845. // [params setObject:ScreenCodeCart forKey:kScreenName];
  8846. //
  8847. // NSString* free=nil;
  8848. //
  8849. // if(isfree)
  8850. // free=@"true";
  8851. // else
  8852. // free=@"false";
  8853. //
  8854. // [params setValue:free forKey:@"free_giveaway"];
  8855. //
  8856. //
  8857. // if(appDelegate.offline_mode)
  8858. // {
  8859. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8860. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8861. // dispatch_async(dispatch_get_main_queue(), ^{
  8862. // result(json);
  8863. // });
  8864. // });
  8865. //
  8866. // return;
  8867. //
  8868. // }
  8869. // [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8870. //
  8871. ////
  8872. ////
  8873. //// if(appDelegate.offline_mode)
  8874. //// {
  8875. //// return [OLDataProvider offline_notimpl];
  8876. //// }
  8877. //// if(![self IsNetworkAvailable])
  8878. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8879. ////
  8880. //// NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8881. //// if(json==nil)
  8882. //// return nil;
  8883. //// NSError *error=nil;
  8884. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8885. //// return jsobj;
  8886. //}
  8887. +(void)request_retrieve_password: (NSString*) user email:(NSString*) email completionHandler:(resultHandler)result
  8888. {
  8889. AppDelegate *appDelegate = nil;
  8890. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8891. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8892. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8893. // if(appDelegate.user!=nil)
  8894. // [params setValue:appDelegate.user forKey:@"user"];
  8895. // if(appDelegate.contact_id!=nil)
  8896. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8897. // if(appDelegate.password!=nil)
  8898. // [params setValue:appDelegate.password forKey:@"password"];
  8899. [params setValue:user forKey:@"username"];
  8900. [params setValue:email forKey:@"email"];
  8901. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  8902. if(appDelegate.offline_mode)
  8903. {
  8904. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8905. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8906. dispatch_async(dispatch_get_main_queue(), ^{
  8907. result(json);
  8908. });
  8909. });
  8910. return;
  8911. }
  8912. [self request_interface:URL_RETRIEVE_PASS parameters:params err_record_url:nil completionHandler:result retry:0];
  8913. //
  8914. //
  8915. // if(![self IsNetworkAvailable])
  8916. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8917. //
  8918. // NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  8919. // if(json==nil)
  8920. // return nil;
  8921. // NSError *error=nil;
  8922. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8923. // return jsobj;
  8924. }
  8925. +(void)request_update_ordercustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info completionHandler:(resultHandler)result
  8926. {
  8927. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8928. AppDelegate *appDelegate = nil;
  8929. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8930. if(appDelegate.user!=nil)
  8931. [info setValue:appDelegate.user forKey:@"user"];
  8932. // if(appDelegate.contact_id!=nil)
  8933. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8934. if(appDelegate.password!=nil)
  8935. [info setValue:appDelegate.password forKey:@"password"];
  8936. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8937. [info setValue:order_code forKey:@"orderCode"];
  8938. // [params setValue:sourceid forKey:@"sourceid"];
  8939. // [params setValue:editor forKey:@"editor"];
  8940. if(appDelegate.offline_mode)
  8941. {
  8942. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8943. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8944. dispatch_async(dispatch_get_main_queue(), ^{
  8945. result(json);
  8946. });
  8947. });
  8948. return;
  8949. }
  8950. [self request_interface:URL_UPDATE_ORDERCUSTOMER parameters:info err_record_url:nil completionHandler:result retry:0];
  8951. // if(appDelegate.offline_mode)
  8952. // {
  8953. // return [OLDataProvider offline_notimpl];
  8954. // }
  8955. // if(![self IsNetworkAvailable])
  8956. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8957. //
  8958. // NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  8959. // if(json!=nil)
  8960. // {
  8961. // NSError *error=nil;
  8962. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8963. // return jsobj;
  8964. // }
  8965. // else
  8966. // return nil;
  8967. }
  8968. +(void)request_update_customer_img: (NSString*) contactid img_url:(NSString*) url completionHandler:(resultHandler)result
  8969. {
  8970. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8971. AppDelegate *appDelegate = nil;
  8972. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8973. if(appDelegate.user!=nil)
  8974. [params setValue:appDelegate.user forKey:@"user"];
  8975. // if(appDelegate.contact_id!=nil)
  8976. if(appDelegate.password!=nil)
  8977. [params setValue:appDelegate.password forKey:@"password"];
  8978. [params setValue:contactid forKey:@"contactId"];
  8979. [params setValue:url forKey:@"business_card"];
  8980. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  8981. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8982. if(appDelegate.offline_mode)
  8983. {
  8984. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8985. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8986. dispatch_async(dispatch_get_main_queue(), ^{
  8987. result(json);
  8988. });
  8989. });
  8990. return;
  8991. }
  8992. [self request_interface:URL_UPDATE_CUSTOMER_BCARD parameters:params err_record_url:nil completionHandler:result retry:0];
  8993. // if(appDelegate.offline_mode)
  8994. // {
  8995. // return [OLDataProvider offline_notimpl];
  8996. // }
  8997. // if(![self IsNetworkAvailable])
  8998. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8999. //
  9000. // NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  9001. // if(json==nil)
  9002. // return nil;
  9003. // NSError *error=nil;
  9004. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9005. // return jsobj;
  9006. }
  9007. +(void)request_commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url completionHandler:(resultHandler)result
  9008. {
  9009. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9010. AppDelegate *appDelegate = nil;
  9011. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9012. if(appDelegate.user!=nil)
  9013. [params setValue:appDelegate.user forKey:@"user"];
  9014. if(appDelegate.contact_id!=nil)
  9015. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9016. if(appDelegate.password!=nil)
  9017. [params setValue:appDelegate.password forKey:@"password"];
  9018. // if(appDelegate.order_code!=nil)
  9019. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  9020. // NSDictionary* customerinfo= appDelegate.customerInfo;
  9021. //
  9022. // NSArray* keys=[customerinfo allKeys];
  9023. // for(int i=0;i<keys.count;i++)
  9024. // {
  9025. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  9026. // }
  9027. //
  9028. // [params setValue:sourceid forKey:@"sourceid"];
  9029. // [params setValue:editor forKey:@"editor"];
  9030. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  9031. if(appDelegate.offline_mode)
  9032. {
  9033. params[@"offline_Command"]=url;
  9034. [OLDataProvider offline_commoneditor_partialrefresh:params completionHandler:result];
  9035. //
  9036. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9037. // NSMutableDictionary* json = [[OLDataProvider offline_commoneditor_partialrefresh:params] mutableCopy];
  9038. // dispatch_async(dispatch_get_main_queue(), ^{
  9039. // result(json);
  9040. // });
  9041. // });
  9042. return;
  9043. }
  9044. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  9045. //
  9046. // if(appDelegate.offline_mode)
  9047. // {
  9048. // params[@"offline_Command"]=url;
  9049. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  9050. // }
  9051. //
  9052. // if(![self IsNetworkAvailable])
  9053. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9054. //
  9055. // NSData* json=[self get_json:url parameters:params];
  9056. // if(json!=nil)
  9057. // {
  9058. // NSError *error=nil;
  9059. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9060. // if([[jsobj valueForKey:@"result"]intValue]==2)
  9061. // [appDelegate SetSo:nil];
  9062. //
  9063. //
  9064. // return jsobj;
  9065. // }
  9066. // else
  9067. // return nil;
  9068. }
  9069. +(void)request_add_address:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  9070. {
  9071. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9072. AppDelegate *appDelegate = nil;
  9073. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9074. if(appDelegate.user!=nil)
  9075. [params setValue:appDelegate.user forKey:@"user"];
  9076. if(appDelegate.contact_id!=nil)
  9077. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9078. if(appDelegate.password!=nil)
  9079. [params setValue:appDelegate.password forKey:@"password"];
  9080. // [params setValue:sourceid forKey:@"sourceid"];
  9081. // [params setValue:editor forKey:@"editor"];
  9082. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  9083. if(appDelegate.offline_mode)
  9084. {
  9085. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9086. NSData* json = [[OLDataProvider offline_saveaddr:params] mutableCopy];
  9087. dispatch_async(dispatch_get_main_queue(), ^{
  9088. result([[RAConvertor data2dict:json] mutableCopy]);
  9089. });
  9090. });
  9091. return;
  9092. }
  9093. [self request_interface:URL_ADDRESS_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  9094. //
  9095. // NSData* json=nil;
  9096. //
  9097. // if(appDelegate.offline_mode)
  9098. // {
  9099. // json= [OLDataProvider offline_saveaddr:params];
  9100. // }
  9101. // else
  9102. // {
  9103. // if(![self IsNetworkAvailable])
  9104. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9105. //
  9106. // json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  9107. // }
  9108. // if(json!=nil)
  9109. // {
  9110. // NSError *error=nil;
  9111. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9112. // return jsobj;
  9113. // }
  9114. // else
  9115. // return nil;
  9116. }
  9117. +(void)request_commit_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  9118. {
  9119. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9120. AppDelegate *appDelegate = nil;
  9121. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9122. if(appDelegate.user!=nil)
  9123. [params setValue:appDelegate.user forKey:@"user"];
  9124. if(appDelegate.contact_id!=nil)
  9125. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9126. if(appDelegate.password!=nil)
  9127. [params setValue:appDelegate.password forKey:@"password"];
  9128. if(appDelegate.order_code!=nil)
  9129. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  9130. // NSDictionary* customerinfo= appDelegate.customerInfo;
  9131. //
  9132. // NSArray* keys=[customerinfo allKeys];
  9133. // for(int i=0;i<keys.count;i++)
  9134. // {
  9135. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  9136. // }
  9137. //
  9138. // [params setValue:sourceid forKey:@"sourceid"];
  9139. // [params setValue:editor forKey:@"editor"];
  9140. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  9141. if(appDelegate.offline_mode)
  9142. {
  9143. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9144. NSData* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  9145. dispatch_async(dispatch_get_main_queue(), ^{
  9146. result([[RAConvertor data2dict:json] mutableCopy]);
  9147. });
  9148. });
  9149. return;
  9150. }
  9151. [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  9152. //
  9153. // NSData* json=nil;
  9154. // if(appDelegate.offline_mode)
  9155. // {
  9156. // json=[OLDataProvider offline_submitorder:params];
  9157. // }
  9158. // else
  9159. // {
  9160. // if(![self IsNetworkAvailable])
  9161. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9162. //
  9163. // json=[self get_json:URL_COMMIT_ORDER parameters:params];
  9164. // }
  9165. // if(json!=nil)
  9166. // {
  9167. // NSError *error=nil;
  9168. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9169. // if([[jsobj valueForKey:@"result"]intValue]==2)
  9170. // [appDelegate SetSo:nil];
  9171. //
  9172. //
  9173. // return jsobj;
  9174. // }
  9175. // else
  9176. // return nil;
  9177. }
  9178. +(void) request_new_offline_ticket:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid completionHandler:(resultHandler)result
  9179. {
  9180. // if(![self IsNetworkAvailable])
  9181. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9182. //
  9183. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9184. AppDelegate *appDelegate = nil;
  9185. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9186. if(appDelegate.user!=nil)
  9187. [params setValue:appDelegate.user forKey:@"user"];
  9188. // if(appDelegate.contact_id!=nil)
  9189. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9190. if(appDelegate.password!=nil)
  9191. [params setValue:appDelegate.password forKey:@"password"];
  9192. [params setValue:ver forKey:@"ver"];
  9193. [params setValue:vid forKey:@"vid"];
  9194. if(buseinternaladdress)
  9195. [params setValue:@"true" forKey:@"internal_address"];
  9196. else
  9197. [params setValue:@"false" forKey:@"internal_address"];
  9198. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  9199. // 无论当前是离线还是在线状态,都可以进行同步;
  9200. // if(appDelegate.offline_mode)
  9201. // {
  9202. //
  9203. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9204. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9205. // dispatch_async(dispatch_get_main_queue(), ^{
  9206. // result(json);
  9207. // });
  9208. // });
  9209. //
  9210. // return;
  9211. //
  9212. // }
  9213. [self request_interface:URL_CHECK_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  9214. //
  9215. // NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  9216. // if(json==nil)
  9217. // return nil;
  9218. // NSError *error=nil;
  9219. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9220. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9221. // //
  9222. // // if (result==2)
  9223. // // {
  9224. // //
  9225. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9226. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9227. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9228. // ////
  9229. // //// [appDelegate update_count_mark];
  9230. // // }
  9231. // return jsobj;
  9232. }
  9233. +(void) request_complete_offline_ticket:(NSString* )vid completionHandler:(resultHandler)result
  9234. {
  9235. AppDelegate *appDelegate = nil;
  9236. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9237. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9238. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  9239. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  9240. // if(appDelegate.user!=nil)
  9241. // [params setValue:appDelegate.user forKey:@"user"];
  9242. // // if(appDelegate.contact_id!=nil)
  9243. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9244. // if(appDelegate.password!=nil)
  9245. // [params setValue:appDelegate.password forKey:@"password"];
  9246. [params setValue:vid forKey:@"downSerial"];
  9247. // 无论当前是离线还是在线状态,都可以进行同步;
  9248. // if(appDelegate.offline_mode)
  9249. // {
  9250. //
  9251. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9252. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9253. // dispatch_async(dispatch_get_main_queue(), ^{
  9254. // result(json);
  9255. // });
  9256. // });
  9257. //
  9258. // return;
  9259. //
  9260. // }
  9261. [self request_interface:URL_FINISH_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  9262. // NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  9263. // if(json==nil)
  9264. // return nil;
  9265. // NSError *error=nil;
  9266. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9267. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9268. // //
  9269. // // if (result==2)
  9270. // // {
  9271. // //
  9272. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9273. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9274. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9275. // ////
  9276. // //// [appDelegate update_count_mark];
  9277. // // }
  9278. // return jsobj;
  9279. }
  9280. +(void) request_download_offline:(NSString* )vid completionHandler:(resultHandler)result
  9281. {
  9282. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9283. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  9284. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  9285. // if(appDelegate.user!=nil)
  9286. // [params setValue:appDelegate.user forKey:@"user"];
  9287. // // if(appDelegate.contact_id!=nil)
  9288. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  9289. // if(appDelegate.password!=nil)
  9290. // [params setValue:appDelegate.password forKey:@"password"];
  9291. [params setValue:vid forKey:@"downSerial"];
  9292. // AppDelegate *appDelegate = nil;
  9293. //
  9294. //
  9295. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9296. // if(appDelegate.offline_mode)
  9297. // {
  9298. //
  9299. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9300. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9301. // dispatch_async(dispatch_get_main_queue(), ^{
  9302. // result(json);
  9303. // });
  9304. // });
  9305. //
  9306. // return;
  9307. //
  9308. // }
  9309. __block bool bbreak = false;
  9310. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9311. __block NSMutableDictionary* download_json=nil;
  9312. int count=0;
  9313. // __block bool preparing = true;
  9314. while ([[download_json valueForKey:@"result"] intValue]!=2&&count<REQUEST_DOWNLOAD_RETRY_TIMES) //超过60分钟还没准被好数据就视为服务器出错。
  9315. {
  9316. if(bbreak)
  9317. break;
  9318. dispatch_async(dispatch_get_main_queue(), ^{
  9319. [self request_interface:URL_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  9320. if([resulti[@"result"] intValue]==RESULT_TRUE)
  9321. {
  9322. if(!bbreak) //此判断保证result只调用一次。
  9323. {
  9324. // appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  9325. // [appDelegate update_count_mark];
  9326. resulti[@"request_count"]=[NSNumber numberWithInt:count];
  9327. result(resulti);
  9328. }
  9329. bbreak=true;
  9330. }
  9331. else if([resulti[@"result"] intValue]==RESULT_ERROR)
  9332. {
  9333. result(resulti);
  9334. bbreak=true;
  9335. }
  9336. } retry:3];
  9337. });
  9338. sleep(RETRY_DELAY);
  9339. count++;
  9340. // download_json=[[RANetwork download_Offline:downSerial] mutableCopy];
  9341. //
  9342. // [RANetwork request_download_offline:downSerial completionHandler:^(NSMutableDictionary *result) {
  9343. // download_json=result;
  9344. // }];
  9345. //
  9346. }
  9347. // for(int i=0;i<150;i++)
  9348. // {
  9349. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  9350. // // result_params[@"resultSerial"]=uuid;
  9351. //
  9352. //
  9353. //
  9354. // sleep(2);
  9355. //
  9356. // // json=[self get_json:URL_CART parameters:params];
  9357. // // if(json!=nil)
  9358. // // {
  9359. // //
  9360. // // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9361. // // if([jsobj[@"result"] intValue]==2)
  9362. // // {
  9363. // // break;
  9364. // // }
  9365. // // }
  9366. //
  9367. // }
  9368. });
  9369. //
  9370. // NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  9371. // if(json==nil)
  9372. // return nil;
  9373. // NSError *error=nil;
  9374. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9375. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9376. // //
  9377. // // if (result==2)
  9378. // // {
  9379. // //
  9380. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9381. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9382. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9383. // ////
  9384. // //// [appDelegate update_count_mark];
  9385. // // }
  9386. // return jsobj;
  9387. }
  9388. + (void)request_fastupload:(NSMutableDictionary *)params filename:(NSString*)filename data:(NSData*) data url:(NSString *)url completionHandler:(resultHandler)result
  9389. {
  9390. //#ifdef test_server
  9391. // url=URL_REQUEST_RECORDS;
  9392. // params[@"prefix"]=URL_REQUEST_RECORDS;
  9393. //#endif
  9394. // [self request_file_fast:url parameters:params completionHandler:result];
  9395. [self request_upload_fast:data FileName:filename server:url parameters:params completionHandler:result];
  9396. }
  9397. +(void)request_err_log:(NSString*) up_params result:(NSString*)result_str module:(NSString*) module code:(int) code completionHandler:(resultHandler)result
  9398. {
  9399. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9400. AppDelegate *appDelegate = nil;
  9401. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9402. if(appDelegate.user!=nil)
  9403. [params setValue:appDelegate.user forKey:@"user"];
  9404. [params setValue:up_params forKey:@"upparam"];
  9405. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  9406. [params setValue:result_str forKey:@"result"];
  9407. [params setValue:module forKey:@"interfac"];
  9408. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  9409. // [params setValue:module forKey:@"module"];
  9410. // [[UIDevice currentDevice] name];
  9411. // if(appDelegate.offline_mode)
  9412. // {
  9413. // return [OLDataProvider offline_notimpl];
  9414. // }
  9415. if(appDelegate.offline_mode)
  9416. {
  9417. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9418. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9419. dispatch_async(dispatch_get_main_queue(), ^{
  9420. result(json);
  9421. });
  9422. });
  9423. return;
  9424. }
  9425. [self request_interface:URL_ERR_LOG parameters:params err_record_url:nil completionHandler:result retry:0];
  9426. //
  9427. // if(![self IsNetworkAvailable])
  9428. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9429. //
  9430. // NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  9431. // if(json==nil)
  9432. // return nil;
  9433. // NSError *error=nil;
  9434. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9435. // return jsobj;
  9436. }
  9437. @end