12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987 |
- <?php
- /**
- * lionfish 商城系统
- *
- * ==========================================================================
- * @link http://www.liofis.com/
- * @copyright Copyright (c) 2015 liofis.com.
- * @license http://www.liofis.com/license.html License
- * ==========================================================================
- *
- * @author fish
- *
- */
- namespace Home\Controller;
- class CommunityController extends CommonController {
-
- public function get_member_ziti_order()
- {
- $gpc = I('request.');
-
-
-
- $xq_member_id = $gpc['memberId'];
-
- $token = $gpc['token'];
-
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- $member_id = $weprogram_token['member_id'];
-
-
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 2) );
- die();
- }
-
- $community_info = D('Home/Front')->get_member_community_info($member_id);
-
-
- if( empty($community_info) && $member_info['pickup_id'] > 0 )
- {
-
- $parent_community_info = M('lionfish_comshop_community_pickup_member')->where( array('member_id' =>$member_id ) )->find();
-
- if(!empty($parent_community_info))
- {
- $community_info = M('lionfish_community_head')->where( array('id' => $parent_community_info['community_id'] ) )->find();
- }
- }
-
-
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 2) );
- die();
- }
-
- $where = ' and o.head_id = '.$community_info['id']." and o.member_id = ".$xq_member_id;
-
- $where .= ' and o.order_status_id = 4 ';
-
-
- $sql = "select o.order_id,o.order_num_alias,o.date_added,o.delivery,o.is_pin,o.is_zhuli,o.shipping_fare,o.voucher_credit,o.store_id,o.total,o.order_status_id,o.lottery_win,o.type,os.name as status_name,o.shipping_name,o.shipping_tel,o.payment_code "
- . " from ".C('DB_PREFIX')."lionfish_comshop_order as o ,
- ".C('DB_PREFIX')."lionfish_comshop_order_status as os
- where o.delivery != 'express' and o.delivery != 'hexiao' and o.order_status_id = os.order_status_id {$where}
- order by o.date_added desc ";
-
- $list = M()->query($sql);
-
- //createTime
- foreach($list as $key => $val)
- {
- $val['checked'] = 1;
- if($val['delivery'] == 'pickup')
- {
- //$val['total'] = round($val['total'],2) - round($val['voucher_credit'],2);
- }else{
- //$val['total'] = round($val['total'],2)+round($val['shipping_fare'],2) - round($val['voucher_credit'],2);
- }
- $val['createTime'] = date('Y-m-d H:i:s', $val['date_added']);
-
- // $val['delivery'] =='pickup'
-
- if($val['shipping_fare']<=0.001 || $val['delivery'] == 'pickup')
- {
- $val['shipping_fare'] = '免运费';
- }else{
- $val['shipping_fare'] = '运费:'.$val['shipping_fare'];
- }
-
-
- if($val['order_status_id'] == 10)
- {
- $val['status_name'] = '等待退款';
- }
- else if($val['order_status_id'] == 4 && $val['delivery'] =='pickup')
- {
- //delivery 6
- $val['status_name'] = '待自提';
- //已自提
- }
- else if($val['order_status_id'] == 6 && $val['delivery'] =='pickup')
- {
- //delivery 6
- $val['status_name'] = '已自提';
- //已自提
- }
- else if($val['order_status_id'] == 1 && $val['type'] == 'lottery')
- {
- //等待开奖
- //一等奖
- if($val['lottery_win'] == 1)
- {
- $val['status_name'] = '一等奖';
- }else {
- $val['status_name'] = '等待开奖';
- }
- }
- else if($val['order_status_id'] == 2 && $val['type'] == 'lottery')
- {
- //等待开奖
- $val['status_name'] = '等待开奖';
- }
-
- $quantity = 0;
- $url = D('Home/Front')->get_config_by_name('shop_domain').'/';
-
-
- $goods_sql = "select order_id,order_goods_id,head_disc,member_disc,level_name,goods_id,is_pin,shipping_fare,name,goods_images,quantity,price,total,rela_goodsoption_valueid,is_refund_state,has_refund_money,has_refund_quantity"
- . " from ".C('DB_PREFIX')."lionfish_comshop_order_goods where order_id= ".$val['order_id']."";
-
- $goods_list = M()->query($goods_sql); //M()->query($goods_sql);
- foreach($goods_list as $kk => $vv)
- {
- //commision
-
- if($is_tuanz == 1){
-
- $community_order_info = M('lionfish_community_head_commiss_order')->where( array('head_id' => $community_info['id'],'order_goods_id' => $vv['order_goods_id']) )->find();
-
-
- if(!empty($community_order_info))
- {
- $vv['commision'] = $community_order_info['money'];
- }else{
- $vv['commision'] = 0;
- }
-
- }
-
- $order_option_list = M('lionfish_comshop_order_option')->where( array('order_goods_id' => $vv['order_goods_id']) )->select();
-
-
- if( !empty($vv['goods_images']))
- {
-
- $goods_images = $url.resize($vv['goods_images'],400,400);
- if(is_array($goods_images))
- {
- $vv['goods_images'] = $vv['goods_images'];
- }else{
- $vv['goods_images']= $url.resize($vv['goods_images'],400,400) ;
- }
-
- }else{
- $vv['goods_images']= '';
- }
-
-
- $goods_filed = M('lionfish_comshop_goods')->field('productprice as price')->where( array('id' => $vv['goods_id']) )->find();
-
- $vv['orign_price'] = $goods_filed['price'];
- $quantity += $vv['quantity'];
- foreach($order_option_list as $option)
- {
- $vv['option_str'][] = $option['value'];
- }
- if( !isset($vv['option_str']) )
- {
- $vv['option_str'] = '';
- }else{
- $vv['option_str'] = implode(',', $vv['option_str']);
- }
- $vv['price'] = round($vv['price'],2);
- $vv['orign_price'] = round($vv['orign_price'],2);
-
- $vv['checked'] = 1;
- if( $vv['is_refund_state'] == 1 || ($vv['has_refund_money'] > 0 && $vv['has_refund_quantity'] > 0) )
- {
- $vv['is_refund_state'] = 1;
- $where = " order_id = '".$vv['order_id']."' and order_goods_id = '".$vv['order_goods_id']."' and state in (0,2,3) ";
- $refund_info = M('lionfish_comshop_order_refund')->field('ref_id,order_id,ref_money,real_refund_quantity,state')->where( $where )->find();
- if(!empty($refund_info)){
- $vv['refund_info'] = $refund_info;
- }else{
- $refund_info = array();
- $refund_info['order_id'] = $val['order_id'];
- $refund_info['ref_money'] = $vv['has_refund_money'];
- $refund_info['real_refund_quantity'] = $vv['has_refund_quantity'];
- $refund_info['state'] = 3;
- $vv['refund_info'] = $refund_info;
- }
- }
- $goods_list[$kk] = $vv;
- }
- $val['quantity'] = $quantity;
- if( empty($val['store_id']) )
- {
- $val['store_id'] = 1;
- }
-
-
- $store_info = array('s_true_name' =>'','s_logo' => '');
-
- $store_info['s_true_name'] = D('Home/Front')->get_config_by_name('shoname');
-
- $store_info['s_logo'] = D('Home/Front')->get_config_by_name('shoplogo');
-
-
-
- if( !empty($store_info['s_logo']))
- {
- $store_info['s_logo'] = $url .tomedia($store_info['s_logo']);
- }else{
-
- $store_info['s_logo'] = '';
- }
-
-
- $order_goods['store_info'] = $store_info;
-
-
-
-
- $val['store_info'] = $store_info;
-
-
- $val['goods_list'] = $goods_list;
-
- if($val['type'] == 'integral')
- {
- //暂时屏蔽积分
- //$integral_order = M('integral_order')->field('score')->where( array('order_id' => $val['order_id']) )->find();
- //$val['score'] = intval($integral_order['score']);
- }
-
- $val['total'] = round($val['total'],2);
- //货到付款订单
- if($val['payment_code'] == 'cashon_delivery'){
- $val['cashondelivery_code_img'] = D('Home/Front')->getCashonDeliveryCode();
- }
- $list[$key] = $val;
- }
-
- $need_data = array('code' => 0);
-
- if( !empty($list) )
- {
- $need_data['data'] = $list;
-
- }else {
- $need_data = array('code' => 1);
- }
-
- echo json_encode( $need_data );
- die();
-
- }
-
-
- public function get_community_zhitui_qrcode()
- {
- $_GPC = I('request.');
-
- $token = $_GPC['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- $member_id = $weprogram_token['member_id'];
-
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $community_info = D('Home/Front')->get_member_community_info($member_id);
-
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
- $head_id = $community_info['id'];
-
-
- $community_zhitui_qrcode_json = D('Home/Front')->get_config_by_name("community_zhitui_qrcode".$head_id);
-
- if( empty($community_zhitui_qrcode_json) )
- {
- $path = "lionfish_comshop/moduleA/groupCenter/apply";
- $zhitui_qrcod = D('Home/Pingoods')->_get_commmon_wxqrcode($path, $head_id);
-
- if( empty($zhitui_qrcod) )
- {
- $zhitui_qrcod = '';
- }else{
- $zhitui_qrcod = tomedia($zhitui_qrcod);
-
- $arr = array();
- $arr['qrcode'] = $zhitui_qrcod;
- $arr['express_time'] = time() + 600;
-
-
- $hd_key = "community_zhitui_qrcode".$head_id;
-
- D('Seller/Config')->update( array( $hd_key => serialize($arr)) );
- }
-
-
-
- echo json_encode( array('code' => 0, 'qrcode' => $zhitui_qrcod ) );
- die();
-
- }else{
-
- $community_zhitui_qrcode_arr = unserialize($community_zhitui_qrcode_json);
-
- if( $community_zhitui_qrcode_arr['express_time'] < time() )
- {
-
- $path = "lionfish_comshop/moduleA/groupCenter/apply";
- $zhitui_qrcod = D('Home/Pingoods')->_get_commmon_wxqrcode($path, $head_id);
-
- if( empty($zhitui_qrcod) )
- {
- $zhitui_qrcod = '';
- }else{
- $zhitui_qrcod = tomedia($zhitui_qrcod);
- $arr = array();
- $arr['qrcode'] = $zhitui_qrcod;
- $arr['express_time'] = time() + 600;
-
- $ky = "community_zhitui_qrcode".$head_id;
-
- D('Seller/Config')->update( array( $ky => serialize($arr) ) );
- }
-
- echo json_encode( array('code' => 0, 'qrcode' => $zhitui_qrcod ) );
- die();
- }else{
-
- echo json_encode( array('code' => 0, 'qrcode' => $community_zhitui_qrcode_arr['qrcode'] ) );
- die();
-
- }
- }
-
-
-
-
-
-
- }
-
-
-
- //------begin---
- /**
- 获取团长绑定核销人员二维码接口
- **/
- public function get_community_bind_member_qrcode()
- {
- $_GPC = I('request.');
-
- $token = $_GPC['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- $member_id = $weprogram_token['member_id'];
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $community_info = D('Home/Front')->get_member_community_info($member_id);
-
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
- $head_id = $community_info['id'];
-
- $community_memberbind_qrcode = D('Home/Front')->get_config_by_name('community_memberbind_qrcode'.$head_id);
-
-
- if( empty($community_memberbind_qrcode) )
- {
-
- $path = "lionfish_comshop/moduleA/groupCenter/bind_member_hexiao";
- $hexiao_qrcod = D('Home/Pingoods')->_get_commmon_wxqrcode($path, $head_id);
-
- $data = array();
- $data['time'] = time();
- $data['hexiao_qrcod'] = $hexiao_qrcod;
-
- $kd_lcc = 'community_memberbind_qrcode'.$head_id;
-
- D('Seller/Config')->update( array( $kd_lcc => serialize($data) ) );
-
-
-
- echo json_encode( array('code' => 0, 'qrcode' => tomedia($hexiao_qrcod) ) );
- die();
- }else{
- $hexiao_data = unserialize($community_memberbind_qrcode);
-
- if($hexiao_data['time'] + 600 < time() )
- {
- $path = "lionfish_comshop/moduleA/groupCenter/bind_member_hexiao";
- $hexiao_qrcod = D('Home/Pingoods')->_get_commmon_wxqrcode($path, $head_id);
-
- $data = array();
- $data['time'] = time();
- $data['hexiao_qrcod'] = $hexiao_qrcod;
-
- $ky = 'community_memberbind_qrcode'.$head_id;
-
- D('Seller/Config')->update( array( $ky => serialize($data) ) );
-
- echo json_encode( array('code' => 0, 'qrcode' => tomedia($hexiao_qrcod) ) );
- die();
- }else{
- echo json_encode( array('code' => 0, 'qrcode' => tomedia($hexiao_data['hexiao_qrcod']) ) );
- die();
- }
- }
-
- }
-
-
-
- /**
- 团长的核销人员列表
- **/
- public function get_community_hexiao_memberlist()
- {
- $_GPC = I('request.');
-
- $token = $_GPC['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- $member_id = $weprogram_token['member_id'];
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $community_info = D('Home/Front')->get_member_community_info($member_id);
-
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
- $head_id = $community_info['id'];
-
-
- $member_list = M()->query("select * from ".C('DB_PREFIX').
- "lionfish_comshop_community_pickup_member where community_id={$head_id} and state = 1 order by id desc ");
-
- if( empty($member_list) )
- {
- echo json_encode( array('code' => 1, 'log' => '暂时没有核销人员') );
- die();
- }else{
-
- foreach( $member_list as $key => $val )
- {
-
- $mb_info = M('lionfish_comshop_member')->field('avatar,username')->where( array('member_id' =>$val['member_id'] ) )->find();
-
- $member_record_count_arr = M()->query(" select count(order_id) as count from ".C('DB_PREFIX')
- ."lionfish_comshop_community_pickup_member_record where member_id=".$val['member_id'] );
-
-
-
- $member_record_count = $member_record_count_arr[0]['count'];
-
- $val['avatar'] = $mb_info['avatar'];
- $val['username'] = $mb_info['username'];
- $val['member_record_count'] = $member_record_count;
-
- $member_list[$key] = $val;
- //ims_lionfish_comshop_community_pickup_member_record
- }
-
- echo json_encode( array('code' => 0, 'member_list' => $member_list) );
- die();
- }
-
-
- //ims_lionfish_comshop_community_pickup_member
-
-
-
- }
-
- /**
- 绑定
- **/
-
- public function bind_community_member_do()
- {
- $_GPC = I('request.');
-
- $token = $_GPC['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- $member_id = $weprogram_token['member_id'];
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $name = $_GPC['name'];
- $mobile = $_GPC['mobile'];
- $community_id = $_GPC['community_id'];
-
-
- $is_in_info = M('lionfish_comshop_community_pickup_member')->where( array('member_id' => $member_id) )->find();
- if( !empty($is_in_info) )
- {
- echo json_encode( array('code' => 0) );
- die();
- }
-
- //pickup_id
- //lionfish_comshop_community_pickup_member
-
-
- $is_in_info = M('lionfish_comshop_community_pickup_member')->where( array('member_id' => $member_id ) )->find();
-
- if( !empty($is_in_info) )
- {
- echo json_encode( array('code' => 0) );
- die();
- }
-
-
- $ins_data = array();
- $ins_data['community_id'] = $community_id;
- $ins_data['member_id'] = $member_id;
- $ins_data['state'] = 1;
- $ins_data['remark'] = '前台扫码添加,姓名:'.$name.',手机号:'.$mobile;
- $ins_data['addtime'] = time();
-
- $pickup_id = M('lionfish_comshop_community_pickup_member')->add($ins_data);
-
- M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->save( array('pickup_id' => $pickup_id ));
-
- echo json_encode( array('code' => 0) );
- die();
- }
-
-
- //2、查看会员核销记录的
-
- public function get_member_hexiao_orderlist()
- {
- $_GPC = I('request.');
-
- $token = $_GPC['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- $member_id = $weprogram_token['member_id'];
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- //lionfish_comshop_community_pickup_member_record
- $page = isset($_GPC['page']) ? $_GPC['page']:'1';
-
- $size = isset($_GPC['size']) ? $_GPC['size']:'20';
- $offset = ($page - 1)* $size;
-
- $where = " and member_id = {$member_id} ";
-
-
- $sql = "select *
- from ".C('DB_PREFIX')."lionfish_comshop_community_pickup_member_record
- where 1 {$where}
- order by id desc limit {$offset},{$size}";
-
- $list = M()->query($sql);
- if( !empty($list) )
- {
- foreach($list as $key => $val)
- {
-
- $mb_info = M('lionfish_comshop_member')->field('username,avatar')->where( array('member_id' =>$val['member_id'] ) )->find();
-
- $val['username'] = $mb_info['username'];
- $val['avatar'] = $mb_info['avatar'];
-
- $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
-
- $list[$key] = $val;
- }
- }
-
- if( empty($list) )
- {
- echo json_encode(array('code' => 1));
- die();
- }else{
- echo json_encode( array('code' =>0, 'data' => $list) );
- die();
- }
-
- }
-
-
- //------end----
-
- /***
- 团长对清单进行收货
- **/
- public function sub_head_delivery()
- {
-
- $gpc = I('request.');
-
- $token = $gpc['token'];
-
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- $member_id = $weprogram_token['member_id'];
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $community_info = D('Home/Front')->get_member_community_info($member_id);
-
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
- $head_id = $community_info['id'];
-
- $list_id = $gpc['list_id'];
-
-
- $list_info = M('lionfish_comshop_deliverylist')->where( array('id' => $list_id, 'head_id' => $head_id) )->find();
-
- if( !empty($list_info) )
- {
-
- M('lionfish_comshop_deliverylist')->where( array('id' => $list_id ) )->save( array('state' => 2,'head_get_time' => time() ) );
-
- //对订单操作,可以去提货了 load_model_class('frontorder')->send_order_operate($order_id);
-
-
- $order_ids_all = M('lionfish_comshop_deliverylist_order')->where( array('list_id' => $list_id ) )->select();
-
- if( !empty($order_ids_all) )
- {
- foreach($order_ids_all as $order_val)
- {
- $order_status_id_info = M('lionfish_comshop_order')->field('order_status_id')->where( array('order_id' => $order_val['order_id'] ) )->find();
-
- $order_status_id = $order_status_id_info['order_status_id'];
- //配送中才能
- if($order_status_id == 14)
- {
-
- $history_data = array();
- $history_data['order_id'] = $order_val['order_id'];
- $history_data['order_status_id'] = 4;
- $history_data['notify'] = 0;
- $history_data['comment'] = '前台团长签收配送清单';
- $history_data['date_added'] = time();
-
- M('lionfish_comshop_order_history')->add( $history_data );
-
- //send_order_operate
- D('Home/Frontorder')->send_order_operate($order_val['order_id']);
- }
-
- }
- }
- echo json_encode( array('code' => 0) );
- die();
- }else{
- echo json_encode( array('code' => 1) );
- die();
- }
-
-
- }
-
- /**
- 获取团长清单的商品列表
- **/
- public function get_head_deliverygoods()
- {
- $gpc = I('request.');
-
- $token = $gpc['token'];
-
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- $member_id = $weprogram_token['member_id'];
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
-
- $community_info = D('Home/Front')->get_member_community_info($member_id);
-
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
- $head_id = $community_info['id'];
-
- //lionfish_comshop_deliverylist_goods
-
- $list_id = $gpc['list_id'];
-
- $page = isset($gpc['page']) ? $gpc['page']:'1';
-
- $size = isset($gpc['size']) ? $gpc['size']:'20';
- $offset = ($page - 1)* $size;
-
- $where = " and list_id = {$list_id} ";
-
-
- $sql = "select *
- from ".C('DB_PREFIX')."lionfish_comshop_deliverylist_goods
- where 1 {$where}
- order by id desc limit {$offset},{$size}";
-
- $list = M()->query($sql);
- if( !empty($list) )
- {
- foreach($list as $key => $val)
- {
- $val['goods_image'] = tomedia($val['goods_image']);
- $list[$key] = $val;
- }
- }
-
- if( empty($list) )
- {
- echo json_encode(array('code' => 1));
- die();
- }else{
- echo json_encode( array('code' =>0, 'data' => $list) );
- die();
- }
-
- }
-
- /**
- 获取团长的清单
- **/
- public function get_head_deliverylist()
- {
- $gpc = I('request.');
-
- $token = $gpc['token'];
-
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- $member_id = $weprogram_token['member_id'];
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $community_info = D('Home/Front')->get_member_community_info($member_id);
-
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
- $head_id = $community_info['id'];
-
- $page = isset($gpc['page']) ? $gpc['page']:'1';
-
- $size = isset($gpc['size']) ? $gpc['size']:'6';
- $offset = ($page - 1)* $size;
-
- $where = " and head_id = {$head_id} ";
-
- $status = isset( $gpc['status'] ) ? $gpc['status']: -1;
- $kyw = isset( $gpc['keywords'] ) ? $gpc['keywords']: '';
-
- if($status >= 0)
- {
- $where .= " and state = {$status} ";
- } else {
-
- }
- if(!empty($kyw))
- {
- $where .= ' and (head_name like "%'.$kyw.'%" or head_mobile like "%'.$kyw.'%" or line_name like "%'.$kyw.'%" or clerk_name like "%'.$kyw.'%" or clerk_mobile like "%'.$kyw.'%" )';
-
- }
-
-
- $sql = "select *
- from ".C('DB_PREFIX')."lionfish_comshop_deliverylist
- where 1 {$where}
- order by id desc limit {$offset},{$size}";
- $list = M()->query($sql);
-
-
- if( !empty($list) )
- {
- foreach ($list as $key => &$val) {
- $val['express_time'] = $val['express_time'] ? date('Y-m-d H:i', $val['express_time']) : '';
- $val['head_get_time'] = $val['head_get_time'] ? date('Y-m-d H:i', $val['head_get_time']) : '';
- $val['create_time'] = $val['create_time'] ? date('Y-m-d H:i',$val['create_time']) : '';
- }
- }
-
- if( empty($list) )
- {
- echo json_encode(array('code' => 1));
- die();
- }else{
- echo json_encode( array('code' =>0, 'data' => $list) );
- die();
- }
-
- }
-
- //--
- public function headorderlist()
- {
- $gpc = I('request.');
-
-
-
-
- $token = $gpc['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- $member_id = $weprogram_token['member_id'];
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $community_info = D('Home/Front')->get_member_community_info($member_id);
-
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
- $head_id = $community_info['id'];
-
- $page = isset($gpc['page']) ? $gpc['page']:'1';
-
- $size = isset($gpc['size']) ? $gpc['size']:'6';
- $offset = ($page - 1)* $size;
-
- $where = " and co.head_id = {$head_id} ";
-
- $order_status = $gpc['order_status'];
-
- if($order_status == 1)
- {
- $where .= " and co.state = 0 ";
- } else if($order_status == 2){
- $where .= " and co.state = 1 ";
- }
-
-
- /*$sql = "select co.order_id,co.state,co.money,co.addtime ,og.total,og.name
- from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co ,
- ".C('DB_PREFIX')."lionfish_comshop_order_goods as og
- where co.order_goods_id = og.order_goods_id {$where}
- order by co.id desc limit {$offset},{$size}";*/
- $sql = "select co.order_id,co.state,co.money,co.addtime ,og.total,og.name,co.type
- from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co left join
- ".C('DB_PREFIX')."lionfish_comshop_order_goods as og on co.order_goods_id = og.order_goods_id
- where 1=1 {$where}
- order by co.id desc limit {$offset},{$size}";
-
- $list = M()->query($sql);
-
- if( !empty($list) )
- {
- foreach($list as $key => $val)
- {
- $val['total'] = sprintf("%.2f",$val['total']);
- $val['money'] = sprintf("%.2f",$val['money']);
-
- $val['addtime'] = date('Y-m-d H:i:s',$val['addtime']);
-
- $order_info= M('lionfish_comshop_order')->field('order_num_alias')->where( array('order_id' => $val['order_id']) )->find();
-
- $val['order_num_alias'] = $order_info['order_num_alias'];
- if($val['type'] == 'tuijian'){
- $val['name'] = "推荐团长现金奖励";
- }
- $list[$key] = $val;
- }
- }
-
- if( empty($list) )
- {
- echo json_encode(array('code' => 1));
- die();
- }else{
- echo json_encode( array('code' =>0, 'data' => $list) );
- die();
- }
-
-
- }
-
- public function cashlist()
- {
- $gpc = I('request.');
-
-
- $token = $gpc['token'];
-
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- $member_id = $weprogram_token['member_id'];
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $community_info = D('Home/Front')->get_member_community_info($member_id);
-
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $page = isset($gpc['page']) ? $gpc['page']:'1';
-
- $size = isset($gpc['size']) ? $gpc['size']:'6';
- $offset = ($page - 1)* $size;
-
- //begin select
-
- $sql = "select *
- from ".C('DB_PREFIX')."lionfish_community_head_tixian_order
- where head_id =".$community_info['id']." and member_id={$member_id} order by id desc limit {$offset},{$size}";
-
- $list = M()->query($sql);
-
- foreach($list as $key => $val)
- {
- $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
- $val['id'] = sprintf("%04d", $val['id']);
-
- $list[$key] = $val;
- }
-
- if( empty($list) )
- {
- echo json_encode( array('code' => 1) );
- die();
- } else{
- echo json_encode( array('code' => 0, 'data' => $list) );
- die();
- }
- //ims_
-
- }
-
- public function get_community_member_orderlist()
- {
- $gpc = I('request.');
-
- $token = $gpc['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- $member_id = $weprogram_token['member_id'];
-
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $community_info = D('Home/Front')->get_member_community_info($member_id);
-
- if( empty($community_info) && $member_info['pickup_id'] > 0 )
- {
-
- $parent_community_info = M('lionfish_comshop_community_pickup_member')->where( array('member_id' => $member_id ) )->find();
-
- if(!empty($parent_community_info))
- {
- $community_info = M('lionfish_community_head')->where( array('id' => $parent_community_info['community_id'] ) )->find();
- }
-
-
- }
-
-
-
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $page = isset($gpc['page']) ? $gpc['page']:'1';
-
- $size = isset($gpc['size']) ? $gpc['size']:'20';
- $offset = ($page - 1)* $size;
-
- //begin select
- $where = ' and h.head_id = '.$community_info['id'];
-
- //date: that.data.date,
- //searchKey: that.data.searchKey,
- if( isset($gpc['date']) && !empty($gpc['date']) )
- {
-
- }
-
- if( isset($gpc['searchKey']) && !empty($gpc['searchKey']) )
- {
- $keywords = $gpc['searchKey'];
-
- $mb_order_list = M()->query( "select member_id from ". C('DB_PREFIX')."lionfish_comshop_order
- where head_id=".$community_info['id']." and (shipping_tel like '%{$keywords}%' or shipping_name like '%{$keywords}%' ) " );
-
- $member_id_ids = array();
- if( !empty($mb_order_list) ){
- foreach($mb_order_list as $val)
- {
- $member_id_ids[] = $val['member_id'];
- }
- }
-
-
- if( !empty($member_id_ids) )
- {
- $member_id_ids_str = implode(',', $member_id_ids);
- $where .=" and (m.username like '%{$keywords}%' or h.member_id in({$member_id_ids_str}) ) ";
- }else{
- $where .=" and (m.username like '%{$keywords}%' ) ";
- }
-
- }
-
- $sql = "select h.member_id,h.id ,m.avatar, m.username ,("."select count(order_id) from ".C('DB_PREFIX')."lionfish_comshop_order
- where order_status_id =4 and delivery!='express' and delivery!='hexiao' and member_id=m.member_id and head_id= ".$community_info['id'].") as m_count
- from ".C('DB_PREFIX')."lionfish_community_history as h left join ".C('DB_PREFIX')."lionfish_comshop_member as m on h.member_id = m.member_id
- where 1 {$where}
- group by h.member_id order by m_count desc, h.id desc limit {$offset},{$size}";
-
-
- $list = M()->query($sql);
-
-
- //ims_lionfish_comshop_order
- $need_list = array();
-
- foreach($list as $key => $val)
- {
- $mb_info_ck = M('lionfish_comshop_member')->where( array('member_id' => $val['member_id'] ) )->find();
- if( empty($mb_info_ck) )
- {
- continue;
- }
-
- $last_order_info = M('lionfish_comshop_order')->field('shipping_tel,shipping_name')->where( array('head_id' => $community_info['id'],'member_id' =>$val['member_id'] ) )->order('order_id desc')->find();
-
- if( empty($last_order_info) )
- {
- $val['mobile'] = '未下单';
- }else{
- $val['mobile'] = $last_order_info['shipping_tel'];
- }
- $val['shipping_name'] = $last_order_info['shipping_name'];
-
- $order_count = M('lionfish_comshop_order')->where( array('head_id' => $community_info['id'],'member_id' => $val['member_id'],'order_status_id' => 4) )->where("delivery!='express' and delivery!='hexiao'")->count();
-
-
- //$val['username'] = $member_info['username'];
- //$val['avatar'] = $member_info['avatar'];
- $val['order_count'] = $order_count;
-
- $list[$key] = $val;
- $need_list[$key] = $val;
- }
-
-
- $close_community_delivery_orders = D('Home/Front')->get_config_by_name('close_community_delivery_orders');
-
-
- if( !empty($need_list) )
- {
- $list = array();
- $i =0;
- foreach($need_list as $key => $val)
- {
- $list[$i] = $val;
- $i ++;
- }
-
- echo json_encode( array('code' => 0, 'data' => $list , 'close_community_delivery_orders'=>$close_community_delivery_orders ) );
- die();
- }else {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- }
-
-
- public function bind_community_info()
- {
- $gpc = I('request.');
-
-
-
- $token = $gpc['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
-
- $member_id = $weprogram_token['member_id'];
-
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $community_info = D('Home/Front')->get_member_community_info($member_id);
-
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $cardname = $gpc['cardname'];
- $cardaccount = $gpc['cardaccount'];
- $cardno = $gpc['cardno'];
-
- //ims_
- //pdo_update('lionfish_community_head', $data, array('id' => $head_info['id']));
-
- $data = array();
- $data['bankname'] = $cardname;
- $data['bankaccount'] = $cardaccount;
- $data['bankusername'] = $cardno;
-
-
- M('lionfish_community_head_commiss')->where( array('head_id' => $community_info['id']) )->save( $data );
-
- echo json_encode( array('code' => 0) );
- die();
-
- }
-
- public function get_community_info()
- {
- $gpc = I('request.');
-
- $token = $gpc['token'];
-
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
-
- $member_id = $weprogram_token['member_id'];
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $community_info = D('Home/Front')->get_member_community_info($member_id);
-
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $community_info['re_id'] = sprintf("%05d", $community_info['id']);
-
- $head_id = $community_info['id'];
- //已获佣金情况
- $commission_info = D('Seller/Community')->get_head_commission_info($member_id, $head_id);
-
- //总订单数量
- $total_order_count = D('Home/Frontorder')->get_community_head_order_count($head_id);
-
- //待配送 1 1
- $wait_send_count = M('lionfish_comshop_order')->where( array('order_status_id' => 1, 'head_id' => $head_id) )->where(" type != 'ignore' ")->count();
-
- //待签收 14 14
-
- $wait_qianshou_count = M('lionfish_comshop_order')->where( array('order_status_id' => 14, 'head_id' => $head_id) )->count();
-
- //待提货 4 4
- $wait_tihuo_count = M('lionfish_comshop_order')->where( array('order_status_id' => 4, 'head_id' => $head_id) )->count();
-
- //完成6-》 (6,11)
- $has_success_count = M('lionfish_comshop_order')->where( array('order_status_id' => array('in','6,11'), 'head_id' => $head_id) )->count();
-
-
-
- //会员数量
- $total_member_count = D('Seller/Community')->get_community_head_member_count($head_id);
-
- //预计佣金 state=0
- $pre_total_money = M('lionfish_community_head_commiss_order')->where( array('state' => 0,'head_id' => $head_id) )->sum('money');
-
- if( empty($pre_total_money) )
- {
- $pre_total_money = 0;
- }
- //退配送费
- $refund_shipping_fare = 0;
- $refund_shipping_sql = "SELECT SUM( refund_shipping_fare ) as refund_shipping_fare "
- . " FROM ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund ogf, ".C('DB_PREFIX')."lionfish_community_head_commiss_order oco "
- . " WHERE ogf.order_id = oco.order_id "
- . " AND oco.head_id = ".$head_id
- . " AND oco.state = 0 "
- . " AND oco.add_shipping_fare > 0 ";
- $refund_shippings = M()->query($refund_shipping_sql);
- if(!empty($refund_shippings)){
- $refund_shipping_fare = $refund_shippings[0]['refund_shipping_fare'];
- }
- $pre_total_money = $pre_total_money - $refund_shipping_fare;
- $commission_info['mix_total_money'] = $pre_total_money + $commission_info['money'] + $commission_info['dongmoney'] + $commission_info['getmoney'];
-
-
-
- $today_time = strtotime( date('Y-m-d').' 00:00:00' );
- //今日订单总数
-
- $today_order_count = M('lionfish_comshop_order')->where("head_id={$head_id} and date_added>={$today_time}")->count();
-
-
- //今日有效订单
-
- $today_effect_order_count = M('lionfish_comshop_order')->where( "order_status_id not in(3,5,7,12) and head_id={$head_id} and date_added>={$today_time} " )->count();
-
-
- //1、销售额:团长下面今日订单额度的总和,当日订单总数页面的总和 TODO..
- $seven_pay_where = " and head_id ={$head_id} and pay_time >= {$today_time} and order_status_id in (1,4,6,11,14) ";
-
- $seven_pay_money_info = D('Seller/Order')->get_order_sum(' sum(total+shipping_fare-voucher_credit-fullreduction_money) as total ' , $seven_pay_where);
-
- $head_today_pay_money = empty($seven_pay_money_info['total']) ? 0:$seven_pay_money_info['total'];
-
- $head_today_pay_money = sprintf("%.2f",$head_today_pay_money);
-
- //2、新增会员数:团长新增的用户统计 TODO..
-
- $sql_count = "select count(h.id) as count from ".C('DB_PREFIX').
- "lionfish_community_history as h, ".C('DB_PREFIX')."lionfish_comshop_member as m where m.member_id=h.member_id and h.head_id={$head_id} and m.create_time>={$today_time} ";
-
- $today_add_head_member_arr = M()->query($sql_count);
-
- $today_add_head_member = $today_add_head_member_arr[0]['count'];
-
- //3.售后订单(笔):今日团长下面,申请售后的订单
- $sql_count = "select count(ref_id) as count from ".C('DB_PREFIX').
- "lionfish_comshop_order_refund where head_id={$head_id} and addtime>={$today_time} ";
-
- $today_after_sale_order_count_arr = M()->query($sql_count);
-
- $today_after_sale_order_count = $today_after_sale_order_count_arr[0]['count'];
-
- //4、今日访客:统计今日浏览团长商城的用户数量 TODO..
- $sql_count = "select count(id) as count from ".C('DB_PREFIX').
- "lionfish_community_history where head_id={$head_id} and addtime>={$today_time} ";
-
- $today_invite_head_member_arr = M()->query($sql_count);
-
- $today_invite_head_member = $today_invite_head_member_arr[0]['count'];
-
-
- //今日付款人数
- $sql_count = "select order_id from ".C('DB_PREFIX')."lionfish_comshop_order where head_id={$head_id} and pay_time>={$today_time} group by member_id ";
- $today_pay_order_list = M()->query($sql_count);
-
- $today_pay_order_count = count($today_pay_order_list);
-
-
-
- //今日预计佣金
- //$today_pre_total_money = M('lionfish_community_head_commiss_order')->where( " state=0 and head_id={$head_id} and addtime>={$today_time}" )->sum('money');
- $pre_sql = "SELECT SUM( co.money ) as money "
- . "FROM ".C('DB_PREFIX')."lionfish_community_head_commiss_order AS co "
- . "LEFT JOIN ".C('DB_PREFIX')."lionfish_comshop_order AS o ON co.order_id = o.order_id"
- . " WHERE co.head_id = ".$head_id
- . " AND co.addtime >= ".$today_time
- . " AND o.order_status_id not in (3,5,7,12) and co.state != 2 ";
- $today_pre_total_moneys = M()->query($pre_sql);
- if(!empty($today_pre_total_moneys)){
- $today_pre_total_money = $today_pre_total_moneys[0]['money'];
- }
- if(empty($today_pre_total_money))
- {
- $today_pre_total_money = 0;
- }
- //退配送费
- $today_refund_shipping_fare = 0;
- $today_refund_shipping_sql = "SELECT SUM( refund_shipping_fare ) as refund_shipping_fare "
- . " FROM ".C('DB_PREFIX')."lionfish_comshop_order_goods_refund ogf, ".C('DB_PREFIX')."lionfish_community_head_commiss_order oco "
- . " WHERE ogf.order_id = oco.order_id "
- . " AND oco.head_id = ".$head_id
- . " AND oco.state = 0 "
- . " AND oco.addtime >= '".$today_time."'"
- . " AND oco.add_shipping_fare > 0 ";
- $today_refund_shippings = M()->query($today_refund_shipping_sql);
- if(!empty($today_refund_shippings)){
- $today_refund_shipping_fare = $today_refund_shippings[0]['refund_shipping_fare'];
- }
- $today_pre_total_money = $today_pre_total_money - $today_refund_shipping_fare;
-
-
- //今日预计佣金+得到佣金
- $today_all_total_money = M('lionfish_community_head_commiss_order')->where( "(state=0 or state =1) and head_id={$head_id} and addtime>={$today_time}" )->sum('money');
-
- if(empty($today_all_total_money))
- {
- $today_all_total_money = 0;
- }
- $today_all_total_money = sprintf("%.2f", $today_all_total_money);
-
-
- $month_day = date('Y-m').'-01 00:00:00';
- $month_time = strtotime($month_day);
-
- //本月收入 and (state=0 or state =1)
- $month_pre_total_money = M('lionfish_community_head_commiss_order')->where( "head_id={$head_id} and (state=0 or state =1) and addtime>={$month_time}" )->sum('money');
-
- if(empty($month_pre_total_money))
- {
- $month_pre_total_money = 0;
- }
-
- /**待确认佣金*/
-
- //$wait_sub_total_money = M('lionfish_community_head_commiss_order')->where( "head_id={$head_id} and state=0" )->sum('money');
- $sql = "select sum( co.money ) as money from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co ,
- ".C('DB_PREFIX')."lionfish_comshop_order_goods as og
- where co.order_goods_id = og.order_goods_id and og.is_refund_state = 0 and co.state = 0 and co.head_id = ".$head_id." order by co.id desc ";
-
- $pre_total_money_list = M()->query($sql);
- $wait_sub_total_money = $pre_total_money_list[0]['money'];
- if( empty($wait_sub_total_money) )
- {
- $wait_sub_total_money = 0;
- }
-
- //提现中
- $dongmoney = M('lionfish_community_head_tixian_order')->where( array('head_id' => $head_id, 'state' => 0) )->sum('money');
- if( empty($dongmoney) )
- {
- $dongmoney = 0 ;
- }
-
-
- /**已成功提现金额**/
-
- $tixian_sucess_money = M('lionfish_community_head_tixian_order')->where( array('head_id' => $head_id, 'state' => 1) )->sum('money');
-
- if( empty($tixian_sucess_money) )
- {
- $tixian_sucess_money = 0;
- }
-
-
- $head_commiss_tixianway_yuer = D('Home/Front')->get_config_by_name('head_commiss_tixianway_yuer');
- $head_commiss_tixianway_weixin = D('Home/Front')->get_config_by_name('head_commiss_tixianway_weixin');
- $head_commiss_tixianway_alipay = D('Home/Front')->get_config_by_name('head_commiss_tixianway_alipay');
- $head_commiss_tixianway_bank = D('Home/Front')->get_config_by_name('head_commiss_tixianway_bank');
-
- $community_info['head_commiss_tixianway_yuer'] = empty($head_commiss_tixianway_yuer) ? 1 : ($head_commiss_tixianway_yuer == 2 ? 1:0);
- $community_info['head_commiss_tixianway_weixin'] = empty($head_commiss_tixianway_weixin) ? 1 : ($head_commiss_tixianway_weixin == 2 ? 1:0);
- $community_info['head_commiss_tixianway_alipay'] = empty($head_commiss_tixianway_alipay) ? 1 : ($head_commiss_tixianway_alipay == 2 ? 1:0);
- $community_info['head_commiss_tixianway_bank'] = empty($head_commiss_tixianway_bank) ? 1 : ($head_commiss_tixianway_bank == 2 ? 1:0);
-
-
- //上一微信真实姓名 lionfish_community_head_tixian_order
- $last_weixin_realname = "";
-
- //C('DB_PREFIX')
- $last_weixin_info = M('lionfish_community_head_tixian_order')->where( array("member_id={$member_id} and head_id={$head_id} and type=2") )->find();
-
- if( !empty($last_weixin_info) )
- {
- $last_weixin_realname = $last_weixin_info['bankusername'];
- }
-
- //上一支付宝账号
- $last_alipay_name = '';
- $last_alipay_account = '';
-
- $last_alipay_info = M('lionfish_community_head_tixian_order')->where("member_id={$member_id} and head_id={$head_id} and type=3")->find();
-
- if( !empty($last_alipay_info) )
- {
- $last_alipay_name = $last_alipay_info['bankusername'];
- $last_alipay_account = $last_alipay_info['bankaccount'];
- }
-
- //上一银行卡信息
- $last_bank_bankname = '';
- $last_bank_account = '';
- $last_bank_name = '';
-
- $last_bank_info = M('lionfish_community_head_tixian_order')->where( "member_id={$member_id} and head_id={$head_id} and type=4" )->find();
-
- if( !empty($last_bank_info) )
- {
- $last_bank_bankname = $last_bank_info['bankname'];
- $last_bank_account = $last_bank_info['bankaccount'];
- $last_bank_name = $last_bank_info['bankusername'];
- }
-
- $community_info['last_weixin_realname'] = $last_weixin_realname;
- $community_info['last_alipay_name'] = $last_alipay_name;
- $community_info['last_alipay_account'] = $last_alipay_account;
-
- $community_info['last_bank_bankname'] = $last_bank_bankname;
- $community_info['last_bank_account'] = $last_bank_account;
- $community_info['last_bank_name'] = $last_bank_name;
-
-
- $head_commission_levelname = D('Home/Front')->get_config_by_name('head_commission_levelname');
- $default_comunity_money = D('Home/Front')->get_config_by_name('default_comunity_money');
-
- $level_list = array(
- 0 => array('levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $default_comunity_money )
- );
-
-
- $hd_level_list = M('lionfish_comshop_community_head_level')->where(1)->select();
-
- if( !empty($hd_level_list) )
- {
- foreach( $hd_level_list as $val )
- {
- $tmp = array();
- $tmp['levelname'] = $val['levelname'];//等级名称
- $tmp['commission'] = $val['commission'];//分佣比例
-
- $level_list[$val['id']] = $tmp;
- }
- }
- $is_show_head_level = D('Home/Front')->get_config_by_name('is_show_head_level');
-
- $community_info['is_show_head_level'] = $is_show_head_level;
- $community_info['head_level_info'] = $level_list[ $community_info['level_id'] ];
-
- // 接龙开关
- $is_open_solitaire = D('Home/Front')->get_config_by_name('is_open_solitaire');
- $is_show_community_ranking = D('Home/Front')->get_config_by_name('is_show_community_ranking');
- //是否显示团长排行, 0不显示,1显示
- $is_show_community_ranking = empty($is_show_community_ranking) ? 0 : $is_show_community_ranking;
- $result = array();
- $result['code'] = 0;
- $result['member_info'] = $member_info;
- $result['community_info'] = $community_info;
- $result['commission_info'] = $commission_info;
- $result['total_order_count'] = $total_order_count;
- $result['total_member_count'] = $total_member_count;
- $result['today_order_count'] = $today_order_count;
- $result['today_effect_order_count'] = $today_effect_order_count;
- $result['today_all_total_money'] = $today_all_total_money;
- $result['today_pay_order_count'] = $today_pay_order_count;
- $result['today_pre_total_money'] = $today_pre_total_money;
- $result['month_pre_total_money'] = $month_pre_total_money;
- $result['pre_total_money'] = $pre_total_money;
- $result['wait_sub_total_money'] = $wait_sub_total_money;
- $result['dongmoney'] = $dongmoney;
- $result['tixian_sucess_money'] = $tixian_sucess_money;
-
- $result['wait_send_count'] = $wait_send_count;
- $result['wait_qianshou_count'] = $wait_qianshou_count;
- $result['wait_tihuo_count'] = $wait_tihuo_count;
- $result['has_success_count'] = $has_success_count;
-
- $result['head_today_pay_money'] = $head_today_pay_money;//今日销售额
- $result['today_add_head_member'] = $today_add_head_member;//今日新增会员数
- $result['today_after_sale_order_count'] = $today_after_sale_order_count;//今日售后订单
- $result['today_invite_head_member'] = $today_invite_head_member;//今日访客
- $result['is_show_community_ranking'] = $is_show_community_ranking;//团长排行
- $result['is_open_solitaire'] = $is_open_solitaire;
-
-
- $community_tixian_fee = D('Home/Front')->get_config_by_name('community_tixian_fee');
-
- $community_min_money = D('Home/Front')->get_config_by_name('community_min_money');
-
- if( empty($community_min_money) )
- {
- $community_min_money = 0;
- }
-
- if( empty($community_tixian_fee) )
- {
- $community_tixian_fee = 0;
- }
- $result['community_tixian_fee'] = $community_tixian_fee;
- $result['community_min_money'] = $community_min_money;
-
-
- $open_community_addhexiaomember = D('Home/Front')->get_config_by_name('open_community_addhexiaomember');
-
- if( empty($open_community_addhexiaomember) )
- {
- $open_community_addhexiaomember = 0;
- }
-
- $result['open_community_addhexiaomember'] = $open_community_addhexiaomember;
-
- //团长等级
- $open_community_head_leve = D('Home/Front')->get_config_by_name('open_community_head_leve');
-
- if( empty($open_community_head_leve) )
- {
- $open_community_head_leve = 0;
- }
-
- $result['open_community_head_leve'] = $open_community_head_leve;
-
- $head_commiss_tixian_publish = D('Home/Front')->get_config_by_name('head_commiss_tixian_publish');
-
- $result['head_commiss_tixian_publish'] = htmlspecialchars_decode( $head_commiss_tixian_publish );
-
-
- $is_need_subscript = 0;
- $need_subscript_template = array();
-
-
- $apply_tixian_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id , 'type' => 'apply_tixian') )->find();
-
- if( empty($apply_tixian_info) )
- {
- $weprogram_subtemplate_apply_tixian = D('Home/Front')->get_config_by_name('weprogram_subtemplate_apply_tixian');
-
- if( !empty($weprogram_subtemplate_apply_tixian) )
- {
- $need_subscript_template['apply_tixian'] = $weprogram_subtemplate_apply_tixian;
- }
- }
-
- if( !empty($need_subscript_template) )
- {
- $is_need_subscript = 1;
- }
-
-
- $result['is_need_subscript'] = $is_need_subscript;
- $result['need_subscript_template'] = $need_subscript_template;
- // 分享信息
- $result['shop_index_share_title'] = D('Home/Front')->get_config_by_name('shop_index_share_title');
- $shop_index_share_image = D('Home/Front')->get_config_by_name('shop_index_share_image');
- $result['shop_index_share_image'] = "";
- if($shop_index_share_image) {
- $result['shop_index_share_image'] = tomedia($shop_index_share_image);
- }
- echo json_encode( $result );
- die();
- }
- //begin
- /**
- 获取团长的下级列表接口
- **/
- public function get_head_child_headlist()
- {
- $gpc = I('request.');
- $_GPC = I('request.');
-
- $token = $gpc['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
-
- $member_id = $weprogram_token['member_id'];
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $community_info = D('Home/Front')->get_member_community_info($member_id);
-
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $head_id = $community_info['id'];
-
-
- //...
-
- $page = isset($_GPC['page']) ? $_GPC['page']:'1';
-
- $size = isset($_GPC['size']) ? $_GPC['size']:'20';
- $offset = ($page - 1)* $size;
-
- //begin select
- //$where = ' and head_id = '.$head_id;
-
- $level = isset($_GPC['level']) ? $_GPC['level']: 1;
-
- $level_1_ids = array();
- $level_2_ids = array();
- $level_3_ids = array();
-
- $head_id_arr = array($head_id);
-
- if( $level == 1 )
- {
- $list = array();
-
- $sql = "select * from ".C('DB_PREFIX')."lionfish_community_head
- where agent_id in (".implode(',', $head_id_arr).") order by id desc limit {$offset},{$size}";
-
- $list = M()->query($sql);
-
- foreach( $list as $vv )
- {
- $level_1_ids[] = $vv['id'];
- }
-
- }else if( $level == 2 )
- {
- $list = array();
-
- $sql = "select * from ".C('DB_PREFIX')."lionfish_community_head
- where agent_id in (".implode(',', $head_id_arr).") order by id desc limit {$offset},{$size}";
-
- $list1 = M()->query($sql);
-
- if( !empty($list1) )
- {
- foreach( $list1 as $vv )
- {
- $level_1_ids[] = $vv['id'];
- }
-
- $level_sql2 =" select * from ".C('DB_PREFIX').
- "lionfish_community_head where
- agent_id in (select id from ".C('DB_PREFIX')."lionfish_community_head
- where agent_id ={$head_id} order by id desc ) order by id desc ";
-
- $list2 = M()->query($level_sql2);
-
- if( !empty($list2) || !empty($level_1_ids))
- {
- foreach( $list2 as $vv )
- {
- $level_2_ids[] = $vv['id'];
- }
-
- $need_ids = empty($level_1_ids) ? array() : $level_1_ids;
- if(!empty($level_2_ids))
- {
- foreach($level_2_ids as $vv)
- {
- $need_ids[] = $vv;
- }
- }
-
- $sql =" select * from ".C('DB_PREFIX').
- "lionfish_community_head where
- id in (".implode(',', $need_ids ).") order by id desc limit {$offset},{$size}";
-
- $list = M()->query($sql);
- }
- }
-
- }else if( $level == 3 ){
- $sql = "select * from ".C('DB_PREFIX')."lionfish_community_head
- where agent_id in (".implode(',', $head_id_arr).") order by id desc limit {$offset},{$size}";
-
- $list1 = M()->query($sql);
-
- if( !empty($list1) )
- {
- foreach( $list1 as $vv )
- {
- $level_1_ids[] = $vv['id'];
- }
- $need_ids = empty($level_1_ids) ? array() : $level_1_ids;
-
- $level_sql2 =" select * from ".C('DB_PREFIX').
- "lionfish_community_head where
- agent_id in (select id from ".C('DB_PREFIX')."lionfish_community_head
- where agent_id ={$head_id} order by id desc ) order by id desc ";
-
- $list2 = M()->query($level_sql2);
-
- if( !empty($list2) || !empty($level_1_ids))
- {
- foreach( $list2 as $vv )
- {
- $level_2_ids[] = $vv['id'];
- }
-
- if(!empty($level_2_ids))
- {
- foreach($level_2_ids as $vv)
- {
- $need_ids[] = $vv;
- }
- }
- }
-
-
- $level_sql3 =" select * from ".C('DB_PREFIX').
- "lionfish_community_head where
- agent_id in (".implode(',', $need_ids).") order by id desc ";
-
- $list3 = M()->query($level_sql3);
-
- if( !empty($list3) )
- {
- foreach( $list3 as $vv )
- {
- $level_3_ids[] = $vv['id'];
- }
-
- if(!empty($level_3_ids))
- {
- foreach($level_3_ids as $vv)
- {
- $need_ids[] = $vv;
- }
- }
- }
-
- $level_sql3 =" select * from ".C('DB_PREFIX').
- "lionfish_community_head where id in (".implode(',',$need_ids).") order by id desc limit {$offset},{$size}";
-
- $list = M()->query($level_sql3);
-
- }
-
-
-
- }
-
- //---------等级
-
- $community_head_level = M('lionfish_comshop_community_head_level')->order('id asc')->select();
-
- $head_commission_levelname = D('Home/Front')->get_config_by_name('head_commission_levelname');
- $default_comunity_money = D('Home/Front')->get_config_by_name('default_comunity_money');
-
- $list_default = array(
- array('id' => '0','level'=>0,'levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $default_comunity_money, )
- );
-
- $community_head_level = array_merge($list_default, $community_head_level);
-
- $level_id_to_name = array( 0=> empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname );
-
-
- foreach($community_head_level as $kk => $vv)
- {
- $level_id_to_name[$vv['id']] = $vv['levelname'];
- }
- //---------等级
-
- $level_list = array();
- $need_list = array();
-
- if( !empty($list) ){
- foreach($list as $key => $val)
- {
- $mb_info = M('lionfish_comshop_member')->field('avatar,username')->where( array('member_id' => $val['member_id'] ) )->find();
-
- $val['level_name'] = $level_id_to_name[ $val['level_id'] ];
-
- $val['avatar'] = $mb_info['avatar'];
- $val['username'] = $mb_info['username'];
- $val['apptime'] = date('Y-m-d H:i:s', $val['apptime']);
-
- $need_list[$key] = $val;
- }
- }
-
- if( !empty($need_list) )
- {
- echo json_encode( array('code' => 0, 'data' => $need_list) );
- die();
- }else {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- }
-
- /**
- 获取团长分销账户信息情况
- **/
- public function get_head_distribute_info()
- {
- $gpc = I('request.');
- $_GPC = I('request.');
-
- $token = $gpc['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- $member_id = $weprogram_token['member_id'];
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $community_info = D('Home/Front')->get_member_community_info($member_id);
-
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $head_id = $community_info['id'];
-
- $open_community_head_leve = D('Home/Front')->get_config_by_name('open_community_head_leve');
- if( empty($open_community_head_leve) )
- {
- $open_community_head_leve = 0;
- }
- //总收入 wait_money
- //lionfish_community_head_commiss_order
-
- /**总收入 0 1 **/
-
- $total_money = M('lionfish_community_head_commiss_order')->where( "(type='tuijian' or type ='commiss') and head_id={$head_id} and state=1" )->sum('money');
-
- if( empty($total_money) )
- {
- $total_money = 0;
- }
- //tuijian commiss
-
-
- //待确认
-
- $tixian_wait_money = M('lionfish_community_head_commiss_order')->where( "(type='tuijian' or type ='commiss') and head_id={$head_id} and state=0" )->sum('money');
-
- if( empty($tixian_wait_money) )
- {
- $tixian_wait_money = 0;
- }
-
- //已确认
- $tixian_success_money = M('lionfish_community_head_commiss_order')->where( "(type='tuijian' or type ='commiss') and head_id={$head_id} and state=1" )->sum('money');
-
- if( empty($tixian_success_money) )
- {
- $tixian_success_money = 0;
- }
-
- //下级团长数量
- $level_count1 = 0;
- $level_count2 = 0;
- $level_count3 = 0;
- $level_count1 = M('lionfish_community_head')->where( array('agent_id' => $head_id ) )->count();
-
- if( empty($level_count1) || $level_count1 == 0 )
- {
- $level_count1 = 0;
- }else{
-
- $level_sql2 =" select count(1) as count from ".C('DB_PREFIX').
- "lionfish_community_head where
- agent_id in (select id from ".C('DB_PREFIX')."lionfish_community_head
- where agent_id ={$head_id} ) ";
- $level_count2_arr = M()->query($level_sql2);
- $level_count2 = $level_count2_arr[0]['count'];
-
- if( empty($level_count2) || $level_count2 == 0 )
- {
- $level_count2 = 0;
- }else{
-
- $level_sqllist2 =" select id from ".C('DB_PREFIX').
- "lionfish_community_head where
- agent_id in (select id from ".C('DB_PREFIX')."lionfish_community_head
- where agent_id ={$head_id} ) ";
-
- $level_list2 = M()->query($level_sqllist2);
- if( !empty($level_list2) )
- {
- $level_arr2 = array();
-
- foreach( $level_list2 as $vvv )
- {
- $level_arr2[] = $vvv['id'];
- }
-
- $level_sql3 =" select count(1) as count from ".C('DB_PREFIX').
- "lionfish_community_head where agent_id in (".implode(',',$level_arr2).") ";
- $level_count3_arr = M()->query( $level_sql3 );
- $level_count3 = $level_count3_arr[0]['count'];
-
- if( empty($level_count3) || $level_count3 == 0 )
- {
- $level_count3 = 0;
- }
- }
- }
- }
-
- $need_data = array();
- $need_data['open_community_head_leve'] = $open_community_head_leve;
- $need_data['total_money'] = $total_money;
- $need_data['wait_money'] = sprintf("%.2f",$tixian_wait_money);
- $need_data['success_money'] = sprintf("%.2f",$tixian_success_money);
- $need_data['level_count1'] = $level_count1;
- $need_data['level_count2'] = $level_count1 + $level_count2 ;
- $need_data['level_count3'] = $level_count1 + $level_count2 + $level_count3;
- echo json_encode( array('code' => 0, 'data' => $need_data ) );
- die();
- }
-
- /**
- 获取团长分销明细
- **/
-
- public function get_head_distribute_order()
- {
- $gpc = I('request.');
- $_GPC = I('request.');
-
- $token = $gpc['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- $member_id = $weprogram_token['member_id'];
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
-
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $community_info = D('Home/Front')->get_member_community_info($member_id);
-
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $head_id = $community_info['id'];
-
-
- $page = isset($_GPC['page']) ? $_GPC['page']:'1';
-
- $size = isset($_GPC['size']) ? $_GPC['size']:'20';
- $offset = ($page - 1)* $size;
-
- $where = ' and head_id = '.$head_id;
-
-
- $type = isset($_GPC['type']) ? $_GPC['type']: '';
- $level = isset($_GPC['level']) ? $_GPC['level']: 0;
-
- if( empty($type) )
- {
- $where .= " and type in ('commiss','tuijian')";
- }
-
- if( $level > 0 )
- {
- //level
- $where .= " and level=".$level;
- }
- //commiss
-
- $sql = "select * from ".C('DB_PREFIX')."lionfish_community_head_commiss_order
- where 1 {$where} order by id desc limit {$offset},{$size}";
-
- $list = M()->query($sql);
-
- $status_list = M('lionfish_comshop_order_status')->select();
-
- $status_arr = array();
- foreach($status_list as $vv)
- {
- $status_arr[ $vv['order_status_id'] ] = $vv['name'];
- }
-
- $need_list = array();
- foreach($list as $key => $val)
- {
- $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
-
- $child_head = M('lionfish_community_head')->where( array('id' => $val['child_head_id'] ) )->find();
-
- $val['child_head_name'] = $child_head['head_name'];
- $val['community_name'] = $child_head['community_name'];
-
- if( $val['type'] == 'commiss')
- {
- $order_info = M('lionfish_comshop_order')->field('order_num_alias,order_status_id')
- ->where( array('order_id' => $val['order_id'] ) )->find();
-
- $val['order_num_alias'] = $order_info['order_num_alias'];
- $val['order_status'] = $status_arr[ $order_info['order_status_id'] ];
- }
-
- $need_list[$key] = $val;
- }
-
- if( !empty($need_list) )
- {
- echo json_encode( array('code' => 0, 'data' => $need_list) );
- die();
- }else {
- echo json_encode( array('code' => 1) );
- die();
- }
- }
-
- //end
-
- public function tixian_community_info()
- {
- $gpc = I('request.');
-
-
-
- $token = $gpc['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
-
- $member_id = $weprogram_token['member_id'];
-
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $community_info = D('Home/Front')->get_member_community_info($member_id);
-
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
- $head_id = $community_info['id'];
- $commission_info = D('Seller/Community')->get_head_commission_info($member_id, $head_id);
-
- $tixian_money = $gpc['tixian_money'];
-
-
- $type = isset($gpc['type']) ? $gpc['type'] : 0;//0 沿用原来的逻辑 1余额 2 微信 3 支付宝 4 银行
-
- $bankname = isset($gpc['bankname']) ? $gpc['bankname'] : ''; //银行名称
-
- $bankaccount = isset($gpc['bankaccount']) ? $gpc['bankaccount'] : '';//卡号,支付宝账号 使用该字段
-
- $bankusername = isset($gpc['bankusername']) ? $gpc['bankusername'] : '';//持卡人姓名,微信名称,支付宝名称, 使用该字段
-
- $service_charge = D('Home/Front')->get_config_by_name('community_tixian_fee');
-
- if($commission_info['money'] >= $tixian_money )
- {
- $data = array();
- $data['member_id'] = $member_id;
- $data['head_id'] = $head_id;
- $data['money'] = floatval($tixian_money);
- $data['state'] = 0;
-
- $data['type'] = $type;
- $data['bankname'] = $bankname;
- $data['bankaccount'] = $bankaccount;
- $data['bankusername'] = $bankusername;
- $data['service_charge'] = round( ($tixian_money * $service_charge) /100,2);
-
- $data['shentime'] = 0;
- $data['addtime'] = time();
-
- M('lionfish_community_head_tixian_order')->add($data);
-
- M()->execute("update ".C('DB_PREFIX')."lionfish_community_head_commiss set money=money - {$tixian_money},dongmoney=dongmoney+{$tixian_money}
- where head_id={$head_id} ");
-
- echo json_encode( array('code' => 0) );
- die();
- }else{
-
- echo json_encode( array('code'=>1) );
- die();
- }
-
-
- }
-
-
- public function sub_community_head()
- {
- $gpc = I('request.');
-
-
- $token = $gpc['token'];
-
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
-
- $member_id = $weprogram_token['member_id'];
-
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
-
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $province_name = $gpc['province_name'];
- $city_name = $gpc['city_name'];
- $area_name = $gpc['area_name'];
- $country_name = $gpc['country_name'];
-
- $lon_lat = $gpc['lon_lat'];
-
- $lon_lat_arr = explode(',', $lon_lat);
- $wechat = $gpc['wechat'];
-
-
-
- $province_info = D('Home/Front')->get_area_ninfo_by_name($province_name);
- $province_id = $province_info['id'];
-
- $city_info = D('Home/Front')->get_area_ninfo_by_name($city_name);
- $city_id = $city_info['id'];
-
- $area_info = D('Home/Front')->get_area_ninfo_by_name($area_name);
- $area_id = $area_info['id'];
-
- $country_info = D('Home/Front')->get_area_ninfo_by_name($country_name);
- $country_id = $country_info['id'];
-
-
- $addr_detail = $gpc['addr_detail'];
- $community_name = $gpc['community_name'];
- $mobile = $gpc['mobile'];
- $head_name = $gpc['head_name'];
-
- $community_id = isset($gpc['community_id']) && intval($gpc['community_id']) > 0 ? $gpc['community_id'] : 0;
-
-
- $data = array();
- $data['member_id'] = $member_id;
- $data['community_name'] = $community_name;
- $data['head_name'] = $head_name;
- $data['head_mobile'] = $mobile;
- $data['province_id'] = $province_id;
- $data['city_id'] = $city_id;
- $data['country_id'] = $country_id;
- $data['area_id'] = $area_id;
- $data['address'] = $addr_detail;
- $data['lon'] = $lon_lat_arr[0];
- $data['lat'] = $lon_lat_arr[1];
- $data['state'] = 0;
- $data['apptime'] = time();
- $data['addtime'] = time();
- $data['wechat'] = $wechat;
-
- $head_info = D('Home/Front')->get_member_community_info($member_id);
-
- $parent_head_id = 0;
-
- if( $member_info['share_id'] > 0 )
- {
- $parent_head_info = D('Home/Front')->get_member_community_info($member_info['share_id']);
- if( !empty($parent_head_info) )
- {
- $parent_head_id = $parent_head_info['id'];
- }
- }
-
- $data['agent_id'] = $parent_head_id;
-
- if( $community_id > 0 )
- {
- $data['agent_id'] = $community_id;
- }
-
-
-
- if( empty($head_info) )
- {
- $head_id = M('lionfish_community_head')->add($data);
-
- }else{
- unset($data['uniacid']);
- unset($data['addtime']);
-
- M('lionfish_community_head')->where( array('id' => $head_info['id']) )->save($data);
- $head_id = $head_info['id'];
- }
-
-
- $head_commiss_info = M('lionfish_community_head_commiss')->where( array('member_id' =>$member_id,'head_id' => $head_id ) )->find();
-
- if( empty($head_commiss_info) )
- {
- $datas = array();
- $datas['member_id'] = $member_id;
-
- $datas['head_id'] = $head_id;
- $datas['money'] = 0;
- $datas['dongmoney'] = 0;
- $datas['getmoney'] = 0;
- $datas['bankname'] = '';
- $datas['bankaccount'] = '';
- $datas['bankusername'] = '';
- $datas['share_avatar'] = '';
- $datas['share_wxcode'] = '';
- $datas['share_title'] = '';
- $datas['share_desc'] = '';
-
- M('lionfish_community_head_commiss')->add( $datas );
-
- }
-
- echo json_encode( array('code' => 0) );
- die();
- }
- /**
- * 获取城市列表
- */
- public function get_city_list()
- {
- $gpc = I('request.');
-
- $token = $gpc['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
-
- $member_id = $weprogram_token['member_id'];
-
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
-
- if( empty($member_info) )
- {
- //echo json_encode( array('code' => 1) );
- //die();
- }
-
- $city_ids_Arr = M('lionfish_community_head')->field('city_id')->order('city_id asc')->select();
-
-
-
-
- $city_ids = array();
- foreach ($city_ids_Arr as $k => $val) {
- $city_ids[] = $val['city_id'];
- }
- $city_ids_str = implode(',', $city_ids);
- $city_list = M('lionfish_comshop_area')->where( array('id' => array('in', $city_ids_str) ) )->select();
-
-
- // {
- // "districtCode": "152900",
- // "districtLevel": "CITY",
- // "parentDistrictCode": "150000",
- // "districtName": "阿拉善盟",
- // "firstLetter": "A",
- // "serviceStatus": "N"
- // }
-
- $city_arr = array();
- foreach ($city_list as $key => $value) {
- $city_arr[$key]["city_id"] = $value["id"];
- $city_arr[$key]["districtCode"] = $value["code"];
- $city_arr[$key]["districtLevel"] = "CITY";
- $city_arr[$key]["parentDistrictCode"] = $value["code"];
- $city_arr[$key]["districtName"] = $value["name"];
- $city_arr[$key]["firstLetter"] = $this->getFirstCharter($value["name"]);
- $city_arr[$key]["serviceStatus"] = "N";
- }
- echo json_encode( array('code' => 0, 'data' => $city_arr) );
- die();
- }
- /**
- * 获取首字母
- * @param [type] $str [description]
- * @return [type] [description]
- */
- function getFirstCharter($str)
- {
- if (empty($str)) {
- return '';
- }
- $fchar = ord($str{0});
- if ($fchar >= ord('A') && $fchar <= ord('z'))
- return strtoupper($str{0});
- $s1 = iconv('UTF-8', 'gb2312', $str);
- $s2 = iconv('gb2312', 'UTF-8', $s1);
- $s = $s2 == $str ? $s1 : $str;
- $asc = ord($s{0}) * 256 + ord($s{1}) - 65536;
-
- if ($asc >= -20319 && $asc <= -20284)
- return 'A';
-
- if ($asc >= -20283 && $asc <= -19776)
- return 'B';
-
- if ($asc >= -19775 && $asc <= -19219)
- return 'C';
-
- if ($asc >= -19218 && $asc <= -18711)
- return 'D';
-
- if ($asc >= -18710 && $asc <= -18527)
- return 'E';
-
- if ($asc >= -18526 && $asc <= -18240)
- return 'F';
-
- if ($asc >= -18239 && $asc <= -17923)
- return 'G';
-
- if ($asc >= -17922 && $asc <= -17418)
- return 'H';
-
- if ($asc >= -17417 && $asc <= -16475)
- return 'J';
-
- if ($asc >= -16474 && $asc <= -16213)
- return 'K';
-
- if ($asc >= -16212 && $asc <= -15641)
- return 'L';
-
- if ($asc >= -15640 && $asc <= -15166)
- return 'M';
-
- if ($asc >= -15165 && $asc <= -14923)
- return 'N';
-
- if ($asc >= -14922 && $asc <= -14915)
- return 'O';
-
- if ($asc >= -14914 && $asc <= -14631)
- return 'P';
-
- if ($asc >= -14630 && $asc <= -14150)
- return 'Q';
-
- if ($asc >= -14149 && $asc <= -14091)
- return 'R';
-
- if ($asc >= -14090 && $asc <= -13319)
- return 'S';
-
- if ($asc >= -13318 && $asc <= -12839)
- return 'T';
-
- if ($asc >= -12838 && $asc <= -12557)
- return 'W';
-
- if ($asc >= -12556 && $asc <= -11848)
- return 'X';
-
- if ($asc >= -11847 && $asc <= -11056)
- return 'Y';
-
- if ($asc >= -11055 && $asc <= -10247)
- return 'Z';
-
- return null;
-
- }
- /**
- * 获取申请页面
- */
- public function get_apply_page()
- {
-
- $info = M('lionfish_comshop_config')->field( 'value' )->where( array('name' => 'communityhead_apply_page') )->find();
-
- if(!empty($info['value'])){
- echo json_encode( array('code' => 0, 'data' => htmlspecialchars_decode(htmlspecialchars_decode($info['value']))) );
- die();
- }else{
- echo json_encode( array('code' => 1 ));
- die();
- }
- }
-
-
- public function check_head_subscriptapply()
- {
- $_GPC = I('request.');
- $token = $_GPC['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- $member_id = $weprogram_token['member_id'];
-
- $is_need_subscript = 0;
- $need_subscript_template = array();
-
- //'pay_order','send_order','hexiao_success','apply_community','open_tuan','take_tuan','pin_tuansuccess','apply_tixian'
-
-
- $apply_community_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id, 'type' => 'apply_community' ) )->find();
-
- if( empty($apply_community_info) )
- {
- $weprogram_subtemplate_apply_community = D('Home/Front')->get_config_by_name('weprogram_subtemplate_apply_community');
-
- if( !empty($weprogram_subtemplate_apply_community) )
- {
- $need_subscript_template['apply_community'] = $weprogram_subtemplate_apply_community;
- }
- }
-
- $apply_tixian_info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id, 'type' => 'apply_tixian' ) )->find();
-
- if( empty($apply_tixian_info) )
- {
- $weprogram_subtemplate_apply_tixian = D('Home/Front')->get_config_by_name('weprogram_subtemplate_apply_tixian');
-
- if( !empty($weprogram_subtemplate_apply_tixian) )
- {
- $need_subscript_template['apply_tixian'] = $weprogram_subtemplate_apply_tixian;
- }
- }
-
- if( !empty($need_subscript_template) )
- {
- $is_need_subscript = 1;
- }
-
-
-
- echo json_encode( array('code' => 0, 'is_need_subscript' => $is_need_subscript,'need_subscript_template' => $need_subscript_template ) );
- die();
-
- }
-
-
- //----------begin ----------------
-
- /**
- * 团长设置页面团长资料
- */
- public function get_head_info()
- {
- $_GPC = I('request.');
-
- $token = $_GPC['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
-
- $member_id = $weprogram_token['member_id'];
-
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
-
- $id = $_GPC['id'];
- if($id > 0)
- {
-
- $item = M('lionfish_community_head')->where( array('id' => $id ) )->find();
-
- $item['province_name'] = D('Seller/Area')->get_area_info($item['province_id']);
- $item['city_name'] = D('Seller/Area')->get_area_info($item['city_id']);
- $item['area_name'] = D('Seller/Area')->get_area_info($item['area_id']);
- $item['country_name'] = D('Seller/Area')->get_area_info($item['country_id']);
-
- if( $item['member_id'] > 0)
- {
- $head_commiss_info = M('lionfish_community_head_commiss')->where( array('head_id' => $item['id'],'member_id' =>$item['member_id'] ) )->find();
-
- if( !empty($head_commiss_info) )
- {
- $item['bankname'] = $head_commiss_info['bankname'];
- $item['bankaccount'] = $head_commiss_info['bankaccount'];
- $item['bankusername'] = $head_commiss_info['bankusername'];
- $item['share_wxcode'] = tomedia($head_commiss_info['share_wxcode']);
- }
- }
- $item['member_info'] = $member_info;
- $item['rest'] = D('Seller/Communityhead')->is_community_rest($id);
- $item['re_id'] = sprintf("%05d", $item['id']);
-
- $delivery_type_tuanz = D('Home/Front')->get_config_by_name('delivery_type_tuanz');
-
- $close_community_reset_btn = D('Home/Front')->get_config_by_name('close_community_reset_btn');
-
-
- if(empty($delivery_type_tuanz))
- {
- $delivery_type_tuanz = 2;
- }
- $item['delivery_type_tuanz'] = $delivery_type_tuanz;
- $item['close_reset_btn'] = $close_community_reset_btn;
-
- if(!empty($item)){
- echo json_encode( array('code' => 0, 'data' => $item) );
- die();
- }else{
- // 无数据
- echo json_encode( array('code' => 2 ));
- die();
- }
- }
- }
- /**
- * 团长设置休息状态
- */
- public function set_head_rest()
- {
- $_GPC = I('request.');
-
- $token = $_GPC['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
-
- $member_id = $weprogram_token['member_id'];
-
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $head_id = $_GPC['id'];
- $rest = $_GPC['rest'];
- if($head_id > 0){
-
- $result = M('lionfish_community_head')->where( array('id' => $head_id) )->save( array('rest' => $rest) );
- if(!empty($result)){
- echo json_encode( array('code' => 0, 'data' => '修改成功'));
- die();
- }else{
- echo json_encode( array('code' => 2, 'data' => '修改失败'));
- die();
- }
- }else{
- // id不存在
- echo json_encode( array('code' => 2, 'data' => 'id不存在' ));
- die();
- }
- }
- /**
- * 团长信息修改
- */
- public function modify_head_info()
- {
- $_GPC = I('request.');
-
- $token = $_GPC['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- $member_id = $weprogram_token['member_id'];
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $head_id = isset($_GPC['id']) ? $_GPC['id'] : 0;
- $data = array();
- $data['head_name'] = $_GPC['head_name'];
- $data['head_mobile'] = $_GPC['head_mobile'];
- $data['is_modify_shipping_method'] = $_GPC['is_modify_shipping_method'];//是否自定义配送开关。0跟随系统,1开启,2关闭
- $data['is_modify_shipping_fare'] = $_GPC['is_modify_shipping_fare'];//是否自定义配送费,0跟随系统,1自定义
- $data['shipping_fare'] = $_GPC['shipping_fare'];// 自定义配送费
-
-
- if($head_id > 0){
-
-
-
- $rs = M('lionfish_community_head')->where( array('id' => $head_id, 'member_id' => $member_id) )->save( $data );
-
-
- $commiss_data = array();
- $commiss_data['share_wxcode'] = $_GPC['share_wxcode'];
- if($commiss_data['share_wxcode']){
-
- $rs = M('lionfish_community_head_commiss')->where( array('head_id' => $head_id, 'member_id' => $member_id) )->save( $commiss_data );
- }
-
- if(!empty($rs)){
- echo json_encode( array('code' => 0, 'data' => '修改成功'));
- die();
- }else{
- echo json_encode( array('code' => 2, 'data' => '修改失败'));
- die();
- }
- }else{
- // id不存在
- echo json_encode( array('code' => 2, 'data' => 'id不存在' ));
- die();
- }
- }
- /**
- * 团长信息修改
- */
- public function modify_head_commiss()
- {
- $_GPC = I('request.');
-
- $token = $_GPC['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- $member_id = $weprogram_token['member_id'];
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $head_id = isset($_GPC['id']) ? $_GPC['id'] : 0;
- $data = array();
- $data['bankname'] = $_GPC['bankname'];
- $data['bankaccount'] = $_GPC['bankaccount'];
- $data['bankusername'] = $_GPC['bankusername'];
- // $data['address'] = $_GPC['address'];
- // $data['lon'] = $_GPC['lon'];
- // $data['lat'] = $_GPC['lat'];
- // $data['state'] = $_GPC['state'];
- if($head_id > 0){
-
- $rs = M('lionfish_community_head_commiss')->where( array('head_id' => $head_id, 'member_id' => $member_id) )->save( $data );
-
- if(!empty($rs)){
- echo json_encode( array('code' => 0, 'data' => '修改成功'));
- die();
- }else{
- echo json_encode( array('code' => 2, 'data' => '修改失败'));
- die();
- }
- }else{
- // id不存在
- echo json_encode( array('code' => 2, 'data' => 'id不存在' ));
- die();
- }
- }
- public function community_index_shareqrcode()
- {
- $_GPC = I('request.');
-
- $token = $_GPC['token'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
- {
- $member_id = 0;
- }else{
- $member_id = $weprogram_token['member_id'];
- }
-
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
-
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
-
- $community_info = D('Home/Front')->get_member_community_info($member_id);
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 1) );
- die();
- }
- $community_id = $community_info['id'];
- $community_index_shareqrcode_json = D('Home/Front')->get_config_by_name('community_index_shareqrcode_'.$community_id );
- $community_index_shareqrcode_arr = unserialize($community_index_shareqrcode_json);
-
- $load_new = false;
- if( empty($community_index_shareqrcode_arr) )
- {
- $load_new = true;
- }else {
- if( $community_index_shareqrcode_arr['endtime'] < time() )
- {
- $load_new = true;
- }
- }
-
- if( $load_new || true )
- {
- $goods_model = D('Home/Pingoods');
- $qrcode_image = $goods_model->_get_index_wxqrcode($member_id,$community_id,'jpg');
-
- $data = array();
- $data['image_path'] = '/'.$qrcode_image;
- $ed_time = time() + 300;
- $js_arr = array('endtime' => $ed_time,'image_path' => $data['image_path'] );
-
- $cd_key = 'community_index_shareqrcode_'.$community_id;
- D('Seller/Config')->update( array( $cd_key => serialize($js_arr) ) );
- }else{
- $data = array();
- $data['image_path'] ='/'.$community_index_shareqrcode_arr['image_path'];
- }
-
- $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
-
- $data['image_path'] = $shop_domain.$data['image_path'];
- $result = array('code' => 0, 'qrcode' => $data['image_path'] );
- echo json_encode($result);
- die();
-
- }
- /**
- * 团长排行榜
- */
- public function community_ranking_list(){
- $_GPC = I('request.');
- $token = $_GPC['token'];
- $type = $_GPC['type'];
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
- if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
- {
- $member_id = 0;
- }else{
- $member_id = $weprogram_token['member_id'];
- }
- $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
- if( empty($member_info) )
- {
- echo json_encode( array('code' => 1, 'mgs'=> '请登录') );
- die();
- }
- $community_info = D('Home/Front')->get_member_community_info($member_id);
- if( empty($community_info) || $community_info['state'] != 1 )
- {
- echo json_encode( array('code' => 1, 'mgs'=> '您不是团长,无法查看') );
- die();
- }
- $begin_time = 0;
- $end_time = 0;
- if($type == 1){//今日
- $begin_time = strtotime(date('Y-m-d'.'00:00:00',time()));
- $end_time = strtotime(date('Y-m-d'.'00:00:00',time()+3600*24));
- }else if($type == 2){//昨日
- $begin_time = strtotime(date('Y-m-d'.'00:00:00',time()-3600*24));
- $end_time = strtotime(date('Y-m-d'.'00:00:00',time()));
- }else if($type == 3){//上周
- $begin_time = strtotime(date("Y-m-d H:i:s",mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y'))));
- $end_time = strtotime(date("Y-m-d H:i:s",mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y'))));
- }else if($type == 4){//上月
- //上月开始时间
- $begin_time = strtotime(date("Y-m-d H:i:s",mktime(0, 0 , 0,date("m")-1,1,date("Y"))));
- //上月结束时间
- $end_time = strtotime(date("Y-m-d H:i:s",mktime(23,59,59,date("m") ,0,date("Y"))));
- }
- $list = array();
- $sql = " select * from ( "
- . " select co.head_id,count(distinct(co.order_id)) as order_count, "
- . " sum(co.money) as money "
- . " from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co "
- . " left join ".C('DB_PREFIX')."lionfish_comshop_order as o "
- . " on co.order_id = o.order_id "
- . " left join ".C('DB_PREFIX')."lionfish_community_head as h "
- . " on co.head_id = h.id "
- . " where co.addtime >= ".$begin_time." and co.addtime <= ".$end_time
- . " and o.order_status_id not in (3,5,7,12) and co.state != 2 and h.state = 1 and h.enable = 1 "
- . " group by co.head_id) t "
- . " order by money desc "
- . " limit 20 ";
- //echo $sql;
- $list = M()->query($sql);
- foreach($list as $k=>$v){
- $community_head = M('lionfish_community_head')->where( array('id' => $v['head_id']) )->find();
- $list[$k]['community_name'] = $community_head['community_name'];
- $member_info = M('lionfish_comshop_member')->field('avatar')->where( array('member_id' => $community_head['member_id']) )->find();
- $list[$k]['avatar'] = $member_info['avatar'];
- }
- $is_show_community_ranking = D('Home/Front')->get_config_by_name('is_show_community_ranking');
- //是否显示团长排行, 0不显示,1显示
- $is_show_community_ranking = empty($is_show_community_ranking) ? 0 : $is_show_community_ranking;
- echo json_encode(array('code' => 0,'data'=>$list , 'is_show_community_ranking' => $is_show_community_ranking ));
- die();
- }
- //----------end----------------------
- }
|