GoodsController.class.php 153 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Seller\Controller;
  10. class GoodsController extends CommonController{
  11. protected function _initialize(){
  12. parent::_initialize();
  13. $this->breadcrumb1='商品管理';
  14. $this->breadcrumb2='普通商品信息';
  15. $this->sellerid = SELLERUID;
  16. }
  17. public function index(){
  18. $pindex = I('get.page', 1);
  19. $psize = 20;
  20. $starttime_arr = I('get.time');
  21. $starttime = isset($starttime_arr['start']) ? strtotime($starttime_arr['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  22. $endtime = isset($starttime_arr['end']) ? strtotime($starttime_arr['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  23. $sort_starttime = I('get.sort_starttime');
  24. $sort_endtime = I('get.sort_endtime');
  25. if( isset($sort_starttime) && $sort_starttime > 0 )
  26. {
  27. $starttime = $sort_starttime;
  28. }
  29. if( isset($sort_endtime) && $sort_endtime > 0 )
  30. {
  31. $endtime = $sort_endtime;
  32. }
  33. $this->starttime = $starttime;
  34. $this->endtime = $endtime;
  35. $searchtime = I('get.searchtime','');
  36. $this->searchtime = $searchtime;
  37. $shop_data = array();
  38. $type = I('get.type','all');
  39. $goods_type = I('get.goods_type', 'normal');
  40. //---begin
  41. $count_common_where ="";
  42. if (defined('ROLE') && ROLE == 'agenter' ) {
  43. $supper_info = get_agent_logininfo();
  44. $supper_goods_list = M('lionfish_comshop_good_common')->field('goods_id')->where( array('supply_id' =>$supper_info['id'] ) )->select();
  45. $gids_list = array();
  46. foreach($supper_goods_list as $vv)
  47. {
  48. $gids_list[] = $vv['goods_id'];
  49. }
  50. if( !empty($gids_list) )
  51. {
  52. $count_common_where = " and id in ( ".implode(',', $gids_list )." )";
  53. }else{
  54. $count_common_where = " and id in (0)";
  55. }
  56. }
  57. $goods_stock_notice = D('Home/Front')->get_config_by_name('goods_stock_notice');
  58. $goods_stock_notice = intval($goods_stock_notice);
  59. if( empty($goods_stock_notice) )
  60. {
  61. $goods_stock_notice = 0;
  62. }
  63. if($goods_type != 'normal' && $goods_type == 'presale')
  64. {
  65. $all_count = D('Seller/Goods')->get_goods_count(" and type = 'presale' {$count_common_where}");//全部商品数量
  66. $onsale_count = D('Seller/Goods')->get_goods_count(" and grounding = 1 and type = 'presale' {$count_common_where}");//出售中商品数量
  67. $getdown_count = D('Seller/Goods')->get_goods_count(" and grounding = 0 and type = 'presale' {$count_common_where}");//已下架商品数量
  68. $warehouse_count = D('Seller/Goods')->get_goods_count(" and grounding = 2 and type = 'presale' {$count_common_where}");//仓库商品数量
  69. $recycle_count = D('Seller/Goods')->get_goods_count(" and grounding = 3 and type = 'presale' {$count_common_where}");//回收站商品数量
  70. $waishen_count = D('Seller/Goods')->get_goods_count(" and grounding = 4 and type = 'presale' {$count_common_where}");//审核商品数量
  71. $unsuccshen_count = D('Seller/Goods')->get_goods_count(" and grounding = 5 and type = 'presale' {$count_common_where}");//拒绝审核商品数量
  72. $stock_notice_count = D('Admin/Goods')->get_goods_count(" and grounding = 1 and total<= {$goods_stock_notice} and type = 'presale' {$count_common_where} ");//回收站商品数量
  73. }
  74. else if($goods_type != 'normal' && $goods_type == 'virtualcard')
  75. {
  76. //礼品卡
  77. $all_count = D('Seller/Goods')->get_goods_count(" and type = 'virtualcard' {$count_common_where}");//全部商品数量
  78. $onsale_count = D('Seller/Goods')->get_goods_count(" and grounding = 1 and type = 'virtualcard' {$count_common_where}");//出售中商品数量
  79. $getdown_count = D('Seller/Goods')->get_goods_count(" and grounding = 0 and type = 'virtualcard' {$count_common_where}");//已下架商品数量
  80. $warehouse_count = D('Seller/Goods')->get_goods_count(" and grounding = 2 and type = 'virtualcard' {$count_common_where}");//仓库商品数量
  81. $recycle_count = D('Seller/Goods')->get_goods_count(" and grounding = 3 and type = 'virtualcard' {$count_common_where}");//回收站商品数量
  82. $waishen_count = D('Seller/Goods')->get_goods_count(" and grounding = 4 and type = 'virtualcard' {$count_common_where}");//审核商品数量
  83. $unsuccshen_count = D('Seller/Goods')->get_goods_count(" and grounding = 5 and type = 'virtualcard' {$count_common_where}");//拒绝审核商品数量
  84. $stock_notice_count = D('Admin/Goods')->get_goods_count(" and grounding = 1 and total<= {$goods_stock_notice} and type = 'virtualcard' {$count_common_where} ");//回收站商品数量
  85. }
  86. else{
  87. $all_count = D('Seller/Goods')->get_goods_count(" and type = 'normal' {$count_common_where}");//全部商品数量
  88. $onsale_count = D('Seller/Goods')->get_goods_count(" and grounding = 1 and type = 'normal' {$count_common_where}");//出售中商品数量
  89. $getdown_count = D('Seller/Goods')->get_goods_count(" and grounding = 0 and type = 'normal' {$count_common_where}");//已下架商品数量
  90. $warehouse_count = D('Seller/Goods')->get_goods_count(" and grounding = 2 and type = 'normal' {$count_common_where}");//仓库商品数量
  91. $recycle_count = D('Seller/Goods')->get_goods_count(" and grounding = 3 and type = 'normal' {$count_common_where}");//回收站商品数量
  92. $waishen_count = D('Seller/Goods')->get_goods_count(" and grounding = 4 and type = 'normal' {$count_common_where}");//审核商品数量
  93. $unsuccshen_count = D('Seller/Goods')->get_goods_count(" and grounding = 5 and type = 'normal' {$count_common_where}");//拒绝审核商品数量
  94. $stock_notice_count = D('Admin/Goods')->get_goods_count(" and grounding = 1 and total<= {$goods_stock_notice} and type = 'normal' {$count_common_where} ");//回收站商品数量
  95. }
  96. $this->assign('waishen_count',$waishen_count);
  97. $this->assign('unsuccshen_count',$unsuccshen_count);
  98. //goods_stock_notice
  99. //grounding 1
  100. //type all 全部
  101. //saleon 1 出售中
  102. //getdown 0 已下架
  103. //warehouse 2 仓库中
  104. //recycle 3 回收站
  105. $psize = 20;
  106. $condition = ' WHERE g.type = "normal" ';
  107. //预售
  108. if($goods_type != 'normal' && $goods_type == 'presale')
  109. {
  110. $condition = ' WHERE g.type = "presale" ';
  111. }else if( $goods_type != 'normal' && $goods_type == 'virtualcard' )
  112. {
  113. $condition = ' WHERE g.type = "virtualcard" ';
  114. }
  115. $sqlcondition = "";
  116. if( !empty($type) && $type != 'all')
  117. {
  118. switch($type)
  119. {
  120. case 'saleon':
  121. $condition .= " and g.grounding = 1";
  122. break;
  123. case 'getdown':
  124. $condition .= " and g.grounding = 0";
  125. break;
  126. case 'warehouse':
  127. $condition .= " and g.grounding = 2";
  128. break;
  129. case 'wait_shen':
  130. $condition .= " and g.grounding = 4";
  131. break;
  132. case 'refuse':
  133. $condition .= " and g.grounding = 5";
  134. break;
  135. case 'recycle':
  136. $condition .= " and g.grounding = 3";
  137. break;
  138. case 'stock_notice':
  139. $condition .= " and g.grounding = 1 and g.total<= {$goods_stock_notice} ";
  140. break;
  141. }
  142. }else{
  143. $condition .= " and g.grounding != 3 ";
  144. }
  145. $keyword = I('get.keyword','','addslashes');
  146. $keyword2 = stripslashes($keyword);
  147. $this->keyword = $keyword2;
  148. if (!(empty($keyword))) {
  149. $condition .= " AND (g.`id` = '{$keyword}' or g.`goodsname` LIKE '%{$keyword}%' or g.`codes` LIKE '%{$keyword}%' ) ";
  150. }
  151. if (defined('ROLE') && ROLE == 'agenter' )
  152. {
  153. $supper_info = get_agent_logininfo();
  154. $sqlcondition .= ' , ' . C('DB_PREFIX'). 'lionfish_comshop_good_common as gm ';
  155. $condition .= ' and gm.goods_id =g.id AND gm.supply_id ='.$supper_info['id'].' ';
  156. }
  157. if( !empty($searchtime) )
  158. {
  159. switch( $searchtime )
  160. {
  161. case 'create':
  162. $condition .= ' AND (gm.begin_time >='.$starttime.' and gm.end_time <= '.$endtime.' )';
  163. if (!defined('ROLE') && ROLE != 'agenter' )
  164. {
  165. $sqlcondition .= ' left join ' . C('DB_PREFIX'). 'lionfish_comshop_good_common as gm on gm.goods_id = g.id ';
  166. }
  167. break;
  168. }
  169. }
  170. $cate = I('get.cate', '');
  171. $this->cate = $cate;
  172. if( !empty($cate) )
  173. {
  174. $cat_ids = D('Seller/GoodsCategory')->getChildCategorys($cate,'id');
  175. $cate_list = M('lionfish_comshop_goods_to_category')->field('goods_id')->where(array('cate_id' => array('in', $cat_ids)))->select();
  176. $catids_arr = array();
  177. foreach($cate_list as $val)
  178. {
  179. $catids_arr[] = $val['goods_id'];
  180. }
  181. if( !empty($catids_arr) )
  182. {
  183. $catids_str = implode(',', $catids_arr);
  184. $condition .= ' and g.id in ('.$catids_str.')';
  185. }else{
  186. $condition .= " and 1=0 ";
  187. }
  188. }
  189. $sql = 'SELECT COUNT(g.id) as count FROM ' .C('DB_PREFIX'). 'lionfish_comshop_goods g ' .$sqlcondition. $condition ;
  190. $total_arr = M()->query($sql);
  191. $total = $total_arr[0]['count'];
  192. //'sortby' =>$sortby,'sortfield' => 'day_salescount',
  193. $sortby = I('get.sortby');
  194. $sortfield = I('get.sortfield');
  195. $this->sortfield = $sortfield;
  196. $sortby = (!empty($sortby) ? ($sortby== 'asc' ?'desc':'asc') : ( !empty($sortfield) ? 'desc':'' ) );
  197. $this->sortby = $sortby;
  198. $pager = pagination2($total, $pindex, $psize);
  199. if (!(empty($total))) {
  200. $index_sort_method = D('Home/Front')->get_config_by_name('index_sort_method');
  201. if( empty($index_sort_method) || $index_sort_method == 0 )
  202. {
  203. $sort_way = 'g.istop DESC, g.settoptime DESC, g.`id` DESC';
  204. if( !empty($sortfield) )
  205. {
  206. $sort_way = ' g.'.$sortfield.' '.$sortby.' , '.$sort_way;
  207. }
  208. $sql = 'SELECT g.* FROM ' .C('DB_PREFIX'). 'lionfish_comshop_goods g ' .$sqlcondition . $condition . '
  209. ORDER BY '.$sort_way.' ';
  210. }else{
  211. $sort_way = 'g.index_sort DESC, g.`id` DESC';
  212. if( !empty($sortfield) )
  213. {
  214. $sort_way = ' g.'.$sortfield.' '.$sortby.' ,'.$sort_way;
  215. }
  216. $sql = 'SELECT g.* FROM ' .C('DB_PREFIX'). 'lionfish_comshop_goods g ' .$sqlcondition . $condition . '
  217. ORDER BY '.$sort_way.' ';
  218. }
  219. if(I('export') != 1) { // 如果导出excel 就显示全部
  220. $sql .= ' limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  221. }
  222. //$sql .= ' limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  223. $list = M()->query($sql);
  224. $open_redis_server = D('Home/Front')->get_config_by_name('open_redis_server');
  225. if( isset($open_redis_server) && $open_redis_server >0 )
  226. {
  227. $open_redis_server = 1;
  228. }else{
  229. $open_redis_server = 0;
  230. }
  231. $this->open_redis_server = $open_redis_server;
  232. foreach ($list as $key => &$value ) {
  233. $price_arr = D('Home/pingoods')->get_goods_price($value['id'], -888 );
  234. $value['codes'] = "\t".$value['codes']."\t";
  235. $value['price_arr'] = $price_arr;
  236. $thumb = M('lionfish_comshop_goods_images')->where( array('goods_id' => $value['id']) )->order('id asc')->find();
  237. if( empty($thumb['thumb']) )
  238. {
  239. $value['thumb'] = $thumb['image'];
  240. }else{
  241. $value['thumb'] = $thumb['thumb'];
  242. }
  243. //is_take_fullreduction print_sub_title
  244. $gd_common = M('lionfish_comshop_good_common')->field('is_take_fullreduction,supply_id,is_only_distribution,is_spike_buy,is_only_express,is_only_hexiao,print_sub_title')->where( array('goods_id' => $value['id']) )->find();
  245. //print_sub_title
  246. $value['print_sub_title'] = $gd_common['print_sub_title'];
  247. //判断是否开启redis
  248. if( $open_redis_server == 1 )
  249. {
  250. $value['redis_total'] = D('Seller/Redisorder')->get_goods_total_quantity( $value['id'] );
  251. }
  252. $value['is_take_fullreduction'] = $gd_common['is_take_fullreduction'];
  253. $value['is_only_hexiao'] = $gd_common['is_only_hexiao'];
  254. $value['is_only_distribution'] = $gd_common['is_only_distribution'];
  255. $value['is_spike_buy'] = $gd_common['is_spike_buy'];
  256. $value['is_only_express'] = $gd_common['is_only_express'];
  257. $value['supply_name'] = '';
  258. $value['supply_type'] = '0';
  259. if( empty($gd_common['supply_id']) || $gd_common['supply_id'] ==0 )
  260. {
  261. $value['supply_id'] = 0;
  262. }else{
  263. $value['supply_id'] = $gd_common['supply_id'];
  264. $sub_info = M('lionfish_comshop_supply')->field('name,type')->where( array('id' => $gd_common['supply_id'] ) )->find();
  265. $value['supply_name'] = $sub_info['name'];
  266. $value['supply_type'] = $sub_info['type'];
  267. }
  268. $categorys = M('lionfish_comshop_goods_to_category')->where( array('goods_id' => $value['id']) )->order('id asc')->select();
  269. $value['cate'] = $categorys;
  270. $time_info = D('home/front')->get_goods_common_field($value['id'] , 'begin_time,end_time');
  271. $value['begin_time'] = $time_info['begin_time'];
  272. $value['end_time'] = $time_info['end_time'];
  273. //团长数量
  274. $head_count = 0;
  275. if( $value['is_all_sale'] == 1 )
  276. {
  277. $head_count = M('lionfish_community_head')->count();
  278. }else{
  279. $head_count = M('lionfish_community_head_goods')->where( array('goods_id' => $value['id'] ) )->count();
  280. }
  281. $value['head_count'] = $head_count;
  282. $value['option'] = [];
  283. if(I('get.export') > 0) {// 商品列表到处excel时要导出规格
  284. $value['option'] = M('lionfish_comshop_goods_option_item_value')->where('goods_id = "'.$value['id'].'"')->field('id,title,productprice,marketprice,card_price,stock,title,goodssn,costprice,weight')->select();
  285. if($value['option'] === null){
  286. $value['option'] = [];
  287. }
  288. foreach($categorys as $categorysKey => $categorysVal){
  289. $categorysInfo = M('lionfish_comshop_goods_category')->where( array('id' => $categorysVal['cate_id']) )->find();
  290. $value['cate'.($categorysKey+1).'_id'] = $categorysVal['cate_id'];
  291. $value['cate'.($categorysKey+1).'_name'] = $categorysInfo['name'];
  292. }
  293. $goodsCommon = M('lionfish_comshop_good_common')->where('goods_id = "'.$value['id'].'"')->field('is_spike_buy,is_new_buy,one_limit_count,oneday_limit_count,total_limit_count,begin_time,end_time')->find();
  294. $value['oneday_limit_count'] = $goodsCommon['oneday_limit_count'];
  295. $value['one_limit_count'] = $goodsCommon['one_limit_count'];
  296. $value['total_limit_count'] = $goodsCommon['total_limit_count'];
  297. $value['is_spike_buy'] = $goodsCommon['is_spike_buy'];
  298. $value['is_new_buy'] = $goodsCommon['is_new_buy'];
  299. $value['pin_begin_time'] = date('Y-m-d H:i:s',$goodsCommon['begin_time']);
  300. $value['pin_end_time'] = date('Y-m-d H:i:s',$goodsCommon['end_time']);
  301. $goodsPin = M('lionfish_comshop_good_pin')->where('goods_id = "'.$value['id'].'"')->field('begin_time,end_time')->find();
  302. if($goodsPin){
  303. $value['pin_begin_time'] = date('Y-m-d H:i:s',$goodsPin['begin_time']);
  304. $value['pin_end_time'] = date('Y-m-d H:i:s',$goodsPin['end_time']);
  305. }
  306. if($value['is_all_sale'] == 1){
  307. $value['is_all_sale_str'] = '[所有团长'.$head_count.']';
  308. }else if($head_count == 0){
  309. $value['is_all_sale_str'] = '[无团长0]';
  310. }else if($head_count > 0){
  311. $value['is_all_sale_str'] = '[部分团长'.$head_count.']';
  312. }
  313. }
  314. }
  315. }
  316. unset($value);
  317. $categorys = D('Seller/GoodsCategory')->getFullCategory(true);
  318. $category = array();
  319. foreach ($categorys as $cate ) {
  320. $category[$cate['id']] = $cate;
  321. }
  322. $this->category =$category;
  323. $this->type = $type;
  324. $this->all_count = $all_count;
  325. $this->onsale_count = $onsale_count;
  326. $this->getdown_count = $getdown_count;
  327. $this->warehouse_count = $warehouse_count;
  328. $this->recycle_count = $recycle_count;
  329. $this->stock_notice_count = $stock_notice_count;
  330. $this->assign('list',$list);// 赋值数据集
  331. $this->assign('pager',$pager);// 赋值分页输出
  332. $is_open_fullreduction = D('Home/Front')->get_config_by_name('is_open_fullreduction');
  333. $this->assign('is_open_fullreduction',$is_open_fullreduction);
  334. //供应商同城配送 0关 1开
  335. $supply_is_open_localtown_distribution = D('Home/Front')->get_config_by_name('supply_is_open_localtown_distribution');
  336. $this->assign('supply_is_open_localtown_distribution',$supply_is_open_localtown_distribution);
  337. //总后台同城配送 0关 1开
  338. $isopen_localtown_delivery = D('Home/Front')->get_config_by_name('isopen_localtown_delivery');
  339. $this->assign('isopen_localtown_delivery',$isopen_localtown_delivery);
  340. $index_sort_method = D('Home/Front')->get_config_by_name('index_sort_method');
  341. if( empty($index_sort_method) || $index_sort_method == 0 )
  342. {
  343. $index_sort_method = 0;
  344. }
  345. $this->index_sort_method = $index_sort_method;
  346. //---
  347. $supply_add_goods_shenhe = D('Home/Front')->get_config_by_name('supply_add_goods_shenhe');
  348. $supply_edit_goods_shenhe = D('Home/Front')->get_config_by_name('supply_edit_goods_shenhe');
  349. if(empty($supply_add_goods_shenhe))
  350. {
  351. $supply_add_goods_shenhe = 0;
  352. }
  353. if(empty($supply_edit_goods_shenhe))
  354. {
  355. $supply_edit_goods_shenhe = 0;
  356. }
  357. $is_open_shenhe = 0;
  358. if($supply_add_goods_shenhe ==1 || $supply_edit_goods_shenhe == 1)
  359. {
  360. $is_open_shenhe = 1;
  361. }
  362. $this->supply_add_goods_shenhe = $supply_add_goods_shenhe;
  363. $this->supply_edit_goods_shenhe = $supply_edit_goods_shenhe;
  364. $this->is_open_shenhe = $is_open_shenhe;
  365. //--
  366. //团长分组
  367. $group_default_list = array(
  368. array('id' => 'default', 'groupname' => '默认分组')
  369. );
  370. $group_list = M('lionfish_community_head_group')->field('id,groupname')->order('id asc')->select();
  371. $group_list = array_merge($group_default_list, $group_list);
  372. $this->group_list = $group_list;
  373. $config_data = D('Seller/Config')->get_all_config();
  374. $is_index = true;
  375. $is_top = true;
  376. $is_updown = true;
  377. $is_fullreduce = true;
  378. $is_vir_count = true;
  379. $is_newbuy = true;
  380. $is_goodsspike = true;
  381. $is_distributionsale = true;
  382. $is_supply_add_goods_shenhe = true;
  383. if (defined('ROLE') && ROLE == 'agenter' )
  384. {
  385. $is_fullreduce = false;
  386. if( isset($config_data['supply_can_goods_isindex']) && $config_data['supply_can_goods_isindex'] == 2 )
  387. {
  388. $is_index = false;
  389. }
  390. if( isset($config_data['supply_can_goods_istop']) && $config_data['supply_can_goods_istop'] == 2 )
  391. {
  392. $is_top = false;
  393. }
  394. if( isset($config_data['supply_can_goods_updown']) && $config_data['supply_can_goods_updown'] == 2 )
  395. {
  396. $is_updown = false;
  397. }
  398. if( isset($config_data['supply_can_vir_count']) && $config_data['supply_can_vir_count'] == 2 )
  399. {
  400. $is_vir_count = false;
  401. }
  402. if( isset($config_data['supply_can_goods_newbuy']) && $config_data['supply_can_goods_newbuy'] == 2 )
  403. {
  404. $is_newbuy = false;
  405. }
  406. if( isset($config_data['supply_can_goods_spike']) && $config_data['supply_can_goods_spike'] == 2 )
  407. {
  408. $is_goodsspike = false;
  409. }
  410. if( isset($config_data['supply_can_distribution_sale']) && $config_data['supply_can_distribution_sale'] == 2 )
  411. {
  412. $is_distributionsale = false;
  413. }
  414. if( isset($config_data['supply_add_goods_shenhe']) && $config_data['supply_add_goods_shenhe'] == 0 )
  415. {
  416. $is_supply_add_goods_shenhe = false;
  417. }
  418. }
  419. $seckill_is_open = D('Home/Front')->get_config_by_name('seckill_is_open');
  420. $this->seckill_is_open = $seckill_is_open;
  421. if(I('get.export') > 0) {// 商品列表到处excel
  422. $this->goods_listexcel($list);
  423. }
  424. $this->config_data = $config_data;
  425. $this->is_index = $is_index;
  426. $this->is_top = $is_top;
  427. $this->is_updown = $is_updown;
  428. $this->is_fullreduce = $is_fullreduce;
  429. $this->is_vir_count = $is_vir_count;
  430. $this->is_newbuy = $is_newbuy;
  431. $this->is_goodsspike = $is_goodsspike;
  432. $this->is_distributionsale = $is_distributionsale;
  433. $this->is_supply_add_goods_shenhe = $is_supply_add_goods_shenhe;
  434. $this->display();
  435. }
  436. /**
  437. * 商品列表到处excel
  438. * @author 刘鑫芮 2020-03-02
  439. * @param $list 商品列表集合数据 全部-根据where 条件搜索的
  440. * */
  441. public function goods_listexcel($list) {
  442. // dump($list);die;
  443. $printList = $list;
  444. foreach($list as $key => $value) {
  445. $printList[$key] = array(
  446. 'id' => $value['id']
  447. );
  448. }
  449. $columns = array(
  450. array(
  451. 'title' => '商品ID(禁止修改)',
  452. 'field' => 'id',
  453. 'width' => 24
  454. ) ,
  455. array(
  456. 'title' => '商品名称',
  457. 'field' => 'goodsname',
  458. 'width' => 24
  459. ) ,
  460. array(
  461. 'title' => '商品简称',
  462. 'field' => 'print_sub_title',
  463. 'width' => 24
  464. ) ,
  465. array(
  466. 'title' => '商品编码',
  467. 'field' => 'codes',
  468. 'width' => 24
  469. ) ,
  470. array(
  471. 'title' => '一级分类ID',
  472. 'field' => 'cate1_id',
  473. 'width' => 24
  474. ) ,
  475. array(
  476. 'title' => '一级分类名称',
  477. 'field' => 'cate1_name',
  478. 'width' => 24
  479. ) ,
  480. array(
  481. 'title' => '二级分类ID',
  482. 'field' => 'cate2_id',
  483. 'width' => 24
  484. ) ,
  485. array(
  486. 'title' => '二级分类名称',
  487. 'field' => 'cate2_name',
  488. 'width' => 24
  489. ) ,
  490. array(
  491. 'title' => '商品价格',
  492. 'field' => 'price',
  493. 'width' => 24
  494. ) ,
  495. array(
  496. 'title' => '商品成本价',
  497. 'field' => 'costprice',
  498. 'width' => 24
  499. ) ,
  500. array(
  501. 'title' => '会员卡价格',
  502. 'field' => 'card_price',
  503. 'width' => 24
  504. ) ,
  505. array(
  506. 'title' => '商品原价',
  507. 'field' => 'productprice',
  508. 'width' => 24
  509. ) ,
  510. array(
  511. 'title' => '商品库存',
  512. 'field' => 'total',
  513. 'width' => 24
  514. ) ,
  515. array(
  516. 'title' => '每日销量',
  517. 'field' => 'day_salescount',
  518. 'width' => 24
  519. ) ,
  520. array(
  521. 'title' => '总销量',
  522. 'field' => 'seller_count',
  523. 'width' => 24
  524. ) ,
  525. array(
  526. 'title' => '1上架/0下架',
  527. 'field' => 'grounding',
  528. 'width' => 24
  529. ) ,
  530. array(
  531. 'title' => '首页推荐(0:取消/1:是)',
  532. 'field' => 'is_index_show',
  533. 'width' => 24
  534. ) ,
  535. array(
  536. 'title' => '限时秒杀(0:取消/1:是)',
  537. 'field' => 'is_spike_buy',
  538. 'width' => 24
  539. ) ,
  540. array(
  541. 'title' => '所有团长',
  542. 'field' => 'is_all_sale_str',
  543. 'width' => 24
  544. ) ,
  545. array(
  546. 'title' => '新人专享',
  547. 'field' => 'is_new_buy',
  548. 'width' => 24
  549. ) ,
  550. array(
  551. 'title' => '商品排序(数字)',
  552. 'field' => 'index_sort',
  553. 'width' => 24
  554. ) ,
  555. array(
  556. 'title' => '每天限购',
  557. 'field' => 'oneday_limit_count',
  558. 'width' => 24
  559. ) ,
  560. array(
  561. 'title' => '单次限购',
  562. 'field' => 'one_limit_count',
  563. 'width' => 24
  564. ) ,
  565. array(
  566. 'title' => '历史限购',
  567. 'field' => 'total_limit_count',
  568. 'width' => 24
  569. ) ,
  570. array(
  571. 'title' => '开始时间',
  572. 'field' => 'pin_begin_time',
  573. 'width' => 24
  574. ) ,
  575. array(
  576. 'title' => '结束时间',
  577. 'field' => 'pin_end_time',
  578. 'width' => 24
  579. ) ,
  580. array(
  581. 'title' => '商品重量(单位:g)',
  582. 'field' => 'weight',
  583. 'width' => 24
  584. ) ,
  585. array(
  586. 'title' => '规格(1:开启/0:关闭)',
  587. 'field' => 'hasoption',
  588. 'width' => 24
  589. ) ,
  590. array(
  591. 'title' => '规格id(禁止修改)',
  592. 'field' => 'option_id',
  593. 'width' => 24
  594. ) ,
  595. array(
  596. 'title' => '规格名称(禁止修改)',
  597. 'field' => 'option_title',
  598. 'width' => 24
  599. ) ,
  600. array(
  601. 'title' => '规格库存',
  602. 'field' => 'option_stock',
  603. 'width' => 24
  604. ) ,
  605. array(
  606. 'title' => '规格现价',
  607. 'field' => 'option_marketprice',
  608. 'width' => 24
  609. ) ,
  610. array(
  611. 'title' => '规格原价',
  612. 'field' => 'option_productprice',
  613. 'width' => 24
  614. ) ,
  615. array(
  616. 'title' => '规格会员价',
  617. 'field' => 'option_card_price',
  618. 'width' => 24
  619. ) ,
  620. array(
  621. 'title' => '规格成本价',
  622. 'field' => 'option_costprice',
  623. 'width' => 24
  624. ) ,
  625. array(
  626. 'title' => '规格编码',
  627. 'field' => 'option_goodssn',
  628. 'width' => 24
  629. ) ,
  630. array(
  631. 'title' => '规格重量(单位:g)',
  632. 'field' => 'option_weight',
  633. 'width' => 24
  634. )
  635. );
  636. sellerLog('导出商品excel', 3);
  637. D('Seller/Excel')->export_goods_list_pi(array(
  638. 'title' => '商品列表',
  639. 'columns' => $columns
  640. ), $list);
  641. }
  642. public function edittags()
  643. {
  644. $_GPC = I('request.');
  645. $id = intval($_GPC['id']);
  646. if (!empty($id)) {
  647. $item = M('lionfish_comshop_goods_tags')->field('id,type,tagname,tagcontent,state,sort_order')->where( array('id' =>$id ) )->find();
  648. if (json_decode($item['tagcontent'], true)) {
  649. $labelname = json_decode($item['tagcontent'], true);
  650. }
  651. else {
  652. $labelname = unserialize($item['tagcontent']);
  653. }
  654. $this->item = $item;
  655. $this->labelname = $labelname;
  656. }
  657. if (IS_POST) {
  658. $data = $_GPC['data'];
  659. D('Seller/Tags')->update($data);
  660. show_json(1, array('url' => U('goods/goodstag') ));
  661. }
  662. $this->display('Goods/addtags');
  663. }
  664. public function addtags()
  665. {
  666. $_GPC = I('request.');
  667. if (IS_POST) {
  668. $data = $_GPC['data'];
  669. D('Seller/Tags')->update($data);
  670. show_json(1, array('url' => U('goods/goodstag')));
  671. }
  672. $this->display();
  673. }
  674. public function show_logs()
  675. {
  676. $goods_id = I('get.goods_id');
  677. D('Seller/Redisorder')->show_logs($goods_id);
  678. }
  679. public function tagsstate()
  680. {
  681. $_GPC = I('request.');
  682. $id = intval($_GPC['id']);
  683. if (empty($id)) {
  684. $id = $_GPC['ids'];
  685. }
  686. if( is_array($id) )
  687. {
  688. $items = M('lionfish_comshop_goods_tags')->field('id,tagname')->where( array('id' => array('in', $id)) )->select();
  689. }else{
  690. $items = M('lionfish_comshop_goods_tags')->field('id,tagname')->where( array('id' =>$id ) )->select();
  691. }
  692. if (empty($item)) {
  693. $item = array();
  694. }
  695. foreach ($items as $item) {
  696. M('lionfish_comshop_goods_tags')->where( array('id' => $item['id']) )->save( array('state' => intval($_GPC['state'])) );
  697. D('Seller/Operatelog')->addOperateLog('goods','修改商品标签状态--'.$item['tagname']);
  698. }
  699. show_json(1, array('url' => U('goods/goodstag')));
  700. }
  701. public function deletetags()
  702. {
  703. $_GPC = I('request.');
  704. $id = intval($_GPC['id']);
  705. if (empty($id)) {
  706. $id = $_GPC['ids'];
  707. }
  708. if( is_array($id) )
  709. {
  710. $items = M('lionfish_comshop_goods_tags')->field('id,tagname')->where( array('id' => array('in', $id)) )->select();
  711. }else{
  712. $items = M('lionfish_comshop_goods_tags')->field('id,tagname')->where( array('id' =>$id ) )->select();
  713. }
  714. //$items = M('lionfish_comshop_goods_tags')->field('id,tagname')->where( array('id' => array('in', $id )) )->select();
  715. if (empty($item)) {
  716. $item = array();
  717. }
  718. foreach ($items as $item) {
  719. M('lionfish_comshop_goods_tags')->where( array('id' => $item['id']) )->delete();
  720. D('Seller/Operatelog')->addOperateLog('goods','删除商品标签--'.$item['tagname']);
  721. }
  722. show_json(1, array('url' => U('goods/goodstag')));
  723. }
  724. public function labelquery()
  725. {
  726. $_GPC = I('request.');
  727. $kwd = trim($_GPC['keyword']);
  728. $type = isset($_GPC['type']) ? $_GPC['type'] : 'normal';
  729. $condition = ' and state = 1 and tag_type="'.$type.'" ';
  730. if (!empty($kwd)) {
  731. $condition .= ' AND tagname LIKE "%'.$kwd.'%" ';
  732. }
  733. $labels = M('lionfish_comshop_goods_tags')->field('id,tagname,tagcontent')->where( '1 '. $condition )->order('id desc')->select();
  734. if (empty($labels)) {
  735. $labels = array();
  736. }
  737. $html = '';
  738. foreach ($labels as $key => $value) {
  739. if (json_decode($value['tagcontent'], true)) {
  740. $labels[$key]['tagcontent'] = json_decode($value['tagcontent'], true);
  741. }
  742. else {
  743. $labels[$key]['tagcontent'] = unserialize($value['tagcontent']);
  744. }
  745. $html .= '<nav class="btn btn-default btn-sm choose_dan_link" data-id="'.$value['id'].'" data-json=\''.json_encode(array("id"=>$value["id"],"tagname"=>$value["tagname"])).'\'>';
  746. $html .= $value['tagname'];
  747. $html .= '</nav>';
  748. }
  749. if( isset($_GPC['is_ajax']) )
  750. {
  751. echo json_encode( array('code' => 0, 'html' => $html) );
  752. die();
  753. }
  754. $this->labels = $labels;
  755. $this->display();
  756. }
  757. public function deletecomment()
  758. {
  759. $_GPC = I('request.');
  760. $id = intval($_GPC['id']);
  761. if (empty($id)) {
  762. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  763. }
  764. $items = M()->query('SELECT comment_id FROM ' . C('DB_PREFIX') .
  765. 'lionfish_comshop_order_comment WHERE comment_id in( ' . $id . ' ) ');
  766. if (empty($item)) {
  767. $item = array();
  768. }
  769. foreach ($items as $item) {
  770. M('lionfish_comshop_order_comment')->where( array('comment_id' => $item['comment_id']) )->delete();
  771. }
  772. show_json(1, array('url' => $_SERVER['HTTP_REFERER'] ));
  773. }
  774. public function addvircomment()
  775. {
  776. $_GPC = I('request.');
  777. if (IS_POST) {
  778. $data = $_GPC['data'];
  779. $jia_id = $_GPC['jiaid'];
  780. $goods_id = $_GPC['goods_id'];
  781. if( empty($goods_id) )
  782. {
  783. show_json(0, array('message' => '请选择评价商品!'));
  784. }
  785. if( empty($jia_id) )
  786. {
  787. show_json(0, array('message' => '请选择机器人!'));
  788. }
  789. $goods_info = M('lionfish_comshop_goods')->field('goodsname')->where( array('id' => $goods_id) )->find();
  790. $goods_image = isset($_GPC['goods_image']) && !empty($_GPC['goods_image']) ? $_GPC['goods_image'] : array();
  791. $time = empty($_GPC['time']) ? time() : $_GPC['time'];
  792. $jia_info = M('lionfish_comshop_jiauser')->where( array('id' => $jia_id ) )->find();
  793. $commen_data = array();
  794. $commen_data['order_id'] = 0;
  795. $commen_data['state'] = 1;
  796. $commen_data['type'] = 1;
  797. $commen_data['member_id'] = $jia_id;
  798. $commen_data['avatar'] = $jia_info['avatar'];
  799. $commen_data['user_name'] = $jia_info['username'];
  800. $commen_data['order_num_alias'] = 1;
  801. $commen_data['star'] = $data['star'];
  802. $commen_data['star3'] = $data['star3'];
  803. $commen_data['star2'] = $data['star2'];
  804. $commen_data['is_picture'] = !empty($goods_image) ? 1: 0;
  805. $commen_data['content'] = $data['content'];
  806. $commen_data['images'] = serialize(implode(',', $goods_image));
  807. $image = D('Home/Pingoods')->get_goods_images($goods_id);
  808. $seller_id = 1;
  809. if(!empty($image))
  810. {
  811. $commen_data['goods_image'] = $image['image'];
  812. }else{
  813. $commen_data['goods_image'] = '';
  814. }
  815. $commen_data['goods_id'] = $goods_id;
  816. $commen_data['goods_name'] = $goods_info['goodsname'];
  817. $commen_data['add_time'] = strtotime($time);
  818. M('lionfish_comshop_order_comment')->add($commen_data);
  819. show_json(1, array('url' => $_SERVER['HTTP_REFERER'] ));
  820. }
  821. $this->display();
  822. }
  823. public function change_cm()
  824. {
  825. $_GPC = I('request.');
  826. $id = intval($_GPC['id']);
  827. //ids
  828. if (empty($id)) {
  829. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  830. }
  831. if (empty($id)) {
  832. show_json(0, array('message' => '参数错误'));
  833. }
  834. $type = trim($_GPC['type']);
  835. $value = trim($_GPC['value']);
  836. if (!(in_array($type, array('is_take_fullreduction')))) {
  837. show_json(0, array('message' => '参数错误'));
  838. }
  839. $items = M('lionfish_comshop_goods')->field('id')->where( 'id in( ' . $id . ' )' )->select();
  840. foreach ($items as $item ) {
  841. //--
  842. if($type == 'is_take_fullreduction' && $value == 1)
  843. {
  844. $gd_common = M('lionfish_comshop_good_common')->field('supply_id')->where( array('goods_id' => $item['id'] ) )->find();
  845. if( !empty($gd_common['supply_id']) && $gd_common['supply_id'] > 0)
  846. {
  847. $supply_info = M('lionfish_comshop_supply')->field('type')->where( array('id' => $gd_common['supply_id'] ) )->find();
  848. if( !empty($supply_info) && $supply_info['type'] == 1 )
  849. {
  850. continue;
  851. }
  852. }
  853. }
  854. //---
  855. M('lionfish_comshop_good_common')->where( array('goods_id' => $item['id']) )->save( array($type => $value) );
  856. }
  857. show_json(1, array('url' => $_SERVER['HTTP_REFERER'] ));
  858. }
  859. public function commentstate()
  860. {
  861. $_GPC = I('request.');
  862. $id = intval($_GPC['id']);
  863. if (empty($id)) {
  864. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  865. }
  866. $items = M('lionfish_comshop_order_comment')->field('comment_id,member_id,is_send_point')->where( "comment_id in ({$id})")->select();
  867. if (empty($item)) {
  868. $item = array();
  869. }
  870. foreach ($items as $item) {
  871. M('lionfish_comshop_order_comment')->where( array('comment_id' => $item['comment_id']) )->save( array('state' => intval($_GPC['state'])) );
  872. if(intval($_GPC['state']) == 1 && $item['is_send_point'] == 0){
  873. //好评有礼送积分
  874. D('Seller/Order')->sendCommentGift($item['comment_id']);
  875. M('lionfish_comshop_order_comment')->where(array('comment_id'=>$item['comment_id'],'member_id'=>$item['member_id']))->save(array('is_send_point'=>1));
  876. }
  877. }
  878. show_json(1, array('url' => $_SERVER['HTTP_REFERER'] ));
  879. }
  880. /**
  881. * 一键设置商品时间
  882. */
  883. public function settime()
  884. {
  885. if (IS_POST) {
  886. $data = I('request.time', array());
  887. $param = array();
  888. $param['goods_same_starttime'] = strtotime(trim($data['start'])) ? strtotime(trim($data['start'])) : time();
  889. $param['goods_same_endtime'] = strtotime(trim($data['end'])) ? strtotime(trim($data['end'])) : time();
  890. $is_samedefault_now = I('request.is_samedefault_now');
  891. $is_sametihuo_time = I('request.is_sametihuo_time');
  892. $pick_up_type = I('request.pick_up_type');
  893. $pick_up_modify = I('request.pick_up_modify');
  894. if( $pick_up_type == 4 )
  895. {
  896. $pick_up_type = 0;
  897. }
  898. $param['is_samedefault_now'] = $is_samedefault_now;
  899. $param['is_sametihuo_time'] = $is_sametihuo_time;
  900. $param['pick_up_type'] = $pick_up_type;
  901. $param['pick_up_modify'] = $pick_up_modify;
  902. // lionfish_comshop_good_common begin_time end_time
  903. D('Seller/Config')->update($param);
  904. $param1 = array();
  905. $param1['begin_time'] = $param['goods_same_starttime'];
  906. $param1['end_time'] = $param['goods_same_endtime'];
  907. //--begin
  908. if (defined('ROLE') && ROLE == 'agenter' )
  909. {
  910. $supper_info = get_agent_logininfo();
  911. if( $is_samedefault_now == 2 )
  912. {
  913. $sql = " update ".C('DB_PREFIX')."lionfish_comshop_good_common set end_time = ".$param['goods_same_endtime'].", begin_time=".$param['goods_same_starttime']."
  914. where ".'goods_id in (select id from '.C('DB_PREFIX').'lionfish_comshop_goods where `grounding` =1 and type != "pin") and supply_id='.$supper_info['id'];
  915. M()->execute($sql);
  916. }
  917. if( $is_sametihuo_time == 2 )
  918. {
  919. $sql = " update ".C('DB_PREFIX')."lionfish_comshop_good_common set pick_up_type = '".$pick_up_type."', pick_up_modify='".$pick_up_modify."'"
  920. . " where goods_id in (select id from ".C('DB_PREFIX')."lionfish_comshop_goods where `grounding` =1 and type != 'pin' ) and supply_id=".$supper_info['id'];
  921. M()->execute($sql);
  922. }
  923. }else{
  924. //取出所有独立供应商
  925. $all_du_supply = M('lionfish_comshop_supply')->where( array('type' => 1) )->select();
  926. $all_du_sids = array();
  927. if( !empty($all_du_supply) )
  928. {
  929. foreach( $all_du_supply as $val )
  930. {
  931. $all_du_sids[] = $val['id'];
  932. }
  933. }
  934. if( $is_samedefault_now == 1 )
  935. {
  936. //仅平台
  937. $where = "";
  938. if( !empty($all_du_sids) )
  939. {
  940. $where = " and supply_id not in(".implode(',', $all_du_sids ).") ";
  941. }
  942. $sql = " update ".C('DB_PREFIX')."lionfish_comshop_good_common set end_time = ".$param['goods_same_endtime'].", begin_time=".$param['goods_same_starttime']."
  943. where ".'goods_id in (select id from '.C('DB_PREFIX').'lionfish_comshop_goods where `grounding` =1 and type != "pin" '.$where.' ) ';
  944. M()->execute($sql);
  945. }else if( $is_samedefault_now == 2 )
  946. {
  947. //所有商品除了拼团
  948. $sql = " update ".C('DB_PREFIX')."lionfish_comshop_good_common set end_time = ".$param['goods_same_endtime'].", begin_time=".$param['goods_same_starttime']."
  949. where ".'goods_id in (select id from '.C('DB_PREFIX').'lionfish_comshop_goods where `grounding` =1 and type != "pin") ';
  950. M()->execute($sql);
  951. }
  952. if( $is_sametihuo_time == 1 )
  953. {
  954. //仅平台
  955. $where = "";
  956. if( !empty($all_du_sids) )
  957. {
  958. $where = " and supply_id not in(".implode(',', $all_du_sids ).") ";
  959. }
  960. $sql = " update ".C('DB_PREFIX')."lionfish_comshop_good_common set pick_up_type = ".$pick_up_type.", pick_up_modify='".$pick_up_modify."'
  961. where ".'goods_id in (select id from '.C('DB_PREFIX').'lionfish_comshop_goods where `grounding` =1 and type != "pin" '.$where.' ) ';
  962. M()->execute($sql);
  963. }else if( $is_sametihuo_time == 2 )
  964. {
  965. $sql = " update ".C('DB_PREFIX')."lionfish_comshop_good_common set pick_up_type = ".$pick_up_type.", pick_up_modify='".$pick_up_modify."'
  966. where ".'goods_id in (select id from '.C('DB_PREFIX').'lionfish_comshop_goods where `grounding` =1 and type != "pin" ) ';
  967. M()->execute($sql);
  968. }
  969. /**
  970. $sql = 'UPDATE '.C('DB_PREFIX'). 'lionfish_comshop_good_pin SET begin_time = '.$param['goods_same_starttime'].
  971. ',end_time='.$param['goods_same_endtime'].' where goods_id in (select id from '.C('DB_PREFIX').'lionfish_comshop_goods where `grounding` =1) ';
  972. M()->execute($sql);
  973. **/
  974. }
  975. D('Seller/Operatelog')->addOperateLog('goods','修改商品设置--统一时间');
  976. //--end
  977. //M('lionfish_comshop_good_common')->where("1")->save($param1);
  978. show_json(1, array('url' => $_SERVER['HTTP_REFERER'] ));
  979. }
  980. $data = D('Seller/Config')->get_all_config();
  981. if(empty($data['goods_same_starttime']))
  982. {
  983. $data['goods_same_starttime'] = time();
  984. }
  985. if(empty($data['goods_same_endtime']))
  986. {
  987. $data['goods_same_endtime'] = time()+86400;
  988. }
  989. $this->data = $data;
  990. $this->display();
  991. }
  992. public function addgoods()
  993. {
  994. if (IS_POST) {
  995. $_GPC = I('request.');
  996. $type = isset($_GPC['type']) ? $_GPC['type'] : 'normal';
  997. if (!isset($_GPC['thumbs']) || empty($_GPC['thumbs'])) {
  998. show_json(0, array('message' => '商品图片必须上传', 'url' => $_SERVER['HTTP_REFERER']));
  999. die();
  1000. }
  1001. if (!empty($_GPC['has_mb_level_buy'])) {
  1002. foreach ($_GPC['discount'] as $val) {
  1003. if (preg_match("/^(([1-9]\d?)|100)$/", $val)) {
  1004. } else {
  1005. show_json(0, array('message' => '请按照提示设置独立会员等级折扣', 'url' => $_SERVER['HTTP_REFERER']));
  1006. die();
  1007. }
  1008. }
  1009. }
  1010. if ($_GPC['is_only_distribution'] == 1 && !empty($_GPC['supply_id'])) {
  1011. //供应商开启同城
  1012. $sup_isopen_localtown_delivery = D('Home/Front')->get_supply_config_by_name('isopen_localtown_delivery', $_GPC['supply_id']);
  1013. if (empty($sup_isopen_localtown_delivery)) {
  1014. $supply_name = M('lionfish_comshop_supply')->field('shopname,type')->where(array('id' => $_GPC['supply_id']))->find();
  1015. if ($supply_name["type"] == 1) {
  1016. show_json(0, array('message' => '独立供应商(' . $supply_name["shopname"] . ')没有开启同城配送,此商品无法开启同城配送', 'url' => $_SERVER['HTTP_REFERER']));
  1017. die();
  1018. }
  1019. }
  1020. }
  1021. $supply_id = $_GPC['supply_id'];
  1022. if (defined('ROLE') && ROLE == 'agenter') {
  1023. $supper_info = get_agent_logininfo();
  1024. $supply_id = $supper_info['id'];
  1025. }
  1026. if ($_GPC['is_only_hexiao'] == 1) {
  1027. if (!empty($supply_id)) {
  1028. $salesroom_count = M('lionfish_comshop_salesroom')->where(array('supply_id' => $supply_id, 'state' => 1))->count();
  1029. if ($salesroom_count == 0) {
  1030. $supply_name = M('lionfish_comshop_supply')->field('shopname,type')->where(array('id' => $supply_id))->find();
  1031. if ($supply_name["type"] == 1) {
  1032. show_json(0, array('message' => '独立供应商(' . $supply_name["shopname"] . ')没有创建门店信息,此商品无法开启到店核销', 'url' => $_SERVER['HTTP_REFERER']));
  1033. die();
  1034. }
  1035. }
  1036. }
  1037. if ($_GPC['grounding'] == 1) {//上架商品
  1038. if ($_GPC['hx_expire_type'] == 1) {//指定过期时间
  1039. $hx_expire_end_time = $_GPC['hx_expire_end_time'];
  1040. if (strtotime($hx_expire_end_time) < time()) {
  1041. show_json(0, array('message' => '核销过期时间小于当前时间,商品不能上架', 'url' => $_SERVER['HTTP_REFERER']));
  1042. die();
  1043. }
  1044. }
  1045. }
  1046. if ($_GPC['hx_expire_type'] == 1) {//指定过期时间
  1047. if ($_GPC['hx_auto_off'] == 1) {//设置自动下架时间
  1048. if (empty($_GPC['hx_auto_off_time']) || !is_numeric($_GPC['hx_auto_off_time']) || floatval($_GPC['hx_auto_off_time']) <= 0) {
  1049. show_json(0, array('message' => '提前自动下架商品时间不能为空且必须为大于0数字', 'url' => $_SERVER['HTTP_REFERER']));
  1050. die();
  1051. }
  1052. }
  1053. }
  1054. }
  1055. //礼品卡
  1056. if (isset($_GET['goods_type']) && $_GET['goods_type'] == 'virtualcard')
  1057. {
  1058. $type = 'virtualcard';
  1059. $virtual_code_id = I('post.virtual_code_id');
  1060. if( !isset($virtual_code_id) || $virtual_code_id <= 0 )
  1061. {
  1062. show_json(0, array('message' => '礼品卡商品必须关联兑换码' ,'url' => $_SERVER['HTTP_REFERER']) );
  1063. die();
  1064. }
  1065. }
  1066. //预售时间判断
  1067. if( isset($_GET['goods_type']) && $_GET['goods_type'] == 'presale' )
  1068. {
  1069. $type = 'presale';
  1070. //预售时间限制判断
  1071. $time = I('post.time');
  1072. $post_begin_time = strtotime( $time['start'] );
  1073. $post_end_time = strtotime( $time['end'] );
  1074. $presale_ding_time = I('post.presale_ding_time');//定金支付时间
  1075. $presale_ding_time_start = strtotime( $presale_ding_time['start'] ); //开始
  1076. $presale_ding_time_end = strtotime( $presale_ding_time['end'] );//结束
  1077. if($presale_ding_time_start < $post_begin_time )
  1078. {
  1079. show_json(0, array('message' => '预售定金支付开始时间不能小于团购开始时间' ,'url' => $_SERVER['HTTP_REFERER']) );
  1080. die();
  1081. }
  1082. if($presale_ding_time_end > $post_end_time )
  1083. {
  1084. show_json(0, array('message' => '预售定金支付结束时间不能大于团购结束时间' ,'url' => $_SERVER['HTTP_REFERER']) );
  1085. die();
  1086. }
  1087. $presale_sendorder_type = I('post.presale_sendorder_type');
  1088. if($presale_sendorder_type == 1)
  1089. {
  1090. $presale_sendorder_afterday = I('post.presale_sendorder_afterday');
  1091. if( $presale_sendorder_afterday < 1 )
  1092. {
  1093. show_json(0, array('message' => '预售购买后几日发货必须是大于0的整数' ,'url' => $_SERVER['HTTP_REFERER']) );
  1094. die();
  1095. }
  1096. }else if( $presale_sendorder_type == 0 )
  1097. {
  1098. //预计发货时间 必须大于 定金尾款付款时间
  1099. $presale_sendorder_datetime = I('post.presale_sendorder_datetime');
  1100. $presale_sendorder_datetime = strtotime($presale_sendorder_datetime.' 00:00:00');
  1101. if( $presale_sendorder_datetime < $presale_ding_time_start )
  1102. {
  1103. show_json(0, array('message' => '固定发货日期必须大于定金支付开始时间' ,'url' => $_SERVER['HTTP_REFERER']) );
  1104. die();
  1105. }
  1106. }
  1107. }
  1108. //判断预售价格是否合理设置,不是bug价格
  1109. $this->checkPresaleAddGoods();
  1110. D('Seller/Goods')->addgoods($type);
  1111. $http_refer = S('HTTP_REFERER');
  1112. $http_refer = empty($http_refer) ? $_SERVER['HTTP_REFERER'] : $http_refer;
  1113. sellerLog('添加新增商品', 3);
  1114. show_json(1, array('message' => '添加商品成功!','url' => $http_refer ));
  1115. }
  1116. S('HTTP_REFERER', $_SERVER['HTTP_REFERER']);
  1117. $category = D('Seller/GoodsCategory')->getFullCategory(true, true);
  1118. $this->category = $category;
  1119. $spec_list = D('Seller/Spec')->get_all_spec();
  1120. $this->spec_list = $spec_list;
  1121. $dispatch_data = M('lionfish_comshop_shipping')->where( array('enabled' => 1,'isdefault' =>1) )->order('sort_order desc')->select();
  1122. $this->dispatch_data = $dispatch_data;
  1123. $set = D('Seller/Config')->get_all_config();
  1124. $this->set = $set;
  1125. $commission_level = array();
  1126. $config_data = $set;
  1127. $this->config_data = $config_data;
  1128. $default = array('id' => 'default', 'levelname' => empty($config_data['commission_levelname']) ? '默认等级' : $config_data['commission_levelname'], 'commission1' => $config_data['commission1'], 'commission2' => $config_data['commission2'], 'commission3' => $config_data['commission3']);
  1129. $others = M('lionfish_comshop_commission_level')->order('commission1 asc')->select();
  1130. $commission_level = array_merge(array($default), $others);
  1131. $communityhead_commission = $config_data['default_comunity_money'];
  1132. $this->communityhead_commission = $communityhead_commission;
  1133. //$level['key']
  1134. foreach($commission_level as $key => $val)
  1135. {
  1136. $val['key'] = $val['id'];
  1137. $commission_level[$key] = $val;
  1138. }
  1139. $this->commission_level = $commission_level;
  1140. $shopset_level = empty($set['commiss_level']) ? 0: $set['commiss_level'];
  1141. $this->shopset_level = $shopset_level;
  1142. //赠送积分开关
  1143. $open_buy_send_score = empty($set['open_buy_send_score']) ? 0: $set['open_buy_send_score'];
  1144. $this->open_buy_send_score = $open_buy_send_score;
  1145. $index_sort_method = empty($set['index_sort_method']) ? 0: $set['index_sort_method'];
  1146. $this->index_sort_method = $index_sort_method;
  1147. $item = array();
  1148. $item['begin_time'] = time();
  1149. $item['community_head_commission'] = $communityhead_commission;
  1150. $item['end_time'] = time() + 86400;
  1151. $item['hexiao_effect_begin_time'] = time();
  1152. $item['hexiao_effect_end_time'] = time() + 86400;
  1153. //预售begin
  1154. if( isset($_GET['goods_type']) && $_GET['goods_type'] == 'presale' )
  1155. {
  1156. $item['presale_ding_time_start'] = time();
  1157. $item['presale_ding_time_end'] = time() + 86400;
  1158. }
  1159. //预售end
  1160. $delivery_type_express = $config_data['delivery_type_express'];
  1161. if( empty($delivery_type_express) )
  1162. {
  1163. $delivery_type_express = 2;
  1164. }
  1165. $this->delivery_type_express = $delivery_type_express;
  1166. $is_open_fullreduction = $config_data['is_open_fullreduction'];
  1167. $this->is_open_fullreduction = $is_open_fullreduction;
  1168. $community_head_level = M('lionfish_comshop_community_head_level')->order('id asc')->select();
  1169. $head_commission_levelname = $config_data['head_commission_levelname'];
  1170. $default_comunity_money = $config_data['default_comunity_money'];
  1171. $list_default = array(
  1172. array('id' => '0','level'=>0,'levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $default_comunity_money, )
  1173. );
  1174. $community_head_level = array_merge($list_default, $community_head_level);
  1175. if( !empty($community_head_level) )
  1176. {
  1177. foreach( $community_head_level as $head_level)
  1178. {
  1179. $item['head_level'.$head_level['id']] = $head_level['commission'];
  1180. }
  1181. }
  1182. $this->item = $item;
  1183. $this->community_head_level = $community_head_level;
  1184. $community_money_type = $config_data['community_money_type'];
  1185. $this->community_money_type = $community_money_type;
  1186. $mb_level = M('lionfish_comshop_member_level')->count();
  1187. $this->mb_level = $mb_level;
  1188. $is_open_only_express = $config_data['is_open_only_express'];
  1189. $this->is_open_only_express = $is_open_only_express;
  1190. $is_open_goods_relative_goods = $config_data['is_open_goods_relative_goods'];
  1191. $this->is_open_goods_relative_goods = $is_open_goods_relative_goods;
  1192. //供应商权限begin
  1193. $is_index = true;
  1194. $is_top = true;
  1195. $is_updown = true;
  1196. $is_fullreduce = true;
  1197. $is_vir_count = true;
  1198. $is_newbuy = true;
  1199. $is_goodsspike = true;
  1200. $supply_can_goods_sendscore = true;
  1201. $supply_can_distribution_sale = true ;
  1202. //核销
  1203. $sales_supply_id = 0;
  1204. if (defined('ROLE') && ROLE == 'agenter' )
  1205. {
  1206. $supply_can_goods_sendscore = empty($config_data['supply_can_goods_sendscore']) ? 0: $config_data['supply_can_goods_sendscore'];
  1207. $supply_can_distribution_sale = empty($config_data['supply_can_distribution_sale']) ? 0: $config_data['supply_can_distribution_sale'];
  1208. $is_fullreduce = false;
  1209. if( isset($config_data['supply_can_goods_isindex']) && $config_data['supply_can_goods_isindex'] == 2 )
  1210. {
  1211. $is_index = false;
  1212. }
  1213. if( isset($config_data['supply_can_goods_istop']) && $config_data['supply_can_goods_istop'] == 2 )
  1214. {
  1215. $is_top = false;
  1216. }
  1217. if( isset($config_data['supply_can_goods_updown']) && $config_data['supply_can_goods_updown'] == 2 )
  1218. {
  1219. $is_updown = false;
  1220. }
  1221. if( isset($config_data['supply_can_vir_count']) && $config_data['supply_can_vir_count'] == 2 )
  1222. {
  1223. $is_vir_count = false;
  1224. }
  1225. if( isset($config_data['supply_can_goods_newbuy']) && $config_data['supply_can_goods_newbuy'] == 2 )
  1226. {
  1227. $is_newbuy = false;
  1228. }
  1229. if( isset($config_data['supply_can_goods_spike']) && $config_data['supply_can_goods_spike'] == 2 )
  1230. {
  1231. $is_goodsspike = false;
  1232. }
  1233. $sales_supply_id = $supper_info = get_agent_logininfo();
  1234. $sales_supply_id = $supper_info['id'];
  1235. }
  1236. $salesroom_count = M('lionfish_comshop_salesroom')->where(array('supply_id' => $sales_supply_id,'state'=>1))->count();
  1237. if($salesroom_count > 0){
  1238. $this->is_exist_salesroom = 1;
  1239. }
  1240. $is_open_vipcard_buy = $config_data['is_open_vipcard_buy'];
  1241. //供应商权限end
  1242. $this->is_index = $is_index;
  1243. $this->supply_can_goods_sendscore = $supply_can_goods_sendscore;
  1244. $this->supply_can_distribution_sale = $supply_can_distribution_sale;
  1245. $this->is_top = $is_top;
  1246. $this->is_updown = $is_updown;
  1247. $this->is_fullreduce = $is_fullreduce;
  1248. $this->is_vir_count = $is_vir_count;
  1249. $this->is_newbuy = $is_newbuy;
  1250. $this->is_goodsspike = $is_goodsspike;
  1251. $this->is_open_vipcard_buy = $is_open_vipcard_buy;
  1252. $seckill_is_open = $config_data['seckill_is_open'];
  1253. $this->seckill_is_open = $seckill_is_open;
  1254. // $is_head_takegoods
  1255. $is_head_takegoods = isset($config_data['is_head_takegoods']) && $config_data['is_head_takegoods'] == 1 ? 1 : 0;
  1256. $this->is_head_takegoods = $is_head_takegoods;
  1257. //判断是否兑换卡 begin
  1258. if( isset($_GET['goods_type']) && $_GET['goods_type'] == 'virtualcard' )
  1259. {
  1260. //商品选中的兑换编组
  1261. $goods_virtualcode_id = 0;
  1262. $this->goods_virtualcode_id = $goods_virtualcode_id;
  1263. //可用的兑换编组列表
  1264. $virtualcard_code_list = D('Seller/VirtualCard')->getCanUseVirtualcardCodes( );
  1265. $this->virtualcard_code_list = $virtualcard_code_list;
  1266. }
  1267. //end
  1268. $isopen_localtown_delivery = isset($config_data['isopen_localtown_delivery']) && $config_data['isopen_localtown_delivery'] == 1 ? 1 : 0;
  1269. $this->isopen_localtown_delivery = $isopen_localtown_delivery;
  1270. $supply_is_open_localtown_distribution = isset($config_data['supply_is_open_localtown_distribution']) && $config_data['supply_is_open_localtown_distribution'] == 1 ? 1 : 0;
  1271. $this->supply_is_open_localtown_distribution = $supply_is_open_localtown_distribution;
  1272. $this->delivery_type_express = isset($config_data['delivery_type_express']) ? $config_data['delivery_type_express'] : 0;
  1273. //$is_default_levellimit_buy = isset($config_data['is_default_levellimit_buy']) && $config_data['is_default_levellimit_buy'] == 1 ? 1 : 0;
  1274. //$this->is_default_levellimit_buy = $is_default_levellimit_buy;
  1275. //$is_default_vipmember_buy = isset($config_data['is_default_vipmember_buy']) && $config_data['is_default_vipmember_buy'] == 1 ? 1 : 0;
  1276. //$this->is_default_vipmember_buy = $is_default_vipmember_buy;
  1277. //获取会员等级列表
  1278. $member_level_ist = M('lionfish_comshop_member_level')->order('id asc')->select();
  1279. $this->member_level_ist = $member_level_ist;
  1280. $this->display();
  1281. }
  1282. public function checkPresaleAddGoods()
  1283. {
  1284. if( isset($_POST['presale_type']) )
  1285. {
  1286. $presale_type = I('post.presale_type', 0);//预售方式 0 定金
  1287. $presale_ding_money = I('post.presale_ding_money', 0);//定金金额,判断定金金额不能大于商品价格
  1288. $presale_deduction_money = I('post.presale_deduction_money');//定金可抵扣金额
  1289. if( $presale_type == 0)
  1290. {
  1291. $goods_price = I('post.price', 0);
  1292. $hasoption = I('post.hasoption');
  1293. if( intval($hasoption) == 1 )
  1294. {
  1295. //取规格最低价格
  1296. $option_ids_arr = I('post.option_ids');
  1297. foreach($option_ids_arr as $val)
  1298. {
  1299. $productprice = I('post.option_productprice_' . $val);
  1300. if( $goods_price > $productprice )
  1301. {
  1302. $goods_price = $productprice;
  1303. }
  1304. }
  1305. }
  1306. if( $presale_ding_money > $goods_price )
  1307. {
  1308. show_json(0 , ['message' => '预售方式为定金,定金金额不能大于商品单价' ] );
  1309. }
  1310. if( $presale_deduction_money > $goods_price )
  1311. {
  1312. show_json(0 , ['message' => '预售方式为定金,定金膨胀金不能大于商品单价' ] );
  1313. }
  1314. if($presale_deduction_money != 0){
  1315. if( $presale_deduction_money < $presale_ding_money )
  1316. {
  1317. show_json(0 , ['message' => '定金膨胀金不能小于定金金额' ] );
  1318. }
  1319. }
  1320. //付费价格
  1321. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  1322. $is_take_vipcard = I('post.is_take_vipcard', 0);
  1323. $card_price =I ('post.card_price'); //付费会员价
  1324. if( !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 && $is_take_vipcard == 1){
  1325. if( $presale_ding_money > $card_price )
  1326. {
  1327. show_json(0 , ['message' => '预售方式为定金,定金金额不能大于付费会员价' ] );
  1328. }
  1329. if( $presale_deduction_money > $card_price )
  1330. {
  1331. show_json(0 , ['message' => '预售方式为定金,定金膨胀金不能大于付费会员价' ] );
  1332. }
  1333. }
  1334. }
  1335. }
  1336. }
  1337. public function category_enabled()
  1338. {
  1339. $id = I('request.id');
  1340. if (empty($id)) {
  1341. $ids = I('request.ids');
  1342. $id = (is_array($ids) ? implode(',', $ids) : 0);
  1343. }
  1344. $items = M('lionfish_comshop_goods_category')->field('id,name')->where( 'id in( ' . $id . ' )' )->select();
  1345. $enabled = I('request.enabled');
  1346. foreach ($items as $item) {
  1347. M('lionfish_comshop_goods_category')->where( array('id' => $item['id']) )->save( array('is_show' => intval($enabled)) );
  1348. D('Seller/Operatelog')->addOperateLog('goods','修改分类首页显示--'.$item['name']);
  1349. }
  1350. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1351. }
  1352. public function category_typeenabled()
  1353. {
  1354. $_GPC = I('request.');
  1355. $id = intval($_GPC['id']);
  1356. if (empty($id)) {
  1357. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  1358. }
  1359. $items = M('lionfish_comshop_goods_category')->field('id,name')->where( 'id in( ' . $id . ' )' )->select();
  1360. foreach ($items as $item) {
  1361. M('lionfish_comshop_goods_category')->where( array('id' => $item['id']) )->save( array('is_type_show' => intval($_GPC['enabled'])) );
  1362. D('Seller/Operatelog')->addOperateLog('goods','修改分类独立分类页显示--'.$item['name']);
  1363. }
  1364. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1365. }
  1366. public function category_expressenabled()
  1367. {
  1368. $_GPC = I('request.');
  1369. $id = intval($_GPC['id']);
  1370. if (empty($id)) {
  1371. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  1372. }
  1373. $items = M('lionfish_comshop_goods_category')->field('id,name')->where( 'id in( ' . $id . ' )' )->select();
  1374. foreach ($items as $item) {
  1375. M('lionfish_comshop_goods_category')->where( array('id' => $item['id']) )->save( array('is_express_show' => intval($_GPC['enabled'])) );
  1376. D('Seller/Operatelog')->addOperateLog('goods','修改分类仅快递商品页显示--'.$item['name']);
  1377. }
  1378. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1379. }
  1380. public function mult_tpl()
  1381. {
  1382. $tpl = I('get.tpl','','trim');
  1383. $spec_str = I('post.spec_str', '', 'trim');
  1384. $options_name = I('post.options_name','','trim');
  1385. $cur_cate_id = I('post.cur_cate_id',0);
  1386. if ($tpl == 'spec') {
  1387. $spec = array('id' => random(32), 'title' => $options_name);
  1388. $need_items = array();
  1389. $spec_list = explode('@', $spec_str);
  1390. foreach($spec_list as $itemname)
  1391. {
  1392. $tmp_item = array('id' =>random(32),'title' => $itemname, 'show' => 1);
  1393. $need_items[] = $tmp_item;
  1394. }
  1395. $spec['items'] = $need_items;
  1396. $this->spec = $spec;
  1397. $this->tmp_item = $tmp_item;
  1398. $this->tpl = $tpl;
  1399. $this->spec_str = $spec_str;
  1400. $this->options_name = $options_name;
  1401. $this->cur_cate_id = $cur_cate_id;
  1402. $this->display('Goods/tpl/spec');
  1403. }
  1404. }
  1405. public function ajax_batchtime_pintuan()
  1406. {
  1407. $begin_time = I('request.begin_time');
  1408. $goodsids = I('request.goodsids');
  1409. $end_time = I('request.end_time');
  1410. foreach ($goodsids as $goods_id ) {
  1411. if($begin_time && $end_time){
  1412. $param = array();
  1413. $param['begin_time'] = strtotime($begin_time);
  1414. $param['end_time'] = strtotime($end_time);
  1415. M('lionfish_comshop_good_common')->where( array('goods_id' => $goods_id) )->save( $param );
  1416. M('lionfish_comshop_good_pin')->where( array('goods_id' => $goods_id) )->save( $param );
  1417. }
  1418. }
  1419. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1420. }
  1421. public function ajax_batchtime()
  1422. {
  1423. $begin_time = I('request.begin_time');
  1424. $goodsids = I('request.goodsids');
  1425. $end_time = I('request.end_time');
  1426. foreach ($goodsids as $goods_id ) {
  1427. if($begin_time && $end_time){
  1428. $param = array();
  1429. $param['begin_time'] = strtotime($begin_time);
  1430. $param['end_time'] = strtotime($end_time);
  1431. M('lionfish_comshop_good_common')->where( array('goods_id' => $goods_id) )->save( $param );
  1432. }
  1433. }
  1434. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1435. }
  1436. public function tpl()
  1437. {
  1438. $tpl = I('get.tpl');
  1439. $title = I('get.title','');
  1440. if ($tpl == 'spec') {
  1441. $spec = array('id' => random(32), 'title' => $title);
  1442. $this->title = $title;
  1443. $this->spec = $spec;
  1444. $this->display('Goods/tpl/spec');
  1445. }else if($tpl == 'specitem')
  1446. {
  1447. $specid = I('get.specid');
  1448. $spec = array('id' => $specid);
  1449. $specitem = array('id' => random(32), 'title' => $title, 'show' => 1);
  1450. $this->specid = $specid;
  1451. $this->spec = $spec;
  1452. $this->specitem = $specitem;
  1453. $this->display('Goods/tpl/spec_item');
  1454. }
  1455. }
  1456. public function config()
  1457. {
  1458. if (IS_POST) {
  1459. $data = I('post.parameter', array());
  1460. $data['goods_stock_notice'] = trim($data['goods_stock_notice']);
  1461. $data['instructions'] = trim($data['instructions']);
  1462. $data['is_show_buy_record'] = trim($data['is_show_buy_record']);
  1463. $data['is_show_list_timer'] = intval($data['is_show_list_timer']);
  1464. $data['is_show_list_count'] = intval($data['is_show_list_count']);
  1465. $data['is_show_comment_list'] = intval($data['is_show_comment_list']);
  1466. $data['is_show_new_buy'] = intval($data['is_show_new_buy']);
  1467. $data['is_new_buy_limit'] = intval($data['is_new_buy_limit']);
  1468. $new_buy_limit_num = !empty(intval($data['new_buy_limit_num'])) ? $data['new_buy_limit_num'] : 1;
  1469. $data['new_buy_limit_num'] = intval($new_buy_limit_num);
  1470. $data['is_show_ziti_time'] = intval($data['is_show_ziti_time']);
  1471. $data['is_show_spike_buy'] = intval($data['is_show_spike_buy']);
  1472. $data['goodsdetails_addcart_bg_color'] = $data['goodsdetails_addcart_bg_color'];
  1473. $data['goodsdetails_buy_bg_color'] = $data['goodsdetails_buy_bg_color'];
  1474. $data['is_show_guess_like'] = $data['is_show_guess_like'];
  1475. $data['show_goods_guess_like'] = $data['show_goods_guess_like'];
  1476. if(!empty($data['num_guess_like'])){
  1477. $data['num_guess_like'] = $data['num_guess_like'];
  1478. }else{
  1479. $data['num_guess_like'] = 8;
  1480. }
  1481. $data['isopen_community_group_share'] = intval($data['isopen_community_group_share']);
  1482. $data['group_share_avatar'] = save_media($data['group_share_avatar']);
  1483. $data['group_share_title'] = trim($data['group_share_title']);
  1484. $data['group_share_desc'] = trim($data['group_share_desc']);
  1485. $data['is_close_details_time'] = intval($data['is_close_details_time']);
  1486. $data['videolist_nav_title'] = trim($data['videolist_nav_title']);
  1487. $data['videolist_share_title'] = trim($data['videolist_share_title']);
  1488. $data['videolist_share_poster'] = save_media($data['videolist_share_poster']);
  1489. $data['goods_details_title_bg'] = save_media($data['goods_details_title_bg']);
  1490. D('Seller/Config')->update($data);
  1491. D('Seller/Operatelog')->addOperateLog('goods','修改商品设置--基本设置');
  1492. //旧的的域名
  1493. $present_realm_name = I('post.present_realm_name');
  1494. //修改商品详情域名
  1495. $new_realm_name = I('post.new_realm_name');
  1496. if(!empty($new_realm_name)){
  1497. $str="/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/";
  1498. if (!preg_match($str,$present_realm_name)){
  1499. show_json(0, array('message' => '旧的域名格式不正确'));
  1500. }
  1501. if (!preg_match($str,$new_realm_name)){
  1502. show_json(0, array('message' => '新的域名格式不正确'));
  1503. }
  1504. $sql = " update ". C('DB_PREFIX') ."lionfish_comshop_good_common set content = replace( content , '".$present_realm_name."' , '".$new_realm_name."' ) ";
  1505. $list = M()->execute($sql);
  1506. if(empty($list)){
  1507. show_json(0, array('message' => '商品详情中不存在该域名,或者不能填写相同的域名,请检查后重新填写'));
  1508. }else{
  1509. D('Seller/Operatelog')->addOperateLog('goods','替换商品详情域名--原域名:'.$present_realm_name.'新域名:'.$new_realm_name );
  1510. }
  1511. }
  1512. show_json(1, array('url'=> U('goods/config')));
  1513. }
  1514. $data = D('Seller/Config')->get_all_config();
  1515. $this->data = $data;
  1516. $this->display();
  1517. }
  1518. function addspec()
  1519. {
  1520. global $_W;
  1521. global $_GPC;
  1522. if (IS_POST) {
  1523. $data = I('post.data');
  1524. D('Seller/Spec')->update($data);
  1525. show_json(1, array('url' => U('goods/goodsspec')));
  1526. }
  1527. $this->display();
  1528. }
  1529. public function editspec()
  1530. {
  1531. $id = I('request.id');
  1532. if (!empty($id)) {
  1533. $item = M('lionfish_comshop_spec')->where( array('id' => $id) )->find();
  1534. if (json_decode($item['value'], true)) {
  1535. $labelname = json_decode($item['value'], true);
  1536. }
  1537. else {
  1538. $labelname = unserialize($item['value']);
  1539. }
  1540. }
  1541. if (IS_POST) {
  1542. $data = I('post.data');
  1543. D('Seller/Spec')->update($data);
  1544. show_json(1, array('url' => U('goods/goodsspec')));
  1545. }
  1546. $this->item = $item;
  1547. $this->labelname = $labelname;
  1548. $this->display('Goods/addspec');
  1549. }
  1550. public function deletespec()
  1551. {
  1552. $id = I('get.id');
  1553. if (empty($id)) {
  1554. $ids = I('post.ids');
  1555. $id = (is_array($ids) ? implode(',', $ids) : 0);
  1556. }
  1557. $items = M('lionfish_comshop_spec')->field('id,name')->where( array('id' => array('in', $id)) )->select();
  1558. if (empty($item)) {
  1559. $item = array();
  1560. }
  1561. foreach ($items as $item) {
  1562. M('lionfish_comshop_spec')->where( array('id' => $item['id']) )->delete();
  1563. D('Seller/Operatelog')->addOperateLog('goods','删除商品规格--'.$item['name']);
  1564. }
  1565. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1566. }
  1567. public function addcategory()
  1568. {
  1569. $data = array();
  1570. $pid = I('get.pid', 0);
  1571. $id = I('get.id', 0);
  1572. if (IS_POST) {
  1573. $data = I('post.data');
  1574. if(!isset($data['sort_order'])){
  1575. show_json(0, array('message' => '分类排序必须填写'));
  1576. }
  1577. if(!is_numeric($data['sort_order'])){
  1578. show_json(0, array('message' => '分类排序必须在1-999之间的整数'));
  1579. }
  1580. if(floor($data['sort_order']) != $data['sort_order']){
  1581. show_json(0, array('message' => '分类排序必须在1-999之间的整数'));
  1582. }
  1583. if($data['sort_order'] < 1 || $data['sort_order'] > 999){
  1584. show_json(0, array('message' => '分类排序必须在1-999之间的整数'));
  1585. }
  1586. $where = array();
  1587. $where['sort_order'] = $data['sort_order'];
  1588. $where['cate_type'] = 'normal';
  1589. $cate_info = M('lionfish_comshop_goods_category')->where($where)->find();
  1590. if(!empty($cate_info) && (($id == 0) || ($id > 0 && $id != $cate_info['id']))){
  1591. show_json(0, array('message' => '分类排序已存在,请重新填写'));
  1592. }
  1593. D('Seller/GoodsCategory')->update($data);
  1594. show_json(1, array('url' => U('goods/goodscategory')));
  1595. }
  1596. if($id >0 )
  1597. {
  1598. $data = M('lionfish_comshop_goods_category')->where( array('id' => $id) )->find();
  1599. $this->data = $data;
  1600. }
  1601. $this->pid = $pid;
  1602. $this->id = $id;
  1603. $this->display();
  1604. }
  1605. /**
  1606. * 更新商品分类排序
  1607. */
  1608. public function update_catesort(){
  1609. $cate_id = I('post.cate_id', 0);
  1610. $sort_order = I('post.sort_order', 0);
  1611. if(!is_numeric($sort_order)){
  1612. show_json(0, array('message' => '分类排序必须为数字'));
  1613. }
  1614. if($sort_order < 1 || $sort_order > 999){
  1615. show_json(0, array('message' => '分类排序必须在1-999之间'));
  1616. }
  1617. if($cate_id > 0){
  1618. $where = array();
  1619. $where['sort_order'] = $sort_order;
  1620. $where['cate_type'] = 'normal';
  1621. $where['id'] = array('neq',$cate_id);
  1622. $cate_info = M('lionfish_comshop_goods_category')->where($where)->find();
  1623. if(!empty($cate_info)){
  1624. show_json(0, array('message' => '分类排序已存在,请重新填写'));
  1625. }
  1626. M('lionfish_comshop_goods_category')->where( array('id' => $cate_id) )->save(array('sort_order'=>$sort_order));
  1627. D('Seller/Operatelog')->addOperateLog('goods','修改商品分类排序--'.$item['name']);
  1628. show_json(1, array('url' => U('goods/goodscategory')));
  1629. }else{
  1630. show_json(0, array('message' => '分类信息错误'));
  1631. }
  1632. }
  1633. public function category_delete()
  1634. {
  1635. $id = I('get.id');
  1636. $item = M('lionfish_comshop_goods_category')->field('id, name, pid')->where( array('id' => $id) )->find();
  1637. M('lionfish_comshop_goods_category')->where( "id={$id} or pid={$id}" )->delete();
  1638. D('Seller/Operatelog')->addOperateLog('goods','删除商品分类--'.$item['name']);
  1639. //m('shop')->getCategory(true);
  1640. show_json(1, array('url' => U('goods/goodscategory')));
  1641. }
  1642. public function goodscategory()
  1643. {
  1644. if (IS_POST) {
  1645. $datas = I('post.datas');
  1646. if (!empty($datas)) {
  1647. D('Seller/GoodsCategory')->goodscategory_modify($datas);
  1648. show_json(1 , array('url' => U('goods/goodscategory') ));
  1649. }
  1650. $parameter = I('post.parameter');
  1651. if (!empty($parameter)) {
  1652. $data = ((is_array($parameter) ? $parameter : array()));
  1653. D('Seller/Config')->update($data);
  1654. show_json(1);
  1655. }
  1656. }
  1657. $children = array();
  1658. $category = M('lionfish_comshop_goods_category')->where(' cate_type="normal" ')->order('pid ASC, sort_order DESC')->select();
  1659. foreach ($category as $index => $row) {
  1660. if (!empty($row['pid'])) {
  1661. $children[$row['pid']][] = $row;
  1662. unset($category[$index]);
  1663. }
  1664. }
  1665. $data = D('Seller/Config')->get_all_config();
  1666. $this->data = $data;
  1667. $this->children = $children;
  1668. $this->category = $category;
  1669. $this->display();
  1670. }
  1671. public function goodsspec()
  1672. {
  1673. $condition = ' 1=1 and spec_type="normal" ';
  1674. $pindex = I('get.page',1);
  1675. $psize = 20;
  1676. $enabled = I('get.enabled');
  1677. if ($enabled != '') {
  1678. $condition .= ' and state=' . intval($enabled);
  1679. }
  1680. $keyword = I('get.keyword','','trim');
  1681. if (!empty($keyword)) {
  1682. $condition .= ' and name like "%'.$keyword.'%" ';
  1683. }
  1684. $offset = ($pindex - 1) * $psize;
  1685. $label = M('lionfish_comshop_spec')->field('id,name,value')->where($condition)->order(' id desc ')->limit($offset, $psize)->select();
  1686. $total = M('lionfish_comshop_spec')->where( $condition )->count();
  1687. $cur_url = U('goods/goodsspec', array('enabled' => $enabled,'keyword' => $keyword));
  1688. $pager = pagination2($total, $pindex, $psize);
  1689. foreach( $label as &$val )
  1690. {
  1691. $val['value'] = unserialize($val['value']);
  1692. $val['value_str'] = !empty($val['value']) ? implode(',', $val['value']) : '';
  1693. }
  1694. $this->keyword = $keyword;
  1695. $this->label = $label;
  1696. $this->total = $total;
  1697. $this->pager = $pager;
  1698. $this->display();
  1699. }
  1700. /**
  1701. 搜索全部商品,可添加虚拟评价
  1702. **/
  1703. public function goods_search_all()
  1704. {
  1705. $goods_name = I('post.goods_name','');
  1706. $where = " status=1 and quantity>0 and store_id = " . $this->sellerid;
  1707. if(!empty($goods_name))
  1708. {
  1709. $where .= " and name like '%".$goods_name."%' ";
  1710. }
  1711. $goods_list = M('goods')->where($where)->limit(20)->select();
  1712. $this->goods_list = $goods_list;
  1713. $result = array();
  1714. $result['html'] = $this->fetch('Goods:goods_list_fetch');
  1715. echo json_encode($result);
  1716. die();
  1717. }
  1718. function toggle_statues_show() {
  1719. $goods_id = I('post.gid',0);
  1720. $goods_info =M('Goods')->where( array('goods_id' => $goods_id) )->find();
  1721. $status = $goods_info['status'] == 1 ? 0: 1;
  1722. $res = M('Goods')->where( array('goods_id' => $goods_id) )->save( array('status' => $status) );
  1723. echo json_encode( array('code' => 1) );
  1724. die();
  1725. }
  1726. /**
  1727. 搜索可报名的商品
  1728. **/
  1729. public function goods_search_voucher()
  1730. {
  1731. $goods_name = I('post.goods_name','');
  1732. $where = " (type='normal' or type ='pintuan') and status=1 and quantity>0 and store_id = " . $this->sellerid;
  1733. if(!empty($goods_name))
  1734. {
  1735. $where .= " and ( name like '%".$goods_name."%' or goods_id like '%".$goods_name."%') ";
  1736. }
  1737. $goods_list = M('goods')->where($where)->limit(10)->select();
  1738. $this->goods_list = $goods_list;
  1739. $result = array();
  1740. $result['html'] = $this->fetch('Goods:goods_list_fetch');
  1741. echo json_encode($result);
  1742. die();
  1743. }
  1744. /**
  1745. 搜索可报名的商品
  1746. **/
  1747. public function goods_search()
  1748. {
  1749. $goods_name = I('post.goods_name','');
  1750. $where = " type='normal' and status=1 and quantity>0 and store_id = " . $this->sellerid;
  1751. if(!empty($goods_name))
  1752. {
  1753. $where .= " and name like '%".$goods_name."%' ";
  1754. }
  1755. $goods_list = M('goods')->where($where)->limit(20)->select();
  1756. $this->goods_list = $goods_list;
  1757. $result = array();
  1758. $result['html'] = $this->fetch('Goods:goods_list_fetch');
  1759. echo json_encode($result);
  1760. die();
  1761. }
  1762. public function query_normal()
  1763. {
  1764. $_GPC = I('request.');
  1765. $kwd = trim($_GPC['keyword']);
  1766. $is_recipe = isset($_GPC['is_recipe']) ? intval($_GPC['is_recipe']) : 0 ;
  1767. $is_soli = isset($_GPC['is_soli']) ? intval($_GPC['is_soli']) : 0 ;
  1768. $params = array();
  1769. $type = isset($_GPC['type']) ? $_GPC['type']:'normal';
  1770. $condition = ' type = "'.$type.'" and grounding = 1 and is_seckill =0 ';
  1771. if (!empty($kwd)) {
  1772. $condition .= ' AND `goodsname` LIKE "%' . $kwd . '%" ';
  1773. }
  1774. if( isset($_GPC['unselect_goodsid']) && $_GPC['unselect_goodsid'] > 0 )
  1775. {
  1776. $condition .= ' AND `id` != '.$_GPC['unselect_goodsid'];
  1777. }
  1778. if( $is_soli == 1 )
  1779. {
  1780. $head_id = $_GPC['head_id'];
  1781. $goods_ids_arr = M('lionfish_community_head_goods')->field('goods_id')->where( "head_id in ({$head_id})" )->order('id desc')->select();
  1782. $ids_arr = array();
  1783. foreach($goods_ids_arr as $val){
  1784. $ids_arr[] = $val['goods_id'];
  1785. }
  1786. if( !empty($ids_arr) )
  1787. {
  1788. $ids_str = implode(',',$ids_arr);
  1789. $condition .= " and ( is_all_sale = 1 or id in ({$ids_str}) ) ";
  1790. }else{
  1791. $condition .= " and ( is_all_sale = 1 ) ";
  1792. }
  1793. //is_all_sale
  1794. }
  1795. //todo....
  1796. $time = time();
  1797. $ds = M('lionfish_comshop_goods')->field('id as gid,goodsname,price,productprice,total')->where( $condition )->select();
  1798. $s_html = "";
  1799. foreach ($ds as &$d) {
  1800. //thumb
  1801. $thumb = M('lionfish_comshop_goods_images')->where( array('goods_id' =>$d['gid'] ) )->order('id asc')->find();
  1802. $d['thumb'] = tomedia($thumb['image']);
  1803. $goods_common_info = M('lionfish_comshop_good_common')->field("begin_time,end_time")->where( array('goods_id' =>$d['gid'] ) )->order('id asc')->find();
  1804. if($time >= $goods_common_info['begin_time'] && $time <= $goods_common_info['end_time']){
  1805. $d['is_finished'] = 0;
  1806. }else{
  1807. $d['is_finished'] = 1;//已结束
  1808. }
  1809. if($d['total'] <= 0){
  1810. $d['is_grab'] = 1;//已抢光
  1811. }else{
  1812. $d['is_grab'] = 0;
  1813. }
  1814. $s_html.= '<tr>';
  1815. $s_html.=" <td><img src='".tomedia($d['thumb'])."' style='width:30px;height:30px;padding1px;border:1px solid #ccc' /> ".$d['goodsname']."</td>";
  1816. if ( isset($_GPC['template']) && $_GPC['template'] == 'mult' ) {
  1817. if( $is_recipe == 1 )
  1818. {
  1819. $s_html.=' <td style="width:80px;"><a href="javascript:;" class="choose_dan_link_recipe" data-json=\''.json_encode($d).'\'>选择</a></td>';
  1820. }else{
  1821. $s_html.=' <td style="width:80px;"><a href="javascript:;" class="choose_dan_link_goods" data-json=\''.json_encode($d).'\'>选择</a></td>';
  1822. }
  1823. }else{
  1824. $s_html.=' <td style="width:80px;"><a href="javascript:;" class="choose_dan_link" data-json=\''.json_encode($d).'\'>选择</a></td>';
  1825. }
  1826. $s_html.="</tr>";
  1827. }
  1828. unset($d);
  1829. if( isset($_GPC['is_ajax']) )
  1830. {
  1831. echo json_encode( array('code' => 0, 'html' =>$s_html ) );
  1832. die();
  1833. }
  1834. $this->ds = $ds;
  1835. $this->_GPC = $_GPC;
  1836. if ( isset($_GPC['template']) && $_GPC['template'] == 'mult' ) {
  1837. if( $is_recipe == 1 )
  1838. {
  1839. $this->display('Goods/query_normal_mult_recipe');
  1840. }else{
  1841. $this->display('Goods/query_normal_mult');
  1842. }
  1843. }else{
  1844. $this->display();
  1845. }
  1846. }
  1847. /**
  1848. * 获取商品规格情况
  1849. */
  1850. function get_ajax_search_goods_info()
  1851. {
  1852. $goods_id = I('get.goods_id');
  1853. $is_hide = I('get.is_hide',0);
  1854. $type = I('get.type','pin');
  1855. //'type' => 'bargain'
  1856. $this->is_hide = $is_hide;
  1857. $goods_info = M('goods')->field('name,goods_id,price,danprice')->where( array('goods_id' => $goods_id) )->find();
  1858. $model=new GoodsModel();
  1859. $this->goods_options=$model->get_goods_options($goods_id, UID);
  1860. $goods_option_mult_value = M('goods_option_mult_value')->where( array('goods_id' => $goods_id ) )->select();
  1861. $goods_option_mult_str = '';
  1862. if( !empty($goods_option_mult_value) )
  1863. {
  1864. $goods_option_mult_arr = array();
  1865. foreach($goods_option_mult_value as $key => $val)
  1866. {
  1867. $goods_option_mult_arr[] = 'mult_id:'.$val['rela_goodsoption_valueid'].'@@mult_qu:'.$val['quantity'].'@@mult_image:'.$val['image'];
  1868. //option_value option_value_id value_name
  1869. $option_name_arr = explode('_', $val['rela_goodsoption_valueid']);
  1870. $option_name_list = array();
  1871. foreach($option_name_arr as $option_value_id_tp)
  1872. {
  1873. $tp_op_val_info =M('option_value')->where( array('option_value_id' => $option_value_id_tp) )->find();
  1874. $option_name_list[] = $tp_op_val_info['value_name'];
  1875. }
  1876. $val['option_name_list'] = $option_name_list;
  1877. $goods_option_mult_value[$key] = $val;
  1878. }
  1879. $goods_option_mult_str = implode(',', $goods_option_mult_arr);
  1880. }
  1881. $this->goods_option_mult_value = $goods_option_mult_value;
  1882. $this->goods_option_mult_str = $goods_option_mult_str;
  1883. $this->goods_info = $goods_info;
  1884. $result = array();
  1885. if($type == 'bargain')
  1886. {
  1887. $result['html'] = $this->fetch('Goods:goods_option_fetch_bargain');
  1888. }
  1889. else if($type == 'integral'){
  1890. $result['html'] = $this->fetch('Goods:goods_option_fetch_integral');
  1891. }else{
  1892. $result['html'] = $this->fetch('Goods:goods_option_fetch');
  1893. }
  1894. echo json_encode($result);
  1895. die();
  1896. }
  1897. function toggle_index_sort()
  1898. {
  1899. $goods_id = I('post.gid',0);
  1900. $index_sort = I('post.index_sort',0,'intval');
  1901. $res = M('Goods')->where( array('goods_id' => $goods_id) )->save( array('index_sort' => $index_sort) );
  1902. echo json_encode( array('code' => 1) );
  1903. die();
  1904. }
  1905. function toggle_index_show()
  1906. {
  1907. $goods_id = I('post.gid',0);
  1908. $goods_info =M('Goods')->where( array('goods_id' => $goods_id) )->find();
  1909. $is_index_show = $goods_info['is_index_show'] == 1 ? 0: 1;
  1910. $res = M('Goods')->where( array('goods_id' => $goods_id) )->save( array('is_index_show' => $is_index_show) );
  1911. echo json_encode( array('code' => 1) );
  1912. die();
  1913. }
  1914. /**
  1915. * 活动商品
  1916. */
  1917. public function activity()
  1918. {
  1919. $this->breadcrumb2='活动商品信息';
  1920. $model=new GoodsModel();
  1921. $filter=I('get.');
  1922. $search=array('store_id' => SELLERUID);
  1923. if(isset($filter['name'])){
  1924. $search['name']=$filter['name'];
  1925. }
  1926. if(isset($filter['category'])){
  1927. $search['category']=$filter['category'];
  1928. $this->get_category=$search['category'];
  1929. }
  1930. if(isset($filter['status'])){
  1931. $search['status']=$filter['status'];
  1932. $this->get_status=$search['status'];
  1933. }
  1934. if(isset($filter['type'])){
  1935. $search['type']=$filter['type'];
  1936. $this->type=$search['type'];
  1937. }else {
  1938. $search['type']='activity';
  1939. $this->type=$search['type'];
  1940. }
  1941. //type
  1942. $data=$model->show_goods_page($search);
  1943. $store_bind_class = M('store_bind_class')->where( array('seller_id' => SELLERUID) )->select();
  1944. $cate_ids = array();
  1945. foreach($store_bind_class as $val)
  1946. {
  1947. if( !empty($val['class_1'])) {
  1948. $cate_ids[] = $val['class_1'];
  1949. }
  1950. if( !empty($val['class_2'])) {
  1951. $cate_ids[] = $val['class_2'];
  1952. }
  1953. if( !empty($val['class_3'])) {
  1954. $cate_ids[] = $val['class_3'];
  1955. }
  1956. }
  1957. if(empty($cate_ids)) {
  1958. $this->category = array();
  1959. } else {
  1960. $cate_ids_str = implode(',', $cate_ids);
  1961. $category=M('goods_category')->where( array('id' => array('in',$cate_ids_str)) )->select();
  1962. $category_tree =list_to_tree($category);
  1963. $this->category = $category_tree;
  1964. }
  1965. foreach($data['list'] as $key => $goods)
  1966. {
  1967. $all_comment = M('order_comment')->where( array('goods_id' => $goods['goods_id']) )->count();
  1968. $wait_comment = M('order_comment')->where( array('state' => 0 ,'goods_id' => $goods['goods_id']) )->count();
  1969. $goods['all_comment'] = $all_comment;
  1970. $goods['wait_comment'] = $wait_comment;
  1971. $data['list'][$key] = $goods;
  1972. }
  1973. $this->assign('empty',$data['empty']);// 赋值数据集
  1974. $this->assign('list',$data['list']);// 赋值数据集
  1975. $this->assign('page',$data['page']);// 赋值分页输出
  1976. $this->display();
  1977. }
  1978. /**
  1979. 回收站商品重新上架
  1980. **/
  1981. public function goback()
  1982. {
  1983. $goods_id = I('get.id',0,'intval');
  1984. $result = array('code' => 0);
  1985. $goods_info = M('goods')->where( array('goods_id' => $goods_id, 'store_id' => SELLERUID) )->find();
  1986. if(empty($goods_info))
  1987. {
  1988. $result['msg'] = '非法操作';
  1989. echo json_encode($result);
  1990. die();
  1991. }
  1992. $up_data = array();
  1993. $up_data['lock_type'] = 'normal';
  1994. $up_data['status'] = 2;//下架
  1995. M('goods')->where( array('goods_id' => $goods_id, 'store_id' => SELLERUID) )->save($up_data);
  1996. $result['code'] = 1;
  1997. echo json_encode($result);
  1998. die();
  1999. }
  2000. public function get_weshare_image()
  2001. {
  2002. $goods_id = I('get.id',0,'intval');
  2003. //400*400 fan_image
  2004. //get_goods_price($goods_id)
  2005. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2006. $goods_img = ROOT_PATH.'Uploads/image/'.$goods_info['image'];
  2007. if( !empty($goods_info['fan_image']) )
  2008. {
  2009. $goods_img = ROOT_PATH.'Uploads/image/'.$goods_info['fan_image'];
  2010. }
  2011. $goods_model = D('Home/Goods');
  2012. $goods_price = $goods_model->get_goods_price($goods_id);
  2013. $goods_price['market_price'] = $goods_info['price'];
  2014. //price
  2015. $goods_title = $goods_info['name'];
  2016. $need_img = $goods_model->_get_compare_zan_img($goods_img,$goods_title,$goods_price);
  2017. //贴上二维码图
  2018. //$rocede_path = $goods_model->_get_goods_user_wxqrcode($goods_id,$member_id);
  2019. //$res = $goods_model->_get_compare_qrcode_bgimg($need_img['need_path'], $rocede_path);
  2020. M('goods_description')->where( array('goods_id' =>$goods_id) )->save( array('wepro_qrcode_image' =>$need_img['need_path']) );
  2021. echo json_encode(array('code' =>1));
  2022. die();
  2023. }
  2024. /**
  2025. 加入回车站
  2026. **/
  2027. public function backhuiche()
  2028. {
  2029. $goods_id = I('get.id',0,'intval');
  2030. $result = array('code' => 0);
  2031. $goods_info = M('goods')->where( array('goods_id' => $goods_id, 'store_id' => SELLERUID) )->find();
  2032. if(empty($goods_info))
  2033. {
  2034. $result['msg'] = '非法操作';
  2035. echo json_encode($result);
  2036. die();
  2037. }
  2038. $lock_type = $goods_info['lock_type'];
  2039. switch($lock_type)
  2040. {
  2041. case 'lottery':
  2042. M('lottery_goods')->where( array('goods_id' => $goods_id) )->delete();
  2043. break;
  2044. case 'super_spike':
  2045. M('super_spike_goods')->where( array('goods_id' => $goods_id) )->delete();
  2046. break;
  2047. case 'spike':
  2048. M('spike_goods')->where( array('goods_id' => $goods_id) )->delete();
  2049. break;
  2050. case 'subject':
  2051. case 'free_trial':
  2052. case 'niyuan':
  2053. case 'oneyuan':
  2054. case 'haitao':
  2055. M('subject_goods')->where( array('goods_id' => $goods_id) )->delete();
  2056. break;
  2057. }
  2058. $up_data = array();
  2059. $up_data['type'] = 'normal';
  2060. $up_data['lock_type'] = 'normal';
  2061. $up_data['status'] = 4;//下架
  2062. M('goods')->where( array('goods_id' => $goods_id, 'store_id' => SELLERUID) )->save($up_data);
  2063. $result['code'] = 1;
  2064. echo json_encode($result);
  2065. die();
  2066. }
  2067. /**
  2068. 撤回活动申请
  2069. **/
  2070. public function backshenqing()
  2071. {
  2072. $goods_id = I('get.id',0,'intval');
  2073. $result = array('code' => 0);
  2074. $goods_info = M('goods')->where( array('goods_id' => $goods_id, 'store_id' => SELLERUID) )->find();
  2075. if(empty($goods_info))
  2076. {
  2077. $result['msg'] = '非法操作';
  2078. echo json_encode($result);
  2079. die();
  2080. }
  2081. $lock_type = $goods_info['lock_type'];
  2082. switch($lock_type)
  2083. {
  2084. case 'lottery':
  2085. M('lottery_goods')->where( array('goods_id' => $goods_id) )->delete();
  2086. break;
  2087. case 'super_spike':
  2088. M('super_spike_goods')->where( array('goods_id' => $goods_id) )->delete();
  2089. break;
  2090. case 'spike':
  2091. M('spike_goods')->where( array('goods_id' => $goods_id) )->delete();
  2092. break;
  2093. case 'subject':
  2094. case 'free_trial':
  2095. case 'niyuan':
  2096. case 'oneyuan':
  2097. case 'haitao':
  2098. M('subject_goods')->where( array('goods_id' => $goods_id) )->delete();
  2099. break;
  2100. }
  2101. $up_data = array();
  2102. $up_data['lock_type'] = 'normal';
  2103. $up_data['status'] = 0;//下架
  2104. M('goods')->where( array('goods_id' => $goods_id, 'store_id' => SELLERUID) )->save($up_data);
  2105. $result['code'] = 1;
  2106. echo json_encode($result);
  2107. die();
  2108. }
  2109. ///Goods/delcomment/id/1
  2110. /**
  2111. * 删除评论
  2112. */
  2113. public function delcomment()
  2114. {
  2115. $id = I('get.id');
  2116. $goods_id = I('get.goods_id');
  2117. M('order_comment')->where( array('comment_id' => $id) )->delete();
  2118. //echo
  2119. $result = array(
  2120. 'status'=>'success',
  2121. 'message'=>'删除成功',
  2122. 'jump'=>U('Goods/comment_info', array('id' => $goods_id))
  2123. );
  2124. $this->osc_alert($result);
  2125. }
  2126. /**
  2127. * 审核评论
  2128. */
  2129. public function toggle_comment_state()
  2130. {
  2131. $comment_id = I('post.comment_id');
  2132. $order_comment = M('order_comment')->where( array('comment_id' => $comment_id) )->find();
  2133. //state
  2134. $state = $order_comment['state'] == 1 ? 0: 1;
  2135. M('order_comment')->where( array('comment_id' => $comment_id) )->save( array('state' => $state) );
  2136. echo json_encode( array('code' => 1) );
  2137. die();
  2138. }
  2139. /**
  2140. * 商品评论信息
  2141. */
  2142. public function comment_info()
  2143. {
  2144. $goods_id = I('get.id');
  2145. $model=new GoodsModel();
  2146. $search = array();
  2147. $search['goods_id'] = $goods_id;
  2148. $data=$model->show_comment_page($search);
  2149. $this->assign('empty',$data['empty']);// 赋值数据集
  2150. $this->assign('list',$data['list']);// 赋值数据集
  2151. $this->assign('page',$data['page']);// 赋值分页输出
  2152. $this->display();
  2153. }
  2154. public function ajax_batchheads()
  2155. {
  2156. $goodsids = I('request.goodsids');
  2157. $head_id_arr = I('request.head_id_arr');
  2158. $is_clear_old = I('request.is_clear_old');
  2159. $is_cancle_allhead = I('request.is_cancle_allhead');
  2160. if( $is_clear_old == 1 )
  2161. {
  2162. foreach($goodsids as $goods_id)
  2163. {
  2164. M('lionfish_community_head_goods')->where( array('goods_id' => $goods_id) )->delete();
  2165. }
  2166. }
  2167. if( isset($is_cancle_allhead) && $is_cancle_allhead == 1 )
  2168. {
  2169. foreach($goodsids as $goods_id)
  2170. {
  2171. M('lionfish_comshop_goods')->where( array('id' => $goods_id) )->save( array('is_all_sale' => 0) );
  2172. }
  2173. }
  2174. foreach($head_id_arr as $head_id)
  2175. {
  2176. foreach($goodsids as $goods_id)
  2177. {
  2178. D('Seller/Communityhead')->insert_head_goods($goods_id, $head_id);
  2179. }
  2180. }
  2181. show_json(1);
  2182. }
  2183. public function ajax_batchcates_headgroup()
  2184. {
  2185. $_GPC = I('request.');
  2186. $goodsids = $_GPC['goodsids'];
  2187. $groupid = $_GPC['groupid'];
  2188. if( $groupid == 'default')
  2189. {
  2190. $groupid = 0;
  2191. }
  2192. $head_list = M('lionfish_community_head')->field('id')->where( array("groupid" => $groupid, 'state' => 1 ) )->select();
  2193. $is_clear_old = $_GPC['is_clear_old'];
  2194. $is_cancle_allhead = isset($_GPC['is_cancle_allhead']) ? $_GPC['is_cancle_allhead'] : 0;
  2195. if($is_cancle_allhead == 1)
  2196. {
  2197. foreach($goodsids as $goods_id)
  2198. {
  2199. M('lionfish_comshop_goods')->where( array('id' => $goods_id) )->save( array('is_all_sale' => 0) );
  2200. }
  2201. }
  2202. if( $is_clear_old == 1 )
  2203. {
  2204. foreach($goodsids as $goods_id)
  2205. {
  2206. M('lionfish_community_head_goods')->where( array('goods_id' => $goods_id ) )->delete();
  2207. }
  2208. }
  2209. if( !empty($head_list) )
  2210. {
  2211. foreach($head_list as $val)
  2212. {
  2213. foreach($goodsids as $goods_id)
  2214. {
  2215. D('Seller/Communityhead')->insert_head_goods($goods_id, $val['id']);
  2216. }
  2217. }
  2218. }
  2219. show_json(1);
  2220. }
  2221. public function ajax_batchcates()
  2222. {
  2223. $iscover = I('request.iscover');
  2224. $goodsids = I('request.goodsids');
  2225. $cates = I('request.cates');
  2226. if( !is_array($cates) )
  2227. {
  2228. $cates = array($cates);
  2229. }
  2230. foreach ($goodsids as $goods_id ) {
  2231. if( $iscover == 1)
  2232. {
  2233. //覆盖,即删除原有的分类
  2234. M('lionfish_comshop_goods_to_category')->where( array('goods_id' => $goods_id) )->delete();
  2235. foreach($cates as $cate_id)
  2236. {
  2237. $post_data_cate = array();
  2238. $post_data_cate['cate_id'] = $cate_id;
  2239. $post_data_cate['goods_id'] = $goods_id;
  2240. M('lionfish_comshop_goods_to_category')->add($post_data_cate);
  2241. }
  2242. }else{
  2243. foreach($cates as $cate_id)
  2244. {
  2245. //仅更新
  2246. $item = M('lionfish_comshop_goods_to_category')->where( array('goods_id' => $goods_id,'cate_id' => $cate_id) )->find();
  2247. if(empty($item))
  2248. {
  2249. $post_data_cate = array();
  2250. $post_data_cate['cate_id'] = $cate_id;
  2251. $post_data_cate['goods_id'] = $goods_id;
  2252. M('lionfish_comshop_goods_to_category')->add($post_data_cate);
  2253. }
  2254. }
  2255. }
  2256. }
  2257. show_json(1);
  2258. }
  2259. public function lotteryinfo()
  2260. {
  2261. $goods_id = I('get.id',0);
  2262. $lottery_goods = M('lottery_goods')->where( array('goods_id' =>$goods_id) )->find();
  2263. if(empty($lottery_goods)){
  2264. die('非法操作');
  2265. }//store_id
  2266. $page = I('get.page',1);
  2267. $per_page = 4;
  2268. $offset = ($page - 1) * $per_page;
  2269. $sql = "select m.uname,m.avatar,p.pin_id,p.lottery_state,o.lottery_win,o.order_id,o.pay_time from ".C('DB_PREFIX')."pin as p,".C('DB_PREFIX')."pin_order as po,
  2270. ".C('DB_PREFIX')."order as o,".C('DB_PREFIX')."order_goods as og,".C('DB_PREFIX')."member as m
  2271. where p.state = 1 and p.pin_id = po.pin_id and po.order_id = o.order_id
  2272. and o.order_id = og.order_id and og.goods_id and o.member_id = m.member_id and og.store_id =".SELLERUID." and og.goods_id = {$goods_id}
  2273. and o.date_added >= ".$lottery_goods['begin_time']." order by p.pin_id asc limit {$offset},{$per_page}";
  2274. //begin_time date_added
  2275. $list=M()->query($sql);
  2276. $this->list = $list;
  2277. $this->goods_id = $goods_id;
  2278. $this->lottery_goods = $lottery_goods;
  2279. if($page>1){
  2280. $result = array();
  2281. $result['code'] = 0;
  2282. if(!empty($list)) {
  2283. $content = $this->fetch('Goods:lottery_info_fetch');
  2284. $result['code'] = 1;
  2285. $result['html'] = $content;
  2286. }
  2287. echo json_encode($result);
  2288. die();
  2289. }
  2290. $this->display();
  2291. }
  2292. public function openlottery()
  2293. {
  2294. $goods_id = I('get.id',0);
  2295. $oids = I('post.oids');
  2296. $order_model = D('Home/Order');
  2297. $order_model->open_goods_lottery_order($goods_id,$oids,false);
  2298. //$order_model->open_goods_lottery_order($goods_id,'',true);
  2299. //$map['id'] = array('in','1,3,8')
  2300. echo json_encode( array('code' => 1) );
  2301. die();
  2302. }
  2303. public function lottery_shenqing()
  2304. {
  2305. $result = array('code' => 0);
  2306. $goods_id = I('post.goods_id',0);
  2307. if($goods_id == 0){
  2308. $result['msg'] = '商品不存在';
  2309. echo json_encode($result);
  2310. die();
  2311. }
  2312. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2313. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2314. $spike_data = array();
  2315. $spike_data['goods_id'] = $goods_id;
  2316. $spike_data['state'] = 0;
  2317. $spike_data['quantity'] = $goods_info['quantity'];
  2318. $spike_data['begin_time'] = 0;
  2319. $spike_data['end_time'] = 0;
  2320. $spike_data['addtime'] = time();
  2321. $rs = M('lottery_goods')->add($spike_data);
  2322. if($rs) {
  2323. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'lottery') );
  2324. }
  2325. $result['code'] = 1;
  2326. echo json_encode($result);
  2327. die();
  2328. } else{
  2329. $result['msg'] = '已存在其他活动中';
  2330. echo json_encode($result);
  2331. die();
  2332. }
  2333. }
  2334. public function xianshimiaosha_shenqing()
  2335. {
  2336. $result = array('code' => 0);
  2337. $goods_id = I('post.goods_id',0);
  2338. if($goods_id == 0){
  2339. $result['msg'] = '商品不存在';
  2340. echo json_encode($result);
  2341. die();
  2342. }
  2343. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2344. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2345. $spike_data = array();
  2346. $spike_data['goods_id'] = $goods_id;
  2347. $spike_data['state'] = 0;
  2348. $spike_data['quantity'] = $goods_info['quantity'];
  2349. $spike_data['begin_time'] = 0;
  2350. $spike_data['end_time'] = 0;
  2351. $spike_data['addtime'] = time();
  2352. $rs = M('spike_goods')->add($spike_data);
  2353. if($rs) {
  2354. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'spike') );
  2355. }
  2356. $result['code'] = 1;
  2357. echo json_encode($result);
  2358. die();
  2359. } else{
  2360. $result['msg'] = '已存在其他活动中';
  2361. echo json_encode($result);
  2362. die();
  2363. }
  2364. }
  2365. public function spike_sub()
  2366. {
  2367. $spike_id = I('post.spike',0);
  2368. $goods_id = I('post.goods_id',0);
  2369. if($goods_id == 0){
  2370. $result['msg'] = '商品不存在';
  2371. echo json_encode($result);
  2372. die();
  2373. }
  2374. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2375. $spike_info = M('spike')->where( array('id' => $spike_id) )->find();
  2376. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2377. $super_data = array();
  2378. $super_data['spike_id'] = $spike_id;
  2379. $super_data['goods_id'] = $goods_id;
  2380. $super_data['state'] = 0;
  2381. $super_data['begin_time'] = $spike_info['begin_time'];
  2382. $super_data['end_time'] = $spike_info['end_time'];
  2383. $super_data['addtime'] = time();
  2384. $rs = M('spike_goods')->add($super_data);
  2385. if($rs) {
  2386. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'spike') );
  2387. }
  2388. $result['code'] = 1;
  2389. echo json_encode($result);
  2390. die();
  2391. } else {
  2392. $result['msg'] = '已存在其他活动中';
  2393. echo json_encode($result);
  2394. die();
  2395. }
  2396. }
  2397. public function chaozhidapai_sub()
  2398. {
  2399. $super_spike_id = I('post.super_spike',0);
  2400. $goods_id = I('post.goods_id',0);
  2401. if($goods_id == 0){
  2402. $result['msg'] = '商品不存在';
  2403. echo json_encode($result);
  2404. die();
  2405. }
  2406. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2407. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2408. $super_data = array();
  2409. $super_data['super_spike_id'] = $super_spike_id;
  2410. $super_data['goods_id'] = $goods_id;
  2411. $super_data['state'] = 0;
  2412. $super_data['begin_time'] = 0;
  2413. $super_data['end_time'] = 0;
  2414. $super_data['addtime'] = time();
  2415. $rs = M('super_spike_goods')->add($super_data);
  2416. if($rs) {
  2417. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'super_spike') );
  2418. }
  2419. $result['code'] = 1;
  2420. echo json_encode($result);
  2421. die();
  2422. } else {
  2423. $result['msg'] = '已存在其他活动中';
  2424. echo json_encode($result);
  2425. die();
  2426. }
  2427. }
  2428. public function oneyuansubject_sub()
  2429. {
  2430. $subject_id = I('post.subject',0);
  2431. $goods_id = I('post.goods_id',0);
  2432. if($goods_id == 0){
  2433. $result['msg'] = '商品不存在';
  2434. echo json_encode($result);
  2435. die();
  2436. }
  2437. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2438. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2439. $super_data = array();
  2440. $super_data['subject_id'] = $subject_id;
  2441. $super_data['goods_id'] = $goods_id;
  2442. $super_data['state'] = 0;
  2443. $super_data['addtime'] = time();
  2444. $rs = M('subject_goods')->add($super_data);
  2445. if($rs) {
  2446. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'oneyuan') );
  2447. }
  2448. $result['code'] = 1;
  2449. echo json_encode($result);
  2450. die();
  2451. } else {
  2452. $result['msg'] = '已存在其他活动中';
  2453. echo json_encode($result);
  2454. die();
  2455. }
  2456. }
  2457. public function niyuansubject_sub()
  2458. {
  2459. $subject_id = I('post.subject',0);
  2460. $goods_id = I('post.goods_id',0);
  2461. if($goods_id == 0){
  2462. $result['msg'] = '商品不存在';
  2463. echo json_encode($result);
  2464. die();
  2465. }
  2466. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2467. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2468. $super_data = array();
  2469. $super_data['subject_id'] = $subject_id;
  2470. $super_data['goods_id'] = $goods_id;
  2471. $super_data['state'] = 0;
  2472. $super_data['addtime'] = time();
  2473. $rs = M('subject_goods')->add($super_data);
  2474. if($rs) {
  2475. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'niyuan') );
  2476. }
  2477. $result['code'] = 1;
  2478. echo json_encode($result);
  2479. die();
  2480. } else {
  2481. $result['msg'] = '已存在其他活动中';
  2482. echo json_encode($result);
  2483. die();
  2484. }
  2485. }
  2486. public function mianfei_sub()
  2487. {
  2488. $subject_id = I('post.subject',0);
  2489. $goods_id = I('post.goods_id',0);
  2490. if($goods_id == 0){
  2491. $result['msg'] = '商品不存在';
  2492. echo json_encode($result);
  2493. die();
  2494. }
  2495. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2496. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2497. $super_data = array();
  2498. $super_data['subject_id'] = $subject_id;
  2499. $super_data['goods_id'] = $goods_id;
  2500. $super_data['state'] = 0;
  2501. $super_data['addtime'] = time();
  2502. $rs = M('subject_goods')->add($super_data);
  2503. if($rs) {
  2504. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'zeyuan') );
  2505. }
  2506. $result['code'] = 1;
  2507. echo json_encode($result);
  2508. die();
  2509. } else {
  2510. $result['msg'] = '已存在其他活动中';
  2511. echo json_encode($result);
  2512. die();
  2513. }
  2514. }
  2515. public function putongsubject_sub()
  2516. {
  2517. $subject_id = I('post.subject',0);
  2518. $goods_id = I('post.goods_id',0);
  2519. if($goods_id == 0){
  2520. $result['msg'] = '商品不存在';
  2521. echo json_encode($result);
  2522. die();
  2523. }
  2524. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2525. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2526. $super_data = array();
  2527. $super_data['subject_id'] = $subject_id;
  2528. $super_data['goods_id'] = $goods_id;
  2529. $super_data['state'] = 0;
  2530. $super_data['addtime'] = time();
  2531. $rs = M('subject_goods')->add($super_data);
  2532. if($rs) {
  2533. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'subject') );
  2534. }
  2535. $result['code'] = 1;
  2536. echo json_encode($result);
  2537. die();
  2538. } else {
  2539. $result['msg'] = '已存在其他活动中';
  2540. echo json_encode($result);
  2541. die();
  2542. }
  2543. }
  2544. public function haitaosubject_sub()
  2545. {
  2546. $subject_id = I('post.subject',0);
  2547. $goods_id = I('post.goods_id',0);
  2548. if($goods_id == 0){
  2549. $result['msg'] = '商品不存在';
  2550. echo json_encode($result);
  2551. die();
  2552. }
  2553. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2554. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2555. $super_data = array();
  2556. $super_data['subject_id'] = $subject_id;
  2557. $super_data['goods_id'] = $goods_id;
  2558. $super_data['state'] = 0;
  2559. $super_data['addtime'] = time();
  2560. $rs = M('subject_goods')->add($super_data);
  2561. if($rs) {
  2562. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'haitao') );
  2563. }
  2564. $result['code'] = 1;
  2565. echo json_encode($result);
  2566. die();
  2567. } else {
  2568. $result['msg'] = '已存在其他活动中';
  2569. echo json_encode($result);
  2570. die();
  2571. }
  2572. }
  2573. public function yiyuan_form()
  2574. {
  2575. $result = array('code' => 0);
  2576. $goods_id = I('post.goods_id',0);
  2577. if($goods_id == 0){
  2578. $result['msg'] = '商品不存在';
  2579. echo json_encode($result);
  2580. die();
  2581. }
  2582. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2583. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2584. $subject = M('subject')->where('can_shenqing=1 and type="oneyuan"')->select();
  2585. $this->subject = $subject;
  2586. $this->goods_id = $goods_id;
  2587. $content = $this->fetch('Goods:goods_oneyuansubject_fetch');
  2588. $result['code'] = 1;
  2589. $result['html'] = $content;
  2590. echo json_encode($result);
  2591. die();
  2592. } else {
  2593. $result['msg'] = '已存在其他活动中';
  2594. echo json_encode($result);
  2595. die();
  2596. }
  2597. }
  2598. public function jiukuaijiu_form()
  2599. {
  2600. $result = array('code' => 0);
  2601. $goods_id = I('post.goods_id',0);
  2602. if($goods_id == 0){
  2603. $result['msg'] = '商品不存在';
  2604. echo json_encode($result);
  2605. die();
  2606. }
  2607. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2608. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2609. $subject = M('subject')->where('can_shenqing=1 and type="niyuan"')->select();
  2610. $this->subject = $subject;
  2611. $this->goods_id = $goods_id;
  2612. $content = $this->fetch('Goods:goods_niyuansubject_fetch');
  2613. $result['code'] = 1;
  2614. $result['html'] = $content;
  2615. echo json_encode($result);
  2616. die();
  2617. } else {
  2618. $result['msg'] = '已存在其他活动中';
  2619. echo json_encode($result);
  2620. die();
  2621. }
  2622. }
  2623. public function lottery_form()
  2624. {
  2625. $result = array('code' => 0);
  2626. $goods_id = I('post.goods_id',0);
  2627. if($goods_id == 0){
  2628. $result['msg'] = '商品不存在';
  2629. echo json_encode($result);
  2630. die();
  2631. }
  2632. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2633. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2634. $voucher_list = M('voucher')->where( "store_id=".SELLERUID." and begin_time>".time() )->select();
  2635. $this->voucher_list = $voucher_list;
  2636. $this->goods_id = $goods_id;
  2637. $content = $this->fetch('Goods:goods_lottery_fetch');
  2638. $result['code'] = 1;
  2639. $result['html'] = $content;
  2640. echo json_encode($result);
  2641. die();
  2642. } else {
  2643. $result['msg'] = '已存在其他活动中';
  2644. echo json_encode($result);
  2645. die();
  2646. }
  2647. }
  2648. public function lottery_sub()
  2649. {
  2650. $voucher_id = I('post.voucher_id',0);
  2651. $goods_id = I('post.goods_id',0);
  2652. $win_quantity = I('post.win_quantity',0);
  2653. $is_auto_open = I('post.is_auto_open',0);
  2654. $real_win_quantity = I('post.real_win_quantity',0);
  2655. if($goods_id == 0){
  2656. $result['msg'] = '商品不存在';
  2657. echo json_encode($result);
  2658. die();
  2659. }
  2660. if($voucher_id == 0){
  2661. $result['msg'] = '请选择退款时赠送的优惠券';
  2662. echo json_encode($result);
  2663. die();
  2664. }
  2665. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2666. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2667. $spike_data = array();
  2668. $spike_data['goods_id'] = $goods_id;
  2669. $spike_data['state'] = 0;
  2670. $spike_data['is_open_lottery'] = 0;
  2671. $spike_data['voucher_id'] = $voucher_id;
  2672. $spike_data['win_quantity'] = $win_quantity;
  2673. $spike_data['is_auto_open'] = $is_auto_open;
  2674. $spike_data['real_win_quantity'] = $real_win_quantity;
  2675. $spike_data['quantity'] = $goods_info['quantity'];
  2676. $spike_data['begin_time'] = 0;
  2677. $spike_data['end_time'] = 0;
  2678. $spike_data['addtime'] = time();
  2679. $rs = M('lottery_goods')->add($spike_data);
  2680. if($rs) {
  2681. M('goods')->where( array('goods_id' => $goods_id) )->save( array('lock_type' =>'lottery') );
  2682. }
  2683. $result['code'] = 1;
  2684. echo json_encode($result);
  2685. die();
  2686. die();
  2687. } else {
  2688. $result['msg'] = '已存在其他活动中';
  2689. echo json_encode($result);
  2690. die();
  2691. }
  2692. }
  2693. public function putongsubject_form()
  2694. {
  2695. $result = array('code' => 0);
  2696. $goods_id = I('post.goods_id',0);
  2697. if($goods_id == 0){
  2698. $result['msg'] = '商品不存在';
  2699. echo json_encode($result);
  2700. die();
  2701. }
  2702. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2703. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2704. $subject = M('subject')->where('can_shenqing=1 and type="normal"')->select();
  2705. $this->subject = $subject;
  2706. $this->goods_id = $goods_id;
  2707. $content = $this->fetch('Goods:goods_putongsubject_fetch');
  2708. $result['code'] = 1;
  2709. $result['html'] = $content;
  2710. echo json_encode($result);
  2711. die();
  2712. } else {
  2713. $result['msg'] = '已存在其他活动中';
  2714. echo json_encode($result);
  2715. die();
  2716. }
  2717. }
  2718. public function haitaosubject_form()
  2719. {
  2720. $result = array('code' => 0);
  2721. $goods_id = I('post.goods_id',0);
  2722. if($goods_id == 0){
  2723. $result['msg'] = '商品不存在';
  2724. echo json_encode($result);
  2725. die();
  2726. }
  2727. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2728. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2729. $subject = M('subject')->where('can_shenqing=1 and type="haitao"')->select();
  2730. $this->subject = $subject;
  2731. $this->goods_id = $goods_id;
  2732. $content = $this->fetch('Goods:goods_haitaosubject_fetch');
  2733. $result['code'] = 1;
  2734. $result['html'] = $content;
  2735. echo json_encode($result);
  2736. die();
  2737. } else {
  2738. $result['msg'] = '已存在其他活动中';
  2739. echo json_encode($result);
  2740. die();
  2741. }
  2742. }
  2743. public function mianfeishiyong_form()
  2744. {
  2745. $result = array('code' => 0);
  2746. $goods_id = I('post.goods_id',0);
  2747. if($goods_id == 0){
  2748. $result['msg'] = '商品不存在';
  2749. echo json_encode($result);
  2750. die();
  2751. }
  2752. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2753. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2754. $subject = M('subject')->where('can_shenqing=1 and type="zeyuan"')->select();
  2755. $this->subject = $subject;
  2756. $this->goods_id = $goods_id;
  2757. $content = $this->fetch('Goods:goods_mianfeishiyong_fetch');
  2758. $result['code'] = 1;
  2759. $result['html'] = $content;
  2760. echo json_encode($result);
  2761. die();
  2762. } else {
  2763. $result['msg'] = '已存在其他活动中';
  2764. echo json_encode($result);
  2765. die();
  2766. }
  2767. }
  2768. public function chaozhidapai_form()
  2769. {
  2770. $result = array('code' => 0);
  2771. $goods_id = I('post.goods_id',0);
  2772. if($goods_id == 0){
  2773. $result['msg'] = '商品不存在';
  2774. echo json_encode($result);
  2775. die();
  2776. }
  2777. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2778. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2779. $super_spike_list = M('super_spike')->where('begin_time>'.time())->select();
  2780. $this->super_spike_list = $super_spike_list;
  2781. $this->goods_id = $goods_id;
  2782. $content = $this->fetch('Goods:goods_chaozhidapai_fetch');
  2783. $result['code'] = 1;
  2784. $result['html'] = $content;
  2785. echo json_encode($result);
  2786. die();
  2787. } else {
  2788. $result['msg'] = '已存在其他活动中';
  2789. echo json_encode($result);
  2790. die();
  2791. }
  2792. }
  2793. public function spike_form()
  2794. {
  2795. $result = array('code' => 0);
  2796. $goods_id = I('post.goods_id',0);
  2797. if($goods_id == 0){
  2798. $result['msg'] = '商品不存在';
  2799. echo json_encode($result);
  2800. die();
  2801. }
  2802. $goods_info = M('goods')->where( array('goods_id' => $goods_id) )->find();
  2803. if($goods_info['type'] == 'normal' && !empty($goods_info)) {
  2804. $spike_list = M('spike')->where()->select();
  2805. //$spike_list = M('spike')->where('begin_time>'.time())->select();
  2806. $this->spike_list = $spike_list;
  2807. $this->goods_id = $goods_id;
  2808. $content = $this->fetch('Goods:goods_spike_fetch');
  2809. $result['code'] = 1;
  2810. $result['html'] = $content;
  2811. echo json_encode($result);
  2812. die();
  2813. } else {
  2814. $result['msg'] = '已存在其他活动中';
  2815. echo json_encode($result);
  2816. die();
  2817. }
  2818. }
  2819. public function get_json_category_tree($pid,$is_ajax=0)
  2820. {
  2821. // {pid:pid,is_ajax:1}
  2822. $pid = empty($_GET['pid']) ? 0: intval($_GET['pid']);
  2823. $is_ajax = empty($_GET['is_ajax']) ? 0:intval($_GET['is_ajax']);
  2824. $goods_cate_model = D('Seller/GoodsCategory');
  2825. //$list = $goods_cate_model->get_parent_cateory($pid,SELLERUID);
  2826. $list = M('goods_category')->field('id,pid,name')->where( array('pid'=>$pid) )->order('sort_order asc')->select();
  2827. if($pid > 0)
  2828. {
  2829. $list = M('goods_category')->field('id,pid,name')->where( array('pid'=>$pid) )->order('sort_order asc')->select();
  2830. }
  2831. $result = array();
  2832. if($is_ajax ==0)
  2833. {
  2834. return $list;
  2835. } else {
  2836. if(empty($list)){
  2837. $result['code'] = 0;
  2838. } else {
  2839. $result['code'] = 1;
  2840. $result['list'] = $list;
  2841. }
  2842. echo json_encode($result);
  2843. die();
  2844. }
  2845. }
  2846. function add(){
  2847. $model=new GoodsModel();
  2848. if(IS_POST){
  2849. $data=I('post.');
  2850. $data['goods_description']['tag'] = str_replace(',', ',', $data['goods_description']['tag']);
  2851. $data['store_id']=SELLERUID;
  2852. if($this->goods_is_shenhe()) {
  2853. $data['status'] = 2;
  2854. }
  2855. $return=$model->add_goods($data);
  2856. $this->osc_alert($return);
  2857. }
  2858. $m=new \Admin\Model\OptionModel();
  2859. //getOptions
  2860. $options_list = $m->getOptions('',SELLERUID);
  2861. $this->options_list = $options_list;
  2862. $pick_list = M('pick_up')->where( array('store_id' => SELLERUID) )->select();
  2863. $this->pick_list = $pick_list;
  2864. $member_model= D('Admin/Member');
  2865. $level_list = $member_model->show_member_level();
  2866. $member_default_levelname_info = D('Home/Front')->get_config_by_name('member_default_levelname');
  2867. $member_defualt_discount_info = D('Home/Front')->get_config_by_name('member_defualt_discount');
  2868. $default = array('id'=>'default', 'level' => 0,'levelname' => $member_default_levelname_info,'discount' => $member_defualt_discount_info);
  2869. array_unshift($level_list['list'], $default );
  2870. $need_level_list = $level_list['list'];
  2871. $set = D('Seller/Config')->get_all_config();
  2872. $this->set = $set;
  2873. /***
  2874. 是否开启 分享等级佣金 begin
  2875. **/
  2876. $index_sort_method = D('Home/Front')->get_config_by_name('index_sort_method');
  2877. if( empty($index_sort_method) || $index_sort_method == 0 )
  2878. {
  2879. $index_sort_method = 0;
  2880. }
  2881. $this->index_sort_method = $index_sort_method;
  2882. $show_fissionsharing_level = 1;
  2883. $is_open_sharing = D('Home/Front')->get_config_by_name('is_open_fissionsharing');
  2884. $show_fissionsharing_level = D('Home/Front')->get_config_by_name('show_fissionsharing_level');
  2885. $this->show_fissionsharing_level = $show_fissionsharing_level;
  2886. $this->is_open_sharing = $is_open_sharing;
  2887. /***
  2888. 是否开启 分享等级佣金 end
  2889. **/
  2890. $this->member_level_is_open_info = D('Home/Front')->get_config_by_name('member_level_is_open');
  2891. $this->need_level_list = $need_level_list;
  2892. $this->cate_data = $this->get_json_category_tree(0);
  2893. $this->action=U('Goods/add');
  2894. $this->crumbs='新增';
  2895. $this->display('edit');
  2896. }
  2897. /**
  2898. 商品是否需要审核
  2899. **/
  2900. function goods_is_shenhe()
  2901. {
  2902. $shenhegoods = M('config')->where( array('name' => 'shenhegoods') )->find();
  2903. $is_need_shen = 0;
  2904. if(!empty($shenhegoods)) {
  2905. $is_need_shen = $shenhegoods['value'];
  2906. }
  2907. return $is_need_shen;
  2908. }
  2909. public function change()
  2910. {
  2911. $id = I('request.id',0);
  2912. //ids
  2913. if (empty($id)) {
  2914. $ids = I('request.ids');
  2915. $id = ((is_array($ids) ? implode(',', $ids) : 0));
  2916. }
  2917. if (empty($id)) {
  2918. show_json(0, array('message' => '参数错误'));
  2919. }
  2920. $type = I('request.type');
  2921. $value = I('request.value');
  2922. //type/grounding/
  2923. $is_can_do = D('Seller/Supply')->checksupply_pri( $type );
  2924. if( !$is_can_do )
  2925. {
  2926. show_json(0, array('message' => '无此操作权限','url' => $_SERVER['HTTP_REFERER'] ));
  2927. }
  2928. if (!(in_array($type, array('goodsname', 'price','index_sort','is_index_show', 'total','grounding', 'goodssn', 'productsn', 'displayorder')))) {
  2929. show_json(0, array('message' => '参数错误','url' => $_SERVER['HTTP_REFERER'] ));
  2930. }
  2931. if($type =='total'){
  2932. $value=str_replace('.00','',$value);
  2933. if(preg_match("/^[1-9][0-9]*$/" ,$value) || $value == 0 ) {
  2934. }else{
  2935. show_json(3);
  2936. }
  2937. }
  2938. $items = M('lionfish_comshop_goods')->field('id,goodsname')->where( array('id' => array('in', $id)) )->select();
  2939. foreach ($items as $item ) {
  2940. if($type == 'grounding' && $value == 1){//上架判断核销商品过期时间
  2941. $goods_hexiao = M('lionfish_comshop_goods_salesroombase')->field('is_only_hexiao,hexiao_type,hx_expire_type,hx_expire_end_time')->where( array('goods_id' => $item['id']) )->find();
  2942. if(!empty($goods_hexiao) && $goods_hexiao['is_only_hexiao'] == 1 && $goods_hexiao['hx_expire_type'] == 1){
  2943. if($goods_hexiao['hx_expire_end_time'] < time()){
  2944. show_json(0, array('message' => '核销过期时间小于当前时间,商品不能上架','url' => $_SERVER['HTTP_REFERER'] ));
  2945. }
  2946. }
  2947. }
  2948. M('lionfish_comshop_goods')->where( array('id' => $item['id']) )->save( array($type => $value) );
  2949. if($type == 'goodsname'){
  2950. D('Seller/Operatelog')->addOperateLog('goods','商品修改名称--'.$item['goodsname']);
  2951. }elseif($type == 'price'){
  2952. D('Seller/Operatelog')->addOperateLog('goods','商品修改价格--'.$item['goodsname']);
  2953. }elseif($type == 'index_sort'){
  2954. D('Seller/Operatelog')->addOperateLog('goods','商品修改排序序号--'.$item['goodsname']);
  2955. }elseif($type == 'is_index_show'){
  2956. D('Seller/Operatelog')->addOperateLog('goods','商品修改首页推荐--'.$item['goodsname']);
  2957. }elseif($type == 'total'){
  2958. D('Seller/Operatelog')->addOperateLog('goods','商品修改库存--'.$item['goodsname']);
  2959. }elseif($type == 'grounding'){
  2960. if($value == 1){
  2961. if (defined('ROLE') && ROLE == 'agenter' )
  2962. {
  2963. $supply_add_goods_shenhe = D('Home/Front')->get_config_by_name('supply_add_goods_shenhe');
  2964. if($supply_add_goods_shenhe == 1 )
  2965. {
  2966. M('lionfish_comshop_goods')->where( array('id' => $item['id']) )->save( array('grounding' => 4) );
  2967. }
  2968. }
  2969. //D('Seller/Operatelog')->addOperateLog('goods','商品上架--'.$item['goodsname']);
  2970. }
  2971. if($value == 0){
  2972. D('Seller/Operatelog')->addOperateLog('goods','商品下架--'.$item['goodsname']);
  2973. }
  2974. if($value == 2){
  2975. D('Seller/Operatelog')->addOperateLog('goods','商品放入仓库中--'.$item['goodsname']);
  2976. }
  2977. if($value == 3){
  2978. D('Seller/Operatelog')->addOperateLog('goods','商品放入回收站--'.$item['goodsname']);
  2979. }
  2980. }elseif($type == 'goodssn'){
  2981. }elseif($type == 'productsn'){
  2982. }elseif($type == 'displayorder'){
  2983. }
  2984. if($type == 'total')
  2985. {
  2986. D('Seller/Redisorder')->sysnc_goods_total($item['id']);
  2987. }
  2988. }
  2989. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2990. }
  2991. public function delete()
  2992. {
  2993. $id = I('get.id');
  2994. //ids
  2995. if (empty($id)) {
  2996. $ids = I('post.ids');
  2997. $id = ((is_array($ids) ? implode(',', $ids) : 0));
  2998. }
  2999. if (empty($id)) {
  3000. show_json(0, array('message' => '参数错误'));
  3001. }
  3002. $items = M('lionfish_comshop_goods')->field('id,goodsname')->where( array('id' => array('in', $id)) )->select();
  3003. foreach ($items as $item ) {
  3004. //pdo_update('lionfish_comshop_goods', array($type => $value), array('id' => $item['id'])); //ims_lionfish_comshop_goods
  3005. M('lionfish_comshop_goods')->where( array('id' => $item['id']) )->delete();
  3006. M('lionfish_comshop_goods_images')->where( array('goods_id' => $item['id']) )->delete();
  3007. M('lionfish_comshop_goods_option')->where( array('goods_id' => $item['id']) )->delete();
  3008. M('lionfish_comshop_goods_option_item')->where( array('goods_id' => $item['id']) )->delete();
  3009. M('lionfish_comshop_goods_option_item_value')->where( array('goods_id' => $item['id']) )->delete();
  3010. M('lionfish_comshop_goods_to_category')->where( array('goods_id' => $item['id']) )->delete();
  3011. M('lionfish_comshop_good_common')->where( array('goods_id' => $item['id']) )->delete();
  3012. D('Seller/Operatelog')->addOperateLog('goods','永久删除商品--'.$item['goodsname']);
  3013. }
  3014. sellerLog('删除了['.$items['goodsname'].']商品', 3);
  3015. show_json(1);
  3016. }
  3017. function edit(){
  3018. $id = I('get.id');
  3019. if (IS_POST) {
  3020. $_GPC = I('post.');
  3021. if( !isset($_GPC['thumbs']) || empty($_GPC['thumbs']) )
  3022. {
  3023. show_json(0, array('message' => '商品图片必须上传' ,'url' => $_SERVER['HTTP_REFERER']) );
  3024. die();
  3025. }
  3026. if(!empty($_GPC['has_mb_level_buy'])){
  3027. foreach($_GPC['discount'] as $val)
  3028. {
  3029. if(preg_match("/^(([1-9]\d?)|100)$/", $val)){
  3030. }else{
  3031. show_json(0, array('message' => '请按照提示设置独立会员等级折扣' ,'url' => $_SERVER['HTTP_REFERER']) );
  3032. die();
  3033. }
  3034. }
  3035. }
  3036. if($_GPC['is_only_distribution'] == 1 && !empty($_GPC['supply_id']) ){
  3037. //供应商开启同城
  3038. $sup_isopen_localtown_delivery = D('Home/Front')->get_supply_config_by_name('isopen_localtown_delivery',$_GPC['supply_id']);
  3039. if( empty($sup_isopen_localtown_delivery) )
  3040. {
  3041. $supply_name = M('lionfish_comshop_supply')->field('shopname,type')->where( array('id' => $_GPC['supply_id'] ) )->find();
  3042. if($supply_name["type"] == 1 ){
  3043. show_json(0, array('message' => '独立供应商('.$supply_name["shopname"].')没有开启同城配送,此商品无法开启同城配送' ,'url' => $_SERVER['HTTP_REFERER']) );
  3044. die();
  3045. }
  3046. }
  3047. }
  3048. $supply_id = $_GPC['supply_id'];
  3049. if (defined('ROLE') && ROLE == 'agenter' )
  3050. {
  3051. $supper_info = get_agent_logininfo();
  3052. $supply_id = $supper_info['id'];
  3053. }
  3054. if($_GPC['is_only_hexiao'] == 1){
  3055. if(!empty($supply_id)){
  3056. $salesroom_count = M('lionfish_comshop_salesroom')->where( array('supply_id' => $supply_id,'state'=>1 ) )->count();
  3057. if($salesroom_count == 0){
  3058. $supply_name = M('lionfish_comshop_supply')->field('shopname,type')->where( array('id' => $supply_id ) )->find();
  3059. if($supply_name["type"] == 1 ){
  3060. show_json(0, array('message' => '独立供应商('.$supply_name["shopname"].')没有创建门店信息,此商品无法开启到店核销' ,'url' => $_SERVER['HTTP_REFERER']) );
  3061. die();
  3062. }
  3063. }
  3064. }
  3065. if($_GPC['grounding'] == 1){//上架商品
  3066. if($_GPC['hx_expire_type'] == 1){//指定过期时间
  3067. $hx_expire_end_time = $_GPC['hx_expire_end_time'];
  3068. if(strtotime($hx_expire_end_time) < time()){
  3069. show_json(0, array('message' => '核销过期时间小于当前时间,商品不能上架' ,'url' => $_SERVER['HTTP_REFERER']) );
  3070. die();
  3071. }
  3072. }
  3073. }
  3074. if($_GPC['hx_expire_type'] == 1){//指定过期时间
  3075. if($_GPC['hx_auto_off'] == 1){//设置自动下架时间
  3076. if(empty($_GPC['hx_auto_off_time']) || !is_numeric($_GPC['hx_auto_off_time']) || floatval($_GPC['hx_auto_off_time']) <= 0){
  3077. show_json(0, array('message' => '提前自动下架商品时间不能为空且必须为大于0数字' ,'url' => $_SERVER['HTTP_REFERER']) );
  3078. die();
  3079. }
  3080. }
  3081. }
  3082. }
  3083. //礼品卡
  3084. if (isset($_GET['goods_type']) && $_GET['goods_type'] == 'virtualcard')
  3085. {
  3086. $type = 'virtualcard';
  3087. $virtual_code_id = I('post.virtual_code_id');
  3088. if( !isset($virtual_code_id) || $virtual_code_id <= 0 )
  3089. {
  3090. show_json(0, array('message' => '礼品卡商品必须关联兑换码' ,'url' => $_SERVER['HTTP_REFERER']) );
  3091. die();
  3092. }
  3093. }
  3094. //预售时间判断
  3095. if( isset($_GET['goods_type']) && $_GET['goods_type'] == 'presale' )
  3096. {
  3097. //预售时间限制判断
  3098. $time = I('post.time');
  3099. $post_begin_time = strtotime( $time['start'] );
  3100. $post_end_time = strtotime( $time['end'] );
  3101. $presale_ding_time = I('post.presale_ding_time');//定金支付时间
  3102. $presale_ding_time_start = strtotime( $presale_ding_time['start'] ); //开始
  3103. $presale_ding_time_end = strtotime( $presale_ding_time['end'] );//结束
  3104. if($presale_ding_time_start < $post_begin_time )
  3105. {
  3106. show_json(0, array('message' => '预售定金支付开始时间不能小于团购开始时间' ,'url' => $_SERVER['HTTP_REFERER']) );
  3107. die();
  3108. }
  3109. if($presale_ding_time_end > $post_end_time )
  3110. {
  3111. show_json(0, array('message' => '预售定金支付结束时间不能大于团购结束时间' ,'url' => $_SERVER['HTTP_REFERER']) );
  3112. die();
  3113. }
  3114. $presale_sendorder_type = I('post.presale_sendorder_type');
  3115. if($presale_sendorder_type == 1)
  3116. {
  3117. $presale_sendorder_afterday = I('post.presale_sendorder_afterday');
  3118. if( $presale_sendorder_afterday < 1 )
  3119. {
  3120. show_json(0, array('message' => '预售购买后几日发货必须是大于0的整数' ,'url' => $_SERVER['HTTP_REFERER']) );
  3121. die();
  3122. }
  3123. }else if( $presale_sendorder_type == 0 )
  3124. {
  3125. //预计发货时间 必须大于 定金尾款付款时间
  3126. $presale_sendorder_datetime = I('post.presale_sendorder_datetime');
  3127. $presale_sendorder_datetime = strtotime($presale_sendorder_datetime.' 00:00:00');
  3128. if( $presale_sendorder_datetime < $presale_ding_time_start )
  3129. {
  3130. show_json(0, array('message' => '固定发货日期必须大于定金支付开始时间' ,'url' => $_SERVER['HTTP_REFERER']) );
  3131. die();
  3132. }
  3133. }
  3134. }
  3135. //判断预售价格是否合理设置,不是bug价格
  3136. $this->checkPresaleAddGoods();
  3137. D('Seller/Goods')->modify_goods();
  3138. $http_refer = S('HTTP_REFERER');
  3139. $http_refer = empty($http_refer) ? $_SERVER['HTTP_REFERER'] : $http_refer;
  3140. $goods = M('lionfish_comshop_goods')->where('id = "'.I('get.id').'"')->field('goodsname')->find();
  3141. sellerLog('编辑了['.$goods['goodsname'].']商品', 3);
  3142. D('Seller/Operatelog')->addOperateLog('goods','编辑商品--'.$goods['goodsname']);
  3143. show_json(1, array('message'=>'修改商品成功!','url' => $http_refer ));
  3144. }
  3145. //sss
  3146. S('HTTP_REFERER', $_SERVER['HTTP_REFERER']);
  3147. $this->id = $id;
  3148. $item = D('Seller/Goods')->get_edit_goods_info($id);
  3149. //-------------------------以上是获取资料
  3150. $limit_goods = array();
  3151. //limit_goods_list
  3152. if( !empty($item['relative_goods_list']) )
  3153. {
  3154. $item['relative_goods_list'] = unserialize($item['relative_goods_list']);
  3155. if( !empty($item['relative_goods_list']) )
  3156. {
  3157. $relative_goods_list_str = implode(',', $item['relative_goods_list']);
  3158. $limit_goods = M()->query("SELECT id as gid,goodsname,subtitle FROM " . C('DB_PREFIX') .
  3159. 'lionfish_comshop_goods WHERE id in('.$relative_goods_list_str.') order by id desc' );
  3160. foreach($limit_goods as $kk => $vv)
  3161. {
  3162. $thumb = M('lionfish_comshop_goods_images')->where( array('goods_id' => $vv['gid'] ) )->order('id asc')->find();
  3163. $vv['image'] = tomedia($thumb['image']);
  3164. $limit_goods[$kk] = $vv;
  3165. }
  3166. }
  3167. }
  3168. $this->limit_goods = $limit_goods;
  3169. $mb_level_discount_list = array();
  3170. if(!empty($item['mb_level_buy_list'])){
  3171. $item['mb_level_buy_list'] = unserialize($item['mb_level_buy_list']);
  3172. foreach($item['mb_level_buy_list'] as $k=>$v){
  3173. $mb_level_discount_list[$v['level_id']] = $v['discount'];
  3174. }
  3175. }
  3176. $this->mb_level_discount_list = $mb_level_discount_list;
  3177. $category = D('Seller/GoodsCategory')->getFullCategory(true, true);
  3178. $this->category = $category;
  3179. $spec_list = D('Seller/Spec')->get_all_spec();
  3180. $this->spec_list = $spec_list;
  3181. $dispatch_data = M('lionfish_comshop_shipping')->where( array('enabled' => 1, 'isdefault' => 1) )->order('sort_order desc')->select();
  3182. $this->dispatch_data = $dispatch_data;
  3183. $set = D('Seller/Config')->get_all_config();
  3184. $this->set = $set;
  3185. $commission_level = array();
  3186. $config_data = $set;
  3187. $this->config_data = $config_data;
  3188. $default = array('id' => 'default', 'levelname' => empty($config_data['commission_levelname']) ? '默认等级' : $config_data['commission_levelname'], 'commission1' => $config_data['commission1'], 'commission2' => $config_data['commission2'], 'commission3' => $config_data['commission3']);
  3189. //$others = pdo_fetchall('SELECT * FROM ' . tablename('lionfish_comshop_commission_level') . ' WHERE uniacid = \'' . $_W['uniacid'] . '\' ORDER BY commission1 asc');
  3190. //$commission_level = array_merge(array($default), $others);
  3191. $commission_level = array();
  3192. //$level['key']
  3193. foreach($commission_level as $key => $val)
  3194. {
  3195. $val['key'] = $val['id'];
  3196. $commission_level[$key] = $val;
  3197. }
  3198. $shopset_level = empty($set['commiss_level']) ? 0: $set['commiss_level'];
  3199. $this->shopset_level = $shopset_level;
  3200. $open_buy_send_score = empty($set['open_buy_send_score']) ? 0: $set['open_buy_send_score'];
  3201. $this->open_buy_send_score = $open_buy_send_score;
  3202. $delivery_type_express = $config_data['delivery_type_express'];
  3203. if( empty($delivery_type_express) )
  3204. {
  3205. $delivery_type_express = 2;
  3206. }
  3207. $this->delivery_type_express = $delivery_type_express;
  3208. $is_open_fullreduction = $config_data['is_open_fullreduction'];
  3209. $this->is_open_fullreduction = $is_open_fullreduction;
  3210. $community_head_level = M('lionfish_comshop_community_head_level')->order('id asc')->select();
  3211. $head_commission_levelname = $config_data['head_commission_levelname'];
  3212. $default_comunity_money = $config_data['default_comunity_money'];
  3213. $list_default = array(
  3214. array('id' => '0','level'=>0,'levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $default_comunity_money, )
  3215. );
  3216. $community_head_level = array_merge($list_default, $community_head_level);
  3217. $community_head_commission_info = D('Seller/Communityhead')->get_goods_head_level_bili( $id );
  3218. $mb_level = M('lionfish_comshop_member_level')->count();
  3219. $this->mb_level = $mb_level;
  3220. if( !empty($community_head_commission_info) )
  3221. {
  3222. foreach( $community_head_commission_info as $kk => $vv)
  3223. {
  3224. $item[$kk] = $vv;
  3225. }
  3226. }
  3227. //判断是否预售 begin
  3228. if( $item['type'] == 'presale' )
  3229. {
  3230. $goods_presale = M('lionfish_comshop_goods_presale')->where(['goods_id' => $id ])->find();
  3231. if( !empty($goods_presale) )
  3232. {
  3233. unset( $goods_presale['id'] );
  3234. unset( $goods_presale['goods_id'] );
  3235. unset( $goods_presale['addtime'] );
  3236. foreach( $goods_presale as $k => $val )
  3237. {
  3238. $item[ $k ] = $val;
  3239. }
  3240. }
  3241. }
  3242. //end
  3243. //判断是否兑换卡 begin
  3244. if( $item['type'] == 'virtualcard' )
  3245. {
  3246. //商品选中的兑换编组
  3247. $goods_virtualcode_info = D('Seller/VirtualCard')->getGoodsVirtualCardInfoByGoodsId( $id );
  3248. $goods_virtualcode_id = $goods_virtualcode_info['code_id'];
  3249. $this->goods_virtualcode_id = $goods_virtualcode_id;
  3250. //可用的兑换编组列表
  3251. $virtualcard_code_list = D('Seller/VirtualCard')->getCanUseVirtualcardCodes( );
  3252. $this->virtualcard_code_list = $virtualcard_code_list;
  3253. }
  3254. //end
  3255. $this->community_head_commission_info = $community_head_commission_info;
  3256. $this->item = $item;
  3257. $this->community_head_level = $community_head_level;
  3258. //end
  3259. $community_money_type = $config_data['community_money_type'];
  3260. $this->community_money_type = $community_money_type;
  3261. $index_sort_method = D('Home/Front')->get_config_by_name('index_sort_method');
  3262. if( empty($index_sort_method) || $index_sort_method == 0 )
  3263. {
  3264. $index_sort_method = 0;
  3265. }
  3266. $this->index_sort_method = $index_sort_method;
  3267. $is_open_only_express = $config_data['is_open_only_express'];
  3268. $this->is_open_only_express = $is_open_only_express;
  3269. $is_open_goods_relative_goods = $config_data['is_open_goods_relative_goods'];
  3270. $this->is_open_goods_relative_goods = $is_open_goods_relative_goods;
  3271. //获取会员等级列表
  3272. $member_level_ist = M('lionfish_comshop_member_level')->order('id asc')->select();
  3273. //供应商权限begin
  3274. $is_index = true;
  3275. $is_top = true;
  3276. $is_updown = true;
  3277. $is_fullreduce = true;
  3278. $is_vir_count = true;
  3279. $is_newbuy = true;
  3280. $is_goodsspike = true;
  3281. $supply_can_goods_sendscore = true;
  3282. $supply_can_distribution_sale = 1;
  3283. $sales_supply_id = 0;
  3284. if (defined('ROLE') && ROLE == 'agenter' )
  3285. {
  3286. $supply_can_goods_sendscore = empty($config_data['supply_can_goods_sendscore']) ? 0: $config_data['supply_can_goods_sendscore'];
  3287. $supply_can_distribution_sale = empty($config_data['supply_can_distribution_sale']) ? 0: $config_data['supply_can_distribution_sale'];
  3288. $is_fullreduce = false;
  3289. if( isset($config_data['supply_can_goods_isindex']) && $config_data['supply_can_goods_isindex'] == 2 )
  3290. {
  3291. $is_index = false;
  3292. }
  3293. if( isset($config_data['supply_can_goods_istop']) && $config_data['supply_can_goods_istop'] == 2 )
  3294. {
  3295. $is_top = false;
  3296. }
  3297. if( isset($config_data['supply_can_goods_updown']) && $config_data['supply_can_goods_updown'] == 2 )
  3298. {
  3299. $is_updown = false;
  3300. }
  3301. if( isset($config_data['supply_can_vir_count']) && $config_data['supply_can_vir_count'] == 2 )
  3302. {
  3303. $is_vir_count = false;
  3304. }
  3305. if( isset($config_data['supply_can_goods_newbuy']) && $config_data['supply_can_goods_newbuy'] == 2 )
  3306. {
  3307. $is_newbuy = false;
  3308. }
  3309. if( isset($config_data['supply_can_goods_spike']) && $config_data['supply_can_goods_spike'] == 2 )
  3310. {
  3311. $is_goodsspike = false;
  3312. }
  3313. $sales_supply_id = $supper_info = get_agent_logininfo();
  3314. $sales_supply_id = $supper_info['id'];
  3315. }
  3316. $salesroom_count = M('lionfish_comshop_salesroom')->where(array('supply_id' => $sales_supply_id,'state'=>1))->count();
  3317. if($salesroom_count > 0){
  3318. $this->is_exist_salesroom = 1;
  3319. }
  3320. $is_open_vipcard_buy = $config_data['is_open_vipcard_buy'];
  3321. $seckill_is_open = $config_data['seckill_is_open'];
  3322. $is_head_takegoods = isset($config_data['is_head_takegoods']) && $config_data['is_head_takegoods'] == 1 ? 1 : 0;
  3323. $isopen_localtown_delivery = isset($config_data['isopen_localtown_delivery']) && $config_data['isopen_localtown_delivery'] == 1 ? 1 : 0;
  3324. $this->isopen_localtown_delivery = $isopen_localtown_delivery;
  3325. $salesroom_count = 0;
  3326. $this->salesroom_count = $salesroom_count;
  3327. //供应商权限end
  3328. $this->supply_can_goods_sendscore = $supply_can_goods_sendscore;
  3329. $this->supply_can_distribution_sale = $supply_can_distribution_sale;
  3330. $this->is_index = $is_index;
  3331. $this->is_top = $is_top;
  3332. $this->is_updown = $is_updown;
  3333. $this->is_fullreduce = $is_fullreduce;
  3334. $this->is_vir_count = $is_vir_count;
  3335. $this->is_newbuy = $is_newbuy;
  3336. $this->is_goodsspike = $is_goodsspike;
  3337. $this->is_open_vipcard_buy = $is_open_vipcard_buy;
  3338. $this->seckill_is_open = $seckill_is_open;
  3339. $this->is_head_takegoods = $is_head_takegoods;
  3340. $this->member_level_is_open_info = D('Home/Front')->get_config_by_name('member_level_is_open');
  3341. $this->member_level_ist = $member_level_ist;
  3342. //$is_default_levellimit_buy = isset($config_data['is_default_levellimit_buy']) && $config_data['is_default_levellimit_buy'] == 1 ? 1 : 0;
  3343. //$this->is_default_levellimit_buy = $is_default_levellimit_buy;
  3344. //$is_default_vipmember_buy = isset($config_data['is_default_vipmember_buy']) && $config_data['is_default_vipmember_buy'] == 1 ? 1 : 0;
  3345. //$this->is_default_vipmember_buy = $is_default_vipmember_buy;
  3346. $isopen_localtown_delivery = isset($config_data['isopen_localtown_delivery']) && $config_data['isopen_localtown_delivery'] == 1 ? 1 : 0;
  3347. $this->isopen_localtown_delivery = $isopen_localtown_delivery;
  3348. $supply_is_open_localtown_distribution = isset($config_data['supply_is_open_localtown_distribution']) && $config_data['supply_is_open_localtown_distribution'] == 1 ? 1 : 0;
  3349. $this->supply_is_open_localtown_distribution = $supply_is_open_localtown_distribution;
  3350. if( $item['type'] == 'presale' )
  3351. {
  3352. $this->display('Presale/addgoods');
  3353. }
  3354. else if( $item['type'] == 'virtualcard' )
  3355. {
  3356. $this->display('Virtualcard/addgoods');
  3357. }
  3358. else{
  3359. $this->display('Goods/addgoods');
  3360. }
  3361. }
  3362. public function labelfile()
  3363. {
  3364. $_GPC = I('request.');
  3365. $id = intval($_GPC['id']);
  3366. if (empty($id)) {
  3367. show_json(0, array() );
  3368. die();
  3369. }
  3370. $condition = ' id = '.$id.' and state = 1 ';
  3371. $labels = M('lionfish_comshop_goods_tags')->field('id,tagname,type,tagcontent')->where($condition)->find();
  3372. if (empty($labels)) {
  3373. $labels = array();
  3374. show_json(0, array('msg' => '您查找的标签不存在或已删除!') );
  3375. die();
  3376. }
  3377. show_json(1, array('label' => $labels['tagname'], 'id' => $labels['id']));
  3378. }
  3379. public function goodstag()
  3380. {
  3381. $_GPC = I('request.');
  3382. $this->gpc = $_GPC;
  3383. $condition = ' 1 and tag_type="normal" ';
  3384. $pindex = max(1, intval($_GPC['page']));
  3385. $psize = 20;
  3386. if ($_GPC['enabled'] != '') {
  3387. $condition .= ' and state=' . intval($_GPC['enabled']);
  3388. }
  3389. if (!empty($_GPC['keyword'])) {
  3390. $_GPC['keyword'] = trim($_GPC['keyword']);
  3391. $condition .= ' and tagname like "%'.$_GPC['keyword'].'%" ';
  3392. }
  3393. $label = M('lionfish_comshop_goods_tags')->where( $condition )->order(' id asc ')->limit( (($pindex - 1) * $psize) . ',' . $psize )->select();
  3394. $total = M('lionfish_comshop_goods_tags')->where( $condition )->count();
  3395. $pager = pagination2($total, $pindex, $psize);
  3396. $this->label = $label;
  3397. $this->pager = $pager;
  3398. $this->display();
  3399. }
  3400. function copy_goods(){
  3401. $id =I('id');
  3402. $model=new GoodsModel();
  3403. if($id){
  3404. foreach ($id as $k => $v) {
  3405. $model->copy_goods($v);
  3406. }
  3407. $data['redirect']=U('Goods/index');
  3408. $this->ajaxReturn($data);
  3409. die;
  3410. }
  3411. }
  3412. function del(){
  3413. $model=new GoodsModel();
  3414. $return=$model->del_goods(I('get.id'));
  3415. $this->osc_alert($return);
  3416. }
  3417. /**
  3418. * 置顶
  3419. * @return [json] 0 失败 1 成功
  3420. */
  3421. public function settop()
  3422. {
  3423. $id = I('request.id');
  3424. //ids
  3425. if (empty($id)) {
  3426. $ids = I('request.ids');
  3427. $id = ((is_array($ids) ? implode(',', $ids) : 0));
  3428. }
  3429. if (empty($id)) {
  3430. show_json(0, array('message' => '参数错误'));
  3431. }
  3432. $type = I('request.type');
  3433. $value = I('request.value');
  3434. if ($type != 'istop') {
  3435. show_json(0, array('message' => '参数错误'));
  3436. }
  3437. $items = M('lionfish_comshop_goods')->field('id')->where( 'id in( ' . $id . ' )' )->select();
  3438. foreach ($items as $item ) {
  3439. $settoptime = $value ? time() : '';
  3440. M('lionfish_comshop_goods')->where( array('id' => $item['id']) )->save( array($type => $value, 'settoptime' => $settoptime) );
  3441. }
  3442. show_json(1, array('url' => $_SERVER['HTTP_REFERER'] ));
  3443. }
  3444. public function industrial()
  3445. {
  3446. $_GPC = I('request.');
  3447. if ( IS_POST ) {
  3448. $data = ((is_array($_GPC['parameter']) ? $_GPC['parameter'] : array()));
  3449. $data['goods_industrial'] = serialize($data['goods_industrial']);
  3450. D('Seller/Config')->update($data);
  3451. D('Seller/Operatelog')->addOperateLog('goods','修改商品设置--工商资质');
  3452. show_json(1, array('url' => $_SERVER['HTTP_REFERER'] ));
  3453. }
  3454. $data = D('Seller/Config')->get_all_config();
  3455. $data['goods_industrial'] = unserialize($data['goods_industrial']);
  3456. $piclist = array();
  3457. if( !empty($data['goods_industrial']) )
  3458. {
  3459. foreach($data['goods_industrial'] as $val)
  3460. {
  3461. $piclist[] = array('image' =>$val, 'thumb' => tomedia($val) ); //$val['image'];
  3462. }
  3463. }
  3464. $this->piclist = $piclist;
  3465. $this->data = $data;
  3466. $this->display();
  3467. }
  3468. /**
  3469. * excel商品导入编辑
  3470. * @author liu 2020-03-03
  3471. * */
  3472. public function excel_goodslist_edit()
  3473. {
  3474. $columns = array(
  3475. array(
  3476. 'title' => '商品ID(禁止修改)',
  3477. 'field' => 'id',
  3478. 'width' => 24
  3479. ) ,
  3480. array(
  3481. 'title' => '商品名称',
  3482. 'field' => 'goodsname',
  3483. 'width' => 24
  3484. ) ,
  3485. array(
  3486. 'title' => '一级分类ID',
  3487. 'field' => 'cate1_id',
  3488. 'width' => 24
  3489. ) ,
  3490. array(
  3491. 'title' => '一级分类名称',
  3492. 'field' => 'cate1_name',
  3493. 'width' => 24
  3494. ) ,
  3495. array(
  3496. 'title' => '二级分类ID',
  3497. 'field' => 'cate2_id',
  3498. 'width' => 24
  3499. ) ,
  3500. array(
  3501. 'title' => '二级分类名称',
  3502. 'field' => 'cate2_name',
  3503. 'width' => 24
  3504. ) ,
  3505. array(
  3506. 'title' => '商品价格',
  3507. 'field' => 'price',
  3508. 'width' => 24
  3509. ) ,
  3510. array(
  3511. 'title' => '商品成本价',
  3512. 'field' => 'costprice',
  3513. 'width' => 24
  3514. ) ,
  3515. array(
  3516. 'title' => '会员卡价格',
  3517. 'field' => 'card_price',
  3518. 'width' => 24
  3519. ) ,
  3520. array(
  3521. 'title' => '商品原价',
  3522. 'field' => 'productprice',
  3523. 'width' => 24
  3524. ) ,
  3525. array(
  3526. 'title' => '商品库存',
  3527. 'field' => 'total',
  3528. 'width' => 24
  3529. ) ,
  3530. array(
  3531. 'title' => '1上架/0下架',
  3532. 'field' => 'grounding',
  3533. 'width' => 24
  3534. ) ,
  3535. array(
  3536. 'title' => '首页推荐(0:取消/1:是)',
  3537. 'field' => 'is_index_show',
  3538. 'width' => 24
  3539. ) ,
  3540. array(
  3541. 'title' => '限时秒杀(0:取消/1:是)',
  3542. 'field' => 'is_spike_buy',
  3543. 'width' => 24
  3544. ) ,
  3545. array(
  3546. 'title' => '所有团长',
  3547. 'field' => 'is_all_sale_str',
  3548. 'width' => 24
  3549. ) ,
  3550. array(
  3551. 'title' => '新人专享',
  3552. 'field' => 'is_new_buy',
  3553. 'width' => 24
  3554. ) ,
  3555. array(
  3556. 'title' => '商品排序(数字)',
  3557. 'field' => 'index_sort',
  3558. 'width' => 24
  3559. ) ,
  3560. array(
  3561. 'title' => '每天限购',
  3562. 'field' => 'oneday_limit_count',
  3563. 'width' => 24
  3564. ) ,
  3565. array(
  3566. 'title' => '单次限购',
  3567. 'field' => 'one_limit_count',
  3568. 'width' => 24
  3569. ) ,
  3570. array(
  3571. 'title' => '历史限购',
  3572. 'field' => 'total_limit_count',
  3573. 'width' => 24
  3574. ) ,
  3575. array(
  3576. 'title' => '开始时间',
  3577. 'field' => 'pin_begin_time',
  3578. 'width' => 24
  3579. ) ,
  3580. array(
  3581. 'title' => '结束时间',
  3582. 'field' => 'pin_end_time',
  3583. 'width' => 24
  3584. ) ,
  3585. array(
  3586. 'title' => '商品重量(单位:g)',
  3587. 'field' => 'weight',
  3588. 'width' => 24
  3589. ) ,
  3590. array(
  3591. 'title' => '规格(1:开启/0:关闭)',
  3592. 'field' => 'hasoption',
  3593. 'width' => 24
  3594. ) ,
  3595. array(
  3596. 'title' => '规格id(禁止修改)',
  3597. 'field' => 'option_id',
  3598. 'width' => 24
  3599. ) ,
  3600. array(
  3601. 'title' => '规格名称(禁止修改)',
  3602. 'field' => 'option_title',
  3603. 'width' => 24
  3604. ) ,
  3605. array(
  3606. 'title' => '规格库存',
  3607. 'field' => 'option_stock',
  3608. 'width' => 24
  3609. ) ,
  3610. array(
  3611. 'title' => '规格现价',
  3612. 'field' => 'option_marketprice',
  3613. 'width' => 24
  3614. ) ,
  3615. array(
  3616. 'title' => '规格原价',
  3617. 'field' => 'option_productprice',
  3618. 'width' => 24
  3619. ) ,
  3620. array(
  3621. 'title' => '规格会员价',
  3622. 'field' => 'option_card_price',
  3623. 'width' => 24
  3624. ) ,
  3625. array(
  3626. 'title' => '规格成本价',
  3627. 'field' => 'option_costprice',
  3628. 'width' => 24
  3629. ) ,
  3630. array(
  3631. 'title' => '规格编码',
  3632. 'field' => 'option_goodssn',
  3633. 'width' => 24
  3634. ) ,
  3635. array(
  3636. 'title' => '规格重量(单位:g)',
  3637. 'field' => 'option_weight',
  3638. 'width' => 24
  3639. )
  3640. );
  3641. sellerLog('导入商品excel编辑', 3);
  3642. $rows = D('Seller/Excel')->import('excel');
  3643. $row_count = count($rows);
  3644. $field_arr = [];
  3645. if($row_count <= 1){
  3646. $this->error('失败','goods/index');
  3647. die;
  3648. }
  3649. foreach($rows[0] as $key => $value) {
  3650. foreach($columns as $k => $val) {
  3651. if($val['title'] == $value){
  3652. $field_arr[$key]= $val['field'];
  3653. }
  3654. }
  3655. }
  3656. unset($rows[0]);
  3657. foreach($rows as $key => $value){
  3658. $this->excelGoodsUpdate($value, $field_arr);
  3659. }
  3660. $this->success('成功','goods/index');
  3661. }
  3662. public function excelGoodsUpdate($data, $field_arr)
  3663. {
  3664. $optionId = 0;
  3665. $goodsId = 0;
  3666. $goodsData = [];
  3667. $optionData = [];
  3668. foreach($data as $key => $value){
  3669. $field = $field_arr[$key];
  3670. if(strstr($field, 'option_') > -1 && $value){// 规格
  3671. if($field == 'option_id'){// 规格id
  3672. $optionId = $value;
  3673. $goodsData = [];
  3674. }
  3675. $optionData[str_replace('option_','',$field)] = $value;
  3676. $goodsId = 0;
  3677. }else{ // 普通商品数据
  3678. if(strstr($field, 'option_') > -1 ) {// 规格
  3679. continue;
  3680. }
  3681. if($field == 'id'){// 规格id
  3682. $goodsId = $value;
  3683. $optionData = [];
  3684. }
  3685. $optionId = 0;
  3686. $goodsData[$field] = $value;
  3687. }
  3688. }
  3689. if($optionId > 0 && count($optionData) > 0){
  3690. unset($optionData['title']);
  3691. unset($optionData['id']);
  3692. M('lionfish_comshop_goods_option_item_value')->where('id = "'.$optionId.'"')->save($optionData);
  3693. unset($optionData);
  3694. }else if($goodsId > 0 && count($goodsData) > 0){
  3695. unset($goodsData['is_all_sale_str']);
  3696. unset($goodsData['cate1_id']);
  3697. unset($goodsData['cate1_name']);
  3698. unset($goodsData['cate2_id']);
  3699. unset($goodsData['cate2_name']);
  3700. unset($goodsData['id']);
  3701. $goodsCommon = M('lionfish_comshop_good_common')->where('goods_id = "'.$goodsId.'"')->field('id')->find();
  3702. if($goodsCommon['id']){
  3703. M('lionfish_comshop_good_common')
  3704. ->where('id = "'.$goodsCommon['id'].'"')
  3705. ->save([
  3706. 'one_limit_count' => $goodsData['one_limit_count'],
  3707. 'total_limit_count' => $goodsData['total_limit_count'],
  3708. 'is_spike_buy' => $goodsData['is_spike_buy'],
  3709. 'is_new_buy' => $goodsData['is_new_buy'],
  3710. ]);
  3711. unset($goodsData['one_limit_count']);
  3712. unset($goodsData['total_limit_count']);
  3713. unset($goodsData['is_spike_buy']);
  3714. unset($goodsData['is_new_buy']);
  3715. }
  3716. $goodsPin = M('lionfish_comshop_good_pin')->where('goods_id = "'.$goodsId.'"')->field('id')->find();
  3717. if($goodsPin['id']){
  3718. M('lionfish_comshop_good_pin')
  3719. ->where('id = "'.$goodsPin['id'].'"')
  3720. ->save([
  3721. 'begin_time' => $goodsData['begin_time'],
  3722. 'end_time' => $goodsData['end_time'],
  3723. ]);
  3724. unset($goodsData['begin_time']);
  3725. unset($goodsData['end_time']);
  3726. }
  3727. M('lionfish_comshop_goods')
  3728. ->where('id = "'.$goodsId.'"')
  3729. ->save($goodsData);
  3730. unset($goodsData);
  3731. }
  3732. }
  3733. public function check_express(){
  3734. $result = array();
  3735. $pintuan_model_buy = D('Home/Front')->get_config_by_name('pintuan_model_buy');
  3736. $count = 0;
  3737. $sql = " select count(1) as count from ".C('DB_PREFIX')."lionfish_comshop_goods as g left join ".C('DB_PREFIX')."lionfish_comshop_good_common as gc "
  3738. . " on g.id = gc.goods_id where g.type = 'normal' AND g.grounding =1 AND gc.is_only_express =1";
  3739. $goods_list = M()->query( $sql );
  3740. if(!empty($goods_list)){
  3741. $count = $goods_list[0]['count'];
  3742. }
  3743. if($count > 0 || $pintuan_model_buy == 0){
  3744. $result['status'] = 1;
  3745. }else{
  3746. $result['status'] = 0;
  3747. }
  3748. echo json_encode($result);
  3749. }
  3750. //部分团长列表
  3751. public function goods_head(){
  3752. $condition = ' ';
  3753. $pindex = I('get.page',1);
  3754. $psize = 20;
  3755. $goods_id = I('get.id');
  3756. $goods_info = M('lionfish_comshop_goods')->where(array('id'=>$goods_id))->field('id,goodsname,is_all_sale')->find();
  3757. $keyword = I('get.keyword','');
  3758. $this->keyword = $keyword;
  3759. if (!empty($keyword)) {
  3760. $condition .= ' and ( m.username like '.'"%' . $keyword . '%"'.' or ch.community_name like '.'"%' . $keyword . '%"'.' or ch.head_name like '.'"%' . $keyword . '%"'.' or ch.head_mobile like '.'"%' . $keyword . '%"'.' or ch.address like '.'"%' . $keyword . '%"'.') ';
  3761. }
  3762. $condition .= ' and hg.goods_id='.$goods_id;
  3763. $sql = "SELECT ch.*,m.we_openid,m.username,m.avatar,hg.id as hg_id FROM " . C('DB_PREFIX') . "lionfish_community_head as ch "
  3764. . " left join ".C('DB_PREFIX')."lionfish_comshop_member as m on ch.member_id = m.member_id "
  3765. . ' left join '.C('DB_PREFIX')."lionfish_community_head_goods as hg on hg.head_id = ch.id "
  3766. . " WHERE 1 " . $condition . " order by ch.id desc ";
  3767. if (empty($export)) {
  3768. $sql .= ' limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  3769. }
  3770. $list = M()->query($sql);
  3771. $sql_count = 'SELECT count(1) as total FROM ' . C('DB_PREFIX') . 'lionfish_community_head as ch '
  3772. . ' left join '.C('DB_PREFIX').'lionfish_comshop_member as m on ch.member_id = m.member_id '
  3773. . ' left join '. C('DB_PREFIX').'lionfish_community_head_goods as hg on hg.head_id = ch.id '
  3774. . ' WHERE 1 ' . $condition;
  3775. $total_arr = M()->query($sql_count);
  3776. $total = $total_arr[0]['total'];
  3777. $pager = pagination2($total, $pindex, $psize);
  3778. $this->goods_info = $goods_info;
  3779. $this->pager = $pager;
  3780. $this->list = $list;
  3781. $this->display('goods_communityhead');
  3782. }
  3783. public function cancel_goods_head(){
  3784. $_GPC = I('request.');
  3785. $id = intval($_GPC['id']);
  3786. $goods_id = intval($_GPC['goods_id']);
  3787. M('lionfish_community_head_goods')->where( array('id' => $id) )->delete();
  3788. show_json(1, array('url' => U('goods/goods_head/id/'.$goods_id)));
  3789. }
  3790. public function all_goods_head(){
  3791. $_GPC = I('request.');
  3792. $goods_id = intval($_GPC['goods_id']);
  3793. M('lionfish_comshop_goods')->where( array('id' => $goods_id) )->save(array('is_all_sale'=>1));
  3794. show_json(1, array('url' => U('goods/index/ok/1')));
  3795. }
  3796. public function copy(){
  3797. // echo 7777;die;
  3798. $data = I('request.');
  3799. $id = $data['id'];
  3800. $res = M('lionfish_comshop_goods')->where(['id'=>$id])->find();
  3801. isset($res['copy_times'])?$res['copy_times']:0;
  3802. $copy_times = $res['copy_times'];
  3803. M('lionfish_comshop_goods')->where(['id'=>$id])->setInc('copy_times');
  3804. //dump($copy_times);
  3805. if ($copy_times>0){
  3806. $copy_times = $copy_times+1;
  3807. $str = '00'.$copy_times;
  3808. }else{
  3809. $str = '001';
  3810. }
  3811. unset($res['id']);
  3812. unset($res['copy_times']);
  3813. $res['goodsname'] = $res['goodsname'].$str;
  3814. //销量设置0
  3815. $res['sales'] = 0;
  3816. $res['seller_count'] = 0;
  3817. $res['day_salescount'] = 0;
  3818. $goods_id = M('lionfish_comshop_goods')->add($res);
  3819. // $goods_id = 385; //to delete
  3820. $cate = M('lionfish_comshop_goods_to_category')->where(['goods_id'=>$id])->select();
  3821. //dump($cate);
  3822. foreach ($cate as $k=>$v){
  3823. $tmp['cate_id'] = $v['cate_id'];
  3824. $tmp['goods_id'] = $goods_id;
  3825. M('lionfish_comshop_goods_to_category')->add($tmp);
  3826. }
  3827. $goods_common = M('lionfish_comshop_good_common')->where(['goods_id'=>$id])->find();
  3828. unset($goods_common['id']);
  3829. $goods_common['goods_id'] = $goods_id;
  3830. // $goods_common['goods_id'] = 385;
  3831. M('lionfish_comshop_good_common')->add($goods_common);
  3832. $option = M('lionfish_comshop_goods_option')->where(['goods_id'=>$id])->select();
  3833. if ( count($option)) {
  3834. foreach ($option as $k => $v) {//循环规格: 颜色 尺寸
  3835. $front_goods_option_id = $v['id'];
  3836. unset($v['id']);
  3837. $v['goods_id'] = $goods_id;
  3838. //dump($v);
  3839. $goods_option_id = M('lionfish_comshop_goods_option')->add($v);
  3840. $option_item = M('lionfish_comshop_goods_option_item')->where(['goods_option_id' => $front_goods_option_id])->select();
  3841. // dump($option_item);die;
  3842. static $i = 0;
  3843. foreach ($option_item as $kk => $vv) { //循环单个规格的选项,颜色有蓝色,绿色。。。
  3844. unset($vv['id']);
  3845. $vv['goods_id'] = $goods_id;
  3846. $vv['goods_option_id'] = $goods_option_id;
  3847. $ids[$i][] = M('lionfish_comshop_goods_option_item')->add($vv);
  3848. }
  3849. $i++;
  3850. }
  3851. $ids = $this->resver_arr($ids);
  3852. $ids = $this->zuhe($ids);
  3853. //dump($ids);die;
  3854. $j = 0;
  3855. $option_item_value = M('lionfish_comshop_goods_option_item_value')->where(['goods_id' => $id])->select();
  3856. foreach ($option_item_value as $key => $value) {
  3857. unset($value['id']);
  3858. $value['option_item_ids'] = $ids[0][$j++];
  3859. $value['goods_id'] = $goods_id;
  3860. M('lionfish_comshop_goods_option_item_value')->add($value);
  3861. }
  3862. }
  3863. $imgs = M('lionfish_comshop_goods_images')->where(['goods_id'=>$id])->select();
  3864. foreach ($imgs as $v){
  3865. unset($v['id']);
  3866. $v['goods_id'] = $goods_id;
  3867. M('lionfish_comshop_goods_images')->add($v);
  3868. }
  3869. D('Seller/Redisorder')->sysnc_goods_total($goods_id);
  3870. $url = U("goods/edit/id/$goods_id");
  3871. echo json_encode(['code'=>1,'url'=>$url]);
  3872. }
  3873. function zuhe($arr){
  3874. if(count($arr) >= 2){
  3875. $tmparr = array();
  3876. $arr1 = array_shift($arr);
  3877. $arr2 = array_shift($arr);
  3878. foreach($arr1 as $k1 => $v1){
  3879. foreach($arr2 as $k2 => $v2){
  3880. $tmparr[] = $v2.'_'.$v1;
  3881. }
  3882. }
  3883. array_unshift($arr, $tmparr);
  3884. $arr = $this->zuhe($arr);
  3885. }else{
  3886. return $arr;
  3887. }
  3888. return $arr;
  3889. }
  3890. function resver_arr($arr){
  3891. $len = count($arr);
  3892. $i = $len - 1;
  3893. foreach($arr as $k=>$v){
  3894. $tmp[$i--] = $v;
  3895. }
  3896. ksort($tmp);
  3897. return $tmp;
  3898. }
  3899. }
  3900. ?>