12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433 |
- <?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 DistributionController extends CommonController {
-
- public function main()
- {
- echo json_encode( array('code' =>0) );
- die();
- }
-
- public function get_instruct()
- {
-
- $communitymember_apply_page = D('Home/Front')->get_config_by_name('communitymember_apply_page');
-
- $communitymember_apply_page = htmlspecialchars_decode($communitymember_apply_page);
-
- echo json_encode( array('code' => 0, 'content' => $communitymember_apply_page) );
- die();
- }
-
- /**
- 提交申请表单
- @param 注意,申请表单的时候,需要判断是否满足其他条件了。如果已经满足了,那么就可以直接申请了
- 提交参数:{token:'xxx', data: [{type:input,name:'姓名',value="123"},{type:radio,name:'姓名',value="123"}] }
-
- **/
- public function sub_distribut_form()
- {
- $_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']) )
- {
- echo json_encode( array('code' => 1,'msg' =>'请先登录') );
- die();
- }
-
- $member_id = $weprogram_token['member_id'];
-
-
- $data = json_decode( htmlspecialchars_decode( $_GPC['data']) ,true);
-
- $commiss_formcontent = serialize( $data );
-
- //M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->save( array('is_writecommiss_form' => 1,'commiss_formcontent' => $commiss_formcontent ) );
-
- //判断是否需要审核
- $commiss_become_condition = D('Home/Front')->get_config_by_name('commiss_become_condition');
-
- if( empty($commiss_become_condition) || $commiss_become_condition == 0 )
- {
- //不需要审核,那么直接升级为分销了
- //M('lionfish_comshop_member')->where( array('share_id' => $member_id, 'agentid' => 0 ) )->save( array('agentid' => $member_id ) );
-
- M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->save( array('is_writecommiss_form' => 1,'commiss_formcontent' => $commiss_formcontent ) );
-
-
- D('Home/Commission')->become_commiss_member($member_id);
-
- echo json_encode( array('code' =>0, 'msg' =>'提交成功') );
- die();
- }else{
- //需要审核,成为分销,待审核状态
- M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->save( array('comsiss_flag' => 1,'is_writecommiss_form' => 1,'commiss_formcontent' => $commiss_formcontent ) );
-
- //将未 挪动上级的会员归到当前会员的下级去
- M('lionfish_comshop_member')->where( array('share_id' => $member_id ) )->save( array('agentid' => $member_id ) );
-
- echo json_encode( array('code' =>0, 'msg' =>'申请成功,平台将尽快审核') );
- die();
- }
-
- echo json_encode( array('code' =>0, 'msg' =>'提交成功') );
- die();
- }
-
- /**
- 会员申请分销按钮确认
- **/
- public function sub_commission_info()
- {
- $_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']) )
- {
- echo json_encode( array('code' => 1,'msg' =>'请先登录') );
- die();
- }
-
- $member_id = $weprogram_token['member_id'];
-
-
- //开始判断
- $share_member_count = M('lionfish_comshop_member')->where( "share_id={$member_id} and (agentid =0 or agentid={$member_id})" )->count();
-
- //1、是否需要分享
- $commiss_sharemember_need = D('Home/Front')->get_config_by_name('commiss_sharemember_need');
-
- if( !empty($commiss_sharemember_need) && $commiss_sharemember_need == 1 )
- {
- // 2、分享多少人才能成为分销
- $commiss_share_member_update = D('Home/Front')->get_config_by_name('commiss_share_member_update');
-
- if( !empty($commiss_share_member_update) && $commiss_share_member_update > 0 )
- {
- if( $share_member_count < $commiss_share_member_update )
- {
- $del = $commiss_share_member_update - $share_member_count;
- echo json_encode( array('code' =>1 , 'msg' => '分享人数还差'.$del.'人','del_count' => $del ) );
- die();
- }
- }
- }
-
- $member_info = M('lionfish_comshop_member')->field('is_writecommiss_form,comsiss_flag,comsiss_state')->where( array('member_id' =>$member_id ) )->find();
-
- // 3、commiss_biaodan_need 是否需要表单
-
- $commiss_biaodan_need = D('Home/Front')->get_config_by_name('commiss_biaodan_need');
-
- if( !empty($commiss_biaodan_need) && $commiss_biaodan_need == 1 )
- {
- if( $member_info['is_writecommiss_form'] != 1)
- {
- echo json_encode( array('code' =>1 , 'msg' => '您未填写表单!' ) );
- die();
- }
- }
-
-
- //4判断是否需要审核
- $commiss_become_condition = D('Home/Front')->get_config_by_name('commiss_become_condition');
-
- if( empty($commiss_become_condition) || $commiss_become_condition == 0 )
- {
- //不需要审核,那么直接升级为分销了
- D('Home/Commission')->become_commiss_member($member_id);
- echo json_encode( array('code' =>0, 'msg' =>'申请成功!') );
- die();
- }else{
- //需要审核,成为分销,待审核状态
- D('Home/Commission')->become_wait_commiss_member($member_id);
- echo json_encode( array('code' =>0, 'msg' =>'申请成功,平台将尽快审核') );
- die();
- }
-
-
- }
-
-
-
- public function get_parent_agent_info_bymemberid()
- {
- $_GPC = I('request.');
-
- $member_id = $_GPC['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, 'msg' => '会员不存在') );
- die();
- }
-
-
-
- $data_result = array('parent_username' => '','parent_telephone' => '','share_username' => '','share_telephone' => '' );
-
- if( $member_info['agentid'] > 0 )
- {
- $parent_mb = M('lionfish_comshop_member')->where( array('member_id' => $member_info['agentid'] ) )->find();
-
- $data_result['parent_username'] = $parent_mb['username'];//上级姓名
- $data_result['parent_telephone'] = $parent_mb['telephone'];//上级电话
- }
- if( $member_info['share_id'] > 0 )
- {
-
- $share_mb = M('lionfish_comshop_member')->where( array('member_id' => $member_info['share_id'] ) )->find();
-
- $data_result['share_username'] = $share_mb['username'];//上级姓名
- $data_result['share_telephone'] = $share_mb['telephone'];//上级电话
- }
-
- echo json_encode( array('code' => 0, 'data' => $data_result) );
- die();
-
- }
-
-
-
-
- public function get_parent_agent_info()
- {
- $_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']) )
- {
- echo json_encode( array('code' => 1,'msg' =>'请先登录') );
- die();
- }
-
- $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, 'msg' => '会员不存在') );
- die();
- }
-
-
- $data_result = array('parent_username' => '','parent_telephone' => '','share_username' => '','share_telephone' => '' );
-
- if( $member_info['agentid'] > 0 )
- {
- $parent_mb = M('lionfish_comshop_member')->where( array('member_id' => $member_info['agentid'] ) )->find();
-
- $data_result['parent_username'] = $parent_mb['username'];//上级姓名
- $data_result['parent_telephone'] = $parent_mb['telephone'];//上级电话
- }
- if( $member_info['share_id'] > 0 )
- {
- $share_mb = M('lionfish_comshop_member')->where( array('member_id' => $member_info['share_id'] ) )->find();
-
- $data_result['share_username'] = $share_mb['username'];//上级姓名
- $data_result['share_telephone'] = $share_mb['telephone'];//上级电话
- }
-
- echo json_encode( array('code' => 0, 'data' => $data_result) );
- die();
-
- }
-
-
- /**
- 会员分销提现 提交接口
- **/
- public function tixian_sub()
- {
- $_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']) )
- {
- echo json_encode( array('code' => 1,'msg' =>'请先登录') );
- die();
- }
-
- $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, 'msg' => '会员不存在') );
- die();
- }
-
-
- if($member_info['comsiss_flag'] != 1 )
- {
- echo json_encode( array('code' => 1, 'msg' => '您还不是分销') );
- die();
- }
- if($member_info['comsiss_state'] != 1 )
- {
- echo json_encode( array('code' => 1, 'msg' => '等待管理员审核') );
- die();
- }
-
- $result = array('code' => 1,'msg' => '提现失败');
- $member_commiss = M('lionfish_comshop_member_commiss')->where( array('member_id' => $member_id ) )->find();
-
- $datas = array();
-
-
- $datas['money'] = $_GPC['money'];
- $money = $datas['money'];
-
-
- $type = $_GPC['type'];// 1余额 2 微信 3 支付宝 4 银行
-
- $bankname = isset($_GPC['bankname']) ? $_GPC['bankname'] : ''; //银行名称
-
- $bankaccount = isset($_GPC['bankaccount']) ? $_GPC['bankaccount'] : '';//卡号,支付宝账号 使用该字段
-
- $bankusername = isset($_GPC['bankusername']) ? $_GPC['bankusername'] : '';//持卡人姓名,微信名称,支付宝名称, 使用该字段
-
- $commiss_money_limit = D('Home/Front')->get_config_by_name('commiss_min_tixian_money');
-
- if(!empty($commiss_money_limit) && $commiss_money_limit >0)
- {
- if($member_commiss['money'] < $commiss_money_limit)
- {
- $result['msg'] = '佣金满'.$commiss_money_limit.'才能提现';
- echo json_encode($result);
- die();
- }
- }
- if($money > 0 && $money <= $member_commiss['money'])
- {
- //判断提现手续费,+ 判断提现金额免审直接到账
- $service_charge = D('Home/Front')->get_config_by_name('commiss_tixian_bili');
-
- $data = array();
- $data['member_id'] = $member_id;
- $data['uniacid'] = 0;
- $data['money'] = $money;
- $data['service_charge'] = $service_charge;
- $data['service_charge_money'] = round( ($money * $service_charge) /100 ,2);
- $data['state'] = 0;
- $data['shentime'] = 0;
-
- $data['type'] = $type;
- $data['bankname'] = $bankname;
- $data['bankaccount'] = $bankaccount;
- $data['bankusername'] = $bankusername;
- $data['addtime'] = time();
- M('lionfish_comshop_member_tixian_order')->add( $data );
-
- $com_arr = array();
- $com_arr['money'] = $member_commiss['money'] - $money;
- $com_arr['dongmoney'] = $member_commiss['dongmoney'] + $money;
-
- M('lionfish_comshop_member_commiss')->where( array('member_id' => $member_id ) )->setInc('money',-$money );
- M('lionfish_comshop_member_commiss')->where( array('member_id' => $member_id ) )->setInc('dongmoney',$money );
-
-
- $result['code'] = 0;
- //commiss_tixian_reviewed 0 , 1
- $commiss_tixian_reviewed = D('Home/Front')->get_config_by_name('commiss_tixian_reviewed');
-
- if(empty($commiss_tixian_reviewed) || $commiss_tixian_reviewed == 0)
- {
- //手动
- } else if( !empty($commiss_tixian_reviewed) && $commiss_tixian_reviewed == 1 ){
- //自动
- }
- }
- echo json_encode($result);
- die();
- }
-
- /**
- 提现记录
- **/
- public function tixian_record()
- {
- $_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']) )
- {
- echo json_encode( array('code' => 1,'msg' =>'请先登录') );
- die();
- }
-
- $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, 'msg' => '会员不存在') );
- die();
- }
-
-
- if($member_info['comsiss_flag'] != 1 )
- {
- echo json_encode( array('code' => 1, 'msg' => '您还不是分销') );
- die();
- }
- if($member_info['comsiss_state'] != 1 )
- {
- echo json_encode( array('code' => 1, 'msg' => '等待管理员审核') );
- die();
- }
- $per_page = 10;
- $page = isset($_GPC['page']) ? $_GPC['page']:1;
-
- $offset = ($page - 1) * $per_page;
-
- $list = array();
- $list = M('lionfish_comshop_member_tixian_order')->where( array('member_id' => $member_id ) )->order( 'addtime desc' )->limit($offset,$per_page )->select();
- foreach($list as $key => $val)
- {
- $val['addtime'] = date('Y-m-d H:i', $val['addtime']);
- $list[$key] = $val;
- }
-
- if( !empty($list) )
- {
- echo json_encode( array('code' =>0, 'data'=>$list) );
- die();
- }else{
- echo json_encode( array('code' => 1) );
- die();
- }
- }
-
- private function get_member_next_child($member_id)
- {
-
- $level = D('Home/Front')->get_config_by_name('commiss_level');// isset($_GPC['level']) ? $_GPC['level']: 1;
-
-
- $level_1_ids = array();
- $level_2_ids = array();
- $level_3_ids = array();
-
- $member_id_arr = array($member_id);
-
- $where = "";
-
- $need_count = 0;
-
- //commiss_level
- if( $level == 1 )
- {
- $list = array();
-
-
- $need_count = M('lionfish_comshop_member')->where( "agentid in (".implode(',', $member_id_arr).")" )->count();
-
-
- }else if( $level == 2 )
- {
- $list = array();
-
- $list1 = M('lionfish_comshop_member')->field('member_id')->where( "agentid in (".implode(',', $member_id_arr).")" )->order('member_id desc')->select();
-
- if( !empty($list1) )
- {
- foreach( $list1 as $vv )
- {
- $level_1_ids[] = $vv['member_id'];
- }
-
- $level_sql2 =" select member_id from ".C('DB_PREFIX').
- "lionfish_comshop_member where
- agentid in (select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
- where agentid ={$member_id} order by member_id desc ) order by member_id desc ";
-
- $list2 = M()->query($level_sql2);
-
- if( !empty($list2) )
- {
- foreach( $list2 as $vv )
- {
- $level_2_ids[] = $vv['member_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;
- }
- }
- if(!empty($need_ids))
- {
- $sql =" select count(member_id) as count from ".C('DB_PREFIX').
- "lionfish_comshop_member where 1 {$where} and
- member_id in (".implode(',', $need_ids ).") ";
-
- $need_count_arr = M()->query($sql);
-
- $need_count = $need_count_arr[0]['count'];
-
-
- }
-
-
-
- }
-
- }else if( $level == 3 ){
- $sql = "select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
- where agentid in (".implode(',', $member_id_arr).") order by member_id desc ";
-
- $list1 = M()->query($sql);
-
- if( !empty($list1) )
- {
- foreach( $list1 as $vv )
- {
- $level_1_ids[] = $vv['member_id'];
- }
- $need_ids = empty($level_1_ids) ? array() : $level_1_ids;
-
- $level_sql2 =" select member_id from ".C('DB_PREFIX').
- "lionfish_comshop_member where
- agentid in (select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
- where agentid ={$member_id} order by member_id desc ) order by member_id desc ";
-
- $list2 = M()->query($level_sql2);
-
- if( !empty($list2) )
- {
- foreach( $list2 as $vv )
- {
- $level_2_ids[] = $vv['member_id'];
- }
-
- if(!empty($level_2_ids))
- {
- foreach($level_2_ids as $vv)
- {
- $need_ids[] = $vv;
- }
- }
- }
-
-
- $level_sql3 =" select * from ".C('DB_PREFIX').
- "lionfish_comshop_member where
- agentid in (".implode(',', $need_ids).") order by member_id desc ";
-
- $list3 = M()->query($level_sql3);
-
- if( !empty($list3) )
- {
- foreach( $list3 as $vv )
- {
- $level_3_ids[] = $vv['member_id'];
- }
-
- if(!empty($level_3_ids))
- {
- foreach($level_3_ids as $vv)
- {
- $need_ids[] = $vv;
- }
- }
- }
-
- $level_sql3 =" select count(member_id) as count from ".C('DB_PREFIX').
- "lionfish_comshop_member where 1 {$where} and member_id in (".implode(',',$need_ids).") ";
-
- $need_count_arr = M()->query($level_sql3);
-
- $need_count = $need_count_arr[0]['count'];
- }
-
- }
-
-
- return $need_count;
-
- }
-
-
- /**
- 获取会员粉丝列表接口
- **/
- public function get_member_fanslist()
- {
-
- $_GPC = I('request.');
-
- $token = $_GPC['token'];
-
- $keyword = $_GPC['keyword'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
- {
- echo json_encode( array('code' => 1,'msg' =>'请先登录') );
- die();
- }
-
- $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, 'msg' => '会员不存在') );
- die();
- }
-
-
- //...
-
- $page = isset($_GPC['page']) ? $_GPC['page']:'1';
-
- $size = isset($_GPC['size']) ? $_GPC['size']:'20';
- $offset = ($page - 1)* $size;
-
- //begin select keyword
-
- $level = D('Home/Front')->get_config_by_name('commiss_level');// isset($_GPC['level']) ? $_GPC['level']: 1;
-
-
- $level_1_ids = array();
- $level_2_ids = array();
- $level_3_ids = array();
-
- $member_id_arr = array($member_id);
-
- $where = "";
-
- if( !empty($keyword) )
- {
- $where .= " and ( username like '%{$keyword}%' or telephone like '%{$keyword}%' ) ";
- }
-
-
-
- //commiss_level ( "share_id={$member_id} and (agentid =0 or agentid={$member_id} )" )
-
- $list = array();
-
- $sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_member
- where 1 {$where} and (share_id = {$member_id} and (agentid =0 or agentid={$member_id} ) ) order by member_id desc limit {$offset},{$size}";
-
- $list = M()->query($sql);
-
- foreach( $list as $vv )
- {
- $level_1_ids[$vv['id']] = $vv['id'];
- }
-
-
-
- $level_list = array();
- $need_list = array();
-
-
- if( !empty($list) )
- {
- foreach($list as $key => $val)
- {
-
- $val['child_level'] = 1;
-
- $val['create_time'] = date('Y-m-d H:i:s', $val['create_time']);
- $need_list[$key] = $val;
- }
- }
-
- $bg_time = strtotime( date('Y-m-d').' 00:00:00');
- $yes_time = $bg_time - 86400;
-
-
- 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_child_headlist()
- {
- $_GPC = I('request.');
-
- $token = $_GPC['token'];
-
- $keyword = $_GPC['keyword'];
-
- $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
-
- if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
- {
- echo json_encode( array('code' => 1,'msg' =>'请先登录') );
- die();
- }
-
- $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, 'msg' => '会员不存在') );
- die();
- }
-
- if($member_info['comsiss_flag'] != 1 )
- {
- echo json_encode( array('code' => 1, 'msg' => '您还不是分销') );
- die();
- }
- if($member_info['comsiss_state'] != 1 )
- {
- echo json_encode( array('code' => 1, 'msg' => '等待管理员审核') );
- die();
- }
-
- //...
-
- $page = isset($_GPC['page']) ? $_GPC['page']:'1';
-
- $size = isset($_GPC['size']) ? $_GPC['size']:'20';
- $offset = ($page - 1)* $size;
-
- $level = D('Home/Front')->get_config_by_name('commiss_level');
-
- $level_1_ids = array();
- $level_2_ids = array();
- $level_3_ids = array();
-
- $member_id_arr = array($member_id);
-
- $where = "";
-
- if( !empty($keyword) )
- {
- $where .= " and ( username like '%{$keyword}%' or telephone like '%{$keyword}%' ) ";
- }
-
- //commiss_level
- if( $level == 1 )
- {
- $list = array();
-
- $sql = "select * from ".C('DB_PREFIX')."lionfish_comshop_member
- where 1 {$where} and agentid in (".implode(',', $member_id_arr).") order by member_id desc limit {$offset},{$size}";
-
- $list = M()->query($sql);
-
- foreach( $list as $vv )
- {
- $level_1_ids[$vv['id']] = $vv['id'];
- }
-
- }else if( $level == 2 )
- {
- $list = array();
-
- $sql = "select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
- where agentid in (".implode(',', $member_id_arr).") order by member_id desc ";
-
- $list1 = M()->query($sql);
-
-
- if( !empty($list1) )
- {
- foreach( $list1 as $vv )
- {
- $level_1_ids[$vv['member_id']] = $vv['member_id'];
- }
-
- $level_sql2 =" select member_id from ".C('DB_PREFIX').
- "lionfish_comshop_member where
- agentid in (select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
- where agentid = {$member_id} order by member_id desc ) order by member_id desc ";
-
- $list2 = M()->query($level_sql2);
-
-
-
- if( !empty($list2) || !empty($list1) )
- {
- foreach( $list2 as $vv )
- {
- $level_2_ids[$vv['member_id']] = $vv['member_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;
- }
- }
-
- if(!empty($need_ids))
- {
- $sql =" select * from ".C('DB_PREFIX').
- "lionfish_comshop_member where 1 {$where} and
- member_id in (".implode(',', $need_ids ).") order by member_id desc limit {$offset},{$size}";
-
- $list = M()->query($sql);
- }
- }
-
-
- }else if( $level == 3 ){
- $sql = "select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
- where agentid in (".implode(',', $member_id_arr).") order by member_id desc ";
-
- $list1 = M()->query($sql);
-
- if( !empty($list1) )
- {
- foreach( $list1 as $vv )
- {
- $level_1_ids[$vv['member_id']] = $vv['member_id'];
- }
- $need_ids = empty($level_1_ids) ? array() : $level_1_ids;
-
- $level_sql2 =" select * from ".C('DB_PREFIX').
- "lionfish_comshop_member where
- agentid in (select member_id from ".C('DB_PREFIX')."lionfish_comshop_member
- where agentid ={$member_id} order by member_id desc ) order by member_id desc ";
-
- $list2 = M()->query($level_sql2);
-
- if( !empty($list2) )
- {
- foreach( $list2 as $vv )
- {
- $level_2_ids[$vv['member_id']] = $vv['member_id'];
- }
-
- if(!empty($level_2_ids))
- {
- foreach($level_2_ids as $vv)
- {
- $need_ids[] = $vv;
- }
- }
- }
-
-
- $level_sql3 =" select member_id from ".C('DB_PREFIX').
- "lionfish_comshop_member where
- agentid in (".implode(',', $need_ids).") order by member_id desc ";
-
- $list3 = M()->query($level_sql3);
-
- if( !empty($list3) )
- {
- foreach( $list3 as $vv )
- {
- $level_3_ids[$vv['member_id']] = $vv['member_id'];
- }
-
- if(!empty($level_3_ids))
- {
- foreach($level_3_ids as $vv)
- {
- $need_ids[] = $vv;
- }
- }
- }
-
- $level_sql3 =" select * from ".C('DB_PREFIX').
- "lionfish_comshop_member where 1 {$where} and member_id in (".implode(',',$need_ids).") order by member_id desc limit {$offset},{$size}";
-
- $list = M()->query($level_sql3);
-
- }
-
- }
-
- $level_list = array();
- $need_list = array();
-
- if( !empty($list) )
- {
- foreach($list as $key => $val)
- {
- //member_id
- $val['child_level'] = 1;
-
- if( isset($level_2_ids[$val['member_id']]) )
- {
- $val['child_level'] = 2;
- }
- else if( isset($level_3_ids[$val['member_id']]) )
- {
- $val['child_level'] = 3;
- }
-
-
- $val['create_time'] = date('Y-m-d H:i:s', $val['create_time']);
- $need_list[$key] = $val;
- }
- }
-
- $bg_time = strtotime( date('Y-m-d').' 00:00:00');
- $yes_time = $bg_time - 86400;
-
- $today_member_count = M('lionfish_comshop_member')->where( "agentid={$member_id} and create_time>={$bg_time}" )->count();
-
- $yes_member_count = M('lionfish_comshop_member')->where( "agentid={$member_id} and create_time>={$yes_time} and create_time< {$bg_time}" )->count();
-
- if( !empty($need_list) )
- {
- echo json_encode( array('code' => 0, 'data' => $need_list , 'today_member_count'=>$today_member_count,'yes_member_count'=>$yes_member_count) );
- die();
- }else {
- echo json_encode( array('code' => 1, 'today_member_count'=>$today_member_count,'yes_member_count'=>$yes_member_count) );
- die();
- }
-
- }
-
- /**
- 获取会员分销基础数据
- **/
- public function get_commission_info()
- {
- $_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']) )
- {
- echo json_encode( array('code' => 1,'msg' =>'请先登录') );
- die();
- }
-
- $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, 'msg' => '会员不存在') );
- die();
- }
-
- if($member_info['comsiss_flag'] != 1 )
- {
- echo json_encode( array('code' => 1, 'msg' => '您还不是分销') );
- die();
- }
- if($member_info['comsiss_state'] != 1 )
- {
- echo json_encode( array('code' => 1, 'msg' => '等待管理员审核') );
- die();
- }
- $parent_info = '';
- //上级信息
- if($member_info['agentid'] > 0 ) {
- $parent_res = D('Home/Commission')->get_parent_info($member_info['agentid']);
- $parent_info['member_id'] = $parent_res['member_id'];
- $parent_info['username'] = $parent_res['username'];
- }
-
- //最小提现金额
- $commiss_min_tixian_money = D('Home/Front')->get_config_by_name('commiss_min_tixian_money');
-
- if( empty($commiss_min_tixian_money) )
- {
- $commiss_min_tixian_money = 0;
- }
-
- $commiss_tixian_bili = D('Home/Front')->get_config_by_name('commiss_tixian_bili');
-
- if( empty($commiss_tixian_bili) )
- {
- $commiss_tixian_bili = 0;
- }
-
- //C('DB_PREFIX')
-
- $member_commiss = M('lionfish_comshop_member_commiss')->where( array('member_id' =>$member_id ) )->find();
- $member_commiss['commiss_min_tixian_money'] = $commiss_min_tixian_money;//最小提现金额, 0标识不限制
-
- $member_commiss['commiss_tixian_bili'] = $commiss_tixian_bili;
-
- $member_commiss['total_commiss_money'] = $member_commiss['money'] + $member_commiss['dongmoney'] + $member_commiss['getmoney'];
-
- //订单数量
- $order_count = M('lionfish_comshop_member_commiss_order')->where( array('member_id' =>$member_id ) )->count();
- //会员数量
-
-
- $member_commiss['order_count'] = $order_count;
- $member_commiss['member_count'] = $this->get_member_next_child($member_id);
-
- $commiss_tixianway_yuer = D('Home/Front')->get_config_by_name('commiss_tixianway_yuer');
-
-
- $commiss_tixianway_weixin = D('Home/Front')->get_config_by_name('commiss_tixianway_weixin');
- $commiss_tixianway_alipay = D('Home/Front')->get_config_by_name('commiss_tixianway_alipay');
- $commiss_tixianway_bank = D('Home/Front')->get_config_by_name('commiss_tixianway_bank');
-
-
- $member_commiss['commiss_tixianway_yuer'] = empty($commiss_tixianway_yuer) ? 1 : ($commiss_tixianway_yuer == 2 ? 1:0);
- $member_commiss['commiss_tixianway_weixin'] = empty($commiss_tixianway_weixin) ? 1 : ($commiss_tixianway_weixin == 2 ? 1:0);
- $member_commiss['commiss_tixianway_alipay'] = empty($commiss_tixianway_alipay) ? 1 : ($commiss_tixianway_alipay == 2 ? 1:0);
- $member_commiss['commiss_tixianway_bank'] = empty($commiss_tixianway_bank) ? 1 : ($commiss_tixianway_bank == 2 ? 1:0);
-
-
- //share_id agentid
- $member_commiss['share_name'] = '';
- if( $member_info['share_id'] > 0 )
- {
- $mbshare_info = M('lionfish_comshop_member')->field('username')->where( array('member_id' => $member_info['share_id']) )->find();
-
- $member_commiss['share_name'] = $mbshare_info['username'];
- }
-
-
- //上一微信真实姓名
- $last_weixin_realname = "";
-
- $last_weixin_info = M('lionfish_comshop_member_tixian_order')->where( "member_id={$member_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_comshop_member_tixian_order')->where( "member_id={$member_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_comshop_member_tixian_order')->where( "member_id={$member_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'];
- }
-
- $member_commiss['last_weixin_realname'] = $last_weixin_realname;
- $member_commiss['last_alipay_name'] = $last_alipay_name;
- $member_commiss['last_alipay_account'] = $last_alipay_account;
-
- $member_commiss['last_bank_bankname'] = $last_bank_bankname;
- $member_commiss['last_bank_account'] = $last_bank_account;
- $member_commiss['last_bank_name'] = $last_bank_name;
-
- $commiss_tixian_publish = D('Home/Front')->get_config_by_name('commiss_tixian_publish');
-
- $member_commiss['commiss_tixian_publish'] = htmlspecialchars_decode( $commiss_tixian_publish );
-
-
- $member_commiss['total_money'] = sprintf('%.2f', $member_commiss['money'] + $member_commiss['dongmoney'] + $member_commiss['getmoney']);
-
- $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;
- }
-
-
- echo json_encode( array('code' =>0,'data' => $member_commiss ,'is_need_subscript' => $is_need_subscript, 'need_subscript_template' => $need_subscript_template, 'parent_info'=>$parent_info ) );
- die();
- }
-
- /**
- 获取分销订单
- **/
- public function listorder_list()
- {
- $_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']) )
- {
- echo json_encode( array('code' => 1,'msg' =>'请先登录') );
- die();
- }
-
- $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, 'msg' => '会员不存在') );
- die();
- }
-
- if($member_info['comsiss_flag'] != 1 )
- {
- echo json_encode( array('code' => 1, 'msg' => '您还不是分销') );
- die();
- }
- if($member_info['comsiss_state'] != 1 )
- {
- echo json_encode( array('code' => 1, 'msg' => '等待管理员审核') );
- die();
- }
-
-
- $per_page = 6;
- $page = isset($_GPC['page']) ? $_GPC['page']:1;
- $offset = ($page - 1) * $per_page;
- $list = array();
- $where = '';
- $state = isset($_GPC['state']) ? $_GPC['state']: -1;
- //state
- if($state >=0)
- {
- $where .= ' and mco.state = '.$state;
- }
- $commiss_level_num = D('Home/Front')->get_config_by_name('commiss_level');
- $where .= ' and mco.level <= '.$commiss_level_num;
-
- $url = D('Home/Front')->get_config_by_name('shop_domain');
- //$this->state = $state;
- $sql = 'select mco.level, mco.money,mco.child_member_id,mco.addtime,mco.state,o.order_id,o.order_num_alias,o.order_status_id,o.order_num_alias,o.total,og.goods_id,og.quantity,og.has_refund_money,og.has_refund_quantity, og.name,og.price,og.goods_images,og.order_goods_id,mco.store_id,m.username as uname from '
- .C('DB_PREFIX')."lionfish_comshop_member_commiss_order as mco , ".C('DB_PREFIX')."lionfish_comshop_order_goods as og,
- ".C('DB_PREFIX')."lionfish_comshop_order as o ,
- ".C('DB_PREFIX')."lionfish_comshop_member as m
- where mco.order_id=og.order_id and mco.order_id = o.order_id and mco.order_goods_id=og.order_goods_id and m.member_id=mco.child_member_id and mco.member_id=".$member_id." {$where} order by mco.id desc limit {$offset},{$per_page}";
-
- $list = M()->query($sql);
-
-
-
- $status_arr = D('Seller/Order')->get_order_status_name();
- //rela_goodsoption_valueid
- foreach($list as $key =>$val)
- {
- $val['total'] = round($val['total'],2);
- $val['money'] = round($val['money'],2);
- $val['price'] = sprintf("%.2f", $val['price']);
- $val['status_name'] = $status_arr[$val['order_status_id']];
- $val['addtime'] = date('Y-m-d', $val['addtime']);
-
- if( !empty($val['goods_images']))
- {
-
- $goods_images = $url. '/'.resize($val['goods_images'],400,400);
- if(is_array($goods_images))
- {
- $val['goods_images'] = $val['goods_images'];
- }else{
- $val['goods_images']= $url.'/'.resize($val['goods_images'],400,400) ;
- }
-
- }else{
- $val['goods_images']= '';
- }
-
-
-
- $order_option_list = M('lionfish_comshop_order_option')->where( array('order_goods_id' => $val['order_goods_id'] ) )->select();
-
- foreach($order_option_list as $option)
- {
- $val['option_str'][] = $option['value'];
- }
- if( !isset($val['option_str']) )
- {
- $val['option_str'] = '';
- }else{
- $val['option_str'] = implode(',', $val['option_str']);
- }
-
- $val['old_commision'] = $val['money'];
- $val['del_commision'] = 0;
-
- $order_goods_refund_list = M('lionfish_comshop_order_goods_refund')->where( "order_goods_id=".$val['order_goods_id'] )->select();
- //level
-
- if( !empty($order_goods_refund_list) )
- {
- $kvbal_total_back_head_orderbuycommiss = 0;//合计退掉佣金
-
- foreach( $order_goods_refund_list as $kvval )
- {
- if($val['level'] == 1)
- $kvbal_total_back_head_orderbuycommiss += $kvval['back_member_commiss_1'];
-
- if($val['level'] == 2)
- $kvbal_total_back_head_orderbuycommiss += $kvval['back_member_commiss_2'];
-
- if($val['level'] == 3)
- $kvbal_total_back_head_orderbuycommiss += $kvval['back_member_commiss_3'];
- }
- $val['del_commision'] = $kvbal_total_back_head_orderbuycommiss;
-
- $val['old_commision'] += $val['del_commision'];
- }
-
-
- $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_haibao()
- {
- $_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']) )
- {
- echo json_encode( array('code' => 1,'msg' =>'请先登录') );
- die();
- }
-
- $goods_model = D('Home/Pingoods');
- $member_id = $weprogram_token['member_id'];
-
- $last_community = M('lionfish_community_history')->field('head_id')->where( array('member_id' => $member_id) )->order('addtime desc')->find();
-
- if( empty($last_community) )
- {
- $last_community = M('lionfish_community_head')->field('id as head_id')->where(" state=1 and enable=1 and rest=0 ")->order('id desc ')->find();
- }
-
- $head_id =0;
-
- if( !empty($last_community) )
- {
- $head_id = $last_community['head_id'];
- }
- //TODO....寻找上一个社区,生成海报。测试png 跟jpg背景的情况,反过来解决 首页 跟商品海报的问题。
-
- $member_info = M('lionfish_comshop_member')->field('commiss_qrcode,avatar,username')->where( array('member_id' => $member_id ) )->find();
-
- $commiss_qrcode = '';
-
- if( empty($member_info['commiss_qrcode']))
- {
- $commiss_qrcode = $goods_model->_get_index_wxqrcode($member_id,$head_id);
-
- $avatar = $goods_model->get_commission_user_avatar($member_info['avatar'], $member_id,5);
-
-
-
- $result = $goods_model->get_commission_index_share_image($head_id,$commiss_qrcode,$avatar, $member_info['username']);
-
- M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->save( array('commiss_qrcode' => $result['full_path']) );
-
- echo json_encode( array('code' => 0, 'commiss_qrcode' => tomedia($result['full_path'] ) ) );
- die();
- }else{
- $commiss_qrcode = $member_info['commiss_qrcode'];
-
- echo json_encode( array('code' => 0, 'commiss_qrcode' => tomedia($commiss_qrcode) ) );
- die();
- }
-
- }
-
-
- }
|