CommunityheadController.class.php 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Seller\Controller;
  15. use Seller\Model\CommunityheadModel;
  16. class CommunityheadController extends CommonController {
  17. protected function _initialize(){
  18. parent::_initialize();
  19. $this->breadcrumb1='团长管理';
  20. $this->breadcrumb2='团长列表';
  21. $this->blog_type = array('question' => '常见帮助');
  22. //'pinjie' => '拼团介绍',
  23. }
  24. public function index(){
  25. $params[':uniacid'] = $uniacid;
  26. $condition = ' ';
  27. $pindex = I('get.page',1);
  28. $psize = 20;
  29. $keyword = I('get.keyword','');
  30. $this->keyword = $keyword;
  31. if (!empty($keyword)) {
  32. $condition .= ' and ( m.username like '.'"%' . $keyword . '%"'.' or ch.community_name like '.'"%' . $keyword . '%"'.' or ch.head_name like '.'"%' . $keyword . '%"'.' or ch.head_mobile like '.'"%' . $keyword . '%"'.' or ch.address like '.'"%' . $keyword . '%"'.') ';
  33. }
  34. $time = I('get.time');
  35. $this->time = $time;
  36. if (!empty($time['start']) && !empty($time['end'])) {
  37. $starttime = strtotime($time['start']);
  38. $endtime = strtotime($time['end']);
  39. $condition .= ' AND ch.apptime >= '.$starttime.' AND ch.apptime <= '.$endtime;
  40. }
  41. $comsiss_state = I('get.comsiss_state',-1);
  42. $this->comsiss_state = $comsiss_state;
  43. if ($comsiss_state != '' && $comsiss_state >= 0) {
  44. $condition .= ' and ch.state=' . intval($comsiss_state);
  45. }
  46. $level_id = I('get.level_id','');
  47. if( $level_id != '' )
  48. {
  49. $condition .= ' and ch.level_id=' . intval($level_id);
  50. }
  51. $this->level_id = $level_id;
  52. $group_id = I('get.group_id','');
  53. if( $group_id != '' )
  54. {
  55. $condition .= ' and ch.groupid=' . intval($group_id);
  56. }
  57. $this->group_id = $group_id;
  58. $sql = 'SELECT ch.*,m.we_openid,m.username,m.avatar FROM ' . C('DB_PREFIX') . "lionfish_community_head as ch left join
  59. ".C('DB_PREFIX')."lionfish_comshop_member as m on ch.member_id = m.member_id
  60. WHERE 1 " . $condition . ' order by ch.id desc ';
  61. $export = I('get.export',0);
  62. if (empty($export)) {
  63. $sql .= ' limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  64. }
  65. $list = M()->query($sql);
  66. $sql_count = 'SELECT count(1) as total FROM ' . C('DB_PREFIX') . 'lionfish_community_head as ch
  67. left join '.C('DB_PREFIX').'lionfish_comshop_member as m on ch.member_id = m.member_id
  68. WHERE 1 ' . $condition;
  69. $total_arr = M()->query($sql_count);
  70. $total = $total_arr[0]['total'];
  71. $all_sell_count = M('lionfish_comshop_goods')->where( array('is_all_sale' => 1,'type' => 'normal') )->count();
  72. //---------等级
  73. $community_head_level = M('lionfish_comshop_community_head_level')->order('id asc')->select();
  74. $head_commission_levelname = D('Home/Front')->get_config_by_name('head_commission_levelname');
  75. $default_comunity_money = D('Home/Front')->get_config_by_name('default_comunity_money');
  76. $list_default = array(
  77. array('id' => '0','level'=>0,'levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $default_comunity_money, )
  78. );
  79. if(empty($community_head_level)){
  80. $community_head_level = array();
  81. }
  82. $community_head_level = array_merge($list_default, $community_head_level);
  83. $level_id_to_name = array();
  84. foreach($community_head_level as $kk => $vv)
  85. {
  86. $level_id_to_name[$vv['id']] = $vv['levelname'];
  87. }
  88. //---------等级
  89. $this->level_id_to_name = $level_id_to_name;
  90. $this->community_head_level = $community_head_level;
  91. $group_list = M('lionfish_community_head_group')->order('id asc')->select();
  92. foreach($group_list as $vv)
  93. {
  94. $keys_group[$vv['id']] = $vv['groupname'];
  95. }
  96. $this->group_list = $group_list;
  97. foreach( $list as $key => $val )
  98. {
  99. //commission_info pre_total_money
  100. $commission_info = M('lionfish_community_head_commiss')->where( array('head_id' => $val['id'],'member_id' => $val['member_id'] ) )->find();
  101. //预计佣金 commission_total
  102. //$pre_total_money = M('lionfish_community_head_commiss_order')->where( array('state' => 0, 'head_id' => $val['id'] ) )->sum('money');
  103. $sql = "select sum( co.money ) as money from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co ,
  104. ".C('DB_PREFIX')."lionfish_comshop_order_goods as og
  105. where co.order_goods_id = og.order_goods_id and og.is_refund_state = 0 and co.state = 0 and co.head_id = ".$val['id']." order by co.id desc ";
  106. $pre_total_money_list = M()->query($sql);
  107. $pre_total_money = $pre_total_money_list[0]['money'];
  108. if( empty($pre_total_money) )
  109. {
  110. $pre_total_money = 0;
  111. }
  112. $commission_info['pre_total_money'] = $pre_total_money;
  113. $commission_info['commission_total'] = $commission_info['money']+ $commission_info['dongmoney'] + $commission_info['getmoney'] + $pre_total_money;
  114. $val['groupname'] = $keys_group[ $val['groupid'] ];
  115. $val['pre_total_money'] = $commission_info['pre_total_money'];
  116. $val['commission_total'] = $commission_info['commission_total'];
  117. if( empty($commission_info['money']) )
  118. {
  119. $commission_info['money'] = 0;
  120. }
  121. $val['money'] = $commission_info['money'];
  122. if( empty($commission_info['dongmoney']) )
  123. {
  124. $commission_info['dongmoney'] = 0;
  125. }
  126. $val['dongmoney']= $commission_info['dongmoney'];
  127. if( empty($commission_info['getmoney']) )
  128. {
  129. $commission_info['getmoney'] = 0;
  130. }
  131. $val['getmoney'] = $commission_info['getmoney'];
  132. $val['commission_info'] = $commission_info;
  133. //普通等级
  134. $val['agent_name'] = '';
  135. if( !empty($val['agent_id']) && $val['agent_id'] > 0 )
  136. {
  137. $parent_community_head = M('lionfish_community_head')->field('head_name')->where( array('id' => $val['agent_id'] ) )->find();
  138. $val['agent_name'] = $parent_community_head['head_name'];
  139. }
  140. $member_info = M('lionfish_comshop_member')->field('username,avatar,we_openid')->where( array('member_id' => $val['member_id'] ) )->find();
  141. $val['province_name'] = D('Seller/Area')->get_area_info($val['province_id']);
  142. $val['city_name'] = D('Seller/Area')->get_area_info($val['city_id']);
  143. $val['area_name'] = D('Seller/Area')->get_area_info($val['area_id']);
  144. $val['country_name'] = D('Seller/Area')->get_area_info($val['country_id']);
  145. //团长商品
  146. $head_goods_count_arr = M()->query("select g.id from ".C('DB_PREFIX')."lionfish_community_head_goods as hg ,".C('DB_PREFIX')."lionfish_comshop_good_common as gc ,".C('DB_PREFIX')."lionfish_comshop_goods as g
  147. where hg.goods_id = gc.goods_id and gc.goods_id = g.id and g.type ='normal' and g.is_all_sale=0 and hg.head_id = ". $val['id'] );
  148. $val['head_goods_count'] = count($head_goods_count_arr);
  149. //所有团长可售商品
  150. $val['all_sell_count'] = $all_sell_count;
  151. //总商品数
  152. $val['goods_count'] =$val['head_goods_count'] + $val['all_sell_count'] ;
  153. //团长订单
  154. $val['head_order_count'] = M('lionfish_comshop_order')->where( array('head_id' => $val['id'] ) )->count();
  155. $member_count_arr = M()->query("SELECT count(DISTINCT(member_id) ) as count FROM ".C('DB_PREFIX')."lionfish_community_history WHERE head_id =". $val['id']);
  156. $val['member_count'] = $member_count_arr[0]['count'];
  157. $val['agent_count'] = M('lionfish_community_head')->where( array('agent_id' => $val['id'] ) )->count();
  158. //$val['member_info'] = $member_info;
  159. $list[$key] = $val;
  160. }
  161. if ($export == '1') {
  162. foreach ($list as &$row) {
  163. //$row['commission_total'] = 0;
  164. //$row['getmoney'] = 0;
  165. $row['commission_total'] = $row['commission_total'];
  166. $row['pre_total_money'] = $row['pre_total_money'];
  167. $row['money']=$row['money'];
  168. $row['dongmoney']=$row['dongmoney'];
  169. $row['getmoney']=$row['getmoney'];
  170. $row['fulladdress'] = $row['province_name'].$row['city_name'].$row['area_name'].$row['country_name'].$row['address'];
  171. $row['addtime'] = date('Y-m-d H:i:s', $row['addtime']);
  172. $row['apptime'] = date('Y-m-d H:i:s', $row['apptime']);
  173. $row['state'] = $row['state'] == 1 ? '已审核':'未审核';
  174. }
  175. unset($row);
  176. $columns = array(
  177. array('title' => 'ID', 'field' => 'member_id', 'width' => 12),
  178. array('title' => '微信用户名', 'field' => 'username', 'width' => 12),
  179. array('title' => '团长名称', 'field' => 'head_name', 'width' => 12),
  180. array('title' => '小区名称', 'field' => 'community_name', 'width' => 12),
  181. array('title' => '联系方式', 'field' => 'head_mobile', 'width' => 12),
  182. array('title' => '在售商品数量', 'field' => 'goods_count', 'width' => 24),
  183. array('title' => 'openid', 'field' => 'we_openid', 'width' => 24),
  184. array('title' => '累计佣金', 'field' => 'commission_total', 'width' => 12),
  185. array('title' => '打款佣金', 'field' => 'getmoney', 'width' => 12),
  186. array('title' => '待确认', 'field' => 'pre_total_money', 'width' => 12),
  187. array('title' => '可提现', 'field' => 'money', 'width' => 12),
  188. array('title' => '已打款', 'field' => 'getmoney', 'width' => 12),
  189. array('title' => '提现中', 'field' => 'dongmoney', 'width' => 12),
  190. array('title' => '总收入', 'field' => 'commission_total', 'width' => 12),
  191. array('title' => '省', 'field' => 'province_name', 'width' => 12),
  192. array('title' => '市', 'field' => 'city_name', 'width' => 12),
  193. array('title' => '区', 'field' => 'area_name', 'width' => 12),
  194. array('title' => '街道/镇', 'field' => 'country_name', 'width' => 12),
  195. array('title' => '提货地址', 'field' => 'address', 'width' => 24),
  196. array('title' => '完整提货地址', 'field' => 'fulladdress', 'width' => 24),
  197. array('title' => '申请时间', 'field' => 'addtime', 'width' => 12),
  198. array('title' => '成为团长时间', 'field' => 'apptime', 'width' => 12),
  199. array('title' => '审核状态', 'field' => 'state', 'width' => 12)
  200. );
  201. D('Seller/Excel')->export($list, array('title' => '团长数据-' . date('Y-m-d-H-i', time()), 'columns' => $columns));
  202. }
  203. $pager = pagination2($total, $pindex, $psize);
  204. $this->pager = $pager;
  205. $this->list = $list;
  206. $open_danhead_model = D('Home/Front')->get_config_by_name('open_danhead_model');
  207. if( empty($open_danhead_model) )
  208. {
  209. $open_danhead_model = 0;
  210. }
  211. $this->open_danhead_model = $open_danhead_model;
  212. $this->display('Communityhead/communityhead');
  213. }
  214. public function lineheadquery()
  215. {
  216. $_GPC = I('request.');
  217. $kwd = trim($_GPC['keyword']);
  218. $is_soli = isset($_GPC['is_soli']) ? $_GPC['is_soli'] : 0;
  219. $is_just_line = isset($_GPC['is_just_line']) ? $_GPC['is_just_line'] : 0;
  220. $is_memberlist = isset($_GPC['is_memberlist']) ? $_GPC['is_memberlist'] : 0;
  221. $is_delivery = isset($_GPC['is_delivery']) ? $_GPC['is_delivery'] : 0;
  222. $is_member_choose = isset($_GPC['is_member_choose']) ? $_GPC['is_member_choose'] : 0;
  223. $is_mult = isset($_GPC['is_mult']) ? $_GPC['is_mult'] : 0;
  224. $s_member_id = isset($_GPC['s_member_id']) ? $_GPC['s_member_id'] : 0;
  225. $params = array();
  226. $condition = ' and state=1 and enable=1 ';
  227. if (!empty($kwd)) {
  228. $condition .= ' AND ( `community_name` LIKE "%'.$kwd.'%" or `head_name` LIKE "%'.$kwd.'%" or `head_mobile` LIKE "%'.$kwd.'%" )';
  229. }
  230. if($is_delivery == 0 && $is_soli ==0 && $is_memberlist == 0)
  231. {
  232. $had_head_list = M()->query('select head_id from '.C('DB_PREFIX')."lionfish_comshop_deliveryline_headrelative ");
  233. }
  234. //is_just_line
  235. if( $is_just_line == 1 )
  236. {
  237. $had_head_list = M()->query('select head_id from '.C('DB_PREFIX')."lionfish_comshop_deliveryline_headrelative ");
  238. $un_slhead_arr = array();
  239. foreach($had_head_list as $val)
  240. {
  241. $un_slhead_arr[] = $val['head_id'];
  242. }
  243. $un_slhead_str = "";
  244. if( !empty($un_slhead_arr) )
  245. {
  246. $condition .= " and id not in( ".implode(',', $un_slhead_arr )." ) ";
  247. }else{
  248. $un_slhead_str = ' 1<>1 ';
  249. }
  250. }
  251. $ds = M()->query('SELECT * FROM ' . C('DB_PREFIX') . 'lionfish_community_head WHERE 1 ' . $condition . ' order by id asc');
  252. $need_data = array();
  253. if( !empty($had_head_list) )
  254. {
  255. $ids_list = array();
  256. foreach($had_head_list as $vv)
  257. {
  258. $ids_list[] = $vv['head_id'];
  259. }
  260. foreach($ds as $key => $val)
  261. {
  262. if( !in_array($val['head_id'], $ids_list) )
  263. {
  264. $need_data[$key] = $val;
  265. }
  266. }
  267. }else{
  268. $need_data = $ds;
  269. }
  270. $s_html = '';
  271. foreach ($need_data as &$value) {
  272. $province = D('Home/Front')->get_area_info($value['province_id']);
  273. $city = D('Home/Front')->get_area_info($value['city_id']);
  274. $area = D('Home/Front')->get_area_info($value['area_id']);
  275. $country = D('Home/Front')->get_area_info($value['country_id']);
  276. //address
  277. $full_name = $province['name'].$city['name'].$area['name'].$country['name'].$value['address'];
  278. $value['fullAddress'] = $full_name;
  279. $s_html.="<tr>";
  280. $s_html.='<td>'.$value['community_name'].'</td>';
  281. $s_html.='<td>'.$value['head_name'].'</td>';
  282. $s_html.='<td>'.$value['head_mobile'].'</td>';
  283. $s_html.='<td>'.$value['fullAddress'].'</td>';
  284. if( $is_member_choose == 1 )
  285. {
  286. $s_html.='<td style="width:80px;"><a href="javascript:;" class="choose_dan_head_mb" data-json=\''.json_encode($value).'\'>选择</a></td>';
  287. }
  288. else{
  289. $s_html.='<td style="width:80px;"><a href="javascript:;" class="choose_dan_head" data-json=\''.json_encode($value).'\'>选择</a></td>';
  290. }
  291. $s_html.="</tr>";
  292. }
  293. if( isset($_GPC['is_ajax']) && $_GPC['is_ajax'] == 1 )
  294. {
  295. echo json_encode( array('code' => 0, 'html' =>$s_html ) );
  296. die();
  297. }
  298. unset($value);
  299. $this->gpc = $_GPC;
  300. $this->need_data = $need_data;
  301. $this->had_head_list = $had_head_list;
  302. $this->s_member_id = $s_member_id;
  303. $this->is_just_line = $is_just_line;
  304. $this->is_mult = $is_mult;
  305. if( $is_soli == 1 )
  306. {
  307. $this->display('Communityhead/lineheadquery_soli');
  308. }
  309. else if( $is_delivery == 1 )
  310. {
  311. $this->display('Communityhead/lineheadquery_delivery');
  312. }
  313. else if( $is_member_choose == 1 )
  314. {
  315. include $this->display('Communityhead/lineheadquery_mb_choose');
  316. }
  317. else{
  318. $this->display('Communityhead/lineheadquery');
  319. }
  320. }
  321. //------begin-------
  322. public function usergroup()
  323. {
  324. $_GPC = I('request.');
  325. $membercount = M('lionfish_community_head')->where("groupid=0")->count();
  326. $list = array(
  327. array('id' => 'default', 'groupname' => '默认分组', 'membercount' => $membercount )
  328. );
  329. $condition = ' ';
  330. $params = array(':uniacid' => $_W['uniacid']);
  331. if (!(empty($_GPC['keyword']))) {
  332. $_GPC['keyword'] = trim($_GPC['keyword']);
  333. $condition .= ' and ( groupname like "%'.$_GPC['keyword'].'%")';
  334. }
  335. $alllist = M('lionfish_community_head_group')->where( "1 ". $condition )->order('id asc')->select();
  336. foreach ($alllist as &$row ) {
  337. $sql = 'select count(*) as count from ' . C('DB_PREFIX') .'lionfish_community_head where find_in_set('.$row['id'].',groupid) limit 1';
  338. $membercount_arr = M()->query($sql);
  339. $row['membercount'] = $membercount_arr[0]['count'];
  340. }
  341. unset($row);
  342. if (empty($_GPC['keyword'])) {
  343. $list = array_merge($list, $alllist);
  344. }
  345. else {
  346. $list = $alllist;
  347. }
  348. $this->gpc = $_GPC;
  349. $this->list = $list;
  350. $this->display();
  351. }
  352. public function deleteusergroup()
  353. {
  354. $_GPC = I('request.');
  355. $id = intval($_GPC['id']);
  356. if (empty($id)) {
  357. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  358. }
  359. $items = M('lionfish_community_head_group')->field('id,groupname')->where( 'id in( ' . $id . ' )' )->select();
  360. foreach ($items as $item ) {
  361. M('lionfish_community_head')->where( array('groupid' => $item['id'] ) )->save( array('groupid' => 0) );
  362. M('lionfish_community_head_group')->where( array('id' => $item['id']) )->delete();
  363. }
  364. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  365. }
  366. public function addusergroup()
  367. {
  368. $_GPC = I('request.');
  369. $id = intval($_GPC['id']);
  370. $group = M('lionfish_community_head_group')->where( array('id' => $id ) )->find();
  371. if (IS_POST) {
  372. $data = array( 'groupname' => trim($_GPC['groupname']) );
  373. if (!(empty($id))) {
  374. M('lionfish_community_head_group')->where( array('id' => $id) )->save( $data );
  375. }
  376. else {
  377. $id = M('lionfish_community_head_group')->add($data);
  378. }
  379. show_json(1, array('url' => U('communityhead/usergroup', array('op' => 'display'))));
  380. }
  381. $this->id = $id;
  382. $this->group = $group;
  383. $this->display();
  384. }
  385. //------end-------
  386. /**
  387. * 禁用状态切换
  388. */
  389. public function enable_check()
  390. {
  391. $id = I('request.id');
  392. if (empty($id)) {
  393. $ids = I('request.ids');
  394. $id = (is_array($ids) ? implode(',', $ids) : 0);
  395. }
  396. $comsiss_state = I('request.enable');
  397. $members = M('lionfish_community_head')->field('id,member_id,enable')->where( array('id' =>array('in', $id)) )->select();
  398. $time = time();
  399. foreach ($members as $member) {
  400. if ($member['enable'] === $comsiss_state) {
  401. continue;
  402. }
  403. if ($comsiss_state == 1) {
  404. M('lionfish_community_head')->where( array('id' => $member['id']) )->save( array('enable' => 1) );
  405. }
  406. else {
  407. M('lionfish_community_head')->where( array('id' => $member['id']) )->save( array('enable' => 0) );
  408. }
  409. }
  410. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  411. }
  412. public function distributionorder()
  413. {
  414. $gpc = I('request.');
  415. $starttime = isset($gpc['time']['start']) ? strtotime($gpc['time']['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  416. $endtime = isset($gpc['time']['end']) ? strtotime($gpc['time']['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  417. $this->starttime = $starttime;
  418. $this->endtime = $endtime;
  419. $this->time = $gpc['time'];
  420. $order_status_arr = D('Seller/Order')->get_order_status_name();
  421. $_GET['is_community'] = 1;//分销订单
  422. $this->is_community = 1;
  423. //$_GPC['type'] = 'community';
  424. $cur_controller = 'communityhead/distributionorder';
  425. $this->cur_controller = $cur_controller;
  426. $need_data = D('Seller/Order')->load_order_list();
  427. $total = $need_data['total'];
  428. $total_money = $need_data['total_money'];
  429. $list = $need_data['list'];
  430. $pager = $need_data['pager'];
  431. $all_count = $need_data['all_count'];
  432. $count_status_1 = $need_data['count_status_1'];
  433. $count_status_3 = $need_data['count_status_3'];
  434. $count_status_4 = $need_data['count_status_4'];
  435. $count_status_5 = $need_data['count_status_5'];
  436. $count_status_7 = $need_data['count_status_7'];
  437. $count_status_11 = $need_data['count_status_11'];
  438. $count_status_14 = $need_data['count_status_14'];
  439. $this->total = $total;
  440. $this->total_money = $total_money;
  441. $this->list = $list;
  442. $this->pager = $pager;
  443. $this->all_count = $all_count;
  444. $this->count_status_1 = $count_status_1;
  445. $this->count_status_3 = $count_status_3;
  446. $this->count_status_4 = $count_status_4;
  447. $this->count_status_5 = $count_status_5;
  448. $this->count_status_7 = $count_status_7;
  449. $this->count_status_11 = $count_status_11;
  450. $this->count_status_14 = $count_status_14;
  451. $this->headid = I('get.headid');
  452. $this->order_status_id = I('get.order_status_id');
  453. $this->display('Order/index');
  454. }
  455. //---begin
  456. public function deletecommunitymember()
  457. {
  458. $_GPC = I('request.');
  459. $id = intval($_GPC['id']);
  460. $apply_info = M('lionfish_comshop_community_pickup_member')->where( array('id' => $id ) )->find();
  461. M('lionfish_comshop_member')->where( array('member_id' => $apply_info['member_id']) )->save( array('pickup_id' => 0 ) );
  462. M('lionfish_comshop_community_pickup_member')->where( array('id' => $id ) )->delete();
  463. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  464. }
  465. public function agent_check_communitymember()
  466. {
  467. $_GPC = I('request.');
  468. $id = intval($_GPC['id']);
  469. $state = intval($_GPC['state']);
  470. if (empty($id)) {
  471. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  472. }
  473. $apply_list = M('lionfish_comshop_community_pickup_member')->where( 'id in( ' . $id . ' )' )->select();
  474. foreach ($apply_list as $apply) {
  475. M('lionfish_comshop_community_pickup_member')->where( array('id' => $apply['id']) )->save( array('state' => $state ) );
  476. }
  477. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  478. }
  479. //---end
  480. public function communityhead()
  481. {
  482. $_GPC = I('request.');
  483. $this->gpc = $_GPC;
  484. $condition = ' ';
  485. $pindex = max(1, intval($_GPC['page']));
  486. $psize = 20;
  487. if (!empty($_GPC['keyword'])) {
  488. $_GPC['keyword'] = trim($_GPC['keyword']);
  489. $condition .= ' and ( m.username like "%'.$_GPC['keyword'].'%" or ch.community_name like "%'.$_GPC['keyword'].'%" or ch.head_name like "%'.$_GPC['keyword'].'%" or ch.head_mobile like "%'.$_GPC['keyword'].'%" or ch.address like "%'.$_GPC['keyword'].'%" ) ';
  490. }
  491. if (!empty($_GPC['time']['start']) && !empty($_GPC['time']['end'])) {
  492. $starttime = strtotime($_GPC['time']['start']);
  493. $endtime = strtotime($_GPC['time']['end']);
  494. $this->starttime = $starttime;
  495. $this->endtime = $endtime;
  496. $condition .= ' AND ch.apptime >= '.$starttime.' AND ch.apptime <= '.$endtime.' ';
  497. }
  498. if ($_GPC['comsiss_state'] != '') {
  499. $condition .= ' and ch.state=' . intval($_GPC['comsiss_state']);
  500. }
  501. if( $_GPC['level_id'] != '' )
  502. {
  503. $condition .= ' and ch.level_id=' . intval($_GPC['level_id']);
  504. }
  505. if( $_GPC['group_id'] != '' )
  506. {
  507. $condition .= ' and ch.groupid=' . intval($_GPC['group_id']);
  508. }
  509. $sql = 'SELECT ch.*,m.we_openid,m.username,m.avatar FROM ' . C('DB_PREFIX') . "lionfish_community_head as ch left join ".C('DB_PREFIX')."lionfish_comshop_member as m on ch.member_id = m.member_id
  510. WHERE 1 " . $condition . ' order by ch.id desc ';
  511. if (empty($_GPC['export'])) {
  512. $sql .= ' limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  513. }
  514. $list = M()->query($sql);
  515. $sql_count = 'SELECT count(1) as count FROM ' . C('DB_PREFIX'). 'lionfish_community_head as ch left join '.C('DB_PREFIX').'lionfish_comshop_member as m on ch.member_id = m.member_id
  516. WHERE 1 ' . $condition;
  517. $total_arr = M()->query($sql_count);
  518. $total = $total_arr[0]['count'];
  519. $all_sell_count = M('lionfish_comshop_goods')->where( array('is_all_sale' => 1) )->count();
  520. //---------等级
  521. $community_head_level = M('lionfish_comshop_community_head_level')->order('id asc')->select();
  522. $head_commission_levelname = D('Home/Front')->get_config_by_name('head_commission_levelname');
  523. $default_comunity_money = D('Home/Front')->get_config_by_name('default_comunity_money');
  524. $list_default = array(
  525. array('id' => '0','level'=>0,'levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $default_comunity_money, )
  526. );
  527. $community_head_level = array_merge($list_default, $community_head_level);
  528. $level_id_to_name = array();
  529. foreach($community_head_level as $kk => $vv)
  530. {
  531. $level_id_to_name[$vv['id']] = $vv['levelname'];
  532. }
  533. //---------等级
  534. //---------分组
  535. $community_head_group = M('lionfish_community_head_group')->order('id asc')->select();
  536. $list_default_group = array(
  537. array('id' => '0','groupname' => '默认等级',)
  538. );
  539. $community_head_group = array_merge($list_default_group, $community_head_group);
  540. $group_id_to_name = array();
  541. foreach($community_head_group as $kk => $vv)
  542. {
  543. $group_id_to_name[$vv['id']] = $vv['groupname'];
  544. }
  545. //---------分组
  546. $this->group_id_to_name = $group_id_to_name;
  547. $this->list_default_group = $list_default_group;
  548. $this->community_head_group = $community_head_group;
  549. $group_list = M('lionfish_community_head_group')->order('id asc')->select();
  550. foreach($group_list as $vv)
  551. {
  552. $keys_group[$vv['id']] = $vv['groupname'];
  553. }
  554. $this->group_list = $group_list;
  555. $this->keys_group = $keys_group;
  556. foreach( $list as $key => $val )
  557. {
  558. //commission_info
  559. $commission_info = M('lionfish_community_head_commiss')->where( array('head_id' => $val['id'],'member_id' => $val['member_id']) )->find();
  560. $commission_info['commission_total'] = $commission_info['money']+ $commission_info['dongmoney'] + $commission_info['getmoney'];
  561. //预计佣金
  562. $pre_total_money = M('lionfish_community_head_commiss_order')->where( array('state' =>0, 'head_id' => $val['id']) )->sum('money');
  563. if( empty($pre_total_money) )
  564. {
  565. $pre_total_money = 0;
  566. }
  567. $val['groupname'] = empty($val['groupid']) ? '默认分组':$keys_group[$val['groupid']];
  568. $commission_info['pre_total_money'] = $pre_total_money;
  569. $commission_info['commission_total'] = $commission_info['money']+ $commission_info['dongmoney'] + $commission_info['getmoney'] +$pre_total_money;
  570. $val['commission_info'] = $commission_info;
  571. //普通等级
  572. $val['agent_name'] = '';
  573. if( !empty($val['agent_id']) && $val['agent_id'] > 0 )
  574. {
  575. $parent_community_head = M('lionfish_community_head')->field('head_name')->where( array('id' => $val['agent_id'] ) )->find();
  576. $val['agent_name'] = $parent_community_head['head_name'];
  577. }
  578. $val['province_name'] = D('Seller/Area')->get_area_info($val['province_id']);
  579. $val['city_name'] = D('Seller/Area')->get_area_info($val['city_id']);
  580. $val['area_name'] = D('Seller/Area')->get_area_info($val['area_id']);
  581. $val['country_name'] = D('Seller/Area')->get_area_info($val['country_id']);
  582. //团长商品
  583. $head_goods_count_arr = M()->query("select count(hg.id) as count from ".C('DB_PREFIX')."lionfish_community_head_goods as hg ,".C('DB_PREFIX')."lionfish_comshop_good_common as gc ,".C('DB_PREFIX')."lionfish_comshop_goods as g
  584. where hg.goods_id = gc.goods_id and gc.goods_id = g.id and g.is_all_sale=0 and hg.head_id =".$val['id'] );
  585. $val['head_goods_count'] = $head_goods_count_arr[0]['count'];
  586. //所有团长可售商品
  587. $val['all_sell_count'] = $all_sell_count;
  588. //总商品数
  589. $val['goods_count'] =$val['head_goods_count'] + $val['all_sell_count'] ;
  590. //$val['member_info'] = $member_info;
  591. $member_count_arr = M()->query("SELECT count(DISTINCT(member_id) ) as count FROM ".
  592. C('DB_PREFIX')."lionfish_community_history WHERE head_id =".$val['id']);
  593. $val['member_count'] = $member_count_arr[0]['count'];
  594. $val['agent_count'] = M('lionfish_community_head')->where( array('agent_id' => $val['id'] ) )->count();
  595. $list[$key] = $val;
  596. }
  597. if ($_GPC['export'] == '1') {
  598. foreach ($list as &$row) {
  599. //$row['username'] = $val['member_info']['username'];
  600. //$row['we_openid'] = $val['member_info']['we_openid'];
  601. $row['commission_total'] = $row['commission_info']['commission_total'];
  602. $row['getmoney'] = $row['commission_info']['getmoney'];
  603. $row['fulladdress'] = $row['province_name'].$row['city_name'].$row['area_name'].$row['country_name'].$row['address'];
  604. $row['addtime'] = date('Y-m-d H:i:s', $row['addtime']);
  605. $row['apptime'] = date('Y-m-d H:i:s', $row['apptime']);
  606. $row['state'] = $row['state'] == 1 ? '已审核':'未审核';
  607. }
  608. unset($row);
  609. $columns = array(
  610. array('title' => 'ID', 'field' => 'member_id', 'width' => 12),
  611. array('title' => '微信用户名', 'field' => 'username', 'width' => 12),
  612. array('title' => '团长名称', 'field' => 'head_name', 'width' => 12),
  613. array('title' => '联系方式', 'field' => 'head_mobile', 'width' => 12),
  614. array('title' => '在售商品数量', 'field' => 'goods_count', 'width' => 24),
  615. array('title' => 'openid', 'field' => 'we_openid', 'width' => 24),
  616. array('title' => '累计佣金', 'field' => 'commission_total', 'width' => 12),
  617. array('title' => '打款佣金', 'field' => 'getmoney', 'width' => 12),
  618. array('title' => '省', 'field' => 'province_name', 'width' => 12),
  619. array('title' => '市', 'field' => 'city_name', 'width' => 12),
  620. array('title' => '区', 'field' => 'area_name', 'width' => 12),
  621. array('title' => '街道/镇', 'field' => 'country_name', 'width' => 12),
  622. array('title' => '提货地址', 'field' => 'address', 'width' => 24),
  623. array('title' => '完整提货地址', 'field' => 'fulladdress', 'width' => 24),
  624. array('title' => '注册时间', 'field' => 'addtime', 'width' => 12),
  625. array('title' => '成为团长时间', 'field' => 'apptime', 'width' => 12),
  626. array('title' => '审核状态', 'field' => 'state', 'width' => 12)
  627. );
  628. load_model_class('excel')->export($list, array('title' => '团长数据-' . date('Y-m-d-H-i', time()), 'columns' => $columns));
  629. }
  630. $pager = pagination2($total, $pindex, $psize);
  631. $this->pager = $pager;
  632. $this->list = $list;
  633. $open_danhead_model = D('Home/Front')->get_config_by_name('open_danhead_model');
  634. if( empty($open_danhead_model) )
  635. {
  636. $open_danhead_model = 0;
  637. }
  638. $this->open_danhead_model = $open_danhead_model;
  639. $this->display('communityhead/communityhead');
  640. }
  641. public function changelevel()
  642. {
  643. $_GPC = I('request.');
  644. $level = $_GPC['level'];
  645. $ids_arr = $_GPC['ids'];
  646. $toggle = $_GPC['toggle'];
  647. $ids = implode(',', $ids_arr);
  648. if($toggle == 'group')
  649. {
  650. M('lionfish_community_head')->where( "id in ({$ids})" )->save( array('groupid' => $level) );
  651. }else if($toggle == 'level'){
  652. M('lionfish_community_head')->where("id in ({$ids})")->save( array('level_id' => $level ) );
  653. }
  654. show_json(1);
  655. }
  656. //--begin
  657. public function deletehead()
  658. {
  659. $_GPC = I('request.');
  660. $id = intval($_GPC['id']);
  661. if (empty($id)) {
  662. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  663. }
  664. $items = M('lionfish_community_head')->field('id')->where( 'id in( ' . $id . ' )' )->select();
  665. foreach ($items as $item ) {
  666. M('lionfish_community_head')->where( array('id' => $item['id'] ) )->delete();
  667. }
  668. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  669. }
  670. //look_piup_record
  671. public function look_piup_record()
  672. {
  673. $_GPC = I('request.');
  674. $member_id = $_GPC['member_id'];
  675. $keyword = trim($_GPC['keyword']);
  676. $condition = ' member_id = '.$member_id;
  677. $pindex = max(1, intval($_GPC['page']));
  678. $psize = 20;
  679. if( !empty($keyword) )
  680. {
  681. }
  682. $sql = 'SELECT * FROM ' . C('DB_PREFIX') ."lionfish_comshop_community_pickup_member_record
  683. WHERE " . $condition . ' order by id desc ';
  684. $sql .= ' limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  685. $list = M()->query($sql);
  686. $total = M('lionfish_comshop_community_pickup_member_record')->where( $condition )->count();
  687. $pager = pagination2($total, $pindex, $psize);
  688. $this->list = $list;
  689. $this->pager = $pager;
  690. $this->gpc = $_GPC;
  691. $this->display();
  692. }
  693. public function lookcommunitymember()
  694. {
  695. $_GPC = I('request.');
  696. //id=272
  697. $community_id = $_GPC['id'];
  698. $keyword = trim($_GPC['keyword']);
  699. $condition = ' and pm.community_id= '.$community_id;
  700. $pindex = max(1, intval($_GPC['page']));
  701. $psize = 20;
  702. if( !empty($keyword) )
  703. {
  704. $condition .= " and m.username like '%".$keyword."%' ";
  705. }
  706. $sql = 'SELECT pm.*, m.username FROM ' . C('DB_PREFIX'). "lionfish_comshop_community_pickup_member as pm , ".
  707. C('DB_PREFIX')."lionfish_comshop_member as m
  708. WHERE pm.member_id = m.member_id " . $condition . ' order by pm.id desc ';
  709. $sql .= ' limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  710. $list = M()->query($sql);
  711. foreach($list as $key => $val)
  712. {
  713. $he_count = M('lionfish_comshop_community_pickup_member_record')->where( array('member_id' => $val['member_id'] ) )->count();
  714. $val['he_count'] = $he_count;
  715. $list[$key] = $val;
  716. }
  717. $total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX'). 'lionfish_comshop_community_pickup_member as pm , '.
  718. C('DB_PREFIX').'lionfish_comshop_member as m WHERE pm.member_id = m.member_id ' . $condition);
  719. $total = $total_arr[0]['count'];
  720. $pager = pagination2($total, $pindex, $psize);
  721. $this->community_id = $community_id;
  722. $this->keyword = $keyword;
  723. $this->list = $list;
  724. $this->pager = $pager;
  725. $this->gpc = $_GPC;
  726. $this->display();
  727. }
  728. public function addcommunitymember()
  729. {
  730. $_GPC = I('request.');
  731. $community_id = $_GPC['community_id'];
  732. //
  733. if (IS_POST) {
  734. $member_id = $_GPC['member_id'];
  735. $ins_data = array();
  736. $ins_data['community_id'] = $community_id;
  737. $ins_data['member_id'] = $member_id;
  738. $ins_data['state'] = 1;
  739. $ins_data['remark'] = '后台添加';
  740. $ins_data['addtime'] = time();
  741. $pickup_id = M('lionfish_comshop_community_pickup_member')->add( $ins_data );
  742. M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->save( array('pickup_id' => $pickup_id) );
  743. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  744. }
  745. $this->community_id = $community_id;
  746. $this->display();
  747. }
  748. //---end
  749. public function goodslist()
  750. {
  751. $head_id = I('request.head_id');
  752. $this->head_id = $head_id;
  753. $pindex = I('request.page', 1);
  754. $psize = 20;
  755. $params = array();
  756. $where = " 1=1 ";
  757. $all_sales_goods = M('lionfish_comshop_goods')->field('id')->where( array('is_all_sale' => 1) )->select();
  758. $all_goods_ids = array();
  759. if( !empty($all_sales_goods) )
  760. {
  761. foreach($all_sales_goods as $val)
  762. {
  763. $all_goods_ids[] = $val['id'];
  764. }
  765. }
  766. $this->all_goods_ids = $all_goods_ids;
  767. $ch_goods_list = M('lionfish_community_head_goods')->field('goods_id')->where( array('head_id' => $head_id) )->select();
  768. $ch_goods_arr = array();
  769. if( !empty($ch_goods_list) )
  770. {
  771. foreach($ch_goods_list as $val)
  772. {
  773. $ch_goods_arr[] = $val['goods_id'];
  774. }
  775. }
  776. $in_goods_ids = array_merge($ch_goods_arr, $all_goods_ids);
  777. $keyword = I('request.keyword');
  778. $this->keyword = $keyword;
  779. if (!(empty($keyword))) {
  780. $where .= ' AND (g.`id` = "'.$keyword.'" or g.`goodsname` LIKE '.'"%' . $keyword . '%"'.' or g.`codes` LIKE '.'"%' . $keyword . '%"'.' )';
  781. }
  782. $cate = I('request.cate');
  783. $this->cate = $cate;
  784. if( !empty($cate) )
  785. {
  786. $cate_list = M('lionfish_comshop_goods_to_category')->field('goods_id')->where( array('cate_id' => $cate) )->select();
  787. $catids_arr = array();
  788. foreach($cate_list as $val)
  789. {
  790. if( in_array($val['goods_id'], $in_goods_ids) )
  791. {
  792. $catids_arr[] = $val['goods_id'];
  793. }
  794. }
  795. if( !empty($catids_arr) )
  796. {
  797. $catids_str = implode(',', $catids_arr);
  798. $where .= ' and g.id in ('.$catids_str.')';
  799. }else{
  800. $where .= " and 1=0 ";
  801. }
  802. }else{
  803. if( !empty($in_goods_ids) )
  804. {
  805. $catids_str = implode(',', $in_goods_ids);
  806. $where .= ' and g.id in ('.$catids_str.')';
  807. }else{
  808. $where .= " and 1=0 ";
  809. }
  810. }
  811. $sql = 'SELECT COUNT(g.id) as count FROM ' .C('DB_PREFIX') . 'lionfish_comshop_goods as g '
  812. ." where {$where} " ;
  813. $total_arr = M()->query($sql);
  814. $total = $total_arr[0]['count'];
  815. //tablename('lionfish_community_head_goods')." as hg " //. tablename('lionfish_community_head_goods')." as hg "
  816. if (!(empty($total))) {
  817. $sql = 'SELECT g.* FROM ' . C('DB_PREFIX') . 'lionfish_comshop_goods as g ' .
  818. " where {$where} " . ' ORDER BY g.`id` DESC LIMIT ' . (($pindex - 1) * $psize) . ',' . $psize;
  819. $list = M()->query($sql);
  820. foreach ($list as $key => &$value ) {
  821. $thumb = M('lionfish_comshop_goods_images')->where( array('goods_id' => $value['id']) )->order('id asc')->find();
  822. $value['thumb'] = $thumb['thumb'];
  823. $categorys = M('lionfish_comshop_goods_to_category')->where( array('goods_id' => $value['id']) )->order('id asc')->select();
  824. $value['cate'] = $categorys;
  825. $desc_info = D('Home/Front')->get_goods_common_field($value['id'] , 'community_head_commission');
  826. $price_arr = D('Home/Pingoods')->get_goods_price($value['id']);
  827. $value['price_arr'] = $price_arr;
  828. $value['community_head_commission'] = $desc_info['community_head_commission'];
  829. }
  830. $pager = pagination2($total, $pindex, $psize);
  831. }
  832. $categorys = D('Seller/GoodsCategory')->getFullCategory(true);
  833. $category = array();
  834. foreach ($categorys as $cate ) {
  835. $category[$cate['id']] = $cate;
  836. }
  837. $this->pager = $pager;
  838. $this->category = $category;
  839. $this->list = $list;
  840. $this->display();
  841. }
  842. public function down_sales()
  843. {
  844. $id = I('request.id', 0);
  845. if (empty($id)) {
  846. $ids = I('request.ids');
  847. $id = (is_array($ids) ? implode(',', $ids) : 0);
  848. }
  849. $head_id = I('request.head_id', 0);
  850. if(!empty($id))
  851. {
  852. M('lionfish_community_head_goods')->where( array('head_id' => $head_id, 'goods_id' => array('in', $id)) )->delete();
  853. }
  854. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  855. }
  856. public function config()
  857. {
  858. global $_W;
  859. global $_GPC;
  860. if (IS_POST) {
  861. $data = I('request.data');
  862. if($data['community_money_type'] ==0){
  863. if( intval($data['default_comunity_money']) < 0 || intval($data['default_comunity_money']) > 100){
  864. show_json(0, array('message' => '团长提成比例应为0~100之间'));
  865. }
  866. }
  867. if( !empty($data) && $data['open_community_head_leve'] >= 1 ){
  868. if( intval($data['community_head_commiss1']) < 0 || intval($data['community_head_commiss1']) > 100){
  869. show_json(0, array('message' => '团长分销1级提成比例应为0~100之间'));
  870. }
  871. }
  872. if( !empty($data) && $data['open_community_head_leve'] >= 2 ){
  873. if( intval($data['community_head_commiss1']) < 0 || intval($data['community_head_commiss1']) > 100){
  874. show_json(0, array('message' => '团长分销1级提成比例应为0~100之间'));
  875. }
  876. if( intval($data['community_head_commiss2']) < 0 || intval($data['community_head_commiss2']) > 100){
  877. show_json(0, array('message' => '团长分销2级提成比例应为0~100之间'));
  878. }
  879. }
  880. if( !empty($data) && $data['open_community_head_leve'] >= 3 ){
  881. if( intval($data['community_head_commiss1']) < 0 || intval($data['community_head_commiss1']) > 100){
  882. show_json(0, array('message' => '团长分销1级提成比例应为0~100之间'));
  883. }
  884. if( intval($data['community_head_commiss2']) < 0 || intval($data['community_head_commiss2']) > 100){
  885. show_json(0, array('message' => '团长分销2级提成比例应为0~100之间'));
  886. }
  887. if( intval($data['community_head_commiss3']) < 0 || intval($data['community_head_commiss3']) > 100){
  888. show_json(0, array('message' => '团长分销3级提成比例应为0~100之间'));
  889. }
  890. }
  891. D('Seller/Config')->update($data);
  892. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  893. }
  894. $data = D('Seller/Config')->get_all_config();
  895. $this->data = $data;
  896. $this->display();
  897. }
  898. public function distributionpostal()
  899. {
  900. if (IS_POST) {
  901. $data = I('request.data');
  902. $data['head_commiss_tixianway_yuer'] = isset($data['head_commiss_tixianway_yuer']) ? $data['head_commiss_tixianway_yuer'] : 1;
  903. $data['head_commiss_tixianway_weixin'] = isset($data['head_commiss_tixianway_weixin']) ? $data['head_commiss_tixianway_weixin'] : 1;
  904. $data['head_commiss_tixianway_alipay'] = isset($data['head_commiss_tixianway_alipay']) ? $data['head_commiss_tixianway_alipay'] : 1;
  905. $data['head_commiss_tixianway_bank'] = isset($data['head_commiss_tixianway_bank']) ? $data['head_commiss_tixianway_bank'] : 1;
  906. D('Seller/Config')->update($data);
  907. show_json(1, array('url' => $_SERVER['HTTP_REFERER']) );
  908. }
  909. $data = D('Seller/Config')->get_all_config();
  910. $this->data = $data;
  911. $this->display();
  912. }
  913. /**
  914. * 禁用状态切换
  915. */
  916. public function rest_check()
  917. {
  918. $_GPC = I('request.');
  919. $id = intval($_GPC['id']);
  920. if (empty($id)) {
  921. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  922. }
  923. $comsiss_state = intval($_GPC['rest']);
  924. $members = M('lionfish_community_head')->field('id,member_id,enable')->where( 'id in( ' . $id . ' )' )->select();
  925. $time = time();
  926. foreach ($members as $member) {
  927. if ($member['rest'] === $comsiss_state) { continue; }
  928. if ($comsiss_state == 1) {
  929. M('lionfish_community_head')->where( array('id' => $member['id']) )->save( array('rest' => 1) );
  930. }
  931. else {
  932. M('lionfish_community_head')->where( array('id' => $member['id']) )->save( array('rest' => 0) );
  933. }
  934. }
  935. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  936. }
  937. public function default_check()
  938. {
  939. $_GPC = I('request.');
  940. $open_danhead_model = D('Home/Front')->get_config_by_name('open_danhead_model');
  941. if( empty($open_danhead_model) )
  942. {
  943. $open_danhead_model = 0;
  944. }
  945. if( $open_danhead_model == 0 )
  946. {
  947. show_json(0, array('message' => '请先开启单团长模式') );
  948. die();
  949. }
  950. $community_model = D('Seller/Community');
  951. $id = intval($_GPC['id']);
  952. if (empty($id)) {
  953. $id = (is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0);
  954. }
  955. $is_default = intval($_GPC['value']);
  956. $members = M('lionfish_community_head')->field('id,member_id,enable')->where( 'id in( ' . $id . ' )' )->select();
  957. $time = time();
  958. foreach ($members as $member) {
  959. if ($member['is_default'] === $is_default) { continue; }
  960. if ($is_default == 1) {
  961. M('lionfish_community_head')->where( 'id>0' )->save( array('is_default' => 0) );
  962. M('lionfish_community_head')->where( array('id' => $member['id'] ) )->save( array('is_default' => 1) );
  963. }
  964. else {
  965. M('lionfish_community_head')->where( array('id' => $member['id'] ) )->save( array('is_default' => 0) );
  966. }
  967. }
  968. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  969. }
  970. public function distribulist()
  971. {
  972. $condition = ' ';
  973. $pindex = I('request.page', 1);
  974. $psize = 20;
  975. $keyword = I('request.keyword');
  976. $this->keyword = $keyword;
  977. if (!empty($keyword)) {
  978. $condition.="and (id like '%{$keyword}%' or username like '%{$keyword}%' or realname like '%{$keyword}%' or bankaccount like '%{$keyword}%')";
  979. }
  980. $time = I('request.time');
  981. $this->time = $time;
  982. $starttime = strtotime( date('Y-m-d').' 00:00:00' );
  983. $endtime = $starttime + 86400;
  984. $searchtime = I('request.searchtime', '');
  985. if( !empty($searchtime) )
  986. {
  987. if (!empty($time['start']) && !empty($time['end'])) {
  988. if (!empty($time['start']) && !empty($time['end'])) {
  989. $starttime = strtotime($time['start']);
  990. $endtime = strtotime($time['end']);
  991. $condition .= ' AND addtime >= '.$starttime.' AND addtime <= '.$endtime;
  992. }
  993. }
  994. }
  995. $this->starttime = $starttime;
  996. $this->endtime = $endtime;
  997. $comsiss_state = I('request.comsiss_state');
  998. $this->comsiss_state = $comsiss_state;
  999. if ($comsiss_state != '') {
  1000. $condition .= ' and state=' . intval($comsiss_state);
  1001. }
  1002. $sql = 'SELECT * FROM ' . C('DB_PREFIX'). "lionfish_community_head_tixian_order o left join " .C('DB_PREFIX')."lionfish_comshop_member m
  1003. on o.member_id = m.member_id WHERE 1 " . $condition . ' order by id desc ';
  1004. $export = I('request.export', 0);
  1005. if (empty($export)) {
  1006. $sql .= ' limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  1007. }
  1008. $community_tixian_fee = D('Home/Front')->get_config_by_name('community_tixian_fee');
  1009. $list = M()->query($sql);
  1010. $total = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX').
  1011. 'lionfish_community_head_tixian_order o left join '.C('DB_PREFIX').'lionfish_comshop_member m on o.member_id = m.member_id WHERE 1 ' . $condition);
  1012. foreach( $list as $key => $val )
  1013. {
  1014. $member_info = M('lionfish_comshop_member')->field('username,avatar,we_openid')->where( array('member_id' => $val['member_id']) )->find();
  1015. //get_area_info($id=0)
  1016. $service_charge = 0;
  1017. if(!empty($community_tixian_fee) && $community_tixian_fee > 0)
  1018. {
  1019. $service_charge = round( ($val['money'] * $community_tixian_fee) /100,2);
  1020. }
  1021. if($val['service_charge'] <= 0)
  1022. {
  1023. $val['service_charge'] = $service_charge;
  1024. }
  1025. $val['community_head_commiss'] = M('lionfish_community_head_commiss')->where( array('head_id' =>$val['head_id'] ) )->find();
  1026. $val['community_head_commiss']['commission_total'] = $val['community_head_commiss']['money']+$val['community_head_commiss']['getmoney']+$val['community_head_commiss']['dongmoney'];
  1027. $val['community_head'] = M('lionfish_community_head')->where( array('id' => $val['head_id'] ) )->find();
  1028. $val['member_info'] = $member_info;
  1029. $list[$key] = $val;
  1030. }
  1031. $this->list = $list;
  1032. if ($export == '1') {
  1033. foreach($list as $key =>&$row)
  1034. {
  1035. $row['community_name'] = $row['community_head']['community_name'];
  1036. $row['head_name'] = $row['community_head']['head_name'];
  1037. $row['head_mobile'] = $row['community_head']['head_mobile'];
  1038. //$row['bankname'] = $row['community_head_commiss']['bankname'];
  1039. //$row['bankaccount'] = $row['community_head_commiss']['bankaccount']."\t";
  1040. //$row['bankusername'] = $row['community_head_commiss']['bankusername'];
  1041. if($row['type'] > 0){
  1042. if( $row['type'] == 1 ){
  1043. $row['bankname'] = "会员余额";
  1044. }else if($row['type'] == 2){
  1045. $row['bankname'] = "微信零钱";
  1046. $row['bankusername'] = $row['bankusername'];
  1047. }else if($row['type'] == 3){
  1048. $row['bankname'] = "支付宝";
  1049. $row['bankusername'] = $row['bankusername'];
  1050. $row['bankaccount'] = "\t".$row['bankaccount'];
  1051. }else if($row['type'] == 4){
  1052. $row['bankname'] = $row['bankname'];
  1053. $row['bankusername'] = $row['bankusername'];
  1054. $row['bankaccount'] = "\t".$row['bankaccount'];
  1055. }
  1056. }else{
  1057. $row['bankname'] = $row['bankname'];
  1058. $row['bankusername'] = $row['bankusername'];
  1059. $row['bankaccount'] = "\t".$row['bankaccount'];
  1060. }
  1061. $row['get_money'] = $row['money']-$row['service_charge'];
  1062. $row['addtime'] = date('Y-m-d H:i:s', $row['addtime']);
  1063. if(!empty($row['shentime']))
  1064. {
  1065. $row['shentime'] = date('Y-m-d H:i:s', $row['shentime']);
  1066. }
  1067. if($row['state'] ==0)
  1068. {
  1069. $row['state'] = '待审核';
  1070. }else if($row[state] ==1)
  1071. {
  1072. $row['state'] = '已审核,打款';
  1073. }else if($row[state] ==2){
  1074. $row['state'] = '已拒绝';
  1075. }
  1076. }
  1077. unset($row);
  1078. $columns = array(
  1079. array('title' => 'ID', 'field' => 'id', 'width' => 12),
  1080. array('title' => '小区名称', 'field' => 'community_name', 'width' => 12),
  1081. array('title' => '团长名称', 'field' => 'head_name', 'width' => 12),
  1082. array('title' => '联系方式', 'field' => 'head_mobile', 'width' => 12),
  1083. array('title' => '打款银行', 'field' => 'bankname', 'width' => 24),
  1084. array('title' => '打款账户', 'field' => 'bankaccount', 'width' => 24),
  1085. array('title' => '真实姓名', 'field' => 'bankusername', 'width' => 24),
  1086. array('title' => '申请提现金额', 'field' => 'money', 'width' => 24),
  1087. array('title' => '手续费', 'field' => 'service_charge', 'width' => 24),
  1088. array('title' => '到账金额', 'field' => 'get_money', 'width' => 24),
  1089. array('title' => '申请时间', 'field' => 'addtime', 'width' => 24),
  1090. array('title' => '审核时间', 'field' => 'shentime', 'width' => 24),
  1091. array('title' => '状态', 'field' => 'state', 'width' => 24)
  1092. );
  1093. D('Seller/Excel')->export($list, array('title' => '团长提现数据-' . date('Y-m-d-H-i', time()), 'columns' => $columns) );
  1094. }
  1095. $pager = pagination2($total[0]['count'], $pindex, $psize);
  1096. $this->pager = $pager;
  1097. $this->display();
  1098. }
  1099. public function agent_check_apply()
  1100. {
  1101. $community_model = D('Seller/Community');
  1102. $id = I('request.id');
  1103. if (empty($id)) {
  1104. $ids = I('request.ids');
  1105. $id = (is_array($ids) ? implode(',', $ids) : 0);
  1106. }
  1107. $comsiss_state = I('request.state');
  1108. $apply_list = M('lionfish_community_head_tixian_order')->where( array('id'=> array('in', $id) ) )->select();
  1109. $time = time();
  1110. $community_tixian_fee = D('Seller/Front')->get_config_by_name('community_tixian_fee');
  1111. $open_weixin_qiye_pay = D('Home/Front')->get_config_by_name('open_weixin_qiye_pay');
  1112. $lib_path = dirname(dirname( dirname(__FILE__) )).'/Lib/';
  1113. require_once $lib_path."/Weixin/lib/WxPay.Api.php";
  1114. foreach ($apply_list as $apply) {
  1115. if ($apply['state'] == $comsiss_state || $apply['state'] == 1 || $apply['state'] == 2) {
  1116. continue;
  1117. }
  1118. $money = $apply['money'];
  1119. $head_id = $apply['head_id'];
  1120. if ($comsiss_state == 1) {
  1121. $service_charge = 0;
  1122. if(!empty($community_tixian_fee) && $community_tixian_fee > 0)
  1123. {
  1124. $service_charge = round( ($money * $community_tixian_fee) /100,2);
  1125. }
  1126. if( $apply['service_charge'] > 0 )
  1127. {
  1128. $service_charge = $apply['service_charge'];
  1129. }
  1130. if( $apply['type'] > 0 )
  1131. {
  1132. if( $apply['type'] == 1 )
  1133. {
  1134. //到会员余额
  1135. $del_money = $money-$service_charge;
  1136. if( $del_money >0 )
  1137. {
  1138. D('Admin/Member')->sendMemberMoneyChange($apply['member_id'], $del_money, 10, '团长提现到余额,提现id:'.$apply['id']);
  1139. }
  1140. }else if( $apply['type'] == 2 ){
  1141. //到微信零钱
  1142. //member_id
  1143. $commiss_head_info = M('lionfish_community_head_commiss')->where( array('head_id' => $head_id,'member_id' =>$apply['member_id'] ) )->find();
  1144. //bankname
  1145. if( !empty($open_weixin_qiye_pay) && $open_weixin_qiye_pay == 1 )
  1146. {
  1147. $mb_info = M('lionfish_comshop_member')->field('we_openid')->where( array('member_id' =>$apply['member_id'] ) )->find();
  1148. $partner_trade_no = build_order_no($apply['id']);
  1149. $desc = date('Y-m-d H:i:s', $apply['addtime']).'申请的提现已到账';
  1150. $username = $apply['bankusername'];
  1151. $amount = ($money-$service_charge) * 100;
  1152. $openid = $mb_info['we_openid'];
  1153. $res = \WxPayApi::payToUser($openid,$amount,$username,$desc,$partner_trade_no,$_W['uniacid']);
  1154. if(empty($res) || $res['result_code'] =='FAIL')
  1155. {
  1156. show_json(0, array('msg' => $res['err_code_des']) );
  1157. }
  1158. }else{
  1159. show_json(0, array('msg' => '请开通微信零钱企业支付') );
  1160. }
  1161. }
  1162. }else{
  1163. //member_id
  1164. $commiss_head_info = M('lionfish_community_head_commiss')->where( array('member_id' => $apply['member_id'],'head_id' => $head_id ) )->find();
  1165. //bankname
  1166. if( !empty($open_weixin_qiye_pay) && $open_weixin_qiye_pay == 1 )
  1167. {
  1168. if( strpos($commiss_head_info['bankname'], '微信') !== false )
  1169. {
  1170. $mb_info = M('lionfish_comshop_member')->field('we_openid')->where( array('member_id' => $apply['member_id'] ) )->find();
  1171. $partner_trade_no = build_order_no($apply['id']);
  1172. $desc = date('Y-m-d H:i:s', $apply['addtime']).'申请的提现已到账';
  1173. $username = $commiss_head_info['bankusername'];
  1174. $amount = ($money-$service_charge) * 100;
  1175. $openid = $mb_info['we_openid'];
  1176. $res = \WxPayApi::payToUser($openid,$amount,$username,$desc,$partner_trade_no,$_W['uniacid']);
  1177. if(empty($res) || $res['result_code'] =='FAIL')
  1178. {
  1179. show_json(0, array('msg' => $res['err_code_des']) );
  1180. }
  1181. }
  1182. }
  1183. }
  1184. M('lionfish_community_head_tixian_order')->where( array('id' => $apply['id']) )->save( array('state' => 1,'service_charge' => $service_charge, 'shentime' => $time));
  1185. //将冻结的钱划一部分到已提现的里面
  1186. M()->execute("update ".C('DB_PREFIX')."lionfish_community_head_commiss set getmoney=getmoney+{$money},dongmoney=dongmoney-{$money}
  1187. where head_id={$head_id} ");
  1188. //检测是否存在账户,没有就新建
  1189. //TODO....sendmsg 发送成为佣金提现成功
  1190. $community_model->send_apply_success_msg($apply['id']);
  1191. }
  1192. else if ($comsiss_state == 2) {
  1193. M('lionfish_community_head_tixian_order')->where( array('id' => $apply['id']) )->save( array('state' => 2, 'shentime' => $time) );
  1194. //退回冻结的货款
  1195. M()->execute("update ".C('DB_PREFIX')."lionfish_community_head_commiss set money=money+{$money},dongmoney=dongmoney-{$money}
  1196. where head_id={$head_id} ");
  1197. }
  1198. else {
  1199. M('lionfish_community_head_tixian_order')->where( array('id' => $member['id']) )->save( array('state' => 0, 'shentime' => 0) );
  1200. }
  1201. }
  1202. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1203. }
  1204. //begin .....
  1205. public function addlevel()
  1206. {
  1207. $this->modifylevel();
  1208. }
  1209. public function editlevel()
  1210. {
  1211. $this->modifylevel();
  1212. }
  1213. private function modifylevel()
  1214. {
  1215. $_GPC = I('request.');
  1216. $id = trim($_GPC['id']);
  1217. $set = D('Seller/Config')->get_all_config();
  1218. if ($id == 'default') {
  1219. $level = array('id' => 'default', 'levelname' => empty($set['head_commission_levelname']) ? '默认等级' : $set['head_commission_levelname'], 'commission' => $set['default_comunity_money'] );
  1220. $has_notice = 1;
  1221. }
  1222. else {
  1223. $level = M('lionfish_comshop_community_head_level')->where( array('id' => intval($id) ) )->find();
  1224. $has_notice = $set['open_community_head_has_notice'];
  1225. if(empty($has_notice))
  1226. {
  1227. $has_notice = 0;
  1228. }
  1229. }
  1230. if (IS_POST) {
  1231. $data = array(
  1232. 'levelname' => trim($_GPC['levelname']),
  1233. 'commission' => trim(trim($_GPC['commission']), '%')
  1234. );
  1235. $data['auto_upgrade'] = $_GPC['auto_upgrade'];
  1236. $data['condition_type'] = $_GPC['condition_type'];
  1237. $data['condition_one'] = $_GPC['condition_one'];
  1238. $data['condition_two'] = $_GPC['condition_two'];
  1239. $data['condition_order_total'] = $_GPC['condition_order_total'];
  1240. $community_money_type = $set['community_money_type'];
  1241. if($community_money_type ==0){
  1242. if( intval($data['commission']) < 0 || intval($data['commission']) > 100){
  1243. show_json(0, array('message' => '团长提成比例应为0~100之间'));
  1244. }
  1245. }
  1246. if($id != 'default')
  1247. {
  1248. if( isset($_GPC['auto_upgrade']) && $_GPC['auto_upgrade'] == 1 )
  1249. {
  1250. if($data['condition_type'] == 0)
  1251. {
  1252. if( empty($data['condition_one']) || $data['condition_one'] <=0 )
  1253. {
  1254. show_json(0, array('msg' => '订单总金额不能为空' ) );
  1255. }
  1256. }else if( $data['condition_type'] == 1 )
  1257. {
  1258. if( empty($data['condition_two']) || $data['condition_two'] <=0 )
  1259. {
  1260. show_json(0, array('msg' => '累计社区用户不能为空' ) );
  1261. }
  1262. }
  1263. }
  1264. }
  1265. D('Seller/Config')->update( array('open_community_head_has_notice' => 1) );
  1266. if (!empty($id)) {
  1267. if ($id == 'default') {
  1268. $set_data = array();
  1269. $set_data['head_commission_levelname'] = $data['levelname'];
  1270. $set_data['default_comunity_money'] = $data['commission'];
  1271. D('Seller/Config')->update($set_data);
  1272. }
  1273. else {
  1274. M('lionfish_comshop_community_head_level')->where( array('id' => $id) )->save( $data );
  1275. }
  1276. }
  1277. else {
  1278. $id = M('lionfish_comshop_community_head_level')->add( $data );
  1279. }
  1280. show_json(1, array('url' => U('Communityhead/headlevel')));
  1281. }
  1282. //此操作将启用等级全局提成,原商品比例失效,可到商品编辑“等级/分销”单独设置
  1283. $open_community_head_leve = $set['open_community_head_leve'];
  1284. if( empty($open_community_head_leve) )
  1285. {
  1286. $open_community_head_leve = 0;
  1287. }
  1288. $community_money_type = $set['community_money_type'];
  1289. $this->community_money_type = $community_money_type;
  1290. $this->level = $level;
  1291. $this->open_community_head_leve = $open_community_head_leve;
  1292. $this->display('Communityhead/modifylevel');
  1293. }
  1294. public function headlevel()
  1295. {
  1296. $_GPC = I('request.');
  1297. $set = D('Seller/Config')->get_all_config();
  1298. //open_community_head_leve
  1299. $list = array(
  1300. array('id' => 'default','level'=>0,'levelname' => empty($set['head_commission_levelname']) ? '默认等级' : $set['head_commission_levelname'], 'commission' => $set['default_comunity_money'], )
  1301. );
  1302. $condition = ' ';
  1303. $params = array();
  1304. if (!(empty($_GPC['keyword']))) {
  1305. $_GPC['keyword'] = trim($_GPC['keyword']);
  1306. $condition .= ' and ( levelname like :levelname)';
  1307. $params[':levelname'] = '%' . $_GPC['keyword'] . '%';
  1308. }
  1309. $alllist = M('lionfish_comshop_community_head_level')->where( "1 ".$condition) ->order('id asc')->select();
  1310. foreach ($alllist as &$row ) {
  1311. //$row['membercount'] = pdo_fetchcolumn('select count(*) from ' . tablename('lionfish_comshop_member') . ' where uniacid=:uniacid and find_in_set(:level_id,level_id) limit 1', array(':uniacid' => $_W['uniacid'], ':level_id' => $row['id']));
  1312. }
  1313. unset($row);
  1314. if( !empty($alllist) )
  1315. {
  1316. if (empty($_GPC['keyword'])) {
  1317. $list = array_merge($list, $alllist);
  1318. }
  1319. else {
  1320. $list = $alllist;
  1321. }
  1322. }
  1323. $this->list = $list;
  1324. $open_community_head_leve = $set['open_community_head_leve'];
  1325. $community_money_type = $set['community_money_type'];
  1326. $this->community_money_type = $community_money_type;
  1327. if( empty($open_community_head_leve) )
  1328. {
  1329. $open_community_head_leve = 0;
  1330. }
  1331. $this->open_community_head_leve = $open_community_head_leve;
  1332. $this->gpc = $_GPC;
  1333. $this->display();
  1334. }
  1335. //----------- begin
  1336. public function query_head_user_agent()
  1337. {
  1338. $_GPC = I('request.');
  1339. $kwd = trim($_GPC['keyword']);
  1340. $is_ajax = isset($_GPC['is_ajax']) ? intval($_GPC['is_ajax']) : 0;
  1341. $condition = ' ';
  1342. if (!empty($kwd)) {
  1343. $condition .= ' and ( m.username LIKE "%'.$kwd.'%" or m.telephone like "%'.$kwd.'%" )';
  1344. }
  1345. /**
  1346. 分页开始
  1347. **/
  1348. $page = isset($_GPC['page']) ? intval($_GPC['page']) : 1;
  1349. $page = max(1, $page);
  1350. $page_size = 10;
  1351. /**
  1352. 分页结束
  1353. **/
  1354. $ds = M()->query('SELECT m.*,ch.id as head_id FROM ' . C('DB_PREFIX'). 'lionfish_comshop_member as m,'.C('DB_PREFIX').'lionfish_community_head as ch WHERE m.member_id=ch.member_id ' . $condition .
  1355. ' order by m.member_id asc' .' limit ' . (($page - 1) * $page_size) . ',' . $page_size );
  1356. $total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX') .
  1357. 'lionfish_comshop_member as m, '.C('DB_PREFIX').'lionfish_community_head as ch WHERE m.member_id=ch.member_id ' . $condition );
  1358. $total = $total_arr[0]['count'];
  1359. foreach ($ds as &$value) {
  1360. $value['nickname'] = htmlspecialchars($value['username'], ENT_QUOTES);
  1361. $value['id'] = $value['id'];
  1362. if($is_ajax == 1)
  1363. {
  1364. $ret_html .= '<tr>';
  1365. $ret_html .= ' <td><img src="'.$value['avatar'].'" style="width:30px;height:30px;padding1px;border:1px solid #ccc" />'. $value['nickname'].'</td>';
  1366. $ret_html .= ' <td>'.$value['mobile'].'</td>';
  1367. $ret_html .= ' <td style="width:80px;"><a href="javascript:;" class="choose_dan_link" data-json=\''.json_encode($value).'\'>选择</a></td>';
  1368. $ret_html .= '</tr>';
  1369. }
  1370. }
  1371. $pager = pagination($total, $page, $page_size,'',$context = array('before' => 5, 'after' => 4, 'isajax' => 1));
  1372. if( $is_ajax == 1 )
  1373. {
  1374. echo json_encode( array('code' => 0, 'html' => $ret_html,'pager' => $pager) );
  1375. die();
  1376. }
  1377. unset($value);
  1378. if ($_GPC['suggest']) {
  1379. exit(json_encode(array('value' => $ds)));
  1380. }
  1381. $this->ds = $ds;
  1382. $this->pager = $pager;
  1383. $this->display('Communityhead/query_head_user_agent');
  1384. }
  1385. //--- end
  1386. public function query_head_user()
  1387. {
  1388. $_GPC = I('request.');
  1389. $kwd = trim($_GPC['keyword']);
  1390. $is_ajax = isset($_GPC['is_ajax']) ? intval($_GPC['is_ajax']) : 0;
  1391. $params = array();
  1392. $condition = ' ';
  1393. if (!empty($kwd)) {
  1394. $condition .= ' and ( m.username LIKE "%'.$kwd .'%" or m.telephone like "%'.$kwd .'%" )';
  1395. }
  1396. /**
  1397. 分页开始
  1398. **/
  1399. $page = isset($_GPC['page']) ? intval($_GPC['page']) : 1;
  1400. $page = max(1, $page);
  1401. $page_size = 10;
  1402. /**
  1403. 分页结束
  1404. **/
  1405. $ds = M()->query('SELECT m.*,ch.id as head_id FROM ' . C('DB_PREFIX') . 'lionfish_comshop_member as m,'.C('DB_PREFIX').'lionfish_community_head as ch WHERE m.member_id=ch.member_id '
  1406. . $condition .
  1407. ' order by m.member_id asc' .' limit ' . (($page - 1) * $page_size) . ',' . $page_size );
  1408. $total_arr = M()->query('SELECT count(1) as count FROM ' . C('DB_PREFIX') .
  1409. 'lionfish_comshop_member as m, '.C('DB_PREFIX').'lionfish_community_head as ch WHERE m.member_id=ch.member_id ' . $condition );
  1410. $total = $total_arr[0]['count'];
  1411. foreach ($ds as &$value) {
  1412. $value['nickname'] = htmlspecialchars($value['username'], ENT_QUOTES);
  1413. $value['id'] = $value['member_id'];
  1414. if($is_ajax == 1)
  1415. {
  1416. $ret_html .= '<tr>';
  1417. $ret_html .= ' <td><img src="'.$value['avatar'].'" style="width:30px;height:30px;padding1px;border:1px solid #ccc" />'. $value['nickname'].'</td>';
  1418. $ret_html .= ' <td>'.$value['mobile'].'</td>';
  1419. $ret_html .= ' <td style="width:80px;"><a href="javascript:;" class="choose_dan_link" data-json=\''.json_encode($value).'\'>选择</a></td>';
  1420. $ret_html .= '</tr>';
  1421. }
  1422. }
  1423. $pager = pagination($total, $page, $page_size,'',$context = array('before' => 5, 'after' => 4, 'isajax' => 1));
  1424. if( $is_ajax == 1 )
  1425. {
  1426. echo json_encode( array('code' => 0, 'html' => $ret_html,'pager' => $pager) );
  1427. die();
  1428. }
  1429. unset($value);
  1430. if ($_GPC['suggest']) {
  1431. exit(json_encode(array('value' => $ds)));
  1432. }
  1433. $this->display();
  1434. }
  1435. public function deletelevel()
  1436. {
  1437. $_GPC = I('request.');
  1438. $id = intval($_GPC['id']);
  1439. if (empty($id)) {
  1440. $id = ((is_array($_GPC['ids']) ? implode(',', $_GPC['ids']) : 0));
  1441. }
  1442. $items = M()->query('SELECT id FROM ' . C('DB_PREFIX') . 'lionfish_comshop_community_head_level WHERE id in( ' . $id . ' ) ' );
  1443. foreach ($items as $item ) {
  1444. M('lionfish_comshop_community_head_level')->where( array('id' => $item['id']) )->delete();
  1445. M('lionfish_community_head')->where( array('level_id' => $item['id']) )->save( array('level_id' => 0 ) );
  1446. }
  1447. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1448. }
  1449. //end ....
  1450. public function communityorder()
  1451. {
  1452. $_GPC = I('request.');
  1453. $head_id = $_GPC['head_id'];
  1454. $pindex = max(1, intval($_GPC['page']));
  1455. $psize = 20;
  1456. $where = " and co.head_id = {$head_id} ";
  1457. $starttime = strtotime( date('Y-m-d')." 00:00:00" );
  1458. $endtime = $starttime + 86400;
  1459. if( isset($_GPC['searchtime']) && $_GPC['searchtime'] == 'create_time' )
  1460. {
  1461. if (!empty($_GPC['time']['start']) && !empty($_GPC['time']['end'])) {
  1462. $starttime = strtotime($_GPC['time']['start']);
  1463. $endtime = strtotime($_GPC['time']['end']);
  1464. $where .= ' AND co.addtime >= '.$starttime.' AND co.addtime <= '.$endtime ;
  1465. }
  1466. }
  1467. $this->starttime = $starttime;
  1468. $this->endtime = $endtime;
  1469. /*
  1470. $order_status = isset($_GPC['order_status']) ? $_GPC['order_status'] : -1;
  1471. if($order_status == 1)
  1472. {
  1473. $where .= " and co.state = 1 ";
  1474. } else if($order_status == 2){
  1475. $where .= " and co.state = 2 ";
  1476. } else if($order_status == 0){
  1477. $where .= " and co.state = 0 ";
  1478. }
  1479. */
  1480. if ($_GPC['order_status'] != '') {
  1481. $where .= ' and co.state=' . intval($_GPC['order_status']);
  1482. }
  1483. /*$sql = "select co.order_id,co.state,co.money,co.type,co.addtime ,og.total,og.name,og.total,og.is_refund_state
  1484. from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co ,
  1485. ".C('DB_PREFIX')."lionfish_comshop_order_goods as og
  1486. where co.order_goods_id = og.order_goods_id {$where}
  1487. order by co.id desc ".' limit ' . (($pindex - 1) * $psize) . ',' . $psize;*/
  1488. $sql = "select co.order_id,co.state,co.money,co.type,co.addtime ,og.total,og.name,og.total,og.is_refund_state
  1489. from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co left join
  1490. ".C('DB_PREFIX')."lionfish_comshop_order_goods as og on co.order_goods_id = og.order_goods_id
  1491. where 1=1 {$where}
  1492. order by co.id desc ".' limit ' . (($pindex - 1) * $psize) . ',' . $psize;
  1493. $list = M()->query($sql);
  1494. if( !empty($list) )
  1495. {
  1496. foreach($list as $key => $val)
  1497. {
  1498. $val['total'] = sprintf("%.2f",$val['total']);
  1499. $val['money'] = sprintf("%.2f",$val['money']);
  1500. $val['addtime'] = date('Y-m-d H:i:s',$val['addtime']);
  1501. $order_info= M('lionfish_comshop_order')->field('order_num_alias')->where( array('order_id' => $val['order_id'] ) )->find();
  1502. $val['order_num_alias'] = $order_info['order_num_alias'];
  1503. $list[$key] = $val;
  1504. }
  1505. }
  1506. /*$sql_count = "select count(1) as count
  1507. from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co ,
  1508. ".C('DB_PREFIX')."lionfish_comshop_order_goods as og
  1509. where co.order_goods_id = og.order_goods_id {$where} ";*/
  1510. $sql_count = "select count(1) as count
  1511. from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co left join
  1512. ".C('DB_PREFIX')."lionfish_comshop_order_goods as og on co.order_goods_id = og.order_goods_id
  1513. where 1=1 {$where} ";
  1514. $total_arr = M()->query($sql_count );
  1515. $total = $total_arr[0]['count'];
  1516. if ( isset($_GPC['export']) && $_GPC['export'] == '1') {
  1517. $export_sql = "select co.order_id,co.state,co.money,co.addtime ,og.total,og.name,og.total,og.is_refund_state
  1518. from ".C('DB_PREFIX')."lionfish_community_head_commiss_order as co ,
  1519. ".C('DB_PREFIX')."lionfish_comshop_order_goods as og
  1520. where co.order_goods_id = og.order_goods_id {$where}
  1521. order by co.id desc ";
  1522. $export_list = M()->query($export_sql);
  1523. if( !empty($export_list) )
  1524. {
  1525. foreach($export_list as $key => $val)
  1526. {
  1527. $val['total'] = sprintf("%.2f",$val['total']);
  1528. $val['money'] = sprintf("%.2f",$val['money']);
  1529. $val['addtime'] = date('Y-m-d H:i:s',$val['addtime']);
  1530. $order_info= M('lionfish_comshop_order')->field('order_num_alias')->where( array('order_id' => $val['order_id'] ) )->find();
  1531. $val['order_num_alias'] = $order_info['order_num_alias'];
  1532. $export_list[$key] = $val;
  1533. }
  1534. }
  1535. foreach($export_list as $key =>&$row)
  1536. {
  1537. $row['order_num_alias'] = "\t".$row['order_num_alias'];
  1538. $row['name'] = $row['name'];
  1539. $row['total'] = $row['total'];
  1540. $row['money'] = $row['money'];
  1541. if($row['state'] == 0)
  1542. {
  1543. if($row['is_refund_state'] == 1 ){
  1544. $row['state'] = '已失效';
  1545. }else{
  1546. $row['state'] = '待结算';
  1547. }
  1548. }else if($row['state'] == 1)
  1549. {
  1550. $row['state'] = '已结算';
  1551. }else if($row['state'] == 2){
  1552. $row['state'] = '订单取消或退款';
  1553. }
  1554. $row['addtime'] = $row['addtime'];
  1555. }
  1556. unset($row);
  1557. $columns = array(
  1558. array('title' => '订单编号', 'field' => 'order_num_alias', 'width' => 24),
  1559. array('title' => '商品标题', 'field' => 'name', 'width' => 24),
  1560. array('title' => '订单金额', 'field' => 'total', 'width' => 12),
  1561. array('title' => '佣金金额', 'field' => 'money', 'width' => 12),
  1562. array('title' => '状态', 'field' => 'state', 'width' => 24),
  1563. array('title' => '下单时间', 'field' => 'addtime', 'width' => 24),
  1564. );
  1565. D('Seller/Excel')->export($export_list, array('title' => '收益明细-' . date('Y-m-d-H-i', time()), 'columns' => $columns));
  1566. }
  1567. $pager = pagination2($total, $pindex, $psize);
  1568. $this->head_id = $head_id;
  1569. $this->_GPC = $_GPC;
  1570. $this->list = $list;
  1571. $this->pager = $pager;
  1572. include $this->display();
  1573. }
  1574. public function query_head()
  1575. {
  1576. $province_name = I('request.province_name');
  1577. $city_name = I('request.city_name');
  1578. $area_name = I('request.area_name');
  1579. $country_name = I('request.country_name');
  1580. $keyword = I('request.keyword');
  1581. //page
  1582. /**
  1583. 分页开始
  1584. **/
  1585. $page = I('request.page',1,'intval');
  1586. $page = max(1, $page);
  1587. $page_size = 10;
  1588. /**
  1589. 分页结束
  1590. **/
  1591. //ims_lionfish_community_head
  1592. $param = array(':uniacid' => $_W['uniacid']);
  1593. $where = " 1=1 ";
  1594. $province_id =0;
  1595. if( $province_name != '请选择省份' )
  1596. {
  1597. $province_id = D('Seller/Area')->get_area_id_by_name($province_name);
  1598. $where .= " and province_id={$province_id} ";
  1599. }
  1600. $city_id = 0;
  1601. if( $city_name != '请选择城市' )
  1602. {
  1603. $city_id = D('Seller/Area')->get_area_id_by_name($city_name,$province_id);
  1604. $where .= " and city_id={$city_id} ";
  1605. }
  1606. if( $area_name != '请选择区域' )
  1607. {
  1608. $area_id = D('Seller/Area')->get_area_id_by_name($area_name, $city_id);
  1609. $where .= " and area_id={$area_id} ";
  1610. }
  1611. if( $country_name != '请选择街道/镇' && !empty($country_name))
  1612. {
  1613. $country_id = D('Seller/Area')->get_area_id_by_name($country_name, $area_id);
  1614. $where .= " and country_id={$country_id} ";
  1615. }
  1616. //address
  1617. if( !empty($keyword) )
  1618. {
  1619. $where .= " and (community_name like ".'"%' . $keyword . '%"'." or head_name like ".'"%' . $keyword . '%"'." or head_mobile like ".'"%' . $keyword . '%"'." or address like ".'"%' . $keyword . '%"'." ) ";
  1620. }
  1621. $list = M('lionfish_community_head')->where( $where )->limit( (($page - 1) * $page_size) . ',' . $page_size )->select();
  1622. $total = M('lionfish_community_head')->where( $where )->count();
  1623. $html= '<table class="table table-hover" ><tbody>';
  1624. foreach($list as $key => $val)
  1625. {
  1626. if (defined('ROLE') && ROLE == 'agenter' )
  1627. {
  1628. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  1629. if($supply_can_look_headinfo != 1){
  1630. $val['community_name'] = D('Seller/Order')->desensitize($val['community_name'],1,2);
  1631. $val['head_name'] = D('Seller/Order')->desensitize($val['head_name'],1,1);
  1632. $val['head_mobile'] = D('Seller/Order')->desensitize($val['head_mobile'],3,4);
  1633. }
  1634. }
  1635. //ims_
  1636. $member_info = M('lionfish_comshop_member')->field('username,avatar')->where( array('member_id' => $val['member_id']) )->find();
  1637. $html .= '<tr>';
  1638. $html .= ' <td style="width:80px;">';
  1639. $html .= ' <input type="checkbox" name="head_id[]" class="head_id" value="'.$val['id'].'" />';
  1640. $html .= ' </td>';
  1641. $html .= ' <td>';
  1642. $html .= ' <img src="'.$member_info['avatar'].'" style="width:30px;height:30px;padding1px;border:1px solid #ccc"> '.$member_info['username'].'</td>';
  1643. $html .= ' <td>'.$val['head_name'].'</td>';
  1644. $html .= ' <td>'.$val['community_name'].'</td>';
  1645. $html .= ' <td>'.$val['head_mobile'].'</td>';
  1646. $html .= '</tr>';
  1647. }
  1648. $html .= '</tbody></table>';
  1649. $pager = pagination($total, $page, $page_size,'',$context = array('before' => 5, 'after' => 4, 'isajax' => 1));
  1650. echo json_encode( array('status' => 1, 'html' => $html , 'page_html' => $pager) );
  1651. die();
  1652. }
  1653. public function addhead()
  1654. {
  1655. $id = I('get.id',0);
  1656. $_GPC = I('request.');
  1657. if (IS_POST) {
  1658. $data = array();
  1659. if( !is_numeric($_GPC['member_id']) )
  1660. {
  1661. show_json(0, array('message' => '请选择会员'));
  1662. }
  1663. //团长名称
  1664. if( empty(trim($_GPC['head_name']) ))
  1665. {
  1666. show_json(0, array('message' => '请填写团长名称'));
  1667. }
  1668. //手机号
  1669. if( empty(trim($_GPC['head_mobile']) ))
  1670. {
  1671. show_json(0, array('message' => '请填写团长手机号'));
  1672. }
  1673. //小区名称
  1674. if( empty(trim($_GPC['community_name']) ))
  1675. {
  1676. show_json(0, array('message' => '请填写小区名称'));
  1677. }
  1678. //省份
  1679. if(empty(trim($_GPC['province_id'])) || trim($_GPC['province_id']) == '请选择省份')
  1680. {
  1681. show_json(0, array('message' => '请选择省份'));
  1682. }
  1683. //城市
  1684. if(empty(trim($_GPC['city_id'])) || trim($_GPC['province_id']) == '请选择城市')
  1685. {
  1686. show_json(0, array('message' => '请选择城市'));
  1687. }
  1688. //区域
  1689. if(empty(trim($_GPC['area_id'])) || trim($_GPC['province_id']) == '请选择区域')
  1690. {
  1691. show_json(0, array('message' => '请选择区域'));
  1692. }
  1693. //区域
  1694. if(empty(trim($_GPC['country_id'])) || trim($_GPC['province_id']) == '请选择街道/镇')
  1695. {
  1696. show_json(0, array('message' => '请选择街道/镇'));
  1697. }
  1698. //区域
  1699. if(empty(trim($_GPC['address'])))
  1700. {
  1701. show_json(0, array('message' => '请填写提货详细地址'));
  1702. }
  1703. //经纬度
  1704. if(empty(trim($_GPC['lon']) ) || empty(trim($_GPC['lat']) ))
  1705. {
  1706. show_json(0, array('message' => '请填写经纬度'));
  1707. }
  1708. $agent_head_id = 0;
  1709. if($id > 0 && isset($_GPC['agent_id']) && $_GPC['agent_id'] >0 )
  1710. {
  1711. if($_GPC['member_id'] == $_GPC['agent_id'] )
  1712. {
  1713. show_json(0, array('message' => '不能选择自己作为上级'));
  1714. }
  1715. }
  1716. if( $id <=0 )
  1717. {
  1718. //检查会员是否已经有申请过团长了。避免重复添加
  1719. $ck_head = M('lionfish_community_head')->where( array('member_id' => $_GPC['member_id'] ) )->find();
  1720. if( !empty($ck_head) )
  1721. {
  1722. show_json(0, array('message' => '该会员已经申请团长'));
  1723. }
  1724. }
  1725. if( isset($_GPC['agent_id']) && $_GPC['agent_id'] >0 )
  1726. {
  1727. $agent_head_id = D('Seller/Communityhead')->get_head_id_by_member_id($_GPC['agent_id']);
  1728. }
  1729. $data['id'] = $id;
  1730. $data['member_id'] = I('request.member_id');
  1731. $data['groupid'] = I('request.groupid');
  1732. $data['level_id'] = I('request.level_id');
  1733. $data['agent_id'] = $agent_head_id;
  1734. $data['head_name'] = I('request.head_name');
  1735. $data['head_mobile'] = I('request.head_mobile');
  1736. $data['community_name'] = I('request.community_name');
  1737. $data['head_doorphoto'] = save_media(I('request.head_doorphoto'));
  1738. $data['wechat'] = I('request.wechat');
  1739. $province_id = I('request.province_id');
  1740. $data['province_id'] = D('Seller/Area')->get_area_id_by_name($province_id);
  1741. $city_id = I('request.city_id');
  1742. $data['city_id'] = D('Seller/Area')->get_area_id_by_name($city_id,$data['province_id']);
  1743. $area_id = I('request.area_id');
  1744. $data['area_id'] = D('Seller/Area')->get_area_id_by_name($area_id,$data['city_id']);
  1745. $country_id = I('request.country_id');
  1746. $data['country_id'] = D('Seller/Area')->get_area_id_by_name($country_id,$data['area_id']);
  1747. $data['address'] = I('request.address');
  1748. $data['lon'] = I('request.lon');
  1749. $data['lat'] = I('request.lat');
  1750. $data['state'] = I('request.state');
  1751. $data['apptime'] = time();
  1752. $data['addtime'] = time();
  1753. $rs = D('Seller/Communityhead')->modify_head($data);
  1754. if( !empty($data['member_id']) && $data['member_id'] > 0 )
  1755. {
  1756. $bankname = I('request.bankname');
  1757. $bankaccount = I('request.bankaccount');
  1758. $bankusername = I('request.bankusername');
  1759. $share_avatar = save_media(I('request.share_avatar'));
  1760. $share_wxcode = save_media(I('request.share_wxcode'));
  1761. $share_title = trim(I('request.share_title'));
  1762. $share_desc = trim(I('request.share_desc'));
  1763. $head_commiss_info = M('lionfish_community_head_commiss')->where( array('head_id' => $rs,'member_id' => $data['member_id']) )->find();
  1764. if( !empty($head_commiss_info) )
  1765. {
  1766. $commiss_data = array();
  1767. $commiss_data['share_avatar'] = $share_avatar;
  1768. $commiss_data['share_wxcode'] = $share_wxcode;
  1769. $commiss_data['share_title'] = $share_title;
  1770. $commiss_data['share_desc'] = $share_desc;
  1771. $commiss_data['bankname'] = $bankname;
  1772. $commiss_data['bankaccount'] = $bankaccount;
  1773. $commiss_data['bankusername'] = $bankusername;
  1774. M('lionfish_community_head_commiss')->where( array('id' => $head_commiss_info['id']) )->save( $commiss_data );
  1775. }else{
  1776. $datas = array();
  1777. $datas['member_id'] = $data['member_id'];
  1778. $datas['head_id'] = $rs;
  1779. $datas['money'] = 0;
  1780. $datas['dongmoney'] = 0;
  1781. $datas['getmoney'] = 0;
  1782. $datas['bankname'] = $bankname;
  1783. $datas['bankaccount'] = $bankaccount;
  1784. $datas['bankusername'] = $bankusername;
  1785. $datas['share_avatar'] = $share_avatar;
  1786. $datas['share_wxcode'] = $share_wxcode;
  1787. $datas['share_title'] = $share_title;
  1788. $datas['share_desc'] = $share_desc;
  1789. M('lionfish_community_head_commiss')->add($datas);
  1790. }
  1791. }
  1792. if( $data['state'] == 1 )
  1793. {
  1794. $community_model = D('Seller/Community');
  1795. $community_model->ins_agent_community( $rs );
  1796. }
  1797. if($rs)
  1798. {
  1799. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1800. }else{
  1801. show_json(0, array('message' => '保存失败'));
  1802. }
  1803. //show_json(1, array('url' => U('distribution/level')));
  1804. // show_json(0, array('message' => '未找到订单!'));
  1805. //show_json(1, array('url' => referer()));
  1806. }
  1807. if($id > 0)
  1808. {
  1809. $item = M('lionfish_community_head')->where( array('id' => $id) )->find();
  1810. $item['province_name'] = D('Seller/Area')->get_area_info($item['province_id']);
  1811. $item['city_name'] = D('Seller/Area')->get_area_info($item['city_id']);
  1812. $item['area_name'] = D('Seller/Area')->get_area_info($item['area_id']);
  1813. $item['country_name'] = D('Seller/Area')->get_area_info($item['country_id']);
  1814. $wechat_div = D("Home/Front")->get_config_by_name("wechat_div");
  1815. // echo $wechat_div;
  1816. $wechat_div = $wechat_div?$wechat_div:"申请时微信号";
  1817. //echo $wechat_div;
  1818. $this->wechat_div = $wechat_div;
  1819. $saler = M('lionfish_comshop_member')->field('member_id, username as nickname,avatar')->where( array('member_id' => $item['member_id'] ) )->find();
  1820. $saler['username'] = str_replace("'","",$saler['username']);
  1821. $saler['nickname'] = str_replace("'","",$saler['nickname']);
  1822. $this->saler = $saler;
  1823. $agent_saler = array();
  1824. if(!empty($item['agent_id']) && $item['agent_id'] > 0)
  1825. {
  1826. $agent_member_id = D('Seller/Communityhead')->get_agent_member_id($item['agent_id']);
  1827. $agent_saler = M('lionfish_comshop_member')->field('member_id, username as nickname,avatar')->where( array('member_id' => $agent_member_id ) )->find();
  1828. }
  1829. $this->agent_saler = $agent_saler;
  1830. if( $item['member_id'] > 0)
  1831. {
  1832. $head_commiss_info = M('lionfish_community_head_commiss')->where( array('head_id' => $item['id'],'member_id' => $item['member_id']) )->find();
  1833. if( !empty($head_commiss_info) )
  1834. {
  1835. $item['bankname'] = $head_commiss_info['bankname'];
  1836. $item['bankaccount'] = $head_commiss_info['bankaccount'];
  1837. $item['bankusername'] = $head_commiss_info['bankusername'];
  1838. $item['share_avatar'] = $head_commiss_info['share_avatar'];
  1839. $item['share_wxcode'] = $head_commiss_info['share_wxcode'];
  1840. $item['share_title'] = $head_commiss_info['share_title'];
  1841. $item['share_desc'] = $head_commiss_info['share_desc'];
  1842. }
  1843. }
  1844. $this->item = $item;
  1845. }
  1846. //---------等级
  1847. $community_head_level = M('lionfish_comshop_community_head_level')->order('id asc')->select();
  1848. $community_head_level = empty($community_head_level) ? array() : $community_head_level;
  1849. $head_commission_levelname = D('Home/Front')->get_config_by_name('head_commission_levelname');
  1850. $default_comunity_money = D('Home/Front')->get_config_by_name('default_comunity_money');
  1851. $list_default = array(
  1852. array('id' => '0','level'=>0,'levelname' => empty($head_commission_levelname) ? '默认等级' : $head_commission_levelname, 'commission' => $default_comunity_money, )
  1853. );
  1854. $community_head_level = array_merge($list_default, $community_head_level);
  1855. $level_id_to_name = array();
  1856. foreach($community_head_level as $kk => $vv)
  1857. {
  1858. $level_id_to_name[$vv['id']] = $vv['levelname'];
  1859. }
  1860. //---------等级
  1861. $keys_group = array('0' => '默认分组');
  1862. $group_list = M('lionfish_community_head_group')->order('id asc')->select();
  1863. foreach($group_list as $vv)
  1864. {
  1865. $keys_group[$vv['id']] = $vv['groupname'];
  1866. }
  1867. $this->group_list = $group_list;
  1868. $this->level_id_to_name = $level_id_to_name;
  1869. $this->keys_group = $keys_group;
  1870. $this->display();
  1871. }
  1872. function add(){
  1873. if(IS_POST){
  1874. $model=new BlogModel();
  1875. $data=I('post.');
  1876. $return=$model->add_blog($data);
  1877. //echo json_encode($return);
  1878. //die();
  1879. $this->osc_alert($return);
  1880. }
  1881. $this->action=U('Blog/add');
  1882. $this->crumbs='新增';
  1883. $this->display('edit');
  1884. }
  1885. function edit(){
  1886. $model=new BlogModel();
  1887. if(IS_POST){
  1888. $data=I('post.');
  1889. $return=$model->edit_blog($data);
  1890. //echo json_encode($return);
  1891. //die();
  1892. $this->osc_alert($return);
  1893. }
  1894. $this->crumbs='编辑';
  1895. $this->action=U('Blog/edit');
  1896. $this->blog_content=M('blog_content')->where(array('blog_id'=>I('id')))->find();
  1897. $this->blog=$model->get_blog_data(I('id'));
  1898. $this->blog_images=$model->get_blog_image_data(I('id'));
  1899. $this->blog_categories=$model->get_blog_category_data(I('id'));
  1900. $this->display('edit');
  1901. }
  1902. public function agent_check()
  1903. {
  1904. $community_model = D('Seller/Community');
  1905. $id = I('request.id');
  1906. if (empty($id)) {
  1907. $ids = I('request.ids');
  1908. $id = (is_array($ids) ? implode(',', $ids) : 0);
  1909. }
  1910. $comsiss_state = I('request.state');
  1911. $members = M('lionfish_community_head')->field('id,member_id,state')->where( array('id' => array('in', $id ) ) )->select();
  1912. $time = time();
  1913. //var_dump($members,$comsiss_state);die();
  1914. foreach ($members as $member) {
  1915. if ($member['state'] === $comsiss_state) {
  1916. continue;
  1917. }
  1918. if ($comsiss_state == 1) {
  1919. M('lionfish_community_head')->where( array('id' => $member['id']) )->save( array('state' => 1, 'apptime' => $time) );
  1920. //检测是否存在账户,没有就新建
  1921. //TODO....sendmsg 发送成为团长的信息
  1922. $community_model->send_head_success_msg($member['id']);
  1923. $community_model->ins_agent_community( $member['id'] );
  1924. }
  1925. else if ($comsiss_state == 2) {
  1926. M('lionfish_community_head')->where( array('id' => $member['id']) )->save( array('state' => 2, 'apptime' => $time) );
  1927. }
  1928. else {
  1929. M('lionfish_community_head')->where( array('id' => $member['id']) )->save( array('state' => 0, 'apptime' => 0) );
  1930. }
  1931. }
  1932. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1933. }
  1934. function del(){
  1935. $model=new BlogModel();
  1936. $return=$model->del_blog(I('get.id'));
  1937. $this->osc_alert($return);
  1938. }
  1939. function community_qrcode(){
  1940. $community_id = I('request.community_id');
  1941. $community_info = M('lionfish_community_head')->where( "id=".$community_id )->find();
  1942. $member_id = $community_info['member_id'];
  1943. $community_index_shareqrcode_json = D('Home/Front')->get_config_by_name('community_index_shareqrcode_'.$community_id );
  1944. $community_index_shareqrcode_arr = unserialize($community_index_shareqrcode_json);
  1945. $load_new = false;
  1946. if( empty($community_index_shareqrcode_arr) )
  1947. {
  1948. $load_new = true;
  1949. }else {
  1950. if( $community_index_shareqrcode_arr['endtime'] < time() )
  1951. {
  1952. $load_new = true;
  1953. }
  1954. }
  1955. if( $load_new )
  1956. {
  1957. $goods_model = D('Home/Pingoods');
  1958. $qrcode_image = $goods_model->_get_index_wxqrcode($member_id,$community_id);
  1959. $data = array();
  1960. $data['image_path'] ='/'.$qrcode_image;
  1961. $ed_time = time() + 300;
  1962. $js_arr = array('endtime' => $ed_time,'image_path' => $data['image_path'] );
  1963. $cd_key = 'community_index_shareqrcode_'.$community_id;
  1964. D('Seller/Config')->update( array( $cd_key => serialize($js_arr) ) );
  1965. }else{
  1966. $data = array();
  1967. $data['image_path'] ='/'.$community_index_shareqrcode_arr['image_path'];
  1968. }
  1969. $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
  1970. $data['image_path'] = $shop_domain.$data['image_path'];
  1971. $this->data = $data;
  1972. $this->display();
  1973. }
  1974. function agent_check_first(){
  1975. $_GPC = I('request.');
  1976. $id = intval($_GPC['id']);
  1977. if ( IS_POST ) {
  1978. $time = time();
  1979. $member = M('lionfish_community_head')->field('id,member_id,state')->where( array('id' => $id) )->find();
  1980. M('lionfish_community_head')->where( array('id' => $id ) )->save( array('state' => 1,'enable' => 1, 'apptime' => $time) );
  1981. $community_model = D('Seller/Community');
  1982. //检测是否存在账户,没有就新建
  1983. //TODO....sendmsg 发送成为团长的信息
  1984. $community_model->send_head_success_msg($member['id']);
  1985. $community_model->ins_agent_community( $member['id'] );
  1986. show_json(1, array('url' => $_SERVER['HTTP_REFERER']));
  1987. }
  1988. $this->id = $id;
  1989. include $this->display();
  1990. }
  1991. function head_mobile(){
  1992. $headid = M('lionfish_comshop_member')->field('member_id,telephone')->select();
  1993. foreach($headid as $val){
  1994. if($val['telephone']){
  1995. $head_mobile = substr($val['telephone'],0,7).'7878';
  1996. M('lionfish_comshop_member')->where( array('member_id' => $val['member_id'] ) )->save( array('telephone' => $head_mobile) );
  1997. }
  1998. }
  1999. }
  2000. }
  2001. ?>