OrderController.class.php 176 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Seller\Controller;
  15. use Admin\Model\OrderModel;
  16. class OrderController extends CommonController{
  17. protected function _initialize(){
  18. parent::_initialize();
  19. }
  20. public function index(){
  21. $time = I('request.time');
  22. $s_time_start = I('request.time_start');
  23. $s_time_end = I('request.time_end');
  24. //var_dump($s_time,2);die();
  25. if( isset($s_time_start) && !empty($s_time_start) )
  26. {
  27. $time['start'] = $s_time_start;
  28. $time['end'] = $s_time_end;
  29. }
  30. $starttime = isset($time['start']) ? strtotime($time['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  31. $endtime = isset($time['end']) ? strtotime($time['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  32. $this->searchfield = I('request.searchfield','');
  33. $this->keyword = I('request.keyword','');
  34. $this->searchtime = I('request.searchtime','');
  35. $this->delivery = I('request.delivery','');
  36. $this->starttime = $starttime;
  37. $this->endtime = $endtime;
  38. $this->time = $time;
  39. //重置缓存
  40. $day_time = strtotime( date('Y-m-d '.'00:00:00') );
  41. $day_key = 'new_ordernotice_'.$day_time;
  42. S( $day_key, array() );
  43. $order_status_id = I('request.order_status_id',0);
  44. $order_status_arr = D('Seller/Order')->get_order_status_name();
  45. $this->order_status_arr = $order_status_arr;
  46. $is_soli_type = I('request.type', '');// isset($_GPC['type']) && $_GPC['type'] == 'soli' ? 1: 0;
  47. $is_soli = 0;
  48. if($is_soli_type == 'soli')
  49. {
  50. $is_soli = 1;
  51. }
  52. //soli
  53. $_GPC['is_soli'] = $is_soli;
  54. $_GET['type'] = 'normal';
  55. $is_presale_order = 0;
  56. if( isset($_GET['presale_order']) && $_GET['presale_order'] == 1 )
  57. {
  58. $is_presale_order = 1;
  59. }
  60. $is_virtualcard_order = 0;
  61. if( isset($_GET['virtualcard_order']) && $_GET['virtualcard_order'] == 1 )
  62. {
  63. $is_virtualcard_order = 1;
  64. }
  65. $this->is_soli = $is_soli;
  66. $this->is_presale_order = $is_presale_order;
  67. $this->is_virtualcard_order = $is_virtualcard_order;
  68. $need_data = D('Seller/Order')->load_order_list();
  69. $cur_controller = 'order/index';
  70. $total = $need_data['total'];
  71. $total_money = $need_data['total_money'];
  72. $list = $need_data['list'];
  73. $pager = $need_data['pager'];
  74. $all_count = $need_data['all_count'];
  75. $count_status_1 = $need_data['count_status_1'];
  76. $count_status_3 = $need_data['count_status_3'];
  77. $count_status_4 = $need_data['count_status_4'];
  78. $count_status_5 = $need_data['count_status_5'];
  79. $count_status_7 = $need_data['count_status_7'];
  80. $count_status_11 = $need_data['count_status_11'];
  81. $count_status_14 = $need_data['count_status_14'];
  82. $count_status_express = $need_data['count_status_express'];
  83. $this->cur_controller = $cur_controller;
  84. $this->total = $total;
  85. $this->total_money = $total_money;
  86. $this->list = $list;
  87. $this->pager = $pager;
  88. $this->all_count = $all_count;
  89. $this->count_status_1 = $count_status_1;
  90. $this->count_status_3 = $count_status_3;
  91. $this->count_status_4 = $count_status_4;
  92. $this->count_status_5 = $count_status_5;
  93. $this->count_status_7 = $count_status_7;
  94. $this->count_status_11 = $count_status_11;
  95. $this->count_status_14 = $count_status_14;
  96. $this->count_status_express = $count_status_express;
  97. $this->order_status_id = $order_status_id;
  98. $this->is_community = I('request.is_community', 0);
  99. $this->headid = I('request.headid', 0);
  100. $open_feier_print = D('Home/Front')->get_config_by_name('open_feier_print');
  101. if( empty($open_feier_print) )
  102. {
  103. $open_feier_print = 0;
  104. }
  105. if (defined('ROLE') && ROLE == 'agenter' )
  106. {
  107. $is_open_supply_print = D('Home/Front')->get_config_by_name('is_open_supply_print' );
  108. if( empty($is_open_supply_print) )
  109. {
  110. $open_feier_print = 0;
  111. }else{
  112. $supper_info = get_agent_logininfo();
  113. $open_feier_print = D('Home/Front')->get_config_by_name('open_feier_print'.$supper_info['id'] );
  114. if( empty($open_feier_print) )
  115. {
  116. $open_feier_print = 0;
  117. }
  118. }
  119. }
  120. $this->open_feier_print = $open_feier_print;
  121. $is_can_look_headinfo = true;
  122. $is_can_nowrfund_order = true;
  123. $is_can_confirm_delivery = true;
  124. $is_can_confirm_receipt = true;
  125. $is_can_third_delivery = true;
  126. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  127. $supply_can_nowrfund_order = D('Home/Front')->get_config_by_name('supply_can_nowrfund_order');
  128. $supply_can_confirm_delivery = D('Home/Front')->get_config_by_name('supply_can_confirm_delivery');
  129. $supply_can_confirm_receipt = D('Home/Front')->get_config_by_name('supply_can_confirm_receipt');
  130. $supply_third_delivery_service = D('Home/Front')->get_config_by_name('supply_third_delivery_service');
  131. if (defined('ROLE') && ROLE == 'agenter' )
  132. {
  133. if( isset($supply_can_look_headinfo) && $supply_can_look_headinfo == 2 )
  134. {
  135. $is_can_look_headinfo = false;
  136. }
  137. if( isset($supply_can_nowrfund_order) && $supply_can_nowrfund_order == 2 )
  138. {
  139. $is_can_nowrfund_order = false;
  140. }
  141. if( isset($supply_can_confirm_delivery) && $supply_can_confirm_delivery == 2 )
  142. {
  143. $is_can_confirm_delivery = false;
  144. }
  145. if( isset($supply_can_confirm_receipt) && $supply_can_confirm_receipt == 2 )
  146. {
  147. $is_can_confirm_receipt = false;
  148. }
  149. }
  150. if( isset($supply_third_delivery_service) && $supply_third_delivery_service == 1){
  151. $is_can_third_delivery = true;
  152. }else{
  153. $is_can_third_delivery = false;
  154. }
  155. $s_id = 1 ;
  156. if(SELLERUID != 1)
  157. {
  158. $seller_info = M('seller')->field('s_role_id')->where( array('s_id' => SELLERUID ) )->find();
  159. $perms_arr = M('lionfish_comshop_perm_role')->where( array('id' => $seller_info['s_role_id']) )->find();
  160. $perms1 = str_replace('.','/',$perms_arr['perms2']);
  161. $perms2 = explode(",", $perms1);
  162. if(in_array("user/user/index", $perms2)){
  163. $s_id = 1 ;
  164. } else {
  165. $s_id = 0 ;
  166. }
  167. }
  168. $this->s_id = $s_id;
  169. $is_localtown_imdada_status = D('Home/Front')->get_config_by_name('is_localtown_imdada_status');
  170. $is_localtown_sf_status = D('Home/Front')->get_config_by_name('is_localtown_sf_status');
  171. //是否开启蜂鸟即配
  172. $is_localtown_ele_status = D('Home/Front')->get_config_by_name('is_localtown_ele_status');
  173. $is_localtown_ele_status = isset($is_localtown_ele_status) ? $is_localtown_ele_status : 0;
  174. //是否开启码科配送
  175. $is_localtown_mk_status = D('Home/Front')->get_config_by_name('is_localtown_mk_status');
  176. $is_localtown_mk_status = isset($is_localtown_mk_status) ? $is_localtown_mk_status : 0;
  177. //码科预览价格
  178. $is_make_prequery_status = D('Home/Front')->get_config_by_name('is_make_prequery_status');
  179. $is_make_prequery_status = isset($is_make_prequery_status) ? $is_make_prequery_status : 0;
  180. $is_imdada_prequery_status = D('Home/Front')->get_config_by_name('is_imdada_prequery_status');
  181. $is_sf_prequery_status = D('Home/Front')->get_config_by_name('is_sf_prequery_status');
  182. $localtown_modifypickingname = D('Home/Front')->get_config_by_name('localtown_modifypickingname');
  183. $localtown_modifypickingname = !empty($localtown_modifypickingname) ? $localtown_modifypickingname: '包装费';
  184. $this->is_can_look_headinfo = $is_can_look_headinfo;
  185. $this->is_can_nowrfund_order = $is_can_nowrfund_order;
  186. $this->is_can_confirm_delivery = $is_can_confirm_delivery;
  187. $this->is_can_confirm_receipt = $is_can_confirm_receipt;
  188. $this->is_localtown_imdada_status = $is_localtown_imdada_status;
  189. $this->is_localtown_sf_status = $is_localtown_sf_status;
  190. $this->is_localtown_mk_status = $is_localtown_mk_status;
  191. $this->is_localtown_ele_status = $is_localtown_ele_status;
  192. $this->is_make_prequery_status = $is_make_prequery_status;
  193. $this->localtown_modifypickingname = $localtown_modifypickingname;
  194. $this->is_can_third_delivery = $is_can_third_delivery;
  195. if($is_localtown_imdada_status == 1 && $is_imdada_prequery_status == 1){
  196. $this->is_imdada_prequery_status = 1;
  197. }else{
  198. $this->is_imdada_prequery_status = 0;
  199. }
  200. if($is_localtown_sf_status == 1 && $is_sf_prequery_status == 1){
  201. $this->is_sf_prequery_status = 1;
  202. }else{
  203. $this->is_sf_prequery_status = 0;
  204. }
  205. $data = D('Seller/Config')->get_all_config();
  206. $this->data = $data;
  207. $this->display('Order/index');
  208. }
  209. public function opremarksaler()
  210. {
  211. $opdata = $this->check_order_data();
  212. extract($opdata);
  213. if (IS_POST) {
  214. $remark = I('request.remark');
  215. M('lionfish_comshop_order')->where( array('order_id' => $item['order_id']) )->save( array('remarksaler' => $remark) );
  216. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  217. }
  218. $this->item = $item;
  219. $this->id = $item['order_id'];
  220. include $this->display();
  221. }
  222. private function check_order_data()
  223. {
  224. $id = I('request.id',0);
  225. $item = M('lionfish_comshop_order')->where( array('order_id' => $id) )->find();
  226. if (empty($item)) {
  227. show_json(0, '未找到订单!');
  228. }
  229. return array('id' => $id, 'item' => $item);
  230. }
  231. public function opsendcancel()
  232. {
  233. $opdata = $this->check_order_data();
  234. extract($opdata);
  235. $sendtype = I('request.sendtype','');
  236. $gpc = I('request.');
  237. if (($item['order_status_id'] != 4) ) {
  238. show_json(0, '订单未发货,不需取消发货!');
  239. }
  240. if (IS_POST) {
  241. $remark = trim($gpc['remark']);
  242. $data = array('express_time' => 0,'shipping_no' =>'','shipping_method' => 0);
  243. $data['order_status_id'] = 1;
  244. M('lionfish_comshop_order')->where( array('order_id' => $item['order_id']) )->save($data);
  245. $history_data = array();
  246. $history_data['order_id'] = $item['order_id'];
  247. $history_data['order_status_id'] = 1;
  248. $history_data['notify'] = 0;
  249. $history_data['comment'] = '订单取消发货 ID: ' . $item['order_id'] . ' 订单号: ' . $item['order_num_alias'];
  250. $history_data['date_added'] = time();
  251. M('lionfish_comshop_order_history')->add($history_data);
  252. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  253. }
  254. $sendgoods = array();
  255. $bundles = array();
  256. $this->id = $item['order_id'];
  257. $this->item = $item;
  258. $this->sendtype = $sendtype;
  259. include $this->display();
  260. }
  261. public function opchangeaddress()
  262. {
  263. $_GPC = I('request.');
  264. $opdata = $this->check_order_data();
  265. extract($opdata);
  266. $new_area = 0;
  267. $address_street = 0;
  268. $province_info = D('Home/Front')->get_area_info($item['shipping_province_id']);
  269. $city_info = D('Home/Front')->get_area_info($item['shipping_city_id']);
  270. $area_info = D('Home/Front')->get_area_info($item['shipping_country_id']);
  271. if (IS_POST) {
  272. $realname = $_GPC['realname'];
  273. $mobile = $_GPC['mobile'];
  274. $province = $_GPC['province'];
  275. $city = $_GPC['city'];
  276. $area = $_GPC['area'];
  277. $street = $_GPC['street'];
  278. $changead = intval($_GPC['changead']);
  279. $address = trim($_GPC['address']);
  280. if (!(empty($id))) {
  281. if (empty($realname)) {
  282. $ret = '请填写收件人姓名!';
  283. //show_json(0, array('msg' => $ret) );
  284. show_json(0, $ret);
  285. }
  286. if (empty($mobile)) {
  287. $ret = '请填写收件人手机!';
  288. show_json(0, $ret);
  289. }
  290. if ($changead) {
  291. if ($province == '请选择省份') {
  292. $ret = '请选择省份!';
  293. show_json(0, $ret);
  294. }
  295. if (empty($address)) {
  296. $ret = '请填写详细地址!';
  297. show_json(0, $ret);
  298. }
  299. }
  300. $address_array = array();
  301. $address_array['shipping_name'] = $realname;
  302. $address_array['shipping_tel'] = $mobile;
  303. if ($changead) {
  304. $province_info = M('lionfish_comshop_area')->where("name like '%{$province}%' ")->find();
  305. if( !empty($province_info))
  306. {
  307. $province_id = $province_info['id'];
  308. }else{
  309. $max_dp = M('lionfish_comshop_area')->order('code desc')->find();
  310. $area_data = array();
  311. $area_data['name'] = $province;
  312. $area_data['pid'] = 0;
  313. $area_data['code'] = $max_dp['code']+1;
  314. $province_id = M('lionfish_comshop_area')->add($area_data);
  315. $up_data = array();
  316. $up_data['code'] = $province_id;
  317. M('lionfish_comshop_area')->where( array('id' => $province_id ) )->save($up_data);
  318. }
  319. //$city_info = M('lionfish_comshop_area')->where("name like '%{$city}%'")->find();
  320. $guding_arr = ['鞍山市'];
  321. if( in_array($city , $guding_arr) )
  322. {
  323. $city_info = M('lionfish_comshop_area')->where("name = '{$city}'")->find();
  324. }else{
  325. $city_info = M('lionfish_comshop_area')->where("name like '%{$city}%'")->find();
  326. }
  327. if( !empty($city_info))
  328. {
  329. $city_id = $city_info['id'];
  330. }else{
  331. $max_dp = M('lionfish_comshop_area')->order('code desc')->find();
  332. $area_data = array();
  333. $area_data['name'] = $city;
  334. $area_data['pid'] = $province_id;
  335. $area_data['code'] = $max_dp['code']+1;
  336. $city_id = M('lionfish_comshop_area')->add( $area_data);
  337. $up_data = array();
  338. $up_data['code'] = $city_id;
  339. M('lionfish_comshop_area')->where( array('id' => $city_id ) )->save($up_data);
  340. }
  341. //city_name: 东莞市
  342. if( empty($area) )
  343. {
  344. if( $city == '东莞市' )
  345. {
  346. $area = '东莞';
  347. }
  348. if( $city == '中山市' )
  349. {
  350. $area = '中山';
  351. //453
  352. }
  353. }
  354. $country_info = M('lionfish_comshop_area')->where( "name like '%{$area}%' " )->find();
  355. if( $area == '中山' )
  356. {
  357. $country_info = M('lionfish_comshop_area')->where( array('id' => 453 ) )->find();
  358. //
  359. }
  360. if( !empty($country_info))
  361. {
  362. $country_id = $country_info['id'];
  363. }else{
  364. $max_dp = M('lionfish_comshop_area')->order('code desc')->find();
  365. $area_data = array();
  366. $area_data['name'] = $area;
  367. $area_data['pid'] = $city_id;
  368. $area_data['code'] = $max_dp['code']+1;
  369. $country_id = M('lionfish_comshop_area')->add( $area_data );
  370. $up_data = array();
  371. $up_data['code'] = $country_id;
  372. M('lionfish_comshop_area')->where( array('id' => $country_id ) )->save( $up_data );
  373. }
  374. $address_array['shipping_province_id'] = $province_id;
  375. $address_array['shipping_city_id'] = $city_id;
  376. $address_array['shipping_country_id'] = $country_id;
  377. $address_array['shipping_address'] = $address;
  378. if( $item['delivery'] == 'tuanz_send' )
  379. {
  380. $address_array['tuan_send_address'] = $address;
  381. }
  382. }
  383. M('lionfish_comshop_order')->where( array('order_id' => $id) )->save( $address_array );
  384. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  385. }
  386. }
  387. $this->id = $item['order_id'];
  388. $this->item = $item;
  389. $this->province_info = $province_info;
  390. $this->city_info = $city_info;
  391. $this->area_info = $area_info;
  392. $this->display();
  393. }
  394. //确认送达团长
  395. public function opsend_tuanz_over()
  396. {
  397. $opdata = $this->check_order_data();
  398. extract($opdata);
  399. //express_tuanz_time D('Home/Frontorder')->send_order_operate($order_info['order_id']);
  400. D('Seller/Order')->do_tuanz_over($item['order_id']);
  401. //D('Seller/Frontorder')->send_order_operate($item['order_id']);
  402. D('Home/Frontorder')->send_order_operate($item['order_id']);
  403. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  404. }
  405. public function all_opprint()
  406. {
  407. $_GPC = I('request.');
  408. $order_arr = $_GPC['order_arr'];
  409. $cache_key = md5(time().mt_rand(100,1000));
  410. S('_all_opprintquene_'.$cache_key, $order_arr);
  411. $this->cache_key = $cache_key;
  412. $this->_GPC = $_GPC;
  413. $this->display();
  414. }
  415. public function do_opprint_quene()
  416. {
  417. $_GPC = I('request.');
  418. $cache_key = $_GPC['cache_key'];
  419. $quene_order_list = S('_all_opprintquene_'.$cache_key);
  420. $order_id = array_shift($quene_order_list);
  421. S('_all_opprintquene_'.$cache_key, $quene_order_list);
  422. $order_info = M('lionfish_comshop_order')->field('order_num_alias')->where( array( 'order_id' => $order_id ) )->find();
  423. $print_model = D('Seller/Printaction');
  424. $result = $print_model->check_print_order( $order_id );
  425. $result2 =$print_model->check_print_order2( $order_id );
  426. if( $result['code'] == 1 || $result2['code'] == 1 )
  427. {
  428. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('is_print_suc' => 1) );
  429. }
  430. if( empty($quene_order_list) )
  431. {
  432. echo json_encode( array('code' => 2) );
  433. die();
  434. }
  435. //清单编号
  436. echo json_encode( array('code' => 0, 'msg' => '订单编号:'.$order_info['order_num_alias']." 处理成功,还剩余".count($quene_order_list)."个订单未处理") );
  437. die();
  438. }
  439. public function opprint()
  440. {
  441. $_GPC = I('request.');
  442. $order_id = $_GPC['id'];
  443. $print_model = D('Seller/Printaction');
  444. $result = $print_model->check_print_order( $order_id );
  445. $result2 = $print_model->check_print_order2( $order_id );
  446. if( $result['code'] == 1 || $result2['code'] == 1 )
  447. {
  448. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('is_print_suc' => 1) );
  449. show_json(1, array('msg' => '打印成功!' ) );
  450. }else{
  451. $open_feier_print = D('Home/Front')->get_config_by_name('open_feier_print');
  452. if(!empty($open_feier_print) && ( $open_feier_print == 2 || $open_feier_print == 1 ) )
  453. {
  454. show_json(0, array('msg' => $result['msg'] ) );
  455. }else{
  456. show_json(0, array('msg' => $result2['msg'] ) );
  457. }
  458. }
  459. }
  460. public function oprefund_goods_do()
  461. {
  462. $_GPC = I('request.');
  463. $opdata = $this->check_order_data();
  464. extract($opdata);
  465. $weixin_model = D('Home/Weixin');
  466. $id = $_GPC['id'];
  467. $order_goods_id = $_GPC['order_goods_id'];
  468. /**
  469. id : 3864
  470. order_goods_id : 4442
  471. **/
  472. //付款总额
  473. $order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id ) )->find();
  474. $this->order_goods_info = $order_goods_info;
  475. $goods_images = tomedia( $order_goods_info['goods_images'] );
  476. $this->goods_images = $goods_images;
  477. $free_tongji = $order_goods_info['total']-$order_goods_info['voucher_credit']-$order_goods_info['fullreduction_money'] - $order_goods_info['score_for_money'] - $order_goods_info['has_refund_money'];
  478. $integral_flow = M('lionfish_comshop_member_integral_flow')->where( array('type' => 'orderbuy', 'order_goods_id' => $order_goods_id ) )->find();
  479. $use_score = 0;
  480. if( !empty($integral_flow) )
  481. {
  482. $use_score = $integral_flow['score'];
  483. }
  484. $this->use_score = $use_score;
  485. $total_quantity = D('Seller/Commonorder')->get_order_goods_quantity($id,$order_goods_id);
  486. $this->total_quantity = $total_quantity;
  487. $has_refund_quantity = D('Seller/Commonorder')->refund_order_goods_quantity($id,$order_goods_id);
  488. $this->has_refund_quantity = $has_refund_quantity;
  489. $has_refund_money = D('Seller/Commonorder')->get_order_goods_refund_money($id,$order_goods_id);
  490. $this->has_refund_money = $has_refund_money;
  491. $shipping_fare = $order_goods_info['shipping_fare'];
  492. $delivery = $opdata['item']['delivery'];
  493. $this->delivery = $delivery;
  494. //预售订单begin
  495. $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $id );
  496. $presale_info = [];
  497. if( $presale_result['code'] == 0 )
  498. {
  499. $presale_info = $presale_result['data'];
  500. }
  501. $this->presale_info = $presale_info;
  502. //end
  503. $is_has_refund_deliveryfree = D('Home/Front')->get_config_by_name('is_has_refund_deliveryfree');
  504. $is_has_refund_deliveryfree = !isset($is_has_refund_deliveryfree) || $is_has_refund_deliveryfree == 1 ? 1:0;
  505. if( $is_has_refund_deliveryfree == 1 && $item['type'] != 'integral')
  506. {
  507. //后台设置退运费了
  508. //退回运费,导致佣金出错问题修改
  509. //$free_tongji += $shipping_fare;
  510. }
  511. if($item['delivery'] == 'hexiao'){
  512. $used_total = D('Home/Salesroom')->get_hexiao_order_goods_used_total($id,$order_goods_id);
  513. $free_tongji = $free_tongji - $used_total;
  514. }
  515. $this->shipping_fare = $shipping_fare;
  516. $this->is_has_refund_deliveryfree = $is_has_refund_deliveryfree;
  517. $this->free_tongji = $free_tongji;
  518. $this->_GPC = $_GPC;
  519. $commiss_state = '未结算';
  520. $commiss_info = M('lionfish_community_head_commiss_order')->where( array('order_id' => $id, 'order_goods_id' =>$order_goods_id,'type' => 'orderbuy' ) )->find();
  521. if( !empty($commiss_info) && $commiss_info['state'] == 1 )
  522. {
  523. $commiss_state = '已结算';
  524. }
  525. $this->commiss_info =$commiss_info;
  526. $this->commiss_state = $commiss_state;
  527. $this->payment_code = $item['payment_code'];
  528. if ( IS_POST ) {
  529. if(!$this->checkLocalTownOrderCanRefund($item)){
  530. show_json(0, array('message' => '同城配送订单配送中不能退款') );
  531. }
  532. $refund_money = isset($_GPC['refund_money']) && $_GPC['refund_money'] >0 ? floatval($_GPC['refund_money']) : 0;
  533. $is_refund_shippingfare = isset($_GPC['is_refund_shippingfare']) ? $_GPC['is_refund_shippingfare'] : 0;//退运费
  534. $is_back_sellcount = isset($_GPC['is_back_sellcount']) ? $_GPC['is_back_sellcount'] : 0;//退库存
  535. $is_back_scorecount = isset($_GPC['is_back_scorecount']) ? $_GPC['is_back_scorecount'] : 0;//退积分
  536. //$free_tongji = $opdata['item']['total']-$opdata['item']['voucher_credit']-$opdata['item']['fullreduction_money'] - $opdata['item']['score_for_money'];
  537. $free_tongji = $order_goods_info['total']-$order_goods_info['voucher_credit']-$order_goods_info['fullreduction_money'] - $order_goods_info['score_for_money'] - $order_goods_info['has_refund_money'];
  538. $refund_quantity = isset($_GPC['refund_quantity']) && $_GPC['refund_quantity'] >0 ? floatval($_GPC['refund_quantity']) : 0;
  539. $real_refund_quantity = isset($_GPC['real_refund_quantity']) && $_GPC['real_refund_quantity'] >0 ? intval($_GPC['real_refund_quantity']) : 0;
  540. //已退商品数量
  541. $refund_total_quantity = M('lionfish_comshop_order_goods_refund')->where( "order_id={$id} and order_goods_id={$order_goods_id} " )->sum('quantity');
  542. //部分退款计算运费
  543. if($refund_quantity + $refund_total_quantity < $order_goods_info['quantity']){
  544. $shipping_fare = round($refund_quantity/$order_goods_info['quantity']*$shipping_fare,2);
  545. }else{
  546. //$shipping_fare = round($refund_quantity/$order_goods_info['quantity']*$shipping_fare,2);
  547. $shipping_fare = $shipping_fare - $refund_total_quantity * round( 1/$order_goods_info['quantity'] * $shipping_fare,2);
  548. }
  549. $pay_total_money = $free_tongji ;
  550. $refund_shipping_fare = 0;
  551. $wx_refund_money = $refund_money;
  552. if( $is_refund_shippingfare == 1)
  553. {
  554. $free_tongji += $shipping_fare;
  555. $refund_shipping_fare = $shipping_fare;
  556. $wx_refund_money = $wx_refund_money + $shipping_fare;
  557. }
  558. $can_free_tongji = $opdata['item']['total'] + $opdata['item']['shipping_fare'] -$opdata['item']['voucher_credit']-$opdata['item']['fullreduction_money'] - $opdata['item']['score_for_money'];
  559. if( $item['type'] == 'integral' )
  560. {
  561. $can_free_tongji = $opdata['item']['total'] -$opdata['item']['voucher_credit']-$opdata['item']['fullreduction_money'] - $opdata['item']['score_for_money'];
  562. }
  563. $can_refund_quantity = 0;
  564. if($item['delivery'] == 'hexiao'){
  565. $can_refund_quantity = D('Home/Salesroom')->get_hexiao_order_goods_can_refund_quantity($id,$order_goods_id);
  566. }
  567. //以及退款了多少钱了 has_refund_money
  568. if($refund_money + $has_refund_money > $can_free_tongji){
  569. show_json(0, array('message' => '总退款金额大于可退款金额') );
  570. }
  571. else if( $refund_money < 0 )
  572. {
  573. show_json(0, array('message' => '填写正确的退款金额') );
  574. }
  575. else if( $is_back_sellcount == 1 && $refund_quantity > $total_quantity )
  576. {
  577. show_json(0, array('message' => '填写正确的退库存数量,最大'.$total_quantity.'个' ) );
  578. }else if($item['delivery'] == 'hexiao' && $can_refund_quantity < $refund_quantity){
  579. show_json(0, array('message' => '核销商品退款数量大于可退款数量'.$refund_quantity.'个' ) );
  580. }
  581. else{
  582. if( $is_refund_shippingfare == 0 && $opdata['item']['type'] == 'integral' )
  583. {
  584. M('lionfish_comshop_order')->where( array('order_id' => $id) )->save( array('shipping_fare' => 0) );
  585. M('lionfish_comshop_order_goods')->where( array('order_goods_id' =>$order_goods_id ) )->save( array('shipping_fare' => 0) );
  586. }
  587. //is_back_sellcount
  588. //$res = $weixin_model->refundOrder($id,$refund_money,0,$order_goods_id,$is_back_sellcount, $refund_quantity,1);
  589. $res = $weixin_model->refundOrder($id,$wx_refund_money,0,$order_goods_id,$is_back_sellcount, $refund_quantity,1);
  590. if( $is_refund_shippingfare == 0 && $opdata['item']['type'] == 'integral' )
  591. {
  592. M('lionfish_comshop_order')->where( array('order_id' => $id) )->save( array('shipping_fare' => $opdata['item']['shipping_fare'] ) );
  593. M('lionfish_comshop_order_goods')->where( array('order_goods_id' =>$order_goods_id ) )->save( array('shipping_fare' => $order_goods_info['shipping_fare']) );
  594. }
  595. if( $res['code'] == 0 )
  596. {
  597. show_json(0, array('message' => $res['msg'] ) );
  598. }else{
  599. //开始插入本次退款的情况
  600. //存储当前这笔退款 影响到的以后佣金情况
  601. //is_back_scorecount
  602. if( $is_back_scorecount == 1 )
  603. {
  604. $refund_score = 0;
  605. $refund_score = intval( ($use_score / $order_goods_info['quantity']) * $refund_quantity);
  606. D('Seller/Commonorder')->refund_order_goods_intrgral( $id, $order_goods_id ,$refund_score );
  607. }else{
  608. $refund_score = 0;
  609. D('Seller/Commonorder')->refund_order_goods_intrgral( $id, $order_goods_id ,0 );
  610. }
  611. //退回运费,导致佣金出错问题修改
  612. $order_goods_refundid = D('Seller/Commonorder')->ins_order_goods_refund($id, $order_goods_id,$pay_total_money,$real_refund_quantity, $refund_quantity,$refund_money,$is_back_sellcount,$refund_shipping_fare);
  613. //$order_goods_refundid = D('Seller/Commonorder')->ins_order_goods_refund($id, $order_goods_id,$pay_total_money,$real_refund_quantity, $refund_quantity,$refund_money,$is_back_sellcount);
  614. //如果这个商品没有数量了。就改变他的状态为已退款的状态
  615. $new_total_quantity = D('Seller/Commonorder')->get_order_goods_quantity($id,$order_goods_id);
  616. if( $new_total_quantity <=0 )
  617. {
  618. D('Seller/Commonorder')->check_refund_order_goods_status($id, $order_goods_id, $refund_money,$is_back_sellcount,$real_refund_quantity, $refund_quantity,$is_refund_shippingfare);
  619. $order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $id ) )->select();
  620. $is_all_refund = true;
  621. foreach($order_goods_list as $val )
  622. {
  623. if($val['is_refund_state'] != 1)
  624. {
  625. $is_all_refund = false;
  626. }
  627. }
  628. $or_gd_info = M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id ) )->find();
  629. if(($or_gd_info['is_refund_state'] == 1) && ($is_all_refund == false) ){
  630. $or_gd_info = M('lionfish_comshop_order_goods')->field('name')->where( array('order_goods_id' => $order_goods_id ) )->find();
  631. $order_history = array();
  632. $order_history['order_id'] = $id;
  633. $order_history['order_status_id'] = 19;
  634. $order_history['notify'] = 0;
  635. if( $item['type'] == 'integral' ){
  636. $order_history['comment'] = '后台子订单退款,退款商品:'.$or_gd_info['name'].','.$real_refund_quantity.'个,退库存/销量数量'.$refund_quantity.'个,退款积分'.$refund_money.'积分';
  637. }else{
  638. $order_history['comment'] = '后台子订单退款,退款商品:'.$or_gd_info['name'].','.$real_refund_quantity.'个,退库存/销量数量'.$refund_quantity.'个,退款金额'.$refund_money.'元';
  639. }
  640. $order_history['date_added'] = time();
  641. M('lionfish_comshop_order_history')->add( $order_history );
  642. }
  643. }else{
  644. $or_gd_info = M('lionfish_comshop_order_goods')->field('name')->where( array('order_goods_id' => $order_goods_id ) )->find();
  645. $order_history = array();
  646. $order_history['order_id'] = $id;
  647. $order_history['order_status_id'] = 19;
  648. $order_history['notify'] = 0;
  649. if( $item['type'] == 'integral' ){
  650. $order_history['comment'] = '后台子订单退款,退款商品:'.$or_gd_info['name'].','.$real_refund_quantity.'个,退库存/销量数量'.$refund_quantity.'个,退款积分'.$refund_money.'积分,';
  651. }else{
  652. $order_history['comment'] = '后台子订单退款,退款商品:'.$or_gd_info['name'].','.$real_refund_quantity.'个,退库存/销量数量'.$refund_quantity.'个,退款金额'.$refund_money.'元,';
  653. }
  654. if($is_refund_shippingfare == 1)
  655. {
  656. $order_history['comment'] .= '. 退配送费:'.$refund_shipping_fare.'元';
  657. }
  658. $order_history['date_added'] = time();
  659. M('lionfish_comshop_order_history')->add( $order_history );
  660. }
  661. //核销订单操作
  662. if($item['delivery'] == 'hexiao'){
  663. //核销商品订单退款
  664. D('Home/Salesroom')->hexiao_refund_action($id,$order_goods_id,$refund_quantity);
  665. //操作核销订单是否完成
  666. D('Seller/Order')->hexiao_finished($id, '未核销商品退款,订单完成');
  667. }
  668. //礼品卡退款
  669. D('Seller/VirtualCard')->refundOrder($id);
  670. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  671. }
  672. }
  673. }
  674. if( $item['type'] == 'integral' )
  675. {
  676. include $this->display('Order/oprefund_goods_dointegral');
  677. }else{
  678. include $this->display();
  679. }
  680. }
  681. public function oprefund_do()
  682. {
  683. $_GPC = I('request.');
  684. $opdata = $this->check_order_data();
  685. extract($opdata);
  686. $id = $_GPC['id'];
  687. //付款总额
  688. $free_tongji = $opdata['item']['total']-$opdata['item']['voucher_credit']-$opdata['item']['fullreduction_money'] - $opdata['item']['score_for_money'];
  689. $total_quantity = M('lionfish_comshop_order_goods')->where( array('order_id' => $id ) )->sum('quantity');
  690. $has_refud_money = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $id ) )->sum('money');
  691. $this->has_refud_money = $has_refud_money;
  692. $has_refund_quantity = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $id ) )->sum('quantity');
  693. $total_quantity = $total_quantity - $has_refund_quantity;
  694. $buy_score_total = M('lionfish_comshop_member_integral_flow')->where( array('type' => 'orderbuy' , 'order_id' => $id ) )->sum('score');
  695. $has_refund_buy_score_total = M('lionfish_comshop_member_integral_flow')->where(array('type' => 'refundorder' , 'order_id' => $id ))->sum('score');
  696. if(!empty($has_refund_buy_score_total) && $has_refund_buy_score_total > 0)
  697. $buy_score_total = $buy_score_total - $has_refund_buy_score_total;
  698. $this->buy_score_total = $buy_score_total;
  699. $shipping_fare = $opdata['item']['shipping_fare'];
  700. $delivery = $opdata['item']['delivery'];
  701. $is_has_refund_deliveryfree = D('Home/Front')->get_config_by_name('is_has_refund_deliveryfree');
  702. $is_has_refund_deliveryfree = !isset($is_has_refund_deliveryfree) || $is_has_refund_deliveryfree == 1 ? 1:0;
  703. if( $is_has_refund_deliveryfree == 1)
  704. {
  705. //后台设置退运费了
  706. //退回运费,导致佣金出错问题修改
  707. $free_tongji += $opdata['item']['shipping_fare'];
  708. }
  709. $hx_used_total = 0;
  710. if($item['delivery'] == 'hexiao'){
  711. $used_quantity = D('Home/Salesroom')->get_hexiao_order_used_quantity($id);
  712. $hx_used_total = D('Home/Salesroom')->get_hexiao_order_used_total($id);
  713. $total_quantity = $total_quantity - $used_quantity;
  714. $free_tongji = $free_tongji - $hx_used_total;
  715. }
  716. //判断是否有预售 begin
  717. $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $id );
  718. $presale_info = [];
  719. if( $presale_result['code'] == 0 )
  720. {
  721. $presale_info = $presale_result['data'];
  722. $free_tongji = $free_tongji - $presale_info['presale_for_ordermoney'];
  723. }
  724. //end
  725. $this->presale_info = $presale_info;
  726. $this->is_has_refund_deliveryfree = $is_has_refund_deliveryfree;
  727. $this->shipping_fare = $shipping_fare;
  728. $this->total_quantity = $total_quantity;
  729. $this->delivery = $delivery;
  730. $this->hx_used_total = $hx_used_total;
  731. if( IS_POST )
  732. {
  733. if(!$this->checkLocalTownOrderCanRefund($item)){
  734. show_json(0, array('message' => '同城配送订单配送中不能退款') );
  735. }
  736. $refund_money = isset($_GPC['refund_money']) && $_GPC['refund_money'] >0 ? floatval($_GPC['refund_money']) : 0;
  737. $is_refund_shippingfare = isset($_GPC['is_refund_shippingfare']) ? $_GPC['is_refund_shippingfare'] : 0;//退运费
  738. $is_back_sellcount = isset($_GPC['is_back_sellcount']) ? $_GPC['is_back_sellcount'] : 0;//退库存
  739. $is_back_buyscore = isset($_GPC['is_back_buyscore']) ? $_GPC['is_back_buyscore'] : 0;//退积分
  740. $wx_refund_money = $refund_money;
  741. $free_tongji = $opdata['item']['total']-$opdata['item']['voucher_credit']-$opdata['item']['fullreduction_money'] - $opdata['item']['score_for_money'];
  742. //已经退款运费
  743. $refund_shipping_fare_amount = M('lionfish_comshop_order_goods_refund')->where( array('order_id' =>$id ) )->sum('refund_shipping_fare');
  744. if( empty($refund_shipping_fare_amount) )
  745. {
  746. $refund_shipping_fare_amount = 0;
  747. }
  748. if( $is_refund_shippingfare == 1 && $opdata['item']['type'] != 'integral' )
  749. {
  750. if($refund_shipping_fare_amount < $shipping_fare) {
  751. $shipping_fare = $shipping_fare - $refund_shipping_fare_amount;
  752. $this->shipping_fare = $shipping_fare;
  753. //$free_tongji += $shipping_fare;
  754. $wx_refund_money += $shipping_fare - $opdata['item']['fare_shipping_free'];
  755. $is_back_buyscore = 2;//退运费
  756. }
  757. }
  758. $free_tongji = $free_tongji - $has_refud_money;
  759. if( $refund_money - $free_tongji >= 0.01 ){
  760. show_json(0, array('message' => '填写金额大于总退款金额' ) );
  761. }
  762. else if( $refund_money < 0 )
  763. {
  764. show_json(0, array('message' => '填写正确的退款金额' ) );
  765. }
  766. else{
  767. $weixin_model = D('Home/Weixin');
  768. $id = $_GPC['id'];
  769. $model = M('lionfish_comshop_order');
  770. //$model->startTrans(); // 开启事务
  771. $order_info = $model->where(array('order_id'=>$id))->find();
  772. if( $order_info['order_status_id'] != 7 )
  773. {
  774. if( $is_refund_shippingfare == 0 && $opdata['item']['type'] == 'integral' )
  775. {
  776. M('lionfish_comshop_order')->where( array('order_id' => $id) )->save( array('shipping_fare' => 0) );
  777. }
  778. //$res = $weixin_model->refundOrder($id,$refund_money,0,0,$is_back_sellcount);
  779. $res = $weixin_model->refundOrder($id,$wx_refund_money,0,0,$is_back_sellcount);
  780. if( $is_refund_shippingfare == 0 && $opdata['item']['type'] == 'integral' )
  781. {
  782. M('lionfish_comshop_order')->where( array('order_id' => $id) )->save( array('shipping_fare' => $opdata['item']['shipping_fare'] ) );
  783. }
  784. $model->commit(); // 开启事务
  785. if( $res['code'] == 0 )
  786. {
  787. show_json(0, array('message' => $res['msg']) );
  788. }else{
  789. //integral
  790. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $id ) )->find();
  791. $comment = '后台操作立即退款,退款金额:'.$refund_money.'元';
  792. if( $is_refund_shippingfare == 0 && $opdata['item']['type'] == 'integral' )
  793. {
  794. $comment = '后台操作立即退款,退款积分:'.$refund_money.'积分';
  795. }
  796. if( $order_info['type'] == 'integral' )
  797. {
  798. $comment = '后台操作立即退款,退还积分:'.$refund_money.'积分';
  799. //$comment = '后台操作立即退款,退款金额:'.$refund_money.'元';
  800. }
  801. if($is_refund_shippingfare == 1)
  802. {
  803. if( $order_info['type'] == 'integral' ){
  804. $refund_shipping_fare_amount2 = M('lionfish_comshop_order_goods_refund')->where( array('order_id' =>$id ) )->sum('refund_shipping_fare');
  805. if( empty($refund_shipping_fare_amount2) )
  806. {
  807. $refund_shipping_fare_amount2 = 0;
  808. }
  809. $new_shipping_fare = $opdata['item']['shipping_fare'] - $refund_shipping_fare_amount2;
  810. $comment .= '. 退配送费:'.$new_shipping_fare.'元';
  811. }else{
  812. $comment .= '. 退配送费:'.$opdata['item']['shipping_fare'].'元';
  813. }
  814. }
  815. if($is_back_sellcount == 1)
  816. {
  817. $comment .= '. 退库存:'.$total_quantity;
  818. }else{
  819. $comment .= '. 不退库存,不减销量';
  820. }
  821. $history_data = array();
  822. $history_data['order_id'] = $id;
  823. $history_data['order_status_id'] = 7;
  824. $history_data['notify'] = 0;
  825. $history_data['comment'] = $comment;
  826. $history_data['date_added'] = time();
  827. M('lionfish_comshop_order_history')->add($history_data);
  828. M('lionfish_comshop_order')->where( array('order_id' => $id) )->save( array('order_status_id' => 7) );
  829. //将所有在退款中的状态,全部重置成已退款成功
  830. M('lionfish_comshop_order_refund')->where( array('order_id' => $id, 'state' => 0) )->save( array('state' => 3) );
  831. //将退款中的 申请订单,全部改成已退款
  832. $refund_all = M('lionfish_comshop_order_refund')->where( array('order_id' =>$id, 'state' => 0 ) )->select();
  833. if( !empty($refund_all) )
  834. {
  835. foreach( $refund_all as $val )
  836. {
  837. $ins_data = array();
  838. $ins_data['ref_id'] = $val['ref_id'];
  839. $ins_data['order_id'] = $val['order_id'];
  840. $ins_data['order_goods_id'] = $val['order_goods_id'];
  841. $ins_data['message'] = '平台同意退款   ,退款成功';
  842. $ins_data['type'] = 2;
  843. $ins_data['addtime'] = time();
  844. M('lionfish_comshop_order_refund_history')->add( $ins_data );
  845. M('lionfish_comshop_order_refund')->where( array('ref_id' => $val['ref_id']) )->save( array('state' => 3) );
  846. }
  847. }
  848. //$data[''] = isset($data['is_print_admin_cancleorder']) ? $data['is_print_admin_cancleorder'] : 0;
  849. $is_print_admin_cancleorder = D('Home/Front')->get_config_by_name('is_print_admin_cancleorder');
  850. D('Seller/Commonorder')->refund_one_order( $id , $is_back_buyscore);
  851. if( isset($is_print_admin_cancleorder) && $is_print_admin_cancleorder == 1 )
  852. {
  853. D('Seller/Printaction')->check_print_order($id,'后台操作取消订单');
  854. D('Seller/Printaction')->check_print_order2($id,'后台操作取消订单');
  855. }
  856. sellerLog('订单['.$order_info['order_num_alias'].']退款成功操作', 2);
  857. //核销订单操作
  858. if($item['delivery'] == 'hexiao'){
  859. D('Home/Salesroom')->hexiao_order_refund_action($id);
  860. }
  861. //礼品卡退款
  862. D('Seller/VirtualCard')->refundOrder($id);
  863. show_json(1, array('message' => '退款成功!') );
  864. }
  865. }else{
  866. //$model->rollback(); // 回滚
  867. show_json(0, array('message' => '请勿重复提交'));
  868. }
  869. }
  870. }
  871. $this->id = $id;
  872. $this->free_tongji = $free_tongji;
  873. $this->item = $item;
  874. $commiss_state = '未结算';
  875. $commiss_info = M('lionfish_community_head_commiss_order')->where( array('order_id' => $id, 'type' => 'orderbuy' ) )->find();
  876. if( !empty($commiss_info) && $commiss_info['state'] == 1 )
  877. {
  878. $commiss_state = '已结算';
  879. }
  880. $this->commiss_state = $commiss_state;
  881. if( $item['type'] == 'integral' )
  882. {
  883. $this->display('Order/oprefund_do_integral');
  884. }else{
  885. $this->display();
  886. }
  887. }
  888. function test()
  889. {
  890. //D('Seller/Printaction')->check_print_order(63);
  891. // lionfish_comshop_order
  892. $shop_name = D('Home/Front')->get_config_by_name('shoname');
  893. $this->shop_name = $shop_name;
  894. $order_id = 174;
  895. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  896. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id) )->select();
  897. $need_order_goods = array();
  898. foreach($order_goods as $key => $value)
  899. {
  900. $value['option_sku'] = D('Seller/Order')->get_order_option_sku($order_id, $value['order_goods_id']);
  901. $need_order_goods[$key] = $value;
  902. }
  903. $province_info = D('Home/Front')->get_area_info($order_info['shipping_province_id']);
  904. $city_info = D('Home/Front')->get_area_info($order_info['shipping_city_id']);
  905. $area_info = D('Home/Front')->get_area_info($order_info['shipping_country_id']);
  906. $member = M('lionfish_comshop_member')->where( array('member_id' => $item['member_id'] ) )->find();
  907. $this->province_info = $province_info;
  908. $this->city_info = $city_info;
  909. $this->area_info = $area_info;
  910. $this->member = $member;
  911. $this->order_info = $order_info;
  912. $this->need_order_goods = $need_order_goods;
  913. $this->display('forms');
  914. }
  915. /**
  916. 打印配送单
  917. **/
  918. public function order_print_dan()
  919. {
  920. $order_id = I('get.id');
  921. $shop_name = D('Home/Front')->get_config_by_name('shoname');
  922. $this->shop_name = $shop_name;
  923. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  924. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id) )->select();
  925. $need_order_goods = array();
  926. $total = 0;
  927. foreach($order_goods as $key => $value)
  928. {
  929. $value['option_sku'] = D('Seller/Order')->get_order_option_sku($order_id, $value['order_goods_id']);
  930. $need_order_goods[$key] = $value;
  931. }
  932. $total = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id) )->sum('total');
  933. //mead-3
  934. $total = $total+$order_info['packing_fare']+$order_info['shipping_fare']-$order_info['voucher_credit']-$order_info['fullreduction_money']- $order_info['score_for_money']+$order_info['localtown_add_shipping_fare']- $order_info['fare_shipping_free'];
  935. if($total < 0){
  936. $total = 0;
  937. }
  938. $legal_amount = D('Seller/Order')->num_to_rmb($total);
  939. $province_info = D('Home/Front')->get_area_info($order_info['shipping_province_id']);
  940. $city_info = D('Home/Front')->get_area_info($order_info['shipping_city_id']);
  941. $area_info = D('Home/Front')->get_area_info($order_info['shipping_country_id']);
  942. $member = M('lionfish_comshop_member')->where( array('member_id' => $order_info['member_id'] ) )->find();
  943. sellerLog('订单['.$order_info['order_num_alias'].']打印配送单', 2);
  944. $order_note_name = D('Home/Front')->get_config_by_name('order_note_name');
  945. $order_note_name = isset($order_note_name) && !empty($order_note_name) ? $order_note_name :'店名';
  946. $this->order_note_name = $order_note_name;
  947. $this->legal_amount = $legal_amount;
  948. $this->province_info = $province_info;
  949. $this->city_info = $city_info;
  950. $this->area_info = $area_info;
  951. $this->member = $member;
  952. $this->total = $total;
  953. $this->order_info = $order_info;
  954. $this->need_order_goods = $need_order_goods;
  955. $this->display('forms');
  956. }
  957. //配送团长
  958. public function opsend_tuanz()
  959. {
  960. $opdata = $this->check_order_data();
  961. extract($opdata);
  962. D('Seller/Order')->do_send_tuanz($item['order_id']);
  963. $order_num_alias = M('lionfish_comshop_order')->where( array('order_id' => $item['order_id'] ) )->find();
  964. D('Seller/Operatelog')->addOperateLog('detailed_list','配送团长--订单编号'.$order_num_alias['order_num_alias']);
  965. //后台自动送达团长
  966. D('Seller/Order')->order_auto_service($item,'后台自动确认送达团长');
  967. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  968. }
  969. //同城配送,确认开始配送流程
  970. public function opsend_localtown()
  971. {
  972. $opdata = $this->check_order_data();
  973. extract($opdata);
  974. $count = D('Seller/Order')->do_send_localtown($item['order_id']);
  975. show_json(1, array('url' => $_SERVER['HTTP_REFERER'], 'count' => $count));
  976. }
  977. public function opsend()
  978. {
  979. $_GPC = I('request.');
  980. $opdata = $this->check_order_data();
  981. extract($opdata);
  982. if (empty($item['address_id'])) {
  983. show_json(0, array('message' => '无收货地址,无法发货!'));
  984. }
  985. if ($item['order_status_id'] == 3) {
  986. show_json(0, array('message' => '订单未付款,无法发货!'));
  987. }
  988. if (IS_POST) {
  989. //express shipping_no $express_info['name'] dispatchname
  990. if (!(empty($_GPC['shipping_no'])) && empty($_GPC['shipping_no'])) {
  991. show_json(0, array('message' => '请输入快递单号!') );
  992. }
  993. if ( empty($_GPC['express']) ) {
  994. show_json(0, array('message' => '请选择快递公司!'));
  995. }
  996. if (!(empty($item['transid']))) {
  997. }
  998. $express_info = D('Seller/Express')->get_express_info($_GPC['express']);
  999. $time = time();
  1000. $data = array(
  1001. 'shipping_method' => trim($_GPC['express']),
  1002. 'shipping_no' => trim($_GPC['shipping_no']),
  1003. 'dispatchname' => $express_info['name'],
  1004. 'express_time' => $time
  1005. );
  1006. $data['order_status_id'] = 4;
  1007. M('lionfish_comshop_order')->where( array('order_id' => $item['order_id']) )->save( $data );
  1008. $history_data = array();
  1009. $history_data['order_id'] = $item['order_id'];
  1010. $history_data['order_status_id'] = 4;
  1011. $history_data['notify'] = 0;
  1012. $history_data['comment'] = '订单发货 ID: ' . $item['order_id'] . ' 订单号: ' . $item['order_num_alias'] . ' <br/>快递公司: ' . $express_info['name'] . ' 快递单号: ' . $_GPC['shipping_no'];
  1013. $history_data['date_added'] = time();
  1014. M('lionfish_comshop_order_history')->add($history_data);
  1015. D('Home/Frontorder')->send_order_operate($item['order_id']);
  1016. sellerLog('订单['.$item['order_num_alias'].']订单发货操作', 2);
  1017. //TODO...发送已经发货的消息通知
  1018. //m('notice')->sendOrderMessage($item['id']);
  1019. //plog('order.op.send', '订单发货 ID: ' . $item['id'] . ' 订单号: ' . $item['ordersn'] . ' <br/>快递公司: ' . $_GPC['expresscom'] . ' 快递单号: ' . $_GPC['expresssn']);
  1020. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1021. }
  1022. $noshipped = array();
  1023. $shipped = array();
  1024. $province_info = D('Home/Front')->get_area_info($item['shipping_province_id']);
  1025. $city_info = D('Home/Front')->get_area_info($item['shipping_city_id']);
  1026. $area_info = D('Home/Front')->get_area_info($item['shipping_country_id']);
  1027. $order_goods = M()->query('select og.order_goods_id as id,og.name as title,og.goods_images as thumb from ' .
  1028. C('DB_PREFIX'). 'lionfish_comshop_order_goods as og where og.order_id= '.$item['order_id']);
  1029. $express_list = D('Seller/Express')->load_all_express();
  1030. $this->province_info = $province_info;
  1031. $this->city_info = $city_info;
  1032. $this->area_info = $area_info;
  1033. $this->order_goods = $order_goods;
  1034. $this->item = $item;
  1035. $this->express_list = $express_list;
  1036. $this->id = $item['order_id'];
  1037. $this->display();
  1038. }
  1039. // 11 已完成
  1040. public function opfinish()
  1041. {
  1042. $opdata = $this->check_order_data();
  1043. extract($opdata);
  1044. M('lionfish_comshop_order')->where(array('order_id' => $item['order_id']) )->save( array('order_status_id' => 11,
  1045. 'finishtime' => time()) );
  1046. $history_data = array();
  1047. $history_data['order_id'] = $item['order_id'];
  1048. $history_data['order_status_id'] = 11;
  1049. $history_data['notify'] = 0;
  1050. $history_data['comment'] = '后台操作,已完成' ;
  1051. $history_data['date_added'] = time();
  1052. sellerLog('订单['.$item['order_num_alias'].']订单完成操作', 2);
  1053. M('lionfish_comshop_order_history')->add($history_data);
  1054. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1055. }
  1056. public function export_form()
  1057. {
  1058. $_GPC = I('request.');
  1059. /**
  1060. order_status_id:
  1061. type: normal
  1062. searchtime:
  1063. time[start]: 2019-12-23 00:00:00
  1064. time[end]: 2019-12-23 23:59:59
  1065. delivery:
  1066. searchfield: ordersn
  1067. keyword:
  1068. export: 0
  1069. **/
  1070. unset($_GPC['controller']);
  1071. unset($_GPC['export']);
  1072. $post_data = array();
  1073. $post_data['order_status_id'] = $_GPC['order_status_id'];
  1074. $post_data['type'] = $_GPC['type'];
  1075. $post_data['searchtime'] = $_GPC['searchtime'];
  1076. $post_data['time[start]'] = $_GPC['time']['start'];
  1077. $post_data['time[end]'] = $_GPC['time']['end'];
  1078. $post_data['headid'] = $_GPC['headid'];
  1079. $post_data['delivery'] = $_GPC['delivery'];
  1080. $post_data['searchfield'] = $_GPC['searchfield'];
  1081. $post_data['keyword'] = $_GPC['keyword'];
  1082. $post_data['export'] = 1;
  1083. $note_content = D('Home/Front')->get_config_by_name('order_note_name');
  1084. $order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
  1085. $columns = array(
  1086. array('title' => '订单流水号', 'field' => 'day_paixu', 'width' => 24, 'sort' => 0, 'is_check' => 1),
  1087. array('title' => '订单编号', 'field' => 'order_num_alias', 'width' => 24, 'sort' => 0, 'is_check' => 1),
  1088. array('title' => '会员昵称', 'field' => 'name', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1089. array('title' => '会员手机号', 'field' => 'telephone', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1090. array('title' => '会员备注', 'field' => 'member_content', 'width' => 24, 'sort' => 0, 'is_check' => 1),
  1091. array('title' => '收货姓名(或自提人)', 'field' => 'shipping_name', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1092. array('title' => '联系电话', 'field' => 'shipping_tel', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1093. array('title' => '收货地址', 'field' => 'address_province_city_area', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1094. array('title' => '供应商名称/类型', 'field' => 'supply_name', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1095. array('title' => '提货详细地址', 'field' => 'address_address', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1096. array('title' => '商品名称', 'field' => 'goods_title', 'width' => 24, 'sort' => 0, 'is_check' => 1),
  1097. array('title' => '商品分类', 'field' => 'goods_category', 'width' => 24, 'sort' => 0, 'is_check' => 1),
  1098. array('title' => '商品价格', 'field' => 'goods_rprice2', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1099. array('title' => '商品数量', 'field' => 'quantity', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1100. array('title' => '支付方式', 'field' => 'paytype', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1101. array('title' => '配送方式', 'field' => 'delivery', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1102. array('title' => '预计送达时间', 'field' => 'expected_delivery_time', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1103. array('title' => '团长配送送货详细地址', 'field' => 'tuan_send_address', 'width' => 22, 'sort' => 0, 'is_check' => 1),
  1104. array('title' => '商品规格', 'field' => 'goods_optiontitle', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1105. array('title' => '商品单价', 'field' => 'goods_price1', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1106. array('title' => '收货时间', 'field' => 'receive_time', 'width' => 24, 'sort' => 0, 'is_check' => 1),
  1107. array('title' => '快递单号', 'field' => 'expresssn', 'width' => 24, 'sort' => 0, 'is_check' => 1),
  1108. array('title' => '下单时间', 'field' => 'createtime', 'width' => 24, 'sort' => 0, 'is_check' => 1),
  1109. array('title' => '小区名称', 'field' => 'community_name', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1110. array('title' => '团长姓名', 'field' => 'head_name', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1111. array('title' => '团长电话', 'field' => 'head_mobile', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1112. array('title' => '退款商品数量', 'field' => 'has_refund_quantity', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1113. array('title' => '退款金额', 'field' => 'has_refund_money', 'width' => 12, 'sort' => 0, 'is_check' => 1),
  1114. array('title' => '微信支付交易单号', 'field' => 'transaction_id', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1115. array('title' => '商品编码', 'field' => 'goods_goodssn', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1116. array('title' => 'openid', 'field' => 'openid', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1117. array('title' => '运费', 'field' => 'dispatchprice', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1118. array('title' => '积分抵扣', 'field' => 'score_for_money', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1119. array('title' => '满额立减', 'field' => 'fullreduction_money', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1120. array('title' => '优惠券优惠', 'field' => 'voucher_credit', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1121. array('title' => '应收款(该笔订单总款)', 'field' => 'price', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1122. array('title' => '状态', 'field' => 'status', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1123. array('title' => '团长佣金', 'field' => 'head_money', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1124. array('title' => '会员佣金', 'field' => 'member_commissmoney', 'width' => 12, 'sort' => 0, 'is_check' => 0),
  1125. array('title' => '付款时间', 'field' => 'paytime', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1126. array('title' => '发货时间', 'field' => 'sendtime', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1127. array('title' => '完成时间', 'field' => 'finishtime', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1128. array('title' => '快递公司', 'field' => 'expresscom', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1129. array('title' => '完整地址', 'field' => 'fullAddress', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1130. array('title' => '订单备注', 'field' => 'remark', 'width' => 36, 'sort' => 0, 'is_check' => 0),
  1131. array('title' => '卖家订单备注', 'field' => 'remarksaler', 'width' => 36, 'sort' => 0, 'is_check' => 0),
  1132. array('title' => '商品成本价', 'field' => 'costprice', 'width' => 36, 'sort' => 0, 'is_check' => 0),
  1133. array('title' => '省市区', 'field' => 'province', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1134. array('title' => '商品重量', 'field' => 'goods_weight', 'width' => 24, 'sort' => 0, 'is_check' => 0),
  1135. );
  1136. if($order_note_open == 1){
  1137. if(empty($note_content)){
  1138. $note_content= '店名';
  1139. }
  1140. $columns[] = array('title' => $note_content, 'field' => 'note_content', 'width' => 24, 'sort' => 0, 'is_check' => 0);
  1141. }
  1142. //load_model_class('config')->update( array('modify_export_fields' => $modify_explode_arr ) );
  1143. sellerLog('订单excel导出操作', 2);
  1144. $modify_explode_json = D('Home/Front')->get_config_by_name('modify_export_fields');
  1145. if( !empty($modify_explode_json) )
  1146. {
  1147. $modify_explode_arr = json_decode($modify_explode_json, true);
  1148. foreach( $columns as $key => $val )
  1149. {
  1150. if( in_array($val['field'], array_keys($modify_explode_arr) ) )
  1151. {
  1152. $val['is_check'] =1;
  1153. $val['sort'] = $modify_explode_arr[$val['field']];
  1154. }else{
  1155. $val['is_check'] =0;
  1156. $val['sort'] = 0;
  1157. }
  1158. $columns[$key] = $val;
  1159. }
  1160. $last_index_sort = array_column($columns,'sort');
  1161. array_multisort($last_index_sort,SORT_DESC,$columns);
  1162. }
  1163. $this->post_data = $post_data;
  1164. $this->columns = $columns;
  1165. $this->_GPC = $_GPC;
  1166. $this->display();
  1167. }
  1168. public function oppay()
  1169. {
  1170. if (defined('ROLE') && ROLE == 'agenter' )
  1171. {
  1172. show_json(0, array('message' => '您无此权限') );
  1173. }
  1174. $order_id = I('request.id');
  1175. $res_arr = D('Seller/Order')->admin_pay_order($order_id);
  1176. if( $res_arr['code'] == 0)
  1177. {
  1178. show_json(0, array('message' => $res_arr['msg']) );
  1179. }else{
  1180. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1181. }
  1182. }
  1183. public function detail()
  1184. {
  1185. $id = I('get.id');
  1186. $item = M('lionfish_comshop_order')->where( array('order_id' => $id ) )->find();
  1187. if (defined('ROLE') && ROLE == 'agenter' )
  1188. {
  1189. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  1190. if($supply_can_look_headinfo != 1){
  1191. $item['ziti_name'] = D('Seller/Order')->desensitize($item['ziti_name'],1,1);
  1192. $item['ziti_mobile'] = D('Seller/Order')->desensitize($item['ziti_mobile'],3,4);
  1193. }
  1194. }
  1195. switch ($item['delivery']){
  1196. case 'pickup':$item['delivery_text'] = '社区自提';break;
  1197. case 'express':$item['delivery_text'] = '快递';break;
  1198. case 'tuanz_send':$item['delivery_text'] = '团长配送';break;
  1199. case 'hexiao':$item['delivery_text'] = '到店核销';break;
  1200. }
  1201. //预收订单信息begin
  1202. $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $id );
  1203. if( $presale_result['code'] == 0 )
  1204. {
  1205. $item['presale_info'] = $presale_result['data'];
  1206. }else{
  1207. $item['presale_info'] = [];
  1208. }
  1209. //预收订单信息end
  1210. if($item['type'] == 'pintuan'){
  1211. $pin_order = M('lionfish_comshop_pin_order')->field('pin_id')->where( array('order_id' => $id ) )->find();
  1212. $pin_id = $pin_order['pin_id'];
  1213. $this->pin_id = $pin_id;
  1214. }
  1215. $order_goods = array();
  1216. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $id) )->select();
  1217. $need_order_goods = array();
  1218. $shipping_fare = 0;
  1219. $fullreduction_money = 0;
  1220. $voucher_credit = 0;
  1221. $total = 0;
  1222. $order_head_status = 0 ;
  1223. foreach($order_goods as $key => $value)
  1224. {
  1225. // lionfish_community_head_commiss_order
  1226. $value['name'] = htmlspecialchars_decode(stripslashes($value['name']));
  1227. $head_commission_order_info = M('lionfish_community_head_commiss_order')->where( array('order_goods_id' => $value['order_goods_id'],'order_id' => $item['order_id']) )->select();
  1228. if( !empty($head_commission_order_info) )
  1229. {
  1230. foreach( $head_commission_order_info as &$vv)
  1231. {
  1232. if($vv['state'] == 1){
  1233. $order_head_status =1;
  1234. }
  1235. $head_info_tp = M('lionfish_community_head')->field('head_name')->where( array('id' => $vv['head_id'] ) )->find();
  1236. $vv['head_name'] = $head_info_tp['head_name'];
  1237. if (defined('ROLE') && ROLE == 'agenter' )
  1238. {
  1239. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  1240. if($supply_can_look_headinfo != 1){
  1241. $vv['head_name'] = D('Seller/Order')->desensitize($vv['head_name'],1,1);
  1242. }
  1243. }
  1244. //退配送费
  1245. $refund_shipping_fare = 0;
  1246. if($vv['type'] == 'orderbuy' && $vv['add_shipping_fare'] > 0){
  1247. $refund_shipping_sql = "SELECT sum(refund_shipping_fare) as refund_shipping_fare "
  1248. . " FROM ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund "
  1249. . " WHERE order_id=".$vv['order_id'].' and order_goods_id='.$vv['order_goods_id'];
  1250. $refund_shippings = M()->query($refund_shipping_sql);
  1251. if(!empty($refund_shippings)){
  1252. $refund_shipping_fare = $refund_shippings[0]['refund_shipping_fare'];
  1253. }
  1254. $vv['add_shipping_fare'] = $vv['add_shipping_fare'] - $refund_shipping_fare;
  1255. $vv['money'] = $vv['money'];
  1256. }else{
  1257. $vv['add_shipping_fare'] = $vv['add_shipping_fare'];
  1258. }
  1259. if($vv['state'] == 2){//分佣订单已取消,分佣金额为0
  1260. $vv['money'] = 0;
  1261. }
  1262. }
  1263. unset($vv);
  1264. }
  1265. if( $value['is_refund_state'] == 1 || $value['has_refund_money'] > 0)
  1266. {
  1267. $refund_info = M('lionfish_comshop_order_refund')->where( array('order_id' => $id,'order_goods_id' => $value['order_goods_id'] ) )->order('ref_id desc')->find();
  1268. $value['refund_info'] = $refund_info;
  1269. $goods_refund_shipping_fare = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $id,'order_goods_id' => $value['order_goods_id'] ) )->sum('refund_shipping_fare');
  1270. $value['goods_refund_shipping_fare'] = $goods_refund_shipping_fare;
  1271. }
  1272. if( $item['is_commission'] == 1 )
  1273. {
  1274. $member_commission_list = M('lionfish_comshop_member_commiss_order')->where( array('order_goods_id' => $value['order_goods_id'],'order_id' => $item['order_id']) )->order('id asc')->select();
  1275. if( !empty($member_commission_list) )
  1276. {
  1277. foreach( $member_commission_list as $kk => $vv )
  1278. {
  1279. $tmp_if = M('lionfish_comshop_member')->field('username')->where( array('member_id' => $vv['member_id'] ) )->find();
  1280. $vv['username'] = $tmp_if['username'];
  1281. $member_commission_list[$kk] = $vv;
  1282. }
  1283. }
  1284. $value['member_commission_list'] = $member_commission_list;
  1285. }
  1286. $value['head_commission_order_info'] = $head_commission_order_info;
  1287. $value['option_sku'] = D('Seller/Order')->get_order_option_sku($item['order_id'], $value['order_goods_id']);
  1288. //退款商品价格
  1289. $has_refund_money = M('lionfish_comshop_order_goods')->where( array('order_id' => $id,'order_goods_id' => $value['order_goods_id'] ) )->find();
  1290. $value['has_refund_money'] = $has_refund_money['has_refund_money'];
  1291. if (defined('ROLE') && ROLE == 'agenter' )
  1292. {
  1293. $supper_info = get_agent_logininfo();
  1294. if($supper_info['id'] != $value['supply_id'])
  1295. {
  1296. continue;
  1297. }
  1298. }
  1299. if( $value['supply_id'] > 0 )
  1300. {
  1301. $supply_info = D('Home/Front')->get_supply_info($value['supply_id']);
  1302. $value['supply_name'] = $supply_info['shopname'];
  1303. $value['supply_type'] = $supply_info['type'] == 1 ? '独立' :'自营';
  1304. }else{
  1305. $value['supply_name'] = '平台自营';
  1306. $value['supply_type'] = '自营';
  1307. }
  1308. $shipping_fare += $value['shipping_fare'];
  1309. $fullreduction_money += $value['fullreduction_money'];
  1310. $voucher_credit += $value['voucher_credit'];
  1311. $total += $value['total'];
  1312. if($item['delivery'] == 'hexiao'){
  1313. $value['hx_info'] = M('lionfish_comshop_order_goods_saleshexiao')->where( array('order_id' => $id,'order_goods_id' => $value['order_goods_id'] ) )->find();
  1314. if(!empty($value['hx_info'])){
  1315. if($value['hx_info']['is_hexiao_over'] == 1 || $value['hx_info']['is_hexiao_over'] == 2){
  1316. $value['hx_info']['is_can_refund'] = 0;
  1317. }else if($value['hx_info']['is_hexiao_over'] == 0){
  1318. $can_refund_quantity = floor($value['hx_info']['remain_hexiao_count']/$value['hx_info']['one_hexiao_count']);
  1319. if($can_refund_quantity >= 1){
  1320. $value['hx_info']['is_can_refund'] = 1;
  1321. }else{
  1322. $value['hx_info']['is_can_refund'] = 0;
  1323. }
  1324. }
  1325. $record_count = M('lionfish_comshop_order_goods_saleshexiao_record')->where(array('order_id' => $id,'order_goods_id' => $value['order_goods_id'] ) )->count();
  1326. $value['hx_info']['record_count'] = $record_count;
  1327. }
  1328. }
  1329. $need_order_goods[$key] = $value;
  1330. }
  1331. if (defined('ROLE') && ROLE == 'agenter' )
  1332. {
  1333. $item['shipping_fare'] = $shipping_fare;
  1334. $item['fullreduction_money'] = $fullreduction_money;
  1335. $item['voucher_credit'] = $voucher_credit;
  1336. $item['total'] = $total;
  1337. }
  1338. $order_goods = $need_order_goods;
  1339. if (empty($item)) {
  1340. $this->message('抱歉,订单不存在!', $_SERVER['HTTP_REFERER'], 'error');
  1341. }
  1342. $member = M('lionfish_comshop_member')->where( array('member_id' => $item['member_id'] ) )->find();
  1343. $province_info = D('Home/Front')->get_area_info($item['shipping_province_id']);
  1344. $city_info = D('Home/Front')->get_area_info($item['shipping_city_id']);
  1345. $area_info = D('Home/Front')->get_area_info($item['shipping_country_id']);
  1346. $express_info = array();
  1347. if( !empty($item['shipping_method']) )
  1348. {
  1349. $express_info = D('Seller/Express')->get_express_info($item['shipping_method']);
  1350. }
  1351. $this->express_info = $express_info;
  1352. $coupon = array();
  1353. //voucher_id voucher_credit
  1354. //ims_
  1355. if( $item['voucher_id'] > 0 )
  1356. {
  1357. $coupon = array();
  1358. //$coupon = pdo_fetch("select * from ".tablename('lionfish_comshop_coupon_list')." where uniacid=:uniacid and id=:id ",
  1359. //array(':uniacid' => $_W['uniacid'], ':id' => $item['voucher_id']));
  1360. }
  1361. if( $item['delivery'] == 'localtown_delivery' && ($item['order_status_id'] != 3 && $item['order_status_id'] != 5 ) )
  1362. {
  1363. $item['orderdistribution_order'] = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $item['order_id'] ) )->find();
  1364. if( !empty($item['orderdistribution_order']) && $item['orderdistribution_order'] > 0 )
  1365. {
  1366. if($item['orderdistribution_order']['orderdistribution_id'] > 0){
  1367. $orderdistribution = M('lionfish_comshop_orderdistribution')->where( array('id' => $item['orderdistribution_order']['orderdistribution_id'] ) )->find();
  1368. $item['orderdistribution_order']['username'] = $orderdistribution['username'];
  1369. }else{
  1370. /*if($item['orderdistribution_order']['orderdistribution_id'] == -1){
  1371. $item['orderdistribution_order']['username'] = "系统默认配送员";
  1372. }else{*/
  1373. if($item['orderdistribution_order']['third_distribution_type'] == 'imdada'){
  1374. $item['orderdistribution_order']['username'] = "达达平台配送";
  1375. }else if($item['orderdistribution_order']['third_distribution_type'] == 'sf'){
  1376. $item['orderdistribution_order']['username'] = "顺丰同城配送";
  1377. }else if($item['orderdistribution_order']['third_distribution_type'] == 'uupt'){
  1378. $item['orderdistribution_order']['username'] = "UU跑腿配送";
  1379. }else if($item['orderdistribution_order']['third_distribution_type'] == 'dianwoda'){
  1380. $item['orderdistribution_order']['username'] = "点我达配送";
  1381. }
  1382. //}
  1383. }
  1384. }
  1385. }
  1386. if (defined('ROLE') && ROLE == 'agenter' )
  1387. {
  1388. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  1389. if($supply_can_look_headinfo != 1){
  1390. if( $item['delivery'] == 'pickup' ){
  1391. $shipping_stree = D('Home/Front')->get_area_info($item['shipping_stree_id']);
  1392. $tuan_address = $province_info['name'].$city_info['name'].$area_info['name'];
  1393. $tuan_address2= str_replace($tuan_address, '',$item['shipping_address']);
  1394. $str = $tuan_address2;
  1395. strlen($str);
  1396. $i = mb_strlen($str,"UTF-8");
  1397. $tuan_address2 = D('Seller/Order')->desensitize($tuan_address2,1,$i-2);
  1398. $item['shipping_address'] = $province_info['name'].$city_info['name'].$area_info['name'].$tuan_address2;
  1399. }
  1400. }
  1401. }
  1402. //售后期
  1403. $open_aftersale = D('Home/Front')->get_config_by_name('open_aftersale');
  1404. //天数
  1405. $open_aftersale_time = D('Home/Front')->get_config_by_name('open_aftersale_time');
  1406. $order_settlement =" ";
  1407. //订单状态
  1408. if($item['order_status_id'] ==5 || $item['order_status_id'] ==7 ){
  1409. //已失效
  1410. $order_status = 2;
  1411. }else{
  1412. //待结算
  1413. $order_status = $order_head_status;
  1414. if(($item['order_status_id'] ==6 || $item['order_status_id'] ==11) ){
  1415. if($item['order_status_id'] ==6){
  1416. $order_settlement = $item['receive_time'] + $open_aftersale_time*86400;
  1417. }
  1418. if($item['order_status_id'] ==11){
  1419. $order_settlement = $item['finishtime'] + $open_aftersale_time*86400;
  1420. }
  1421. }
  1422. }
  1423. $this->open_aftersale = $open_aftersale;
  1424. $this->order_status = $order_status;
  1425. $this->open_aftersale_time = $open_aftersale_time;
  1426. $this->order_settlement = $order_settlement;
  1427. $this->id = $id;
  1428. $this->item = $item;
  1429. $this->order_goods = $order_goods;
  1430. $this->member = $member;
  1431. $this->province_info = $province_info;
  1432. $this->city_info = $city_info;
  1433. $this->area_info = $area_info;
  1434. $history_list = M('lionfish_comshop_order_history')->where( array('order_id' => $id ) )->order('order_history_id asc')->select();
  1435. $order_status_arr = D('Seller/Order')->get_order_status_name();
  1436. //$order_history['order_status_id'] = 18;
  1437. $order_status_arr[18] = '已结算';
  1438. $order_status_arr[19] = '商品部分退款';
  1439. $order_status_arr[20] = '拒绝商品部分退款';
  1440. $order_status_arr[15] = '预售支付定金';
  1441. foreach( $history_list as &$val )
  1442. {
  1443. if( $val[''] == '订单改价' )
  1444. {
  1445. $val['order_status_name'] = 'comment';
  1446. }
  1447. else{
  1448. $val['order_status_name'] = $order_status_arr[$val['order_status_id']];
  1449. }
  1450. }
  1451. unset($val);
  1452. $this->history_list = $history_list;
  1453. $this->order_status_arr = $order_status_arr;
  1454. $is_can_look_headinfo = true;
  1455. $is_can_nowrfund_order = true;
  1456. $is_can_confirm_delivery = true;
  1457. $is_can_confirm_receipt = true;
  1458. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  1459. $supply_can_nowrfund_order = D('Home/Front')->get_config_by_name('supply_can_nowrfund_order');
  1460. $supply_can_confirm_delivery = D('Home/Front')->get_config_by_name('supply_can_confirm_delivery');
  1461. $supply_can_confirm_receipt = D('Home/Front')->get_config_by_name('supply_can_confirm_receipt');
  1462. if (defined('ROLE') && ROLE == 'agenter' )
  1463. {
  1464. if( isset($supply_can_look_headinfo) && $supply_can_look_headinfo == 2 )
  1465. {
  1466. $is_can_look_headinfo = false;
  1467. }
  1468. if( isset($supply_can_nowrfund_order) && $supply_can_nowrfund_order == 2 )
  1469. {
  1470. $is_can_nowrfund_order = false;
  1471. }
  1472. if( isset($supply_can_confirm_delivery) && $supply_can_confirm_delivery == 2 )
  1473. {
  1474. $is_can_confirm_delivery = false;
  1475. }
  1476. if( isset($supply_can_confirm_receipt) && $supply_can_confirm_receipt == 2 )
  1477. {
  1478. $is_can_confirm_receipt = false;
  1479. }
  1480. }
  1481. $s_id = 1 ;
  1482. if(SELLERUID != 1)
  1483. {
  1484. $seller_info = M('seller')->field('s_role_id')->where( array('s_id' => SELLERUID ) )->find();
  1485. $perms_arr = M('lionfish_comshop_perm_role')->where( array('id' => $seller_info['s_role_id']) )->find();
  1486. $perms1 = str_replace('.','/',$perms_arr['perms2']);
  1487. $perms2 = explode(",", $perms1);
  1488. if(in_array("user/user/index", $perms2)){
  1489. $s_id = 1 ;
  1490. } else {
  1491. $s_id = 0 ;
  1492. }
  1493. }
  1494. $this->s_id = $s_id;
  1495. //预售判断 begin
  1496. $is_presale = 0;
  1497. $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $id );
  1498. $presale_for_ordermoney = 0;
  1499. if( $presale_result['code'] == 0 )
  1500. {
  1501. if( $presale_result['data']['presale_deduction_money'] > 0 )
  1502. {
  1503. $presale_for_ordermoney = $presale_result['data']['presale_for_ordermoney'];
  1504. }
  1505. $is_presale = 1;
  1506. }
  1507. $this->is_presale = $is_presale;
  1508. $this->presale_for_ordermoney = $presale_for_ordermoney;
  1509. //预售end
  1510. //礼品卡begin
  1511. $is_virtualcard = 0;
  1512. $virtualcard_result = D('Seller/VirtualCard')->getVirtualCardOrderInfO( $id );
  1513. if( $virtualcard_result['code'] == 0 )
  1514. {
  1515. $is_virtualcard = 1;
  1516. $this->virtualcard_info = $virtualcard_result['data'];
  1517. }
  1518. $this->is_virtualcard = $is_virtualcard;
  1519. //礼品卡end
  1520. //订单表单信息
  1521. $order_form_data = D('Home/Allform')->getOrderFormInfo($id, $item['member_id']);
  1522. $this->order_form_data = $order_form_data;
  1523. $is_order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
  1524. $order_note_name = D('Home/Front')->get_config_by_name('order_note_name');
  1525. $order_note_name = isset($order_note_name) && !empty($order_note_name) ? $order_note_name :'店名';
  1526. $open_admin_payment = D('Home/Front')->get_config_by_name('open_admin_payment');
  1527. $this->open_admin_payment = $open_admin_payment;
  1528. $localtown_modifypickingname = D('Home/Front')->get_config_by_name('localtown_modifypickingname');
  1529. $localtown_modifypickingname = !empty($localtown_modifypickingname) ? $localtown_modifypickingname: '包装费';
  1530. $this->is_order_note_open = $is_order_note_open;
  1531. $this->order_note_name = $order_note_name;
  1532. $this->is_can_look_headinfo = $is_can_look_headinfo;
  1533. $this->is_can_nowrfund_order = $is_can_nowrfund_order;
  1534. $this->is_can_confirm_delivery = $is_can_confirm_delivery;
  1535. $this->is_can_confirm_receipt = $is_can_confirm_receipt;
  1536. $this->localtown_modifypickingname = $localtown_modifypickingname;
  1537. $this->display();
  1538. }
  1539. //查看物流
  1540. public function express(){
  1541. $_GPC = I('request.');
  1542. $order_id = $_GPC['order_id'];
  1543. $express_list = D('Seller/Order')->goods_express($order_id);
  1544. if($express_list['code'] == 2){
  1545. $code = $express_list['code'];
  1546. $reason = $express_list['Reason'];
  1547. $this->code = $code;
  1548. $this->reason = $reason;
  1549. }
  1550. $new_array = json_decode(json_encode($express_list['order_info']['shipping_traces']), true);
  1551. $new_array = array_reverse($new_array);
  1552. $this->list = $new_array;
  1553. $this->display();
  1554. }
  1555. public function refund_mult()
  1556. {
  1557. $_GPC = I('request.');
  1558. $ids_arr = $_GPC['ids_arr'];
  1559. $cache_key = md5(time().count($ids_arr).'_sendmulutrefund');
  1560. $quene_order_list = array();
  1561. //限定配送数组
  1562. S('_multrefund_'.$cache_key, $ids_arr);
  1563. $this->_GPC = $_GPC;
  1564. $this->cache_key = $cache_key;
  1565. $this->display();
  1566. }
  1567. public function refund_mult_do()
  1568. {
  1569. $_GPC = I('request.');
  1570. $cache_key = $_GPC['cache_key'];
  1571. $quene_order_list = S('_multrefund_'.$cache_key);
  1572. $order_id = array_shift($quene_order_list);
  1573. S('_multrefund_'.$cache_key, $quene_order_list);
  1574. //...
  1575. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  1576. $weixin_model = D('Home/Weixin');
  1577. $title = '订单编号:'.$order_info['order_num_alias']." 处理成功,还剩余".count($quene_order_list)."个订单未处理";
  1578. //order_status_id
  1579. if( in_array($order_info['order_status_id'], array(1,4,6,10,11,12,14)) ){
  1580. $res = $weixin_model->refundOrder($order_id);
  1581. if( $res['code'] == 0 )
  1582. {
  1583. $title = '订单编号:'.$order_info['order_num_alias']." 退款失败,还剩余".count($quene_order_list)."个清单未处理";
  1584. }else{
  1585. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  1586. $comment = '群接龙批量退款,全额退款';
  1587. $order_history = array();
  1588. $order_history['order_id'] = $order_id;
  1589. $order_history['order_status_id'] = 7;
  1590. $order_history['notify'] = 0;
  1591. $order_history['comment'] = $comment;
  1592. $order_history['date_added'] = time();
  1593. M('lionfish_comshop_order_history')->add( $order_history );
  1594. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('order_status_id' => 7) );
  1595. $refund_all = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_id, 'state' => 0 ) )->select();
  1596. if( !empty($refund_all) )
  1597. {
  1598. foreach( $refund_all as $val )
  1599. {
  1600. $ins_data = array();
  1601. $ins_data['ref_id'] = $val['ref_id'];
  1602. $ins_data['order_id'] = $val['order_id'];
  1603. $ins_data['order_goods_id'] = $val['order_goods_id'];
  1604. $ins_data['message'] = '群接龙批量退款 ,退款成功';
  1605. $ins_data['type'] = 2;
  1606. $ins_data['addtime'] = time();
  1607. M('lionfish_comshop_order_refund_history')->add( $ins_data );
  1608. M('lionfish_comshop_order_refund')->where( array('ref_id' => $val['ref_id']) )->save( array('state' => 3) );
  1609. }
  1610. }
  1611. $is_print_admin_cancleorder = D('Home/Front')->get_config_by_name('is_print_admin_cancleorder');
  1612. if( isset($is_print_admin_cancleorder) && $is_print_admin_cancleorder == 1 )
  1613. {
  1614. sellerLog('群接龙后台取消订单', 2);
  1615. D('Seller/Printaction')->check_print_order($id,'群接龙后台取消订单');
  1616. D('Seller/Printaction')->check_print_order2($id,'群接龙后台取消订单');
  1617. }
  1618. }
  1619. }
  1620. if( empty($quene_order_list) )
  1621. {
  1622. echo json_encode( array('code' => 2) );
  1623. die();
  1624. }
  1625. //清单编号
  1626. echo json_encode( array('code' => 0, 'msg' => $title ) );
  1627. die();
  1628. }
  1629. public function opreceive()
  1630. {
  1631. $opdata = $this->check_order_data();
  1632. extract($opdata);
  1633. //检查订单是否能确认收货(存在售后未完成无法确认收货)
  1634. $result = D('Seller/Order')->check_order_receive($item['order_id']);
  1635. if($result['status'] == 0){
  1636. show_json(0, array('msg'=>"该订单处于售后处理中,请处理后再确认收货!"));
  1637. }
  1638. if($item['delivery'] == 'localtown_delivery') {
  1639. $result = D('Seller/Order')->check_localtown_order_receive($item['order_id']);
  1640. if ($result['status'] == 0) {
  1641. show_json(0, array('msg' => "该订单未有配送员接单或还未指定配送员,无法确认收货!"));
  1642. }
  1643. }
  1644. //pdo_update('lionfish_comshop_order', array('order_status_id' => 6, 'receive_time' => time()), array('order_id' => $item['order_id'], 'uniacid' => $_W['uniacid']));
  1645. if( $item['delivery'] == 'localtown_delivery' )
  1646. {
  1647. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $item['order_id']) )->save( array('state' => 4) );
  1648. D('Home/LocaltownDelivery')->write_distribution_log( $item['order_id'], 0 , 4 , "后台操作,确认收货" );
  1649. }
  1650. D('Seller/Order')->receive_order($item['order_id']);
  1651. M('lionfish_comshop_order_history')->where( array('order_id' => $item['order_id'],'order_status_id' => 6) )->save( array( 'comment' => '后台操作,确认收货') );
  1652. if( $item['delivery'] == 'localtown_delivery' )
  1653. {
  1654. //D('Home/LocaltownDelivery')->distribution_deliverying_order( $item['order_id'] );
  1655. D('Home/LocaltownDelivery')->distribution_arrived_order( $item['order_id'] ,0 );
  1656. }
  1657. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1658. }
  1659. public function orderaftersales()
  1660. {
  1661. //$_GPC['order_status_id'] = 12;
  1662. $gpc = I('request.');
  1663. $this->gpc = $gpc;
  1664. $this->_GPC = $gpc;
  1665. $time = I('request.time');
  1666. $starttime = isset($time['start']) ? strtotime($time['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  1667. $endtime = isset($time['end']) ? strtotime($time['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  1668. $this->searchfield = I('request.searchfield','');
  1669. $this->keyword = I('request.keyword','');
  1670. $this->searchtime = I('request.searchtime','');
  1671. $this->delivery = I('request.delivery','');
  1672. $this->starttime = $starttime;
  1673. $this->endtime = $endtime;
  1674. $this->time = $time;
  1675. $order_status_arr = D('Seller/Order')->get_order_status_name();
  1676. $this->order_status_arr = $order_status_arr;
  1677. $need_data = D('Seller/Order')->load_afterorder_list();//改造原来的加载方法
  1678. $this->need_data = $need_data;
  1679. $cur_controller = 'order/order';
  1680. $total = $need_data['total'];
  1681. $total_money = $need_data['total_money'];
  1682. $list = $need_data['list'];
  1683. $pager = $need_data['pager'];
  1684. $all_count = $need_data['all_count'];
  1685. $count_status_1 = $need_data['count_status_1'];
  1686. $count_status_3 = $need_data['count_status_3'];
  1687. $count_status_4 = $need_data['count_status_4'];
  1688. $count_status_5 = $need_data['count_status_5'];
  1689. $count_status_7 = $need_data['count_status_7'];
  1690. $count_status_11 = $need_data['count_status_11'];
  1691. $count_status_14 = $need_data['count_status_14'];
  1692. $this->cur_controller = $cur_controller;
  1693. $this->total = $total;
  1694. $this->total_money = $total_money;
  1695. $this->list = $list;
  1696. $this->pager = $pager;
  1697. $this->all_count = $all_count;
  1698. $this->count_status_1 = $count_status_1;
  1699. $this->count_status_3 = $count_status_3;
  1700. $this->count_status_4 = $count_status_4;
  1701. $this->count_status_5 = $count_status_5;
  1702. $this->count_status_7 = $count_status_7;
  1703. $this->count_status_11 = $count_status_11;
  1704. $this->count_status_14 = $count_status_14;
  1705. $s_id = 1 ;
  1706. if(SELLERUID != 1)
  1707. {
  1708. $seller_info = M('seller')->field('s_role_id')->where( array('s_id' => SELLERUID ) )->find();
  1709. $perms_arr = M('lionfish_comshop_perm_role')->where( array('id' => $seller_info['s_role_id']) )->find();
  1710. $perms1 = str_replace('.','/',$perms_arr['perms2']);
  1711. $perms2 = explode(",", $perms1);
  1712. if(in_array("user/user/index", $perms2)){
  1713. $s_id = 1 ;
  1714. } else {
  1715. $s_id = 0 ;
  1716. }
  1717. }
  1718. $this->s_id = $s_id;
  1719. $open_feier_print = D('Home/Front')->get_config_by_name('open_feier_print');
  1720. if( empty($open_feier_print) )
  1721. {
  1722. $open_feier_print = 0;
  1723. }
  1724. $this->open_feier_print = $open_feier_print;
  1725. //退款状态:0申请中,1商家拒绝,2平台介入,3退款成功,4退款失败,5:撤销申请
  1726. $order_refund_state = array(0=>'申请中',1=>'商家拒绝', 2=>'平台介入',3=>'退款成功',4=>'退款失败',5=>'撤销申请');
  1727. $this->order_refund_state = $order_refund_state;
  1728. $is_can_look_headinfo = true;
  1729. $is_can_nowrfund_order = true;
  1730. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  1731. $supply_can_nowrfund_order = D('Home/Front')->get_config_by_name('supply_can_nowrfund_order');
  1732. if (defined('ROLE') && ROLE == 'agenter' )
  1733. {
  1734. if( isset($supply_can_look_headinfo) && $supply_can_look_headinfo == 2 )
  1735. {
  1736. $is_can_look_headinfo = false;
  1737. }
  1738. if( isset($supply_can_nowrfund_order) && $supply_can_nowrfund_order == 2 )
  1739. {
  1740. $is_can_nowrfund_order = false;
  1741. }
  1742. }
  1743. $this->is_can_look_headinfo = $is_can_look_headinfo;
  1744. $this->is_can_nowrfund_order = $is_can_nowrfund_order;
  1745. $this->display();
  1746. }
  1747. public function oprefund_doform()
  1748. {
  1749. $_GPC = I('request.');
  1750. $ref_id = $_GPC['ref_id'];
  1751. $refund_info = M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id ) )->find();
  1752. $this->ref_id = $ref_id;
  1753. $this->refund_info = $refund_info;
  1754. if (IS_POST) {
  1755. $order_history = array();
  1756. $order_history['order_id'] = $refund_info['order_id'];
  1757. $order_history['order_status_id'] = 0;
  1758. $order_history['notify'] = 0;
  1759. $order_history['comment'] = '';
  1760. $order_history['date_added'] = time();
  1761. $remarkrefund = $_GPC['remarkrefund'];
  1762. $is_forbidden = $_GPC['is_forbidden'];
  1763. $cansub = $_GPC['cansub'];
  1764. if( isset($_GPC['is_forbidden']) && $_GPC['is_forbidden'] > 0 )
  1765. {
  1766. //添加
  1767. $refund_disable = M('lionfish_comshop_order_refund_disable')->where( array('ref_id' => $ref_id ) )->find();
  1768. if( empty($refund_disable) )
  1769. {
  1770. //插入
  1771. $ins_data = array();
  1772. $ins_data['ref_id'] = $ref_id;
  1773. $ins_data['order_id'] = $refund_info['order_id'];
  1774. $ins_data['order_goods_id'] = $refund_info['order_goods_id'];
  1775. $ins_data['addtime'] = time();
  1776. M('lionfish_comshop_order_refund_disable')->add($ins_data);
  1777. }
  1778. }else{
  1779. //删除
  1780. M('lionfish_comshop_order_refund_disable')->where( array('ref_id' => $ref_id ) )->delete();
  1781. }
  1782. if($cansub == 1)
  1783. {
  1784. //确认退款 remarkrefund
  1785. $weixin_model = D('Home/Weixin');
  1786. $order_refund = M('lionfish_comshop_order_refund')->field('ref_money,real_refund_quantity,ref_shipping_fare')->where( array('ref_id' => $ref_id ) )->find();
  1787. //$order_info['total']
  1788. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $refund_info['order_id'] ) )->find();
  1789. if( $order_info['type'] == 'integral' || $order_info['type'] == 'normal' )
  1790. {
  1791. //M('lionfish_comshop_order')->where( array('order_id' => $refund_info['order_id'] ) )->save( array('shipping_fare' => $order_refund['ref_shipping_fare'] ) );
  1792. if( !empty($refund_info['order_goods_id']) && $refund_info['order_goods_id'] > 0 )
  1793. {
  1794. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_goods_id' =>$refund_info['order_goods_id'] ) )->find();
  1795. M('lionfish_comshop_order_goods')->where( array('order_goods_id' =>$refund_info['order_goods_id'] ) )->save( array('shipping_fare' => $order_refund['ref_shipping_fare'] ) );
  1796. }
  1797. }
  1798. if( $order_refund['real_refund_quantity'] > 0 )
  1799. {
  1800. //部分商品退款
  1801. $res = $weixin_model->refundOrder($refund_info['order_id'], $order_refund['ref_money'],0,$refund_info['order_goods_id'],1, $order_refund['real_refund_quantity'],1);
  1802. }else{
  1803. $res = $weixin_model->refundOrder($refund_info['order_id'], $order_refund['ref_money'],0,$refund_info['order_goods_id']);
  1804. }
  1805. if( $order_info['type'] == 'integral' || $order_info['type'] == 'normal')
  1806. {
  1807. //M('lionfish_comshop_order')->where( array('order_id' => $refund_info['order_id'] ) )->save( array('shipping_fare' => $order_info['shipping_fare'] ) );
  1808. if( !empty($refund_info['order_goods_id']) && $refund_info['order_goods_id'] > 0 )
  1809. {
  1810. M('lionfish_comshop_order_goods')->where( array('order_goods_id' =>$refund_info['order_goods_id'] ) )->save( array('shipping_fare' => $order_goods['shipping_fare'] ) );
  1811. }
  1812. }
  1813. if($res['code'] == 1)
  1814. {
  1815. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $refund_info['order_goods_id'] , 'order_id' => $refund_info['order_id'] ) )->find();
  1816. if( $order_refund['real_refund_quantity'] <= 0 )
  1817. {
  1818. $order_refund['real_refund_quantity'] = $order_goods['quantity'] - $order_goods['has_refund_quantity'];
  1819. }
  1820. $pay_total_money = $order_goods['total']-$order_goods['voucher_credit']-$order_goods['fullreduction_money'] - $order_goods['score_for_money'];
  1821. $buy_usescore = D('Seller/Commonorder')->get_order_goods_buyscore($refund_info['order_id'], $refund_info['order_goods_id']);
  1822. if( !empty($buy_usescore) && $buy_usescore > 0 )
  1823. {
  1824. $res_score= ceil( $buy_usescore * ( $order_refund['real_refund_quantity']/ $order_goods['quantity']) );
  1825. D('Seller/Commonorder')->refund_order_goods_intrgral( $refund_info['order_id'], $refund_info['order_goods_id'] ,$res_score );
  1826. }
  1827. if($order_refund['ref_money']-$order_refund['ref_shipping_fare'] <= 0){
  1828. $refund_money = 0;
  1829. }else{
  1830. $refund_money = $order_refund['ref_money']-$order_refund['ref_shipping_fare'];
  1831. }
  1832. if( $order_info['type'] == 'integral'){
  1833. $refund_money = $order_refund['ref_money'];
  1834. }
  1835. //退款配送费问题
  1836. D('Seller/Commonorder')->ins_order_goods_refund($refund_info['order_id'], $refund_info['order_goods_id'],$pay_total_money,$order_refund['real_refund_quantity'], $order_refund['real_refund_quantity'],$refund_money,1,$order_refund['ref_shipping_fare']);
  1837. //如果这个商品没有数量了。就改变他的状态为已退款的状态
  1838. $new_total_quantity = D('Seller/Commonorder')->get_order_goods_quantity($refund_info['order_id'],$refund_info['order_goods_id'] );
  1839. $ref_count = M('lionfish_comshop_order_refund')->where( array('order_id' => $refund_info['order_id'], 'state' => 0 ) )->count();
  1840. if( $new_total_quantity <=0 && $ref_count <= 1)
  1841. {
  1842. D('Seller/Commonorder')->check_refund_order_goods_status($refund_info['order_id'],$refund_info['order_goods_id'], $order_refund['ref_money'],1,$order_refund['real_refund_quantity'], $order_refund['real_refund_quantity'],1,'平台同意退款,');
  1843. }else{
  1844. $order_history = array();
  1845. $order_history['uniacid'] = 0;
  1846. $order_history['order_id'] = $refund_info['order_id'];
  1847. $order_history['order_goods_id'] = $refund_info['order_goods_id'];
  1848. $order_history['notify'] = 0;
  1849. $order_history['order_status_id'] = 19;
  1850. if( $order_info['type'] == 'integral' )
  1851. {
  1852. $order_history['comment'] = '平台同意退款,子订单退款,退款商品:'.$order_refund['real_refund_quantity'] .'个,退库存/销量数量'.$order_refund['real_refund_quantity'].'个,退款积分'.$order_refund['ref_money'].'积分';
  1853. if( !empty($order_refund['ref_shipping_fare']) ){
  1854. $order_history['comment'] .= '. 退配送费:'.$order_refund['ref_shipping_fare'].'元';
  1855. }
  1856. }else{
  1857. $order_history['comment'] = '平台同意退款,子订单退款,退款商品:'.$order_refund['real_refund_quantity'] .'个,退库存/销量数量'.$order_refund['real_refund_quantity'].'个,退款金额'.$order_refund['ref_money'].'元';
  1858. }
  1859. $order_history['date_added'] = time();
  1860. M('lionfish_comshop_order_history')->add( $order_history );
  1861. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $refund_info['order_goods_id'] ) )->save( array('is_refund_state' => 0 ) );
  1862. }
  1863. //D('Seller/Commonorder')->ins_order_goods_refund($order_id, $order_goods_id,$pay_total_money,$real_refund_quantity, $refund_quantity,$refund_money, $is_back_sellcount);
  1864. $order_refund_history = array();
  1865. $order_refund_history['ref_id'] = $ref_id;
  1866. $order_refund_history['order_id'] = $refund_info['order_id'];
  1867. $order_refund_history['order_goods_id'] = $refund_info['order_goods_id'];
  1868. $order_refund_history['message'] = '平台同意退款'.' '.$remarkrefund.' ,退款成功';
  1869. $order_refund_history['type'] = 2;
  1870. $order_refund_history['addtime'] = time();
  1871. M('lionfish_comshop_order_refund_history')->add( $order_refund_history );
  1872. //通过 lionfish_comshop_order_refund
  1873. sellerLog('同意'.$remarkrefund.'退款成功操作', 2);
  1874. M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id) )->save( array('state' => 3,'modify_time' => time(),'remarkrefund' => $remarkrefund) );
  1875. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1876. }else{
  1877. if( empty($res['msg']) )
  1878. {
  1879. $res['msg'] = '请检查商户号与cert证书';
  1880. }
  1881. $order_refund_history = array();
  1882. $order_refund_history['ref_id'] = $ref_id;
  1883. $order_refund_history['order_id'] = $refund_info['order_id'];
  1884. $order_refund_history['order_goods_id'] = $refund_info['order_goods_id'];
  1885. $order_refund_history['message'] = '平台同意退款'.' '.$remarkrefund.' ,但是退款失败:'.$res['msg'];
  1886. $order_refund_history['type'] = 2;
  1887. $order_refund_history['addtime'] = time();
  1888. M('lionfish_comshop_order_refund_history')->add( $order_refund_history );
  1889. show_json(0, array('message' => $res['msg']) );
  1890. }
  1891. }else if($cansub == 2){
  1892. //拒绝退款
  1893. $order_refund_history = array();
  1894. $order_refund_history['ref_id'] = $ref_id;
  1895. $order_refund_history['order_id'] = $refund_info['order_id'];
  1896. $order_refund_history['order_goods_id'] = $refund_info['order_goods_id'];
  1897. $order_refund_history['message'] = '平台拒绝退款'.' '.$remarkrefund;
  1898. $order_refund_history['type'] = 2;
  1899. $order_refund_history['addtime'] = time();
  1900. M('lionfish_comshop_order_refund_history')->add( $order_refund_history );
  1901. M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id) )->save( array('state' => 1,'modify_time' => time(),'remarkrefund' => $remarkrefund ) );
  1902. $item = M('lionfish_comshop_order')->field('order_status_id,last_refund_order_status_id')->where( array('order_id' => $refund_info['order_id'] ) )->find();
  1903. $order_history['order_status_id'] = 20;
  1904. //如果是部分退款,那么就不是12了
  1905. if( $item['order_status_id'] == 12)
  1906. {
  1907. $order_history['order_status_id'] = 12;
  1908. if( $item['last_refund_order_status_id'] > 0 )
  1909. {
  1910. $order_history['order_status_id'] = $item['last_refund_order_status_id'];
  1911. M('lionfish_comshop_order')->where( array('order_id' => $refund_info['order_id'] ) )->save( array('order_status_id' => $item['last_refund_order_status_id']) );
  1912. $order_history['order_status_id'] = $item['last_refund_order_status_id'];
  1913. $order_history['comment'] = '商家拒绝退款,订单回退上一状态';
  1914. }else{
  1915. $order_history['comment'] = '商家拒绝退款';
  1916. }
  1917. }
  1918. if( !empty($refund_info['order_goods_id']) && $refund_info['order_goods_id'] > 0 )
  1919. {
  1920. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $refund_info['order_goods_id'] ) )->save( array('is_refund_state' => 0) );
  1921. }
  1922. //拒绝 order_status_id
  1923. sellerLog($order_history['comment'].'操作', 2);
  1924. M('lionfish_comshop_order_history')->add( $order_history );
  1925. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1926. }
  1927. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1928. }
  1929. $this->display();
  1930. }
  1931. public function oprefund()
  1932. {
  1933. $_GPC = I('request.');
  1934. $opdata = $this->check_order_data();
  1935. extract($opdata);
  1936. $ref_id = $_GPC['ref_id'];
  1937. $ref_info = M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id ) )->find();
  1938. $step_array = array();
  1939. $step_array[1]['step'] = 1;
  1940. $step_array[1]['title'] = '客户发起退款';
  1941. $step_array[1]['time'] = $ref_info['addtime'];
  1942. $step_array[1]['done'] = 1;
  1943. $step_array[2]['step'] = 2;
  1944. $step_array[2]['title'] = '平台处理维权申请';
  1945. $step_array[2]['done'] = 0;
  1946. $step_array[2]['time'] = '';
  1947. $step_array[3]['step'] = 3;
  1948. $step_array[3]['done'] = 0;
  1949. $step_array[3]['title'] = '商家处理退款完成';
  1950. $step_array[3]['time'] = '';
  1951. $ref_id = I('request.ref_id');
  1952. $this->ref_id = $ref_id;
  1953. $this->ref_info = $ref_info;
  1954. $order_goods_id = $ref_info['order_goods_id'];
  1955. if( !empty($order_goods_id) && $order_goods_id > 0 )
  1956. {
  1957. $goods = M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id, 'order_id' => $id ) )->select();
  1958. }else{
  1959. $goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $id ) )->select();
  1960. }
  1961. $total_fare = 0;
  1962. $total_shipping_fare = 0;
  1963. $total_voucher_credit =0;
  1964. $total_fullreduction_money = 0;
  1965. $total_total_fare = 0;
  1966. $total_score_for_money = 0;
  1967. /**
  1968. php echo number_format($item['total']+$item['shipping_fare']-$item['voucher_credit']-$item['fullreduction_money'],2)
  1969. **/
  1970. foreach($goods as &$value)
  1971. {
  1972. $value['option_sku'] = D('Seller/Order')->get_order_option_sku($item['order_id'], $value['order_goods_id']);
  1973. $total_fare += $value['total'];
  1974. $total_shipping_fare += $value['shipping_fare'];
  1975. $total_voucher_credit += $value['voucher_credit'];
  1976. $total_fullreduction_money += $value['fullreduction_money'];
  1977. $total_score_for_money += $value['score_for_money'];
  1978. $total_total_fare += $value['total']+$value['shipping_fare']-$value['voucher_credit']-$value['fullreduction_money']-$value['score_for_money'];
  1979. }
  1980. $this->goods = $goods;
  1981. $this->total_fare = $total_fare;
  1982. $this->total_shipping_fare = $total_shipping_fare;
  1983. $this->total_voucher_credit = $total_voucher_credit;
  1984. $this->total_fullreduction_money = $total_fullreduction_money;
  1985. $this->total_score_for_money = $total_score_for_money;
  1986. $this->total_total_fare = $total_total_fare;
  1987. unset($r);
  1988. $item['goods'] = $goods;
  1989. $member = M('lionfish_comshop_member')->where( array('member_id' => $item['member_id']) )->find();
  1990. $this->member = $member;
  1991. $express_list = array();
  1992. $r_type = array(1=>'仅退款',2 => '退款退货');
  1993. //ims_
  1994. $this->r_type =$r_type;
  1995. $order_refund = M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id) )->find();
  1996. $this->order_refund = $order_refund;
  1997. if($order_refund['modify_time'] != 0 && $order_refund['state']== 3)
  1998. {
  1999. $step_array[3]['done'] = 1;
  2000. $step_array[3]['time'] = $order_refund['modify_time'];
  2001. }
  2002. $refund_imgs = M('lionfish_comshop_order_refund_image')->where( array('ref_id' => $order_refund['ref_id'] ) )->select();
  2003. $this->refund_imgs = $refund_imgs;
  2004. /**
  2005. if( !empty($order_goods_id) && $order_goods_id > 0 )
  2006. {
  2007. $order_refund_history = M('lionfish_comshop_order_refund_history')->where( array('order_id' =>$id,'order_goods_id' => $order_goods_id ) )->order('addtime asc')->select();
  2008. }
  2009. else{
  2010. $order_refund_history = M('lionfish_comshop_order_refund_history')->where( array('order_id' =>$id ) )->order('addtime asc')->select();
  2011. }
  2012. **/
  2013. $order_refund_history = M('lionfish_comshop_order_refund_history')->where( array('ref_id' => $ref_id ) )->order('addtime asc')->select();
  2014. $i = 1;
  2015. foreach($order_refund_history as $key => $val)
  2016. {
  2017. if( $i == 1 && $val['type'] == 2 )
  2018. {
  2019. $step_array[2]['done'] = 1;
  2020. $step_array[2]['time'] = time();
  2021. $i++;
  2022. }
  2023. $val['type'] = $val['type'] == 1 ?'用户反馈':'商家反馈';
  2024. switch($val['type'])
  2025. {
  2026. case 1:
  2027. $val['type'] = '用户反馈';
  2028. break;
  2029. case 2:
  2030. $val['type'] = '商家反馈';
  2031. break;
  2032. case 3:
  2033. $val['type'] = '平台反馈';
  2034. break;
  2035. }
  2036. $order_refund_history_image = M('lionfish_comshop_order_refund_history_image')->where( array('orh_id' => $val['id']) )->select();
  2037. if(!empty($order_refund_history_image))
  2038. {
  2039. foreach($order_refund_history_image as $kk => $vv)
  2040. {
  2041. $vv['thumb_image'] = resize ($vv['image'], 200,200);
  2042. $order_refund_history_image[$kk] = $vv;
  2043. }
  2044. }
  2045. $val['order_refund_history_image'] = $order_refund_history_image;
  2046. $order_refund_history[$key] = $val;
  2047. }
  2048. $this->step_array = $step_array;
  2049. $this->order_refund_history = $order_refund_history;
  2050. $this->item = $item;
  2051. $this->display();
  2052. }
  2053. public function oprefund_submit()
  2054. {
  2055. $gpc = I('request.');
  2056. $opdata = $this->check_order_data();
  2057. extract($opdata);
  2058. if (IS_POST) {
  2059. $id = $gpc['id'];
  2060. //refundstatus message refundcontent
  2061. $refundstatus = $gpc['refundstatus'];
  2062. $message = $gpc['message'];
  2063. $refundcontent = $gpc['refundcontent'];
  2064. $ref_id = $gpc['refundid'];
  2065. /**
  2066. int(37)
  2067. string(1) "1"
  2068. string(0) ""
  2069. string(15) "天天来退货"
  2070. **/
  2071. //1 ,3
  2072. $comment = '';
  2073. switch( $refundstatus )
  2074. {
  2075. case 1:
  2076. $comment = $refundcontent;
  2077. break;
  2078. case 3:
  2079. $comment = $message;
  2080. break;
  2081. }
  2082. $ref_info = M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id ) )->find();
  2083. $result = array('code' =>1);
  2084. $order_refund_history = array();
  2085. $order_refund_history['order_id'] = $ref_info['order_id'];
  2086. $order_refund_history['order_goods_id'] = $ref_info['order_goods_id'];
  2087. $order_refund_history['message'] = htmlspecialchars($comment);
  2088. $order_refund_history['type'] = 2;
  2089. $order_refund_history['addtime'] = time();
  2090. M('lionfish_comshop_order_refund_history')->add($order_refund_history);
  2091. $order_history = array();
  2092. $order_history['order_id'] = $id;
  2093. $order_history['order_status_id'] = 0;
  2094. $order_history['notify'] = 0;
  2095. $order_history['comment'] = '';
  2096. $order_history['date_added'] = time();
  2097. if($refundstatus ==1)
  2098. {
  2099. M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id) )->save( array('state' => 1) );
  2100. //id item $order_info $item
  2101. $item = M('lionfish_comshop_order')->field('order_status_id,last_refund_order_status_id')->where( array('order_id' => $id ) )->find();
  2102. //如果是部分退款,那么就不是12了
  2103. if( $item['order_status_id'] == 12)
  2104. {
  2105. $order_history['order_status_id'] = 12;
  2106. if( $item['last_refund_order_status_id'] > 0 )
  2107. {
  2108. $order_history['order_status_id'] = $item['last_refund_order_status_id'];
  2109. M('lionfish_comshop_order')->where( array('order_id' => $id) )->save( array('order_status_id' =>$item['last_refund_order_status_id'] ) );
  2110. $order_history['order_status_id'] = $item['last_refund_order_status_id'];
  2111. }
  2112. }
  2113. if( !empty($ref_info['order_goods_id']) && $ref_info['order_goods_id'] > 0 )
  2114. {
  2115. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $ref_info['order_goods_id'] ) )->save( array('is_refund_state' =>0 ) );
  2116. }
  2117. //拒绝 order_status_id
  2118. $order_history['comment'] = '商家拒绝退款,订单回退上一状态';
  2119. M('lionfish_comshop_order_history')->add( $order_history );
  2120. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2121. } else {
  2122. $weixin_model = D('Home/Weixin');
  2123. $order_refund = M('lionfish_comshop_order_refund')->field('ref_money')->where( array('ref_id' => $ref_id) )->find();
  2124. $res = $weixin_model->refundOrder($id, $order_refund['ref_money'],0,$ref_info['order_goods_id']);
  2125. //array('code' => 0, 'msg' => $res['err_code_des']);
  2126. if($res['code'] == 1)
  2127. {
  2128. $order_history['order_status_id'] = 7;
  2129. $order_history['comment'] = '商家同意退款';
  2130. M('lionfish_comshop_order_history')->add( $order_history );
  2131. //通过 lionfish_comshop_order_refund
  2132. M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id) )->save( array('state' => 3) );
  2133. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2134. }else{
  2135. if( empty($res['msg']) )
  2136. {
  2137. $res['msg'] = '请检查商户号与cert证书';
  2138. }
  2139. show_json(0, array('message' => $res['msg']) );
  2140. }
  2141. }
  2142. }
  2143. $r_type = array(1=>'仅退款',2 => '退款退货');
  2144. //ims_
  2145. $order_refund = M('lionfish_comshop_order_refund')->where( array('order_id' => $id) )->find();
  2146. $refund_imgs = M('lionfish_comshop_order_refund_image')->where( array('ref_id' => $order_refund['ref_id']) )->find();
  2147. $order_refund_history = M('lionfish_comshop_order_refund_history')->where( array('order_id' => $id) )->order('addtime asc')->select();
  2148. foreach($order_refund_history as $key => $val)
  2149. {
  2150. $val['type'] = $val['type'] == 1 ?'用户反馈':'商家反馈';
  2151. switch($val['type'])
  2152. {
  2153. case 1:
  2154. $val['type'] = '用户反馈';
  2155. break;
  2156. case 2:
  2157. $val['type'] = '商家反馈';
  2158. break;
  2159. case 3:
  2160. $val['type'] = '平台反馈';
  2161. break;
  2162. }
  2163. $order_refund_history_image = M('lionfish_comshop_order_refund_history_image')->where( array('orh_id' => $val['id']) )->select();
  2164. if(!empty($order_refund_history_image))
  2165. {
  2166. foreach($order_refund_history_image as $kk => $vv)
  2167. {
  2168. $vv['thumb_image'] = resize ($vv['image'], 200,200);
  2169. $order_refund_history_image[$kk] = $vv;
  2170. }
  2171. }
  2172. $val['order_refund_history_image'] = $order_refund_history_image;
  2173. $order_refund_history[$key] = $val;
  2174. }
  2175. $this->order_refund = $order_refund;
  2176. $this->r_type = $r_type;
  2177. $this->item = $item;
  2178. $this->display();
  2179. }
  2180. public function ordercomment_gift()
  2181. {
  2182. if (IS_POST) {
  2183. $data = array();
  2184. $data = I('request.data');
  2185. $data['open_comment_gift'] = trim($data['open_comment_gift']);
  2186. $data['comment_gift_score'] = trim($data['comment_gift_score']);
  2187. $data['comment_gift_time'] = trim($data['comment_gift_time']);
  2188. $data['comment_gift_max_score'] = trim($data['comment_gift_max_score']);
  2189. $data['comment_gift_publish'] = trim($data['comment_gift_publish']);
  2190. D('Seller/Config')->update($data);
  2191. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2192. }
  2193. $data = D('Seller/Config')->get_all_config();
  2194. if(empty($data['comment_gift_publish'])){
  2195. $data['comment_gift_publish'] = "​参与好评有礼活动,好评成功并且后台审核通过以后可获得获得活动积分";
  2196. }
  2197. $this->data = $data;
  2198. $this->display();
  2199. }
  2200. public function ordercomment_config()
  2201. {
  2202. if (IS_POST) {
  2203. $data = array();
  2204. $data = I('request.data');
  2205. $data['open_comment_shenhe'] = trim($data['open_comment_shenhe']);
  2206. D('Seller/Config')->update($data);
  2207. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2208. }
  2209. $data = D('Seller/Config')->get_all_config();
  2210. $this->data = $data;
  2211. $this->display();
  2212. }
  2213. public function ordercomment()
  2214. {
  2215. $condition = ' 1 ';//0
  2216. $pindex = I('request.page', 1);
  2217. $psize = 20;
  2218. $keyword = I('request.keyword');
  2219. $this->keyword = $keyword;
  2220. if (!empty($keyword)) {
  2221. $condition .= ' and content like '.'"%' . $keyword . '%" ';
  2222. }
  2223. $label = M()->query('SELECT * FROM ' . C('DB_PREFIX'). "lionfish_comshop_order_comment
  2224. WHERE " . $condition . ' order by comment_id desc limit ' . (($pindex - 1) * $psize) . ',' . $psize);
  2225. $total = M('lionfish_comshop_order_comment')->where($condition)->count();
  2226. $pager = pagination2($total, $pindex, $psize);
  2227. $this->pager = $pager;
  2228. $this->total = $total;
  2229. $this->label = $label;
  2230. $this->display();
  2231. }
  2232. public function deletecomment()
  2233. {
  2234. $id = I('request.id');
  2235. if (empty($id)) {
  2236. $ids = I('request.ids');
  2237. $id = (is_array($ids) ? implode(',', $ids) : 0);
  2238. }
  2239. $items = M('lionfish_comshop_order_comment')->field('comment_id')->where( array('comment_id' => array('in',$id) ) )->select();
  2240. if (empty($item)) {
  2241. $item = array();
  2242. }
  2243. foreach ($items as $item) {
  2244. M('lionfish_comshop_order_comment')->where( array('comment_id' => $item['comment_id']) )->delete();
  2245. }
  2246. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2247. }
  2248. public function commentstate()
  2249. {
  2250. $id = I('request.id');
  2251. if (empty($id)) {
  2252. $ids = I('request.ids');
  2253. $id = (is_array($ids) ? implode(',', $ids) : 0);
  2254. }
  2255. $items = pdo_fetchall('SELECT comment_id FROM ' . tablename('lionfish_comshop_order_comment') . '
  2256. WHERE comment_id in( ' . $id . ' ) ' );
  2257. $items = M('lionfish_comshop_order_comment')->where( array() )->select();
  2258. if (empty($item)) {
  2259. $item = array();
  2260. }
  2261. foreach ($items as $item) {
  2262. pdo_update('lionfish_comshop_order_comment', array('state' => intval($_GPC['state'])), array('comment_id' => $item['comment_id']));
  2263. }
  2264. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2265. }
  2266. public function config()
  2267. {
  2268. if (IS_POST) {
  2269. $data = array();
  2270. $data = I('request.data');
  2271. $data['open_admin_payment'] = trim($data['open_admin_payment']);
  2272. $data['open_auto_receive'] = trim($data['open_auto_receive']);
  2273. $data['shop_limit_buy_distance'] = trim($data['shop_limit_buy_distance']);
  2274. $data['is_open_order_message'] = trim($data['is_open_order_message']);
  2275. $data['is_hidden_orderlist_phone'] = trim($data['is_hidden_orderlist_phone']);
  2276. $data['order_pay_after_share_img'] = save_media($data['order_pay_after_share_img']);
  2277. //-----begin
  2278. if( $data['shop_limit_buy_distance'] == 1)
  2279. {
  2280. if( empty($data['shop_buy_distance']) || $data['shop_buy_distance'] <= 0 )
  2281. {
  2282. show_json(0, array('msg' => '开启限制购买距离,购买距离不能为空') );
  2283. }
  2284. }
  2285. if( $data['open_auto_delete'] == 1)
  2286. {
  2287. if( empty($data['auto_cancle_order_time']) || $data['auto_cancle_order_time'] <= 0 )
  2288. {
  2289. show_json(0, array('msg' => '开启自动取消订单,自动取消订单时间不能为空') );
  2290. }
  2291. }
  2292. //open_aftersale
  2293. if( $data['open_auto_recive_order'] == 1)
  2294. {
  2295. if( empty($data['auto_recive_order_time']) || $data['auto_recive_order_time'] <= 0 )
  2296. {
  2297. show_json(0, array('msg' => '开启系统自动签收,自动签收天数不能为空') );
  2298. }
  2299. }
  2300. $open_aftersale = isset($data['open_aftersale']) ? $data['open_aftersale']:0;
  2301. $open_aftersale_time = isset($data['open_aftersale_time']) ? $data['open_aftersale_time']:0;
  2302. if( $open_aftersale == 1 && ($open_aftersale_time ==0 || empty($open_aftersale_time) ) )
  2303. {
  2304. show_json(0, array('msg' => '开启售后期,请填写售后期天数') );
  2305. }
  2306. if( $data['open_redis_server'] == 1)
  2307. {
  2308. if( empty($data['redis_host']))
  2309. {
  2310. show_json(0, array('msg' => '开启redis服务,redis-host不能为空') );
  2311. }
  2312. if( empty($data['redis_port']))
  2313. {
  2314. show_json(0, array('msg' => '开启redis服务,redis-port不能为空') );
  2315. }
  2316. }
  2317. $open_feier_print = isset($data['open_feier_print']) ? $data['open_feier_print']:0;
  2318. if(empty($open_feier_print) || $open_feier_print == 0)
  2319. {
  2320. $data['open_feier_print'] = $open_feier_print;
  2321. }else if($open_feier_print == 1){
  2322. $feier_print_sn = isset($data['feier_print_sn']) ? $data['feier_print_sn']:'';
  2323. $feier_print_key = isset($data['feier_print_key']) ? $data['feier_print_key']:'';
  2324. $data['open_feier_print'] = $open_feier_print;
  2325. $data['feier_print_sn'] = $feier_print_sn;
  2326. $data['feier_print_key'] = $feier_print_key;
  2327. $feier_print_sn_old_arr = M('lionfish_comshop_config')->where( array('name' => 'feier_print_sn') )->find();
  2328. $feier_print_sn_old = $feier_print_sn_old_arr['value'];
  2329. $feier_print_key_old_arr = M('lionfish_comshop_config')->where( array('name' => 'feier_print_key') )->find();
  2330. $feier_print_key_old = $feier_print_key_old_arr['value'];
  2331. if($feier_print_sn_old != $feier_print_sn || $feier_print_key_old != $feier_print_key)
  2332. {
  2333. //开始添加打印机
  2334. //printaction
  2335. $print_model = D('Seller/Printaction');
  2336. $snlist = "{$feier_print_sn}#{$feier_print_key}";
  2337. $print_model->addprinter($snlist);
  2338. }
  2339. //...todo测试订单自动打印
  2340. }else if($open_feier_print == 2){
  2341. $yilian_machine_code = isset($data['yilian_machine_code']) ? $data['yilian_machine_code']:'';
  2342. $yilian_msign = isset($data['yilian_msign']) ? $data['yilian_msign']:'';
  2343. $yilian_client_id = isset($data['yilian_client_id']) ? $data['yilian_client_id']:'';
  2344. $yilian_client_key = isset($data['yilian_client_key']) ? $data['yilian_client_key']:'';
  2345. $data['open_feier_print'] = $open_feier_print;
  2346. $data['yilian_machine_code'] = $yilian_machine_code;
  2347. $data['yilian_msign'] = $yilian_msign;
  2348. $data['yilian_client_id'] = $yilian_client_id;
  2349. $data['yilian_client_key'] = $yilian_client_key;
  2350. $yilian_client_id_old = D('Home/Front')->get_config_by_name('yilian_client_id');
  2351. $yilian_machine_code_old = D('Home/Front')->get_config_by_name('yilian_machine_code');
  2352. $yilian_msign_old = D('Home/Front')->get_config_by_name('yilian_msign');
  2353. if(true || $yilian_client_id != $yilian_client_id_old || $yilian_machine_code_old != $yilian_machine_code || $yilian_msign_old != $yilian_msign)
  2354. {
  2355. //开始添加打印机
  2356. //printaction
  2357. $print_model = D('Seller/Printaction');
  2358. $res = $print_model->addyilianyunprinter($yilian_client_id,$yilian_client_key,$yilian_machine_code, $yilian_msign );
  2359. if($res != 0)
  2360. {
  2361. show_json(0, array('msg' => '添加易联云打印机失败!'));
  2362. }
  2363. }
  2364. //...todo测试订单自动打印
  2365. }
  2366. //----end
  2367. $data['is_print_auto'] = $data['is_print_auto'] == 1 ? 0 : 1;
  2368. $data['is_print_cancleorder'] = isset($data['is_print_cancleorder']) ? $data['is_print_cancleorder'] : 0;
  2369. $data['is_print_admin_cancleorder'] = isset($data['is_print_admin_cancleorder']) ? $data['is_print_admin_cancleorder'] : 0;
  2370. $data['is_print_dansupply_order'] = isset($data['is_print_dansupply_order']) ? $data['is_print_dansupply_order'] : 0;
  2371. //----------redis begin
  2372. $data['open_redis_server'] = intval($data['open_redis_server']);
  2373. if($data['open_redis_server'] == 1 && !class_exists('Redis')){
  2374. $data['open_redis_server'] = 0;
  2375. }
  2376. //----------redis end
  2377. $data['is_has_refund_deliveryfree'] = isset($data['is_has_refund_deliveryfree']) ? $data['is_has_refund_deliveryfree'] : 0;
  2378. //订单自动发货
  2379. $data['is_localtown_auto_delivery'] = isset($data['is_localtown_auto_delivery']) ? $data['is_localtown_auto_delivery'] : 0;
  2380. $data['is_communityhead_auto_delivery'] = isset($data['is_communityhead_auto_delivery']) ? $data['is_communityhead_auto_delivery'] : 0;
  2381. $data['is_communityhead_auto_service'] = isset($data['is_communityhead_auto_service']) ? $data['is_communityhead_auto_service'] : 0;
  2382. $data['is_ziti_auto_delivery'] = isset($data['is_ziti_auto_delivery']) ? $data['is_ziti_auto_delivery'] : 0;
  2383. $data['is_ziti_auto_service'] = isset($data['is_ziti_auto_service']) ? $data['is_ziti_auto_service'] : 0;
  2384. $data['order_mead_money_num'] = isset($data['order_mead_money_num']) ? $data['order_mead_money_num'] : 2;
  2385. S('order_mead_money_num',$data['order_mead_money_num'],1440);
  2386. D('Seller/Config')->update($data);
  2387. //将商品库存写入redis
  2388. if($data['open_redis_server'] == 1 )
  2389. D('Seller/Redisorder')->sysnc_allgoods_total();
  2390. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2391. }
  2392. $data = D('Seller/Config')->get_all_config();
  2393. $this->data = $data;
  2394. $this->display();
  2395. }
  2396. public function opclose()
  2397. {
  2398. $opdata = $this->check_order_data();
  2399. extract($opdata);
  2400. if ($item['order_status_id'] == 5) {
  2401. show_json(0, '订单已关闭,无需重复关闭!');
  2402. }
  2403. else if (3 != $item['order_status_id']) {
  2404. show_json(0, '订单已付款,不能关闭!');
  2405. }
  2406. if (IS_POST) {
  2407. //load_model_class('frontorder')->cancel_order($item['order_id']);
  2408. D('Home/Frontorder')->cancel_order($item['order_id'], false, '后台操作,取消订单');
  2409. /**
  2410. $time = time();
  2411. pdo_update('lionfish_comshop_order', array('order_status_id' => 5, 'canceltime' => $time), array('order_id' => $item['order_id'], 'uniacid' => $_W['uniacid'])) ;
  2412. //'remarkclose' => $_GPC['remark']),
  2413. $history_data = array();
  2414. $history_data['uniacid'] = $_W['uniacid'];
  2415. $history_data['order_id'] = $item['order_id'];
  2416. $history_data['order_status_id'] = 5;
  2417. $history_data['notify'] = 0;
  2418. $history_data['comment'] = '后台操作,取消订单' ;
  2419. $history_data['date_added'] = time();
  2420. pdo_insert('lionfish_comshop_order_history', $history_data);
  2421. **/
  2422. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2423. }
  2424. $this->item = $item;
  2425. $this->display();
  2426. }
  2427. //--begin
  2428. public function ordersendall()
  2429. {
  2430. $_GPC = I('request.');
  2431. $express_list = D('Seller/Express')->load_all_express();
  2432. $this->_GPC = $_GPC;
  2433. if( IS_POST )
  2434. {
  2435. $type = isset($_GPC['type']) && !empty($_GPC['type']) ? $_GPC['type']:'normal';
  2436. $fext = substr($_FILES['excelfile']['name'], strrpos($_FILES['excelfile']['name'], '.') + 1);
  2437. $express = trim($_GPC['express']);
  2438. $expresscom = trim($_GPC['expresscom']);
  2439. if( $fext == 'csv' )
  2440. {
  2441. $file_name = $_FILES['excelfile']['tmp_name'];
  2442. $file = fopen($file_name,'r');
  2443. $rows = array();
  2444. $i =0;
  2445. while ($data = fgetcsv($file)) {
  2446. $rows[] = eval('return '.iconv('gbk','utf-8',var_export($data,true)).';');
  2447. }
  2448. //var_dump( $rows );
  2449. //die();
  2450. }else{
  2451. $rows = D('Seller/Excel')->import('excelfile');
  2452. }
  2453. $num = count($rows);
  2454. $time = time();
  2455. $express_arr = array();
  2456. foreach($express_list as $val)
  2457. {
  2458. $express_arr[ $val['id'] ] = $val['name'];
  2459. }
  2460. $i = 0;
  2461. $err_array = array();
  2462. $quene_order_list = array();
  2463. $cache_key = md5(time().count($rows));
  2464. $j =0;
  2465. foreach ($rows as $rownum => $col)
  2466. {
  2467. $order_id = trim($col[0]);
  2468. if (empty($order_id)) {
  2469. $err_array[] = $order_id;
  2470. continue;
  2471. }
  2472. if($j == 0)
  2473. {
  2474. $j++;
  2475. continue;
  2476. }
  2477. $quene_order_list[] = array('order_num_alias' => $order_id , 'shipping_no' => $col[1], 'express' => $express,'expresscom' => $expresscom );
  2478. }
  2479. S('_orderquene_'.$cache_key, $quene_order_list);
  2480. $this->cache_key = $cache_key;
  2481. $this->type = $type;
  2482. $this->display('Order/oploadexcelorder');
  2483. die();
  2484. }
  2485. $this->express_list = $express_list;
  2486. $this->type = I('request.type');
  2487. $this->display();
  2488. }
  2489. public function do_order_quene()
  2490. {
  2491. $_GPC = I('request.');
  2492. $type = $_GPC['type'];
  2493. $cache_key = $_GPC['cache_key'];
  2494. $quene_order_list = S('_orderquene_'.$cache_key);
  2495. $tmp_info = array_shift($quene_order_list);
  2496. S('_orderquene_'.$cache_key, $quene_order_list);
  2497. $express = $tmp_info['express'];
  2498. $expresscom = $tmp_info['expresscom'];
  2499. $shipping_no = $tmp_info['shipping_no'];
  2500. $tmp_info['order_num_alias'] = trim($tmp_info['order_num_alias']);
  2501. $tmp_info['order_num_alias'] = preg_replace("/(\s|\&nbsp\;| |\xc2\xa0)/","",$tmp_info['order_num_alias']);
  2502. //$rows = D('Seller/Excel')->import('excelfile');
  2503. $order_info = M('lionfish_comshop_order')->where( array('order_num_alias' => $tmp_info['order_num_alias'] ) )->find();
  2504. if(!empty($order_info) && $order_info['order_status_id'] == 1)
  2505. {
  2506. if( $type == 'mult' && $order_info['delivery'] == 'express' )
  2507. {
  2508. $ex_info = D('Seller/Express')-> get_express_info($express);
  2509. $data = array();
  2510. $data['express_time'] = time();
  2511. $data['order_status_id'] = 4;
  2512. $data['shipping_no'] = $shipping_no;
  2513. $data['shipping_method'] = $express;
  2514. $data['dispatchname'] = $ex_info['name'];
  2515. M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id'] ) )->save( $data );
  2516. $history_data = array();
  2517. $history_data['order_id'] = $order_info['order_id'];
  2518. $history_data['order_status_id'] = 4;
  2519. $history_data['notify'] = 0;
  2520. $history_data['comment'] = '订单快递已发货,后台导入批量发货';
  2521. $history_data['date_added'] = time();
  2522. M('lionfish_comshop_order_history')->add($history_data);
  2523. //TODO..发送已发货的模板消息
  2524. D('Home/Frontorder')->send_order_operate($order_info['order_id']);
  2525. }
  2526. else {
  2527. if($order_info['delivery'] != 'express')
  2528. {
  2529. /*if($order_info['delivery'] == 'localtown_delivery'){
  2530. M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id']) )->save( array('order_status_id' => 4,'express_time' => time(), 'express_tuanz_time' => time()) );
  2531. //todo ... send member msg goods is ing
  2532. $history_data = array();
  2533. $history_data['order_id'] = $order_info['order_id'];
  2534. $history_data['order_status_id'] = 4;
  2535. $history_data['notify'] = 0;
  2536. $history_data['comment'] = '订单配送中,使用表格发货';
  2537. $history_data['date_added'] = time();
  2538. M('lionfish_comshop_order_history')->add( $history_data );
  2539. D('Home/LocaltownDelivery')->change_distribution_order_state( $order_info['order_id'], 0, 1);
  2540. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_info['order_id']) )->save( array('delivery_type' => 1) );
  2541. D('Home/Frontorder')->send_order_operate($order_info['order_id']);
  2542. //给配送员发送公众号消息
  2543. $count = D('Seller/Redisorder')->set_distribution_delivery_message($order_info['order_id']);
  2544. }else{*/
  2545. if($order_info['delivery'] != 'localtown_delivery' && $order_info['delivery'] != 'hexiao') {
  2546. $data = array();
  2547. $data['express_time'] = time();
  2548. $data['order_status_id'] = 14;
  2549. M('lionfish_comshop_order')->where(array('order_id' => $order_info['order_id']))->save($data);
  2550. $history_data = array();
  2551. $history_data['order_id'] = $order_info['order_id'];
  2552. $history_data['order_status_id'] = 14;
  2553. $history_data['notify'] = 0;
  2554. $history_data['comment'] = '订单配送中,使用表格发货';
  2555. $history_data['date_added'] = time();
  2556. M('lionfish_comshop_order_history')->add($history_data);
  2557. }
  2558. //}
  2559. }
  2560. }
  2561. //TODO...发送已经发货给团长的消息通知
  2562. }
  2563. if($type =='mult_send_tuanz' && $order_info['delivery'] != 'express' && $order_info['order_status_id'] == 14 )
  2564. {
  2565. //订单批量团长签收 2019012749451499751
  2566. $history_data = array();
  2567. $history_data['order_id'] = $order_info['order_id'];
  2568. $history_data['order_status_id'] = 4;
  2569. $history_data['notify'] = 0;
  2570. $history_data['comment'] = '后台批量导入发货到团长';
  2571. $history_data['date_added'] = time();
  2572. M('lionfish_comshop_order_history')->add( $history_data );
  2573. D('Home/Frontorder')->send_order_operate($order_info['order_id']);
  2574. }
  2575. if($type =='mult_member_receive_order' && $order_info['order_status_id'] == 4 )
  2576. {
  2577. /*if($order_info['delivery'] == 'localtown_delivery'){
  2578. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_info['order_id']) )->save( array('state' => 4,'orderdistribution_id'=> -1) );
  2579. D('Seller/Order')->receive_order($order_info['order_id']);
  2580. M('lionfish_comshop_order_history')->where( array('order_id' => $order_info['order_id'],'order_status_id' => 6) )->save( array( 'comment' => '系统自动收货,等待结算佣金') );
  2581. }else{*/
  2582. if($order_info['delivery'] != 'localtown_delivery' && $order_info['delivery'] != 'hexiao') {
  2583. //批量用户确认收货
  2584. D('Home/Frontorder')->receive_order($order_info['order_id'], true);
  2585. }
  2586. //}
  2587. }
  2588. if( empty($quene_order_list) )
  2589. {
  2590. echo json_encode( array('code' => 2) );
  2591. die();
  2592. }
  2593. echo json_encode( array('code' => 0, 'msg' => '订单号:'.$tmp_info['order_num_alias']." 处理成功,还剩余".count($quene_order_list)."个订单未处理") );
  2594. die();
  2595. }
  2596. //--end
  2597. public function ordersendall2()
  2598. {
  2599. if( IS_POST )
  2600. {
  2601. $type = I('request.type', 'normal');
  2602. $express = I('request.express', '');
  2603. $expresscom = I('request.expresscom', '');
  2604. $rows = D('Seller/Excel')->import('excelfile');
  2605. $num = count($rows);
  2606. $time = time();
  2607. $express_arr = array();
  2608. foreach($express_list as $val)
  2609. {
  2610. $express_arr[ $val['id'] ] = $val['name'];
  2611. }
  2612. $i = 0;
  2613. $err_array = array();
  2614. $j =0;
  2615. foreach ($rows as $rownum => $col) {
  2616. $order_id = trim($col[0]);
  2617. if (empty($order_id)) {
  2618. $err_array[] = $order_id;
  2619. continue;
  2620. }
  2621. if($j == 0)
  2622. {
  2623. $j++;
  2624. continue;
  2625. }
  2626. $order_info = M('lionfish_comshop_order')->where( array('order_num_alias' => $order_id ) )->find();
  2627. if(!empty($order_info) && $order_info['order_status_id'] == 1)
  2628. {
  2629. //判断是否快递类型 type //normal mult
  2630. if( $type == 'mult' && $order_info['delivery'] == 'express' )
  2631. {
  2632. $data = array();
  2633. $data['express_time'] = time();
  2634. $data['order_status_id'] = 4;
  2635. $data['shipping_no'] = $col[1];
  2636. $data['shipping_method'] = $express;
  2637. $data['dispatchname'] = $expresscom;
  2638. M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id'] ) )->save( $data );
  2639. $history_data = array();
  2640. $history_data['order_id'] = $order_info['order_id'];
  2641. $history_data['order_status_id'] = 4;
  2642. $history_data['notify'] = 0;
  2643. $history_data['comment'] = '订单快递已发货';
  2644. $history_data['date_added'] = time();
  2645. M('lionfish_comshop_order_history')->add($history_data);
  2646. //TODO..发送已发货的模板消息
  2647. D('Home/Frontorder')->send_order_operate($order_info['order_id']);
  2648. }else {
  2649. if($order_info['delivery'] != 'express')
  2650. {
  2651. $data = array();
  2652. $data['express_time'] = time();
  2653. $data['order_status_id'] = 14;
  2654. M('lionfish_comshop_order')->where( array('order_id' => $order_info['order_id'] ) )->save($data);
  2655. $history_data = array();
  2656. $history_data['order_id'] = $order_info['order_id'];
  2657. $history_data['order_status_id'] = 14;
  2658. $history_data['notify'] = 0;
  2659. $history_data['comment'] = '订单配送中';
  2660. $history_data['date_added'] = time();
  2661. M('lionfish_comshop_order_history')->add($history_data);
  2662. }
  2663. }
  2664. //TODO...发送已经发货给团长的消息通知
  2665. ++$i;
  2666. }
  2667. if($type =='mult_send_tuanz' && $order_info['delivery'] != 'express' && $order_info['order_status_id'] == 14 )
  2668. {
  2669. //订单批量团长签收 2019012749451499751
  2670. D('Home/Frontorder')->send_order_operate($order_info['order_id']);
  2671. ++$i;
  2672. }
  2673. if($type =='mult_member_receive_order' && $order_info['order_status_id'] == 4 )
  2674. {
  2675. //批量用户确认收货
  2676. D('Home/Frontorder')->receive_order($order_info['order_id'], true);
  2677. ++$i;
  2678. }
  2679. }
  2680. $tip = '';
  2681. if($type =='mult_send_tuanz')
  2682. {
  2683. $msg = $i . '个订单批量送达团长成功!';
  2684. }
  2685. else if($type == 'mult_member_receive_order')
  2686. {
  2687. $msg = $i . '个订单批量用户确认收货!';
  2688. }
  2689. else{
  2690. $msg = $i . '个订单发货成功!';
  2691. }
  2692. if ($i < $num) {
  2693. $url = '';
  2694. if (!empty($err_array)) {
  2695. $j = 1;
  2696. if($type =='mult_send_tuanz')
  2697. {
  2698. $tip .= '<br>' . count($err_array) . '个订单批量送达团长失败,失败的订单编号: <br>';
  2699. }else if($type == 'mult_member_receive_order'){
  2700. $tip .= '<br>' . count($err_array) . '个订单批量用户确认收货,失败的订单编号: <br>';
  2701. }
  2702. else{
  2703. $tip .= '<br>' . count($err_array) . '个订单发货失败,失败的订单编号: <br>';
  2704. }
  2705. foreach ($err_array as $k => $v) {
  2706. $tip .= $v . ' ';
  2707. if (($j % 2) == 0) {
  2708. $tip .= '<br>';
  2709. }
  2710. ++$j;
  2711. }
  2712. }
  2713. }
  2714. else {
  2715. $url = U('order/ordersendall', array('type' => $type) );
  2716. }
  2717. $redirect = $url;
  2718. $this->message = $msg.$tip;
  2719. $this->redirect = $redirect;
  2720. $this->display('Public/_message');
  2721. die();
  2722. }
  2723. $express_list = D('Seller/Express')->load_all_express();
  2724. $this->express_list = $express_list;
  2725. $this->type = I('request.type');
  2726. $this->display();
  2727. }
  2728. public function opchangeexpress()
  2729. {
  2730. $_GPC = I('request.');
  2731. $opdata = $this->check_order_data();
  2732. extract($opdata);
  2733. $changeexpress = 1;
  2734. $sendtype = intval($_GPC['sendtype']);
  2735. $edit_flag = 1;
  2736. if (IS_POST) {
  2737. if (!(empty($_GPC['shipping_no'])) && empty($_GPC['shipping_no'])) {
  2738. show_json(0, array('msg' => '请输入快递单号!') );
  2739. }
  2740. if (!(empty($item['transid']))) {
  2741. }
  2742. $express_info = D('Seller/Express')->get_express_info($_GPC['express']);
  2743. $time = time();
  2744. $data = array(
  2745. 'shipping_method' => trim($_GPC['express']),
  2746. 'dispatchname' => $express_info['name'],
  2747. 'shipping_no' => trim($_GPC['shipping_no']),
  2748. 'express_time' => $time
  2749. );
  2750. M('lionfish_comshop_order')->where( array('order_id' => $item['order_id']) )->save( $data );
  2751. $history_data = array();
  2752. $history_data['order_id'] = $item['order_id'];
  2753. $history_data['order_status_id'] = 4;
  2754. $history_data['notify'] = 0;
  2755. $history_data['comment'] = '修改发货物流,订单发货 ID: ' . $item['order_id'] . ' 订单号: ' . $item['order_num_alias'] . ' <br/>快递公司: ' . $express_info['name'] . ' 快递单号: ' . $_GPC['shipping_no'];
  2756. $history_data['date_added'] = time();
  2757. M('lionfish_comshop_order_history')->add( $history_data );
  2758. //TODO...发送已经发货的消息通知
  2759. //m('notice')->sendOrderMessage($item['id']);
  2760. //plog('order.op.send', '订单发货 ID: ' . $item['id'] . ' 订单号: ' . $item['ordersn'] . ' <br/>快递公司: ' . $_GPC['expresscom'] . ' 快递单号: ' . $_GPC['expresssn']);
  2761. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  2762. }
  2763. $noshipped = array();
  2764. $shipped = array();
  2765. $province_info = D('Home/Front')->get_area_info($item['shipping_province_id']);
  2766. $city_info = D('Home/Front')->get_area_info($item['shipping_city_id']);
  2767. $area_info = D('Home/Front')->get_area_info($item['shipping_country_id']);
  2768. $order_goods = M('lionfish_comshop_order_goods')->field('order_goods_id as id,name as title,goods_images as thumb')->where( array('order_id' => $item['order_id']) )->select();
  2769. $express_list = D('Seller/Express')->load_all_express();
  2770. $this->id = $item['order_id'];
  2771. $this->item = $item;
  2772. $this->province_info = $province_info;
  2773. $this->city_info = $city_info;
  2774. $this->area_info = $area_info;
  2775. $this->order_goods = $order_goods;
  2776. $this->express_list = $express_list;
  2777. $this->display('Order/opsend');
  2778. }
  2779. public function batchsend_import()
  2780. {
  2781. global $_W;
  2782. global $_GPC;
  2783. $type = I('request.type','normal');
  2784. $this->type = $type;
  2785. $columns = array();
  2786. $columns[] = array('title' => '订单编号', 'field' => '', 'width' => 32);
  2787. //$columns[] = array('title' => '快递单号', 'field' => '', 'width' => 32);
  2788. if($type == 'normal')
  2789. {
  2790. D('Seller/Excel')->temp('批量发货数据模板', $columns);
  2791. }else{
  2792. $columns[] = array('title' => '快递单号', 'field' => '', 'width' => 32);
  2793. D('Seller/Excel')->temp('批量发货数据模板', $columns);
  2794. }
  2795. }
  2796. /**
  2797. * 上传订单Excel批量发货
  2798. */
  2799. function sendexpress_excel_done()
  2800. {
  2801. set_time_limit(0);
  2802. if(isset($_FILES["file"]) && ($_FILES["file"]["error"] == 0)){
  2803. $excel_dir = ROOT_PATH.'Uploads/image/'.date('Y-m-d');
  2804. $extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
  2805. RecursiveMkdir( $excel_dir );
  2806. $path = $excel_dir.'/'.md5($_FILES['file']['name'].mt_rand(1, 999)).'.'.$extension;
  2807. $rs = move_uploaded_file($_FILES["file"]["tmp_name"],$path);
  2808. $notify_model = D('Home/Weixinnotify');
  2809. //
  2810. $result = importExecl($path);
  2811. if(!empty($result)) {
  2812. $order_ids = array();
  2813. //开始导入数据库,并发货
  2814. foreach($result as $val){
  2815. if(empty($val[0]))
  2816. {
  2817. continue;
  2818. }
  2819. $order_info = M('order')->field('order_id,order_status_id,delivery')->where( array('order_num_alias' => trim($val[0])) )->find();
  2820. //order_status_id 1
  2821. if($order_info['order_status_id'] != 1)
  2822. {
  2823. continue;
  2824. }
  2825. //['delivery'] == 'pickup'
  2826. $order_ids[] = $order_info['order_id'];
  2827. if($order_info['delivery'] == 'pickup')
  2828. {
  2829. M('order')->where( array('order_id' => $order_info['order_id'] ) )->save( array('order_status_id' => 4) );
  2830. } else {
  2831. M('order')->where( array('order_id' => $order_info['order_id'] ) )->save( array('shipping_method' =>$val[5],'shipping_no' =>$val[6],'order_status_id' => 4) );
  2832. }
  2833. $oh = array();
  2834. $oh['order_id']=$order_info['order_id'];
  2835. $oh['order_status_id']=4;
  2836. $oh['notify'] = 0;
  2837. $oh['comment']='导入excel批量发货';
  2838. $oh['date_added']=time();
  2839. $oh_id=M('OrderHistory')->add($oh);
  2840. }
  2841. foreach($order_ids as $order_id) {
  2842. $order_info = M('order')->field('delivery')->where( array('order_id' => $order_id) )->find();
  2843. if($order_info['delivery'] == 'pickup')
  2844. {
  2845. $notify_model->sendPickupMsg($order_id);
  2846. } else {
  2847. $notify_model->sendExpressMsg($order_id);
  2848. }
  2849. }
  2850. }
  2851. }
  2852. echo json_encode( array('code' => 1) );
  2853. die();
  2854. }
  2855. function sendexpress()
  2856. {
  2857. $this->breadcrumb2='批量发货';
  2858. $this->display();
  2859. }
  2860. function print_order(){
  2861. $model=new OrderModel();
  2862. $this->order=$model->order_info(I('id'));
  2863. $this->print=true;
  2864. $this->display('./Themes/Home/default/Mail/order.html');
  2865. }
  2866. public function refunddone()
  2867. {
  2868. $id = I('get.id',0,'intval');
  2869. $comment = I('post.comment');
  2870. $order_refund_type = I('post.order_refund_type',0,'intval');
  2871. $result = array('code' =>1);
  2872. $order_refund_history = array();
  2873. $order_refund_history['order_id'] = $id;
  2874. $order_refund_history['message'] = htmlspecialchars($comment);
  2875. $order_refund_history['type'] = 2;
  2876. $order_refund_history['addtime'] = time();
  2877. M('order_refund_history')->add($order_refund_history);
  2878. $order_history = array();
  2879. $order_history['order_id'] = $id;
  2880. $order_history['order_status_id'] = 0;
  2881. $order_history['notify'] = 0;
  2882. $order_history['comment'] = '';
  2883. $order_history['date_added'] = time();
  2884. if($order_refund_type ==1)
  2885. {
  2886. //拒绝
  2887. M('order_refund')->where( array('order_id' => $id) )->save( array('state' => 1) );
  2888. $order_history['order_status_id'] = 12;
  2889. $order_history['comment'] = '商家拒绝退款';
  2890. M('order_history')->add($order_history);
  2891. } else {
  2892. $order_history['order_status_id'] = 12;
  2893. $order_history['comment'] = '商家统一退款';
  2894. M('order_history')->add($order_history);
  2895. $weixin_model = D('Home/Weixin');
  2896. //通过
  2897. M('order_refund')->where( array('order_id' => $id) )->save( array('state' => 3) );
  2898. $order_refund = M('order_refund')->where( array('order_id' => $id) )->find();
  2899. $weixin_model->refundOrder($id, $order_refund['ref_money']);
  2900. }
  2901. echo json_encode($result);
  2902. die();
  2903. }
  2904. public function show_refund()
  2905. {
  2906. $this->crumbs='订单退款详情';
  2907. $model=new OrderModel();
  2908. $data = $model->order_info(I('id'));
  2909. $order_statuses = $data['order_statuses'];
  2910. $need_status = array();
  2911. foreach($order_statuses as $key => $val)
  2912. {
  2913. if( in_array($val['order_status_id'], array(4)) )
  2914. {
  2915. $need_status[$key] = $val;
  2916. }
  2917. }
  2918. $data['order_statuses'] = $need_status;
  2919. $refund_reason = array(
  2920. '97' =>'商品有质量问题',
  2921. '98' =>'没有收到货',
  2922. '99' =>'商品少发漏发发错',
  2923. '100' =>'商品与描述不一致',
  2924. '101' =>'收到商品时有划痕或破损',
  2925. '102' =>'质疑假货',
  2926. '111' =>'其他',
  2927. );
  2928. $order_refund = M('order_refund')->where( array('order_id' =>I('id')) )->find();
  2929. //ref_type
  2930. $order_refund['ref_type'] = $order_refund['ref_type'] ==1 ? '仅退款': '退款退货';
  2931. $order_refund['ref_name'] = empty($refund_reason[$order_refund['ref_name']]) ? $order_refund['ref_name']: $refund_reason[$order_refund['ref_name']] ;
  2932. $refund_state = array(
  2933. 0 => '申请中',
  2934. 1 => '商家拒绝',
  2935. 2 => '平台介入',
  2936. 3 => '退款成功',
  2937. 4 => '退款失败',
  2938. 5 => '撤销申请',
  2939. );
  2940. $order_refund['state'] = $refund_state[$order_refund['state']];
  2941. $this->order_refund = $order_refund;
  2942. $order_refund_image = M('order_refund_image')->where( array('ref_id' => $order_refund['ref_id']) )->select();
  2943. $refund_images = array();
  2944. if(!empty($order_refund_image))
  2945. {
  2946. foreach($order_refund_image as $refund_image)
  2947. {
  2948. $refund_image['thumb_image'] = resize($refund_image['image'], 100, 100);
  2949. $refund_images[] = $refund_image;
  2950. }
  2951. }
  2952. $order_refund_history = M('order_refund_history')->where( array('order_id' => I('id')) )->order('addtime asc')->select();
  2953. foreach($order_refund_history as $key => $val)
  2954. {
  2955. $val['type'] = $val['type'] == 1 ?'用户反馈':'商家反馈';
  2956. switch($val['type'])
  2957. {
  2958. case 1:
  2959. $val['type'] = '用户反馈';
  2960. break;
  2961. case 2:
  2962. $val['type'] = '商家反馈';
  2963. break;
  2964. case 3:
  2965. $val['type'] = '平台反馈';
  2966. break;
  2967. }
  2968. $order_refund_history_image = M('order_refund_history_image')->where( array('orh_id' => $val['id']) )->select();
  2969. if(!empty($order_refund_history_image))
  2970. {
  2971. foreach($order_refund_history_image as $kk => $vv)
  2972. {
  2973. $vv['thumb_image'] = resize($vv['image'], 100, 100);
  2974. $order_refund_history_image[$kk] = $vv;
  2975. }
  2976. }
  2977. $val['order_refund_history_image'] = $order_refund_history_image;
  2978. $order_refund_history[$key] = $val;
  2979. }
  2980. $this->order_refund_history = $order_refund_history;
  2981. $this->refund_images = $refund_images;
  2982. $this->data = $data;
  2983. $this->display('refund');
  2984. }
  2985. public function show_order(){
  2986. $this->crumbs='订单详情';
  2987. //is_ziti/1 commiss_list
  2988. $is_ziti = I('get.is_ziti', 0);
  2989. if($is_ziti == 1)
  2990. {
  2991. $this->breadcrumb1='自提管理';
  2992. $this->breadcrumb2='自提管理';
  2993. }
  2994. $model=new OrderModel();
  2995. $data = $model->order_info(I('id'));
  2996. $order_statuses = $data['order_statuses'];
  2997. $need_status = array();
  2998. foreach($order_statuses as $key => $val)
  2999. {
  3000. if( in_array($val['order_status_id'], array(1,2,3,4,5,6,7,8,11,12,13)) )
  3001. {
  3002. $need_status[$key] = $val;
  3003. }
  3004. }
  3005. $data['order_statuses'] = $need_status;
  3006. //$data['order']
  3007. if($data['order']['type'] == 'integral')
  3008. {
  3009. $integral_order = M('integral_order')->where( array('order_id' => I('id') ) )->find();
  3010. $this->integral_order = $integral_order;
  3011. }
  3012. $this->data = $data;
  3013. $pick_order_info = array();
  3014. $pick_up = array();
  3015. if($data['order']['delivery'] == 'pickup')
  3016. {
  3017. $pick_order_info = M('pick_order')->where( array('order_id' => $data['order']['order_id']) )->find();
  3018. $pick_up = M('pick_up')->where( array('id' => $pick_order_info['pick_id']) )->find();
  3019. }
  3020. $this->pick_order_info = $pick_order_info;
  3021. $this->pick_up = $pick_up;
  3022. $sql="select s.* from ".C('DB_PREFIX')."seller_express as s, ".C('DB_PREFIX')."seller_express_relat as ser
  3023. where s.id = ser.express_id and ser.store_id = ".SELLERUID;
  3024. $express_list= M()->query($sql);
  3025. $this->express_list = $express_list;
  3026. //$data['order']['order_id']
  3027. $order_goods_haitao = M('order_goods_haitao')->where( array('order_id' => $data['order']['order_id']) )->find();
  3028. $this->order_goods_haitao = $order_goods_haitao;
  3029. $this->display('show');
  3030. }
  3031. function history(){
  3032. $model=new OrderModel();
  3033. if(IS_POST){
  3034. if(I('order_status_id')==C('cancel_order_status_id')){
  3035. $Order = new \Home\Model\OrderModel();
  3036. $Order->cancel_order($_GET['id']);
  3037. storage_user_action(session('user_auth.uid'),session('user_auth.username'),C('BACKEND_USER'),'取消了订单 '.$_GET['id']);
  3038. $result=true;
  3039. }else{
  3040. //order_status_id 4
  3041. if($_POST['order_status_id'] != 4)
  3042. {
  3043. unset($_POST['shipping_no']);
  3044. unset($_POST['shipping_method']);
  3045. die();
  3046. }else {
  3047. }
  3048. $result=$model->addOrderHistory($_GET['id'],$_POST);
  3049. }
  3050. if($result){
  3051. $this->success='新增成功!!';
  3052. }else{
  3053. $this->error='新增失败!!';
  3054. }
  3055. }
  3056. $results = $model->getOrderHistories($_GET['id']);
  3057. foreach ($results as $result) {
  3058. $histories[] = array(
  3059. 'notify' => $result['notify'] ? '是' : '否',
  3060. 'status' => $result['status'],
  3061. 'comment' => nl2br($result['comment']),
  3062. 'date_added' => date('Y/m/d H:i:s', $result['date_added'])
  3063. );
  3064. }
  3065. $this->histories=$histories;
  3066. $this->display();
  3067. }
  3068. function del(){
  3069. $model=new OrderModel();
  3070. $return=$model->del_order(I('get.id'));
  3071. $this->osc_alert($return);
  3072. }
  3073. //begin
  3074. public function printconfig()
  3075. {
  3076. if (defined('ROLE') && ROLE == 'agenter' )
  3077. {
  3078. $supper_info = get_agent_logininfo();
  3079. if (IS_POST) {
  3080. $_GPC = I('request.');
  3081. $data = array();
  3082. $data = ((is_array($_GPC['data']) ? $_GPC['data'] : array()));
  3083. //$supper_info['id']
  3084. $open_feier_print = isset($data['open_feier_print'.$supper_info['id']]) ? $data['open_feier_print'.$supper_info['id']]:0;
  3085. if(empty($open_feier_print) || $open_feier_print == 0)
  3086. {
  3087. $data['open_feier_print'.$supper_info['id']] = $open_feier_print;
  3088. }else if($open_feier_print == 1){
  3089. $feier_print_sn = isset($data['feier_print_sn'.$supper_info['id']]) ? $data['feier_print_sn'.$supper_info['id']]:'';
  3090. $feier_print_key = isset($data['feier_print_key'.$supper_info['id']]) ? $data['feier_print_key'.$supper_info['id']]:'';
  3091. $data['open_feier_print'.$supper_info['id']] = $open_feier_print;
  3092. $data['feier_print_sn'.$supper_info['id']] = $feier_print_sn;
  3093. $data['feier_print_key'.$supper_info['id']] = $feier_print_key;
  3094. $feier_print_sn_old_arr = M('lionfish_comshop_config')->where( array('name' => 'feier_print_sn'.$supper_info['id'] ) )->find();
  3095. $feier_print_sn_old = $feier_print_sn_old_arr['value'];
  3096. $feier_print_key_old_arr = M('lionfish_comshop_config')->where( array('name' => 'feier_print_key'.$supper_info['id'] ) )->find();
  3097. $feier_print_key_old = $feier_print_key_old_arr['value'];
  3098. if($feier_print_sn_old != $feier_print_sn || $feier_print_key_old != $feier_print_key)
  3099. {
  3100. //开始添加打印机
  3101. //printaction
  3102. $print_model = D('Seller/Printaction');
  3103. $snlist = "{$feier_print_sn}#{$feier_print_key}";
  3104. $print_model->addprinter($snlist);
  3105. }
  3106. //...todo测试订单自动打印
  3107. }else if($open_feier_print == 2){
  3108. $yilian_machine_code = isset($data['yilian_machine_code'.$supper_info['id']]) ? $data['yilian_machine_code'.$supper_info['id']]:'';
  3109. $yilian_msign = isset($data['yilian_msign'.$supper_info['id']]) ? $data['yilian_msign'.$supper_info['id']]:'';
  3110. $yilian_client_id = isset($data['yilian_client_id'.$supper_info['id']]) ? $data['yilian_client_id'.$supper_info['id']]:'';
  3111. $yilian_client_key = isset($data['yilian_client_key'.$supper_info['id']]) ? $data['yilian_client_key'.$supper_info['id']]:'';
  3112. $data['open_feier_print'.$supper_info['id']] = $open_feier_print;
  3113. $data['yilian_machine_code'.$supper_info['id']] = $yilian_machine_code;
  3114. $data['yilian_msign'.$supper_info['id']] = $yilian_msign;
  3115. $data['yilian_client_id'.$supper_info['id']] = $yilian_client_id;
  3116. $data['yilian_client_key'.$supper_info['id']] = $yilian_client_key;
  3117. $yilian_client_id_old_arr = M('lionfish_comshop_config')->where( array('name' => 'yilian_client_id'.$supper_info['id'] ) )->find();
  3118. $yilian_client_id_old = $yilian_client_id_old_arr['value'];
  3119. $yilian_machine_code_old_arr = M('lionfish_comshop_config')->where( array('name' => 'yilian_machine_code'.$supper_info['id'] ) )->find();
  3120. $yilian_machine_code_old = $yilian_machine_code_old_arr['value'];
  3121. $yilian_msign_old_arr = M('lionfish_comshop_config')->where( array('name' => 'yilian_msign'.$supper_info['id'] ) )->find();
  3122. $yilian_msign_old = $yilian_msign_old_arr['value'];
  3123. if(true || $yilian_client_id != $yilian_client_id_old || $yilian_machine_code_old != $yilian_machine_code || $yilian_msign_old != $yilian_msign)
  3124. {
  3125. //开始添加打印机
  3126. //printaction
  3127. $print_model = D('Seller/Printaction');
  3128. $res = $print_model->addyilianyunprinter($yilian_client_id,$yilian_client_key,$yilian_machine_code, $yilian_msign );
  3129. if($res != 0)
  3130. {
  3131. show_json(0, array('msg' => '添加易联云打印机失败!' ) );
  3132. }
  3133. }
  3134. //...todo测试订单自动打印
  3135. }
  3136. D('Seller/Config')->update($data);
  3137. show_json(1);
  3138. }
  3139. $data = D('Seller/Config')->get_all_config();
  3140. $this->supper_info = $supper_info;
  3141. $this->data = $data;
  3142. include $this->display();
  3143. }
  3144. }
  3145. public function express_list(){
  3146. $this->type = I('request.type','');
  3147. $this->order_id = I('request.order_id','');
  3148. $express_list = D('Seller/Express')->load_kdn_express();
  3149. $this->express_list = $express_list;
  3150. $this->display();
  3151. }
  3152. public function kdn_print_log_list(){
  3153. $log_list = M('lionfish_comshop_order_kdniao_print_log')->order('id desc')->limit(5)->select();
  3154. $this->log_list = $log_list;
  3155. $this->display();
  3156. }
  3157. /**
  3158. * 判断快递鸟寄件人信息
  3159. * @param $express_code
  3160. */
  3161. public function check_kdn_sender($express_code){
  3162. $result = array();
  3163. $result['status'] = 1;
  3164. $data = D('Seller/Config')->get_all_config();
  3165. if(empty($data['kdn_sender_name'])){
  3166. $result['status'] = 0;
  3167. $result['msg'] = '寄件人未配置';
  3168. return $result;
  3169. }
  3170. if(empty($data['kdn_sender_mobile'])){
  3171. $result['status'] = 0;
  3172. $result['msg'] = '寄件人联系电话未配置';
  3173. return $result;
  3174. }
  3175. if(empty($data['kdn_province_id'])){
  3176. $result['status'] = 0;
  3177. $result['msg'] = '寄件人省份未配置';
  3178. return $result;
  3179. }
  3180. if(empty($data['kdn_city_id'])){
  3181. $result['status'] = 0;
  3182. $result['msg'] = '寄件人城市未配置';
  3183. return $result;
  3184. }
  3185. if(empty($data['kdn_area_id'])){
  3186. $result['status'] = 0;
  3187. $result['msg'] = '寄件人区域未配置';
  3188. return $result;
  3189. }
  3190. if(empty($data['kdn_sender_address'])){
  3191. $result['status'] = 0;
  3192. $result['msg'] = '寄件人详细地址未配置';
  3193. return $result;
  3194. }
  3195. $code_list = array('EMS','YZPY','YZBK');
  3196. if(in_array($express_code,$code_list)){
  3197. if(empty($data['kdn_sender_postcode'])){
  3198. $result['status'] = 0;
  3199. $result['msg'] = '寄件人邮编未配置';
  3200. return $result;
  3201. }
  3202. }
  3203. return $result;
  3204. }
  3205. //打印面单
  3206. public function kdniao_order(){
  3207. $result = array();
  3208. $order_id = I('request.order_id','');
  3209. $express_code = I('request.express_code','');
  3210. if(empty($order_id)){
  3211. $result['status'] = 1;
  3212. $result['message'] = "订单号不存在";
  3213. }else if(empty($express_code)){
  3214. $result['status'] = 1;
  3215. $result['message'] = "快递公司不存在";
  3216. }else{
  3217. $sender_result = $this->check_kdn_sender($express_code);
  3218. if($sender_result['status'] == 1){
  3219. $kdNiao = new \Lib\KdApiEOrder();
  3220. $config_data = D('Seller/Config')->get_all_config();
  3221. $result = $kdNiao->printOrder($order_id,$express_code,$config_data);
  3222. }else{
  3223. $result['status'] = 3;
  3224. $result['message'] = $sender_result['msg'];
  3225. }
  3226. }
  3227. echo json_encode($result);
  3228. }
  3229. //打印多条订单面单
  3230. public function kdniao_print_orders(){
  3231. $print_type = I('request.print_type','');
  3232. $order_id = I('request.order_id','');
  3233. $express_code = I('request.express_code','');
  3234. $order_id_list = array();
  3235. $order_list = array();
  3236. $order_kdn_status = array();
  3237. if($print_type == "select"){
  3238. $order_list = M('lionfish_comshop_order')->field('order_id,is_kdn_print')->where("order_status_id = 1 and delivery = 'express' and order_id in (".$order_id.")")->select();
  3239. }else if($print_type == "all"){
  3240. $order_list = M('lionfish_comshop_order')->field('order_id,is_kdn_print')->where("order_status_id = 1 and delivery = 'express' ")->select();
  3241. }
  3242. foreach($order_list as $k=>$v){
  3243. $order_id_list[] = $v['order_id'];
  3244. $order_kdn_status[$v['order_id']] = $v['is_kdn_print'];
  3245. }
  3246. $time = time();
  3247. $print_count = count($order_id_list);
  3248. //保存快递鸟打印日志
  3249. $kd_data = array();
  3250. $kd_data['addtime'] = $time;
  3251. $kd_data['print_count'] = $print_count;
  3252. $kdn_id = M('lionfish_comshop_order_kdniao_print_log')->add( $kd_data );
  3253. $succ_count = 0;
  3254. $fail_count = 0;
  3255. $fail_result = array();
  3256. $kdNiao = new \Lib\KdApiEOrder();
  3257. $config_data = D('Seller/Config')->get_all_config();
  3258. $sender_result = $this->check_kdn_sender($express_code);
  3259. if($sender_result['status'] == 1){
  3260. foreach($order_id_list as $v){
  3261. if($order_kdn_status[$v] == 1){
  3262. $succ_count++;
  3263. }else{
  3264. $result = $kdNiao->printOrder($v,$express_code,$config_data);
  3265. if($result['status'] == 0){//打印成功
  3266. $succ_count++;
  3267. }else{//打印失败
  3268. $fail_count++;
  3269. $fail_result[] = $result['message'];
  3270. }
  3271. }
  3272. }
  3273. }else{
  3274. $result['status'] = 3;
  3275. $result['message'] = $sender_result['msg'];
  3276. }
  3277. $fail_reason = json_encode(array_unique($fail_result));
  3278. //打印完成更新快递鸟打印日志
  3279. $kdn_data = array();
  3280. $kdn_data['succ_count'] = $succ_count;
  3281. $kdn_data['fail_count'] = $fail_count;
  3282. $kdn_data['fail_reason'] = $fail_reason;
  3283. $kdn_data['status'] = 1;
  3284. M('lionfish_comshop_order_kdniao_print_log')->where(array('id' => $kdn_id))->save($kdn_data);
  3285. $kdn_order_ids = implode(",",$order_id_list);
  3286. echo json_encode(array('status'=>0,'order_ids'=>$kdn_order_ids));
  3287. }
  3288. //检查是否配置快递鸟接口参数
  3289. public function check_kdniao(){
  3290. $config_data = D('Seller/Config')->get_all_config();
  3291. if(isset($config_data['kdniao_id']) && !empty($config_data['kdniao_id']) && isset($config_data['kdniao_api_key']) && !empty($config_data['kdniao_api_key'])){
  3292. show_json(1);
  3293. }else{
  3294. show_json(0, array('msg' => '快递鸟未配置!' ) );
  3295. }
  3296. }
  3297. public function kdn_info(){
  3298. $this->order_id = I('request.order_id','');
  3299. $kdn_info = M('lionfish_comshop_order_kdniao_info')->where( array('order_id' => $this->order_id,'status'=>1) )->find();
  3300. $this->kdn_info = $kdn_info;
  3301. $this->display();
  3302. }
  3303. public function kdn_orders_info(){
  3304. $this->order_ids = I('request.order_ids','');
  3305. $kdn_list_info = M('lionfish_comshop_order_kdniao_info')->where("order_id in (".$this->order_ids.") and status = 1")->select();
  3306. $this->kdn_list_info = $kdn_list_info;
  3307. $this->display();
  3308. }
  3309. /**
  3310. * 快递鸟打印成功订单发货
  3311. */
  3312. public function kdn_send(){
  3313. $order_id = I('request.id','');
  3314. $order_ids = I('request.ids','');
  3315. if(!empty($order_id)){
  3316. $item = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  3317. if (empty($item)) {
  3318. show_json(0, '未找到订单!');
  3319. }
  3320. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  3321. if(!empty($order_info)) {
  3322. if ($order_info['order_status_id'] == 1 && $order_info['delivery'] == 'express' && $order_info['is_kdn_print'] == 1) {
  3323. $express_info = D('Seller/Express')->get_express_info($order_info['shipping_method']);
  3324. $data = array();
  3325. $data['order_status_id'] = 4;
  3326. M('lionfish_comshop_order')->where(array('order_id' => $order_id))->save($data);
  3327. $history_data = array();
  3328. $history_data['order_id'] = $order_id;
  3329. $history_data['order_status_id'] = 4;
  3330. $history_data['notify'] = 0;
  3331. $history_data['comment'] = '订单发货 ID: ' . $order_id . ' 订单号: ' . $item['order_num_alias'] . ' <br/>快递公司: ' . $express_info['name'] . ' 快递单号: ' . $item['shipping_no'];
  3332. $history_data['date_added'] = time();
  3333. M('lionfish_comshop_order_history')->add($history_data);
  3334. D('Home/Frontorder')->send_order_operate($item['order_id']);
  3335. } else {
  3336. show_json(0, '待发货快递订单才能发货成功!');
  3337. }
  3338. }else{
  3339. show_json(0, '未找到订单!');
  3340. }
  3341. }else if(!empty($order_ids)){
  3342. $ids = explode(",",$order_ids);
  3343. foreach($ids as $k=>$v){
  3344. $order_id = $v;
  3345. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  3346. if (empty($order_info)) {
  3347. show_json(0, '未找到订单!');
  3348. }
  3349. if(!empty($order_info)) {
  3350. if ($order_info['order_status_id'] == 1 && $order_info['delivery'] == 'express' && $order_info['is_kdn_print'] == 1) {
  3351. $express_info = D('Seller/Express')->get_express_info($order_info['shipping_method']);
  3352. $data = array();
  3353. $data['order_status_id'] = 4;
  3354. M('lionfish_comshop_order')->where(array('order_id' => $order_id))->save($data);
  3355. $history_data = array();
  3356. $history_data['order_id'] = $order_id;
  3357. $history_data['order_status_id'] = 4;
  3358. $history_data['notify'] = 0;
  3359. $history_data['comment'] = '订单发货 ID: ' . $order_id . ' 订单号: ' . $item['order_num_alias'] . ' <br/>快递公司: ' . $express_info['name'] . ' 快递单号: ' . $item['shipping_no'];
  3360. $history_data['date_added'] = time();
  3361. M('lionfish_comshop_order_history')->add($history_data);
  3362. D('Home/Frontorder')->send_order_operate($item['order_id']);
  3363. } else {
  3364. show_json(0, '待发货快递订单才能发货成功!');
  3365. }
  3366. }else{
  3367. show_json(0, '未找到订单!');
  3368. }
  3369. }
  3370. }else{
  3371. show_json(0, '未找到订单!');
  3372. }
  3373. show_json(1);
  3374. }
  3375. /**
  3376. * 修改订单价格
  3377. */
  3378. public function change_order(){
  3379. $_GPC = I('request.');
  3380. $opdata = $this->check_order_data();
  3381. extract($opdata);
  3382. $id = I('request.id',0);
  3383. if( IS_POST )
  3384. {
  3385. $_GPC = I('request.');
  3386. $order_id = $_GPC['id'];
  3387. $order_goods_ids = $_GPC['order_goods_id'];
  3388. $change_prices = $_GPC['change_price'];
  3389. $count = 0;
  3390. foreach($change_prices as $v){
  3391. if(empty(trim($v))){
  3392. $count++;
  3393. }
  3394. }
  3395. if($count == count($change_prices)){
  3396. show_json(0, array('message' => '未填写涨价或减价金额!'));
  3397. }
  3398. //改价后的商品实付价格不能低于0.1元
  3399. foreach($order_goods_ids as $k=>$order_goods_id){
  3400. $order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_id' =>$id,'order_goods_id' =>$order_goods_id ) )->find();
  3401. $total = $order_goods_info['total'];
  3402. $fullreduction_money = $order_goods_info['fullreduction_money'];
  3403. $voucher_credit = $order_goods_info['voucher_credit'];
  3404. $score_for_money = $order_goods_info['score_for_money'];
  3405. $total = round($total - $fullreduction_money - $voucher_credit - $score_for_money,2);
  3406. if(!empty($change_prices[$k])){
  3407. $change_price = $change_prices[$k];
  3408. $total = floatval($total) + floatval($change_price);
  3409. if(bccomp($total, '0.1', 2) == -1){
  3410. show_json(0, array('message' => '改价后的商品实付价格不能低于0.1元'));
  3411. }
  3412. }
  3413. }
  3414. $change_amount = 0;
  3415. foreach($order_goods_ids as $k=>$order_goods_id){
  3416. $order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_id' =>$id,'order_goods_id' =>$order_goods_id ) )->find();
  3417. $total = $order_goods_info['total'];
  3418. $update_data = array();
  3419. if(!empty($change_prices[$k])){
  3420. $change_amount = $change_amount + $change_prices[$k];
  3421. $change_price = $change_prices[$k];
  3422. $update_data['total'] = round(floatval($total) + floatval($change_price),2);
  3423. $update_data['is_change_price'] = 1;
  3424. M('lionfish_comshop_order_goods')->where( array('order_id' =>$id,'order_goods_id' => $order_goods_id ) )->save( $update_data);
  3425. }
  3426. }
  3427. $order_info = M('lionfish_comshop_order')->where( array('order_id' =>$id) )->find();
  3428. $order_total = $order_info['total'];
  3429. $order_data = array();
  3430. $order_data['total'] = round(floatval($order_total) + floatval($change_amount),2);
  3431. $order_data['is_change_price'] = 1;
  3432. M('lionfish_comshop_order')->where( array('order_id' =>$id) )->save($order_data);
  3433. $oh = array();
  3434. $oh['order_id'] = $id;
  3435. $oh['order_status_id']=15;
  3436. $oh['comment']='订单改价';
  3437. $oh['date_added']=time();
  3438. M('lionfish_comshop_order_history')->add($oh);
  3439. show_json(1);
  3440. }
  3441. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $id) )->select();
  3442. foreach($order_goods as $k=>$v){
  3443. $order_goods[$k]['goods_img_url'] = tomedia($v['goods_images']);
  3444. }
  3445. $this->item = $opdata['item'];
  3446. $this->order_goods = $order_goods;
  3447. $this->display();
  3448. }
  3449. //检查是否配置第三方配送接口参数
  3450. public function check_delivery_config(){
  3451. $_GPC = I('request.');
  3452. $config_data = D('Seller/Config')->get_all_config();
  3453. $data_type = $_GPC['data_type'];
  3454. if($data_type == 'imdada'){
  3455. if(isset($config_data['localtown_imdada_merchant_id']) && !empty($config_data['localtown_imdada_shop_no']) && isset($config_data['localtown_imdada_appkey']) && !empty($config_data['localtown_imdada_appsecret'])){
  3456. show_json(1);
  3457. }else{
  3458. show_json(0, array('msg' => '达达配送平台参数未配置!' ) );
  3459. }
  3460. }else if($data_type == 'sf'){
  3461. if(isset($config_data['localtown_sf_dev_id']) && !empty($config_data['localtown_sf_dev_key']) && isset($config_data['localtown_sf_store_id'])){
  3462. show_json(1);
  3463. }else{
  3464. show_json(0, array('msg' => '顺丰同城参数未配置!' ) );
  3465. }
  3466. }else if($data_type == 'make'){
  3467. if(isset($config_data['localtown_mk_token']) && !empty($config_data['localtown_mk_token']) ){
  3468. show_json(1);
  3469. }else{
  3470. show_json(0, array('msg' => '码科配送参数未配置!' ) );
  3471. }
  3472. }else if($data_type == 'ele'){
  3473. if(isset($config_data['localtown_ele_app_id']) && !empty($config_data['localtown_ele_secret_key']) && isset($config_data['localtown_ele_store_code']) && !empty($config_data['localtown_ele_transport_name'])
  3474. && !empty($config_data['localtown_ele_transport_address']) && !empty($config_data['localtown_ele_transport_longitude']) && !empty($config_data['localtown_ele_transport_latitude'])
  3475. && !empty($config_data['localtown_ele_transport_tel']) && !empty($config_data['localtown_ele_position_source'])
  3476. ){
  3477. show_json(1);
  3478. }else{
  3479. show_json(0, array('msg' => '蜂鸟即配平台参数未配置!' ) );
  3480. }
  3481. }
  3482. }
  3483. /**
  3484. * 将订单推送给第三方配送
  3485. */
  3486. public function thirth_delivery_order(){
  3487. $_GPC = I('request.');
  3488. $data_type = $_GPC['data_type'];
  3489. $order_id = $_GPC['order_id'];
  3490. if(empty($data_type)){
  3491. show_json(0, array('msg' => '未选择第三方配送' ) );
  3492. }
  3493. if(empty($order_id)){
  3494. show_json(0, array('msg' => '订单号不存在' ) );
  3495. }
  3496. $order_info = M('lionfish_comshop_order')->where( array('order_id' =>$order_id) )->find();
  3497. if(empty($order_info)){
  3498. show_json(0, array('msg' => '订单不存在' ) );
  3499. }
  3500. //店铺地址
  3501. if($order_info['store_id'] > 0) {
  3502. $store_data = D('Home/Order')->getOrderStoreAddress($order_info);
  3503. $order_info['store_data'] = $store_data;
  3504. }
  3505. //商品信息
  3506. $sql = "select og.goods_id,og.name as goods_name,og.quantity,og.price,og.total,og.rela_goodsoption_valueid,g.weight as goods_weight from "
  3507. . C('DB_PREFIX')."lionfish_comshop_order_goods as og left join ".C('DB_PREFIX')."lionfish_comshop_goods as g on og.goods_id=g.id "
  3508. ." where og.order_id = ".$order_id;
  3509. $goods_list = M()->query($sql);
  3510. $goods_count = 0;
  3511. $goods_weight = 0;
  3512. $goods_type_count = 0;
  3513. foreach($goods_list as $k=>$v){
  3514. $goods_count = $goods_count + $v['quantity'];
  3515. if(!empty($v['rela_goodsoption_valueid'])){
  3516. $goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('option_item_ids' => $v['rela_goodsoption_valueid'],'goods_id' => $v['goods_id']) )->find();
  3517. if(!empty($goods_option_mult_value)){
  3518. $v['goods_weight'] = $goods_option_mult_value['weight'];
  3519. }
  3520. }
  3521. $goods_weight = $goods_weight + $v['quantity'] * $v['goods_weight'];
  3522. $goods_type_count = $goods_type_count + 1;
  3523. }
  3524. if(empty($goods_weight)){
  3525. $goods_weight = 100;//默认100克
  3526. }
  3527. $order_info['goods_list'] = $goods_list;
  3528. //商品种类
  3529. $order_info['goods_type_count'] = $goods_type_count;
  3530. //商品数量
  3531. $order_info['goods_count'] = $goods_count;
  3532. //商品重量
  3533. $order_info['goods_weight'] = $goods_weight;
  3534. //订单总金额
  3535. $order_info['order_total'] = $order_info['total']+$order_info['packing_fare']+$order_info['shipping_fare']-$order_info['voucher_credit']-$order_info['fullreduction_money']-$order_info['score_for_money']+$order_info['localtown_add_shipping_fare']-$order_info['fare_shipping_free'];
  3536. //收货人地址
  3537. $province_info = D('Home/Front')->get_area_info($order_info['shipping_province_id']);
  3538. $city_info = D('Home/Front')->get_area_info($order_info['shipping_city_id']);
  3539. $area_info = D('Home/Front')->get_area_info($order_info['shipping_country_id']);
  3540. $order_info['shipping_address'] = $province_info['name'].$city_info['name'].$area_info['name'].$order_info['shipping_address'];
  3541. //收货人经纬度
  3542. $order_distribution_info = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3543. //收货人地址纬度
  3544. $order_info['shipping_lat'] = $order_distribution_info['member_lat'];
  3545. //收货人地址经度
  3546. $order_info['shipping_lng'] = $order_distribution_info['member_lon'];
  3547. //商城名称
  3548. $shoname = D('Home/Front')->get_config_by_name('shoname');
  3549. $order_info['shoname'] = $shoname;
  3550. if($data_type == 'imdada'){
  3551. $imdada = new \Lib\Localtown\Imdada();
  3552. $result = $imdada->addOrder($order_info);
  3553. if($result['status'] == 1){//成功
  3554. //配送费用
  3555. $delivery_fee = $result['result']['fee'];
  3556. $express_info = array();
  3557. $express_info['delivery_fee'] = $delivery_fee;
  3558. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3559. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3560. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3561. show_json(1);
  3562. }else{//失败
  3563. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3564. }
  3565. }else if($data_type == 'sf'){
  3566. $sfexpress = new \Lib\Localtown\Sfexpress();
  3567. $result = $sfexpress->addOrder($order_info);
  3568. if($result['status'] == 1){//成功
  3569. //配送费用
  3570. $delivery_fee = round($result['result']['total_price']/100,2);
  3571. //顺丰订单号
  3572. $delivery_order_id = $result['result']['sf_order_id'];
  3573. //顺丰运单号
  3574. $delivery_bill_id = $result['result']['sf_bill_id'];
  3575. $express_info = array();
  3576. $express_info['delivery_fee'] = $delivery_fee;
  3577. $express_info['delivery_order_id'] = $delivery_order_id;
  3578. $express_info['delivery_bill_id'] = $delivery_bill_id;
  3579. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3580. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3581. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3582. show_json(1);
  3583. }else{//失败
  3584. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3585. }
  3586. }else if( $data_type == 'make' )
  3587. {
  3588. //$store_data = D('Home/Make')->getOrderStoreAddress($order_info);
  3589. $result = D('Home/Make')->addOrder($order_info);
  3590. if( $result['code'] == 0 )
  3591. {
  3592. //码科订单号
  3593. $delivery_order_id = $result['order_number'];
  3594. $express_info = array();
  3595. $express_info['delivery_fee'] = $order_distribution_info['shipping_money'];
  3596. $express_info['delivery_order_id'] = $delivery_order_id;
  3597. $express_info['delivery_bill_id'] = '';
  3598. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3599. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3600. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3601. show_json(1);
  3602. }else{
  3603. show_json(0, array('msg' => $result['message'] ) );
  3604. }
  3605. }else if($data_type == 'ele'){//蜂鸟即配
  3606. $eleDistribution = new \Lib\Localtown\EleDistribution();
  3607. $order_code = build_order_no(session('user_auth.uid'));
  3608. //保存蜂鸟即配商户订单号
  3609. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->save(['order_code'=>$order_code]);
  3610. $order_info['order_num_alias'] = $order_code;
  3611. $result = $eleDistribution->addOrder($order_info);
  3612. if($result['status'] == 1){//成功
  3613. //配送费用
  3614. $delivery_fee = round($result['result']['total_price']/100,2);
  3615. //蜂鸟即配订单号
  3616. $delivery_order_id = $result['result']['sf_order_id'];
  3617. //蜂鸟即配运单号
  3618. $delivery_bill_id = $result['result']['sf_bill_id'];
  3619. $express_info = array();
  3620. $express_info['delivery_fee'] = $delivery_fee;
  3621. $express_info['delivery_order_id'] = $delivery_order_id;
  3622. $express_info['delivery_bill_id'] = $delivery_bill_id;
  3623. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3624. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3625. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3626. show_json(1);
  3627. }else{//失败
  3628. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3629. }
  3630. }else{
  3631. show_json(0, array('msg' => '不存在第三方配送' ) );
  3632. }
  3633. }
  3634. /**
  3635. * 将订单重新推送给第三方配送
  3636. */
  3637. public function thirth_renew_delivery_order(){
  3638. $_GPC = I('request.');
  3639. $data_type = $_GPC['data_type'];
  3640. $order_id = $_GPC['order_id'];
  3641. if(empty($data_type)){
  3642. show_json(0, array('msg' => '未选择第三方配送' ) );
  3643. }
  3644. if(empty($order_id)){
  3645. show_json(0, array('msg' => '订单号不存在' ) );
  3646. }
  3647. $order_info = M('lionfish_comshop_order')->where( array('order_id' =>$order_id) )->find();
  3648. if(empty($order_info)){
  3649. show_json(0, array('msg' => '订单不存在' ) );
  3650. }
  3651. //店铺地址
  3652. if($order_info['store_id'] > 0) {
  3653. $store_data = D('Home/Order')->getOrderStoreAddress($order_info);
  3654. $order_info['store_data'] = $store_data;
  3655. }
  3656. //商品信息
  3657. $sql = "select og.goods_id,og.name as goods_name,og.quantity,og.rela_goodsoption_valueid,g.weight as goods_weight from "
  3658. . C('DB_PREFIX')."lionfish_comshop_order_goods as og left join ".C('DB_PREFIX')."lionfish_comshop_goods as g on og.goods_id=g.id "
  3659. ." where og.order_id = ".$order_id;
  3660. $goods_list = M()->query($sql);
  3661. $goods_count = 0;
  3662. $goods_weight = 0;
  3663. $goods_type_count = 0;
  3664. foreach($goods_list as $k=>$v){
  3665. $goods_count = $goods_count + $v['quantity'];
  3666. if(!empty($v['rela_goodsoption_valueid'])){
  3667. $goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('option_item_ids' => $v['rela_goodsoption_valueid'],'goods_id' => $v['goods_id']) )->find();
  3668. if(!empty($goods_option_mult_value)){
  3669. $v['goods_weight'] = $goods_option_mult_value['weight'];
  3670. }
  3671. }
  3672. $goods_weight = $goods_weight + $v['quantity'] * $v['goods_weight'];
  3673. $goods_type_count = $goods_type_count + 1;
  3674. }
  3675. if(empty($goods_weight)){
  3676. $goods_weight = 100;//默认100克
  3677. }
  3678. $order_info['goods_list'] = $goods_list;
  3679. //商品种类
  3680. $order_info['goods_type_count'] = $goods_type_count;
  3681. //商品数量
  3682. $order_info['goods_count'] = $goods_count;
  3683. //商品重量
  3684. $order_info['goods_weight'] = $goods_weight;
  3685. //订单总金额
  3686. $order_info['order_total'] = $order_info['total']+$order_info['packing_fare']+$order_info['shipping_fare']-$order_info['voucher_credit']-$order_info['fullreduction_money']-$order_info['score_for_money']+$order_info['localtown_add_shipping_fare']-$order_info['fare_shipping_free'];
  3687. //收货人地址
  3688. $province_info = D('Home/Front')->get_area_info($order_info['shipping_province_id']);
  3689. $city_info = D('Home/Front')->get_area_info($order_info['shipping_city_id']);
  3690. $area_info = D('Home/Front')->get_area_info($order_info['shipping_country_id']);
  3691. $order_info['shipping_address'] = $province_info['name'].$city_info['name'].$area_info['name'].$order_info['shipping_address'];
  3692. //收货人经纬度
  3693. $order_distribution_info = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3694. //收货人地址纬度
  3695. $order_info['shipping_lat'] = $order_distribution_info['member_lat'];
  3696. //收货人地址经度
  3697. $order_info['shipping_lng'] = $order_distribution_info['member_lon'];
  3698. //商城名称
  3699. $shoname = D('Home/Front')->get_config_by_name('shoname');
  3700. $order_info['shoname'] = $shoname;
  3701. if($data_type == 'imdada'){
  3702. $imdada = new \Lib\Localtown\Imdada();
  3703. $result = $imdada->reAddOrder($order_info);
  3704. if($result['status'] == 1){//成功
  3705. //配送费用
  3706. $delivery_fee = array();
  3707. $delivery_fee['delivery_fee'] = $result['result']['fee'];
  3708. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$delivery_fee);
  3709. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3710. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3711. show_json(1);
  3712. }else{//失败
  3713. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3714. }
  3715. }else if($data_type == 'sf'){
  3716. $sfexpress = new \Lib\Localtown\Sfexpress();
  3717. $result = $sfexpress->addOrder($order_info);
  3718. if($result['status'] == 1){//成功
  3719. //配送费用
  3720. $delivery_fee = round($result['result']['total_price']/100,2);
  3721. //顺丰订单号
  3722. $delivery_order_id = $result['result']['sf_order_id'];
  3723. //顺丰运单号
  3724. $delivery_bill_id = $result['result']['sf_bill_id'];
  3725. $express_info = array();
  3726. $express_info['delivery_fee'] = $delivery_fee;
  3727. $express_info['delivery_order_id'] = $delivery_order_id;
  3728. $express_info['delivery_bill_id'] = $delivery_bill_id;
  3729. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3730. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3731. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3732. show_json(1);
  3733. }else{//失败
  3734. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3735. }
  3736. }else if($data_type == 'make')
  3737. {
  3738. $result = D('Home/Make')->addOrder($order_info);
  3739. if( $result['code'] == 0 )
  3740. {
  3741. //码科订单号
  3742. $delivery_order_id = $result['order_number'];
  3743. $express_info = array();
  3744. $express_info['delivery_fee'] = $order_distribution_info['shipping_money'];
  3745. $express_info['delivery_order_id'] = $delivery_order_id;
  3746. $express_info['delivery_bill_id'] = '';
  3747. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3748. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3749. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3750. show_json(1);
  3751. }else{
  3752. show_json(0, array('msg' => $result['message'] ) );
  3753. }
  3754. }else if($data_type == 'ele'){//蜂鸟即配
  3755. $eleDistribution = new \Lib\Localtown\EleDistribution();
  3756. $order_code = build_order_no(session('user_auth.uid'));
  3757. //保存蜂鸟即配商户订单号
  3758. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->save(['order_code'=>$order_code]);
  3759. $order_info['order_num_alias'] = $order_code;
  3760. $result = $eleDistribution->addOrder($order_info);
  3761. if($result['status'] == 1){//成功
  3762. //配送费用
  3763. $delivery_fee = round($result['result']['total_price']/100,2);
  3764. //蜂鸟即配订单号
  3765. $delivery_order_id = $result['result']['sf_order_id'];
  3766. //蜂鸟即配运单号
  3767. $delivery_bill_id = $result['result']['sf_bill_id'];
  3768. $express_info = array();
  3769. $express_info['delivery_fee'] = $delivery_fee;
  3770. $express_info['delivery_order_id'] = $delivery_order_id;
  3771. $express_info['delivery_bill_id'] = $delivery_bill_id;
  3772. D('Seller/Order')->do_send_localtown_thirth_delivery($order_id,$data_type,$express_info);
  3773. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3774. D('Seller/Supply')->update_supply_commission($order_id,$shipping_money["shipping_money"]);
  3775. show_json(1);
  3776. }else{//失败
  3777. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3778. }
  3779. }
  3780. else{
  3781. show_json(0, array('msg' => '不存在第三方配送' ) );
  3782. }
  3783. }
  3784. public function third_cancel_reason(){
  3785. $order_id = I('request.order_id','');
  3786. $third_distribution_type = I('request.third_distribution_type','');
  3787. $this->order_id = $order_id;
  3788. $this->third_distribution_type = $third_distribution_type;
  3789. $this->display();
  3790. }
  3791. /**
  3792. * 取消第三方配送订单
  3793. */
  3794. public function thirth_cancel_delivery_order(){
  3795. $_GPC = I('request.');
  3796. $order_id = $_GPC['order_id'];
  3797. if(empty($order_id)){
  3798. show_json(0, array('msg' => '订单号不存在' ) );
  3799. }
  3800. $order_info = M('lionfish_comshop_order')->where( array('order_id' =>$order_id) )->find();
  3801. if(empty($order_info)){
  3802. show_json(0, array('msg' => '订单不存在' ) );
  3803. }
  3804. $orderdistribution_info = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' =>$order_id) )->find();
  3805. if(empty($orderdistribution_info)){
  3806. show_json(0, array('msg' => '配送订单不存在' ) );
  3807. }
  3808. $cancel_reason_id = $_GPC['cancel_reason_id'];
  3809. $cancel_reason = $_GPC['cancel_reason'];
  3810. $data_type = $orderdistribution_info['third_distribution_type'];
  3811. if($orderdistribution_info['state'] == 0 || $orderdistribution_info['state'] == 1 || $orderdistribution_info['state'] == 2){
  3812. if($data_type == 'imdada'){
  3813. $imdada = new \Lib\Localtown\Imdada();
  3814. $result = $imdada->cancelOrder($order_info,$cancel_reason_id,$cancel_reason);
  3815. if($result['status'] == 1){//成功
  3816. $deduct_fee = $result['result']['deduct_fee'];
  3817. $other_data = array();
  3818. $other_data['deduct_fee'] = $deduct_fee+$orderdistribution_info['deduct_fee'];
  3819. $other_data['cancel_reason'] = $cancel_reason;
  3820. $other_data['now_deduct_fee'] = $deduct_fee;
  3821. D('Seller/Order')->do_cancel_thirth_delivery_order($order_id,$data_type,$other_data);
  3822. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3823. D('Seller/Supply')->thirth_cancel_supply_commission($order_id,$shipping_money["shipping_money"]);
  3824. show_json(1);
  3825. }else{//失败
  3826. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3827. }
  3828. }else if($data_type == 'sf'){
  3829. $sfexpress = new \Lib\Localtown\Sfexpress();
  3830. $result = $sfexpress->cancelOrder($orderdistribution_info,$cancel_reason);
  3831. if($result['status'] == 1){//成功
  3832. $other_data = array();
  3833. if(empty($cancel_reason)){
  3834. $cancel_reason = "商家取消";
  3835. }
  3836. $other_data['cancel_reason'] = $cancel_reason;
  3837. $deduct_fee = round($result['result']['deduction_detail']['deduction_fee']/100,2);
  3838. $other_data['deduct_fee'] = $deduct_fee+$orderdistribution_info['deduct_fee'];
  3839. $other_data['now_deduct_fee'] = $deduct_fee;
  3840. D('Seller/Order')->do_cancel_thirth_delivery_order($order_id,$data_type,$other_data);
  3841. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3842. D('Seller/Supply')->thirth_cancel_supply_commission($order_id,$shipping_money["shipping_money"]);
  3843. show_json(1);
  3844. }else{//失败
  3845. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3846. }
  3847. }else if( $data_type == 'make' )
  3848. {
  3849. //$orderdistribution_info
  3850. $third_order_id = $orderdistribution_info['third_order_id'];
  3851. $result = D('Home/Make')->cancelOrder( $third_order_id );
  3852. if( $result['code'] == 0 )
  3853. {
  3854. $other_data = array();
  3855. if(empty($cancel_reason)){
  3856. $cancel_reason = "商家取消";
  3857. }
  3858. $other_data['cancel_reason'] = $cancel_reason;
  3859. $deduct_fee = 0;
  3860. $other_data['deduct_fee'] = $deduct_fee+$orderdistribution_info['deduct_fee'];
  3861. $other_data['now_deduct_fee'] = $deduct_fee;
  3862. D('Seller/Order')->do_cancel_thirth_delivery_order($order_id,$data_type,$other_data);
  3863. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3864. //D('Seller/Supply')->thirth_cancel_supply_commission($order_id,$shipping_money["shipping_money"]);
  3865. //load_model_class('supply')->thirth_cancel_supply_commission($order_id,$shipping_money["shipping_money"]);
  3866. show_json(1);
  3867. }else{
  3868. show_json(0, array('msg' => $result['message'] ) );
  3869. }
  3870. }else if($data_type == 'ele'){
  3871. $eleDistribution = new \Lib\Localtown\EleDistribution();
  3872. $result = $eleDistribution->cancelOrder($orderdistribution_info,$cancel_reason_id,$cancel_reason);
  3873. if($result['status'] == 1){//成功
  3874. $other_data = array();
  3875. if(empty($cancel_reason)){
  3876. $cancel_reason = "商家取消";
  3877. }
  3878. $other_data['cancel_reason'] = $cancel_reason;
  3879. $deduct_fee = round($result['result']['deduction_detail']['deduction_fee']/100,2);
  3880. $other_data['deduct_fee'] = $deduct_fee+$orderdistribution_info['deduct_fee'];
  3881. $other_data['now_deduct_fee'] = $deduct_fee;
  3882. D('Seller/Order')->do_cancel_thirth_delivery_order($order_id,$data_type,$other_data);
  3883. $shipping_money = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->find();
  3884. D('Seller/Supply')->thirth_cancel_supply_commission($order_id,$shipping_money["shipping_money"]);
  3885. show_json(1);
  3886. }else{//失败
  3887. show_json(0, array('msg' => $result['code'].':'.$result['message'] ) );
  3888. }
  3889. }
  3890. }else{
  3891. show_json(0, array('msg' => '配送订单无法取消' ) );
  3892. }
  3893. }
  3894. /**
  3895. * 达达平台模拟取货
  3896. */
  3897. public function orderFetch(){
  3898. $_GPC = I('request.');
  3899. $order_sn = $_GPC['order_sn'];
  3900. $type = $_GPC['type'];
  3901. $imdada = new \Lib\Localtown\Imdada();
  3902. if($type == 1){
  3903. $imdada->orderFetch($order_sn);//模拟取货
  3904. }else if($type == 2){
  3905. $imdada->orderFinish($order_sn);//完成订单
  3906. }else if($type == 3){
  3907. $imdada->orderCancel($order_sn);//取消订单
  3908. }else if($type == 4){
  3909. $imdada->orderAbnormal($order_sn);//异常妥投物品返还中
  3910. }
  3911. }
  3912. public function third_delivery_log_list(){
  3913. $order_id = I('request.order_id','');
  3914. $orderdistribution_info = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' =>$order_id) )->find();
  3915. $distribution_type = $orderdistribution_info['third_distribution_type'];
  3916. $log_list = M('lionfish_comshop_orderdistribution_thirth_log')->where( array('order_id' =>$order_id,'third_distribution_type'=>$distribution_type) )->order('addtime desc')->select();
  3917. $third_name = "";
  3918. if($distribution_type == 'imdada'){
  3919. $third_name = '达达平台';
  3920. }else if($distribution_type == 'sf'){
  3921. $third_name = '顺丰同城';
  3922. }else if($distribution_type == 'make'){
  3923. $third_name = '码科配送';
  3924. }else if($distribution_type == 'uupt'){
  3925. $third_name = 'UU跑腿';
  3926. }else if($distribution_type == 'dianwoda'){
  3927. $third_name = '点我达';
  3928. }
  3929. $this->third_name = $third_name;
  3930. $this->log_list = $log_list;
  3931. $this->orderdistribution_info = $orderdistribution_info;
  3932. $this->display();
  3933. }
  3934. //end
  3935. /**
  3936. * 订单核销
  3937. */
  3938. public function order_hexiao()
  3939. {
  3940. $opdata = $this->check_order_data();
  3941. extract($opdata);
  3942. if( $item['delivery'] == 'hexiao' )
  3943. {
  3944. D('Seller/Order')->hexiao_all_orders($item['order_id']);
  3945. }
  3946. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  3947. }
  3948. /**
  3949. * 商品按订单核销
  3950. */
  3951. public function order_goods_hexiao(){
  3952. $opdata = $this->check_order_data();
  3953. extract($opdata);
  3954. $order_goods_id = I('request.order_goods_id','');
  3955. $order_hexiao_info = M('lionfish_comshop_order_goods_saleshexiao')->where( array('order_id' => $id, 'order_goods_id' => $order_goods_id) )->find();
  3956. if (empty($order_hexiao_info)) {
  3957. show_json(0, '未找到核销订单!');
  3958. }
  3959. D('Seller/Order')->hexiao_order_goods($order_hexiao_info,0);
  3960. D('Seller/Order')->hexiao_finished($id,'后台确认使用,订单完成');
  3961. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  3962. }
  3963. /**
  3964. * 查看核销记录
  3965. */
  3966. public function view_hexiao_history(){
  3967. $opdata = $this->get_goods_saleshexiao();
  3968. extract($opdata);
  3969. $data = D('Seller/Order')->get_goods_hexiao_record();
  3970. $this->order_hexiao_info = $order_hexiao_info;
  3971. $this->hx_list = $data['hx_list'];
  3972. $this->display("hexiao_history");
  3973. }
  3974. /**
  3975. * 按次数核销商品
  3976. */
  3977. public function hexiao_times(){
  3978. $opdata = $this->get_goods_saleshexiao();
  3979. extract($opdata);
  3980. $data = D('Seller/Order')->get_goods_hexiao_record();
  3981. $this->order_hexiao_info = $order_hexiao_info;
  3982. $this->hx_list = $data['hx_list'];
  3983. $this->hx_count = $data['hx_count'];
  3984. $this->display();
  3985. }
  3986. /**
  3987. * 获取商品核销信息
  3988. * @return
  3989. */
  3990. public function get_goods_saleshexiao(){
  3991. $opdata = $this->check_order_data();
  3992. extract($opdata);
  3993. $order_goods_id = I('request.order_goods_id','');
  3994. $order_hexiao_info = M('lionfish_comshop_order_goods_saleshexiao')->where( array('order_id' => $id, 'order_goods_id' => $order_goods_id) )->find();
  3995. if (empty($order_hexiao_info)) {
  3996. show_json(0, '未找到核销订单!');
  3997. }
  3998. $order_goods_info = M('lionfish_comshop_order_goods')->where(array('order_goods_id'=>$order_hexiao_info['order_goods_id']))->field('goods_id,name as goods_name,goods_images,quantity')->find();
  3999. $order_hexiao_info['goods_id'] = $order_goods_info['goods_id'];
  4000. $order_hexiao_info['goods_name'] = $order_goods_info['goods_name'];
  4001. $order_hexiao_info['goods_images'] = tomedia($order_goods_info['goods_images']);
  4002. $order_hexiao_info['quantity'] = $order_goods_info['quantity'];
  4003. return array('order_hexiao_info' => $order_hexiao_info);
  4004. }
  4005. /**
  4006. * 核销商品使用
  4007. */
  4008. public function hexiao_goods(){
  4009. $hx_id = I('request.hx_id','');
  4010. $hx_count = I('request.hx_count','');
  4011. if(empty($hx_id)){
  4012. show_json(0, '核销商品数据错误!');
  4013. }
  4014. if(empty($hx_count)){
  4015. show_json(0, '核销商品数量错误!');
  4016. }
  4017. $order_hexiao_info = M('lionfish_comshop_order_goods_saleshexiao')->where( array('id' => $hx_id) )->find();
  4018. if (empty($order_hexiao_info)) {
  4019. show_json(0, '未找到核销订单!');
  4020. }
  4021. D('Seller/Order')->hexiao_order_goods($order_hexiao_info,$hx_count);
  4022. D('Seller/Order')->hexiao_finished($order_hexiao_info['order_id'],'后台确认使用,订单完成');
  4023. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  4024. }
  4025. /**
  4026. * 查看商品指定核销信息
  4027. */
  4028. public function hexiao_goods_assign_salesroom(){
  4029. $goods_id = I('request.goods_id','');
  4030. $order_goods_id = I('request.order_goods_id','');
  4031. if(empty($goods_id)){
  4032. show_json(0, '商品信息错误!');
  4033. }
  4034. if(empty($order_goods_id)){
  4035. show_json(0, '核销商品信息错误!');
  4036. }
  4037. $order_goods_info = M('lionfish_comshop_order_goods')->where(array('order_goods_id'=>$order_goods_id))->field('goods_id,name as goods_name,goods_images,quantity')->find();
  4038. $goods_salesroom_info = D('Seller/Order')->get_goods_assign_salesroom($goods_id);
  4039. $this->salesroom_list = $goods_salesroom_info['salesroom_list'];
  4040. $this->smember_list = $goods_salesroom_info['smember_list'];
  4041. $this->goods_info = $order_goods_info;
  4042. $this->display();
  4043. }
  4044. public function checkLocalTownOrderCanRefund($item){
  4045. if($item['delivery'] == 'localtown_delivery'){//同城配送订单
  4046. if($item['order_status_id'] == 4){//已发货不能退款
  4047. return false;
  4048. }else{
  4049. return true;
  4050. }
  4051. }else{
  4052. return true;
  4053. }
  4054. }
  4055. }
  4056. ?>