CommunityheadController.class.php 84 KB

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