RANetwork.m 395 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940
  1. //
  2. // iSalesNetwork.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 14-6-20.
  6. // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "RANetwork.h"
  9. #import "RAUtils.h"
  10. #import "RASingleton.h"
  11. #ifdef GOOGLE_ANALYTICS
  12. #import "GoogleAnalyst.h"
  13. #endif
  14. #import "ERPUtils.h"
  15. #import "RAConvertor.h"
  16. #import "ActiveViewController.h"
  17. #import "ZipArchive.h"
  18. #import "RADataProvider.h"
  19. NSString *const kScreenName = @"kScreenName";
  20. NSString *const kAction = @"kAction";
  21. NSString *const kExtra = @"kExtra";
  22. NSString *const ScreenCodeLoginView = @"Login Screen";
  23. NSString *const ScreenCodeHomeView = @"Home Screen";
  24. NSString *const ScreenCodeCategory = @"Category Screen";
  25. NSString *const ScreenCodeCart = @"Cart Sceen";
  26. NSString *const ScreenCodeOrderList = @"Order History Screen";
  27. NSString *const ScreenCodeSearch = @"Search Screen";
  28. NSString *const ScreenCodeAccount = @"Account Screen";
  29. NSString *const ScreenCodeWishList = @"Wish List Screen";
  30. NSString *const ScreenCodePortfolio = @"Portfolio Screen";
  31. NSString *const ScreenCodeViewPortfolios = @"View Portfolios Screen";
  32. NSString *const ScreenCodeCamScan = @"Cam Scan Screen";
  33. NSString *const ScreenCodeScannerSetting = @"Scanner Setting Screen";
  34. NSString *const ScreenCodeOfflineSetting = @"Offline Setting Screen";
  35. NSString *const ScreenCodePlaceOrder = @"Place Order Screen";
  36. NSString *const ScreenCodeCustomerInfo = @"Customer Information Screen";
  37. NSString *const ScreenCodeNewCustomer = @"New Customer Screen";
  38. NSString *const ScreenCodeEditCustomer = @"Edit Customer Information Screen";
  39. NSString *const ScreenCodeModelInfo = @"Model Information Screen";
  40. NSString *const ScreenCodeOrderInfo = @"Order Information Screeen";
  41. NSString *const ScreenCodeUserSign = @"User Sign Screen";
  42. NSString *const ScreenCodeNewAddress = @"New Address Screen";
  43. NSString *const ScreenCodeAdvanceSearch = @"Account Advance Search Screen";
  44. NSString *const ScreenCodeCreatePortfolio = @"Create Portfolio Screen";
  45. NSString *const ScreenCodeParticularCategory = @"Particular Category Screen";
  46. NSString *const ScreenCodeEditPortfolio = @"Edit Portfolio Screen";
  47. NSString *const ScreenCodePriceSetting = @"Price Setting Screen";
  48. NSString *const ScreenCodeCategoryPrice = @"Category Price Screen";
  49. NSString *const ScreenCodeSetCatetoryPrice = @"Set Category Price Screen";
  50. NSString *const ScreenCodeUploadImage = @"Upload Image Screen";
  51. NSString *const ScreenCodeOfflineSync = @"Offline Sync Screen";
  52. @implementation RANetwork
  53. +(NSMutableDictionary*) prepare_additional_params:(NSMutableDictionary* ) params
  54. {
  55. AppDelegate *appDelegate = nil;
  56. //some UI methods ej
  57. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  58. // if(appDelegate.user!=nil)
  59. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.user key:@"usai"] forKey:@"user"];
  60. // if(appDelegate.password!=nil)
  61. // [params setValue:[AESCrypt AES128Encrypt:appDelegate.password key:@"usai"] forKey:@"password"];
  62. //
  63. //
  64. //
  65. // if(appDelegate.user!=nil)
  66. // [params setValue:appDelegate.user forKey:@"user"];
  67. //
  68. // if(appDelegate.contact_id!=nil)
  69. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  70. // if(appDelegate.password!=nil)
  71. // [params setValue:appDelegate.password forKey:@"password"];
  72. //
  73. // [params setValue:appDelegate.build forKey:@"app_ver"];
  74. //
  75. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  76. // NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  77. // [params setValue:short_version forKey:@"app_short_ver"];
  78. //
  79. //
  80. //
  81. //#if TARGET_IPHONE_SIMULATOR//模拟器
  82. // [params setValue:@"simulator_uuid" forKey:@"deviceid"];
  83. //#elif TARGET_OS_IPHONE//真机
  84. // UIDevice * dev = [UIDevice currentDevice];
  85. // NSUUID* uuid =dev.identifierForVendor;
  86. // [params setValue:uuid.UUIDString forKey:@"deviceid"];
  87. //#endif
  88. if(RASingleton.sharedInstance.duid!=nil && params[@"udid"]==nil)
  89. params[@"udid"]=RASingleton.sharedInstance.duid;
  90. # ifdef DEBUG
  91. [params setValue:@"true" forKey:@"is_debug"];
  92. # endif
  93. if(appDelegate.user!=nil && params[@"user"]==nil)
  94. [params setValue:appDelegate.user forKey:@"user"];
  95. if(appDelegate.password!=nil&& params[@"password"]==nil)
  96. [params setValue:appDelegate.password forKey:@"password"];
  97. if(appDelegate.ipad_perm!=nil)
  98. [params setValue:appDelegate.ipad_perm forKey:@"ipad_perm"];
  99. [params setValue:appDelegate.build forKey:@"app_ver"];
  100. NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  101. NSString* short_version =[infoDict objectForKey:@"CFBundleShortVersionString"];
  102. [params setValue:short_version forKey:@"app_short_ver"];
  103. #if TARGET_IPHONE_SIMULATOR//模拟器
  104. [params setValue:@"simulator_uuid" forKey:@"idfv"];
  105. #elif TARGET_OS_IPHONE//真机
  106. UIDevice * dev = [UIDevice currentDevice];
  107. NSUUID* uuid =dev.identifierForVendor;
  108. [params setValue:uuid.UUIDString forKey:@"idfv"];
  109. #endif
  110. //
  111. // NSString *userAction = [params valueForKey:kAction];
  112. // NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  113. // if ([userAction isEqualToString:@"Login"]) {
  114. // if (!extra) {
  115. // extra = [NSMutableDictionary dictionary];
  116. // }
  117. // [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  118. // }
  119. return params;
  120. }
  121. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params file:(NSString *) file //delegate:(id < NSURLConnectionDelegate >)delegate
  122. {
  123. // NSString* e=[AESCrypt AES128Encrypt:@"密码学中的高级加密标准(Advanced Encryption Standard,AES),又称 高级加密标准Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用。经过五年的甄选流程,高级加密标准由美国国家标准与技术研究院 (NIST)于2001年11月26日发布于FIPS PUB 197,并在2002年5月26日成为有效的标准。2006年,高级加密标准已然成为对称密钥加密中最流行的算法之一。 " key:@"usai2010"];
  124. // DebugLog(e);
  125. // NSString* d=[AESCrypt decrypt:@"VzB4+lENfbzWX7ggHh2Os1P69l5YBzKmM51yqA37AfoKgPY8bJgdK8M4WvF+wDyOsLWP\/o8H5+bHMivQp1u8wM2QV7SYzgzPwV85QKtYWIzEgLe9T0HO69EdutWz7k1rdAT\/mftsRin0Hy5SHk7txTZT\/zPH5X+FQiExCTFm5Zus39HYvp+VxCX4+kYeymn8B63AUd3mRQyscUvDjfgU2olKR\/TP8PV3g+VQMZxpKfol3P1iOtz3XQlHZV0pM6SAf+SwT0sPfrdn6CZFfNQlrKA9QjMrnBdMeSCquSIWXnmLv6okzvnlJnT0SjvJuUeqNdBC5EZ0ACnhI0MrXVZEsq1EuM9al7oPzvU5EZbjZpmx+fSFIkMzTT8bYClTnG1bsL1MCcU4pSODDorUj8zalA==" password:@"usai2010"];
  126. params = [self prepare_additional_params:params];
  127. DebugLog(@"\n++++++++++++++++++++++Request++++++++++++++++++++++\n%@\n++++++++++++++++++++++Params++++++++++++++++++++++\n%@\n",url,[RAConvertor dict2string:params]);
  128. return [super get_json:url parameters:params file:(NSString*)file err_recorder:URL_ERR_LOG result_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  129. int result=[[jsobj valueForKey:@"result"] intValue];
  130. // UIApplication * app = [UIApplication sharedApplication];
  131. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  132. switch (result) {
  133. case 0:
  134. [jsobj setValue:MSG_USERAUTH_ERROR forKey:@"err_msg"];
  135. break;
  136. case 1:
  137. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  138. break;
  139. case 2:
  140. [jsobj setValue:MSG_SUCCESS forKey:@"err_msg"];
  141. break;
  142. case 8:
  143. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  144. break;
  145. case 9:
  146. [jsobj setValue:[jsobj valueForKey:@"msg"] forKey:@"err_msg"];
  147. break;
  148. case 99:
  149. [jsobj setValue:MSG_TIMEOUT forKey:@"err_msg"];
  150. break;
  151. default:
  152. [jsobj setValue:MSG_ERROR forKey:@"err_msg"];
  153. break;
  154. }
  155. // if([appDelegate.build intValue]< [[jsobj valueForKey:@"min_ver"]intValue])
  156. // {
  157. // [jsobj setValue:@"9" forKey:@"result"];
  158. // [jsobj setValue:MSG_VER_LOW forKey:@"err_msg"];
  159. // }
  160. return jsobj;
  161. } decrypt_handler:^NSMutableDictionary *(NSMutableDictionary *jsobj) {
  162. return nil;
  163. // NSString* base64str = jsobj[@"str"];
  164. // NSString* decryptstr=[AESCrypt AES128Decrypt:base64str key:@"usai2010"];
  165. // jsobj=[[RAUtils string2dict:decryptstr] mutableCopy];
  166. // return jsobj;
  167. }];
  168. /*
  169. */
  170. return nil;
  171. }
  172. +(void) LoadImage:(NSString*) url into:(UIImageView*) container
  173. {
  174. DebugLog(@"LoadImage:(NSString*) url in:(UIImageView*) container");
  175. NSString* file_name=[url lastPathComponent];
  176. NSData* img_data = [iSalesDB load_cached_img:file_name loadFrom:url];
  177. if(img_data==nil)
  178. {
  179. DebugLog(@"IMG NOT CACHED %@",file_name);
  180. img_data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
  181. [iSalesDB cache_img:img_data filename:file_name saveTo:url];
  182. //load from internet;
  183. }
  184. if(img_data!=nil)
  185. {
  186. UIImage * img =[UIImage imageWithData:img_data];
  187. if(img==nil)
  188. DebugLog(@"UIIMAGE IS NIL! %@",file_name);
  189. else
  190. dispatch_async(dispatch_get_main_queue(), ^{
  191. container.image =img;
  192. });
  193. }
  194. else
  195. {
  196. DebugLog(@"IMG DOWNLOAD FAILED! %@",file_name);
  197. }
  198. }
  199. //+(NSData*)fake_json:(NSString*) url
  200. //{
  201. // NSString* jsonfile = nil;
  202. // if([url isEqualToString:URL_UPDATE_AUTH])
  203. // {
  204. // jsonfile=@"login";
  205. //
  206. // }
  207. // else if([url isEqualToString:URL_REQUEST_CATMENU])
  208. // {
  209. // jsonfile=@"categorymenu";
  210. // }
  211. // else if([url isEqualToString:URL_LOAD_HOME])
  212. // {
  213. // jsonfile=@"homepage";
  214. // }
  215. // else if([url isEqualToString:URL_SEARCH])
  216. // {
  217. // jsonfile=@"search";
  218. // }
  219. // else if([url isEqualToString:URL_CATEGORY_LOADMORE])
  220. // {
  221. // jsonfile=@"category_more";
  222. // }else if([url isEqualToString:URL_ITEM_DETAIL])
  223. // {
  224. // jsonfile=@"detail";
  225. // }else if([url isEqualToString:URL_CART])
  226. // {
  227. // jsonfile=@"cart";
  228. // }else if([url isEqualToString:URL_ORDER_LIST])
  229. // {
  230. // jsonfile=@"orderlist";
  231. // }
  232. //// else if([url isEqualToString:URL_ORDER_INFO])
  233. //// {
  234. //// jsonfile=@"orderinfo";
  235. //// }
  236. //// else if([url isEqualToString:URL_ORDER_INFO])
  237. //// {
  238. //// jsonfile=@"orderinfo2label";
  239. //// }
  240. //
  241. //
  242. //
  243. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:jsonfile ofType:@"json" ]];
  244. // NSMutableString *result = [[NSMutableString alloc] initWithData:json encoding:NSUTF8StringEncoding];
  245. //
  246. // DebugLog(@"result: \n%@",result);
  247. // return json;
  248. //}
  249. +(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
  250. {
  251. NSString *userAction = [params valueForKey:kAction];
  252. NSMutableDictionary *extra = [[params valueForKey:kExtra] mutableCopy];
  253. if ([userAction isEqualToString:@"Login"]) {
  254. if (!extra) {
  255. extra = [NSMutableDictionary dictionary];
  256. }
  257. [extra setObject:[params objectForKey:@"user"] forKey:@"user"];
  258. }
  259. #if defined(BUILD_NPD) || defined(BUILD_USAI) || defined(BUILD_UWAVER)
  260. NSString *screenName = [params valueForKey:kScreenName];
  261. [ERPUtils googleAnalyticsSendRequestString:url WithScreen:screenName Action:userAction Extra:extra];
  262. #endif
  263. return [self get_json:url parameters:params file:nil];
  264. }
  265. //+(NSDictionary*)request_Editor:(NSString*) sourceid editor:(NSString*)editor
  266. //{
  267. //
  268. //}
  269. +(NSDictionary*) delete_portfoliolist:(NSString* ) listid
  270. {
  271. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  272. __block AppDelegate *appDelegate = nil;
  273. dispatch_sync(dispatch_get_main_queue(), ^{
  274. //some UI methods ej
  275. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  276. });
  277. if(appDelegate.user!=nil)
  278. [params setValue:appDelegate.user forKey:@"user"];
  279. if(appDelegate.contact_id!=nil)
  280. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  281. if(appDelegate.password!=nil)
  282. [params setValue:appDelegate.password forKey:@"password"];
  283. [params setValue:listid forKey:@"tearsheetsId"];
  284. // [params setValue:editor forKey:@"editor"];
  285. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  286. // [params setValue:@"Delete Portfolio" forKey:kAction];
  287. NSData* json = nil;
  288. if(appDelegate.offline_mode)
  289. {
  290. json = [OLDataProvider offline_removePDF:params];
  291. } else {
  292. if(![self IsNetworkAvailable])
  293. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  294. json=[self get_json:URL_PORTFOLIOLIST_REMOVE parameters:params];
  295. }
  296. if(json!=nil)
  297. {
  298. NSError *error=nil;
  299. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  300. return jsobj;
  301. }
  302. else
  303. return nil;
  304. }
  305. +(NSDictionary*) portfolio_remove:(NSString* ) item_ids
  306. {
  307. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  308. __block AppDelegate *appDelegate = nil;
  309. dispatch_sync(dispatch_get_main_queue(), ^{
  310. //some UI methods ej
  311. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  312. });
  313. if(appDelegate.user!=nil)
  314. [params setValue:appDelegate.user forKey:@"user"];
  315. if(appDelegate.contact_id!=nil)
  316. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  317. if(appDelegate.password!=nil)
  318. [params setValue:appDelegate.password forKey:@"password"];
  319. [params setValue:item_ids forKey:@"portfolioId"];
  320. // [params setValue:editor forKey:@"editor"];
  321. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  322. NSData* json = nil;
  323. if(appDelegate.offline_mode)
  324. {
  325. json = [OLDataProvider offline_removePortfolio:params];
  326. } else {
  327. if(![self IsNetworkAvailable])
  328. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  329. json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  330. }
  331. if(json!=nil)
  332. {
  333. NSError *error=nil;
  334. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  335. int result = [[jsobj valueForKey:@"result"] intValue];
  336. if (result==2)
  337. {
  338. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  339. [appDelegate update_count_mark];
  340. }
  341. return jsobj;
  342. }
  343. else
  344. return nil;
  345. }
  346. //+(NSDictionary*) watchlist_remove:(NSString* ) item_ids
  347. //{
  348. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  349. // __block AppDelegate *appDelegate = nil;
  350. //
  351. // dispatch_sync(dispatch_get_main_queue(), ^{
  352. // //some UI methods ej
  353. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  354. // });
  355. // if(appDelegate.user!=nil)
  356. // [params setValue:appDelegate.user forKey:@"user"];
  357. // if(appDelegate.contact_id!=nil)
  358. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  359. // if(appDelegate.password!=nil)
  360. // [params setValue:appDelegate.password forKey:@"password"];
  361. // [params setValue:item_ids forKey:@"collectId"];
  362. // // [params setValue:editor forKey:@"editor"];
  363. //
  364. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  365. //
  366. // if(appDelegate.offline_mode)
  367. // {
  368. // return [OLDataProvider offline_deletewishlist:params];
  369. // }
  370. // if(![self IsNetworkAvailable])
  371. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  372. //
  373. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  374. // if(json!=nil)
  375. // {
  376. // NSError *error=nil;
  377. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  378. // int result = [[jsobj valueForKey:@"result"] intValue];
  379. //
  380. // if (result==2)
  381. // {
  382. //
  383. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  384. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  385. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  386. //
  387. // [appDelegate update_count_mark];
  388. // }
  389. // return jsobj;
  390. // }
  391. // else
  392. // return nil;
  393. //}
  394. //+(NSDictionary*) move_cart2wish:(NSString* ) item_ids
  395. //{
  396. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  397. // __block AppDelegate *appDelegate = nil;
  398. //
  399. // dispatch_sync(dispatch_get_main_queue(), ^{
  400. // //some UI methods ej
  401. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  402. // });
  403. // if(appDelegate.user!=nil)
  404. // [params setValue:appDelegate.user forKey:@"user"];
  405. // if(appDelegate.contact_id!=nil)
  406. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  407. // if(appDelegate.password!=nil)
  408. // [params setValue:appDelegate.password forKey:@"password"];
  409. // if(appDelegate.order_code!=nil)
  410. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  411. // [params setValue:item_ids forKey:@"cartItemId"];
  412. // // [params setValue:editor forKey:@"editor"];
  413. //
  414. // [params setValue:ScreenCodeCart forKey:kScreenName];
  415. // // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  416. //
  417. // NSData* json = nil;
  418. // if(appDelegate.offline_mode)
  419. // {
  420. // json= [OLDataProvider offline_movecart2wish:params];
  421. // }
  422. // else
  423. // {
  424. // if(![self IsNetworkAvailable])
  425. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  426. //
  427. // json=[self get_json:URL_CART2WISH parameters:params];
  428. // }
  429. // if(json!=nil)
  430. // {
  431. // NSError *error=nil;
  432. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  433. // int result = [[jsobj valueForKey:@"result"] intValue];
  434. //
  435. // if (result==2)
  436. // {
  437. //
  438. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  439. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  440. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  441. //
  442. // [appDelegate update_count_mark];
  443. // }
  444. // return jsobj;
  445. // }
  446. // else
  447. // return nil;
  448. //}
  449. //+(NSDictionary*) move_wish2cart:(NSString* ) item_ids
  450. //{
  451. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  452. // __block AppDelegate *appDelegate = nil;
  453. //
  454. // dispatch_sync(dispatch_get_main_queue(), ^{
  455. // //some UI methods ej
  456. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  457. // });
  458. // if(appDelegate.user!=nil)
  459. // [params setValue:appDelegate.user forKey:@"user"];
  460. // if(appDelegate.contact_id!=nil)
  461. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  462. // if(appDelegate.password!=nil)
  463. // [params setValue:appDelegate.password forKey:@"password"];
  464. // if(appDelegate.order_code!=nil)
  465. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  466. // [params setValue:item_ids forKey:@"collectId"];
  467. // // [params setValue:editor forKey:@"editor"];
  468. //
  469. // [params setValue:ScreenCodeWishList forKey:kScreenName];
  470. // [params setValue:@"Move To Cart" forKey:kAction];
  471. //
  472. // NSData *json = nil;
  473. // if(appDelegate.offline_mode)
  474. // {
  475. // json = [OLDataProvider offline_movewish2cart:params];
  476. // } else {
  477. // if(![self IsNetworkAvailable])
  478. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  479. //
  480. // json=[self get_json:URL_WISH2CART parameters:params];
  481. // }
  482. //
  483. // if(json!=nil)
  484. // {
  485. // NSError *error=nil;
  486. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  487. // int result = [[jsobj valueForKey:@"result"] intValue];
  488. //
  489. // if (result==2)
  490. // {
  491. //
  492. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  493. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  494. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  495. //
  496. // [appDelegate update_count_mark];
  497. // }
  498. // return jsobj;
  499. // }
  500. // else
  501. // return nil;
  502. //}
  503. //+(NSDictionary*) cart_remove:(NSString* ) item_ids
  504. //{
  505. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  506. // __block AppDelegate *appDelegate = nil;
  507. //
  508. // dispatch_sync(dispatch_get_main_queue(), ^{
  509. // //some UI methods ej
  510. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  511. // });
  512. // if(appDelegate.user!=nil)
  513. // [params setValue:appDelegate.user forKey:@"user"];
  514. // if(appDelegate.contact_id!=nil)
  515. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  516. // if(appDelegate.password!=nil)
  517. // [params setValue:appDelegate.password forKey:@"password"];
  518. //
  519. // if(appDelegate.order_code!=nil)
  520. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  521. // [params setValue:item_ids forKey:@"cartItemId"];
  522. // // [params setValue:editor forKey:@"editor"];
  523. //
  524. // [params setValue:ScreenCodeCart forKey:kScreenName];
  525. // // [params setValue:@"" forKey:kAction];
  526. //
  527. // NSData* json=nil;
  528. // if(appDelegate.offline_mode)
  529. // {
  530. // json= [OLDataProvider offline_cartremove:params];
  531. // }
  532. // else
  533. // {
  534. // if(![self IsNetworkAvailable])
  535. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  536. //
  537. // json=[self get_json:URL_CART_REMOVE parameters:params];
  538. // }
  539. // if(json!=nil)
  540. // {
  541. // NSError *error=nil;
  542. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  543. //
  544. // int result = [[jsobj valueForKey:@"result"] intValue];
  545. //
  546. // if (result==2)
  547. // {
  548. //
  549. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  550. //
  551. //
  552. // [appDelegate update_count_mark];
  553. // }
  554. // return jsobj;
  555. // }
  556. // else
  557. // return nil;
  558. //}
  559. //+(NSDictionary*) cart_check:(NSString* ) item_ids
  560. //{
  561. // return nil;
  562. // if(![self IsNetworkAvailable])
  563. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  564. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  565. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  566. // if(appDelegate.user!=nil)
  567. // [params setValue:appDelegate.user forKey:@"user"];
  568. // if(appDelegate.contact_id!=nil)
  569. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  570. // if(appDelegate.password!=nil)
  571. // [params setValue:appDelegate.password forKey:@"password"];
  572. // [params setValue:item_ids forKey:@"cartItemId"];
  573. // // [params setValue:editor forKey:@"editor"];
  574. // if(appDelegate.offline_mode)
  575. // {
  576. // return [OLDataProvider offline_notimpl];
  577. // }
  578. // NSData* json=[self get_json:URL_CART_CHECK parameters:params];
  579. // if(json!=nil)
  580. // {
  581. // NSError *error=nil;
  582. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  583. // return jsobj;
  584. // }
  585. // else
  586. // return nil;
  587. //}
  588. +(NSDictionary*)create_Address:(NSMutableDictionary*)params
  589. {
  590. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  591. __block AppDelegate *appDelegate = nil;
  592. dispatch_sync(dispatch_get_main_queue(), ^{
  593. //some UI methods ej
  594. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  595. });
  596. if(appDelegate.user!=nil)
  597. [params setValue:appDelegate.user forKey:@"user"];
  598. if(appDelegate.contact_id!=nil)
  599. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  600. if(appDelegate.password!=nil)
  601. [params setValue:appDelegate.password forKey:@"password"];
  602. // [params setValue:sourceid forKey:@"sourceid"];
  603. // [params setValue:editor forKey:@"editor"];
  604. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  605. NSData* json=nil;
  606. if(appDelegate.offline_mode)
  607. {
  608. json= [OLDataProvider offline_saveaddr:params];
  609. }
  610. else
  611. {
  612. if(![self IsNetworkAvailable])
  613. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  614. json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  615. }
  616. if(json!=nil)
  617. {
  618. NSError *error=nil;
  619. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  620. return jsobj;
  621. }
  622. else
  623. return nil;
  624. }
  625. +(NSDictionary*)copy_Order:(NSString*) order_code
  626. {
  627. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  628. __block AppDelegate *appDelegate = nil;
  629. dispatch_sync(dispatch_get_main_queue(), ^{
  630. //some UI methods ej
  631. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  632. });
  633. if(appDelegate.user!=nil)
  634. [params setValue:appDelegate.user forKey:@"user"];
  635. if(appDelegate.contact_id!=nil)
  636. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  637. if(appDelegate.password!=nil)
  638. [params setValue:appDelegate.password forKey:@"password"];
  639. // NSString* ssaved = @"false";
  640. // if(saved)
  641. // ssaved=@"true";
  642. // [params setValue:@"true" forKey:@"saved"];
  643. [params setValue:order_code forKey:@"code"];
  644. // [params setValue:sourceid forKey:@"sourceid"];
  645. // [params setValue:editor forKey:@"editor"];
  646. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  647. NSData* json=nil;
  648. if(appDelegate.offline_mode)
  649. {
  650. json= [OLDataProvider offline_copyorder:params];
  651. }
  652. else
  653. {
  654. if(![self IsNetworkAvailable])
  655. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  656. json=[self get_json:URL_COPY_ORDER parameters:params];
  657. }
  658. if(json!=nil)
  659. {
  660. NSError *error=nil;
  661. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  662. return jsobj;
  663. }
  664. else
  665. return nil;
  666. }
  667. +(NSDictionary*)sign_Order:(NSString*) order_code path:(NSString*)path
  668. {
  669. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  670. __block AppDelegate *appDelegate = nil;
  671. dispatch_sync(dispatch_get_main_queue(), ^{
  672. //some UI methods ej
  673. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  674. });
  675. if(appDelegate.user!=nil)
  676. [params setValue:appDelegate.user forKey:@"user"];
  677. if(appDelegate.contact_id!=nil)
  678. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  679. if(appDelegate.password!=nil)
  680. [params setValue:appDelegate.password forKey:@"password"];
  681. // NSString* ssaved = @"false";
  682. // if(saved)
  683. // ssaved=@"true";
  684. // [params setValue:@"true" forKey:@"saved"];
  685. [params setValue:order_code forKey:@"orderCode"];
  686. [params setValue:path forKey:@"picpath"];
  687. // [params setValue:sourceid forKey:@"sourceid"];
  688. // [params setValue:editor forKey:@"editor"];
  689. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  690. NSData* json=nil;
  691. if(appDelegate.offline_mode)
  692. {
  693. json= [OLDataProvider offline_signorder:params];
  694. }
  695. else
  696. {
  697. if(![self IsNetworkAvailable])
  698. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  699. json=[self get_json:URL_SIGN_ORDER parameters:params];
  700. }
  701. if(json!=nil)
  702. {
  703. NSError *error=nil;
  704. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  705. return jsobj;
  706. }
  707. else
  708. return nil;
  709. }
  710. +(NSDictionary*)commit_Order:(NSString*) order_code //saved:(bool) saved
  711. {
  712. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  713. __block AppDelegate *appDelegate = nil;
  714. dispatch_sync(dispatch_get_main_queue(), ^{
  715. //some UI methods ej
  716. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  717. });
  718. if(appDelegate.user!=nil)
  719. [params setValue:appDelegate.user forKey:@"user"];
  720. if(appDelegate.contact_id!=nil)
  721. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  722. if(appDelegate.password!=nil)
  723. [params setValue:appDelegate.password forKey:@"password"];
  724. // NSString* ssaved = @"false";
  725. // if(saved)
  726. // ssaved=@"true";
  727. [params setValue:@"true" forKey:@"saved"];
  728. [params setValue:order_code forKey:@"orderCode"];
  729. // [params setValue:sourceid forKey:@"sourceid"];
  730. // [params setValue:editor forKey:@"editor"];
  731. [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  732. NSData* json = nil;
  733. if(appDelegate.offline_mode)
  734. {
  735. json= [OLDataProvider offline_submitorder:params];
  736. }
  737. else
  738. {
  739. if(![self IsNetworkAvailable])
  740. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  741. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  742. }
  743. if(json!=nil)
  744. {
  745. NSError *error=nil;
  746. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  747. return jsobj;
  748. }
  749. else
  750. return nil;
  751. }
  752. //+(NSDictionary*)open_Order:(NSString*) order_code
  753. //{
  754. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  755. // __block AppDelegate *appDelegate = nil;
  756. //
  757. // dispatch_sync(dispatch_get_main_queue(), ^{
  758. // //some UI methods ej
  759. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  760. // });
  761. // if(appDelegate.user!=nil)
  762. // [params setValue:appDelegate.user forKey:@"user"];
  763. // // if(appDelegate.contact_id!=nil)
  764. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  765. // if(appDelegate.password!=nil)
  766. // [params setValue:appDelegate.password forKey:@"password"];
  767. //
  768. // [params setValue:order_code forKey:@"orderCode"];
  769. // // [params setValue:sourceid forKey:@"sourceid"];
  770. // // [params setValue:editor forKey:@"editor"];
  771. //
  772. // [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  773. //
  774. // NSData* json=nil;
  775. // if(appDelegate.offline_mode)
  776. // {
  777. // json=[OLDataProvider offline_editorder:params];
  778. //
  779. // }
  780. // else
  781. // {
  782. // if(![self IsNetworkAvailable])
  783. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  784. //
  785. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  786. // }
  787. // if(json!=nil)
  788. // {
  789. // NSError *error=nil;
  790. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  791. // int result = [[jsobj valueForKey:@"result"] intValue];
  792. //
  793. // if (result==2)
  794. // {
  795. //
  796. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  797. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  798. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  799. //
  800. // [appDelegate update_count_mark];
  801. //
  802. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  803. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  804. // }
  805. //
  806. // }
  807. //
  808. // return jsobj;
  809. // }
  810. // else
  811. // return nil;
  812. //}
  813. +(NSDictionary*)delete_Order:(NSString*) order_id
  814. {
  815. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  816. __block AppDelegate *appDelegate = nil;
  817. dispatch_sync(dispatch_get_main_queue(), ^{
  818. //some UI methods ej
  819. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  820. });
  821. if(appDelegate.user!=nil)
  822. [params setValue:appDelegate.user forKey:@"user"];
  823. // if(appDelegate.contact_id!=nil)
  824. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  825. if(appDelegate.password!=nil)
  826. [params setValue:appDelegate.password forKey:@"password"];
  827. [params setValue:order_id forKey:@"orderId"];
  828. // [params setValue:sourceid forKey:@"sourceid"];
  829. // [params setValue:editor forKey:@"editor"];
  830. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  831. if(appDelegate.offline_mode)
  832. {
  833. return [OLDataProvider offline_notimpl];
  834. }
  835. if(![self IsNetworkAvailable])
  836. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  837. NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  838. if(json!=nil)
  839. {
  840. NSError *error=nil;
  841. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  842. return jsobj;
  843. }
  844. else
  845. return nil;
  846. }
  847. +(NSDictionary*)cancel_Order:(NSString*) order_id order_code:(NSString*) order_code
  848. {
  849. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  850. __block AppDelegate *appDelegate = nil;
  851. dispatch_sync(dispatch_get_main_queue(), ^{
  852. //some UI methods ej
  853. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  854. });
  855. if(appDelegate.user!=nil)
  856. [params setValue:appDelegate.user forKey:@"user"];
  857. // if(appDelegate.contact_id!=nil)
  858. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  859. if(appDelegate.password!=nil)
  860. [params setValue:appDelegate.password forKey:@"password"];
  861. [params setValue:order_id forKey:@"orderId"];
  862. [params setValue:order_code forKey:@"orderCode"];
  863. // [params setValue:sourceid forKey:@"sourceid"];
  864. // [params setValue:editor forKey:@"editor"];
  865. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  866. NSData* json=nil;
  867. if(appDelegate.offline_mode)
  868. {
  869. json=[OLDataProvider offline_cancelorder:params];
  870. }
  871. else
  872. {
  873. if(![self IsNetworkAvailable])
  874. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  875. json=[self get_json:URL_CANCEL_ORDER parameters:params];
  876. }
  877. if(json!=nil)
  878. {
  879. NSError *error=nil;
  880. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  881. return jsobj;
  882. }
  883. else
  884. return nil;
  885. }
  886. +(NSDictionary*)release_Order:(NSString*) order_code withScreen:(NSString *)screenName
  887. {
  888. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  889. __block AppDelegate *appDelegate = nil;
  890. dispatch_sync(dispatch_get_main_queue(), ^{
  891. //some UI methods ej
  892. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  893. });
  894. if(appDelegate.user!=nil)
  895. [params setValue:appDelegate.user forKey:@"user"];
  896. // if(appDelegate.contact_id!=nil)
  897. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  898. if(appDelegate.password!=nil)
  899. [params setValue:appDelegate.password forKey:@"password"];
  900. [params setValue:order_code forKey:@"orderCode"];
  901. // [params setValue:sourceid forKey:@"sourceid"];
  902. // [params setValue:editor forKey:@"editor"];
  903. if (screenName) {
  904. [params setValue:screenName forKey:kScreenName];
  905. }
  906. NSData* json=nil;
  907. if(appDelegate.offline_mode)
  908. {
  909. json= [OLDataProvider offline_resetorder:params];
  910. }
  911. else
  912. {
  913. if(![self IsNetworkAvailable])
  914. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  915. json=[self get_json:URL_RELEASE_ORDER parameters:params];
  916. }
  917. if(json!=nil)
  918. {
  919. NSError *error=nil;
  920. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  921. if([[jsobj valueForKey:@"result"]intValue]==2)
  922. { [appDelegate SetSo:nil];
  923. appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  924. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  925. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  926. [appDelegate update_count_mark];
  927. }
  928. return jsobj;
  929. }
  930. else
  931. return nil;
  932. }
  933. +(NSDictionary*)update_OrderCustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info
  934. {
  935. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  936. __block AppDelegate *appDelegate = nil;
  937. dispatch_sync(dispatch_get_main_queue(), ^{
  938. //some UI methods ej
  939. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  940. });
  941. if(appDelegate.user!=nil)
  942. [info setValue:appDelegate.user forKey:@"user"];
  943. // if(appDelegate.contact_id!=nil)
  944. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  945. if(appDelegate.password!=nil)
  946. [info setValue:appDelegate.password forKey:@"password"];
  947. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  948. [info setValue:order_code forKey:@"orderCode"];
  949. // [params setValue:sourceid forKey:@"sourceid"];
  950. // [params setValue:editor forKey:@"editor"];
  951. if(appDelegate.offline_mode)
  952. {
  953. return [OLDataProvider offline_notimpl];
  954. }
  955. if(![self IsNetworkAvailable])
  956. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  957. NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  958. if(json!=nil)
  959. {
  960. NSError *error=nil;
  961. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  962. return jsobj;
  963. }
  964. else
  965. return nil;
  966. }
  967. //+(NSDictionary*)commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url
  968. //{
  969. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  970. // __block AppDelegate *appDelegate = nil;
  971. //
  972. // dispatch_sync(dispatch_get_main_queue(), ^{
  973. // //some UI methods ej
  974. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  975. // });
  976. // if(appDelegate.user!=nil)
  977. // [params setValue:appDelegate.user forKey:@"user"];
  978. // if(appDelegate.contact_id!=nil)
  979. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  980. // if(appDelegate.password!=nil)
  981. // [params setValue:appDelegate.password forKey:@"password"];
  982. //
  983. // // if(appDelegate.order_code!=nil)
  984. // // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  985. //
  986. // // NSDictionary* customerinfo= appDelegate.customerInfo;
  987. // //
  988. // // NSArray* keys=[customerinfo allKeys];
  989. // // for(int i=0;i<keys.count;i++)
  990. // // {
  991. // // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  992. // // }
  993. // //
  994. // // [params setValue:sourceid forKey:@"sourceid"];
  995. // // [params setValue:editor forKey:@"editor"];
  996. //
  997. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  998. //
  999. // if(appDelegate.offline_mode)
  1000. // {
  1001. // params[@"offline_Command"]=url;
  1002. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  1003. // }
  1004. //
  1005. // if(![self IsNetworkAvailable])
  1006. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1007. //
  1008. // NSData* json=[self get_json:url parameters:params];
  1009. // if(json!=nil)
  1010. // {
  1011. // NSError *error=nil;
  1012. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1013. // if([[jsobj valueForKey:@"result"]intValue]==2)
  1014. // [appDelegate SetSo:nil];
  1015. //
  1016. //
  1017. // return jsobj;
  1018. // }
  1019. // else
  1020. // return nil;
  1021. //}
  1022. +(NSDictionary*)saveandcommit_Order:(NSMutableDictionary*)params
  1023. {
  1024. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1025. __block AppDelegate *appDelegate = nil;
  1026. dispatch_sync(dispatch_get_main_queue(), ^{
  1027. //some UI methods ej
  1028. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1029. });
  1030. if(appDelegate.user!=nil)
  1031. [params setValue:appDelegate.user forKey:@"user"];
  1032. if(appDelegate.contact_id!=nil)
  1033. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1034. if(appDelegate.password!=nil)
  1035. [params setValue:appDelegate.password forKey:@"password"];
  1036. if(appDelegate.order_code!=nil)
  1037. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1038. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1039. //
  1040. // NSArray* keys=[customerinfo allKeys];
  1041. // for(int i=0;i<keys.count;i++)
  1042. // {
  1043. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1044. // }
  1045. //
  1046. // [params setValue:sourceid forKey:@"sourceid"];
  1047. // [params setValue:editor forKey:@"editor"];
  1048. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1049. NSData* json=nil;
  1050. if(appDelegate.offline_mode)
  1051. {
  1052. json=[OLDataProvider offline_submitorder:params];
  1053. }
  1054. else
  1055. {
  1056. if(![self IsNetworkAvailable])
  1057. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1058. json=[self get_json:URL_COMMIT_ORDER parameters:params];
  1059. }
  1060. if(json!=nil)
  1061. {
  1062. NSError *error=nil;
  1063. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1064. if([[jsobj valueForKey:@"result"]intValue]==2)
  1065. [appDelegate SetSo:nil];
  1066. return jsobj;
  1067. }
  1068. else
  1069. return nil;
  1070. }
  1071. +(NSDictionary*)update_Customer:(NSMutableDictionary*)params
  1072. {
  1073. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1074. __block AppDelegate *appDelegate = nil;
  1075. dispatch_sync(dispatch_get_main_queue(), ^{
  1076. //some UI methods ej
  1077. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1078. });
  1079. if(appDelegate.user!=nil)
  1080. [params setValue:appDelegate.user forKey:@"user"];
  1081. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1082. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1083. // else
  1084. if(appDelegate.contact_id!=nil)
  1085. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1086. if(appDelegate.password!=nil)
  1087. [params setValue:appDelegate.password forKey:@"password"];
  1088. // NSDictionary* customerinfo=nil;
  1089. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1090. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1091. // else
  1092. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1093. //
  1094. // appDelegate.customerInfo;
  1095. // NSArray* keys=[customerinfo allKeys];
  1096. // for(int i=0;i<keys.count;i++)
  1097. // {
  1098. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1099. // }
  1100. // [params setValue:sourceid forKey:@"sourceid"];
  1101. // [params setValue:editor forKey:@"editor"];
  1102. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1103. NSData* json=nil;
  1104. if(appDelegate.offline_mode)
  1105. {
  1106. json= [OLDataProvider offline_saveContact:params];
  1107. }
  1108. else
  1109. {
  1110. if(![self IsNetworkAvailable])
  1111. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1112. json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  1113. }
  1114. if(json!=nil)
  1115. {
  1116. NSError *error=nil;
  1117. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1118. return jsobj;
  1119. }
  1120. else
  1121. return nil;
  1122. }
  1123. +(NSDictionary*)save_newCustomer:(NSMutableDictionary*)params
  1124. {
  1125. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1126. __block AppDelegate *appDelegate = nil;
  1127. dispatch_sync(dispatch_get_main_queue(), ^{
  1128. //some UI methods ej
  1129. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1130. });
  1131. if(appDelegate.user!=nil)
  1132. [params setValue:appDelegate.user forKey:@"user"];
  1133. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1134. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1135. // else
  1136. if(appDelegate.contact_id!=nil)
  1137. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1138. if(appDelegate.password!=nil)
  1139. [params setValue:appDelegate.password forKey:@"password"];
  1140. // NSDictionary* customerinfo=nil;
  1141. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1142. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1143. // else
  1144. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1145. //
  1146. // appDelegate.customerInfo;
  1147. // NSArray* keys=[customerinfo allKeys];
  1148. // for(int i=0;i<keys.count;i++)
  1149. // {
  1150. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1151. // }
  1152. // [params setValue:sourceid forKey:@"sourceid"];
  1153. // [params setValue:editor forKey:@"editor"];
  1154. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1155. NSData* json=nil;
  1156. if(appDelegate.offline_mode)
  1157. {
  1158. json= [OLDataProvider offline_saveNewContact:params];
  1159. }
  1160. else
  1161. {
  1162. if(![self IsNetworkAvailable])
  1163. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1164. json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  1165. }
  1166. if(json!=nil)
  1167. {
  1168. NSError *error=nil;
  1169. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1170. return jsobj;
  1171. }
  1172. else
  1173. return nil;
  1174. }
  1175. +(NSDictionary*)save_Order:(NSMutableDictionary*)params
  1176. {
  1177. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1178. __block AppDelegate *appDelegate = nil;
  1179. dispatch_sync(dispatch_get_main_queue(), ^{
  1180. //some UI methods ej
  1181. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1182. });
  1183. if(appDelegate.user!=nil)
  1184. [params setValue:appDelegate.user forKey:@"user"];
  1185. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1186. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1187. // else
  1188. if(appDelegate.contact_id!=nil)
  1189. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1190. if(appDelegate.password!=nil)
  1191. [params setValue:appDelegate.password forKey:@"password"];
  1192. if(appDelegate.order_code!=nil)
  1193. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1194. // NSDictionary* customerinfo=nil;
  1195. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  1196. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1197. // else
  1198. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1199. //
  1200. // appDelegate.customerInfo;
  1201. // NSArray* keys=[customerinfo allKeys];
  1202. // for(int i=0;i<keys.count;i++)
  1203. // {
  1204. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1205. // }
  1206. // [params setValue:sourceid forKey:@"sourceid"];
  1207. // [params setValue:editor forKey:@"editor"];
  1208. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1209. NSData* json=nil;
  1210. if(appDelegate.offline_mode)
  1211. {
  1212. json= [OLDataProvider offline_saveorder:params];
  1213. }
  1214. else
  1215. {
  1216. if(![self IsNetworkAvailable])
  1217. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1218. json=[self get_json:URL_SAVE_ORDER parameters:params];
  1219. }
  1220. if(json!=nil)
  1221. {
  1222. NSError *error=nil;
  1223. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1224. NSString *so = [jsobj valueForKey:@"so#"];
  1225. if (so) {
  1226. [appDelegate SetSo:so];
  1227. }
  1228. return jsobj;
  1229. }
  1230. else
  1231. return nil;
  1232. }
  1233. //+(NSDictionary*)request_Editor:(NSString*) request_url params:(NSMutableDictionary*)params
  1234. //{
  1235. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1236. // __block AppDelegate *appDelegate = nil;
  1237. //
  1238. // dispatch_sync(dispatch_get_main_queue(), ^{
  1239. // //some UI methods ej
  1240. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1241. // });
  1242. // if(appDelegate.user!=nil)
  1243. // [params setValue:appDelegate.user forKey:@"user"];
  1244. //
  1245. //
  1246. // // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1247. // // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1248. // // else
  1249. //
  1250. // if(appDelegate.contact_id!=nil)
  1251. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1252. // if(appDelegate.password!=nil)
  1253. // [params setValue:appDelegate.password forKey:@"password"];
  1254. //
  1255. // if(appDelegate.order_code!=nil)
  1256. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1257. // // [params setValue:sourceid forKey:@"sourceid"];
  1258. // // [params setValue:editor forKey:@"editor"];
  1259. // DebugLog(@"request editor url:%@",request_url);
  1260. //
  1261. //
  1262. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1263. // {
  1264. // [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  1265. // }
  1266. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1267. // {
  1268. // [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  1269. // }
  1270. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1271. // {
  1272. // [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  1273. // }
  1274. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1275. // {
  1276. // [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  1277. // }
  1278. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1279. // {
  1280. // [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  1281. // }
  1282. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1283. // [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  1284. // }
  1285. //
  1286. // NSData* json = nil;
  1287. // if(appDelegate.offline_mode)
  1288. // {
  1289. // if([request_url isEqualToString:URL_NEW_CUSTOMER])
  1290. // {
  1291. // json= [OLDataProvider offline_createContact:params];
  1292. // }
  1293. // else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  1294. // {
  1295. // json= [OLDataProvider offline_editContact:params];
  1296. // }
  1297. // else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  1298. // {
  1299. // json= [OLDataProvider offline_contactAdvancedSearch:params];
  1300. // }
  1301. // else if([request_url isEqualToString:URL_CARTDELIVERY])
  1302. // {
  1303. // json= [OLDataProvider offline_placeorder:params];
  1304. // }
  1305. // else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  1306. // {
  1307. // json= [OLDataProvider offline_addreditor:params];
  1308. // }
  1309. // else if ([request_url isEqualToString:URL_DM_PARAMS]){
  1310. // json = [OLDataProvider offline_createTearSheet:params];
  1311. // }
  1312. //
  1313. // else
  1314. // return [OLDataProvider offline_notimpl];
  1315. // }
  1316. // else
  1317. // {
  1318. // if(![self IsNetworkAvailable])
  1319. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1320. //
  1321. // if([request_url isEqualToString:URL_CARTDELIVERY])
  1322. // {
  1323. // NSError *error=nil;
  1324. //
  1325. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1326. // params[@"resultSerial"]=uuid;
  1327. //
  1328. // for(int i=0;i<150;i++)
  1329. // {
  1330. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1331. // // result_params[@"resultSerial"]=uuid;
  1332. // json=[self get_json:request_url parameters:params];
  1333. // if(json!=nil)
  1334. // {
  1335. //
  1336. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1337. // if([jsobj[@"result"] intValue]==2 || [jsobj[@"result"] intValue] == 8)
  1338. // {
  1339. // break;
  1340. // }
  1341. // }
  1342. // sleep(2);
  1343. // }
  1344. // }
  1345. // else
  1346. // json =[self get_json:request_url parameters:params];
  1347. // }
  1348. // if(json!=nil)
  1349. // {
  1350. // NSError *error=nil;
  1351. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1352. // return jsobj;
  1353. // }
  1354. // else
  1355. // return nil;
  1356. //}
  1357. //+(NSDictionary*)request_OrderInfo:(NSString*) orderid
  1358. //{
  1359. // if(![self IsNetworkAvailable])
  1360. // return nil;
  1361. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1362. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1363. // if(appDelegate.user!=nil)
  1364. // [params setValue:appDelegate.user forKey:@"user"];
  1365. // if(appDelegate.password!=nil)
  1366. // [params setValue:appDelegate.password forKey:@"password"];
  1367. // [params setValue:orderid forKey:@"orderid"];
  1368. // NSData* json=[self get_json:URL_ORDER_INFO parameters:params];
  1369. // NSError *error=nil;
  1370. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1371. // return jsobj;
  1372. //}
  1373. +(NSDictionary*)request_OrderList:(int ) offset limit :(int)limit keywords :(NSString* ) keywords status:(NSString*) status_code customer:(NSString*) customer is_merged:(BOOL) isMerged
  1374. {
  1375. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1376. __block AppDelegate *appDelegate = nil;
  1377. dispatch_sync(dispatch_get_main_queue(), ^{
  1378. //some UI methods ej
  1379. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1380. });
  1381. if(appDelegate.user!=nil)
  1382. [params setValue:appDelegate.user forKey:@"user"];
  1383. if(appDelegate.contact_id!=nil)
  1384. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1385. if(appDelegate.password!=nil)
  1386. [params setValue:appDelegate.password forKey:@"password"];
  1387. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1388. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1389. [params setValue:keywords forKey:@"keyWord"];
  1390. [params setValue:customer forKey:@"customer_filter"];
  1391. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  1392. [params setValue:status_code forKey:@"orderStatus"];
  1393. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1394. if (keywords) {
  1395. [params setObject:@"Search" forKey:kAction];
  1396. }
  1397. NSData* json=nil;
  1398. if(appDelegate.offline_mode)
  1399. {
  1400. json= [OLDataProvider offline_orderlist:params];
  1401. }
  1402. else
  1403. {
  1404. if(![self IsNetworkAvailable])
  1405. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1406. json=[self get_json:URL_ORDER_LIST parameters:params];
  1407. }
  1408. if(json==nil)
  1409. return nil;
  1410. NSError *error=nil;
  1411. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1412. return jsobj;
  1413. }
  1414. +(NSDictionary*)request_PDFList:(int ) offset limit:(int)limit keywords:(NSString* ) keywords
  1415. {
  1416. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1417. __block AppDelegate *appDelegate = nil;
  1418. dispatch_sync(dispatch_get_main_queue(), ^{
  1419. //some UI methods ej
  1420. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1421. });
  1422. if(appDelegate.user!=nil)
  1423. [params setValue:appDelegate.user forKey:@"user"];
  1424. if(appDelegate.contact_id!=nil)
  1425. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1426. if(appDelegate.password!=nil)
  1427. [params setValue:appDelegate.password forKey:@"password"];
  1428. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  1429. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  1430. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  1431. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  1432. // [params setValue:filter forKey:@"filter"];
  1433. [params setValue:keywords forKey:@"keyWord"];
  1434. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  1435. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  1436. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  1437. if (keywords) {
  1438. [params setObject:@"Search" forKey:kAction];
  1439. }
  1440. NSData* json = nil;
  1441. if(appDelegate.offline_mode)
  1442. {
  1443. json = [OLDataProvider offline_pdfList:params];
  1444. } else {
  1445. if(![self IsNetworkAvailable])
  1446. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1447. json=[self get_json:URL_DM_LIST parameters:params];
  1448. }
  1449. if(json==nil)
  1450. return nil;
  1451. NSError *error=nil;
  1452. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1453. return jsobj;
  1454. }
  1455. +(NSDictionary*)err_log:(NSString*) up_params result:(NSString*)result module:(NSString*) module code:(int) code//device:(NSString*) device
  1456. {
  1457. #ifdef ERR_LOG
  1458. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1459. __block AppDelegate *appDelegate = nil;
  1460. dispatch_sync(dispatch_get_main_queue(), ^{
  1461. //some UI methods ej
  1462. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1463. });
  1464. if(appDelegate.user!=nil)
  1465. [params setValue:appDelegate.user forKey:@"user"];
  1466. [params setValue:up_params forKey:@"upparam"];
  1467. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  1468. [params setValue:result forKey:@"result"];
  1469. [params setValue:module forKey:@"interfac"];
  1470. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  1471. // [params setValue:module forKey:@"module"];
  1472. // [[UIDevice currentDevice] name];
  1473. // if(appDelegate.offline_mode)
  1474. // {
  1475. // return [OLDataProvider offline_notimpl];
  1476. // }
  1477. if(![self IsNetworkAvailable])
  1478. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1479. NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  1480. if(json==nil)
  1481. return nil;
  1482. NSError *error=nil;
  1483. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1484. return jsobj;
  1485. #else
  1486. return nil;
  1487. #endif
  1488. }
  1489. //+(NSDictionary*)request_ContactList:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams
  1490. //{
  1491. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1492. //
  1493. // if(upparams!=nil)
  1494. // params = [upparams mutableCopy];
  1495. // __block AppDelegate *appDelegate = nil;
  1496. //
  1497. // dispatch_sync(dispatch_get_main_queue(), ^{
  1498. // //some UI methods ej
  1499. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1500. // });
  1501. // if(appDelegate.user!=nil)
  1502. // [params setValue:appDelegate.user forKey:@"user"];
  1503. //
  1504. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  1505. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  1506. // else
  1507. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1508. //
  1509. // if(appDelegate.password!=nil)
  1510. // [params setValue:appDelegate.password forKey:@"password"];
  1511. //
  1512. // [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  1513. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1514. // [params setValue:contact_type forKey:@"contactType"];
  1515. // [params setValue:keywords forKey:@"keyword"];
  1516. //
  1517. // [params setObject:ScreenCodeAccount forKey:kScreenName];
  1518. // if (keywords) {
  1519. // [params setObject:@"Search" forKey:kAction];
  1520. // }
  1521. // if (upparams) {
  1522. // [params setObject:@"Advance Search" forKey:kAction];
  1523. // }
  1524. //
  1525. // NSString* url=nil;
  1526. // if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  1527. // url=URL_SHIPTO_LIST;
  1528. // else
  1529. // url=URL_CONTACT_LIST;
  1530. //
  1531. // if(appDelegate.offline_mode)
  1532. // return [OLDataProvider offline_contactlist:params];
  1533. //
  1534. // if(![self IsNetworkAvailable])
  1535. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1536. //
  1537. // NSData* json=[self get_json:url parameters:params];
  1538. // if(json==nil)
  1539. // return nil;
  1540. // NSError *error=nil;
  1541. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1542. // return jsobj;
  1543. //}
  1544. //+(NSDictionary*)request_OrderDetail:(NSMutableDictionary *) params
  1545. //{
  1546. // // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1547. // if (params == nil) {
  1548. // params = [[NSMutableDictionary alloc] init];
  1549. // }
  1550. // __block AppDelegate *appDelegate = nil;
  1551. //
  1552. // dispatch_sync(dispatch_get_main_queue(), ^{
  1553. // //some UI methods ej
  1554. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1555. // });
  1556. // if(appDelegate.user!=nil)
  1557. // [params setValue:appDelegate.user forKey:@"user"];
  1558. // if(appDelegate.contact_id!=nil)
  1559. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1560. // if(appDelegate.password!=nil)
  1561. // [params setValue:appDelegate.password forKey:@"password"];
  1562. //
  1563. //
  1564. // // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  1565. //
  1566. // [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  1567. //
  1568. // NSData* json=nil;
  1569. // if(appDelegate.offline_mode)
  1570. // {
  1571. // json= [OLDataProvider offline_orderdetail:params];
  1572. // }
  1573. // else
  1574. // {
  1575. // if(![self IsNetworkAvailable])
  1576. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1577. //
  1578. // NSError *error=nil;
  1579. //
  1580. // NSString * uuid= [[NSUUID UUID] UUIDString];
  1581. // params[@"resultSerial"]=uuid;
  1582. //
  1583. // for(int i=0;i<150;i++)
  1584. // {
  1585. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  1586. // // result_params[@"resultSerial"]=uuid;
  1587. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  1588. // if(json!=nil)
  1589. // {
  1590. //
  1591. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1592. // int resultCode = [jsobj[@"result"] intValue];
  1593. // if(resultCode==2 || resultCode == 8)
  1594. // {
  1595. // break;
  1596. // }
  1597. // }
  1598. // sleep(2);
  1599. // }
  1600. //
  1601. //
  1602. // }
  1603. // if(json==nil)
  1604. // return nil;
  1605. // NSError *error=nil;
  1606. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1607. // return jsobj;
  1608. //}
  1609. //+(NSDictionary*) add_toCart:(NSString* ) item_id count:(int) count name:(NSString *)name
  1610. //{
  1611. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1612. // __block AppDelegate *appDelegate = nil;
  1613. //
  1614. // dispatch_sync(dispatch_get_main_queue(), ^{
  1615. // //some UI methods ej
  1616. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1617. // });
  1618. // if(appDelegate.user!=nil)
  1619. // [params setValue:appDelegate.user forKey:@"user"];
  1620. // if(appDelegate.contact_id!=nil)
  1621. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1622. // if(appDelegate.password!=nil)
  1623. // [params setValue:appDelegate.password forKey:@"password"];
  1624. //
  1625. // if(appDelegate.order_code!=nil)
  1626. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1627. // [params setValue:item_id forKey:@"product_id"];
  1628. // [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  1629. //
  1630. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  1631. // [params setObject:@"Add To Cart" forKey:kAction];
  1632. // if (name) {
  1633. // NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  1634. // [params setObject:extra forKey:kExtra];
  1635. // }
  1636. //
  1637. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1638. //
  1639. // NSArray* keys=[customerinfo allKeys];
  1640. // for(int i=0;i<keys.count;i++)
  1641. // {
  1642. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1643. // }
  1644. //
  1645. // NSData* json=nil;
  1646. // if(appDelegate.offline_mode)
  1647. // {
  1648. // json=[OLDataProvider offline_add2cart:params];
  1649. // }
  1650. // else
  1651. // {
  1652. // if(![self IsNetworkAvailable])
  1653. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1654. //
  1655. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  1656. // }
  1657. // if(json==nil)
  1658. // return nil;
  1659. // NSError *error=nil;
  1660. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1661. //
  1662. //
  1663. //
  1664. // int result = [[jsobj valueForKey:@"result"] intValue];
  1665. //
  1666. // if (result==2)
  1667. // {
  1668. //
  1669. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1670. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1671. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1672. //
  1673. // [appDelegate update_count_mark];
  1674. // }
  1675. //
  1676. // return jsobj;
  1677. //}
  1678. //+(NSDictionary*) add_toCart_byName:(NSString* ) model_name withScreen:(NSString *)screenName
  1679. //{
  1680. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1681. // __block AppDelegate *appDelegate = nil;
  1682. //
  1683. // dispatch_sync(dispatch_get_main_queue(), ^{
  1684. // //some UI methods ej
  1685. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1686. // });
  1687. // if(appDelegate.user!=nil)
  1688. // [params setValue:appDelegate.user forKey:@"user"];
  1689. // if(appDelegate.contact_id!=nil)
  1690. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1691. // if(appDelegate.password!=nil)
  1692. // [params setValue:appDelegate.password forKey:@"password"];
  1693. //
  1694. // if(appDelegate.order_code!=nil)
  1695. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1696. // [params setValue:model_name forKey:@"product_name"];
  1697. // [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  1698. //
  1699. // [params setObject:screenName forKey:kScreenName];
  1700. // [params setObject:@"Add To Cart" forKey:kAction];
  1701. // if (!model_name) {
  1702. // model_name = @"";
  1703. // }
  1704. // [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  1705. //
  1706. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1707. //
  1708. // NSArray* keys=[customerinfo allKeys];
  1709. // for(int i=0;i<keys.count;i++)
  1710. // {
  1711. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1712. // }
  1713. // NSData* json=nil;
  1714. // if(appDelegate.offline_mode)
  1715. // {
  1716. // json= [OLDataProvider offline_add2cartbyname:params];
  1717. // }
  1718. // else
  1719. // {
  1720. // if(![self IsNetworkAvailable])
  1721. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1722. //
  1723. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  1724. // }
  1725. // if(json==nil)
  1726. // return nil;
  1727. // NSError *error=nil;
  1728. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1729. //
  1730. //
  1731. //
  1732. // int result = [[jsobj valueForKey:@"result"] intValue];
  1733. //
  1734. // if (result==2||result==8)
  1735. // {
  1736. //
  1737. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1738. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1739. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1740. //
  1741. // [appDelegate update_count_mark];
  1742. // }
  1743. //
  1744. // return jsobj;
  1745. //}
  1746. //+(NSDictionary*) new_Customer
  1747. //{
  1748. // if(![self IsNetworkAvailable])
  1749. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1750. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1751. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1752. // if(appDelegate.user!=nil)
  1753. // [params setValue:appDelegate.user forKey:@"user"];
  1754. //// if(appDelegate.contact_id!=nil)
  1755. //// [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1756. // if(appDelegate.password!=nil)
  1757. // [params setValue:appDelegate.password forKey:@"password"];
  1758. //
  1759. //// if(appDelegate.order_code!=nil)
  1760. //// [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1761. //
  1762. //
  1763. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1764. //
  1765. // NSArray* keys=[customerinfo allKeys];
  1766. // for(int i=0;i<keys.count;i++)
  1767. // {
  1768. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1769. // }
  1770. //
  1771. // NSData* json=[self get_json:URL_CUSTOMER_EDIT parameters:params];
  1772. // if(json==nil)
  1773. // return nil;
  1774. // NSError *error=nil;
  1775. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1776. // return jsobj;
  1777. //}
  1778. //+(NSDictionary*) new_Order
  1779. //{
  1780. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1781. // __block AppDelegate *appDelegate = nil;
  1782. //
  1783. // dispatch_sync(dispatch_get_main_queue(), ^{
  1784. // //some UI methods ej
  1785. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1786. // });
  1787. // if(appDelegate.user!=nil)
  1788. // [params setValue:appDelegate.user forKey:@"user"];
  1789. // if(appDelegate.contact_id!=nil)
  1790. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1791. // if(appDelegate.password!=nil)
  1792. // [params setValue:appDelegate.password forKey:@"password"];
  1793. //
  1794. // if(appDelegate.order_code!=nil)
  1795. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  1796. //
  1797. //
  1798. // [params setObject:ScreenCodeOrderList forKey:kScreenName];
  1799. //
  1800. // NSDictionary* customerinfo= appDelegate.customerInfo;
  1801. //
  1802. // NSArray* keys=[customerinfo allKeys];
  1803. // for(int i=0;i<keys.count;i++)
  1804. // {
  1805. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  1806. // }
  1807. //
  1808. // NSData* json = nil;
  1809. // if(appDelegate.offline_mode)
  1810. // {
  1811. // json= [OLDataProvider offline_createorder:params];
  1812. // }
  1813. // else
  1814. // {
  1815. // if(![self IsNetworkAvailable])
  1816. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1817. //
  1818. // json=[self get_json:URL_NEW_ORDER parameters:params];
  1819. // }
  1820. // if(json==nil)
  1821. // return nil;
  1822. // NSError *error=nil;
  1823. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1824. // int result = [[jsobj valueForKey:@"result"] intValue];
  1825. //
  1826. // if (result==2)
  1827. // {
  1828. //
  1829. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1830. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1831. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1832. //
  1833. // [appDelegate update_count_mark];
  1834. // }
  1835. //
  1836. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  1837. //
  1838. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  1839. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  1840. // }
  1841. //
  1842. // return jsobj;
  1843. //}
  1844. +(NSDictionary*) add_toPortfolio:(NSString* ) item_id withScreen:(NSString *)screenName
  1845. {
  1846. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1847. __block AppDelegate *appDelegate = nil;
  1848. dispatch_sync(dispatch_get_main_queue(), ^{
  1849. //some UI methods ej
  1850. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1851. });
  1852. if(appDelegate.user!=nil)
  1853. [params setValue:appDelegate.user forKey:@"user"];
  1854. if(appDelegate.contact_id!=nil)
  1855. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1856. if(appDelegate.password!=nil)
  1857. [params setValue:appDelegate.password forKey:@"password"];
  1858. [params setValue:item_id forKey:@"product_id"];
  1859. [params setObject:screenName forKey:kScreenName];
  1860. NSData* json = nil;
  1861. if(appDelegate.offline_mode)
  1862. {
  1863. json = [OLDataProvider offline_add2Portfolio:params];
  1864. } else {
  1865. if(![self IsNetworkAvailable])
  1866. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1867. json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  1868. }
  1869. if(json==nil)
  1870. return nil;
  1871. NSError *error=nil;
  1872. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1873. int result = [[jsobj valueForKey:@"result"] intValue];
  1874. if (result==2)
  1875. {
  1876. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1877. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1878. appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1879. [appDelegate update_count_mark];
  1880. }
  1881. return jsobj;
  1882. }
  1883. //+(NSDictionary*) add_toWatchList:(NSString* ) item_id withScreen:(NSString *)screenName
  1884. //{
  1885. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1886. // __block AppDelegate *appDelegate = nil;
  1887. //
  1888. // dispatch_sync(dispatch_get_main_queue(), ^{
  1889. // //some UI methods ej
  1890. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1891. // });
  1892. // if(appDelegate.user!=nil)
  1893. // [params setValue:appDelegate.user forKey:@"user"];
  1894. // if(appDelegate.contact_id!=nil)
  1895. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1896. // if(appDelegate.password!=nil)
  1897. // [params setValue:appDelegate.password forKey:@"password"];
  1898. //
  1899. //
  1900. // [params setValue:item_id forKey:@"product_id"];
  1901. //
  1902. // [params setObject:screenName forKey:kScreenName];
  1903. //
  1904. // if(appDelegate.offline_mode)
  1905. // {
  1906. // return [OLDataProvider offline_add2wishlist:params];
  1907. // }
  1908. // if(![self IsNetworkAvailable])
  1909. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1910. //
  1911. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  1912. // if(json==nil)
  1913. // return nil;
  1914. // NSError *error=nil;
  1915. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1916. // int result = [[jsobj valueForKey:@"result"] intValue];
  1917. //
  1918. // if (result==2)
  1919. // {
  1920. //
  1921. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  1922. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  1923. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  1924. //
  1925. // [appDelegate update_count_mark];
  1926. // }
  1927. // return jsobj;
  1928. //}
  1929. //+(NSDictionary*) cart_setPrice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes
  1930. //{
  1931. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1932. // __block AppDelegate *appDelegate = nil;
  1933. //
  1934. // dispatch_sync(dispatch_get_main_queue(), ^{
  1935. // //some UI methods ej
  1936. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  1937. // });
  1938. // if(appDelegate.user!=nil)
  1939. // [params setValue:appDelegate.user forKey:@"user"];
  1940. // if(appDelegate.contact_id!=nil)
  1941. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1942. // if(appDelegate.password!=nil)
  1943. // [params setValue:appDelegate.password forKey:@"password"];
  1944. //
  1945. // [params setValue:cart_id forKey:@"cartitem_id"];
  1946. // [params setValue:notes forKey:@"item_note"];
  1947. //
  1948. // [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  1949. //
  1950. // [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  1951. //
  1952. // [params setObject:ScreenCodeCart forKey:kScreenName];
  1953. //
  1954. // NSData* json= nil;
  1955. // if(appDelegate.offline_mode)
  1956. // {
  1957. // json=[OLDataProvider offline_cartsetprice:params];
  1958. // }
  1959. // else
  1960. // {
  1961. // if(![self IsNetworkAvailable])
  1962. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1963. //
  1964. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  1965. // }
  1966. // if(json==nil)
  1967. // return nil;
  1968. // NSError *error=nil;
  1969. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1970. // return jsobj;
  1971. //}
  1972. //+(NSDictionary*) portfolio_setQTY:(NSString*) watchlist_id QTY:(int)qty
  1973. //{
  1974. // if(![self IsNetworkAvailable])
  1975. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  1976. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  1977. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  1978. // if(appDelegate.user!=nil)
  1979. // [params setValue:appDelegate.user forKey:@"user"];
  1980. // if(appDelegate.contact_id!=nil)
  1981. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  1982. // if(appDelegate.password!=nil)
  1983. // [params setValue:appDelegate.password forKey:@"password"];
  1984. //
  1985. // [params setValue:watchlist_id forKey:@"item_id"];
  1986. //
  1987. // [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  1988. //
  1989. //
  1990. //
  1991. // NSData* json=[self get_json:URL_DM_SET_QTY parameters:params];
  1992. // if(json==nil)
  1993. // return nil;
  1994. // NSError *error=nil;
  1995. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  1996. // return jsobj;
  1997. //}
  1998. +(NSDictionary*) portfolio_setPrice:(NSString*) watchlist_id price:(float) price discount:(float) discount QTY:(int)qty qty_p:(float) qty_p notes:(NSString*)notes
  1999. {
  2000. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2001. __block AppDelegate *appDelegate = nil;
  2002. dispatch_sync(dispatch_get_main_queue(), ^{
  2003. //some UI methods ej
  2004. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2005. });
  2006. if(appDelegate.user!=nil)
  2007. [params setValue:appDelegate.user forKey:@"user"];
  2008. if(appDelegate.contact_id!=nil)
  2009. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2010. if(appDelegate.password!=nil)
  2011. [params setValue:appDelegate.password forKey:@"password"];
  2012. [params setValue:watchlist_id forKey:@"item_id"];
  2013. // if(notes.length>0)
  2014. // [params setValue:notes forKey:@"notes"];
  2015. if(notes)
  2016. [params setValue:notes forKey:@"notes"];
  2017. if(price != -MAXFLOAT)
  2018. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  2019. if (discount != -MAXFLOAT)
  2020. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  2021. if(qty_p != -MAXFLOAT)
  2022. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  2023. if(qty != -INT32_MAX)
  2024. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  2025. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2026. NSData* json = nil;
  2027. if(appDelegate.offline_mode)
  2028. {
  2029. json = [OLDataProvider offline_editPortfolio:params];
  2030. } else {
  2031. if(![self IsNetworkAvailable])
  2032. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2033. json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  2034. }
  2035. if(json==nil)
  2036. return nil;
  2037. NSError *error=nil;
  2038. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2039. return jsobj;
  2040. }
  2041. //+(NSDictionary*) cart_setGeneralNote:(NSString*) order_code notes:(NSString*) notes
  2042. //{
  2043. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2044. // __block AppDelegate *appDelegate = nil;
  2045. //
  2046. // dispatch_sync(dispatch_get_main_queue(), ^{
  2047. // //some UI methods ej
  2048. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2049. // });
  2050. // if(appDelegate.user!=nil)
  2051. // [params setValue:appDelegate.user forKey:@"user"];
  2052. // if(appDelegate.contact_id!=nil)
  2053. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2054. // if(appDelegate.password!=nil)
  2055. // [params setValue:appDelegate.password forKey:@"password"];
  2056. //
  2057. // [params setValue:order_code forKey:@"orderCode"];
  2058. //
  2059. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2060. //
  2061. // if(notes.length==0)
  2062. // notes=@"";
  2063. //
  2064. //
  2065. // [params setValue:notes forKey:@"comments"];
  2066. // NSData* json=nil;
  2067. // if(appDelegate.offline_mode)
  2068. // {
  2069. // json= [OLDataProvider offline_updategnotes:params];
  2070. // }
  2071. // else
  2072. // {
  2073. // if(![self IsNetworkAvailable])
  2074. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2075. //
  2076. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  2077. // }
  2078. // if(json==nil)
  2079. // return nil;
  2080. // NSError *error=nil;
  2081. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2082. // return jsobj;
  2083. //}
  2084. //+(NSDictionary*) cart_setItemNote:(NSString*) cart_id notes:(NSString*) notes
  2085. //{
  2086. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2087. // __block AppDelegate *appDelegate = nil;
  2088. //
  2089. // dispatch_sync(dispatch_get_main_queue(), ^{
  2090. // //some UI methods ej
  2091. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2092. // });
  2093. // if(appDelegate.user!=nil)
  2094. // [params setValue:appDelegate.user forKey:@"user"];
  2095. // if(appDelegate.contact_id!=nil)
  2096. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2097. // if(appDelegate.password!=nil)
  2098. // [params setValue:appDelegate.password forKey:@"password"];
  2099. //
  2100. // [params setValue:cart_id forKey:@"cartitem_id"];
  2101. //
  2102. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2103. //
  2104. // if(notes.length==0)
  2105. // notes=@"";
  2106. //
  2107. //
  2108. // [params setValue:notes forKey:@"notes"];
  2109. // NSData* json=nil;
  2110. // if(appDelegate.offline_mode)
  2111. // {
  2112. // json= [OLDataProvider offline_cartsetlnotes:params];
  2113. // }
  2114. // else
  2115. // {
  2116. // if(![self IsNetworkAvailable])
  2117. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2118. //
  2119. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  2120. // }
  2121. // if(json==nil)
  2122. // return nil;
  2123. // NSError *error=nil;
  2124. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2125. // return jsobj;
  2126. //}
  2127. //+(NSDictionary*) cart_setFree:(NSString*) cart_id isfree:(bool) isfree
  2128. //{
  2129. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2130. // __block AppDelegate *appDelegate = nil;
  2131. //
  2132. // dispatch_sync(dispatch_get_main_queue(), ^{
  2133. // //some UI methods ej
  2134. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2135. // });
  2136. // if(appDelegate.user!=nil)
  2137. // [params setValue:appDelegate.user forKey:@"user"];
  2138. // if(appDelegate.contact_id!=nil)
  2139. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2140. // if(appDelegate.password!=nil)
  2141. // [params setValue:appDelegate.password forKey:@"password"];
  2142. //
  2143. // [params setValue:cart_id forKey:@"cartitem_id"];
  2144. //
  2145. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2146. //
  2147. // NSString* free=nil;
  2148. //
  2149. // if(isfree)
  2150. // free=@"true";
  2151. // else
  2152. // free=@"false";
  2153. //
  2154. // [params setValue:free forKey:@"free_giveaway"];
  2155. //
  2156. // if(appDelegate.offline_mode)
  2157. // {
  2158. // return [OLDataProvider offline_notimpl];
  2159. // }
  2160. // if(![self IsNetworkAvailable])
  2161. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2162. //
  2163. // NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  2164. // if(json==nil)
  2165. // return nil;
  2166. // NSError *error=nil;
  2167. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2168. // return jsobj;
  2169. //}
  2170. //+(NSDictionary*) cart_setQTY:(NSString*) cart_id value:(int) value
  2171. //{
  2172. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2173. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2174. // if(appDelegate.user!=nil)
  2175. // [params setValue:appDelegate.user forKey:@"user"];
  2176. // if(appDelegate.contact_id!=nil)
  2177. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2178. // if(appDelegate.password!=nil)
  2179. // [params setValue:appDelegate.password forKey:@"password"];
  2180. //
  2181. // [params setValue:cart_id forKey:@"cartitem_id"];
  2182. //
  2183. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2184. //
  2185. // [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  2186. //
  2187. // NSData* json=nil;
  2188. // if(appDelegate.offline_mode)
  2189. // {
  2190. // json= [OLDataProvider offline_cartsetqty:params];
  2191. // }
  2192. // else
  2193. // {
  2194. // if(![self IsNetworkAvailable])
  2195. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2196. //
  2197. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2198. // }
  2199. // if(json==nil)
  2200. // return nil;
  2201. // NSError *error=nil;
  2202. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2203. // return jsobj;
  2204. //
  2205. //}
  2206. //+(NSDictionary*) cart_incresement:(NSString*) cart_id increse:(bool) increse
  2207. //{
  2208. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2209. // __block AppDelegate *appDelegate = nil;
  2210. //
  2211. // dispatch_sync(dispatch_get_main_queue(), ^{
  2212. // //some UI methods ej
  2213. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2214. // });
  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. // [params setValue:cart_id forKey:@"cartitem_id"];
  2223. //
  2224. // if(increse)
  2225. // [params setValue:@"1" forKey:@"incrementType"];
  2226. // else
  2227. // [params setValue:@"0" forKey:@"incrementType"];
  2228. //
  2229. //
  2230. //
  2231. // if(appDelegate.offline_mode)
  2232. // {
  2233. // return [OLDataProvider offline_notimpl];
  2234. // }
  2235. // if(![self IsNetworkAvailable])
  2236. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2237. //
  2238. // NSData* json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  2239. // if(json==nil)
  2240. // return nil;
  2241. // NSError *error=nil;
  2242. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2243. // return jsobj;
  2244. //}
  2245. +(NSDictionary*) finish_download_Offline:(NSString* )vid
  2246. {
  2247. if(![self IsNetworkAvailable])
  2248. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2249. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2250. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  2251. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2252. // if(appDelegate.user!=nil)
  2253. // [params setValue:appDelegate.user forKey:@"user"];
  2254. // // if(appDelegate.contact_id!=nil)
  2255. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2256. // if(appDelegate.password!=nil)
  2257. // [params setValue:appDelegate.password forKey:@"password"];
  2258. [params setValue:vid forKey:@"downSerial"];
  2259. NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  2260. if(json==nil)
  2261. return nil;
  2262. NSError *error=nil;
  2263. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2264. // int result = [[jsobj valueForKey:@"result"] intValue];
  2265. //
  2266. // if (result==2)
  2267. // {
  2268. //
  2269. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2270. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2271. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2272. ////
  2273. //// [appDelegate update_count_mark];
  2274. // }
  2275. return jsobj;
  2276. }
  2277. +(NSDictionary*) download_Offline:(NSString* )vid
  2278. {
  2279. if(![self IsNetworkAvailable])
  2280. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2281. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2282. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2283. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2284. // if(appDelegate.user!=nil)
  2285. // [params setValue:appDelegate.user forKey:@"user"];
  2286. // // if(appDelegate.contact_id!=nil)
  2287. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2288. // if(appDelegate.password!=nil)
  2289. // [params setValue:appDelegate.password forKey:@"password"];
  2290. [params setValue:vid forKey:@"downSerial"];
  2291. NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  2292. if(json==nil)
  2293. return nil;
  2294. NSError *error=nil;
  2295. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2296. // int result = [[jsobj valueForKey:@"result"] intValue];
  2297. //
  2298. // if (result==2)
  2299. // {
  2300. //
  2301. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2302. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2303. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2304. ////
  2305. //// [appDelegate update_count_mark];
  2306. // }
  2307. return jsobj;
  2308. }
  2309. +(NSDictionary*) check_Offline:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid
  2310. {
  2311. if(![self IsNetworkAvailable])
  2312. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2313. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2314. __block AppDelegate *appDelegate = nil;
  2315. dispatch_sync(dispatch_get_main_queue(), ^{
  2316. //some UI methods ej
  2317. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2318. });
  2319. if(appDelegate.user!=nil)
  2320. [params setValue:appDelegate.user forKey:@"user"];
  2321. // if(appDelegate.contact_id!=nil)
  2322. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2323. if(appDelegate.password!=nil)
  2324. [params setValue:appDelegate.password forKey:@"password"];
  2325. [params setValue:ver forKey:@"ver"];
  2326. [params setValue:vid forKey:@"vid"];
  2327. if(buseinternaladdress)
  2328. [params setValue:@"true" forKey:@"internal_address"];
  2329. else
  2330. [params setValue:@"false" forKey:@"internal_address"];
  2331. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  2332. NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  2333. if(json==nil)
  2334. return nil;
  2335. NSError *error=nil;
  2336. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2337. // int result = [[jsobj valueForKey:@"result"] intValue];
  2338. //
  2339. // if (result==2)
  2340. // {
  2341. //
  2342. //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2343. //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2344. //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2345. ////
  2346. //// [appDelegate update_count_mark];
  2347. // }
  2348. return jsobj;
  2349. }
  2350. //+(NSDictionary*)request_Cart:(int)sort
  2351. //{
  2352. //
  2353. // DebugLog(@"iSalesNetwork::request_Cart");
  2354. //
  2355. //
  2356. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2357. // __block AppDelegate *appDelegate = nil;
  2358. //
  2359. // dispatch_sync(dispatch_get_main_queue(), ^{
  2360. // //some UI methods ej
  2361. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2362. // });
  2363. // if(appDelegate.user!=nil)
  2364. // [params setValue:appDelegate.user forKey:@"user"];
  2365. // // if(appDelegate.contact_id!=nil)
  2366. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2367. // if(appDelegate.password!=nil)
  2368. // [params setValue:appDelegate.password forKey:@"password"];
  2369. //
  2370. // if(appDelegate.order_code!=nil)
  2371. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2372. //
  2373. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2374. //
  2375. // [params setObject:ScreenCodeCart forKey:kScreenName];
  2376. //
  2377. // NSData* json=nil;
  2378. // if(appDelegate.offline_mode)
  2379. // {
  2380. // json= [OLDataProvider offline_requestcart:params];
  2381. // }
  2382. // else
  2383. // {
  2384. // if(![self IsNetworkAvailable])
  2385. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2386. //
  2387. // NSError *error=nil;
  2388. //
  2389. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2390. // params[@"resultSerial"]=uuid;
  2391. //
  2392. // for(int i=0;i<150;i++)
  2393. // {
  2394. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2395. // // result_params[@"resultSerial"]=uuid;
  2396. // json=[self get_json:URL_CART parameters:params];
  2397. // if(json!=nil)
  2398. // {
  2399. //
  2400. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2401. // if([jsobj[@"result"] intValue]==2)
  2402. // {
  2403. // break;
  2404. // }
  2405. // }
  2406. // sleep(2);
  2407. // }
  2408. //
  2409. // }
  2410. // if(json==nil)
  2411. // return nil;
  2412. // NSError *error=nil;
  2413. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2414. // int result = [[jsobj valueForKey:@"result"] intValue];
  2415. //
  2416. // if (result==2)
  2417. // {
  2418. //
  2419. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2420. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2421. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2422. //
  2423. // [appDelegate update_count_mark];
  2424. // }
  2425. // return jsobj;
  2426. //}
  2427. //+(NSDictionary*)request_Portfolio:(int)sort
  2428. //{
  2429. //
  2430. //
  2431. //
  2432. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2433. // __block AppDelegate *appDelegate = nil;
  2434. //
  2435. // dispatch_sync(dispatch_get_main_queue(), ^{
  2436. // //some UI methods ej
  2437. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2438. // });
  2439. // if(appDelegate.user!=nil)
  2440. // [params setValue:appDelegate.user forKey:@"user"];
  2441. // if(appDelegate.contact_id!=nil)
  2442. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2443. // if(appDelegate.password!=nil)
  2444. // [params setValue:appDelegate.password forKey:@"password"];
  2445. //
  2446. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2447. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2448. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2449. //
  2450. // [params setObject:ScreenCodePortfolio forKey:kScreenName];
  2451. //
  2452. // NSData* json = nil;
  2453. // if(appDelegate.offline_mode)
  2454. // {
  2455. // json = [OLDataProvider offline_portfolioList:params];
  2456. // } else {
  2457. // if(![self IsNetworkAvailable])
  2458. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2459. //
  2460. // json = [self get_json:URL_PORTFOLIO parameters:params];
  2461. // }
  2462. //
  2463. //
  2464. // if(json==nil)
  2465. // return nil;
  2466. // NSError *error=nil;
  2467. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2468. // int result = [[jsobj valueForKey:@"result"] intValue];
  2469. //
  2470. // if (result==2)
  2471. // {
  2472. //
  2473. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2474. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2475. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  2476. //
  2477. // [appDelegate update_count_mark];
  2478. // }
  2479. // return jsobj;
  2480. //}
  2481. //+(NSDictionary*)request_WatchList:(int)sort
  2482. //{
  2483. //
  2484. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2485. // __block AppDelegate *appDelegate = nil;
  2486. //
  2487. // dispatch_sync(dispatch_get_main_queue(), ^{
  2488. // //some UI methods ej
  2489. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2490. // });
  2491. // if(appDelegate.user!=nil)
  2492. // [params setValue:appDelegate.user forKey:@"user"];
  2493. // if(appDelegate.contact_id!=nil)
  2494. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2495. // if(appDelegate.password!=nil)
  2496. // [params setValue:appDelegate.password forKey:@"password"];
  2497. //
  2498. // [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  2499. // [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  2500. //
  2501. // [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  2502. //
  2503. // [params setObject:ScreenCodeWishList forKey:kScreenName];
  2504. //
  2505. // if(appDelegate.offline_mode)
  2506. // {
  2507. // return [OLDataProvider offline_wishlist:params];
  2508. // }
  2509. // if(![self IsNetworkAvailable])
  2510. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2511. //
  2512. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  2513. // if(json==nil)
  2514. // return nil;
  2515. // NSError *error=nil;
  2516. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2517. // int result = [[jsobj valueForKey:@"result"] intValue];
  2518. //
  2519. // if (result==2)
  2520. // {
  2521. //
  2522. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  2523. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  2524. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  2525. //
  2526. // [appDelegate update_count_mark];
  2527. // }
  2528. // return jsobj;
  2529. //}
  2530. //+(NSDictionary*)request_ItemDetail: (NSString* ) item_id model_name:(NSString*) model_name category_id:(NSString*) category_id use_name :(bool) use_name groupName:(NSString *)groupName
  2531. //{
  2532. //
  2533. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2534. // __block AppDelegate *appDelegate = nil;
  2535. //
  2536. // dispatch_sync(dispatch_get_main_queue(), ^{
  2537. // //some UI methods ej
  2538. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2539. // });
  2540. // if(appDelegate.user!=nil)
  2541. // [params setValue:appDelegate.user forKey:@"user"];
  2542. // if(appDelegate.contact_id!=nil)
  2543. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2544. // if(appDelegate.password!=nil)
  2545. // [params setValue:appDelegate.password forKey:@"password"];
  2546. // if(appDelegate.order_code!=nil)
  2547. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2548. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2549. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2550. // if(use_name)
  2551. // [params setValue:model_name forKey:@"product_name"];
  2552. // else
  2553. // [params setValue:item_id forKey:@"product_id"];
  2554. //
  2555. //
  2556. // [params setValue:category_id forKey:@"category"];
  2557. //
  2558. // [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  2559. // [params setObject:@"Open A Model" forKey:kAction];
  2560. // if (model_name) {
  2561. // NSDictionary *extra = @{@"ModelName" : model_name};
  2562. // [params setObject:extra forKey:kExtra];
  2563. // }
  2564. //
  2565. // if (groupName.length > 0) {
  2566. // [params setObject:groupName forKey:@"groupName"];
  2567. // }
  2568. //
  2569. // if(appDelegate.offline_mode)
  2570. // return [OLDataProvider offline_model:params];
  2571. //
  2572. // if(![self IsNetworkAvailable])
  2573. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2574. //
  2575. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  2576. // if(json==nil)
  2577. // return nil;
  2578. // NSError *error=nil;
  2579. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2580. // return jsobj;
  2581. //}
  2582. //+(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
  2583. //{
  2584. // if(![self IsNetworkAvailable])
  2585. // return nil;
  2586. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2587. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2588. // if(appDelegate.user!=nil)
  2589. // [params setValue:appDelegate.user forKey:@"user"];
  2590. // if(appDelegate.contact_id!=nil)
  2591. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2592. // if(appDelegate.password!=nil)
  2593. // [params setValue:appDelegate.password forKey:@"password"];
  2594. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2595. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2596. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2597. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2598. // [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  2599. // [params setValue:filter forKey:@"filter"];
  2600. // [params setValue:keyword forKey:@"keyword"];
  2601. //
  2602. //
  2603. // NSData* json=[self get_json:URL_CATEGORY_LOADMORE parameters:params];
  2604. // if(json==nil)
  2605. // return nil;
  2606. // NSError *error=nil;
  2607. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2608. // return jsobj;
  2609. //
  2610. //}
  2611. //+(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
  2612. //
  2613. //{
  2614. //
  2615. //
  2616. // __block AppDelegate *appDelegate = nil;
  2617. //
  2618. // dispatch_sync(dispatch_get_main_queue(), ^{
  2619. // //some UI methods ej
  2620. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2621. // });
  2622. //
  2623. //
  2624. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2625. //
  2626. // if(appDelegate.user!=nil)
  2627. // [params setValue:appDelegate.user forKey:@"user"];
  2628. // if(appDelegate.contact_id!=nil)
  2629. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2630. // if(appDelegate.password!=nil)
  2631. // [params setValue:appDelegate.password forKey:@"password"];
  2632. // if(appDelegate.order_code!=nil)
  2633. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2634. //
  2635. // [params setValue:addTo forKey:@"addTo"];
  2636. // [params setValue:orderCode forKey:@"orderCode"];
  2637. // [params setValue:alert forKey:@"alert"];
  2638. // [params setValue:qty forKey:@"sold_by_qty"];
  2639. // [params setValue:available forKey:@"available"];
  2640. // [params setValue:price forKey:@"price"];
  2641. // [params setValue:bestseller forKey:@"bestseller"];
  2642. // [params setValue:modelname forKey:@"modelName"];
  2643. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2644. //
  2645. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2646. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2647. // [params setValue:category forKey:@"category"];
  2648. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2649. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2650. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2651. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2652. // [params setValue:filter forKey:@"filter"];
  2653. // [params setValue:keyword forKey:@"keyword"];
  2654. //
  2655. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  2656. // if ([addTo isEqualToString:@"cart"]) {
  2657. // [params setObject:@"Add To Cart" forKey:kAction];
  2658. // }
  2659. //
  2660. //
  2661. // NSData* json= nil;
  2662. //
  2663. // if(appDelegate.offline_mode)
  2664. // {
  2665. // json= [OLDataProvider offline_categoryaddall:params];
  2666. // }
  2667. // else
  2668. // {
  2669. // if(![self IsNetworkAvailable])
  2670. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2671. //
  2672. //
  2673. // NSError *error=nil;
  2674. //
  2675. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2676. // params[@"resultSerial"]=uuid;
  2677. //
  2678. // for(int i=0;i<150;i++)
  2679. // {
  2680. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2681. // // result_params[@"resultSerial"]=uuid;
  2682. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  2683. // if(json!=nil)
  2684. // {
  2685. //
  2686. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2687. // int resultInt = [jsobj[@"result"] intValue];
  2688. // if(resultInt == 2 || resultInt == 8)
  2689. // {
  2690. // break;
  2691. // }
  2692. // }
  2693. // sleep(2);
  2694. // }
  2695. //
  2696. //
  2697. //
  2698. // }
  2699. // if(json==nil)
  2700. // return nil;
  2701. // NSError *error=nil;
  2702. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2703. // return jsobj;
  2704. //
  2705. //}
  2706. //+(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
  2707. //{
  2708. //
  2709. //
  2710. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2711. //
  2712. //
  2713. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2714. //
  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. // if(appDelegate.order_code!=nil)
  2722. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2723. //
  2724. // [params setValue:alert forKey:@"alert"];
  2725. // [params setValue:qty forKey:@"sold_by_qty"];
  2726. // [params setValue:available forKey:@"available"];
  2727. // [params setValue:price forKey:@"price"];
  2728. // [params setValue:bestseller forKey:@"bestseller"];
  2729. // [params setValue:modelname forKey:@"modelName"];
  2730. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2731. //
  2732. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2733. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2734. // [params setValue:category forKey:@"category"];
  2735. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2736. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2737. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2738. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2739. // [params setValue:filter forKey:@"filter"];
  2740. // [params setValue:keyword forKey:@"keyword"];
  2741. //
  2742. //
  2743. //
  2744. // if(appDelegate.offline_mode)
  2745. // return [OLDataProvider offline_category:params];
  2746. // if(![self IsNetworkAvailable])
  2747. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2748. //
  2749. // NSData* json=[self get_json:URL_ADDALL2PORTFOLIO parameters:params];
  2750. // if(json==nil)
  2751. // return nil;
  2752. // NSError *error=nil;
  2753. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2754. // return jsobj;
  2755. //
  2756. //}
  2757. //+(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
  2758. //{
  2759. //
  2760. //
  2761. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  2762. //
  2763. //
  2764. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2765. //
  2766. // if(appDelegate.user!=nil)
  2767. // [params setValue:appDelegate.user forKey:@"user"];
  2768. // if(appDelegate.contact_id!=nil)
  2769. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2770. // if(appDelegate.password!=nil)
  2771. // [params setValue:appDelegate.password forKey:@"password"];
  2772. // if(appDelegate.order_code!=nil)
  2773. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2774. //
  2775. // [params setValue:alert forKey:@"alert"];
  2776. // [params setValue:qty forKey:@"sold_by_qty"];
  2777. // [params setValue:available forKey:@"available"];
  2778. // [params setValue:price forKey:@"price"];
  2779. // [params setValue:bestseller forKey:@"bestseller"];
  2780. // [params setValue:modelname forKey:@"modelName"];
  2781. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2782. //
  2783. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2784. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2785. // [params setValue:category forKey:@"category"];
  2786. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2787. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2788. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2789. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2790. // [params setValue:filter forKey:@"filter"];
  2791. // [params setValue:keyword forKey:@"keyword"];
  2792. //
  2793. //
  2794. //
  2795. // if(appDelegate.offline_mode)
  2796. // return [OLDataProvider offline_category:params];
  2797. // if(![self IsNetworkAvailable])
  2798. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2799. //
  2800. // NSData* json=[self get_json:URL_ADDALL2WISH parameters:params];
  2801. // if(json==nil)
  2802. // return nil;
  2803. // NSError *error=nil;
  2804. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2805. // return jsobj;
  2806. //
  2807. //}
  2808. //+(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
  2809. //{
  2810. //
  2811. //
  2812. // __block AppDelegate *appDelegate = nil;
  2813. //
  2814. // dispatch_sync(dispatch_get_main_queue(), ^{
  2815. // //some UI methods ej
  2816. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2817. // });
  2818. //
  2819. //
  2820. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2821. //
  2822. // if(appDelegate.user!=nil)
  2823. // [params setValue:appDelegate.user forKey:@"user"];
  2824. // if(appDelegate.contact_id!=nil)
  2825. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2826. // if(appDelegate.password!=nil)
  2827. // [params setValue:appDelegate.password forKey:@"password"];
  2828. // if(appDelegate.order_code!=nil)
  2829. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2830. //
  2831. // [params setValue:alert forKey:@"alert"];
  2832. // [params setValue:qty forKey:@"sold_by_qty"];
  2833. // [params setValue:available forKey:@"available"];
  2834. // [params setValue:price forKey:@"price"];
  2835. // [params setValue:bestseller forKey:@"bestseller"];
  2836. // [params setValue:modelname forKey:@"modelName"];
  2837. // [params setValue:modeldescrip forKey:@"modelDescription"];
  2838. //
  2839. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2840. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2841. // [params setValue:category forKey:@"category"];
  2842. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2843. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2844. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2845. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2846. // [params setValue:filter forKey:@"filter"];
  2847. // [params setValue:keyword forKey:@"keyword"];
  2848. //
  2849. // [params setObject:ScreenCodeCategory forKey:kScreenName];
  2850. // if (alert) {
  2851. // [params setObject:@"Filter" forKey:kAction];
  2852. // }
  2853. // if ([Singleton sharedInstance].homeItemClick) {
  2854. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  2855. // [Singleton sharedInstance].homeItemClick = NO;
  2856. //
  2857. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  2858. // [Singleton sharedInstance].homeClickedItemName = nil;
  2859. // [params setObject:extra forKey:kExtra];
  2860. //
  2861. // }
  2862. //
  2863. //
  2864. // if(appDelegate.offline_mode)
  2865. // return [OLDataProvider offline_category:params];
  2866. // if(![self IsNetworkAvailable])
  2867. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2868. //
  2869. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  2870. // if(json==nil)
  2871. // return nil;
  2872. // NSError *error=nil;
  2873. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2874. // return jsobj;
  2875. //
  2876. //}
  2877. //+(NSDictionary*)Search_addall:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo
  2878. //{
  2879. //
  2880. //
  2881. //
  2882. //
  2883. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2884. // __block AppDelegate *appDelegate = nil;
  2885. //
  2886. // dispatch_sync(dispatch_get_main_queue(), ^{
  2887. // //some UI methods ej
  2888. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2889. // });
  2890. // if(appDelegate.user!=nil)
  2891. // [params setValue:appDelegate.user forKey:@"user"];
  2892. // if(appDelegate.contact_id!=nil)
  2893. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2894. // if(appDelegate.password!=nil)
  2895. // [params setValue:appDelegate.password forKey:@"password"];
  2896. // if(appDelegate.order_code!=nil)
  2897. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2898. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2899. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2900. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2901. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2902. // // [params setValue:filter forKey:@"filter"];
  2903. // [params setValue:keywords forKey:@"keyword"];
  2904. // [params setValue:addTo forKey:@"addTo"];
  2905. //
  2906. // [params setValue:orderCode forKey:@"orderCode"];
  2907. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2908. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2909. // if(matchfull)
  2910. // [params setValue:@"true" forKey:@"exactMatch"];
  2911. // else
  2912. // [params setValue:@"false" forKey:@"exactMatch"];
  2913. //
  2914. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  2915. // if ([addTo isEqualToString:@"cart"]) {
  2916. // [params setObject:@"Add To Cart" forKey:kAction];
  2917. // }
  2918. //
  2919. // NSData* json=nil;
  2920. // if(appDelegate.offline_mode)
  2921. // {
  2922. // json=[OLDataProvider offline_searchaddall:params];
  2923. // }
  2924. // else
  2925. // {
  2926. // if(![self IsNetworkAvailable])
  2927. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  2928. //
  2929. // NSError *error=nil;
  2930. //
  2931. // NSString * uuid= [[NSUUID UUID] UUIDString];
  2932. // params[@"resultSerial"]=uuid;
  2933. //
  2934. // for(int i=0;i<150;i++)
  2935. // {
  2936. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  2937. // // result_params[@"resultSerial"]=uuid;
  2938. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  2939. // if(json!=nil)
  2940. // {
  2941. //
  2942. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2943. // if([jsobj[@"result"] intValue]==2)
  2944. // {
  2945. // break;
  2946. // }
  2947. // }
  2948. // sleep(2);
  2949. // }
  2950. // }
  2951. // if(json==nil)
  2952. // return nil;
  2953. // NSError *error=nil;
  2954. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  2955. // return jsobj;
  2956. //
  2957. //}
  2958. //+(NSDictionary*)Search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull
  2959. //{
  2960. //
  2961. //
  2962. //
  2963. //
  2964. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  2965. // __block AppDelegate *appDelegate = nil;
  2966. //
  2967. // dispatch_sync(dispatch_get_main_queue(), ^{
  2968. // //some UI methods ej
  2969. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  2970. // });
  2971. // if(appDelegate.user!=nil)
  2972. // [params setValue:appDelegate.user forKey:@"user"];
  2973. // if(appDelegate.contact_id!=nil)
  2974. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  2975. // if(appDelegate.password!=nil)
  2976. // [params setValue:appDelegate.password forKey:@"password"];
  2977. // if(appDelegate.order_code!=nil)
  2978. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  2979. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  2980. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  2981. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  2982. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  2983. // // [params setValue:filter forKey:@"filter"];
  2984. // [params setValue:keywords forKey:@"keyword"];
  2985. //
  2986. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  2987. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  2988. // if(matchfull)
  2989. // [params setValue:@"true" forKey:@"exactMatch"];
  2990. // else
  2991. // [params setValue:@"false" forKey:@"exactMatch"];
  2992. //
  2993. // [params setObject:ScreenCodeSearch forKey:kScreenName];
  2994. // if (keywords) {
  2995. // [params setObject:@"Search" forKey:kAction];
  2996. // }
  2997. //
  2998. // if(appDelegate.offline_mode)
  2999. // {
  3000. // return [OLDataProvider offline_search:params];
  3001. // }
  3002. // if(![self IsNetworkAvailable])
  3003. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3004. //
  3005. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3006. // if(json==nil)
  3007. // return nil;
  3008. // NSError *error=nil;
  3009. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3010. // return jsobj;
  3011. //}
  3012. //+(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
  3013. //{
  3014. // // for debug
  3015. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3016. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3017. //
  3018. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3019. // __block AppDelegate *appDelegate = nil;
  3020. //
  3021. // dispatch_sync(dispatch_get_main_queue(), ^{
  3022. // //some UI methods ej
  3023. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3024. // });
  3025. // if(appDelegate.user!=nil)
  3026. // [params setValue:appDelegate.user forKey:@"user"];
  3027. // if(appDelegate.contact_id!=nil)
  3028. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3029. // if(appDelegate.password!=nil)
  3030. // [params setValue:appDelegate.password forKey:@"password"];
  3031. // if(appDelegate.order_code!=nil)
  3032. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3033. //
  3034. // [params setValue:addTo forKey:@"addTo"];
  3035. //
  3036. // [params setValue:orderCode forKey:@"orderCode"];
  3037. //
  3038. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3039. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3040. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3041. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3042. // // [params setValue:filter forKey:@"filter"];
  3043. // [params setValue:covertype forKey:@"covertype"];
  3044. // [params setValue:ctgid forKey:@"ctgId"];
  3045. // [params setValue:modelname forKey:@"modelName"];
  3046. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3047. // [params setValue:alert forKey:@"alert"];
  3048. // [params setValue:qty forKey:@"sold_by_qty"];
  3049. // [params setValue:available forKey:@"available"];
  3050. // [params setValue:price forKey:@"price"];
  3051. // [params setValue:bestseller forKey:@"bestseller"];
  3052. //
  3053. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3054. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3055. //
  3056. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3057. // if ([addTo isEqualToString:@"cart"]) {
  3058. // [params setObject:@"Add To Cart" forKey:kAction];
  3059. // }
  3060. //
  3061. // NSData* json = nil;
  3062. //
  3063. // if(appDelegate.offline_mode)
  3064. // {
  3065. // json= [OLDataProvider offline_itemsearchaddall:params];
  3066. // }
  3067. // else
  3068. // {
  3069. // if(![self IsNetworkAvailable])
  3070. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3071. // NSError *error=nil;
  3072. //
  3073. // NSString * uuid= [[NSUUID UUID] UUIDString];
  3074. // params[@"resultSerial"]=uuid;
  3075. //
  3076. // for(int i=0;i<150;i++)
  3077. // {
  3078. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  3079. // // result_params[@"resultSerial"]=uuid;
  3080. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  3081. // if(json!=nil)
  3082. // {
  3083. //
  3084. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3085. // if([jsobj[@"result"] intValue]==2)
  3086. // {
  3087. // break;
  3088. // }
  3089. // }
  3090. // sleep(2);
  3091. // }
  3092. // }
  3093. // if(json==nil)
  3094. // return nil;
  3095. // NSError *error=nil;
  3096. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3097. // return jsobj;
  3098. //}
  3099. //+(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
  3100. //{
  3101. //
  3102. // // for debug
  3103. // // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  3104. // //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3105. //
  3106. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3107. // __block AppDelegate *appDelegate = nil;
  3108. //
  3109. // dispatch_sync(dispatch_get_main_queue(), ^{
  3110. // //some UI methods ej
  3111. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3112. // });
  3113. // if(appDelegate.user!=nil)
  3114. // [params setValue:appDelegate.user forKey:@"user"];
  3115. // if(appDelegate.contact_id!=nil)
  3116. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3117. // if(appDelegate.password!=nil)
  3118. // [params setValue:appDelegate.password forKey:@"password"];
  3119. // if(appDelegate.order_code!=nil)
  3120. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  3121. //
  3122. //
  3123. // [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  3124. // if (alert && qty && available && price && bestseller) {
  3125. // [params setObject:@"Filter" forKey:kAction];
  3126. // }
  3127. // if ([Singleton sharedInstance].homeItemClick) {
  3128. // [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  3129. // [Singleton sharedInstance].homeItemClick = NO;
  3130. //
  3131. // NSDictionary *extra = @{@"CoverName" : [Singleton sharedInstance].homeClickedItemName};
  3132. // [Singleton sharedInstance].homeClickedItemName = nil;
  3133. // [params setObject:extra forKey:kExtra];
  3134. // }
  3135. //
  3136. //
  3137. // // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3138. // // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3139. // // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3140. // // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3141. // // [params setValue:filter forKey:@"filter"];
  3142. // [params setValue:covertype forKey:@"covertype"];
  3143. // [params setValue:ctgid forKey:@"ctgId"];
  3144. // [params setValue:modelname forKey:@"modelName"];
  3145. // [params setValue:modeldescrip forKey:@"modelDescription"];
  3146. // [params setValue:alert forKey:@"alert"];
  3147. // [params setValue:qty forKey:@"sold_by_qty"];
  3148. // [params setValue:available forKey:@"available"];
  3149. // [params setValue:price forKey:@"price"];
  3150. // [params setValue:bestseller forKey:@"bestseller"];
  3151. //
  3152. // [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  3153. // [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  3154. //
  3155. // if(appDelegate.offline_mode)
  3156. // {
  3157. // return [OLDataProvider offline_itemsearch:params];
  3158. // }
  3159. // if(![self IsNetworkAvailable])
  3160. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3161. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  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. //+(NSDictionary*)Search: (NSString*) category customid:(int) customid price_template:(int) price_template sort:(int) sort_by filter:(NSString*) filter keyword:(NSString*) keyword
  3169. //{
  3170. // if(![self IsNetworkAvailable])
  3171. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3172. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3173. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3174. // if(appDelegate.user!=nil)
  3175. // [params setValue:appDelegate.user forKey:@"user"];
  3176. // if(appDelegate.contact_id!=nil)
  3177. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3178. // if(appDelegate.password!=nil)
  3179. // [params setValue:appDelegate.password forKey:@"password"];
  3180. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3181. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3182. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  3183. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  3184. // [params setValue:filter forKey:@"filter"];
  3185. // [params setValue:keyword forKey:@"keyword"];
  3186. //
  3187. //
  3188. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  3189. // if(json==nil)
  3190. // return nil;
  3191. // NSError *error=nil;
  3192. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3193. // return jsobj;
  3194. //}
  3195. +(NSDictionary*)request_model_qty: (NSString*) fashionId
  3196. {
  3197. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3198. __block AppDelegate *appDelegate = nil;
  3199. dispatch_sync(dispatch_get_main_queue(), ^{
  3200. //some UI methods ej
  3201. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3202. });
  3203. if(appDelegate.user!=nil)
  3204. [params setValue:appDelegate.user forKey:@"user"];
  3205. if(appDelegate.contact_id!=nil)
  3206. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3207. if(appDelegate.password!=nil)
  3208. [params setValue:appDelegate.password forKey:@"password"];
  3209. [params setValue:fashionId forKey:@"fashionId"];
  3210. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  3211. NSData* json = nil;
  3212. if(appDelegate.offline_mode)
  3213. {
  3214. json = [OLDataProvider offline_model_qty:params];
  3215. } else {
  3216. if(![self IsNetworkAvailable])
  3217. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3218. json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  3219. }
  3220. if(json==nil)
  3221. return nil;
  3222. NSError *error=nil;
  3223. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3224. return jsobj;
  3225. }
  3226. +(NSDictionary*)retrieve_password: (NSString*) user email:(NSString*) email
  3227. {
  3228. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3229. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3230. // if(appDelegate.user!=nil)
  3231. // [params setValue:appDelegate.user forKey:@"user"];
  3232. // if(appDelegate.contact_id!=nil)
  3233. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3234. // if(appDelegate.password!=nil)
  3235. // [params setValue:appDelegate.password forKey:@"password"];
  3236. [params setValue:user forKey:@"username"];
  3237. [params setValue:email forKey:@"email"];
  3238. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3239. if(![self IsNetworkAvailable])
  3240. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3241. NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  3242. if(json==nil)
  3243. return nil;
  3244. NSError *error=nil;
  3245. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3246. return jsobj;
  3247. }
  3248. +(NSDictionary*)load_HomePage:(int) price_template customid:(int) customid
  3249. {
  3250. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3251. __block AppDelegate *appDelegate = nil;
  3252. dispatch_sync(dispatch_get_main_queue(), ^{
  3253. //some UI methods ej
  3254. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3255. });
  3256. if(appDelegate.user!=nil)
  3257. [params setValue:appDelegate.user forKey:@"user"];
  3258. if(appDelegate.contact_id!=nil)
  3259. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  3260. if(appDelegate.password!=nil)
  3261. [params setValue:appDelegate.password forKey:@"password"];
  3262. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  3263. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  3264. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  3265. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  3266. if(appDelegate.offline_mode)
  3267. {
  3268. //params[@"offline_Command"]=url;
  3269. return [OLDataProvider offline_home];
  3270. }
  3271. if(![self IsNetworkAvailable])
  3272. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3273. NSData* json=[self get_json:URL_LOAD_HOME parameters:params];
  3274. if(json==nil)
  3275. return nil;
  3276. NSError *error=nil;
  3277. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3278. return jsobj;
  3279. }
  3280. //+(NSDictionary*)logout
  3281. //{
  3282. //
  3283. //
  3284. //
  3285. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3286. // __block AppDelegate *appDelegate = nil;
  3287. //
  3288. // dispatch_sync(dispatch_get_main_queue(), ^{
  3289. // //some UI methods ej
  3290. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3291. // });
  3292. // if(appDelegate.user!=nil)
  3293. // [params setValue:appDelegate.user forKey:@"user"];
  3294. //
  3295. //
  3296. // if(appDelegate.password!=nil)
  3297. // [params setValue:appDelegate.password forKey:@"password"];
  3298. //
  3299. //
  3300. // if(appDelegate.offline_mode)
  3301. // {
  3302. // return [OLDataProvider offline_logout:params];
  3303. // }
  3304. // if(![self IsNetworkAvailable])
  3305. // {
  3306. // DebugLog(@"NET ERR");
  3307. //
  3308. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3309. // // return nil;
  3310. // }
  3311. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  3312. // //if(json==nil)
  3313. //
  3314. //
  3315. // if(json==nil)
  3316. // return nil;
  3317. // NSError *error=nil;
  3318. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3319. // int result = [[jsobj valueForKey:@"result"] intValue];
  3320. //
  3321. // if (result==2)
  3322. // {
  3323. //
  3324. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  3325. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  3326. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  3327. //
  3328. // [appDelegate update_count_mark];
  3329. //
  3330. //
  3331. // appDelegate.can_show_price =false;
  3332. // appDelegate.can_see_price =false;
  3333. // appDelegate.can_create_portfolio =false;
  3334. // appDelegate.can_create_order =false;
  3335. //
  3336. //
  3337. // appDelegate.can_cancel_order =false;
  3338. // appDelegate.can_set_cart_price =false;
  3339. // appDelegate.can_delete_order =false;
  3340. // appDelegate.can_submit_order =false;
  3341. // appDelegate.can_set_tearsheet_price =false;
  3342. // appDelegate.can_update_contact_info = false;
  3343. //
  3344. // appDelegate.save_order_logout = false;
  3345. // appDelegate.submit_order_logout = false;
  3346. // appDelegate.alert_sold_in_quantities = false;
  3347. //
  3348. // appDelegate.ipad_perm =nil ;
  3349. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  3350. // appDelegate.OrderFilter= nil;
  3351. // [appDelegate SetSo:nil];
  3352. // [appDelegate set_main_button_panel];
  3353. //#ifdef RA_NOTIFICATION
  3354. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  3355. //#endif
  3356. // }
  3357. // return jsobj;
  3358. //}
  3359. +(NSDictionary*)request_Cagegory
  3360. {
  3361. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  3362. __block AppDelegate *appDelegate = nil;
  3363. dispatch_sync(dispatch_get_main_queue(), ^{
  3364. //some UI methods ej
  3365. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3366. });
  3367. if(appDelegate.offline_mode)
  3368. {
  3369. //params[@"offline_Command"]=url;
  3370. return [OLDataProvider offline_category_menu];
  3371. }
  3372. if(![self IsNetworkAvailable])
  3373. {
  3374. DebugLog(@"NET ERR");
  3375. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3376. // return nil;
  3377. }
  3378. NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  3379. //if(json==nil)
  3380. if(json==nil)
  3381. return nil;
  3382. NSError *error=nil;
  3383. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3384. return jsobj;
  3385. }
  3386. +(int)Authorize : (NSString*) user password:(NSString*) password{
  3387. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  3388. // return RESULT_NET_ERROR;
  3389. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3390. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3391. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3392. __block AppDelegate *appDelegate = nil;
  3393. dispatch_sync(dispatch_get_main_queue(), ^{
  3394. //some UI methods ej
  3395. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3396. });
  3397. if(RASingleton.sharedInstance.duid !=nil)
  3398. [params setValue:RASingleton.sharedInstance.duid forKey:@"udid"];
  3399. [params setValue:@"handset_login" forKey:@"action"];
  3400. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  3401. [params setValue:user forKey:@"user"];
  3402. [params setValue:password forKey:@"password"];
  3403. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  3404. #ifdef TEST
  3405. [params setValue:@"true" forKey:@"is_debug"];
  3406. #else
  3407. [params setValue:@"false" forKey:@"is_debug"];
  3408. #endif
  3409. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  3410. [params setObject:@"Login" forKey:kAction];
  3411. NSData* json= nil;
  3412. if(appDelegate.offline_mode)
  3413. {
  3414. json= [OLDataProvider offline_login:params] ;
  3415. }
  3416. else
  3417. {
  3418. if(![self IsNetworkAvailable])
  3419. return RESULT_NET_NOTAVAILABLE;
  3420. json =[self get_json:URL_UPDATE_AUTH parameters:params];
  3421. }
  3422. if(json==nil)
  3423. return RESULT_NET_ERROR;
  3424. int ret = [self parse_authinfo:json user:user password:password];
  3425. DebugLog(@"parse_authinfo return %d ",ret);
  3426. return ret;
  3427. }
  3428. +(NSDictionary*)update_customer_img: (NSString*) contactid img_url:(NSString*) url
  3429. {
  3430. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3431. __block AppDelegate *appDelegate = nil;
  3432. dispatch_sync(dispatch_get_main_queue(), ^{
  3433. //some UI methods ej
  3434. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3435. });
  3436. if(appDelegate.user!=nil)
  3437. [params setValue:appDelegate.user forKey:@"user"];
  3438. // if(appDelegate.contact_id!=nil)
  3439. if(appDelegate.password!=nil)
  3440. [params setValue:appDelegate.password forKey:@"password"];
  3441. [params setValue:contactid forKey:@"contactId"];
  3442. [params setValue:url forKey:@"business_card"];
  3443. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  3444. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  3445. if(appDelegate.offline_mode)
  3446. {
  3447. return [OLDataProvider offline_notimpl];
  3448. }
  3449. if(![self IsNetworkAvailable])
  3450. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3451. NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  3452. if(json==nil)
  3453. return nil;
  3454. NSError *error=nil;
  3455. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3456. return jsobj;
  3457. }
  3458. +(NSDictionary*)request_PendingOrder:(NSString *)contactid
  3459. {
  3460. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3461. __block AppDelegate *appDelegate = nil;
  3462. dispatch_sync(dispatch_get_main_queue(), ^{
  3463. //some UI methods ej
  3464. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3465. });
  3466. if(appDelegate.user!=nil)
  3467. [params setValue:appDelegate.user forKey:@"user"];
  3468. // if(appDelegate.contact_id!=nil)
  3469. if(appDelegate.password!=nil)
  3470. [params setValue:appDelegate.password forKey:@"password"];
  3471. [params setValue:contactid forKey:@"contactId"];
  3472. if(appDelegate.offline_mode)
  3473. {
  3474. return [OLDataProvider offline_notimpl];
  3475. }
  3476. if(![self IsNetworkAvailable])
  3477. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3478. NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  3479. if(json==nil)
  3480. return nil;
  3481. NSError *error=nil;
  3482. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3483. return jsobj;
  3484. }
  3485. //+(NSDictionary*)request_CustomerInfo:(NSString* ) contactid
  3486. //{
  3487. //
  3488. //
  3489. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3490. // __block AppDelegate *appDelegate = nil;
  3491. //
  3492. // dispatch_sync(dispatch_get_main_queue(), ^{
  3493. // //some UI methods ej
  3494. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3495. // });
  3496. // if(appDelegate.user!=nil)
  3497. // [params setValue:appDelegate.user forKey:@"user"];
  3498. // // if(appDelegate.contact_id!=nil)
  3499. //
  3500. // if(appDelegate.password!=nil)
  3501. // [params setValue:appDelegate.password forKey:@"password"];
  3502. // [params setValue:contactid forKey:@"contactId"];
  3503. //
  3504. // [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  3505. //
  3506. // if(appDelegate.offline_mode)
  3507. // return [OLDataProvider offline_contactinfo:params];
  3508. // if(![self IsNetworkAvailable])
  3509. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3510. //
  3511. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  3512. // if(json==nil)
  3513. // return nil;
  3514. // NSError *error=nil;
  3515. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3516. // return jsobj;
  3517. //
  3518. //}
  3519. +(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
  3520. {
  3521. DebugLog(@"parse_authinfo");
  3522. NSError *error=nil;
  3523. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3524. if(jsobj)
  3525. {
  3526. __block AppDelegate *appDelegate = nil;
  3527. dispatch_sync(dispatch_get_main_queue(), ^{
  3528. //some UI methods ej
  3529. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3530. });
  3531. int result = [[jsobj valueForKey:@"result"] intValue];
  3532. if (result<0)
  3533. return result;
  3534. if(result!=AP_USER_AUTH&& result!=9)
  3535. {
  3536. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  3537. // [appDelegate Logout];
  3538. if(result==8)
  3539. {
  3540. return RESULT_LOGIN_DEVICE;
  3541. }
  3542. return RESULT_FALSE;
  3543. }
  3544. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  3545. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  3546. user=[objheader objectForKey:@"username"] ;
  3547. DebugLog(@"required_ver=%@ ",required_ver);
  3548. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  3549. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  3550. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  3551. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  3552. // if([ibadge isEqual:[NSNull null]])
  3553. // strbadge=@"0";
  3554. // if(ibadge==nil)
  3555. // ibadge=@"0";
  3556. // if([strbadge isEqualToString:@"null"])
  3557. // strbadge=@"0";
  3558. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  3559. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  3560. if([appDelegate.build intValue]<[required_ver intValue])
  3561. return RESULT_VER_LOW;
  3562. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  3563. appDelegate.user = user;
  3564. appDelegate.password = password;
  3565. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  3566. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  3567. appDelegate.bLogin = true;
  3568. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  3569. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  3570. {
  3571. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  3572. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  3573. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  3574. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  3575. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  3576. }
  3577. NSString* mode =[jsobj valueForKey:@"mode"] ;
  3578. [appDelegate SetMode:mode];
  3579. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  3580. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  3581. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  3582. [appDelegate update_count_mark];
  3583. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  3584. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  3585. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  3586. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  3587. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  3588. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  3589. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  3590. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  3591. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  3592. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  3593. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  3594. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  3595. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  3596. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  3597. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  3598. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  3599. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  3600. [appDelegate set_main_button_panel];
  3601. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  3602. // shop order status filter
  3603. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  3604. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  3605. // Sales order status filter
  3606. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  3607. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  3608. // specialInstruction
  3609. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  3610. //-价格类型
  3611. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  3612. // 权限
  3613. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  3614. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  3615. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  3616. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  3617. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  3618. [[RASingleton sharedInstance] resetGlobalLock];
  3619. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  3620. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  3621. }
  3622. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  3623. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  3624. // {
  3625. // // no update on the server;
  3626. // return RESULT_TRUE;
  3627. // }
  3628. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  3629. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  3630. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3631. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  3632. // [defaults synchronize];
  3633. //
  3634. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  3635. // NSArray* keys= [objfuncs allKeys];
  3636. /*
  3637. db.setTransactionSuccessful();
  3638. db.endTransaction();
  3639. */
  3640. return RESULT_TRUE;
  3641. }
  3642. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  3643. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  3644. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  3645. return RESULT_USERAUTH_ERROR;
  3646. }
  3647. //+(bool) IsNetworkAvailable
  3648. //{
  3649. //
  3650. // if (([Reachability reachabilityForInternetConnection].currentReachabilityStatus == NotReachable) &&
  3651. // ([Reachability reachabilityForLocalWiFi].currentReachabilityStatus == NotReachable))
  3652. // return false;
  3653. // return true;
  3654. //}
  3655. //+(NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim
  3656. //{
  3657. // NSScanner *theScanner = [NSScanner scannerWithString:html];
  3658. // NSString *text = nil;
  3659. //
  3660. // while ([theScanner isAtEnd] == NO) {
  3661. // // find start of tag
  3662. // [theScanner scanUpToString:@"<" intoString:NULL] ;
  3663. // // find end of tag
  3664. // [theScanner scanUpToString:@">" intoString:&text] ;
  3665. // // replace the found tag with a space
  3666. // //(you can filter multi-spaces out later if you wish)
  3667. // html = [html stringByReplacingOccurrencesOfString:
  3668. // [ NSString stringWithFormat:@"%@>", text]
  3669. // withString:@""];
  3670. // }
  3671. //
  3672. // return trim ? [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : html;
  3673. //}
  3674. //
  3675. //+(NSString *)flattenURL:(NSString *)url trimWhiteSpace:(BOOL)trim
  3676. //{
  3677. // NSScanner *theScanner = [NSScanner scannerWithString:url];
  3678. // NSString *text = nil;
  3679. //
  3680. // while ([theScanner isAtEnd] == NO) {
  3681. // // find start of tag
  3682. // [theScanner scanUpToString:@"/" intoString:NULL] ;
  3683. // // find end of tag
  3684. // [theScanner scanUpToString:@"/" intoString:&text] ;
  3685. // // replace the found tag with a space
  3686. // //(you can filter multi-spaces out later if you wish)
  3687. // url = [url stringByReplacingOccurrencesOfString:
  3688. // [ NSString stringWithFormat:@"%@", text]
  3689. // withString:@""];
  3690. // }
  3691. //
  3692. // return trim ? [url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : url;
  3693. //}
  3694. + (NSDictionary *)set_npd_shop_price_type:(NSInteger)priceType {
  3695. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3696. __block AppDelegate *appDelegate = nil;
  3697. dispatch_sync(dispatch_get_main_queue(), ^{
  3698. //some UI methods ej
  3699. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3700. });
  3701. if(appDelegate.user!=nil)
  3702. [dic setValue:appDelegate.user forKey:@"user"];
  3703. if(appDelegate.password!=nil)
  3704. [dic setValue:appDelegate.password forKey:@"password"];
  3705. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  3706. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  3707. NSData* json=nil;
  3708. if(appDelegate.offline_mode)
  3709. {
  3710. return [OLDataProvider offline_notimpl];
  3711. }
  3712. else
  3713. {
  3714. if(![self IsNetworkAvailable])
  3715. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3716. json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  3717. }
  3718. if(json!=nil)
  3719. {
  3720. NSError *error=nil;
  3721. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3722. return jsobj;
  3723. }
  3724. return nil;
  3725. }
  3726. + (NSDictionary *)get_npd_shop_givenPrice {
  3727. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3728. __block AppDelegate *appDelegate = nil;
  3729. dispatch_sync(dispatch_get_main_queue(), ^{
  3730. //some UI methods ej
  3731. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3732. });
  3733. if(appDelegate.user!=nil)
  3734. [dic setValue:appDelegate.user forKey:@"user"];
  3735. if(appDelegate.password!=nil)
  3736. [dic setValue:appDelegate.password forKey:@"password"];
  3737. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  3738. NSData* json=nil;
  3739. if(appDelegate.offline_mode)
  3740. {
  3741. return [OLDataProvider offline_notimpl];
  3742. }
  3743. else
  3744. {
  3745. if(![self IsNetworkAvailable])
  3746. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3747. json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  3748. }
  3749. if(json!=nil)
  3750. {
  3751. NSError *error=nil;
  3752. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3753. return jsobj;
  3754. }
  3755. return nil;
  3756. }
  3757. + (NSDictionary *)set_npd_shop_givenPrice:(NSMutableDictionary *)params {
  3758. __block AppDelegate *appDelegate = nil;
  3759. dispatch_sync(dispatch_get_main_queue(), ^{
  3760. //some UI methods ej
  3761. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3762. });
  3763. if(appDelegate.user!=nil)
  3764. [params setValue:appDelegate.user forKey:@"user"];
  3765. if(appDelegate.password!=nil)
  3766. [params setValue:appDelegate.password forKey:@"password"];
  3767. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  3768. NSData* json=nil;
  3769. if(appDelegate.offline_mode)
  3770. {
  3771. return [OLDataProvider offline_notimpl];
  3772. }
  3773. else
  3774. {
  3775. if(![self IsNetworkAvailable])
  3776. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3777. json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  3778. }
  3779. if(json!=nil)
  3780. {
  3781. NSError *error=nil;
  3782. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3783. return jsobj;
  3784. }
  3785. return nil;
  3786. }
  3787. + (NSDictionary *)merge_order:(NSMutableDictionary *)params {
  3788. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3789. __block AppDelegate *appDelegate = nil;
  3790. dispatch_sync(dispatch_get_main_queue(), ^{
  3791. //some UI methods ej
  3792. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3793. });
  3794. if(appDelegate.user!=nil)
  3795. [dic setValue:appDelegate.user forKey:@"user"];
  3796. if(appDelegate.password!=nil)
  3797. [dic setValue:appDelegate.password forKey:@"password"];
  3798. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  3799. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  3800. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  3801. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  3802. NSData* json=nil;
  3803. if(appDelegate.offline_mode)
  3804. {
  3805. return [OLDataProvider offline_notimpl];
  3806. }
  3807. else
  3808. {
  3809. if(![self IsNetworkAvailable])
  3810. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3811. json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  3812. }
  3813. if(json!=nil)
  3814. {
  3815. NSError *error=nil;
  3816. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3817. return jsobj;
  3818. }
  3819. else
  3820. return nil;
  3821. }
  3822. //+ (NSDictionary *)lock_order:(NSString *)oderCode
  3823. //{
  3824. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  3825. // __block AppDelegate *appDelegate = nil;
  3826. //
  3827. // dispatch_sync(dispatch_get_main_queue(), ^{
  3828. // //some UI methods ej
  3829. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3830. // });
  3831. // if(appDelegate.user!=nil)
  3832. // [params setValue:appDelegate.user forKey:@"user"];
  3833. //
  3834. // if(appDelegate.password!=nil)
  3835. // [params setValue:appDelegate.password forKey:@"password"];
  3836. //
  3837. // [params setValue:oderCode forKey:@"orderCode"];
  3838. //
  3839. // NSData* json=nil;
  3840. // if(appDelegate.offline_mode)
  3841. // {
  3842. // json=[OLDataProvider offline_editorder:params];
  3843. //
  3844. // }
  3845. // else
  3846. // {
  3847. // if(![self IsNetworkAvailable])
  3848. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3849. //
  3850. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  3851. // }
  3852. // if(json!=nil)
  3853. // {
  3854. // NSError *error=nil;
  3855. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3856. //
  3857. // return jsobj;
  3858. // }
  3859. // else
  3860. // return nil;
  3861. //}
  3862. + (NSDictionary *)quoteOrder:(NSString *)so_id emailAddr:(NSString *)addr {
  3863. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3864. __block AppDelegate *appDelegate = nil;
  3865. dispatch_sync(dispatch_get_main_queue(), ^{
  3866. //some UI methods ej
  3867. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3868. });
  3869. if(appDelegate.user!=nil)
  3870. [dic setValue:appDelegate.user forKey:@"user"];
  3871. if(appDelegate.password!=nil)
  3872. [dic setValue:appDelegate.password forKey:@"password"];
  3873. [dic setValue:so_id forKey:@"orderCode"];
  3874. [dic setValue:addr forKey:@"email"];
  3875. [dic setObject:ScreenCodeCart forKey:kScreenName];
  3876. if (appDelegate.customerInfo) {
  3877. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  3878. if (customer_cid) {
  3879. [dic setValue:customer_cid forKey:@"contactId"];
  3880. }
  3881. }
  3882. NSData* json=nil;
  3883. if(appDelegate.offline_mode)
  3884. {
  3885. return [OLDataProvider offline_notimpl];
  3886. }
  3887. else
  3888. {
  3889. if(![self IsNetworkAvailable])
  3890. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3891. json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  3892. }
  3893. if(json!=nil)
  3894. {
  3895. NSError *error=nil;
  3896. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3897. return jsobj;
  3898. }
  3899. return @{@"result" : @(RESULT_FALSE)};
  3900. }
  3901. + (NSDictionary *)notifyModel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName{
  3902. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3903. __block AppDelegate *appDelegate = nil;
  3904. dispatch_sync(dispatch_get_main_queue(), ^{
  3905. //some UI methods ej
  3906. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3907. });
  3908. if(appDelegate.user!=nil)
  3909. [dic setValue:appDelegate.user forKey:@"user"];
  3910. if(appDelegate.password!=nil)
  3911. [dic setValue:appDelegate.password forKey:@"password"];
  3912. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  3913. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  3914. if (customer_cid) {
  3915. [dic setValue:customer_cid forKey:@"contactId"];
  3916. }
  3917. }
  3918. [dic setObject:screenName forKey:kScreenName];
  3919. [dic setValue:modelID forKey:@"productId"];
  3920. if (addr) { // 弹框输入
  3921. [dic setValue:addr forKey:@"email"];
  3922. } else {
  3923. // employee选择了Contact,并且Contact有Email
  3924. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  3925. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  3926. // if (email) {
  3927. // [dic setValue:email forKey:@"email"];
  3928. // }
  3929. // }
  3930. }
  3931. NSData* json=nil;
  3932. if(appDelegate.offline_mode)
  3933. {
  3934. return [OLDataProvider offline_notimpl];
  3935. }
  3936. else
  3937. {
  3938. if(![self IsNetworkAvailable])
  3939. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3940. json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  3941. }
  3942. if(json!=nil)
  3943. {
  3944. NSError *error=nil;
  3945. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3946. return jsobj;
  3947. }
  3948. return @{@"result" : @(RESULT_FALSE)};
  3949. }
  3950. + (NSDictionary *)quoteWishlist2EmailAddr:(NSString *)addr {
  3951. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3952. __block AppDelegate *appDelegate = nil;
  3953. dispatch_sync(dispatch_get_main_queue(), ^{
  3954. //some UI methods ej
  3955. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3956. });
  3957. if(appDelegate.user!=nil)
  3958. [dic setValue:appDelegate.user forKey:@"user"];
  3959. if(appDelegate.password!=nil)
  3960. [dic setValue:appDelegate.password forKey:@"password"];
  3961. [dic setValue:addr forKey:@"email"];
  3962. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  3963. // if (appDelegate.customerInfo) {
  3964. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  3965. // if (customer_cid) {
  3966. // [dic setValue:customer_cid forKey:@"contactId"];
  3967. // }
  3968. // }
  3969. NSData* json=nil;
  3970. if(appDelegate.offline_mode)
  3971. {
  3972. return [OLDataProvider offline_notimpl];
  3973. }
  3974. else
  3975. {
  3976. if(![self IsNetworkAvailable])
  3977. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  3978. json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  3979. }
  3980. if(json!=nil)
  3981. {
  3982. NSError *error=nil;
  3983. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  3984. return jsobj;
  3985. }
  3986. return @{@"result" : @(RESULT_FALSE)};
  3987. }
  3988. + (NSDictionary *)movetobackorder:(NSString *)cart_item_id {
  3989. if (cart_item_id == nil || cart_item_id.length < 1) {
  3990. return @{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"};
  3991. }
  3992. __block AppDelegate *appDelegate = nil;
  3993. dispatch_sync(dispatch_get_main_queue(), ^{
  3994. //some UI methods ej
  3995. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  3996. });
  3997. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  3998. if(appDelegate.user!=nil)
  3999. [dic setValue:appDelegate.user forKey:@"user"];
  4000. if(appDelegate.password!=nil)
  4001. [dic setValue:appDelegate.password forKey:@"password"];
  4002. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  4003. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  4004. [dic setObject:ScreenCodeCart forKey:kScreenName];
  4005. if(![self IsNetworkAvailable])
  4006. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4007. NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  4008. if(json!=nil)
  4009. {
  4010. NSError *error=nil;
  4011. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4012. return jsobj;
  4013. }
  4014. return @{@"result" : @(RESULT_FALSE)};
  4015. }
  4016. + (NSDictionary*)request_hangTag:(NSString *)group {
  4017. #ifdef BUILD_UWAVER
  4018. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4019. __block AppDelegate *appDelegate = nil;
  4020. dispatch_sync(dispatch_get_main_queue(), ^{
  4021. //some UI methods ej
  4022. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4023. });
  4024. if(appDelegate.user!=nil)
  4025. [params setValue:appDelegate.user forKey:@"user"];
  4026. if(appDelegate.contact_id!=nil)
  4027. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4028. if(appDelegate.password!=nil)
  4029. [params setValue:appDelegate.password forKey:@"password"];
  4030. if (group) {
  4031. [params setValue:group forKey:@"groupName"];
  4032. }
  4033. NSString * uuid= [[NSUUID UUID] UUIDString];
  4034. params[@"resultSerial"]=uuid;
  4035. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4036. NSData* json = nil;
  4037. if(appDelegate.offline_mode)
  4038. {
  4039. return [OLDataProvider offline_notimpl];
  4040. } else {
  4041. if(![self IsNetworkAvailable])
  4042. return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4043. json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  4044. }
  4045. if(json==nil)
  4046. return nil;
  4047. NSError *error=nil;
  4048. NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4049. return jsobj;
  4050. #else
  4051. return nil;
  4052. #endif
  4053. }
  4054. #pragma mark 2020 new interface
  4055. // 新接口逐步替换以前的网络请求,2020
  4056. +(void)request_home:(int) price_template customid:(int) customid completionHandler:(resultHandler)result
  4057. {
  4058. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4059. AppDelegate *appDelegate = nil;
  4060. //some UI methods ej
  4061. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4062. if(appDelegate.user!=nil)
  4063. [params setValue:appDelegate.user forKey:@"user"];
  4064. if(appDelegate.contact_id!=nil)
  4065. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4066. if(appDelegate.password!=nil)
  4067. [params setValue:appDelegate.password forKey:@"password"];
  4068. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4069. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4070. [params setObject:ScreenCodeHomeView forKey:kScreenName];
  4071. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  4072. if(appDelegate.offline_mode)
  4073. {
  4074. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4075. NSMutableDictionary* json = [[OLDataProvider offline_home] mutableCopy];
  4076. dispatch_async(dispatch_get_main_queue(), ^{
  4077. result(json);
  4078. });
  4079. });
  4080. return;
  4081. }
  4082. [self request_interface:URL_LOAD_HOME parameters:params err_record_url:nil completionHandler:result retry:0];
  4083. return;
  4084. }
  4085. +(void)request_category:(resultHandler)result
  4086. {
  4087. // DebugLog(@"@@@@@@@@@@@@@@@@@@@LOADING CATEGORY MENU");
  4088. AppDelegate *appDelegate = nil;
  4089. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4090. if(appDelegate.offline_mode)
  4091. {
  4092. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4093. NSMutableDictionary* json = [[OLDataProvider offline_category_menu] mutableCopy];
  4094. dispatch_async(dispatch_get_main_queue(), ^{
  4095. result(json);
  4096. });
  4097. });
  4098. return;
  4099. }
  4100. [self request_interface:URL_REQUEST_CATMENU parameters:[NSMutableDictionary new] err_record_url:nil completionHandler:result retry:0];
  4101. //
  4102. // if(![self IsNetworkAvailable])
  4103. // {
  4104. // DebugLog(@"NET ERR");
  4105. //
  4106. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4107. // // return nil;
  4108. // }
  4109. //
  4110. // NSData* json=[self get_json:URL_REQUEST_CATMENU parameters:nil];
  4111. // //if(json==nil)
  4112. //
  4113. //
  4114. // if(json==nil)
  4115. // return nil;
  4116. // NSError *error=nil;
  4117. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4118. // return jsobj;
  4119. }
  4120. +(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
  4121. {
  4122. AppDelegate *appDelegate = nil;
  4123. //some UI methods ej
  4124. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4125. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4126. if(appDelegate.user!=nil)
  4127. [params setValue:appDelegate.user forKey:@"user"];
  4128. if(appDelegate.contact_id!=nil)
  4129. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4130. if(appDelegate.password!=nil)
  4131. [params setValue:appDelegate.password forKey:@"password"];
  4132. if(appDelegate.order_code!=nil)
  4133. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4134. [params setValue:alert forKey:@"alert"];
  4135. [params setValue:qty forKey:@"sold_by_qty"];
  4136. [params setValue:available forKey:@"available"];
  4137. [params setValue:price forKey:@"price"];
  4138. [params setValue:bestseller forKey:@"bestseller"];
  4139. [params setValue:modelname forKey:@"modelName"];
  4140. [params setValue:modeldescrip forKey:@"modelDescription"];
  4141. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4142. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4143. [params setValue:category forKey:@"category"];
  4144. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4145. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4146. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4147. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4148. [params setValue:filter forKey:@"filter"];
  4149. [params setValue:keyword forKey:@"keyword"];
  4150. [params setObject:ScreenCodeCategory forKey:kScreenName];
  4151. if (alert) {
  4152. [params setObject:@"Filter" forKey:kAction];
  4153. }
  4154. if ([RASingleton sharedInstance].homeItemClick) {
  4155. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  4156. [RASingleton sharedInstance].homeItemClick = NO;
  4157. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  4158. [RASingleton sharedInstance].homeClickedItemName = nil;
  4159. [params setObject:extra forKey:kExtra];
  4160. }
  4161. if(appDelegate.offline_mode)
  4162. {
  4163. // [OLDataProvider offline_category:params completionHandler:result];
  4164. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4165. NSMutableDictionary* json = [[OLDataProvider offline_category:params] mutableCopy];
  4166. dispatch_async(dispatch_get_main_queue(), ^{
  4167. result(json);
  4168. });
  4169. });
  4170. return;
  4171. }
  4172. [self request_interface:URL_CATEGORY parameters:params err_record_url:nil completionHandler:result retry:0];
  4173. return ;
  4174. //
  4175. // if(![self IsNetworkAvailable])
  4176. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4177. //
  4178. // NSData* json=[self get_json:URL_CATEGORY parameters:params];
  4179. // if(json==nil)
  4180. // return nil;
  4181. // NSError *error=nil;
  4182. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4183. // return jsobj;
  4184. //
  4185. }
  4186. +(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
  4187. {
  4188. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4189. AppDelegate *appDelegate = nil;
  4190. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4191. if(appDelegate.user!=nil)
  4192. [params setValue:appDelegate.user forKey:@"user"];
  4193. if(appDelegate.contact_id!=nil)
  4194. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4195. if(appDelegate.password!=nil)
  4196. [params setValue:appDelegate.password forKey:@"password"];
  4197. if(appDelegate.order_code!=nil)
  4198. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4199. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4200. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4201. if(use_name)
  4202. [params setValue:model_name forKey:@"product_name"];
  4203. else
  4204. if(use_upc){
  4205. params[@"search_upc"]=@true;
  4206. [params setValue:upc_code forKey:@"upc_code"];
  4207. }
  4208. else
  4209. [params setValue:item_id forKey:@"product_id"];
  4210. [params setValue:category_id forKey:@"category"];
  4211. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  4212. [params setObject:@"Open A Model" forKey:kAction];
  4213. if (model_name) {
  4214. NSDictionary *extra = @{@"ModelName" : model_name};
  4215. [params setObject:extra forKey:kExtra];
  4216. }
  4217. if (groupName.length > 0) {
  4218. [params setObject:groupName forKey:@"groupName"];
  4219. }
  4220. if(appDelegate.offline_mode)
  4221. {
  4222. [OLDataProvider offline_model:params completionHandler:result];
  4223. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4224. // NSMutableDictionary* json = [[OLDataProvider offline_model:params] mutableCopy];
  4225. // dispatch_async(dispatch_get_main_queue(), ^{
  4226. // result(json);
  4227. // });
  4228. // });
  4229. return;
  4230. }
  4231. [self request_interface:URL_ITEM_DETAIL parameters:params err_record_url:nil completionHandler:result retry:0];
  4232. //
  4233. // if(appDelegate.offline_mode)
  4234. // return [OLDataProvider offline_model:params];
  4235. //
  4236. // if(![self IsNetworkAvailable])
  4237. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4238. //
  4239. // NSData* json=[self get_json:URL_ITEM_DETAIL parameters:params];
  4240. // if(json==nil)
  4241. // return nil;
  4242. // NSError *error=nil;
  4243. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4244. // return jsobj;
  4245. }
  4246. +(void)request_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull completionHandler:(resultHandler)result
  4247. {
  4248. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4249. AppDelegate *appDelegate = nil;
  4250. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4251. if(appDelegate.user!=nil)
  4252. [params setValue:appDelegate.user forKey:@"user"];
  4253. if(appDelegate.contact_id!=nil)
  4254. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4255. if(appDelegate.password!=nil)
  4256. [params setValue:appDelegate.password forKey:@"password"];
  4257. if(appDelegate.order_code!=nil)
  4258. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4259. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4260. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4261. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  4262. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4263. // [params setValue:filter forKey:@"filter"];
  4264. [params setValue:keywords forKey:@"keyword"];
  4265. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  4266. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  4267. if(matchfull)
  4268. [params setValue:@"true" forKey:@"exactMatch"];
  4269. else
  4270. [params setValue:@"false" forKey:@"exactMatch"];
  4271. [params setObject:ScreenCodeSearch forKey:kScreenName];
  4272. if (keywords) {
  4273. [params setObject:@"Search" forKey:kAction];
  4274. }
  4275. if(appDelegate.offline_mode)
  4276. {
  4277. // [OLDataProvider offline_search:params completionHandler:result];
  4278. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4279. NSMutableDictionary* json = [[OLDataProvider offline_search:params] mutableCopy];
  4280. dispatch_async(dispatch_get_main_queue(), ^{
  4281. result(json);
  4282. });
  4283. });
  4284. return;
  4285. }
  4286. [self request_interface:URL_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  4287. // if(appDelegate.offline_mode)
  4288. // {
  4289. // return [OLDataProvider offline_search:params];
  4290. // }
  4291. // if(![self IsNetworkAvailable])
  4292. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4293. //
  4294. // NSData* json=[self get_json:URL_SEARCH parameters:params];
  4295. // if(json==nil)
  4296. // return nil;
  4297. // NSError *error=nil;
  4298. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4299. // return jsobj;
  4300. }
  4301. +(void)request_login: (NSString*) user password:(NSString*) password completionHandler:(resultHandler)result
  4302. {
  4303. // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
  4304. // return RESULT_NET_ERROR;
  4305. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4306. long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4307. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4308. AppDelegate *appDelegate = nil;
  4309. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4310. if(RASingleton.sharedInstance.duid !=nil)
  4311. [params setValue:RASingleton.sharedInstance.duid forKey:@"udid"];
  4312. [params setValue:@"handset_login" forKey:@"action"];
  4313. // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
  4314. [params setValue:user forKey:@"user"];
  4315. [params setValue:password forKey:@"password"];
  4316. [params setValue:[NSString stringWithFormat:@"%ld",ver] forKey:@"auth_ver"];
  4317. #ifdef TEST
  4318. [params setValue:@"true" forKey:@"is_debug"];
  4319. #else
  4320. [params setValue:@"false" forKey:@"is_debug"];
  4321. #endif
  4322. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  4323. [params setObject:@"Login" forKey:kAction];
  4324. if(appDelegate.offline_mode)
  4325. {
  4326. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4327. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_login:params]] mutableCopy];
  4328. dispatch_async(dispatch_get_main_queue(), ^{
  4329. int ret = [self parse_logininfo:json user:user password:password] ;
  4330. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4331. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4332. result(retjson);
  4333. });
  4334. });
  4335. return;
  4336. }
  4337. NSString* url;
  4338. bool scan_guest = false;
  4339. #ifdef SCANNER_ORDER
  4340. params[@"site_name"]=[RADataProvider getSiteName];
  4341. params[@"_method"]=@"login";
  4342. url = [appDelegate.address stringByAppendingPathComponent:URL_UPDATE_AUTH];
  4343. if([user.uppercaseString isEqualToString:@"GUEST"]&&[password.uppercaseString isEqualToString:@"GUEST"])
  4344. scan_guest = true;
  4345. #else
  4346. url = URL_UPDATE_AUTH;
  4347. #endif
  4348. if(scan_guest)
  4349. {
  4350. [OLDataProvider realguestLogin];
  4351. // int ret = [self parse_logininfo:chresult user:user password:password] ;
  4352. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4353. retjson[@"result"]= [NSNumber numberWithInt:RESULT_TRUE];
  4354. result(retjson);
  4355. }
  4356. else
  4357. {
  4358. [self request_interface:url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *chresult) {
  4359. int ret = [self parse_logininfo:chresult user:user password:password] ;
  4360. NSMutableDictionary * retjson = [NSMutableDictionary new];
  4361. retjson[@"result"]= [NSNumber numberWithInt:ret];
  4362. result(retjson);
  4363. } retry:0];
  4364. }
  4365. //
  4366. // NSData* json= nil;
  4367. // if(appDelegate.offline_mode)
  4368. // {
  4369. // json= [OLDataProvider offline_login:params] ;
  4370. //
  4371. // }
  4372. // else
  4373. // {
  4374. // if(![self IsNetworkAvailable])
  4375. // return RESULT_NET_NOTAVAILABLE;
  4376. // json =[self get_json:URL_UPDATE_AUTH parameters:params];
  4377. //
  4378. // }
  4379. //
  4380. // if(json==nil)
  4381. // return RESULT_NET_ERROR;
  4382. //
  4383. // int ret = [self parse_authinfo:json user:user password:password];
  4384. // DebugLog(@"parse_authinfo return %d ",ret);
  4385. //
  4386. //
  4387. // return ret;
  4388. //
  4389. }
  4390. +(int)parse_logininfo : (NSMutableDictionary *) jsobj user:(NSString*) user password:(NSString*) password
  4391. {
  4392. // DebugLog(@"parse_authinfo");
  4393. // NSError *error=nil;
  4394. //
  4395. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4396. if(jsobj)
  4397. {
  4398. AppDelegate *appDelegate = nil;
  4399. //some UI methods ej
  4400. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4401. int result = [[jsobj valueForKey:@"result"] intValue];
  4402. if (result<0)
  4403. return result;
  4404. if(result!=AP_USER_AUTH&& result!=9)
  4405. {
  4406. DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
  4407. // [appDelegate Logout];
  4408. if(result==8)
  4409. {
  4410. return RESULT_LOGIN_DEVICE;
  4411. }
  4412. return RESULT_FALSE;
  4413. }
  4414. NSDictionary* objheader = [jsobj objectForKey:@"header"];
  4415. NSString* required_ver=[jsobj objectForKey:@"min_ver"] ;
  4416. user=[objheader objectForKey:@"username"] ;
  4417. DebugLog(@"required_ver=%@ ",required_ver);
  4418. // NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
  4419. // NSString* versionNum =[infoDict valueForKey:@"CFBundleVersion"];
  4420. // versionNum = [NSString stringWithFormat:@"A%@",versionNum];
  4421. // int ibadge = [[objheader valueForKey:@"badge"] intValue];
  4422. // if([ibadge isEqual:[NSNull null]])
  4423. // strbadge=@"0";
  4424. // if(ibadge==nil)
  4425. // ibadge=@"0";
  4426. // if([strbadge isEqualToString:@"null"])
  4427. // strbadge=@"0";
  4428. // app.applicationIconBadgeNumber = ibadge;//[strbadge intValue];
  4429. // BOOL bigger = [appDelegate.build compare:required_ver] ;
  4430. #ifndef SCANNER_ORDER
  4431. if([appDelegate.build intValue]<[required_ver intValue])
  4432. return RESULT_VER_LOW;
  4433. #endif
  4434. // appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
  4435. appDelegate.user = user;
  4436. appDelegate.password = password;
  4437. appDelegate.user_type = [[objheader valueForKey:@"user_type"] intValue];
  4438. appDelegate.user_icon =[objheader valueForKey:@"user_img"] ;
  4439. appDelegate.bLogin = true;
  4440. appDelegate.customer_type = [[objheader valueForKey:@"customer_login_type"] intValue];
  4441. #ifdef SCANNER_ORDER
  4442. appDelegate.available_price_group = objheader[@"price_group"];
  4443. [RADataProvider default_price_group];
  4444. #endif
  4445. if(appDelegate.user_type==USER_ROLE_CUSTOMER)
  4446. {
  4447. appDelegate.customerInfo = [[objheader objectForKeyedSubscript:@"customerInfo"] mutableCopy];
  4448. appDelegate.contact_id = [objheader valueForKey:@"contact_id"];
  4449. // appDelegate.order_code =[objheader valueForKey:@"orderCode"];
  4450. // appDelegate.order_status =[[objheader valueForKey:@"orderStatus"] intValue];
  4451. // [appDelegate SetSo:[objheader valueForKey:@"soId"]];
  4452. }
  4453. NSString* mode =[jsobj valueForKey:@"mode"] ;
  4454. [appDelegate SetMode:mode];
  4455. appDelegate.cart_count = [[objheader valueForKey:@"cart_count"] intValue];
  4456. appDelegate.wish_count =[[objheader valueForKey:@"wish_count"] intValue];
  4457. appDelegate.port_count =[[objheader valueForKey:@"portfolio_count"] intValue];
  4458. [appDelegate update_count_mark];
  4459. appDelegate.can_show_price =[[objheader valueForKey:@"can_show_price"] boolValue];
  4460. appDelegate.can_see_price =[[objheader valueForKey:@"can_see_price"] boolValue];
  4461. appDelegate.can_create_portfolio =[[objheader valueForKey:@"can_create_portfolio"] boolValue];
  4462. appDelegate.can_create_order =[[objheader valueForKey:@"can_create_order"] boolValue];
  4463. appDelegate.can_cancel_order =[[objheader valueForKey:@"can_cancel_order"] boolValue];
  4464. appDelegate.can_set_cart_price =[[objheader valueForKey:@"can_set_cart_price"] boolValue];
  4465. appDelegate.can_delete_order =[[objheader valueForKey:@"can_delete_order"] boolValue];
  4466. appDelegate.can_update_contact_info =[[objheader valueForKey:@"can_update_contact_info"] boolValue];
  4467. appDelegate.can_submit_order =[[objheader valueForKey:@"can_submit_order"] boolValue];
  4468. appDelegate.can_set_tearsheet_price =[[objheader valueForKey:@"can_set_tearsheet_price"] boolValue];
  4469. appDelegate.save_order_logout =[[objheader valueForKey:@"save_order_logout"] boolValue];
  4470. appDelegate.submit_order_logout =[[objheader valueForKey:@"submit_order_logout"] boolValue];
  4471. appDelegate.alert_sold_in_quantities = [[objheader valueForKey:@"alert_sold_in_quantities"] boolValue];
  4472. appDelegate.can_create_backorder = [[objheader valueForKey:@"can_create_backorder"] boolValue];
  4473. appDelegate.ipad_perm =[objheader valueForKey:@"ipad_perm"] ;
  4474. NSString* strfilter = [objheader valueForKey:@"statusFilter"] ;
  4475. appDelegate.OrderFilter= [[RAConvertor string2dict:strfilter] mutableCopy];
  4476. [appDelegate set_main_button_panel];
  4477. if(appDelegate.user_type==USER_ROLE_CUSTOMER) {
  4478. // shop order status filter
  4479. NSString *shopOrderStatusFilterStr = [objheader valueForKey:@"shopOrderFilter"] ;
  4480. [RASingleton sharedInstance].shop_order_status_filter = [[RAConvertor string2dict:shopOrderStatusFilterStr] mutableCopy];
  4481. // Sales order status filter
  4482. NSString *salesOrderStatusFilterStr = [objheader valueForKey:@"purchaseOrderFilter"] ;
  4483. [RASingleton sharedInstance].sales_order_status_filter = [[RAConvertor string2dict:salesOrderStatusFilterStr] mutableCopy];
  4484. // specialInstruction
  4485. [RASingleton sharedInstance].specialInstruction = [objheader valueForKey:@"specialInstruction"];
  4486. //-价格类型
  4487. [RASingleton sharedInstance].npd_shop_price_type = [[objheader valueForKey:@"price_type"] integerValue];
  4488. // 权限
  4489. [RASingleton sharedInstance].permissions_price_setting = [[objheader valueForKey:@"can_set_price_formula"] boolValue];
  4490. [RASingleton sharedInstance].permissions_edit_order = [[objheader valueForKey:@"can_place_order"] boolValue];
  4491. [RASingleton sharedInstance].permissions_submit_order = [[objheader valueForKey:@"can_submit_order"] boolValue];
  4492. [RASingleton sharedInstance].permissions_merge_order = [[objheader valueForKey:@"can_merge_order"] boolValue];
  4493. [RASingleton sharedInstance].deliveryString = [objheader valueForKey:@"delivery_price"];
  4494. [[RASingleton sharedInstance] resetGlobalLock];
  4495. [RASingleton sharedInstance].customer_can_see_sales_Order = [[objheader valueForKey:@"can_see_salesorder"] boolValue];
  4496. [RASingleton sharedInstance].customerInfo = [objheader objectForKeyedSubscript:@"customerInfo"];
  4497. }
  4498. // DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
  4499. // if ([[objheader valueForKey:@"update"] boolValue]==false)
  4500. // {
  4501. // // no update on the server;
  4502. // return RESULT_TRUE;
  4503. // }
  4504. // int Auth_InfoVer = [[objheader valueForKey:@"ver"] intValue];
  4505. // NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  4506. // [defaults removeObjectForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4507. // [defaults setInteger:Auth_InfoVer forKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
  4508. // [defaults synchronize];
  4509. //
  4510. // NSDictionary* objfuncs = [jsobj objectForKey:@"functions"];
  4511. // NSArray* keys= [objfuncs allKeys];
  4512. /*
  4513. db.setTransactionSuccessful();
  4514. db.endTransaction();
  4515. */
  4516. return RESULT_TRUE;
  4517. }
  4518. // NSDictionary *weatherInfo = [jsobj objectForKey:@"weatherinfo"];
  4519. // txtView.text = [NSString stringWithFormat:@"今天是 %@ %@ %@ 的天气状况是:%@ %@ ",[weatherInfo objectForKey:@"date_y"],[weatherInfo objectForKey:@"week"],[weatherInfo objectForKey:@"city"], [weatherInfo objectForKey:@"weather1"], [weatherInfo objectForKey:@"temp1"]];
  4520. // DebugLog(@"weatherInfo字典里面的内容为--》%@", weatherDic );
  4521. return RESULT_USERAUTH_ERROR;
  4522. }
  4523. +(void)request_contactlist:(int) offset limit:(int)limit keywords:(NSString*) keywords type:(NSString*) contact_type adv_search:(NSDictionary*)upparams completionHandler:(resultHandler)result
  4524. {
  4525. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4526. if(upparams!=nil)
  4527. params = [upparams mutableCopy];
  4528. AppDelegate *appDelegate = nil;
  4529. //some UI methods ej
  4530. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4531. if(appDelegate.user!=nil)
  4532. [params setValue:appDelegate.user forKey:@"user"];
  4533. if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  4534. [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  4535. else
  4536. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4537. if(appDelegate.password!=nil)
  4538. [params setValue:appDelegate.password forKey:@"password"];
  4539. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  4540. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  4541. [params setValue:contact_type forKey:@"contactType"];
  4542. [params setValue:keywords forKey:@"keyword"];
  4543. [params setObject:ScreenCodeAccount forKey:kScreenName];
  4544. if (keywords) {
  4545. [params setObject:@"Search" forKey:kAction];
  4546. }
  4547. if (upparams) {
  4548. [params setObject:@"Advance Search" forKey:kAction];
  4549. }
  4550. NSString* url=nil;
  4551. if([contact_type isEqualToString:@"Sales_Order_Ship_To"])
  4552. url=URL_SHIPTO_LIST;
  4553. else
  4554. url=URL_CONTACT_LIST;
  4555. if(appDelegate.offline_mode)
  4556. {
  4557. [OLDataProvider offline_contactlist:params completionHandler:result];
  4558. return;
  4559. }
  4560. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  4561. //
  4562. // if(appDelegate.offline_mode)
  4563. // return [OLDataProvider offline_contactlist:params];
  4564. //
  4565. // if(![self IsNetworkAvailable])
  4566. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4567. //
  4568. // NSData* json=[self get_json:url parameters:params];
  4569. // if(json==nil)
  4570. // return nil;
  4571. // NSError *error=nil;
  4572. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4573. // return jsobj;
  4574. }
  4575. +(void)request_contactinfo:(NSString* ) contactid completionHandler:(resultHandler)result
  4576. {
  4577. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4578. AppDelegate *appDelegate = nil;
  4579. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4580. if(appDelegate.user!=nil)
  4581. [params setValue:appDelegate.user forKey:@"user"];
  4582. // if(appDelegate.contact_id!=nil)
  4583. if(appDelegate.password!=nil)
  4584. [params setValue:appDelegate.password forKey:@"password"];
  4585. [params setValue:contactid forKey:@"contactId"];
  4586. [params setObject:ScreenCodeCustomerInfo forKey:kScreenName];
  4587. if(appDelegate.offline_mode)
  4588. {
  4589. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4590. // [OLDataProvider offline_contactinfo:params completionHandler:result] ;
  4591. // });
  4592. params[@"mode"]=appDelegate.mode;
  4593. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4594. NSMutableDictionary* json = [[OLDataProvider offline_contactinfo:params] mutableCopy];
  4595. dispatch_async(dispatch_get_main_queue(), ^{
  4596. result(json);
  4597. });
  4598. });
  4599. return;
  4600. }
  4601. [self request_interface:URL_CUSTOMER_INFO parameters:params err_record_url:nil completionHandler:result retry:0];
  4602. // if(appDelegate.offline_mode)
  4603. // return [OLDataProvider offline_contactinfo:params];
  4604. // if(![self IsNetworkAvailable])
  4605. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4606. //
  4607. // NSData* json=[self get_json:URL_CUSTOMER_INFO parameters:params];
  4608. // if(json==nil)
  4609. // return nil;
  4610. // NSError *error=nil;
  4611. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4612. // return jsobj;
  4613. //
  4614. }
  4615. +(void)request_editor:(NSString*) request_url params:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  4616. {
  4617. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4618. AppDelegate *appDelegate = nil;
  4619. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4620. if(appDelegate.user!=nil)
  4621. [params setValue:appDelegate.user forKey:@"user"];
  4622. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  4623. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  4624. // else
  4625. if(appDelegate.contact_id!=nil)
  4626. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4627. if(appDelegate.password!=nil)
  4628. [params setValue:appDelegate.password forKey:@"password"];
  4629. if(appDelegate.order_code!=nil)
  4630. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  4631. bool can_create_backorder=appDelegate.can_create_backorder;
  4632. // [params setValue:sourceid forKey:@"sourceid"];
  4633. // [params setValue:editor forKey:@"editor"];
  4634. DebugLog(@"request editor url:%@",request_url);
  4635. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  4636. {
  4637. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  4638. }
  4639. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  4640. {
  4641. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  4642. }
  4643. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  4644. {
  4645. [params setObject:ScreenCodeAdvanceSearch forKey:kScreenName];
  4646. }
  4647. else if([request_url isEqualToString:URL_CARTDELIVERY])
  4648. {
  4649. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  4650. }
  4651. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  4652. {
  4653. [params setObject:ScreenCodeNewAddress forKey:kScreenName];
  4654. }
  4655. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  4656. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  4657. }
  4658. if(appDelegate.offline_mode)
  4659. {
  4660. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4661. NSData* json = nil;
  4662. if([request_url isEqualToString:URL_NEW_CUSTOMER])
  4663. {
  4664. json= [OLDataProvider offline_createContact:params];
  4665. }
  4666. else if([request_url isEqualToString:URL_EDIT_CUSTOMER])
  4667. {
  4668. json= [OLDataProvider offline_editContact:params];
  4669. }
  4670. else if([request_url isEqualToString:URL_CUSTOMER_ADV_SEARCH])
  4671. {
  4672. json= [OLDataProvider offline_contactAdvancedSearch:params];
  4673. }
  4674. else if([request_url isEqualToString:URL_CARTDELIVERY])
  4675. {
  4676. params[@"contact_id"]=params[@"contactId"];
  4677. params[@"can_create_backorder"]=@(can_create_backorder);
  4678. json= [OLDataProvider offline_placeorder:params];
  4679. }
  4680. else if([request_url isEqualToString:URL_ADDRESS_EDOTOR])
  4681. {
  4682. json= [OLDataProvider offline_addreditor:params];
  4683. }
  4684. else if ([request_url isEqualToString:URL_DM_PARAMS]){
  4685. json = [OLDataProvider offline_createTearSheet:params];
  4686. }
  4687. dispatch_async(dispatch_get_main_queue(), ^{
  4688. if(json==nil)
  4689. result( [[OLDataProvider offline_notimpl] mutableCopy]);
  4690. else
  4691. result([[RAConvertor data2dict:json] mutableCopy]);
  4692. });
  4693. });
  4694. return;
  4695. }
  4696. else
  4697. {
  4698. if([request_url isEqualToString:URL_CARTDELIVERY])
  4699. {
  4700. NSString * uuid= [[NSUUID UUID] UUIDString];
  4701. params[@"resultSerial"]=uuid;
  4702. __block bool bbreak = false;
  4703. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4704. for(int i=0;i<150;i++)
  4705. {
  4706. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  4707. // result_params[@"resultSerial"]=uuid;
  4708. //json=[self get_json:request_url parameters:params];
  4709. if(bbreak)
  4710. break;
  4711. dispatch_async(dispatch_get_main_queue(), ^{
  4712. DebugLog(@"request cart delivery %d",i);
  4713. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  4714. if(resulti!=nil)
  4715. {
  4716. if([resulti[@"result"] intValue]==2 || [resulti[@"result"] intValue] == 8)
  4717. {
  4718. if(!bbreak) //此判断保证result只调用一次。
  4719. {
  4720. result(resulti);
  4721. DebugLog(@"result called at %d",i);
  4722. }
  4723. bbreak=true;
  4724. }
  4725. }
  4726. } retry:3];
  4727. });
  4728. // [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  4729. sleep(2);
  4730. }
  4731. });
  4732. }
  4733. else
  4734. [self request_interface:request_url parameters:params err_record_url:nil completionHandler:result retry:0];
  4735. }
  4736. // if(json!=nil)
  4737. // {
  4738. // NSError *error=nil;
  4739. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4740. // return jsobj;
  4741. // }
  4742. // else
  4743. // return nil;
  4744. }
  4745. +(void)request_wishlist:(int)sort completionHandler:(resultHandler)result
  4746. {
  4747. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4748. AppDelegate *appDelegate = nil;
  4749. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4750. if(appDelegate.user!=nil)
  4751. [params setValue:appDelegate.user forKey:@"user"];
  4752. if(appDelegate.contact_id!=nil)
  4753. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4754. if(appDelegate.password!=nil)
  4755. [params setValue:appDelegate.password forKey:@"password"];
  4756. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  4757. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  4758. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  4759. [params setObject:ScreenCodeWishList forKey:kScreenName];
  4760. if(appDelegate.offline_mode)
  4761. {
  4762. [OLDataProvider offline_wishlist:params completionHandler:^(NSMutableDictionary *resulti) {
  4763. int result_code = [[resulti valueForKey:@"result"] intValue];
  4764. if (result_code==2)
  4765. {
  4766. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  4767. [appDelegate update_count_mark];;
  4768. result(resulti);
  4769. }
  4770. }];
  4771. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4772. // NSMutableDictionary* json = [[OLDataProvider offline_wishlist:params] mutableCopy];
  4773. // dispatch_async(dispatch_get_main_queue(), ^{
  4774. // result(json);
  4775. // });
  4776. // });
  4777. return;
  4778. }
  4779. [self request_interface:URL_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  4780. int result_code = [[resulti valueForKey:@"result"] intValue];
  4781. if (result_code==2)
  4782. {
  4783. appDelegate.wish_count =[[resulti valueForKey:@"count"] intValue];
  4784. [appDelegate update_count_mark];;
  4785. result(resulti);
  4786. }
  4787. } retry:0];
  4788. // if(appDelegate.offline_mode)
  4789. // {
  4790. // return [OLDataProvider offline_wishlist:params];
  4791. // }
  4792. // if(![self IsNetworkAvailable])
  4793. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4794. //
  4795. // NSData* json=[self get_json:URL_WATCHLIST parameters:params];
  4796. // if(json==nil)
  4797. // return nil;
  4798. // NSError *error=nil;
  4799. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4800. // int result = [[jsobj valueForKey:@"result"] intValue];
  4801. //
  4802. // if (result==2)
  4803. // {
  4804. //
  4805. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  4806. // appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  4807. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  4808. //
  4809. // [appDelegate update_count_mark];
  4810. // }
  4811. // return jsobj;
  4812. }
  4813. +(void)request_portfoliolist:(int)sort completionHandler:(resultHandler)result
  4814. {
  4815. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4816. AppDelegate *appDelegate = nil;
  4817. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4818. if(appDelegate.user!=nil)
  4819. [params setValue:appDelegate.user forKey:@"user"];
  4820. if(appDelegate.contact_id!=nil)
  4821. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4822. if(appDelegate.password!=nil)
  4823. [params setValue:appDelegate.password forKey:@"password"];
  4824. [params setValue:[NSString stringWithFormat:@"%d",0 ] forKey:@"offset"];
  4825. [params setValue:[NSString stringWithFormat:@"%d",INT_MAX ] forKey:@"limit"];
  4826. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  4827. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  4828. if(appDelegate.offline_mode)
  4829. {
  4830. params[@"user"]=appDelegate.user;
  4831. params[@"contact_id"]=appDelegate.contact_id;
  4832. params[@"can_see_price"]=@(appDelegate.can_see_price);
  4833. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4834. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_portfolioList:params]] mutableCopy];
  4835. dispatch_async(dispatch_get_main_queue(), ^{
  4836. if ([json[@"result"] intValue]==2)
  4837. {
  4838. appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  4839. [appDelegate update_count_mark];
  4840. }
  4841. result(json);
  4842. });
  4843. });
  4844. return;
  4845. }
  4846. [self request_interface:URL_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  4847. if ([resulti[@"result"] intValue]==2)
  4848. {
  4849. appDelegate.port_count =[[resulti valueForKey:@"count"] intValue];
  4850. [appDelegate update_count_mark];
  4851. }
  4852. result(resulti);
  4853. } retry:0];
  4854. // NSData* json = nil;
  4855. // if(appDelegate.offline_mode)
  4856. // {
  4857. // json = [OLDataProvider offline_portfolioList:params];
  4858. // } else {
  4859. // if(![self IsNetworkAvailable])
  4860. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4861. //
  4862. // json = [self get_json:URL_PORTFOLIO parameters:params];
  4863. // }
  4864. //
  4865. //
  4866. // if(json==nil)
  4867. // return nil;
  4868. // NSError *error=nil;
  4869. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4870. // int result = [[jsobj valueForKey:@"result"] intValue];
  4871. //
  4872. // if (result==2)
  4873. // {
  4874. //
  4875. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  4876. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  4877. // appDelegate.port_count =[[jsobj valueForKey:@"count"] intValue];
  4878. //
  4879. // [appDelegate update_count_mark];
  4880. // }
  4881. // return jsobj;
  4882. }
  4883. +(void)request_portfoliopdf:(int ) offset limit:(int)limit keywords:(NSString* ) keywords completionHandler:(resultHandler)result
  4884. {
  4885. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4886. AppDelegate *appDelegate = nil;
  4887. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4888. if(appDelegate.user!=nil)
  4889. [params setValue:appDelegate.user forKey:@"user"];
  4890. if(appDelegate.contact_id!=nil)
  4891. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4892. if(appDelegate.password!=nil)
  4893. [params setValue:appDelegate.password forKey:@"password"];
  4894. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  4895. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  4896. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  4897. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  4898. // [params setValue:filter forKey:@"filter"];
  4899. [params setValue:keywords forKey:@"keyWord"];
  4900. [params setValue:[NSString stringWithFormat:@"%d",limit] forKey:@"limit"];
  4901. [params setValue:[NSString stringWithFormat:@"%d",offset] forKey:@"offset"];
  4902. [params setObject:ScreenCodeViewPortfolios forKey:kScreenName];
  4903. if (keywords) {
  4904. [params setObject:@"Search" forKey:kAction];
  4905. }
  4906. if(appDelegate.offline_mode)
  4907. {
  4908. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4909. NSData* json = [[OLDataProvider offline_pdfList:params] mutableCopy];
  4910. dispatch_async(dispatch_get_main_queue(), ^{
  4911. result([[RAConvertor data2dict:json] mutableCopy]);
  4912. });
  4913. });
  4914. return;
  4915. }
  4916. [self request_interface:URL_DM_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  4917. return;
  4918. // NSData* json = nil;
  4919. // if(appDelegate.offline_mode)
  4920. // {
  4921. // json = [OLDataProvider offline_pdfList:params];
  4922. // } else {
  4923. // if(![self IsNetworkAvailable])
  4924. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4925. //
  4926. // json=[self get_json:URL_DM_LIST parameters:params];
  4927. // }
  4928. // if(json==nil)
  4929. // return nil;
  4930. // NSError *error=nil;
  4931. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4932. // return jsobj;
  4933. }
  4934. +(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
  4935. {
  4936. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4937. AppDelegate *appDelegate = nil;
  4938. //some UI methods ej
  4939. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4940. if(appDelegate.user!=nil)
  4941. [params setValue:appDelegate.user forKey:@"user"];
  4942. if(appDelegate.contact_id!=nil)
  4943. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  4944. if(appDelegate.password!=nil)
  4945. [params setValue:appDelegate.password forKey:@"password"];
  4946. [params setValue:[NSString stringWithFormat:@"%d",offset ] forKey:@"offset"];
  4947. [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  4948. [params setValue:keywords forKey:@"keyWord"];
  4949. [params setValue:customer forKey:@"customer_filter"];
  4950. [params setValue:[NSNumber numberWithBool:isMerged] forKey:@"isMerged"];
  4951. [params setValue:status_code forKey:@"orderStatus"];
  4952. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  4953. if (keywords) {
  4954. [params setObject:@"Search" forKey:kAction];
  4955. }
  4956. if(appDelegate.offline_mode)
  4957. {
  4958. params[@"user"]=appDelegate.user;
  4959. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4960. NSData* json = [[OLDataProvider offline_orderlist:params] mutableCopy];
  4961. dispatch_async(dispatch_get_main_queue(), ^{
  4962. result([[RAConvertor data2dict:json] mutableCopy]);
  4963. });
  4964. });
  4965. return;
  4966. }
  4967. [self request_interface:URL_ORDER_LIST parameters:params err_record_url:nil completionHandler:result retry:0];
  4968. // NSData* json=nil;
  4969. // if(appDelegate.offline_mode)
  4970. // {
  4971. // json= [OLDataProvider offline_orderlist:params];
  4972. // }
  4973. // else
  4974. // {
  4975. // if(![self IsNetworkAvailable])
  4976. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  4977. //
  4978. // json=[self get_json:URL_ORDER_LIST parameters:params];
  4979. // }
  4980. // if(json==nil)
  4981. // return nil;
  4982. // NSError *error=nil;
  4983. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  4984. // return jsobj;
  4985. }
  4986. +(void)request_logout:(resultHandler)result
  4987. {
  4988. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  4989. AppDelegate *appDelegate = nil;
  4990. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  4991. if(appDelegate.user!=nil)
  4992. [params setValue:appDelegate.user forKey:@"user"];
  4993. if(appDelegate.password!=nil)
  4994. [params setValue:appDelegate.password forKey:@"password"];
  4995. if(appDelegate.offline_mode)
  4996. {
  4997. [OLDataProvider offline_logout:params completionHandler:result];
  4998. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  4999. // NSMutableDictionary* json = [[OLDataProvider offline_logout:params] mutableCopy];
  5000. // dispatch_async(dispatch_get_main_queue(), ^{
  5001. // result(json);
  5002. // });
  5003. // });
  5004. return;
  5005. }
  5006. [self request_interface:URL_LOGOUT parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5007. NSMutableDictionary* jsobj=resulti;
  5008. int result_code = [[jsobj valueForKey:@"result"] intValue];
  5009. if (result_code==2)
  5010. {
  5011. appDelegate.cart_count = 0;//[[jsobj :@"cart_count"] intValue];
  5012. appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5013. appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5014. [appDelegate update_count_mark];
  5015. appDelegate.can_show_price =false;
  5016. appDelegate.can_see_price =false;
  5017. appDelegate.can_create_portfolio =false;
  5018. appDelegate.can_create_order =false;
  5019. appDelegate.can_cancel_order =false;
  5020. appDelegate.can_set_cart_price =false;
  5021. appDelegate.can_delete_order =false;
  5022. appDelegate.can_submit_order =false;
  5023. appDelegate.can_set_tearsheet_price =false;
  5024. appDelegate.can_update_contact_info = false;
  5025. appDelegate.save_order_logout = false;
  5026. appDelegate.submit_order_logout = false;
  5027. appDelegate.alert_sold_in_quantities = false;
  5028. appDelegate.ipad_perm =nil ;
  5029. appDelegate.user_type = USER_ROLE_UNKNOWN;
  5030. appDelegate.OrderFilter= nil;
  5031. [appDelegate SetSo:nil];
  5032. [appDelegate set_main_button_panel];
  5033. #ifdef RA_NOTIFICATION
  5034. [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5035. #endif
  5036. }
  5037. result(resulti);
  5038. } retry:0];
  5039. //
  5040. // if(appDelegate.offline_mode)
  5041. // {
  5042. // return [OLDataProvider offline_logout:params];
  5043. // }
  5044. // if(![self IsNetworkAvailable])
  5045. // {
  5046. // DebugLog(@"NET ERR");
  5047. //
  5048. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5049. // // return nil;
  5050. // }
  5051. // NSData* json=[self get_json:URL_LOGOUT parameters:params];
  5052. // //if(json==nil)
  5053. //
  5054. //
  5055. // if(json==nil)
  5056. // return nil;
  5057. // NSError *error=nil;
  5058. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5059. // int result = [[jsobj valueForKey:@"result"] intValue];
  5060. //
  5061. // if (result==2)
  5062. // {
  5063. //
  5064. // appDelegate.cart_count = 0;//[[jsobj valueForKey:@"cart_count"] intValue];
  5065. // appDelegate.wish_count =0;//[[jsobj valueForKey:@"wish_count"] intValue];
  5066. // appDelegate.port_count =0;//[[jsobj valueForKey:@"portfolio_count"] intValue];
  5067. //
  5068. // [appDelegate update_count_mark];
  5069. //
  5070. //
  5071. // appDelegate.can_show_price =false;
  5072. // appDelegate.can_see_price =false;
  5073. // appDelegate.can_create_portfolio =false;
  5074. // appDelegate.can_create_order =false;
  5075. //
  5076. //
  5077. // appDelegate.can_cancel_order =false;
  5078. // appDelegate.can_set_cart_price =false;
  5079. // appDelegate.can_delete_order =false;
  5080. // appDelegate.can_submit_order =false;
  5081. // appDelegate.can_set_tearsheet_price =false;
  5082. // appDelegate.can_update_contact_info = false;
  5083. //
  5084. // appDelegate.save_order_logout = false;
  5085. // appDelegate.submit_order_logout = false;
  5086. // appDelegate.alert_sold_in_quantities = false;
  5087. //
  5088. // appDelegate.ipad_perm =nil ;
  5089. // appDelegate.user_type = USER_ROLE_UNKNOWN;
  5090. // appDelegate.OrderFilter= nil;
  5091. // [appDelegate SetSo:nil];
  5092. // [appDelegate set_main_button_panel];
  5093. //#ifdef RA_NOTIFICATION
  5094. // [ActiveViewController Notify:@"SearchViewController" Message:RA_NOTIFICATION_CLEAR_DATA];
  5095. //#endif
  5096. // }
  5097. // return jsobj;
  5098. }
  5099. + (void)request_hangtag:(NSString *)group completionHandler:(resultHandler)result
  5100. {
  5101. #ifdef BUILD_UWAVER
  5102. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5103. AppDelegate *appDelegate = nil;
  5104. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5105. if(appDelegate.user!=nil)
  5106. [params setValue:appDelegate.user forKey:@"user"];
  5107. if(appDelegate.contact_id!=nil)
  5108. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5109. if(appDelegate.password!=nil)
  5110. [params setValue:appDelegate.password forKey:@"password"];
  5111. if (group) {
  5112. [params setValue:group forKey:@"groupName"];
  5113. }
  5114. NSString * uuid= [[NSUUID UUID] UUIDString];
  5115. params[@"resultSerial"]=uuid;
  5116. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  5117. if(appDelegate.offline_mode)
  5118. {
  5119. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5120. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5121. dispatch_async(dispatch_get_main_queue(), ^{
  5122. result(json);
  5123. });
  5124. });
  5125. return;
  5126. }
  5127. [self request_interface:URL_CREATE_HANG_TAG parameters:params err_record_url:nil completionHandler:result retry:0];
  5128. // NSData* json = nil;
  5129. // if(appDelegate.offline_mode)
  5130. // {
  5131. // json = [OLDataProvider offline_portfolioList:params];
  5132. // } else {
  5133. // if(![self IsNetworkAvailable])
  5134. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5135. //
  5136. // json = [self get_json:URL_CREATE_HANG_TAG parameters:params];
  5137. // }
  5138. //
  5139. //
  5140. // if(json==nil)
  5141. // return nil;
  5142. // NSError *error=nil;
  5143. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5144. //
  5145. // return jsobj;
  5146. #else
  5147. return result(nil);
  5148. #endif
  5149. }
  5150. + (void)request_movetobackorder:(NSString *)cart_item_id completionHandler:(resultHandler)result
  5151. {
  5152. if (cart_item_id == nil || cart_item_id.length < 1) {
  5153. result([@{@"result" : @(RESULT_FALSE),@"err_msg" : @"invalided product"} mutableCopy]);
  5154. }
  5155. AppDelegate *appDelegate = nil;
  5156. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5157. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5158. if(appDelegate.user!=nil)
  5159. [dic setValue:appDelegate.user forKey:@"user"];
  5160. if(appDelegate.password!=nil)
  5161. [dic setValue:appDelegate.password forKey:@"password"];
  5162. [dic setValue:cart_item_id forKey:@"orderitem_id"];
  5163. [dic setValue:appDelegate.order_code forKey:@"order_code"];
  5164. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5165. if(appDelegate.offline_mode)
  5166. {
  5167. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5168. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5169. dispatch_async(dispatch_get_main_queue(), ^{
  5170. result(json);
  5171. });
  5172. });
  5173. return;
  5174. }
  5175. [self request_interface:URL_MOVE_TO_BACK_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5176. // if(![self IsNetworkAvailable])
  5177. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5178. //
  5179. // NSData *json = [RANetwork get_json:URL_MOVE_TO_BACK_ORDER parameters:dic];
  5180. //
  5181. // if(json!=nil)
  5182. // {
  5183. // NSError *error=nil;
  5184. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5185. //
  5186. // return jsobj;
  5187. // }
  5188. //
  5189. // return @{@"result" : @(RESULT_FALSE)};
  5190. }
  5191. + (void)request_emailwishlist:(NSString *)addr completionHandler:(resultHandler)result
  5192. {
  5193. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5194. AppDelegate *appDelegate = nil;
  5195. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5196. if(appDelegate.user!=nil)
  5197. [dic setValue:appDelegate.user forKey:@"user"];
  5198. if(appDelegate.password!=nil)
  5199. [dic setValue:appDelegate.password forKey:@"password"];
  5200. [dic setValue:addr forKey:@"email"];
  5201. [dic setObject:ScreenCodeWishList forKey:kScreenName];
  5202. // if (appDelegate.customerInfo) {
  5203. // NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5204. // if (customer_cid) {
  5205. // [dic setValue:customer_cid forKey:@"contactId"];
  5206. // }
  5207. // }
  5208. if(appDelegate.offline_mode)
  5209. {
  5210. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5211. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5212. dispatch_async(dispatch_get_main_queue(), ^{
  5213. result(json);
  5214. });
  5215. });
  5216. return;
  5217. }
  5218. [self request_interface:URL_EMAIL_WISHLIST parameters:dic err_record_url:nil completionHandler:result retry:0];
  5219. // NSData* json=nil;
  5220. // if(appDelegate.offline_mode)
  5221. // {
  5222. // return [OLDataProvider offline_notimpl];
  5223. // }
  5224. // else
  5225. // {
  5226. // if(![self IsNetworkAvailable])
  5227. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5228. //
  5229. // json = [RANetwork get_json:URL_EMAIL_WISHLIST parameters:dic];
  5230. // }
  5231. // if(json!=nil)
  5232. // {
  5233. // NSError *error=nil;
  5234. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5235. //
  5236. //
  5237. // return jsobj;
  5238. // }
  5239. //
  5240. // return @{@"result" : @(RESULT_FALSE)};
  5241. }
  5242. +(void)request_notifymodel:(NSString *)modelID emailAddr:(NSString *)addr withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  5243. {
  5244. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5245. AppDelegate *appDelegate = nil;
  5246. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5247. if(appDelegate.user!=nil)
  5248. [dic setValue:appDelegate.user forKey:@"user"];
  5249. if(appDelegate.password!=nil)
  5250. [dic setValue:appDelegate.password forKey:@"password"];
  5251. if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5252. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5253. if (customer_cid) {
  5254. [dic setValue:customer_cid forKey:@"contactId"];
  5255. }
  5256. }
  5257. [dic setObject:screenName forKey:kScreenName];
  5258. [dic setValue:modelID forKey:@"productId"];
  5259. if (addr) { // 弹框输入
  5260. [dic setValue:addr forKey:@"email"];
  5261. } else {
  5262. // employee选择了Contact,并且Contact有Email
  5263. // if (appDelegate.user_type == USER_ROLE_EMPLOYEE && appDelegate.customerInfo) {
  5264. // NSString *email = [appDelegate.customerInfo objectForKey:@"customer_email"];
  5265. // if (email) {
  5266. // [dic setValue:email forKey:@"email"];
  5267. // }
  5268. // }
  5269. }
  5270. if(appDelegate.offline_mode)
  5271. {
  5272. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5273. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5274. dispatch_async(dispatch_get_main_queue(), ^{
  5275. result(json);
  5276. });
  5277. });
  5278. return;
  5279. }
  5280. [self request_interface:URL_NOTIFY_ME parameters:dic err_record_url:nil completionHandler:result retry:0];
  5281. // NSData* json=nil;
  5282. // if(appDelegate.offline_mode)
  5283. // {
  5284. // return [OLDataProvider offline_notimpl];
  5285. // }
  5286. // else
  5287. // {
  5288. // if(![self IsNetworkAvailable])
  5289. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5290. //
  5291. // json = [RANetwork get_json:URL_NOTIFY_ME parameters:dic];
  5292. // }
  5293. // if(json!=nil)
  5294. // {
  5295. // NSError *error=nil;
  5296. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5297. //
  5298. //
  5299. // return jsobj;
  5300. // }
  5301. //
  5302. // return @{@"result" : @(RESULT_FALSE)};
  5303. }
  5304. + (void)request_qouteorder:(NSString *)so_id emailAddr:(NSString *)addr completionHandler:(resultHandler)result
  5305. {
  5306. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5307. AppDelegate *appDelegate = nil;
  5308. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5309. if(appDelegate.user!=nil)
  5310. [dic setValue:appDelegate.user forKey:@"user"];
  5311. if(appDelegate.password!=nil)
  5312. [dic setValue:appDelegate.password forKey:@"password"];
  5313. [dic setValue:so_id forKey:@"orderCode"];
  5314. [dic setValue:addr forKey:@"email"];
  5315. [dic setObject:ScreenCodeCart forKey:kScreenName];
  5316. if (appDelegate.customerInfo) {
  5317. NSString *customer_cid = [appDelegate.customerInfo objectForKey:@"customer_cid"];
  5318. if (customer_cid) {
  5319. [dic setValue:customer_cid forKey:@"contactId"];
  5320. }
  5321. }
  5322. if(appDelegate.offline_mode)
  5323. {
  5324. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5325. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5326. dispatch_async(dispatch_get_main_queue(), ^{
  5327. result(json);
  5328. });
  5329. });
  5330. return;
  5331. }
  5332. [self request_interface:URL_EMAIL_CART parameters:dic err_record_url:nil completionHandler:result retry:0];
  5333. // NSData* json=nil;
  5334. // if(appDelegate.offline_mode)
  5335. // {
  5336. // return [OLDataProvider offline_notimpl];
  5337. // }
  5338. // else
  5339. // {
  5340. // if(![self IsNetworkAvailable])
  5341. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5342. //
  5343. // json = [RANetwork get_json:URL_EMAIL_CART parameters:dic];
  5344. // }
  5345. // if(json!=nil)
  5346. // {
  5347. // NSError *error=nil;
  5348. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5349. //
  5350. //
  5351. // return jsobj;
  5352. // }
  5353. //
  5354. // return @{@"result" : @(RESULT_FALSE)};
  5355. }
  5356. + (void)request_mergeorder:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  5357. {
  5358. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  5359. AppDelegate *appDelegate = nil;
  5360. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5361. if(appDelegate.user!=nil)
  5362. [dic setValue:appDelegate.user forKey:@"user"];
  5363. if(appDelegate.password!=nil)
  5364. [dic setValue:appDelegate.password forKey:@"password"];
  5365. [dic setValue:[params objectForKey:@"order_ids"] forKey:@"order_ids"];
  5366. [dic setValue:[params objectForKey:@"targetOrderId"] forKey:@"targetOrderId"];
  5367. [dic setValue:[params objectForKey:@"customerInfo"] forKey:@"customerInfo"];
  5368. [dic setObject:ScreenCodeOrderList forKey:kScreenName];
  5369. if(appDelegate.offline_mode)
  5370. {
  5371. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5372. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5373. dispatch_async(dispatch_get_main_queue(), ^{
  5374. result(json);
  5375. });
  5376. });
  5377. return;
  5378. }
  5379. [self request_interface:URL_SET_MERGE_ORDER parameters:dic err_record_url:nil completionHandler:result retry:0];
  5380. // NSData* json=nil;
  5381. // if(appDelegate.offline_mode)
  5382. // {
  5383. // return [OLDataProvider offline_notimpl];
  5384. // }
  5385. // else
  5386. // {
  5387. // if(![self IsNetworkAvailable])
  5388. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5389. //
  5390. // json=[self get_json:URL_SET_MERGE_ORDER parameters:dic];
  5391. // }
  5392. // if(json!=nil)
  5393. // {
  5394. // NSError *error=nil;
  5395. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5396. //
  5397. //
  5398. // return jsobj;
  5399. // }
  5400. // else
  5401. // return nil;
  5402. }
  5403. +(void)request_pendingorder:(NSString *)contactid completionHandler:(resultHandler)result
  5404. {
  5405. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5406. AppDelegate *appDelegate = nil;
  5407. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5408. if(appDelegate.user!=nil)
  5409. [params setValue:appDelegate.user forKey:@"user"];
  5410. // if(appDelegate.contact_id!=nil)
  5411. if(appDelegate.password!=nil)
  5412. [params setValue:appDelegate.password forKey:@"password"];
  5413. [params setValue:contactid forKey:@"contactId"];
  5414. if(appDelegate.offline_mode)
  5415. {
  5416. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5417. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5418. dispatch_async(dispatch_get_main_queue(), ^{
  5419. result(json);
  5420. });
  5421. });
  5422. return;
  5423. }
  5424. [self request_interface:URL_CUSTOMER_PENDINGORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  5425. //
  5426. // if(appDelegate.offline_mode)
  5427. // {
  5428. // return [OLDataProvider offline_notimpl];
  5429. // }
  5430. // if(![self IsNetworkAvailable])
  5431. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5432. //
  5433. // NSData* json=[self get_json:URL_CUSTOMER_PENDINGORDER parameters:params];
  5434. // if(json==nil)
  5435. // return nil;
  5436. // NSError *error=nil;
  5437. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5438. // return jsobj;
  5439. //
  5440. }
  5441. +(void) request_removeportfolio:(NSString* ) item_ids completionHandler:(resultHandler)result
  5442. {
  5443. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5444. AppDelegate *appDelegate = nil;
  5445. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5446. if(appDelegate.user!=nil)
  5447. [params setValue:appDelegate.user forKey:@"user"];
  5448. if(appDelegate.contact_id!=nil)
  5449. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5450. if(appDelegate.password!=nil)
  5451. [params setValue:appDelegate.password forKey:@"password"];
  5452. [params setValue:item_ids forKey:@"portfolioId"];
  5453. // [params setValue:editor forKey:@"editor"];
  5454. [params setValue:ScreenCodePortfolio forKey:kScreenName];
  5455. if(appDelegate.offline_mode)
  5456. {
  5457. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5458. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_removePortfolio:params]] mutableCopy];
  5459. dispatch_async(dispatch_get_main_queue(), ^{
  5460. int result_code = [[resulti valueForKey:@"result"] intValue];
  5461. if (result_code==2)
  5462. {
  5463. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5464. [appDelegate update_count_mark];
  5465. };
  5466. result(resulti);
  5467. });
  5468. });
  5469. return;
  5470. }
  5471. [self request_interface:URL_PORTFOLIO_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5472. int result_code = [[resulti valueForKey:@"result"] intValue];
  5473. if (result_code==2)
  5474. {
  5475. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  5476. [appDelegate update_count_mark];
  5477. };
  5478. result(resulti);
  5479. } retry:0];
  5480. // NSData* json = nil;
  5481. // if(appDelegate.offline_mode)
  5482. // {
  5483. // json = [OLDataProvider offline_removePortfolio:params];
  5484. // } else {
  5485. // if(![self IsNetworkAvailable])
  5486. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5487. // json=[self get_json:URL_PORTFOLIO_REMOVE parameters:params];
  5488. // }
  5489. // if(json!=nil)
  5490. // {
  5491. // NSError *error=nil;
  5492. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5493. //
  5494. //
  5495. // int result = [[jsobj valueForKey:@"result"] intValue];
  5496. //
  5497. // if (result==2)
  5498. // {
  5499. //
  5500. //
  5501. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5502. //
  5503. // [appDelegate update_count_mark];
  5504. // }
  5505. // return jsobj;
  5506. // }
  5507. // else
  5508. // return nil;
  5509. }
  5510. +(void) request_removeportfoliopdf:(NSString* ) listid completionHandler:(resultHandler)result
  5511. {
  5512. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5513. AppDelegate *appDelegate = nil;
  5514. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5515. if(appDelegate.user!=nil)
  5516. [params setValue:appDelegate.user forKey:@"user"];
  5517. if(appDelegate.contact_id!=nil)
  5518. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5519. if(appDelegate.password!=nil)
  5520. [params setValue:appDelegate.password forKey:@"password"];
  5521. [params setValue:listid forKey:@"tearsheetsId"];
  5522. // [params setValue:editor forKey:@"editor"];
  5523. [params setValue:ScreenCodeViewPortfolios forKey:kScreenName];
  5524. // [params setValue:@"Delete Portfolio" forKey:kAction];
  5525. if(appDelegate.offline_mode)
  5526. {
  5527. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5528. NSData* json = [[OLDataProvider offline_removePDF:params] mutableCopy];
  5529. dispatch_async(dispatch_get_main_queue(), ^{
  5530. result([[RAConvertor data2dict:json] mutableCopy]);
  5531. });
  5532. });
  5533. return;
  5534. }
  5535. [self request_interface:URL_PORTFOLIOLIST_REMOVE parameters:params err_record_url:nil completionHandler:result retry:0];
  5536. }
  5537. +(void) request_remove_wishlist:(NSString* ) item_ids completionHandler:(resultHandler)result
  5538. {
  5539. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5540. __block AppDelegate *appDelegate = nil;
  5541. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5542. if(appDelegate.user!=nil)
  5543. [params setValue:appDelegate.user forKey:@"user"];
  5544. if(appDelegate.contact_id!=nil)
  5545. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5546. if(appDelegate.password!=nil)
  5547. [params setValue:appDelegate.password forKey:@"password"];
  5548. [params setValue:item_ids forKey:@"collectId"];
  5549. // [params setValue:editor forKey:@"editor"];
  5550. [params setValue:ScreenCodeWishList forKey:kScreenName];
  5551. if(appDelegate.offline_mode)
  5552. {
  5553. // [OLDataProvider offline_deletewishlist:params completionHandler:result];
  5554. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5555. NSMutableDictionary* resulti = [[OLDataProvider offline_deletewishlist:params] mutableCopy];
  5556. dispatch_async(dispatch_get_main_queue(), ^{
  5557. int result_code = [[resulti valueForKey:@"result"] intValue];
  5558. if (result_code==2)
  5559. {
  5560. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  5561. [appDelegate update_count_mark];
  5562. };
  5563. result(resulti);
  5564. });
  5565. });
  5566. return;
  5567. }
  5568. [self request_interface:URL_WATCHLIST_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5569. int result_code = [[resulti valueForKey:@"result"] intValue];
  5570. if (result_code==2)
  5571. {
  5572. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  5573. [appDelegate update_count_mark];
  5574. };
  5575. result(resulti);
  5576. } retry:0];
  5577. //
  5578. //
  5579. // if(appDelegate.offline_mode)
  5580. // {
  5581. // return [OLDataProvider offline_deletewishlist:params];
  5582. // }
  5583. // if(![self IsNetworkAvailable])
  5584. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5585. //
  5586. // NSData* json=[self get_json:URL_WATCHLIST_REMOVE parameters:params];
  5587. // if(json!=nil)
  5588. // {
  5589. // NSError *error=nil;
  5590. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5591. // int result = [[jsobj valueForKey:@"result"] intValue];
  5592. //
  5593. // if (result==2)
  5594. // {
  5595. //
  5596. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5597. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  5598. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5599. //
  5600. // [appDelegate update_count_mark];
  5601. // }
  5602. // return jsobj;
  5603. // }
  5604. // else
  5605. // return nil;
  5606. }
  5607. +(void) request_remove_cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  5608. {
  5609. #ifdef SCANNER_ORDER
  5610. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  5611. {
  5612. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  5613. //
  5614. //
  5615. // [appDelegate update_count_mark];
  5616. NSArray* arr=[RAConvertor string2arr:item_ids separator:@","];
  5617. // NSData* json =[NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:URL_SO_CART ofType:@"json" ]];
  5618. NSMutableDictionary* cartTemplate=[OLDataProvider loadScanTemplate:@"scan_cart.json"];
  5619. NSMutableDictionary* newsection =[cartTemplate[@"section_0"] mutableCopy];
  5620. int newcount = 0;
  5621. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  5622. int count = [section[@"count"] intValue];
  5623. for(int i=0;i<count;i++)
  5624. {
  5625. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  5626. long index = [arr indexOfObject:item[@"cart_item_id"]] ;
  5627. if(index ==NSNotFound)
  5628. {
  5629. newsection[[NSString stringWithFormat:@"item_%d",newcount]] = item;
  5630. newcount ++;
  5631. }
  5632. }
  5633. newsection[@"count"]=@(newcount);
  5634. RASingleton.sharedInstance.scan_cart[@"section_0"] = newsection;
  5635. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  5636. result(RASingleton.sharedInstance.scan_cart);
  5637. return;
  5638. }
  5639. #else
  5640. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5641. AppDelegate *appDelegate = nil;
  5642. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5643. if(appDelegate.user!=nil)
  5644. [params setValue:appDelegate.user forKey:@"user"];
  5645. if(appDelegate.contact_id!=nil)
  5646. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5647. if(appDelegate.password!=nil)
  5648. [params setValue:appDelegate.password forKey:@"password"];
  5649. if(appDelegate.order_code!=nil)
  5650. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5651. [params setValue:item_ids forKey:@"cartItemId"];
  5652. // [params setValue:editor forKey:@"editor"];
  5653. [params setValue:ScreenCodeCart forKey:kScreenName];
  5654. // [params setValue:@"" forKey:kAction];
  5655. if(appDelegate.offline_mode)
  5656. {
  5657. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5658. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_cartremove:params]] mutableCopy];
  5659. dispatch_async(dispatch_get_main_queue(), ^{
  5660. int result_code = [[resulti valueForKey:@"result"] intValue];
  5661. if (result_code==2)
  5662. {
  5663. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5664. [appDelegate update_count_mark];
  5665. };
  5666. result(resulti);
  5667. });
  5668. });
  5669. return;
  5670. }
  5671. [self request_interface:URL_CART_REMOVE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5672. int result_code = [[resulti valueForKey:@"result"] intValue];
  5673. if (result_code==2)
  5674. {
  5675. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5676. [appDelegate update_count_mark];
  5677. };
  5678. result(resulti);
  5679. } retry:0];
  5680. #endif
  5681. }
  5682. +(void)request_delete_account:(resultHandler)result
  5683. {
  5684. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5685. AppDelegate *appDelegate = nil;
  5686. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5687. if(appDelegate.user!=nil)
  5688. [params setValue:appDelegate.user forKey:@"user"];
  5689. if(appDelegate.password!=nil)
  5690. [params setValue:appDelegate.password forKey:@"password"];
  5691. if(appDelegate.offline_mode)
  5692. {
  5693. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5694. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5695. dispatch_async(dispatch_get_main_queue(), ^{
  5696. result(json);
  5697. });
  5698. });
  5699. return;
  5700. }
  5701. #ifdef SCANNER_ORDER
  5702. params[@"site_name"]=[RADataProvider getSiteName];
  5703. params[@"_method"]=@"cancelOfflineOrderUser";
  5704. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_DELETE_ACCOUNT];
  5705. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  5706. #else
  5707. [self request_interface:URL_DELETE_ACCOUNT parameters:params err_record_url:nil completionHandler:result retry:0];
  5708. #endif
  5709. }
  5710. +(void) request_create_order:(resultHandler)result
  5711. {
  5712. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5713. AppDelegate *appDelegate = nil;
  5714. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5715. if(appDelegate.user!=nil)
  5716. [params setValue:appDelegate.user forKey:@"user"];
  5717. if(appDelegate.contact_id!=nil)
  5718. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5719. if(appDelegate.password!=nil)
  5720. [params setValue:appDelegate.password forKey:@"password"];
  5721. if(appDelegate.order_code!=nil)
  5722. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5723. [params setObject:ScreenCodeOrderList forKey:kScreenName];
  5724. NSDictionary* customerinfo= appDelegate.customerInfo;
  5725. NSArray* keys=[customerinfo allKeys];
  5726. for(int i=0;i<keys.count;i++)
  5727. {
  5728. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  5729. }
  5730. if(appDelegate.offline_mode)
  5731. {
  5732. [OLDataProvider offline_createorder:params completionHandler:^(NSMutableDictionary *resulti) {
  5733. int result_code = [[resulti valueForKey:@"result"] intValue];
  5734. if (result_code==2)
  5735. {
  5736. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5737. [appDelegate update_count_mark];
  5738. };
  5739. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  5740. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5741. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  5742. }
  5743. result(resulti);
  5744. }];
  5745. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5746. // NSData* json = [[OLDataProvider offline_createorder:params] mutableCopy];
  5747. // dispatch_async(dispatch_get_main_queue(), ^{
  5748. // result([[RAConvertor data2dict:json] mutableCopy]);
  5749. // });
  5750. // });
  5751. return;
  5752. }
  5753. [self request_interface:URL_NEW_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5754. int result_code = [[resulti valueForKey:@"result"] intValue];
  5755. if (result_code==2)
  5756. {
  5757. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5758. [appDelegate update_count_mark];
  5759. };
  5760. [appDelegate SetSo:[resulti valueForKey:@"soId"]];
  5761. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5762. [RASingleton sharedInstance].currentOrderIsMerged = NO;
  5763. }
  5764. result(resulti);
  5765. } retry:0];
  5766. //
  5767. // NSData* json = nil;
  5768. // if(appDelegate.offline_mode)
  5769. // {
  5770. // json= [OLDataProvider offline_createorder:params];
  5771. // }
  5772. // else
  5773. // {
  5774. // if(![self IsNetworkAvailable])
  5775. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5776. //
  5777. // json=[self get_json:URL_NEW_ORDER parameters:params];
  5778. // }
  5779. // if(json==nil)
  5780. // return nil;
  5781. // NSError *error=nil;
  5782. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5783. // int result = [[jsobj valueForKey:@"result"] intValue];
  5784. //
  5785. // if (result==2)
  5786. // {
  5787. //
  5788. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5789. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  5790. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5791. //
  5792. // [appDelegate update_count_mark];
  5793. // }
  5794. //
  5795. // [appDelegate SetSo:[jsobj valueForKey:@"soId"]];
  5796. //
  5797. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5798. // [Singleton sharedInstance].currentOrderIsMerged = NO;
  5799. // }
  5800. //
  5801. // return jsobj;
  5802. }
  5803. +(void)request_open_order:(NSString*) order_code completionHandler:(resultHandler)result
  5804. {
  5805. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5806. AppDelegate *appDelegate = nil;
  5807. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5808. if(appDelegate.user!=nil)
  5809. [params setValue:appDelegate.user forKey:@"user"];
  5810. // if(appDelegate.contact_id!=nil)
  5811. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5812. if(appDelegate.password!=nil)
  5813. [params setValue:appDelegate.password forKey:@"password"];
  5814. [params setValue:order_code forKey:@"orderCode"];
  5815. // [params setValue:sourceid forKey:@"sourceid"];
  5816. // [params setValue:editor forKey:@"editor"];
  5817. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  5818. if(appDelegate.offline_mode)
  5819. {
  5820. params[@"appDelegate.order_code"]=appDelegate.order_code;
  5821. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5822. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_editorder:params]] mutableCopy];
  5823. dispatch_async(dispatch_get_main_queue(), ^{
  5824. int result_code = [[resulti valueForKey:@"result"] intValue];
  5825. if (result_code==2)
  5826. {
  5827. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5828. [appDelegate update_count_mark];
  5829. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5830. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  5831. }
  5832. }
  5833. result(resulti);
  5834. });
  5835. });
  5836. return;
  5837. }
  5838. [self request_interface:URL_OPEN_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5839. int result_code = [[resulti valueForKey:@"result"] intValue];
  5840. if (result_code==2)
  5841. {
  5842. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5843. [appDelegate update_count_mark];
  5844. if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5845. [RASingleton sharedInstance].currentOrderIsMerged = [[resulti valueForKey:@"is_merged_order"] boolValue];
  5846. }
  5847. }
  5848. result(resulti);
  5849. } retry:0];
  5850. //
  5851. // NSData* json=nil;
  5852. // if(appDelegate.offline_mode)
  5853. // {
  5854. // json=[OLDataProvider offline_editorder:params];
  5855. //
  5856. // }
  5857. // else
  5858. // {
  5859. // if(![self IsNetworkAvailable])
  5860. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  5861. //
  5862. // json=[self get_json:URL_OPEN_ORDER parameters:params];
  5863. // }
  5864. // if(json!=nil)
  5865. // {
  5866. // NSError *error=nil;
  5867. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5868. // int result = [[jsobj valueForKey:@"result"] intValue];
  5869. //
  5870. // if (result==2)
  5871. // {
  5872. //
  5873. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  5874. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  5875. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  5876. //
  5877. // [appDelegate update_count_mark];
  5878. //
  5879. // if (appDelegate.user_type == USER_ROLE_CUSTOMER) {
  5880. // [Singleton sharedInstance].currentOrderIsMerged = [[jsobj valueForKey:@"is_merged_order"] boolValue];
  5881. // }
  5882. //
  5883. // }
  5884. //
  5885. // return jsobj;
  5886. // }
  5887. // else
  5888. // return nil;
  5889. }
  5890. +(void)request_order_discount:(double)discount completionHandler:(resultHandler)result
  5891. {
  5892. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5893. AppDelegate *appDelegate = nil;
  5894. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5895. if(appDelegate.user!=nil)
  5896. [params setValue:appDelegate.user forKey:@"user"];
  5897. // if(appDelegate.contact_id!=nil)
  5898. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5899. if(appDelegate.password!=nil)
  5900. [params setValue:appDelegate.password forKey:@"password"];
  5901. if(appDelegate.order_code!=nil)
  5902. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5903. [params setValue:@(discount) forKey:@"app_discount"];
  5904. if(appDelegate.offline_mode)
  5905. {
  5906. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5907. NSMutableDictionary* json = [[OLDataProvider offline_setorderdiscount:params] mutableCopy];
  5908. dispatch_async(dispatch_get_main_queue(), ^{
  5909. result(json);
  5910. });
  5911. });
  5912. return;
  5913. //
  5914. //
  5915. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5916. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  5917. // dispatch_async(dispatch_get_main_queue(), ^{
  5918. // result(json);
  5919. // });
  5920. // });
  5921. //
  5922. // return;
  5923. }
  5924. [self request_interface:URL_ORDER_DISCOUNT parameters:params err_record_url:nil completionHandler:result retry:0];
  5925. }
  5926. +(void)request_cart:(int)sort completionHandler:(resultHandler)result
  5927. {
  5928. DebugLog(@"iSalesNetwork::request_Cart");
  5929. AppDelegate *appDelegate = nil;
  5930. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  5931. #ifdef SCANNER_ORDER
  5932. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  5933. {
  5934. appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  5935. [appDelegate update_count_mark];
  5936. result(RASingleton.sharedInstance.scan_cart);
  5937. return;
  5938. }
  5939. #else
  5940. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  5941. if(appDelegate.user!=nil)
  5942. [params setValue:appDelegate.user forKey:@"user"];
  5943. // if(appDelegate.contact_id!=nil)
  5944. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  5945. if(appDelegate.password!=nil)
  5946. [params setValue:appDelegate.password forKey:@"password"];
  5947. if(appDelegate.order_code!=nil)
  5948. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  5949. [params setValue:[NSNumber numberWithInt:sort] forKey:@"sort"];
  5950. [params setObject:ScreenCodeCart forKey:kScreenName];
  5951. if(appDelegate.offline_mode)
  5952. {
  5953. [OLDataProvider offline_requestcart:params completionHandler:^(NSMutableDictionary *resulti) {
  5954. if([resulti[@"result"] intValue]==2)
  5955. {
  5956. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5957. [appDelegate update_count_mark];
  5958. result(resulti);
  5959. }
  5960. }];
  5961. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5962. // NSData* json = [[OLDataProvider offline_requestcart:params] mutableCopy];
  5963. // dispatch_async(dispatch_get_main_queue(), ^{
  5964. // result([[RAConvertor data2dict:json] mutableCopy]);
  5965. // });
  5966. // });
  5967. return;
  5968. }
  5969. NSString * uuid= [[NSUUID UUID] UUIDString];
  5970. params[@"resultSerial"]=uuid;
  5971. __block bool bbreak = false;
  5972. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  5973. for(int i=0;i<150;i++)
  5974. {
  5975. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  5976. // result_params[@"resultSerial"]=uuid;
  5977. if(bbreak)
  5978. break;
  5979. dispatch_async(dispatch_get_main_queue(), ^{
  5980. [self request_interface:URL_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  5981. if([resulti[@"result"] intValue]==2)
  5982. {
  5983. if(!bbreak) //此判断保证result只调用一次。
  5984. {
  5985. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  5986. [appDelegate update_count_mark];
  5987. result(resulti);
  5988. }
  5989. bbreak=true;
  5990. }
  5991. } retry:3];
  5992. });
  5993. sleep(2);
  5994. // json=[self get_json:URL_CART parameters:params];
  5995. // if(json!=nil)
  5996. // {
  5997. //
  5998. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  5999. // if([jsobj[@"result"] intValue]==2)
  6000. // {
  6001. // break;
  6002. // }
  6003. // }
  6004. }
  6005. });
  6006. //
  6007. //
  6008. //
  6009. // NSData* json=nil;
  6010. // if(appDelegate.offline_mode)
  6011. // {
  6012. // json= [OLDataProvider offline_requestcart:params];
  6013. // }
  6014. // else
  6015. // {
  6016. // if(![self IsNetworkAvailable])
  6017. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6018. //
  6019. // NSError *error=nil;
  6020. //
  6021. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6022. // params[@"resultSerial"]=uuid;
  6023. //
  6024. // for(int i=0;i<150;i++)
  6025. // {
  6026. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6027. // // result_params[@"resultSerial"]=uuid;
  6028. // json=[self get_json:URL_CART parameters:params];
  6029. // if(json!=nil)
  6030. // {
  6031. //
  6032. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6033. // if([jsobj[@"result"] intValue]==2)
  6034. // {
  6035. // break;
  6036. // }
  6037. // }
  6038. // sleep(2);
  6039. // }
  6040. //
  6041. // }
  6042. // if(json==nil)
  6043. // return nil;
  6044. // NSError *error=nil;
  6045. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6046. // int result = [[jsobj valueForKey:@"result"] intValue];
  6047. //
  6048. // if (result==2)
  6049. // {
  6050. //
  6051. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6052. // //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  6053. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6054. //
  6055. // [appDelegate update_count_mark];
  6056. // }
  6057. // return jsobj;
  6058. #endif
  6059. }
  6060. +(void) request_move_wish2cart:(NSString* ) item_ids completionHandler:(resultHandler)result
  6061. {
  6062. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6063. AppDelegate *appDelegate = nil;
  6064. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6065. if(appDelegate.user!=nil)
  6066. [params setValue:appDelegate.user forKey:@"user"];
  6067. if(appDelegate.contact_id!=nil)
  6068. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6069. if(appDelegate.password!=nil)
  6070. [params setValue:appDelegate.password forKey:@"password"];
  6071. if(appDelegate.order_code!=nil)
  6072. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6073. [params setValue:item_ids forKey:@"collectId"];
  6074. // [params setValue:editor forKey:@"editor"];
  6075. [params setValue:ScreenCodeWishList forKey:kScreenName];
  6076. [params setValue:@"Move To Cart" forKey:kAction];
  6077. if(appDelegate.offline_mode)
  6078. {
  6079. // [OLDataProvider offline_movewish2cart:params completionHandler:result];
  6080. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6081. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6082. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movewish2cart:params]] mutableCopy];
  6083. dispatch_async(dispatch_get_main_queue(), ^{
  6084. int result_code = [[resulti valueForKey:@"result"] intValue];
  6085. if (result_code==2)
  6086. {
  6087. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6088. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6089. [appDelegate update_count_mark];
  6090. }
  6091. result(resulti);
  6092. });
  6093. });
  6094. return;
  6095. }
  6096. [self request_interface:URL_WISH2CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6097. int result_code = [[resulti valueForKey:@"result"] intValue];
  6098. if (result_code==2)
  6099. {
  6100. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6101. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6102. [appDelegate update_count_mark];
  6103. }
  6104. result(resulti);
  6105. } retry:0];
  6106. //
  6107. // NSData *json = nil;
  6108. // if(appDelegate.offline_mode)
  6109. // {
  6110. // json = [OLDataProvider offline_movewish2cart:params];
  6111. // } else {
  6112. // if(![self IsNetworkAvailable])
  6113. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6114. //
  6115. // json=[self get_json:URL_WISH2CART parameters:params];
  6116. // }
  6117. //
  6118. // if(json!=nil)
  6119. // {
  6120. // NSError *error=nil;
  6121. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6122. // int result = [[jsobj valueForKey:@"result"] intValue];
  6123. //
  6124. // if (result==2)
  6125. // {
  6126. //
  6127. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6128. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6129. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6130. //
  6131. // [appDelegate update_count_mark];
  6132. // }
  6133. // return jsobj;
  6134. // }
  6135. // else
  6136. // return nil;
  6137. }
  6138. +(void) request_move_cart2wish:(NSString* ) item_ids completionHandler:(resultHandler)result
  6139. {
  6140. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6141. AppDelegate *appDelegate = nil;
  6142. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6143. if(appDelegate.user!=nil)
  6144. [params setValue:appDelegate.user forKey:@"user"];
  6145. if(appDelegate.contact_id!=nil)
  6146. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6147. if(appDelegate.password!=nil)
  6148. [params setValue:appDelegate.password forKey:@"password"];
  6149. if(appDelegate.order_code!=nil)
  6150. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6151. [params setValue:item_ids forKey:@"cartItemId"];
  6152. // [params setValue:editor forKey:@"editor"];
  6153. [params setValue:ScreenCodeCart forKey:kScreenName];
  6154. // [params setValue:@"Cart Move To Wish List" forKey:kAction];
  6155. if(appDelegate.offline_mode)
  6156. {
  6157. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6158. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_movecart2wish:params]] mutableCopy];
  6159. dispatch_async(dispatch_get_main_queue(), ^{
  6160. int result_code = [[resulti valueForKey:@"result"] intValue];
  6161. if (result_code==2)
  6162. {
  6163. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6164. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6165. [appDelegate update_count_mark];
  6166. }
  6167. result(resulti);
  6168. });
  6169. });
  6170. return;
  6171. }
  6172. [self request_interface:URL_CART2WISH parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6173. int result_code = [[resulti valueForKey:@"result"] intValue];
  6174. if (result_code==2)
  6175. {
  6176. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6177. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6178. [appDelegate update_count_mark];
  6179. }
  6180. result(resulti);
  6181. } retry:0];
  6182. //
  6183. // NSData* json = nil;
  6184. // if(appDelegate.offline_mode)
  6185. // {
  6186. // json= [OLDataProvider offline_movecart2wish:params];
  6187. // }
  6188. // else
  6189. // {
  6190. // if(![self IsNetworkAvailable])
  6191. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6192. //
  6193. // json=[self get_json:URL_CART2WISH parameters:params];
  6194. // }
  6195. // if(json!=nil)
  6196. // {
  6197. // NSError *error=nil;
  6198. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6199. // int result = [[jsobj valueForKey:@"result"] intValue];
  6200. //
  6201. // if (result==2)
  6202. // {
  6203. //
  6204. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6205. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6206. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6207. //
  6208. // [appDelegate update_count_mark];
  6209. // }
  6210. // return jsobj;
  6211. // }
  6212. // else
  6213. // return nil;
  6214. }
  6215. +(void)request_orderdetail:(NSMutableDictionary *) params completionHandler:(resultHandler)result
  6216. {
  6217. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6218. if (params == nil) {
  6219. params = [[NSMutableDictionary alloc] init];
  6220. }
  6221. AppDelegate *appDelegate = nil;
  6222. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6223. if(appDelegate.user!=nil)
  6224. [params setValue:appDelegate.user forKey:@"user"];
  6225. if(appDelegate.contact_id!=nil)
  6226. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6227. if(appDelegate.password!=nil)
  6228. [params setValue:appDelegate.password forKey:@"password"];
  6229. // [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
  6230. [params setObject:ScreenCodeOrderInfo forKey:kScreenName];
  6231. if(appDelegate.offline_mode)
  6232. {
  6233. params[@"mode"]=appDelegate.mode;
  6234. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6235. NSData* json = [[OLDataProvider offline_orderdetail:params] mutableCopy];
  6236. dispatch_async(dispatch_get_main_queue(), ^{
  6237. result([[RAConvertor data2dict:json] mutableCopy]);
  6238. });
  6239. });
  6240. return;
  6241. }
  6242. NSString * uuid= [[NSUUID UUID] UUIDString];
  6243. params[@"resultSerial"]=uuid;
  6244. __block bool bbreak = false;
  6245. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6246. for(int i=0;i<150;i++)
  6247. {
  6248. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6249. // result_params[@"resultSerial"]=uuid;
  6250. if(bbreak)
  6251. break;
  6252. dispatch_async(dispatch_get_main_queue(), ^{
  6253. [self request_interface:URL_ORDER_DETAIL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6254. if([resulti[@"result"] intValue]==2||[resulti[@"result"] intValue]==8)
  6255. {
  6256. if(!bbreak)//此判断保证result只调用一次。
  6257. result(resulti);
  6258. bbreak=true;
  6259. }
  6260. } retry:3];
  6261. });
  6262. sleep(2);
  6263. }
  6264. });
  6265. //
  6266. // NSData* json=nil;
  6267. // if(appDelegate.offline_mode)
  6268. // {
  6269. // json= [OLDataProvider offline_orderdetail:params];
  6270. // }
  6271. // else
  6272. // {
  6273. // if(![self IsNetworkAvailable])
  6274. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6275. //
  6276. // NSError *error=nil;
  6277. //
  6278. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6279. // params[@"resultSerial"]=uuid;
  6280. //
  6281. // for(int i=0;i<150;i++)
  6282. // {
  6283. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6284. // // result_params[@"resultSerial"]=uuid;
  6285. // json=[self get_json:URL_ORDER_DETAIL parameters:params];
  6286. // if(json!=nil)
  6287. // {
  6288. //
  6289. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6290. // int resultCode = [jsobj[@"result"] intValue];
  6291. // if(resultCode==2 || resultCode == 8)
  6292. // {
  6293. // break;
  6294. // }
  6295. // }
  6296. // sleep(2);
  6297. // }
  6298. //
  6299. //
  6300. // }
  6301. // if(json==nil)
  6302. // return nil;
  6303. // NSError *error=nil;
  6304. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6305. // return jsobj;
  6306. }
  6307. //
  6308. //+(void)request_commit_order:(NSString*) order_code completionHandler:(resultHandler)result
  6309. //{
  6310. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6311. // AppDelegate *appDelegate = nil;
  6312. //
  6313. //
  6314. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6315. //
  6316. // if(appDelegate.user!=nil)
  6317. // [params setValue:appDelegate.user forKey:@"user"];
  6318. // if(appDelegate.contact_id!=nil)
  6319. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6320. // if(appDelegate.password!=nil)
  6321. // [params setValue:appDelegate.password forKey:@"password"];
  6322. // // NSString* ssaved = @"false";
  6323. // // if(saved)
  6324. // // ssaved=@"true";
  6325. // [params setValue:@"true" forKey:@"saved"];
  6326. // [params setValue:order_code forKey:@"orderCode"];
  6327. // // [params setValue:sourceid forKey:@"sourceid"];
  6328. // // [params setValue:editor forKey:@"editor"];
  6329. //
  6330. // [params setValue:ScreenCodePlaceOrder forKey:kScreenName];
  6331. //
  6332. //
  6333. // if(appDelegate.offline_mode)
  6334. // {
  6335. //
  6336. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6337. // NSMutableDictionary* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  6338. // dispatch_async(dispatch_get_main_queue(), ^{
  6339. // result(json);
  6340. // });
  6341. // });
  6342. //
  6343. // return;
  6344. // }
  6345. //
  6346. //
  6347. // [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6348. //
  6349. //// NSData* json = nil;
  6350. ////
  6351. //// if(appDelegate.offline_mode)
  6352. //// {
  6353. //// json= [OLDataProvider offline_submitorder:params];
  6354. //// }
  6355. //// else
  6356. //// {
  6357. //// if(![self IsNetworkAvailable])
  6358. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6359. ////
  6360. //// json=[self get_json:URL_COMMIT_ORDER parameters:params];
  6361. //// }
  6362. //// if(json!=nil)
  6363. //// {
  6364. //// NSError *error=nil;
  6365. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6366. //// return jsobj;
  6367. //// }
  6368. //// else
  6369. //// return nil;
  6370. //
  6371. //}
  6372. +(void)request_copy_order:(NSString*) order_code completionHandler:(resultHandler)result
  6373. {
  6374. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6375. AppDelegate *appDelegate = nil;
  6376. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6377. if(appDelegate.user!=nil)
  6378. [params setValue:appDelegate.user forKey:@"user"];
  6379. if(appDelegate.contact_id!=nil)
  6380. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6381. if(appDelegate.password!=nil)
  6382. [params setValue:appDelegate.password forKey:@"password"];
  6383. // NSString* ssaved = @"false";
  6384. // if(saved)
  6385. // ssaved=@"true";
  6386. // [params setValue:@"true" forKey:@"saved"];
  6387. [params setValue:order_code forKey:@"code"];
  6388. // [params setValue:sourceid forKey:@"sourceid"];
  6389. // [params setValue:editor forKey:@"editor"];
  6390. [params setValue:ScreenCodeOrderInfo forKey:kScreenName];
  6391. if(appDelegate.offline_mode)
  6392. {
  6393. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6394. NSData* json = [[OLDataProvider offline_copyorder:params] mutableCopy];
  6395. dispatch_async(dispatch_get_main_queue(), ^{
  6396. result([[RAConvertor data2dict:json] mutableCopy]);
  6397. });
  6398. });
  6399. return;
  6400. }
  6401. [self request_interface:URL_COPY_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  6402. // NSData* json=nil;
  6403. // if(appDelegate.offline_mode)
  6404. // {
  6405. // json= [OLDataProvider offline_copyorder:params];
  6406. // }
  6407. // else
  6408. // {
  6409. // if(![self IsNetworkAvailable])
  6410. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6411. //
  6412. // json=[self get_json:URL_COPY_ORDER parameters:params];
  6413. // }
  6414. // if(json!=nil)
  6415. // {
  6416. // NSError *error=nil;
  6417. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6418. // return jsobj;
  6419. // }
  6420. // else
  6421. // return nil;
  6422. }
  6423. //
  6424. //+ (void)request_fastdownload:(NSMutableDictionary *)params url:(NSString *)url completionHandler:(resultHandler)result
  6425. //{
  6426. //
  6427. // //#ifdef test_server
  6428. // // url=URL_REQUEST_RECORDS;
  6429. // // params[@"prefix"]=URL_REQUEST_RECORDS;
  6430. // //#endif
  6431. //
  6432. // [self request_file_fast:url parameters:params completionHandler:result];
  6433. //
  6434. //}
  6435. +(void) request_addto_portfolio:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6436. {
  6437. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6438. AppDelegate *appDelegate = nil;
  6439. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6440. if(appDelegate.user!=nil)
  6441. [params setValue:appDelegate.user forKey:@"user"];
  6442. if(appDelegate.contact_id!=nil)
  6443. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6444. if(appDelegate.password!=nil)
  6445. [params setValue:appDelegate.password forKey:@"password"];
  6446. [params setValue:item_id forKey:@"product_id"];
  6447. [params setObject:screenName forKey:kScreenName];
  6448. if(appDelegate.offline_mode)
  6449. {
  6450. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6451. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_add2Portfolio:params]] mutableCopy];
  6452. dispatch_async(dispatch_get_main_queue(), ^{
  6453. int result_code = [[resulti valueForKey:@"result"] intValue];
  6454. if (result_code==2)
  6455. {
  6456. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6457. [appDelegate update_count_mark];
  6458. }
  6459. result(resulti);
  6460. });
  6461. });
  6462. return;
  6463. }
  6464. [self request_interface:URL_ADD_TO_PORTFOLIO parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6465. int result_code = [[resulti valueForKey:@"result"] intValue];
  6466. if (result_code==2)
  6467. {
  6468. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  6469. [appDelegate update_count_mark];
  6470. }
  6471. result(resulti);
  6472. } retry:0];
  6473. //
  6474. // NSData* json = nil;
  6475. // if(appDelegate.offline_mode)
  6476. // {
  6477. // json = [OLDataProvider offline_add2Portfolio:params];
  6478. // } else {
  6479. // if(![self IsNetworkAvailable])
  6480. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6481. //
  6482. // json=[self get_json:URL_ADD_TO_PORTFOLIO parameters:params];
  6483. // }
  6484. //
  6485. // if(json==nil)
  6486. // return nil;
  6487. // NSError *error=nil;
  6488. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6489. // int result = [[jsobj valueForKey:@"result"] intValue];
  6490. //
  6491. // if (result==2)
  6492. // {
  6493. //
  6494. // // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6495. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6496. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6497. //
  6498. // [appDelegate update_count_mark];
  6499. // }
  6500. // return jsobj;
  6501. }
  6502. +(void)request_addall_search:(long ) offset limit :(long)limit keywords :(NSString*) keywords matchfull:(bool)matchfull orderCode:(NSString*) orderCode addTo:(NSString*) addTo completionHandler:(resultHandler)result
  6503. {
  6504. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6505. AppDelegate *appDelegate = nil;
  6506. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6507. if(appDelegate.user!=nil)
  6508. [params setValue:appDelegate.user forKey:@"user"];
  6509. if(appDelegate.contact_id!=nil)
  6510. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6511. if(appDelegate.password!=nil)
  6512. [params setValue:appDelegate.password forKey:@"password"];
  6513. if(appDelegate.order_code!=nil)
  6514. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6515. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6516. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6517. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  6518. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6519. // [params setValue:filter forKey:@"filter"];
  6520. [params setValue:keywords forKey:@"keyword"];
  6521. [params setValue:addTo forKey:@"addTo"];
  6522. [params setValue:orderCode forKey:@"orderCode"];
  6523. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6524. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6525. if(matchfull)
  6526. [params setValue:@"true" forKey:@"exactMatch"];
  6527. else
  6528. [params setValue:@"false" forKey:@"exactMatch"];
  6529. [params setObject:ScreenCodeSearch forKey:kScreenName];
  6530. if ([addTo isEqualToString:@"cart"]) {
  6531. [params setObject:@"Add To Cart" forKey:kAction];
  6532. }
  6533. if(appDelegate.offline_mode)
  6534. {
  6535. if ([addTo isEqualToString:@"cart"])
  6536. {
  6537. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6538. }
  6539. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6540. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_searchaddall:params]] mutableCopy];
  6541. dispatch_async(dispatch_get_main_queue(), ^{
  6542. int result_code =[json[@"result"] intValue];
  6543. if (result_code==2||result_code==8)
  6544. {
  6545. if(json[@"cart_count"])
  6546. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6547. if(json[@"wish_count"])
  6548. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  6549. if(json[@"portfolio_count"])
  6550. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  6551. //
  6552. //
  6553. [appDelegate update_count_mark];
  6554. }
  6555. result(json);
  6556. });
  6557. });
  6558. return;
  6559. }
  6560. NSString * uuid= [[NSUUID UUID] UUIDString];
  6561. params[@"resultSerial"]=uuid;
  6562. __block bool bbreak = false;
  6563. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6564. for(int i=0;i<150;i++)
  6565. {
  6566. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6567. // result_params[@"resultSerial"]=uuid;
  6568. if(bbreak)
  6569. break;
  6570. dispatch_async(dispatch_get_main_queue(), ^{
  6571. [self request_interface:URL_SEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6572. if([resulti[@"result"] intValue]==2)
  6573. {
  6574. if(!bbreak)//此判断保证result只调用一次。
  6575. result(resulti);
  6576. bbreak=true;
  6577. }
  6578. } retry:3];
  6579. });
  6580. sleep(2);
  6581. }
  6582. });
  6583. //
  6584. //
  6585. // NSData* json=nil;
  6586. // if(appDelegate.offline_mode)
  6587. // {
  6588. // json=[OLDataProvider offline_searchaddall:params];
  6589. // }
  6590. // else
  6591. // {
  6592. // if(![self IsNetworkAvailable])
  6593. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6594. //
  6595. // NSError *error=nil;
  6596. //
  6597. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6598. // params[@"resultSerial"]=uuid;
  6599. //
  6600. // for(int i=0;i<150;i++)
  6601. // {
  6602. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6603. // // result_params[@"resultSerial"]=uuid;
  6604. // json=[self get_json:URL_SEARCHADDALL parameters:params];
  6605. // if(json!=nil)
  6606. // {
  6607. //
  6608. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6609. // if([jsobj[@"result"] intValue]==2)
  6610. // {
  6611. // break;
  6612. // }
  6613. // }
  6614. // sleep(2);
  6615. // }
  6616. // }
  6617. // if(json==nil)
  6618. // return nil;
  6619. // NSError *error=nil;
  6620. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6621. // return jsobj;
  6622. }
  6623. +(void) request_addto_cart_byupc:(NSString* ) upc_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6624. {
  6625. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6626. AppDelegate *appDelegate = nil;
  6627. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6628. if(appDelegate.user!=nil)
  6629. [params setValue:appDelegate.user forKey:@"user"];
  6630. if(appDelegate.contact_id!=nil)
  6631. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6632. if(appDelegate.password!=nil)
  6633. [params setValue:appDelegate.password forKey:@"password"];
  6634. if(appDelegate.order_code!=nil)
  6635. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6636. [params setValue:upc_code forKey:@"upc_code"];
  6637. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  6638. [params setObject:screenName forKey:kScreenName];
  6639. [params setObject:@"Add To Cart" forKey:kAction];
  6640. if (!upc_code) {
  6641. upc_code = @"";
  6642. }
  6643. [params setObject:@{@"UPCCode" : upc_code} forKey:kExtra];
  6644. params[@"search_upc"]=@true;
  6645. NSDictionary* customerinfo= appDelegate.customerInfo;
  6646. NSArray* keys=[customerinfo allKeys];
  6647. for(int i=0;i<keys.count;i++)
  6648. {
  6649. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  6650. }
  6651. if(appDelegate.offline_mode)
  6652. {
  6653. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6654. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  6655. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6656. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyupc:params]] mutableCopy];
  6657. dispatch_async(dispatch_get_main_queue(), ^{
  6658. int result_code = [[json valueForKey:@"result"] intValue];
  6659. if (result_code==2||result_code==8)
  6660. {
  6661. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6662. [appDelegate update_count_mark];
  6663. }
  6664. result(json);
  6665. });
  6666. });
  6667. return;
  6668. }
  6669. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6670. int result_code = [[resulti valueForKey:@"result"] intValue];
  6671. if (result_code==2||result_code==8)
  6672. {
  6673. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6674. [appDelegate update_count_mark];
  6675. }
  6676. result(resulti);
  6677. } retry:0];
  6678. }
  6679. +(void) request_addto_cart_byname:(NSString* ) model_name withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6680. {
  6681. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6682. AppDelegate *appDelegate = nil;
  6683. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6684. if(appDelegate.user!=nil)
  6685. [params setValue:appDelegate.user forKey:@"user"];
  6686. if(appDelegate.contact_id!=nil)
  6687. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6688. if(appDelegate.password!=nil)
  6689. [params setValue:appDelegate.password forKey:@"password"];
  6690. if(appDelegate.order_code!=nil)
  6691. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6692. [params setValue:model_name forKey:@"product_name"];
  6693. [params setValue:[NSString stringWithFormat:@"%d",-1] forKey:@"count"];
  6694. [params setObject:screenName forKey:kScreenName];
  6695. [params setObject:@"Add To Cart" forKey:kAction];
  6696. if (!model_name) {
  6697. model_name = @"";
  6698. }
  6699. [params setObject:@{@"ModelName" : model_name} forKey:kExtra];
  6700. NSDictionary* customerinfo= appDelegate.customerInfo;
  6701. NSArray* keys=[customerinfo allKeys];
  6702. for(int i=0;i<keys.count;i++)
  6703. {
  6704. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  6705. }
  6706. if(appDelegate.offline_mode)
  6707. {
  6708. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6709. // [OLDataProvider offline_add2cartbyname:params completionHandler:result];
  6710. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6711. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cartbyname:params]] mutableCopy];
  6712. dispatch_async(dispatch_get_main_queue(), ^{
  6713. int result_code = [[json valueForKey:@"result"] intValue];
  6714. if (result_code==2||result_code==8)
  6715. {
  6716. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6717. [appDelegate update_count_mark];
  6718. }
  6719. result(json);
  6720. });
  6721. });
  6722. return;
  6723. }
  6724. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6725. int result_code = [[resulti valueForKey:@"result"] intValue];
  6726. if (result_code==2||result_code==8)
  6727. {
  6728. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  6729. [appDelegate update_count_mark];
  6730. }
  6731. result(resulti);
  6732. } retry:0];
  6733. // NSData* json=nil;
  6734. // if(appDelegate.offline_mode)
  6735. // {
  6736. // json= [OLDataProvider offline_add2cartbyname:params];
  6737. // }
  6738. // else
  6739. // {
  6740. // if(![self IsNetworkAvailable])
  6741. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6742. //
  6743. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  6744. // }
  6745. // if(json==nil)
  6746. // return nil;
  6747. // NSError *error=nil;
  6748. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6749. //
  6750. //
  6751. //
  6752. // int result = [[jsobj valueForKey:@"result"] intValue];
  6753. //
  6754. // if (result==2||result==8)
  6755. // {
  6756. //
  6757. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6758. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6759. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6760. //
  6761. // [appDelegate update_count_mark];
  6762. // }
  6763. //
  6764. // return jsobj;
  6765. }
  6766. +(void) request_addto_wishlist:(NSString* ) item_id withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  6767. {
  6768. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6769. AppDelegate *appDelegate = nil;
  6770. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6771. if(appDelegate.user!=nil)
  6772. [params setValue:appDelegate.user forKey:@"user"];
  6773. if(appDelegate.contact_id!=nil)
  6774. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6775. if(appDelegate.password!=nil)
  6776. [params setValue:appDelegate.password forKey:@"password"];
  6777. [params setValue:item_id forKey:@"product_id"];
  6778. [params setObject:screenName forKey:kScreenName];
  6779. if(appDelegate.offline_mode)
  6780. {
  6781. // [OLDataProvider offline_add2wishlist:params completionHandler:result];
  6782. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6783. NSMutableDictionary* resulti = [[OLDataProvider offline_add2wishlist:params] mutableCopy];
  6784. dispatch_async(dispatch_get_main_queue(), ^{
  6785. int result_code = [[resulti valueForKey:@"result"] intValue];
  6786. if (result_code==2||result_code==8)
  6787. {
  6788. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6789. [appDelegate update_count_mark];
  6790. }
  6791. result(resulti);
  6792. });
  6793. });
  6794. return;
  6795. }
  6796. [self request_interface:URL_ADD_TO_WATCHLIST parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6797. int result_code = [[resulti valueForKey:@"result"] intValue];
  6798. if (result_code==2||result_code==8)
  6799. {
  6800. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  6801. [appDelegate update_count_mark];
  6802. }
  6803. result(resulti);
  6804. } retry:0];
  6805. // if(appDelegate.offline_mode)
  6806. // {
  6807. // return [OLDataProvider offline_add2wishlist:params];
  6808. // }
  6809. // if(![self IsNetworkAvailable])
  6810. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6811. //
  6812. // NSData* json=[self get_json:URL_ADD_TO_WATCHLIST parameters:params];
  6813. // if(json==nil)
  6814. // return nil;
  6815. // NSError *error=nil;
  6816. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6817. // int result = [[jsobj valueForKey:@"result"] intValue];
  6818. //
  6819. // if (result==2)
  6820. // {
  6821. //
  6822. // //appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  6823. // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  6824. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  6825. //
  6826. // [appDelegate update_count_mark];
  6827. // }
  6828. // return jsobj;
  6829. }
  6830. +(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
  6831. {
  6832. // for debug
  6833. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  6834. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6835. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6836. AppDelegate *appDelegate = nil;
  6837. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6838. if(appDelegate.user!=nil)
  6839. [params setValue:appDelegate.user forKey:@"user"];
  6840. if(appDelegate.contact_id!=nil)
  6841. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6842. if(appDelegate.password!=nil)
  6843. [params setValue:appDelegate.password forKey:@"password"];
  6844. if(appDelegate.order_code!=nil)
  6845. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6846. [params setValue:addTo forKey:@"addTo"];
  6847. [params setValue:orderCode forKey:@"orderCode"];
  6848. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6849. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6850. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  6851. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6852. // [params setValue:filter forKey:@"filter"];
  6853. [params setValue:covertype forKey:@"covertype"];
  6854. [params setValue:ctgid forKey:@"ctgId"];
  6855. [params setValue:modelname forKey:@"modelName"];
  6856. [params setValue:modeldescrip forKey:@"modelDescription"];
  6857. [params setValue:alert forKey:@"alert"];
  6858. [params setValue:qty forKey:@"sold_by_qty"];
  6859. [params setValue:available forKey:@"available"];
  6860. [params setValue:price forKey:@"price"];
  6861. [params setValue:bestseller forKey:@"bestseller"];
  6862. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6863. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6864. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  6865. if ([addTo isEqualToString:@"cart"]) {
  6866. [params setObject:@"Add To Cart" forKey:kAction];
  6867. }
  6868. if(appDelegate.offline_mode)
  6869. {
  6870. if ([addTo isEqualToString:@"cart"])
  6871. {
  6872. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6873. }
  6874. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6875. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_itemsearchaddall:params]] mutableCopy];
  6876. dispatch_async(dispatch_get_main_queue(), ^{
  6877. int result_code =[json[@"result"] intValue];
  6878. if (result_code==2||result_code==8)
  6879. {
  6880. if(json[@"cart_count"])
  6881. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  6882. if(json[@"wish_count"])
  6883. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  6884. if(json[@"portfolio_count"])
  6885. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  6886. //
  6887. //
  6888. [appDelegate update_count_mark];
  6889. }
  6890. result(json);
  6891. });
  6892. });
  6893. return;
  6894. }
  6895. NSString * uuid= [[NSUUID UUID] UUIDString];
  6896. params[@"resultSerial"]=uuid;
  6897. __block bool bbreak = false;
  6898. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6899. for(int i=0;i<150;i++)
  6900. {
  6901. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6902. // result_params[@"resultSerial"]=uuid;
  6903. if(bbreak)
  6904. break;
  6905. dispatch_async(dispatch_get_main_queue(), ^{
  6906. [self request_interface:URL_ITEMSEARCHADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  6907. if([resulti[@"result"] intValue]==2)
  6908. {
  6909. if(!bbreak)//此判断保证result只调用一次。
  6910. result(resulti);
  6911. bbreak=true;
  6912. }
  6913. } retry:3];
  6914. });
  6915. sleep(2);
  6916. }
  6917. });
  6918. //
  6919. // NSData* json = nil;
  6920. //
  6921. // if(appDelegate.offline_mode)
  6922. // {
  6923. // json= [OLDataProvider offline_itemsearchaddall:params];
  6924. // }
  6925. // else
  6926. // {
  6927. // if(![self IsNetworkAvailable])
  6928. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  6929. // NSError *error=nil;
  6930. //
  6931. // NSString * uuid= [[NSUUID UUID] UUIDString];
  6932. // params[@"resultSerial"]=uuid;
  6933. //
  6934. // for(int i=0;i<150;i++)
  6935. // {
  6936. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  6937. // // result_params[@"resultSerial"]=uuid;
  6938. // json=[self get_json:URL_ITEMSEARCHADDALL parameters:params];
  6939. // if(json!=nil)
  6940. // {
  6941. //
  6942. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6943. // if([jsobj[@"result"] intValue]==2)
  6944. // {
  6945. // break;
  6946. // }
  6947. // }
  6948. // sleep(2);
  6949. // }
  6950. // }
  6951. // if(json==nil)
  6952. // return nil;
  6953. // NSError *error=nil;
  6954. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  6955. // return jsobj;
  6956. }
  6957. +(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
  6958. {
  6959. AppDelegate *appDelegate = nil;
  6960. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  6961. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  6962. if(appDelegate.user!=nil)
  6963. [params setValue:appDelegate.user forKey:@"user"];
  6964. if(appDelegate.contact_id!=nil)
  6965. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  6966. if(appDelegate.password!=nil)
  6967. [params setValue:appDelegate.password forKey:@"password"];
  6968. if(appDelegate.order_code!=nil)
  6969. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  6970. [params setValue:addTo forKey:@"addTo"];
  6971. [params setValue:orderCode forKey:@"orderCode"];
  6972. [params setValue:alert forKey:@"alert"];
  6973. [params setValue:qty forKey:@"sold_by_qty"];
  6974. [params setValue:available forKey:@"available"];
  6975. [params setValue:price forKey:@"price"];
  6976. [params setValue:bestseller forKey:@"bestseller"];
  6977. [params setValue:modelname forKey:@"modelName"];
  6978. [params setValue:modeldescrip forKey:@"modelDescription"];
  6979. [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  6980. [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  6981. [params setValue:category forKey:@"category"];
  6982. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6983. [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  6984. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  6985. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  6986. [params setValue:filter forKey:@"filter"];
  6987. [params setValue:keyword forKey:@"keyword"];
  6988. [params setObject:ScreenCodeCategory forKey:kScreenName];
  6989. if ([addTo isEqualToString:@"cart"]) {
  6990. [params setObject:@"Add To Cart" forKey:kAction];
  6991. }
  6992. if(appDelegate.offline_mode)
  6993. {
  6994. if ([addTo isEqualToString:@"cart"])
  6995. {
  6996. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  6997. }
  6998. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  6999. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_categoryaddall:params]] mutableCopy];
  7000. dispatch_async(dispatch_get_main_queue(), ^{
  7001. int result_code =[json[@"result"] intValue];
  7002. if (result_code==2||result_code==8)
  7003. {
  7004. if(json[@"cart_count"])
  7005. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  7006. if(json[@"wish_count"])
  7007. appDelegate.wish_count =[[json valueForKey:@"wish_count"] intValue];
  7008. if(json[@"portfolio_count"])
  7009. appDelegate.port_count =[[json valueForKey:@"portfolio_count"] intValue];
  7010. //
  7011. //
  7012. [appDelegate update_count_mark];
  7013. }
  7014. result(json);
  7015. });
  7016. });
  7017. return;
  7018. }
  7019. NSString * uuid= [[NSUUID UUID] UUIDString];
  7020. params[@"resultSerial"]=uuid;
  7021. __block bool bbreak = false;
  7022. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7023. for(int i=0;i<150;i++)
  7024. {
  7025. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7026. // result_params[@"resultSerial"]=uuid;
  7027. if(bbreak)
  7028. break;
  7029. dispatch_async(dispatch_get_main_queue(), ^{
  7030. [self request_interface:URL_CATEGORYADDALL parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7031. if([resulti[@"result"] intValue]==2|| [resulti[@"result"] intValue] == 8)
  7032. {
  7033. if(!bbreak)//此判断保证result只调用一次。
  7034. {
  7035. int result_code =[resulti[@"result"] intValue];
  7036. if (result_code==2||result_code==8)
  7037. {
  7038. if(resulti[@"cart_count"])
  7039. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  7040. if(resulti[@"wish_count"])
  7041. appDelegate.wish_count =[[resulti valueForKey:@"wish_count"] intValue];
  7042. if(resulti[@"portfolio_count"])
  7043. appDelegate.port_count =[[resulti valueForKey:@"portfolio_count"] intValue];
  7044. //
  7045. //
  7046. [appDelegate update_count_mark];
  7047. }
  7048. result(resulti);
  7049. }
  7050. bbreak=true;
  7051. }
  7052. } retry:3];
  7053. });
  7054. sleep(2);
  7055. }
  7056. });
  7057. //
  7058. // NSData* json= nil;
  7059. //
  7060. // if(appDelegate.offline_mode)
  7061. // {
  7062. // json= [OLDataProvider offline_categoryaddall:params];
  7063. // }
  7064. // else
  7065. // {
  7066. // if(![self IsNetworkAvailable])
  7067. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7068. //
  7069. //
  7070. // NSError *error=nil;
  7071. //
  7072. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7073. // params[@"resultSerial"]=uuid;
  7074. //
  7075. // for(int i=0;i<150;i++)
  7076. // {
  7077. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7078. //// result_params[@"resultSerial"]=uuid;
  7079. // json=[self get_json:URL_CATEGORYADDALL parameters:params];
  7080. // if(json!=nil)
  7081. // {
  7082. //
  7083. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7084. // int resultInt = [jsobj[@"result"] intValue];
  7085. // if(resultInt == 2 || resultInt == 8)
  7086. // {
  7087. // break;
  7088. // }
  7089. // }
  7090. // sleep(2);
  7091. // }
  7092. //
  7093. //
  7094. //
  7095. // }
  7096. // if(json==nil)
  7097. // return nil;
  7098. // NSError *error=nil;
  7099. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7100. // return jsobj;
  7101. }
  7102. +(void)request_save_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7103. {
  7104. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7105. AppDelegate *appDelegate = nil;
  7106. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7107. if(appDelegate.user!=nil)
  7108. [params setValue:appDelegate.user forKey:@"user"];
  7109. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  7110. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7111. // else
  7112. if(appDelegate.contact_id!=nil)
  7113. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7114. if(appDelegate.password!=nil)
  7115. [params setValue:appDelegate.password forKey:@"password"];
  7116. if(appDelegate.order_code!=nil)
  7117. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7118. // NSDictionary* customerinfo=nil;
  7119. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  7120. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7121. // else
  7122. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7123. //
  7124. // appDelegate.customerInfo;
  7125. // NSArray* keys=[customerinfo allKeys];
  7126. // for(int i=0;i<keys.count;i++)
  7127. // {
  7128. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7129. // }
  7130. // [params setValue:sourceid forKey:@"sourceid"];
  7131. // [params setValue:editor forKey:@"editor"];
  7132. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  7133. if(appDelegate.offline_mode)
  7134. {
  7135. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7136. NSData* json = [[OLDataProvider offline_saveorder:params] mutableCopy];
  7137. dispatch_async(dispatch_get_main_queue(), ^{
  7138. result([[RAConvertor data2dict:json] mutableCopy]);
  7139. });
  7140. });
  7141. return;
  7142. }
  7143. [self request_interface:URL_SAVE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  7144. //
  7145. // NSData* json=nil;
  7146. //
  7147. // if(appDelegate.offline_mode)
  7148. // {
  7149. // json= [OLDataProvider offline_saveorder:params];
  7150. // }
  7151. // else
  7152. // {
  7153. // if(![self IsNetworkAvailable])
  7154. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7155. //
  7156. // json=[self get_json:URL_SAVE_ORDER parameters:params];
  7157. // }
  7158. // if(json!=nil)
  7159. // {
  7160. // NSError *error=nil;
  7161. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7162. // NSString *so = [jsobj valueForKey:@"so#"];
  7163. // if (so) {
  7164. // [appDelegate SetSo:so];
  7165. // }
  7166. // return jsobj;
  7167. // }
  7168. // else
  7169. // return nil;
  7170. }
  7171. +(void) request_update_cartqty:(NSString*) cart_id value:(int) value completionHandler:(resultHandler)result
  7172. {
  7173. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  7174. #ifdef SCANNER_ORDER
  7175. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7176. {
  7177. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7178. //
  7179. //
  7180. // [appDelegate update_count_mark];
  7181. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7182. int count = [section[@"count"] intValue];
  7183. for(int i=0;i<count;i++)
  7184. {
  7185. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7186. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7187. {
  7188. item[@"count"] =@(value);
  7189. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7190. break;
  7191. }
  7192. }
  7193. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7194. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7195. result(RASingleton.sharedInstance.scan_cart);
  7196. [OLDataProvider updateScanOrder:appDelegate.order_code];
  7197. return;
  7198. }
  7199. #else
  7200. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7201. if(appDelegate.user!=nil)
  7202. [params setValue:appDelegate.user forKey:@"user"];
  7203. if(appDelegate.contact_id!=nil)
  7204. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7205. if(appDelegate.password!=nil)
  7206. [params setValue:appDelegate.password forKey:@"password"];
  7207. [params setValue:cart_id forKey:@"cartitem_id"];
  7208. [params setObject:ScreenCodeCart forKey:kScreenName];
  7209. [params setValue:[NSString stringWithFormat:@"%d",value] forKey:@"inputInt"];
  7210. if(appDelegate.offline_mode)
  7211. {
  7212. params[@"can_create_backorder"]=@(appDelegate.can_create_backorder);
  7213. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7214. NSData* json = [[OLDataProvider offline_cartsetqty:params] mutableCopy];
  7215. dispatch_async(dispatch_get_main_queue(), ^{
  7216. result([[RAConvertor data2dict:json] mutableCopy]);
  7217. });
  7218. });
  7219. return;
  7220. }
  7221. [self request_interface:URL_CART_INCRESEMENT parameters:params err_record_url:nil completionHandler:result retry:0];
  7222. //
  7223. // NSData* json=nil;
  7224. // if(appDelegate.offline_mode)
  7225. // {
  7226. // json= [OLDataProvider offline_cartsetqty:params];
  7227. // }
  7228. // else
  7229. // {
  7230. // if(![self IsNetworkAvailable])
  7231. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7232. //
  7233. // json=[self get_json:URL_CART_INCRESEMENT parameters:params];
  7234. // }
  7235. // if(json==nil)
  7236. // return nil;
  7237. // NSError *error=nil;
  7238. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7239. // return jsobj;
  7240. #endif
  7241. }
  7242. +(void) request_update_cartgeneralnote:(NSString*) order_code notes:(NSString*) notes completionHandler:(resultHandler)result
  7243. {
  7244. #ifdef SCANNER_ORDER
  7245. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7246. {
  7247. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7248. //
  7249. //
  7250. // [appDelegate update_count_mark];
  7251. RASingleton.sharedInstance.scan_cart[@"general_note"] = notes;
  7252. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7253. result(RASingleton.sharedInstance.scan_cart);
  7254. return;
  7255. }
  7256. #else
  7257. AppDelegate *appDelegate = nil;
  7258. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7259. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7260. if(appDelegate.user!=nil)
  7261. [params setValue:appDelegate.user forKey:@"user"];
  7262. if(appDelegate.contact_id!=nil)
  7263. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7264. if(appDelegate.password!=nil)
  7265. [params setValue:appDelegate.password forKey:@"password"];
  7266. [params setValue:order_code forKey:@"orderCode"];
  7267. [params setObject:ScreenCodeCart forKey:kScreenName];
  7268. if(notes.length==0)
  7269. notes=@"";
  7270. [params setValue:notes forKey:@"comments"];
  7271. if(appDelegate.offline_mode)
  7272. {
  7273. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7274. NSData* json = [[OLDataProvider offline_updategnotes:params] mutableCopy];
  7275. dispatch_async(dispatch_get_main_queue(), ^{
  7276. result([[RAConvertor data2dict:json] mutableCopy]);
  7277. });
  7278. });
  7279. return;
  7280. }
  7281. [self request_interface:URL_CART_GENERAL_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7282. //
  7283. // NSData* json=nil;
  7284. // if(appDelegate.offline_mode)
  7285. // {
  7286. // json= [OLDataProvider offline_updategnotes:params];
  7287. // }
  7288. // else
  7289. // {
  7290. // if(![self IsNetworkAvailable])
  7291. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7292. //
  7293. // json=[self get_json:URL_CART_GENERAL_NOTES parameters:params];
  7294. // }
  7295. // if(json==nil)
  7296. // return nil;
  7297. // NSError *error=nil;
  7298. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7299. // return jsobj;
  7300. #endif
  7301. }
  7302. +(void) request_update_cartitemnote:(NSString*) cart_id notes:(NSString*) notes completionHandler:(resultHandler)result
  7303. {
  7304. AppDelegate *appDelegate = nil;
  7305. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7306. #ifdef SCANNER_ORDER
  7307. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  7308. {
  7309. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  7310. //
  7311. //
  7312. // [appDelegate update_count_mark];
  7313. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  7314. int count = [section[@"count"] intValue];
  7315. for(int i=0;i<count;i++)
  7316. {
  7317. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  7318. if([item[@"cart_item_id"] isEqualToString:cart_id])
  7319. {
  7320. item[@"note"] =notes;
  7321. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  7322. break;
  7323. }
  7324. }
  7325. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  7326. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  7327. result(RASingleton.sharedInstance.scan_cart);
  7328. return;
  7329. }
  7330. #else
  7331. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7332. if(appDelegate.user!=nil)
  7333. [params setValue:appDelegate.user forKey:@"user"];
  7334. if(appDelegate.contact_id!=nil)
  7335. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7336. if(appDelegate.password!=nil)
  7337. [params setValue:appDelegate.password forKey:@"password"];
  7338. [params setValue:cart_id forKey:@"cartitem_id"];
  7339. [params setObject:ScreenCodeCart forKey:kScreenName];
  7340. if(notes.length==0)
  7341. notes=@"";
  7342. [params setValue:notes forKey:@"notes"];
  7343. if(appDelegate.offline_mode)
  7344. {
  7345. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7346. NSData* json = [[OLDataProvider offline_cartsetlnotes:params] mutableCopy];
  7347. dispatch_async(dispatch_get_main_queue(), ^{
  7348. result([[RAConvertor data2dict:json] mutableCopy]);
  7349. });
  7350. });
  7351. return;
  7352. }
  7353. [self request_interface:URL_CART_ITEM_NOTES parameters:params err_record_url:nil completionHandler:result retry:0];
  7354. //
  7355. // NSData* json=nil;
  7356. // if(appDelegate.offline_mode)
  7357. // {
  7358. // json= [OLDataProvider offline_cartsetlnotes:params];
  7359. // }
  7360. // else
  7361. // {
  7362. // if(![self IsNetworkAvailable])
  7363. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7364. //
  7365. // json=[self get_json:URL_CART_ITEM_NOTES parameters:params];
  7366. // }
  7367. // if(json==nil)
  7368. // return nil;
  7369. // NSError *error=nil;
  7370. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7371. // return jsobj;
  7372. #endif
  7373. }
  7374. + (void)request_update_npd_shop_price_type:(NSInteger)priceType completionHandler:(resultHandler)result
  7375. {
  7376. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7377. AppDelegate *appDelegate = nil;
  7378. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7379. if(appDelegate.user!=nil)
  7380. [dic setValue:appDelegate.user forKey:@"user"];
  7381. if(appDelegate.password!=nil)
  7382. [dic setValue:appDelegate.password forKey:@"password"];
  7383. [dic setValue:[NSString stringWithFormat:@"%ld",priceType] forKey:@"price_type"];
  7384. [dic setObject:ScreenCodePriceSetting forKey:kScreenName];
  7385. if(appDelegate.offline_mode)
  7386. {
  7387. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7388. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7389. dispatch_async(dispatch_get_main_queue(), ^{
  7390. result(json);
  7391. });
  7392. });
  7393. return;
  7394. }
  7395. [self request_interface:URL_SET_PRICE_TYPE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7396. //
  7397. // NSData* json=nil;
  7398. // if(appDelegate.offline_mode)
  7399. // {
  7400. // return [OLDataProvider offline_notimpl];
  7401. // }
  7402. // else
  7403. // {
  7404. // if(![self IsNetworkAvailable])
  7405. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7406. //
  7407. // json = [RANetwork get_json:URL_SET_PRICE_TYPE parameters:dic];
  7408. // }
  7409. // if(json!=nil)
  7410. // {
  7411. // NSError *error=nil;
  7412. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7413. //
  7414. //
  7415. // return jsobj;
  7416. // }
  7417. //
  7418. //
  7419. // return nil;
  7420. }
  7421. + (void)request_npd_shop_givenprice:(resultHandler)result
  7422. {
  7423. NSMutableDictionary* dic = [[NSMutableDictionary alloc] init];
  7424. AppDelegate *appDelegate = nil;
  7425. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7426. if(appDelegate.user!=nil)
  7427. [dic setValue:appDelegate.user forKey:@"user"];
  7428. if(appDelegate.password!=nil)
  7429. [dic setValue:appDelegate.password forKey:@"password"];
  7430. [dic setObject:ScreenCodeCategoryPrice forKey:kScreenName];
  7431. if(appDelegate.offline_mode)
  7432. {
  7433. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7434. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7435. dispatch_async(dispatch_get_main_queue(), ^{
  7436. result(json);
  7437. });
  7438. });
  7439. return;
  7440. }
  7441. [self request_interface:URL_GET_CIVEN_PRICE parameters:dic err_record_url:nil completionHandler:result retry:0];
  7442. //
  7443. // NSData* json=nil;
  7444. // if(appDelegate.offline_mode)
  7445. // {
  7446. // return [OLDataProvider offline_notimpl];
  7447. // }
  7448. // else
  7449. // {
  7450. // if(![self IsNetworkAvailable])
  7451. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7452. //
  7453. // json = [RANetwork get_json:URL_GET_CIVEN_PRICE parameters:dic];
  7454. // }
  7455. // if(json!=nil)
  7456. // {
  7457. // NSError *error=nil;
  7458. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7459. //
  7460. //
  7461. // return jsobj;
  7462. // }
  7463. //
  7464. //
  7465. // return nil;
  7466. }
  7467. + (void)request_update_npd_shop_givenprice:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  7468. {
  7469. AppDelegate *appDelegate = nil;
  7470. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7471. if(appDelegate.user!=nil)
  7472. [params setValue:appDelegate.user forKey:@"user"];
  7473. if(appDelegate.password!=nil)
  7474. [params setValue:appDelegate.password forKey:@"password"];
  7475. [params setObject:ScreenCodeSetCatetoryPrice forKey:kScreenName];
  7476. if(appDelegate.offline_mode)
  7477. {
  7478. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7479. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  7480. dispatch_async(dispatch_get_main_queue(), ^{
  7481. result(json);
  7482. });
  7483. });
  7484. return;
  7485. }
  7486. [self request_interface:URL_SET_GIVEN_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  7487. //
  7488. // NSData* json=nil;
  7489. // if(appDelegate.offline_mode)
  7490. // {
  7491. // return [OLDataProvider offline_notimpl];
  7492. // }
  7493. // else
  7494. // {
  7495. // if(![self IsNetworkAvailable])
  7496. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7497. //
  7498. // json = [RANetwork get_json:URL_SET_GIVEN_PRICE parameters:params];
  7499. // }
  7500. // if(json!=nil)
  7501. // {
  7502. // NSError *error=nil;
  7503. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7504. //
  7505. //
  7506. // return jsobj;
  7507. // }
  7508. //
  7509. //
  7510. // return nil;
  7511. }
  7512. +(void) request_create_portfolio:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7513. {
  7514. AppDelegate *appDelegate = nil;
  7515. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7516. if(appDelegate.offline_mode)
  7517. {
  7518. params[@"contact_id"]=params[@"contactId"];
  7519. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7520. NSData* json = [[OLDataProvider offline_direct_save_TearSheet:params] mutableCopy];
  7521. dispatch_async(dispatch_get_main_queue(), ^{
  7522. result([[RAConvertor data2dict:json] mutableCopy]);
  7523. });
  7524. });
  7525. return;
  7526. }
  7527. //
  7528. // if(appDelegate.offline_mode)
  7529. // {
  7530. //
  7531. //
  7532. // NSData*json = [OLDataProvider offline_direct_save_TearSheet:params];
  7533. // if(json==nil)
  7534. // return nil;
  7535. // NSError *error=nil;
  7536. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7537. //
  7538. // return jsobj[@"pdf_path"];
  7539. // }
  7540. // else
  7541. // {
  7542. // return nil;
  7543. // }
  7544. }
  7545. +(void)request_save_portfoliodirectly:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7546. {
  7547. NSMutableDictionary* off_params = [params mutableCopy];
  7548. AppDelegate *appDelegate = nil;
  7549. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7550. if(appDelegate.user!=nil)
  7551. [params setValue:appDelegate.user forKey:@"user"];
  7552. if(appDelegate.contact_id!=nil)
  7553. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7554. if(appDelegate.password!=nil)
  7555. params[@"off_params"]=[RAConvertor dict2string:off_params];
  7556. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  7557. [params setValue:appDelegate.password forKey:@"password"];
  7558. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7559. if(appDelegate.offline_mode)
  7560. {
  7561. params[@"contact_id"]=appDelegate.contact_id;
  7562. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7563. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_direct_save_TearSheet:params]] mutableCopy];
  7564. dispatch_async(dispatch_get_main_queue(), ^{
  7565. result(json);
  7566. });
  7567. });
  7568. return;
  7569. }
  7570. NSString * uuid= [[NSUUID UUID] UUIDString];
  7571. params[@"resultSerial"]=uuid;
  7572. __block bool bbreak = false;
  7573. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7574. for(int i=0;i<150;i++)
  7575. {
  7576. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7577. // result_params[@"resultSerial"]=uuid;
  7578. if(bbreak)
  7579. break;
  7580. dispatch_async(dispatch_get_main_queue(), ^{
  7581. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7582. if([resulti[@"result"] intValue]==2)
  7583. {
  7584. if(!bbreak)//此判断保证result只调用一次。
  7585. result(resulti);
  7586. bbreak=true;
  7587. }
  7588. } retry:3];
  7589. });
  7590. sleep(2);
  7591. }
  7592. });
  7593. //
  7594. //
  7595. // NSData* json= nil;
  7596. //
  7597. // if(appDelegate.offline_mode)
  7598. // {
  7599. // json = [OLDataProvider offline_direct_save_TearSheet:params];
  7600. // }
  7601. // else
  7602. // {
  7603. // if(![self IsNetworkAvailable])
  7604. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7605. //
  7606. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7607. //
  7608. // NSError *error=nil;
  7609. //
  7610. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7611. // params[@"resultSerial"]=uuid;
  7612. //
  7613. // for(int i=0;i<150;i++)
  7614. // {
  7615. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7616. // // result_params[@"resultSerial"]=uuid;
  7617. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7618. // if(json!=nil)
  7619. // {
  7620. //
  7621. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7622. // if([jsobj[@"result"] intValue]==2)
  7623. // {
  7624. // break;
  7625. // }
  7626. // }
  7627. // sleep(5);
  7628. // }
  7629. //
  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_save_portfolio:(NSMutableDictionary *)params completionHandler:(resultHandler)result
  7638. {
  7639. AppDelegate *appDelegate = nil;
  7640. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7641. if(appDelegate.user!=nil)
  7642. [params setValue:appDelegate.user forKey:@"user"];
  7643. if(appDelegate.contact_id!=nil)
  7644. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7645. NSMutableDictionary* off_params = [params mutableCopy];;
  7646. [off_params removeObjectForKey:@"password"]; // 确保离线参数不会写入创建用户的密码;
  7647. params[@"off_params"]=[RAConvertor dict2string:off_params];
  7648. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7649. if(appDelegate.password!=nil)
  7650. [params setValue:appDelegate.password forKey:@"password"];
  7651. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7652. if(appDelegate.offline_mode)
  7653. {
  7654. params[@"contact_id"]=appDelegate.contact_id;
  7655. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7656. NSData* json = [[OLDataProvider offline_save_TearSheet:params] mutableCopy];
  7657. dispatch_async(dispatch_get_main_queue(), ^{
  7658. result([[RAConvertor data2dict:json] mutableCopy]);
  7659. });
  7660. });
  7661. return;
  7662. }
  7663. [self request_interface:URL_SAVE_DM parameters:params err_record_url:nil completionHandler:result retry:0];
  7664. //
  7665. // NSData* json = nil;
  7666. // if(appDelegate.offline_mode)
  7667. // {
  7668. // json = [OLDataProvider offline_save_TearSheet:params];
  7669. // } else {
  7670. // if(![self IsNetworkAvailable])
  7671. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7672. //
  7673. // json=[self get_json:URL_SAVE_DM parameters:params];
  7674. // }
  7675. // if(json==nil)
  7676. // return nil;
  7677. // NSError *error=nil;
  7678. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7679. // return jsobj;
  7680. }
  7681. +(void)request_portfoliopreview:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7682. {
  7683. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7684. AppDelegate *appDelegate = nil;
  7685. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7686. if(appDelegate.user!=nil)
  7687. [params setValue:appDelegate.user forKey:@"user"];
  7688. if(appDelegate.contact_id!=nil)
  7689. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7690. if(appDelegate.password!=nil)
  7691. [params setValue:appDelegate.password forKey:@"password"];
  7692. [params setObject:ScreenCodeCreatePortfolio forKey:kScreenName];
  7693. // [params setValue:request_url forKey:@"pdfUrl"];
  7694. if(appDelegate.offline_mode)
  7695. {
  7696. params[@"contact_id"]=params[@"contactId"];
  7697. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7698. NSData* json = [[OLDataProvider offline_request_tearsheet:params] mutableCopy];
  7699. dispatch_async(dispatch_get_main_queue(), ^{
  7700. result([[RAConvertor data2dict:json] mutableCopy]);
  7701. });
  7702. });
  7703. return;
  7704. }
  7705. NSString * uuid= [[NSUUID UUID] UUIDString];
  7706. params[@"resultSerial"]=uuid;
  7707. __block bool bbreak = false;
  7708. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7709. for(int i=0;i<150;i++)
  7710. {
  7711. // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7712. // result_params[@"resultSerial"]=uuid;
  7713. if(bbreak)
  7714. break;
  7715. dispatch_async(dispatch_get_main_queue(), ^{
  7716. [self request_interface:URL_REQUEST_DM parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  7717. if([resulti[@"result"] intValue]==2)
  7718. {
  7719. if(!bbreak)//此判断保证result只调用一次。
  7720. result(resulti);
  7721. bbreak=true;
  7722. }
  7723. } retry:3];
  7724. });
  7725. sleep(5);
  7726. }
  7727. });
  7728. //
  7729. // NSData* json= nil;
  7730. // if(appDelegate.offline_mode)
  7731. // {
  7732. // json= [OLDataProvider offline_request_tearsheet:params];
  7733. // }
  7734. // else
  7735. // {
  7736. // if(![self IsNetworkAvailable])
  7737. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7738. //
  7739. // NSError *error=nil;
  7740. //
  7741. // NSString * uuid= [[NSUUID UUID] UUIDString];
  7742. // params[@"resultSerial"]=uuid;
  7743. //
  7744. // for(int i=0;i<150;i++)
  7745. // {
  7746. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  7747. // // result_params[@"resultSerial"]=uuid;
  7748. // json=[self get_json:URL_REQUEST_DM parameters:params];
  7749. // if(json!=nil)
  7750. // {
  7751. //
  7752. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7753. // if([jsobj[@"result"] intValue]==2)
  7754. // {
  7755. // break;
  7756. // }
  7757. // }
  7758. // sleep(5);
  7759. // }
  7760. // }
  7761. // if(json==nil)
  7762. // return nil;
  7763. // NSError *error=nil;
  7764. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7765. // return jsobj;
  7766. }
  7767. +(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
  7768. {
  7769. // for debug
  7770. // return [RAUtils error_json:RESULT_NET_ERROR err_msg:nil];
  7771. //return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7772. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7773. AppDelegate *appDelegate = nil;
  7774. //some UI methods ej
  7775. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7776. if(appDelegate.user!=nil)
  7777. [params setValue:appDelegate.user forKey:@"user"];
  7778. if(appDelegate.contact_id!=nil)
  7779. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7780. if(appDelegate.password!=nil)
  7781. [params setValue:appDelegate.password forKey:@"password"];
  7782. if(appDelegate.order_code!=nil)
  7783. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  7784. [params setObject:ScreenCodeParticularCategory forKey:kScreenName];
  7785. if (alert && qty && available && price && bestseller) {
  7786. [params setObject:@"Filter" forKey:kAction];
  7787. }
  7788. if ([RASingleton sharedInstance].homeItemClick) {
  7789. [params setObject:@"Brow A Particular Category On Home" forKey:kAction];
  7790. [RASingleton sharedInstance].homeItemClick = NO;
  7791. NSDictionary *extra = @{@"CoverName" : [RASingleton sharedInstance].homeClickedItemName};
  7792. [RASingleton sharedInstance].homeClickedItemName = nil;
  7793. [params setObject:extra forKey:kExtra];
  7794. }
  7795. // [params setValue:[NSString stringWithFormat:@"%d",price_template] forKey:@"price_template"];
  7796. // [params setValue:[NSString stringWithFormat:@"%d",customid] forKey:@"custom_id"];
  7797. // [params setValue:[NSString stringWithFormat:@"%@",category] forKey:@"category"];
  7798. // [params setValue:[NSString stringWithFormat:@"%d",sort_by] forKey:@"sort_by"];
  7799. // [params setValue:filter forKey:@"filter"];
  7800. [params setValue:covertype forKey:@"covertype"];
  7801. [params setValue:ctgid forKey:@"ctgId"];
  7802. [params setValue:modelname forKey:@"modelName"];
  7803. [params setValue:modeldescrip forKey:@"modelDescription"];
  7804. [params setValue:alert forKey:@"alert"];
  7805. [params setValue:qty forKey:@"sold_by_qty"];
  7806. [params setValue:available forKey:@"available"];
  7807. [params setValue:price forKey:@"price"];
  7808. [params setValue:bestseller forKey:@"bestseller"];
  7809. [params setValue:[NSString stringWithFormat:@"%ld",limit] forKey:@"limit"];
  7810. [params setValue:[NSString stringWithFormat:@"%ld",offset] forKey:@"offset"];
  7811. if(appDelegate.offline_mode)
  7812. {
  7813. // [OLDataProvider offline_itemsearch:params completionHandler:result];
  7814. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7815. NSMutableDictionary* json = [[OLDataProvider offline_itemsearch:params] mutableCopy];
  7816. dispatch_async(dispatch_get_main_queue(), ^{
  7817. result(json);
  7818. });
  7819. });
  7820. return;
  7821. }
  7822. [self request_interface:URL_ITEM_SEARCH parameters:params err_record_url:nil completionHandler:result retry:0];
  7823. // if(appDelegate.offline_mode)
  7824. // {
  7825. // return [OLDataProvider offline_itemsearch:params];
  7826. // }
  7827. // if(![self IsNetworkAvailable])
  7828. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7829. // NSData* json=[self get_json:URL_ITEM_SEARCH parameters:params];
  7830. // if(json==nil)
  7831. // return nil;
  7832. // NSError *error=nil;
  7833. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7834. // return jsobj;
  7835. }
  7836. +(void)request_modelqty: (NSString*) fashionId completionHandler:(resultHandler)result
  7837. {
  7838. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7839. AppDelegate *appDelegate = nil;
  7840. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7841. if(appDelegate.user!=nil)
  7842. [params setValue:appDelegate.user forKey:@"user"];
  7843. if(appDelegate.contact_id!=nil)
  7844. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7845. if(appDelegate.password!=nil)
  7846. [params setValue:appDelegate.password forKey:@"password"];
  7847. [params setValue:fashionId forKey:@"fashionId"];
  7848. [params setObject:ScreenCodeEditPortfolio forKey:kScreenName];
  7849. if(appDelegate.offline_mode)
  7850. {
  7851. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7852. NSData* json = [[OLDataProvider offline_model_qty:params] mutableCopy];
  7853. dispatch_async(dispatch_get_main_queue(), ^{
  7854. result([[RAConvertor data2dict:json] mutableCopy]);
  7855. });
  7856. });
  7857. return;
  7858. }
  7859. [self request_interface:URL_REQUEST_MODEL_QTY parameters:params err_record_url:nil completionHandler:result retry:0];
  7860. // NSData* json = nil;
  7861. // if(appDelegate.offline_mode)
  7862. // {
  7863. // json = [OLDataProvider offline_model_qty:params];
  7864. // } else {
  7865. // if(![self IsNetworkAvailable])
  7866. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7867. //
  7868. // json=[self get_json:URL_REQUEST_MODEL_QTY parameters:params];
  7869. // }
  7870. // if(json==nil)
  7871. // return nil;
  7872. // NSError *error=nil;
  7873. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7874. // return jsobj;
  7875. }
  7876. +(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
  7877. {
  7878. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7879. AppDelegate *appDelegate = nil;
  7880. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7881. if(appDelegate.user!=nil)
  7882. [params setValue:appDelegate.user forKey:@"user"];
  7883. if(appDelegate.contact_id!=nil)
  7884. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7885. if(appDelegate.password!=nil)
  7886. [params setValue:appDelegate.password forKey:@"password"];
  7887. [params setValue:watchlist_id forKey:@"item_id"];
  7888. // if(notes.length>0)
  7889. // [params setValue:notes forKey:@"notes"];
  7890. if(notes)
  7891. [params setValue:notes forKey:@"notes"];
  7892. if(price != -MAXFLOAT)
  7893. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  7894. if (discount != -MAXFLOAT)
  7895. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  7896. if(qty_p != -MAXFLOAT)
  7897. [params setValue:[NSString stringWithFormat:@"%f",qty_p] forKey:@"available_percent"];
  7898. if(qty != -INT32_MAX)
  7899. [params setValue:[NSString stringWithFormat:@"%d",qty] forKey:@"available_qty"];
  7900. [params setObject:ScreenCodePortfolio forKey:kScreenName];
  7901. // NSData* json = nil;
  7902. if(appDelegate.offline_mode)
  7903. {
  7904. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7905. NSData* json = [[OLDataProvider offline_editPortfolio:params] mutableCopy];
  7906. dispatch_async(dispatch_get_main_queue(), ^{
  7907. result([[RAConvertor data2dict:json] mutableCopy]);
  7908. });
  7909. });
  7910. return;
  7911. }
  7912. [self request_interface:URL_PORTFOLIO_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  7913. //
  7914. // if(appDelegate.offline_mode)
  7915. // {
  7916. // json = [OLDataProvider offline_editPortfolio:params];
  7917. // } else {
  7918. // if(![self IsNetworkAvailable])
  7919. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7920. //
  7921. // json = [self get_json:URL_PORTFOLIO_SET_PRICE parameters:params];
  7922. // }
  7923. // if(json==nil)
  7924. // return nil;
  7925. // NSError *error=nil;
  7926. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7927. // return jsobj;
  7928. }
  7929. +(void)request_add_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7930. {
  7931. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7932. AppDelegate *appDelegate = nil;
  7933. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7934. if(appDelegate.user!=nil)
  7935. [params setValue:appDelegate.user forKey:@"user"];
  7936. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  7937. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7938. // else
  7939. if(appDelegate.contact_id!=nil)
  7940. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7941. if(appDelegate.password!=nil)
  7942. [params setValue:appDelegate.password forKey:@"password"];
  7943. // NSDictionary* customerinfo=nil;
  7944. // if(![[appDelegate.customerInfo valueForKey:@"customer_cid" ] isEqualToString: [appDelegate.customerInfo valueForKey:@"customer_cid" ]]&& appDelegate.order_customer_id!=nil)
  7945. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  7946. // else
  7947. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  7948. //
  7949. // appDelegate.customerInfo;
  7950. // NSArray* keys=[customerinfo allKeys];
  7951. // for(int i=0;i<keys.count;i++)
  7952. // {
  7953. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  7954. // }
  7955. // [params setValue:sourceid forKey:@"sourceid"];
  7956. // [params setValue:editor forKey:@"editor"];
  7957. [params setObject:ScreenCodeNewCustomer forKey:kScreenName];
  7958. if(appDelegate.offline_mode)
  7959. {
  7960. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  7961. NSData* json = [[OLDataProvider offline_saveNewContact:params] mutableCopy];
  7962. dispatch_async(dispatch_get_main_queue(), ^{
  7963. result([[RAConvertor data2dict:json] mutableCopy]);
  7964. });
  7965. });
  7966. return;
  7967. }
  7968. [self request_interface:URL_CUSTOMER_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  7969. //
  7970. // NSData* json=nil;
  7971. // if(appDelegate.offline_mode)
  7972. // {
  7973. // json= [OLDataProvider offline_saveNewContact:params];
  7974. // }
  7975. // else
  7976. // {
  7977. // if(![self IsNetworkAvailable])
  7978. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  7979. //
  7980. // json=[self get_json:URL_CUSTOMER_SAVE parameters:params];
  7981. // }
  7982. //
  7983. // if(json!=nil)
  7984. // {
  7985. // NSError *error=nil;
  7986. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  7987. // return jsobj;
  7988. // }
  7989. // else
  7990. // return nil;
  7991. }
  7992. +(void)request_update_customer:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  7993. {
  7994. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  7995. AppDelegate *appDelegate = nil;
  7996. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  7997. if(appDelegate.user!=nil)
  7998. [params setValue:appDelegate.user forKey:@"user"];
  7999. // if(![appDelegate.order_customer_id isEqualToString: appDelegate.contact_id]&& appDelegate.order_customer_id!=nil)
  8000. // [params setValue:appDelegate.order_customer_id forKey:@"contactId"];
  8001. // else
  8002. if(appDelegate.contact_id!=nil)
  8003. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8004. if(appDelegate.password!=nil)
  8005. [params setValue:appDelegate.password forKey:@"password"];
  8006. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8007. if(appDelegate.offline_mode)
  8008. {
  8009. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8010. NSData* json = [[OLDataProvider offline_saveContact:params] mutableCopy];
  8011. dispatch_async(dispatch_get_main_queue(), ^{
  8012. result([[RAConvertor data2dict:json] mutableCopy]);
  8013. });
  8014. });
  8015. return;
  8016. }
  8017. [self request_interface:URL_CUSTOMER_UPDATE parameters:params err_record_url:nil completionHandler:result retry:0];
  8018. //
  8019. // NSData* json=nil;
  8020. // if(appDelegate.offline_mode)
  8021. // {
  8022. // json= [OLDataProvider offline_saveContact:params];
  8023. // }
  8024. // else
  8025. // {
  8026. // if(![self IsNetworkAvailable])
  8027. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8028. //
  8029. // json=[self get_json:URL_CUSTOMER_UPDATE parameters:params];
  8030. // }
  8031. //
  8032. // if(json!=nil)
  8033. // {
  8034. // NSError *error=nil;
  8035. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8036. // return jsobj;
  8037. // }
  8038. // else
  8039. // return nil;
  8040. }
  8041. +(void)request_delete_order:(NSString*) order_id completionHandler:(resultHandler)result
  8042. {
  8043. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8044. AppDelegate *appDelegate = nil;
  8045. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8046. if(appDelegate.user!=nil)
  8047. [params setValue:appDelegate.user forKey:@"user"];
  8048. // if(appDelegate.contact_id!=nil)
  8049. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8050. if(appDelegate.password!=nil)
  8051. [params setValue:appDelegate.password forKey:@"password"];
  8052. [params setValue:order_id forKey:@"orderId"];
  8053. // [params setValue:sourceid forKey:@"sourceid"];
  8054. // [params setValue:editor forKey:@"editor"];
  8055. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8056. if(appDelegate.offline_mode)
  8057. {
  8058. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8059. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8060. dispatch_async(dispatch_get_main_queue(), ^{
  8061. result(json);
  8062. });
  8063. });
  8064. return;
  8065. }
  8066. [self request_interface:URL_DELETE_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8067. //
  8068. // if(appDelegate.offline_mode)
  8069. // {
  8070. // return [OLDataProvider offline_notimpl];
  8071. // }
  8072. // if(![self IsNetworkAvailable])
  8073. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8074. //
  8075. // NSData* json=[self get_json:URL_DELETE_ORDER parameters:params];
  8076. // if(json!=nil)
  8077. // {
  8078. // NSError *error=nil;
  8079. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8080. //
  8081. //
  8082. // return jsobj;
  8083. // }
  8084. // else
  8085. // return nil;
  8086. }
  8087. +(void)request_cancel_order:(NSString*) order_id order_code:(NSString*) order_code completionHandler:(resultHandler)result
  8088. {
  8089. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8090. AppDelegate *appDelegate = nil;
  8091. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8092. if(appDelegate.user!=nil)
  8093. [params setValue:appDelegate.user forKey:@"user"];
  8094. // if(appDelegate.contact_id!=nil)
  8095. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8096. if(appDelegate.password!=nil)
  8097. [params setValue:appDelegate.password forKey:@"password"];
  8098. [params setValue:order_id forKey:@"orderId"];
  8099. [params setValue:order_code forKey:@"orderCode"];
  8100. // [params setValue:sourceid forKey:@"sourceid"];
  8101. // [params setValue:editor forKey:@"editor"];
  8102. [params setValue:ScreenCodeOrderList forKey:kScreenName];
  8103. if(appDelegate.offline_mode)
  8104. {
  8105. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8106. NSData* json = [[OLDataProvider offline_cancelorder:params] mutableCopy];
  8107. dispatch_async(dispatch_get_main_queue(), ^{
  8108. result([[RAConvertor data2dict:json] mutableCopy]);
  8109. });
  8110. });
  8111. return;
  8112. }
  8113. [self request_interface:URL_CANCEL_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8114. //
  8115. // NSData* json=nil;
  8116. // if(appDelegate.offline_mode)
  8117. // {
  8118. // json=[OLDataProvider offline_cancelorder:params];
  8119. // }
  8120. // else
  8121. // {
  8122. // if(![self IsNetworkAvailable])
  8123. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8124. // json=[self get_json:URL_CANCEL_ORDER parameters:params];
  8125. // }
  8126. // if(json!=nil)
  8127. // {
  8128. // NSError *error=nil;
  8129. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8130. //
  8131. //
  8132. // return jsobj;
  8133. // }
  8134. // else
  8135. // return nil;
  8136. }
  8137. +(void)request_release_order:(NSString*) order_code withScreen:(NSString *)screenName completionHandler:(resultHandler)result
  8138. {
  8139. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8140. AppDelegate *appDelegate = nil;
  8141. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8142. if(appDelegate.user!=nil)
  8143. [params setValue:appDelegate.user forKey:@"user"];
  8144. // if(appDelegate.contact_id!=nil)
  8145. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8146. if(appDelegate.password!=nil)
  8147. [params setValue:appDelegate.password forKey:@"password"];
  8148. [params setValue:order_code forKey:@"orderCode"];
  8149. // [params setValue:sourceid forKey:@"sourceid"];
  8150. // [params setValue:editor forKey:@"editor"];
  8151. if (screenName) {
  8152. [params setValue:screenName forKey:kScreenName];
  8153. }
  8154. if(appDelegate.offline_mode)
  8155. {
  8156. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8157. NSMutableDictionary* resulti = [[RAConvertor data2dict:[OLDataProvider offline_resetorder:params]] mutableCopy];
  8158. dispatch_async(dispatch_get_main_queue(), ^{
  8159. if([[resulti valueForKey:@"result"]intValue]==2)
  8160. { [appDelegate SetSo:nil];
  8161. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8162. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8163. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8164. [appDelegate update_count_mark];
  8165. dispatch_async(dispatch_get_main_queue(), ^{
  8166. result(resulti);
  8167. });
  8168. }
  8169. });
  8170. });
  8171. return;
  8172. }
  8173. [self request_interface:URL_RELEASE_ORDER parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8174. if([[resulti valueForKey:@"result"]intValue]==2)
  8175. { [appDelegate SetSo:nil];
  8176. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8177. //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8178. // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8179. [appDelegate update_count_mark];
  8180. dispatch_async(dispatch_get_main_queue(), ^{
  8181. result(resulti);
  8182. });
  8183. }
  8184. } retry:0];
  8185. //
  8186. // NSData* json=nil;
  8187. // if(appDelegate.offline_mode)
  8188. // {
  8189. // json= [OLDataProvider offline_resetorder:params];
  8190. // }
  8191. // else
  8192. // {
  8193. // if(![self IsNetworkAvailable])
  8194. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8195. //
  8196. // json=[self get_json:URL_RELEASE_ORDER parameters:params];
  8197. // }
  8198. // if(json!=nil)
  8199. // {
  8200. // NSError *error=nil;
  8201. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8202. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8203. // { [appDelegate SetSo:nil];
  8204. //
  8205. //
  8206. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8207. // //appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8208. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8209. //
  8210. // [appDelegate update_count_mark];
  8211. // }
  8212. // return jsobj;
  8213. // }
  8214. // else
  8215. // return nil;
  8216. }
  8217. +(void)request_update_order_signature:(NSString*) order_code path:(NSString*)path completionHandler:(resultHandler)result
  8218. {
  8219. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8220. AppDelegate *appDelegate = nil;
  8221. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8222. if(appDelegate.user!=nil)
  8223. [params setValue:appDelegate.user forKey:@"user"];
  8224. if(appDelegate.contact_id!=nil)
  8225. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8226. if(appDelegate.password!=nil)
  8227. [params setValue:appDelegate.password forKey:@"password"];
  8228. // NSString* ssaved = @"false";
  8229. // if(saved)
  8230. // ssaved=@"true";
  8231. // [params setValue:@"true" forKey:@"saved"];
  8232. [params setValue:order_code forKey:@"orderCode"];
  8233. [params setValue:path forKey:@"picpath"];
  8234. // [params setValue:sourceid forKey:@"sourceid"];
  8235. // [params setValue:editor forKey:@"editor"];
  8236. [params setValue:ScreenCodeUserSign forKey:kScreenName];
  8237. if(appDelegate.offline_mode)
  8238. {
  8239. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8240. NSData* json = [[OLDataProvider offline_signorder:params] mutableCopy];
  8241. dispatch_async(dispatch_get_main_queue(), ^{
  8242. result([[RAConvertor data2dict:json] mutableCopy]);
  8243. });
  8244. });
  8245. return;
  8246. }
  8247. [self request_interface:URL_SIGN_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8248. //
  8249. // NSData* json=nil;
  8250. // if(appDelegate.offline_mode)
  8251. // {
  8252. // json= [OLDataProvider offline_signorder:params];
  8253. // }
  8254. // else
  8255. // {
  8256. // if(![self IsNetworkAvailable])
  8257. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8258. //
  8259. // json=[self get_json:URL_SIGN_ORDER parameters:params];
  8260. // }
  8261. // if(json!=nil)
  8262. // {
  8263. // NSError *error=nil;
  8264. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8265. // return jsobj;
  8266. // }
  8267. // else
  8268. // return nil;
  8269. }
  8270. #ifdef SCANNER_ORDER
  8271. +(void) request_scan_bulkdiscount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8272. {
  8273. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  8274. //
  8275. //
  8276. // [appDelegate update_count_mark];
  8277. if(RASingleton.sharedInstance.price_type==0)
  8278. {
  8279. result(RASingleton.sharedInstance.scan_cart);
  8280. return;
  8281. }
  8282. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  8283. int count = [section[@"count"] intValue];
  8284. for(int i=0;i<count;i++)
  8285. {
  8286. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  8287. if ([item[@"special_price"] boolValue]||[item[@"net_price"] boolValue])
  8288. continue;
  8289. int item_count = [item[@"count"] intValue];
  8290. float price=[item[@"unit_price"] floatValue] ;
  8291. item[@"discount"] =@(discount);
  8292. // item[@"subtotal_price"] =@(price*item_count);
  8293. item[@"subtotal_price"]= [NSString stringWithFormat:@"%f",price*item_count*(1-discount/100.0)];
  8294. if(discount>0)
  8295. item[@"note"] =[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  8296. else
  8297. item[@"note"] =@"";
  8298. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  8299. }
  8300. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  8301. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  8302. result(RASingleton.sharedInstance.scan_cart);
  8303. AppDelegate *appDelegate = nil;
  8304. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8305. [OLDataProvider updateScanOrder:appDelegate.order_code];
  8306. return;
  8307. }
  8308. #endif
  8309. +(void) request_update_cart_modelprice:(NSString*) cart_id price:(float) price discount:(float) discount notes:(NSString*) notes completionHandler:(resultHandler)result
  8310. {
  8311. AppDelegate *appDelegate = nil;
  8312. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8313. #ifdef SCANNER_ORDER
  8314. // return;
  8315. // if(RASingleton.sharedInstance.enable_OfflineOrder)
  8316. {
  8317. // appDelegate.cart_count = [[RASingleton.sharedInstance.scan_cart valueForKey:@"cart_count"] intValue];
  8318. //
  8319. //
  8320. // [appDelegate update_count_mark];
  8321. NSMutableDictionary* section = [RASingleton.sharedInstance.scan_cart[@"section_0"] mutableCopy];
  8322. int count = [section[@"count"] intValue];
  8323. for(int i=0;i<count;i++)
  8324. {
  8325. NSMutableDictionary* item = [section[[NSString stringWithFormat:@"item_%d",i]] mutableCopy];
  8326. if([item[@"cart_item_id"] isEqualToString:cart_id])
  8327. {
  8328. int item_count = [item[@"count"] intValue];
  8329. item[@"unit_price"] =@(price);
  8330. item[@"discount"] =@(discount);
  8331. // item[@"subtotal_price"] =@(price*item_count);
  8332. item[@"subtotal_price"]= [NSString stringWithFormat:@"%f",price*item_count*(1-discount/100.0)];
  8333. if(discount>0)
  8334. item[@"note"] =[NSString stringWithFormat:@"Note: discount %d%% off.",(int)discount];
  8335. else
  8336. item[@"note"] =@"";
  8337. section[[NSString stringWithFormat:@"item_%d",i]] = item;
  8338. break;
  8339. }
  8340. }
  8341. RASingleton.sharedInstance.scan_cart[@"section_0"] = section;
  8342. [OLDataProvider saveScanCart:RASingleton.sharedInstance.scan_cart];
  8343. result(RASingleton.sharedInstance.scan_cart);
  8344. [OLDataProvider updateScanOrder:appDelegate.order_code];
  8345. return;
  8346. }
  8347. #else
  8348. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8349. if(appDelegate.user!=nil)
  8350. [params setValue:appDelegate.user forKey:@"user"];
  8351. if(appDelegate.contact_id!=nil)
  8352. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8353. if(appDelegate.password!=nil)
  8354. [params setValue:appDelegate.password forKey:@"password"];
  8355. [params setValue:cart_id forKey:@"cartitem_id"];
  8356. [params setValue:notes forKey:@"item_note"];
  8357. [params setValue:[NSString stringWithFormat:@"%f",price] forKey:@"price"];
  8358. [params setValue:[NSString stringWithFormat:@"%f",discount] forKey:@"discount"];
  8359. [params setObject:ScreenCodeCart forKey:kScreenName];
  8360. if(appDelegate.offline_mode)
  8361. {
  8362. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8363. NSData* json = [[OLDataProvider offline_cartsetprice:params] mutableCopy];
  8364. dispatch_async(dispatch_get_main_queue(), ^{
  8365. result([[RAConvertor data2dict:json] mutableCopy]);
  8366. });
  8367. });
  8368. return;
  8369. }
  8370. [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8371. //
  8372. // NSData* json= nil;
  8373. // if(appDelegate.offline_mode)
  8374. // {
  8375. // json=[OLDataProvider offline_cartsetprice:params];
  8376. // }
  8377. // else
  8378. // {
  8379. // if(![self IsNetworkAvailable])
  8380. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8381. //
  8382. // json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8383. // }
  8384. // if(json==nil)
  8385. // return nil;
  8386. // NSError *error=nil;
  8387. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8388. // return jsobj;
  8389. #endif
  8390. }
  8391. +(void) request_addto_cart:(NSString* ) item_id count:(int) count name:(NSString *)name completionHandler:(resultHandler)result
  8392. {
  8393. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8394. AppDelegate *appDelegate = nil;
  8395. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8396. if(appDelegate.user!=nil)
  8397. [params setValue:appDelegate.user forKey:@"user"];
  8398. if(appDelegate.contact_id!=nil)
  8399. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8400. if(appDelegate.password!=nil)
  8401. [params setValue:appDelegate.password forKey:@"password"];
  8402. if(appDelegate.order_code!=nil)
  8403. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8404. [params setValue:item_id forKey:@"product_id"];
  8405. [params setValue:[NSString stringWithFormat:@"%d",count] forKey:@"count"];
  8406. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  8407. [params setObject:@"Add To Cart" forKey:kAction];
  8408. if (name) {
  8409. NSDictionary *extra = @{@"ModelName" : name,@"Count" : @(count)};
  8410. [params setObject:extra forKey:kExtra];
  8411. }
  8412. NSDictionary* customerinfo= appDelegate.customerInfo;
  8413. NSArray* keys=[customerinfo allKeys];
  8414. for(int i=0;i<keys.count;i++)
  8415. {
  8416. [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8417. }
  8418. if(appDelegate.offline_mode)
  8419. {
  8420. // [OLDataProvider offline_add2cart:params completionHandler:^(NSMutableDictionary *resulti) {
  8421. // NSMutableDictionary* json = resulti;
  8422. // if ([json[@"result"] intValue]==2)
  8423. // {
  8424. // appDelegate.port_count =[[json valueForKey:@"count"] intValue];
  8425. //
  8426. // [appDelegate update_count_mark];
  8427. // }
  8428. // result(json);
  8429. // }];
  8430. params[@"can_create_backorder"]= @(appDelegate.can_create_backorder);
  8431. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8432. NSMutableDictionary* json = [[RAConvertor data2dict:[OLDataProvider offline_add2cart:params]] mutableCopy];
  8433. dispatch_async(dispatch_get_main_queue(), ^{
  8434. if ([json[@"result"] intValue]==2)
  8435. {
  8436. appDelegate.cart_count = [[json valueForKey:@"cart_count"] intValue];
  8437. [appDelegate update_count_mark];
  8438. }
  8439. result(json);
  8440. });
  8441. });
  8442. return;
  8443. }
  8444. [self request_interface:URL_ADD_TO_CART parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8445. if ([resulti[@"result"] intValue]==2)
  8446. {
  8447. appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8448. [appDelegate update_count_mark];
  8449. }
  8450. result(resulti);
  8451. } retry:0];
  8452. //
  8453. // NSData* json=nil;
  8454. // if(appDelegate.offline_mode)
  8455. // {
  8456. // json=[OLDataProvider offline_add2cart:params];
  8457. // }
  8458. // else
  8459. // {
  8460. // if(![self IsNetworkAvailable])
  8461. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8462. //
  8463. // json=[self get_json:URL_ADD_TO_CART parameters:params];
  8464. // }
  8465. // if(json==nil)
  8466. // return nil;
  8467. // NSError *error=nil;
  8468. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8469. //
  8470. //
  8471. //
  8472. // int result = [[jsobj valueForKey:@"result"] intValue];
  8473. //
  8474. // if (result==2)
  8475. // {
  8476. //
  8477. // appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8478. // // appDelegate.wish_count =[[jsobj valueForKey:@"wish_count"] intValue];
  8479. // // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8480. //
  8481. // [appDelegate update_count_mark];
  8482. // }
  8483. //
  8484. // return jsobj;
  8485. }
  8486. //+(void) request_update_cart_modelfree:(NSString*) cart_id isfree:(bool) isfree completionHandler:(resultHandler)result
  8487. //{
  8488. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8489. // AppDelegate *appDelegate = nil;
  8490. //
  8491. //
  8492. //
  8493. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8494. //
  8495. // if(appDelegate.user!=nil)
  8496. // [params setValue:appDelegate.user forKey:@"user"];
  8497. // if(appDelegate.contact_id!=nil)
  8498. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8499. // if(appDelegate.password!=nil)
  8500. // [params setValue:appDelegate.password forKey:@"password"];
  8501. //
  8502. // [params setValue:cart_id forKey:@"cartitem_id"];
  8503. //
  8504. // [params setObject:ScreenCodeCart forKey:kScreenName];
  8505. //
  8506. // NSString* free=nil;
  8507. //
  8508. // if(isfree)
  8509. // free=@"true";
  8510. // else
  8511. // free=@"false";
  8512. //
  8513. // [params setValue:free forKey:@"free_giveaway"];
  8514. //
  8515. //
  8516. // if(appDelegate.offline_mode)
  8517. // {
  8518. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8519. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8520. // dispatch_async(dispatch_get_main_queue(), ^{
  8521. // result(json);
  8522. // });
  8523. // });
  8524. //
  8525. // return;
  8526. //
  8527. // }
  8528. // [self request_interface:URL_CART_SET_PRICE parameters:params err_record_url:nil completionHandler:result retry:0];
  8529. //
  8530. ////
  8531. ////
  8532. //// if(appDelegate.offline_mode)
  8533. //// {
  8534. //// return [OLDataProvider offline_notimpl];
  8535. //// }
  8536. //// if(![self IsNetworkAvailable])
  8537. //// return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8538. ////
  8539. //// NSData* json=[self get_json:URL_CART_SET_PRICE parameters:params];
  8540. //// if(json==nil)
  8541. //// return nil;
  8542. //// NSError *error=nil;
  8543. //// NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8544. //// return jsobj;
  8545. //}
  8546. +(void)request_retrieve_password: (NSString*) user email:(NSString*) email completionHandler:(resultHandler)result
  8547. {
  8548. AppDelegate *appDelegate = nil;
  8549. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8550. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8551. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8552. // if(appDelegate.user!=nil)
  8553. // [params setValue:appDelegate.user forKey:@"user"];
  8554. // if(appDelegate.contact_id!=nil)
  8555. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8556. // if(appDelegate.password!=nil)
  8557. // [params setValue:appDelegate.password forKey:@"password"];
  8558. [params setValue:user forKey:@"username"];
  8559. [params setValue:email forKey:@"email"];
  8560. [params setObject:ScreenCodeLoginView forKey:kScreenName];
  8561. if(appDelegate.offline_mode)
  8562. {
  8563. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8564. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8565. dispatch_async(dispatch_get_main_queue(), ^{
  8566. result(json);
  8567. });
  8568. });
  8569. return;
  8570. }
  8571. #ifdef SCANNER_ORDER
  8572. params[@"site_name"]=[RADataProvider getSiteName];
  8573. params[@"_method"]=@"forgotPasswordOfflineOrderUser";
  8574. params[@"user"]=user;
  8575. NSString* url = [appDelegate.address stringByAppendingPathComponent:URL_RETRIEVE_PASS];
  8576. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  8577. #else
  8578. [self request_interface:URL_RETRIEVE_PASS parameters:params err_record_url:nil completionHandler:result retry:0];
  8579. #endif
  8580. //
  8581. //
  8582. // if(![self IsNetworkAvailable])
  8583. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8584. //
  8585. // NSData* json=[self get_json:URL_RETRIEVE_PASS parameters:params];
  8586. // if(json==nil)
  8587. // return nil;
  8588. // NSError *error=nil;
  8589. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8590. // return jsobj;
  8591. }
  8592. +(void)request_update_ordercustomer:(NSString*) order_code customerinfo:(NSMutableDictionary*)info completionHandler:(resultHandler)result
  8593. {
  8594. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8595. AppDelegate *appDelegate = nil;
  8596. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8597. if(appDelegate.user!=nil)
  8598. [info setValue:appDelegate.user forKey:@"user"];
  8599. // if(appDelegate.contact_id!=nil)
  8600. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8601. if(appDelegate.password!=nil)
  8602. [info setValue:appDelegate.password forKey:@"password"];
  8603. [info setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8604. [info setValue:order_code forKey:@"orderCode"];
  8605. // [params setValue:sourceid forKey:@"sourceid"];
  8606. // [params setValue:editor forKey:@"editor"];
  8607. if(appDelegate.offline_mode)
  8608. {
  8609. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8610. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8611. dispatch_async(dispatch_get_main_queue(), ^{
  8612. result(json);
  8613. });
  8614. });
  8615. return;
  8616. }
  8617. [self request_interface:URL_UPDATE_ORDERCUSTOMER parameters:info err_record_url:nil completionHandler:result retry:0];
  8618. // if(appDelegate.offline_mode)
  8619. // {
  8620. // return [OLDataProvider offline_notimpl];
  8621. // }
  8622. // if(![self IsNetworkAvailable])
  8623. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8624. //
  8625. // NSData* json=[self get_json:URL_UPDATE_ORDERCUSTOMER parameters:info];
  8626. // if(json!=nil)
  8627. // {
  8628. // NSError *error=nil;
  8629. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8630. // return jsobj;
  8631. // }
  8632. // else
  8633. // return nil;
  8634. }
  8635. +(void)request_update_customer_img: (NSString*) contactid img_url:(NSString*) url completionHandler:(resultHandler)result
  8636. {
  8637. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8638. AppDelegate *appDelegate = nil;
  8639. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8640. if(appDelegate.user!=nil)
  8641. [params setValue:appDelegate.user forKey:@"user"];
  8642. // if(appDelegate.contact_id!=nil)
  8643. if(appDelegate.password!=nil)
  8644. [params setValue:appDelegate.password forKey:@"password"];
  8645. [params setValue:contactid forKey:@"contactId"];
  8646. [params setValue:url forKey:@"business_card"];
  8647. // [params setValue:[NSNumber numberWithInt:index ] forKey:@"index"];
  8648. [params setObject:ScreenCodeEditCustomer forKey:kScreenName];
  8649. if(appDelegate.offline_mode)
  8650. {
  8651. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8652. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8653. dispatch_async(dispatch_get_main_queue(), ^{
  8654. result(json);
  8655. });
  8656. });
  8657. return;
  8658. }
  8659. [self request_interface:URL_UPDATE_CUSTOMER_BCARD parameters:params err_record_url:nil completionHandler:result retry:0];
  8660. // if(appDelegate.offline_mode)
  8661. // {
  8662. // return [OLDataProvider offline_notimpl];
  8663. // }
  8664. // if(![self IsNetworkAvailable])
  8665. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8666. //
  8667. // NSData* json=[self get_json:URL_UPDATE_CUSTOMER_BCARD parameters:params];
  8668. // if(json==nil)
  8669. // return nil;
  8670. // NSError *error=nil;
  8671. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8672. // return jsobj;
  8673. }
  8674. +(void)request_commoneditor_partialrefresh: (NSMutableDictionary*)params url:(NSString*)url completionHandler:(resultHandler)result
  8675. {
  8676. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8677. AppDelegate *appDelegate = nil;
  8678. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8679. if(appDelegate.user!=nil)
  8680. [params setValue:appDelegate.user forKey:@"user"];
  8681. if(appDelegate.contact_id!=nil)
  8682. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8683. if(appDelegate.password!=nil)
  8684. [params setValue:appDelegate.password forKey:@"password"];
  8685. // if(appDelegate.order_code!=nil)
  8686. // [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8687. // NSDictionary* customerinfo= appDelegate.customerInfo;
  8688. //
  8689. // NSArray* keys=[customerinfo allKeys];
  8690. // for(int i=0;i<keys.count;i++)
  8691. // {
  8692. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8693. // }
  8694. //
  8695. // [params setValue:sourceid forKey:@"sourceid"];
  8696. // [params setValue:editor forKey:@"editor"];
  8697. [params setObject:ScreenCodeModelInfo forKey:kScreenName];
  8698. if(appDelegate.offline_mode)
  8699. {
  8700. params[@"offline_Command"]=url;
  8701. [OLDataProvider offline_commoneditor_partialrefresh:params completionHandler:result];
  8702. //
  8703. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8704. // NSMutableDictionary* json = [[OLDataProvider offline_commoneditor_partialrefresh:params] mutableCopy];
  8705. // dispatch_async(dispatch_get_main_queue(), ^{
  8706. // result(json);
  8707. // });
  8708. // });
  8709. return;
  8710. }
  8711. [self request_interface:url parameters:params err_record_url:nil completionHandler:result retry:0];
  8712. //
  8713. // if(appDelegate.offline_mode)
  8714. // {
  8715. // params[@"offline_Command"]=url;
  8716. // return [OLDataProvider offline_commoneditor_partialrefresh:params];
  8717. // }
  8718. //
  8719. // if(![self IsNetworkAvailable])
  8720. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8721. //
  8722. // NSData* json=[self get_json:url parameters:params];
  8723. // if(json!=nil)
  8724. // {
  8725. // NSError *error=nil;
  8726. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8727. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8728. // [appDelegate SetSo:nil];
  8729. //
  8730. //
  8731. // return jsobj;
  8732. // }
  8733. // else
  8734. // return nil;
  8735. }
  8736. +(void)request_add_address:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8737. {
  8738. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8739. AppDelegate *appDelegate = nil;
  8740. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8741. if(appDelegate.user!=nil)
  8742. [params setValue:appDelegate.user forKey:@"user"];
  8743. if(appDelegate.contact_id!=nil)
  8744. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8745. if(appDelegate.password!=nil)
  8746. [params setValue:appDelegate.password forKey:@"password"];
  8747. // [params setValue:sourceid forKey:@"sourceid"];
  8748. // [params setValue:editor forKey:@"editor"];
  8749. [params setValue:ScreenCodeNewAddress forKey:kScreenName];
  8750. if(appDelegate.offline_mode)
  8751. {
  8752. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8753. NSData* json = [[OLDataProvider offline_saveaddr:params] mutableCopy];
  8754. dispatch_async(dispatch_get_main_queue(), ^{
  8755. result([[RAConvertor data2dict:json] mutableCopy]);
  8756. });
  8757. });
  8758. return;
  8759. }
  8760. [self request_interface:URL_ADDRESS_SAVE parameters:params err_record_url:nil completionHandler:result retry:0];
  8761. //
  8762. // NSData* json=nil;
  8763. //
  8764. // if(appDelegate.offline_mode)
  8765. // {
  8766. // json= [OLDataProvider offline_saveaddr:params];
  8767. // }
  8768. // else
  8769. // {
  8770. // if(![self IsNetworkAvailable])
  8771. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8772. //
  8773. // json =[self get_json:URL_ADDRESS_SAVE parameters:params];
  8774. // }
  8775. // if(json!=nil)
  8776. // {
  8777. // NSError *error=nil;
  8778. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8779. // return jsobj;
  8780. // }
  8781. // else
  8782. // return nil;
  8783. }
  8784. +(void)request_commit_order:(NSMutableDictionary*)params completionHandler:(resultHandler)result
  8785. {
  8786. // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8787. AppDelegate *appDelegate = nil;
  8788. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8789. if(appDelegate.user!=nil)
  8790. [params setValue:appDelegate.user forKey:@"user"];
  8791. if(appDelegate.contact_id!=nil)
  8792. [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8793. if(appDelegate.password!=nil)
  8794. [params setValue:appDelegate.password forKey:@"password"];
  8795. if(appDelegate.order_code!=nil)
  8796. [params setValue:appDelegate.order_code forKey:@"orderCode"];
  8797. // NSDictionary* customerinfo= appDelegate.customerInfo;
  8798. //
  8799. // NSArray* keys=[customerinfo allKeys];
  8800. // for(int i=0;i<keys.count;i++)
  8801. // {
  8802. // [params setValue:[customerinfo valueForKey:(NSString*)keys[i]] forKey:keys[i] ];
  8803. // }
  8804. //
  8805. // [params setValue:sourceid forKey:@"sourceid"];
  8806. // [params setValue:editor forKey:@"editor"];
  8807. [params setObject:ScreenCodePlaceOrder forKey:kScreenName];
  8808. if(appDelegate.offline_mode)
  8809. {
  8810. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8811. NSData* json = [[OLDataProvider offline_submitorder:params] mutableCopy];
  8812. dispatch_async(dispatch_get_main_queue(), ^{
  8813. result([[RAConvertor data2dict:json] mutableCopy]);
  8814. });
  8815. });
  8816. return;
  8817. }
  8818. [self request_interface:URL_COMMIT_ORDER parameters:params err_record_url:nil completionHandler:result retry:0];
  8819. //
  8820. // NSData* json=nil;
  8821. // if(appDelegate.offline_mode)
  8822. // {
  8823. // json=[OLDataProvider offline_submitorder:params];
  8824. // }
  8825. // else
  8826. // {
  8827. // if(![self IsNetworkAvailable])
  8828. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8829. //
  8830. // json=[self get_json:URL_COMMIT_ORDER parameters:params];
  8831. // }
  8832. // if(json!=nil)
  8833. // {
  8834. // NSError *error=nil;
  8835. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8836. // if([[jsobj valueForKey:@"result"]intValue]==2)
  8837. // [appDelegate SetSo:nil];
  8838. //
  8839. //
  8840. // return jsobj;
  8841. // }
  8842. // else
  8843. // return nil;
  8844. }
  8845. +(void) request_new_offline_ticket:(NSString* )ver useInternalAddress:(bool)buseinternaladdress vid:(NSString*)vid completionHandler:(resultHandler)result
  8846. {
  8847. // if(![self IsNetworkAvailable])
  8848. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  8849. //
  8850. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8851. AppDelegate *appDelegate = nil;
  8852. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8853. if(appDelegate.user!=nil)
  8854. [params setValue:appDelegate.user forKey:@"user"];
  8855. // if(appDelegate.contact_id!=nil)
  8856. // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8857. if(appDelegate.password!=nil)
  8858. [params setValue:appDelegate.password forKey:@"password"];
  8859. [params setValue:ver forKey:@"ver"];
  8860. [params setValue:vid forKey:@"vid"];
  8861. if(buseinternaladdress)
  8862. [params setValue:@"true" forKey:@"internal_address"];
  8863. else
  8864. [params setValue:@"false" forKey:@"internal_address"];
  8865. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  8866. // 无论当前是离线还是在线状态,都可以进行同步;
  8867. // if(appDelegate.offline_mode)
  8868. // {
  8869. //
  8870. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8871. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8872. // dispatch_async(dispatch_get_main_queue(), ^{
  8873. // result(json);
  8874. // });
  8875. // });
  8876. //
  8877. // return;
  8878. //
  8879. // }
  8880. [self request_interface:URL_CHECK_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  8881. //
  8882. // NSData* json=[self get_json:URL_CHECK_OFFLINE parameters:params];
  8883. // if(json==nil)
  8884. // return nil;
  8885. // NSError *error=nil;
  8886. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8887. // // int result = [[jsobj valueForKey:@"result"] intValue];
  8888. // //
  8889. // // if (result==2)
  8890. // // {
  8891. // //
  8892. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8893. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  8894. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8895. // ////
  8896. // //// [appDelegate update_count_mark];
  8897. // // }
  8898. // return jsobj;
  8899. }
  8900. +(void) request_complete_offline_ticket:(NSString* )vid completionHandler:(resultHandler)result
  8901. {
  8902. // AppDelegate *appDelegate = nil;
  8903. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8904. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8905. [params setObject:ScreenCodeOfflineSetting forKey:kScreenName];
  8906. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8907. // if(appDelegate.user!=nil)
  8908. // [params setValue:appDelegate.user forKey:@"user"];
  8909. // // if(appDelegate.contact_id!=nil)
  8910. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8911. // if(appDelegate.password!=nil)
  8912. // [params setValue:appDelegate.password forKey:@"password"];
  8913. [params setValue:vid forKey:@"downSerial"];
  8914. // 无论当前是离线还是在线状态,都可以进行同步;
  8915. // if(appDelegate.offline_mode)
  8916. // {
  8917. //
  8918. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8919. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8920. // dispatch_async(dispatch_get_main_queue(), ^{
  8921. // result(json);
  8922. // });
  8923. // });
  8924. //
  8925. // return;
  8926. //
  8927. // }
  8928. [self request_interface:URL_FINISH_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:result retry:0];
  8929. // NSData* json=[self get_json:URL_FINISH_DOWNLOAD_OFFLINE parameters:params];
  8930. // if(json==nil)
  8931. // return nil;
  8932. // NSError *error=nil;
  8933. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  8934. // // int result = [[jsobj valueForKey:@"result"] intValue];
  8935. // //
  8936. // // if (result==2)
  8937. // // {
  8938. // //
  8939. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  8940. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  8941. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  8942. // ////
  8943. // //// [appDelegate update_count_mark];
  8944. // // }
  8945. // return jsobj;
  8946. }
  8947. +(void) request_download_offline:(NSString* )vid completionHandler:(resultHandler)result
  8948. {
  8949. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  8950. [params setObject:ScreenCodeOfflineSync forKey:kScreenName];
  8951. // AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  8952. // if(appDelegate.user!=nil)
  8953. // [params setValue:appDelegate.user forKey:@"user"];
  8954. // // if(appDelegate.contact_id!=nil)
  8955. // // [params setValue:appDelegate.contact_id forKey:@"contactId"];
  8956. // if(appDelegate.password!=nil)
  8957. // [params setValue:appDelegate.password forKey:@"password"];
  8958. [params setValue:vid forKey:@"downSerial"];
  8959. // AppDelegate *appDelegate = nil;
  8960. //
  8961. //
  8962. // appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  8963. // if(appDelegate.offline_mode)
  8964. // {
  8965. //
  8966. // dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8967. // NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  8968. // dispatch_async(dispatch_get_main_queue(), ^{
  8969. // result(json);
  8970. // });
  8971. // });
  8972. //
  8973. // return;
  8974. //
  8975. // }
  8976. __block bool bbreak = false;
  8977. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  8978. __block NSMutableDictionary* download_json=nil;
  8979. int count=0;
  8980. // __block bool preparing = true;
  8981. while ([[download_json valueForKey:@"result"] intValue]!=2&&count<REQUEST_DOWNLOAD_RETRY_TIMES) //超过60分钟还没准被好数据就视为服务器出错。
  8982. {
  8983. if(bbreak)
  8984. break;
  8985. dispatch_async(dispatch_get_main_queue(), ^{
  8986. [self request_interface:URL_DOWNLOAD_OFFLINE parameters:params err_record_url:nil completionHandler:^(NSMutableDictionary *resulti) {
  8987. if([resulti[@"result"] intValue]==RESULT_TRUE)
  8988. {
  8989. if(!bbreak) //此判断保证result只调用一次。
  8990. {
  8991. // appDelegate.cart_count = [[resulti valueForKey:@"cart_count"] intValue];
  8992. // [appDelegate update_count_mark];
  8993. resulti[@"request_count"]=[NSNumber numberWithInt:count];
  8994. result(resulti);
  8995. }
  8996. bbreak=true;
  8997. }
  8998. else if([resulti[@"result"] intValue]==RESULT_ERROR)
  8999. {
  9000. result(resulti);
  9001. bbreak=true;
  9002. }
  9003. } retry:3];
  9004. });
  9005. sleep(RETRY_DELAY);
  9006. count++;
  9007. // download_json=[[RANetwork download_Offline:downSerial] mutableCopy];
  9008. //
  9009. // [RANetwork request_download_offline:downSerial completionHandler:^(NSMutableDictionary *result) {
  9010. // download_json=result;
  9011. // }];
  9012. //
  9013. }
  9014. // for(int i=0;i<150;i++)
  9015. // {
  9016. // // NSMutableDictionary* result_params = [[NSMutableDictionary alloc]init];
  9017. // // result_params[@"resultSerial"]=uuid;
  9018. //
  9019. //
  9020. //
  9021. // sleep(2);
  9022. //
  9023. // // json=[self get_json:URL_CART parameters:params];
  9024. // // if(json!=nil)
  9025. // // {
  9026. // //
  9027. // // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9028. // // if([jsobj[@"result"] intValue]==2)
  9029. // // {
  9030. // // break;
  9031. // // }
  9032. // // }
  9033. //
  9034. // }
  9035. });
  9036. //
  9037. // NSData* json=[self get_json:URL_DOWNLOAD_OFFLINE parameters:params];
  9038. // if(json==nil)
  9039. // return nil;
  9040. // NSError *error=nil;
  9041. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9042. // // int result = [[jsobj valueForKey:@"result"] intValue];
  9043. // //
  9044. // // if (result==2)
  9045. // // {
  9046. // //
  9047. // //// appDelegate.cart_count = [[jsobj valueForKey:@"cart_count"] intValue];
  9048. // //// //appDelegate.wish_count =[[jsobj valueForKey:@"count"] intValue];
  9049. // //// // appDelegate.port_count =[[jsobj valueForKey:@"portfolio_count"] intValue];
  9050. // ////
  9051. // //// [appDelegate update_count_mark];
  9052. // // }
  9053. // return jsobj;
  9054. }
  9055. + (void)request_fastupload:(NSMutableDictionary *)params filename:(NSString*)filename data:(NSData*) data url:(NSString *)url completionHandler:(resultHandler)result
  9056. {
  9057. //#ifdef test_server
  9058. // url=URL_REQUEST_RECORDS;
  9059. // params[@"prefix"]=URL_REQUEST_RECORDS;
  9060. //#endif
  9061. // [self request_file_fast:url parameters:params completionHandler:result];
  9062. #ifdef SCANNER_ORDER
  9063. params[@"site_name"]=[RADataProvider getSiteName];
  9064. #endif
  9065. [self request_upload_fast:data FileName:filename server:url parameters:params completionHandler:result];
  9066. }
  9067. +(void)request_err_log:(NSString*) up_params result:(NSString*)result_str module:(NSString*) module code:(int) code completionHandler:(resultHandler)result
  9068. {
  9069. NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
  9070. AppDelegate *appDelegate = nil;
  9071. appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
  9072. if(appDelegate.user!=nil)
  9073. [params setValue:appDelegate.user forKey:@"user"];
  9074. [params setValue:up_params forKey:@"upparam"];
  9075. [params setValue:[NSNumber numberWithInt:code ] forKey:@"code"];
  9076. [params setValue:result_str forKey:@"result"];
  9077. [params setValue:module forKey:@"interfac"];
  9078. [params setValue:[RAUtils base64en:[RAConvertor dict2string: [RAUtils device_info]]] forKey:@"device"];
  9079. // [params setValue:module forKey:@"module"];
  9080. // [[UIDevice currentDevice] name];
  9081. // if(appDelegate.offline_mode)
  9082. // {
  9083. // return [OLDataProvider offline_notimpl];
  9084. // }
  9085. if(appDelegate.offline_mode)
  9086. {
  9087. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  9088. NSMutableDictionary* json = [[OLDataProvider offline_notimpl] mutableCopy];
  9089. dispatch_async(dispatch_get_main_queue(), ^{
  9090. result(json);
  9091. });
  9092. });
  9093. return;
  9094. }
  9095. [self request_interface:URL_ERR_LOG parameters:params err_record_url:nil completionHandler:result retry:0];
  9096. //
  9097. // if(![self IsNetworkAvailable])
  9098. // return [RAUtils error_json:RESULT_NET_NOTAVAILABLE err_msg:nil];
  9099. //
  9100. // NSData* json=[self get_json:URL_ERR_LOG parameters:params];
  9101. // if(json==nil)
  9102. // return nil;
  9103. // NSError *error=nil;
  9104. // NSDictionary *jsobj = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:&error];
  9105. // return jsobj;
  9106. }
  9107. @end