CommunityheadController.class.php 76 KB

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