1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983 |
- <?php
- /**
- * lionfish 商城系统
- *
- *
- * @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----------------------
- }
|